implemented menu events

This commit is contained in:
pierre%netscape.com 1998-09-22 04:21:31 +00:00
parent a5908b59da
commit 254d8d510d
2 changed files with 154 additions and 115 deletions

View File

@ -15,12 +15,22 @@
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include <Menus.h>
#include "nsViewerApp.h"
#include "nsBrowserWindow.h"
#include "nsIImageManager.h"
#include "nsIWidget.h"
#include <stdlib.h>
#include "resources.h"
#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;
@ -51,43 +61,119 @@ nsNativeBrowserWindow::~nsNativeBrowserWindow()
{
}
/*static void MenuProc(PRUint32 aId)
enum
{
// XXX our menus are horked: we can't support multiple windows!
nsBrowserWindow* bw = (nsBrowserWindow*)
nsBrowserWindow::gBrowsers.ElementAt(0);
bw->DispatchMenuItem(aId);
}*/ // XXX Nothing was calling this function
menu_First = 128,
menu_Apple = menu_First,
menu_File,
menu_Edit,
menu_Sample,
menu_Last = menu_Sample,
// why is width passed to this function? XXX Platform specific?
submenu_Print = 16,
cmd_Sample0 = 1000,
cmd_PrintOneColumn = 2000,
cmd_Find = 3000
};
nsresult
nsNativeBrowserWindow::CreateMenuBar(PRInt32 aWidth)
{
MenuHandle theMenu;
//CreateViewerMenus(XtParent((Widget)mWindow->GetNativeData(NS_NATIVE_WIDGET)), MenuProc);
int i;
for (i = 2000; i <= 2004; ++i)
{
theMenu = GetMenu (i);
if (i < 2003)
InsertMenu (theMenu, 0);
else
InsertMenu (theMenu, -1);
}
AppendResMenu (GetMenuHandle (2000), 'DRVR');
DrawMenuBar();
return NS_OK;
for (int i = menu_First; i <= menu_Last; i++)
{
InsertMenu(GetMenu(i), 0);
}
InsertMenu(GetMenu(submenu_Print), -1);
AppendResMenu(GetMenuHandle(menu_Apple), 'DRVR');
DrawMenuBar();
return NS_OK;
}
nsEventStatus
nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID)
{
// Dispatch motif-only menu code goes here
PRInt32 xpID = 0;
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);
}
// Dispatch xp menu items
return nsBrowserWindow::DispatchMenuItem(aID);
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: xpID = VIEWER_WINDOW_OPEN; break;
case cmd_Open: xpID = VIEWER_FILE_OPEN; break;
case cmd_Close:
WindowPtr whichwindow = FrontWindow();
nsIWidget* raptorWindow = (nsIWidget*)GetWRefCon(whichwindow);
raptorWindow->Destroy();
break;
case cmd_Save: /*n.a.*/ break;
case cmd_SaveAs: /*n.a.*/ break;
case cmd_Revert: /*n.a.*/ break;
case cmd_PageSetup: /*n.a.*/ break;
case cmd_Print: /*n.a.*/ break;
case cmd_Quit: xpID = VIEWER_EXIT; break;
}
break;
case menu_Edit:
switch (menuItem)
{
case cmd_Undo: /*n.a.*/ break;
case cmd_Cut: xpID = VIEWER_EDIT_CUT; break;
case cmd_Copy: xpID = VIEWER_EDIT_COPY; break;
case cmd_Paste: xpID = VIEWER_EDIT_PASTE; break;
case cmd_Clear: /*n.a.*/ break;
case cmd_SelectAll: xpID = VIEWER_EDIT_SELECTALL; break;
case cmd_Find: xpID = VIEWER_EDIT_FINDINPAGE; break;
}
break;
case menu_Sample:
xpID = VIEWER_DEMO0 + menuItem - cmd_Sample0;
break;
case submenu_Print:
xpID = VIEWER_ONE_COLUMN + menuItem - cmd_PrintOneColumn;
break;
}
// Dispatch xp menu items
if (xpID != 0)
return nsBrowserWindow::DispatchMenuItem(xpID);
else
return nsEventStatus_eIgnore;
}
//----------------------------------------------------------------------

View File

@ -41,10 +41,8 @@ static NS_DEFINE_IID(kITEXTWIDGETIID, NS_TEXTFIELD_CID);
*/
nsMacMessagePump::nsMacMessagePump(nsToolkit *aToolkit)
{
mRunning = PR_FALSE;
mToolkit = aToolkit;
}
//=================================================================
@ -67,7 +65,6 @@ nsMacMessagePump::~nsMacMessagePump()
PRBool
nsMacMessagePump::DoMessagePump()
{
PRBool stillrunning = PR_TRUE;
EventRecord theevent;
long sleep=0;
PRInt16 haveevent;
@ -86,7 +83,7 @@ unsigned char evtype;
SetRectRgn(currgn,-32000,-32000,-32000,-32000);
while(mRunning && stillrunning)
while(mRunning)
{
haveevent = ::WaitNextEvent(everyEvent,&theevent,sleep,0l);
@ -253,68 +250,6 @@ nsWindow *thewindow;
}
//==============================================================
// XXXX Quick and Extra Ugly hack: These #defines copied from resources.h in the viewer
// project. This makes the the widget project tied to the viewer project. This is bad. This
// is ugly. This should be fixed soon.
#define VIEWER_OPEN 40000
#define VIEWER_EXIT 40002
#define PREVIEW_CLOSE 40003
#define VIEWER_WINDOW_OPEN 40009
#define VIEWER_FILE_OPEN 40010
// Note: must be in ascending sequential order
#define VIEWER_DEMO0 40011
#define VIEWER_VISUAL_DEBUGGING 40021
// Note: must be in ascending sequential order
#define VIEWER_ONE_COLUMN 40040
#define JS_CONSOLE 40100
#define EDITOR_MODE 40120
#define VIEWER_EDIT_CUT 40201
#define FILE_MENU 2000
#define EDIT_MENU 2001
#define DEBU_MENU 2002
#define DEMO_MENU 128
#define PRIN_MENU 129
static PRUint32 translateMenu (long aMenuResult)
{
PRUint32 result = 0;
long menuid = HiWord(aMenuResult);
long menuItem = LoWord(aMenuResult);
switch (menuid)
{
case FILE_MENU:
switch (menuItem)
{
//case XXX: result = XXXX; break;
}
break;
case EDIT_MENU:
result = VIEWER_EDIT_CUT + menuItem;
break;
case DEBU_MENU:
result = VIEWER_VISUAL_DEBUGGING + menuItem;
break;
case DEMO_MENU:
result = VIEWER_DEMO0 - 1 + menuItem;
break;
case PRIN_MENU:
result = VIEWER_ONE_COLUMN + menuItem;
break;
}
return result;
}
//=================================================================
/* Turns a mousedown event into a raptor mousedown event
* @update dc 08/31/98
@ -338,27 +273,9 @@ nsMouseEvent mouseevent;
if (inMenuBar == partcode)
{
nsMenuEvent theEvent;
nsWindow *raptorWindow;
long menuItem = MenuSelect(aTheEvent->where);
HiliteMenu(0);
#if 1
whichwindow = FrontWindow();
raptorWindow = (nsWindow *) GetWRefCon (whichwindow);
#else
// XXX For some reason this returns null... which is bad...
raptorWindow = mToolkit->GetFocus();
#endif
theEvent.eventStructType = NS_MENU_EVENT;
theEvent.message = NS_MENU_SELECTED;
theEvent.menuItem = translateMenu (menuItem);
theEvent.widget = raptorWindow;
theEvent.nativeMsg = aTheEvent;
raptorWindow->DispatchEvent(&theEvent);
long menuResult = MenuSelect(aTheEvent->where);
if (HiWord(menuResult) != 0)
DoMenu(aTheEvent, menuResult);
return;
}
@ -479,7 +396,7 @@ nsMouseEvent mouseevent;
if(thewindow)
{
thewindow->Destroy();
mRunning = PR_FALSE;
//mRunning = PR_FALSE;
}
else
{
@ -732,6 +649,9 @@ nsTextWidget *widget;
if(aTheEvent->modifiers&cmdKey)
{
// do a menu key command
long menuResult = MenuKey(ch);
if (HiWord(menuResult) != 0)
DoMenu(aTheEvent, menuResult);
}
else
{
@ -767,4 +687,37 @@ nsTextWidget *widget;
}
}
//==============================================================
//=================================================================
/* Turns a menu event into a raptor menu event
* @update ps 09/21/98
* @param aTheEvent -- A pointer to a Macintosh EventRecord
* @return NONE
*/
void
nsMacMessagePump::DoMenu(EventRecord *aTheEvent, long menuItem)
{
WindowPtr whichwindow;
nsMenuEvent theEvent;
nsWindow* raptorWindow = nsnull;
#if 1
whichwindow = FrontWindow();
if (whichwindow)
raptorWindow = (nsWindow *) GetWRefCon (whichwindow);
#else
// XXX For some reason this returns null... which is bad...
raptorWindow = mToolkit->GetFocus();
#endif
if (raptorWindow)
{
theEvent.eventStructType = NS_MENU_EVENT;
theEvent.message = NS_MENU_SELECTED;
theEvent.menuItem = menuItem;
theEvent.widget = raptorWindow;
theEvent.nativeMsg = aTheEvent;
raptorWindow->DispatchEvent(&theEvent);
}
HiliteMenu(0);
}