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