Back to index

lightning-sunbird  0.9+nobinonly
nsQtMenu.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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  *   Lars Knoll <knoll@kde.org>
00024  *   Zack Rusin <zack@kde.org>
00025  *
00026  * Alternatively, the contents of this file may be used under the terms of
00027  * either the GNU General Public License Version 2 or later (the "GPL"), or
00028  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00029  * in which case the provisions of the GPL or the LGPL are applicable instead
00030  * of those above. If you wish to allow use of your version of this file only
00031  * under the terms of either the GPL or the LGPL, and not to allow others to
00032  * use your version of this file under the terms of the MPL, indicate your
00033  * decision by deleting the provisions above and replace them with the notice
00034  * and other provisions required by the GPL or the LGPL. If you do not delete
00035  * the provisions above, a recipient may use your version of this file under
00036  * the terms of any one of the MPL, the GPL or the LGPL.
00037  *
00038  * ***** END LICENSE BLOCK ***** */
00039 
00040 #include <qwidget.h>
00041 #include "nsBrowserWindow.h"
00042 #include "nsQtMenu.h"
00043 #include "resources.h"
00044 #include "nscore.h"
00045 #include <stdio.h>
00046 
00047 nsMenuEventHandler::nsMenuEventHandler(nsBrowserWindow * window)
00048 {
00049     mWindow = window;
00050 }
00051 
00052 void nsMenuEventHandler::MenuItemActivated(int id)
00053 {
00054     mWindow->DispatchMenuItem(id);
00055 }
00056 
00057 void CreateViewerMenus(nsIWidget *  aParentInterface, void *data, QWidget ** aMenuBarOut)
00058 {
00059     QWidget *aParent = (QWidget *)aParentInterface->GetNativeData(NS_NATIVE_WIDGET);
00060 
00061     nsBrowserWindow * window = (nsBrowserWindow *) data;
00062 
00063     nsMenuEventHandler * eventHandler = new nsMenuEventHandler(window);
00064 
00065     QMenuBar * menuBar = new QMenuBar(aParent);
00066     QPopupMenu * file = new QPopupMenu(aParent);
00067     QObject::connect(file,
00068                      SIGNAL(activated(int)),
00069                      eventHandler,
00070                      SLOT(MenuItemActivated(int)));
00071     QPopupMenu * samples = new QPopupMenu(aParent);
00072     QObject::connect(samples,
00073                      SIGNAL(activated(int)),
00074                      eventHandler,
00075                      SLOT(MenuItemActivated(int)));
00076     QPopupMenu * xptests = new QPopupMenu(aParent);
00077     QObject::connect(xptests,
00078                      SIGNAL(activated(int)),
00079                      eventHandler,
00080                      SLOT(MenuItemActivated(int)));
00081     QPopupMenu * edit = new QPopupMenu(aParent);
00082     QObject::connect(edit,
00083                      SIGNAL(activated(int)),
00084                      eventHandler,
00085                      SLOT(MenuItemActivated(int)));
00086     QPopupMenu * debug = new QPopupMenu(aParent);
00087     QObject::connect(debug,
00088                      SIGNAL(activated(int)),
00089                      eventHandler,
00090                      SLOT(MenuItemActivated(int)));
00091     QPopupMenu * eventdebug = new QPopupMenu(aParent);
00092     QObject::connect(eventdebug,
00093                      SIGNAL(activated(int)),
00094                      eventHandler,
00095                      SLOT(MenuItemActivated(int)));
00096     QPopupMenu * style = new QPopupMenu(aParent);
00097     QObject::connect(style,
00098                      SIGNAL(activated(int)),
00099                      eventHandler,
00100                      SLOT(MenuItemActivated(int)));
00101     QPopupMenu * tools = new QPopupMenu(aParent);
00102     QObject::connect(tools,
00103                      SIGNAL(activated(int)),
00104                      eventHandler,
00105                      SLOT(MenuItemActivated(int)));
00106     QPopupMenu * select = new QPopupMenu(aParent);
00107     QObject::connect(select,
00108                      SIGNAL(activated(int)),
00109                      eventHandler,
00110                      SLOT(MenuItemActivated(int)));
00111     QPopupMenu * compatibility = new QPopupMenu(aParent);
00112     QObject::connect(compatibility,
00113                      SIGNAL(activated(int)),
00114                      eventHandler,
00115                      SLOT(MenuItemActivated(int)));
00116     QPopupMenu * render = new QPopupMenu(aParent);
00117     QObject::connect(render,
00118                      SIGNAL(activated(int)),
00119                      eventHandler,
00120                      SLOT(MenuItemActivated(int)));
00121 
00122     InsertMenuItem(file, "&New Window", eventHandler, VIEWER_WINDOW_OPEN);
00123     InsertMenuItem(file, "&Open", eventHandler, VIEWER_FILE_OPEN);
00124     InsertMenuItem(file, "&View Source", eventHandler, VIEW_SOURCE);
00125 
00126     InsertMenuItem(samples, "demo #0", eventHandler, VIEWER_DEMO0);
00127     InsertMenuItem(samples, "demo #1", eventHandler, VIEWER_DEMO1);
00128     InsertMenuItem(samples, "demo #2", eventHandler, VIEWER_DEMO2);
00129     InsertMenuItem(samples, "demo #3", eventHandler, VIEWER_DEMO3);
00130     InsertMenuItem(samples, "demo #4", eventHandler, VIEWER_DEMO4);
00131     InsertMenuItem(samples, "demo #5", eventHandler, VIEWER_DEMO5);
00132     InsertMenuItem(samples, "demo #6", eventHandler, VIEWER_DEMO6);
00133     InsertMenuItem(samples, "demo #7", eventHandler, VIEWER_DEMO7);
00134     InsertMenuItem(samples, "demo #8", eventHandler, VIEWER_DEMO8);
00135     InsertMenuItem(samples, "demo #9", eventHandler, VIEWER_DEMO9);
00136     InsertMenuItem(samples, "demo #10", eventHandler, VIEWER_DEMO10);
00137     InsertMenuItem(samples, "demo #11", eventHandler, VIEWER_DEMO11);
00138     InsertMenuItem(samples, "demo #12", eventHandler, VIEWER_DEMO12);
00139     InsertMenuItem(samples, "demo #13", eventHandler, VIEWER_DEMO13);
00140     InsertMenuItem(samples, "demo #14", eventHandler, VIEWER_DEMO14);
00141     InsertMenuItem(samples, "demo #15", eventHandler, VIEWER_DEMO15);
00142     InsertMenuItem(samples, "demo #16", eventHandler, VIEWER_DEMO16);
00143     InsertMenuItem(samples, "demo #17", eventHandler, VIEWER_DEMO17);
00144 
00145     file->insertItem("&Samples", samples);
00146 
00147     InsertMenuItem(file, "&Test Sites", eventHandler, VIEWER_TOP100);
00148 
00149     InsertMenuItem(xptests, "Toolbar Test 1", eventHandler, VIEWER_XPTOOLKITTOOLBAR1);
00150     InsertMenuItem(xptests, "Tree Test 1", eventHandler, VIEWER_XPTOOLKITTREE1);
00151 
00152     file->insertItem("XPToolkit Tests", xptests);
00153 
00154     InsertMenuItem(file, nsnull, nsnull, 0);
00155     InsertMenuItem(file, "Print Preview", eventHandler, VIEWER_ONE_COLUMN);
00156     InsertMenuItem(file, "Print", eventHandler, VIEWER_PRINT);
00157     InsertMenuItem(file, nsnull, nsnull, 0);
00158     InsertMenuItem(file, "&Exit", eventHandler, VIEWER_EXIT);
00159 
00160     InsertMenuItem(edit, "Cu&t", eventHandler, VIEWER_EDIT_CUT);
00161     InsertMenuItem(edit, "&Copy", eventHandler, VIEWER_EDIT_COPY);
00162     InsertMenuItem(edit, "&Paste", eventHandler, VIEWER_EDIT_PASTE);
00163     InsertMenuItem(edit, nsnull, nsnull, 0);
00164     InsertMenuItem(edit, "Select All", eventHandler, VIEWER_EDIT_SELECTALL);
00165     InsertMenuItem(edit, nsnull, nsnull, 0);
00166     InsertMenuItem(edit, "Find in Page", eventHandler, VIEWER_EDIT_FINDINPAGE);
00167 
00168     InsertMenuItem(debug, "&Visual Debugging", eventHandler, VIEWER_VISUAL_DEBUGGING);
00169     InsertMenuItem(debug, nsnull, nsnull, 0);
00170 
00171     InsertMenuItem(eventdebug, "Toggle Paint Flashing", eventHandler, VIEWER_TOGGLE_PAINT_FLASHING);
00172     InsertMenuItem(eventdebug, "Toggle Paint Dumping", eventHandler, VIEWER_TOGGLE_PAINT_DUMPING);
00173     InsertMenuItem(eventdebug, "Toggle Invalidate Dumping", eventHandler, VIEWER_TOGGLE_INVALIDATE_DUMPING);
00174     InsertMenuItem(eventdebug, "Toggle Event Dumping", eventHandler, VIEWER_TOGGLE_EVENT_DUMPING);
00175     InsertMenuItem(eventdebug, nsnull, nsnull, 0);
00176     InsertMenuItem(eventdebug, "Toggle Motion Event Dumping", eventHandler, VIEWER_TOGGLE_MOTION_EVENT_DUMPING);
00177     InsertMenuItem(eventdebug, "Toggle Crossing Event Dumping", eventHandler, VIEWER_TOGGLE_CROSSING_EVENT_DUMPING);
00178 
00179     debug->insertItem("Event Debugging", eventdebug);
00180 
00181     InsertMenuItem(debug, nsnull, nsnull, 0);
00182     InsertMenuItem(debug, "&Reflow Test", eventHandler, VIEWER_REFLOW_TEST);
00183     InsertMenuItem(debug, nsnull, nsnull, 0);
00184     InsertMenuItem(debug, "Dump &Content", eventHandler, VIEWER_DUMP_CONTENT);
00185     InsertMenuItem(debug, "Dump &Frames", eventHandler, VIEWER_DUMP_FRAMES);
00186     InsertMenuItem(debug, "Dump &Views", eventHandler, VIEWER_DUMP_VIEWS);
00187     InsertMenuItem(debug, nsnull, nsnull, 0);
00188     InsertMenuItem(debug, "Dump &Style Sheets", eventHandler, VIEWER_DUMP_STYLE_SHEETS);
00189     InsertMenuItem(debug, "Dump &Style Contexts", eventHandler, VIEWER_DUMP_STYLE_CONTEXTS);
00190     InsertMenuItem(debug, nsnull, nsnull, 0);
00191 //     InsertMenuItem(debug, "Show Content Size", eventHandler, VIEWER_SHOW_CONTENT_SIZE);
00192 //     InsertMenuItem(debug, "Show Frame Size", eventHandler, VIEWER_SHOW_FRAME_SIZE);
00193 //     InsertMenuItem(debug, "Show Style Size", eventHandler, VIEWER_SHOW_STYLE_SIZE);
00194     InsertMenuItem(debug, nsnull, nsnull, 0);
00195     InsertMenuItem(debug, "Debug Save", eventHandler, VIEWER_DEBUGSAVE);
00196     InsertMenuItem(debug, "Debug Output Text", eventHandler, VIEWER_DISPLAYTEXT);
00197     InsertMenuItem(debug, "Debug Output HTML", eventHandler, VIEWER_DISPLAYHTML);
00198     InsertMenuItem(debug, "Debug Toggle Selection", eventHandler, VIEWER_TOGGLE_SELECTION);
00199     InsertMenuItem(debug, nsnull, nsnull, 0);
00200     InsertMenuItem(debug, "Debug Robot", eventHandler, VIEWER_DEBUGROBOT);
00201     InsertMenuItem(debug, nsnull, nsnull, 0);
00202 //     InsertMenuItem(debug, "Show Content Quality", eventHandler, VIEWER_SHOW_CONTENT_QUALITY);
00203     InsertMenuItem(debug, nsnull, nsnull, 0);
00204     debug->insertItem("Style", style);
00205 
00206     InsertMenuItem(select, "List Available Sheets", eventHandler, VIEWER_SELECT_STYLE_LIST);
00207     InsertMenuItem(select, nsnull, nsnull, 0);
00208     InsertMenuItem(select, "Select Default", eventHandler, VIEWER_SELECT_STYLE_DEFAULT);
00209     InsertMenuItem(select, nsnull, nsnull, 0);
00210     InsertMenuItem(select, "Select Alternative 1", eventHandler, VIEWER_SELECT_STYLE_ONE);
00211     InsertMenuItem(select, "Select Alternative 2", eventHandler, VIEWER_SELECT_STYLE_TWO);
00212     InsertMenuItem(select, "Select Alternative 3", eventHandler, VIEWER_SELECT_STYLE_THREE);
00213     InsertMenuItem(select, "Select Alternative 4", eventHandler, VIEWER_SELECT_STYLE_FOUR);
00214 
00215     style->insertItem("Select &Style Sheet", select);
00216 
00217     InsertMenuItem(compatibility, "Use DTD", eventHandler, VIEWER_USE_DTD_MODE);
00218     InsertMenuItem(compatibility, "Nav Quirks", eventHandler, VIEWER_NAV_QUIRKS_MODE);
00219     InsertMenuItem(compatibility, "Standard", eventHandler, VIEWER_STANDARD_MODE);
00220 
00221     style->insertItem("&Compatibility Mode", compatibility);
00222 
00223     InsertMenuItem(render, "Native", eventHandler, VIEWER_NATIVE_WIDGET_MODE);
00224     InsertMenuItem(render, "Gfx", eventHandler, VIEWER_GFX_WIDGET_MODE);
00225 
00226     style->insertItem("&Widget Render Mode", render);
00227 
00228     InsertMenuItem(tools, "&JavaScript Console", eventHandler, JS_CONSOLE);
00229     InsertMenuItem(tools, "&Editor Mode", eventHandler, EDITOR_MODE);
00230 
00231     menuBar->insertItem("&File", file);
00232     menuBar->insertItem("&Edit", edit);
00233     menuBar->insertItem("&Debug", debug);
00234     menuBar->insertItem("&Tools", tools);
00235 
00236     qDebug("menubar height = %d", menuBar->height());
00237     menuBar->resize(menuBar->sizeHint());
00238     menuBar->show();
00239 }
00240 
00241 
00242 void InsertMenuItem(QPopupMenu * popup, const char * string, QObject * receiver, int id)
00243 {
00244     if (popup)
00245     {
00246         if (string)
00247         {
00248             popup->insertItem(string, id);
00249 
00250             //popup->connectItem(id, receiver, SLOT(MenuItemActivated(int)));
00251 #if 0
00252             popup->insertItem(string,
00253                               receiver,
00254                               SLOT(MenuItemActivated(int)),
00255                               0,
00256                               id);
00257 #endif
00258         }
00259         else
00260         {
00261             popup->insertSeparator();
00262         }
00263     }
00264 }