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();
338 wxFrame
* win
= mbar
->GetFrame();
342 // VZ: we could find the menu from its handle here by examining all
343 // the menus in the menu bar recursively but knowing that neither
344 // wxMSW nor wxGTK do it why bother...
348 GetEventParameter(event
,
349 kEventParamDirectObject
,
351 sizeof(menuRef
), NULL
,
357 switch (GetEventKind(event
))
359 case kEventMenuOpening
:
360 type
= wxEVT_MENU_OPEN
;
362 case kEventMenuClosed
:
363 type
= wxEVT_MENU_CLOSE
;
365 case kEventMenuTargetItem
:
366 type
= wxEVT_MENU_HIGHLIGHT
;
367 GetEventParameter(event
, kEventParamMenuCommand
,
368 typeMenuCommand
, NULL
,
369 sizeof(cmd
), NULL
, &cmd
);
370 if (cmd
== 0) return eventNotHandledErr
;
373 wxFAIL_MSG(wxT("Unexpected menu event kind"));
377 wxMenuEvent
wxevent(type
, cmd
);
378 wxevent
.SetEventObject(win
);
380 (void)win
->GetEventHandler()->ProcessEvent(wxevent
);
383 return eventNotHandledErr
;
386 // due to the rather low-level event API of wxWindows, we cannot use RunApplicationEventLoop
387 // but have to use ReceiveNextEvent dealing with events manually, therefore we also have
388 // deal with clicks in the menu bar explicitely
390 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
392 static pascal OSStatus
MouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
394 OSStatus result
= eventNotHandledErr
;
397 UInt32 modifiers
= 0;
398 EventMouseButton button
= 0 ;
401 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
402 sizeof( Point
), NULL
, &point
);
403 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
404 sizeof( UInt32
), NULL
, &modifiers
);
405 GetEventParameter( event
, kEventParamMouseButton
, typeMouseButton
, NULL
,
406 sizeof( EventMouseButton
), NULL
, &button
);
407 GetEventParameter( event
, kEventParamClickCount
, typeUInt32
, NULL
,
408 sizeof( UInt32
), NULL
, &click
);
410 if ( button
== 0 || GetEventKind( event
) == kEventMouseUp
)
411 modifiers
+= btnState
;
414 switch( GetEventKind(event
) )
416 case kEventMouseDown
:
420 short windowPart
= ::FindWindow(point
, &window
);
422 if ( windowPart
== inMenuBar
)
424 MenuSelect( point
) ;
429 case kEventMouseDragged
:
432 if ( wxTheApp
->s_captureWindow
)
433 wxMacWindowEventHandler( handler
, event
, (void*) wxTheApp
->s_captureWindow
->MacGetTopLevelWindow() ) ;
436 case kEventMouseMoved
:
438 wxTheApp
->MacHandleMouseMovedEvent( point
.h
, point
.v
, modifiers
, EventTimeToTicks( GetEventTime( event
) ) ) ;
448 static pascal OSStatus
CommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
450 OSStatus result
= eventNotHandledErr
;
454 GetEventParameter( event
, kEventParamDirectObject
, typeHICommand
, NULL
,
455 sizeof( HICommand
), NULL
, &command
);
457 MenuCommand id
= command
.commandID
;
458 if ( id
== kHICommandPreferences
)
459 id
= wxApp::s_macPreferencesMenuItemId
;
461 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
462 wxMenu
* menu
= NULL
;
463 wxMenuItem
* item
= NULL
;
467 item
= mbar
->FindItem( id
, &menu
) ;
468 // it is not 100 % sure that an menu of id 0 is really ours, safety check
469 if ( id
== 0 && menu
!= NULL
&& menu
->GetHMenu() != command
.menu
.menuRef
)
476 if ( item
== NULL
|| menu
== NULL
|| mbar
== NULL
)
479 switch( GetEventKind( event
) )
481 case kEventProcessCommand
:
483 if (item
->IsCheckable())
485 item
->Check( !item
->IsChecked() ) ;
488 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
492 case kEventCommandUpdateStatus
:
493 // eventually trigger an updateui round
503 static pascal OSStatus
ApplicationEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
505 OSStatus result
= eventNotHandledErr
;
506 switch ( GetEventKind( event
) )
508 case kEventAppActivated
:
511 wxTheApp
->MacResume( true ) ;
515 case kEventAppDeactivated
:
518 wxTheApp
->MacSuspend( true ) ;
528 pascal OSStatus
wxAppEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
530 OSStatus result
= eventNotHandledErr
;
531 switch( GetEventClass( event
) )
533 case kEventClassCommand
:
534 result
= CommandEventHandler( handler
, event
, data
) ;
536 case kEventClassApplication
:
537 result
= ApplicationEventHandler( handler
, event
, data
) ;
539 case kEventClassMenu
:
540 result
= MenuEventHandler( handler
, event
, data
) ;
542 case kEventClassMouse
:
543 result
= MouseEventHandler( handler
, event
, data
) ;
545 case kEventClassAppleEvent
:
548 wxMacConvertEventToRecord( event
, &rec
) ;
549 result
= AEProcessAppleEvent( &rec
) ;
559 DEFINE_ONE_SHOT_HANDLER_GETTER( wxAppEventHandler
)
563 #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
564 // we know it's there ;-)
565 WXIMPORT
char std::__throws_bad_alloc
;
568 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
574 UMAInitToolbox( 4, sm_isEmbedded
) ;
575 SetEventMask( everyEvent
) ;
576 UMAShowWatchCursor() ;
578 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
579 // open shared library resources from here since we don't have
580 // __wxinitialize in Mach-O shared libraries
581 wxStAppResource::OpenSharedLibraryResource(NULL
);
585 // test the minimal configuration necessary
591 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
593 error
= kMacSTRWrongMachine
;
595 else if (theMachine
< gestaltMacPlus
)
597 error
= kMacSTRWrongMachine
;
599 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
601 error
= kMacSTROldSystem
;
603 else if ( theSystem
< 0x0860 )
605 error
= kMacSTROldSystem
;
607 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
609 error
= kMacSTRSmallSize
;
615 if ( !UMAHasAppearance() )
617 error = kMacSTRNoPre8Yet ;
623 // if we encountered any problems so far, give the error code and exit immediately
627 wxStAppResource resload
;
631 GetIndString(message
, 128, error
);
632 UMAShowArrowCursor() ;
633 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
634 itemHit
= Alert(128, nil
);
639 # if __option(profile)
640 ProfilerInit( collectDetailed
, bestTimeBase
, 40000 , 50 ) ;
645 // now avoid exceptions thrown for new (bad_alloc)
646 // FIXME CS for some changes outside wxMac does not compile anymore
648 std::__throws_bad_alloc
= 0 ;
653 s_macCursorRgn
= ::NewRgn() ;
655 // Mac OS X passes a process serial number command line argument when
656 // the application is launched from the Finder. This argument must be
657 // removed from the command line arguments before being handled by the
658 // application (otherwise applications would need to handle it)
661 static const wxChar
*ARG_PSN
= _T("-psn_");
662 if ( wxStrncmp(argv
[1], ARG_PSN
, wxStrlen(ARG_PSN
)) == 0 )
664 // remove this argument
666 memmove(argv
+ 1, argv
+ 2, argc
* sizeof(char *));
670 if ( !wxAppBase::Initialize(argc
, argv
) )
674 wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
678 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
679 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
681 wxMacCreateNotifierTable() ;
683 UMAShowArrowCursor() ;
688 bool wxApp::OnInitGui()
690 if( !wxAppBase::OnInitGui() )
694 InstallStandardEventHandler( GetApplicationEventTarget() ) ;
698 InstallApplicationEventHandler(
699 GetwxAppEventHandlerUPP(),
700 GetEventTypeCount(eventList
), eventList
, wxTheApp
, (EventHandlerRef
*)&(wxTheApp
->m_macEventHandler
));
706 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
707 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
708 NewAEEventHandlerUPP(AEHandleODoc
) ,
710 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
711 NewAEEventHandlerUPP(AEHandleOApp
) ,
713 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
714 NewAEEventHandlerUPP(AEHandlePDoc
) ,
716 AEInstallEventHandler( kCoreEventClass
, kAEReopenApplication
,
717 NewAEEventHandlerUPP(AEHandleRApp
) ,
719 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
720 NewAEEventHandlerUPP(AEHandleQuit
) ,
723 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
724 NewAEEventHandlerProc(AEHandleODoc
) ,
726 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
727 NewAEEventHandlerProc(AEHandleOApp
) ,
729 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
730 NewAEEventHandlerProc(AEHandlePDoc
) ,
732 AEInstallEventHandler( kCoreEventClass
, kAEReopenApplication
,
733 NewAEEventHandlerProc(AEHandleRApp
) ,
735 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
736 NewAEEventHandlerProc(AEHandleQuit
) ,
744 void wxApp::CleanUp()
746 wxToolTip::RemoveToolTips() ;
748 // One last chance for pending objects to be cleaned up
749 wxTheApp
->DeletePendingObjects();
751 wxMacDestroyNotifierTable() ;
753 delete wxWinMacWindowList
;
754 wxWinMacWindowList
= NULL
;
756 delete wxWinMacControlList
;
757 wxWinMacControlList
= NULL
;
760 # if __option(profile)
761 ProfilerDump( (StringPtr
)"\papp.prof" ) ;
766 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
767 // close shared library resources from here since we don't have
768 // __wxterminate in Mach-O shared libraries
769 wxStAppResource::CloseSharedLibraryResource();
772 UMACleanupToolbox() ;
773 if (s_macCursorRgn
) {
774 ::DisposeRgn((RgnHandle
)s_macCursorRgn
);
781 wxAppBase::CleanUp();
784 //----------------------------------------------------------------------
785 // misc initialization stuff
786 //----------------------------------------------------------------------
788 // extern variable for shared library resource id
789 // need to be able to find it with NSLookupAndBindSymbol
790 short gSharedLibraryResource
= kResFileNotOpened
;
792 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
793 CFBundleRef gSharedLibraryBundle
= NULL
;
794 #endif /* WXMAKINGDLL_CORE && __DARWIN__ */
796 wxStAppResource::wxStAppResource()
798 m_currentRefNum
= CurResFile() ;
799 if ( gSharedLibraryResource
!= kResFileNotOpened
)
801 UseResFile( gSharedLibraryResource
) ;
805 wxStAppResource::~wxStAppResource()
807 if ( m_currentRefNum
!= kResFileNotOpened
)
809 UseResFile( m_currentRefNum
) ;
813 void wxStAppResource::OpenSharedLibraryResource(const void *initBlock
)
815 gSharedLibraryResource
= kResFileNotOpened
;
817 #ifdef WXMAKINGDLL_CORE
818 if ( initBlock
!= NULL
) {
819 const CFragInitBlock
*theInitBlock
= (const CFragInitBlock
*)initBlock
;
820 FSSpec
*fileSpec
= NULL
;
822 if (theInitBlock
->fragLocator
.where
== kDataForkCFragLocator
) {
823 fileSpec
= theInitBlock
->fragLocator
.u
.onDisk
.fileSpec
;
825 else if (theInitBlock
->fragLocator
.where
== kResourceCFragLocator
) {
826 fileSpec
= theInitBlock
->fragLocator
.u
.inSegs
.fileSpec
;
829 if (fileSpec
!= NULL
) {
830 gSharedLibraryResource
= FSpOpenResFile(fileSpec
, fsRdPerm
);
835 // Open the shared library resource file if it is not yet open
838 const char *theLibPath
;
840 gSharedLibraryBundle
= CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWindows"));
841 if (gSharedLibraryBundle
!= NULL
) {
842 // wxWindows has been bundled into a framework
843 // load the framework resources
845 gSharedLibraryResource
= CFBundleOpenBundleResourceMap(gSharedLibraryBundle
);
848 // wxWindows is a simple dynamic shared library
849 // load the resources from the data fork of a separate resource file
853 OSErr theErr
= noErr
;
855 // get the library path
856 theSymbol
= NSLookupAndBindSymbol("_gSharedLibraryResource");
857 theModule
= NSModuleForSymbol(theSymbol
);
858 theLibPath
= NSLibraryNameForModule(theModule
);
860 // if we call wxLogDebug from here then, as wxTheApp hasn't been
861 // created yet when we're called from wxApp::Initialize(), wxLog
862 // is going to create a default stderr-based log target instead of
863 // the expected normal GUI one -- don't do it, if we really want
864 // to see this message just use fprintf() here
866 wxLogDebug( wxT("wxMac library installation name is '%s'"),
870 // allocate copy to replace .dylib.* extension with .rsrc
871 if (theLibPath
!= NULL
) {
873 theResPath
= wxString(theLibPath
, wxConvLocal
);
875 theResPath
= wxString(theLibPath
);
877 // replace '_core' with '' in case of multi-lib build
878 theResPath
.Replace(wxT("_core"), wxEmptyString
);
879 // replace ".dylib" shared library extension with ".rsrc"
880 theResPath
.Replace(wxT(".dylib"), wxT(".rsrc"));
881 // Find the begining of the filename
882 theName
= theResPath
.AfterLast('/');
885 wxLogDebug( wxT("wxMac resources file name is '%s'"),
886 theResPath
.mb_str() );
889 theErr
= FSPathMakeRef((UInt8
*) theResPath
.mb_str(), &theResRef
, false);
890 if (theErr
!= noErr
) {
891 // try in current directory (using name only)
892 theErr
= FSPathMakeRef((UInt8
*) theName
.mb_str(), &theResRef
, false);
895 // open the resource file
896 if (theErr
== noErr
) {
897 theErr
= FSOpenResourceFile( &theResRef
, 0, NULL
, fsRdPerm
,
898 &gSharedLibraryResource
);
900 if (theErr
!= noErr
) {
902 wxLogDebug( wxT("unable to open wxMac resource file '%s'\n"),
903 theResPath
.mb_str() );
904 #endif // __WXDEBUG__
909 #endif /* __DARWIN__ */
911 #endif /* WXMAKINGDLL_CORE */
914 void wxStAppResource::CloseSharedLibraryResource()
916 #ifdef WXMAKINGDLL_CORE
917 // Close the shared library resource file
918 if (gSharedLibraryResource
!= kResFileNotOpened
) {
920 if (gSharedLibraryBundle
!= NULL
) {
921 CFBundleCloseBundleResourceMap(gSharedLibraryBundle
,
922 gSharedLibraryResource
);
923 gSharedLibraryBundle
= NULL
;
926 #endif /* __DARWIN__ */
928 CloseResFile(gSharedLibraryResource
);
930 gSharedLibraryResource
= kResFileNotOpened
;
932 #endif /* WXMAKINGDLL_CORE */
935 #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
937 // for shared libraries we have to manually get the correct resource
938 // ref num upon initializing and releasing when terminating, therefore
939 // the __wxinitialize and __wxterminate must be used
942 void __sinit(void); /* (generated by linker) */
943 pascal OSErr
__initialize(const CFragInitBlock
*theInitBlock
);
944 pascal void __terminate(void);
947 pascal OSErr
__wxinitialize(const CFragInitBlock
*theInitBlock
)
949 wxStAppResource::OpenSharedLibraryResource( theInitBlock
) ;
950 return __initialize( theInitBlock
) ;
953 pascal void __wxterminate(void)
955 wxStAppResource::CloseSharedLibraryResource() ;
959 #endif /* WXMAKINGDLL_CORE && !__DARWIN__ */
963 bool wxMacConvertEventToRecord( EventRef event
, EventRecord
*rec
)
965 bool converted
= ConvertEventRefToEventRecord( event
,rec
) ;
966 OSStatus err
= noErr
;
969 switch( GetEventClass( event
) )
971 case kEventClassKeyboard
:
974 switch( GetEventKind(event
) )
976 case kEventRawKeyDown
:
977 rec
->what
= keyDown
;
979 case kEventRawKeyRepeat
:
980 rec
->what
= autoKey
;
982 case kEventRawKeyUp
:
985 case kEventRawKeyModifiersChanged
:
986 rec
->what
= nullEvent
;
995 unsigned char charCode
;
997 GetMouse( &rec
->where
) ;
999 err
= GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
1000 err
= GetEventParameter(event
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
1001 err
= GetEventParameter(event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
1002 rec
->modifiers
= modifiers
;
1003 rec
->message
= (keyCode
<< 8 ) + charCode
;
1007 case kEventClassTextInput
:
1009 switch( GetEventKind( event
) )
1011 case kEventTextInputUnicodeForKeyEvent
:
1014 err
= GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent
) ;
1018 unsigned char charCode
;
1020 GetMouse( &rec
->where
) ;
1021 rec
->what
= keyDown
;
1022 err
= GetEventParameter(rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
1023 err
= GetEventParameter(rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
1024 err
= GetEventParameter(rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
1025 rec
->modifiers
= modifiers
;
1026 rec
->message
= (keyCode
<< 8 ) + charCode
;
1042 pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
1044 OSStatus result = eventNotHandledErr ;
1047 switch ( GetEventClass( event ) )
1049 case kEventClassKeyboard :
1050 if ( wxMacConvertEventToRecord( event , &rec ) )
1052 wxTheApp->MacHandleModifierEvents( &rec ) ;
1053 wxTheApp->MacHandleOneEvent( &rec ) ;
1057 case kEventClassTextInput :
1058 if ( wxMacConvertEventToRecord( event , &rec ) )
1060 wxTheApp->MacHandleModifierEvents( &rec ) ;
1061 wxTheApp->MacHandleOneEvent( &rec ) ;
1075 m_printMode
= wxPRINT_WINDOWS
;
1078 m_macCurrentEvent
= NULL
;
1080 m_macCurrentEventHandlerCallRef
= NULL
;
1084 int wxApp::MainLoop()
1096 void wxApp::ExitMainLoop()
1098 m_keepGoing
= FALSE
;
1101 // Is a message/event pending?
1102 bool wxApp::Pending()
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
.m_timeStamp
= 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( 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( 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
1850 // wxHIDKeyboard keyboard;
1851 // return keyboard.IsActive(key);
1853 // TODO: Have it use HID Manager on OSX...
1854 //if OS X > 10.2 (i.e. 10.2.x)
1855 //a known apple bug prevents the system from determining led
1856 //states with GetKeys... can only determine caps lock led
1857 return !!(GetCurrentKeyModifiers() & wxKeyCodeToMacModifier(key
));
1859 // KeyMapByteArray keymap;
1860 // GetKeys((BigEndianLong*)keymap);
1861 // return !!(BitTst(keymap, (sizeof(KeyMapByteArray)*8) - iKey));
1866 void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr
)
1868 EventRecord
* ev
= (EventRecord
*) evr
;
1869 wxToolTip::RemoveToolTips() ;
1871 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1872 if ( HiWord( menuresult
) )
1874 if ( !s_macIsInModalLoop
)
1875 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1879 wxWindow
* focus
= wxWindow::FindFocus() ;
1881 if ( MacSendKeyDownEvent( focus
, ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) == false )
1884 // we must handle control keys the other way round, otherwise text content is updated too late
1885 // has not been handled -> perform default
1886 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
1887 if ( control
&& control
->GetMacControl() != NULL
)
1891 keychar
= short(ev
->message
& charCodeMask
);
1892 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1893 ::HandleControlKey( (ControlHandle
) control
->GetMacControl() , keycode
, keychar
, ev
->modifiers
) ;
1900 void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr
)
1902 EventRecord
* ev
= (EventRecord
*) evr
;
1903 wxToolTip::RemoveToolTips() ;
1905 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1906 if ( HiWord( menuresult
) )
1911 MacSendKeyUpEvent( wxWindow::FindFocus() , ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) ;
1917 bool wxApp::MacSendKeyDownEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
)
1924 keychar
= short(keymessage
& charCodeMask
);
1925 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
1927 if ( modifiers
& ( controlKey
|shiftKey
|optionKey
) )
1929 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1930 // and look at the character after
1932 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
);
1933 keychar
= short(keyInfo
& charCodeMask
);
1934 keycode
= short(keyInfo
& keyCodeMask
) >> 8 ;
1936 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1937 long realkeyval
= keyval
;
1938 if ( keyval
== keychar
)
1940 // 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)
1941 realkeyval
= short(keymessage
& charCodeMask
) ;
1942 keyval
= wxToupper( keyval
) ;
1945 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1946 bool handled
= false ;
1947 event
.m_shiftDown
= modifiers
& shiftKey
;
1948 event
.m_controlDown
= modifiers
& controlKey
;
1949 event
.m_altDown
= modifiers
& optionKey
;
1950 event
.m_metaDown
= modifiers
& cmdKey
;
1951 event
.m_keyCode
= keyval
;
1955 event
.m_timeStamp
= when
;
1956 event
.SetEventObject(focus
);
1957 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1958 if ( handled
&& event
.GetSkipped() )
1965 wxWindow
*ancestor
= focus
;
1968 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1971 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1972 handled
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1975 if (ancestor
->IsTopLevel())
1977 ancestor
= ancestor
->GetParent();
1980 #endif // wxUSE_ACCEL
1984 event
.Skip( FALSE
) ;
1985 event
.SetEventType( wxEVT_CHAR
) ;
1987 event
.m_keyCode
= realkeyval
;
1989 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1990 if ( handled
&& event
.GetSkipped() )
1994 (keyval
== WXK_TAB
) &&
1995 // CS: copied the change below from wxGTK
1996 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
1997 // have this style, yet choose not to process this particular TAB in which
1998 // case TAB must still work as a navigational character
2000 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
2002 (focus
->GetParent()) &&
2003 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
2005 wxNavigationKeyEvent new_event
;
2006 new_event
.SetEventObject( focus
);
2007 new_event
.SetDirection( !event
.ShiftDown() );
2008 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
2009 new_event
.SetWindowChange( event
.ControlDown() );
2010 new_event
.SetCurrentFocus( focus
);
2011 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
2012 if ( handled
&& new_event
.GetSkipped() )
2015 // backdoor handler for default return and command escape
2016 if ( !handled
&& (!focus
->IsKindOf(CLASSINFO(wxControl
) ) || !focus
->MacCanFocus() ) )
2018 // if window is not having a focus still testing for default enter or cancel
2019 // TODO add the UMA version for ActiveNonFloatingWindow
2020 wxWindow
* focus
= wxFindWinFromMacWindow( FrontWindow() ) ;
2023 if ( keyval
== WXK_RETURN
)
2025 wxButton
*def
= wxDynamicCast(focus
->GetDefaultItem(),
2027 if ( def
&& def
->IsEnabled() )
2029 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
2030 event
.SetEventObject(def
);
2031 def
->Command(event
);
2035 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
2036 else if (keyval
== WXK_ESCAPE
|| (keyval
== '.' && modifiers
& cmdKey
) )
2038 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
2039 new_event
.SetEventObject( focus
);
2040 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
2047 bool wxApp::MacSendKeyUpEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
)
2054 keychar
= short(keymessage
& charCodeMask
);
2055 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
2056 if ( modifiers
& ( controlKey
|shiftKey
|optionKey
) )
2058 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
2059 // and look at the character after
2061 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
);
2062 keychar
= short(keyInfo
& charCodeMask
);
2063 keycode
= short(keyInfo
& keyCodeMask
) >> 8 ;
2065 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
2067 if ( keyval
== keychar
)
2069 keyval
= wxToupper( keyval
) ;
2071 bool handled
= false ;
2073 wxKeyEvent
event(wxEVT_KEY_UP
);
2074 event
.m_shiftDown
= modifiers
& shiftKey
;
2075 event
.m_controlDown
= modifiers
& controlKey
;
2076 event
.m_altDown
= modifiers
& optionKey
;
2077 event
.m_metaDown
= modifiers
& cmdKey
;
2078 event
.m_keyCode
= keyval
;
2082 event
.m_timeStamp
= when
;
2083 event
.SetEventObject(focus
);
2084 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
2090 void wxApp::MacHandleActivateEvent( WXEVENTREF evr
)
2092 EventRecord
* ev
= (EventRecord
*) evr
;
2093 WindowRef window
= (WindowRef
) ev
->message
;
2096 bool activate
= (ev
->modifiers
& activeFlag
) ;
2097 WindowClass wclass
;
2098 ::GetWindowClass ( window
, &wclass
) ;
2099 if ( wclass
== kFloatingWindowClass
)
2101 // if it is a floater we activate/deactivate the front non-floating window instead
2102 window
= ::FrontNonFloatingWindow() ;
2104 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2106 win
->MacActivate( ev
->when
, activate
) ;
2110 void wxApp::MacHandleUpdateEvent( WXEVENTREF evr
)
2112 EventRecord
* ev
= (EventRecord
*) evr
;
2113 WindowRef window
= (WindowRef
) ev
->message
;
2114 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2117 if ( !wxPendingDelete
.Member(win
) )
2118 win
->MacUpdate( ev
->when
) ;
2122 // since there is no way of telling this foreign window to update itself
2123 // we have to invalidate the update region otherwise we keep getting the same
2124 // event over and over again
2125 BeginUpdate( window
) ;
2126 EndUpdate( window
) ;
2130 void wxApp::MacHandleDiskEvent( WXEVENTREF evr
)
2132 EventRecord
* ev
= (EventRecord
*) evr
;
2133 if ( HiWord( ev
->message
) != noErr
)
2137 SetPt( &point
, 100 , 100 ) ;
2139 err
= DIBadMount( point
, ev
->message
) ;
2140 wxASSERT( err
== noErr
) ;
2144 void wxApp::MacHandleOSEvent( WXEVENTREF evr
)
2146 EventRecord
* ev
= (EventRecord
*) evr
;
2147 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
2149 case suspendResumeMessage
:
2151 bool isResuming
= ev
->message
& resumeFlag
;
2152 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
2154 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
2157 WindowRef oldFrontWindow
= NULL
;
2158 WindowRef newFrontWindow
= NULL
;
2160 // in case we don't take care of activating ourselves, we have to synchronize
2161 // our idea of the active window with the process manager's - which it already activated
2163 if ( !doesActivate
)
2164 oldFrontWindow
= ::FrontNonFloatingWindow() ;
2166 MacResume( convertClipboard
) ;
2168 newFrontWindow
= ::FrontNonFloatingWindow() ;
2170 if ( oldFrontWindow
)
2172 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
2174 win
->MacActivate( ev
->when
, false ) ;
2176 if ( newFrontWindow
)
2178 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
2180 win
->MacActivate( ev
->when
, true ) ;
2185 MacSuspend( convertClipboard
) ;
2189 case mouseMovedMessage
:
2193 wxWindow
* currentMouseWindow
= NULL
;
2195 if (s_captureWindow
)
2197 currentMouseWindow
= s_captureWindow
;
2201 wxWindow::MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) ,
2202 ¤tMouseWindow
) ;
2205 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
2207 wxMouseEvent event
;
2209 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
2210 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
2212 event
.m_leftDown
= isDown
&& !controlDown
;
2213 event
.m_middleDown
= FALSE
;
2214 event
.m_rightDown
= isDown
&& controlDown
;
2215 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
2216 event
.m_controlDown
= ev
->modifiers
& controlKey
;
2217 event
.m_altDown
= ev
->modifiers
& optionKey
;
2218 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
2219 event
.m_x
= ev
->where
.h
;
2220 event
.m_y
= ev
->where
.v
;
2221 event
.m_timeStamp
= ev
->when
;
2222 event
.SetEventObject(this);
2224 if ( wxWindow::s_lastMouseWindow
)
2226 wxMouseEvent
eventleave(event
);
2227 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
2228 wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
2229 eventleave
.SetEventObject( wxWindow::s_lastMouseWindow
) ;
2231 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
2233 if ( currentMouseWindow
)
2235 wxMouseEvent
evententer(event
);
2236 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
2237 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
2238 evententer
.SetEventObject( currentMouseWindow
) ;
2239 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
2241 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
2244 short windowPart
= inNoWindow
;
2246 if ( s_captureWindow
)
2248 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
2249 windowPart
= inContent
;
2253 windowPart
= ::FindWindow(ev
->where
, &window
);
2260 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2262 win
->MacMouseMoved( ev
, windowPart
) ;
2269 UMAShowArrowCursor();
2279 UMAShowArrowCursor();
2290 void wxApp::MacHandleMouseMovedEvent(wxInt32 x
, wxInt32 y
,wxUint32 modifiers
, long timestamp
)
2294 wxWindow
* currentMouseWindow
= NULL
;
2296 if (s_captureWindow
)
2298 currentMouseWindow
= s_captureWindow
;
2302 wxWindow::MacGetWindowFromPoint( wxPoint( x
, y
) , ¤tMouseWindow
) ;
2305 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
2307 wxMouseEvent event
;
2309 bool isDown
= !(modifiers
& btnState
) ; // 1 is for up
2310 bool controlDown
= modifiers
& controlKey
; // for simulating right mouse
2312 event
.m_leftDown
= isDown
&& !controlDown
;
2314 event
.m_middleDown
= FALSE
;
2315 event
.m_rightDown
= isDown
&& controlDown
;
2317 event
.m_shiftDown
= modifiers
& shiftKey
;
2318 event
.m_controlDown
= modifiers
& controlKey
;
2319 event
.m_altDown
= modifiers
& optionKey
;
2320 event
.m_metaDown
= modifiers
& cmdKey
;
2324 event
.m_timeStamp
= timestamp
;
2326 if ( wxWindow::s_lastMouseWindow
)
2328 wxMouseEvent
eventleave(event
);
2329 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
2330 wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
2331 eventleave
.SetEventObject( wxWindow::s_lastMouseWindow
) ;
2334 wxToolTip::RelayEvent( wxWindow::s_lastMouseWindow
, eventleave
);
2335 #endif // wxUSE_TOOLTIPS
2336 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
2338 if ( currentMouseWindow
)
2340 wxMouseEvent
evententer(event
);
2341 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
2342 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
2343 evententer
.SetEventObject( currentMouseWindow
) ;
2345 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
2346 #endif // wxUSE_TOOLTIPS
2347 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
2349 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
2352 short windowPart
= inNoWindow
;
2354 if ( s_captureWindow
)
2356 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
2357 windowPart
= inContent
;
2361 Point pt
= { y
, x
} ;
2362 windowPart
= ::FindWindow(pt
, &window
);
2369 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2371 win
->MacFireMouseEvent( nullEvent
, x
, y
, modifiers
, timestamp
) ;
2378 UMAShowArrowCursor();
2388 UMAShowArrowCursor();
2395 void wxApp::MacHandleMenuCommand( wxUint32 id
)
2397 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
2398 wxFrame
* frame
= mbar
->GetFrame();
2399 wxCHECK_RET( mbar
!= NULL
&& frame
!= NULL
, wxT("error in menu item callback") );
2402 frame
->ProcessCommand(id
);
2407 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
2410 return; // no menu item selected
2412 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
2415 Str255 deskAccessoryName
;
2418 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
2419 GetPort(&savedPort
);
2420 OpenDeskAcc(deskAccessoryName
);
2427 GetMenuItemCommandID( GetMenuHandle(macMenuId
) , macMenuItemNum
, &id
) ;
2428 MacHandleMenuCommand( id
) ;