Back to index

lightning-sunbird  0.9+nobinonly
nsGtkMenu.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 <gtk/gtk.h>
00039 
00040 #include "nsBrowserWindow.h"
00041 #include "resources.h"
00042 #include "nscore.h"
00043 
00044 #include <stdio.h>
00045 
00046 typedef GtkItemFactoryCallback GIFC;
00047 
00048 void gtk_ifactory_cb (nsBrowserWindow *nbw,
00049                       guint callback_action, 
00050                       GtkWidget *widget)
00051 {
00052   nbw->DispatchMenuItem(callback_action);
00053 }
00054 
00055 GtkItemFactoryEntry menu_items[] =
00056 {
00057   { "/_File",                      nsnull,       nsnull,                     0,                   "<Branch>" },
00058   { "/File/_New Window",           nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_WINDOW_OPEN,  nsnull },
00059   { "/File/_Open...",                     nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_FILE_OPEN,    nsnull },
00060   { "/File/_View Source",          nsnull, (GIFC)gtk_ifactory_cb,     VIEW_SOURCE,         nsnull },
00061   { "/File/_Samples",                     nsnull,       nsnull,                     0,                   "<Branch>" },
00062   { "/File/Samples/demo #0",              nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEMO0,        nsnull },
00063   { "/File/Samples/demo #1",              nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEMO1,        nsnull },
00064   { "/File/Samples/demo #2",              nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEMO2,        nsnull },
00065   { "/File/Samples/demo #3",              nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEMO3,        nsnull },
00066   { "/File/Samples/demo #4",              nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEMO4,        nsnull },
00067   { "/File/Samples/demo #5",              nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEMO5,        nsnull },
00068   { "/File/Samples/demo #6",              nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEMO6,        nsnull },
00069   { "/File/Samples/demo #7",              nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEMO7,        nsnull },
00070   { "/File/Samples/demo #8",              nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEMO8,        nsnull },
00071   { "/File/Samples/demo #9",              nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEMO9,        nsnull },
00072   { "/File/Samples/demo #10",             nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEMO10,              nsnull },
00073   { "/File/Samples/demo #11",             nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEMO11,              nsnull },
00074   { "/File/Samples/demo #12",             nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEMO12,              nsnull },
00075   { "/File/Samples/demo #13",             nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEMO13,              nsnull },
00076   { "/File/Samples/demo #14",             nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEMO14,              nsnull },
00077   { "/File/Samples/demo #15",             nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEMO15,              nsnull },
00078   { "/File/Samples/demo #16",             nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEMO16,              nsnull },
00079   { "/File/Samples/demo #17",             nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEMO17,              nsnull },
00080   { "/File/_Test Sites",           nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_TOP100,              nsnull },
00081   { "/File/XPToolkit Tests",              nsnull,       nsnull,                     0,                   "<Branch>" },
00082   { "/File/XPToolkit Tests/Toolbar Test 1",       nsnull, (GIFC)gtk_ifactory_cb,  VIEWER_XPTOOLKITTOOLBAR1,     nsnull },
00083   { "/File/XPToolkit Tests/Tree Test 1",       nsnull, (GIFC)gtk_ifactory_cb,  VIEWER_XPTOOLKITTREE1,     nsnull },
00084   { "/File/sep1",                  nsnull,       nsnull,                     0,                   "<Separator>" },
00085   { "/File/Print Preview",  nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_ONE_COLUMN,   nsnull },
00086   { "/File/Print",                 nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_PRINT,        nsnull },
00087   { "/File/sep2",                  nsnull,       nsnull,                     0,                   "<Separator>" },
00088   { "/File/_Exit",                 nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_EXIT,         nsnull },
00089 
00090   { "/_Edit",                      nsnull,       nsnull,                     0,                   "<Branch>" },
00091   { "/Edit/Cu_t",                  nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_EDIT_CUT,     nsnull },
00092   { "/Edit/_Copy",                 nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_EDIT_COPY,    nsnull },
00093   { "/Edit/_Paste",                nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_EDIT_PASTE,   nsnull },
00094   { "/Edit/sep1",                  nsnull,       nsnull,                     0,                   "<Separator>" },
00095   { "/Edit/Select All",                   nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_EDIT_SELECTALL,      nsnull },
00096   { "/Edit/sep1",                  nsnull,       nsnull,                     0,                   "<Separator>" },
00097   { "/Edit/Find in Page",          nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_EDIT_FINDINPAGE,     nsnull },
00098 
00099 //#ifdef DEBUG // turning off for now
00100   { "/_Debug",                            nsnull,       nsnull,                     0,                   "<Branch>"    },
00101   { "/Debug/_Visual Debugging",           nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_VISUAL_DEBUGGING,nsnull },
00102   { "/Debug/Visual _Event Debugging",            nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_VISUAL_EVENT_DEBUGGING,nsnull },
00103   { "/Debug/sep1",                 nsnull,       nsnull,                     0,                   "<Separator>" },
00104   { "/Debug/Event Debugging/Toggle Paint Flashing",            nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_TOGGLE_PAINT_FLASHING,nsnull },
00105   { "/Debug/Event Debugging/Toggle Paint Dumping",             nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_TOGGLE_PAINT_DUMPING,nsnull },
00106   { "/Debug/Event Debugging/Toggle Invalidate Dumping",        nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_TOGGLE_INVALIDATE_DUMPING,nsnull },
00107   { "/Debug/Event Debugging/Toggle Event Dumping",             nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_TOGGLE_EVENT_DUMPING,nsnull },
00108   { "/Debug/Event Debugging/sep1", nsnull,       nsnull,                     0,                   "<Separator>" },
00109   { "/Debug/Event Debugging/Toggle Motion Event Dumping",             nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_TOGGLE_MOTION_EVENT_DUMPING,nsnull },
00110   { "/Debug/Event Debugging/Toggle Crossing Event Dumping",           nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_TOGGLE_CROSSING_EVENT_DUMPING,nsnull },
00111   { "/Debug/sep1",                 nsnull,       nsnull,                     0,                   "<Separator>" },
00112   { "/Debug/Reflow Debugging/_Reflow Test",             nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_REFLOW_TEST,  nsnull },
00113   { "/Debug/Reflow Debugging/Dump Reflow Stats",        nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEBUG_DUMP_REFLOW_TOTS,     nsnull },
00114   { "/Debug/Reflow Debugging/Reflow Counts On",         nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DSP_REFLOW_CNTS_ON,  nsnull },
00115   { "/Debug/Reflow Debugging/Reflow Counts Off",        nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DSP_REFLOW_CNTS_OFF, nsnull },
00116   { "/Debug/sep1",                 nsnull,       nsnull,                     0,                   "<Separator>" },
00117   { "/Debug/Dump _Content",        nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DUMP_CONTENT, nsnull },
00118   { "/Debug/Dump _Frames",         nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DUMP_FRAMES,  nsnull },
00119   { "/Debug/Dump _Views",          nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DUMP_VIEWS,   nsnull },
00120   { "/Debug/sep1",                 nsnull,       nsnull,                     0,                   "<Separator>" },
00121   { "/Debug/Dump _Style Sheets",   nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DUMP_STYLE_SHEETS,   nsnull },
00122   { "/Debug/Dump _Style Contexts", nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DUMP_STYLE_CONTEXTS, nsnull},
00123   { "/Debug/sep1",                 nsnull,       nsnull,                     0,                   "<Separator>" },
00124   { "/Debug/Debug Save",           nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEBUGSAVE,    nsnull },
00125   { "/Debug/Debug Output Text",           nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DISPLAYTEXT,  nsnull },
00126   { "/Debug/Debug Output HTML",           nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DISPLAYHTML,  nsnull },
00127   { "/Debug/Debug Toggle Selection",      nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_TOGGLE_SELECTION,nsnull },
00128   { "/Debug/sep1",                 nsnull,       nsnull,                     0,                   "<Separator>" },
00129   { "/Debug/Debug Robot",          nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_DEBUGROBOT,   nsnull },
00130   { "/_Style",                            nsnull,       nsnull,                     0,                   "<Branch>"    },
00131   { "/Style/Select _Style Sheet",         nsnull, nsnull,        0,        "<Branch>" },
00132   { "/Style/Select Style Sheet/List Available Sheets", nsnull, (GIFC)gtk_ifactory_cb, VIEWER_SELECT_STYLE_LIST, nsnull },
00133   { "/Style/Select Style Sheet/sep1", nsnull, nsnull,        0,        "<Separator>" },
00134   { "/Style/Select Style Sheet/Select Default", nsnull, (GIFC)gtk_ifactory_cb, VIEWER_SELECT_STYLE_DEFAULT, nsnull },
00135   { "/Style/Select Style Sheet/sep1", nsnull, nsnull,        0,        "<Separator>" },
00136   { "/Style/Select Style Sheet/Select Alternative 1", nsnull, (GIFC)gtk_ifactory_cb, VIEWER_SELECT_STYLE_ONE, nsnull },
00137   { "/Style/Select Style Sheet/Select Alternative 2", nsnull, (GIFC)gtk_ifactory_cb, VIEWER_SELECT_STYLE_TWO, nsnull },
00138   { "/Style/Select Style Sheet/Select Alternative 3", nsnull, (GIFC)gtk_ifactory_cb, VIEWER_SELECT_STYLE_THREE, nsnull },
00139   { "/Style/Select Style Sheet/Select Alternative 4", nsnull, (GIFC)gtk_ifactory_cb, VIEWER_SELECT_STYLE_FOUR, nsnull },
00140   { "/Style/_Compatibility Mode",         nsnull,       nsnull,                     0,                   "<Branch>" },
00141   { "/Style/Compatibility Mode/Use DTD",  nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_USE_DTD_MODE, nsnull },
00142   { "/Style/Compatibility Mode/Nav Quirks",      nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_NAV_QUIRKS_MODE,     nsnull },
00143   { "/Style/Compatibility Mode/Standard", nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_STANDARD_MODE,       nsnull },
00144   { "/Style/_Gfx Scrollbars Mode",        nsnull,       nsnull,                     0,                   "<Branch>" },
00145   { "/Style/Gfx Scrollbars Mode/Gfx On",  nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_GFX_SCROLLBARS_ON,   nsnull },
00146   { "/Style/Gfx Scrollbars Mode/Gfx Off", nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_GFX_SCROLLBARS_OFF,  nsnull },
00147 //#endif
00148 
00149   { "/_URLs",                                nsnull, nsnull,                 0,              "<Branch>" },
00150   { "/URLs/Goto URL 1",            nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_GOTO_TEST_URL1,nsnull },
00151   { "/URLs/Goto URL 2",            nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_GOTO_TEST_URL2,nsnull },
00152   { "/URLs/sep1",                  nsnull,       nsnull,                     0,                   "<Separator>" },
00153   { "/URLs/Save URL 1",            nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_SAVE_TEST_URL1,nsnull },
00154   { "/URLs/Save URL 2",            nsnull,       (GIFC)gtk_ifactory_cb,      VIEWER_SAVE_TEST_URL2,nsnull },
00155 
00156   { "/_Tools",                                nsnull, nsnull,                 0,              "<Branch>" },
00157   { "/Tools/_JavaScript Console",  nsnull,       (GIFC)gtk_ifactory_cb,      JS_CONSOLE,   nsnull },
00158   { "/Tools/_Editor Mode",         nsnull,       (GIFC)gtk_ifactory_cb,      EDITOR_MODE,  nsnull }
00159 };
00160 
00161 void CreateViewerMenus(nsIWidget *   aParent, 
00162                        gpointer      data,
00163                        GtkWidget **  aMenuBarOut) 
00164 {
00165   NS_ASSERTION(nsnull != aParent,"null parent.");
00166   NS_ASSERTION(nsnull != aMenuBarOut,"null out param.");
00167 
00168   NS_WARNING("CreateViewerMenus is not implemented yet!\n");
00169 
00170   GtkItemFactory *item_factory;
00171   GtkWidget *menubar;
00172 
00173   GdkWindow *window;
00174 
00175   window = (GdkWindow *)aParent->GetNativeData(NS_NATIVE_WINDOW);
00176   
00177   int nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
00178   item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>", nsnull);
00179 
00180   gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, data);
00181 
00182   menubar = gtk_item_factory_get_widget (item_factory, "<main>");
00183 
00184   // XXX fix this or kill viewer.
00185 
00186   /*
00187     NS_ASSERTION(GDK_IS_SUPERWIN(gdkSuperWin), "code assumes a gdksuperwin.");
00188     mozBox = gtk_mozbox_new(gdkSuperWin->bin_window);
00189      NS_ASSERTION((mozBox != NULL), "failed to create mozBox.");
00190 
00191      gtk_container_add(GTK_CONTAINER(mozBox), menubar);
00192      gtk_mozbox_set_position(GTK_MOZBOX(mozBox), 0, 0 );
00193      gtk_widget_show(menubar);
00194      gtk_widget_show(mozBox);
00195 
00196      *aMenuBarOut = menubar;
00197    */
00198 }