]> git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/app.cpp
metal appearance supported under 10.3
[wxWidgets.git] / src / mac / classic / app.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: app.cpp
3 // Purpose: wxApp
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "app.h"
14 #endif
15
16 #include "wx/defs.h"
17
18 #include "wx/window.h"
19 #include "wx/frame.h"
20 #include "wx/button.h"
21 #include "wx/app.h"
22 #include "wx/utils.h"
23 #include "wx/gdicmn.h"
24 #include "wx/pen.h"
25 #include "wx/brush.h"
26 #include "wx/cursor.h"
27 #include "wx/intl.h"
28 #include "wx/icon.h"
29 #include "wx/palette.h"
30 #include "wx/dc.h"
31 #include "wx/dialog.h"
32 #include "wx/msgdlg.h"
33 #include "wx/log.h"
34 #include "wx/module.h"
35 #include "wx/memory.h"
36 #include "wx/tooltip.h"
37 #include "wx/textctrl.h"
38 #include "wx/menu.h"
39 #include "wx/docview.h"
40 #include "wx/filename.h"
41
42 #include <string.h>
43
44 // mac
45
46 #ifndef __DARWIN__
47 #if __option(profile)
48 #include <profiler.h>
49 #endif
50 #endif
51
52 #include "apprsrc.h"
53
54 #include "wx/mac/uma.h"
55 #include "wx/mac/macnotfy.h"
56
57 #ifdef __DARWIN__
58 # include <CoreServices/CoreServices.h>
59 # if defined(WXMAKINGDLL_CORE)
60 # include <mach-o/dyld.h>
61 # endif
62 #else
63 # include <Sound.h>
64 # include <Threads.h>
65 # include <ToolUtils.h>
66 # include <DiskInit.h>
67 # include <Devices.h>
68 #endif
69
70 extern wxList wxPendingDelete;
71 extern wxList *wxWinMacWindowList;
72 extern wxList *wxWinMacControlList;
73 #if wxUSE_THREADS
74 extern size_t g_numberOfThreads;
75 #endif // wxUSE_THREADS
76
77 // statics for implementation
78
79 static bool s_inYield = FALSE;
80
81 #if TARGET_CARBON
82 static bool s_inReceiveEvent = FALSE ;
83 static EventTime sleepTime = kEventDurationNoWait ;
84 #else
85 static long sleepTime = 0 ;
86 #endif
87
88 #if !USE_SHARED_LIBRARY
89 IMPLEMENT_DYNAMIC_CLASS(wxApp, wxEvtHandler)
90 BEGIN_EVENT_TABLE(wxApp, wxEvtHandler)
91 EVT_IDLE(wxApp::OnIdle)
92 EVT_END_SESSION(wxApp::OnEndSession)
93 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession)
94 END_EVENT_TABLE()
95 #endif
96
97
98 const short kMacMinHeap = (29 * 1024) ;
99 // platform specific static variables
100
101 const short kwxMacMenuBarResource = 1 ;
102 const short kwxMacAppleMenuId = 1 ;
103
104 WXHRGN wxApp::s_macCursorRgn = NULL;
105 wxWindow* wxApp::s_captureWindow = NULL ;
106 int wxApp::s_lastMouseDown = 0 ;
107 long wxApp::sm_lastMessageTime = 0;
108 long wxApp::s_lastModifiers = 0 ;
109
110
111 bool wxApp::s_macSupportPCMenuShortcuts = true ;
112 long wxApp::s_macAboutMenuItemId = wxID_ABOUT ;
113 long wxApp::s_macPreferencesMenuItemId = wxID_PREFERENCES ;
114 long wxApp::s_macExitMenuItemId = wxID_EXIT ;
115 wxString wxApp::s_macHelpMenuTitleName = wxT("&Help") ;
116
117 // Normally we're not a plugin
118 bool wxApp::sm_isEmbedded = false;
119 //----------------------------------------------------------------------
120 // Core Apple Event Support
121 //----------------------------------------------------------------------
122
123 pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
124 pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
125 pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
126 pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
127 pascal OSErr AEHandleRApp( const AppleEvent *event , AppleEvent *reply , long refcon ) ;
128
129 pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
130 {
131 return wxTheApp->MacHandleAEODoc( (AppleEvent*) event , reply) ;
132 }
133
134 pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
135 {
136 return wxTheApp->MacHandleAEOApp( (AppleEvent*) event , reply ) ;
137 }
138
139 pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
140 {
141 return wxTheApp->MacHandleAEPDoc( (AppleEvent*) event , reply ) ;
142 }
143
144 pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
145 {
146 return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ;
147 }
148
149 pascal OSErr AEHandleRApp( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
150 {
151 return wxTheApp->MacHandleAERApp( (AppleEvent*) event , reply) ;
152 }
153
154 // AEODoc Calls MacOpenFile on each of the files passed
155
156 short wxApp::MacHandleAEODoc(const WXEVENTREF event, WXEVENTREF WXUNUSED(reply))
157 {
158 AEDescList docList;
159 AEKeyword keywd;
160 DescType returnedType;
161 Size actualSize;
162 long itemsInList;
163 FSSpec theSpec;
164 OSErr err;
165 short i;
166 err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList);
167 if (err != noErr)
168 return err;
169
170 err = AECountItems(&docList, &itemsInList);
171 if (err != noErr)
172 return err;
173
174 ProcessSerialNumber PSN ;
175 PSN.highLongOfPSN = 0 ;
176 PSN.lowLongOfPSN = kCurrentProcess ;
177 SetFrontProcess( &PSN ) ;
178
179 for (i = 1; i <= itemsInList; i++) {
180 AEGetNthPtr(&docList, i, typeFSS, &keywd, &returnedType,
181 (Ptr) & theSpec, sizeof(theSpec), &actualSize);
182 wxString fName = wxMacFSSpec2MacFilename(&theSpec);
183 MacOpenFile(fName);
184 }
185 return noErr;
186 }
187
188 // AEPDoc Calls MacPrintFile on each of the files passed
189
190 short wxApp::MacHandleAEPDoc(const WXEVENTREF event , WXEVENTREF WXUNUSED(reply))
191 {
192 AEDescList docList;
193 AEKeyword keywd;
194 DescType returnedType;
195 Size actualSize;
196 long itemsInList;
197 FSSpec theSpec;
198 OSErr err;
199 short i;
200 err = AEGetParamDesc((AppleEvent *)event, keyDirectObject, typeAEList,&docList);
201 if (err != noErr)
202 return err;
203
204 err = AECountItems(&docList, &itemsInList);
205 if (err != noErr)
206 return err;
207
208 ProcessSerialNumber PSN ;
209 PSN.highLongOfPSN = 0 ;
210 PSN.lowLongOfPSN = kCurrentProcess ;
211 SetFrontProcess( &PSN ) ;
212
213 for (i = 1; i <= itemsInList; i++) {
214 AEGetNthPtr(&docList, i, typeFSS, &keywd, &returnedType,
215 (Ptr) & theSpec, sizeof(theSpec), &actualSize);
216 wxString fName = wxMacFSSpec2MacFilename(&theSpec);
217 MacPrintFile(fName);
218 }
219 return noErr;
220 }
221
222 // AEOApp calls MacNewFile
223
224 short wxApp::MacHandleAEOApp(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply))
225 {
226 MacNewFile() ;
227 return noErr ;
228 }
229
230 // AEQuit attempts to quit the application
231
232 short wxApp::MacHandleAEQuit(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply))
233 {
234 wxWindow* win = GetTopWindow() ;
235 if ( win )
236 {
237 wxCommandEvent exitEvent(wxEVT_COMMAND_MENU_SELECTED, s_macExitMenuItemId);
238 if (!win->ProcessEvent(exitEvent))
239 win->Close(TRUE ) ;
240 }
241 else
242 {
243 ExitMainLoop() ;
244 }
245 return noErr ;
246 }
247
248 // AEROApp calls MacReopenApp
249
250 short wxApp::MacHandleAERApp(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNUSED(reply))
251 {
252 MacReopenApp() ;
253 return noErr ;
254 }
255
256
257 //----------------------------------------------------------------------
258 // Support Routines linking the Mac...File Calls to the Document Manager
259 //----------------------------------------------------------------------
260
261 void wxApp::MacOpenFile(const wxString & fileName )
262 {
263 wxDocManager* dm = wxDocManager::GetDocumentManager() ;
264 if ( dm )
265 dm->CreateDocument(fileName , wxDOC_SILENT ) ;
266 }
267
268 void wxApp::MacPrintFile(const wxString & fileName )
269 {
270 wxDocManager* dm = wxDocManager::GetDocumentManager() ;
271 if ( dm )
272 {
273 wxDocument *doc = dm->CreateDocument(fileName , wxDOC_SILENT ) ;
274 if ( doc )
275 {
276 wxView* view = doc->GetFirstView() ;
277 if( view )
278 {
279 wxPrintout *printout = view->OnCreatePrintout();
280 if (printout)
281 {
282 wxPrinter printer;
283 printer.Print(view->GetFrame(), printout, TRUE);
284 delete printout;
285 }
286 }
287 if (doc->Close())
288 {
289 doc->DeleteAllViews();
290 dm->RemoveDocument(doc) ;
291 }
292 }
293 }
294 }
295
296 void wxApp::MacNewFile()
297 {
298 }
299
300 void wxApp::MacReopenApp()
301 {
302 // eventually check for open docs, if none, call MacNewFile
303 }
304
305 //----------------------------------------------------------------------
306 // Carbon Event Handler
307 //----------------------------------------------------------------------
308
309 #if TARGET_CARBON
310
311 static const EventTypeSpec eventList[] =
312 {
313 { kEventClassCommand, kEventProcessCommand } ,
314 { kEventClassCommand, kEventCommandUpdateStatus } ,
315
316 { kEventClassMenu, kEventMenuOpening },
317 { kEventClassMenu, kEventMenuClosed },
318 { kEventClassMenu, kEventMenuTargetItem },
319
320 { kEventClassApplication , kEventAppActivated } ,
321 { kEventClassApplication , kEventAppDeactivated } ,
322 // handling the quit event is not recommended by apple
323 // rather using the quit apple event - which we do
324
325 { kEventClassAppleEvent , kEventAppleEvent } ,
326
327 { kEventClassMouse , kEventMouseDown } ,
328 { kEventClassMouse , kEventMouseMoved } ,
329 { kEventClassMouse , kEventMouseUp } ,
330 { kEventClassMouse , kEventMouseDragged } ,
331 { 'WXMC' , 'WXMC' }
332 } ;
333
334 static pascal OSStatus
335 MenuEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
336 {
337 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar();
338
339 if ( mbar )
340 {
341 wxFrame* win = mbar->GetFrame();
342 if ( win )
343 {
344
345 // VZ: we could find the menu from its handle here by examining all
346 // the menus in the menu bar recursively but knowing that neither
347 // wxMSW nor wxGTK do it why bother...
348 #if 0
349 MenuRef menuRef;
350
351 GetEventParameter(event,
352 kEventParamDirectObject,
353 typeMenuRef, NULL,
354 sizeof(menuRef), NULL,
355 &menuRef);
356 #endif // 0
357
358 wxEventType type=0;
359 MenuCommand cmd=0;
360 switch (GetEventKind(event))
361 {
362 case kEventMenuOpening:
363 type = wxEVT_MENU_OPEN;
364 break;
365 case kEventMenuClosed:
366 type = wxEVT_MENU_CLOSE;
367 break;
368 case kEventMenuTargetItem:
369 type = wxEVT_MENU_HIGHLIGHT;
370 GetEventParameter(event, kEventParamMenuCommand,
371 typeMenuCommand, NULL,
372 sizeof(cmd), NULL, &cmd);
373 if (cmd == 0) return eventNotHandledErr;
374 break;
375 default:
376 wxFAIL_MSG(wxT("Unexpected menu event kind"));
377 break;
378 }
379
380 wxMenuEvent wxevent(type, cmd);
381 wxevent.SetEventObject(win);
382
383 (void)win->GetEventHandler()->ProcessEvent(wxevent);
384 }
385 }
386
387 return eventNotHandledErr;
388 }
389
390 // due to the rather low-level event API of wxWidgets, we cannot use RunApplicationEventLoop
391 // but have to use ReceiveNextEvent dealing with events manually, therefore we also have
392 // deal with clicks in the menu bar explicitely
393
394 pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ;
395
396 static pascal OSStatus MouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
397 {
398 OSStatus result = eventNotHandledErr ;
399
400 Point point ;
401 UInt32 modifiers = 0;
402 EventMouseButton button = 0 ;
403 UInt32 click = 0 ;
404
405 GetEventParameter( event, kEventParamMouseLocation, typeQDPoint, NULL,
406 sizeof( Point ), NULL, &point );
407 GetEventParameter( event, kEventParamKeyModifiers, typeUInt32, NULL,
408 sizeof( UInt32 ), NULL, &modifiers );
409 GetEventParameter( event, kEventParamMouseButton, typeMouseButton, NULL,
410 sizeof( EventMouseButton ), NULL, &button );
411 GetEventParameter( event, kEventParamClickCount, typeUInt32, NULL,
412 sizeof( UInt32 ), NULL, &click );
413
414 if ( button == 0 || GetEventKind( event ) == kEventMouseUp )
415 modifiers += btnState ;
416
417
418 switch( GetEventKind(event) )
419 {
420 case kEventMouseDown :
421 {
422 WindowRef window ;
423
424 short windowPart = ::FindWindow(point, &window);
425
426 if ( windowPart == inMenuBar )
427 {
428 MenuSelect( point ) ;
429 result = noErr ;
430 }
431 }
432 break ;
433 case kEventMouseDragged :
434 case kEventMouseUp :
435 {
436 if ( wxTheApp->s_captureWindow )
437 wxMacWindowEventHandler( handler , event , (void*) wxTheApp->s_captureWindow->MacGetTopLevelWindow() ) ;
438 }
439 break ;
440 case kEventMouseMoved :
441 {
442 wxTheApp->MacHandleMouseMovedEvent( point.h , point.v , modifiers , EventTimeToTicks( GetEventTime( event ) ) ) ;
443 result = noErr ;
444 break ;
445 }
446 break ;
447 }
448
449 return result ;
450 }
451
452 static pascal OSStatus CommandEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
453 {
454 OSStatus result = eventNotHandledErr ;
455
456 HICommand command ;
457
458 GetEventParameter( event, kEventParamDirectObject, typeHICommand, NULL,
459 sizeof( HICommand ), NULL, &command );
460
461 MenuCommand id = command.commandID ;
462 if ( id == kHICommandPreferences )
463 id = wxApp::s_macPreferencesMenuItemId ;
464
465 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
466 wxMenu* menu = NULL ;
467 wxMenuItem* item = NULL ;
468
469 if ( mbar )
470 {
471 item = mbar->FindItem( id , &menu ) ;
472 // it is not 100 % sure that an menu of id 0 is really ours, safety check
473 if ( id == 0 && menu != NULL && menu->GetHMenu() != command.menu.menuRef )
474 {
475 item = NULL ;
476 menu = NULL ;
477 }
478 }
479
480 if ( item == NULL || menu == NULL || mbar == NULL )
481 return result ;
482
483 switch( GetEventKind( event ) )
484 {
485 case kEventProcessCommand :
486 {
487 if (item->IsCheckable())
488 {
489 item->Check( !item->IsChecked() ) ;
490 }
491
492 menu->SendEvent( id , item->IsCheckable() ? item->IsChecked() : -1 ) ;
493 result = noErr ;
494 }
495 break ;
496 case kEventCommandUpdateStatus:
497 // eventually trigger an updateui round
498 result = noErr ;
499 break ;
500 default :
501 break ;
502 }
503
504 return result ;
505 }
506
507 static pascal OSStatus ApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
508 {
509 OSStatus result = eventNotHandledErr ;
510 switch ( GetEventKind( event ) )
511 {
512 case kEventAppActivated :
513 {
514 if ( wxTheApp )
515 wxTheApp->MacResume( true ) ;
516 result = noErr ;
517 }
518 break ;
519 case kEventAppDeactivated :
520 {
521 if ( wxTheApp )
522 wxTheApp->MacSuspend( true ) ;
523 result = noErr ;
524 }
525 break ;
526 default :
527 break ;
528 }
529 return result ;
530 }
531
532 pascal OSStatus wxAppEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
533 {
534 OSStatus result = eventNotHandledErr ;
535 switch( GetEventClass( event ) )
536 {
537 case kEventClassCommand :
538 result = CommandEventHandler( handler , event , data ) ;
539 break ;
540 case kEventClassApplication :
541 result = ApplicationEventHandler( handler , event , data ) ;
542 break ;
543 case kEventClassMenu :
544 result = MenuEventHandler( handler , event , data ) ;
545 break ;
546 case kEventClassMouse :
547 result = MouseEventHandler( handler , event , data ) ;
548 break ;
549 case kEventClassAppleEvent :
550 {
551 EventRecord rec ;
552 wxMacConvertEventToRecord( event , &rec ) ;
553 result = AEProcessAppleEvent( &rec ) ;
554 }
555 break ;
556 default :
557 break ;
558 }
559
560 return result ;
561 }
562
563 DEFINE_ONE_SHOT_HANDLER_GETTER( wxAppEventHandler )
564
565 #endif
566
567 #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
568 // we know it's there ;-)
569 WXIMPORT char std::__throws_bad_alloc ;
570 #endif
571
572 bool wxApp::Initialize(int& argc, wxChar **argv)
573 {
574 int error = 0 ;
575
576 // Mac-specific
577
578 UMAInitToolbox( 4, sm_isEmbedded ) ;
579 SetEventMask( everyEvent ) ;
580 UMAShowWatchCursor() ;
581
582 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
583 // open shared library resources from here since we don't have
584 // __wxinitialize in Mach-O shared libraries
585 wxStAppResource::OpenSharedLibraryResource(NULL);
586 #endif
587
588 #ifndef __DARWIN__
589 // test the minimal configuration necessary
590
591 # if !TARGET_CARBON
592 long theSystem ;
593 long theMachine;
594
595 if (Gestalt(gestaltMachineType, &theMachine) != noErr)
596 {
597 error = kMacSTRWrongMachine;
598 }
599 else if (theMachine < gestaltMacPlus)
600 {
601 error = kMacSTRWrongMachine;
602 }
603 else if (Gestalt(gestaltSystemVersion, &theSystem) != noErr )
604 {
605 error = kMacSTROldSystem ;
606 }
607 else if ( theSystem < 0x0860 )
608 {
609 error = kMacSTROldSystem ;
610 }
611 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap)
612 {
613 error = kMacSTRSmallSize;
614 }
615 # endif
616 /*
617 else
618 {
619 if ( !UMAHasAppearance() )
620 {
621 error = kMacSTRNoPre8Yet ;
622 }
623 }
624 */
625 #endif
626
627 // if we encountered any problems so far, give the error code and exit immediately
628
629 if ( error )
630 {
631 wxStAppResource resload ;
632 short itemHit;
633 Str255 message;
634
635 GetIndString(message, 128, error);
636 UMAShowArrowCursor() ;
637 ParamText("\pFatal Error", message, (ConstStr255Param)"\p", (ConstStr255Param)"\p");
638 itemHit = Alert(128, nil);
639 return FALSE ;
640 }
641
642 #ifndef __DARWIN__
643 # if __option(profile)
644 ProfilerInit( collectDetailed, bestTimeBase , 40000 , 50 ) ;
645 # endif
646 #endif
647
648 #ifndef __DARWIN__
649 // now avoid exceptions thrown for new (bad_alloc)
650 // FIXME CS for some changes outside wxMac does not compile anymore
651 #if 0
652 std::__throws_bad_alloc = 0 ;
653 #endif
654
655 #endif
656
657 s_macCursorRgn = ::NewRgn() ;
658
659 // Mac OS X passes a process serial number command line argument when
660 // the application is launched from the Finder. This argument must be
661 // removed from the command line arguments before being handled by the
662 // application (otherwise applications would need to handle it)
663 if ( argc > 1 )
664 {
665 static const wxChar *ARG_PSN = _T("-psn_");
666 if ( wxStrncmp(argv[1], ARG_PSN, wxStrlen(ARG_PSN)) == 0 )
667 {
668 // remove this argument
669 --argc;
670 memmove(argv + 1, argv + 2, argc * sizeof(char *));
671 }
672 }
673
674 if ( !wxAppBase::Initialize(argc, argv) )
675 return false;
676
677 #if wxUSE_INTL
678 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
679 #endif
680
681
682 wxWinMacWindowList = new wxList(wxKEY_INTEGER);
683 wxWinMacControlList = new wxList(wxKEY_INTEGER);
684
685 wxMacCreateNotifierTable() ;
686
687 UMAShowArrowCursor() ;
688
689 return true;
690 }
691
692 bool wxApp::OnInitGui()
693 {
694 if( !wxAppBase::OnInitGui() )
695 return false ;
696
697 #if TARGET_CARBON
698 InstallStandardEventHandler( GetApplicationEventTarget() ) ;
699
700 if (!sm_isEmbedded)
701 {
702 InstallApplicationEventHandler(
703 GetwxAppEventHandlerUPP(),
704 GetEventTypeCount(eventList), eventList, wxTheApp, (EventHandlerRef *)&(wxTheApp->m_macEventHandler));
705 }
706 #endif
707
708 if (!sm_isEmbedded)
709 {
710 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
711 AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments ,
712 NewAEEventHandlerUPP(AEHandleODoc) ,
713 0 , FALSE ) ;
714 AEInstallEventHandler( kCoreEventClass , kAEOpenApplication ,
715 NewAEEventHandlerUPP(AEHandleOApp) ,
716 0 , FALSE ) ;
717 AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments ,
718 NewAEEventHandlerUPP(AEHandlePDoc) ,
719 0 , FALSE ) ;
720 AEInstallEventHandler( kCoreEventClass , kAEReopenApplication ,
721 NewAEEventHandlerUPP(AEHandleRApp) ,
722 0 , FALSE ) ;
723 AEInstallEventHandler( kCoreEventClass , kAEQuitApplication ,
724 NewAEEventHandlerUPP(AEHandleQuit) ,
725 0 , FALSE ) ;
726 #else
727 AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments ,
728 NewAEEventHandlerProc(AEHandleODoc) ,
729 0 , FALSE ) ;
730 AEInstallEventHandler( kCoreEventClass , kAEOpenApplication ,
731 NewAEEventHandlerProc(AEHandleOApp) ,
732 0 , FALSE ) ;
733 AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments ,
734 NewAEEventHandlerProc(AEHandlePDoc) ,
735 0 , FALSE ) ;
736 AEInstallEventHandler( kCoreEventClass , kAEReopenApplication ,
737 NewAEEventHandlerProc(AEHandleRApp) ,
738 0 , FALSE ) ;
739 AEInstallEventHandler( kCoreEventClass , kAEQuitApplication ,
740 NewAEEventHandlerProc(AEHandleQuit) ,
741 0 , FALSE ) ;
742 #endif
743 }
744
745 return TRUE ;
746 }
747
748 void wxApp::CleanUp()
749 {
750 wxToolTip::RemoveToolTips() ;
751
752 // One last chance for pending objects to be cleaned up
753 wxTheApp->DeletePendingObjects();
754
755 wxMacDestroyNotifierTable() ;
756
757 delete wxWinMacWindowList ;
758 wxWinMacWindowList = NULL;
759
760 delete wxWinMacControlList ;
761 wxWinMacControlList = NULL;
762
763 #ifndef __DARWIN__
764 # if __option(profile)
765 ProfilerDump( (StringPtr)"\papp.prof" ) ;
766 ProfilerTerm() ;
767 # endif
768 #endif
769
770 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
771 // close shared library resources from here since we don't have
772 // __wxterminate in Mach-O shared libraries
773 wxStAppResource::CloseSharedLibraryResource();
774 #endif
775
776 UMACleanupToolbox() ;
777 if (s_macCursorRgn) {
778 ::DisposeRgn((RgnHandle)s_macCursorRgn);
779 }
780
781 #if 0
782 TerminateAE() ;
783 #endif
784
785 wxAppBase::CleanUp();
786 }
787
788 //----------------------------------------------------------------------
789 // misc initialization stuff
790 //----------------------------------------------------------------------
791
792 // extern variable for shared library resource id
793 // need to be able to find it with NSLookupAndBindSymbol
794 short gSharedLibraryResource = kResFileNotOpened ;
795
796 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
797 CFBundleRef gSharedLibraryBundle = NULL;
798 #endif /* WXMAKINGDLL_CORE && __DARWIN__ */
799
800 wxStAppResource::wxStAppResource()
801 {
802 m_currentRefNum = CurResFile() ;
803 if ( gSharedLibraryResource != kResFileNotOpened )
804 {
805 UseResFile( gSharedLibraryResource ) ;
806 }
807 }
808
809 wxStAppResource::~wxStAppResource()
810 {
811 if ( m_currentRefNum != kResFileNotOpened )
812 {
813 UseResFile( m_currentRefNum ) ;
814 }
815 }
816
817 void wxStAppResource::OpenSharedLibraryResource(const void *initBlock)
818 {
819 gSharedLibraryResource = kResFileNotOpened;
820
821 #ifdef WXMAKINGDLL_CORE
822 if ( initBlock != NULL ) {
823 const CFragInitBlock *theInitBlock = (const CFragInitBlock *)initBlock;
824 FSSpec *fileSpec = NULL;
825
826 if (theInitBlock->fragLocator.where == kDataForkCFragLocator) {
827 fileSpec = theInitBlock->fragLocator.u.onDisk.fileSpec;
828 }
829 else if (theInitBlock->fragLocator.where == kResourceCFragLocator) {
830 fileSpec = theInitBlock->fragLocator.u.inSegs.fileSpec;
831 }
832
833 if (fileSpec != NULL) {
834 gSharedLibraryResource = FSpOpenResFile(fileSpec, fsRdPerm);
835 }
836 }
837 else {
838 #ifdef __DARWIN__
839 // Open the shared library resource file if it is not yet open
840 NSSymbol theSymbol;
841 NSModule theModule;
842 const char *theLibPath;
843
844 gSharedLibraryBundle = CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWidgets"));
845 if (gSharedLibraryBundle != NULL) {
846 // wxWidgets has been bundled into a framework
847 // load the framework resources
848
849 gSharedLibraryResource = CFBundleOpenBundleResourceMap(gSharedLibraryBundle);
850 }
851 else {
852 // wxWidgets is a simple dynamic shared library
853 // load the resources from the data fork of a separate resource file
854 wxString theResPath;
855 wxString theName;
856 FSRef theResRef;
857 OSErr theErr = noErr;
858
859 // get the library path
860 theSymbol = NSLookupAndBindSymbol("_gSharedLibraryResource");
861 theModule = NSModuleForSymbol(theSymbol);
862 theLibPath = NSLibraryNameForModule(theModule);
863
864 // if we call wxLogDebug from here then, as wxTheApp hasn't been
865 // created yet when we're called from wxApp::Initialize(), wxLog
866 // is going to create a default stderr-based log target instead of
867 // the expected normal GUI one -- don't do it, if we really want
868 // to see this message just use fprintf() here
869 #if 0
870 wxLogDebug( wxT("wxMac library installation name is '%s'"),
871 theLibPath );
872 #endif
873
874 // allocate copy to replace .dylib.* extension with .rsrc
875 if (theLibPath != NULL) {
876 #if wxUSE_UNICODE
877 theResPath = wxString(theLibPath, wxConvLocal);
878 #else
879 theResPath = wxString(theLibPath);
880 #endif
881 // replace '_core' with '' in case of multi-lib build
882 theResPath.Replace(wxT("_core"), wxEmptyString);
883 // replace ".dylib" shared library extension with ".rsrc"
884 theResPath.Replace(wxT(".dylib"), wxT(".rsrc"));
885 // Find the begining of the filename
886 theName = theResPath.AfterLast('/');
887
888 #if 0
889 wxLogDebug( wxT("wxMac resources file name is '%s'"),
890 theResPath.mb_str() );
891 #endif
892
893 theErr = FSPathMakeRef((UInt8 *) theResPath.mb_str(), &theResRef, false);
894 if (theErr != noErr) {
895 // try in current directory (using name only)
896 theErr = FSPathMakeRef((UInt8 *) theName.mb_str(), &theResRef, false);
897 }
898
899 // open the resource file
900 if (theErr == noErr) {
901 theErr = FSOpenResourceFile( &theResRef, 0, NULL, fsRdPerm,
902 &gSharedLibraryResource);
903 }
904 if (theErr != noErr) {
905 #ifdef __WXDEBUG__
906 wxLogDebug( wxT("unable to open wxMac resource file '%s'\n"),
907 theResPath.mb_str() );
908 #endif // __WXDEBUG__
909 }
910
911 }
912 }
913 #endif /* __DARWIN__ */
914 }
915 #endif /* WXMAKINGDLL_CORE */
916 }
917
918 void wxStAppResource::CloseSharedLibraryResource()
919 {
920 #ifdef WXMAKINGDLL_CORE
921 // Close the shared library resource file
922 if (gSharedLibraryResource != kResFileNotOpened) {
923 #ifdef __DARWIN__
924 if (gSharedLibraryBundle != NULL) {
925 CFBundleCloseBundleResourceMap(gSharedLibraryBundle,
926 gSharedLibraryResource);
927 gSharedLibraryBundle = NULL;
928 }
929 else
930 #endif /* __DARWIN__ */
931 {
932 CloseResFile(gSharedLibraryResource);
933 }
934 gSharedLibraryResource = kResFileNotOpened;
935 }
936 #endif /* WXMAKINGDLL_CORE */
937 }
938
939 #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
940
941 // for shared libraries we have to manually get the correct resource
942 // ref num upon initializing and releasing when terminating, therefore
943 // the __wxinitialize and __wxterminate must be used
944
945 extern "C" {
946 void __sinit(void); /* (generated by linker) */
947 pascal OSErr __initialize(const CFragInitBlock *theInitBlock);
948 pascal void __terminate(void);
949 }
950
951 pascal OSErr __wxinitialize(const CFragInitBlock *theInitBlock)
952 {
953 wxStAppResource::OpenSharedLibraryResource( theInitBlock ) ;
954 return __initialize( theInitBlock ) ;
955 }
956
957 pascal void __wxterminate(void)
958 {
959 wxStAppResource::CloseSharedLibraryResource() ;
960 __terminate() ;
961 }
962
963 #endif /* WXMAKINGDLL_CORE && !__DARWIN__ */
964
965 #if TARGET_CARBON
966
967 bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec)
968 {
969 bool converted = ConvertEventRefToEventRecord( event,rec) ;
970 OSStatus err = noErr ;
971 if ( !converted )
972 {
973 switch( GetEventClass( event ) )
974 {
975 case kEventClassKeyboard :
976 {
977 converted = true ;
978 switch( GetEventKind(event) )
979 {
980 case kEventRawKeyDown :
981 rec->what = keyDown ;
982 break ;
983 case kEventRawKeyRepeat :
984 rec->what = autoKey ;
985 break ;
986 case kEventRawKeyUp :
987 rec->what = keyUp ;
988 break ;
989 case kEventRawKeyModifiersChanged :
990 rec->what = nullEvent ;
991 break ;
992 default :
993 converted = false ;
994 break ;
995 }
996 if ( converted )
997 {
998 UInt32 keyCode ;
999 unsigned char charCode ;
1000 UInt32 modifiers ;
1001 GetMouse( &rec->where) ;
1002
1003 err = GetEventParameter(event, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers);
1004 err = GetEventParameter(event, kEventParamKeyCode, typeUInt32, NULL, 4, NULL, &keyCode);
1005 err = GetEventParameter(event, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode);
1006 rec->modifiers = modifiers ;
1007 rec->message = (keyCode << 8 ) + charCode ;
1008 }
1009 }
1010 break ;
1011 case kEventClassTextInput :
1012 {
1013 switch( GetEventKind( event ) )
1014 {
1015 case kEventTextInputUnicodeForKeyEvent :
1016 {
1017 EventRef rawEvent ;
1018 err = GetEventParameter( event , kEventParamTextInputSendKeyboardEvent ,typeEventRef,NULL,sizeof(rawEvent),NULL,&rawEvent ) ;
1019 converted = true ;
1020 {
1021 UInt32 keyCode ;
1022 unsigned char charCode ;
1023 UInt32 modifiers ;
1024 GetMouse( &rec->where) ;
1025 rec->what = keyDown ;
1026 err = GetEventParameter(rawEvent, kEventParamKeyModifiers, typeUInt32, NULL, 4, NULL, &modifiers);
1027 err = GetEventParameter(rawEvent, kEventParamKeyCode, typeUInt32, NULL, 4, NULL, &keyCode);
1028 err = GetEventParameter(rawEvent, kEventParamKeyMacCharCodes, typeChar, NULL, 1, NULL, &charCode);
1029 rec->modifiers = modifiers ;
1030 rec->message = (keyCode << 8 ) + charCode ;
1031 }
1032 }
1033 break ;
1034 default :
1035 break ;
1036 }
1037 }
1038 break ;
1039 }
1040 }
1041
1042 return converted ;
1043 }
1044
1045 /*
1046 pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
1047 {
1048 OSStatus result = eventNotHandledErr ;
1049
1050 EventRecord rec ;
1051 switch ( GetEventClass( event ) )
1052 {
1053 case kEventClassKeyboard :
1054 if ( wxMacConvertEventToRecord( event , &rec ) )
1055 {
1056 wxTheApp->MacHandleModifierEvents( &rec ) ;
1057 wxTheApp->MacHandleOneEvent( &rec ) ;
1058 result = noErr ;
1059 }
1060 break ;
1061 case kEventClassTextInput :
1062 if ( wxMacConvertEventToRecord( event , &rec ) )
1063 {
1064 wxTheApp->MacHandleModifierEvents( &rec ) ;
1065 wxTheApp->MacHandleOneEvent( &rec ) ;
1066 result = noErr ;
1067 }
1068 break ;
1069 default :
1070 break ;
1071 }
1072 return result ;
1073 }
1074 */
1075 #endif
1076
1077 wxApp::wxApp()
1078 {
1079 m_printMode = wxPRINT_WINDOWS;
1080 m_auto3D = TRUE;
1081
1082 m_macCurrentEvent = NULL ;
1083 #if TARGET_CARBON
1084 m_macCurrentEventHandlerCallRef = NULL ;
1085 #endif
1086 }
1087
1088 int wxApp::MainLoop()
1089 {
1090 m_keepGoing = TRUE;
1091
1092 while (m_keepGoing)
1093 {
1094 MacDoOneEvent() ;
1095 }
1096
1097 return 0;
1098 }
1099
1100 void wxApp::ExitMainLoop()
1101 {
1102 m_keepGoing = FALSE;
1103 }
1104
1105 // Is a message/event pending?
1106 bool wxApp::Pending()
1107 {
1108 #if TARGET_CARBON
1109 // without the receive event (with pull param = false ) nothing is ever reported
1110 EventRef theEvent;
1111 ReceiveNextEvent (0, NULL, kEventDurationNoWait, false, &theEvent);
1112 return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ;
1113 #else
1114 EventRecord event ;
1115
1116 return EventAvail( everyEvent , &event ) ;
1117 #endif
1118 }
1119
1120 // Dispatch a message.
1121 bool wxApp::Dispatch()
1122 {
1123 MacDoOneEvent() ;
1124
1125 return true;
1126 }
1127
1128 void wxApp::OnIdle(wxIdleEvent& event)
1129 {
1130 wxAppBase::OnIdle(event);
1131
1132 // If they are pending events, we must process them: pending events are
1133 // either events to the threads other than main or events posted with
1134 // wxPostEvent() functions
1135 wxMacProcessNotifierAndPendingEvents();
1136
1137 if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
1138 wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
1139 }
1140
1141 void wxApp::WakeUpIdle()
1142 {
1143 wxMacWakeUp() ;
1144 }
1145
1146 void wxApp::Exit()
1147 {
1148 wxApp::CleanUp();
1149 ::ExitToShell() ;
1150 }
1151
1152 void wxApp::OnEndSession(wxCloseEvent& WXUNUSED(event))
1153 {
1154 if (GetTopWindow())
1155 GetTopWindow()->Close(TRUE);
1156 }
1157
1158 // Default behaviour: close the application with prompts. The
1159 // user can veto the close, and therefore the end session.
1160 void wxApp::OnQueryEndSession(wxCloseEvent& event)
1161 {
1162 if (GetTopWindow())
1163 {
1164 if (!GetTopWindow()->Close(!event.CanVeto()))
1165 event.Veto(TRUE);
1166 }
1167 }
1168
1169 extern "C" void wxCYield() ;
1170 void wxCYield()
1171 {
1172 wxYield() ;
1173 }
1174
1175 // Yield to other processes
1176
1177 bool wxApp::Yield(bool onlyIfNeeded)
1178 {
1179 if (s_inYield)
1180 {
1181 if ( !onlyIfNeeded )
1182 {
1183 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1184 }
1185
1186 return FALSE;
1187 }
1188
1189 s_inYield = TRUE;
1190
1191 #if wxUSE_THREADS
1192 YieldToAnyThread() ;
1193 #endif
1194 // by definition yield should handle all non-processed events
1195 #if TARGET_CARBON
1196 EventRef theEvent;
1197
1198 OSStatus status = noErr ;
1199 do
1200 {
1201 s_inReceiveEvent = true ;
1202 status = ReceiveNextEvent(0, NULL,kEventDurationNoWait,true,&theEvent) ;
1203 s_inReceiveEvent = false ;
1204
1205 if ( status == eventLoopTimedOutErr )
1206 {
1207 // make sure next time the event loop will trigger idle events
1208 sleepTime = kEventDurationNoWait ;
1209 }
1210 else if ( status == eventLoopQuitErr )
1211 {
1212 // according to QA1061 this may also occur when a WakeUp Process
1213 // is executed
1214 }
1215 else
1216 {
1217 MacHandleOneEvent( theEvent ) ;
1218 ReleaseEvent(theEvent);
1219 }
1220 } while( status == noErr ) ;
1221 #else
1222 EventRecord event ;
1223
1224 // having a larger value here leads to large performance slowdowns
1225 // so we cannot give background apps more processor time here
1226 // we do so however having a large sleep value in the main event loop
1227 sleepTime = 0 ;
1228
1229 while ( !IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn))
1230 {
1231 MacHandleModifierEvents( &event ) ;
1232 MacHandleOneEvent( &event );
1233 if ( event.what != kHighLevelEvent )
1234 SetRectRgn( (RgnHandle) wxApp::s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ;
1235 }
1236 MacHandleModifierEvents( &event ) ;
1237 #endif
1238
1239 wxMacProcessNotifierAndPendingEvents() ;
1240 s_inYield = FALSE;
1241
1242 return TRUE;
1243 }
1244
1245 // platform specifics
1246
1247 void wxApp::MacSuspend( bool convertClipboard )
1248 {
1249 #if !TARGET_CARBON
1250 // we have to deactive the top level windows manually
1251
1252 wxWindowListNode* node = wxTopLevelWindows.GetFirst();
1253 while (node)
1254 {
1255 wxTopLevelWindow* win = (wxTopLevelWindow*) node->Data();
1256 #if TARGET_CARBON
1257 #if 0 // having problems right now with that
1258 if (!win->HasFlag(wxSTAY_ON_TOP))
1259 #endif
1260 #endif
1261 win->MacActivate( ((EventRecord*) MacGetCurrentEvent())->when , false ) ;
1262
1263 node = node->GetNext();
1264 }
1265
1266 ::HideFloatingWindows() ;
1267 #endif
1268 s_lastMouseDown = 0 ;
1269
1270 if( convertClipboard )
1271 {
1272 MacConvertPrivateToPublicScrap() ;
1273 }
1274 }
1275
1276 extern wxList wxModalDialogs;
1277
1278 void wxApp::MacResume( bool convertClipboard )
1279 {
1280 s_lastMouseDown = 0 ;
1281 if( convertClipboard )
1282 {
1283 MacConvertPublicToPrivateScrap() ;
1284 }
1285
1286 #if !TARGET_CARBON
1287 ::ShowFloatingWindows() ;
1288 // raise modal dialogs in case a non modal window was selected to activate the app
1289
1290 wxNode* node = wxModalDialogs.GetFirst();
1291 while (node)
1292 {
1293 wxDialog* dialog = (wxDialog *) node->GetData();
1294 dialog->Raise();
1295
1296 node = node->GetNext();
1297 }
1298 #endif
1299 }
1300
1301 void wxApp::MacConvertPrivateToPublicScrap()
1302 {
1303 }
1304
1305 void wxApp::MacConvertPublicToPrivateScrap()
1306 {
1307 }
1308
1309 void wxApp::MacDoOneEvent()
1310 {
1311 #if TARGET_CARBON
1312 EventRef theEvent;
1313
1314 s_inReceiveEvent = true ;
1315 OSStatus status = ReceiveNextEvent(0, NULL,sleepTime,true,&theEvent) ;
1316 s_inReceiveEvent = false ;
1317 if ( status == eventLoopTimedOutErr )
1318 {
1319 if ( wxTheApp->ProcessIdle() )
1320 sleepTime = kEventDurationNoWait ;
1321 else
1322 {
1323 #if wxUSE_THREADS
1324 if (g_numberOfThreads)
1325 {
1326 sleepTime = kEventDurationNoWait;
1327 }
1328 else
1329 #endif // wxUSE_THREADS
1330 {
1331 sleepTime = kEventDurationSecond;
1332 }
1333 }
1334 }
1335 else if ( status == eventLoopQuitErr )
1336 {
1337 // according to QA1061 this may also occur when a WakeUp Process
1338 // is executed
1339 }
1340 else
1341 {
1342 MacHandleOneEvent( theEvent ) ;
1343 ReleaseEvent(theEvent);
1344 sleepTime = kEventDurationNoWait ;
1345 }
1346 #else
1347 EventRecord event ;
1348
1349 EventMask eventMask = everyEvent ;
1350
1351 if (WaitNextEvent(eventMask, &event, sleepTime, (RgnHandle) s_macCursorRgn))
1352 {
1353 MacHandleModifierEvents( &event ) ;
1354 MacHandleOneEvent( &event );
1355 }
1356 else
1357 {
1358 MacHandleModifierEvents( &event ) ;
1359 // idlers
1360 WindowPtr window = ::FrontWindow() ;
1361 if ( window )
1362 ::IdleControls( window ) ;
1363
1364 if ( wxTheApp->ProcessIdle() )
1365 sleepTime = kEventDurationNoWait;
1366 else
1367 {
1368 #if wxUSE_THREADS
1369 if (g_numberOfThreads)
1370 {
1371 sleepTime = kEventDurationNoWait;
1372 }
1373 else
1374 #endif // wxUSE_THREADS
1375 {
1376 sleepTime = kEventDurationSecond;
1377 }
1378 }
1379 }
1380 if ( event.what != kHighLevelEvent )
1381 SetRectRgn( (RgnHandle) s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ;
1382 #endif
1383 // repeaters
1384
1385 DeletePendingObjects() ;
1386 wxMacProcessNotifierAndPendingEvents() ;
1387 }
1388
1389 /*virtual*/ void wxApp::MacHandleUnhandledEvent( WXEVENTREF evr )
1390 {
1391 // Override to process unhandled events as you please
1392 }
1393
1394 void wxApp::MacHandleOneEvent( WXEVENTREF evr )
1395 {
1396 #if TARGET_CARBON
1397 EventTargetRef theTarget;
1398 theTarget = GetEventDispatcherTarget();
1399 m_macCurrentEvent = evr ;
1400 OSStatus status = SendEventToEventTarget ((EventRef) evr , theTarget);
1401 if(status == eventNotHandledErr)
1402 {
1403 MacHandleUnhandledEvent(evr);
1404 }
1405 #else
1406 EventRecord* ev = (EventRecord*) evr ;
1407 m_macCurrentEvent = ev ;
1408
1409 wxApp::sm_lastMessageTime = ev->when ;
1410
1411 switch (ev->what)
1412 {
1413 case mouseDown:
1414 MacHandleMouseDownEvent( ev ) ;
1415 if ( ev->modifiers & controlKey )
1416 s_lastMouseDown = 2;
1417 else
1418 s_lastMouseDown = 1;
1419 break;
1420 case mouseUp:
1421 if ( s_lastMouseDown == 2 )
1422 {
1423 ev->modifiers |= controlKey ;
1424 }
1425 else
1426 {
1427 ev->modifiers &= ~controlKey ;
1428 }
1429 MacHandleMouseUpEvent( ev ) ;
1430 s_lastMouseDown = 0;
1431 break;
1432 case activateEvt:
1433 MacHandleActivateEvent( ev ) ;
1434 break;
1435 case updateEvt:
1436 // In embedded mode we first let the UnhandledEvent function
1437 // try to handle the update event. If we handle it ourselves
1438 // first and then pass it on, the host's windows won't update.
1439 MacHandleUnhandledEvent(ev);
1440 MacHandleUpdateEvent( ev ) ;
1441 break;
1442 case keyDown:
1443 case autoKey:
1444 MacHandleKeyDownEvent( ev ) ;
1445 break;
1446 case keyUp:
1447 MacHandleKeyUpEvent( ev ) ;
1448 break;
1449 case diskEvt:
1450 MacHandleDiskEvent( ev ) ;
1451 break;
1452 case osEvt:
1453 MacHandleOSEvent( ev ) ;
1454 break;
1455 case kHighLevelEvent:
1456 MacHandleHighLevelEvent( ev ) ;
1457 break;
1458 default:
1459 break;
1460 }
1461 #endif
1462 wxMacProcessNotifierAndPendingEvents() ;
1463 }
1464
1465 #if !TARGET_CARBON
1466 bool s_macIsInModalLoop = false ;
1467
1468 void wxApp::MacHandleModifierEvents( WXEVENTREF evr )
1469 {
1470 EventRecord* ev = (EventRecord*) evr ;
1471 if ( ev->modifiers != s_lastModifiers && wxWindow::FindFocus() != NULL )
1472 {
1473 wxKeyEvent event(wxEVT_KEY_DOWN);
1474
1475 event.m_shiftDown = ev->modifiers & shiftKey;
1476 event.m_controlDown = ev->modifiers & controlKey;
1477 event.m_altDown = ev->modifiers & optionKey;
1478 event.m_metaDown = ev->modifiers & cmdKey;
1479
1480 event.m_x = ev->where.h;
1481 event.m_y = ev->where.v;
1482 event.m_timeStamp = ev->when;
1483 wxWindow* focus = wxWindow::FindFocus() ;
1484 event.SetEventObject(focus);
1485
1486 if ( (ev->modifiers ^ s_lastModifiers ) & controlKey )
1487 {
1488 event.m_keyCode = WXK_CONTROL ;
1489 event.SetEventType( ( ev->modifiers & controlKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
1490 focus->GetEventHandler()->ProcessEvent( event ) ;
1491 }
1492 if ( (ev->modifiers ^ s_lastModifiers ) & shiftKey )
1493 {
1494 event.m_keyCode = WXK_SHIFT ;
1495 event.SetEventType( ( ev->modifiers & shiftKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
1496 focus->GetEventHandler()->ProcessEvent( event ) ;
1497 }
1498 if ( (ev->modifiers ^ s_lastModifiers ) & optionKey )
1499 {
1500 event.m_keyCode = WXK_ALT ;
1501 event.SetEventType( ( ev->modifiers & optionKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
1502 focus->GetEventHandler()->ProcessEvent( event ) ;
1503 }
1504 if ( ( ev->modifiers ^ s_lastModifiers ) & cmdKey )
1505 {
1506 event.m_keyCode = WXK_COMMAND ;
1507 event.SetEventType( ( ev->modifiers & cmdKey ) ? wxEVT_KEY_DOWN : wxEVT_KEY_UP ) ;
1508 focus->GetEventHandler()->ProcessEvent( event ) ;
1509 }
1510 s_lastModifiers = ev->modifiers ;
1511 }
1512 }
1513
1514 void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr )
1515 {
1516 // we must avoid reentrancy problems when processing high level events eg printing
1517 bool former = s_inYield ;
1518 s_inYield = TRUE ;
1519 EventRecord* ev = (EventRecord*) evr ;
1520 ::AEProcessAppleEvent( ev ) ;
1521 s_inYield = former ;
1522 }
1523
1524 void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr )
1525 {
1526 EventRecord* ev = (EventRecord*) evr ;
1527 wxToolTip::RemoveToolTips() ;
1528
1529 WindowRef window;
1530 WindowRef frontWindow = ::FrontNonFloatingWindow() ;
1531 WindowAttributes frontWindowAttributes = NULL ;
1532 if ( frontWindow )
1533 ::GetWindowAttributes( frontWindow , &frontWindowAttributes ) ;
1534
1535 short windowPart = ::FindWindow(ev->where, &window);
1536 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( (WXWindow) window ) ;
1537 if ( wxPendingDelete.Member(win) )
1538 return ;
1539
1540 BitMap screenBits;
1541 GetQDGlobalsScreenBits( &screenBits );
1542
1543 switch (windowPart)
1544 {
1545 case inMenuBar :
1546 if ( s_macIsInModalLoop )
1547 {
1548 SysBeep ( 30 ) ;
1549 }
1550 else
1551 {
1552 UInt32 menuresult = MenuSelect(ev->where) ;
1553 MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) );
1554 s_lastMouseDown = 0;
1555 }
1556 break ;
1557 case inSysWindow :
1558 SystemClick( ev , window ) ;
1559 s_lastMouseDown = 0;
1560 break ;
1561 case inDrag :
1562 if ( window != frontWindow && s_macIsInModalLoop && !(ev->modifiers & cmdKey ) )
1563 {
1564 SysBeep ( 30 ) ;
1565 }
1566 else
1567 {
1568 DragWindow(window, ev->where, &screenBits.bounds);
1569 if (win)
1570 {
1571 GrafPtr port ;
1572 GetPort( &port ) ;
1573 Point pt = { 0, 0 } ;
1574 SetPortWindowPort(window) ;
1575 LocalToGlobal( &pt ) ;
1576 SetPort( port ) ;
1577 win->SetSize( pt.h , pt.v , -1 ,
1578 -1 , wxSIZE_USE_EXISTING);
1579 }
1580 s_lastMouseDown = 0;
1581 }
1582 break ;
1583 case inGoAway:
1584 if (TrackGoAway(window, ev->where))
1585 {
1586 if ( win )
1587 win->Close() ;
1588 }
1589 s_lastMouseDown = 0;
1590 break;
1591 case inGrow:
1592 {
1593 Rect newContentRect ;
1594 Rect constraintRect ;
1595 constraintRect.top = win->GetMinHeight() ;
1596 if ( constraintRect.top == -1 )
1597 constraintRect.top = 0 ;
1598 constraintRect.left = win->GetMinWidth() ;
1599 if ( constraintRect.left == -1 )
1600 constraintRect.left = 0 ;
1601 constraintRect.right = win->GetMaxWidth() ;
1602 if ( constraintRect.right == -1 )
1603 constraintRect.right = 32000 ;
1604 constraintRect.bottom = win->GetMaxHeight() ;
1605 if ( constraintRect.bottom == -1 )
1606 constraintRect.bottom = 32000 ;
1607
1608 Boolean growResult = ResizeWindow( window , ev->where ,
1609 &constraintRect , &newContentRect ) ;
1610 if ( growResult )
1611 {
1612 win->SetSize( newContentRect.left , newContentRect.top ,
1613 newContentRect.right - newContentRect.left ,
1614 newContentRect.bottom - newContentRect.top, wxSIZE_USE_EXISTING);
1615 }
1616 s_lastMouseDown = 0;
1617 }
1618 break;
1619 case inZoomIn:
1620 case inZoomOut:
1621 if (TrackBox(window, ev->where, windowPart))
1622 {
1623 // TODO setup size event
1624 ZoomWindow( window , windowPart , false ) ;
1625 if (win)
1626 {
1627 Rect tempRect ;
1628 GrafPtr port ;
1629 GetPort( &port ) ;
1630 Point pt = { 0, 0 } ;
1631 SetPortWindowPort(window) ;
1632 LocalToGlobal( &pt ) ;
1633 SetPort( port ) ;
1634
1635 GetWindowPortBounds(window, &tempRect ) ;
1636 win->SetSize( pt.h , pt.v , tempRect.right-tempRect.left ,
1637 tempRect.bottom-tempRect.top, wxSIZE_USE_EXISTING);
1638 }
1639 }
1640 s_lastMouseDown = 0;
1641 break;
1642 case inCollapseBox :
1643 // TODO setup size event
1644 s_lastMouseDown = 0;
1645 break ;
1646
1647 case inContent :
1648 {
1649 GrafPtr port ;
1650 GetPort( &port ) ;
1651 SetPortWindowPort(window) ;
1652 SetPort( port ) ;
1653 }
1654 if ( window != frontWindow && wxTheApp->s_captureWindow == NULL )
1655 {
1656 if ( s_macIsInModalLoop )
1657 {
1658 SysBeep ( 30 ) ;
1659 }
1660 else if ( UMAIsWindowFloating( window ) )
1661 {
1662 if ( win )
1663 win->MacMouseDown( ev , windowPart ) ;
1664 }
1665 else
1666 {
1667 // Activate window first
1668 ::SelectWindow( window ) ;
1669
1670 // Send event later
1671 if ( win )
1672 win->MacMouseDown( ev , windowPart ) ;
1673 }
1674 }
1675 else
1676 {
1677 if ( win )
1678 win->MacMouseDown( ev , windowPart ) ;
1679 }
1680 break ;
1681 default:
1682 break;
1683 }
1684 }
1685
1686 void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr )
1687 {
1688 EventRecord* ev = (EventRecord*) evr ;
1689 WindowRef window;
1690
1691 short windowPart = inNoWindow ;
1692 if ( wxTheApp->s_captureWindow )
1693 {
1694 window = (WindowRef) s_captureWindow->MacGetRootWindow() ;
1695 windowPart = inContent ;
1696 }
1697 else
1698 {
1699 windowPart = ::FindWindow(ev->where, &window) ;
1700 }
1701
1702 switch (windowPart)
1703 {
1704 case inMenuBar :
1705 break ;
1706 case inSysWindow :
1707 break ;
1708 default:
1709 {
1710 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( (WXWindow) window ) ;
1711 if ( win )
1712 win->MacMouseUp( ev , windowPart ) ;
1713 }
1714 break;
1715 }
1716 }
1717
1718 #endif
1719
1720 long wxMacTranslateKey(unsigned char key, unsigned char code) ;
1721 long wxMacTranslateKey(unsigned char key, unsigned char code)
1722 {
1723 long retval = key ;
1724 switch (key)
1725 {
1726 case kHomeCharCode :
1727 retval = WXK_HOME;
1728 break;
1729 case kEnterCharCode :
1730 retval = WXK_RETURN;
1731 break;
1732 case kEndCharCode :
1733 retval = WXK_END;
1734 break;
1735 case kHelpCharCode :
1736 retval = WXK_HELP;
1737 break;
1738 case kBackspaceCharCode :
1739 retval = WXK_BACK;
1740 break;
1741 case kTabCharCode :
1742 retval = WXK_TAB;
1743 break;
1744 case kPageUpCharCode :
1745 retval = WXK_PAGEUP;
1746 break;
1747 case kPageDownCharCode :
1748 retval = WXK_PAGEDOWN;
1749 break;
1750 case kReturnCharCode :
1751 retval = WXK_RETURN;
1752 break;
1753 case kFunctionKeyCharCode :
1754 {
1755 switch( code )
1756 {
1757 case 0x7a :
1758 retval = WXK_F1 ;
1759 break;
1760 case 0x78 :
1761 retval = WXK_F2 ;
1762 break;
1763 case 0x63 :
1764 retval = WXK_F3 ;
1765 break;
1766 case 0x76 :
1767 retval = WXK_F4 ;
1768 break;
1769 case 0x60 :
1770 retval = WXK_F5 ;
1771 break;
1772 case 0x61 :
1773 retval = WXK_F6 ;
1774 break;
1775 case 0x62:
1776 retval = WXK_F7 ;
1777 break;
1778 case 0x64 :
1779 retval = WXK_F8 ;
1780 break;
1781 case 0x65 :
1782 retval = WXK_F9 ;
1783 break;
1784 case 0x6D :
1785 retval = WXK_F10 ;
1786 break;
1787 case 0x67 :
1788 retval = WXK_F11 ;
1789 break;
1790 case 0x6F :
1791 retval = WXK_F12 ;
1792 break;
1793 case 0x69 :
1794 retval = WXK_F13 ;
1795 break;
1796 case 0x6B :
1797 retval = WXK_F14 ;
1798 break;
1799 case 0x71 :
1800 retval = WXK_F15 ;
1801 break;
1802 }
1803 }
1804 break ;
1805 case kEscapeCharCode :
1806 retval = WXK_ESCAPE ;
1807 break ;
1808 case kLeftArrowCharCode :
1809 retval = WXK_LEFT ;
1810 break ;
1811 case kRightArrowCharCode :
1812 retval = WXK_RIGHT ;
1813 break ;
1814 case kUpArrowCharCode :
1815 retval = WXK_UP ;
1816 break ;
1817 case kDownArrowCharCode :
1818 retval = WXK_DOWN ;
1819 break ;
1820 case kDeleteCharCode :
1821 retval = WXK_DELETE ;
1822 default:
1823 break ;
1824 } // end switch
1825
1826 return retval;
1827 }
1828
1829 int wxKeyCodeToMacModifier(wxKeyCode key)
1830 {
1831 switch (key)
1832 {
1833 case WXK_START:
1834 case WXK_MENU:
1835 return cmdKey;
1836
1837 case WXK_SHIFT:
1838 return shiftKey;
1839
1840 case WXK_CAPITAL:
1841 return alphaLock;
1842
1843 case WXK_ALT:
1844 return optionKey;
1845
1846 case WXK_CONTROL:
1847 return controlKey;
1848
1849 default:
1850 return 0;
1851 }
1852 }
1853
1854 bool wxGetKeyState(wxKeyCode key) //virtual key code if < 10.2.x, else see below
1855 {
1856 #if __WXMAC_CARBON__
1857 //#ifdef __DARWIN__
1858 // wxHIDKeyboard keyboard;
1859 // return keyboard.IsActive(key);
1860 //#else
1861 // TODO: Have it use HID Manager on OSX...
1862 //if OS X > 10.2 (i.e. 10.2.x)
1863 //a known apple bug prevents the system from determining led
1864 //states with GetKeys... can only determine caps lock led
1865 return !!(GetCurrentKeyModifiers() & wxKeyCodeToMacModifier(key));
1866 #else
1867 KeyMap keymap;
1868 GetKeys(keymap);
1869 return !!(BitTst(keymap, (sizeof(KeyMap)*8) - key));
1870 #endif
1871 }
1872
1873 #if !TARGET_CARBON
1874 void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
1875 {
1876 EventRecord* ev = (EventRecord*) evr ;
1877 wxToolTip::RemoveToolTips() ;
1878
1879 UInt32 menuresult = UMAMenuEvent(ev) ;
1880 if ( HiWord( menuresult ) )
1881 {
1882 if ( !s_macIsInModalLoop )
1883 MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ;
1884 }
1885 else
1886 {
1887 wxWindow* focus = wxWindow::FindFocus() ;
1888
1889 if ( MacSendKeyDownEvent( focus , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) == false )
1890 {
1891 #if 0
1892 // we must handle control keys the other way round, otherwise text content is updated too late
1893 // has not been handled -> perform default
1894 wxControl* control = wxDynamicCast( focus , wxControl ) ;
1895 if ( control && control->GetMacControl() != NULL )
1896 {
1897 short keycode ;
1898 short keychar ;
1899 keychar = short(ev->message & charCodeMask);
1900 keycode = short(ev->message & keyCodeMask) >> 8 ;
1901 ::HandleControlKey( (ControlHandle) control->GetMacControl() , keycode , keychar , ev->modifiers ) ;
1902 }
1903 #endif
1904 }
1905 }
1906 }
1907
1908 void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr )
1909 {
1910 EventRecord* ev = (EventRecord*) evr ;
1911 wxToolTip::RemoveToolTips() ;
1912
1913 UInt32 menuresult = UMAMenuEvent(ev) ;
1914 if ( HiWord( menuresult ) )
1915 {
1916 }
1917 else
1918 {
1919 MacSendKeyUpEvent( wxWindow::FindFocus() , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) ;
1920 }
1921 }
1922
1923 #endif
1924
1925 bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey )
1926 {
1927 if ( !focus )
1928 return false ;
1929
1930 short keycode ;
1931 short keychar ;
1932 keychar = short(keymessage & charCodeMask);
1933 keycode = short(keymessage & keyCodeMask) >> 8 ;
1934
1935 if ( modifiers & ( controlKey|shiftKey|optionKey ) )
1936 {
1937 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1938 // and look at the character after
1939 UInt32 state = 0;
1940 UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state);
1941 keychar = short(keyInfo & charCodeMask);
1942 keycode = short(keyInfo & keyCodeMask) >> 8 ;
1943 }
1944 long keyval = wxMacTranslateKey(keychar, keycode) ;
1945 long realkeyval = keyval ;
1946 if ( keyval == keychar )
1947 {
1948 // we are not on a special character combo -> pass the real os event-value to EVT_CHAR, but not to EVT_KEY (make upper first)
1949 realkeyval = short(keymessage & charCodeMask) ;
1950 keyval = wxToupper( keyval ) ;
1951 }
1952
1953 wxKeyEvent event(wxEVT_KEY_DOWN);
1954 bool handled = false ;
1955 event.m_shiftDown = modifiers & shiftKey;
1956 event.m_controlDown = modifiers & controlKey;
1957 event.m_altDown = modifiers & optionKey;
1958 event.m_metaDown = modifiers & cmdKey;
1959 event.m_keyCode = keyval ;
1960
1961 event.m_x = wherex;
1962 event.m_y = wherey;
1963 event.m_timeStamp = when;
1964 event.SetEventObject(focus);
1965 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1966 if ( handled && event.GetSkipped() )
1967 handled = false ;
1968 if ( !handled )
1969 {
1970 #if wxUSE_ACCEL
1971 if (!handled)
1972 {
1973 wxWindow *ancestor = focus;
1974 while (ancestor)
1975 {
1976 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1977 if (command != -1)
1978 {
1979 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1980 handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
1981 break;
1982 }
1983 if (ancestor->IsTopLevel())
1984 break;
1985 ancestor = ancestor->GetParent();
1986 }
1987 }
1988 #endif // wxUSE_ACCEL
1989 }
1990 if (!handled)
1991 {
1992 event.Skip( FALSE ) ;
1993 event.SetEventType( wxEVT_CHAR ) ;
1994 // raw value again
1995 event.m_keyCode = realkeyval ;
1996
1997 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1998 if ( handled && event.GetSkipped() )
1999 handled = false ;
2000 }
2001 if ( !handled &&
2002 (keyval == WXK_TAB) &&
2003 // CS: copied the change below from wxGTK
2004 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
2005 // have this style, yet choose not to process this particular TAB in which
2006 // case TAB must still work as a navigational character
2007 #if 0
2008 (!focus->HasFlag(wxTE_PROCESS_TAB)) &&
2009 #endif
2010 (focus->GetParent()) &&
2011 (focus->GetParent()->HasFlag( wxTAB_TRAVERSAL)) )
2012 {
2013 wxNavigationKeyEvent new_event;
2014 new_event.SetEventObject( focus );
2015 new_event.SetDirection( !event.ShiftDown() );
2016 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
2017 new_event.SetWindowChange( event.ControlDown() );
2018 new_event.SetCurrentFocus( focus );
2019 handled = focus->GetEventHandler()->ProcessEvent( new_event );
2020 if ( handled && new_event.GetSkipped() )
2021 handled = false ;
2022 }
2023 // backdoor handler for default return and command escape
2024 if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) )
2025 {
2026 // if window is not having a focus still testing for default enter or cancel
2027 // TODO add the UMA version for ActiveNonFloatingWindow
2028 wxWindow* focus = wxFindWinFromMacWindow( (WXWindow) FrontWindow() ) ;
2029 if ( focus )
2030 {
2031 if ( keyval == WXK_RETURN )
2032 {
2033 wxButton *def = wxDynamicCast(focus->GetDefaultItem(),
2034 wxButton);
2035 if ( def && def->IsEnabled() )
2036 {
2037 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
2038 event.SetEventObject(def);
2039 def->Command(event);
2040 return true ;
2041 }
2042 }
2043 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
2044 else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) )
2045 {
2046 wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
2047 new_event.SetEventObject( focus );
2048 handled = focus->GetEventHandler()->ProcessEvent( new_event );
2049 }
2050 }
2051 }
2052 return handled ;
2053 }
2054
2055 bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey )
2056 {
2057 if ( !focus )
2058 return false ;
2059
2060 short keycode ;
2061 short keychar ;
2062 keychar = short(keymessage & charCodeMask);
2063 keycode = short(keymessage & keyCodeMask) >> 8 ;
2064 if ( modifiers & ( controlKey|shiftKey|optionKey ) )
2065 {
2066 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
2067 // and look at the character after
2068 UInt32 state = 0;
2069 UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state);
2070 keychar = short(keyInfo & charCodeMask);
2071 keycode = short(keyInfo & keyCodeMask) >> 8 ;
2072 }
2073 long keyval = wxMacTranslateKey(keychar, keycode) ;
2074
2075 if ( keyval == keychar )
2076 {
2077 keyval = wxToupper( keyval ) ;
2078 }
2079 bool handled = false ;
2080
2081 wxKeyEvent event(wxEVT_KEY_UP);
2082 event.m_shiftDown = modifiers & shiftKey;
2083 event.m_controlDown = modifiers & controlKey;
2084 event.m_altDown = modifiers & optionKey;
2085 event.m_metaDown = modifiers & cmdKey;
2086 event.m_keyCode = keyval ;
2087
2088 event.m_x = wherex;
2089 event.m_y = wherey;
2090 event.m_timeStamp = when;
2091 event.SetEventObject(focus);
2092 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
2093
2094 return handled ;
2095 }
2096
2097 #if !TARGET_CARBON
2098 void wxApp::MacHandleActivateEvent( WXEVENTREF evr )
2099 {
2100 EventRecord* ev = (EventRecord*) evr ;
2101 WindowRef window = (WindowRef) ev->message ;
2102 if ( window )
2103 {
2104 bool activate = (ev->modifiers & activeFlag ) ;
2105 WindowClass wclass ;
2106 ::GetWindowClass ( window , &wclass ) ;
2107 if ( wclass == kFloatingWindowClass )
2108 {
2109 // if it is a floater we activate/deactivate the front non-floating window instead
2110 window = ::FrontNonFloatingWindow() ;
2111 }
2112 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( (WXWindow) window ) ;
2113 if ( win )
2114 win->MacActivate( ev->when , activate ) ;
2115 }
2116 }
2117
2118 void wxApp::MacHandleUpdateEvent( WXEVENTREF evr )
2119 {
2120 EventRecord* ev = (EventRecord*) evr ;
2121 WindowRef window = (WindowRef) ev->message ;
2122 wxTopLevelWindowMac * win = wxFindWinFromMacWindow( (WXWindow) window ) ;
2123 if ( win )
2124 {
2125 if ( !wxPendingDelete.Member(win) )
2126 win->MacUpdate( ev->when ) ;
2127 }
2128 else
2129 {
2130 // since there is no way of telling this foreign window to update itself
2131 // we have to invalidate the update region otherwise we keep getting the same
2132 // event over and over again
2133 BeginUpdate( window ) ;
2134 EndUpdate( window ) ;
2135 }
2136 }
2137
2138 void wxApp::MacHandleDiskEvent( WXEVENTREF evr )
2139 {
2140 EventRecord* ev = (EventRecord*) evr ;
2141 if ( HiWord( ev->message ) != noErr )
2142 {
2143 OSErr err ;
2144 Point point ;
2145 SetPt( &point , 100 , 100 ) ;
2146
2147 err = DIBadMount( point , ev->message ) ;
2148 wxASSERT( err == noErr ) ;
2149 }
2150 }
2151
2152 void wxApp::MacHandleOSEvent( WXEVENTREF evr )
2153 {
2154 EventRecord* ev = (EventRecord*) evr ;
2155 switch( ( ev->message & osEvtMessageMask ) >> 24 )
2156 {
2157 case suspendResumeMessage :
2158 {
2159 bool isResuming = ev->message & resumeFlag ;
2160 bool convertClipboard = ev->message & convertClipboardFlag ;
2161
2162 bool doesActivate = UMAGetProcessModeDoesActivateOnFGSwitch() ;
2163 if ( isResuming )
2164 {
2165 WindowRef oldFrontWindow = NULL ;
2166 WindowRef newFrontWindow = NULL ;
2167
2168 // in case we don't take care of activating ourselves, we have to synchronize
2169 // our idea of the active window with the process manager's - which it already activated
2170
2171 if ( !doesActivate )
2172 oldFrontWindow = ::FrontNonFloatingWindow() ;
2173
2174 MacResume( convertClipboard ) ;
2175
2176 newFrontWindow = ::FrontNonFloatingWindow() ;
2177
2178 if ( oldFrontWindow )
2179 {
2180 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( (WXWindow) oldFrontWindow ) ;
2181 if ( win )
2182 win->MacActivate( ev->when , false ) ;
2183 }
2184 if ( newFrontWindow )
2185 {
2186 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( (WXWindow) newFrontWindow ) ;
2187 if ( win )
2188 win->MacActivate( ev->when , true ) ;
2189 }
2190 }
2191 else
2192 {
2193 MacSuspend( convertClipboard ) ;
2194 }
2195 }
2196 break ;
2197 case mouseMovedMessage :
2198 {
2199 WindowRef window;
2200
2201 wxWindow* currentMouseWindow = NULL ;
2202
2203 if (s_captureWindow )
2204 {
2205 currentMouseWindow = s_captureWindow ;
2206 }
2207 else
2208 {
2209 wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) ,
2210 &currentMouseWindow ) ;
2211 }
2212
2213 if ( currentMouseWindow != wxWindow::s_lastMouseWindow )
2214 {
2215 wxMouseEvent event ;
2216
2217 bool isDown = !(ev->modifiers & btnState) ; // 1 is for up
2218 bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse
2219
2220 event.m_leftDown = isDown && !controlDown;
2221 event.m_middleDown = FALSE;
2222 event.m_rightDown = isDown && controlDown;
2223 event.m_shiftDown = ev->modifiers & shiftKey;
2224 event.m_controlDown = ev->modifiers & controlKey;
2225 event.m_altDown = ev->modifiers & optionKey;
2226 event.m_metaDown = ev->modifiers & cmdKey;
2227 event.m_x = ev->where.h;
2228 event.m_y = ev->where.v;
2229 event.m_timeStamp = ev->when;
2230 event.SetEventObject(this);
2231
2232 if ( wxWindow::s_lastMouseWindow )
2233 {
2234 wxMouseEvent eventleave(event);
2235 eventleave.SetEventType( wxEVT_LEAVE_WINDOW );
2236 wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y );
2237 eventleave.SetEventObject( wxWindow::s_lastMouseWindow ) ;
2238
2239 wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave);
2240 }
2241 if ( currentMouseWindow )
2242 {
2243 wxMouseEvent evententer(event);
2244 evententer.SetEventType( wxEVT_ENTER_WINDOW );
2245 currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y );
2246 evententer.SetEventObject( currentMouseWindow ) ;
2247 currentMouseWindow->GetEventHandler()->ProcessEvent(evententer);
2248 }
2249 wxWindow::s_lastMouseWindow = currentMouseWindow ;
2250 }
2251
2252 short windowPart = inNoWindow ;
2253
2254 if ( s_captureWindow )
2255 {
2256 window = (WindowRef) s_captureWindow->MacGetRootWindow() ;
2257 windowPart = inContent ;
2258 }
2259 else
2260 {
2261 windowPart = ::FindWindow(ev->where, &window);
2262 }
2263
2264 switch (windowPart)
2265 {
2266 case inContent :
2267 {
2268 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( (WXWindow) window ) ;
2269 if ( win )
2270 win->MacMouseMoved( ev , windowPart ) ;
2271 else
2272 {
2273 if ( wxIsBusy() )
2274 {
2275 }
2276 else
2277 UMAShowArrowCursor();
2278 }
2279 }
2280 break;
2281 default :
2282 {
2283 if ( wxIsBusy() )
2284 {
2285 }
2286 else
2287 UMAShowArrowCursor();
2288 }
2289 break ;
2290 }
2291 }
2292 break ;
2293
2294 }
2295 }
2296 #else
2297
2298 void wxApp::MacHandleMouseMovedEvent(wxInt32 x , wxInt32 y ,wxUint32 modifiers , long timestamp)
2299 {
2300 WindowRef window;
2301
2302 wxWindow* currentMouseWindow = NULL ;
2303
2304 if (s_captureWindow )
2305 {
2306 currentMouseWindow = s_captureWindow ;
2307 }
2308 else
2309 {
2310 wxWindow::MacGetWindowFromPoint( wxPoint( x, y ) , &currentMouseWindow ) ;
2311 }
2312
2313 if ( currentMouseWindow != wxWindow::s_lastMouseWindow )
2314 {
2315 wxMouseEvent event ;
2316
2317 bool isDown = !(modifiers & btnState) ; // 1 is for up
2318 bool controlDown = modifiers & controlKey ; // for simulating right mouse
2319
2320 event.m_leftDown = isDown && !controlDown;
2321
2322 event.m_middleDown = FALSE;
2323 event.m_rightDown = isDown && controlDown;
2324
2325 event.m_shiftDown = modifiers & shiftKey;
2326 event.m_controlDown = modifiers & controlKey;
2327 event.m_altDown = modifiers & optionKey;
2328 event.m_metaDown = modifiers & cmdKey;
2329
2330 event.m_x = x;
2331 event.m_y = y;
2332 event.m_timeStamp = timestamp;
2333
2334 if ( wxWindow::s_lastMouseWindow )
2335 {
2336 wxMouseEvent eventleave(event);
2337 eventleave.SetEventType( wxEVT_LEAVE_WINDOW );
2338 wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y );
2339 eventleave.SetEventObject( wxWindow::s_lastMouseWindow ) ;
2340
2341 #if wxUSE_TOOLTIPS
2342 wxToolTip::RelayEvent( wxWindow::s_lastMouseWindow , eventleave);
2343 #endif // wxUSE_TOOLTIPS
2344 wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave);
2345 }
2346 if ( currentMouseWindow )
2347 {
2348 wxMouseEvent evententer(event);
2349 evententer.SetEventType( wxEVT_ENTER_WINDOW );
2350 currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y );
2351 evententer.SetEventObject( currentMouseWindow ) ;
2352 #if wxUSE_TOOLTIPS
2353 wxToolTip::RelayEvent( currentMouseWindow , evententer);
2354 #endif // wxUSE_TOOLTIPS
2355 currentMouseWindow->GetEventHandler()->ProcessEvent(evententer);
2356 }
2357 wxWindow::s_lastMouseWindow = currentMouseWindow ;
2358 }
2359
2360 short windowPart = inNoWindow ;
2361
2362 if ( s_captureWindow )
2363 {
2364 window = (WindowRef) s_captureWindow->MacGetRootWindow() ;
2365 windowPart = inContent ;
2366 }
2367 else
2368 {
2369 Point pt= { y , x } ;
2370 windowPart = ::FindWindow(pt , &window);
2371 }
2372
2373 switch (windowPart)
2374 {
2375 case inContent :
2376 {
2377 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
2378 if ( win )
2379 win->MacFireMouseEvent( nullEvent , x , y , modifiers , timestamp ) ;
2380 else
2381 {
2382 if ( wxIsBusy() )
2383 {
2384 }
2385 else
2386 UMAShowArrowCursor();
2387 }
2388 }
2389 break;
2390 default :
2391 {
2392 if ( wxIsBusy() )
2393 {
2394 }
2395 else
2396 UMAShowArrowCursor();
2397 }
2398 break ;
2399 }
2400 }
2401 #endif
2402
2403 void wxApp::MacHandleMenuCommand( wxUint32 id )
2404 {
2405 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
2406 wxFrame* frame = mbar->GetFrame();
2407 wxCHECK_RET( mbar != NULL && frame != NULL, wxT("error in menu item callback") );
2408 if ( frame )
2409 {
2410 frame->ProcessCommand(id);
2411 }
2412 }
2413
2414 #if !TARGET_CARBON
2415 void wxApp::MacHandleMenuSelect( int macMenuId , int macMenuItemNum )
2416 {
2417 if (macMenuId == 0)
2418 return; // no menu item selected
2419
2420 if (macMenuId == kwxMacAppleMenuId && macMenuItemNum > 1)
2421 {
2422 #if ! TARGET_CARBON
2423 Str255 deskAccessoryName ;
2424 GrafPtr savedPort ;
2425
2426 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId), macMenuItemNum, deskAccessoryName);
2427 GetPort(&savedPort);
2428 OpenDeskAcc(deskAccessoryName);
2429 SetPort(savedPort);
2430 #endif
2431 }
2432 else
2433 {
2434 MenuCommand id ;
2435 GetMenuItemCommandID( GetMenuHandle(macMenuId) , macMenuItemNum , &id ) ;
2436 MacHandleMenuCommand( id ) ;
2437 }
2438 HiliteMenu(0);
2439 }
2440 #endif