1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "app.h"
18 #include "wx/window.h"
20 #include "wx/button.h"
23 #include "wx/gdicmn.h"
26 #include "wx/cursor.h"
29 #include "wx/palette.h"
31 #include "wx/dialog.h"
32 #include "wx/msgdlg.h"
34 #include "wx/module.h"
35 #include "wx/memory.h"
36 #include "wx/tooltip.h"
37 #include "wx/textctrl.h"
39 #include "wx/docview.h"
53 #include "wx/mac/uma.h"
54 #include "wx/mac/macnotfy.h"
57 # include <CoreServices/CoreServices.h>
58 # if defined(WXMAKINGDLL_CORE)
59 # include <mach-o/dyld.h>
64 # include <ToolUtils.h>
65 # include <DiskInit.h>
69 extern wxList wxPendingDelete
;
70 extern wxList
*wxWinMacWindowList
;
71 extern wxList
*wxWinMacControlList
;
73 // statics for implementation
75 static bool s_inYield
= FALSE
;
78 static bool s_inReceiveEvent
= FALSE
;
79 static EventTime sleepTime
= kEventDurationNoWait
;
81 static long sleepTime
= 0 ;
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
)
94 const short kMacMinHeap
= (29 * 1024) ;
95 // platform specific static variables
97 const short kwxMacMenuBarResource
= 1 ;
98 const short kwxMacAppleMenuId
= 1 ;
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 ;
107 bool wxApp::s_macSupportPCMenuShortcuts
= true ;
108 long wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
109 long wxApp::s_macPreferencesMenuItemId
= wxID_PREFERENCES
;
110 long wxApp::s_macExitMenuItemId
= wxID_EXIT
;
111 wxString
wxApp::s_macHelpMenuTitleName
= wxT("&Help") ;
113 //----------------------------------------------------------------------
114 // Core Apple Event Support
115 //----------------------------------------------------------------------
117 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
118 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
119 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
120 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
122 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
124 return wxTheApp
->MacHandleAEODoc( (AppleEvent
*) event
, reply
) ;
127 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
129 return wxTheApp
->MacHandleAEOApp( (AppleEvent
*) event
, reply
) ;
132 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
134 return wxTheApp
->MacHandleAEPDoc( (AppleEvent
*) event
, reply
) ;
137 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
139 return wxTheApp
->MacHandleAEQuit( (AppleEvent
*) event
, reply
) ;
142 // AEODoc Calls MacOpenFile on each of the files passed
144 short wxApp::MacHandleAEODoc(const WXEVENTREF event
, WXEVENTREF
WXUNUSED(reply
))
148 DescType returnedType
;
154 err
= AEGetParamDesc((AppleEvent
*)event
, keyDirectObject
, typeAEList
,&docList
);
158 err
= AECountItems(&docList
, &itemsInList
);
162 ProcessSerialNumber PSN
;
163 PSN
.highLongOfPSN
= 0 ;
164 PSN
.lowLongOfPSN
= kCurrentProcess
;
165 SetFrontProcess( &PSN
) ;
167 for (i
= 1; i
<= itemsInList
; i
++) {
168 AEGetNthPtr(&docList
, i
, typeFSS
, &keywd
, &returnedType
,
169 (Ptr
) & theSpec
, sizeof(theSpec
), &actualSize
);
170 wxString fName
= wxMacFSSpec2MacFilename(&theSpec
);
176 // AEPDoc Calls MacPrintFile on each of the files passed
178 short wxApp::MacHandleAEPDoc(const WXEVENTREF event
, WXEVENTREF
WXUNUSED(reply
))
182 DescType returnedType
;
188 err
= AEGetParamDesc((AppleEvent
*)event
, keyDirectObject
, typeAEList
,&docList
);
192 err
= AECountItems(&docList
, &itemsInList
);
196 ProcessSerialNumber PSN
;
197 PSN
.highLongOfPSN
= 0 ;
198 PSN
.lowLongOfPSN
= kCurrentProcess
;
199 SetFrontProcess( &PSN
) ;
201 for (i
= 1; i
<= itemsInList
; i
++) {
202 AEGetNthPtr(&docList
, i
, typeFSS
, &keywd
, &returnedType
,
203 (Ptr
) & theSpec
, sizeof(theSpec
), &actualSize
);
204 wxString fName
= wxMacFSSpec2MacFilename(&theSpec
);
210 // AEOApp calls MacNewFile
212 short wxApp::MacHandleAEOApp(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
218 // AEQuit attempts to quit the application
220 short wxApp::MacHandleAEQuit(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
222 wxWindow
* win
= GetTopWindow() ;
234 //----------------------------------------------------------------------
235 // Support Routines linking the Mac...File Calls to the Document Manager
236 //----------------------------------------------------------------------
238 void wxApp::MacOpenFile(const wxString
& fileName
)
240 wxDocManager
* dm
= wxDocManager::GetDocumentManager() ;
242 dm
->CreateDocument(fileName
, wxDOC_SILENT
) ;
245 void wxApp::MacPrintFile(const wxString
& fileName
)
247 wxDocManager
* dm
= wxDocManager::GetDocumentManager() ;
250 wxDocument
*doc
= dm
->CreateDocument(fileName
, wxDOC_SILENT
) ;
253 wxView
* view
= doc
->GetFirstView() ;
256 wxPrintout
*printout
= view
->OnCreatePrintout();
260 printer
.Print(view
->GetFrame(), printout
, TRUE
);
266 doc
->DeleteAllViews();
267 dm
->RemoveDocument(doc
) ;
273 void wxApp::MacNewFile()
277 //----------------------------------------------------------------------
278 // Carbon Event Handler
279 //----------------------------------------------------------------------
283 static const EventTypeSpec eventList
[] =
285 { kEventClassCommand
, kEventProcessCommand
} ,
286 { kEventClassCommand
, kEventCommandUpdateStatus
} ,
288 { kEventClassMenu
, kEventMenuOpening
},
289 { kEventClassMenu
, kEventMenuClosed
},
291 { kEventClassApplication
, kEventAppActivated
} ,
292 { kEventClassApplication
, kEventAppDeactivated
} ,
293 // handling the quit event is not recommended by apple
294 // rather using the quit apple event - which we do
296 { kEventClassAppleEvent
, kEventAppleEvent
} ,
298 { kEventClassMouse
, kEventMouseDown
} ,
299 { kEventClassMouse
, kEventMouseMoved
} ,
300 { kEventClassMouse
, kEventMouseUp
} ,
301 { kEventClassMouse
, kEventMouseDragged
} ,
305 static pascal OSStatus
306 MenuEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
308 // FIXME: this doesn't work for multiple windows
309 wxWindow
*win
= wxTheApp
->GetTopWindow();
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...
318 GetEventParameter(event
,
319 kEventParamDirectObject
,
321 sizeof(menuRef
), NULL
,
325 wxMenuEvent
wxevent(GetEventKind(event
) == kEventMenuOpening
328 wxevent
.SetEventObject(win
);
330 (void)win
->GetEventHandler()->ProcessEvent(wxevent
);
333 return eventNotHandledErr
;
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
340 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
342 static pascal OSStatus
MouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
344 OSStatus result
= eventNotHandledErr
;
347 UInt32 modifiers
= 0;
348 EventMouseButton button
= 0 ;
351 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
352 sizeof( Point
), NULL
, &point
);
353 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
354 sizeof( UInt32
), NULL
, &modifiers
);
355 GetEventParameter( event
, kEventParamMouseButton
, typeMouseButton
, NULL
,
356 sizeof( EventMouseButton
), NULL
, &button
);
357 GetEventParameter( event
, kEventParamClickCount
, typeUInt32
, NULL
,
358 sizeof( UInt32
), NULL
, &click
);
360 if ( button
== 0 || GetEventKind( event
) == kEventMouseUp
)
361 modifiers
+= btnState
;
364 switch( GetEventKind(event
) )
366 case kEventMouseDown
:
370 short windowPart
= ::FindWindow(point
, &window
);
372 if ( windowPart
== inMenuBar
)
374 MenuSelect( point
) ;
379 case kEventMouseDragged
:
382 if ( wxTheApp
->s_captureWindow
)
383 wxMacWindowEventHandler( handler
, event
, (void*) wxTheApp
->s_captureWindow
->MacGetTopLevelWindow() ) ;
386 case kEventMouseMoved
:
388 wxTheApp
->MacHandleMouseMovedEvent( point
.h
, point
.v
, modifiers
, EventTimeToTicks( GetEventTime( event
) ) ) ;
398 static pascal OSStatus
CommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
400 OSStatus result
= eventNotHandledErr
;
404 GetEventParameter( event
, kEventParamDirectObject
, typeHICommand
, NULL
,
405 sizeof( HICommand
), NULL
, &command
);
407 MenuCommand id
= command
.commandID
;
408 if ( id
== kHICommandPreferences
)
409 id
= wxApp::s_macPreferencesMenuItemId
;
411 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
412 wxMenu
* menu
= NULL
;
413 wxMenuItem
* item
= NULL
;
417 item
= mbar
->FindItem( id
, &menu
) ;
418 // it is not 100 % sure that an menu of id 0 is really ours, safety check
419 if ( id
== 0 && menu
!= NULL
&& menu
->GetHMenu() != command
.menu
.menuRef
)
426 if ( item
== NULL
|| menu
== NULL
|| mbar
== NULL
)
429 switch( GetEventKind( event
) )
431 case kEventProcessCommand
:
433 if (item
->IsCheckable())
435 item
->Check( !item
->IsChecked() ) ;
438 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
442 case kEventCommandUpdateStatus
:
443 // eventually trigger an updateui round
453 static pascal OSStatus
ApplicationEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
455 OSStatus result
= eventNotHandledErr
;
456 switch ( GetEventKind( event
) )
458 case kEventAppActivated
:
461 wxTheApp
->MacResume( true ) ;
465 case kEventAppDeactivated
:
468 wxTheApp
->MacSuspend( true ) ;
478 pascal OSStatus
wxAppEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
480 OSStatus result
= eventNotHandledErr
;
481 switch( GetEventClass( event
) )
483 case kEventClassCommand
:
484 result
= CommandEventHandler( handler
, event
, data
) ;
486 case kEventClassApplication
:
487 result
= ApplicationEventHandler( handler
, event
, data
) ;
489 case kEventClassMenu
:
490 result
= MenuEventHandler( handler
, event
, data
) ;
492 case kEventClassMouse
:
493 result
= MouseEventHandler( handler
, event
, data
) ;
495 case kEventClassAppleEvent
:
498 wxMacConvertEventToRecord( event
, &rec
) ;
499 result
= AEProcessAppleEvent( &rec
) ;
509 DEFINE_ONE_SHOT_HANDLER_GETTER( wxAppEventHandler
)
513 #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
514 // we know it's there ;-)
515 WXIMPORT
char std::__throws_bad_alloc
;
518 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
524 UMAInitToolbox( 4 ) ;
525 SetEventMask( everyEvent
) ;
526 UMAShowWatchCursor() ;
528 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
529 // open shared library resources from here since we don't have
530 // __wxinitialize in Mach-O shared libraries
531 wxStAppResource::OpenSharedLibraryResource(NULL
);
535 // test the minimal configuration necessary
541 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
543 error
= kMacSTRWrongMachine
;
545 else if (theMachine
< gestaltMacPlus
)
547 error
= kMacSTRWrongMachine
;
549 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
551 error
= kMacSTROldSystem
;
553 else if ( theSystem
< 0x0860 )
555 error
= kMacSTROldSystem
;
557 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
559 error
= kMacSTRSmallSize
;
565 if ( !UMAHasAppearance() )
567 error = kMacSTRNoPre8Yet ;
573 // if we encountered any problems so far, give the error code and exit immediately
577 wxStAppResource resload
;
581 GetIndString(message
, 128, error
);
582 UMAShowArrowCursor() ;
583 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
584 itemHit
= Alert(128, nil
);
589 # if __option(profile)
590 ProfilerInit( collectDetailed
, bestTimeBase
, 40000 , 50 ) ;
595 // now avoid exceptions thrown for new (bad_alloc)
596 // FIXME CS for some changes outside wxMac does not compile anymore
598 std::__throws_bad_alloc
= 0 ;
603 s_macCursorRgn
= ::NewRgn() ;
605 // Mac OS X passes a process serial number command line argument when
606 // the application is launched from the Finder. This argument must be
607 // removed from the command line arguments before being handled by the
608 // application (otherwise applications would need to handle it)
611 static const wxChar
*ARG_PSN
= _T("-psn_");
612 if ( wxStrncmp(argv
[1], ARG_PSN
, wxStrlen(ARG_PSN
)) == 0 )
614 // remove this argument
616 memmove(argv
+ 1, argv
+ 2, argc
* sizeof(char *));
620 if ( !wxAppBase::Initialize(argc
, argv
) )
623 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
624 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
626 wxMacCreateNotifierTable() ;
628 UMAShowArrowCursor() ;
633 bool wxApp::OnInitGui()
635 if( !wxAppBase::OnInitGui() )
639 InstallStandardEventHandler( GetApplicationEventTarget() ) ;
641 InstallApplicationEventHandler(
642 GetwxAppEventHandlerUPP(),
643 GetEventTypeCount(eventList
), eventList
, wxTheApp
, (EventHandlerRef
*)&(wxTheApp
->m_macEventHandler
));
646 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
647 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
648 NewAEEventHandlerUPP(AEHandleODoc
) ,
650 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
651 NewAEEventHandlerUPP(AEHandleOApp
) ,
653 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
654 NewAEEventHandlerUPP(AEHandlePDoc
) ,
656 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
657 NewAEEventHandlerUPP(AEHandleQuit
) ,
660 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
661 NewAEEventHandlerProc(AEHandleODoc
) ,
663 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
664 NewAEEventHandlerProc(AEHandleOApp
) ,
666 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
667 NewAEEventHandlerProc(AEHandlePDoc
) ,
669 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
670 NewAEEventHandlerProc(AEHandleQuit
) ,
677 void wxApp::CleanUp()
679 wxToolTip::RemoveToolTips() ;
681 // One last chance for pending objects to be cleaned up
682 wxTheApp
->DeletePendingObjects();
684 wxMacDestroyNotifierTable() ;
686 delete wxWinMacWindowList
;
687 wxWinMacWindowList
= NULL
;
689 delete wxWinMacControlList
;
690 wxWinMacControlList
= NULL
;
693 # if __option(profile)
694 ProfilerDump( (StringPtr
)"\papp.prof" ) ;
699 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
700 // close shared library resources from here since we don't have
701 // __wxterminate in Mach-O shared libraries
702 wxStAppResource::CloseSharedLibraryResource();
705 UMACleanupToolbox() ;
706 if (s_macCursorRgn
) {
707 ::DisposeRgn((RgnHandle
)s_macCursorRgn
);
714 wxAppBase::CleanUp();
717 //----------------------------------------------------------------------
718 // misc initialization stuff
719 //----------------------------------------------------------------------
721 // extern variable for shared library resource id
722 // need to be able to find it with NSLookupAndBindSymbol
723 short gSharedLibraryResource
= kResFileNotOpened
;
725 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
726 CFBundleRef gSharedLibraryBundle
= NULL
;
727 #endif /* WXMAKINGDLL_CORE && __DARWIN__ */
729 wxStAppResource::wxStAppResource()
731 m_currentRefNum
= CurResFile() ;
732 if ( gSharedLibraryResource
!= kResFileNotOpened
)
734 UseResFile( gSharedLibraryResource
) ;
738 wxStAppResource::~wxStAppResource()
740 if ( m_currentRefNum
!= kResFileNotOpened
)
742 UseResFile( m_currentRefNum
) ;
746 void wxStAppResource::OpenSharedLibraryResource(const void *initBlock
)
748 gSharedLibraryResource
= kResFileNotOpened
;
750 #ifdef WXMAKINGDLL_CORE
751 if ( initBlock
!= NULL
) {
752 const CFragInitBlock
*theInitBlock
= (const CFragInitBlock
*)initBlock
;
753 FSSpec
*fileSpec
= NULL
;
755 if (theInitBlock
->fragLocator
.where
== kDataForkCFragLocator
) {
756 fileSpec
= theInitBlock
->fragLocator
.u
.onDisk
.fileSpec
;
758 else if (theInitBlock
->fragLocator
.where
== kResourceCFragLocator
) {
759 fileSpec
= theInitBlock
->fragLocator
.u
.inSegs
.fileSpec
;
762 if (fileSpec
!= NULL
) {
763 gSharedLibraryResource
= FSpOpenResFile(fileSpec
, fsRdPerm
);
768 // Open the shared library resource file if it is not yet open
771 const char *theLibPath
;
773 gSharedLibraryBundle
= CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWindows"));
774 if (gSharedLibraryBundle
!= NULL
) {
775 // wxWindows has been bundled into a framework
776 // load the framework resources
778 gSharedLibraryResource
= CFBundleOpenBundleResourceMap(gSharedLibraryBundle
);
781 // wxWindows is a simple dynamic shared library
782 // load the resources from the data fork of a separate resource file
786 OSErr theErr
= noErr
;
788 // get the library path
789 theSymbol
= NSLookupAndBindSymbol("_gSharedLibraryResource");
790 theModule
= NSModuleForSymbol(theSymbol
);
791 theLibPath
= NSLibraryNameForModule(theModule
);
793 // if we call wxLogDebug from here then, as wxTheApp hasn't been
794 // created yet when we're called from wxApp::Initialize(), wxLog
795 // is going to create a default stderr-based log target instead of
796 // the expected normal GUI one -- don't do it, if we really want
797 // to see this message just use fprintf() here
799 wxLogDebug( wxT("wxMac library installation name is '%s'"),
803 // allocate copy to replace .dylib.* extension with .rsrc
804 if (theLibPath
!= NULL
) {
805 theResPath
= theLibPath
;
806 // replace '_core' with '' in case of multi-lib build
807 theResPath
.Replace(wxT("_core"), wxEmptyString
);
808 // replace ".dylib" shared library extension with ".rsrc"
809 theResPath
.Replace(wxT(".dylib"), wxT(".rsrc"));
810 // Find the begining of the filename
811 theName
= theResPath
.AfterLast('/');
814 wxLogDebug( wxT("wxMac resources file name is '%s'"),
815 theResPath
.mb_str() );
818 theErr
= FSPathMakeRef((UInt8
*) theResPath
.mb_str(), &theResRef
, false);
819 if (theErr
!= noErr
) {
820 // try in current directory (using name only)
821 theErr
= FSPathMakeRef((UInt8
*) theName
.mb_str(), &theResRef
, false);
824 // open the resource file
825 if (theErr
== noErr
) {
826 theErr
= FSOpenResourceFile( &theResRef
, 0, NULL
, fsRdPerm
,
827 &gSharedLibraryResource
);
829 if (theErr
!= noErr
) {
832 wxT("unable to open wxMac resource file '%s'\n"),
833 theResPath
.mb_str() );
834 #endif // __WXDEBUG__
839 #endif /* __DARWIN__ */
841 #endif /* WXMAKINGDLL_CORE */
844 void wxStAppResource::CloseSharedLibraryResource()
846 #ifdef WXMAKINGDLL_CORE
847 // Close the shared library resource file
848 if (gSharedLibraryResource
!= kResFileNotOpened
) {
850 if (gSharedLibraryBundle
!= NULL
) {
851 CFBundleCloseBundleResourceMap(gSharedLibraryBundle
,
852 gSharedLibraryResource
);
853 gSharedLibraryBundle
= NULL
;
856 #endif /* __DARWIN__ */
858 CloseResFile(gSharedLibraryResource
);
860 gSharedLibraryResource
= kResFileNotOpened
;
862 #endif /* WXMAKINGDLL_CORE */
865 #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
867 // for shared libraries we have to manually get the correct resource
868 // ref num upon initializing and releasing when terminating, therefore
869 // the __wxinitialize and __wxterminate must be used
872 void __sinit(void); /* (generated by linker) */
873 pascal OSErr
__initialize(const CFragInitBlock
*theInitBlock
);
874 pascal void __terminate(void);
877 pascal OSErr
__wxinitialize(const CFragInitBlock
*theInitBlock
)
879 wxStAppResource::OpenSharedLibraryResource( theInitBlock
) ;
880 return __initialize( theInitBlock
) ;
883 pascal void __wxterminate(void)
885 wxStAppResource::CloseSharedLibraryResource() ;
889 #endif /* WXMAKINGDLL_CORE && !__DARWIN__ */
893 bool wxMacConvertEventToRecord( EventRef event
, EventRecord
*rec
)
895 bool converted
= ConvertEventRefToEventRecord( event
,rec
) ;
896 OSStatus err
= noErr
;
899 switch( GetEventClass( event
) )
901 case kEventClassKeyboard
:
904 switch( GetEventKind(event
) )
906 case kEventRawKeyDown
:
907 rec
->what
= keyDown
;
909 case kEventRawKeyRepeat
:
910 rec
->what
= autoKey
;
912 case kEventRawKeyUp
:
915 case kEventRawKeyModifiersChanged
:
916 rec
->what
= nullEvent
;
925 unsigned char charCode
;
927 GetMouse( &rec
->where
) ;
929 err
= GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
930 err
= GetEventParameter(event
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
931 err
= GetEventParameter(event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
932 rec
->modifiers
= modifiers
;
933 rec
->message
= (keyCode
<< 8 ) + charCode
;
937 case kEventClassTextInput
:
939 switch( GetEventKind( event
) )
941 case kEventTextInputUnicodeForKeyEvent
:
944 err
= GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent
) ;
948 unsigned char charCode
;
950 GetMouse( &rec
->where
) ;
951 rec
->what
= keyDown
;
952 err
= GetEventParameter(rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
953 err
= GetEventParameter(rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
954 err
= GetEventParameter(rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
955 rec
->modifiers
= modifiers
;
956 rec
->message
= (keyCode
<< 8 ) + charCode
;
972 pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
974 OSStatus result = eventNotHandledErr ;
977 switch ( GetEventClass( event ) )
979 case kEventClassKeyboard :
980 if ( wxMacConvertEventToRecord( event , &rec ) )
982 wxTheApp->MacHandleModifierEvents( &rec ) ;
983 wxTheApp->MacHandleOneEvent( &rec ) ;
987 case kEventClassTextInput :
988 if ( wxMacConvertEventToRecord( event , &rec ) )
990 wxTheApp->MacHandleModifierEvents( &rec ) ;
991 wxTheApp->MacHandleOneEvent( &rec ) ;
1005 m_printMode
= wxPRINT_WINDOWS
;
1008 m_macCurrentEvent
= NULL
;
1010 m_macCurrentEventHandlerCallRef
= NULL
;
1014 int wxApp::MainLoop()
1026 void wxApp::ExitMainLoop()
1028 m_keepGoing
= FALSE
;
1031 // Is a message/event pending?
1032 bool wxApp::Pending()
1035 return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ;
1039 return EventAvail( everyEvent
, &event
) ;
1043 // Dispatch a message.
1044 bool wxApp::Dispatch()
1051 void wxApp::OnIdle(wxIdleEvent
& event
)
1053 wxAppBase::OnIdle(event
);
1055 // If they are pending events, we must process them: pending events are
1056 // either events to the threads other than main or events posted with
1057 // wxPostEvent() functions
1058 wxMacProcessNotifierAndPendingEvents();
1060 if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
1061 wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
1064 void wxApp::WakeUpIdle()
1075 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
1078 GetTopWindow()->Close(TRUE
);
1081 // Default behaviour: close the application with prompts. The
1082 // user can veto the close, and therefore the end session.
1083 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
1087 if (!GetTopWindow()->Close(!event
.CanVeto()))
1092 extern "C" void wxCYield() ;
1098 // Yield to other processes
1100 bool wxApp::Yield(bool onlyIfNeeded
)
1104 if ( !onlyIfNeeded
)
1106 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1115 YieldToAnyThread() ;
1117 // by definition yield should handle all non-processed events
1121 OSStatus status
= noErr
;
1124 s_inReceiveEvent
= true ;
1125 status
= ReceiveNextEvent(0, NULL
,kEventDurationNoWait
,true,&theEvent
) ;
1126 s_inReceiveEvent
= false ;
1128 if ( status
== eventLoopTimedOutErr
)
1130 // make sure next time the event loop will trigger idle events
1131 sleepTime
= kEventDurationNoWait
;
1133 else if ( status
== eventLoopQuitErr
)
1135 // according to QA1061 this may also occur when a WakeUp Process
1140 MacHandleOneEvent( theEvent
) ;
1141 ReleaseEvent(theEvent
);
1143 } while( status
== noErr
) ;
1147 // having a larger value here leads to large performance slowdowns
1148 // so we cannot give background apps more processor time here
1149 // we do so however having a large sleep value in the main event loop
1152 while ( !IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, (RgnHandle
) wxApp::s_macCursorRgn
))
1154 MacHandleModifierEvents( &event
) ;
1155 MacHandleOneEvent( &event
);
1156 if ( event
.what
!= kHighLevelEvent
)
1157 SetRectRgn( (RgnHandle
) wxApp::s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1159 MacHandleModifierEvents( &event
) ;
1162 wxMacProcessNotifierAndPendingEvents() ;
1168 // platform specifics
1170 void wxApp::MacSuspend( bool convertClipboard
)
1173 // we have to deactive the top level windows manually
1175 wxWindowListNode
* node
= wxTopLevelWindows
.GetFirst();
1178 wxTopLevelWindow
* win
= (wxTopLevelWindow
*) node
->Data();
1180 #if 0 // having problems right now with that
1181 if (!win
->HasFlag(wxSTAY_ON_TOP
))
1184 win
->MacActivate( ((EventRecord
*) MacGetCurrentEvent())->when
, false ) ;
1186 node
= node
->GetNext();
1189 ::HideFloatingWindows() ;
1191 s_lastMouseDown
= 0 ;
1193 if( convertClipboard
)
1195 MacConvertPrivateToPublicScrap() ;
1199 extern wxList wxModalDialogs
;
1201 void wxApp::MacResume( bool convertClipboard
)
1203 s_lastMouseDown
= 0 ;
1204 if( convertClipboard
)
1206 MacConvertPublicToPrivateScrap() ;
1210 ::ShowFloatingWindows() ;
1211 // raise modal dialogs in case a non modal window was selected to activate the app
1213 wxNode
* node
= wxModalDialogs
.GetFirst();
1216 wxDialog
* dialog
= (wxDialog
*) node
->GetData();
1219 node
= node
->GetNext();
1224 void wxApp::MacConvertPrivateToPublicScrap()
1228 void wxApp::MacConvertPublicToPrivateScrap()
1232 void wxApp::MacDoOneEvent()
1237 s_inReceiveEvent
= true ;
1238 OSStatus status
= ReceiveNextEvent(0, NULL
,sleepTime
,true,&theEvent
) ;
1239 s_inReceiveEvent
= false ;
1240 if ( status
== eventLoopTimedOutErr
)
1242 if ( wxTheApp
->ProcessIdle() )
1243 sleepTime
= kEventDurationNoWait
;
1245 sleepTime
= kEventDurationForever
;
1247 else if ( status
== eventLoopQuitErr
)
1249 // according to QA1061 this may also occur when a WakeUp Process
1254 MacHandleOneEvent( theEvent
) ;
1255 ReleaseEvent(theEvent
);
1256 sleepTime
= kEventDurationNoWait
;
1261 EventMask eventMask
= everyEvent
;
1263 if (WaitNextEvent(eventMask
, &event
, sleepTime
, (RgnHandle
) s_macCursorRgn
))
1265 MacHandleModifierEvents( &event
) ;
1266 MacHandleOneEvent( &event
);
1270 MacHandleModifierEvents( &event
) ;
1272 WindowPtr window
= ::FrontWindow() ;
1274 ::IdleControls( window
) ;
1276 if ( wxTheApp
->ProcessIdle() )
1279 sleepTime
= GetCaretTime() / 2 ;
1281 if ( event
.what
!= kHighLevelEvent
)
1282 SetRectRgn( (RgnHandle
) s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1286 DeletePendingObjects() ;
1287 wxMacProcessNotifierAndPendingEvents() ;
1290 void wxApp::MacHandleOneEvent( WXEVENTREF evr
)
1293 EventTargetRef theTarget
;
1294 theTarget
= GetEventDispatcherTarget();
1295 m_macCurrentEvent
= evr
;
1296 SendEventToEventTarget ((EventRef
) evr
, theTarget
);
1298 EventRecord
* ev
= (EventRecord
*) evr
;
1299 m_macCurrentEvent
= ev
;
1301 wxApp::sm_lastMessageTime
= ev
->when
;
1306 MacHandleMouseDownEvent( ev
) ;
1307 if ( ev
->modifiers
& controlKey
)
1308 s_lastMouseDown
= 2;
1310 s_lastMouseDown
= 1;
1313 if ( s_lastMouseDown
== 2 )
1315 ev
->modifiers
|= controlKey
;
1319 ev
->modifiers
&= ~controlKey
;
1321 MacHandleMouseUpEvent( ev
) ;
1322 s_lastMouseDown
= 0;
1325 MacHandleActivateEvent( ev
) ;
1328 MacHandleUpdateEvent( ev
) ;
1332 MacHandleKeyDownEvent( ev
) ;
1335 MacHandleKeyUpEvent( ev
) ;
1338 MacHandleDiskEvent( ev
) ;
1341 MacHandleOSEvent( ev
) ;
1343 case kHighLevelEvent
:
1344 MacHandleHighLevelEvent( ev
) ;
1350 wxMacProcessNotifierAndPendingEvents() ;
1354 bool s_macIsInModalLoop
= false ;
1356 void wxApp::MacHandleModifierEvents( WXEVENTREF evr
)
1358 EventRecord
* ev
= (EventRecord
*) evr
;
1359 if ( ev
->modifiers
!= s_lastModifiers
&& wxWindow::FindFocus() != NULL
)
1361 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1363 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1364 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1365 event
.m_altDown
= ev
->modifiers
& optionKey
;
1366 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1368 event
.m_x
= ev
->where
.h
;
1369 event
.m_y
= ev
->where
.v
;
1370 event
.m_timeStamp
= ev
->when
;
1371 wxWindow
* focus
= wxWindow::FindFocus() ;
1372 event
.SetEventObject(focus
);
1374 if ( (ev
->modifiers
^ s_lastModifiers
) & controlKey
)
1376 event
.m_keyCode
= WXK_CONTROL
;
1377 event
.SetEventType( ( ev
->modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1378 focus
->GetEventHandler()->ProcessEvent( event
) ;
1380 if ( (ev
->modifiers
^ s_lastModifiers
) & shiftKey
)
1382 event
.m_keyCode
= WXK_SHIFT
;
1383 event
.SetEventType( ( ev
->modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1384 focus
->GetEventHandler()->ProcessEvent( event
) ;
1386 if ( (ev
->modifiers
^ s_lastModifiers
) & optionKey
)
1388 event
.m_keyCode
= WXK_ALT
;
1389 event
.SetEventType( ( ev
->modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1390 focus
->GetEventHandler()->ProcessEvent( event
) ;
1392 if ( ( ev
->modifiers
^ s_lastModifiers
) & cmdKey
)
1394 event
.m_keyCode
= WXK_COMMAND
;
1395 event
.SetEventType( ( ev
->modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1396 focus
->GetEventHandler()->ProcessEvent( event
) ;
1398 s_lastModifiers
= ev
->modifiers
;
1402 void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr
)
1404 // we must avoid reentrancy problems when processing high level events eg printing
1405 bool former
= s_inYield
;
1407 EventRecord
* ev
= (EventRecord
*) evr
;
1408 ::AEProcessAppleEvent( ev
) ;
1409 s_inYield
= former
;
1412 void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr
)
1414 EventRecord
* ev
= (EventRecord
*) evr
;
1415 wxToolTip::RemoveToolTips() ;
1418 WindowRef frontWindow
= ::FrontNonFloatingWindow() ;
1419 WindowAttributes frontWindowAttributes
= NULL
;
1421 ::GetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
1423 short windowPart
= ::FindWindow(ev
->where
, &window
);
1424 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1425 if ( wxPendingDelete
.Member(win
) )
1429 GetQDGlobalsScreenBits( &screenBits
);
1434 if ( s_macIsInModalLoop
)
1440 UInt32 menuresult
= MenuSelect(ev
->where
) ;
1441 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1442 s_lastMouseDown
= 0;
1446 SystemClick( ev
, window
) ;
1447 s_lastMouseDown
= 0;
1450 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1456 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1461 Point pt
= { 0, 0 } ;
1462 SetPortWindowPort(window
) ;
1463 LocalToGlobal( &pt
) ;
1465 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1466 -1 , wxSIZE_USE_EXISTING
);
1468 s_lastMouseDown
= 0;
1472 if (TrackGoAway(window
, ev
->where
))
1477 s_lastMouseDown
= 0;
1481 Rect newContentRect
;
1482 Rect constraintRect
;
1483 constraintRect
.top
= win
->GetMinHeight() ;
1484 if ( constraintRect
.top
== -1 )
1485 constraintRect
.top
= 0 ;
1486 constraintRect
.left
= win
->GetMinWidth() ;
1487 if ( constraintRect
.left
== -1 )
1488 constraintRect
.left
= 0 ;
1489 constraintRect
.right
= win
->GetMaxWidth() ;
1490 if ( constraintRect
.right
== -1 )
1491 constraintRect
.right
= 32000 ;
1492 constraintRect
.bottom
= win
->GetMaxHeight() ;
1493 if ( constraintRect
.bottom
== -1 )
1494 constraintRect
.bottom
= 32000 ;
1496 Boolean growResult
= ResizeWindow( window
, ev
->where
,
1497 &constraintRect
, &newContentRect
) ;
1500 win
->SetSize( newContentRect
.left
, newContentRect
.top
,
1501 newContentRect
.right
- newContentRect
.left
,
1502 newContentRect
.bottom
- newContentRect
.top
, wxSIZE_USE_EXISTING
);
1504 s_lastMouseDown
= 0;
1509 if (TrackBox(window
, ev
->where
, windowPart
))
1511 // TODO setup size event
1512 ZoomWindow( window
, windowPart
, false ) ;
1518 Point pt
= { 0, 0 } ;
1519 SetPortWindowPort(window
) ;
1520 LocalToGlobal( &pt
) ;
1523 GetWindowPortBounds(window
, &tempRect
) ;
1524 win
->SetSize( pt
.h
, pt
.v
, tempRect
.right
-tempRect
.left
,
1525 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1528 s_lastMouseDown
= 0;
1530 case inCollapseBox
:
1531 // TODO setup size event
1532 s_lastMouseDown
= 0;
1539 SetPortWindowPort(window
) ;
1542 if ( window
!= frontWindow
&& wxTheApp
->s_captureWindow
== NULL
)
1544 if ( s_macIsInModalLoop
)
1548 else if ( UMAIsWindowFloating( window
) )
1551 win
->MacMouseDown( ev
, windowPart
) ;
1555 // Activate window first
1556 ::SelectWindow( window
) ;
1560 win
->MacMouseDown( ev
, windowPart
) ;
1566 win
->MacMouseDown( ev
, windowPart
) ;
1574 void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr
)
1576 EventRecord
* ev
= (EventRecord
*) evr
;
1579 short windowPart
= inNoWindow
;
1580 if ( wxTheApp
->s_captureWindow
)
1582 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
1583 windowPart
= inContent
;
1587 windowPart
= ::FindWindow(ev
->where
, &window
) ;
1598 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1600 win
->MacMouseUp( ev
, windowPart
) ;
1608 long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
1609 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1614 case kHomeCharCode
:
1617 case kEnterCharCode
:
1618 retval
= WXK_RETURN
;
1623 case kHelpCharCode
:
1626 case kBackspaceCharCode
:
1632 case kPageUpCharCode
:
1633 retval
= WXK_PAGEUP
;
1635 case kPageDownCharCode
:
1636 retval
= WXK_PAGEDOWN
;
1638 case kReturnCharCode
:
1639 retval
= WXK_RETURN
;
1641 case kFunctionKeyCharCode
:
1693 case kEscapeCharCode
:
1694 retval
= WXK_ESCAPE
;
1696 case kLeftArrowCharCode
:
1699 case kRightArrowCharCode
:
1700 retval
= WXK_RIGHT
;
1702 case kUpArrowCharCode
:
1705 case kDownArrowCharCode
:
1708 case kDeleteCharCode
:
1709 retval
= WXK_DELETE
;
1718 void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr
)
1720 EventRecord
* ev
= (EventRecord
*) evr
;
1721 wxToolTip::RemoveToolTips() ;
1723 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1724 if ( HiWord( menuresult
) )
1726 if ( !s_macIsInModalLoop
)
1727 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1731 wxWindow
* focus
= wxWindow::FindFocus() ;
1733 if ( MacSendKeyDownEvent( focus
, ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) == false )
1736 // we must handle control keys the other way round, otherwise text content is updated too late
1737 // has not been handled -> perform default
1738 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
1739 if ( control
&& control
->GetMacControl() != NULL
)
1743 keychar
= short(ev
->message
& charCodeMask
);
1744 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1745 ::HandleControlKey( (ControlHandle
) control
->GetMacControl() , keycode
, keychar
, ev
->modifiers
) ;
1752 void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr
)
1754 EventRecord
* ev
= (EventRecord
*) evr
;
1755 wxToolTip::RemoveToolTips() ;
1757 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1758 if ( HiWord( menuresult
) )
1763 MacSendKeyUpEvent( wxWindow::FindFocus() , ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) ;
1769 bool wxApp::MacSendKeyDownEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
)
1776 keychar
= short(keymessage
& charCodeMask
);
1777 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
1779 if ( modifiers
& ( controlKey
|shiftKey
|optionKey
) )
1781 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1782 // and look at the character after
1784 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
);
1785 keychar
= short(keyInfo
& charCodeMask
);
1786 keycode
= short(keyInfo
& keyCodeMask
) >> 8 ;
1788 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1789 long realkeyval
= keyval
;
1790 if ( keyval
== keychar
)
1792 // 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)
1793 realkeyval
= short(keymessage
& charCodeMask
) ;
1794 keyval
= wxToupper( keyval
) ;
1797 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1798 bool handled
= false ;
1799 event
.m_shiftDown
= modifiers
& shiftKey
;
1800 event
.m_controlDown
= modifiers
& controlKey
;
1801 event
.m_altDown
= modifiers
& optionKey
;
1802 event
.m_metaDown
= modifiers
& cmdKey
;
1803 event
.m_keyCode
= keyval
;
1807 event
.m_timeStamp
= when
;
1808 event
.SetEventObject(focus
);
1809 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1810 if ( handled
&& event
.GetSkipped() )
1817 wxWindow
*ancestor
= focus
;
1820 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1823 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1824 handled
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1827 if (ancestor
->IsTopLevel())
1829 ancestor
= ancestor
->GetParent();
1832 #endif // wxUSE_ACCEL
1836 event
.Skip( FALSE
) ;
1837 event
.SetEventType( wxEVT_CHAR
) ;
1839 event
.m_keyCode
= realkeyval
;
1841 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1842 if ( handled
&& event
.GetSkipped() )
1846 (keyval
== WXK_TAB
) &&
1847 // CS: copied the change below from wxGTK
1848 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
1849 // have this style, yet choose not to process this particular TAB in which
1850 // case TAB must still work as a navigational character
1852 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1854 (focus
->GetParent()) &&
1855 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1857 wxNavigationKeyEvent new_event
;
1858 new_event
.SetEventObject( focus
);
1859 new_event
.SetDirection( !event
.ShiftDown() );
1860 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1861 new_event
.SetWindowChange( event
.ControlDown() );
1862 new_event
.SetCurrentFocus( focus
);
1863 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1864 if ( handled
&& new_event
.GetSkipped() )
1867 // backdoor handler for default return and command escape
1868 if ( !handled
&& (!focus
->IsKindOf(CLASSINFO(wxControl
) ) || !focus
->MacCanFocus() ) )
1870 // if window is not having a focus still testing for default enter or cancel
1871 // TODO add the UMA version for ActiveNonFloatingWindow
1872 wxWindow
* focus
= wxFindWinFromMacWindow( FrontWindow() ) ;
1875 if ( keyval
== WXK_RETURN
)
1877 wxButton
*def
= wxDynamicCast(focus
->GetDefaultItem(),
1879 if ( def
&& def
->IsEnabled() )
1881 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
1882 event
.SetEventObject(def
);
1883 def
->Command(event
);
1887 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1888 else if (keyval
== WXK_ESCAPE
|| (keyval
== '.' && modifiers
& cmdKey
) )
1890 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1891 new_event
.SetEventObject( focus
);
1892 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1899 bool wxApp::MacSendKeyUpEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
)
1906 keychar
= short(keymessage
& charCodeMask
);
1907 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
1908 if ( modifiers
& ( controlKey
|shiftKey
|optionKey
) )
1910 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1911 // and look at the character after
1913 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
);
1914 keychar
= short(keyInfo
& charCodeMask
);
1915 keycode
= short(keyInfo
& keyCodeMask
) >> 8 ;
1917 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1919 if ( keyval
== keychar
)
1921 keyval
= wxToupper( keyval
) ;
1923 bool handled
= false ;
1925 wxKeyEvent
event(wxEVT_KEY_UP
);
1926 event
.m_shiftDown
= modifiers
& shiftKey
;
1927 event
.m_controlDown
= modifiers
& controlKey
;
1928 event
.m_altDown
= modifiers
& optionKey
;
1929 event
.m_metaDown
= modifiers
& cmdKey
;
1930 event
.m_keyCode
= keyval
;
1934 event
.m_timeStamp
= when
;
1935 event
.SetEventObject(focus
);
1936 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1942 void wxApp::MacHandleActivateEvent( WXEVENTREF evr
)
1944 EventRecord
* ev
= (EventRecord
*) evr
;
1945 WindowRef window
= (WindowRef
) ev
->message
;
1948 bool activate
= (ev
->modifiers
& activeFlag
) ;
1949 WindowClass wclass
;
1950 ::GetWindowClass ( window
, &wclass
) ;
1951 if ( wclass
== kFloatingWindowClass
)
1953 // if it is a floater we activate/deactivate the front non-floating window instead
1954 window
= ::FrontNonFloatingWindow() ;
1956 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1958 win
->MacActivate( ev
->when
, activate
) ;
1962 void wxApp::MacHandleUpdateEvent( WXEVENTREF evr
)
1964 EventRecord
* ev
= (EventRecord
*) evr
;
1965 WindowRef window
= (WindowRef
) ev
->message
;
1966 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1969 if ( !wxPendingDelete
.Member(win
) )
1970 win
->MacUpdate( ev
->when
) ;
1974 // since there is no way of telling this foreign window to update itself
1975 // we have to invalidate the update region otherwise we keep getting the same
1976 // event over and over again
1977 BeginUpdate( window
) ;
1978 EndUpdate( window
) ;
1982 void wxApp::MacHandleDiskEvent( WXEVENTREF evr
)
1984 EventRecord
* ev
= (EventRecord
*) evr
;
1985 if ( HiWord( ev
->message
) != noErr
)
1989 SetPt( &point
, 100 , 100 ) ;
1991 err
= DIBadMount( point
, ev
->message
) ;
1992 wxASSERT( err
== noErr
) ;
1996 void wxApp::MacHandleOSEvent( WXEVENTREF evr
)
1998 EventRecord
* ev
= (EventRecord
*) evr
;
1999 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
2001 case suspendResumeMessage
:
2003 bool isResuming
= ev
->message
& resumeFlag
;
2004 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
2006 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
2009 WindowRef oldFrontWindow
= NULL
;
2010 WindowRef newFrontWindow
= NULL
;
2012 // in case we don't take care of activating ourselves, we have to synchronize
2013 // our idea of the active window with the process manager's - which it already activated
2015 if ( !doesActivate
)
2016 oldFrontWindow
= ::FrontNonFloatingWindow() ;
2018 MacResume( convertClipboard
) ;
2020 newFrontWindow
= ::FrontNonFloatingWindow() ;
2022 if ( oldFrontWindow
)
2024 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
2026 win
->MacActivate( ev
->when
, false ) ;
2028 if ( newFrontWindow
)
2030 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
2032 win
->MacActivate( ev
->when
, true ) ;
2037 MacSuspend( convertClipboard
) ;
2041 case mouseMovedMessage
:
2045 wxWindow
* currentMouseWindow
= NULL
;
2047 if (s_captureWindow
)
2049 currentMouseWindow
= s_captureWindow
;
2053 wxWindow::MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) ,
2054 ¤tMouseWindow
) ;
2057 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
2059 wxMouseEvent event
;
2061 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
2062 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
2064 event
.m_leftDown
= isDown
&& !controlDown
;
2065 event
.m_middleDown
= FALSE
;
2066 event
.m_rightDown
= isDown
&& controlDown
;
2067 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
2068 event
.m_controlDown
= ev
->modifiers
& controlKey
;
2069 event
.m_altDown
= ev
->modifiers
& optionKey
;
2070 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
2071 event
.m_x
= ev
->where
.h
;
2072 event
.m_y
= ev
->where
.v
;
2073 event
.m_timeStamp
= ev
->when
;
2074 event
.SetEventObject(this);
2076 if ( wxWindow::s_lastMouseWindow
)
2078 wxMouseEvent
eventleave(event
);
2079 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
2080 wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
2081 eventleave
.SetEventObject( wxWindow::s_lastMouseWindow
) ;
2083 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
2085 if ( currentMouseWindow
)
2087 wxMouseEvent
evententer(event
);
2088 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
2089 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
2090 evententer
.SetEventObject( currentMouseWindow
) ;
2091 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
2093 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
2096 short windowPart
= inNoWindow
;
2098 if ( s_captureWindow
)
2100 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
2101 windowPart
= inContent
;
2105 windowPart
= ::FindWindow(ev
->where
, &window
);
2112 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2114 win
->MacMouseMoved( ev
, windowPart
) ;
2121 UMAShowArrowCursor();
2131 UMAShowArrowCursor();
2142 void wxApp::MacHandleMouseMovedEvent(wxInt32 x
, wxInt32 y
,wxUint32 modifiers
, long timestamp
)
2146 wxWindow
* currentMouseWindow
= NULL
;
2148 if (s_captureWindow
)
2150 currentMouseWindow
= s_captureWindow
;
2154 wxWindow::MacGetWindowFromPoint( wxPoint( x
, y
) , ¤tMouseWindow
) ;
2157 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
2159 wxMouseEvent event
;
2161 bool isDown
= !(modifiers
& btnState
) ; // 1 is for up
2162 bool controlDown
= modifiers
& controlKey
; // for simulating right mouse
2164 event
.m_leftDown
= isDown
&& !controlDown
;
2166 event
.m_middleDown
= FALSE
;
2167 event
.m_rightDown
= isDown
&& controlDown
;
2169 event
.m_shiftDown
= modifiers
& shiftKey
;
2170 event
.m_controlDown
= modifiers
& controlKey
;
2171 event
.m_altDown
= modifiers
& optionKey
;
2172 event
.m_metaDown
= modifiers
& cmdKey
;
2176 event
.m_timeStamp
= timestamp
;
2178 if ( wxWindow::s_lastMouseWindow
)
2180 wxMouseEvent
eventleave(event
);
2181 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
2182 wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
2183 eventleave
.SetEventObject( wxWindow::s_lastMouseWindow
) ;
2186 wxToolTip::RelayEvent( wxWindow::s_lastMouseWindow
, eventleave
);
2187 #endif // wxUSE_TOOLTIPS
2188 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
2190 if ( currentMouseWindow
)
2192 wxMouseEvent
evententer(event
);
2193 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
2194 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
2195 evententer
.SetEventObject( currentMouseWindow
) ;
2197 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
2198 #endif // wxUSE_TOOLTIPS
2199 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
2201 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
2204 short windowPart
= inNoWindow
;
2206 if ( s_captureWindow
)
2208 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
2209 windowPart
= inContent
;
2213 Point pt
= { y
, x
} ;
2214 windowPart
= ::FindWindow(pt
, &window
);
2221 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2223 win
->MacFireMouseEvent( nullEvent
, x
, y
, modifiers
, timestamp
) ;
2230 UMAShowArrowCursor();
2240 UMAShowArrowCursor();
2247 void wxApp::MacHandleMenuCommand( wxUint32 id
)
2249 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
2250 wxFrame
* frame
= mbar
->GetFrame();
2251 wxCHECK_RET( mbar
!= NULL
&& frame
!= NULL
, wxT("error in menu item callback") );
2254 frame
->ProcessCommand(id
);
2259 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
2262 return; // no menu item selected
2264 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
2267 Str255 deskAccessoryName
;
2270 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
2271 GetPort(&savedPort
);
2272 OpenDeskAcc(deskAccessoryName
);
2279 GetMenuItemCommandID( GetMenuHandle(macMenuId
) , macMenuItemNum
, &id
) ;
2280 MacHandleMenuCommand( id
) ;