Back to index

lightning-sunbird  0.9+nobinonly
nsAppShellCocoa.mm
Go to the documentation of this file.
00001 /* -*- Mode: c++; tab-width: 2; indent-tabs-mode: nil; -*- */
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
00006  * Version 1.1 (the "License"); you may not use this file except in
00007  * compliance with 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 the GNU General Public License Version 2 or later (the "GPL"), or 
00026  * 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 // 
00039 // nsAppShellCocoa
00040 //
00041 // This file contains the default implementation of the application shell. Clients
00042 // may either use this implementation or write their own. If you write your
00043 // own, you must create a message sink to route events to. (The message sink
00044 // interface may change, so this comment must be updated accordingly.)
00045 //
00046 
00047 #undef DARWIN
00048 #import <Cocoa/Cocoa.h>
00049 
00050 #include "nsAppShellCocoa.h"
00051 
00052 
00053 NS_IMPL_THREADSAFE_ISUPPORTS1(nsAppShellCocoa, nsIAppShell)
00054 
00055 
00056 //-------------------------------------------------------------------------
00057 //
00058 // nsAppShellCocoa constructor
00059 //
00060 //-------------------------------------------------------------------------
00061 nsAppShellCocoa::nsAppShellCocoa()
00062 {
00063   mainPool = [[NSAutoreleasePool alloc] init];
00064 }
00065 
00066 //-------------------------------------------------------------------------
00067 //
00068 // nsAppShellCocoa destructor
00069 //
00070 //-------------------------------------------------------------------------
00071 nsAppShellCocoa::~nsAppShellCocoa()
00072 {
00073   [mainPool release];
00074 }
00075 
00076 
00077 //-------------------------------------------------------------------------
00078 //
00079 // Create the application shell
00080 //
00081 // There's reallly not a whole lot that needs to be done here. The
00082 // window will register its own interest in the necessary events
00083 // so there's no need for us to create a pump or a sink.
00084 //
00085 //-------------------------------------------------------------------------
00086 
00087 NS_IMETHODIMP
00088 nsAppShellCocoa::Create(int* argc, char ** argv)
00089 {
00090   // this call initializes NSApplication
00091   [NSApplication sharedApplication];
00092        return NS_OK;
00093 }
00094 
00095 
00096 //-------------------------------------------------------------------------
00097 //
00098 // Enter a message handler loop
00099 //
00100 //-------------------------------------------------------------------------
00101 NS_IMETHODIMP
00102 nsAppShellCocoa::Run(void)
00103 {
00104   [NSApp run];
00105   return NS_OK;
00106 }
00107 
00108 
00109 //-------------------------------------------------------------------------
00110 //
00111 // Exit appshell
00112 //
00113 //-------------------------------------------------------------------------
00114 NS_IMETHODIMP
00115 nsAppShellCocoa::Exit(void)
00116 {
00117   [NSApp stop:nil];
00118        return NS_OK;
00119 }
00120 
00121 
00122 //-------------------------------------------------------------------------
00123 //
00124 // respond to notifications that an event queue has come or gone
00125 //
00126 //-------------------------------------------------------------------------
00127 NS_IMETHODIMP
00128 nsAppShellCocoa::ListenToEventQueue(nsIEventQueue * aQueue, PRBool aListen)
00129 { 
00130   // unnecessary; handled elsewhere
00131   return NS_OK;
00132 }
00133 
00134 
00135 //-------------------------------------------------------------------------
00136 //
00137 // Prepare to process events
00138 //
00139 //-------------------------------------------------------------------------
00140 NS_IMETHODIMP
00141 nsAppShellCocoa::Spinup(void)
00142 {
00143        return NS_OK;
00144 }
00145 
00146 
00147 //-------------------------------------------------------------------------
00148 //
00149 // Stop being prepared to process events.
00150 //
00151 //-------------------------------------------------------------------------
00152 NS_IMETHODIMP
00153 nsAppShellCocoa::Spindown(void)
00154 {
00155        return NS_OK;
00156 }
00157 
00158 
00159 //
00160 // GetNativeEvent
00161 // DispatchNativeEvent
00162 //
00163 // These are generally used in the tight loop of a modal event loop. Cocoa
00164 // has other ways of dealing with this, perhaps those should be investigated
00165 // here.
00166 //
00167 
00168 NS_METHOD
00169 nsAppShellCocoa::GetNativeEvent(PRBool &aRealEvent, void *&aEvent)
00170 {
00171   aEvent = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:nil inMode:NSEventTrackingRunLoopMode dequeue:YES];
00172   aRealEvent = (aEvent != nil);
00173   return NS_OK;
00174 }
00175 
00176 NS_METHOD
00177 nsAppShellCocoa::DispatchNativeEvent(PRBool aRealEvent, void *aEvent)
00178 {
00179   if (aRealEvent)
00180     [NSApp sendEvent:(NSEvent*)aEvent];
00181   return NS_OK;
00182 }