From f8474ee65ece32cc8811ff05e7ce11919127bae3 Mon Sep 17 00:00:00 2001 From: "pierre%netscape.com" Date: Wed, 23 Sep 1998 09:23:07 +0000 Subject: [PATCH] handle menu events when there is no window --- webshell/tests/viewer/nsMacMain.cpp | 119 +++++++++++++++++----------- webshell/tests/viewer/nsViewerApp.h | 3 + widget/src/mac/nsMacMessagePump.h | 40 +++++----- 3 files changed, 96 insertions(+), 66 deletions(-) diff --git a/webshell/tests/viewer/nsMacMain.cpp b/webshell/tests/viewer/nsMacMain.cpp index cc41e6fc3685..28c6463a96fd 100644 --- a/webshell/tests/viewer/nsMacMain.cpp +++ b/webshell/tests/viewer/nsMacMain.cpp @@ -23,43 +23,15 @@ #include #include "resources.h" -#include // MacOS includes +#include // MacOS includes #include #include #include #include #include -#include // PP includes - - -static nsNativeViewerApp* gTheApp; - -nsNativeViewerApp::nsNativeViewerApp() -{ -} - -nsNativeViewerApp::~nsNativeViewerApp() -{ -} - -int -nsNativeViewerApp::Run() -{ - OpenWindow(); - mAppShell->Run(); - return 0; -} - -//---------------------------------------------------------------------- - -nsNativeBrowserWindow::nsNativeBrowserWindow() -{ -} - -nsNativeBrowserWindow::~nsNativeBrowserWindow() -{ -} +#include // for PP standard menu commands +#include "nsMacMessagePump.h" // for the windowless menu event handler enum { @@ -77,6 +49,76 @@ enum cmd_Find = 3000 }; + +static nsNativeViewerApp* gTheApp; + +nsNativeViewerApp::nsNativeViewerApp() +{ + nsMacMessagePump::SetWindowlessMenuEventHandler(DispatchMenuItemWithoutWindow); +} + +nsNativeViewerApp::~nsNativeViewerApp() +{ +} + +int +nsNativeViewerApp::Run() +{ + OpenWindow(); + mAppShell->Run(); + return 0; +} + +void nsNativeViewerApp::DispatchMenuItemWithoutWindow(PRInt32 menuResult) +{ + long menuID = HiWord(menuResult); + long menuItem = LoWord(menuResult); + switch (menuID) + { + case menu_Apple: + switch (menuItem) + { + case cmd_About: + ::Alert(128, nil); + break; + default: + Str255 daName; + GetMenuItemText(GetMenuHandle(menu_Apple), menuItem, daName); + OpenDeskAcc(daName); + break; + } + break; + + case menu_File: + + switch (menuItem) + { + case cmd_New: + gTheApp->OpenWindow(); + break; + case cmd_Open: + nsBrowserWindow * newWindow; + gTheApp->OpenWindow(0, newWindow); + newWindow->DoFileOpen(); + break; + case cmd_Quit: + gTheApp->Exit(); + break; + } + break; + } +} + +//---------------------------------------------------------------------- + +nsNativeBrowserWindow::nsNativeBrowserWindow() +{ +} + +nsNativeBrowserWindow::~nsNativeBrowserWindow() +{ +} + nsresult nsNativeBrowserWindow::CreateMenuBar(PRInt32 aWidth) { @@ -97,21 +139,6 @@ nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID) long menuID = HiWord(aID); long menuItem = LoWord(aID); - Int16** theMcmdH = (Int16**) ::GetResource('Mcmd', menuID); - if (theMcmdH != nil) - { - if (::GetHandleSize((Handle)theMcmdH) > 0) - { - Int16 numCommands = (*theMcmdH)[0]; - if (numCommands >= menuItem) - { - CommandT* theCommandNums = (CommandT*)(&(*theMcmdH)[1]); - menuItem = theCommandNums[menuItem-1]; - } - } - ::ReleaseResource((Handle) theMcmdH); - } - switch (menuID) { case menu_Apple: diff --git a/webshell/tests/viewer/nsViewerApp.h b/webshell/tests/viewer/nsViewerApp.h index f1803db134d0..6f20d866f8aa 100644 --- a/webshell/tests/viewer/nsViewerApp.h +++ b/webshell/tests/viewer/nsViewerApp.h @@ -96,6 +96,9 @@ public: ~nsNativeViewerApp(); virtual int Run(); +#ifdef XP_MAC + static void DispatchMenuItemWithoutWindow(PRInt32 menuResult); +#endif }; #endif /* nsViewerApp_h___ */ diff --git a/widget/src/mac/nsMacMessagePump.h b/widget/src/mac/nsMacMessagePump.h index f47b22004675..f91fec3dda98 100644 --- a/widget/src/mac/nsMacMessagePump.h +++ b/widget/src/mac/nsMacMessagePump.h @@ -19,16 +19,9 @@ #ifndef nsMacMessagePump_h__ #define nsMacMessagePump_h__ -#include "nsToolKit.h" -#include "nsWindow.h" -#include -#include -#include -#include -#include -#include - - +#include "prtypes.h" +class nsToolkit; +class nsWindow; //================================================ @@ -54,17 +47,24 @@ class nsMacMessagePump virtual ~nsMacMessagePump(); PRBool DoMessagePump(); - void DoMouseDown(EventRecord *aTheEvent); - void DoMouseUp(EventRecord *aTheEvent); - void DoMouseMove(EventRecord *aTheEvent); - void DoPaintEvent(EventRecord *aTheEvent); - void DoKey(EventRecord *aTheEvent); - void DoMenu(EventRecord *aTheEvent, long menuItem); - void DoIdleWidgets(); - void SetCurrentWindow(nsWindow *aTheWin) { gCurrentWindow = aTheWin;} - void StopRunning() {mRunning = PR_FALSE;} - nsWindow* GetCurrentWindow(void) {return(gCurrentWindow);} + void StopRunning() {mRunning = PR_FALSE;} + void DoMouseDown(EventRecord *aTheEvent); + void DoMouseUp(EventRecord *aTheEvent); + void DoMouseMove(EventRecord *aTheEvent); + void DoPaintEvent(EventRecord *aTheEvent); + void DoKey(EventRecord *aTheEvent); + void DoMenu(EventRecord *aTheEvent, long menuResult); + void DoIdleWidgets(); + + + void SetCurrentWindow(nsWindow *aTheWin) { gCurrentWindow = aTheWin;} + nsWindow* GetCurrentWindow(void) {return(gCurrentWindow);} + + typedef void (*nsWindowlessMenuEventHandler) (PRInt32 menuResult); + static nsWindowlessMenuEventHandler gWindowlessMenuEventHandler; + static void SetWindowlessMenuEventHandler(nsWindowlessMenuEventHandler func) + {gWindowlessMenuEventHandler = func;} };