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