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