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