Back to index

lightning-sunbird  0.9+nobinonly
nsPhMain.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 "nsWidgetsCID.h"
00041 #include "nsIServiceManager.h"
00042 #include "nsIComponentManager.h"
00043 #include "nsIMenuBar.h"
00044 #include "nsIMenu.h"
00045 #include "nsIMenuItem.h"
00046 #include "nsIThread.h"
00047 
00048 #include <stdlib.h>
00049 #include <signal.h>
00050 
00051 #include "plevent.h"
00052 #include "resources.h"
00053 
00054 #include <photon/Pg.h>
00055 #include <Pt.h>
00056 
00057 extern "C" char * strsignal(int);
00058 
00059 #define PRINTF printf
00060 
00061 static nsNativeViewerApp* gTheApp;
00062 
00063 nsNativeViewerApp::nsNativeViewerApp()
00064 {
00065 }
00066 
00067 nsNativeViewerApp::~nsNativeViewerApp()
00068 {
00069 }
00070 
00071 int
00072 nsNativeViewerApp::Run()
00073 {
00074   PRINTF( ">>> nsViewerApp::Run() <<<\n" );
00075   OpenWindow();
00076   mAppShell->Run();
00077   return 0;
00078 }
00079 
00080 //----------------------------------------------------------------------
00081 
00082 nsNativeBrowserWindow::nsNativeBrowserWindow()
00083 {
00084 }
00085 
00086 nsNativeBrowserWindow::~nsNativeBrowserWindow()
00087 {
00088 }
00089 
00090 nsresult
00091 nsNativeBrowserWindow::InitNativeWindow()
00092 {
00093        // override to do something special with platform native windows
00094   return NS_OK;
00095 }
00096 
00097 extern void  CreateViewerMenus(PtWidget_t*, void *);
00098 
00099 nsresult
00100 nsNativeBrowserWindow::CreateMenuBar(PRInt32 aWidth)
00101 {
00102   PtWidget_t *mMenuBar= nsnull;
00103   void        *voidData;
00104 
00105   voidData = mWindow->GetNativeData(NS_NATIVE_WINDOW);
00106   mMenuBar = PtCreateWidget( PtMenuBar, (PtWidget_t *) voidData , 0, NULL);
00107 
00108   if (mMenuBar)
00109   {
00110       mWindow->ShowMenuBar( PR_TRUE );
00111       ::CreateViewerMenus(mMenuBar,this);
00112   }
00113   return NS_OK;
00114 }
00115 
00116 nsresult
00117 nsNativeBrowserWindow::GetMenuBarHeight(PRInt32 * aHeightOut)
00118 {
00119   NS_ASSERTION(nsnull != aHeightOut,"null out param.");
00120 
00121   *aHeightOut = 31;
00122 
00123   return NS_OK;
00124 }
00125 
00126 nsEventStatus
00127 nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID)
00128 {
00129   // Dispatch motif-only menu code goes here
00130 
00131   // Dispatch xp menu items
00132   return nsBrowserWindow::DispatchMenuItem(aID);
00133 }
00134 
00135 
00136 void abnormal_exit_handler(int signum)
00137 {
00138   /* Free any shared memory that has been allocated */
00139   PgShmemCleanup();
00140 
00141 #if 1
00142   if (    (signum == SIGSEGV)
00143        || (signum == SIGILL)
00144           || (signum == SIGABRT)
00145         )
00146   {
00147     printf("prog = viewer\npid = %d\nsignal = %s\n", getpid(), strsignal(signum));
00148 
00149 #if 0
00150     printf("stack logged to someplace\n");
00151     printf("need to fix xpcom/base/nsTraceRefCnt.cpp in WalkTheStack.\n");
00152     nsTraceRefcntImpl::WalkTheStack(stdout);
00153 #endif
00154 
00155     printf("Sleeping for 5 minutes.\n");
00156     printf("Type 'gdb viewer %d' to attach your debugger to this thread.\n", getpid());
00157     sleep(300);
00158     printf("Done sleeping...\n");
00159   }
00160 #endif
00161 
00162   _exit(1);
00163 } 
00164 
00165 //----------------------------------------------------------------------
00166 int main(int argc, char **argv)
00167 {
00168 
00169   /* I need this to free shared memory in case of a crash */
00170   signal(SIGTERM, abnormal_exit_handler);
00171   signal(SIGQUIT, abnormal_exit_handler);
00172   signal(SIGINT,  abnormal_exit_handler);
00173   signal(SIGHUP,  abnormal_exit_handler);
00174   signal(SIGSEGV, abnormal_exit_handler);
00175   signal(SIGILL,  abnormal_exit_handler);
00176   signal(SIGABRT, abnormal_exit_handler);
00177 
00178   // Initialize XPCOM
00179   nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
00180   NS_ASSERTION(NS_SUCCEEDED(rv), "NS_InitXPCOM failed");
00181   if (NS_SUCCEEDED(rv)) {
00182     // The toolkit service in mozilla will look in the environment
00183     // to determine which toolkit to use.  Yes, it is a dumb hack to
00184     // force it here, but we have no choice because of toolkit specific
00185     // code linked into the viewer.
00186     putenv("MOZ_TOOLKIT=photon");
00187        
00188     gTheApp = new nsNativeViewerApp();
00189     gTheApp->Initialize(argc, argv);
00190     gTheApp->Run();
00191     delete gTheApp;
00192 
00193     // Shutdown XPCOM
00194     rv = NS_ShutdownXPCOM(nsnull);
00195     NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
00196   }
00197   
00198   return 0;
00199 }
00200