]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/app.cpp
log changes
[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 = 0 ;
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 , 20000 , 40 ) ;
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 if ( win )
1544 win->MacMouseDown( ev , windowPart ) ;
1545 ::SelectWindow( window ) ;
1546 }
1547 }
1548 else
1549 {
1550 if ( win )
1551 win->MacMouseDown( ev , windowPart ) ;
1552 }
1553 break ;
1554 default:
1555 break;
1556 }
1557 }
1558
1559 void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr )
1560 {
1561 EventRecord* ev = (EventRecord*) evr ;
1562 WindowRef window;
1563
1564 short windowPart = inNoWindow ;
1565 if ( wxTheApp->s_captureWindow )
1566 {
1567 window = (WindowRef) s_captureWindow->MacGetRootWindow() ;
1568 windowPart = inContent ;
1569 }
1570 else
1571 {
1572 windowPart = ::FindWindow(ev->where, &window) ;
1573 }
1574
1575 switch (windowPart)
1576 {
1577 case inMenuBar :
1578 break ;
1579 case inSysWindow :
1580 break ;
1581 default:
1582 {
1583 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
1584 if ( win )
1585 win->MacMouseUp( ev , windowPart ) ;
1586 }
1587 break;
1588 }
1589 }
1590
1591 #endif
1592
1593 long wxMacTranslateKey(unsigned char key, unsigned char code) ;
1594 long wxMacTranslateKey(unsigned char key, unsigned char code)
1595 {
1596 long retval = key ;
1597 switch (key)
1598 {
1599 case kHomeCharCode :
1600 retval = WXK_HOME;
1601 break;
1602 case kEnterCharCode :
1603 retval = WXK_RETURN;
1604 break;
1605 case kEndCharCode :
1606 retval = WXK_END;
1607 break;
1608 case kHelpCharCode :
1609 retval = WXK_HELP;
1610 break;
1611 case kBackspaceCharCode :
1612 retval = WXK_BACK;
1613 break;
1614 case kTabCharCode :
1615 retval = WXK_TAB;
1616 break;
1617 case kPageUpCharCode :
1618 retval = WXK_PAGEUP;
1619 break;
1620 case kPageDownCharCode :
1621 retval = WXK_PAGEDOWN;
1622 break;
1623 case kReturnCharCode :
1624 retval = WXK_RETURN;
1625 break;
1626 case kFunctionKeyCharCode :
1627 {
1628 switch( code )
1629 {
1630 case 0x7a :
1631 retval = WXK_F1 ;
1632 break;
1633 case 0x78 :
1634 retval = WXK_F2 ;
1635 break;
1636 case 0x63 :
1637 retval = WXK_F3 ;
1638 break;
1639 case 0x76 :
1640 retval = WXK_F4 ;
1641 break;
1642 case 0x60 :
1643 retval = WXK_F5 ;
1644 break;
1645 case 0x61 :
1646 retval = WXK_F6 ;
1647 break;
1648 case 0x62:
1649 retval = WXK_F7 ;
1650 break;
1651 case 0x64 :
1652 retval = WXK_F8 ;
1653 break;
1654 case 0x65 :
1655 retval = WXK_F9 ;
1656 break;
1657 case 0x6D :
1658 retval = WXK_F10 ;
1659 break;
1660 case 0x67 :
1661 retval = WXK_F11 ;
1662 break;
1663 case 0x6F :
1664 retval = WXK_F12 ;
1665 break;
1666 case 0x69 :
1667 retval = WXK_F13 ;
1668 break;
1669 case 0x6B :
1670 retval = WXK_F14 ;
1671 break;
1672 case 0x71 :
1673 retval = WXK_F15 ;
1674 break;
1675 }
1676 }
1677 break ;
1678 case kEscapeCharCode :
1679 retval = WXK_ESCAPE ;
1680 break ;
1681 case kLeftArrowCharCode :
1682 retval = WXK_LEFT ;
1683 break ;
1684 case kRightArrowCharCode :
1685 retval = WXK_RIGHT ;
1686 break ;
1687 case kUpArrowCharCode :
1688 retval = WXK_UP ;
1689 break ;
1690 case kDownArrowCharCode :
1691 retval = WXK_DOWN ;
1692 break ;
1693 case kDeleteCharCode :
1694 retval = WXK_DELETE ;
1695 default:
1696 break ;
1697 } // end switch
1698
1699 return retval;
1700 }
1701
1702 #if !TARGET_CARBON
1703 void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr )
1704 {
1705 EventRecord* ev = (EventRecord*) evr ;
1706 wxToolTip::RemoveToolTips() ;
1707
1708 UInt32 menuresult = UMAMenuEvent(ev) ;
1709 if ( HiWord( menuresult ) )
1710 {
1711 if ( !s_macIsInModalLoop )
1712 MacHandleMenuSelect( HiWord( menuresult ) , LoWord( menuresult ) ) ;
1713 }
1714 else
1715 {
1716 wxWindow* focus = wxWindow::FindFocus() ;
1717
1718 if ( MacSendKeyDownEvent( focus , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) == false )
1719 {
1720 #if 0
1721 // we must handle control keys the other way round, otherwise text content is updated too late
1722 // has not been handled -> perform default
1723 wxControl* control = wxDynamicCast( focus , wxControl ) ;
1724 if ( control && control->GetMacControl() != NULL )
1725 {
1726 short keycode ;
1727 short keychar ;
1728 keychar = short(ev->message & charCodeMask);
1729 keycode = short(ev->message & keyCodeMask) >> 8 ;
1730 ::HandleControlKey( (ControlHandle) control->GetMacControl() , keycode , keychar , ev->modifiers ) ;
1731 }
1732 #endif
1733 }
1734 }
1735 }
1736
1737 void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr )
1738 {
1739 EventRecord* ev = (EventRecord*) evr ;
1740 wxToolTip::RemoveToolTips() ;
1741
1742 UInt32 menuresult = UMAMenuEvent(ev) ;
1743 if ( HiWord( menuresult ) )
1744 {
1745 }
1746 else
1747 {
1748 MacSendKeyUpEvent( wxWindow::FindFocus() , ev->message , ev->modifiers , ev->when , ev->where.h , ev->where.v ) ;
1749 }
1750 }
1751
1752 #endif
1753
1754 bool wxApp::MacSendKeyDownEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey )
1755 {
1756 if ( !focus )
1757 return false ;
1758
1759 short keycode ;
1760 short keychar ;
1761 keychar = short(keymessage & charCodeMask);
1762 keycode = short(keymessage & keyCodeMask) >> 8 ;
1763
1764 if ( modifiers & ( controlKey|shiftKey|optionKey ) )
1765 {
1766 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1767 // and look at the character after
1768 UInt32 state = 0;
1769 UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state);
1770 keychar = short(keyInfo & charCodeMask);
1771 keycode = short(keyInfo & keyCodeMask) >> 8 ;
1772 }
1773 long keyval = wxMacTranslateKey(keychar, keycode) ;
1774 long realkeyval = keyval ;
1775 if ( keyval == keychar )
1776 {
1777 // 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)
1778 realkeyval = short(keymessage & charCodeMask) ;
1779 keyval = wxToupper( keyval ) ;
1780 }
1781
1782 wxKeyEvent event(wxEVT_KEY_DOWN);
1783 bool handled = false ;
1784 event.m_shiftDown = modifiers & shiftKey;
1785 event.m_controlDown = modifiers & controlKey;
1786 event.m_altDown = modifiers & optionKey;
1787 event.m_metaDown = modifiers & cmdKey;
1788 event.m_keyCode = keyval ;
1789
1790 event.m_x = wherex;
1791 event.m_y = wherey;
1792 event.m_timeStamp = when;
1793 event.SetEventObject(focus);
1794 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1795 if ( handled && event.GetSkipped() )
1796 handled = false ;
1797 if ( !handled )
1798 {
1799 #if wxUSE_ACCEL
1800 if (!handled)
1801 {
1802 wxWindow *ancestor = focus;
1803 while (ancestor)
1804 {
1805 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1806 if (command != -1)
1807 {
1808 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1809 handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
1810 break;
1811 }
1812 if (ancestor->IsTopLevel())
1813 break;
1814 ancestor = ancestor->GetParent();
1815 }
1816 }
1817 #endif // wxUSE_ACCEL
1818 }
1819 if (!handled)
1820 {
1821 event.Skip( FALSE ) ;
1822 event.SetEventType( wxEVT_CHAR ) ;
1823 // raw value again
1824 event.m_keyCode = realkeyval ;
1825
1826 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1827 if ( handled && event.GetSkipped() )
1828 handled = false ;
1829 }
1830 if ( !handled &&
1831 (keyval == WXK_TAB) &&
1832 // CS: copied the change below from wxGTK
1833 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
1834 // have this style, yet choose not to process this particular TAB in which
1835 // case TAB must still work as a navigational character
1836 #if 0
1837 (!focus->HasFlag(wxTE_PROCESS_TAB)) &&
1838 #endif
1839 (focus->GetParent()) &&
1840 (focus->GetParent()->HasFlag( wxTAB_TRAVERSAL)) )
1841 {
1842 wxNavigationKeyEvent new_event;
1843 new_event.SetEventObject( focus );
1844 new_event.SetDirection( !event.ShiftDown() );
1845 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1846 new_event.SetWindowChange( event.ControlDown() );
1847 new_event.SetCurrentFocus( focus );
1848 handled = focus->GetEventHandler()->ProcessEvent( new_event );
1849 if ( handled && new_event.GetSkipped() )
1850 handled = false ;
1851 }
1852 // backdoor handler for default return and command escape
1853 if ( !handled && (!focus->IsKindOf(CLASSINFO(wxControl) ) || !focus->MacCanFocus() ) )
1854 {
1855 // if window is not having a focus still testing for default enter or cancel
1856 // TODO add the UMA version for ActiveNonFloatingWindow
1857 wxWindow* focus = wxFindWinFromMacWindow( FrontWindow() ) ;
1858 if ( focus )
1859 {
1860 if ( keyval == WXK_RETURN )
1861 {
1862 wxButton *def = wxDynamicCast(focus->GetDefaultItem(),
1863 wxButton);
1864 if ( def && def->IsEnabled() )
1865 {
1866 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() );
1867 event.SetEventObject(def);
1868 def->Command(event);
1869 return true ;
1870 }
1871 }
1872 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1873 else if (keyval == WXK_ESCAPE || (keyval == '.' && modifiers & cmdKey ) )
1874 {
1875 wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL);
1876 new_event.SetEventObject( focus );
1877 handled = focus->GetEventHandler()->ProcessEvent( new_event );
1878 }
1879 }
1880 }
1881 return handled ;
1882 }
1883
1884 bool wxApp::MacSendKeyUpEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey )
1885 {
1886 if ( !focus )
1887 return false ;
1888
1889 short keycode ;
1890 short keychar ;
1891 keychar = short(keymessage & charCodeMask);
1892 keycode = short(keymessage & keyCodeMask) >> 8 ;
1893 if ( modifiers & ( controlKey|shiftKey|optionKey ) )
1894 {
1895 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1896 // and look at the character after
1897 UInt32 state = 0;
1898 UInt32 keyInfo = KeyTranslate((Ptr)GetScriptManagerVariable(smKCHRCache), ( modifiers & (~(controlKey|shiftKey|optionKey))) | keycode, &state);
1899 keychar = short(keyInfo & charCodeMask);
1900 keycode = short(keyInfo & keyCodeMask) >> 8 ;
1901 }
1902 long keyval = wxMacTranslateKey(keychar, keycode) ;
1903
1904 if ( keyval == keychar )
1905 {
1906 keyval = wxToupper( keyval ) ;
1907 }
1908 bool handled = false ;
1909
1910 wxKeyEvent event(wxEVT_KEY_UP);
1911 event.m_shiftDown = modifiers & shiftKey;
1912 event.m_controlDown = modifiers & controlKey;
1913 event.m_altDown = modifiers & optionKey;
1914 event.m_metaDown = modifiers & cmdKey;
1915 event.m_keyCode = keyval ;
1916
1917 event.m_x = wherex;
1918 event.m_y = wherey;
1919 event.m_timeStamp = when;
1920 event.SetEventObject(focus);
1921 handled = focus->GetEventHandler()->ProcessEvent( event ) ;
1922
1923 return handled ;
1924 }
1925
1926 #if !TARGET_CARBON
1927 void wxApp::MacHandleActivateEvent( WXEVENTREF evr )
1928 {
1929 EventRecord* ev = (EventRecord*) evr ;
1930 WindowRef window = (WindowRef) ev->message ;
1931 if ( window )
1932 {
1933 bool activate = (ev->modifiers & activeFlag ) ;
1934 WindowClass wclass ;
1935 ::GetWindowClass ( window , &wclass ) ;
1936 if ( wclass == kFloatingWindowClass )
1937 {
1938 // if it is a floater we activate/deactivate the front non-floating window instead
1939 window = ::FrontNonFloatingWindow() ;
1940 }
1941 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
1942 if ( win )
1943 win->MacActivate( ev->when , activate ) ;
1944 }
1945 }
1946
1947 void wxApp::MacHandleUpdateEvent( WXEVENTREF evr )
1948 {
1949 EventRecord* ev = (EventRecord*) evr ;
1950 WindowRef window = (WindowRef) ev->message ;
1951 wxTopLevelWindowMac * win = wxFindWinFromMacWindow( window ) ;
1952 if ( win )
1953 {
1954 if ( !wxPendingDelete.Member(win) )
1955 win->MacUpdate( ev->when ) ;
1956 }
1957 else
1958 {
1959 // since there is no way of telling this foreign window to update itself
1960 // we have to invalidate the update region otherwise we keep getting the same
1961 // event over and over again
1962 BeginUpdate( window ) ;
1963 EndUpdate( window ) ;
1964 }
1965 }
1966
1967 void wxApp::MacHandleDiskEvent( WXEVENTREF evr )
1968 {
1969 EventRecord* ev = (EventRecord*) evr ;
1970 if ( HiWord( ev->message ) != noErr )
1971 {
1972 OSErr err ;
1973 Point point ;
1974 SetPt( &point , 100 , 100 ) ;
1975
1976 err = DIBadMount( point , ev->message ) ;
1977 wxASSERT( err == noErr ) ;
1978 }
1979 }
1980
1981 void wxApp::MacHandleOSEvent( WXEVENTREF evr )
1982 {
1983 EventRecord* ev = (EventRecord*) evr ;
1984 switch( ( ev->message & osEvtMessageMask ) >> 24 )
1985 {
1986 case suspendResumeMessage :
1987 {
1988 bool isResuming = ev->message & resumeFlag ;
1989 bool convertClipboard = ev->message & convertClipboardFlag ;
1990
1991 bool doesActivate = UMAGetProcessModeDoesActivateOnFGSwitch() ;
1992 if ( isResuming )
1993 {
1994 WindowRef oldFrontWindow = NULL ;
1995 WindowRef newFrontWindow = NULL ;
1996
1997 // in case we don't take care of activating ourselves, we have to synchronize
1998 // our idea of the active window with the process manager's - which it already activated
1999
2000 if ( !doesActivate )
2001 oldFrontWindow = ::FrontNonFloatingWindow() ;
2002
2003 MacResume( convertClipboard ) ;
2004
2005 newFrontWindow = ::FrontNonFloatingWindow() ;
2006
2007 if ( oldFrontWindow )
2008 {
2009 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( oldFrontWindow ) ;
2010 if ( win )
2011 win->MacActivate( ev->when , false ) ;
2012 }
2013 if ( newFrontWindow )
2014 {
2015 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( newFrontWindow ) ;
2016 if ( win )
2017 win->MacActivate( ev->when , true ) ;
2018 }
2019 }
2020 else
2021 {
2022 MacSuspend( convertClipboard ) ;
2023 }
2024 }
2025 break ;
2026 case mouseMovedMessage :
2027 {
2028 WindowRef window;
2029
2030 wxWindow* currentMouseWindow = NULL ;
2031
2032 if (s_captureWindow )
2033 {
2034 currentMouseWindow = s_captureWindow ;
2035 }
2036 else
2037 {
2038 wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) ,
2039 &currentMouseWindow ) ;
2040 }
2041
2042 if ( currentMouseWindow != wxWindow::s_lastMouseWindow )
2043 {
2044 wxMouseEvent event ;
2045
2046 bool isDown = !(ev->modifiers & btnState) ; // 1 is for up
2047 bool controlDown = ev->modifiers & controlKey ; // for simulating right mouse
2048
2049 event.m_leftDown = isDown && !controlDown;
2050 event.m_middleDown = FALSE;
2051 event.m_rightDown = isDown && controlDown;
2052 event.m_shiftDown = ev->modifiers & shiftKey;
2053 event.m_controlDown = ev->modifiers & controlKey;
2054 event.m_altDown = ev->modifiers & optionKey;
2055 event.m_metaDown = ev->modifiers & cmdKey;
2056 event.m_x = ev->where.h;
2057 event.m_y = ev->where.v;
2058 event.m_timeStamp = ev->when;
2059 event.SetEventObject(this);
2060
2061 if ( wxWindow::s_lastMouseWindow )
2062 {
2063 wxMouseEvent eventleave(event);
2064 eventleave.SetEventType( wxEVT_LEAVE_WINDOW );
2065 wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y );
2066 eventleave.SetEventObject( wxWindow::s_lastMouseWindow ) ;
2067
2068 wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave);
2069 }
2070 if ( currentMouseWindow )
2071 {
2072 wxMouseEvent evententer(event);
2073 evententer.SetEventType( wxEVT_ENTER_WINDOW );
2074 currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y );
2075 evententer.SetEventObject( currentMouseWindow ) ;
2076 currentMouseWindow->GetEventHandler()->ProcessEvent(evententer);
2077 }
2078 wxWindow::s_lastMouseWindow = currentMouseWindow ;
2079 }
2080
2081 short windowPart = inNoWindow ;
2082
2083 if ( s_captureWindow )
2084 {
2085 window = (WindowRef) s_captureWindow->MacGetRootWindow() ;
2086 windowPart = inContent ;
2087 }
2088 else
2089 {
2090 windowPart = ::FindWindow(ev->where, &window);
2091 }
2092
2093 switch (windowPart)
2094 {
2095 case inContent :
2096 {
2097 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
2098 if ( win )
2099 win->MacMouseMoved( ev , windowPart ) ;
2100 else
2101 {
2102 if ( wxIsBusy() )
2103 {
2104 }
2105 else
2106 UMAShowArrowCursor();
2107 }
2108 }
2109 break;
2110 default :
2111 {
2112 if ( wxIsBusy() )
2113 {
2114 }
2115 else
2116 UMAShowArrowCursor();
2117 }
2118 break ;
2119 }
2120 }
2121 break ;
2122
2123 }
2124 }
2125 #else
2126
2127 void wxApp::MacHandleMouseMovedEvent(wxInt32 x , wxInt32 y ,wxUint32 modifiers , long timestamp)
2128 {
2129 WindowRef window;
2130
2131 wxWindow* currentMouseWindow = NULL ;
2132
2133 if (s_captureWindow )
2134 {
2135 currentMouseWindow = s_captureWindow ;
2136 }
2137 else
2138 {
2139 wxWindow::MacGetWindowFromPoint( wxPoint( x, y ) , &currentMouseWindow ) ;
2140 }
2141
2142 if ( currentMouseWindow != wxWindow::s_lastMouseWindow )
2143 {
2144 wxMouseEvent event ;
2145
2146 bool isDown = !(modifiers & btnState) ; // 1 is for up
2147 bool controlDown = modifiers & controlKey ; // for simulating right mouse
2148
2149 event.m_leftDown = isDown && !controlDown;
2150
2151 event.m_middleDown = FALSE;
2152 event.m_rightDown = isDown && controlDown;
2153
2154 event.m_shiftDown = modifiers & shiftKey;
2155 event.m_controlDown = modifiers & controlKey;
2156 event.m_altDown = modifiers & optionKey;
2157 event.m_metaDown = modifiers & cmdKey;
2158
2159 event.m_x = x;
2160 event.m_y = y;
2161 event.m_timeStamp = timestamp;
2162
2163 if ( wxWindow::s_lastMouseWindow )
2164 {
2165 wxMouseEvent eventleave(event);
2166 eventleave.SetEventType( wxEVT_LEAVE_WINDOW );
2167 wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y );
2168 eventleave.SetEventObject( wxWindow::s_lastMouseWindow ) ;
2169
2170 #if wxUSE_TOOLTIPS
2171 wxToolTip::RelayEvent( wxWindow::s_lastMouseWindow , eventleave);
2172 #endif // wxUSE_TOOLTIPS
2173 wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave);
2174 }
2175 if ( currentMouseWindow )
2176 {
2177 wxMouseEvent evententer(event);
2178 evententer.SetEventType( wxEVT_ENTER_WINDOW );
2179 currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y );
2180 evententer.SetEventObject( currentMouseWindow ) ;
2181 #if wxUSE_TOOLTIPS
2182 wxToolTip::RelayEvent( currentMouseWindow , evententer);
2183 #endif // wxUSE_TOOLTIPS
2184 currentMouseWindow->GetEventHandler()->ProcessEvent(evententer);
2185 }
2186 wxWindow::s_lastMouseWindow = currentMouseWindow ;
2187 }
2188
2189 short windowPart = inNoWindow ;
2190
2191 if ( s_captureWindow )
2192 {
2193 window = (WindowRef) s_captureWindow->MacGetRootWindow() ;
2194 windowPart = inContent ;
2195 }
2196 else
2197 {
2198 Point pt= { y , x } ;
2199 windowPart = ::FindWindow(pt , &window);
2200 }
2201
2202 switch (windowPart)
2203 {
2204 case inContent :
2205 {
2206 wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ;
2207 if ( win )
2208 win->MacFireMouseEvent( nullEvent , x , y , modifiers , timestamp ) ;
2209 else
2210 {
2211 if ( wxIsBusy() )
2212 {
2213 }
2214 else
2215 UMAShowArrowCursor();
2216 }
2217 }
2218 break;
2219 default :
2220 {
2221 if ( wxIsBusy() )
2222 {
2223 }
2224 else
2225 UMAShowArrowCursor();
2226 }
2227 break ;
2228 }
2229 }
2230 #endif
2231
2232 void wxApp::MacHandleMenuCommand( wxUint32 id )
2233 {
2234 wxMenuBar* mbar = wxMenuBar::MacGetInstalledMenuBar() ;
2235 wxFrame* frame = mbar->GetFrame();
2236 wxCHECK_RET( mbar != NULL && frame != NULL, wxT("error in menu item callback") );
2237 if ( frame )
2238 {
2239 frame->ProcessCommand(id);
2240 }
2241 }
2242
2243 #if !TARGET_CARBON
2244 void wxApp::MacHandleMenuSelect( int macMenuId , int macMenuItemNum )
2245 {
2246 if (macMenuId == 0)
2247 return; // no menu item selected
2248
2249 if (macMenuId == kwxMacAppleMenuId && macMenuItemNum > 1)
2250 {
2251 #if ! TARGET_CARBON
2252 Str255 deskAccessoryName ;
2253 GrafPtr savedPort ;
2254
2255 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId), macMenuItemNum, deskAccessoryName);
2256 GetPort(&savedPort);
2257 OpenDeskAcc(deskAccessoryName);
2258 SetPort(savedPort);
2259 #endif
2260 }
2261 else
2262 {
2263 MenuCommand id ;
2264 GetMenuItemCommandID( GetMenuHandle(macMenuId) , macMenuItemNum , &id ) ;
2265 MacHandleMenuCommand( id ) ;
2266 }
2267 HiliteMenu(0);
2268 }
2269 #endif