1998-07-24 17:19:44 +00:00
|
|
|
/* -*- 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 "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.
|
|
|
|
*/
|
1998-09-12 00:06:05 +00:00
|
|
|
|
1998-07-24 17:19:44 +00:00
|
|
|
#include "nsViewerApp.h"
|
|
|
|
#include "nsBrowserWindow.h"
|
|
|
|
#include "nsIImageManager.h"
|
1998-09-22 04:21:31 +00:00
|
|
|
#include "nsIWidget.h"
|
1998-07-24 17:19:44 +00:00
|
|
|
#include <stdlib.h>
|
1998-09-22 04:21:31 +00:00
|
|
|
#include "resources.h"
|
|
|
|
|
1998-09-23 09:23:07 +00:00
|
|
|
#include <ToolUtils.h> // MacOS includes
|
1998-09-22 04:21:31 +00:00
|
|
|
#include <Menus.h>
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <Devices.h>
|
|
|
|
#include <Resources.h>
|
|
|
|
#include <Dialogs.h>
|
|
|
|
|
1998-09-23 09:23:07 +00:00
|
|
|
#include <PP_Messages.h> // for PP standard menu commands
|
|
|
|
#include "nsMacMessagePump.h" // for the windowless menu event handler
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
menu_First = 128,
|
|
|
|
menu_Apple = menu_First,
|
|
|
|
menu_File,
|
|
|
|
menu_Edit,
|
|
|
|
menu_Sample,
|
1998-12-08 02:16:42 +00:00
|
|
|
menu_Debug,
|
|
|
|
menu_Tools,
|
|
|
|
menu_Last = menu_Tools,
|
1998-09-23 09:23:07 +00:00
|
|
|
|
|
|
|
submenu_Print = 16,
|
|
|
|
|
|
|
|
cmd_Sample0 = 1000,
|
|
|
|
cmd_PrintOneColumn = 2000,
|
1998-12-08 02:16:42 +00:00
|
|
|
cmd_Find = 3000,
|
|
|
|
|
|
|
|
cmd_DebugMode = 4000,
|
|
|
|
cmd_DebugRobot,
|
|
|
|
cmd_JSConsole,
|
|
|
|
cmd_EditorMode,
|
|
|
|
cmd_Top100
|
1998-09-23 09:23:07 +00:00
|
|
|
};
|
1998-07-24 17:19:44 +00:00
|
|
|
|
1998-09-12 00:06:05 +00:00
|
|
|
|
1998-07-24 17:19:44 +00:00
|
|
|
static nsNativeViewerApp* gTheApp;
|
|
|
|
|
1998-10-29 14:06:26 +00:00
|
|
|
|
|
|
|
static long ConvertOSMenuResultToPPMenuResult(long menuResult);
|
|
|
|
static long ConvertOSMenuResultToPPMenuResult(long menuResult)
|
|
|
|
{
|
|
|
|
// Convert MacOS menu item to PowerPlant menu item because
|
|
|
|
// in our sample app, we use Constructor for resource editing
|
|
|
|
long menuID = HiWord(menuResult);
|
|
|
|
long menuItem = LoWord(menuResult);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
menuResult = (menuID << 16) + menuItem;
|
|
|
|
return (menuResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
1998-07-24 17:19:44 +00:00
|
|
|
nsNativeViewerApp::nsNativeViewerApp()
|
|
|
|
{
|
1998-09-23 09:23:07 +00:00
|
|
|
nsMacMessagePump::SetWindowlessMenuEventHandler(DispatchMenuItemWithoutWindow);
|
1998-07-24 17:19:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsNativeViewerApp::~nsNativeViewerApp()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
nsNativeViewerApp::Run()
|
|
|
|
{
|
|
|
|
OpenWindow();
|
|
|
|
mAppShell->Run();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1998-09-23 09:23:07 +00:00
|
|
|
void nsNativeViewerApp::DispatchMenuItemWithoutWindow(PRInt32 menuResult)
|
|
|
|
{
|
1998-10-29 14:06:26 +00:00
|
|
|
menuResult = ConvertOSMenuResultToPPMenuResult(menuResult);
|
|
|
|
|
1998-09-23 09:23:07 +00:00
|
|
|
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;
|
1998-12-03 17:59:13 +00:00
|
|
|
}
|
1998-09-23 09:23:07 +00:00
|
|
|
}
|
|
|
|
|
1998-10-29 14:06:26 +00:00
|
|
|
#pragma mark -
|
1998-07-24 17:19:44 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsNativeBrowserWindow::nsNativeBrowserWindow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsNativeBrowserWindow::~nsNativeBrowserWindow()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsNativeBrowserWindow::CreateMenuBar(PRInt32 aWidth)
|
|
|
|
{
|
1998-09-22 04:21:31 +00:00
|
|
|
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;
|
1998-07-24 17:19:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nsEventStatus
|
|
|
|
nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID)
|
|
|
|
{
|
1998-10-29 14:06:26 +00:00
|
|
|
aID = ConvertOSMenuResultToPPMenuResult(aID);
|
|
|
|
|
1998-09-22 04:21:31 +00:00
|
|
|
PRInt32 xpID = 0;
|
|
|
|
long menuID = HiWord(aID);
|
|
|
|
long menuItem = LoWord(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();
|
1998-10-29 14:06:26 +00:00
|
|
|
nsIWidget* raptorWindow = *(nsIWidget**)::GetWRefCon(whichwindow);
|
1998-09-22 04:21:31 +00:00
|
|
|
raptorWindow->Destroy();
|
|
|
|
break;
|
1998-12-03 17:59:13 +00:00
|
|
|
case 2000: xpID = VIEW_SOURCE; break;
|
|
|
|
case 2001: xpID = VIEWER_TREEVIEW; break;
|
1998-09-22 04:21:31 +00:00
|
|
|
case cmd_Save: /*n.a.*/ break;
|
|
|
|
case cmd_SaveAs: /*n.a.*/ break;
|
|
|
|
case cmd_Revert: /*n.a.*/ break;
|
|
|
|
case cmd_PageSetup: /*n.a.*/ break;
|
1998-12-04 15:08:18 +00:00
|
|
|
case cmd_Print: xpID = VIEWER_PRINT; break;
|
1998-09-22 04:21:31 +00:00
|
|
|
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;
|
1998-12-08 02:16:42 +00:00
|
|
|
case cmd_Preferences: xpID = VIEWER_PREFS; break;
|
1998-09-22 04:21:31 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case menu_Sample:
|
|
|
|
xpID = VIEWER_DEMO0 + menuItem - cmd_Sample0;
|
|
|
|
break;
|
|
|
|
|
1998-12-08 02:16:42 +00:00
|
|
|
case menu_Debug:
|
|
|
|
switch (menuItem)
|
|
|
|
{
|
|
|
|
case cmd_DebugMode: xpID = VIEWER_VISUAL_DEBUGGING; break;
|
|
|
|
case cmd_DebugRobot: xpID = VIEWER_DEBUGROBOT; break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case menu_Tools:
|
|
|
|
switch (menuItem)
|
|
|
|
{
|
|
|
|
case cmd_JSConsole: xpID = JS_CONSOLE; break;
|
|
|
|
case cmd_EditorMode: xpID = EDITOR_MODE; break;
|
|
|
|
case cmd_Top100: xpID = VIEWER_TOP100; break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1998-09-22 04:21:31 +00:00
|
|
|
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;
|
1998-07-24 17:19:44 +00:00
|
|
|
}
|
|
|
|
|
1998-10-29 14:06:26 +00:00
|
|
|
#pragma mark -
|
1998-07-24 17:19:44 +00:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
|
|
|
|
// Hack to get il_ss set so it doesn't fail in xpcompat.c
|
|
|
|
nsIImageManager *manager;
|
|
|
|
NS_NewImageManager(&manager);
|
|
|
|
|
|
|
|
gTheApp = new nsNativeViewerApp();
|
1998-10-09 17:13:21 +00:00
|
|
|
NS_ADDREF(gTheApp);
|
1998-07-24 17:19:44 +00:00
|
|
|
gTheApp->Initialize(argc, argv);
|
|
|
|
gTheApp->Run();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|