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 <gtk/gtk.h>
00039 
00040 #include "nsViewerApp.h"
00041 #include "nsBrowserWindow.h"
00042 #include "nsGtkMenu.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 GtkWidget * sgHackMenuBar = nsnull;
00096 
00097 nsresult
00098 nsNativeBrowserWindow::CreateMenuBar(PRInt32 aWidth)
00099 {
00100   CreateViewerMenus(mWindow,this,&sgHackMenuBar);
00101   return NS_OK;
00102 }
00103 
00104 nsresult
00105 nsNativeBrowserWindow::GetMenuBarHeight(PRInt32 * aHeightOut)
00106 {
00107   NS_ASSERTION(nsnull != aHeightOut,"null out param.");
00108 
00109   *aHeightOut = 0;
00110 
00111   if (nsnull != sgHackMenuBar && mHaveMenuBar)
00112   {
00113     *aHeightOut = sgHackMenuBar->allocation.height;
00114   }
00115 
00116   return NS_OK;
00117 }
00118 
00119 nsEventStatus
00120 nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID)
00121 {
00122   // Dispatch motif-only menu code goes here
00123 
00124   // Dispatch xp menu items
00125   return nsBrowserWindow::DispatchMenuItem(aID);
00126 }
00127 
00128 //----------------------------------------------------------------------
00129 
00130 
00131 #ifdef DEBUG_ramiro
00132 #define CRAWL_STACK_ON_SIGSEGV
00133 #endif // DEBUG_ramiro
00134 
00135 
00136 #ifdef CRAWL_STACK_ON_SIGSEGV
00137 
00138 #include <signal.h>
00139 #include <unistd.h>
00140 #include "nsTraceRefcntImpl.h"
00141 
00142 extern "C" char * strsignal(int);
00143 
00144 static char _progname[1024] = "huh?";
00145 
00146 void
00147 ah_crap_handler(int signum)
00148 {
00149 
00150   printf("prog = %s\npid = %d\nsignal = %s\n",
00151          _progname,
00152          getpid(),
00153          strsignal(signum));
00154   
00155   printf("stack logged to someplace\n");
00156   nsTraceRefcntImpl::WalkTheStack(stdout);
00157 
00158   printf("Sleeping for 5 minutes.\n");
00159   printf("Type 'gdb %s %d' to attach your debugger to this thread.\n",
00160          _progname,
00161          getpid());
00162 
00163   sleep(300);
00164 
00165   printf("Done sleeping...\n");
00166 } 
00167 #endif // CRAWL_STACK_ON_SIGSEGV
00168 
00169 int main(int argc, char **argv)
00170 {
00171 #ifdef NS_TRACE_MALLOC
00172   argc = NS_TraceMallocStartupArgs(argc, argv);
00173 #endif
00174 
00175 #ifdef CRAWL_STACK_ON_SIGSEGV
00176   strcpy(_progname,argv[0]);
00177   signal(SIGSEGV, ah_crap_handler);
00178   signal(SIGILL, ah_crap_handler);
00179   signal(SIGABRT, ah_crap_handler);
00180 #endif // CRAWL_STACK_ON_SIGSEGV
00181 
00182 #ifdef MOZ_WIDGET_GTK
00183   gtk_set_locale();
00184 #endif
00185   gtk_init(&argc, &argv);
00186 
00187   // Initialize XPCOM
00188   nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
00189   NS_ASSERTION(NS_SUCCEEDED(rv), "NS_InitXPCOM failed");
00190   if (NS_SUCCEEDED(rv)) {
00191     // The toolkit service in mozilla will look in the environment
00192     // to determine which toolkit to use.  Yes, it is a dumb hack to
00193     // force it here, but we have no choice because of toolkit specific
00194     // code linked into the viewer.
00195     putenv("MOZ_TOOLKIT=gtk");
00196 
00197     gTheApp = new nsNativeViewerApp();
00198     gTheApp->Initialize(argc, argv);
00199     gTheApp->Run();
00200     delete gTheApp;
00201 
00202      // Shutdown XPCOM
00203     rv = NS_ShutdownXPCOM(nsnull);
00204     NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
00205 
00206     // XXX This is disabled because sometimes it hangs waiting for a
00207     // netlib thread to exit, which isn't exiting :-(. Need more
00208     // shutdown logic in necko first.
00209 #if 0
00210     // Shutdown NSPR
00211     PR_LogFlush();
00212     PR_Cleanup();
00213 #endif
00214   }
00215 
00216   return 0;
00217 }