mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-03 20:49:27 +00:00
handle menu events when there is no window
This commit is contained in:
parent
d62fe33fb5
commit
f8474ee65e
@ -23,43 +23,15 @@
|
||||
#include <stdlib.h>
|
||||
#include "resources.h"
|
||||
|
||||
#include <ToolUtils.h> // MacOS includes
|
||||
#include <ToolUtils.h> // MacOS includes
|
||||
#include <Menus.h>
|
||||
#include <Windows.h>
|
||||
#include <Devices.h>
|
||||
#include <Resources.h>
|
||||
#include <Dialogs.h>
|
||||
|
||||
#include <PP_Messages.h> // PP includes
|
||||
|
||||
|
||||
static nsNativeViewerApp* gTheApp;
|
||||
|
||||
nsNativeViewerApp::nsNativeViewerApp()
|
||||
{
|
||||
}
|
||||
|
||||
nsNativeViewerApp::~nsNativeViewerApp()
|
||||
{
|
||||
}
|
||||
|
||||
int
|
||||
nsNativeViewerApp::Run()
|
||||
{
|
||||
OpenWindow();
|
||||
mAppShell->Run();
|
||||
return 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
nsNativeBrowserWindow::nsNativeBrowserWindow()
|
||||
{
|
||||
}
|
||||
|
||||
nsNativeBrowserWindow::~nsNativeBrowserWindow()
|
||||
{
|
||||
}
|
||||
#include <PP_Messages.h> // 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:
|
||||
|
@ -96,6 +96,9 @@ public:
|
||||
~nsNativeViewerApp();
|
||||
|
||||
virtual int Run();
|
||||
#ifdef XP_MAC
|
||||
static void DispatchMenuItemWithoutWindow(PRInt32 menuResult);
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif /* nsViewerApp_h___ */
|
||||
|
@ -19,16 +19,9 @@
|
||||
#ifndef nsMacMessagePump_h__
|
||||
#define nsMacMessagePump_h__
|
||||
|
||||
#include "nsToolKit.h"
|
||||
#include "nsWindow.h"
|
||||
#include <Fonts.h>
|
||||
#include <TextEdit.h>
|
||||
#include <Dialogs.h>
|
||||
#include <Traps.h>
|
||||
#include <Events.h>
|
||||
#include <Menus.h>
|
||||
|
||||
|
||||
#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;}
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user