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"
40 #include "wx/filename.h"
54 #include "wx/mac/uma.h"
55 #include "wx/mac/macnotfy.h"
58 # include <CoreServices/CoreServices.h>
59 # if defined(WXMAKINGDLL_CORE)
60 # include <mach-o/dyld.h>
65 # include <ToolUtils.h>
66 # include <DiskInit.h>
70 extern wxList wxPendingDelete
;
71 extern wxList
*wxWinMacWindowList
;
72 extern wxList
*wxWinMacControlList
;
74 extern size_t g_numberOfThreads
;
75 #endif // wxUSE_THREADS
77 // statics for implementation
79 static bool s_inYield
= FALSE
;
82 static bool s_inReceiveEvent
= FALSE
;
83 static EventTime sleepTime
= kEventDurationNoWait
;
85 static long sleepTime
= 0 ;
88 #if !USE_SHARED_LIBRARY
89 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
90 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
91 EVT_IDLE(wxApp::OnIdle
)
92 EVT_END_SESSION(wxApp::OnEndSession
)
93 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
98 const short kMacMinHeap
= (29 * 1024) ;
99 // platform specific static variables
101 const short kwxMacMenuBarResource
= 1 ;
102 const short kwxMacAppleMenuId
= 1 ;
104 WXHRGN
wxApp::s_macCursorRgn
= NULL
;
105 wxWindow
* wxApp::s_captureWindow
= NULL
;
106 int wxApp::s_lastMouseDown
= 0 ;
107 long wxApp::sm_lastMessageTime
= 0;
108 long wxApp::s_lastModifiers
= 0 ;
111 bool wxApp::s_macSupportPCMenuShortcuts
= true ;
112 long wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
113 long wxApp::s_macPreferencesMenuItemId
= wxID_PREFERENCES
;
114 long wxApp::s_macExitMenuItemId
= wxID_EXIT
;
115 wxString
wxApp::s_macHelpMenuTitleName
= wxT("&Help") ;
117 // Normally we're not a plugin
118 bool wxApp::sm_isEmbedded
= false;
119 //----------------------------------------------------------------------
120 // Core Apple Event Support
121 //----------------------------------------------------------------------
123 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
124 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
125 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
126 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
127 pascal OSErr
AEHandleRApp( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
129 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
131 return wxTheApp
->MacHandleAEODoc( (AppleEvent
*) event
, reply
) ;
134 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
136 return wxTheApp
->MacHandleAEOApp( (AppleEvent
*) event
, reply
) ;
139 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
141 return wxTheApp
->MacHandleAEPDoc( (AppleEvent
*) event
, reply
) ;
144 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
146 return wxTheApp
->MacHandleAEQuit( (AppleEvent
*) event
, reply
) ;
149 pascal OSErr
AEHandleRApp( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
151 return wxTheApp
->MacHandleAERApp( (AppleEvent
*) event
, reply
) ;
154 // AEODoc Calls MacOpenFile on each of the files passed
156 short wxApp::MacHandleAEODoc(const WXEVENTREF event
, WXEVENTREF
WXUNUSED(reply
))
160 DescType returnedType
;
166 err
= AEGetParamDesc((AppleEvent
*)event
, keyDirectObject
, typeAEList
,&docList
);
170 err
= AECountItems(&docList
, &itemsInList
);
174 ProcessSerialNumber PSN
;
175 PSN
.highLongOfPSN
= 0 ;
176 PSN
.lowLongOfPSN
= kCurrentProcess
;
177 SetFrontProcess( &PSN
) ;
179 for (i
= 1; i
<= itemsInList
; i
++) {
180 AEGetNthPtr(&docList
, i
, typeFSS
, &keywd
, &returnedType
,
181 (Ptr
) & theSpec
, sizeof(theSpec
), &actualSize
);
182 wxString fName
= wxMacFSSpec2MacFilename(&theSpec
);
188 // AEPDoc Calls MacPrintFile on each of the files passed
190 short wxApp::MacHandleAEPDoc(const WXEVENTREF event
, WXEVENTREF
WXUNUSED(reply
))
194 DescType returnedType
;
200 err
= AEGetParamDesc((AppleEvent
*)event
, keyDirectObject
, typeAEList
,&docList
);
204 err
= AECountItems(&docList
, &itemsInList
);
208 ProcessSerialNumber PSN
;
209 PSN
.highLongOfPSN
= 0 ;
210 PSN
.lowLongOfPSN
= kCurrentProcess
;
211 SetFrontProcess( &PSN
) ;
213 for (i
= 1; i
<= itemsInList
; i
++) {
214 AEGetNthPtr(&docList
, i
, typeFSS
, &keywd
, &returnedType
,
215 (Ptr
) & theSpec
, sizeof(theSpec
), &actualSize
);
216 wxString fName
= wxMacFSSpec2MacFilename(&theSpec
);
222 // AEOApp calls MacNewFile
224 short wxApp::MacHandleAEOApp(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
230 // AEQuit attempts to quit the application
232 short wxApp::MacHandleAEQuit(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
234 wxWindow
* win
= GetTopWindow() ;
237 wxCommandEvent
exitEvent(wxEVT_COMMAND_MENU_SELECTED
, s_macExitMenuItemId
);
238 if (!win
->ProcessEvent(exitEvent
))
248 // AEROApp calls MacReopenApp
250 short wxApp::MacHandleAERApp(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
257 //----------------------------------------------------------------------
258 // Support Routines linking the Mac...File Calls to the Document Manager
259 //----------------------------------------------------------------------
261 void wxApp::MacOpenFile(const wxString
& fileName
)
263 wxDocManager
* dm
= wxDocManager::GetDocumentManager() ;
265 dm
->CreateDocument(fileName
, wxDOC_SILENT
) ;
268 void wxApp::MacPrintFile(const wxString
& fileName
)
270 wxDocManager
* dm
= wxDocManager::GetDocumentManager() ;
273 wxDocument
*doc
= dm
->CreateDocument(fileName
, wxDOC_SILENT
) ;
276 wxView
* view
= doc
->GetFirstView() ;
279 wxPrintout
*printout
= view
->OnCreatePrintout();
283 printer
.Print(view
->GetFrame(), printout
, TRUE
);
289 doc
->DeleteAllViews();
290 dm
->RemoveDocument(doc
) ;
296 void wxApp::MacNewFile()
300 void wxApp::MacReopenApp()
302 // eventually check for open docs, if none, call MacNewFile
305 //----------------------------------------------------------------------
306 // Carbon Event Handler
307 //----------------------------------------------------------------------
311 static const EventTypeSpec eventList
[] =
313 { kEventClassCommand
, kEventProcessCommand
} ,
314 { kEventClassCommand
, kEventCommandUpdateStatus
} ,
316 { kEventClassMenu
, kEventMenuOpening
},
317 { kEventClassMenu
, kEventMenuClosed
},
318 { kEventClassMenu
, kEventMenuTargetItem
},
320 { kEventClassApplication
, kEventAppActivated
} ,
321 { kEventClassApplication
, kEventAppDeactivated
} ,
322 // handling the quit event is not recommended by apple
323 // rather using the quit apple event - which we do
325 { kEventClassAppleEvent
, kEventAppleEvent
} ,
327 { kEventClassMouse
, kEventMouseDown
} ,
328 { kEventClassMouse
, kEventMouseMoved
} ,
329 { kEventClassMouse
, kEventMouseUp
} ,
330 { kEventClassMouse
, kEventMouseDragged
} ,
334 static pascal OSStatus
335 MenuEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
337 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar();
341 wxFrame
* win
= mbar
->GetFrame();
345 // VZ: we could find the menu from its handle here by examining all
346 // the menus in the menu bar recursively but knowing that neither
347 // wxMSW nor wxGTK do it why bother...
351 GetEventParameter(event
,
352 kEventParamDirectObject
,
354 sizeof(menuRef
), NULL
,
360 switch (GetEventKind(event
))
362 case kEventMenuOpening
:
363 type
= wxEVT_MENU_OPEN
;
365 case kEventMenuClosed
:
366 type
= wxEVT_MENU_CLOSE
;
368 case kEventMenuTargetItem
:
369 type
= wxEVT_MENU_HIGHLIGHT
;
370 GetEventParameter(event
, kEventParamMenuCommand
,
371 typeMenuCommand
, NULL
,
372 sizeof(cmd
), NULL
, &cmd
);
373 if (cmd
== 0) return eventNotHandledErr
;
376 wxFAIL_MSG(wxT("Unexpected menu event kind"));
380 wxMenuEvent
wxevent(type
, cmd
);
381 wxevent
.SetEventObject(win
);
383 (void)win
->GetEventHandler()->ProcessEvent(wxevent
);
387 return eventNotHandledErr
;
390 // due to the rather low-level event API of wxWidgets, we cannot use RunApplicationEventLoop
391 // but have to use ReceiveNextEvent dealing with events manually, therefore we also have
392 // deal with clicks in the menu bar explicitely
394 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
396 static pascal OSStatus
MouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
398 OSStatus result
= eventNotHandledErr
;
401 UInt32 modifiers
= 0;
402 EventMouseButton button
= 0 ;
405 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
406 sizeof( Point
), NULL
, &point
);
407 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
408 sizeof( UInt32
), NULL
, &modifiers
);
409 GetEventParameter( event
, kEventParamMouseButton
, typeMouseButton
, NULL
,
410 sizeof( EventMouseButton
), NULL
, &button
);
411 GetEventParameter( event
, kEventParamClickCount
, typeUInt32
, NULL
,
412 sizeof( UInt32
), NULL
, &click
);
414 if ( button
== 0 || GetEventKind( event
) == kEventMouseUp
)
415 modifiers
+= btnState
;
418 switch( GetEventKind(event
) )
420 case kEventMouseDown
:
424 short windowPart
= ::FindWindow(point
, &window
);
426 if ( windowPart
== inMenuBar
)
428 MenuSelect( point
) ;
433 case kEventMouseDragged
:
436 if ( wxTheApp
->s_captureWindow
)
437 wxMacWindowEventHandler( handler
, event
, (void*) wxTheApp
->s_captureWindow
->MacGetTopLevelWindow() ) ;
440 case kEventMouseMoved
:
442 wxTheApp
->MacHandleMouseMovedEvent( point
.h
, point
.v
, modifiers
, EventTimeToTicks( GetEventTime( event
) ) ) ;
452 static pascal OSStatus
CommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
454 OSStatus result
= eventNotHandledErr
;
458 GetEventParameter( event
, kEventParamDirectObject
, typeHICommand
, NULL
,
459 sizeof( HICommand
), NULL
, &command
);
461 MenuCommand id
= command
.commandID
;
462 if ( id
== kHICommandPreferences
)
463 id
= wxApp::s_macPreferencesMenuItemId
;
465 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
466 wxMenu
* menu
= NULL
;
467 wxMenuItem
* item
= NULL
;
471 item
= mbar
->FindItem( id
, &menu
) ;
472 // it is not 100 % sure that an menu of id 0 is really ours, safety check
473 if ( id
== 0 && menu
!= NULL
&& menu
->GetHMenu() != command
.menu
.menuRef
)
480 if ( item
== NULL
|| menu
== NULL
|| mbar
== NULL
)
483 switch( GetEventKind( event
) )
485 case kEventProcessCommand
:
487 if (item
->IsCheckable())
489 item
->Check( !item
->IsChecked() ) ;
492 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
496 case kEventCommandUpdateStatus
:
497 // eventually trigger an updateui round
507 static pascal OSStatus
ApplicationEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
509 OSStatus result
= eventNotHandledErr
;
510 switch ( GetEventKind( event
) )
512 case kEventAppActivated
:
515 wxTheApp
->MacResume( true ) ;
519 case kEventAppDeactivated
:
522 wxTheApp
->MacSuspend( true ) ;
532 pascal OSStatus
wxAppEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
534 OSStatus result
= eventNotHandledErr
;
535 switch( GetEventClass( event
) )
537 case kEventClassCommand
:
538 result
= CommandEventHandler( handler
, event
, data
) ;
540 case kEventClassApplication
:
541 result
= ApplicationEventHandler( handler
, event
, data
) ;
543 case kEventClassMenu
:
544 result
= MenuEventHandler( handler
, event
, data
) ;
546 case kEventClassMouse
:
547 result
= MouseEventHandler( handler
, event
, data
) ;
549 case kEventClassAppleEvent
:
552 wxMacConvertEventToRecord( event
, &rec
) ;
553 result
= AEProcessAppleEvent( &rec
) ;
563 DEFINE_ONE_SHOT_HANDLER_GETTER( wxAppEventHandler
)
567 #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
568 // we know it's there ;-)
569 WXIMPORT
char std::__throws_bad_alloc
;
572 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
578 UMAInitToolbox( 4, sm_isEmbedded
) ;
579 SetEventMask( everyEvent
) ;
580 UMAShowWatchCursor() ;
582 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
583 // open shared library resources from here since we don't have
584 // __wxinitialize in Mach-O shared libraries
585 wxStAppResource::OpenSharedLibraryResource(NULL
);
589 // test the minimal configuration necessary
595 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
597 error
= kMacSTRWrongMachine
;
599 else if (theMachine
< gestaltMacPlus
)
601 error
= kMacSTRWrongMachine
;
603 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
605 error
= kMacSTROldSystem
;
607 else if ( theSystem
< 0x0860 )
609 error
= kMacSTROldSystem
;
611 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
613 error
= kMacSTRSmallSize
;
619 if ( !UMAHasAppearance() )
621 error = kMacSTRNoPre8Yet ;
627 // if we encountered any problems so far, give the error code and exit immediately
631 wxStAppResource resload
;
635 GetIndString(message
, 128, error
);
636 UMAShowArrowCursor() ;
637 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
638 itemHit
= Alert(128, nil
);
643 # if __option(profile)
644 ProfilerInit( collectDetailed
, bestTimeBase
, 40000 , 50 ) ;
649 // now avoid exceptions thrown for new (bad_alloc)
650 // FIXME CS for some changes outside wxMac does not compile anymore
652 std::__throws_bad_alloc
= 0 ;
657 s_macCursorRgn
= ::NewRgn() ;
659 // Mac OS X passes a process serial number command line argument when
660 // the application is launched from the Finder. This argument must be
661 // removed from the command line arguments before being handled by the
662 // application (otherwise applications would need to handle it)
665 static const wxChar
*ARG_PSN
= _T("-psn_");
666 if ( wxStrncmp(argv
[1], ARG_PSN
, wxStrlen(ARG_PSN
)) == 0 )
668 // remove this argument
670 memmove(argv
+ 1, argv
+ 2, argc
* sizeof(char *));
674 if ( !wxAppBase::Initialize(argc
, argv
) )
678 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
682 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
683 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
685 wxMacCreateNotifierTable() ;
687 UMAShowArrowCursor() ;
692 bool wxApp::OnInitGui()
694 if( !wxAppBase::OnInitGui() )
698 InstallStandardEventHandler( GetApplicationEventTarget() ) ;
702 InstallApplicationEventHandler(
703 GetwxAppEventHandlerUPP(),
704 GetEventTypeCount(eventList
), eventList
, wxTheApp
, (EventHandlerRef
*)&(wxTheApp
->m_macEventHandler
));
710 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
711 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
712 NewAEEventHandlerUPP(AEHandleODoc
) ,
714 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
715 NewAEEventHandlerUPP(AEHandleOApp
) ,
717 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
718 NewAEEventHandlerUPP(AEHandlePDoc
) ,
720 AEInstallEventHandler( kCoreEventClass
, kAEReopenApplication
,
721 NewAEEventHandlerUPP(AEHandleRApp
) ,
723 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
724 NewAEEventHandlerUPP(AEHandleQuit
) ,
727 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
728 NewAEEventHandlerProc(AEHandleODoc
) ,
730 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
731 NewAEEventHandlerProc(AEHandleOApp
) ,
733 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
734 NewAEEventHandlerProc(AEHandlePDoc
) ,
736 AEInstallEventHandler( kCoreEventClass
, kAEReopenApplication
,
737 NewAEEventHandlerProc(AEHandleRApp
) ,
739 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
740 NewAEEventHandlerProc(AEHandleQuit
) ,
748 void wxApp::CleanUp()
750 wxToolTip::RemoveToolTips() ;
752 // One last chance for pending objects to be cleaned up
753 wxTheApp
->DeletePendingObjects();
755 wxMacDestroyNotifierTable() ;
757 delete wxWinMacWindowList
;
758 wxWinMacWindowList
= NULL
;
760 delete wxWinMacControlList
;
761 wxWinMacControlList
= NULL
;
764 # if __option(profile)
765 ProfilerDump( (StringPtr
)"\papp.prof" ) ;
770 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
771 // close shared library resources from here since we don't have
772 // __wxterminate in Mach-O shared libraries
773 wxStAppResource::CloseSharedLibraryResource();
776 UMACleanupToolbox() ;
777 if (s_macCursorRgn
) {
778 ::DisposeRgn((RgnHandle
)s_macCursorRgn
);
785 wxAppBase::CleanUp();
788 //----------------------------------------------------------------------
789 // misc initialization stuff
790 //----------------------------------------------------------------------
792 // extern variable for shared library resource id
793 // need to be able to find it with NSLookupAndBindSymbol
794 short gSharedLibraryResource
= kResFileNotOpened
;
796 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
797 CFBundleRef gSharedLibraryBundle
= NULL
;
798 #endif /* WXMAKINGDLL_CORE && __DARWIN__ */
800 wxStAppResource::wxStAppResource()
802 m_currentRefNum
= CurResFile() ;
803 if ( gSharedLibraryResource
!= kResFileNotOpened
)
805 UseResFile( gSharedLibraryResource
) ;
809 wxStAppResource::~wxStAppResource()
811 if ( m_currentRefNum
!= kResFileNotOpened
)
813 UseResFile( m_currentRefNum
) ;
817 void wxStAppResource::OpenSharedLibraryResource(const void *initBlock
)
819 gSharedLibraryResource
= kResFileNotOpened
;
821 #ifdef WXMAKINGDLL_CORE
822 if ( initBlock
!= NULL
) {
823 const CFragInitBlock
*theInitBlock
= (const CFragInitBlock
*)initBlock
;
824 FSSpec
*fileSpec
= NULL
;
826 if (theInitBlock
->fragLocator
.where
== kDataForkCFragLocator
) {
827 fileSpec
= theInitBlock
->fragLocator
.u
.onDisk
.fileSpec
;
829 else if (theInitBlock
->fragLocator
.where
== kResourceCFragLocator
) {
830 fileSpec
= theInitBlock
->fragLocator
.u
.inSegs
.fileSpec
;
833 if (fileSpec
!= NULL
) {
834 gSharedLibraryResource
= FSpOpenResFile(fileSpec
, fsRdPerm
);
839 // Open the shared library resource file if it is not yet open
842 const char *theLibPath
;
844 gSharedLibraryBundle
= CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWidgets"));
845 if (gSharedLibraryBundle
!= NULL
) {
846 // wxWidgets has been bundled into a framework
847 // load the framework resources
849 gSharedLibraryResource
= CFBundleOpenBundleResourceMap(gSharedLibraryBundle
);
852 // wxWidgets is a simple dynamic shared library
853 // load the resources from the data fork of a separate resource file
857 OSErr theErr
= noErr
;
859 // get the library path
860 theSymbol
= NSLookupAndBindSymbol("_gSharedLibraryResource");
861 theModule
= NSModuleForSymbol(theSymbol
);
862 theLibPath
= NSLibraryNameForModule(theModule
);
864 // if we call wxLogDebug from here then, as wxTheApp hasn't been
865 // created yet when we're called from wxApp::Initialize(), wxLog
866 // is going to create a default stderr-based log target instead of
867 // the expected normal GUI one -- don't do it, if we really want
868 // to see this message just use fprintf() here
870 wxLogDebug( wxT("wxMac library installation name is '%s'"),
874 // allocate copy to replace .dylib.* extension with .rsrc
875 if (theLibPath
!= NULL
) {
877 theResPath
= wxString(theLibPath
, wxConvLocal
);
879 theResPath
= wxString(theLibPath
);
881 // replace '_core' with '' in case of multi-lib build
882 theResPath
.Replace(wxT("_core"), wxEmptyString
);
883 // replace ".dylib" shared library extension with ".rsrc"
884 theResPath
.Replace(wxT(".dylib"), wxT(".rsrc"));
885 // Find the begining of the filename
886 theName
= theResPath
.AfterLast('/');
889 wxLogDebug( wxT("wxMac resources file name is '%s'"),
890 theResPath
.mb_str() );
893 theErr
= FSPathMakeRef((UInt8
*) theResPath
.mb_str(), &theResRef
, false);
894 if (theErr
!= noErr
) {
895 // try in current directory (using name only)
896 theErr
= FSPathMakeRef((UInt8
*) theName
.mb_str(), &theResRef
, false);
899 // open the resource file
900 if (theErr
== noErr
) {
901 theErr
= FSOpenResourceFile( &theResRef
, 0, NULL
, fsRdPerm
,
902 &gSharedLibraryResource
);
904 if (theErr
!= noErr
) {
906 wxLogDebug( wxT("unable to open wxMac resource file '%s'\n"),
907 theResPath
.mb_str() );
908 #endif // __WXDEBUG__
913 #endif /* __DARWIN__ */
915 #endif /* WXMAKINGDLL_CORE */
918 void wxStAppResource::CloseSharedLibraryResource()
920 #ifdef WXMAKINGDLL_CORE
921 // Close the shared library resource file
922 if (gSharedLibraryResource
!= kResFileNotOpened
) {
924 if (gSharedLibraryBundle
!= NULL
) {
925 CFBundleCloseBundleResourceMap(gSharedLibraryBundle
,
926 gSharedLibraryResource
);
927 gSharedLibraryBundle
= NULL
;
930 #endif /* __DARWIN__ */
932 CloseResFile(gSharedLibraryResource
);
934 gSharedLibraryResource
= kResFileNotOpened
;
936 #endif /* WXMAKINGDLL_CORE */
939 #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
941 // for shared libraries we have to manually get the correct resource
942 // ref num upon initializing and releasing when terminating, therefore
943 // the __wxinitialize and __wxterminate must be used
946 void __sinit(void); /* (generated by linker) */
947 pascal OSErr
__initialize(const CFragInitBlock
*theInitBlock
);
948 pascal void __terminate(void);
951 pascal OSErr
__wxinitialize(const CFragInitBlock
*theInitBlock
)
953 wxStAppResource::OpenSharedLibraryResource( theInitBlock
) ;
954 return __initialize( theInitBlock
) ;
957 pascal void __wxterminate(void)
959 wxStAppResource::CloseSharedLibraryResource() ;
963 #endif /* WXMAKINGDLL_CORE && !__DARWIN__ */
967 bool wxMacConvertEventToRecord( EventRef event
, EventRecord
*rec
)
969 bool converted
= ConvertEventRefToEventRecord( event
,rec
) ;
970 OSStatus err
= noErr
;
973 switch( GetEventClass( event
) )
975 case kEventClassKeyboard
:
978 switch( GetEventKind(event
) )
980 case kEventRawKeyDown
:
981 rec
->what
= keyDown
;
983 case kEventRawKeyRepeat
:
984 rec
->what
= autoKey
;
986 case kEventRawKeyUp
:
989 case kEventRawKeyModifiersChanged
:
990 rec
->what
= nullEvent
;
999 unsigned char charCode
;
1001 GetMouse( &rec
->where
) ;
1003 err
= GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
1004 err
= GetEventParameter(event
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
1005 err
= GetEventParameter(event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
1006 rec
->modifiers
= modifiers
;
1007 rec
->message
= (keyCode
<< 8 ) + charCode
;
1011 case kEventClassTextInput
:
1013 switch( GetEventKind( event
) )
1015 case kEventTextInputUnicodeForKeyEvent
:
1018 err
= GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent
) ;
1022 unsigned char charCode
;
1024 GetMouse( &rec
->where
) ;
1025 rec
->what
= keyDown
;
1026 err
= GetEventParameter(rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
1027 err
= GetEventParameter(rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
1028 err
= GetEventParameter(rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
1029 rec
->modifiers
= modifiers
;
1030 rec
->message
= (keyCode
<< 8 ) + charCode
;
1046 pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
1048 OSStatus result = eventNotHandledErr ;
1051 switch ( GetEventClass( event ) )
1053 case kEventClassKeyboard :
1054 if ( wxMacConvertEventToRecord( event , &rec ) )
1056 wxTheApp->MacHandleModifierEvents( &rec ) ;
1057 wxTheApp->MacHandleOneEvent( &rec ) ;
1061 case kEventClassTextInput :
1062 if ( wxMacConvertEventToRecord( event , &rec ) )
1064 wxTheApp->MacHandleModifierEvents( &rec ) ;
1065 wxTheApp->MacHandleOneEvent( &rec ) ;
1079 m_printMode
= wxPRINT_WINDOWS
;
1082 m_macCurrentEvent
= NULL
;
1084 m_macCurrentEventHandlerCallRef
= NULL
;
1088 int wxApp::MainLoop()
1100 void wxApp::ExitMainLoop()
1102 m_keepGoing
= FALSE
;
1105 // Is a message/event pending?
1106 bool wxApp::Pending()
1109 // without the receive event (with pull param = false ) nothing is ever reported
1111 ReceiveNextEvent (0, NULL
, kEventDurationNoWait
, false, &theEvent
);
1112 return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ;
1116 return EventAvail( everyEvent
, &event
) ;
1120 // Dispatch a message.
1121 bool wxApp::Dispatch()
1128 void wxApp::OnIdle(wxIdleEvent
& event
)
1130 wxAppBase::OnIdle(event
);
1132 // If they are pending events, we must process them: pending events are
1133 // either events to the threads other than main or events posted with
1134 // wxPostEvent() functions
1135 wxMacProcessNotifierAndPendingEvents();
1137 if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
1138 wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
1141 void wxApp::WakeUpIdle()
1152 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
1155 GetTopWindow()->Close(TRUE
);
1158 // Default behaviour: close the application with prompts. The
1159 // user can veto the close, and therefore the end session.
1160 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
1164 if (!GetTopWindow()->Close(!event
.CanVeto()))
1169 extern "C" void wxCYield() ;
1175 // Yield to other processes
1177 bool wxApp::Yield(bool onlyIfNeeded
)
1181 if ( !onlyIfNeeded
)
1183 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1192 YieldToAnyThread() ;
1194 // by definition yield should handle all non-processed events
1198 OSStatus status
= noErr
;
1201 s_inReceiveEvent
= true ;
1202 status
= ReceiveNextEvent(0, NULL
,kEventDurationNoWait
,true,&theEvent
) ;
1203 s_inReceiveEvent
= false ;
1205 if ( status
== eventLoopTimedOutErr
)
1207 // make sure next time the event loop will trigger idle events
1208 sleepTime
= kEventDurationNoWait
;
1210 else if ( status
== eventLoopQuitErr
)
1212 // according to QA1061 this may also occur when a WakeUp Process
1217 MacHandleOneEvent( theEvent
) ;
1218 ReleaseEvent(theEvent
);
1220 } while( status
== noErr
) ;
1224 // having a larger value here leads to large performance slowdowns
1225 // so we cannot give background apps more processor time here
1226 // we do so however having a large sleep value in the main event loop
1229 while ( !IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, (RgnHandle
) wxApp::s_macCursorRgn
))
1231 MacHandleModifierEvents( &event
) ;
1232 MacHandleOneEvent( &event
);
1233 if ( event
.what
!= kHighLevelEvent
)
1234 SetRectRgn( (RgnHandle
) wxApp::s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1236 MacHandleModifierEvents( &event
) ;
1239 wxMacProcessNotifierAndPendingEvents() ;
1245 // platform specifics
1247 void wxApp::MacSuspend( bool convertClipboard
)
1250 // we have to deactive the top level windows manually
1252 wxWindowListNode
* node
= wxTopLevelWindows
.GetFirst();
1255 wxTopLevelWindow
* win
= (wxTopLevelWindow
*) node
->Data();
1257 #if 0 // having problems right now with that
1258 if (!win
->HasFlag(wxSTAY_ON_TOP
))
1261 win
->MacActivate( ((EventRecord
*) MacGetCurrentEvent())->when
, false ) ;
1263 node
= node
->GetNext();
1266 ::HideFloatingWindows() ;
1268 s_lastMouseDown
= 0 ;
1270 if( convertClipboard
)
1272 MacConvertPrivateToPublicScrap() ;
1276 extern wxList wxModalDialogs
;
1278 void wxApp::MacResume( bool convertClipboard
)
1280 s_lastMouseDown
= 0 ;
1281 if( convertClipboard
)
1283 MacConvertPublicToPrivateScrap() ;
1287 ::ShowFloatingWindows() ;
1288 // raise modal dialogs in case a non modal window was selected to activate the app
1290 wxNode
* node
= wxModalDialogs
.GetFirst();
1293 wxDialog
* dialog
= (wxDialog
*) node
->GetData();
1296 node
= node
->GetNext();
1301 void wxApp::MacConvertPrivateToPublicScrap()
1305 void wxApp::MacConvertPublicToPrivateScrap()
1309 void wxApp::MacDoOneEvent()
1314 s_inReceiveEvent
= true ;
1315 OSStatus status
= ReceiveNextEvent(0, NULL
,sleepTime
,true,&theEvent
) ;
1316 s_inReceiveEvent
= false ;
1317 if ( status
== eventLoopTimedOutErr
)
1319 if ( wxTheApp
->ProcessIdle() )
1320 sleepTime
= kEventDurationNoWait
;
1324 if (g_numberOfThreads
)
1326 sleepTime
= kEventDurationNoWait
;
1329 #endif // wxUSE_THREADS
1331 sleepTime
= kEventDurationSecond
;
1335 else if ( status
== eventLoopQuitErr
)
1337 // according to QA1061 this may also occur when a WakeUp Process
1342 MacHandleOneEvent( theEvent
) ;
1343 ReleaseEvent(theEvent
);
1344 sleepTime
= kEventDurationNoWait
;
1349 EventMask eventMask
= everyEvent
;
1351 if (WaitNextEvent(eventMask
, &event
, sleepTime
, (RgnHandle
) s_macCursorRgn
))
1353 MacHandleModifierEvents( &event
) ;
1354 MacHandleOneEvent( &event
);
1358 MacHandleModifierEvents( &event
) ;
1360 WindowPtr window
= ::FrontWindow() ;
1362 ::IdleControls( window
) ;
1364 if ( wxTheApp
->ProcessIdle() )
1365 sleepTime
= kEventDurationNoWait
;
1369 if (g_numberOfThreads
)
1371 sleepTime
= kEventDurationNoWait
;
1374 #endif // wxUSE_THREADS
1376 sleepTime
= kEventDurationSecond
;
1380 if ( event
.what
!= kHighLevelEvent
)
1381 SetRectRgn( (RgnHandle
) s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1385 DeletePendingObjects() ;
1386 wxMacProcessNotifierAndPendingEvents() ;
1389 /*virtual*/ void wxApp::MacHandleUnhandledEvent( WXEVENTREF evr
)
1391 // Override to process unhandled events as you please
1394 void wxApp::MacHandleOneEvent( WXEVENTREF evr
)
1397 EventTargetRef theTarget
;
1398 theTarget
= GetEventDispatcherTarget();
1399 m_macCurrentEvent
= evr
;
1400 OSStatus status
= SendEventToEventTarget ((EventRef
) evr
, theTarget
);
1401 if(status
== eventNotHandledErr
)
1403 MacHandleUnhandledEvent(evr
);
1406 EventRecord
* ev
= (EventRecord
*) evr
;
1407 m_macCurrentEvent
= ev
;
1409 wxApp::sm_lastMessageTime
= ev
->when
;
1414 MacHandleMouseDownEvent( ev
) ;
1415 if ( ev
->modifiers
& controlKey
)
1416 s_lastMouseDown
= 2;
1418 s_lastMouseDown
= 1;
1421 if ( s_lastMouseDown
== 2 )
1423 ev
->modifiers
|= controlKey
;
1427 ev
->modifiers
&= ~controlKey
;
1429 MacHandleMouseUpEvent( ev
) ;
1430 s_lastMouseDown
= 0;
1433 MacHandleActivateEvent( ev
) ;
1436 // In embedded mode we first let the UnhandledEvent function
1437 // try to handle the update event. If we handle it ourselves
1438 // first and then pass it on, the host's windows won't update.
1439 MacHandleUnhandledEvent(ev
);
1440 MacHandleUpdateEvent( ev
) ;
1444 MacHandleKeyDownEvent( ev
) ;
1447 MacHandleKeyUpEvent( ev
) ;
1450 MacHandleDiskEvent( ev
) ;
1453 MacHandleOSEvent( ev
) ;
1455 case kHighLevelEvent
:
1456 MacHandleHighLevelEvent( ev
) ;
1462 wxMacProcessNotifierAndPendingEvents() ;
1466 bool s_macIsInModalLoop
= false ;
1468 void wxApp::MacHandleModifierEvents( WXEVENTREF evr
)
1470 EventRecord
* ev
= (EventRecord
*) evr
;
1471 if ( ev
->modifiers
!= s_lastModifiers
&& wxWindow::FindFocus() != NULL
)
1473 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1475 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1476 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1477 event
.m_altDown
= ev
->modifiers
& optionKey
;
1478 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1480 event
.m_x
= ev
->where
.h
;
1481 event
.m_y
= ev
->where
.v
;
1482 event
.SetTimestamp( ev
->when
);
1483 wxWindow
* focus
= wxWindow::FindFocus() ;
1484 event
.SetEventObject(focus
);
1486 if ( (ev
->modifiers
^ s_lastModifiers
) & controlKey
)
1488 event
.m_keyCode
= WXK_CONTROL
;
1489 event
.SetEventType( ( ev
->modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1490 focus
->GetEventHandler()->ProcessEvent( event
) ;
1492 if ( (ev
->modifiers
^ s_lastModifiers
) & shiftKey
)
1494 event
.m_keyCode
= WXK_SHIFT
;
1495 event
.SetEventType( ( ev
->modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1496 focus
->GetEventHandler()->ProcessEvent( event
) ;
1498 if ( (ev
->modifiers
^ s_lastModifiers
) & optionKey
)
1500 event
.m_keyCode
= WXK_ALT
;
1501 event
.SetEventType( ( ev
->modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1502 focus
->GetEventHandler()->ProcessEvent( event
) ;
1504 if ( ( ev
->modifiers
^ s_lastModifiers
) & cmdKey
)
1506 event
.m_keyCode
= WXK_COMMAND
;
1507 event
.SetEventType( ( ev
->modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1508 focus
->GetEventHandler()->ProcessEvent( event
) ;
1510 s_lastModifiers
= ev
->modifiers
;
1514 void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr
)
1516 // we must avoid reentrancy problems when processing high level events eg printing
1517 bool former
= s_inYield
;
1519 EventRecord
* ev
= (EventRecord
*) evr
;
1520 ::AEProcessAppleEvent( ev
) ;
1521 s_inYield
= former
;
1524 void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr
)
1526 EventRecord
* ev
= (EventRecord
*) evr
;
1527 wxToolTip::RemoveToolTips() ;
1530 WindowRef frontWindow
= ::FrontNonFloatingWindow() ;
1531 WindowAttributes frontWindowAttributes
= NULL
;
1533 ::GetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
1535 short windowPart
= ::FindWindow(ev
->where
, &window
);
1536 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( (WXWindow
) window
) ;
1537 if ( wxPendingDelete
.Member(win
) )
1541 GetQDGlobalsScreenBits( &screenBits
);
1546 if ( s_macIsInModalLoop
)
1552 UInt32 menuresult
= MenuSelect(ev
->where
) ;
1553 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1554 s_lastMouseDown
= 0;
1558 SystemClick( ev
, window
) ;
1559 s_lastMouseDown
= 0;
1562 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1568 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1573 Point pt
= { 0, 0 } ;
1574 SetPortWindowPort(window
) ;
1575 LocalToGlobal( &pt
) ;
1577 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1578 -1 , wxSIZE_USE_EXISTING
);
1580 s_lastMouseDown
= 0;
1584 if (TrackGoAway(window
, ev
->where
))
1589 s_lastMouseDown
= 0;
1593 Rect newContentRect
;
1594 Rect constraintRect
;
1595 constraintRect
.top
= win
->GetMinHeight() ;
1596 if ( constraintRect
.top
== -1 )
1597 constraintRect
.top
= 0 ;
1598 constraintRect
.left
= win
->GetMinWidth() ;
1599 if ( constraintRect
.left
== -1 )
1600 constraintRect
.left
= 0 ;
1601 constraintRect
.right
= win
->GetMaxWidth() ;
1602 if ( constraintRect
.right
== -1 )
1603 constraintRect
.right
= 32000 ;
1604 constraintRect
.bottom
= win
->GetMaxHeight() ;
1605 if ( constraintRect
.bottom
== -1 )
1606 constraintRect
.bottom
= 32000 ;
1608 Boolean growResult
= ResizeWindow( window
, ev
->where
,
1609 &constraintRect
, &newContentRect
) ;
1612 win
->SetSize( newContentRect
.left
, newContentRect
.top
,
1613 newContentRect
.right
- newContentRect
.left
,
1614 newContentRect
.bottom
- newContentRect
.top
, wxSIZE_USE_EXISTING
);
1616 s_lastMouseDown
= 0;
1621 if (TrackBox(window
, ev
->where
, windowPart
))
1623 // TODO setup size event
1624 ZoomWindow( window
, windowPart
, false ) ;
1630 Point pt
= { 0, 0 } ;
1631 SetPortWindowPort(window
) ;
1632 LocalToGlobal( &pt
) ;
1635 GetWindowPortBounds(window
, &tempRect
) ;
1636 win
->SetSize( pt
.h
, pt
.v
, tempRect
.right
-tempRect
.left
,
1637 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1640 s_lastMouseDown
= 0;
1642 case inCollapseBox
:
1643 // TODO setup size event
1644 s_lastMouseDown
= 0;
1651 SetPortWindowPort(window
) ;
1654 if ( window
!= frontWindow
&& wxTheApp
->s_captureWindow
== NULL
)
1656 if ( s_macIsInModalLoop
)
1660 else if ( UMAIsWindowFloating( window
) )
1663 win
->MacMouseDown( ev
, windowPart
) ;
1667 // Activate window first
1668 ::SelectWindow( window
) ;
1672 win
->MacMouseDown( ev
, windowPart
) ;
1678 win
->MacMouseDown( ev
, windowPart
) ;
1686 void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr
)
1688 EventRecord
* ev
= (EventRecord
*) evr
;
1691 short windowPart
= inNoWindow
;
1692 if ( wxTheApp
->s_captureWindow
)
1694 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
1695 windowPart
= inContent
;
1699 windowPart
= ::FindWindow(ev
->where
, &window
) ;
1710 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( (WXWindow
) window
) ;
1712 win
->MacMouseUp( ev
, windowPart
) ;
1720 long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
1721 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1726 case kHomeCharCode
:
1729 case kEnterCharCode
:
1730 retval
= WXK_RETURN
;
1735 case kHelpCharCode
:
1738 case kBackspaceCharCode
:
1744 case kPageUpCharCode
:
1745 retval
= WXK_PAGEUP
;
1747 case kPageDownCharCode
:
1748 retval
= WXK_PAGEDOWN
;
1750 case kReturnCharCode
:
1751 retval
= WXK_RETURN
;
1753 case kFunctionKeyCharCode
:
1805 case kEscapeCharCode
:
1806 retval
= WXK_ESCAPE
;
1808 case kLeftArrowCharCode
:
1811 case kRightArrowCharCode
:
1812 retval
= WXK_RIGHT
;
1814 case kUpArrowCharCode
:
1817 case kDownArrowCharCode
:
1820 case kDeleteCharCode
:
1821 retval
= WXK_DELETE
;
1829 int wxKeyCodeToMacModifier(wxKeyCode key
)
1854 bool wxGetKeyState(wxKeyCode key
) //virtual key code if < 10.2.x, else see below
1856 wxASSERT_MSG(key
!= WXK_LBUTTON
&& key
!= WXK_RBUTTON
&& key
!=
1857 WXK_MBUTTON
, wxT("can't use wxGetKeyState() for mouse buttons"));
1861 return !!(BitTst(keymap
, (sizeof(KeyMap
)*8) - key
));
1865 void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr
)
1867 EventRecord
* ev
= (EventRecord
*) evr
;
1868 wxToolTip::RemoveToolTips() ;
1870 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1871 if ( HiWord( menuresult
) )
1873 if ( !s_macIsInModalLoop
)
1874 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1878 wxWindow
* focus
= wxWindow::FindFocus() ;
1880 if ( MacSendKeyDownEvent( focus
, ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) == false )
1883 // we must handle control keys the other way round, otherwise text content is updated too late
1884 // has not been handled -> perform default
1885 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
1886 if ( control
&& control
->GetMacControl() != NULL
)
1890 keychar
= short(ev
->message
& charCodeMask
);
1891 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1892 ::HandleControlKey( (ControlHandle
) control
->GetMacControl() , keycode
, keychar
, ev
->modifiers
) ;
1899 void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr
)
1901 EventRecord
* ev
= (EventRecord
*) evr
;
1902 wxToolTip::RemoveToolTips() ;
1904 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1905 if ( HiWord( menuresult
) )
1910 MacSendKeyUpEvent( wxWindow::FindFocus() , ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) ;
1916 bool wxApp::MacSendKeyDownEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
)
1923 keychar
= short(keymessage
& charCodeMask
);
1924 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
1926 if ( modifiers
& ( controlKey
|shiftKey
|optionKey
) )
1928 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1929 // and look at the character after
1931 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
);
1932 keychar
= short(keyInfo
& charCodeMask
);
1933 keycode
= short(keyInfo
& keyCodeMask
) >> 8 ;
1935 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1936 long realkeyval
= keyval
;
1937 if ( keyval
== keychar
)
1939 // 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)
1940 realkeyval
= short(keymessage
& charCodeMask
) ;
1941 keyval
= wxToupper( keyval
) ;
1944 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1945 bool handled
= false ;
1946 event
.m_shiftDown
= modifiers
& shiftKey
;
1947 event
.m_controlDown
= modifiers
& controlKey
;
1948 event
.m_altDown
= modifiers
& optionKey
;
1949 event
.m_metaDown
= modifiers
& cmdKey
;
1950 event
.m_keyCode
= keyval
;
1954 event
.SetTimestamp(when
);
1955 event
.SetEventObject(focus
);
1956 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1957 if ( handled
&& event
.GetSkipped() )
1964 wxWindow
*ancestor
= focus
;
1967 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1970 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1971 handled
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1974 if (ancestor
->IsTopLevel())
1976 ancestor
= ancestor
->GetParent();
1979 #endif // wxUSE_ACCEL
1983 event
.Skip( FALSE
) ;
1984 event
.SetEventType( wxEVT_CHAR
) ;
1986 event
.m_keyCode
= realkeyval
;
1988 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1989 if ( handled
&& event
.GetSkipped() )
1993 (keyval
== WXK_TAB
) &&
1994 // CS: copied the change below from wxGTK
1995 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
1996 // have this style, yet choose not to process this particular TAB in which
1997 // case TAB must still work as a navigational character
1999 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
2001 (focus
->GetParent()) &&
2002 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
2004 wxNavigationKeyEvent new_event
;
2005 new_event
.SetEventObject( focus
);
2006 new_event
.SetDirection( !event
.ShiftDown() );
2007 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
2008 new_event
.SetWindowChange( event
.ControlDown() );
2009 new_event
.SetCurrentFocus( focus
);
2010 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
2011 if ( handled
&& new_event
.GetSkipped() )
2014 // backdoor handler for default return and command escape
2015 if ( !handled
&& (!focus
->IsKindOf(CLASSINFO(wxControl
) ) || !focus
->MacCanFocus() ) )
2017 // if window is not having a focus still testing for default enter or cancel
2018 // TODO add the UMA version for ActiveNonFloatingWindow
2019 wxWindow
* focus
= wxFindWinFromMacWindow( (WXWindow
) FrontWindow() ) ;
2022 if ( keyval
== WXK_RETURN
)
2024 wxButton
*def
= wxDynamicCast(focus
->GetDefaultItem(),
2026 if ( def
&& def
->IsEnabled() )
2028 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
2029 event
.SetEventObject(def
);
2030 def
->Command(event
);
2034 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
2035 else if (keyval
== WXK_ESCAPE
|| (keyval
== '.' && modifiers
& cmdKey
) )
2037 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
2038 new_event
.SetEventObject( focus
);
2039 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
2046 bool wxApp::MacSendKeyUpEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
)
2053 keychar
= short(keymessage
& charCodeMask
);
2054 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
2055 if ( modifiers
& ( controlKey
|shiftKey
|optionKey
) )
2057 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
2058 // and look at the character after
2060 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
);
2061 keychar
= short(keyInfo
& charCodeMask
);
2062 keycode
= short(keyInfo
& keyCodeMask
) >> 8 ;
2064 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
2066 if ( keyval
== keychar
)
2068 keyval
= wxToupper( keyval
) ;
2070 bool handled
= false ;
2072 wxKeyEvent
event(wxEVT_KEY_UP
);
2073 event
.m_shiftDown
= modifiers
& shiftKey
;
2074 event
.m_controlDown
= modifiers
& controlKey
;
2075 event
.m_altDown
= modifiers
& optionKey
;
2076 event
.m_metaDown
= modifiers
& cmdKey
;
2077 event
.m_keyCode
= keyval
;
2081 event
.SetTimestamp(when
);
2082 event
.SetEventObject(focus
);
2083 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
2089 void wxApp::MacHandleActivateEvent( WXEVENTREF evr
)
2091 EventRecord
* ev
= (EventRecord
*) evr
;
2092 WindowRef window
= (WindowRef
) ev
->message
;
2095 bool activate
= (ev
->modifiers
& activeFlag
) ;
2096 WindowClass wclass
;
2097 ::GetWindowClass ( window
, &wclass
) ;
2098 if ( wclass
== kFloatingWindowClass
)
2100 // if it is a floater we activate/deactivate the front non-floating window instead
2101 window
= ::FrontNonFloatingWindow() ;
2103 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( (WXWindow
) window
) ;
2105 win
->MacActivate( ev
->when
, activate
) ;
2109 void wxApp::MacHandleUpdateEvent( WXEVENTREF evr
)
2111 EventRecord
* ev
= (EventRecord
*) evr
;
2112 WindowRef window
= (WindowRef
) ev
->message
;
2113 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( (WXWindow
) window
) ;
2116 if ( !wxPendingDelete
.Member(win
) )
2117 win
->MacUpdate( ev
->when
) ;
2121 // since there is no way of telling this foreign window to update itself
2122 // we have to invalidate the update region otherwise we keep getting the same
2123 // event over and over again
2124 BeginUpdate( window
) ;
2125 EndUpdate( window
) ;
2129 void wxApp::MacHandleDiskEvent( WXEVENTREF evr
)
2131 EventRecord
* ev
= (EventRecord
*) evr
;
2132 if ( HiWord( ev
->message
) != noErr
)
2136 SetPt( &point
, 100 , 100 ) ;
2138 err
= DIBadMount( point
, ev
->message
) ;
2139 wxASSERT( err
== noErr
) ;
2143 void wxApp::MacHandleOSEvent( WXEVENTREF evr
)
2145 EventRecord
* ev
= (EventRecord
*) evr
;
2146 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
2148 case suspendResumeMessage
:
2150 bool isResuming
= ev
->message
& resumeFlag
;
2151 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
2153 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
2156 WindowRef oldFrontWindow
= NULL
;
2157 WindowRef newFrontWindow
= NULL
;
2159 // in case we don't take care of activating ourselves, we have to synchronize
2160 // our idea of the active window with the process manager's - which it already activated
2162 if ( !doesActivate
)
2163 oldFrontWindow
= ::FrontNonFloatingWindow() ;
2165 MacResume( convertClipboard
) ;
2167 newFrontWindow
= ::FrontNonFloatingWindow() ;
2169 if ( oldFrontWindow
)
2171 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( (WXWindow
) oldFrontWindow
) ;
2173 win
->MacActivate( ev
->when
, false ) ;
2175 if ( newFrontWindow
)
2177 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( (WXWindow
) newFrontWindow
) ;
2179 win
->MacActivate( ev
->when
, true ) ;
2184 MacSuspend( convertClipboard
) ;
2188 case mouseMovedMessage
:
2192 wxWindow
* currentMouseWindow
= NULL
;
2194 if (s_captureWindow
)
2196 currentMouseWindow
= s_captureWindow
;
2200 wxWindow::MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) ,
2201 ¤tMouseWindow
) ;
2204 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
2206 wxMouseEvent event
;
2208 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
2209 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
2211 event
.m_leftDown
= isDown
&& !controlDown
;
2212 event
.m_middleDown
= FALSE
;
2213 event
.m_rightDown
= isDown
&& controlDown
;
2214 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
2215 event
.m_controlDown
= ev
->modifiers
& controlKey
;
2216 event
.m_altDown
= ev
->modifiers
& optionKey
;
2217 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
2218 event
.m_x
= ev
->where
.h
;
2219 event
.m_y
= ev
->where
.v
;
2220 event
.SetTimestamp( ev
->when
);
2221 event
.SetEventObject(this);
2223 if ( wxWindow::s_lastMouseWindow
)
2225 wxMouseEvent
eventleave(event
);
2226 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
2227 wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
2228 eventleave
.SetEventObject( wxWindow::s_lastMouseWindow
) ;
2230 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
2232 if ( currentMouseWindow
)
2234 wxMouseEvent
evententer(event
);
2235 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
2236 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
2237 evententer
.SetEventObject( currentMouseWindow
) ;
2238 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
2240 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
2243 short windowPart
= inNoWindow
;
2245 if ( s_captureWindow
)
2247 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
2248 windowPart
= inContent
;
2252 windowPart
= ::FindWindow(ev
->where
, &window
);
2259 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( (WXWindow
) window
) ;
2261 win
->MacMouseMoved( ev
, windowPart
) ;
2268 UMAShowArrowCursor();
2278 UMAShowArrowCursor();
2289 void wxApp::MacHandleMouseMovedEvent(wxInt32 x
, wxInt32 y
,wxUint32 modifiers
, long timestamp
)
2293 wxWindow
* currentMouseWindow
= NULL
;
2295 if (s_captureWindow
)
2297 currentMouseWindow
= s_captureWindow
;
2301 wxWindow::MacGetWindowFromPoint( wxPoint( x
, y
) , ¤tMouseWindow
) ;
2304 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
2306 wxMouseEvent event
;
2308 bool isDown
= !(modifiers
& btnState
) ; // 1 is for up
2309 bool controlDown
= modifiers
& controlKey
; // for simulating right mouse
2311 event
.m_leftDown
= isDown
&& !controlDown
;
2313 event
.m_middleDown
= FALSE
;
2314 event
.m_rightDown
= isDown
&& controlDown
;
2316 event
.m_shiftDown
= modifiers
& shiftKey
;
2317 event
.m_controlDown
= modifiers
& controlKey
;
2318 event
.m_altDown
= modifiers
& optionKey
;
2319 event
.m_metaDown
= modifiers
& cmdKey
;
2323 event
.SetTimestamp(timestamp
);
2325 if ( wxWindow::s_lastMouseWindow
)
2327 wxMouseEvent
eventleave(event
);
2328 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
2329 wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
2330 eventleave
.SetEventObject( wxWindow::s_lastMouseWindow
) ;
2333 wxToolTip::RelayEvent( wxWindow::s_lastMouseWindow
, eventleave
);
2334 #endif // wxUSE_TOOLTIPS
2335 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
2337 if ( currentMouseWindow
)
2339 wxMouseEvent
evententer(event
);
2340 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
2341 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
2342 evententer
.SetEventObject( currentMouseWindow
) ;
2344 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
2345 #endif // wxUSE_TOOLTIPS
2346 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
2348 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
2351 short windowPart
= inNoWindow
;
2353 if ( s_captureWindow
)
2355 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
2356 windowPart
= inContent
;
2360 Point pt
= { y
, x
} ;
2361 windowPart
= ::FindWindow(pt
, &window
);
2368 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2370 win
->MacFireMouseEvent( nullEvent
, x
, y
, modifiers
, timestamp
) ;
2377 UMAShowArrowCursor();
2387 UMAShowArrowCursor();
2394 void wxApp::MacHandleMenuCommand( wxUint32 id
)
2396 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
2397 wxFrame
* frame
= mbar
->GetFrame();
2398 wxCHECK_RET( mbar
!= NULL
&& frame
!= NULL
, wxT("error in menu item callback") );
2401 frame
->ProcessCommand(id
);
2406 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
2409 return; // no menu item selected
2411 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
2414 Str255 deskAccessoryName
;
2417 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
2418 GetPort(&savedPort
);
2419 OpenDeskAcc(deskAccessoryName
);
2426 GetMenuItemCommandID( GetMenuHandle(macMenuId
) , macMenuItemNum
, &id
) ;
2427 MacHandleMenuCommand( id
) ;