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
, sizeof(ARG_PSN
) - 1) == 0 )
614 // remove this argument
615 memmove(argv
, argv
+ 1, argc
--);
619 if ( !wxAppBase::Initialize(argc
, argv
) )
622 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
623 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
625 wxMacCreateNotifierTable() ;
627 UMAShowArrowCursor() ;
632 bool wxApp::OnInitGui()
634 if( !wxAppBase::OnInitGui() )
638 InstallStandardEventHandler( GetApplicationEventTarget() ) ;
640 InstallApplicationEventHandler(
641 GetwxAppEventHandlerUPP(),
642 GetEventTypeCount(eventList
), eventList
, wxTheApp
, (EventHandlerRef
*)&(wxTheApp
->m_macEventHandler
));
645 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
646 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
647 NewAEEventHandlerUPP(AEHandleODoc
) ,
649 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
650 NewAEEventHandlerUPP(AEHandleOApp
) ,
652 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
653 NewAEEventHandlerUPP(AEHandlePDoc
) ,
655 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
656 NewAEEventHandlerUPP(AEHandleQuit
) ,
659 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
660 NewAEEventHandlerProc(AEHandleODoc
) ,
662 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
663 NewAEEventHandlerProc(AEHandleOApp
) ,
665 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
666 NewAEEventHandlerProc(AEHandlePDoc
) ,
668 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
669 NewAEEventHandlerProc(AEHandleQuit
) ,
676 void wxApp::CleanUp()
678 wxToolTip::RemoveToolTips() ;
680 // One last chance for pending objects to be cleaned up
681 wxTheApp
->DeletePendingObjects();
683 wxMacDestroyNotifierTable() ;
685 delete wxWinMacWindowList
;
686 wxWinMacWindowList
= NULL
;
688 delete wxWinMacControlList
;
689 wxWinMacControlList
= NULL
;
692 # if __option(profile)
693 ProfilerDump( (StringPtr
)"\papp.prof" ) ;
698 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
699 // close shared library resources from here since we don't have
700 // __wxterminate in Mach-O shared libraries
701 wxStAppResource::CloseSharedLibraryResource();
704 UMACleanupToolbox() ;
705 if (s_macCursorRgn
) {
706 ::DisposeRgn((RgnHandle
)s_macCursorRgn
);
713 wxAppBase::CleanUp();
716 //----------------------------------------------------------------------
717 // misc initialization stuff
718 //----------------------------------------------------------------------
720 // extern variable for shared library resource id
721 // need to be able to find it with NSLookupAndBindSymbol
722 short gSharedLibraryResource
= kResFileNotOpened
;
724 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
725 CFBundleRef gSharedLibraryBundle
= NULL
;
726 #endif /* WXMAKINGDLL_CORE && __DARWIN__ */
728 wxStAppResource::wxStAppResource()
730 m_currentRefNum
= CurResFile() ;
731 if ( gSharedLibraryResource
!= kResFileNotOpened
)
733 UseResFile( gSharedLibraryResource
) ;
737 wxStAppResource::~wxStAppResource()
739 if ( m_currentRefNum
!= kResFileNotOpened
)
741 UseResFile( m_currentRefNum
) ;
745 void wxStAppResource::OpenSharedLibraryResource(const void *initBlock
)
747 gSharedLibraryResource
= kResFileNotOpened
;
749 #ifdef WXMAKINGDLL_CORE
750 if ( initBlock
!= NULL
) {
751 const CFragInitBlock
*theInitBlock
= (const CFragInitBlock
*)initBlock
;
752 FSSpec
*fileSpec
= NULL
;
754 if (theInitBlock
->fragLocator
.where
== kDataForkCFragLocator
) {
755 fileSpec
= theInitBlock
->fragLocator
.u
.onDisk
.fileSpec
;
757 else if (theInitBlock
->fragLocator
.where
== kResourceCFragLocator
) {
758 fileSpec
= theInitBlock
->fragLocator
.u
.inSegs
.fileSpec
;
761 if (fileSpec
!= NULL
) {
762 gSharedLibraryResource
= FSpOpenResFile(fileSpec
, fsRdPerm
);
767 // Open the shared library resource file if it is not yet open
770 const char *theLibPath
;
772 gSharedLibraryBundle
= CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWindows"));
773 if (gSharedLibraryBundle
!= NULL
) {
774 // wxWindows has been bundled into a framework
775 // load the framework resources
777 gSharedLibraryResource
= CFBundleOpenBundleResourceMap(gSharedLibraryBundle
);
780 // wxWindows is a simple dynamic shared library
781 // load the resources from the data fork of a separate resource file
785 OSErr theErr
= noErr
;
787 // get the library path
788 theSymbol
= NSLookupAndBindSymbol("_gSharedLibraryResource");
789 theModule
= NSModuleForSymbol(theSymbol
);
790 theLibPath
= NSLibraryNameForModule(theModule
);
792 // if we call wxLogDebug from here then, as wxTheApp hasn't been
793 // created yet when we're called from wxApp::Initialize(), wxLog
794 // is going to create a default stderr-based log target instead of
795 // the expected normal GUI one -- don't do it, if we really want
796 // to see this message just use fprintf() here
798 wxLogDebug( wxT("wxMac library installation name is '%s'"),
802 // allocate copy to replace .dylib.* extension with .rsrc
803 if (theLibPath
!= NULL
) {
804 theResPath
= theLibPath
;
805 // replace '_core' with '' in case of multi-lib build
806 theResPath
.Replace(wxT("_core"), wxEmptyString
);
807 // replace ".dylib" shared library extension with ".rsrc"
808 theResPath
.Replace(wxT(".dylib"), wxT(".rsrc"));
809 // Find the begining of the filename
810 theName
= theResPath
.AfterLast('/');
813 wxLogDebug( wxT("wxMac resources file name is '%s'"),
814 theResPath
.mb_str() );
817 theErr
= FSPathMakeRef((UInt8
*) theResPath
.mb_str(), &theResRef
, false);
818 if (theErr
!= noErr
) {
819 // try in current directory (using name only)
820 theErr
= FSPathMakeRef((UInt8
*) theName
.mb_str(), &theResRef
, false);
823 // open the resource file
824 if (theErr
== noErr
) {
825 theErr
= FSOpenResourceFile( &theResRef
, 0, NULL
, fsRdPerm
,
826 &gSharedLibraryResource
);
828 if (theErr
!= noErr
) {
831 wxT("unable to open wxMac resource file '%s'\n"),
832 theResPath
.mb_str() );
833 #endif // __WXDEBUG__
838 #endif /* __DARWIN__ */
840 #endif /* WXMAKINGDLL_CORE */
843 void wxStAppResource::CloseSharedLibraryResource()
845 #ifdef WXMAKINGDLL_CORE
846 // Close the shared library resource file
847 if (gSharedLibraryResource
!= kResFileNotOpened
) {
849 if (gSharedLibraryBundle
!= NULL
) {
850 CFBundleCloseBundleResourceMap(gSharedLibraryBundle
,
851 gSharedLibraryResource
);
852 gSharedLibraryBundle
= NULL
;
855 #endif /* __DARWIN__ */
857 CloseResFile(gSharedLibraryResource
);
859 gSharedLibraryResource
= kResFileNotOpened
;
861 #endif /* WXMAKINGDLL_CORE */
864 #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
866 // for shared libraries we have to manually get the correct resource
867 // ref num upon initializing and releasing when terminating, therefore
868 // the __wxinitialize and __wxterminate must be used
871 void __sinit(void); /* (generated by linker) */
872 pascal OSErr
__initialize(const CFragInitBlock
*theInitBlock
);
873 pascal void __terminate(void);
876 pascal OSErr
__wxinitialize(const CFragInitBlock
*theInitBlock
)
878 wxStAppResource::OpenSharedLibraryResource( theInitBlock
) ;
879 return __initialize( theInitBlock
) ;
882 pascal void __wxterminate(void)
884 wxStAppResource::CloseSharedLibraryResource() ;
888 #endif /* WXMAKINGDLL_CORE && !__DARWIN__ */
892 bool wxMacConvertEventToRecord( EventRef event
, EventRecord
*rec
)
894 bool converted
= ConvertEventRefToEventRecord( event
,rec
) ;
895 OSStatus err
= noErr
;
898 switch( GetEventClass( event
) )
900 case kEventClassKeyboard
:
903 switch( GetEventKind(event
) )
905 case kEventRawKeyDown
:
906 rec
->what
= keyDown
;
908 case kEventRawKeyRepeat
:
909 rec
->what
= autoKey
;
911 case kEventRawKeyUp
:
914 case kEventRawKeyModifiersChanged
:
915 rec
->what
= nullEvent
;
924 unsigned char charCode
;
926 GetMouse( &rec
->where
) ;
928 err
= GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
929 err
= GetEventParameter(event
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
930 err
= GetEventParameter(event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
931 rec
->modifiers
= modifiers
;
932 rec
->message
= (keyCode
<< 8 ) + charCode
;
936 case kEventClassTextInput
:
938 switch( GetEventKind( event
) )
940 case kEventTextInputUnicodeForKeyEvent
:
943 err
= GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent
) ;
947 unsigned char charCode
;
949 GetMouse( &rec
->where
) ;
950 rec
->what
= keyDown
;
951 err
= GetEventParameter(rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
952 err
= GetEventParameter(rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
953 err
= GetEventParameter(rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
954 rec
->modifiers
= modifiers
;
955 rec
->message
= (keyCode
<< 8 ) + charCode
;
971 pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
973 OSStatus result = eventNotHandledErr ;
976 switch ( GetEventClass( event ) )
978 case kEventClassKeyboard :
979 if ( wxMacConvertEventToRecord( event , &rec ) )
981 wxTheApp->MacHandleModifierEvents( &rec ) ;
982 wxTheApp->MacHandleOneEvent( &rec ) ;
986 case kEventClassTextInput :
987 if ( wxMacConvertEventToRecord( event , &rec ) )
989 wxTheApp->MacHandleModifierEvents( &rec ) ;
990 wxTheApp->MacHandleOneEvent( &rec ) ;
1004 m_printMode
= wxPRINT_WINDOWS
;
1007 m_macCurrentEvent
= NULL
;
1009 m_macCurrentEventHandlerCallRef
= NULL
;
1013 int wxApp::MainLoop()
1025 void wxApp::ExitMainLoop()
1027 m_keepGoing
= FALSE
;
1030 // Is a message/event pending?
1031 bool wxApp::Pending()
1034 return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ;
1038 return EventAvail( everyEvent
, &event
) ;
1042 // Dispatch a message.
1043 bool wxApp::Dispatch()
1050 void wxApp::OnIdle(wxIdleEvent
& event
)
1052 wxAppBase::OnIdle(event
);
1054 // If they are pending events, we must process them: pending events are
1055 // either events to the threads other than main or events posted with
1056 // wxPostEvent() functions
1057 wxMacProcessNotifierAndPendingEvents();
1059 if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
1060 wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
1063 void wxApp::WakeUpIdle()
1074 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
1077 GetTopWindow()->Close(TRUE
);
1080 // Default behaviour: close the application with prompts. The
1081 // user can veto the close, and therefore the end session.
1082 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
1086 if (!GetTopWindow()->Close(!event
.CanVeto()))
1091 extern "C" void wxCYield() ;
1097 // Yield to other processes
1099 bool wxApp::Yield(bool onlyIfNeeded
)
1103 if ( !onlyIfNeeded
)
1105 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1114 YieldToAnyThread() ;
1116 // by definition yield should handle all non-processed events
1120 OSStatus status
= noErr
;
1123 s_inReceiveEvent
= true ;
1124 status
= ReceiveNextEvent(0, NULL
,kEventDurationNoWait
,true,&theEvent
) ;
1125 s_inReceiveEvent
= false ;
1127 if ( status
== eventLoopTimedOutErr
)
1129 // make sure next time the event loop will trigger idle events
1130 sleepTime
= kEventDurationNoWait
;
1132 else if ( status
== eventLoopQuitErr
)
1134 // according to QA1061 this may also occur when a WakeUp Process
1139 MacHandleOneEvent( theEvent
) ;
1140 ReleaseEvent(theEvent
);
1142 } while( status
== noErr
) ;
1146 // having a larger value here leads to large performance slowdowns
1147 // so we cannot give background apps more processor time here
1148 // we do so however having a large sleep value in the main event loop
1151 while ( !IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, (RgnHandle
) wxApp::s_macCursorRgn
))
1153 MacHandleModifierEvents( &event
) ;
1154 MacHandleOneEvent( &event
);
1155 if ( event
.what
!= kHighLevelEvent
)
1156 SetRectRgn( (RgnHandle
) wxApp::s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1158 MacHandleModifierEvents( &event
) ;
1161 wxMacProcessNotifierAndPendingEvents() ;
1167 // platform specifics
1169 void wxApp::MacSuspend( bool convertClipboard
)
1172 // we have to deactive the top level windows manually
1174 wxWindowListNode
* node
= wxTopLevelWindows
.GetFirst();
1177 wxTopLevelWindow
* win
= (wxTopLevelWindow
*) node
->Data();
1179 #if 0 // having problems right now with that
1180 if (!win
->HasFlag(wxSTAY_ON_TOP
))
1183 win
->MacActivate( ((EventRecord
*) MacGetCurrentEvent())->when
, false ) ;
1185 node
= node
->GetNext();
1188 ::HideFloatingWindows() ;
1190 s_lastMouseDown
= 0 ;
1192 if( convertClipboard
)
1194 MacConvertPrivateToPublicScrap() ;
1198 extern wxList wxModalDialogs
;
1200 void wxApp::MacResume( bool convertClipboard
)
1202 s_lastMouseDown
= 0 ;
1203 if( convertClipboard
)
1205 MacConvertPublicToPrivateScrap() ;
1209 ::ShowFloatingWindows() ;
1210 // raise modal dialogs in case a non modal window was selected to activate the app
1212 wxNode
* node
= wxModalDialogs
.GetFirst();
1215 wxDialog
* dialog
= (wxDialog
*) node
->GetData();
1218 node
= node
->GetNext();
1223 void wxApp::MacConvertPrivateToPublicScrap()
1227 void wxApp::MacConvertPublicToPrivateScrap()
1231 void wxApp::MacDoOneEvent()
1236 s_inReceiveEvent
= true ;
1237 OSStatus status
= ReceiveNextEvent(0, NULL
,sleepTime
,true,&theEvent
) ;
1238 s_inReceiveEvent
= false ;
1239 if ( status
== eventLoopTimedOutErr
)
1241 if ( wxTheApp
->ProcessIdle() )
1242 sleepTime
= kEventDurationNoWait
;
1244 sleepTime
= kEventDurationForever
;
1246 else if ( status
== eventLoopQuitErr
)
1248 // according to QA1061 this may also occur when a WakeUp Process
1253 MacHandleOneEvent( theEvent
) ;
1254 ReleaseEvent(theEvent
);
1255 sleepTime
= kEventDurationNoWait
;
1260 EventMask eventMask
= everyEvent
;
1262 if (WaitNextEvent(eventMask
, &event
, sleepTime
, (RgnHandle
) s_macCursorRgn
))
1264 MacHandleModifierEvents( &event
) ;
1265 MacHandleOneEvent( &event
);
1269 MacHandleModifierEvents( &event
) ;
1271 WindowPtr window
= ::FrontWindow() ;
1273 ::IdleControls( window
) ;
1275 if ( wxTheApp
->ProcessIdle() )
1278 sleepTime
= GetCaretTime() / 2 ;
1280 if ( event
.what
!= kHighLevelEvent
)
1281 SetRectRgn( (RgnHandle
) s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1285 DeletePendingObjects() ;
1286 wxMacProcessNotifierAndPendingEvents() ;
1289 void wxApp::MacHandleOneEvent( WXEVENTREF evr
)
1292 EventTargetRef theTarget
;
1293 theTarget
= GetEventDispatcherTarget();
1294 m_macCurrentEvent
= evr
;
1295 SendEventToEventTarget ((EventRef
) evr
, theTarget
);
1297 EventRecord
* ev
= (EventRecord
*) evr
;
1298 m_macCurrentEvent
= ev
;
1300 wxApp::sm_lastMessageTime
= ev
->when
;
1305 MacHandleMouseDownEvent( ev
) ;
1306 if ( ev
->modifiers
& controlKey
)
1307 s_lastMouseDown
= 2;
1309 s_lastMouseDown
= 1;
1312 if ( s_lastMouseDown
== 2 )
1314 ev
->modifiers
|= controlKey
;
1318 ev
->modifiers
&= ~controlKey
;
1320 MacHandleMouseUpEvent( ev
) ;
1321 s_lastMouseDown
= 0;
1324 MacHandleActivateEvent( ev
) ;
1327 MacHandleUpdateEvent( ev
) ;
1331 MacHandleKeyDownEvent( ev
) ;
1334 MacHandleKeyUpEvent( ev
) ;
1337 MacHandleDiskEvent( ev
) ;
1340 MacHandleOSEvent( ev
) ;
1342 case kHighLevelEvent
:
1343 MacHandleHighLevelEvent( ev
) ;
1349 wxMacProcessNotifierAndPendingEvents() ;
1353 bool s_macIsInModalLoop
= false ;
1355 void wxApp::MacHandleModifierEvents( WXEVENTREF evr
)
1357 EventRecord
* ev
= (EventRecord
*) evr
;
1358 if ( ev
->modifiers
!= s_lastModifiers
&& wxWindow::FindFocus() != NULL
)
1360 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1362 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1363 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1364 event
.m_altDown
= ev
->modifiers
& optionKey
;
1365 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1367 event
.m_x
= ev
->where
.h
;
1368 event
.m_y
= ev
->where
.v
;
1369 event
.m_timeStamp
= ev
->when
;
1370 wxWindow
* focus
= wxWindow::FindFocus() ;
1371 event
.SetEventObject(focus
);
1373 if ( (ev
->modifiers
^ s_lastModifiers
) & controlKey
)
1375 event
.m_keyCode
= WXK_CONTROL
;
1376 event
.SetEventType( ( ev
->modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1377 focus
->GetEventHandler()->ProcessEvent( event
) ;
1379 if ( (ev
->modifiers
^ s_lastModifiers
) & shiftKey
)
1381 event
.m_keyCode
= WXK_SHIFT
;
1382 event
.SetEventType( ( ev
->modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1383 focus
->GetEventHandler()->ProcessEvent( event
) ;
1385 if ( (ev
->modifiers
^ s_lastModifiers
) & optionKey
)
1387 event
.m_keyCode
= WXK_ALT
;
1388 event
.SetEventType( ( ev
->modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1389 focus
->GetEventHandler()->ProcessEvent( event
) ;
1391 if ( ( ev
->modifiers
^ s_lastModifiers
) & cmdKey
)
1393 event
.m_keyCode
= WXK_COMMAND
;
1394 event
.SetEventType( ( ev
->modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1395 focus
->GetEventHandler()->ProcessEvent( event
) ;
1397 s_lastModifiers
= ev
->modifiers
;
1401 void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr
)
1403 // we must avoid reentrancy problems when processing high level events eg printing
1404 bool former
= s_inYield
;
1406 EventRecord
* ev
= (EventRecord
*) evr
;
1407 ::AEProcessAppleEvent( ev
) ;
1408 s_inYield
= former
;
1411 void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr
)
1413 EventRecord
* ev
= (EventRecord
*) evr
;
1414 wxToolTip::RemoveToolTips() ;
1417 WindowRef frontWindow
= ::FrontNonFloatingWindow() ;
1418 WindowAttributes frontWindowAttributes
= NULL
;
1420 ::GetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
1422 short windowPart
= ::FindWindow(ev
->where
, &window
);
1423 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1424 if ( wxPendingDelete
.Member(win
) )
1428 GetQDGlobalsScreenBits( &screenBits
);
1433 if ( s_macIsInModalLoop
)
1439 UInt32 menuresult
= MenuSelect(ev
->where
) ;
1440 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1441 s_lastMouseDown
= 0;
1445 SystemClick( ev
, window
) ;
1446 s_lastMouseDown
= 0;
1449 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1455 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1460 Point pt
= { 0, 0 } ;
1461 SetPortWindowPort(window
) ;
1462 LocalToGlobal( &pt
) ;
1464 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1465 -1 , wxSIZE_USE_EXISTING
);
1467 s_lastMouseDown
= 0;
1471 if (TrackGoAway(window
, ev
->where
))
1476 s_lastMouseDown
= 0;
1480 Rect newContentRect
;
1481 Rect constraintRect
;
1482 constraintRect
.top
= win
->GetMinHeight() ;
1483 if ( constraintRect
.top
== -1 )
1484 constraintRect
.top
= 0 ;
1485 constraintRect
.left
= win
->GetMinWidth() ;
1486 if ( constraintRect
.left
== -1 )
1487 constraintRect
.left
= 0 ;
1488 constraintRect
.right
= win
->GetMaxWidth() ;
1489 if ( constraintRect
.right
== -1 )
1490 constraintRect
.right
= 32000 ;
1491 constraintRect
.bottom
= win
->GetMaxHeight() ;
1492 if ( constraintRect
.bottom
== -1 )
1493 constraintRect
.bottom
= 32000 ;
1495 Boolean growResult
= ResizeWindow( window
, ev
->where
,
1496 &constraintRect
, &newContentRect
) ;
1499 win
->SetSize( newContentRect
.left
, newContentRect
.top
,
1500 newContentRect
.right
- newContentRect
.left
,
1501 newContentRect
.bottom
- newContentRect
.top
, wxSIZE_USE_EXISTING
);
1503 s_lastMouseDown
= 0;
1508 if (TrackBox(window
, ev
->where
, windowPart
))
1510 // TODO setup size event
1511 ZoomWindow( window
, windowPart
, false ) ;
1517 Point pt
= { 0, 0 } ;
1518 SetPortWindowPort(window
) ;
1519 LocalToGlobal( &pt
) ;
1522 GetWindowPortBounds(window
, &tempRect
) ;
1523 win
->SetSize( pt
.h
, pt
.v
, tempRect
.right
-tempRect
.left
,
1524 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1527 s_lastMouseDown
= 0;
1529 case inCollapseBox
:
1530 // TODO setup size event
1531 s_lastMouseDown
= 0;
1538 SetPortWindowPort(window
) ;
1541 if ( window
!= frontWindow
&& wxTheApp
->s_captureWindow
== NULL
)
1543 if ( s_macIsInModalLoop
)
1547 else if ( UMAIsWindowFloating( window
) )
1550 win
->MacMouseDown( ev
, windowPart
) ;
1554 // Activate window first
1555 ::SelectWindow( window
) ;
1559 win
->MacMouseDown( ev
, windowPart
) ;
1565 win
->MacMouseDown( ev
, windowPart
) ;
1573 void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr
)
1575 EventRecord
* ev
= (EventRecord
*) evr
;
1578 short windowPart
= inNoWindow
;
1579 if ( wxTheApp
->s_captureWindow
)
1581 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
1582 windowPart
= inContent
;
1586 windowPart
= ::FindWindow(ev
->where
, &window
) ;
1597 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1599 win
->MacMouseUp( ev
, windowPart
) ;
1607 long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
1608 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1613 case kHomeCharCode
:
1616 case kEnterCharCode
:
1617 retval
= WXK_RETURN
;
1622 case kHelpCharCode
:
1625 case kBackspaceCharCode
:
1631 case kPageUpCharCode
:
1632 retval
= WXK_PAGEUP
;
1634 case kPageDownCharCode
:
1635 retval
= WXK_PAGEDOWN
;
1637 case kReturnCharCode
:
1638 retval
= WXK_RETURN
;
1640 case kFunctionKeyCharCode
:
1692 case kEscapeCharCode
:
1693 retval
= WXK_ESCAPE
;
1695 case kLeftArrowCharCode
:
1698 case kRightArrowCharCode
:
1699 retval
= WXK_RIGHT
;
1701 case kUpArrowCharCode
:
1704 case kDownArrowCharCode
:
1707 case kDeleteCharCode
:
1708 retval
= WXK_DELETE
;
1717 void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr
)
1719 EventRecord
* ev
= (EventRecord
*) evr
;
1720 wxToolTip::RemoveToolTips() ;
1722 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1723 if ( HiWord( menuresult
) )
1725 if ( !s_macIsInModalLoop
)
1726 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1730 wxWindow
* focus
= wxWindow::FindFocus() ;
1732 if ( MacSendKeyDownEvent( focus
, ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) == false )
1735 // we must handle control keys the other way round, otherwise text content is updated too late
1736 // has not been handled -> perform default
1737 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
1738 if ( control
&& control
->GetMacControl() != NULL
)
1742 keychar
= short(ev
->message
& charCodeMask
);
1743 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1744 ::HandleControlKey( (ControlHandle
) control
->GetMacControl() , keycode
, keychar
, ev
->modifiers
) ;
1751 void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr
)
1753 EventRecord
* ev
= (EventRecord
*) evr
;
1754 wxToolTip::RemoveToolTips() ;
1756 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1757 if ( HiWord( menuresult
) )
1762 MacSendKeyUpEvent( wxWindow::FindFocus() , ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) ;
1768 bool wxApp::MacSendKeyDownEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
)
1775 keychar
= short(keymessage
& charCodeMask
);
1776 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
1778 if ( modifiers
& ( controlKey
|shiftKey
|optionKey
) )
1780 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1781 // and look at the character after
1783 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
);
1784 keychar
= short(keyInfo
& charCodeMask
);
1785 keycode
= short(keyInfo
& keyCodeMask
) >> 8 ;
1787 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1788 long realkeyval
= keyval
;
1789 if ( keyval
== keychar
)
1791 // we are not on a special character combo -> pass the real os event-value to EVT_CHAR, but not to EVT_KEY (make upper first)
1792 realkeyval
= short(keymessage
& charCodeMask
) ;
1793 keyval
= wxToupper( keyval
) ;
1796 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1797 bool handled
= false ;
1798 event
.m_shiftDown
= modifiers
& shiftKey
;
1799 event
.m_controlDown
= modifiers
& controlKey
;
1800 event
.m_altDown
= modifiers
& optionKey
;
1801 event
.m_metaDown
= modifiers
& cmdKey
;
1802 event
.m_keyCode
= keyval
;
1806 event
.m_timeStamp
= when
;
1807 event
.SetEventObject(focus
);
1808 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1809 if ( handled
&& event
.GetSkipped() )
1816 wxWindow
*ancestor
= focus
;
1819 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1822 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1823 handled
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1826 if (ancestor
->IsTopLevel())
1828 ancestor
= ancestor
->GetParent();
1831 #endif // wxUSE_ACCEL
1835 event
.Skip( FALSE
) ;
1836 event
.SetEventType( wxEVT_CHAR
) ;
1838 event
.m_keyCode
= realkeyval
;
1840 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1841 if ( handled
&& event
.GetSkipped() )
1845 (keyval
== WXK_TAB
) &&
1846 // CS: copied the change below from wxGTK
1847 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
1848 // have this style, yet choose not to process this particular TAB in which
1849 // case TAB must still work as a navigational character
1851 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1853 (focus
->GetParent()) &&
1854 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1856 wxNavigationKeyEvent new_event
;
1857 new_event
.SetEventObject( focus
);
1858 new_event
.SetDirection( !event
.ShiftDown() );
1859 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1860 new_event
.SetWindowChange( event
.ControlDown() );
1861 new_event
.SetCurrentFocus( focus
);
1862 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1863 if ( handled
&& new_event
.GetSkipped() )
1866 // backdoor handler for default return and command escape
1867 if ( !handled
&& (!focus
->IsKindOf(CLASSINFO(wxControl
) ) || !focus
->MacCanFocus() ) )
1869 // if window is not having a focus still testing for default enter or cancel
1870 // TODO add the UMA version for ActiveNonFloatingWindow
1871 wxWindow
* focus
= wxFindWinFromMacWindow( FrontWindow() ) ;
1874 if ( keyval
== WXK_RETURN
)
1876 wxButton
*def
= wxDynamicCast(focus
->GetDefaultItem(),
1878 if ( def
&& def
->IsEnabled() )
1880 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
1881 event
.SetEventObject(def
);
1882 def
->Command(event
);
1886 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1887 else if (keyval
== WXK_ESCAPE
|| (keyval
== '.' && modifiers
& cmdKey
) )
1889 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1890 new_event
.SetEventObject( focus
);
1891 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1898 bool wxApp::MacSendKeyUpEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
)
1905 keychar
= short(keymessage
& charCodeMask
);
1906 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
1907 if ( modifiers
& ( controlKey
|shiftKey
|optionKey
) )
1909 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1910 // and look at the character after
1912 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
);
1913 keychar
= short(keyInfo
& charCodeMask
);
1914 keycode
= short(keyInfo
& keyCodeMask
) >> 8 ;
1916 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1918 if ( keyval
== keychar
)
1920 keyval
= wxToupper( keyval
) ;
1922 bool handled
= false ;
1924 wxKeyEvent
event(wxEVT_KEY_UP
);
1925 event
.m_shiftDown
= modifiers
& shiftKey
;
1926 event
.m_controlDown
= modifiers
& controlKey
;
1927 event
.m_altDown
= modifiers
& optionKey
;
1928 event
.m_metaDown
= modifiers
& cmdKey
;
1929 event
.m_keyCode
= keyval
;
1933 event
.m_timeStamp
= when
;
1934 event
.SetEventObject(focus
);
1935 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1941 void wxApp::MacHandleActivateEvent( WXEVENTREF evr
)
1943 EventRecord
* ev
= (EventRecord
*) evr
;
1944 WindowRef window
= (WindowRef
) ev
->message
;
1947 bool activate
= (ev
->modifiers
& activeFlag
) ;
1948 WindowClass wclass
;
1949 ::GetWindowClass ( window
, &wclass
) ;
1950 if ( wclass
== kFloatingWindowClass
)
1952 // if it is a floater we activate/deactivate the front non-floating window instead
1953 window
= ::FrontNonFloatingWindow() ;
1955 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1957 win
->MacActivate( ev
->when
, activate
) ;
1961 void wxApp::MacHandleUpdateEvent( WXEVENTREF evr
)
1963 EventRecord
* ev
= (EventRecord
*) evr
;
1964 WindowRef window
= (WindowRef
) ev
->message
;
1965 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1968 if ( !wxPendingDelete
.Member(win
) )
1969 win
->MacUpdate( ev
->when
) ;
1973 // since there is no way of telling this foreign window to update itself
1974 // we have to invalidate the update region otherwise we keep getting the same
1975 // event over and over again
1976 BeginUpdate( window
) ;
1977 EndUpdate( window
) ;
1981 void wxApp::MacHandleDiskEvent( WXEVENTREF evr
)
1983 EventRecord
* ev
= (EventRecord
*) evr
;
1984 if ( HiWord( ev
->message
) != noErr
)
1988 SetPt( &point
, 100 , 100 ) ;
1990 err
= DIBadMount( point
, ev
->message
) ;
1991 wxASSERT( err
== noErr
) ;
1995 void wxApp::MacHandleOSEvent( WXEVENTREF evr
)
1997 EventRecord
* ev
= (EventRecord
*) evr
;
1998 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
2000 case suspendResumeMessage
:
2002 bool isResuming
= ev
->message
& resumeFlag
;
2003 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
2005 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
2008 WindowRef oldFrontWindow
= NULL
;
2009 WindowRef newFrontWindow
= NULL
;
2011 // in case we don't take care of activating ourselves, we have to synchronize
2012 // our idea of the active window with the process manager's - which it already activated
2014 if ( !doesActivate
)
2015 oldFrontWindow
= ::FrontNonFloatingWindow() ;
2017 MacResume( convertClipboard
) ;
2019 newFrontWindow
= ::FrontNonFloatingWindow() ;
2021 if ( oldFrontWindow
)
2023 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
2025 win
->MacActivate( ev
->when
, false ) ;
2027 if ( newFrontWindow
)
2029 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
2031 win
->MacActivate( ev
->when
, true ) ;
2036 MacSuspend( convertClipboard
) ;
2040 case mouseMovedMessage
:
2044 wxWindow
* currentMouseWindow
= NULL
;
2046 if (s_captureWindow
)
2048 currentMouseWindow
= s_captureWindow
;
2052 wxWindow::MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) ,
2053 ¤tMouseWindow
) ;
2056 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
2058 wxMouseEvent event
;
2060 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
2061 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
2063 event
.m_leftDown
= isDown
&& !controlDown
;
2064 event
.m_middleDown
= FALSE
;
2065 event
.m_rightDown
= isDown
&& controlDown
;
2066 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
2067 event
.m_controlDown
= ev
->modifiers
& controlKey
;
2068 event
.m_altDown
= ev
->modifiers
& optionKey
;
2069 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
2070 event
.m_x
= ev
->where
.h
;
2071 event
.m_y
= ev
->where
.v
;
2072 event
.m_timeStamp
= ev
->when
;
2073 event
.SetEventObject(this);
2075 if ( wxWindow::s_lastMouseWindow
)
2077 wxMouseEvent
eventleave(event
);
2078 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
2079 wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
2080 eventleave
.SetEventObject( wxWindow::s_lastMouseWindow
) ;
2082 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
2084 if ( currentMouseWindow
)
2086 wxMouseEvent
evententer(event
);
2087 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
2088 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
2089 evententer
.SetEventObject( currentMouseWindow
) ;
2090 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
2092 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
2095 short windowPart
= inNoWindow
;
2097 if ( s_captureWindow
)
2099 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
2100 windowPart
= inContent
;
2104 windowPart
= ::FindWindow(ev
->where
, &window
);
2111 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2113 win
->MacMouseMoved( ev
, windowPart
) ;
2120 UMAShowArrowCursor();
2130 UMAShowArrowCursor();
2141 void wxApp::MacHandleMouseMovedEvent(wxInt32 x
, wxInt32 y
,wxUint32 modifiers
, long timestamp
)
2145 wxWindow
* currentMouseWindow
= NULL
;
2147 if (s_captureWindow
)
2149 currentMouseWindow
= s_captureWindow
;
2153 wxWindow::MacGetWindowFromPoint( wxPoint( x
, y
) , ¤tMouseWindow
) ;
2156 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
2158 wxMouseEvent event
;
2160 bool isDown
= !(modifiers
& btnState
) ; // 1 is for up
2161 bool controlDown
= modifiers
& controlKey
; // for simulating right mouse
2163 event
.m_leftDown
= isDown
&& !controlDown
;
2165 event
.m_middleDown
= FALSE
;
2166 event
.m_rightDown
= isDown
&& controlDown
;
2168 event
.m_shiftDown
= modifiers
& shiftKey
;
2169 event
.m_controlDown
= modifiers
& controlKey
;
2170 event
.m_altDown
= modifiers
& optionKey
;
2171 event
.m_metaDown
= modifiers
& cmdKey
;
2175 event
.m_timeStamp
= timestamp
;
2177 if ( wxWindow::s_lastMouseWindow
)
2179 wxMouseEvent
eventleave(event
);
2180 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
2181 wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
2182 eventleave
.SetEventObject( wxWindow::s_lastMouseWindow
) ;
2185 wxToolTip::RelayEvent( wxWindow::s_lastMouseWindow
, eventleave
);
2186 #endif // wxUSE_TOOLTIPS
2187 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
2189 if ( currentMouseWindow
)
2191 wxMouseEvent
evententer(event
);
2192 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
2193 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
2194 evententer
.SetEventObject( currentMouseWindow
) ;
2196 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
2197 #endif // wxUSE_TOOLTIPS
2198 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
2200 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
2203 short windowPart
= inNoWindow
;
2205 if ( s_captureWindow
)
2207 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
2208 windowPart
= inContent
;
2212 Point pt
= { y
, x
} ;
2213 windowPart
= ::FindWindow(pt
, &window
);
2220 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2222 win
->MacFireMouseEvent( nullEvent
, x
, y
, modifiers
, timestamp
) ;
2229 UMAShowArrowCursor();
2239 UMAShowArrowCursor();
2246 void wxApp::MacHandleMenuCommand( wxUint32 id
)
2248 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
2249 wxFrame
* frame
= mbar
->GetFrame();
2250 wxCHECK_RET( mbar
!= NULL
&& frame
!= NULL
, wxT("error in menu item callback") );
2253 frame
->ProcessCommand(id
);
2258 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
2261 return; // no menu item selected
2263 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
2266 Str255 deskAccessoryName
;
2269 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
2270 GetPort(&savedPort
);
2271 OpenDeskAcc(deskAccessoryName
);
2278 GetMenuItemCommandID( GetMenuHandle(macMenuId
) , macMenuItemNum
, &id
) ;
2279 MacHandleMenuCommand( id
) ;