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