~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/webshell/tests/viewer/nsPhMain.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
4
 *
 
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/
 
9
 *
 
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
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
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.
 
21
 *
 
22
 * Contributor(s):
 
23
 *
 
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.
 
35
 *
 
36
 * ***** END LICENSE BLOCK ***** */
 
37
 
 
38
#include "nsViewerApp.h"
 
39
#include "nsBrowserWindow.h"
 
40
#include "nsWidgetsCID.h"
 
41
#include "nsIServiceManager.h"
 
42
#include "nsIComponentManager.h"
 
43
#include "nsIMenuBar.h"
 
44
#include "nsIMenu.h"
 
45
#include "nsIMenuItem.h"
 
46
#include "nsIThread.h"
 
47
 
 
48
#include <stdlib.h>
 
49
#include <signal.h>
 
50
 
 
51
#include "plevent.h"
 
52
#include "resources.h"
 
53
 
 
54
#include <photon/Pg.h>
 
55
#include <Pt.h>
 
56
 
 
57
extern "C" char * strsignal(int);
 
58
 
 
59
#define PRINTF printf
 
60
 
 
61
static nsNativeViewerApp* gTheApp;
 
62
 
 
63
nsNativeViewerApp::nsNativeViewerApp()
 
64
{
 
65
}
 
66
 
 
67
nsNativeViewerApp::~nsNativeViewerApp()
 
68
{
 
69
}
 
70
 
 
71
int
 
72
nsNativeViewerApp::Run()
 
73
{
 
74
  PRINTF( ">>> nsViewerApp::Run() <<<\n" );
 
75
  OpenWindow();
 
76
  mAppShell->Run();
 
77
  return 0;
 
78
}
 
79
 
 
80
//----------------------------------------------------------------------
 
81
 
 
82
nsNativeBrowserWindow::nsNativeBrowserWindow()
 
83
{
 
84
}
 
85
 
 
86
nsNativeBrowserWindow::~nsNativeBrowserWindow()
 
87
{
 
88
}
 
89
 
 
90
nsresult
 
91
nsNativeBrowserWindow::InitNativeWindow()
 
92
{
 
93
        // override to do something special with platform native windows
 
94
  return NS_OK;
 
95
}
 
96
 
 
97
extern void  CreateViewerMenus(PtWidget_t*, void *);
 
98
 
 
99
nsresult
 
100
nsNativeBrowserWindow::CreateMenuBar(PRInt32 aWidth)
 
101
{
 
102
  PtWidget_t *mMenuBar= nsnull;
 
103
  void        *voidData;
 
104
 
 
105
  voidData = mWindow->GetNativeData(NS_NATIVE_WINDOW);
 
106
  mMenuBar = PtCreateWidget( PtMenuBar, (PtWidget_t *) voidData , 0, NULL);
 
107
 
 
108
  if (mMenuBar)
 
109
  {
 
110
      mWindow->ShowMenuBar( PR_TRUE );
 
111
      ::CreateViewerMenus(mMenuBar,this);
 
112
  }
 
113
  return NS_OK;
 
114
}
 
115
 
 
116
nsresult
 
117
nsNativeBrowserWindow::GetMenuBarHeight(PRInt32 * aHeightOut)
 
118
{
 
119
  NS_ASSERTION(nsnull != aHeightOut,"null out param.");
 
120
 
 
121
  *aHeightOut = 31;
 
122
 
 
123
  return NS_OK;
 
124
}
 
125
 
 
126
nsEventStatus
 
127
nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID)
 
128
{
 
129
  // Dispatch motif-only menu code goes here
 
130
 
 
131
  // Dispatch xp menu items
 
132
  return nsBrowserWindow::DispatchMenuItem(aID);
 
133
}
 
134
 
 
135
 
 
136
void abnormal_exit_handler(int signum)
 
137
{
 
138
  /* Free any shared memory that has been allocated */
 
139
  PgShmemCleanup();
 
140
 
 
141
#if 1
 
142
  if (    (signum == SIGSEGV)
 
143
       || (signum == SIGILL)
 
144
           || (signum == SIGABRT)
 
145
         )
 
146
  {
 
147
    PR_GetCurrentThread();
 
148
    printf("prog = viewer\npid = %d\nsignal = %s\n", getpid(), strsignal(signum));
 
149
 
 
150
#if 0
 
151
    printf("stack logged to someplace\n");
 
152
    printf("need to fix xpcom/base/nsTraceRefCnt.cpp in WalkTheStack.\n");
 
153
    nsTraceRefcntImpl::WalkTheStack(stdout);
 
154
#endif
 
155
 
 
156
    printf("Sleeping for 5 minutes.\n");
 
157
    printf("Type 'gdb viewer %d' to attach your debugger to this thread.\n", getpid());
 
158
    sleep(300);
 
159
    printf("Done sleeping...\n");
 
160
  }
 
161
#endif
 
162
 
 
163
  _exit(1);
 
164
 
165
 
 
166
//----------------------------------------------------------------------
 
167
int main(int argc, char **argv)
 
168
{
 
169
 
 
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);
 
178
 
 
179
  // Initialize XPCOM
 
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");
 
188
        
 
189
    gTheApp = new nsNativeViewerApp();
 
190
    gTheApp->Initialize(argc, argv);
 
191
    gTheApp->Run();
 
192
    delete gTheApp;
 
193
 
 
194
    // Shutdown XPCOM
 
195
    rv = NS_ShutdownXPCOM(nsnull);
 
196
    NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
 
197
  }
 
198
  
 
199
  return 0;
 
200
}
 
201