]> git.saurik.com Git - wxWidgets.git/blob - src/mac/app.cpp
added xpmdecod.cpp
[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/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 UMAShowWatchCursor() ;
354
355 #ifdef __UNIX__
356 AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , AEHandleODoc ,
357 (long) wxTheApp , FALSE ) ;
358 AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , AEHandleOApp ,
359 (long) wxTheApp , FALSE ) ;
360 AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , AEHandlePDoc ,
361 (long) wxTheApp , FALSE ) ;
362 AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , AEHandleQuit ,
363 (long) wxTheApp , FALSE ) ;
364 #else
365 AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments , NewAEEventHandlerProc(AEHandleODoc) ,
366 (long) wxTheApp , FALSE ) ;
367 AEInstallEventHandler( kCoreEventClass , kAEOpenApplication , NewAEEventHandlerProc(AEHandleOApp) ,
368 (long) wxTheApp , FALSE ) ;
369 AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments , NewAEEventHandlerProc(AEHandlePDoc) ,
370 (long) wxTheApp , FALSE ) ;
371 AEInstallEventHandler( kCoreEventClass , kAEQuitApplication , NewAEEventHandlerProc(AEHandleQuit) ,
372 (long) wxTheApp , FALSE ) ;
373 #endif
374
375
376 #ifndef __UNIX__
377 // test the minimal configuration necessary
378
379 #if !TARGET_CARBON
380 long theSystem ;
381 long theMachine;
382
383 if (Gestalt(gestaltMachineType, &theMachine) != noErr)
384 {
385 error = kMacSTRWrongMachine;
386 }
387 else if (theMachine < gestaltMacPlus)
388 {
389 error = kMacSTRWrongMachine;
390 }
391 else if (Gestalt(gestaltSystemVersion, &theSystem) != noErr )
392 {
393 error = kMacSTROldSystem ;
394 }
395 else if ( theSystem < 0x0750 )
396 {
397 error = kMacSTROldSystem ;
398 }
399 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap)
400 {
401 error = kMacSTRSmallSize;
402 }
403 #endif
404 /*
405 else
406 {
407 if ( !UMAHasAppearance() )
408 {
409 error = kMacSTRNoPre8Yet ;
410 }
411 }
412 */
413 #endif
414
415 // if we encountered any problems so far, give the error code and exit immediately
416
417 if ( error )
418 {
419 short itemHit;
420 Str255 message;
421
422 GetIndString(message, 128, error);
423 UMAShowArrowCursor() ;
424 ParamText("\pFatal Error", message, (ConstStr255Param)"\p", (ConstStr255Param)"\p");
425 itemHit = Alert(128, nil);
426 return FALSE ;
427 }
428
429 #ifndef __UNIX__
430 #if __option(profile)
431 ProfilerInit( collectDetailed, bestTimeBase , 20000 , 40 ) ;
432 #endif
433 #endif
434
435 // now avoid exceptions thrown for new (bad_alloc)
436
437 #ifndef __UNIX__
438 std::__throws_bad_alloc = FALSE ;
439 #endif
440
441 s_macCursorRgn = ::NewRgn() ;
442
443 #ifdef __WXMSW__
444 wxBuffer = new char[1500];
445 #else
446 wxBuffer = new char[BUFSIZ + 512];
447 #endif
448
449 wxClassInfo::InitializeClasses();
450
451 #if wxUSE_RESOURCES
452 // wxGetResource(wxT("wxWindows"), wxT("OsVersion"), &wxOsVersion);
453 #endif
454
455 #if wxUSE_THREADS
456 wxPendingEventsLocker = new wxCriticalSection;
457 #endif
458 wxTheColourDatabase = new wxColourDatabase(wxKEY_STRING);
459 wxTheColourDatabase->Initialize();
460
461 wxInitializeStockLists();
462 wxInitializeStockObjects();
463
464 #if wxUSE_WX_RESOURCES
465 wxInitializeResourceSystem();
466 #endif
467
468 wxBitmap::InitStandardHandlers();
469
470 wxModule::RegisterModules();
471 if (!wxModule::InitializeModules()) {
472 return FALSE;
473 }
474
475 wxWinMacWindowList = new wxList(wxKEY_INTEGER);
476 wxWinMacControlList = new wxList(wxKEY_INTEGER);
477
478 wxMacCreateNotifierTable() ;
479
480 UMAShowArrowCursor() ;
481
482 return TRUE;
483 }
484
485 void wxApp::CleanUp()
486 {
487 #if wxUSE_LOG
488 // flush the logged messages if any and install a 'safer' log target: the
489 // default one (wxLogGui) can't be used after the resources are freed just
490 // below and the user suppliedo ne might be even more unsafe (using any
491 // wxWindows GUI function is unsafe starting from now)
492 wxLog::DontCreateOnDemand();
493
494 // this will flush the old messages if any
495 delete wxLog::SetActiveTarget(new wxLogStderr);
496 #endif // wxUSE_LOG
497
498 // One last chance for pending objects to be cleaned up
499 wxTheApp->DeletePendingObjects();
500
501 wxModule::CleanUpModules();
502
503 #if wxUSE_WX_RESOURCES
504 wxCleanUpResourceSystem();
505 #endif
506
507 wxDeleteStockObjects() ;
508
509 // Destroy all GDI lists, etc.
510 wxDeleteStockLists();
511
512 delete wxTheColourDatabase;
513 wxTheColourDatabase = NULL;
514
515 wxBitmap::CleanUpHandlers();
516
517 delete[] wxBuffer;
518 wxBuffer = NULL;
519
520 wxMacDestroyNotifierTable() ;
521 if (wxWinMacWindowList)
522 delete wxWinMacWindowList ;
523
524 delete wxPendingEvents;
525 #if wxUSE_THREADS
526 delete wxPendingEventsLocker;
527 // If we don't do the following, we get an apparent memory leak.
528 ((wxEvtHandler&) wxDefaultValidator).ClearEventLocker();
529 #endif
530
531 wxClassInfo::CleanUpClasses();
532
533 #ifndef __UNIX__
534 #if __option(profile)
535 ProfilerDump( "\papp.prof" ) ;
536 ProfilerTerm() ;
537 #endif
538 #endif
539
540 delete wxTheApp;
541 wxTheApp = NULL;
542
543 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
544 // At this point we want to check if there are any memory
545 // blocks that aren't part of the wxDebugContext itself,
546 // as a special case. Then when dumping we need to ignore
547 // wxDebugContext, too.
548 if (wxDebugContext::CountObjectsLeft(TRUE) > 0)
549 {
550 wxLogDebug(wxT("There were memory leaks."));
551 wxDebugContext::Dump();
552 wxDebugContext::PrintStatistics();
553 }
554 // wxDebugContext::SetStream(NULL, NULL);
555 #endif
556
557 #if wxUSE_LOG
558 // do it as the very last thing because everything else can log messages
559 delete wxLog::SetActiveTarget(NULL);
560 #endif // wxUSE_LOG
561
562 UMACleanupToolbox() ;
563 if (s_macCursorRgn)
564 ::DisposeRgn(s_macCursorRgn);
565
566 #if 0
567 TerminateAE() ;
568 #endif
569 }
570
571 int wxEntry( int argc, char *argv[] , bool enterLoop )
572 {
573 #ifdef __MWERKS__
574 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
575 // This seems to be necessary since there are 'rogue'
576 // objects present at this point (perhaps global objects?)
577 // Setting a checkpoint will ignore them as far as the
578 // memory checking facility is concerned.
579 // Of course you may argue that memory allocated in globals should be
580 // checked, but this is a reasonable compromise.
581 wxDebugContext::SetCheckpoint();
582 #endif
583 #endif
584 if (!wxApp::Initialize()) {
585 return 0;
586 }
587 // create the application object or ensure that one already exists
588 if (!wxTheApp)
589 {
590 // The app may have declared a global application object, but we recommend
591 // the IMPLEMENT_APP macro is used instead, which sets an initializer
592 // function for delayed, dynamic app object construction.
593 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
594 wxT("No initializer - use IMPLEMENT_APP macro.") );
595
596 wxTheApp = (wxApp*) (*wxApp::GetInitializerFunction()) ();
597 }
598
599 wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") );
600
601 #ifdef __WXMAC__
602 argc = 0 ; // currently we don't support files as parameters
603 #endif
604
605 wxTheApp->argc = argc;
606 wxTheApp->argv = argv;
607
608 // GUI-specific initialization, such as creating an app context.
609 wxTheApp->OnInitGui();
610
611 // we could try to get the open apple events here to adjust argc and argv better
612
613
614 // Here frames insert themselves automatically
615 // into wxTopLevelWindows by getting created
616 // in OnInit().
617
618 int retValue = 0;
619
620 if ( wxTheApp->OnInit() )
621 {
622 if ( enterLoop )
623 {
624 retValue = wxTheApp->OnRun();
625 }
626 else
627 // We want to initialize, but not run or exit immediately.
628 return 1;
629 }
630 //else: app initialization failed, so we skipped OnRun()
631
632 wxWindow *topWindow = wxTheApp->GetTopWindow();
633 if ( topWindow )
634 {
635 // Forcibly delete the window.
636 if ( topWindow->IsKindOf(CLASSINFO(wxFrame)) ||
637 topWindow->IsKindOf(CLASSINFO(wxDialog)) )
638 {
639 topWindow->Close(TRUE);
640 wxTheApp->DeletePendingObjects();
641 }
642 else
643 {
644 delete topWindow;
645 wxTheApp->SetTopWindow(NULL);
646 }
647 }
648
649 wxTheApp->OnExit();
650
651 wxApp::CleanUp();
652
653 return retValue;
654 }
655
656 // Static member initialization
657 wxAppInitializerFunction wxAppBase::m_appInitFn = (wxAppInitializerFunction) NULL;
658
659 wxApp::wxApp()
660 {
661 m_topWindow = NULL;
662 wxTheApp = this;
663
664 m_wantDebugOutput = TRUE ;
665
666 argc = 0;
667 argv = NULL;
668
669 m_printMode = wxPRINT_WINDOWS;
670 m_exitOnFrameDelete = TRUE;
671 m_auto3D = TRUE;
672 }
673
674 bool wxApp::Initialized()
675 {
676 if (GetTopWindow())
677 return TRUE;
678 else
679 return FALSE;
680 }
681
682 int wxApp::MainLoop()
683 {
684 m_keepGoing = TRUE;
685
686 while (m_keepGoing)
687 {
688 MacDoOneEvent() ;
689 }
690
691 return 0;
692 }
693
694 // Returns TRUE if more time is needed.
695 bool wxApp::ProcessIdle()
696 {
697 wxIdleEvent event;
698 event.SetEventObject(this);
699 ProcessEvent(event);
700
701 return event.MoreRequested();
702 }
703
704 void wxApp::ExitMainLoop()
705 {
706 m_keepGoing = FALSE;
707 }
708
709 // Is a message/event pending?
710 bool wxApp::Pending()
711 {
712 EventRecord event ;
713
714 return EventAvail( everyEvent , &event ) ;
715 }
716
717 // Dispatch a message.
718 void wxApp::Dispatch()
719 {
720 MacDoOneEvent() ;
721 }
722
723 void wxApp::OnIdle(wxIdleEvent& event)
724 {
725 static bool s_inOnIdle = FALSE;
726
727 // Avoid recursion (via ProcessEvent default case)
728 if ( s_inOnIdle )
729 return;
730
731
732 s_inOnIdle = TRUE;
733
734 // 'Garbage' collection of windows deleted with Close().
735 DeletePendingObjects();
736
737 // flush the logged messages if any
738 wxLog *pLog = wxLog::GetActiveTarget();
739 if ( pLog != NULL && pLog->HasPendingMessages() )
740 pLog->Flush();
741
742 // Send OnIdle events to all windows
743 bool needMore = SendIdleEvents();
744
745 if (needMore)
746 event.RequestMore(TRUE);
747
748 // If they are pending events, we must process them: pending events are
749 // either events to the threads other than main or events posted with
750 // wxPostEvent() functions
751 wxMacProcessNotifierAndPendingEvents();
752
753 s_inOnIdle = FALSE;
754 }
755
756 void wxWakeUpIdle()
757 {
758 wxMacWakeUp() ;
759 }
760
761 // Send idle event to all top-level windows
762 bool wxApp::SendIdleEvents()
763 {
764 bool needMore = FALSE;
765 wxNode* node = wxTopLevelWindows.First();
766 while (node)
767 {
768 wxWindow* win = (wxWindow*) node->Data();
769 if (SendIdleEvents(win))
770 needMore = TRUE;
771
772 node = node->Next();
773 }
774 return needMore;
775 }
776
777 // Send idle event to window and all subwindows
778 bool wxApp::SendIdleEvents(wxWindow* win)
779 {
780 bool needMore = FALSE;
781
782 wxIdleEvent event;
783 event.SetEventObject(win);
784 win->ProcessEvent(event);
785
786 if (event.MoreRequested())
787 needMore = TRUE;
788
789 wxNode* node = win->GetChildren().First();
790 while (node)
791 {
792 wxWindow* win = (wxWindow*) node->Data();
793 if (SendIdleEvents(win))
794 needMore = TRUE;
795
796 node = node->Next();
797 }
798 return needMore ;
799 }
800
801 void wxApp::DeletePendingObjects()
802 {
803 wxNode *node = wxPendingDelete.First();
804 while (node)
805 {
806 wxObject *obj = (wxObject *)node->Data();
807
808 delete obj;
809
810 if (wxPendingDelete.Member(obj))
811 delete node;
812
813 // Deleting one object may have deleted other pending
814 // objects, so start from beginning of list again.
815 node = wxPendingDelete.First();
816 }
817 }
818
819 wxIcon
820 wxApp::GetStdIcon(int which) const
821 {
822 switch(which)
823 {
824 case wxICON_INFORMATION:
825 return wxIcon("wxICON_INFO");
826
827 case wxICON_QUESTION:
828 return wxIcon("wxICON_QUESTION");
829
830 case wxICON_EXCLAMATION:
831 return wxIcon("wxICON_WARNING");
832
833 default:
834 wxFAIL_MSG(wxT("requested non existent standard icon"));
835 // still fall through
836
837 case wxICON_HAND:
838 return wxIcon("wxICON_ERROR");
839 }
840 }
841
842 void wxExit()
843 {
844 wxLogError(_("Fatal error: exiting"));
845
846 wxApp::CleanUp();
847 ::ExitToShell() ;
848 }
849
850 void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event))
851 {
852 if (GetTopWindow())
853 GetTopWindow()->Close(TRUE);
854 }
855
856 // Default behaviour: close the application with prompts. The
857 // user can veto the close, and therefore the end session.
858 void wxApp::OnQueryEndSession(wxCloseEvent& event)
859 {
860 if (GetTopWindow())
861 {
862 if (!GetTopWindow()->Close(!event.CanVeto()))
863 event.Veto(TRUE);
864 }
865 }
866
867 extern "C" void wxCYield() ;
868 void wxCYield()
869 {
870 wxYield() ;
871 }
872
873 // Yield to other processes
874
875 static bool gs_inYield = FALSE;
876
877 bool wxYield()
878 {
879 #ifdef __WXDEBUG__
880 if (gs_inYield)
881 wxFAIL_MSG( wxT("wxYield called recursively" ) );
882 #endif
883
884 gs_inYield = TRUE;
885
886 #if wxUSE_THREADS
887 YieldToAnyThread() ;
888 #endif
889 EventRecord event ;
890
891 long sleepTime = 0 ; //::GetCaretTime();
892
893 while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, wxApp::s_macCursorRgn))
894 {
895 wxTheApp->MacHandleOneEvent( &event );
896 }
897
898 wxMacProcessNotifierAndPendingEvents() ;
899
900 gs_inYield = FALSE;
901
902 return TRUE;
903 }
904
905 // Yield to incoming messages; but fail silently if recursion is detected.
906 bool wxYieldIfNeeded()
907 {
908 if (gs_inYield)
909 return FALSE;
910
911 return wxYield();
912 }
913
914 // platform specifics
915
916 void wxApp::MacSuspend( bool convertClipboard )
917 {
918 // we have to deactive the window manually
919
920 wxWindow* window = GetTopWindow() ;
921 if ( window )
922 window->MacActivate( MacGetCurrentEvent() , false ) ;
923
924 s_lastMouseDown = 0 ;
925 if( convertClipboard )
926 {
927 MacConvertPrivateToPublicScrap() ;
928 }
929
930 UMAHideFloatingWindows() ;
931 }
932
933 void wxApp::MacResume( bool convertClipboard )
934 {
935 s_lastMouseDown = 0 ;
936 if( convertClipboard )
937 {
938 MacConvertPublicToPrivateScrap() ;
939 }
940
941 UMAShowFloatingWindows() ;
942 }
943
944 void wxApp::MacConvertPrivateToPublicScrap()
945 {
946 }
947
948 void wxApp::MacConvertPublicToPrivateScrap()
949 {
950 }
951
952 void wxApp::MacDoOneEvent()
953 {
954 EventRecord event ;
955
956 long sleepTime = ::GetCaretTime();
957
958 if (WaitNextEvent(everyEvent, &event,sleepTime, s_macCursorRgn))
959 {
960 MacHandleOneEvent( &event );
961 }
962 else
963 {
964 // idlers
965 WindowPtr window = UMAFrontWindow() ;
966 if ( window )
967 UMAIdleControls( window ) ;
968
969 wxTheApp->ProcessIdle() ;
970 }
971 if ( event.what != kHighLevelEvent )
972 SetRectRgn( s_macCursorRgn , event.where.h - 1 , event.where.v - 1, event.where.h + 1 , event.where.v + 1 ) ;
973
974 // repeaters
975
976 wxMacProcessNotifierAndPendingEvents() ;
977 }
978
979 void wxApp::MacHandleOneEvent( EventRecord *ev )
980 {
981 m_macCurrentEvent = ev ;
982
983 wxApp::sm_lastMessageTime = ev->when ;
984
985 switch (ev->what)
986 {
987 case mouseDown:
988 MacHandleMouseDownEvent( ev ) ;
989 if ( ev->modifiers & controlKey )
990 s_lastMouseDown = 2;
991 else
992 s_lastMouseDown = 1;
993 break;
994 case mouseUp:
995 if ( s_lastMouseDown == 2 )
996 {
997 ev->modifiers |= controlKey ;
998 }
999 else
1000 {
1001 ev->modifiers &= ~controlKey ;
1002 }
1003 MacHandleMouseUpEvent( ev ) ;
1004 s_lastMouseDown = 0;
1005 break;
1006 case activateEvt:
1007 MacHandleActivateEvent( ev ) ;
1008 break;
1009 case updateEvt:
1010 MacHandleUpdateEvent( ev ) ;
1011 break;
1012 case keyDown:
1013 case autoKey:
1014 MacHandleKeyDownEvent( ev ) ;
1015 break;
1016 case keyUp:
1017 MacHandleKeyUpEvent( ev ) ;
1018 break;
1019 case diskEvt:
1020 MacHandleDiskEvent( ev ) ;
1021 break;
1022 case osEvt:
1023 MacHandleOSEvent( ev ) ;
1024 break;
1025 case kHighLevelEvent:
1026 MacHandleHighLevelEvent( ev ) ;
1027 break;
1028 default:
1029 break;
1030 }
1031 wxMacProcessNotifierAndPendingEvents() ;
1032 }
1033
1034 void wxApp::MacHandleHighLevelEvent( EventRecord *ev )
1035 {
1036 ::AEProcessAppleEvent( ev ) ;
1037 }
1038
1039 bool s_macIsInModalLoop = false ;
1040
1041 void wxApp::MacHandleMouseDownEvent( EventRecord *ev )
1042 {
1043 wxToolTip::RemoveToolTips() ;
1044
1045 WindowRef window;
1046 WindowRef frontWindow = UMAFrontNonFloatingWindow() ;
1047 WindowAttributes frontWindowAttributes = NULL ;
1048 if ( frontWindow )
1049 UMAGetWindowAttributes( frontWindow , &frontWindowAttributes ) ;
1050
1051 short windowPart = ::FindWindow(ev->where, &window);
1052 wxWindow* win = wxFindWinFromMacWindow( window ) ;
1053
1054 BitMap screenBits;
1055 GetQDGlobalsScreenBits( &screenBits );
1056
1057 switch (windowPart)
1058 {
1059 case inMenuBar :
1060 if ( s_macIsInModalLoop )
1061 {
1062 SysBeep ( 30 ) ;
1063 }
1064 else
1065 {
1066 UInt32 menuresult = MenuSelect(ev->where) ;
1067 MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) );
1068 s_lastMouseDown = 0;
1069 }
1070 break ;
1071 #if !TARGET_CARBON
1072 case inSysWindow :
1073 SystemClick( ev , window ) ;
1074 s_lastMouseDown = 0;
1075 break ;
1076 #endif
1077 case inDrag :
1078 if ( window != frontWindow && s_macIsInModalLoop && !(ev->modifiers & cmdKey ) )
1079 {
1080 SysBeep ( 30 ) ;
1081 }
1082 else
1083 {
1084 DragWindow(window, ev->where, &screenBits.bounds);
1085 if (win)
1086 {
1087 GrafPtr port ;
1088 GetPort( &port ) ;
1089 Point pt = { 0, 0 } ;
1090 #if TARGET_CARBON
1091 SetPort( GetWindowPort(window) ) ;
1092 #else
1093 SetPort( (window) ) ;
1094 #endif
1095 SetOrigin( 0 , 0 ) ;
1096 LocalToGlobal( &pt ) ;
1097 SetPort( port ) ;
1098 win->SetSize( pt.h , pt.v , -1 ,
1099 -1 , wxSIZE_USE_EXISTING);
1100 }
1101 s_lastMouseDown = 0;
1102 }
1103 break ;
1104 case inGoAway:
1105 if (TrackGoAway(window, ev->where))
1106 {
1107 if ( win )
1108 win->Close() ;
1109 }
1110 s_lastMouseDown = 0;
1111 break;
1112 case inGrow:
1113 {
1114 int growResult = GrowWindow(window , ev->where, &screenBits.bounds);
1115 if (growResult != 0)
1116 {
1117 int newWidth = LoWord(growResult);
1118 int newHeight = HiWord(growResult);
1119 int oldWidth, oldHeight;
1120
1121
1122 if (win)
1123 {
1124 win->GetSize(&oldWidth, &oldHeight);
1125 if (newWidth == 0)
1126 newWidth = oldWidth;
1127 if (newHeight == 0)
1128 newHeight = oldHeight;
1129 win->SetSize( -1, -1, newWidth, newHeight, wxSIZE_USE_EXISTING);
1130 }
1131 }
1132 s_lastMouseDown = 0;
1133 }
1134 break;
1135 case inZoomIn:
1136 case inZoomOut:
1137 if (TrackBox(window, ev->where, windowPart))
1138 {
1139 // TODO setup size event
1140 ZoomWindow( window , windowPart , false ) ;
1141 if (win)
1142 {
1143 Rect tempRect ;
1144
1145 GetWindowPortBounds(window, &tempRect ) ;
1146 win->SetSize( -1, -1, tempRect.right-tempRect.left ,
1147 tempRect.bottom-tempRect.top, wxSIZE_USE_EXISTING);
1148 }
1149 }
1150 s_lastMouseDown = 0;
1151 break;
1152 case inCollapseBox :
1153 // TODO setup size event
1154 s_lastMouseDown = 0;
1155 break ;
1156
1157 case inContent :
1158 {
1159 GrafPtr port ;
1160 GetPort( &port ) ;
1161 #if TARGET_CARBON
1162 SetPort( GetWindowPort(window) ) ;
1163 #else
1164 SetPort( (window) ) ;
1165 #endif
1166 SetOrigin( 0 , 0 ) ;
1167 SetPort( port ) ;
1168 }
1169 if ( window != frontWindow )
1170 {
1171 if ( s_macIsInModalLoop )
1172 {
1173 SysBeep ( 30 ) ;
1174 }
1175 else if ( UMAIsWindowFloating( window ) )
1176 {
1177 if ( win )
1178 win->MacMouseDown( ev , windowPart ) ;
1179 }
1180 else
1181 {
1182 UMASelectWindow( window ) ;
1183 }
1184 }
1185 else
1186 {
1187 if ( win )
1188 win->MacMouseDown( ev , windowPart ) ;
1189 }
1190 break ;
1191
1192 default:
1193 break;
1194 }
1195 }
1196
1197 void wxApp::MacHandleMouseUpEvent( EventRecord *ev )
1198 {
1199 WindowRef window;
1200
1201 short windowPart = ::FindWindow(ev->where, &window);
1202
1203 switch (windowPart)
1204 {
1205 case inMenuBar :
1206 break ;
1207 case inSysWindow :
1208 break ;
1209 default:
1210 {
1211 wxWindow* win = wxFindWinFromMacWindow( window ) ;
1212 if ( win )
1213 win->MacMouseUp( ev , windowPart ) ;
1214 }
1215 break;
1216 }
1217 }
1218
1219 long wxMacTranslateKey(unsigned char key, unsigned char code)
1220 {
1221 long retval = key ;
1222 switch (key)
1223 {
1224 case 0x01 :
1225 retval = WXK_HOME;
1226 break;
1227 case 0x03 :
1228 retval = WXK_RETURN;
1229 break;
1230 case 0x04 :
1231 retval = WXK_END;
1232 break;
1233 case 0x05 :
1234 retval = WXK_HELP;
1235 break;
1236 case 0x08 :
1237 retval = WXK_BACK;
1238 break;
1239 case 0x09 :
1240 retval = WXK_TAB;
1241 break;
1242 case 0x0b :
1243 retval = WXK_PAGEUP;
1244 break;
1245 case 0x0c :
1246 retval = WXK_PAGEDOWN;
1247 break;
1248 case 0x0d :
1249 retval = WXK_RETURN;
1250 break;
1251 case 0x10 :
1252 {
1253 switch( code )
1254 {
1255 case 0x7a :
1256 retval = WXK_F1 ;
1257 break;
1258 case 0x78 :
1259 retval = WXK_F2 ;
1260 break;
1261 case 0x63 :
1262 retval = WXK_F3 ;
1263 break;
1264 case 0x76 :
1265 retval = WXK_F4 ;
1266 break;
1267 case 0x60 :
1268 retval = WXK_F5 ;
1269 break;
1270 case 0x61 :
1271 retval = WXK_F6 ;
1272 break;
1273 case 0x62:
1274 retval = WXK_F7 ;
1275 break;
1276 case 0x64 :
1277 retval = WXK_F8 ;
1278 break;
1279 case 0x65 :
1280 retval = WXK_F9 ;
1281 break;
1282 case 0x6D :
1283 retval = WXK_F10 ;
1284 break;
1285 case 0x67 :
1286 retval = WXK_F11 ;
1287 break;
1288 case 0x6F :
1289 retval = WXK_F12 ;
1290 break;
1291 case 0x69 :
1292 retval = WXK_F13 ;
1293 break;
1294 case 0x6B :
1295 retval = WXK_F14 ;
1296 break;
1297 case 0x71 :
1298 retval = WXK_F15 ;
1299 break;
1300 }
1301 }
1302 break ;
1303 case 0x1b :
1304 retval = WXK_ESCAPE ;
1305 break ;
1306 case 0x1c :
1307 retval = WXK_LEFT ;
1308 break ;
1309 case 0x1d :
1310 retval = WXK_RIGHT ;
1311 break ;
1312 case 0x1e :
1313 retval = WXK_UP ;
1314 break ;
1315 case 0x1f :
1316 retval = WXK_DOWN ;
1317 break ;
1318 case 0x7F :
1319 retval = WXK_DELETE ;
1320 default:
1321 break ;
1322 } // end switch
1323
1324 return retval;
1325 }
1326
1327 void wxApp::MacHandleKeyDownEvent( EventRecord *ev )
1328 {
1329 wxToolTip::RemoveToolTips() ;
1330
1331 UInt32 menuresult = UMAMenuEvent(ev) ;
1332 if ( HiWord( menuresult ) )
1333 {
1334 if ( !s_macIsInModalLoop )
1335 MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ;
1336 }
1337 else
1338 {
1339 short keycode ;
1340 short keychar ;
1341 keychar = short(ev->message & charCodeMask);
1342 keycode = short(ev->message & keyCodeMask) >> 8 ;
1343
1344 wxWindow* focus = wxWindow::FindFocus() ;
1345 if ( focus )
1346 {
1347 long keyval = wxMacTranslateKey(keychar, keycode) ;
1348
1349 wxKeyEvent event(wxEVT_KEY_DOWN);
1350 event.m_shiftDown = ev->modifiers & shiftKey;
1351 event.m_controlDown = ev->modifiers & controlKey;
1352 event.m_altDown = ev->modifiers & optionKey;
1353 event.m_metaDown = ev->modifiers & cmdKey;
1354 event.m_keyCode = keyval;
1355 event.m_x = ev->where.h;
1356 event.m_y = ev->where.v;
1357 event.m_timeStamp = ev->when;
1358 event.SetEventObject(focus);
1359 bool handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1360 if ( !handled )
1361 {
1362 #if wxUSE_ACCEL
1363 if (!handled)
1364 {
1365 wxWindow *ancestor = focus;
1366 /*
1367 while (ancestor)
1368 {
1369 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1370 if (command != -1)
1371 {
1372 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1373 handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
1374 break;
1375 }
1376 if (ancestor->m_isFrame)
1377 break;
1378 ancestor = ancestor->GetParent();
1379 }
1380 */
1381 }
1382 #endif // wxUSE_ACCEL
1383 }
1384 if (!handled)
1385 {
1386 wxKeyEvent event(wxEVT_CHAR);
1387 event.m_shiftDown = ev->modifiers & shiftKey;
1388 event.m_controlDown = ev->modifiers & controlKey;
1389 event.m_altDown = ev->modifiers & optionKey;
1390 event.m_metaDown = ev->modifiers & cmdKey;
1391 event.m_keyCode = keyval;
1392 event.m_x = ev->where.h;
1393 event.m_y = ev->where.v;
1394 event.m_timeStamp = ev->when;
1395 event.SetEventObject(focus);
1396 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1397 }
1398 if ( !handled &&
1399 (keyval == WXK_TAB) &&
1400 (!focus->HasFlag(wxTE_PROCESS_TAB)) &&
1401 (focus->GetParent()) &&
1402 (focus->GetParent()->HasFlag( wxTAB_TRAVERSAL)) )
1403 {
1404 wxNavigationKeyEvent new_event;
1405 new_event.SetEventObject( focus );
1406 new_event.SetDirection( !event.ShiftDown() );
1407 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1408 new_event.SetWindowChange( event.ControlDown() );
1409 new_event.SetCurrentFocus( focus );
1410 handled = focus->GetEventHandler()->ProcessEvent( new_event );
1411 }
1412 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1413 if ( (!handled) &&
1414 (keyval == '.' && event.ControlDown() ) )
1415 {
1416 wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
1417 new_event.SetEventObject( focus );
1418 handled = focus->GetEventHandler()->ProcessEvent( new_event );
1419 }
1420 }
1421 }
1422 }
1423
1424 void wxApp::MacHandleKeyUpEvent( EventRecord *ev )
1425 {
1426 // nothing to do
1427 }
1428
1429 void wxApp::MacHandleActivateEvent( EventRecord *ev )
1430 {
1431 WindowRef window = (WindowRef) ev->message ;
1432 if ( window )
1433 {
1434 bool activate = (ev->modifiers & activeFlag ) ;
1435 WindowClass wclass ;
1436 UMAGetWindowClass ( window , &wclass ) ;
1437 if ( wclass == kFloatingWindowClass )
1438 {
1439 // if it is a floater we activate/deactivate the front non-floating window instead
1440 window = UMAFrontNonFloatingWindow() ;
1441 }
1442 wxWindow* win = wxFindWinFromMacWindow( window ) ;
1443 if ( win )
1444 win->MacActivate( ev , activate ) ;
1445 }
1446 }
1447
1448 void wxApp::MacHandleUpdateEvent( EventRecord *ev )
1449 {
1450 WindowRef window = (WindowRef) ev->message ;
1451 wxWindow * win = wxFindWinFromMacWindow( window ) ;
1452 if ( win )
1453 {
1454 win->MacUpdate( ev ) ;
1455 }
1456 else
1457 {
1458 // since there is no way of telling this foreign window to update itself
1459 // we have to invalidate the update region otherwise we keep getting the same
1460 // event over and over again
1461 BeginUpdate( window ) ;
1462 EndUpdate( window ) ;
1463 }
1464 }
1465
1466 void wxApp::MacHandleDiskEvent( EventRecord *ev )
1467 {
1468 if ( HiWord( ev->message ) != noErr )
1469 {
1470 #if !TARGET_CARBON
1471 OSErr err ;
1472 Point point ;
1473 SetPt( &point , 100 , 100 ) ;
1474
1475 err = DIBadMount( point , ev->message ) ;
1476 wxASSERT( err == noErr ) ;
1477 #endif
1478 }
1479 }
1480
1481 void wxApp::MacHandleOSEvent( EventRecord *ev )
1482 {
1483 switch( ( ev->message & osEvtMessageMask ) >> 24 )
1484 {
1485 case suspendResumeMessage :
1486 {
1487 bool isResuming = ev->message & resumeFlag ;
1488 #if !TARGET_CARBON
1489 bool convertClipboard = ev->message & convertClipboardFlag ;
1490 #else
1491 bool convertClipboard = false;
1492 #endif
1493 bool doesActivate = UMAGetProcessModeDoesActivateOnFGSwitch() ;
1494 if ( isResuming )
1495 {
1496 WindowRef oldFrontWindow = NULL ;
1497 WindowRef newFrontWindow = NULL ;
1498
1499 // in case we don't take care of activating ourselves, we have to synchronize
1500 // our idea of the active window with the process manager's - which it already activated
1501
1502 if ( !doesActivate )
1503 oldFrontWindow = UMAFrontNonFloatingWindow() ;
1504
1505 MacResume( convertClipboard ) ;
1506
1507 newFrontWindow = UMAFrontNonFloatingWindow() ;
1508
1509 if ( oldFrontWindow )
1510 {
1511 wxWindow* win = wxFindWinFromMacWindow( oldFrontWindow ) ;
1512 if ( win )
1513 win->MacActivate( ev , false ) ;
1514 }
1515 if ( newFrontWindow )
1516 {
1517 wxWindow* win = wxFindWinFromMacWindow( newFrontWindow ) ;
1518 if ( win )
1519 win->MacActivate( ev , true ) ;
1520 }
1521 }
1522 else
1523 {
1524 MacSuspend( convertClipboard ) ;
1525
1526 // in case this suspending did close an active window, another one might
1527 // have surfaced -> lets deactivate that one
1528
1529 WindowRef newActiveWindow = UMAGetActiveNonFloatingWindow() ;
1530 if ( newActiveWindow )
1531 {
1532 wxWindow* win = wxFindWinFromMacWindow( newActiveWindow ) ;
1533 if ( win )
1534 win->MacActivate( ev , false ) ;
1535 }
1536 }
1537 }
1538 break ;
1539 case mouseMovedMessage :
1540 {
1541 WindowRef window;
1542
1543 wxWindow* currentMouseWindow = NULL ;
1544
1545 wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) ,
1546 &currentMouseWindow ) ;
1547
1548 if ( currentMouseWindow != wxWindow::s_lastMouseWindow )
1549 {
1550 wxMouseEvent event ;
1551
1552 bool isDown = !(ev->modifiers & btnState) ; // 1 is for up
1553 bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse
1554
1555 event.m_leftDown = isDown && !controlDown;
1556 event.m_middleDown = FALSE;
1557 event.m_rightDown = isDown && controlDown;
1558 event.m_shiftDown = ev->modifiers & shiftKey;
1559 event.m_controlDown = ev->modifiers & controlKey;
1560 event.m_altDown = ev->modifiers & optionKey;
1561 event.m_metaDown = ev->modifiers & cmdKey;
1562 event.m_x = ev->where.h;
1563 event.m_y = ev->where.v;
1564 event.m_timeStamp = ev->when;
1565 event.SetEventObject(this);
1566
1567 if ( wxWindow::s_lastMouseWindow )
1568 {
1569 wxMouseEvent eventleave(event ) ;
1570 eventleave.SetEventType( wxEVT_LEAVE_WINDOW ) ;
1571 wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave);
1572 }
1573 if ( currentMouseWindow )
1574 {
1575 wxMouseEvent evententer(event ) ;
1576 evententer.SetEventType( wxEVT_ENTER_WINDOW ) ;
1577 currentMouseWindow->GetEventHandler()->ProcessEvent(evententer);
1578 }
1579 wxWindow::s_lastMouseWindow = currentMouseWindow ;
1580 }
1581
1582 short windowPart = ::FindWindow(ev->where, &window);
1583
1584 switch (windowPart)
1585 {
1586 // fixes for setting the cursor back from dominic mazzoni
1587 case inMenuBar :
1588 UMAShowArrowCursor();
1589 break ;
1590 case inSysWindow :
1591 UMAShowArrowCursor();
1592 break ;
1593 default:
1594 {
1595 if ( s_lastMouseDown == 0 )
1596 ev->modifiers |= btnState ;
1597
1598 wxWindow* win = wxFindWinFromMacWindow( window ) ;
1599 if ( win )
1600 win->MacMouseMoved( ev , windowPart ) ;
1601 else
1602 UMAShowArrowCursor();
1603
1604 }
1605 break;
1606 }
1607 }
1608 break ;
1609
1610 }
1611 }
1612
1613 void wxApp::MacHandleMenuSelect( int macMenuId , int macMenuItemNum )
1614 {
1615 if (macMenuId == 0)
1616 return; // no menu item selected
1617
1618 if (macMenuId == kwxMacAppleMenuId && macMenuItemNum > 1)
1619 {
1620 #if ! TARGET_CARBON
1621 Str255 deskAccessoryName ;
1622 GrafPtr savedPort ;
1623
1624 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId), macMenuItemNum, deskAccessoryName);
1625 GetPort(&savedPort);
1626 OpenDeskAcc(deskAccessoryName);
1627 SetPort(savedPort);
1628 #endif
1629 }
1630 else
1631 {
1632 wxWindow* frontwindow = wxFindWinFromMacWindow( ::FrontWindow() ) ;
1633 if ( frontwindow && wxMenuBar::MacGetInstalledMenuBar() )
1634 wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow->GetEventHandler() , 0 , macMenuId , macMenuItemNum ) ;
1635 }
1636 HiliteMenu(0);
1637 }
1638
1639 /*
1640 long wxApp::MacTranslateKey(char key, int mods)
1641 {
1642 }
1643
1644 void wxApp::MacAdjustCursor()
1645 {
1646 }
1647
1648 */
1649 /*
1650 void
1651 wxApp::macAdjustCursor()
1652 {
1653 if (ev->what != kHighLevelEvent)
1654 {
1655 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1656 if (theMacWxFrame)
1657 {
1658 if (!theMacWxFrame->MacAdjustCursor(ev->where))
1659 ::SetCursor(&(qd.arrow));
1660 }
1661 }
1662 }
1663 */