Back to index

lightning-sunbird  0.9+nobinonly
nsQtMain.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  *     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 of the GNU General Public License Version 2 or later (the "GPL"),
00028  * or 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 "nsViewerApp.h"
00041 #include "nsBrowserWindow.h"
00042 #include "nsQtMenu.h"
00043 #include "nsIServiceManager.h"
00044 #include "nsIThread.h"
00045 #include "plevent.h"
00046 #include "prinit.h"
00047 #include "prlog.h"
00048 
00049 #ifdef NS_TRACE_MALLOC
00050 #include "nsTraceMalloc.h"
00051 #endif
00052 
00053 static nsNativeViewerApp* gTheApp;
00054 
00055 nsNativeViewerApp::nsNativeViewerApp()
00056 {
00057 }
00058 
00059 nsNativeViewerApp::~nsNativeViewerApp()
00060 {
00061 }
00062 
00063 int
00064 nsNativeViewerApp::Run()
00065 {
00066   OpenWindow();
00067   // XXX mAppShell can be set to NULL while mAppShell->Run() is running
00068   // because nsViewerApp::Exit() is called.  I don't know what should
00069   // happen, but this is a workaround that neither crashes nor leaks.
00070   // See <URL: http://bugzilla.mozilla.org/show_bug.cgi?id=28557 >
00071   nsIAppShell* theAppShell = mAppShell;
00072   NS_ADDREF(theAppShell);
00073   theAppShell->Run();
00074   NS_RELEASE(theAppShell);
00075   return 0;
00076 }
00077 
00078 //----------------------------------------------------------------------
00079 
00080 nsNativeBrowserWindow::nsNativeBrowserWindow()
00081 {
00082 }
00083 
00084 nsNativeBrowserWindow::~nsNativeBrowserWindow()
00085 {
00086 }
00087 
00088 nsresult
00089 nsNativeBrowserWindow::InitNativeWindow()
00090 {
00091        // override to do something special with platform native windows
00092   return NS_OK;
00093 }
00094 
00095 static QWidget * sgHackMenuBar = nsnull;
00096 
00097 nsresult
00098 nsNativeBrowserWindow::CreateMenuBar(PRInt32 aWidth)
00099 {
00100   CreateViewerMenus(mWindow, this, &sgHackMenuBar);
00101   mHaveMenuBar = PR_TRUE;
00102   return NS_OK;
00103 }
00104 
00105 nsresult
00106 nsNativeBrowserWindow::GetMenuBarHeight(PRInt32 * aHeightOut)
00107 {
00108   NS_ASSERTION(nsnull != aHeightOut,"null out param.");
00109 
00110   *aHeightOut = 0;
00111 
00112   if (nsnull != sgHackMenuBar && mHaveMenuBar)
00113   {
00114     *aHeightOut = sgHackMenuBar->height();
00115   }
00116 
00117   qDebug("menubar height = %d",  *aHeightOut);
00118   return NS_OK;
00119 }
00120 
00121 nsEventStatus
00122 nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID)
00123 {
00124   // Dispatch motif-only menu code goes here
00125 
00126   // Dispatch xp menu items
00127   return nsBrowserWindow::DispatchMenuItem(aID);
00128 }
00129 
00130 //----------------------------------------------------------------------
00131 
00132 
00133 #ifdef DEBUG_ramiro
00134 #define CRAWL_STACK_ON_SIGSEGV
00135 #endif // DEBUG_ramiro
00136 
00137 
00138 #ifdef CRAWL_STACK_ON_SIGSEGV
00139 
00140 #include <signal.h>
00141 #include <unistd.h>
00142 #include "nsTraceRefcntImpl.h"
00143 
00144 extern "C" char * strsignal(int);
00145 
00146 static char _progname[1024] = "huh?";
00147 
00148 void
00149 ah_crap_handler(int signum)
00150 {
00151   PR_GetCurrentThread();
00152 
00153   printf("prog = %s\npid = %d\nsignal = %s\n",
00154          _progname,
00155          getpid(),
00156          strsignal(signum));
00157 
00158   printf("stack logged to someplace\n");
00159   nsTraceRefcntImpl::WalkTheStack(stdout);
00160 
00161   printf("Sleeping for 5 minutes.\n");
00162   printf("Type 'gdb %s %d' to attach your debugger to this thread.\n",
00163          _progname,
00164          getpid());
00165 
00166   sleep(300);
00167 
00168   printf("Done sleeping...\n");
00169 }
00170 #endif // CRAWL_STACK_ON_SIGSEGV
00171 
00172 int main(int argc, char **argv)
00173 {
00174 #ifdef NS_TRACE_MALLOC
00175   argc = NS_TraceMallocStartupArgs(argc, argv);
00176 #endif
00177 
00178 #ifdef CRAWL_STACK_ON_SIGSEGV
00179   strcpy(_progname,argv[0]);
00180   signal(SIGSEGV, ah_crap_handler);
00181   signal(SIGILL, ah_crap_handler);
00182   signal(SIGABRT, ah_crap_handler);
00183 #endif // CRAWL_STACK_ON_SIGSEGV
00184 
00185   // Initialize XPCOM
00186   nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
00187   NS_ASSERTION(NS_SUCCEEDED(rv), "NS_InitXPCOM failed");
00188   if (NS_SUCCEEDED(rv)) {
00189     // The toolkit service in mozilla will look in the environment
00190     // to determine which toolkit to use.  Yes, it is a dumb hack to
00191     // force it here, but we have no choice because of toolkit specific
00192     // code linked into the viewer.
00193     putenv("MOZ_TOOLKIT=qt");
00194 
00195     gTheApp = new nsNativeViewerApp();
00196     gTheApp->Initialize(argc, argv);
00197     gTheApp->Run();
00198     delete gTheApp;
00199 
00200      // Shutdown XPCOM
00201     rv = NS_ShutdownXPCOM(nsnull);
00202     NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
00203 
00204     // XXX This is disabled because sometimes it hangs waiting for a
00205     // netlib thread to exit, which isn't exiting :-(. Need more
00206     // shutdown logic in necko first.
00207 #if 0
00208     // Shutdown NSPR
00209     PR_LogFlush();
00210     PR_Cleanup();
00211 #endif
00212   }
00213 
00214   return 0;
00215 }