added motif menus to the viewer

This commit is contained in:
rods 1998-06-10 22:41:43 +00:00
parent d101f134c6
commit e09efc1dca
6 changed files with 391 additions and 125 deletions

View File

@ -104,17 +104,20 @@ $(OBJDIR)/nsDocLoader.o:: nsDocLoader.cpp
$(OBJDIR)/nsViewer.o:: nsViewer.cpp
$(CCC) -o $@ -c $(CFLAGS) nsViewer.cpp $(LDFLAGS)
$(OBJDIR)/nsMotifMenu.o:: nsMotifMenu.cpp
$(CCC) -o $@ -c $(CFLAGS) nsMotifMenu.cpp $(LDFLAGS)
$(OBJDIR)/%.o: %.cpp
@$(MAKE_OBJDIR)
$(CCC) -o $@ $(CFLAGS) -c $*.cpp
$(PROGS):$(OBJDIR)/%: $(OBJDIR)/%.o $(OBJDIR)/nsDocLoader.o $(OBJDIR)/nsViewer.o $(EX_LIBS)
$(PROGS):$(OBJDIR)/%: $(OBJDIR)/%.o $(OBJDIR)/nsDocLoader.o $(OBJDIR)/nsViewer.o $(OBJDIR)/nsMotifMenu.o $(EX_LIBS)
@$(MAKE_OBJDIR)
ifeq ($(OS_ARCH),Linux)
$(CCC) -rdynamic -o $@ $@.o $(OBJDIR)/nsDocLoader.o $(OBJDIR)/nsViewer.o $(LDFLAGS) $(EX_LIBS) $(OS_LIBS) -L/usr/X11R6/lib -lXm -lXt -lX11 -lXp -lXext
$(CCC) -rdynamic -o $@ $@.o $(OBJDIR)/nsDocLoader.o $(OBJDIR)/nsViewer.o $(OBJDIR)/nsMotifMenu.o $(LDFLAGS) $(EX_LIBS) $(OS_LIBS) -L/usr/X11R6/lib -lXm -lXt -lX11 -lXp -lXext
else
$(CCC) -o $@ $@.o -woff 84,85 $(LDFLAGS) $(OBJDIR)/nsDocLoader.o $(OBJDIR)/nsViewer.o $(EX_LIBS) $(OS_LIBS) -lXm -lXt -lX11
$(CCC) -o $@ $@.o -woff 84,85 $(LDFLAGS) $(OBJDIR)/nsDocLoader.o $(OBJDIR)/nsViewer.o $(OBJDIR)/nsMotifMenu.o $(EX_LIBS) $(OS_LIBS) -lXm -lXt -lX11
endif
export::

View File

@ -17,8 +17,13 @@
*/
#include "nsViewer.h"
#include "nsMotifMenu.h"
class nsMotifViewer : public nsViewer {
virtual void AddMenu(nsIWidget* aMainWindow);
};
//--------------------------------------------------------
nsresult ExecuteViewer(nsViewer* aViewer, int argc, char **argv)
{
nsIWidget *mainWindow = nsnull;
@ -29,11 +34,28 @@ nsresult ExecuteViewer(nsViewer* aViewer, int argc, char **argv)
return result;
}
//--------------------------------------------------------
nsMotifViewer * gViewer = nsnull;
//--------------------------------------------------------
void main(int argc, char **argv)
{
nsViewer* viewer = new nsViewer();
SetViewer(viewer);
viewer->ProcessArguments(argc, argv);
ExecuteViewer(viewer, argc, argv);
gViewer = new nsMotifViewer();
SetViewer(gViewer);
gViewer->ProcessArguments(argc, argv);
ExecuteViewer(gViewer, argc, argv);
}
//--------------------------------------------------------
void MenuProc(PRUint32 aId)
{
gViewer->DispatchMenuItem(aId);
}
//--------------------------------------------------------
void nsMotifViewer::AddMenu(nsIWidget* aMainWindow)
{
CreateViewerMenus(XtParent(aMainWindow->GetNativeData(NS_NATIVE_WIDGET)), MenuProc);
}

View File

@ -0,0 +1,194 @@
/* -*- 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.
*/
#include <Xm/CascadeBG.h>
#include <Xm/PushBG.h>
#include <Xm/SeparatoG.h>
#include "resources.h"
#include "nsMotifMenu.h"
//==============================================================
typedef struct _callBackInfo {
MenuCallbackProc mCallback;
PRUint32 mId;
} MenuCallbackStruct;
//==============================================================
void nsXtWidget_Menu_Callback(Widget w, XtPointer p, XtPointer call_data)
{
fprintf(stderr, "Menu Selected 0x%x 0x%x\n", p, call_data);
MenuCallbackStruct * cbs = (MenuCallbackStruct *)p;
if (cbs != NULL) {
MenuCallbackProc cb = (MenuCallbackProc)call_data;
if (cbs->mCallback != NULL) {
(*cbs->mCallback)(cbs->mId);
}
}
}
//-----------------------------------------------------
Widget CreatePulldownMenu(Widget aParent,
char * aMenuTitle,
char * aMenuMnemonic)
{
Widget pullDown;
Widget casBtn;
XmString str;
pullDown = XmCreatePulldownMenu(aParent, "_pulldown", NULL, 0);
str = XmStringCreateLocalized(aMenuTitle);
casBtn = XtVaCreateManagedWidget(aMenuTitle,
xmCascadeButtonGadgetClass, aParent,
XmNsubMenuId, pullDown,
XmNlabelString, str,
XmNmnemonic, aMenuMnemonic,
NULL);
XmStringFree(str);
return pullDown;
}
//-----------------------------------------------------
Widget CreateMenuItem(Widget aParent,
char * aTitle,
long aID,
MenuCallbackProc aCallback)
{
Widget widget = XtVaCreateManagedWidget(aTitle, xmPushButtonGadgetClass,
aParent,
NULL);
MenuCallbackStruct * cbs = new MenuCallbackStruct();
cbs->mCallback = aCallback;
cbs->mId = aID;
XtAddCallback(widget, XmNactivateCallback, nsXtWidget_Menu_Callback, cbs);
return widget;
}
//-----------------------------------------------------
Widget CreateSeparator(Widget aParent)
{
Widget widget = XtVaCreateManagedWidget("__sep", xmSeparatorGadgetClass,
aParent,
NULL);
}
typedef struct _menuBtns {
char * title;
char * mneu;
long command;
} MenuBtns;
//-----------------------------------------------------
void AddMenuItems(Widget aParent,
MenuBtns * aBtns,
MenuCallbackProc aCallback)
{
int i = 0;
while (aBtns[i].title != NULL) {
if (!strcmp(aBtns[i].title, "separator")) {
CreateSeparator(aParent);
} else {
CreateMenuItem(aParent, aBtns[i].title, aBtns[i].command, aCallback);
}
i++;
}
}
//-----------------------------------------------------
void CreateViewerMenus(Widget aParent, MenuCallbackProc aCallback)
{
MenuBtns editBtns[] = {
{"Cut", "T", VIEWER_EDIT_CUT},
{"Copy", "C", VIEWER_EDIT_COPY},
{"Paste", "P", VIEWER_EDIT_PASTE},
{"separator", NULL, 0},
{"Select All", "A", VIEWER_EDIT_SELECTALL},
{"separator", NULL, 0},
{"Find in Page", "F", VIEWER_EDIT_FINDINPAGE},
{NULL, NULL, 0}
};
MenuBtns debugBtns[] = {
{"Visual Debugging", "V", VIEWER_VISUAL_DEBUGGING},
{"Reflow Test", "R", VIEWER_REFLOW_TEST},
{"separator", NULL, 0},
{"Dump Content", "C", VIEWER_DUMP_CONTENT},
{"Dump Frames", "F", VIEWER_DUMP_FRAMES},
{"Dump Views", "V", VIEWER_DUMP_VIEWS},
{"separator", NULL, 0},
{"Dump Style Sheets", "S", VIEWER_DUMP_STYLE_SHEETS},
{"Dump Style Contexts", "T", VIEWER_DUMP_STYLE_CONTEXTS},
{"separator", NULL, 0},
{"Show Content Size", "z", VIEWER_SHOW_CONTENT_SIZE},
{"Show Frame Size", "a", VIEWER_SHOW_FRAME_SIZE},
{"Show Style Size", "y", VIEWER_SHOW_STYLE_SIZE},
{"separator", NULL, 0},
{"Debug Robot", "R", VIEWER_DEBUGROBOT},
{NULL, NULL, 0}
};
Widget menuBar;
Widget fileMenu;
Widget debugMenu;
Widget menu;
menuBar = XmCreateMenuBar(aParent, "menubar", NULL, 0);
fileMenu = CreatePulldownMenu(menuBar, "File", "F");
CreateMenuItem(fileMenu, "Open...", VIEWER_OPEN, aCallback);
menu = CreatePulldownMenu(fileMenu, "Samples", "S");
CreateMenuItem(menu, "demo #0", VIEWER_DEMO0, aCallback);
CreateMenuItem(menu, "demo #1", VIEWER_DEMO1, aCallback);
CreateMenuItem(menu, "demo #2", VIEWER_DEMO2, aCallback);
CreateMenuItem(menu, "demo #3", VIEWER_DEMO3, aCallback);
CreateMenuItem(menu, "demo #4", VIEWER_DEMO4, aCallback);
CreateMenuItem(menu, "demo #5", VIEWER_DEMO5, aCallback);
CreateMenuItem(menu, "demo #6", VIEWER_DEMO6, aCallback);
CreateMenuItem(menu, "demo #7", VIEWER_DEMO7, aCallback);
CreateMenuItem(menu, "demo #8", VIEWER_DEMO8, aCallback);
menu = CreatePulldownMenu(fileMenu, "Print Preview", "P");
CreateMenuItem(menu, "One Column", VIEWER_ONE_COLUMN, aCallback);
CreateMenuItem(menu, "Two Column", VIEWER_TWO_COLUMN, aCallback);
CreateMenuItem(menu, "Three Column", VIEWER_THREE_COLUMN, aCallback);
CreateMenuItem(fileMenu, "Exit", VIEWER_EXIT, aCallback);
menu = CreatePulldownMenu(menuBar, "Edit", "E");
AddMenuItems(menu, editBtns, aCallback);
debugMenu = CreatePulldownMenu(menuBar, "Debug", "D");
AddMenuItems(debugMenu, debugBtns, aCallback);
menu = CreatePulldownMenu(menuBar, "Tools", "T");
CreateMenuItem(menu, "Java Script Console", JS_CONSOLE, aCallback);
XtManageChild(menuBar);
}

View File

@ -0,0 +1,33 @@
/* -*- 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.
*/
#ifndef _nsMotifMenu_h_
#define _nsMotifMenu_h_
#include <Xm/Xm.h>
#include "nscore.h"
typedef void (*MenuCallbackProc)(
PRUint32
);
void CreateViewerMenus(Widget aParent, MenuCallbackProc aCallback);
#endif // _nsMotifMenu_h_

View File

@ -84,6 +84,7 @@ static NS_DEFINE_IID(kCScrollingViewCID, NS_SCROLLING_VIEW_CID);
#define START_URL SAMPLES_BASE_URL "/test0.html"
nsViewer* gTheViewer = nsnull;
WindowData * gMainWindowData = nsnull;
nsIAppShell *gAppShell= nsnull;
static char* startURL;
static nsVoidArray* gWindows;
@ -890,126 +891,135 @@ void nsViewer::ExitViewer()
nsEventStatus nsViewer::DispatchMenuItem(nsGUIEvent *aEvent)
{
nsEventStatus result = nsEventStatus_eIgnore;
if (aEvent->message == NS_MENU_SELECTED) {
nsMenuEvent* menuEvent = (nsMenuEvent*)aEvent;
WindowData* wd = FindWindowData(aEvent->widget);
return ProcessMenu(menuEvent->menuItem, wd);
}
return result;
}
nsEventStatus nsViewer::DispatchMenuItem(PRUint32 aId)
{
return ProcessMenu(aId, gMainWindowData);
}
nsEventStatus nsViewer::ProcessMenu(PRUint32 aId, WindowData* wd)
{
nsEventStatus result = nsEventStatus_eIgnore;
switch(aId) {
case VIEWER_EXIT:
ExitViewer();
return nsEventStatus_eConsumeNoDefault;
case PREVIEW_CLOSE:
wd->windowWidget->Destroy();
return nsEventStatus_eConsumeNoDefault;
case VIEWER_FILE_OPEN:
OpenHTMLFile(wd);
break;
case VIEWER_EDIT_CUT:
break;
case VIEWER_EDIT_COPY:
CopySelection(wd);
break;
case VIEWER_EDIT_PASTE:
break;
case VIEWER_EDIT_SELECTALL:
SelectAll(wd);
break;
case VIEWER_EDIT_FINDINPAGE:
break;
switch(aEvent->message) {
case NS_MENU_SELECTED:
nsMenuEvent* menuEvent = (nsMenuEvent*)aEvent;
WindowData* wd = FindWindowData(aEvent->widget);
switch(menuEvent->menuItem) {
case VIEWER_EXIT:
ExitViewer();
return nsEventStatus_eConsumeNoDefault;
case PREVIEW_CLOSE:
aEvent->widget->Destroy();
return nsEventStatus_eConsumeNoDefault;
case VIEWER_FILE_OPEN:
OpenHTMLFile(wd);
break;
case VIEWER_EDIT_CUT:
break;
case VIEWER_EDIT_COPY:
CopySelection(wd);
break;
case VIEWER_EDIT_PASTE:
break;
case VIEWER_EDIT_SELECTALL:
SelectAll(wd);
break;
case VIEWER_EDIT_FINDINPAGE:
break;
case VIEWER_DEMO0:
case VIEWER_DEMO1:
case VIEWER_DEMO2:
case VIEWER_DEMO3:
case VIEWER_DEMO4:
case VIEWER_DEMO5:
case VIEWER_DEMO6:
case VIEWER_DEMO7:
case VIEWER_DEMO8:
if ((nsnull != wd) && (nsnull != wd->ww)) {
PRIntn ix = menuEvent->menuItem - VIEWER_DEMO0;
char* url = new char[500];
PR_snprintf(url, 500, "%s/test%d.html", SAMPLES_BASE_URL, ix);
wd->observer->LoadURL(url);
delete url;
}
break;
case VIEWER_VISUAL_DEBUGGING:
if ((nsnull != wd) && (nsnull != wd->ww)) {
wd->ww->ShowFrameBorders(PRBool(!wd->ww->GetShowFrameBorders()));
}
break;
case VIEWER_DUMP_CONTENT:
if ((nsnull != wd) && (nsnull != wd->ww)) {
wd->ww->DumpContent();
}
break;
case VIEWER_DUMP_FRAMES:
if ((nsnull != wd) && (nsnull != wd->ww)) {
wd->ww->DumpFrames();
}
break;
case VIEWER_DUMP_VIEWS:
if ((nsnull != wd) && (nsnull != wd->ww)) {
wd->ww->DumpViews();
}
break;
case VIEWER_DUMP_STYLE_SHEETS:
if ((nsnull != wd) && (nsnull != wd->ww)) {
wd->ww->DumpStyleSheets();
}
break;
case VIEWER_DUMP_STYLE_CONTEXTS:
if ((nsnull != wd) && (nsnull != wd->ww)) {
wd->ww->DumpStyleContexts();
}
break;
case VIEWER_DEBUGROBOT:
DoDebugRobot(wd);
break;
case VIEWER_SHOW_CONTENT_SIZE:
if (nsnull != wd) {
wd->ShowContentSize();
}
break;
case VIEWER_SHOW_FRAME_SIZE:
if (nsnull != wd) {
wd->ShowFrameSize();
}
break;
case VIEWER_SHOW_STYLE_SIZE:
if (nsnull != wd) {
wd->ShowStyleSize();
}
break;
case VIEWER_ONE_COLUMN:
case VIEWER_TWO_COLUMN:
case VIEWER_THREE_COLUMN:
if ((nsnull != wd) && (nsnull != wd->ww)) {
ShowPrintPreview(wd->ww, menuEvent->menuItem - VIEWER_ONE_COLUMN + 1);
}
break;
case JS_CONSOLE:
ShowConsole(wd);
break;
case VIEWER_DEMO0:
case VIEWER_DEMO1:
case VIEWER_DEMO2:
case VIEWER_DEMO3:
case VIEWER_DEMO4:
case VIEWER_DEMO5:
case VIEWER_DEMO6:
case VIEWER_DEMO7:
case VIEWER_DEMO8:
if ((nsnull != wd) && (nsnull != wd->ww)) {
PRIntn ix = aId - VIEWER_DEMO0;
char* url = new char[500];
PR_snprintf(url, 500, "%s/test%d.html", SAMPLES_BASE_URL, ix);
wd->observer->LoadURL(url);
delete url;
}
break;
break;
case VIEWER_VISUAL_DEBUGGING:
if ((nsnull != wd) && (nsnull != wd->ww)) {
wd->ww->ShowFrameBorders(PRBool(!wd->ww->GetShowFrameBorders()));
}
break;
case VIEWER_DUMP_CONTENT:
if ((nsnull != wd) && (nsnull != wd->ww)) {
wd->ww->DumpContent();
}
break;
case VIEWER_DUMP_FRAMES:
if ((nsnull != wd) && (nsnull != wd->ww)) {
wd->ww->DumpFrames();
}
break;
case VIEWER_DUMP_VIEWS:
if ((nsnull != wd) && (nsnull != wd->ww)) {
wd->ww->DumpViews();
}
break;
case VIEWER_DUMP_STYLE_SHEETS:
if ((nsnull != wd) && (nsnull != wd->ww)) {
wd->ww->DumpStyleSheets();
}
break;
case VIEWER_DUMP_STYLE_CONTEXTS:
if ((nsnull != wd) && (nsnull != wd->ww)) {
wd->ww->DumpStyleContexts();
}
break;
case VIEWER_DEBUGROBOT:
DoDebugRobot(wd);
break;
case VIEWER_SHOW_CONTENT_SIZE:
if (nsnull != wd) {
wd->ShowContentSize();
}
break;
case VIEWER_SHOW_FRAME_SIZE:
if (nsnull != wd) {
wd->ShowFrameSize();
}
break;
case VIEWER_SHOW_STYLE_SIZE:
if (nsnull != wd) {
wd->ShowStyleSize();
}
break;
case VIEWER_ONE_COLUMN:
case VIEWER_TWO_COLUMN:
case VIEWER_THREE_COLUMN:
if ((nsnull != wd) && (nsnull != wd->ww)) {
ShowPrintPreview(wd->ww, aId - VIEWER_ONE_COLUMN + 1);
}
break;
case JS_CONSOLE:
ShowConsole(wd);
break;
}
return(result);
@ -1070,6 +1080,7 @@ nsDocLoader* nsViewer::SetupViewer(nsIWidget **aMainWindow, int argc, char **arg
// Create a top level window for the WebWidget
WindowData* wd = CreateTopLevel("Raptor HTML Viewer", 620, 400);
*aMainWindow = wd->windowWidget;
gMainWindowData = wd;
// Attach a menu to the top level window
AddMenu(wd->windowWidget);

View File

@ -147,6 +147,9 @@ class nsViewer : public nsDispatchListener {
virtual nsDocLoader* SetupViewer(nsIWidget **aMainWindow,int argc, char **argv);
virtual void CleanupViewer(nsDocLoader* aDl);
virtual nsEventStatus DispatchMenuItem(nsGUIEvent *aEvent);
virtual nsEventStatus nsViewer::DispatchMenuItem(PRUint32 aId);
virtual nsEventStatus nsViewer::ProcessMenu(PRUint32 aId, WindowData* wd);
virtual nsresult ShowPrintPreview(nsIWebWidget* web, PRIntn aColumns);
virtual WindowData* CreateTopLevel(const char* title, int aWidth, int aHeight);
virtual void AddTestDocs(nsDocLoader* aDocLoader);