1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is mozilla.org code.
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998
20
* the Initial Developer. All Rights Reserved.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the NPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the NPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
38
#include "nsViewerApp.h"
39
#include "nsBrowserWindow.h"
40
#include "nsWidgetsCID.h"
41
#include "nsIServiceManager.h"
42
#include "nsIComponentManager.h"
43
#include "nsIMenuBar.h"
45
#include "nsIMenuItem.h"
46
#include "nsIThread.h"
52
#include "resources.h"
54
#include <photon/Pg.h>
57
extern "C" char * strsignal(int);
61
static nsNativeViewerApp* gTheApp;
63
nsNativeViewerApp::nsNativeViewerApp()
67
nsNativeViewerApp::~nsNativeViewerApp()
72
nsNativeViewerApp::Run()
74
PRINTF( ">>> nsViewerApp::Run() <<<\n" );
80
//----------------------------------------------------------------------
82
nsNativeBrowserWindow::nsNativeBrowserWindow()
86
nsNativeBrowserWindow::~nsNativeBrowserWindow()
91
nsNativeBrowserWindow::InitNativeWindow()
93
// override to do something special with platform native windows
97
extern void CreateViewerMenus(PtWidget_t*, void *);
100
nsNativeBrowserWindow::CreateMenuBar(PRInt32 aWidth)
102
PtWidget_t *mMenuBar= nsnull;
105
voidData = mWindow->GetNativeData(NS_NATIVE_WINDOW);
106
mMenuBar = PtCreateWidget( PtMenuBar, (PtWidget_t *) voidData , 0, NULL);
110
mWindow->ShowMenuBar( PR_TRUE );
111
::CreateViewerMenus(mMenuBar,this);
117
nsNativeBrowserWindow::GetMenuBarHeight(PRInt32 * aHeightOut)
119
NS_ASSERTION(nsnull != aHeightOut,"null out param.");
127
nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID)
129
// Dispatch motif-only menu code goes here
131
// Dispatch xp menu items
132
return nsBrowserWindow::DispatchMenuItem(aID);
136
void abnormal_exit_handler(int signum)
138
/* Free any shared memory that has been allocated */
142
if ( (signum == SIGSEGV)
143
|| (signum == SIGILL)
144
|| (signum == SIGABRT)
147
PR_GetCurrentThread();
148
printf("prog = viewer\npid = %d\nsignal = %s\n", getpid(), strsignal(signum));
151
printf("stack logged to someplace\n");
152
printf("need to fix xpcom/base/nsTraceRefCnt.cpp in WalkTheStack.\n");
153
nsTraceRefcntImpl::WalkTheStack(stdout);
156
printf("Sleeping for 5 minutes.\n");
157
printf("Type 'gdb viewer %d' to attach your debugger to this thread.\n", getpid());
159
printf("Done sleeping...\n");
166
//----------------------------------------------------------------------
167
int main(int argc, char **argv)
170
/* I need this to free shared memory in case of a crash */
171
signal(SIGTERM, abnormal_exit_handler);
172
signal(SIGQUIT, abnormal_exit_handler);
173
signal(SIGINT, abnormal_exit_handler);
174
signal(SIGHUP, abnormal_exit_handler);
175
signal(SIGSEGV, abnormal_exit_handler);
176
signal(SIGILL, abnormal_exit_handler);
177
signal(SIGABRT, abnormal_exit_handler);
180
nsresult rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
181
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_InitXPCOM failed");
182
if (NS_SUCCEEDED(rv)) {
183
// The toolkit service in mozilla will look in the environment
184
// to determine which toolkit to use. Yes, it is a dumb hack to
185
// force it here, but we have no choice because of toolkit specific
186
// code linked into the viewer.
187
putenv("MOZ_TOOLKIT=photon");
189
gTheApp = new nsNativeViewerApp();
190
gTheApp->Initialize(argc, argv);
195
rv = NS_ShutdownXPCOM(nsnull);
196
NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");