Back to index

lightning-sunbird  0.9+nobinonly
nsWinMain.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 Communicator client 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  *   Michael Lowe <michael.lowe@bigfoot.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 #include <windows.h>
00039 #include "nsViewerApp.h"
00040 #include "nsBrowserWindow.h"
00041 #include "nsITimer.h"
00042 #include "JSConsole.h"
00043 #include "plevent.h"
00044 #include "nsIServiceManager.h"
00045 #include "nsWidgetsCID.h"
00046 
00047 JSConsole *gConsole;
00048 HINSTANCE gInstance, gPrevInstance;
00049 
00050 nsNativeViewerApp::nsNativeViewerApp()
00051 {
00052 }
00053 
00054 nsNativeViewerApp::~nsNativeViewerApp()
00055 {
00056 }
00057 
00058 
00059 int
00060 nsNativeViewerApp::Run() 
00061 {
00062   if (mJustShutdown)
00063     return 0;
00064 
00065   OpenWindow();
00066  
00067   // Process messages
00068   MSG  msg;
00069   int  keepGoing = 1;
00070 
00071   // Pump all messages
00072   do {
00073     // Give priority to system messages (in particular keyboard, mouse,
00074     // timer, and paint messages).
00075     // Note: on Win98 and NT 5.0 we can also use PM_QS_INPUT and PM_QS_PAINT flags.
00076     if (::PeekMessage(&msg, NULL, 0, WM_USER-1, PM_REMOVE) || 
00077       ::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
00078 
00079       keepGoing = (msg.message != WM_QUIT);
00080 
00081       // If we successfully retrieved a message then dispatch it
00082       if (keepGoing >= 0) {
00083         if (!JSConsole::sAccelTable || !gConsole || !gConsole->GetMainWindow() ||
00084           !TranslateAccelerator(gConsole->GetMainWindow(), JSConsole::sAccelTable, &msg)) {
00085           TranslateMessage(&msg);
00086           DispatchMessage(&msg);
00087         }
00088       }
00089 
00090     } else {
00091        // Block and wait for any posted application message
00092       ::WaitMessage();
00093     }
00094   } while (keepGoing != 0);
00095 
00096   return msg.wParam;
00097 }
00098 
00099 //----------------------------------------------------------------------
00100 
00101 nsNativeBrowserWindow::nsNativeBrowserWindow()
00102 {
00103 }
00104 
00105 nsNativeBrowserWindow::~nsNativeBrowserWindow()
00106 {
00107 }
00108 
00109 nsresult
00110 nsNativeBrowserWindow::InitNativeWindow()
00111 {
00112        // override to do something special with platform native windows
00113   return NS_OK;
00114 }
00115 
00116 nsresult
00117 nsNativeBrowserWindow::CreateMenuBar(PRInt32 aWidth)
00118 {
00119   HMENU menu = ::LoadMenu(gInstance, "Viewer");
00120   HWND hwnd = (HWND)mWindow->GetNativeData(NS_NATIVE_WIDGET);
00121   ::SetMenu(hwnd, menu);
00122 
00123   return NS_OK;
00124 }
00125 
00126 nsresult
00127 nsNativeBrowserWindow::GetMenuBarHeight(PRInt32 * aHeightOut)
00128 {
00129   NS_ENSURE_ARG_POINTER(aHeightOut);
00130 
00131   *aHeightOut = 0;
00132 
00133   return NS_OK;
00134 }
00135 
00136 nsEventStatus
00137 nsNativeBrowserWindow::DispatchMenuItem(PRInt32 aID)
00138 {
00139   // Dispatch windows-only menu code goes here
00140 
00141   // Dispatch xp menu items
00142   return nsBrowserWindow::DispatchMenuItem(aID);
00143 }
00144 
00145 //----------------------------------------------------------------------
00146 
00147 int main(int argc, char **argv)
00148 {
00149   nsresult rv;
00150   rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
00151   NS_ASSERTION(NS_SUCCEEDED(rv), "NS_InitXPCOM failed");
00152   nsViewerApp* app = new nsNativeViewerApp();
00153   NS_ADDREF(app);
00154   app->Initialize(argc, argv);
00155   int result = app->Run();
00156   app->Exit();  // this exit is needed for the -x case where the close box is never clicked
00157   NS_RELEASE(app);
00158   rv = NS_ShutdownXPCOM(nsnull);
00159   NS_ASSERTION(NS_SUCCEEDED(rv), "NS_ShutdownXPCOM failed");
00160   return result;
00161 }
00162 
00163 #ifndef __GNUC__
00164 int PASCAL
00165 WinMain(HINSTANCE instance, HINSTANCE prevInstance, LPSTR cmdParam, 
00166         int nCmdShow)
00167 {
00168   gInstance = instance;
00169   gPrevInstance = prevInstance;
00170   return main(0, nsnull);
00171 }
00172 #endif
00173