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