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