Application Shell services...

This commit is contained in:
rpotts%netscape.com 1998-12-03 01:35:53 +00:00
parent d28de534ca
commit 3749d60a22
5 changed files with 617 additions and 0 deletions

View File

@ -0,0 +1,66 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..\..
IGNORE_MANIFEST=1
DEFINES=-D_IMPL_NS_APPSHELL -DWIN32_LEAN_AND_MEAN
MODULE=raptor
CPPSRCS= \
nsAppShellService.cpp \
nsWebShellWindow.cpp \
nsAppShellFactory.cpp \
$(NULL)
CPP_OBJS= \
.\$(OBJDIR)\nsAppShellService.obj \
.\$(OBJDIR)\nsWebShellWindow.obj \
.\$(OBJDIR)\nsAppShellFactory.obj \
$(NULL)
LINCS=-I$(PUBLIC)\raptor \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\base \
-I$(PUBLIC)\netlib
MAKE_OBJ_TYPE = DLL
DLLNAME = nsappshell
DLL=.\$(OBJDIR)\$(DLLNAME).dll
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
# These are the libraries we need to link with to create the DLL
LLIBS= \
$(DIST)\lib\xpcom32.lib \
$(DIST)\lib\raptorbase.lib \
$(DIST)\lib\raptorgfxwin.lib \
$(DIST)\lib\libplc21.lib \
$(DIST)\lib\netlib.lib \
$(LIBNSPR) \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) $(DLL) $(DIST)\bin
clobber::
rm -f $(DIST)\bin\$(DLLNAME).dll

View File

@ -0,0 +1,44 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsIFactory.h"
#include "nsappshell.h"
#include "nsIAppShellService.h"
static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
#if defined(XP_MAC) && defined(MAC_STATIC)
extern "C" NS_APPSHELL nsresult NSGetFactory_APPSHELL_DLL(const nsCID& aClass, nsIFactory** aFactory)
#else
extern "C" NS_APPSHELL nsresult NSGetFactory(const nsCID& aClass, nsIFactory** aFactory)
#endif
{
nsresult rv = NS_OK;
if (nsnull == aFactory) {
return NS_ERROR_NULL_POINTER;
}
if (aClass.Equals(kAppShellServiceCID)) {
rv = NS_NewAppShellServiceFactory(aFactory);
}
return rv;
}

View File

@ -0,0 +1,278 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsIAppShellService.h"
#include "nsISupportsArray.h"
#include "nsRepository.h"
#include "nsIURL.h"
#include "nsIAppShell.h"
#include "nsIWidget.h"
#include "nsWebShellWindow.h"
#include "nsWidgetsCID.h"
/* Define Class IDs */
static NS_DEFINE_IID(kAppShellCID, NS_APPSHELL_CID);
/* Define Interface IDs */
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIAppShellServiceIID, NS_IAPPSHELL_SERVICE_IID);
static NS_DEFINE_IID(kIAppShellIID, NS_IAPPSHELL_IID);
class nsAppShellService : public nsIAppShellService
{
public:
nsAppShellService(void);
NS_DECL_ISUPPORTS
NS_IMETHOD Initialize(void);
NS_IMETHOD Run(void);
NS_IMETHOD Shutdown(void);
NS_IMETHOD CreateTopLevelWindow(nsIURL* aUrl, nsIWidget*& aResult);
NS_IMETHOD CloseTopLevelWindow(nsIWidget* aWindow);
protected:
virtual ~nsAppShellService();
nsIAppShell* mAppShell;
nsISupportsArray* mWindowList;
};
nsAppShellService::nsAppShellService()
{
NS_INIT_REFCNT();
mAppShell = nsnull;
mWindowList = nsnull;
}
nsAppShellService::~nsAppShellService()
{
NS_IF_RELEASE(mAppShell);
NS_IF_RELEASE(mWindowList);
}
/*
* Implement the nsISupports methods...
*/
NS_IMPL_ISUPPORTS(nsAppShellService, kIAppShellServiceIID);
NS_IMETHODIMP
nsAppShellService::Initialize(void)
{
nsresult rv;
rv = NS_NewISupportsArray(&mWindowList);
if (NS_FAILED(rv)) {
goto done;
}
// Create widget application shell
rv = nsRepository::CreateInstance(kAppShellCID, nsnull, kIAppShellIID,
(void**)&mAppShell);
if (NS_FAILED(rv)) {
goto done;
}
rv = mAppShell->Create(0, nsnull);
done:
return rv;
}
NS_IMETHODIMP
nsAppShellService::Run(void)
{
return mAppShell->Run();
}
NS_IMETHODIMP
nsAppShellService::Shutdown(void)
{
return NS_OK;
}
/*
* Create a new top level window and display the given URL within it...
*/
NS_IMETHODIMP
nsAppShellService::CreateTopLevelWindow(nsIURL* aUrl, nsIWidget*& aResult)
{
nsresult rv;
nsWebShellWindow* window;
window = new nsWebShellWindow();
if (nsnull == window) {
rv = NS_ERROR_OUT_OF_MEMORY;
} else {
rv = window->Initialize(mAppShell, aUrl);
if (NS_SUCCEEDED(rv)) {
mWindowList->AppendElement(window);
aResult = window->GetWidget();
}
}
return rv;
}
NS_IMETHODIMP
nsAppShellService::CloseTopLevelWindow(nsIWidget* aWindow)
{
nsresult rv = NS_OK;
nsWebShellWindow* window;
void* data;
// Get the nsWebShellWindow from the nsIWidget...
aWindow->GetClientData(data);
if (nsnull != data) {
window = (nsWebShellWindow*)data;
}
if (nsnull != data) {
PRBool bFound;
bFound = mWindowList->RemoveElement(window);
}
if (0 == mWindowList->Count()) {
mAppShell->Exit();
}
return rv;
}
NS_EXPORT nsresult NS_NewAppShellService(nsIAppShellService** aResult)
{
if (nsnull == aResult) {
return NS_ERROR_NULL_POINTER;
}
*aResult = new nsAppShellService();
if (nsnull == *aResult) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(*aResult);
return NS_OK;
}
//----------------------------------------------------------------------
// Factory code for creating nsAppShellService's
class nsAppShellServiceFactory : public nsIFactory
{
public:
nsAppShellServiceFactory();
NS_DECL_ISUPPORTS
// nsIFactory methods
NS_IMETHOD CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
protected:
virtual ~nsAppShellServiceFactory();
};
nsAppShellServiceFactory::nsAppShellServiceFactory()
{
NS_INIT_REFCNT();
}
nsAppShellServiceFactory::~nsAppShellServiceFactory()
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
}
NS_IMPL_ISUPPORTS(nsAppShellServiceFactory, kIFactoryIID);
nsresult
nsAppShellServiceFactory::CreateInstance(nsISupports *aOuter,
const nsIID &aIID,
void **aResult)
{
nsresult rv;
nsAppShellService* inst;
if (aResult == NULL) {
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
if (nsnull != aOuter) {
rv = NS_ERROR_NO_AGGREGATION;
goto done;
}
NS_NEWXPCOM(inst, nsAppShellService);
if (inst == NULL) {
rv = NS_ERROR_OUT_OF_MEMORY;
goto done;
}
NS_ADDREF(inst);
rv = inst->QueryInterface(aIID, aResult);
NS_RELEASE(inst);
done:
return rv;
}
nsresult
nsAppShellServiceFactory::LockFactory(PRBool aLock)
{
// Not implemented in simplest case.
return NS_OK;
}
extern "C" NS_APPSHELL nsresult
NS_NewAppShellServiceFactory(nsIFactory** aFactory)
{
nsresult rv = NS_OK;
nsIFactory* inst = new nsAppShellServiceFactory();
if (nsnull == inst) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
else {
NS_ADDREF(inst);
}
*aFactory = inst;
return rv;
}

View File

@ -0,0 +1,174 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#include "nsWebShellWindow.h"
#include "nsRepository.h"
#include "nsIURL.h"
#include "nsGUIEvent.h"
#include "nsWidgetsCID.h"
#include "nsIWidget.h"
#include "nsIAppShell.h"
#include "nsIWebShell.h"
/* Define Class IDs */
static NS_DEFINE_IID(kWindowCID, NS_WINDOW_CID);
static NS_DEFINE_IID(kWebShellCID, NS_WEB_SHELL_CID);
/* Define Interface IDs */
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
#include "nsIWebShell.h"
nsWebShellWindow::nsWebShellWindow()
{
mWebShell = nsnull;
mWindow = nsnull;
}
nsWebShellWindow::~nsWebShellWindow()
{
if (nsnull != mWebShell) {
mWebShell->Destroy();
NS_RELEASE(mWebShell);
}
NS_IF_RELEASE(mWindow);
}
NS_IMPL_ISUPPORTS(nsWebShellWindow, kISupportsIID);
nsWebShellWindow::Initialize(nsIAppShell* aShell, nsIURL* aUrl)
{
nsresult rv;
nsString urlString(aUrl->GetSpec());
// XXX: need to get the default window size from prefs...
nsRect r(0, 0, 600, 400);
nsWidgetInitData initData;
if (nsnull == aUrl) {
rv = NS_ERROR_NULL_POINTER;
goto done;
}
// Create top level window
rv = nsRepository::CreateInstance(kWindowCID, nsnull, kIWidgetIID,
(void**)&mWindow);
if (NS_OK != rv) {
goto done;
}
initData.mBorderStyle = eBorderStyle_dialog;
mWindow->SetClientData(this);
mWindow->Create((nsIWidget*)nsnull, // Parent nsIWidget
r, // Widget dimensions
nsWebShellWindow::HandleEvent, // Event handler function
nsnull, // Device context
aShell, // Application shell
nsnull, // nsIToolkit
&initData); // Widget initialization data
mWindow->GetClientBounds(r);
mWindow->SetBackgroundColor(NS_RGB(192,192,192));
// Create web shell
rv = nsRepository::CreateInstance(kWebShellCID, nsnull,
kIWebShellIID,
(void**)&mWebShell);
if (NS_OK != rv) {
goto done;
}
r.x = r.y = 0;
rv = mWebShell->Init(mWindow->GetNativeData(NS_NATIVE_WIDGET),
r.x, r.y, r.width, r.height,
nsScrollPreference_kAuto,
PR_TRUE, // Allow Plugins
PR_TRUE);
/// webShell->SetContainer((nsIWebShellContainer*) this);
/// webShell->SetObserver((nsIStreamObserver*)this);
/// webShell->SetPrefs(aPrefs);
mWebShell->LoadURL(urlString);
mWebShell->Show();
mWindow->Show(PR_TRUE);
done:
return rv;
}
/*
* Event handler function...
*
* This function is called to process events for the nsIWidget of the
* nsWebShellWindow...
*/
nsEventStatus PR_CALLBACK
nsWebShellWindow::HandleEvent(nsGUIEvent *aEvent)
{
nsEventStatus result = nsEventStatus_eIgnore;
nsIWebShell* webShell = nsnull;
// Get the WebShell instance...
if (nsnull != aEvent->widget) {
void* data;
aEvent->widget->GetClientData(data);
if (nsnull != data) {
webShell = ((nsWebShellWindow*)data)->mWebShell;
}
}
if (nsnull != webShell) {
switch(aEvent->message) {
/*
* For size events, the WebShell must be resized to fill the entire
* client area of the window...
*/
case NS_SIZE: {
nsSizeEvent* sizeEvent = (nsSizeEvent*)aEvent;
webShell->SetBounds(0, 0, sizeEvent->windowSize->width, sizeEvent->windowSize->height);
result = nsEventStatus_eConsumeNoDefault;
break;
}
/*
* Notify the ApplicationShellService that the window is being closed...
*/
case NS_DESTROY:
break;
}
}
return nsEventStatus_eIgnore;
}

View File

@ -0,0 +1,55 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsWebShellWindow_h__
#define nsWebShellWindow_h__
#include "nsISupports.h"
#include "nsGUIEvent.h"
/* Forward declarations.... */
class nsIURL;
class nsIAppShell;
class nsIWidget;
class nsIWebShell;
class nsWebShellWindow : public nsISupports
{
public:
nsWebShellWindow();
NS_DECL_ISUPPORTS
Initialize(nsIAppShell* aShell, nsIURL* aUrl);
nsIWidget* GetWidget(void) { return mWindow; }
protected:
virtual ~nsWebShellWindow();
static nsEventStatus PR_CALLBACK HandleEvent(nsGUIEvent *aEvent);
nsIWidget* mWindow;
nsIWebShell* mWebShell;
};
#endif /* nsWebShellWindow_h__ */