]> git.saurik.com Git - wxWidgets.git/blame - src/mac/app.cpp
title-less windows also for windows
[wxWidgets.git] / src / mac / app.cpp
CommitLineData
e9576ca5
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: app.cpp
3// Purpose: wxApp
4// Author: AUTHOR
5// Modified by:
6// Created: ??/??/98
7// RCS-ID: $Id$
8// Copyright: (c) AUTHOR
8461e4c2 9// Licence: wxWindows licence
e9576ca5
SC
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "app.h"
14#endif
15
df06d1a4
GD
16#include "wx/defs.h"
17
03e11df5 18#include "wx/window.h"
e9576ca5 19#include "wx/frame.h"
e8566d35 20#include "wx/button.h"
e9576ca5
SC
21#include "wx/app.h"
22#include "wx/utils.h"
23#include "wx/gdicmn.h"
24#include "wx/pen.h"
25#include "wx/brush.h"
26#include "wx/cursor.h"
ed5b9811 27#include "wx/intl.h"
e9576ca5
SC
28#include "wx/icon.h"
29#include "wx/palette.h"
30#include "wx/dc.h"
31#include "wx/dialog.h"
32#include "wx/msgdlg.h"
33#include "wx/log.h"
34#include "wx/module.h"
35#include "wx/memory.h"
2f1ae414 36#include "wx/tooltip.h"
b3c406a5 37#include "wx/textctrl.h"
03e11df5 38#include "wx/menu.h"
e9576ca5 39#if wxUSE_WX_RESOURCES
df06d1a4 40# include "wx/resource.h"
e9576ca5
SC
41#endif
42
43#include <string.h>
44
8be97d65
SC
45// mac
46
f5c6eb5c 47#ifndef __DARWIN__
03e11df5 48 #if __option(profile)
8461e4c2 49 #include <profiler.h>
03e11df5 50 #endif
9779893b 51#endif
519cb848 52
8be97d65
SC
53#include "apprsrc.h"
54
03e11df5
GD
55#include "wx/mac/uma.h"
56#include "wx/mac/macnotfy.h"
2f1ae414 57
df06d1a4
GD
58#ifdef __DARWIN__
59# include <CoreServices/CoreServices.h>
ed581ee2
GD
60# if defined(WXMAKINGDLL)
61# include <mach-o/dyld.h>
62# endif
df06d1a4
GD
63#else
64# include <Sound.h>
65# include <Threads.h>
66# include <ToolUtils.h>
67# include <DiskInit.h>
68# include <Devices.h>
2f1ae414 69#endif
519cb848 70
e9576ca5
SC
71extern char *wxBuffer;
72extern wxList wxPendingDelete;
519cb848
SC
73extern wxList *wxWinMacWindowList;
74extern wxList *wxWinMacControlList;
e9576ca5 75
6418cb93 76wxApp *wxTheApp = NULL;
e9576ca5 77
2f1ae414 78#if !USE_SHARED_LIBRARY
e9576ca5
SC
79IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
80BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
81 EVT_IDLE(wxApp::OnIdle)
2f1ae414
SC
82 EVT_END_SESSION(wxApp::OnEndSession)
83 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession)
e9576ca5 84END_EVENT_TABLE()
2f1ae414 85#endif
e9576ca5 86
169935ad 87
8461e4c2 88const short kMacMinHeap = (29 * 1024) ;
8be97d65 89// platform specific static variables
169935ad 90
519cb848
SC
91const short kwxMacMenuBarResource = 1 ;
92const short kwxMacAppleMenuId = 1 ;
93
fbbdb7cd
GD
94WXHRGN wxApp::s_macCursorRgn = NULL;
95wxWindow* wxApp::s_captureWindow = NULL ;
96int wxApp::s_lastMouseDown = 0 ;
97long wxApp::sm_lastMessageTime = 0;
519cb848 98
fbbdb7cd
GD
99bool wxApp::s_macDefaultEncodingIsPC = true ;
100bool wxApp::s_macSupportPCMenuShortcuts = true ;
101long wxApp::s_macAboutMenuItemId = wxID_ABOUT ;
102wxString wxApp::s_macHelpMenuTitleName = "&Help" ;
519cb848 103
72055702
SC
104pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
105pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
106pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
107pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
108
109
007ae8d0 110pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long refcon )
519cb848 111{
ba2928c6 112 // GD: UNUSED wxApp* app = (wxApp*) refcon ;
8461e4c2 113 return wxTheApp->MacHandleAEODoc( (AppleEvent*) event , reply) ;
519cb848
SC
114}
115
007ae8d0 116pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long refcon )
519cb848 117{
ba2928c6 118 // GD: UNUSED wxApp* app = (wxApp*) refcon ;
8461e4c2 119 return wxTheApp->MacHandleAEOApp( (AppleEvent*) event , reply ) ;
519cb848
SC
120}
121
007ae8d0 122pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long refcon )
519cb848 123{
ba2928c6 124 // GD: UNUSED wxApp* app = (wxApp*) refcon ;
8461e4c2 125 return wxTheApp->MacHandleAEPDoc( (AppleEvent*) event , reply ) ;
519cb848
SC
126}
127
007ae8d0 128pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long refcon )
519cb848 129{
ba2928c6 130 // GD: UNUSED wxApp* app = (wxApp*) refcon ;
8461e4c2 131 return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ;
519cb848
SC
132}
133
76a5e5d2 134short wxApp::MacHandleAEODoc(const WXEVENTREF event , WXEVENTREF reply)
519cb848 135{
c1fb8167 136 SysBeep(40) ;
8461e4c2
VZ
137 ProcessSerialNumber PSN ;
138 PSN.highLongOfPSN = 0 ;
139 PSN.lowLongOfPSN = kCurrentProcess ;
140 SetFrontProcess( &PSN ) ;
141 return noErr ;
519cb848
SC
142}
143
76a5e5d2 144short wxApp::MacHandleAEPDoc(const WXEVENTREF event , WXEVENTREF reply)
519cb848 145{
8461e4c2 146 return noErr ;
519cb848
SC
147}
148
76a5e5d2 149short wxApp::MacHandleAEOApp(const WXEVENTREF event , WXEVENTREF reply)
519cb848 150{
8461e4c2 151 return noErr ;
519cb848
SC
152}
153
76a5e5d2 154short wxApp::MacHandleAEQuit(const WXEVENTREF event , WXEVENTREF reply)
519cb848 155{
8461e4c2
VZ
156 wxWindow* win = GetTopWindow() ;
157 if ( win )
158 {
159 win->Close(TRUE ) ;
160 }
161 else
162 {
163 ExitMainLoop() ;
164 }
165 return noErr ;
519cb848
SC
166}
167
df06d1a4 168char StringMac[] = "\x0d\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
8461e4c2
VZ
169 "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
170 "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf"
171 "\xb1\xb4\xb5\xb6\xbb\xbc\xbe\xbf"
172 "\xc0\xc1\xc2\xc4\xc7\xc8\xc9\xcb\xcc\xcd\xce\xcf"
173 "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xca\xdb" ;
519cb848 174
2f1ae414 175char StringANSI[] = "\x0a\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8"
8461e4c2
VZ
176 "\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC"
177 "\x86\xBA\xA2\xA3\xA7\x95\xB6\xDF\xAE\xA9\x99\xB4\xA8\xC6\xD8"
178 "\xB1\xA5\xB5\xF0\xAA\xBA\xE6\xF8"
179 "\xBF\xA1\xAC\x83\xAB\xBB\x85\xC0\xC3\xD5\x8C\x9C"
180 "\x96\x97\x93\x94\x91\x92\xF7\xFF\xA0\x80" ;
519cb848
SC
181
182void wxMacConvertFromPC( const char *from , char *to , int len )
183{
8461e4c2
VZ
184 char *c ;
185 if ( from == to )
186 {
187 for( int i = 0 ; i < len ; ++ i )
188 {
189 c = strchr( StringANSI , *from ) ;
190 if ( c != NULL )
191 {
192 *to = StringMac[ c - StringANSI] ;
193 }
194 ++to ;
195 ++from ;
196 }
197 }
198 else
199 {
200 for( int i = 0 ; i < len ; ++ i )
201 {
202 c = strchr( StringANSI , *from ) ;
203 if ( c != NULL )
204 {
205 *to = StringMac[ c - StringANSI] ;
206 }
207 else
208 {
209 *to = *from ;
210 }
211 ++to ;
212 ++from ;
213 }
214 }
519cb848
SC
215}
216
217void wxMacConvertToPC( const char *from , char *to , int len )
218{
8461e4c2
VZ
219 char *c ;
220 if ( from == to )
221 {
222 for( int i = 0 ; i < len ; ++ i )
223 {
224 c = strchr( StringMac , *from ) ;
225 if ( c != NULL )
226 {
227 *to = StringANSI[ c - StringMac] ;
228 }
229 ++to ;
230 ++from ;
231 }
232 }
233 else
234 {
235 for( int i = 0 ; i < len ; ++ i )
236 {
237 c = strchr( StringMac , *from ) ;
238 if ( c != NULL )
239 {
240 *to = StringANSI[ c - StringMac] ;
241 }
242 else
243 {
244 *to = *from ;
245 }
246 ++to ;
247 ++from ;
248 }
249 }
519cb848
SC
250}
251
9779893b 252void wxMacConvertFromPC( char * p )
519cb848 253{
8461e4c2
VZ
254 char *ptr = p ;
255 int len = strlen ( p ) ;
9779893b 256
8461e4c2 257 wxMacConvertFromPC( ptr , ptr , len ) ;
519cb848
SC
258}
259
9779893b 260void wxMacConvertFromPCForControls( char * p )
519cb848 261{
8461e4c2
VZ
262 char *ptr = p ;
263 int len = strlen ( p ) ;
264
265 wxMacConvertFromPC( ptr , ptr , len ) ;
ba2928c6 266 for ( unsigned int i = 0 ; i < strlen ( ptr ) ; i++ )
8461e4c2
VZ
267 {
268 if ( ptr[i] == '&' && ptr[i]+1 != ' ' )
269 {
270 memmove( &ptr[i] , &ptr[i+1] , strlen( &ptr[i+1] ) + 1) ;
271 }
272 }
519cb848
SC
273}
274
9779893b 275void wxMacConvertFromPC( unsigned char *p )
519cb848 276{
8461e4c2
VZ
277 char *ptr = (char*) p + 1 ;
278 int len = p[0] ;
9779893b 279
8461e4c2 280 wxMacConvertFromPC( ptr , ptr , len ) ;
519cb848
SC
281}
282
283extern char *wxBuffer ;
284
9779893b 285wxString wxMacMakeMacStringFromPC( const char * p )
519cb848 286{
8461e4c2
VZ
287 const char *ptr = p ;
288 int len = strlen ( p ) ;
289 char *buf = wxBuffer ;
290
291 if ( len >= BUFSIZ + 512 )
292 {
293 buf = new char [len+1] ;
294 }
295
296 wxMacConvertFromPC( ptr , buf , len ) ;
297 buf[len] = 0 ;
298 wxString result( buf ) ;
299 if ( buf != wxBuffer )
300 delete buf ;
301 return result ;
519cb848
SC
302}
303
304
9779893b 305void wxMacConvertToPC( char * p )
519cb848 306{
8461e4c2
VZ
307 char *ptr = p ;
308 int len = strlen ( p ) ;
9779893b 309
8461e4c2 310 wxMacConvertToPC( ptr , ptr , len ) ;
519cb848
SC
311}
312
9779893b 313void wxMacConvertToPC( unsigned char *p )
519cb848 314{
8461e4c2
VZ
315 char *ptr = (char*) p + 1 ;
316 int len = p[0] ;
9779893b 317
8461e4c2 318 wxMacConvertToPC( ptr , ptr , len ) ;
519cb848
SC
319}
320
9779893b 321wxString wxMacMakePCStringFromMac( const char * p )
519cb848 322{
8461e4c2
VZ
323 const char *ptr = p ;
324 int len = strlen ( p ) ;
325 char *buf = wxBuffer ;
326
327 if ( len >= BUFSIZ + 512 )
328 {
329 buf = new char [len+1] ;
330 }
331
332 wxMacConvertToPC( ptr , buf , len ) ;
333 buf[len] = 0 ;
334
335 wxString result( buf ) ;
336 if ( buf != wxBuffer )
337 delete buf ;
338 return result ;
519cb848 339}
169935ad 340
8461e4c2 341wxString wxMacMakeStringFromMacString( const char* from , bool mac2pcEncoding )
3d2791f1 342{
8461e4c2
VZ
343 if (mac2pcEncoding)
344 {
345 return wxMacMakePCStringFromMac( from ) ;
346 }
347 else
348 {
349 return wxString( from ) ;
350 }
3d2791f1
SC
351}
352
8461e4c2 353wxString wxMacMakeStringFromPascal( StringPtr from , bool mac2pcEncoding )
3d2791f1
SC
354{
355 // this is safe since a pascal string can never be larger than 256 bytes
356 char s[256] ;
357 CopyPascalStringToC( from , s ) ;
8461e4c2
VZ
358 if (mac2pcEncoding)
359 {
360 return wxMacMakePCStringFromMac( s ) ;
361 }
362 else
363 {
364 return wxString( s ) ;
365 }
3d2791f1
SC
366}
367
8461e4c2 368void wxMacStringToPascal( const char * from , StringPtr to , bool pc2macEncoding )
3d2791f1 369{
8461e4c2
VZ
370 if (pc2macEncoding)
371 {
372 CopyCStringToPascal( wxMacMakeMacStringFromPC( from ) , to ) ;
373 }
374 else
375 {
376 CopyCStringToPascal( from , to ) ;
377 }
3d2791f1 378}
ed581ee2
GD
379
380#if defined(WXMAKINGDLL) && !defined(__DARWIN__)
53fd991c
SC
381// we know it's there ;-)
382WXIMPORT char std::__throws_bad_alloc ;
383#endif
384
e9576ca5
SC
385bool wxApp::Initialize()
386{
fbbdb7cd 387 int error = 0 ;
9779893b 388
fbbdb7cd 389 // Mac-specific
9779893b 390
fbbdb7cd
GD
391 UMAInitToolbox( 4 ) ;
392 SetEventMask( everyEvent ) ;
8461e4c2 393 UMAShowWatchCursor() ;
8be97d65 394
fbbdb7cd
GD
395#if defined(WXMAKINGDLL) && defined(__DARWIN__)
396 // open shared library resources from here since we don't have
397 // __wxinitialize in Mach-O shared libraries
398 wxStAppResource::OpenSharedLibraryResource(NULL);
399#endif
400
4114d0af 401#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
fbbdb7cd
GD
402 AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments ,
403 NewAEEventHandlerUPP(AEHandleODoc) ,
03e11df5 404 (long) wxTheApp , FALSE ) ;
fbbdb7cd
GD
405 AEInstallEventHandler( kCoreEventClass , kAEOpenApplication ,
406 NewAEEventHandlerUPP(AEHandleOApp) ,
03e11df5 407 (long) wxTheApp , FALSE ) ;
fbbdb7cd
GD
408 AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments ,
409 NewAEEventHandlerUPP(AEHandlePDoc) ,
03e11df5 410 (long) wxTheApp , FALSE ) ;
fbbdb7cd
GD
411 AEInstallEventHandler( kCoreEventClass , kAEQuitApplication ,
412 NewAEEventHandlerUPP(AEHandleQuit) ,
03e11df5
GD
413 (long) wxTheApp , FALSE ) ;
414#else
fbbdb7cd
GD
415 AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments ,
416 NewAEEventHandlerProc(AEHandleODoc) ,
417 (long) wxTheApp , FALSE ) ;
418 AEInstallEventHandler( kCoreEventClass , kAEOpenApplication ,
419 NewAEEventHandlerProc(AEHandleOApp) ,
420 (long) wxTheApp , FALSE ) ;
421 AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments ,
422 NewAEEventHandlerProc(AEHandlePDoc) ,
423 (long) wxTheApp , FALSE ) ;
424 AEInstallEventHandler( kCoreEventClass , kAEQuitApplication ,
425 NewAEEventHandlerProc(AEHandleQuit) ,
426 (long) wxTheApp , FALSE ) ;
03e11df5 427#endif
8be97d65 428
f5c6eb5c 429#ifndef __DARWIN__
fbbdb7cd 430 // test the minimal configuration necessary
8be97d65 431
fbbdb7cd 432# if !TARGET_CARBON
8461e4c2
VZ
433 long theSystem ;
434 long theMachine;
435
436 if (Gestalt(gestaltMachineType, &theMachine) != noErr)
437 {
438 error = kMacSTRWrongMachine;
439 }
440 else if (theMachine < gestaltMacPlus)
441 {
442 error = kMacSTRWrongMachine;
443 }
444 else if (Gestalt(gestaltSystemVersion, &theSystem) != noErr )
445 {
446 error = kMacSTROldSystem ;
447 }
72055702 448 else if ( theSystem < 0x0860 )
8461e4c2
VZ
449 {
450 error = kMacSTROldSystem ;
451 }
452 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap)
453 {
454 error = kMacSTRSmallSize;
455 }
fbbdb7cd 456# endif
8461e4c2
VZ
457 /*
458 else
459 {
460 if ( !UMAHasAppearance() )
461 {
462 error = kMacSTRNoPre8Yet ;
463 }
464 }
465 */
ed5b9811 466#endif
8be97d65 467
8461e4c2 468 // if we encountered any problems so far, give the error code and exit immediately
9779893b 469
169935ad 470 if ( error )
9779893b 471 {
53fd991c 472 wxStAppResource resload ;
8461e4c2
VZ
473 short itemHit;
474 Str255 message;
475
476 GetIndString(message, 128, error);
477 UMAShowArrowCursor() ;
478 ParamText("\pFatal Error", message, (ConstStr255Param)"\p", (ConstStr255Param)"\p");
479 itemHit = Alert(128, nil);
480 return FALSE ;
9779893b 481 }
519cb848 482
f5c6eb5c 483#ifndef __DARWIN__
fbbdb7cd 484# if __option(profile)
8461e4c2 485 ProfilerInit( collectDetailed, bestTimeBase , 20000 , 40 ) ;
fbbdb7cd 486# endif
9779893b 487#endif
519cb848 488
f5c6eb5c 489#ifndef __DARWIN__
ed581ee2
GD
490 // now avoid exceptions thrown for new (bad_alloc)
491 std::__throws_bad_alloc = FALSE ;
03e11df5 492#endif
9779893b 493
8461e4c2 494 s_macCursorRgn = ::NewRgn() ;
8be97d65 495
ed581ee2
GD
496 wxBuffer = new char[BUFSIZ + 512];
497
498 wxClassInfo::InitializeClasses();
e9576ca5 499
2f1ae414
SC
500#if wxUSE_RESOURCES
501// wxGetResource(wxT("wxWindows"), wxT("OsVersion"), &wxOsVersion);
e9576ca5 502#endif
e9576ca5 503
2f1ae414
SC
504#if wxUSE_THREADS
505 wxPendingEventsLocker = new wxCriticalSection;
506#endif
ed581ee2
GD
507
508 wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
509 wxTheColourDatabase->Initialize();
e9576ca5 510
fc0daf84 511#ifdef __WXDEBUG__
0a67a93b
SC
512#if wxUSE_LOG
513 // flush the logged messages if any and install a 'safer' log target: the
514 // default one (wxLogGui) can't be used after the resources are freed just
515 // below and the user suppliedo ne might be even more unsafe (using any
516 // wxWindows GUI function is unsafe starting from now)
517 wxLog::DontCreateOnDemand();
518
519 // this will flush the old messages if any
520 delete wxLog::SetActiveTarget(new wxLogStderr);
521#endif // wxUSE_LOG
fc0daf84 522#endif
0a67a93b 523
0a6cce3b
SC
524 wxWinMacWindowList = new wxList(wxKEY_INTEGER);
525 wxWinMacControlList = new wxList(wxKEY_INTEGER);
526
e9576ca5
SC
527 wxInitializeStockLists();
528 wxInitializeStockObjects();
529
530#if wxUSE_WX_RESOURCES
531 wxInitializeResourceSystem();
532#endif
533
534 wxBitmap::InitStandardHandlers();
535
536 wxModule::RegisterModules();
03e11df5 537 if (!wxModule::InitializeModules()) {
519cb848 538 return FALSE;
03e11df5 539 }
e9576ca5 540
2f1ae414 541 wxMacCreateNotifierTable() ;
9779893b 542
2f1ae414 543 UMAShowArrowCursor() ;
8461e4c2 544
e9576ca5
SC
545 return TRUE;
546}
547
548void wxApp::CleanUp()
549{
12cd5f34 550 wxToolTip::RemoveToolTips() ;
2f1ae414
SC
551#if wxUSE_LOG
552 // flush the logged messages if any and install a 'safer' log target: the
553 // default one (wxLogGui) can't be used after the resources are freed just
554 // below and the user suppliedo ne might be even more unsafe (using any
555 // wxWindows GUI function is unsafe starting from now)
556 wxLog::DontCreateOnDemand();
557
558 // this will flush the old messages if any
559 delete wxLog::SetActiveTarget(new wxLogStderr);
560#endif // wxUSE_LOG
561
562 // One last chance for pending objects to be cleaned up
563 wxTheApp->DeletePendingObjects();
564
fbbdb7cd 565 wxModule::CleanUpModules();
e9576ca5
SC
566
567#if wxUSE_WX_RESOURCES
fbbdb7cd 568 wxCleanUpResourceSystem();
e9576ca5
SC
569#endif
570
fbbdb7cd 571 wxDeleteStockObjects() ;
e9576ca5 572
2f1ae414
SC
573 // Destroy all GDI lists, etc.
574 wxDeleteStockLists();
e9576ca5 575
fbbdb7cd
GD
576 delete wxTheColourDatabase;
577 wxTheColourDatabase = NULL;
e9576ca5 578
fbbdb7cd 579 wxBitmap::CleanUpHandlers();
519cb848 580
fbbdb7cd
GD
581 delete[] wxBuffer;
582 wxBuffer = NULL;
12cd5f34 583
fbbdb7cd
GD
584 wxMacDestroyNotifierTable() ;
585 if (wxWinMacWindowList) {
586 delete wxWinMacWindowList ;
587 }
588 if (wxWinMacControlList) {
589 delete wxWinMacControlList ;
590 }
2f1ae414 591 delete wxPendingEvents;
fbbdb7cd 592
2f1ae414
SC
593#if wxUSE_THREADS
594 delete wxPendingEventsLocker;
595 // If we don't do the following, we get an apparent memory leak.
596 ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker();
597#endif
598
fbbdb7cd 599 wxClassInfo::CleanUpClasses();
e9576ca5 600
f5c6eb5c 601#ifndef __DARWIN__
fbbdb7cd
GD
602# if __option(profile)
603 ProfilerDump( "\papp.prof" ) ;
604 ProfilerTerm() ;
605# endif
9779893b 606#endif
519cb848 607
fbbdb7cd
GD
608 delete wxTheApp;
609 wxTheApp = NULL;
9779893b 610
e9576ca5 611#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
2f1ae414
SC
612 // At this point we want to check if there are any memory
613 // blocks that aren't part of the wxDebugContext itself,
614 // as a special case. Then when dumping we need to ignore
615 // wxDebugContext, too.
616 if (wxDebugContext::CountObjectsLeft(TRUE) > 0)
617 {
618 wxLogDebug(wxT("There were memory leaks."));
619 wxDebugContext::Dump();
620 wxDebugContext::PrintStatistics();
621 }
622 // wxDebugContext::SetStream(NULL, NULL);
e9576ca5 623#endif
9779893b 624
2f1ae414
SC
625#if wxUSE_LOG
626 // do it as the very last thing because everything else can log messages
627 delete wxLog::SetActiveTarget(NULL);
628#endif // wxUSE_LOG
169935ad 629
fbbdb7cd
GD
630#if defined(WXMAKINGDLL) && defined(__DARWIN__)
631 // close shared library resources from here since we don't have
632 // __wxterminate in Mach-O shared libraries
633 wxStAppResource::CloseSharedLibraryResource();
634#endif
635
8461e4c2 636 UMACleanupToolbox() ;
fbbdb7cd 637 if (s_macCursorRgn) {
76a5e5d2 638 ::DisposeRgn((RgnHandle)s_macCursorRgn);
fbbdb7cd
GD
639 }
640
8461e4c2
VZ
641 #if 0
642 TerminateAE() ;
643 #endif
e9576ca5
SC
644}
645
92b002a4
RD
646//----------------------------------------------------------------------
647// wxEntry
648//----------------------------------------------------------------------
649
fbbdb7cd
GD
650// extern variable for shared library resource id
651// need to be able to find it with NSLookupAndBindSymbol
652short gSharedLibraryResource = kResFileNotOpened ;
653
ed581ee2 654#if defined(WXMAKINGDLL) && defined(__DARWIN__)
fbbdb7cd 655CFBundleRef gSharedLibraryBundle = NULL;
ed581ee2 656#endif /* WXMAKINGDLL && __DARWIN__ */
53fd991c
SC
657
658wxStAppResource::wxStAppResource()
659{
fbbdb7cd
GD
660 m_currentRefNum = CurResFile() ;
661 if ( gSharedLibraryResource != kResFileNotOpened )
662 {
663 UseResFile( gSharedLibraryResource ) ;
664 }
665}
666
667wxStAppResource::~wxStAppResource()
668{
669 if ( m_currentRefNum != kResFileNotOpened )
670 {
671 UseResFile( m_currentRefNum ) ;
672 }
673}
674
675void wxStAppResource::OpenSharedLibraryResource(const void *initBlock)
676{
677 gSharedLibraryResource = kResFileNotOpened;
678
679#ifdef WXMAKINGDLL
680 if ( initBlock != NULL ) {
681 const CFragInitBlock *theInitBlock = (const CFragInitBlock *)initBlock;
682 FSSpec *fileSpec = NULL;
683
684 if (theInitBlock->fragLocator.where == kDataForkCFragLocator) {
685 fileSpec = theInitBlock->fragLocator.u.onDisk.fileSpec;
686 }
687 else if (theInitBlock->fragLocator.where == kResourceCFragLocator) {
688 fileSpec = theInitBlock->fragLocator.u.inSegs.fileSpec;
689 }
690
691 if (fileSpec != NULL) {
692 gSharedLibraryResource = FSpOpenResFile(fileSpec, fsRdPerm);
693 }
694 }
695 else {
696#ifdef __DARWIN__
697 // Open the shared library resource file if it is not yet open
ed581ee2
GD
698 NSSymbol theSymbol;
699 NSModule theModule;
700 const char *theLibPath;
701
fbbdb7cd
GD
702 gSharedLibraryBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWindows"));
703 if (gSharedLibraryBundle != NULL) {
ed581ee2
GD
704 // wxWindows has been bundled into a framework
705 // load the framework resources
706
fbbdb7cd 707 gSharedLibraryResource = CFBundleOpenBundleResourceMap(gSharedLibraryBundle);
ed581ee2
GD
708 }
709 else {
710 // wxWindows is a simple dynamic shared library
711 // load the resources from the data fork of a separate resource file
712 char *theResPath;
713 char *theName;
714 char *theExt;
715 FSRef theResRef;
716 OSErr theErr = noErr;
717
718 // get the library path
fbbdb7cd 719 theSymbol = NSLookupAndBindSymbol("_gSharedLibraryResource");
ed581ee2
GD
720 theModule = NSModuleForSymbol(theSymbol);
721 theLibPath = NSLibraryNameForModule(theModule);
ed581ee2
GD
722
723 // allocate copy to replace .dylib.* extension with .rsrc
724 theResPath = strdup(theLibPath);
725 if (theResPath != NULL) {
726 theName = strrchr(theResPath, '/');
727 if (theName == NULL) {
728 // no directory elements in path
729 theName = theResPath;
730 }
731 // find ".dylib" shared library extension
732 theExt = strstr(theName, ".dylib");
733 // overwrite extension with ".rsrc"
734 strcpy(theExt, ".rsrc");
735
736 wxLogDebug( theResPath );
737
738 theErr = FSPathMakeRef((UInt8 *) theResPath, &theResRef, false);
739 if (theErr != noErr) {
740 // try in current directory (using name only)
741 theErr = FSPathMakeRef((UInt8 *) theName, &theResRef, false);
742 }
743
744 // free duplicated resource file path
745 free(theResPath);
746
747 // open the resource file
748 if (theErr == noErr) {
749 theErr = FSOpenResourceFile( &theResRef, 0, NULL, fsRdPerm,
fbbdb7cd 750 &gSharedLibraryResource);
ed581ee2
GD
751 }
752 }
753 }
fbbdb7cd 754#endif /* __DARWIN__ */
53fd991c 755 }
fbbdb7cd 756#endif /* WXMAKINGDLL */
53fd991c
SC
757}
758
fbbdb7cd 759void wxStAppResource::CloseSharedLibraryResource()
53fd991c 760{
fbbdb7cd 761#ifdef WXMAKINGDLL
ed581ee2 762 // Close the shared library resource file
fbbdb7cd
GD
763 if (gSharedLibraryResource != kResFileNotOpened) {
764#ifdef __DARWIN__
765 if (gSharedLibraryBundle != NULL) {
766 CFBundleCloseBundleResourceMap(gSharedLibraryBundle,
767 gSharedLibraryResource);
768 gSharedLibraryBundle = NULL;
ed581ee2 769 }
fbbdb7cd
GD
770 else
771#endif /* __DARWIN__ */
772 {
773 CloseResFile(gSharedLibraryResource);
ed581ee2 774 }
fbbdb7cd
GD
775 gSharedLibraryResource = kResFileNotOpened;
776 }
777#endif /* WXMAKINGDLL */
53fd991c
SC
778}
779
ed581ee2 780#if defined(WXMAKINGDLL) && !defined(__DARWIN__)
53fd991c 781
ed581ee2
GD
782// for shared libraries we have to manually get the correct resource
783// ref num upon initializing and releasing when terminating, therefore
784// the __wxinitialize and __wxterminate must be used
53fd991c 785
53fd991c 786extern "C" {
fbbdb7cd
GD
787 void __sinit(void); /* (generated by linker) */
788 pascal OSErr __initialize(const CFragInitBlock *theInitBlock);
789 pascal void __terminate(void);
53fd991c 790}
53fd991c
SC
791
792pascal OSErr __wxinitialize(const CFragInitBlock *theInitBlock)
793{
fbbdb7cd
GD
794 wxStAppResource::OpenSharedLibraryResource( theInitBlock ) ;
795 return __initialize( theInitBlock ) ;
53fd991c
SC
796}
797
798pascal void __wxterminate(void)
799{
fbbdb7cd 800 wxStAppResource::CloseSharedLibraryResource() ;
53fd991c
SC
801 __terminate() ;
802}
ed581ee2
GD
803
804#endif /* WXMAKINGDLL && !__DARWIN__ */
53fd991c
SC
805
806int WXDLLEXPORT wxEntryStart( int argc, char *argv[] )
92b002a4
RD
807{
808 return wxApp::Initialize();
809}
810
53fd991c 811int WXDLLEXPORT wxEntryInitGui()
92b002a4
RD
812{
813 return wxTheApp->OnInitGui();
814}
815
53fd991c 816void WXDLLEXPORT wxEntryCleanup()
92b002a4
RD
817{
818 wxApp::CleanUp();
819}
820
2f1ae414 821int wxEntry( int argc, char *argv[] , bool enterLoop )
e9576ca5 822{
7c551d95
SC
823#ifdef __MWERKS__
824#if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
825 // This seems to be necessary since there are 'rogue'
826 // objects present at this point (perhaps global objects?)
827 // Setting a checkpoint will ignore them as far as the
828 // memory checking facility is concerned.
829 // Of course you may argue that memory allocated in globals should be
830 // checked, but this is a reasonable compromise.
831 wxDebugContext::SetCheckpoint();
832#endif
833#endif
92b002a4 834 if (!wxEntryStart(argc, argv)) {
2f1ae414 835 return 0;
03e11df5 836 }
2f1ae414
SC
837 // create the application object or ensure that one already exists
838 if (!wxTheApp)
e9576ca5 839 {
2f1ae414
SC
840 // The app may have declared a global application object, but we recommend
841 // the IMPLEMENT_APP macro is used instead, which sets an initializer
842 // function for delayed, dynamic app object construction.
843 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
844 wxT("No initializer - use IMPLEMENT_APP macro.") );
9779893b 845
2f1ae414
SC
846 wxTheApp = (wxApp*) (*wxApp::GetInitializerFunction()) ();
847 }
9779893b 848
2f1ae414 849 wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") );
e9576ca5 850
e94e53ac
GD
851#ifdef __DARWIN__
852 // Mac OS X passes a process serial number command line argument when
853 // the application is launched from the Finder. This argument must be
854 // removed from the command line arguments before being handled by the
855 // application (otherwise applications would need to handle it)
856
857 if (argc > 1) {
ed581ee2
GD
858 char theArg[6] = "";
859 strncpy(theArg, argv[1], 5);
e94e53ac 860
ed581ee2 861 if (strcmp(theArg, "-psn_") == 0) {
e94e53ac
GD
862 // assume the argument is always the only one and remove it
863 --argc;
864 }
865 }
866#else
89ebf1c9 867 argc = 0 ; // currently we don't support files as parameters
519cb848 868#endif
89ebf1c9 869 // we could try to get the open apple events here to adjust argc and argv better
519cb848 870
89ebf1c9
RR
871 wxTheApp->argc = argc;
872 wxTheApp->argv = argv;
9779893b 873
89ebf1c9
RR
874 // GUI-specific initialization, such as creating an app context.
875 wxEntryInitGui();
9779893b 876
89ebf1c9
RR
877 // Here frames insert themselves automatically
878 // into wxTopLevelWindows by getting created
879 // in OnInit().
9779893b 880
89ebf1c9 881 int retValue = 0;
9779893b 882
8461e4c2
VZ
883 if ( wxTheApp->OnInit() )
884 {
885 if ( enterLoop )
886 {
887 retValue = wxTheApp->OnRun();
888 }
889 else
890 // We want to initialize, but not run or exit immediately.
891 return 1;
892 }
893 //else: app initialization failed, so we skipped OnRun()
894
895 wxWindow *topWindow = wxTheApp->GetTopWindow();
896 if ( topWindow )
897 {
898 // Forcibly delete the window.
899 if ( topWindow->IsKindOf(CLASSINFO(wxFrame)) ||
900 topWindow->IsKindOf(CLASSINFO(wxDialog)) )
901 {
902 topWindow->Close(TRUE);
903 wxTheApp->DeletePendingObjects();
904 }
905 else
906 {
907 delete topWindow;
908 wxTheApp->SetTopWindow(NULL);
909 }
910 }
911
912 wxTheApp->OnExit();
913
92b002a4 914 wxEntryCleanup();
8461e4c2
VZ
915
916 return retValue;
03e11df5 917}
e9576ca5
SC
918
919// Static member initialization
2f1ae414 920wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL;
e9576ca5
SC
921
922wxApp::wxApp()
923{
924 m_topWindow = NULL;
925 wxTheApp = this;
2f1ae414 926
1b21409b
JS
927#if WXWIN_COMPATIBILITY_2_2
928 m_wantDebugOutput = TRUE;
929#endif
2f1ae414 930
e9576ca5
SC
931 argc = 0;
932 argv = NULL;
519cb848 933
e9576ca5 934 m_printMode = wxPRINT_WINDOWS;
e9576ca5
SC
935 m_exitOnFrameDelete = TRUE;
936 m_auto3D = TRUE;
937}
938
939bool wxApp::Initialized()
940{
519cb848 941 if (GetTopWindow())
e9576ca5 942 return TRUE;
519cb848
SC
943 else
944 return FALSE;
e9576ca5
SC
945}
946
947int wxApp::MainLoop()
948{
949 m_keepGoing = TRUE;
950
e9576ca5
SC
951 while (m_keepGoing)
952 {
8461e4c2 953 MacDoOneEvent() ;
e9576ca5 954 }
e9576ca5
SC
955
956 return 0;
957}
958
959// Returns TRUE if more time is needed.
960bool wxApp::ProcessIdle()
961{
962 wxIdleEvent event;
963 event.SetEventObject(this);
964 ProcessEvent(event);
965
966 return event.MoreRequested();
967}
968
969void wxApp::ExitMainLoop()
970{
971 m_keepGoing = FALSE;
972}
973
974// Is a message/event pending?
975bool wxApp::Pending()
976{
8461e4c2 977 EventRecord event ;
519cb848
SC
978
979 return EventAvail( everyEvent , &event ) ;
e9576ca5
SC
980}
981
982// Dispatch a message.
983void wxApp::Dispatch()
984{
8461e4c2 985 MacDoOneEvent() ;
e9576ca5
SC
986}
987
988void wxApp::OnIdle(wxIdleEvent& event)
989{
2f1ae414 990 static bool s_inOnIdle = FALSE;
e9576ca5 991
2f1ae414
SC
992 // Avoid recursion (via ProcessEvent default case)
993 if ( s_inOnIdle )
994 return;
e9576ca5 995
2f1ae414
SC
996
997 s_inOnIdle = TRUE;
e9576ca5
SC
998
999 // 'Garbage' collection of windows deleted with Close().
1000 DeletePendingObjects();
1001
1002 // flush the logged messages if any
1003 wxLog *pLog = wxLog::GetActiveTarget();
1004 if ( pLog != NULL && pLog->HasPendingMessages() )
1005 pLog->Flush();
1006
1007 // Send OnIdle events to all windows
1008 bool needMore = SendIdleEvents();
1009
1010 if (needMore)
1011 event.RequestMore(TRUE);
1012
2f1ae414
SC
1013 // If they are pending events, we must process them: pending events are
1014 // either events to the threads other than main or events posted with
1015 // wxPostEvent() functions
1016 wxMacProcessNotifierAndPendingEvents();
1017
1018 s_inOnIdle = FALSE;
e9576ca5
SC
1019}
1020
9779893b
RD
1021void wxWakeUpIdle()
1022{
8461e4c2 1023 wxMacWakeUp() ;
9779893b
RD
1024}
1025
e9576ca5
SC
1026// Send idle event to all top-level windows
1027bool wxApp::SendIdleEvents()
1028{
1029 bool needMore = FALSE;
8461e4c2
VZ
1030 wxNode* node = wxTopLevelWindows.First();
1031 while (node)
1032 {
1033 wxWindow* win = (wxWindow*) node->Data();
1034 if (SendIdleEvents(win))
e9576ca5
SC
1035 needMore = TRUE;
1036
8461e4c2
VZ
1037 node = node->Next();
1038 }
e9576ca5
SC
1039 return needMore;
1040}
1041
1042// Send idle event to window and all subwindows
1043bool wxApp::SendIdleEvents(wxWindow* win)
1044{
1045 bool needMore = FALSE;
1046
8461e4c2
VZ
1047 wxIdleEvent event;
1048 event.SetEventObject(win);
1049 win->ProcessEvent(event);
e9576ca5
SC
1050
1051 if (event.MoreRequested())
1052 needMore = TRUE;
1053
8461e4c2
VZ
1054 wxNode* node = win->GetChildren().First();
1055 while (node)
1056 {
1057 wxWindow* win = (wxWindow*) node->Data();
1058 if (SendIdleEvents(win))
e9576ca5
SC
1059 needMore = TRUE;
1060
8461e4c2
VZ
1061 node = node->Next();
1062 }
e9576ca5
SC
1063 return needMore ;
1064}
1065
1066void wxApp::DeletePendingObjects()
1067{
1068 wxNode *node = wxPendingDelete.First();
1069 while (node)
1070 {
1071 wxObject *obj = (wxObject *)node->Data();
9779893b 1072
e9576ca5
SC
1073 delete obj;
1074
1075 if (wxPendingDelete.Member(obj))
1076 delete node;
1077
1078 // Deleting one object may have deleted other pending
1079 // objects, so start from beginning of list again.
1080 node = wxPendingDelete.First();
1081 }
1082}
1083
e9576ca5
SC
1084void wxExit()
1085{
2f1ae414
SC
1086 wxLogError(_("Fatal error: exiting"));
1087
1088 wxApp::CleanUp();
8461e4c2 1089 ::ExitToShell() ;
e9576ca5
SC
1090}
1091
2f1ae414
SC
1092void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event))
1093{
1094 if (GetTopWindow())
1095 GetTopWindow()->Close(TRUE);
1096}
1097
1098// Default behaviour: close the application with prompts. The
1099// user can veto the close, and therefore the end session.
1100void wxApp::OnQueryEndSession(wxCloseEvent& event)
1101{
1102 if (GetTopWindow())
1103 {
1104 if (!GetTopWindow()->Close(!event.CanVeto()))
1105 event.Veto(TRUE);
1106 }
1107}
1108
1109extern "C" void wxCYield() ;
1110void wxCYield()
1111{
8461e4c2 1112 wxYield() ;
2f1ae414
SC
1113}
1114
e9576ca5 1115// Yield to other processes
cb2713bf 1116
8461e4c2 1117bool wxApp::Yield(bool onlyIfNeeded)
e9576ca5 1118{
8461e4c2
VZ
1119 static bool s_inYield = FALSE;
1120
1121 if (s_inYield)
1122 {
1123 if ( !onlyIfNeeded )
1124 {
1125 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1126 }
1127
1128 return FALSE;
1129 }
1130
1131 s_inYield = TRUE;
cb2713bf 1132
2f1ae414 1133#if wxUSE_THREADS
cb2713bf 1134 YieldToAnyThread() ;
2f1ae414 1135#endif
cb2713bf 1136 EventRecord event ;
2f1ae414 1137
8461e4c2 1138 long sleepTime = 1 ; //::GetCaretTime();
2f1ae414 1139
76a5e5d2 1140 while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn))
8461e4c2
VZ
1141 {
1142 wxTheApp->MacHandleOneEvent( &event );
1143 if ( event.what != kHighLevelEvent )
76a5e5d2 1144 SetRectRgn( (RgnHandle) wxApp::s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ;
8461e4c2 1145 }
2f1ae414 1146
8461e4c2 1147 wxMacProcessNotifierAndPendingEvents() ;
cb2713bf 1148
8461e4c2 1149 s_inYield = FALSE;
cb2713bf 1150
8461e4c2 1151 return TRUE;
169935ad
SC
1152}
1153
9779893b 1154// platform specifics
169935ad 1155
519cb848
SC
1156void wxApp::MacSuspend( bool convertClipboard )
1157{
1c469f7f 1158 // we have to deactive the top level windows manually
8461e4c2 1159
1c469f7f
SC
1160 wxNode* node = wxTopLevelWindows.First();
1161 while (node)
1162 {
1163 wxTopLevelWindow* win = (wxTopLevelWindow*) node->Data();
1164 win->MacActivate( MacGetCurrentEvent() , false ) ;
8461e4c2 1165
1c469f7f
SC
1166 node = node->Next();
1167 }
1168
1169 s_lastMouseDown = 0 ;
1170 if( convertClipboard )
1171 {
1172 MacConvertPrivateToPublicScrap() ;
1173 }
8461e4c2 1174
1c469f7f 1175 ::HideFloatingWindows() ;
519cb848
SC
1176}
1177
1178void wxApp::MacResume( bool convertClipboard )
1179{
8461e4c2
VZ
1180 s_lastMouseDown = 0 ;
1181 if( convertClipboard )
1182 {
1183 MacConvertPublicToPrivateScrap() ;
1184 }
9779893b 1185
72055702 1186 ::ShowFloatingWindows() ;
519cb848
SC
1187}
1188
1189void wxApp::MacConvertPrivateToPublicScrap()
1190{
519cb848
SC
1191}
1192
1193void wxApp::MacConvertPublicToPrivateScrap()
1194{
519cb848
SC
1195}
1196
9779893b 1197void wxApp::MacDoOneEvent()
169935ad
SC
1198{
1199 EventRecord event ;
1200
6264b550 1201 long sleepTime = 1; // GetCaretTime() / 4 ;
169935ad 1202
76a5e5d2 1203 if (WaitNextEvent(everyEvent, &event, sleepTime, (RgnHandle) s_macCursorRgn))
8461e4c2 1204 {
6264b550 1205 MacHandleOneEvent( &event );
8461e4c2
VZ
1206 }
1207 else
1208 {
1209 // idlers
72055702 1210 WindowPtr window = ::FrontWindow() ;
8461e4c2 1211 if ( window )
72055702 1212 ::IdleControls( window ) ;
9779893b 1213
8461e4c2
VZ
1214 wxTheApp->ProcessIdle() ;
1215 }
1216 if ( event.what != kHighLevelEvent )
76a5e5d2 1217 SetRectRgn( (RgnHandle) s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ;
519cb848 1218
8461e4c2 1219 // repeaters
519cb848 1220
6264b550 1221 DeletePendingObjects() ;
8461e4c2 1222 wxMacProcessNotifierAndPendingEvents() ;
169935ad
SC
1223}
1224
76a5e5d2 1225void wxApp::MacHandleOneEvent( WXEVENTREF evr )
169935ad 1226{
76a5e5d2 1227 EventRecord* ev = (EventRecord*) evr ;
8461e4c2
VZ
1228 m_macCurrentEvent = ev ;
1229
1230 wxApp::sm_lastMessageTime = ev->when ;
1231
1232 switch (ev->what)
1233 {
1234 case mouseDown:
1235 MacHandleMouseDownEvent( ev ) ;
1236 if ( ev->modifiers & controlKey )
1237 s_lastMouseDown = 2;
1238 else
1239 s_lastMouseDown = 1;
1240 break;
1241 case mouseUp:
1242 if ( s_lastMouseDown == 2 )
1243 {
1244 ev->modifiers |= controlKey ;
1245 }
1246 else
1247 {
1248 ev->modifiers &= ~controlKey ;
1249 }
1250 MacHandleMouseUpEvent( ev ) ;
1251 s_lastMouseDown = 0;
1252 break;
1253 case activateEvt:
1254 MacHandleActivateEvent( ev ) ;
1255 break;
1256 case updateEvt:
1257 MacHandleUpdateEvent( ev ) ;
1258 break;
1259 case keyDown:
1260 case autoKey:
1261 MacHandleKeyDownEvent( ev ) ;
1262 break;
1263 case keyUp:
1264 MacHandleKeyUpEvent( ev ) ;
1265 break;
1266 case diskEvt:
1267 MacHandleDiskEvent( ev ) ;
1268 break;
1269 case osEvt:
1270 MacHandleOSEvent( ev ) ;
1271 break;
1272 case kHighLevelEvent:
1273 MacHandleHighLevelEvent( ev ) ;
1274 break;
1275 default:
1276 break;
1277 }
1278 wxMacProcessNotifierAndPendingEvents() ;
169935ad
SC
1279}
1280
76a5e5d2 1281void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr )
169935ad 1282{
76a5e5d2 1283 EventRecord* ev = (EventRecord*) evr ;
8461e4c2 1284 ::AEProcessAppleEvent( ev ) ;
169935ad
SC
1285}
1286
519cb848
SC
1287bool s_macIsInModalLoop = false ;
1288
76a5e5d2 1289void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr )
169935ad 1290{
76a5e5d2 1291 EventRecord* ev = (EventRecord*) evr ;
8461e4c2 1292 wxToolTip::RemoveToolTips() ;
2f1ae414 1293
8461e4c2 1294 WindowRef window;
72055702 1295 WindowRef frontWindow = ::FrontNonFloatingWindow() ;
8461e4c2
VZ
1296 WindowAttributes frontWindowAttributes = NULL ;
1297 if ( frontWindow )
72055702 1298 ::GetWindowAttributes( frontWindow , &frontWindowAttributes ) ;
9779893b 1299
8461e4c2 1300 short windowPart = ::FindWindow(ev->where, &window);
a3722eeb 1301 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
0a67a93b
SC
1302 if ( wxPendingDelete.Member(win) )
1303 return ;
9779893b 1304
8461e4c2
VZ
1305 BitMap screenBits;
1306 GetQDGlobalsScreenBits( &screenBits );
1307
1308 switch (windowPart)
1309 {
1310 case inMenuBar :
1311 if ( s_macIsInModalLoop )
1312 {
1313 SysBeep ( 30 ) ;
1314 }
1315 else
1316 {
1317 UInt32 menuresult = MenuSelect(ev->where) ;
1318 MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) );
1319 s_lastMouseDown = 0;
1320 }
1321 break ;
2f1ae414 1322#if !TARGET_CARBON
8461e4c2
VZ
1323 case inSysWindow :
1324 SystemClick( ev , window ) ;
1325 s_lastMouseDown = 0;
1326 break ;
2f1ae414 1327#endif
8461e4c2
VZ
1328 case inDrag :
1329 if ( window != frontWindow && s_macIsInModalLoop && !(ev->modifiers & cmdKey ) )
1330 {
1331 SysBeep ( 30 ) ;
1332 }
1333 else
1334 {
1335 DragWindow(window, ev->where, &screenBits.bounds);
1336 if (win)
1337 {
1338 GrafPtr port ;
1339 GetPort( &port ) ;
1340 Point pt = { 0, 0 } ;
66a09d47 1341 SetPortWindowPort(window) ;
8461e4c2
VZ
1342 LocalToGlobal( &pt ) ;
1343 SetPort( port ) ;
1344 win->SetSize( pt.h , pt.v , -1 ,
1345 -1 , wxSIZE_USE_EXISTING);
1346 }
1347 s_lastMouseDown = 0;
1348 }
1349 break ;
1350 case inGoAway:
1351 if (TrackGoAway(window, ev->where))
1352 {
1353 if ( win )
1354 win->Close() ;
1355 }
1356 s_lastMouseDown = 0;
1357 break;
1358 case inGrow:
1359 {
1360 int growResult = GrowWindow(window , ev->where, &screenBits.bounds);
1361 if (growResult != 0)
1362 {
1363 int newWidth = LoWord(growResult);
1364 int newHeight = HiWord(growResult);
1365 int oldWidth, oldHeight;
1366
1367
1368 if (win)
1369 {
1370 win->GetSize(&oldWidth, &oldHeight);
1371 if (newWidth == 0)
1372 newWidth = oldWidth;
1373 if (newHeight == 0)
1374 newHeight = oldHeight;
1375 win->SetSize( -1, -1, newWidth, newHeight, wxSIZE_USE_EXISTING);
1376 }
1377 }
1378 s_lastMouseDown = 0;
1379 }
1380 break;
1381 case inZoomIn:
1382 case inZoomOut:
1383 if (TrackBox(window, ev->where, windowPart))
1384 {
1385 // TODO setup size event
1386 ZoomWindow( window , windowPart , false ) ;
1387 if (win)
1388 {
1389 Rect tempRect ;
1390
1391 GetWindowPortBounds(window, &tempRect ) ;
1392 win->SetSize( -1, -1, tempRect.right-tempRect.left ,
1393 tempRect.bottom-tempRect.top, wxSIZE_USE_EXISTING);
1394 }
1395 }
1396 s_lastMouseDown = 0;
1397 break;
1398 case inCollapseBox :
1399 // TODO setup size event
1400 s_lastMouseDown = 0;
1401 break ;
1402
1403 case inContent :
1404 {
1405 GrafPtr port ;
1406 GetPort( &port ) ;
66a09d47 1407 SetPortWindowPort(window) ;
8461e4c2
VZ
1408 SetPort( port ) ;
1409 }
1410 if ( window != frontWindow && wxTheApp->s_captureWindow == NULL )
1411 {
1412 if ( s_macIsInModalLoop )
1413 {
1414 SysBeep ( 30 ) ;
1415 }
1416 else if ( UMAIsWindowFloating( window ) )
1417 {
1418 if ( win )
1419 win->MacMouseDown( ev , windowPart ) ;
1420 }
1421 else
1422 {
1423 if ( win )
1424 win->MacMouseDown( ev , windowPart ) ;
72055702 1425 ::SelectWindow( window ) ;
8461e4c2
VZ
1426 }
1427 }
1428 else
1429 {
1430 if ( win )
1431 win->MacMouseDown( ev , windowPart ) ;
1432 }
1433 break ;
1434
1435 default:
1436 break;
1437 }
169935ad
SC
1438}
1439
76a5e5d2 1440void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr )
169935ad 1441{
76a5e5d2 1442 EventRecord* ev = (EventRecord*) evr ;
8461e4c2
VZ
1443 WindowRef window;
1444
4f5a3250
SC
1445 short windowPart = inNoWindow ;
1446 if ( wxTheApp->s_captureWindow )
1447 {
1448 window = (WindowRef) s_captureWindow->MacGetRootWindow() ;
1449 windowPart = inContent ;
1450 }
1451 else
1452 {
1453 windowPart = ::FindWindow(ev->where, &window) ;
1454 }
8461e4c2
VZ
1455
1456 switch (windowPart)
1457 {
1458 case inMenuBar :
1459 break ;
1460 case inSysWindow :
1461 break ;
1462 default:
1463 {
a3722eeb 1464 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
8461e4c2
VZ
1465 if ( win )
1466 win->MacMouseUp( ev , windowPart ) ;
1467 }
1468 break;
1469 }
169935ad
SC
1470}
1471
72055702 1472long wxMacTranslateKey(unsigned char key, unsigned char code) ;
7c551d95 1473long wxMacTranslateKey(unsigned char key, unsigned char code)
9779893b 1474{
8461e4c2 1475 long retval = key ;
9779893b 1476 switch (key)
519cb848 1477 {
8461e4c2
VZ
1478 case 0x01 :
1479 retval = WXK_HOME;
1480 break;
1481 case 0x03 :
1482 retval = WXK_RETURN;
1483 break;
1484 case 0x04 :
1485 retval = WXK_END;
1486 break;
1487 case 0x05 :
1488 retval = WXK_HELP;
1489 break;
1490 case 0x08 :
1491 retval = WXK_BACK;
1492 break;
1493 case 0x09 :
1494 retval = WXK_TAB;
1495 break;
1496 case 0x0b :
1497 retval = WXK_PAGEUP;
1498 break;
1499 case 0x0c :
1500 retval = WXK_PAGEDOWN;
1501 break;
1502 case 0x0d :
1503 retval = WXK_RETURN;
1504 break;
1505 case 0x10 :
1506 {
1507 switch( code )
1508 {
1509 case 0x7a :
1510 retval = WXK_F1 ;
1511 break;
1512 case 0x78 :
1513 retval = WXK_F2 ;
1514 break;
1515 case 0x63 :
1516 retval = WXK_F3 ;
1517 break;
1518 case 0x76 :
1519 retval = WXK_F4 ;
1520 break;
1521 case 0x60 :
1522 retval = WXK_F5 ;
1523 break;
1524 case 0x61 :
1525 retval = WXK_F6 ;
1526 break;
1527 case 0x62:
1528 retval = WXK_F7 ;
1529 break;
1530 case 0x64 :
1531 retval = WXK_F8 ;
1532 break;
1533 case 0x65 :
1534 retval = WXK_F9 ;
1535 break;
1536 case 0x6D :
1537 retval = WXK_F10 ;
1538 break;
1539 case 0x67 :
1540 retval = WXK_F11 ;
1541 break;
1542 case 0x6F :
1543 retval = WXK_F12 ;
1544 break;
1545 case 0x69 :
1546 retval = WXK_F13 ;
1547 break;
1548 case 0x6B :
1549 retval = WXK_F14 ;
1550 break;
1551 case 0x71 :
1552 retval = WXK_F15 ;
1553 break;
1554 }
1555 }
1556 break ;
1557 case 0x1b :
1558 retval = WXK_ESCAPE ;
1559 break ;
1560 case 0x1c :
1561 retval = WXK_LEFT ;
1562 break ;
1563 case 0x1d :
1564 retval = WXK_RIGHT ;
1565 break ;
1566 case 0x1e :
1567 retval = WXK_UP ;
1568 break ;
1569 case 0x1f :
1570 retval = WXK_DOWN ;
1571 break ;
1572 case 0x7F :
1573 retval = WXK_DELETE ;
1574 default:
1575 break ;
1576 } // end switch
1577
1578 return retval;
169935ad
SC
1579}
1580
76a5e5d2 1581void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
169935ad 1582{
76a5e5d2 1583 EventRecord* ev = (EventRecord*) evr ;
8461e4c2
VZ
1584 wxToolTip::RemoveToolTips() ;
1585
1586 UInt32 menuresult = UMAMenuEvent(ev) ;
1587 if ( HiWord( menuresult ) )
1588 {
1589 if ( !s_macIsInModalLoop )
1590 MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ;
1591 }
1592 else
1593 {
1594 short keycode ;
1595 short keychar ;
1596 keychar = short(ev->message & charCodeMask);
1597 keycode = short(ev->message & keyCodeMask) >> 8 ;
35a8698b
SC
1598 // it is wxWindows Convention to have Ctrl Key Combinations at ASCII char value
1599 if ( ev->modifiers & controlKey && keychar >= 0 && keychar < 0x20 )
1600 {
1601 keychar += 0x40 ;
1602 }
e562df9b
SC
1603 long keyval = wxMacTranslateKey(keychar, keycode) ;
1604 bool handled = false ;
8461e4c2
VZ
1605 wxWindow* focus = wxWindow::FindFocus() ;
1606 if ( focus )
1607 {
8461e4c2
VZ
1608
1609 wxKeyEvent event(wxEVT_KEY_DOWN);
1610 event.m_shiftDown = ev->modifiers & shiftKey;
1611 event.m_controlDown = ev->modifiers & controlKey;
1612 event.m_altDown = ev->modifiers & optionKey;
1613 event.m_metaDown = ev->modifiers & cmdKey;
1614 event.m_keyCode = keyval;
1615 event.m_x = ev->where.h;
1616 event.m_y = ev->where.v;
1617 event.m_timeStamp = ev->when;
1618 event.SetEventObject(focus);
e562df9b 1619 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
35a8698b
SC
1620 if ( handled && event.GetSkipped() )
1621 handled = false ;
8461e4c2
VZ
1622 if ( !handled )
1623 {
ba2928c6 1624#if wxUSE_ACCEL
8461e4c2
VZ
1625 if (!handled)
1626 {
ba2928c6 1627 wxWindow *ancestor = focus;
8461e4c2
VZ
1628 while (ancestor)
1629 {
1630 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1631 if (command != -1)
1632 {
1633 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1634 handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
1635 break;
1636 }
35a8698b 1637 if (ancestor->IsTopLevel())
8461e4c2
VZ
1638 break;
1639 ancestor = ancestor->GetParent();
1640 }
8461e4c2 1641 }
ba2928c6 1642#endif // wxUSE_ACCEL
8461e4c2
VZ
1643 }
1644 if (!handled)
1645 {
1646 wxKeyEvent event(wxEVT_CHAR);
1647 event.m_shiftDown = ev->modifiers & shiftKey;
1648 event.m_controlDown = ev->modifiers & controlKey;
1649 event.m_altDown = ev->modifiers & optionKey;
1650 event.m_metaDown = ev->modifiers & cmdKey;
1651 event.m_keyCode = keyval;
1652 event.m_x = ev->where.h;
1653 event.m_y = ev->where.v;
1654 event.m_timeStamp = ev->when;
1655 event.SetEventObject(focus);
1656 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
35a8698b
SC
1657 if ( handled && event.GetSkipped() )
1658 handled = false ;
8461e4c2
VZ
1659 }
1660 if ( !handled &&
1661 (keyval == WXK_TAB) &&
35a8698b
SC
1662// CS: copied the change below from wxGTK
1663// VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
1664// have this style, yet choose not to process this particular TAB in which
1665// case TAB must still work as a navigational character
1666#if 0
8461e4c2 1667 (!focus->HasFlag(wxTE_PROCESS_TAB)) &&
35a8698b 1668#endif
8461e4c2
VZ
1669 (focus->GetParent()) &&
1670 (focus->GetParent()->HasFlag( wxTAB_TRAVERSAL)) )
1671 {
1672 wxNavigationKeyEvent new_event;
1673 new_event.SetEventObject( focus );
1674 new_event.SetDirection( !event.ShiftDown() );
1675 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1676 new_event.SetWindowChange( event.ControlDown() );
1677 new_event.SetCurrentFocus( focus );
1678 handled = focus->GetEventHandler()->ProcessEvent( new_event );
35a8698b
SC
1679 if ( handled && new_event.GetSkipped() )
1680 handled = false ;
8461e4c2 1681 }
e562df9b
SC
1682 }
1683 if ( !handled )
1684 {
1685 // if window is not having a focus still testing for default enter or cancel
1686 // TODO add the UMA version for ActiveNonFloatingWindow
1687 focus = wxFindWinFromMacWindow( FrontWindow() ) ;
1688 if ( focus )
1689 {
1690 if ( keyval == WXK_RETURN )
1691 {
1692 wxButton *def = wxDynamicCast(focus->GetDefaultItem(),
1693 wxButton);
1694 if ( def && def->IsEnabled() )
1695 {
1696 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
1697 event.SetEventObject(def);
1698 def->Command(event);
1699 return ;
1700 }
1701 }
8461e4c2 1702 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
e562df9b 1703 else if (keyval == WXK_ESCAPE || (keyval == '.' && ev->modifiers & cmdKey ) )
8461e4c2 1704 {
e562df9b
SC
1705 wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
1706 new_event.SetEventObject( focus );
1707 handled = focus->GetEventHandler()->ProcessEvent( new_event );
8461e4c2 1708 }
e562df9b 1709 }
8461e4c2
VZ
1710 }
1711 }
169935ad
SC
1712}
1713
76a5e5d2 1714void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr )
169935ad 1715{
76a5e5d2 1716 EventRecord* ev = (EventRecord*) evr ;
8461e4c2
VZ
1717 wxToolTip::RemoveToolTips() ;
1718
1719 UInt32 menuresult = UMAMenuEvent(ev) ;
1720 if ( HiWord( menuresult ) )
1721 {
1722 }
1723 else
1724 {
1725 short keycode ;
1726 short keychar ;
1727 keychar = short(ev->message & charCodeMask);
1728 keycode = short(ev->message & keyCodeMask) >> 8 ;
1729
1730 wxWindow* focus = wxWindow::FindFocus() ;
1731 if ( focus )
1732 {
1733 long keyval = wxMacTranslateKey(keychar, keycode) ;
1734
1735 wxKeyEvent event(wxEVT_KEY_UP);
1736 event.m_shiftDown = ev->modifiers & shiftKey;
1737 event.m_controlDown = ev->modifiers & controlKey;
1738 event.m_altDown = ev->modifiers & optionKey;
1739 event.m_metaDown = ev->modifiers & cmdKey;
1740 event.m_keyCode = keyval;
1741 event.m_x = ev->where.h;
1742 event.m_y = ev->where.v;
1743 event.m_timeStamp = ev->when;
1744 event.SetEventObject(focus);
1745 bool handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1746 }
1747 }
169935ad
SC
1748}
1749
76a5e5d2 1750void wxApp::MacHandleActivateEvent( WXEVENTREF evr )
169935ad 1751{
76a5e5d2 1752 EventRecord* ev = (EventRecord*) evr ;
8461e4c2
VZ
1753 WindowRef window = (WindowRef) ev->message ;
1754 if ( window )
1755 {
1756 bool activate = (ev->modifiers & activeFlag ) ;
1757 WindowClass wclass ;
72055702 1758 ::GetWindowClass ( window , &wclass ) ;
8461e4c2
VZ
1759 if ( wclass == kFloatingWindowClass )
1760 {
1761 // if it is a floater we activate/deactivate the front non-floating window instead
72055702 1762 window = ::FrontNonFloatingWindow() ;
8461e4c2 1763 }
a3722eeb 1764 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
8461e4c2
VZ
1765 if ( win )
1766 win->MacActivate( ev , activate ) ;
1767 }
169935ad
SC
1768}
1769
76a5e5d2 1770void wxApp::MacHandleUpdateEvent( WXEVENTREF evr )
169935ad 1771{
76a5e5d2 1772 EventRecord* ev = (EventRecord*) evr ;
8461e4c2 1773 WindowRef window = (WindowRef) ev->message ;
a3722eeb 1774 wxTopLevelWindowMac * win = wxFindWinFromMacWindow( window ) ;
8461e4c2
VZ
1775 if ( win )
1776 {
0a67a93b 1777 if ( !wxPendingDelete.Member(win) )
a3722eeb 1778 win->MacUpdate( ev->when ) ;
8461e4c2
VZ
1779 }
1780 else
1781 {
1782 // since there is no way of telling this foreign window to update itself
1783 // we have to invalidate the update region otherwise we keep getting the same
1784 // event over and over again
1785 BeginUpdate( window ) ;
1786 EndUpdate( window ) ;
1787 }
169935ad
SC
1788}
1789
76a5e5d2 1790void wxApp::MacHandleDiskEvent( WXEVENTREF evr )
169935ad 1791{
76a5e5d2 1792 EventRecord* ev = (EventRecord*) evr ;
8461e4c2 1793 if ( HiWord( ev->message ) != noErr )
519cb848 1794 {
2f1ae414 1795 #if !TARGET_CARBON
8461e4c2
VZ
1796 OSErr err ;
1797 Point point ;
1798 SetPt( &point , 100 , 100 ) ;
9779893b 1799
8461e4c2
VZ
1800 err = DIBadMount( point , ev->message ) ;
1801 wxASSERT( err == noErr ) ;
2f1ae414 1802#endif
8461e4c2 1803 }
169935ad
SC
1804}
1805
76a5e5d2 1806void wxApp::MacHandleOSEvent( WXEVENTREF evr )
169935ad 1807{
76a5e5d2 1808 EventRecord* ev = (EventRecord*) evr ;
8461e4c2
VZ
1809 switch( ( ev->message & osEvtMessageMask ) >> 24 )
1810 {
1811 case suspendResumeMessage :
1812 {
1813 bool isResuming = ev->message & resumeFlag ;
5fde6fcc 1814#if !TARGET_CARBON
8461e4c2 1815 bool convertClipboard = ev->message & convertClipboardFlag ;
5fde6fcc 1816#else
8461e4c2 1817 bool convertClipboard = false;
5fde6fcc 1818#endif
8461e4c2
VZ
1819 bool doesActivate = UMAGetProcessModeDoesActivateOnFGSwitch() ;
1820 if ( isResuming )
1821 {
1822 WindowRef oldFrontWindow = NULL ;
1823 WindowRef newFrontWindow = NULL ;
1824
1825 // in case we don't take care of activating ourselves, we have to synchronize
1826 // our idea of the active window with the process manager's - which it already activated
1827
1828 if ( !doesActivate )
72055702 1829 oldFrontWindow = ::FrontNonFloatingWindow() ;
8461e4c2
VZ
1830
1831 MacResume( convertClipboard ) ;
1832
72055702 1833 newFrontWindow = ::FrontNonFloatingWindow() ;
8461e4c2
VZ
1834
1835 if ( oldFrontWindow )
1836 {
a3722eeb 1837 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( oldFrontWindow ) ;
8461e4c2
VZ
1838 if ( win )
1839 win->MacActivate( ev , false ) ;
1840 }
1841 if ( newFrontWindow )
1842 {
a3722eeb 1843 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( newFrontWindow ) ;
8461e4c2
VZ
1844 if ( win )
1845 win->MacActivate( ev , true ) ;
1846 }
1847 }
1848 else
1849 {
1850 MacSuspend( convertClipboard ) ;
1851
1852 // in case this suspending did close an active window, another one might
1853 // have surfaced -> lets deactivate that one
1854
72055702
SC
1855/* TODO : find out what to do on systems < 10 , perhaps FrontNonFloatingWindow
1856 WindowRef newActiveWindow = ::ActiveNonFloatingWindow() ;
8461e4c2
VZ
1857 if ( newActiveWindow )
1858 {
1859 wxWindow* win = wxFindWinFromMacWindow( newActiveWindow ) ;
1860 if ( win )
1861 win->MacActivate( ev , false ) ;
1862 }
72055702 1863*/
8461e4c2
VZ
1864 }
1865 }
1866 break ;
1867 case mouseMovedMessage :
1868 {
1869 WindowRef window;
1870
1871 wxWindow* currentMouseWindow = NULL ;
1872
1873 wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) ,
1874 &currentMouseWindow ) ;
8461e4c2
VZ
1875 if ( currentMouseWindow != wxWindow::s_lastMouseWindow )
1876 {
1877 wxMouseEvent event ;
1878
1879 bool isDown = !(ev->modifiers & btnState) ; // 1 is for up
1880 bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse
1881
1882 event.m_leftDown = isDown && !controlDown;
1883 event.m_middleDown = FALSE;
1884 event.m_rightDown = isDown && controlDown;
1885 event.m_shiftDown = ev->modifiers & shiftKey;
1886 event.m_controlDown = ev->modifiers & controlKey;
1887 event.m_altDown = ev->modifiers & optionKey;
1888 event.m_metaDown = ev->modifiers & cmdKey;
1889 event.m_x = ev->where.h;
1890 event.m_y = ev->where.v;
1891 event.m_timeStamp = ev->when;
1892 event.SetEventObject(this);
ed60b502 1893
8461e4c2
VZ
1894 if ( wxWindow::s_lastMouseWindow )
1895 {
ed60b502
RR
1896 wxMouseEvent eventleave(event);
1897 eventleave.SetEventType( wxEVT_LEAVE_WINDOW );
1898 wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y );
d1bdc41d 1899 eventleave.SetEventObject( wxWindow::s_lastMouseWindow ) ;
ed60b502 1900
8461e4c2
VZ
1901 wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave);
1902 }
1903 if ( currentMouseWindow )
1904 {
ed60b502
RR
1905 wxMouseEvent evententer(event);
1906 evententer.SetEventType( wxEVT_ENTER_WINDOW );
1907 currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y );
d1bdc41d 1908 evententer.SetEventObject( currentMouseWindow ) ;
8461e4c2
VZ
1909 currentMouseWindow->GetEventHandler()->ProcessEvent(evententer);
1910 }
1911 wxWindow::s_lastMouseWindow = currentMouseWindow ;
1912 }
1913
1914 short windowPart = ::FindWindow(ev->where, &window);
1915
1916 switch (windowPart)
1917 {
1918 // fixes for setting the cursor back from dominic mazzoni
1919 case inMenuBar :
1920 UMAShowArrowCursor();
1921 break ;
1922 case inSysWindow :
1923 UMAShowArrowCursor();
1924 break ;
1925 default:
1926 {
6264b550
RR
1927 // if ( s_lastMouseDown == 0 )
1928 // ev->modifiers |= btnState ;
1929
1930 // Calling GetNextEvent with a zero event mask will always
1931 // pass back a null event. However, it fills the EventRecord
1932 // with the state of the modifier keys. This is needed since
1933 // the modifier state returned by WaitForNextEvent often is
1934 // wrong mouse move events. The attempt above to correct this
1935 // didn't always work (under OS X at least).
1936
1937 EventRecord tmp;
1938 ::GetNextEvent(0, &tmp);
1939 ev->modifiers = tmp.modifiers;
1940
a3722eeb 1941 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
8461e4c2
VZ
1942 if ( win )
1943 win->MacMouseMoved( ev , windowPart ) ;
1944 else
1945 UMAShowArrowCursor();
1946
1947 }
1948 break;
1949 }
1950 }
1951 break ;
1952
1953 }
169935ad
SC
1954}
1955
519cb848 1956void wxApp::MacHandleMenuSelect( int macMenuId , int macMenuItemNum )
169935ad 1957{
8461e4c2
VZ
1958 if (macMenuId == 0)
1959 return; // no menu item selected
1960
1961 if (macMenuId == kwxMacAppleMenuId && macMenuItemNum > 1)
1962 {
1963 #if ! TARGET_CARBON
1964 Str255 deskAccessoryName ;
1965 GrafPtr savedPort ;
1966
1967 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId), macMenuItemNum, deskAccessoryName);
1968 GetPort(&savedPort);
1969 OpenDeskAcc(deskAccessoryName);
1970 SetPort(savedPort);
1971 #endif
1972 }
1973 else
1974 {
1975 wxWindow* frontwindow = wxFindWinFromMacWindow( ::FrontWindow() ) ;
1976 if ( frontwindow && wxMenuBar::MacGetInstalledMenuBar() )
1977 wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow->GetEventHandler() , 0 , macMenuId , macMenuItemNum ) ;
1978 }
1979 HiliteMenu(0);
169935ad
SC
1980}
1981
519cb848
SC
1982/*
1983long wxApp::MacTranslateKey(char key, int mods)
169935ad 1984{
169935ad
SC
1985}
1986
519cb848 1987void wxApp::MacAdjustCursor()
169935ad 1988{
169935ad
SC
1989}
1990
519cb848
SC
1991*/
1992/*
169935ad
SC
1993void
1994wxApp::macAdjustCursor()
1995{
519cb848 1996 if (ev->what != kHighLevelEvent)
169935ad 1997 {
8461e4c2
VZ
1998 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1999 if (theMacWxFrame)
2000 {
2001 if (!theMacWxFrame->MacAdjustCursor(ev->where))
2002 ::SetCursor(&(qd.arrow));
2003 }
169935ad
SC
2004 }
2005}
9779893b 2006*/