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
;
72 extern size_t g_numberOfThreads
;
74 // statics for implementation
76 static bool s_inYield
= FALSE
;
79 static bool s_inReceiveEvent
= FALSE
;
80 static EventTime sleepTime
= kEventDurationNoWait
;
82 static long sleepTime
= 0 ;
85 #if !USE_SHARED_LIBRARY
86 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
87 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
88 EVT_IDLE(wxApp::OnIdle
)
89 EVT_END_SESSION(wxApp::OnEndSession
)
90 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
95 const short kMacMinHeap
= (29 * 1024) ;
96 // platform specific static variables
98 const short kwxMacMenuBarResource
= 1 ;
99 const short kwxMacAppleMenuId
= 1 ;
101 WXHRGN
wxApp::s_macCursorRgn
= NULL
;
102 wxWindow
* wxApp::s_captureWindow
= NULL
;
103 int wxApp::s_lastMouseDown
= 0 ;
104 long wxApp::sm_lastMessageTime
= 0;
105 long wxApp::s_lastModifiers
= 0 ;
108 bool wxApp::s_macSupportPCMenuShortcuts
= true ;
109 long wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
110 long wxApp::s_macPreferencesMenuItemId
= wxID_PREFERENCES
;
111 long wxApp::s_macExitMenuItemId
= wxID_EXIT
;
112 wxString
wxApp::s_macHelpMenuTitleName
= wxT("&Help") ;
114 // Normally we're not a plugin
115 bool wxApp::sm_isEmbedded
= false;
116 //----------------------------------------------------------------------
117 // Core Apple Event Support
118 //----------------------------------------------------------------------
120 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
121 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
122 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
123 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
125 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
127 return wxTheApp
->MacHandleAEODoc( (AppleEvent
*) event
, reply
) ;
130 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
132 return wxTheApp
->MacHandleAEOApp( (AppleEvent
*) event
, reply
) ;
135 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
137 return wxTheApp
->MacHandleAEPDoc( (AppleEvent
*) event
, reply
) ;
140 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
142 return wxTheApp
->MacHandleAEQuit( (AppleEvent
*) event
, reply
) ;
145 // AEODoc Calls MacOpenFile on each of the files passed
147 short wxApp::MacHandleAEODoc(const WXEVENTREF event
, WXEVENTREF
WXUNUSED(reply
))
151 DescType returnedType
;
157 err
= AEGetParamDesc((AppleEvent
*)event
, keyDirectObject
, typeAEList
,&docList
);
161 err
= AECountItems(&docList
, &itemsInList
);
165 ProcessSerialNumber PSN
;
166 PSN
.highLongOfPSN
= 0 ;
167 PSN
.lowLongOfPSN
= kCurrentProcess
;
168 SetFrontProcess( &PSN
) ;
170 for (i
= 1; i
<= itemsInList
; i
++) {
171 AEGetNthPtr(&docList
, i
, typeFSS
, &keywd
, &returnedType
,
172 (Ptr
) & theSpec
, sizeof(theSpec
), &actualSize
);
173 wxString fName
= wxMacFSSpec2MacFilename(&theSpec
);
179 // AEPDoc Calls MacPrintFile on each of the files passed
181 short wxApp::MacHandleAEPDoc(const WXEVENTREF event
, WXEVENTREF
WXUNUSED(reply
))
185 DescType returnedType
;
191 err
= AEGetParamDesc((AppleEvent
*)event
, keyDirectObject
, typeAEList
,&docList
);
195 err
= AECountItems(&docList
, &itemsInList
);
199 ProcessSerialNumber PSN
;
200 PSN
.highLongOfPSN
= 0 ;
201 PSN
.lowLongOfPSN
= kCurrentProcess
;
202 SetFrontProcess( &PSN
) ;
204 for (i
= 1; i
<= itemsInList
; i
++) {
205 AEGetNthPtr(&docList
, i
, typeFSS
, &keywd
, &returnedType
,
206 (Ptr
) & theSpec
, sizeof(theSpec
), &actualSize
);
207 wxString fName
= wxMacFSSpec2MacFilename(&theSpec
);
213 // AEOApp calls MacNewFile
215 short wxApp::MacHandleAEOApp(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
221 // AEQuit attempts to quit the application
223 short wxApp::MacHandleAEQuit(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
225 wxWindow
* win
= GetTopWindow() ;
237 //----------------------------------------------------------------------
238 // Support Routines linking the Mac...File Calls to the Document Manager
239 //----------------------------------------------------------------------
241 void wxApp::MacOpenFile(const wxString
& fileName
)
243 wxDocManager
* dm
= wxDocManager::GetDocumentManager() ;
245 dm
->CreateDocument(fileName
, wxDOC_SILENT
) ;
248 void wxApp::MacPrintFile(const wxString
& fileName
)
250 wxDocManager
* dm
= wxDocManager::GetDocumentManager() ;
253 wxDocument
*doc
= dm
->CreateDocument(fileName
, wxDOC_SILENT
) ;
256 wxView
* view
= doc
->GetFirstView() ;
259 wxPrintout
*printout
= view
->OnCreatePrintout();
263 printer
.Print(view
->GetFrame(), printout
, TRUE
);
269 doc
->DeleteAllViews();
270 dm
->RemoveDocument(doc
) ;
276 void wxApp::MacNewFile()
280 //----------------------------------------------------------------------
281 // Carbon Event Handler
282 //----------------------------------------------------------------------
286 static const EventTypeSpec eventList
[] =
288 { kEventClassCommand
, kEventProcessCommand
} ,
289 { kEventClassCommand
, kEventCommandUpdateStatus
} ,
291 { kEventClassMenu
, kEventMenuOpening
},
292 { kEventClassMenu
, kEventMenuClosed
},
293 { kEventClassMenu
, kEventMenuTargetItem
},
295 { kEventClassApplication
, kEventAppActivated
} ,
296 { kEventClassApplication
, kEventAppDeactivated
} ,
297 // handling the quit event is not recommended by apple
298 // rather using the quit apple event - which we do
300 { kEventClassAppleEvent
, kEventAppleEvent
} ,
302 { kEventClassMouse
, kEventMouseDown
} ,
303 { kEventClassMouse
, kEventMouseMoved
} ,
304 { kEventClassMouse
, kEventMouseUp
} ,
305 { kEventClassMouse
, kEventMouseDragged
} ,
309 static pascal OSStatus
310 MenuEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
312 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar();
313 wxFrame
* win
= mbar
->GetFrame();
317 // VZ: we could find the menu from its handle here by examining all
318 // the menus in the menu bar recursively but knowing that neither
319 // wxMSW nor wxGTK do it why bother...
323 GetEventParameter(event
,
324 kEventParamDirectObject
,
326 sizeof(menuRef
), NULL
,
332 switch (GetEventKind(event
))
334 case kEventMenuOpening
:
335 type
= wxEVT_MENU_OPEN
;
337 case kEventMenuClosed
:
338 type
= wxEVT_MENU_CLOSE
;
340 case kEventMenuTargetItem
:
341 type
= wxEVT_MENU_HIGHLIGHT
;
342 GetEventParameter(event
, kEventParamMenuCommand
,
343 typeMenuCommand
, NULL
,
344 sizeof(cmd
), NULL
, &cmd
);
345 if (cmd
== 0) return eventNotHandledErr
;
348 wxFAIL_MSG(wxT("Unexpected menu event kind"));
352 wxMenuEvent
wxevent(type
, cmd
);
353 wxevent
.SetEventObject(win
);
355 (void)win
->GetEventHandler()->ProcessEvent(wxevent
);
358 return eventNotHandledErr
;
361 // due to the rather low-level event API of wxWindows, we cannot use RunApplicationEventLoop
362 // but have to use ReceiveNextEvent dealing with events manually, therefore we also have
363 // deal with clicks in the menu bar explicitely
365 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
367 static pascal OSStatus
MouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
369 OSStatus result
= eventNotHandledErr
;
372 UInt32 modifiers
= 0;
373 EventMouseButton button
= 0 ;
376 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
377 sizeof( Point
), NULL
, &point
);
378 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
379 sizeof( UInt32
), NULL
, &modifiers
);
380 GetEventParameter( event
, kEventParamMouseButton
, typeMouseButton
, NULL
,
381 sizeof( EventMouseButton
), NULL
, &button
);
382 GetEventParameter( event
, kEventParamClickCount
, typeUInt32
, NULL
,
383 sizeof( UInt32
), NULL
, &click
);
385 if ( button
== 0 || GetEventKind( event
) == kEventMouseUp
)
386 modifiers
+= btnState
;
389 switch( GetEventKind(event
) )
391 case kEventMouseDown
:
395 short windowPart
= ::FindWindow(point
, &window
);
397 if ( windowPart
== inMenuBar
)
399 MenuSelect( point
) ;
404 case kEventMouseDragged
:
407 if ( wxTheApp
->s_captureWindow
)
408 wxMacWindowEventHandler( handler
, event
, (void*) wxTheApp
->s_captureWindow
->MacGetTopLevelWindow() ) ;
411 case kEventMouseMoved
:
413 wxTheApp
->MacHandleMouseMovedEvent( point
.h
, point
.v
, modifiers
, EventTimeToTicks( GetEventTime( event
) ) ) ;
423 static pascal OSStatus
CommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
425 OSStatus result
= eventNotHandledErr
;
429 GetEventParameter( event
, kEventParamDirectObject
, typeHICommand
, NULL
,
430 sizeof( HICommand
), NULL
, &command
);
432 MenuCommand id
= command
.commandID
;
433 if ( id
== kHICommandPreferences
)
434 id
= wxApp::s_macPreferencesMenuItemId
;
436 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
437 wxMenu
* menu
= NULL
;
438 wxMenuItem
* item
= NULL
;
442 item
= mbar
->FindItem( id
, &menu
) ;
443 // it is not 100 % sure that an menu of id 0 is really ours, safety check
444 if ( id
== 0 && menu
!= NULL
&& menu
->GetHMenu() != command
.menu
.menuRef
)
451 if ( item
== NULL
|| menu
== NULL
|| mbar
== NULL
)
454 switch( GetEventKind( event
) )
456 case kEventProcessCommand
:
458 if (item
->IsCheckable())
460 item
->Check( !item
->IsChecked() ) ;
463 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
467 case kEventCommandUpdateStatus
:
468 // eventually trigger an updateui round
478 static pascal OSStatus
ApplicationEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
480 OSStatus result
= eventNotHandledErr
;
481 switch ( GetEventKind( event
) )
483 case kEventAppActivated
:
486 wxTheApp
->MacResume( true ) ;
490 case kEventAppDeactivated
:
493 wxTheApp
->MacSuspend( true ) ;
503 pascal OSStatus
wxAppEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
505 OSStatus result
= eventNotHandledErr
;
506 switch( GetEventClass( event
) )
508 case kEventClassCommand
:
509 result
= CommandEventHandler( handler
, event
, data
) ;
511 case kEventClassApplication
:
512 result
= ApplicationEventHandler( handler
, event
, data
) ;
514 case kEventClassMenu
:
515 result
= MenuEventHandler( handler
, event
, data
) ;
517 case kEventClassMouse
:
518 result
= MouseEventHandler( handler
, event
, data
) ;
520 case kEventClassAppleEvent
:
523 wxMacConvertEventToRecord( event
, &rec
) ;
524 result
= AEProcessAppleEvent( &rec
) ;
534 DEFINE_ONE_SHOT_HANDLER_GETTER( wxAppEventHandler
)
538 #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
539 // we know it's there ;-)
540 WXIMPORT
char std::__throws_bad_alloc
;
543 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
549 UMAInitToolbox( 4, sm_isEmbedded
) ;
550 SetEventMask( everyEvent
) ;
551 UMAShowWatchCursor() ;
553 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
554 // open shared library resources from here since we don't have
555 // __wxinitialize in Mach-O shared libraries
556 wxStAppResource::OpenSharedLibraryResource(NULL
);
560 // test the minimal configuration necessary
566 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
568 error
= kMacSTRWrongMachine
;
570 else if (theMachine
< gestaltMacPlus
)
572 error
= kMacSTRWrongMachine
;
574 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
576 error
= kMacSTROldSystem
;
578 else if ( theSystem
< 0x0860 )
580 error
= kMacSTROldSystem
;
582 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
584 error
= kMacSTRSmallSize
;
590 if ( !UMAHasAppearance() )
592 error = kMacSTRNoPre8Yet ;
598 // if we encountered any problems so far, give the error code and exit immediately
602 wxStAppResource resload
;
606 GetIndString(message
, 128, error
);
607 UMAShowArrowCursor() ;
608 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
609 itemHit
= Alert(128, nil
);
614 # if __option(profile)
615 ProfilerInit( collectDetailed
, bestTimeBase
, 40000 , 50 ) ;
620 // now avoid exceptions thrown for new (bad_alloc)
621 // FIXME CS for some changes outside wxMac does not compile anymore
623 std::__throws_bad_alloc
= 0 ;
628 s_macCursorRgn
= ::NewRgn() ;
630 // Mac OS X passes a process serial number command line argument when
631 // the application is launched from the Finder. This argument must be
632 // removed from the command line arguments before being handled by the
633 // application (otherwise applications would need to handle it)
636 static const wxChar
*ARG_PSN
= _T("-psn_");
637 if ( wxStrncmp(argv
[1], ARG_PSN
, wxStrlen(ARG_PSN
)) == 0 )
639 // remove this argument
641 memmove(argv
+ 1, argv
+ 2, argc
* sizeof(char *));
645 if ( !wxAppBase::Initialize(argc
, argv
) )
648 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
649 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
651 wxMacCreateNotifierTable() ;
653 UMAShowArrowCursor() ;
658 bool wxApp::OnInitGui()
660 if( !wxAppBase::OnInitGui() )
664 InstallStandardEventHandler( GetApplicationEventTarget() ) ;
668 InstallApplicationEventHandler(
669 GetwxAppEventHandlerUPP(),
670 GetEventTypeCount(eventList
), eventList
, wxTheApp
, (EventHandlerRef
*)&(wxTheApp
->m_macEventHandler
));
676 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
677 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
678 NewAEEventHandlerUPP(AEHandleODoc
) ,
680 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
681 NewAEEventHandlerUPP(AEHandleOApp
) ,
683 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
684 NewAEEventHandlerUPP(AEHandlePDoc
) ,
686 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
687 NewAEEventHandlerUPP(AEHandleQuit
) ,
690 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
691 NewAEEventHandlerProc(AEHandleODoc
) ,
693 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
694 NewAEEventHandlerProc(AEHandleOApp
) ,
696 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
697 NewAEEventHandlerProc(AEHandlePDoc
) ,
699 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
700 NewAEEventHandlerProc(AEHandleQuit
) ,
708 void wxApp::CleanUp()
710 wxToolTip::RemoveToolTips() ;
712 // One last chance for pending objects to be cleaned up
713 wxTheApp
->DeletePendingObjects();
715 wxMacDestroyNotifierTable() ;
717 delete wxWinMacWindowList
;
718 wxWinMacWindowList
= NULL
;
720 delete wxWinMacControlList
;
721 wxWinMacControlList
= NULL
;
724 # if __option(profile)
725 ProfilerDump( (StringPtr
)"\papp.prof" ) ;
730 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
731 // close shared library resources from here since we don't have
732 // __wxterminate in Mach-O shared libraries
733 wxStAppResource::CloseSharedLibraryResource();
736 UMACleanupToolbox() ;
737 if (s_macCursorRgn
) {
738 ::DisposeRgn((RgnHandle
)s_macCursorRgn
);
745 wxAppBase::CleanUp();
748 //----------------------------------------------------------------------
749 // misc initialization stuff
750 //----------------------------------------------------------------------
752 // extern variable for shared library resource id
753 // need to be able to find it with NSLookupAndBindSymbol
754 short gSharedLibraryResource
= kResFileNotOpened
;
756 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
757 CFBundleRef gSharedLibraryBundle
= NULL
;
758 #endif /* WXMAKINGDLL_CORE && __DARWIN__ */
760 wxStAppResource::wxStAppResource()
762 m_currentRefNum
= CurResFile() ;
763 if ( gSharedLibraryResource
!= kResFileNotOpened
)
765 UseResFile( gSharedLibraryResource
) ;
769 wxStAppResource::~wxStAppResource()
771 if ( m_currentRefNum
!= kResFileNotOpened
)
773 UseResFile( m_currentRefNum
) ;
777 void wxStAppResource::OpenSharedLibraryResource(const void *initBlock
)
779 gSharedLibraryResource
= kResFileNotOpened
;
781 #ifdef WXMAKINGDLL_CORE
782 if ( initBlock
!= NULL
) {
783 const CFragInitBlock
*theInitBlock
= (const CFragInitBlock
*)initBlock
;
784 FSSpec
*fileSpec
= NULL
;
786 if (theInitBlock
->fragLocator
.where
== kDataForkCFragLocator
) {
787 fileSpec
= theInitBlock
->fragLocator
.u
.onDisk
.fileSpec
;
789 else if (theInitBlock
->fragLocator
.where
== kResourceCFragLocator
) {
790 fileSpec
= theInitBlock
->fragLocator
.u
.inSegs
.fileSpec
;
793 if (fileSpec
!= NULL
) {
794 gSharedLibraryResource
= FSpOpenResFile(fileSpec
, fsRdPerm
);
799 // Open the shared library resource file if it is not yet open
802 const char *theLibPath
;
804 gSharedLibraryBundle
= CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWindows"));
805 if (gSharedLibraryBundle
!= NULL
) {
806 // wxWindows has been bundled into a framework
807 // load the framework resources
809 gSharedLibraryResource
= CFBundleOpenBundleResourceMap(gSharedLibraryBundle
);
812 // wxWindows is a simple dynamic shared library
813 // load the resources from the data fork of a separate resource file
817 OSErr theErr
= noErr
;
819 // get the library path
820 theSymbol
= NSLookupAndBindSymbol("_gSharedLibraryResource");
821 theModule
= NSModuleForSymbol(theSymbol
);
822 theLibPath
= NSLibraryNameForModule(theModule
);
824 // if we call wxLogDebug from here then, as wxTheApp hasn't been
825 // created yet when we're called from wxApp::Initialize(), wxLog
826 // is going to create a default stderr-based log target instead of
827 // the expected normal GUI one -- don't do it, if we really want
828 // to see this message just use fprintf() here
830 wxLogDebug( wxT("wxMac library installation name is '%s'"),
834 // allocate copy to replace .dylib.* extension with .rsrc
835 if (theLibPath
!= NULL
) {
837 theResPath
= wxString(theLibPath
, wxConvLocal
);
839 theResPath
= wxString(theLibPath
);
841 // replace '_core' with '' in case of multi-lib build
842 theResPath
.Replace(wxT("_core"), wxEmptyString
);
843 // replace ".dylib" shared library extension with ".rsrc"
844 theResPath
.Replace(wxT(".dylib"), wxT(".rsrc"));
845 // Find the begining of the filename
846 theName
= theResPath
.AfterLast('/');
849 wxLogDebug( wxT("wxMac resources file name is '%s'"),
850 theResPath
.mb_str() );
853 theErr
= FSPathMakeRef((UInt8
*) theResPath
.mb_str(), &theResRef
, false);
854 if (theErr
!= noErr
) {
855 // try in current directory (using name only)
856 theErr
= FSPathMakeRef((UInt8
*) theName
.mb_str(), &theResRef
, false);
859 // open the resource file
860 if (theErr
== noErr
) {
861 theErr
= FSOpenResourceFile( &theResRef
, 0, NULL
, fsRdPerm
,
862 &gSharedLibraryResource
);
864 if (theErr
!= noErr
) {
866 wxLogDebug( wxT("unable to open wxMac resource file '%s'\n"),
867 theResPath
.mb_str() );
868 #endif // __WXDEBUG__
873 #endif /* __DARWIN__ */
875 #endif /* WXMAKINGDLL_CORE */
878 void wxStAppResource::CloseSharedLibraryResource()
880 #ifdef WXMAKINGDLL_CORE
881 // Close the shared library resource file
882 if (gSharedLibraryResource
!= kResFileNotOpened
) {
884 if (gSharedLibraryBundle
!= NULL
) {
885 CFBundleCloseBundleResourceMap(gSharedLibraryBundle
,
886 gSharedLibraryResource
);
887 gSharedLibraryBundle
= NULL
;
890 #endif /* __DARWIN__ */
892 CloseResFile(gSharedLibraryResource
);
894 gSharedLibraryResource
= kResFileNotOpened
;
896 #endif /* WXMAKINGDLL_CORE */
899 #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
901 // for shared libraries we have to manually get the correct resource
902 // ref num upon initializing and releasing when terminating, therefore
903 // the __wxinitialize and __wxterminate must be used
906 void __sinit(void); /* (generated by linker) */
907 pascal OSErr
__initialize(const CFragInitBlock
*theInitBlock
);
908 pascal void __terminate(void);
911 pascal OSErr
__wxinitialize(const CFragInitBlock
*theInitBlock
)
913 wxStAppResource::OpenSharedLibraryResource( theInitBlock
) ;
914 return __initialize( theInitBlock
) ;
917 pascal void __wxterminate(void)
919 wxStAppResource::CloseSharedLibraryResource() ;
923 #endif /* WXMAKINGDLL_CORE && !__DARWIN__ */
927 bool wxMacConvertEventToRecord( EventRef event
, EventRecord
*rec
)
929 bool converted
= ConvertEventRefToEventRecord( event
,rec
) ;
930 OSStatus err
= noErr
;
933 switch( GetEventClass( event
) )
935 case kEventClassKeyboard
:
938 switch( GetEventKind(event
) )
940 case kEventRawKeyDown
:
941 rec
->what
= keyDown
;
943 case kEventRawKeyRepeat
:
944 rec
->what
= autoKey
;
946 case kEventRawKeyUp
:
949 case kEventRawKeyModifiersChanged
:
950 rec
->what
= nullEvent
;
959 unsigned char charCode
;
961 GetMouse( &rec
->where
) ;
963 err
= GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
964 err
= GetEventParameter(event
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
965 err
= GetEventParameter(event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
966 rec
->modifiers
= modifiers
;
967 rec
->message
= (keyCode
<< 8 ) + charCode
;
971 case kEventClassTextInput
:
973 switch( GetEventKind( event
) )
975 case kEventTextInputUnicodeForKeyEvent
:
978 err
= GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent
) ;
982 unsigned char charCode
;
984 GetMouse( &rec
->where
) ;
985 rec
->what
= keyDown
;
986 err
= GetEventParameter(rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
987 err
= GetEventParameter(rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
988 err
= GetEventParameter(rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
989 rec
->modifiers
= modifiers
;
990 rec
->message
= (keyCode
<< 8 ) + charCode
;
1006 pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
1008 OSStatus result = eventNotHandledErr ;
1011 switch ( GetEventClass( event ) )
1013 case kEventClassKeyboard :
1014 if ( wxMacConvertEventToRecord( event , &rec ) )
1016 wxTheApp->MacHandleModifierEvents( &rec ) ;
1017 wxTheApp->MacHandleOneEvent( &rec ) ;
1021 case kEventClassTextInput :
1022 if ( wxMacConvertEventToRecord( event , &rec ) )
1024 wxTheApp->MacHandleModifierEvents( &rec ) ;
1025 wxTheApp->MacHandleOneEvent( &rec ) ;
1039 m_printMode
= wxPRINT_WINDOWS
;
1042 m_macCurrentEvent
= NULL
;
1044 m_macCurrentEventHandlerCallRef
= NULL
;
1048 int wxApp::MainLoop()
1060 void wxApp::ExitMainLoop()
1062 m_keepGoing
= FALSE
;
1065 // Is a message/event pending?
1066 bool wxApp::Pending()
1069 return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ;
1073 return EventAvail( everyEvent
, &event
) ;
1077 // Dispatch a message.
1078 bool wxApp::Dispatch()
1085 void wxApp::OnIdle(wxIdleEvent
& event
)
1087 wxAppBase::OnIdle(event
);
1089 // If they are pending events, we must process them: pending events are
1090 // either events to the threads other than main or events posted with
1091 // wxPostEvent() functions
1092 wxMacProcessNotifierAndPendingEvents();
1094 if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
1095 wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
1098 void wxApp::WakeUpIdle()
1109 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
1112 GetTopWindow()->Close(TRUE
);
1115 // Default behaviour: close the application with prompts. The
1116 // user can veto the close, and therefore the end session.
1117 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
1121 if (!GetTopWindow()->Close(!event
.CanVeto()))
1126 extern "C" void wxCYield() ;
1132 // Yield to other processes
1134 bool wxApp::Yield(bool onlyIfNeeded
)
1138 if ( !onlyIfNeeded
)
1140 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1149 YieldToAnyThread() ;
1151 // by definition yield should handle all non-processed events
1155 OSStatus status
= noErr
;
1158 s_inReceiveEvent
= true ;
1159 status
= ReceiveNextEvent(0, NULL
,kEventDurationNoWait
,true,&theEvent
) ;
1160 s_inReceiveEvent
= false ;
1162 if ( status
== eventLoopTimedOutErr
)
1164 // make sure next time the event loop will trigger idle events
1165 sleepTime
= kEventDurationNoWait
;
1167 else if ( status
== eventLoopQuitErr
)
1169 // according to QA1061 this may also occur when a WakeUp Process
1174 MacHandleOneEvent( theEvent
) ;
1175 ReleaseEvent(theEvent
);
1177 } while( status
== noErr
) ;
1181 // having a larger value here leads to large performance slowdowns
1182 // so we cannot give background apps more processor time here
1183 // we do so however having a large sleep value in the main event loop
1186 while ( !IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, (RgnHandle
) wxApp::s_macCursorRgn
))
1188 MacHandleModifierEvents( &event
) ;
1189 MacHandleOneEvent( &event
);
1190 if ( event
.what
!= kHighLevelEvent
)
1191 SetRectRgn( (RgnHandle
) wxApp::s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1193 MacHandleModifierEvents( &event
) ;
1196 wxMacProcessNotifierAndPendingEvents() ;
1202 // platform specifics
1204 void wxApp::MacSuspend( bool convertClipboard
)
1207 // we have to deactive the top level windows manually
1209 wxWindowListNode
* node
= wxTopLevelWindows
.GetFirst();
1212 wxTopLevelWindow
* win
= (wxTopLevelWindow
*) node
->Data();
1214 #if 0 // having problems right now with that
1215 if (!win
->HasFlag(wxSTAY_ON_TOP
))
1218 win
->MacActivate( ((EventRecord
*) MacGetCurrentEvent())->when
, false ) ;
1220 node
= node
->GetNext();
1223 ::HideFloatingWindows() ;
1225 s_lastMouseDown
= 0 ;
1227 if( convertClipboard
)
1229 MacConvertPrivateToPublicScrap() ;
1233 extern wxList wxModalDialogs
;
1235 void wxApp::MacResume( bool convertClipboard
)
1237 s_lastMouseDown
= 0 ;
1238 if( convertClipboard
)
1240 MacConvertPublicToPrivateScrap() ;
1244 ::ShowFloatingWindows() ;
1245 // raise modal dialogs in case a non modal window was selected to activate the app
1247 wxNode
* node
= wxModalDialogs
.GetFirst();
1250 wxDialog
* dialog
= (wxDialog
*) node
->GetData();
1253 node
= node
->GetNext();
1258 void wxApp::MacConvertPrivateToPublicScrap()
1262 void wxApp::MacConvertPublicToPrivateScrap()
1266 void wxApp::MacDoOneEvent()
1271 s_inReceiveEvent
= true ;
1272 OSStatus status
= ReceiveNextEvent(0, NULL
,sleepTime
,true,&theEvent
) ;
1273 s_inReceiveEvent
= false ;
1274 if ( status
== eventLoopTimedOutErr
)
1276 if ( wxTheApp
->ProcessIdle() )
1277 sleepTime
= kEventDurationNoWait
;
1280 if (g_numberOfThreads
)
1282 sleepTime
= kEventDurationNoWait
;
1286 sleepTime
= kEventDurationSecond
;
1290 else if ( status
== eventLoopQuitErr
)
1292 // according to QA1061 this may also occur when a WakeUp Process
1297 MacHandleOneEvent( theEvent
) ;
1298 ReleaseEvent(theEvent
);
1299 sleepTime
= kEventDurationNoWait
;
1304 EventMask eventMask
= everyEvent
;
1306 if (WaitNextEvent(eventMask
, &event
, sleepTime
, (RgnHandle
) s_macCursorRgn
))
1308 MacHandleModifierEvents( &event
) ;
1309 MacHandleOneEvent( &event
);
1313 MacHandleModifierEvents( &event
) ;
1315 WindowPtr window
= ::FrontWindow() ;
1317 ::IdleControls( window
) ;
1319 if ( wxTheApp
->ProcessIdle() )
1320 sleepTime
= kEventDurationNoWait
;
1323 if (g_numberOfThreads
)
1325 sleepTime
= kEventDurationNoWait
;
1329 sleepTime
= kEventDurationSecond
;
1333 if ( event
.what
!= kHighLevelEvent
)
1334 SetRectRgn( (RgnHandle
) s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1338 DeletePendingObjects() ;
1339 wxMacProcessNotifierAndPendingEvents() ;
1342 /*virtual*/ void wxApp::MacHandleUnhandledEvent( WXEVENTREF evr
)
1344 // Override to process unhandled events as you please
1347 void wxApp::MacHandleOneEvent( WXEVENTREF evr
)
1350 EventTargetRef theTarget
;
1351 theTarget
= GetEventDispatcherTarget();
1352 m_macCurrentEvent
= evr
;
1353 OSStatus status
= SendEventToEventTarget ((EventRef
) evr
, theTarget
);
1354 if(status
== eventNotHandledErr
)
1356 MacHandleUnhandledEvent(evr
);
1359 EventRecord
* ev
= (EventRecord
*) evr
;
1360 m_macCurrentEvent
= ev
;
1362 wxApp::sm_lastMessageTime
= ev
->when
;
1367 MacHandleMouseDownEvent( ev
) ;
1368 if ( ev
->modifiers
& controlKey
)
1369 s_lastMouseDown
= 2;
1371 s_lastMouseDown
= 1;
1374 if ( s_lastMouseDown
== 2 )
1376 ev
->modifiers
|= controlKey
;
1380 ev
->modifiers
&= ~controlKey
;
1382 MacHandleMouseUpEvent( ev
) ;
1383 s_lastMouseDown
= 0;
1386 MacHandleActivateEvent( ev
) ;
1389 // In embedded mode we first let the UnhandledEvent function
1390 // try to handle the update event. If we handle it ourselves
1391 // first and then pass it on, the host's windows won't update.
1392 MacHandleUnhandledEvent(ev
);
1393 MacHandleUpdateEvent( ev
) ;
1397 MacHandleKeyDownEvent( ev
) ;
1400 MacHandleKeyUpEvent( ev
) ;
1403 MacHandleDiskEvent( ev
) ;
1406 MacHandleOSEvent( ev
) ;
1408 case kHighLevelEvent
:
1409 MacHandleHighLevelEvent( ev
) ;
1415 wxMacProcessNotifierAndPendingEvents() ;
1419 bool s_macIsInModalLoop
= false ;
1421 void wxApp::MacHandleModifierEvents( WXEVENTREF evr
)
1423 EventRecord
* ev
= (EventRecord
*) evr
;
1424 if ( ev
->modifiers
!= s_lastModifiers
&& wxWindow::FindFocus() != NULL
)
1426 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1428 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1429 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1430 event
.m_altDown
= ev
->modifiers
& optionKey
;
1431 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1433 event
.m_x
= ev
->where
.h
;
1434 event
.m_y
= ev
->where
.v
;
1435 event
.m_timeStamp
= ev
->when
;
1436 wxWindow
* focus
= wxWindow::FindFocus() ;
1437 event
.SetEventObject(focus
);
1439 if ( (ev
->modifiers
^ s_lastModifiers
) & controlKey
)
1441 event
.m_keyCode
= WXK_CONTROL
;
1442 event
.SetEventType( ( ev
->modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1443 focus
->GetEventHandler()->ProcessEvent( event
) ;
1445 if ( (ev
->modifiers
^ s_lastModifiers
) & shiftKey
)
1447 event
.m_keyCode
= WXK_SHIFT
;
1448 event
.SetEventType( ( ev
->modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1449 focus
->GetEventHandler()->ProcessEvent( event
) ;
1451 if ( (ev
->modifiers
^ s_lastModifiers
) & optionKey
)
1453 event
.m_keyCode
= WXK_ALT
;
1454 event
.SetEventType( ( ev
->modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1455 focus
->GetEventHandler()->ProcessEvent( event
) ;
1457 if ( ( ev
->modifiers
^ s_lastModifiers
) & cmdKey
)
1459 event
.m_keyCode
= WXK_COMMAND
;
1460 event
.SetEventType( ( ev
->modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1461 focus
->GetEventHandler()->ProcessEvent( event
) ;
1463 s_lastModifiers
= ev
->modifiers
;
1467 void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr
)
1469 // we must avoid reentrancy problems when processing high level events eg printing
1470 bool former
= s_inYield
;
1472 EventRecord
* ev
= (EventRecord
*) evr
;
1473 ::AEProcessAppleEvent( ev
) ;
1474 s_inYield
= former
;
1477 void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr
)
1479 EventRecord
* ev
= (EventRecord
*) evr
;
1480 wxToolTip::RemoveToolTips() ;
1483 WindowRef frontWindow
= ::FrontNonFloatingWindow() ;
1484 WindowAttributes frontWindowAttributes
= NULL
;
1486 ::GetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
1488 short windowPart
= ::FindWindow(ev
->where
, &window
);
1489 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1490 if ( wxPendingDelete
.Member(win
) )
1494 GetQDGlobalsScreenBits( &screenBits
);
1499 if ( s_macIsInModalLoop
)
1505 UInt32 menuresult
= MenuSelect(ev
->where
) ;
1506 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1507 s_lastMouseDown
= 0;
1511 SystemClick( ev
, window
) ;
1512 s_lastMouseDown
= 0;
1515 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1521 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1526 Point pt
= { 0, 0 } ;
1527 SetPortWindowPort(window
) ;
1528 LocalToGlobal( &pt
) ;
1530 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1531 -1 , wxSIZE_USE_EXISTING
);
1533 s_lastMouseDown
= 0;
1537 if (TrackGoAway(window
, ev
->where
))
1542 s_lastMouseDown
= 0;
1546 Rect newContentRect
;
1547 Rect constraintRect
;
1548 constraintRect
.top
= win
->GetMinHeight() ;
1549 if ( constraintRect
.top
== -1 )
1550 constraintRect
.top
= 0 ;
1551 constraintRect
.left
= win
->GetMinWidth() ;
1552 if ( constraintRect
.left
== -1 )
1553 constraintRect
.left
= 0 ;
1554 constraintRect
.right
= win
->GetMaxWidth() ;
1555 if ( constraintRect
.right
== -1 )
1556 constraintRect
.right
= 32000 ;
1557 constraintRect
.bottom
= win
->GetMaxHeight() ;
1558 if ( constraintRect
.bottom
== -1 )
1559 constraintRect
.bottom
= 32000 ;
1561 Boolean growResult
= ResizeWindow( window
, ev
->where
,
1562 &constraintRect
, &newContentRect
) ;
1565 win
->SetSize( newContentRect
.left
, newContentRect
.top
,
1566 newContentRect
.right
- newContentRect
.left
,
1567 newContentRect
.bottom
- newContentRect
.top
, wxSIZE_USE_EXISTING
);
1569 s_lastMouseDown
= 0;
1574 if (TrackBox(window
, ev
->where
, windowPart
))
1576 // TODO setup size event
1577 ZoomWindow( window
, windowPart
, false ) ;
1583 Point pt
= { 0, 0 } ;
1584 SetPortWindowPort(window
) ;
1585 LocalToGlobal( &pt
) ;
1588 GetWindowPortBounds(window
, &tempRect
) ;
1589 win
->SetSize( pt
.h
, pt
.v
, tempRect
.right
-tempRect
.left
,
1590 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1593 s_lastMouseDown
= 0;
1595 case inCollapseBox
:
1596 // TODO setup size event
1597 s_lastMouseDown
= 0;
1604 SetPortWindowPort(window
) ;
1607 if ( window
!= frontWindow
&& wxTheApp
->s_captureWindow
== NULL
)
1609 if ( s_macIsInModalLoop
)
1613 else if ( UMAIsWindowFloating( window
) )
1616 win
->MacMouseDown( ev
, windowPart
) ;
1620 // Activate window first
1621 ::SelectWindow( window
) ;
1625 win
->MacMouseDown( ev
, windowPart
) ;
1631 win
->MacMouseDown( ev
, windowPart
) ;
1639 void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr
)
1641 EventRecord
* ev
= (EventRecord
*) evr
;
1644 short windowPart
= inNoWindow
;
1645 if ( wxTheApp
->s_captureWindow
)
1647 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
1648 windowPart
= inContent
;
1652 windowPart
= ::FindWindow(ev
->where
, &window
) ;
1663 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1665 win
->MacMouseUp( ev
, windowPart
) ;
1673 long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
1674 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1679 case kHomeCharCode
:
1682 case kEnterCharCode
:
1683 retval
= WXK_RETURN
;
1688 case kHelpCharCode
:
1691 case kBackspaceCharCode
:
1697 case kPageUpCharCode
:
1698 retval
= WXK_PAGEUP
;
1700 case kPageDownCharCode
:
1701 retval
= WXK_PAGEDOWN
;
1703 case kReturnCharCode
:
1704 retval
= WXK_RETURN
;
1706 case kFunctionKeyCharCode
:
1758 case kEscapeCharCode
:
1759 retval
= WXK_ESCAPE
;
1761 case kLeftArrowCharCode
:
1764 case kRightArrowCharCode
:
1765 retval
= WXK_RIGHT
;
1767 case kUpArrowCharCode
:
1770 case kDownArrowCharCode
:
1773 case kDeleteCharCode
:
1774 retval
= WXK_DELETE
;
1782 int wxKeyCodeToMacModifier(wxKeyCode key
)
1807 bool wxGetKeyState(wxKeyCode key
) //virtual key code if < 10.2.x, else see below
1809 // TODO: Have it use HID Manager on OSX...
1810 //if OS X > 10.2 (i.e. 10.2.x)
1811 //a known apple bug prevents the system from determining led
1812 //states with GetKeys... can only determine caps lock led
1813 return !!(GetCurrentKeyModifiers() & wxKeyCodeToMacModifier(key
));
1815 // KeyMapByteArray keymap;
1816 // GetKeys((BigEndianLong*)keymap);
1817 // return !!(BitTst(keymap, (sizeof(KeyMapByteArray)*8) - iKey));
1821 void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr
)
1823 EventRecord
* ev
= (EventRecord
*) evr
;
1824 wxToolTip::RemoveToolTips() ;
1826 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1827 if ( HiWord( menuresult
) )
1829 if ( !s_macIsInModalLoop
)
1830 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1834 wxWindow
* focus
= wxWindow::FindFocus() ;
1836 if ( MacSendKeyDownEvent( focus
, ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) == false )
1839 // we must handle control keys the other way round, otherwise text content is updated too late
1840 // has not been handled -> perform default
1841 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
1842 if ( control
&& control
->GetMacControl() != NULL
)
1846 keychar
= short(ev
->message
& charCodeMask
);
1847 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1848 ::HandleControlKey( (ControlHandle
) control
->GetMacControl() , keycode
, keychar
, ev
->modifiers
) ;
1855 void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr
)
1857 EventRecord
* ev
= (EventRecord
*) evr
;
1858 wxToolTip::RemoveToolTips() ;
1860 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1861 if ( HiWord( menuresult
) )
1866 MacSendKeyUpEvent( wxWindow::FindFocus() , ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) ;
1872 bool wxApp::MacSendKeyDownEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
)
1879 keychar
= short(keymessage
& charCodeMask
);
1880 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
1882 if ( modifiers
& ( controlKey
|shiftKey
|optionKey
) )
1884 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1885 // and look at the character after
1887 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
);
1888 keychar
= short(keyInfo
& charCodeMask
);
1889 keycode
= short(keyInfo
& keyCodeMask
) >> 8 ;
1891 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1892 long realkeyval
= keyval
;
1893 if ( keyval
== keychar
)
1895 // 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)
1896 realkeyval
= short(keymessage
& charCodeMask
) ;
1897 keyval
= wxToupper( keyval
) ;
1900 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1901 bool handled
= false ;
1902 event
.m_shiftDown
= modifiers
& shiftKey
;
1903 event
.m_controlDown
= modifiers
& controlKey
;
1904 event
.m_altDown
= modifiers
& optionKey
;
1905 event
.m_metaDown
= modifiers
& cmdKey
;
1906 event
.m_keyCode
= keyval
;
1910 event
.m_timeStamp
= when
;
1911 event
.SetEventObject(focus
);
1912 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1913 if ( handled
&& event
.GetSkipped() )
1920 wxWindow
*ancestor
= focus
;
1923 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1926 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1927 handled
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1930 if (ancestor
->IsTopLevel())
1932 ancestor
= ancestor
->GetParent();
1935 #endif // wxUSE_ACCEL
1939 event
.Skip( FALSE
) ;
1940 event
.SetEventType( wxEVT_CHAR
) ;
1942 event
.m_keyCode
= realkeyval
;
1944 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1945 if ( handled
&& event
.GetSkipped() )
1949 (keyval
== WXK_TAB
) &&
1950 // CS: copied the change below from wxGTK
1951 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
1952 // have this style, yet choose not to process this particular TAB in which
1953 // case TAB must still work as a navigational character
1955 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1957 (focus
->GetParent()) &&
1958 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1960 wxNavigationKeyEvent new_event
;
1961 new_event
.SetEventObject( focus
);
1962 new_event
.SetDirection( !event
.ShiftDown() );
1963 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1964 new_event
.SetWindowChange( event
.ControlDown() );
1965 new_event
.SetCurrentFocus( focus
);
1966 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1967 if ( handled
&& new_event
.GetSkipped() )
1970 // backdoor handler for default return and command escape
1971 if ( !handled
&& (!focus
->IsKindOf(CLASSINFO(wxControl
) ) || !focus
->MacCanFocus() ) )
1973 // if window is not having a focus still testing for default enter or cancel
1974 // TODO add the UMA version for ActiveNonFloatingWindow
1975 wxWindow
* focus
= wxFindWinFromMacWindow( FrontWindow() ) ;
1978 if ( keyval
== WXK_RETURN
)
1980 wxButton
*def
= wxDynamicCast(focus
->GetDefaultItem(),
1982 if ( def
&& def
->IsEnabled() )
1984 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
1985 event
.SetEventObject(def
);
1986 def
->Command(event
);
1990 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1991 else if (keyval
== WXK_ESCAPE
|| (keyval
== '.' && modifiers
& cmdKey
) )
1993 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1994 new_event
.SetEventObject( focus
);
1995 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
2002 bool wxApp::MacSendKeyUpEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
)
2009 keychar
= short(keymessage
& charCodeMask
);
2010 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
2011 if ( modifiers
& ( controlKey
|shiftKey
|optionKey
) )
2013 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
2014 // and look at the character after
2016 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
);
2017 keychar
= short(keyInfo
& charCodeMask
);
2018 keycode
= short(keyInfo
& keyCodeMask
) >> 8 ;
2020 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
2022 if ( keyval
== keychar
)
2024 keyval
= wxToupper( keyval
) ;
2026 bool handled
= false ;
2028 wxKeyEvent
event(wxEVT_KEY_UP
);
2029 event
.m_shiftDown
= modifiers
& shiftKey
;
2030 event
.m_controlDown
= modifiers
& controlKey
;
2031 event
.m_altDown
= modifiers
& optionKey
;
2032 event
.m_metaDown
= modifiers
& cmdKey
;
2033 event
.m_keyCode
= keyval
;
2037 event
.m_timeStamp
= when
;
2038 event
.SetEventObject(focus
);
2039 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
2045 void wxApp::MacHandleActivateEvent( WXEVENTREF evr
)
2047 EventRecord
* ev
= (EventRecord
*) evr
;
2048 WindowRef window
= (WindowRef
) ev
->message
;
2051 bool activate
= (ev
->modifiers
& activeFlag
) ;
2052 WindowClass wclass
;
2053 ::GetWindowClass ( window
, &wclass
) ;
2054 if ( wclass
== kFloatingWindowClass
)
2056 // if it is a floater we activate/deactivate the front non-floating window instead
2057 window
= ::FrontNonFloatingWindow() ;
2059 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2061 win
->MacActivate( ev
->when
, activate
) ;
2065 void wxApp::MacHandleUpdateEvent( WXEVENTREF evr
)
2067 EventRecord
* ev
= (EventRecord
*) evr
;
2068 WindowRef window
= (WindowRef
) ev
->message
;
2069 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2072 if ( !wxPendingDelete
.Member(win
) )
2073 win
->MacUpdate( ev
->when
) ;
2077 // since there is no way of telling this foreign window to update itself
2078 // we have to invalidate the update region otherwise we keep getting the same
2079 // event over and over again
2080 BeginUpdate( window
) ;
2081 EndUpdate( window
) ;
2085 void wxApp::MacHandleDiskEvent( WXEVENTREF evr
)
2087 EventRecord
* ev
= (EventRecord
*) evr
;
2088 if ( HiWord( ev
->message
) != noErr
)
2092 SetPt( &point
, 100 , 100 ) ;
2094 err
= DIBadMount( point
, ev
->message
) ;
2095 wxASSERT( err
== noErr
) ;
2099 void wxApp::MacHandleOSEvent( WXEVENTREF evr
)
2101 EventRecord
* ev
= (EventRecord
*) evr
;
2102 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
2104 case suspendResumeMessage
:
2106 bool isResuming
= ev
->message
& resumeFlag
;
2107 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
2109 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
2112 WindowRef oldFrontWindow
= NULL
;
2113 WindowRef newFrontWindow
= NULL
;
2115 // in case we don't take care of activating ourselves, we have to synchronize
2116 // our idea of the active window with the process manager's - which it already activated
2118 if ( !doesActivate
)
2119 oldFrontWindow
= ::FrontNonFloatingWindow() ;
2121 MacResume( convertClipboard
) ;
2123 newFrontWindow
= ::FrontNonFloatingWindow() ;
2125 if ( oldFrontWindow
)
2127 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
2129 win
->MacActivate( ev
->when
, false ) ;
2131 if ( newFrontWindow
)
2133 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
2135 win
->MacActivate( ev
->when
, true ) ;
2140 MacSuspend( convertClipboard
) ;
2144 case mouseMovedMessage
:
2148 wxWindow
* currentMouseWindow
= NULL
;
2150 if (s_captureWindow
)
2152 currentMouseWindow
= s_captureWindow
;
2156 wxWindow::MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) ,
2157 ¤tMouseWindow
) ;
2160 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
2162 wxMouseEvent event
;
2164 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
2165 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
2167 event
.m_leftDown
= isDown
&& !controlDown
;
2168 event
.m_middleDown
= FALSE
;
2169 event
.m_rightDown
= isDown
&& controlDown
;
2170 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
2171 event
.m_controlDown
= ev
->modifiers
& controlKey
;
2172 event
.m_altDown
= ev
->modifiers
& optionKey
;
2173 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
2174 event
.m_x
= ev
->where
.h
;
2175 event
.m_y
= ev
->where
.v
;
2176 event
.m_timeStamp
= ev
->when
;
2177 event
.SetEventObject(this);
2179 if ( wxWindow::s_lastMouseWindow
)
2181 wxMouseEvent
eventleave(event
);
2182 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
2183 wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
2184 eventleave
.SetEventObject( wxWindow::s_lastMouseWindow
) ;
2186 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
2188 if ( currentMouseWindow
)
2190 wxMouseEvent
evententer(event
);
2191 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
2192 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
2193 evententer
.SetEventObject( currentMouseWindow
) ;
2194 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
2196 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
2199 short windowPart
= inNoWindow
;
2201 if ( s_captureWindow
)
2203 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
2204 windowPart
= inContent
;
2208 windowPart
= ::FindWindow(ev
->where
, &window
);
2215 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2217 win
->MacMouseMoved( ev
, windowPart
) ;
2224 UMAShowArrowCursor();
2234 UMAShowArrowCursor();
2245 void wxApp::MacHandleMouseMovedEvent(wxInt32 x
, wxInt32 y
,wxUint32 modifiers
, long timestamp
)
2249 wxWindow
* currentMouseWindow
= NULL
;
2251 if (s_captureWindow
)
2253 currentMouseWindow
= s_captureWindow
;
2257 wxWindow::MacGetWindowFromPoint( wxPoint( x
, y
) , ¤tMouseWindow
) ;
2260 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
2262 wxMouseEvent event
;
2264 bool isDown
= !(modifiers
& btnState
) ; // 1 is for up
2265 bool controlDown
= modifiers
& controlKey
; // for simulating right mouse
2267 event
.m_leftDown
= isDown
&& !controlDown
;
2269 event
.m_middleDown
= FALSE
;
2270 event
.m_rightDown
= isDown
&& controlDown
;
2272 event
.m_shiftDown
= modifiers
& shiftKey
;
2273 event
.m_controlDown
= modifiers
& controlKey
;
2274 event
.m_altDown
= modifiers
& optionKey
;
2275 event
.m_metaDown
= modifiers
& cmdKey
;
2279 event
.m_timeStamp
= timestamp
;
2281 if ( wxWindow::s_lastMouseWindow
)
2283 wxMouseEvent
eventleave(event
);
2284 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
2285 wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
2286 eventleave
.SetEventObject( wxWindow::s_lastMouseWindow
) ;
2289 wxToolTip::RelayEvent( wxWindow::s_lastMouseWindow
, eventleave
);
2290 #endif // wxUSE_TOOLTIPS
2291 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
2293 if ( currentMouseWindow
)
2295 wxMouseEvent
evententer(event
);
2296 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
2297 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
2298 evententer
.SetEventObject( currentMouseWindow
) ;
2300 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
2301 #endif // wxUSE_TOOLTIPS
2302 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
2304 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
2307 short windowPart
= inNoWindow
;
2309 if ( s_captureWindow
)
2311 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
2312 windowPart
= inContent
;
2316 Point pt
= { y
, x
} ;
2317 windowPart
= ::FindWindow(pt
, &window
);
2324 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2326 win
->MacFireMouseEvent( nullEvent
, x
, y
, modifiers
, timestamp
) ;
2333 UMAShowArrowCursor();
2343 UMAShowArrowCursor();
2350 void wxApp::MacHandleMenuCommand( wxUint32 id
)
2352 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
2353 wxFrame
* frame
= mbar
->GetFrame();
2354 wxCHECK_RET( mbar
!= NULL
&& frame
!= NULL
, wxT("error in menu item callback") );
2357 frame
->ProcessCommand(id
);
2362 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
2365 return; // no menu item selected
2367 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
2370 Str255 deskAccessoryName
;
2373 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
2374 GetPort(&savedPort
);
2375 OpenDeskAcc(deskAccessoryName
);
2382 GetMenuItemCommandID( GetMenuHandle(macMenuId
) , macMenuItemNum
, &id
) ;
2383 MacHandleMenuCommand( id
) ;