Back to index

lightning-sunbird  0.9+nobinonly
nsPhMenu.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include <Pt.h>
00039 
00040 #include "nsBrowserWindow.h"
00041 #include "resources.h"
00042 #include "nscore.h"
00043 
00044 #include <stdio.h>
00045 
00046 
00047 int MenuItemActivate (PtWidget_t *widget, void *command, PtCallbackInfo_t *cbinfo)
00048 {
00049   PtArg_t    arg;
00050   void       **data;
00051 
00052   PtWidget_t *nativeWindow = PtGetParent( widget, PtWindow );
00053 
00054   if( nativeWindow )
00055   {  
00056     PtSetArg( &arg, Pt_ARG_USER_DATA, &data, 0 );
00057     if( PtGetResources( nativeWindow, 1, &arg ) == 0 )
00058     {
00059       if( data )
00060       {
00061         nsIWidget *xpWindow = (nsIWidget *) *data;
00062         nsBrowserWindow* bw = nsBrowserWindow::FindBrowserFor( xpWindow, FIND_WINDOW );
00063 
00064         if( bw )
00065         {
00066           bw->DispatchMenuItem( (int) command );
00067         }
00068       }
00069     }
00070   }
00071 
00072   return Pt_CONTINUE;
00073 }
00074 
00075 
00076 int TopLevelMenuItemArm (PtWidget_t *widget, void *Menu, PtCallbackInfo_t *cbinfo)
00077 {
00078 //  printf("TopLevelMenuItemArm Menu=<%p>\n", Menu);
00079   
00080     PtPositionMenu ( (PtWidget_t *) Menu, NULL);
00081        PtRealizeWidget( (PtWidget_t *) Menu);  
00082 }  
00083 
00084 PtWidget_t *CreateTopLevelMenu(PtWidget_t *aParent, char *Label)
00085 {
00086   PtArg_t     arg[10];
00087   PtWidget_t  *menu, *menubutton;
00088 
00089     PtSetArg(&arg[0], Pt_ARG_BUTTON_TYPE, Pt_MENU_DOWN, 0);
00090     PtSetArg(&arg[1], Pt_ARG_TEXT_STRING, Label, 0);
00091     menubutton = PtCreateWidget(PtMenuButton, aParent, 2, arg);
00092 
00093     /* Now Create the Photon Menu that is attached to the mMenuButton */
00094     PtSetArg(&arg[0], Pt_ARG_MENU_FLAGS, Pt_MENU_AUTO, 0xFFFFFFFF);
00095     menu = PtCreateWidget (PtMenu, menubutton, 1, arg);
00096 
00097    /* Set the Call back on this top level menu button */
00098     PtAddCallback(menubutton, Pt_CB_ARM, TopLevelMenuItemArm, menu);
00099 
00100     PtRealizeWidget(menubutton);
00101 
00102 //  printf("CreateTopLevelMenu: Label=<%s> menubutton=<%p> menu=<%p>\n", Label, menubutton, menu);
00103     return menu;
00104 }
00105 
00106 
00107 PtWidget_t *CreateSubMenu(PtWidget_t *aParent, char *Label)
00108 {
00109   PtArg_t     arg[10];
00110   PtWidget_t  *menu, *menubutton;
00111 
00112        PtSetArg(&arg[0], Pt_ARG_BUTTON_TYPE, Pt_MENU_RIGHT, 0);
00113     PtSetArg(&arg[1], Pt_ARG_TEXT_STRING, Label, 0);
00114     menubutton = PtCreateWidget(PtMenuButton, aParent, 2, arg);
00115 
00116     PtSetArg(&arg[0], Pt_ARG_MENU_FLAGS, Pt_MENU_CHILD | Pt_MENU_AUTO, 0xFFFFFFFF);
00117     menu = PtCreateWidget (PtMenu, menubutton, 1, arg);
00118 
00119     return menu;
00120 }
00121 
00122 PtWidget_t *CreateMenuItem(PtWidget_t *aParent, char *Label, int command)
00123 {
00124   PtArg_t     arg[10];
00125   PtWidget_t  *menuitem;
00126 
00127 //printf("CreateMenuItem: aParent=<%p>, Label=<%s> command=<%d>\n", aParent, Label, command);
00128   
00129   PtSetArg ( &arg[0], Pt_ARG_BUTTON_TYPE, Pt_MENU_TEXT, 0);
00130   PtSetArg ( &arg[1], Pt_ARG_USER_DATA, &command, sizeof(void *) );
00131   if (Label == NULL)
00132   {
00133     PtSetArg ( &arg[2], Pt_ARG_SEP_TYPE, Pt_ETCHED_IN, 0);
00134     menuitem = PtCreateWidget (PtSeparator, aParent, 3, arg);
00135   }
00136   else
00137   {
00138     PtSetArg ( &arg[2], Pt_ARG_TEXT_STRING, Label, 0);
00139     menuitem = PtCreateWidget (PtMenuButton, aParent, 3, arg);
00140     PtAddCallback(menuitem, Pt_CB_ACTIVATE, MenuItemActivate , (void *) command);
00141   }
00142 
00143   return menuitem;
00144 }
00145 
00146 void CreateViewerMenus(PtWidget_t *menubar, void *data) 
00147 {
00148   PtArg_t     arg[10];
00149   PtWidget_t  *menu, *submenu, *submenu2;
00150 
00151 //printf("Entering CreateViewerMenus menubar=<%p>\n", menubar);
00152 
00153   menu = CreateTopLevelMenu(menubar, "File");
00154   CreateMenuItem(menu, "New Window",VIEWER_WINDOW_OPEN);
00155   CreateMenuItem(menu, "Open",VIEWER_FILE_OPEN);
00156   CreateMenuItem(menu, "View Source",VIEW_SOURCE);
00157 
00158   submenu=CreateSubMenu(menu, "Samples");
00159 
00160 struct MenuList_s {
00161  char     *Label;
00162  PRUint32 Command;
00163 };
00164 
00165 struct MenuList_s DemoList[18] = 
00166 { 
00167   {"#0 Basic Styles", VIEWER_DEMO0},
00168   {"#1 CSS Styles", VIEWER_DEMO1},
00169   {"#2 Images", VIEWER_DEMO2},
00170   {"#3 Basic Tables", VIEWER_DEMO3},
00171   {"#4 Sample Tables", VIEWER_DEMO4},
00172   {"#5 More Styles", VIEWER_DEMO5},
00173   {"#6 Deeply Nested Tables", VIEWER_DEMO6},
00174   {"#7 Scaled Anim Image", VIEWER_DEMO7},
00175   {"#8 Form", VIEWER_DEMO8},
00176   {"#9 Frames", VIEWER_DEMO9},
00177   {"#10 Anim Images", VIEWER_DEMO10},
00178   {"#11 Fixed Positioning", VIEWER_DEMO11},
00179   {"#12 More Fixed Pos", VIEWER_DEMO12},
00180   {"#13 DHTML", VIEWER_DEMO13},
00181   {"#14 XML Sorting", VIEWER_DEMO14},
00182   {"#15 XML IRS", VIEWER_DEMO15},
00183   {"#16 Gfx Widgets", VIEWER_DEMO16},
00184   {"#17 <Empty>", VIEWER_DEMO17}
00185 };
00186 
00187   for(int i=0; i<=17; i++)
00188   {
00189     CreateMenuItem(submenu, DemoList[i].Label,DemoList[i].Command);
00190   }
00191 
00192   CreateMenuItem(menu, "Test Sites", VIEWER_TOP100);
00193   submenu=CreateSubMenu(menu, "XPToolkit Tests");
00194   CreateMenuItem(submenu, "Toolbar Test 1", VIEWER_XPTOOLKITTOOLBAR1);
00195   CreateMenuItem(submenu, "Tree Test 2", VIEWER_XPTOOLKITTREE1);
00196   CreateMenuItem(menu, NULL, 0);
00197   CreateMenuItem(menu, "Print Preview", VIEWER_ONE_COLUMN);
00198   CreateMenuItem(menu, "Print", VIEWER_PRINT);
00199   CreateMenuItem(menu, "Print Setup", VIEWER_PRINT_SETUP);
00200   CreateMenuItem(menu, NULL, 0);
00201   CreateMenuItem(menu, "Exit", VIEWER_EXIT);
00202 
00203   menu = CreateTopLevelMenu(menubar, "Edit");
00204   CreateMenuItem(menu, "Cut", VIEWER_EDIT_CUT);
00205   CreateMenuItem(menu, "Copy", VIEWER_EDIT_COPY);
00206   CreateMenuItem(menu, "Paste", VIEWER_EDIT_PASTE);
00207   CreateMenuItem(menu, NULL, 0);
00208   CreateMenuItem(menu, "Select All", VIEWER_EDIT_SELECTALL);
00209   CreateMenuItem(menu, NULL, 0);
00210   CreateMenuItem(menu, "Find in Page", VIEWER_EDIT_FINDINPAGE);
00211  
00212 //#ifdef DEBUG 
00213   menu = CreateTopLevelMenu(menubar, "Debug");
00214   CreateMenuItem(menu, "Visual Debugging", VIEWER_VISUAL_DEBUGGING);
00215   CreateMenuItem(menu, NULL, 0);
00216   submenu=CreateSubMenu(menu, "Event Debugging");
00217   CreateMenuItem(submenu, "Toggle Paint Flashing", VIEWER_TOGGLE_PAINT_FLASHING);
00218   CreateMenuItem(submenu, "Toggle Paint Dumpinging", VIEWER_TOGGLE_PAINT_DUMPING);
00219   CreateMenuItem(submenu, "Toggle Invalidate Dumping", VIEWER_TOGGLE_INVALIDATE_DUMPING);
00220   CreateMenuItem(submenu, "Toggle Event Dumping", VIEWER_TOGGLE_EVENT_DUMPING);
00221   CreateMenuItem(submenu, NULL, 0);
00222   CreateMenuItem(submenu, "Toggle Motion Event Dumping", VIEWER_TOGGLE_MOTION_EVENT_DUMPING);
00223   CreateMenuItem(submenu, "Toggle Crossing Event Dumpinging", VIEWER_TOGGLE_CROSSING_EVENT_DUMPING);
00224   CreateMenuItem(menu, NULL, 0);
00225   CreateMenuItem(menu, "Reflow Test", VIEWER_REFLOW_TEST);
00226   CreateMenuItem(menu, NULL, 0);
00227   CreateMenuItem(menu, "Dump Content", VIEWER_DUMP_CONTENT);
00228   CreateMenuItem(menu, "Dump Frames", VIEWER_DUMP_FRAMES);
00229   CreateMenuItem(menu, "Dump Views", VIEWER_DUMP_VIEWS);
00230   CreateMenuItem(menu, NULL, 0);
00231   CreateMenuItem(menu, "Dump Style Sheets", VIEWER_DUMP_STYLE_SHEETS);
00232   CreateMenuItem(menu, "Dump Style Contexts", VIEWER_DUMP_STYLE_CONTEXTS);
00233   CreateMenuItem(menu, NULL, 0);
00234   CreateMenuItem(menu, "Debug Save", VIEWER_DEBUGSAVE);
00235   CreateMenuItem(menu, "Debug Output Text", VIEWER_DISPLAYTEXT);
00236   CreateMenuItem(menu, "Debug Output HTML", VIEWER_DISPLAYHTML);
00237   CreateMenuItem(menu, "Debug Toggle Selection", VIEWER_TOGGLE_SELECTION);
00238   CreateMenuItem(menu, NULL, 0);
00239   CreateMenuItem(menu, "Debug Robot", VIEWER_DEBUGROBOT);
00240   CreateMenuItem(menu, NULL, 0);
00241   submenu=CreateSubMenu(menu, "Style");
00242   submenu2=CreateSubMenu(submenu, "Select Style Sheet");
00243   CreateMenuItem(submenu2, "List Available Sheets", VIEWER_SELECT_STYLE_LIST);
00244   CreateMenuItem(submenu2, NULL, 0);
00245   CreateMenuItem(submenu2, "Select Default", VIEWER_SELECT_STYLE_DEFAULT);
00246   CreateMenuItem(submenu2, NULL, 0);
00247   CreateMenuItem(submenu2, "Select Alternative 1", VIEWER_SELECT_STYLE_ONE);
00248   CreateMenuItem(submenu2, "Select Alternative 2", VIEWER_SELECT_STYLE_TWO);
00249   CreateMenuItem(submenu2, "Select Alternative 3", VIEWER_SELECT_STYLE_THREE);
00250   CreateMenuItem(submenu2, "Select Alternative 4", VIEWER_SELECT_STYLE_FOUR);
00251   submenu2=CreateSubMenu(submenu, "Compatibility Mode");
00252   CreateMenuItem(submenu2, "Use DTD", VIEWER_USE_DTD_MODE);
00253   CreateMenuItem(submenu2, "Nav Quirks", VIEWER_NAV_QUIRKS_MODE);
00254   CreateMenuItem(submenu2, "Standard", VIEWER_STANDARD_MODE);
00255   submenu2=CreateSubMenu(submenu, "Widget Render Mode");
00256   CreateMenuItem(submenu2, "Native", VIEWER_NATIVE_WIDGET_MODE); 
00257   CreateMenuItem(submenu2, "Gfx", VIEWER_GFX_WIDGET_MODE); 
00258 //#endif
00259 
00260   menu = CreateTopLevelMenu(menubar, "Tools");
00261   CreateMenuItem(menu, "JavaScript Console", JS_CONSOLE);
00262   CreateMenuItem(menu, "Editor Mode", EDITOR_MODE);
00263 }
00264