Implement some toplevel windowing functionality
git-svn-id: svn://10.0.0.236/trunk@1118 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
parent
0862eba745
commit
f8555ac899
@ -21,7 +21,8 @@
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIApplicationShell.h"
|
||||
#include "nsweb.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsshell.h"
|
||||
#include "nscore.h"
|
||||
|
||||
// bf88e640-df99-11d1-9244-00805f8a7ab6
|
||||
@ -43,6 +44,15 @@ public:
|
||||
NS_IMETHOD_(nsIApplicationShell *) GetApplicationShell() = 0;
|
||||
NS_IMETHOD_(void) SetApplicationShell(nsIApplicationShell * aApplicationShell) = 0;
|
||||
|
||||
NS_IMETHOD_(nsIWidget *) CreateApplicationWindow(const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction) = 0 ;
|
||||
|
||||
NS_IMETHOD ShowApplicationWindow(PRBool show) = 0 ;
|
||||
|
||||
NS_IMETHOD_(void *) GetApplicationWindowNativeInstance() = 0;
|
||||
|
||||
NS_IMETHOD ExitApplication() = 0 ;
|
||||
|
||||
};
|
||||
|
||||
#endif /* nsIShellInstance_h___ */
|
||||
|
||||
@ -16,7 +16,14 @@
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
#ifdef NS_WIN32
|
||||
#include "windows.h"
|
||||
#endif
|
||||
|
||||
#include "NSApplicationManager.h"
|
||||
#include "nsString.h"
|
||||
|
||||
nsHashtable * NSApplicationManager::applications = NULL;
|
||||
PRMonitor *NSApplicationManager::monitor = NULL;
|
||||
@ -158,3 +165,35 @@ nsresult NSApplicationManager::DeleteShellAssociation(nsIApplicationShell * aApp
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult NSApplicationManager::ModalMessage(const nsString &aMessage,
|
||||
const nsString &aTitle,
|
||||
nsModalMessageType aModalMessageType)
|
||||
{
|
||||
|
||||
nsresult res = NS_OK ;
|
||||
|
||||
#ifdef NS_WIN32
|
||||
|
||||
PRInt32 msgtype ;
|
||||
|
||||
switch (aModalMessageType)
|
||||
{
|
||||
case eModalMessage_ok:
|
||||
msgtype = MB_OK ;
|
||||
break ;
|
||||
|
||||
case eModalMessage_ok_cancel:
|
||||
msgtype = MB_OK ;
|
||||
break ;
|
||||
|
||||
default:
|
||||
msgtype = MB_OK ;
|
||||
break ;
|
||||
|
||||
}
|
||||
::MessageBox(NULL, (const char *)aMessage.GetUnicode(), (const char *)aTitle.GetUnicode(), msgtype);
|
||||
|
||||
#endif
|
||||
|
||||
return res ;
|
||||
}
|
||||
|
||||
@ -26,13 +26,25 @@
|
||||
#include "prmon.h"
|
||||
#include "plstr.h"
|
||||
#include "nsCom.h"
|
||||
#include "nsweb.h"
|
||||
#include "nsshell.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsIShellInstance.h"
|
||||
#include "nsIApplicationShell.h"
|
||||
|
||||
|
||||
class NS_WEB NSApplicationManager {
|
||||
/**
|
||||
* ModalMessage enums
|
||||
*/
|
||||
|
||||
enum nsModalMessageType {
|
||||
///OK Modal Message
|
||||
eModalMessage_ok,
|
||||
///OK/CANCEL Modal Message
|
||||
eModalMessage_ok_cancel,
|
||||
};
|
||||
|
||||
|
||||
class NS_SHELL NSApplicationManager {
|
||||
private:
|
||||
static PRMonitor *monitor;
|
||||
static nsHashtable * applications;
|
||||
@ -51,6 +63,7 @@ public:
|
||||
static nsresult DeleteShellAssociation(nsIApplicationShell * aApplicationShell,
|
||||
nsIShellInstance *aShellInstance);
|
||||
|
||||
static nsresult ModalMessage(const nsString &aMessage, const nsString &aTitle, nsModalMessageType aModalMessageType);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@ -50,6 +50,7 @@ public:
|
||||
|
||||
nsShellInstance::nsShellInstance()
|
||||
{
|
||||
mApplicationWindow = NULL;
|
||||
}
|
||||
|
||||
nsShellInstance::~nsShellInstance()
|
||||
@ -163,6 +164,48 @@ nsresult nsShellInstance::RegisterFactories()
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsIWidget * nsShellInstance::CreateApplicationWindow(const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction)
|
||||
{
|
||||
|
||||
static NS_DEFINE_IID(kIWidgetIID, NS_IWIDGET_IID);
|
||||
static NS_DEFINE_IID(kCWindowCID, NS_WINDOW_CID);
|
||||
|
||||
NSRepository::CreateInstance(kCWindowCID,
|
||||
nsnull,
|
||||
kIWidgetIID,
|
||||
(LPVOID*)&(mApplicationWindow));
|
||||
|
||||
mApplicationWindow->Create((nsIWidget*)NULL,
|
||||
aRect,
|
||||
aHandleEventFunction,
|
||||
NULL);
|
||||
|
||||
return (mApplicationWindow);
|
||||
}
|
||||
|
||||
|
||||
nsresult nsShellInstance::ShowApplicationWindow(PRBool show)
|
||||
{
|
||||
mApplicationWindow->Show(show);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsShellInstance::ExitApplication()
|
||||
{
|
||||
|
||||
#ifdef NS_WIN32
|
||||
PostQuitMessage(0);
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void * nsShellInstance::GetApplicationWindowNativeInstance()
|
||||
{
|
||||
return (mApplicationWindow->GetNativeData(NS_NATIVE_WINDOW));
|
||||
}
|
||||
|
||||
nsShellInstanceFactory::nsShellInstanceFactory()
|
||||
{
|
||||
}
|
||||
|
||||
@ -43,18 +43,27 @@ public:
|
||||
|
||||
NS_IMETHOD Run();
|
||||
|
||||
NS_METHOD RegisterFactories();
|
||||
NS_IMETHOD RegisterFactories();
|
||||
|
||||
NS_METHOD_(void *) GetNativeInstance();
|
||||
NS_METHOD_(void) SetNativeInstance(void * aNativeInstance);
|
||||
NS_IMETHOD_(void *) GetNativeInstance();
|
||||
NS_IMETHOD_(void) SetNativeInstance(void * aNativeInstance);
|
||||
|
||||
NS_METHOD_(nsIApplicationShell *) GetApplicationShell();
|
||||
NS_METHOD_(void) SetApplicationShell(nsIApplicationShell * aApplicationShell);
|
||||
NS_IMETHOD_(nsIApplicationShell *) GetApplicationShell();
|
||||
NS_IMETHOD_(void) SetApplicationShell(nsIApplicationShell * aApplicationShell);
|
||||
|
||||
NS_IMETHOD_(nsIWidget *) CreateApplicationWindow(const nsRect &aRect,
|
||||
EVENT_CALLBACK aHandleEventFunction) ;
|
||||
|
||||
NS_IMETHOD ShowApplicationWindow(PRBool show) ;
|
||||
|
||||
NS_IMETHOD_(void *) GetApplicationWindowNativeInstance() ;
|
||||
|
||||
NS_IMETHOD ExitApplication() ;
|
||||
|
||||
private:
|
||||
nsNativeApplicationInstance mNativeInstance ;
|
||||
nsIApplicationShell * mApplicationShell ;
|
||||
nsIWidget * mApplicationWindow ;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -37,6 +37,7 @@
|
||||
#include "nsWidgetsCID.h"
|
||||
#include "nsGfxCIID.h"
|
||||
#include "nsApplicationManager.h"
|
||||
#include "nsString.h"
|
||||
|
||||
#include "nsAppTest.h"
|
||||
|
||||
@ -200,8 +201,11 @@ MyLoadImage(char *aFileName)
|
||||
nsIRenderingContext *drawCtx = gWindow->GetRenderingContext();
|
||||
if (NS_NewImageGroup(&gImageGroup) != NS_OK ||
|
||||
gImageGroup->Init(drawCtx) != NS_OK) {
|
||||
::MessageBox(NULL, "Couldn't create image group",
|
||||
class1Name, MB_OK);
|
||||
nsString aMessage("Couldn't create image group");
|
||||
|
||||
NSApplicationManager::ModalMessage(aMessage,
|
||||
class1Name,
|
||||
eModalMessage_ok);
|
||||
NS_RELEASE(drawCtx);
|
||||
return;
|
||||
}
|
||||
@ -223,8 +227,12 @@ MyLoadImage(char *aFileName)
|
||||
observer,
|
||||
white, 0, 0, 0);
|
||||
if (gImageReq == NULL) {
|
||||
::MessageBox(NULL, "Couldn't create image request",
|
||||
class1Name, MB_OK);
|
||||
|
||||
nsString aMessage("Couldn't create image request");
|
||||
|
||||
NSApplicationManager::ModalMessage(aMessage,
|
||||
class1Name,
|
||||
eModalMessage_ok);
|
||||
}
|
||||
}
|
||||
|
||||
@ -265,6 +273,46 @@ OpenFileDialog(char *aBuffer, int32 aBufLen)
|
||||
return (PRBool)result;
|
||||
}
|
||||
|
||||
nsEventStatus PR_CALLBACK
|
||||
HandleEventApplication(nsGUIEvent *aEvent)
|
||||
{
|
||||
nsEventStatus result = nsEventStatus_eConsumeNoDefault;
|
||||
switch(aEvent->message) {
|
||||
|
||||
case NS_CREATE:
|
||||
{
|
||||
// Initialize image library
|
||||
if (NS_NewImageManager(&gImageManager) != NS_OK ||
|
||||
gImageManager->Init() != NS_OK) {
|
||||
nsString aMessage("Can't initialize the image library");
|
||||
NSApplicationManager::ModalMessage(aMessage,
|
||||
class1Name,
|
||||
eModalMessage_ok);
|
||||
}
|
||||
|
||||
gImageManager->SetCacheSize(1024*1024);
|
||||
return nsEventStatus_eConsumeNoDefault;
|
||||
}
|
||||
break ;
|
||||
|
||||
case NS_DESTROY:
|
||||
{
|
||||
MyInterrupt();
|
||||
MyReleaseImages();
|
||||
if (gImageGroup != nsnull) {
|
||||
NS_RELEASE(gImageGroup);
|
||||
}
|
||||
if (gImageManager != nsnull) {
|
||||
NS_RELEASE(gImageManager);
|
||||
}
|
||||
shellInstance->ExitApplication() ;
|
||||
}
|
||||
break ;
|
||||
}
|
||||
|
||||
return nsEventStatus_eIgnore;
|
||||
}
|
||||
|
||||
long PASCAL
|
||||
WndProc(HWND hWnd, UINT msg, WPARAM param, LPARAM lparam)
|
||||
{
|
||||
@ -292,7 +340,7 @@ WndProc(HWND hWnd, UINT msg, WPARAM param, LPARAM lparam)
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
/*
|
||||
case WM_CREATE:
|
||||
// Initialize image library
|
||||
if (NS_NewImageManager(&gImageManager) != NS_OK ||
|
||||
@ -314,7 +362,7 @@ WndProc(HWND hWnd, UINT msg, WPARAM param, LPARAM lparam)
|
||||
}
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
|
||||
*/
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@ -365,6 +413,8 @@ nsresult RunAppTest(nsAppTest * aAppTest)
|
||||
|
||||
void InitAppTest(nsAppTest * aAppTest)
|
||||
{
|
||||
static NS_DEFINE_IID(kCChildWindowIID, NS_CHILD_CID);
|
||||
|
||||
nsresult res = NS_OK;
|
||||
|
||||
res = NSApplicationManager::GetShellInstance(aAppTest, &shellInstance) ;
|
||||
@ -372,6 +422,22 @@ void InitAppTest(nsAppTest * aAppTest)
|
||||
if (res == NS_OK)
|
||||
gInstance = (HINSTANCE) shellInstance->GetNativeInstance();
|
||||
|
||||
nsRect rect(100, 100, 600, 600);
|
||||
|
||||
shellInstance->CreateApplicationWindow(rect, HandleEventApplication);
|
||||
|
||||
gHwnd = shellInstance->GetApplicationWindowNativeInstance();
|
||||
|
||||
nsRect rect2(0, 0, 620, 400);
|
||||
|
||||
nsresult rv = NSRepository::CreateInstance(kCChildWindowIID, NULL, kIWidgetIID, (void**)&gWindow);
|
||||
|
||||
if (NS_OK == rv) {
|
||||
gWindow->Create((nsNativeWindow)gHwnd, rect2, MyHandleEvent, NULL);
|
||||
}
|
||||
|
||||
shellInstance->ShowApplicationWindow(PR_TRUE) ;
|
||||
/*
|
||||
// if (!prevInstance) {
|
||||
WNDCLASS wndClass;
|
||||
wndClass.style = 0;
|
||||
@ -389,6 +455,6 @@ void InitAppTest(nsAppTest * aAppTest)
|
||||
|
||||
// Create our first top level window
|
||||
HWND gHwnd = CreateTopLevel(class1Name, "Raptor HTML Viewer", 620, 400);
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user