~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/webshell/tests/viewer/nsPhMenu.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
5
 * The contents of this file are subject to the Netscape Public License
 
6
 * Version 1.1 (the "License"); you may not use this file except in
 
7
 * compliance with the License. You may obtain a copy of the License at
 
8
 * http://www.mozilla.org/NPL/
 
9
 *
 
10
 * Software distributed under the License is distributed on an "AS IS" basis,
 
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
12
 * for the specific language governing rights and limitations under the
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
17
 * The Initial Developer of the Original Code is 
 
18
 * Netscape Communications Corporation.
 
19
 * Portions created by the Initial Developer are Copyright (C) 1998
 
20
 * the Initial Developer. All Rights Reserved.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
24
 * Alternatively, the contents of this file may be used under the terms of
 
25
 * either the GNU General Public License Version 2 or later (the "GPL"), or 
 
26
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
27
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
28
 * of those above. If you wish to allow use of your version of this file only
 
29
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
30
 * use your version of this file under the terms of the NPL, indicate your
 
31
 * decision by deleting the provisions above and replace them with the notice
 
32
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
33
 * the provisions above, a recipient may use your version of this file under
 
34
 * the terms of any one of the NPL, the GPL or the LGPL.
 
35
 *
 
36
 * ***** END LICENSE BLOCK ***** */
 
37
 
 
38
#include <Pt.h>
 
39
 
 
40
#include "nsBrowserWindow.h"
 
41
#include "resources.h"
 
42
#include "nscore.h"
 
43
 
 
44
#include <stdio.h>
 
45
 
 
46
 
 
47
int MenuItemActivate (PtWidget_t *widget, void *command, PtCallbackInfo_t *cbinfo)
 
48
{
 
49
  PtArg_t    arg;
 
50
  void       **data;
 
51
 
 
52
  PtWidget_t *nativeWindow = PtGetParent( widget, PtWindow );
 
53
 
 
54
  if( nativeWindow )
 
55
  {  
 
56
    PtSetArg( &arg, Pt_ARG_USER_DATA, &data, 0 );
 
57
    if( PtGetResources( nativeWindow, 1, &arg ) == 0 )
 
58
    {
 
59
      if( data )
 
60
      {
 
61
        nsIWidget *xpWindow = (nsIWidget *) *data;
 
62
        nsBrowserWindow* bw = nsBrowserWindow::FindBrowserFor( xpWindow, FIND_WINDOW );
 
63
 
 
64
        if( bw )
 
65
        {
 
66
          bw->DispatchMenuItem( (int) command );
 
67
        }
 
68
      }
 
69
    }
 
70
  }
 
71
 
 
72
  return Pt_CONTINUE;
 
73
}
 
74
 
 
75
 
 
76
int TopLevelMenuItemArm (PtWidget_t *widget, void *Menu, PtCallbackInfo_t *cbinfo)
 
77
{
 
78
//  printf("TopLevelMenuItemArm Menu=<%p>\n", Menu);
 
79
  
 
80
    PtPositionMenu ( (PtWidget_t *) Menu, NULL);
 
81
        PtRealizeWidget( (PtWidget_t *) Menu);  
 
82
}  
 
83
 
 
84
PtWidget_t *CreateTopLevelMenu(PtWidget_t *aParent, char *Label)
 
85
{
 
86
  PtArg_t     arg[10];
 
87
  PtWidget_t  *menu, *menubutton;
 
88
 
 
89
    PtSetArg(&arg[0], Pt_ARG_BUTTON_TYPE, Pt_MENU_DOWN, 0);
 
90
    PtSetArg(&arg[1], Pt_ARG_TEXT_STRING, Label, 0);
 
91
    menubutton = PtCreateWidget(PtMenuButton, aParent, 2, arg);
 
92
 
 
93
    /* Now Create the Photon Menu that is attached to the mMenuButton */
 
94
    PtSetArg(&arg[0], Pt_ARG_MENU_FLAGS, Pt_MENU_AUTO, 0xFFFFFFFF);
 
95
    menu = PtCreateWidget (PtMenu, menubutton, 1, arg);
 
96
 
 
97
   /* Set the Call back on this top level menu button */
 
98
    PtAddCallback(menubutton, Pt_CB_ARM, TopLevelMenuItemArm, menu);
 
99
 
 
100
    PtRealizeWidget(menubutton);
 
101
 
 
102
//  printf("CreateTopLevelMenu: Label=<%s> menubutton=<%p> menu=<%p>\n", Label, menubutton, menu);
 
103
    return menu;
 
104
}
 
105
 
 
106
 
 
107
PtWidget_t *CreateSubMenu(PtWidget_t *aParent, char *Label)
 
108
{
 
109
  PtArg_t     arg[10];
 
110
  PtWidget_t  *menu, *menubutton;
 
111
 
 
112
        PtSetArg(&arg[0], Pt_ARG_BUTTON_TYPE, Pt_MENU_RIGHT, 0);
 
113
    PtSetArg(&arg[1], Pt_ARG_TEXT_STRING, Label, 0);
 
114
    menubutton = PtCreateWidget(PtMenuButton, aParent, 2, arg);
 
115
 
 
116
    PtSetArg(&arg[0], Pt_ARG_MENU_FLAGS, Pt_MENU_CHILD | Pt_MENU_AUTO, 0xFFFFFFFF);
 
117
    menu = PtCreateWidget (PtMenu, menubutton, 1, arg);
 
118
 
 
119
    return menu;
 
120
}
 
121
 
 
122
PtWidget_t *CreateMenuItem(PtWidget_t *aParent, char *Label, int command)
 
123
{
 
124
  PtArg_t     arg[10];
 
125
  PtWidget_t  *menuitem;
 
126
 
 
127
//printf("CreateMenuItem: aParent=<%p>, Label=<%s> command=<%d>\n", aParent, Label, command);
 
128
  
 
129
  PtSetArg ( &arg[0], Pt_ARG_BUTTON_TYPE, Pt_MENU_TEXT, 0);
 
130
  PtSetArg ( &arg[1], Pt_ARG_USER_DATA, &command, sizeof(void *) );
 
131
  if (Label == NULL)
 
132
  {
 
133
    PtSetArg ( &arg[2], Pt_ARG_SEP_TYPE, Pt_ETCHED_IN, 0);
 
134
    menuitem = PtCreateWidget (PtSeparator, aParent, 3, arg);
 
135
  }
 
136
  else
 
137
  {
 
138
    PtSetArg ( &arg[2], Pt_ARG_TEXT_STRING, Label, 0);
 
139
    menuitem = PtCreateWidget (PtMenuButton, aParent, 3, arg);
 
140
    PtAddCallback(menuitem, Pt_CB_ACTIVATE, MenuItemActivate , (void *) command);
 
141
  }
 
142
 
 
143
  return menuitem;
 
144
}
 
145
 
 
146
void CreateViewerMenus(PtWidget_t *menubar, void *data) 
 
147
{
 
148
  PtArg_t     arg[10];
 
149
  PtWidget_t  *menu, *submenu, *submenu2;
 
150
 
 
151
//printf("Entering CreateViewerMenus menubar=<%p>\n", menubar);
 
152
 
 
153
  menu = CreateTopLevelMenu(menubar, "File");
 
154
  CreateMenuItem(menu, "New Window",VIEWER_WINDOW_OPEN);
 
155
  CreateMenuItem(menu, "Open",VIEWER_FILE_OPEN);
 
156
  CreateMenuItem(menu, "View Source",VIEW_SOURCE);
 
157
 
 
158
  submenu=CreateSubMenu(menu, "Samples");
 
159
 
 
160
struct MenuList_s {
 
161
 char     *Label;
 
162
 PRUint32 Command;
 
163
};
 
164
 
 
165
struct MenuList_s DemoList[18] = 
 
166
 
167
  {"#0 Basic Styles", VIEWER_DEMO0},
 
168
  {"#1 CSS Styles", VIEWER_DEMO1},
 
169
  {"#2 Images", VIEWER_DEMO2},
 
170
  {"#3 Basic Tables", VIEWER_DEMO3},
 
171
  {"#4 Sample Tables", VIEWER_DEMO4},
 
172
  {"#5 More Styles", VIEWER_DEMO5},
 
173
  {"#6 Deeply Nested Tables", VIEWER_DEMO6},
 
174
  {"#7 Scaled Anim Image", VIEWER_DEMO7},
 
175
  {"#8 Form", VIEWER_DEMO8},
 
176
  {"#9 Frames", VIEWER_DEMO9},
 
177
  {"#10 Anim Images", VIEWER_DEMO10},
 
178
  {"#11 Fixed Positioning", VIEWER_DEMO11},
 
179
  {"#12 More Fixed Pos", VIEWER_DEMO12},
 
180
  {"#13 DHTML", VIEWER_DEMO13},
 
181
  {"#14 XML Sorting", VIEWER_DEMO14},
 
182
  {"#15 XML IRS", VIEWER_DEMO15},
 
183
  {"#16 Gfx Widgets", VIEWER_DEMO16},
 
184
  {"#17 <Empty>", VIEWER_DEMO17}
 
185
};
 
186
 
 
187
  for(int i=0; i<=17; i++)
 
188
  {
 
189
    CreateMenuItem(submenu, DemoList[i].Label,DemoList[i].Command);
 
190
  }
 
191
 
 
192
  CreateMenuItem(menu, "Test Sites", VIEWER_TOP100);
 
193
  submenu=CreateSubMenu(menu, "XPToolkit Tests");
 
194
  CreateMenuItem(submenu, "Toolbar Test 1", VIEWER_XPTOOLKITTOOLBAR1);
 
195
  CreateMenuItem(submenu, "Tree Test 2", VIEWER_XPTOOLKITTREE1);
 
196
  CreateMenuItem(menu, NULL, 0);
 
197
  CreateMenuItem(menu, "Print Preview", VIEWER_ONE_COLUMN);
 
198
  CreateMenuItem(menu, "Print", VIEWER_PRINT);
 
199
  CreateMenuItem(menu, "Print Setup", VIEWER_PRINT_SETUP);
 
200
  CreateMenuItem(menu, NULL, 0);
 
201
  CreateMenuItem(menu, "Exit", VIEWER_EXIT);
 
202
 
 
203
  menu = CreateTopLevelMenu(menubar, "Edit");
 
204
  CreateMenuItem(menu, "Cut", VIEWER_EDIT_CUT);
 
205
  CreateMenuItem(menu, "Copy", VIEWER_EDIT_COPY);
 
206
  CreateMenuItem(menu, "Paste", VIEWER_EDIT_PASTE);
 
207
  CreateMenuItem(menu, NULL, 0);
 
208
  CreateMenuItem(menu, "Select All", VIEWER_EDIT_SELECTALL);
 
209
  CreateMenuItem(menu, NULL, 0);
 
210
  CreateMenuItem(menu, "Find in Page", VIEWER_EDIT_FINDINPAGE);
 
211
 
 
212
//#ifdef DEBUG 
 
213
  menu = CreateTopLevelMenu(menubar, "Debug");
 
214
  CreateMenuItem(menu, "Visual Debugging", VIEWER_VISUAL_DEBUGGING);
 
215
  CreateMenuItem(menu, NULL, 0);
 
216
  submenu=CreateSubMenu(menu, "Event Debugging");
 
217
  CreateMenuItem(submenu, "Toggle Paint Flashing", VIEWER_TOGGLE_PAINT_FLASHING);
 
218
  CreateMenuItem(submenu, "Toggle Paint Dumpinging", VIEWER_TOGGLE_PAINT_DUMPING);
 
219
  CreateMenuItem(submenu, "Toggle Invalidate Dumping", VIEWER_TOGGLE_INVALIDATE_DUMPING);
 
220
  CreateMenuItem(submenu, "Toggle Event Dumping", VIEWER_TOGGLE_EVENT_DUMPING);
 
221
  CreateMenuItem(submenu, NULL, 0);
 
222
  CreateMenuItem(submenu, "Toggle Motion Event Dumping", VIEWER_TOGGLE_MOTION_EVENT_DUMPING);
 
223
  CreateMenuItem(submenu, "Toggle Crossing Event Dumpinging", VIEWER_TOGGLE_CROSSING_EVENT_DUMPING);
 
224
  CreateMenuItem(menu, NULL, 0);
 
225
  CreateMenuItem(menu, "Reflow Test", VIEWER_REFLOW_TEST);
 
226
  CreateMenuItem(menu, NULL, 0);
 
227
  CreateMenuItem(menu, "Dump Content", VIEWER_DUMP_CONTENT);
 
228
  CreateMenuItem(menu, "Dump Frames", VIEWER_DUMP_FRAMES);
 
229
  CreateMenuItem(menu, "Dump Views", VIEWER_DUMP_VIEWS);
 
230
  CreateMenuItem(menu, NULL, 0);
 
231
  CreateMenuItem(menu, "Dump Style Sheets", VIEWER_DUMP_STYLE_SHEETS);
 
232
  CreateMenuItem(menu, "Dump Style Contexts", VIEWER_DUMP_STYLE_CONTEXTS);
 
233
  CreateMenuItem(menu, NULL, 0);
 
234
  CreateMenuItem(menu, "Debug Save", VIEWER_DEBUGSAVE);
 
235
  CreateMenuItem(menu, "Debug Output Text", VIEWER_DISPLAYTEXT);
 
236
  CreateMenuItem(menu, "Debug Output HTML", VIEWER_DISPLAYHTML);
 
237
  CreateMenuItem(menu, "Debug Toggle Selection", VIEWER_TOGGLE_SELECTION);
 
238
  CreateMenuItem(menu, NULL, 0);
 
239
  CreateMenuItem(menu, "Debug Robot", VIEWER_DEBUGROBOT);
 
240
  CreateMenuItem(menu, NULL, 0);
 
241
  submenu=CreateSubMenu(menu, "Style");
 
242
  submenu2=CreateSubMenu(submenu, "Select Style Sheet");
 
243
  CreateMenuItem(submenu2, "List Available Sheets", VIEWER_SELECT_STYLE_LIST);
 
244
  CreateMenuItem(submenu2, NULL, 0);
 
245
  CreateMenuItem(submenu2, "Select Default", VIEWER_SELECT_STYLE_DEFAULT);
 
246
  CreateMenuItem(submenu2, NULL, 0);
 
247
  CreateMenuItem(submenu2, "Select Alternative 1", VIEWER_SELECT_STYLE_ONE);
 
248
  CreateMenuItem(submenu2, "Select Alternative 2", VIEWER_SELECT_STYLE_TWO);
 
249
  CreateMenuItem(submenu2, "Select Alternative 3", VIEWER_SELECT_STYLE_THREE);
 
250
  CreateMenuItem(submenu2, "Select Alternative 4", VIEWER_SELECT_STYLE_FOUR);
 
251
  submenu2=CreateSubMenu(submenu, "Compatibility Mode");
 
252
  CreateMenuItem(submenu2, "Use DTD", VIEWER_USE_DTD_MODE);
 
253
  CreateMenuItem(submenu2, "Nav Quirks", VIEWER_NAV_QUIRKS_MODE);
 
254
  CreateMenuItem(submenu2, "Standard", VIEWER_STANDARD_MODE);
 
255
  submenu2=CreateSubMenu(submenu, "Widget Render Mode");
 
256
  CreateMenuItem(submenu2, "Native", VIEWER_NATIVE_WIDGET_MODE); 
 
257
  CreateMenuItem(submenu2, "Gfx", VIEWER_GFX_WIDGET_MODE); 
 
258
//#endif
 
259
 
 
260
  menu = CreateTopLevelMenu(menubar, "Tools");
 
261
  CreateMenuItem(menu, "JavaScript Console", JS_CONSOLE);
 
262
  CreateMenuItem(menu, "Editor Mode", EDITOR_MODE);
 
263
}
 
264