Back to index

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