1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
14 #include "wx/window.h"
16 #include "wx/button.h"
19 #include "wx/gdicmn.h"
22 #include "wx/cursor.h"
25 #include "wx/palette.h"
27 #include "wx/dialog.h"
28 #include "wx/msgdlg.h"
30 #include "wx/module.h"
31 #include "wx/memory.h"
32 #include "wx/tooltip.h"
33 #include "wx/textctrl.h"
35 #include "wx/docview.h"
36 #include "wx/filename.h"
50 #include "wx/mac/uma.h"
51 #include "wx/mac/macnotfy.h"
54 # include <CoreServices/CoreServices.h>
55 # if defined(WXMAKINGDLL_CORE)
56 # include <mach-o/dyld.h>
61 # include <ToolUtils.h>
62 # include <DiskInit.h>
66 extern wxList wxPendingDelete
;
67 extern wxList
*wxWinMacWindowList
;
68 extern wxList
*wxWinMacControlList
;
70 extern size_t g_numberOfThreads
;
71 #endif // wxUSE_THREADS
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 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
85 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
86 EVT_IDLE(wxApp::OnIdle
)
87 EVT_END_SESSION(wxApp::OnEndSession
)
88 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
91 const short kMacMinHeap
= (29 * 1024) ;
92 // platform specific static variables
94 const short kwxMacMenuBarResource
= 1 ;
95 const short kwxMacAppleMenuId
= 1 ;
97 WXHRGN
wxApp::s_macCursorRgn
= NULL
;
98 wxWindow
* wxApp::s_captureWindow
= NULL
;
99 int wxApp::s_lastMouseDown
= 0 ;
100 long wxApp::sm_lastMessageTime
= 0;
101 long wxApp::s_lastModifiers
= 0 ;
104 bool wxApp::s_macSupportPCMenuShortcuts
= true ;
105 long wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
106 long wxApp::s_macPreferencesMenuItemId
= wxID_PREFERENCES
;
107 long wxApp::s_macExitMenuItemId
= wxID_EXIT
;
108 wxString
wxApp::s_macHelpMenuTitleName
= wxT("&Help") ;
110 // Normally we're not a plugin
111 bool wxApp::sm_isEmbedded
= false;
112 //----------------------------------------------------------------------
113 // Core Apple Event Support
114 //----------------------------------------------------------------------
116 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
117 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
118 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
119 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
120 pascal OSErr
AEHandleRApp( 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 pascal OSErr
AEHandleRApp( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
144 return wxTheApp
->MacHandleAERApp( (AppleEvent
*) event
, reply
) ;
147 // AEODoc Calls MacOpenFile on each of the files passed
149 short wxApp::MacHandleAEODoc(const WXEVENTREF event
, WXEVENTREF
WXUNUSED(reply
))
153 DescType returnedType
;
159 err
= AEGetParamDesc((AppleEvent
*)event
, keyDirectObject
, typeAEList
,&docList
);
163 err
= AECountItems(&docList
, &itemsInList
);
167 ProcessSerialNumber PSN
;
168 PSN
.highLongOfPSN
= 0 ;
169 PSN
.lowLongOfPSN
= kCurrentProcess
;
170 SetFrontProcess( &PSN
) ;
172 for (i
= 1; i
<= itemsInList
; i
++) {
173 AEGetNthPtr(&docList
, i
, typeFSS
, &keywd
, &returnedType
,
174 (Ptr
) & theSpec
, sizeof(theSpec
), &actualSize
);
175 wxString fName
= wxMacFSSpec2MacFilename(&theSpec
);
181 // AEPDoc Calls MacPrintFile on each of the files passed
183 short wxApp::MacHandleAEPDoc(const WXEVENTREF event
, WXEVENTREF
WXUNUSED(reply
))
187 DescType returnedType
;
193 err
= AEGetParamDesc((AppleEvent
*)event
, keyDirectObject
, typeAEList
,&docList
);
197 err
= AECountItems(&docList
, &itemsInList
);
201 ProcessSerialNumber PSN
;
202 PSN
.highLongOfPSN
= 0 ;
203 PSN
.lowLongOfPSN
= kCurrentProcess
;
204 SetFrontProcess( &PSN
) ;
206 for (i
= 1; i
<= itemsInList
; i
++) {
207 AEGetNthPtr(&docList
, i
, typeFSS
, &keywd
, &returnedType
,
208 (Ptr
) & theSpec
, sizeof(theSpec
), &actualSize
);
209 wxString fName
= wxMacFSSpec2MacFilename(&theSpec
);
215 // AEOApp calls MacNewFile
217 short wxApp::MacHandleAEOApp(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
223 // AEQuit attempts to quit the application
225 short wxApp::MacHandleAEQuit(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
227 wxWindow
* win
= GetTopWindow() ;
230 wxCommandEvent
exitEvent(wxEVT_COMMAND_MENU_SELECTED
, s_macExitMenuItemId
);
231 if (!win
->ProcessEvent(exitEvent
))
241 // AEROApp calls MacReopenApp
243 short wxApp::MacHandleAERApp(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
250 //----------------------------------------------------------------------
251 // Support Routines linking the Mac...File Calls to the Document Manager
252 //----------------------------------------------------------------------
254 void wxApp::MacOpenFile(const wxString
& fileName
)
256 wxDocManager
* dm
= wxDocManager::GetDocumentManager() ;
258 dm
->CreateDocument(fileName
, wxDOC_SILENT
) ;
261 void wxApp::MacPrintFile(const wxString
& fileName
)
263 wxDocManager
* dm
= wxDocManager::GetDocumentManager() ;
266 wxDocument
*doc
= dm
->CreateDocument(fileName
, wxDOC_SILENT
) ;
269 wxView
* view
= doc
->GetFirstView() ;
272 wxPrintout
*printout
= view
->OnCreatePrintout();
276 printer
.Print(view
->GetFrame(), printout
, TRUE
);
282 doc
->DeleteAllViews();
283 dm
->RemoveDocument(doc
) ;
289 void wxApp::MacNewFile()
293 void wxApp::MacReopenApp()
295 // eventually check for open docs, if none, call MacNewFile
298 //----------------------------------------------------------------------
299 // Carbon Event Handler
300 //----------------------------------------------------------------------
304 static const EventTypeSpec eventList
[] =
306 { kEventClassCommand
, kEventProcessCommand
} ,
307 { kEventClassCommand
, kEventCommandUpdateStatus
} ,
309 { kEventClassMenu
, kEventMenuOpening
},
310 { kEventClassMenu
, kEventMenuClosed
},
311 { kEventClassMenu
, kEventMenuTargetItem
},
313 { kEventClassApplication
, kEventAppActivated
} ,
314 { kEventClassApplication
, kEventAppDeactivated
} ,
315 // handling the quit event is not recommended by apple
316 // rather using the quit apple event - which we do
318 { kEventClassAppleEvent
, kEventAppleEvent
} ,
320 { kEventClassMouse
, kEventMouseDown
} ,
321 { kEventClassMouse
, kEventMouseMoved
} ,
322 { kEventClassMouse
, kEventMouseUp
} ,
323 { kEventClassMouse
, kEventMouseDragged
} ,
327 static pascal OSStatus
328 MenuEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
330 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar();
334 wxFrame
* win
= mbar
->GetFrame();
338 // VZ: we could find the menu from its handle here by examining all
339 // the menus in the menu bar recursively but knowing that neither
340 // wxMSW nor wxGTK do it why bother...
344 GetEventParameter(event
,
345 kEventParamDirectObject
,
347 sizeof(menuRef
), NULL
,
353 switch (GetEventKind(event
))
355 case kEventMenuOpening
:
356 type
= wxEVT_MENU_OPEN
;
358 case kEventMenuClosed
:
359 type
= wxEVT_MENU_CLOSE
;
361 case kEventMenuTargetItem
:
362 type
= wxEVT_MENU_HIGHLIGHT
;
363 GetEventParameter(event
, kEventParamMenuCommand
,
364 typeMenuCommand
, NULL
,
365 sizeof(cmd
), NULL
, &cmd
);
366 if (cmd
== 0) return eventNotHandledErr
;
369 wxFAIL_MSG(wxT("Unexpected menu event kind"));
373 wxMenuEvent
wxevent(type
, cmd
);
374 wxevent
.SetEventObject(win
);
376 (void)win
->GetEventHandler()->ProcessEvent(wxevent
);
380 return eventNotHandledErr
;
383 // due to the rather low-level event API of wxWidgets, we cannot use RunApplicationEventLoop
384 // but have to use ReceiveNextEvent dealing with events manually, therefore we also have
385 // to deal with clicks in the menu bar explicitly
387 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
389 static pascal OSStatus
MouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
391 OSStatus result
= eventNotHandledErr
;
394 UInt32 modifiers
= 0;
395 EventMouseButton button
= 0 ;
398 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
399 sizeof( Point
), NULL
, &point
);
400 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
401 sizeof( UInt32
), NULL
, &modifiers
);
402 GetEventParameter( event
, kEventParamMouseButton
, typeMouseButton
, NULL
,
403 sizeof( EventMouseButton
), NULL
, &button
);
404 GetEventParameter( event
, kEventParamClickCount
, typeUInt32
, NULL
,
405 sizeof( UInt32
), NULL
, &click
);
407 if ( button
== 0 || GetEventKind( event
) == kEventMouseUp
)
408 modifiers
+= btnState
;
411 switch( GetEventKind(event
) )
413 case kEventMouseDown
:
417 short windowPart
= ::FindWindow(point
, &window
);
419 if ( windowPart
== inMenuBar
)
421 MenuSelect( point
) ;
426 case kEventMouseDragged
:
429 if ( wxTheApp
->s_captureWindow
)
430 wxMacWindowEventHandler( handler
, event
, (void*) wxTheApp
->s_captureWindow
->MacGetTopLevelWindow() ) ;
433 case kEventMouseMoved
:
435 wxTheApp
->MacHandleMouseMovedEvent( point
.h
, point
.v
, modifiers
, EventTimeToTicks( GetEventTime( event
) ) ) ;
445 static pascal OSStatus
CommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
447 OSStatus result
= eventNotHandledErr
;
451 GetEventParameter( event
, kEventParamDirectObject
, typeHICommand
, NULL
,
452 sizeof( HICommand
), NULL
, &command
);
454 MenuCommand id
= command
.commandID
;
455 if ( id
== kHICommandPreferences
)
456 id
= wxApp::s_macPreferencesMenuItemId
;
458 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
459 wxMenu
* menu
= NULL
;
460 wxMenuItem
* item
= NULL
;
464 item
= mbar
->FindItem( id
, &menu
) ;
465 // it is not 100 % sure that an menu of id 0 is really ours, safety check
466 if ( id
== 0 && menu
!= NULL
&& menu
->GetHMenu() != command
.menu
.menuRef
)
473 if ( item
== NULL
|| menu
== NULL
|| mbar
== NULL
)
476 switch( GetEventKind( event
) )
478 case kEventProcessCommand
:
480 if (item
->IsCheckable())
482 item
->Check( !item
->IsChecked() ) ;
485 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
489 case kEventCommandUpdateStatus
:
490 // eventually trigger an updateui round
500 static pascal OSStatus
ApplicationEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
502 OSStatus result
= eventNotHandledErr
;
503 switch ( GetEventKind( event
) )
505 case kEventAppActivated
:
508 wxTheApp
->MacResume( true ) ;
512 case kEventAppDeactivated
:
515 wxTheApp
->MacSuspend( true ) ;
525 pascal OSStatus
wxAppEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
527 OSStatus result
= eventNotHandledErr
;
528 switch( GetEventClass( event
) )
530 case kEventClassCommand
:
531 result
= CommandEventHandler( handler
, event
, data
) ;
533 case kEventClassApplication
:
534 result
= ApplicationEventHandler( handler
, event
, data
) ;
536 case kEventClassMenu
:
537 result
= MenuEventHandler( handler
, event
, data
) ;
539 case kEventClassMouse
:
540 result
= MouseEventHandler( handler
, event
, data
) ;
542 case kEventClassAppleEvent
:
545 wxMacConvertEventToRecord( event
, &rec
) ;
546 result
= AEProcessAppleEvent( &rec
) ;
556 DEFINE_ONE_SHOT_HANDLER_GETTER( wxAppEventHandler
)
560 #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
561 // we know it's there ;-)
562 WXIMPORT
char std::__throws_bad_alloc
;
565 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
571 UMAInitToolbox( 4, sm_isEmbedded
) ;
572 SetEventMask( everyEvent
) ;
573 UMAShowWatchCursor() ;
575 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
576 // open shared library resources from here since we don't have
577 // __wxinitialize in Mach-O shared libraries
578 wxStAppResource::OpenSharedLibraryResource(NULL
);
582 // test the minimal configuration necessary
588 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
590 error
= kMacSTRWrongMachine
;
592 else if (theMachine
< gestaltMacPlus
)
594 error
= kMacSTRWrongMachine
;
596 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
598 error
= kMacSTROldSystem
;
600 else if ( theSystem
< 0x0860 )
602 error
= kMacSTROldSystem
;
604 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
606 error
= kMacSTRSmallSize
;
612 if ( !UMAHasAppearance() )
614 error = kMacSTRNoPre8Yet ;
620 // if we encountered any problems so far, give the error code and exit immediately
624 wxStAppResource resload
;
628 GetIndString(message
, 128, error
);
629 UMAShowArrowCursor() ;
630 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
631 itemHit
= Alert(128, nil
);
636 # if __option(profile)
637 ProfilerInit( collectDetailed
, bestTimeBase
, 40000 , 50 ) ;
642 // now avoid exceptions thrown for new (bad_alloc)
643 // FIXME CS for some changes outside wxMac does not compile anymore
645 std::__throws_bad_alloc
= 0 ;
650 s_macCursorRgn
= ::NewRgn() ;
652 // Mac OS X passes a process serial number command line argument when
653 // the application is launched from the Finder. This argument must be
654 // removed from the command line arguments before being handled by the
655 // application (otherwise applications would need to handle it)
658 static const wxChar
*ARG_PSN
= _T("-psn_");
659 if ( wxStrncmp(argv
[1], ARG_PSN
, wxStrlen(ARG_PSN
)) == 0 )
661 // remove this argument
663 memmove(argv
+ 1, argv
+ 2, argc
* sizeof(char *));
667 if ( !wxAppBase::Initialize(argc
, argv
) )
671 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
675 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
676 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
678 wxMacCreateNotifierTable() ;
680 UMAShowArrowCursor() ;
685 bool wxApp::OnInitGui()
687 if( !wxAppBase::OnInitGui() )
691 InstallStandardEventHandler( GetApplicationEventTarget() ) ;
695 InstallApplicationEventHandler(
696 GetwxAppEventHandlerUPP(),
697 GetEventTypeCount(eventList
), eventList
, wxTheApp
, (EventHandlerRef
*)&(wxTheApp
->m_macEventHandler
));
703 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
704 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
705 NewAEEventHandlerUPP(AEHandleODoc
) ,
707 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
708 NewAEEventHandlerUPP(AEHandleOApp
) ,
710 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
711 NewAEEventHandlerUPP(AEHandlePDoc
) ,
713 AEInstallEventHandler( kCoreEventClass
, kAEReopenApplication
,
714 NewAEEventHandlerUPP(AEHandleRApp
) ,
716 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
717 NewAEEventHandlerUPP(AEHandleQuit
) ,
720 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
721 NewAEEventHandlerProc(AEHandleODoc
) ,
723 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
724 NewAEEventHandlerProc(AEHandleOApp
) ,
726 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
727 NewAEEventHandlerProc(AEHandlePDoc
) ,
729 AEInstallEventHandler( kCoreEventClass
, kAEReopenApplication
,
730 NewAEEventHandlerProc(AEHandleRApp
) ,
732 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
733 NewAEEventHandlerProc(AEHandleQuit
) ,
741 void wxApp::CleanUp()
743 wxToolTip::RemoveToolTips() ;
745 // One last chance for pending objects to be cleaned up
746 wxTheApp
->DeletePendingObjects();
748 wxMacDestroyNotifierTable() ;
750 delete wxWinMacWindowList
;
751 wxWinMacWindowList
= NULL
;
753 delete wxWinMacControlList
;
754 wxWinMacControlList
= NULL
;
757 # if __option(profile)
758 ProfilerDump( (StringPtr
)"\papp.prof" ) ;
763 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
764 // close shared library resources from here since we don't have
765 // __wxterminate in Mach-O shared libraries
766 wxStAppResource::CloseSharedLibraryResource();
769 UMACleanupToolbox() ;
770 if (s_macCursorRgn
) {
771 ::DisposeRgn((RgnHandle
)s_macCursorRgn
);
778 wxAppBase::CleanUp();
781 //----------------------------------------------------------------------
782 // misc initialization stuff
783 //----------------------------------------------------------------------
785 // extern variable for shared library resource id
786 // need to be able to find it with NSLookupAndBindSymbol
787 short gSharedLibraryResource
= kResFileNotOpened
;
789 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
790 CFBundleRef gSharedLibraryBundle
= NULL
;
791 #endif /* WXMAKINGDLL_CORE && __DARWIN__ */
793 wxStAppResource::wxStAppResource()
795 m_currentRefNum
= CurResFile() ;
796 if ( gSharedLibraryResource
!= kResFileNotOpened
)
798 UseResFile( gSharedLibraryResource
) ;
802 wxStAppResource::~wxStAppResource()
804 if ( m_currentRefNum
!= kResFileNotOpened
)
806 UseResFile( m_currentRefNum
) ;
810 void wxStAppResource::OpenSharedLibraryResource(const void *initBlock
)
812 gSharedLibraryResource
= kResFileNotOpened
;
814 #ifdef WXMAKINGDLL_CORE
815 if ( initBlock
!= NULL
) {
816 const CFragInitBlock
*theInitBlock
= (const CFragInitBlock
*)initBlock
;
817 FSSpec
*fileSpec
= NULL
;
819 if (theInitBlock
->fragLocator
.where
== kDataForkCFragLocator
) {
820 fileSpec
= theInitBlock
->fragLocator
.u
.onDisk
.fileSpec
;
822 else if (theInitBlock
->fragLocator
.where
== kResourceCFragLocator
) {
823 fileSpec
= theInitBlock
->fragLocator
.u
.inSegs
.fileSpec
;
826 if (fileSpec
!= NULL
) {
827 gSharedLibraryResource
= FSpOpenResFile(fileSpec
, fsRdPerm
);
832 // Open the shared library resource file if it is not yet open
835 const char *theLibPath
;
837 gSharedLibraryBundle
= CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWidgets"));
838 if (gSharedLibraryBundle
!= NULL
) {
839 // wxWidgets has been bundled into a framework
840 // load the framework resources
842 gSharedLibraryResource
= CFBundleOpenBundleResourceMap(gSharedLibraryBundle
);
845 // wxWidgets is a simple dynamic shared library
846 // load the resources from the data fork of a separate resource file
850 OSErr theErr
= noErr
;
852 // get the library path
853 theSymbol
= NSLookupAndBindSymbol("_gSharedLibraryResource");
854 theModule
= NSModuleForSymbol(theSymbol
);
855 theLibPath
= NSLibraryNameForModule(theModule
);
857 // if we call wxLogDebug from here then, as wxTheApp hasn't been
858 // created yet when we're called from wxApp::Initialize(), wxLog
859 // is going to create a default stderr-based log target instead of
860 // the expected normal GUI one -- don't do it, if we really want
861 // to see this message just use fprintf() here
863 wxLogDebug( wxT("wxMac library installation name is '%s'"),
867 // allocate copy to replace .dylib.* extension with .rsrc
868 if (theLibPath
!= NULL
) {
870 theResPath
= wxString(theLibPath
, wxConvLocal
);
872 theResPath
= wxString(theLibPath
);
874 // replace '_core' with '' in case of multi-lib build
875 theResPath
.Replace(wxT("_core"), wxEmptyString
);
876 // replace ".dylib" shared library extension with ".rsrc"
877 theResPath
.Replace(wxT(".dylib"), wxT(".rsrc"));
878 // Find the begining of the filename
879 theName
= theResPath
.AfterLast('/');
882 wxLogDebug( wxT("wxMac resources file name is '%s'"),
883 theResPath
.mb_str() );
886 theErr
= FSPathMakeRef((UInt8
*) theResPath
.mb_str(), &theResRef
, false);
887 if (theErr
!= noErr
) {
888 // try in current directory (using name only)
889 theErr
= FSPathMakeRef((UInt8
*) theName
.mb_str(), &theResRef
, false);
892 // open the resource file
893 if (theErr
== noErr
) {
894 theErr
= FSOpenResourceFile( &theResRef
, 0, NULL
, fsRdPerm
,
895 &gSharedLibraryResource
);
897 if (theErr
!= noErr
) {
899 wxLogDebug( wxT("unable to open wxMac resource file '%s'\n"),
900 theResPath
.mb_str() );
901 #endif // __WXDEBUG__
906 #endif /* __DARWIN__ */
908 #endif /* WXMAKINGDLL_CORE */
911 void wxStAppResource::CloseSharedLibraryResource()
913 #ifdef WXMAKINGDLL_CORE
914 // Close the shared library resource file
915 if (gSharedLibraryResource
!= kResFileNotOpened
) {
917 if (gSharedLibraryBundle
!= NULL
) {
918 CFBundleCloseBundleResourceMap(gSharedLibraryBundle
,
919 gSharedLibraryResource
);
920 gSharedLibraryBundle
= NULL
;
923 #endif /* __DARWIN__ */
925 CloseResFile(gSharedLibraryResource
);
927 gSharedLibraryResource
= kResFileNotOpened
;
929 #endif /* WXMAKINGDLL_CORE */
932 #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
934 // for shared libraries we have to manually get the correct resource
935 // ref num upon initializing and releasing when terminating, therefore
936 // the __wxinitialize and __wxterminate must be used
939 void __sinit(void); /* (generated by linker) */
940 pascal OSErr
__initialize(const CFragInitBlock
*theInitBlock
);
941 pascal void __terminate(void);
944 pascal OSErr
__wxinitialize(const CFragInitBlock
*theInitBlock
)
946 wxStAppResource::OpenSharedLibraryResource( theInitBlock
) ;
947 return __initialize( theInitBlock
) ;
950 pascal void __wxterminate(void)
952 wxStAppResource::CloseSharedLibraryResource() ;
956 #endif /* WXMAKINGDLL_CORE && !__DARWIN__ */
960 bool wxMacConvertEventToRecord( EventRef event
, EventRecord
*rec
)
962 bool converted
= ConvertEventRefToEventRecord( event
,rec
) ;
963 OSStatus err
= noErr
;
966 switch( GetEventClass( event
) )
968 case kEventClassKeyboard
:
971 switch( GetEventKind(event
) )
973 case kEventRawKeyDown
:
974 rec
->what
= keyDown
;
976 case kEventRawKeyRepeat
:
977 rec
->what
= autoKey
;
979 case kEventRawKeyUp
:
982 case kEventRawKeyModifiersChanged
:
983 rec
->what
= nullEvent
;
992 unsigned char charCode
;
994 GetMouse( &rec
->where
) ;
996 err
= GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
997 err
= GetEventParameter(event
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
998 err
= GetEventParameter(event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
999 rec
->modifiers
= modifiers
;
1000 rec
->message
= (keyCode
<< 8 ) + charCode
;
1004 case kEventClassTextInput
:
1006 switch( GetEventKind( event
) )
1008 case kEventTextInputUnicodeForKeyEvent
:
1011 err
= GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent
) ;
1015 unsigned char charCode
;
1017 GetMouse( &rec
->where
) ;
1018 rec
->what
= keyDown
;
1019 err
= GetEventParameter(rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
1020 err
= GetEventParameter(rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
1021 err
= GetEventParameter(rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
1022 rec
->modifiers
= modifiers
;
1023 rec
->message
= (keyCode
<< 8 ) + charCode
;
1039 pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
1041 OSStatus result = eventNotHandledErr ;
1044 switch ( GetEventClass( event ) )
1046 case kEventClassKeyboard :
1047 if ( wxMacConvertEventToRecord( event , &rec ) )
1049 wxTheApp->MacHandleModifierEvents( &rec ) ;
1050 wxTheApp->MacHandleOneEvent( &rec ) ;
1054 case kEventClassTextInput :
1055 if ( wxMacConvertEventToRecord( event , &rec ) )
1057 wxTheApp->MacHandleModifierEvents( &rec ) ;
1058 wxTheApp->MacHandleOneEvent( &rec ) ;
1072 m_printMode
= wxPRINT_WINDOWS
;
1075 m_macCurrentEvent
= NULL
;
1077 m_macCurrentEventHandlerCallRef
= NULL
;
1081 int wxApp::MainLoop()
1093 void wxApp::ExitMainLoop()
1095 m_keepGoing
= FALSE
;
1098 // Is a message/event pending?
1099 bool wxApp::Pending()
1102 // without the receive event (with pull param = false ) nothing is ever reported
1104 ReceiveNextEvent (0, NULL
, kEventDurationNoWait
, false, &theEvent
);
1105 return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ;
1109 return EventAvail( everyEvent
, &event
) ;
1113 // Dispatch a message.
1114 bool wxApp::Dispatch()
1121 void wxApp::OnIdle(wxIdleEvent
& event
)
1123 wxAppBase::OnIdle(event
);
1125 // If they are pending events, we must process them: pending events are
1126 // either events to the threads other than main or events posted with
1127 // wxPostEvent() functions
1128 wxMacProcessNotifierAndPendingEvents();
1130 if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
1131 wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
1134 void wxApp::WakeUpIdle()
1145 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
1148 GetTopWindow()->Close(TRUE
);
1151 // Default behaviour: close the application with prompts. The
1152 // user can veto the close, and therefore the end session.
1153 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
1157 if (!GetTopWindow()->Close(!event
.CanVeto()))
1162 extern "C" void wxCYield() ;
1168 // Yield to other processes
1170 bool wxApp::Yield(bool onlyIfNeeded
)
1174 if ( !onlyIfNeeded
)
1176 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1185 YieldToAnyThread() ;
1187 // by definition yield should handle all non-processed events
1191 OSStatus status
= noErr
;
1194 s_inReceiveEvent
= true ;
1195 status
= ReceiveNextEvent(0, NULL
,kEventDurationNoWait
,true,&theEvent
) ;
1196 s_inReceiveEvent
= false ;
1198 if ( status
== eventLoopTimedOutErr
)
1200 // make sure next time the event loop will trigger idle events
1201 sleepTime
= kEventDurationNoWait
;
1203 else if ( status
== eventLoopQuitErr
)
1205 // according to QA1061 this may also occur when a WakeUp Process
1210 MacHandleOneEvent( theEvent
) ;
1211 ReleaseEvent(theEvent
);
1213 } while( status
== noErr
) ;
1217 // having a larger value here leads to large performance slowdowns
1218 // so we cannot give background apps more processor time here
1219 // we do so however having a large sleep value in the main event loop
1222 while ( !IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, (RgnHandle
) wxApp::s_macCursorRgn
))
1224 MacHandleModifierEvents( &event
) ;
1225 MacHandleOneEvent( &event
);
1226 if ( event
.what
!= kHighLevelEvent
)
1227 SetRectRgn( (RgnHandle
) wxApp::s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1229 MacHandleModifierEvents( &event
) ;
1232 wxMacProcessNotifierAndPendingEvents() ;
1238 // platform specifics
1240 void wxApp::MacSuspend( bool convertClipboard
)
1243 // we have to deactive the top level windows manually
1245 wxWindowListNode
* node
= wxTopLevelWindows
.GetFirst();
1248 wxTopLevelWindow
* win
= (wxTopLevelWindow
*) node
->Data();
1250 #if 0 // having problems right now with that
1251 if (!win
->HasFlag(wxSTAY_ON_TOP
))
1254 win
->MacActivate( ((EventRecord
*) MacGetCurrentEvent())->when
, false ) ;
1256 node
= node
->GetNext();
1259 ::HideFloatingWindows() ;
1261 s_lastMouseDown
= 0 ;
1263 if( convertClipboard
)
1265 MacConvertPrivateToPublicScrap() ;
1269 extern wxList wxModalDialogs
;
1271 void wxApp::MacResume( bool convertClipboard
)
1273 s_lastMouseDown
= 0 ;
1274 if( convertClipboard
)
1276 MacConvertPublicToPrivateScrap() ;
1280 ::ShowFloatingWindows() ;
1281 // raise modal dialogs in case a non modal window was selected to activate the app
1283 wxNode
* node
= wxModalDialogs
.GetFirst();
1286 wxDialog
* dialog
= (wxDialog
*) node
->GetData();
1289 node
= node
->GetNext();
1294 void wxApp::MacConvertPrivateToPublicScrap()
1298 void wxApp::MacConvertPublicToPrivateScrap()
1302 void wxApp::MacDoOneEvent()
1307 s_inReceiveEvent
= true ;
1308 OSStatus status
= ReceiveNextEvent(0, NULL
,sleepTime
,true,&theEvent
) ;
1309 s_inReceiveEvent
= false ;
1310 if ( status
== eventLoopTimedOutErr
)
1312 if ( wxTheApp
->ProcessIdle() )
1313 sleepTime
= kEventDurationNoWait
;
1317 if (g_numberOfThreads
)
1319 sleepTime
= kEventDurationNoWait
;
1322 #endif // wxUSE_THREADS
1324 sleepTime
= kEventDurationSecond
;
1328 else if ( status
== eventLoopQuitErr
)
1330 // according to QA1061 this may also occur when a WakeUp Process
1335 MacHandleOneEvent( theEvent
) ;
1336 ReleaseEvent(theEvent
);
1337 sleepTime
= kEventDurationNoWait
;
1342 EventMask eventMask
= everyEvent
;
1344 if (WaitNextEvent(eventMask
, &event
, sleepTime
, (RgnHandle
) s_macCursorRgn
))
1346 MacHandleModifierEvents( &event
) ;
1347 MacHandleOneEvent( &event
);
1351 MacHandleModifierEvents( &event
) ;
1353 WindowPtr window
= ::FrontWindow() ;
1355 ::IdleControls( window
) ;
1357 if ( wxTheApp
->ProcessIdle() )
1358 sleepTime
= kEventDurationNoWait
;
1362 if (g_numberOfThreads
)
1364 sleepTime
= kEventDurationNoWait
;
1367 #endif // wxUSE_THREADS
1369 sleepTime
= kEventDurationSecond
;
1373 if ( event
.what
!= kHighLevelEvent
)
1374 SetRectRgn( (RgnHandle
) s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1378 DeletePendingObjects() ;
1379 wxMacProcessNotifierAndPendingEvents() ;
1382 /*virtual*/ void wxApp::MacHandleUnhandledEvent( WXEVENTREF evr
)
1384 // Override to process unhandled events as you please
1387 void wxApp::MacHandleOneEvent( WXEVENTREF evr
)
1390 EventTargetRef theTarget
;
1391 theTarget
= GetEventDispatcherTarget();
1392 m_macCurrentEvent
= evr
;
1393 OSStatus status
= SendEventToEventTarget ((EventRef
) evr
, theTarget
);
1394 if(status
== eventNotHandledErr
)
1396 MacHandleUnhandledEvent(evr
);
1399 EventRecord
* ev
= (EventRecord
*) evr
;
1400 m_macCurrentEvent
= ev
;
1402 wxApp::sm_lastMessageTime
= ev
->when
;
1407 MacHandleMouseDownEvent( ev
) ;
1408 if ( ev
->modifiers
& controlKey
)
1409 s_lastMouseDown
= 2;
1411 s_lastMouseDown
= 1;
1414 if ( s_lastMouseDown
== 2 )
1416 ev
->modifiers
|= controlKey
;
1420 ev
->modifiers
&= ~controlKey
;
1422 MacHandleMouseUpEvent( ev
) ;
1423 s_lastMouseDown
= 0;
1426 MacHandleActivateEvent( ev
) ;
1429 // In embedded mode we first let the UnhandledEvent function
1430 // try to handle the update event. If we handle it ourselves
1431 // first and then pass it on, the host's windows won't update.
1432 MacHandleUnhandledEvent(ev
);
1433 MacHandleUpdateEvent( ev
) ;
1437 MacHandleKeyDownEvent( ev
) ;
1440 MacHandleKeyUpEvent( ev
) ;
1443 MacHandleDiskEvent( ev
) ;
1446 MacHandleOSEvent( ev
) ;
1448 case kHighLevelEvent
:
1449 MacHandleHighLevelEvent( ev
) ;
1455 wxMacProcessNotifierAndPendingEvents() ;
1459 bool s_macIsInModalLoop
= false ;
1461 void wxApp::MacHandleModifierEvents( WXEVENTREF evr
)
1463 EventRecord
* ev
= (EventRecord
*) evr
;
1464 if ( ev
->modifiers
!= s_lastModifiers
&& wxWindow::FindFocus() != NULL
)
1466 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1468 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1469 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1470 event
.m_altDown
= ev
->modifiers
& optionKey
;
1471 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1473 event
.m_x
= ev
->where
.h
;
1474 event
.m_y
= ev
->where
.v
;
1475 event
.SetTimestamp( ev
->when
);
1476 wxWindow
* focus
= wxWindow::FindFocus() ;
1477 event
.SetEventObject(focus
);
1479 if ( (ev
->modifiers
^ s_lastModifiers
) & controlKey
)
1481 event
.m_keyCode
= WXK_CONTROL
;
1482 event
.SetEventType( ( ev
->modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1483 focus
->GetEventHandler()->ProcessEvent( event
) ;
1485 if ( (ev
->modifiers
^ s_lastModifiers
) & shiftKey
)
1487 event
.m_keyCode
= WXK_SHIFT
;
1488 event
.SetEventType( ( ev
->modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1489 focus
->GetEventHandler()->ProcessEvent( event
) ;
1491 if ( (ev
->modifiers
^ s_lastModifiers
) & optionKey
)
1493 event
.m_keyCode
= WXK_ALT
;
1494 event
.SetEventType( ( ev
->modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1495 focus
->GetEventHandler()->ProcessEvent( event
) ;
1497 if ( ( ev
->modifiers
^ s_lastModifiers
) & cmdKey
)
1499 event
.m_keyCode
= WXK_COMMAND
;
1500 event
.SetEventType( ( ev
->modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1501 focus
->GetEventHandler()->ProcessEvent( event
) ;
1503 s_lastModifiers
= ev
->modifiers
;
1507 void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr
)
1509 // we must avoid reentrancy problems when processing high level events eg printing
1510 bool former
= s_inYield
;
1512 EventRecord
* ev
= (EventRecord
*) evr
;
1513 ::AEProcessAppleEvent( ev
) ;
1514 s_inYield
= former
;
1517 void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr
)
1519 EventRecord
* ev
= (EventRecord
*) evr
;
1520 wxToolTip::RemoveToolTips() ;
1523 WindowRef frontWindow
= ::FrontNonFloatingWindow() ;
1524 WindowAttributes frontWindowAttributes
= NULL
;
1526 ::GetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
1528 short windowPart
= ::FindWindow(ev
->where
, &window
);
1529 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( (WXWindow
) window
) ;
1530 if ( wxPendingDelete
.Member(win
) )
1534 GetQDGlobalsScreenBits( &screenBits
);
1539 if ( s_macIsInModalLoop
)
1545 UInt32 menuresult
= MenuSelect(ev
->where
) ;
1546 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1547 s_lastMouseDown
= 0;
1551 SystemClick( ev
, window
) ;
1552 s_lastMouseDown
= 0;
1555 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1561 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1566 Point pt
= { 0, 0 } ;
1567 SetPortWindowPort(window
) ;
1568 LocalToGlobal( &pt
) ;
1570 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1571 -1 , wxSIZE_USE_EXISTING
);
1573 s_lastMouseDown
= 0;
1577 if (TrackGoAway(window
, ev
->where
))
1582 s_lastMouseDown
= 0;
1586 Rect newContentRect
;
1587 Rect constraintRect
;
1588 constraintRect
.top
= win
->GetMinHeight() ;
1589 if ( constraintRect
.top
== -1 )
1590 constraintRect
.top
= 0 ;
1591 constraintRect
.left
= win
->GetMinWidth() ;
1592 if ( constraintRect
.left
== -1 )
1593 constraintRect
.left
= 0 ;
1594 constraintRect
.right
= win
->GetMaxWidth() ;
1595 if ( constraintRect
.right
== -1 )
1596 constraintRect
.right
= 32000 ;
1597 constraintRect
.bottom
= win
->GetMaxHeight() ;
1598 if ( constraintRect
.bottom
== -1 )
1599 constraintRect
.bottom
= 32000 ;
1601 Boolean growResult
= ResizeWindow( window
, ev
->where
,
1602 &constraintRect
, &newContentRect
) ;
1605 win
->SetSize( newContentRect
.left
, newContentRect
.top
,
1606 newContentRect
.right
- newContentRect
.left
,
1607 newContentRect
.bottom
- newContentRect
.top
, wxSIZE_USE_EXISTING
);
1609 s_lastMouseDown
= 0;
1614 if (TrackBox(window
, ev
->where
, windowPart
))
1616 // TODO setup size event
1617 ZoomWindow( window
, windowPart
, false ) ;
1623 Point pt
= { 0, 0 } ;
1624 SetPortWindowPort(window
) ;
1625 LocalToGlobal( &pt
) ;
1628 GetWindowPortBounds(window
, &tempRect
) ;
1629 win
->SetSize( pt
.h
, pt
.v
, tempRect
.right
-tempRect
.left
,
1630 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1633 s_lastMouseDown
= 0;
1635 case inCollapseBox
:
1636 // TODO setup size event
1637 s_lastMouseDown
= 0;
1644 SetPortWindowPort(window
) ;
1647 if ( window
!= frontWindow
&& wxTheApp
->s_captureWindow
== NULL
)
1649 if ( s_macIsInModalLoop
)
1653 else if ( UMAIsWindowFloating( window
) )
1656 win
->MacMouseDown( ev
, windowPart
) ;
1660 // Activate window first
1661 ::SelectWindow( window
) ;
1665 win
->MacMouseDown( ev
, windowPart
) ;
1671 win
->MacMouseDown( ev
, windowPart
) ;
1679 void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr
)
1681 EventRecord
* ev
= (EventRecord
*) evr
;
1684 short windowPart
= inNoWindow
;
1685 if ( wxTheApp
->s_captureWindow
)
1687 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
1688 windowPart
= inContent
;
1692 windowPart
= ::FindWindow(ev
->where
, &window
) ;
1703 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( (WXWindow
) window
) ;
1705 win
->MacMouseUp( ev
, windowPart
) ;
1713 long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
1714 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1719 case kHomeCharCode
:
1722 case kEnterCharCode
:
1723 retval
= WXK_RETURN
;
1728 case kHelpCharCode
:
1731 case kBackspaceCharCode
:
1737 case kPageUpCharCode
:
1738 retval
= WXK_PAGEUP
;
1740 case kPageDownCharCode
:
1741 retval
= WXK_PAGEDOWN
;
1743 case kReturnCharCode
:
1744 retval
= WXK_RETURN
;
1746 case kFunctionKeyCharCode
:
1798 case kEscapeCharCode
:
1799 retval
= WXK_ESCAPE
;
1801 case kLeftArrowCharCode
:
1804 case kRightArrowCharCode
:
1805 retval
= WXK_RIGHT
;
1807 case kUpArrowCharCode
:
1810 case kDownArrowCharCode
:
1813 case kDeleteCharCode
:
1814 retval
= WXK_DELETE
;
1822 int wxKeyCodeToMacModifier(wxKeyCode key
)
1847 bool wxGetKeyState(wxKeyCode key
) //virtual key code if < 10.2.x, else see below
1849 wxASSERT_MSG(key
!= WXK_LBUTTON
&& key
!= WXK_RBUTTON
&& key
!=
1850 WXK_MBUTTON
, wxT("can't use wxGetKeyState() for mouse buttons"));
1854 return !!(BitTst(keymap
, (sizeof(KeyMap
)*8) - key
));
1858 void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr
)
1860 EventRecord
* ev
= (EventRecord
*) evr
;
1861 wxToolTip::RemoveToolTips() ;
1863 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1864 if ( HiWord( menuresult
) )
1866 if ( !s_macIsInModalLoop
)
1867 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1871 wxWindow
* focus
= wxWindow::FindFocus() ;
1873 if ( MacSendKeyDownEvent( focus
, ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) == false )
1876 // we must handle control keys the other way round, otherwise text content is updated too late
1877 // has not been handled -> perform default
1878 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
1879 if ( control
&& control
->GetMacControl() != NULL
)
1883 keychar
= short(ev
->message
& charCodeMask
);
1884 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1885 ::HandleControlKey( (ControlHandle
) control
->GetMacControl() , keycode
, keychar
, ev
->modifiers
) ;
1892 void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr
)
1894 EventRecord
* ev
= (EventRecord
*) evr
;
1895 wxToolTip::RemoveToolTips() ;
1897 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1898 if ( HiWord( menuresult
) )
1903 MacSendKeyUpEvent( wxWindow::FindFocus() , ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) ;
1909 bool wxApp::MacSendKeyDownEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
)
1916 keychar
= short(keymessage
& charCodeMask
);
1917 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
1919 if ( modifiers
& ( controlKey
|shiftKey
|optionKey
) )
1921 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1922 // and look at the character after
1924 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
);
1925 keychar
= short(keyInfo
& charCodeMask
);
1926 keycode
= short(keyInfo
& keyCodeMask
) >> 8 ;
1928 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1929 long realkeyval
= keyval
;
1930 if ( keyval
== keychar
)
1932 // 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)
1933 realkeyval
= short(keymessage
& charCodeMask
) ;
1934 keyval
= wxToupper( keyval
) ;
1937 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1938 bool handled
= false ;
1939 event
.m_shiftDown
= modifiers
& shiftKey
;
1940 event
.m_controlDown
= modifiers
& controlKey
;
1941 event
.m_altDown
= modifiers
& optionKey
;
1942 event
.m_metaDown
= modifiers
& cmdKey
;
1943 event
.m_keyCode
= keyval
;
1947 event
.SetTimestamp(when
);
1948 event
.SetEventObject(focus
);
1949 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1950 if ( handled
&& event
.GetSkipped() )
1957 wxWindow
*ancestor
= focus
;
1960 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1963 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1964 handled
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1967 if (ancestor
->IsTopLevel())
1969 ancestor
= ancestor
->GetParent();
1972 #endif // wxUSE_ACCEL
1976 event
.Skip( FALSE
) ;
1977 event
.SetEventType( wxEVT_CHAR
) ;
1979 event
.m_keyCode
= realkeyval
;
1981 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1982 if ( handled
&& event
.GetSkipped() )
1986 (keyval
== WXK_TAB
) &&
1987 // CS: copied the change below from wxGTK
1988 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
1989 // have this style, yet choose not to process this particular TAB in which
1990 // case TAB must still work as a navigational character
1992 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1994 (focus
->GetParent()) &&
1995 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1997 wxNavigationKeyEvent new_event
;
1998 new_event
.SetEventObject( focus
);
1999 new_event
.SetDirection( !event
.ShiftDown() );
2000 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
2001 new_event
.SetWindowChange( event
.ControlDown() );
2002 new_event
.SetCurrentFocus( focus
);
2003 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
2004 if ( handled
&& new_event
.GetSkipped() )
2007 // backdoor handler for default return and command escape
2008 if ( !handled
&& (!focus
->IsKindOf(CLASSINFO(wxControl
) ) || !focus
->MacCanFocus() ) )
2010 // if window is not having a focus still testing for default enter or cancel
2011 // TODO add the UMA version for ActiveNonFloatingWindow
2012 wxWindow
* focus
= wxFindWinFromMacWindow( (WXWindow
) FrontWindow() ) ;
2015 if ( keyval
== WXK_RETURN
)
2017 wxButton
*def
= wxDynamicCast(focus
->GetDefaultItem(),
2019 if ( def
&& def
->IsEnabled() )
2021 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
2022 event
.SetEventObject(def
);
2023 def
->Command(event
);
2027 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
2028 else if (keyval
== WXK_ESCAPE
|| (keyval
== '.' && modifiers
& cmdKey
) )
2030 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
2031 new_event
.SetEventObject( focus
);
2032 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
2039 bool wxApp::MacSendKeyUpEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
)
2046 keychar
= short(keymessage
& charCodeMask
);
2047 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
2048 if ( modifiers
& ( controlKey
|shiftKey
|optionKey
) )
2050 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
2051 // and look at the character after
2053 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
);
2054 keychar
= short(keyInfo
& charCodeMask
);
2055 keycode
= short(keyInfo
& keyCodeMask
) >> 8 ;
2057 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
2059 if ( keyval
== keychar
)
2061 keyval
= wxToupper( keyval
) ;
2063 bool handled
= false ;
2065 wxKeyEvent
event(wxEVT_KEY_UP
);
2066 event
.m_shiftDown
= modifiers
& shiftKey
;
2067 event
.m_controlDown
= modifiers
& controlKey
;
2068 event
.m_altDown
= modifiers
& optionKey
;
2069 event
.m_metaDown
= modifiers
& cmdKey
;
2070 event
.m_keyCode
= keyval
;
2074 event
.SetTimestamp(when
);
2075 event
.SetEventObject(focus
);
2076 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
2082 void wxApp::MacHandleActivateEvent( WXEVENTREF evr
)
2084 EventRecord
* ev
= (EventRecord
*) evr
;
2085 WindowRef window
= (WindowRef
) ev
->message
;
2088 bool activate
= (ev
->modifiers
& activeFlag
) ;
2089 WindowClass wclass
;
2090 ::GetWindowClass ( window
, &wclass
) ;
2091 if ( wclass
== kFloatingWindowClass
)
2093 // if it is a floater we activate/deactivate the front non-floating window instead
2094 window
= ::FrontNonFloatingWindow() ;
2096 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( (WXWindow
) window
) ;
2098 win
->MacActivate( ev
->when
, activate
) ;
2102 void wxApp::MacHandleUpdateEvent( WXEVENTREF evr
)
2104 EventRecord
* ev
= (EventRecord
*) evr
;
2105 WindowRef window
= (WindowRef
) ev
->message
;
2106 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( (WXWindow
) window
) ;
2109 if ( !wxPendingDelete
.Member(win
) )
2110 win
->MacUpdate( ev
->when
) ;
2114 // since there is no way of telling this foreign window to update itself
2115 // we have to invalidate the update region otherwise we keep getting the same
2116 // event over and over again
2117 BeginUpdate( window
) ;
2118 EndUpdate( window
) ;
2122 void wxApp::MacHandleDiskEvent( WXEVENTREF evr
)
2124 EventRecord
* ev
= (EventRecord
*) evr
;
2125 if ( HiWord( ev
->message
) != noErr
)
2129 SetPt( &point
, 100 , 100 ) ;
2131 err
= DIBadMount( point
, ev
->message
) ;
2132 wxASSERT( err
== noErr
) ;
2136 void wxApp::MacHandleOSEvent( WXEVENTREF evr
)
2138 EventRecord
* ev
= (EventRecord
*) evr
;
2139 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
2141 case suspendResumeMessage
:
2143 bool isResuming
= ev
->message
& resumeFlag
;
2144 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
2146 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
2149 WindowRef oldFrontWindow
= NULL
;
2150 WindowRef newFrontWindow
= NULL
;
2152 // in case we don't take care of activating ourselves, we have to synchronize
2153 // our idea of the active window with the process manager's - which it already activated
2155 if ( !doesActivate
)
2156 oldFrontWindow
= ::FrontNonFloatingWindow() ;
2158 MacResume( convertClipboard
) ;
2160 newFrontWindow
= ::FrontNonFloatingWindow() ;
2162 if ( oldFrontWindow
)
2164 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( (WXWindow
) oldFrontWindow
) ;
2166 win
->MacActivate( ev
->when
, false ) ;
2168 if ( newFrontWindow
)
2170 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( (WXWindow
) newFrontWindow
) ;
2172 win
->MacActivate( ev
->when
, true ) ;
2177 MacSuspend( convertClipboard
) ;
2181 case mouseMovedMessage
:
2185 wxWindow
* currentMouseWindow
= NULL
;
2187 if (s_captureWindow
)
2189 currentMouseWindow
= s_captureWindow
;
2193 wxWindow::MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) ,
2194 ¤tMouseWindow
) ;
2197 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
2199 wxMouseEvent event
;
2201 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
2202 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
2204 event
.m_leftDown
= isDown
&& !controlDown
;
2205 event
.m_middleDown
= FALSE
;
2206 event
.m_rightDown
= isDown
&& controlDown
;
2207 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
2208 event
.m_controlDown
= ev
->modifiers
& controlKey
;
2209 event
.m_altDown
= ev
->modifiers
& optionKey
;
2210 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
2211 event
.m_x
= ev
->where
.h
;
2212 event
.m_y
= ev
->where
.v
;
2213 event
.SetTimestamp( ev
->when
);
2214 event
.SetEventObject(this);
2216 if ( wxWindow::s_lastMouseWindow
)
2218 wxMouseEvent
eventleave(event
);
2219 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
2220 wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
2221 eventleave
.SetEventObject( wxWindow::s_lastMouseWindow
) ;
2223 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
2225 if ( currentMouseWindow
)
2227 wxMouseEvent
evententer(event
);
2228 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
2229 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
2230 evententer
.SetEventObject( currentMouseWindow
) ;
2231 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
2233 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
2236 short windowPart
= inNoWindow
;
2238 if ( s_captureWindow
)
2240 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
2241 windowPart
= inContent
;
2245 windowPart
= ::FindWindow(ev
->where
, &window
);
2252 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( (WXWindow
) window
) ;
2254 win
->MacMouseMoved( ev
, windowPart
) ;
2261 UMAShowArrowCursor();
2271 UMAShowArrowCursor();
2282 void wxApp::MacHandleMouseMovedEvent(wxInt32 x
, wxInt32 y
,wxUint32 modifiers
, long timestamp
)
2286 wxWindow
* currentMouseWindow
= NULL
;
2288 if (s_captureWindow
)
2290 currentMouseWindow
= s_captureWindow
;
2294 wxWindow::MacGetWindowFromPoint( wxPoint( x
, y
) , ¤tMouseWindow
) ;
2297 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
2299 wxMouseEvent event
;
2301 bool isDown
= !(modifiers
& btnState
) ; // 1 is for up
2302 bool controlDown
= modifiers
& controlKey
; // for simulating right mouse
2304 event
.m_leftDown
= isDown
&& !controlDown
;
2306 event
.m_middleDown
= FALSE
;
2307 event
.m_rightDown
= isDown
&& controlDown
;
2309 event
.m_shiftDown
= modifiers
& shiftKey
;
2310 event
.m_controlDown
= modifiers
& controlKey
;
2311 event
.m_altDown
= modifiers
& optionKey
;
2312 event
.m_metaDown
= modifiers
& cmdKey
;
2316 event
.SetTimestamp(timestamp
);
2318 if ( wxWindow::s_lastMouseWindow
)
2320 wxMouseEvent
eventleave(event
);
2321 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
2322 wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
2323 eventleave
.SetEventObject( wxWindow::s_lastMouseWindow
) ;
2326 wxToolTip::RelayEvent( wxWindow::s_lastMouseWindow
, eventleave
);
2327 #endif // wxUSE_TOOLTIPS
2328 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
2330 if ( currentMouseWindow
)
2332 wxMouseEvent
evententer(event
);
2333 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
2334 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
2335 evententer
.SetEventObject( currentMouseWindow
) ;
2337 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
2338 #endif // wxUSE_TOOLTIPS
2339 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
2341 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
2344 short windowPart
= inNoWindow
;
2346 if ( s_captureWindow
)
2348 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
2349 windowPart
= inContent
;
2353 Point pt
= { y
, x
} ;
2354 windowPart
= ::FindWindow(pt
, &window
);
2361 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2363 win
->MacFireMouseEvent( nullEvent
, x
, y
, modifiers
, timestamp
) ;
2370 UMAShowArrowCursor();
2380 UMAShowArrowCursor();
2387 void wxApp::MacHandleMenuCommand( wxUint32 id
)
2389 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
2390 wxFrame
* frame
= mbar
->GetFrame();
2391 wxCHECK_RET( mbar
!= NULL
&& frame
!= NULL
, wxT("error in menu item callback") );
2394 frame
->ProcessCommand(id
);
2399 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
2402 return; // no menu item selected
2404 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
2407 Str255 deskAccessoryName
;
2410 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
2411 GetPort(&savedPort
);
2412 OpenDeskAcc(deskAccessoryName
);
2419 GetMenuItemCommandID( GetMenuHandle(macMenuId
) , macMenuItemNum
, &id
) ;
2420 MacHandleMenuCommand( id
) ;