1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "app.h"
18 #include "wx/window.h"
20 #include "wx/button.h"
23 #include "wx/gdicmn.h"
26 #include "wx/cursor.h"
29 #include "wx/palette.h"
31 #include "wx/dialog.h"
32 #include "wx/msgdlg.h"
34 #include "wx/module.h"
35 #include "wx/memory.h"
36 #include "wx/tooltip.h"
37 #include "wx/textctrl.h"
39 #include "wx/docview.h"
53 #include "wx/mac/uma.h"
54 #include "wx/mac/macnotfy.h"
57 # include <CoreServices/CoreServices.h>
58 # if defined(WXMAKINGDLL_CORE)
59 # include <mach-o/dyld.h>
64 # include <ToolUtils.h>
65 # include <DiskInit.h>
69 extern wxList wxPendingDelete
;
70 extern wxList
*wxWinMacWindowList
;
71 extern wxList
*wxWinMacControlList
;
73 // statics for implementation
75 static bool s_inYield
= FALSE
;
78 static bool s_inReceiveEvent
= FALSE
;
79 static EventTime sleepTime
= kEventDurationNoWait
;
81 static long sleepTime
= 0 ;
84 #if !USE_SHARED_LIBRARY
85 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
86 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
87 EVT_IDLE(wxApp::OnIdle
)
88 EVT_END_SESSION(wxApp::OnEndSession
)
89 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
94 const short kMacMinHeap
= (29 * 1024) ;
95 // platform specific static variables
97 const short kwxMacMenuBarResource
= 1 ;
98 const short kwxMacAppleMenuId
= 1 ;
100 WXHRGN
wxApp::s_macCursorRgn
= NULL
;
101 wxWindow
* wxApp::s_captureWindow
= NULL
;
102 int wxApp::s_lastMouseDown
= 0 ;
103 long wxApp::sm_lastMessageTime
= 0;
104 long wxApp::s_lastModifiers
= 0 ;
107 bool wxApp::s_macDefaultEncodingIsPC
= true ;
108 bool wxApp::s_macSupportPCMenuShortcuts
= true ;
109 long wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
110 long wxApp::s_macPreferencesMenuItemId
= 0 ;
111 long wxApp::s_macExitMenuItemId
= wxID_EXIT
;
112 wxString
wxApp::s_macHelpMenuTitleName
= wxT("&Help") ;
114 //----------------------------------------------------------------------
115 // Core Apple Event Support
116 //----------------------------------------------------------------------
118 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
119 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
120 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
121 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
123 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
125 return wxTheApp
->MacHandleAEODoc( (AppleEvent
*) event
, reply
) ;
128 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
130 return wxTheApp
->MacHandleAEOApp( (AppleEvent
*) event
, reply
) ;
133 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
135 return wxTheApp
->MacHandleAEPDoc( (AppleEvent
*) event
, reply
) ;
138 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
140 return wxTheApp
->MacHandleAEQuit( (AppleEvent
*) event
, reply
) ;
143 // AEODoc Calls MacOpenFile on each of the files passed
145 short wxApp::MacHandleAEODoc(const WXEVENTREF event
, WXEVENTREF
WXUNUSED(reply
))
149 DescType returnedType
;
155 err
= AEGetParamDesc((AppleEvent
*)event
, keyDirectObject
, typeAEList
,&docList
);
159 err
= AECountItems(&docList
, &itemsInList
);
163 ProcessSerialNumber PSN
;
164 PSN
.highLongOfPSN
= 0 ;
165 PSN
.lowLongOfPSN
= kCurrentProcess
;
166 SetFrontProcess( &PSN
) ;
168 for (i
= 1; i
<= itemsInList
; i
++) {
169 AEGetNthPtr(&docList
, i
, typeFSS
, &keywd
, &returnedType
,
170 (Ptr
) & theSpec
, sizeof(theSpec
), &actualSize
);
171 wxString fName
= wxMacFSSpec2MacFilename(&theSpec
);
177 // AEPDoc Calls MacPrintFile on each of the files passed
179 short wxApp::MacHandleAEPDoc(const WXEVENTREF event
, WXEVENTREF
WXUNUSED(reply
))
183 DescType returnedType
;
189 err
= AEGetParamDesc((AppleEvent
*)event
, keyDirectObject
, typeAEList
,&docList
);
193 err
= AECountItems(&docList
, &itemsInList
);
197 ProcessSerialNumber PSN
;
198 PSN
.highLongOfPSN
= 0 ;
199 PSN
.lowLongOfPSN
= kCurrentProcess
;
200 SetFrontProcess( &PSN
) ;
202 for (i
= 1; i
<= itemsInList
; i
++) {
203 AEGetNthPtr(&docList
, i
, typeFSS
, &keywd
, &returnedType
,
204 (Ptr
) & theSpec
, sizeof(theSpec
), &actualSize
);
205 wxString fName
= wxMacFSSpec2MacFilename(&theSpec
);
211 // AEOApp calls MacNewFile
213 short wxApp::MacHandleAEOApp(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
219 // AEQuit attempts to quit the application
221 short wxApp::MacHandleAEQuit(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
223 /* wxWindow* win = GetTopWindow() ;
236 //----------------------------------------------------------------------
237 // Support Routines linking the Mac...File Calls to the Document Manager
238 //----------------------------------------------------------------------
240 void wxApp::MacOpenFile(const wxString
& fileName
)
242 wxDocManager
* dm
= wxDocManager::GetDocumentManager() ;
244 dm
->CreateDocument(fileName
, wxDOC_SILENT
) ;
247 void wxApp::MacPrintFile(const wxString
& fileName
)
249 wxDocManager
* dm
= wxDocManager::GetDocumentManager() ;
252 wxDocument
*doc
= dm
->CreateDocument(fileName
, wxDOC_SILENT
) ;
255 wxView
* view
= doc
->GetFirstView() ;
258 wxPrintout
*printout
= view
->OnCreatePrintout();
262 printer
.Print(view
->GetFrame(), printout
, TRUE
);
268 doc
->DeleteAllViews();
269 dm
->RemoveDocument(doc
) ;
275 void wxApp::MacNewFile()
279 //----------------------------------------------------------------------
280 // Carbon Event Handler
281 //----------------------------------------------------------------------
285 static const EventTypeSpec eventList
[] =
287 { kEventClassCommand
, kEventProcessCommand
} ,
288 { kEventClassCommand
, kEventCommandUpdateStatus
} ,
290 { kEventClassMenu
, kEventMenuOpening
},
291 { kEventClassMenu
, kEventMenuClosed
},
293 { kEventClassApplication
, kEventAppActivated
} ,
294 { kEventClassApplication
, kEventAppDeactivated
} ,
295 // handling the quit event is not recommended by apple
296 // rather using the quit apple event - which we do
298 { kEventClassAppleEvent
, kEventAppleEvent
} ,
300 { kEventClassMouse
, kEventMouseDown
} ,
304 static pascal OSStatus
305 MenuEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
307 // FIXME: this doesn't work for multiple windows
308 wxWindow
*win
= wxTheApp
->GetTopWindow();
311 // VZ: we could find the menu from its handle here by examining all
312 // the menus in the menu bar recursively but knowing that neither
313 // wxMSW nor wxGTK do it why bother...
317 GetEventParameter(event
,
318 kEventParamDirectObject
,
320 sizeof(menuRef
), NULL
,
324 wxMenuEvent
wxevent(GetEventKind(event
) == kEventMenuOpening
327 wxevent
.SetEventObject(win
);
329 (void)win
->GetEventHandler()->ProcessEvent(wxevent
);
332 return eventNotHandledErr
;
335 // due to the rather low-level event API of wxWindows, we cannot use RunApplicationEventLoop
336 // but have to use ReceiveNextEvent dealing with events manually, therefore we also have
337 // deal with clicks in the menu bar explicitely
339 static pascal OSStatus
MouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
341 OSStatus result
= eventNotHandledErr
;
343 switch( GetEventKind(event
) )
345 case kEventMouseDown
:
350 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
351 sizeof( Point
), NULL
, &point
);
352 short windowPart
= ::FindWindow(point
, &window
);
354 if ( windowPart
== inMenuBar
)
356 MenuSelect( point
) ;
366 static pascal OSStatus
CommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
368 OSStatus result
= eventNotHandledErr
;
372 GetEventParameter( event
, kEventParamDirectObject
, typeHICommand
, NULL
,
373 sizeof( HICommand
), NULL
, &command
);
375 MenuCommand id
= command
.commandID
;
376 if ( id
== kHICommandPreferences
)
377 id
= wxApp::s_macPreferencesMenuItemId
;
379 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
380 wxMenu
* menu
= NULL
;
381 wxMenuItem
* item
= NULL
;
384 item
= mbar
->FindItem( id
, &menu
) ;
386 if ( item
== NULL
|| menu
== NULL
|| mbar
== NULL
)
389 switch( GetEventKind( event
) )
391 case kEventProcessCommand
:
393 if (item
->IsCheckable())
395 item
->Check( !item
->IsChecked() ) ;
398 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
402 case kEventCommandUpdateStatus
:
403 // eventually trigger an updateui round
413 static pascal OSStatus
ApplicationEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
415 OSStatus result
= eventNotHandledErr
;
416 switch ( GetEventKind( event
) )
418 case kEventAppActivated
:
421 wxTheApp
->MacResume( true ) ;
425 case kEventAppDeactivated
:
428 wxTheApp
->MacSuspend( true ) ;
438 pascal OSStatus
wxAppEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
440 OSStatus result
= eventNotHandledErr
;
441 switch( GetEventClass( event
) )
443 case kEventClassCommand
:
444 result
= CommandEventHandler( handler
, event
, data
) ;
446 case kEventClassApplication
:
447 result
= ApplicationEventHandler( handler
, event
, data
) ;
449 case kEventClassMenu
:
450 result
= MenuEventHandler( handler
, event
, data
) ;
452 case kEventClassMouse
:
453 result
= MouseEventHandler( handler
, event
, data
) ;
455 case kEventClassAppleEvent
:
458 wxMacConvertEventToRecord( event
, &rec
) ;
459 result
= AEProcessAppleEvent( &rec
) ;
469 DEFINE_ONE_SHOT_HANDLER_GETTER( wxAppEventHandler
)
473 #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
474 // we know it's there ;-)
475 WXIMPORT
char std::__throws_bad_alloc
;
478 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
484 UMAInitToolbox( 4 ) ;
485 SetEventMask( everyEvent
) ;
486 UMAShowWatchCursor() ;
488 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
489 // open shared library resources from here since we don't have
490 // __wxinitialize in Mach-O shared libraries
491 wxStAppResource::OpenSharedLibraryResource(NULL
);
495 // test the minimal configuration necessary
501 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
503 error
= kMacSTRWrongMachine
;
505 else if (theMachine
< gestaltMacPlus
)
507 error
= kMacSTRWrongMachine
;
509 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
511 error
= kMacSTROldSystem
;
513 else if ( theSystem
< 0x0860 )
515 error
= kMacSTROldSystem
;
517 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
519 error
= kMacSTRSmallSize
;
525 if ( !UMAHasAppearance() )
527 error = kMacSTRNoPre8Yet ;
533 // if we encountered any problems so far, give the error code and exit immediately
537 wxStAppResource resload
;
541 GetIndString(message
, 128, error
);
542 UMAShowArrowCursor() ;
543 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
544 itemHit
= Alert(128, nil
);
549 # if __option(profile)
550 ProfilerInit( collectDetailed
, bestTimeBase
, 20000 , 40 ) ;
555 // now avoid exceptions thrown for new (bad_alloc)
556 // FIXME CS for some changes outside wxMac does not compile anymore
558 std::__throws_bad_alloc
= 0 ;
562 wxMacSetupConverters() ;
564 s_macCursorRgn
= ::NewRgn() ;
566 // Mac OS X passes a process serial number command line argument when
567 // the application is launched from the Finder. This argument must be
568 // removed from the command line arguments before being handled by the
569 // application (otherwise applications would need to handle it)
572 static const wxChar
*ARG_PSN
= _T("-psn_");
573 if ( wxStrncmp(argv
[1], ARG_PSN
, sizeof(ARG_PSN
) - 1) == 0 )
575 // remove this argument
576 memmove(argv
, argv
+ 1, argc
--);
580 if ( !wxAppBase::Initialize(argc
, argv
) )
583 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
584 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
586 wxMacCreateNotifierTable() ;
588 UMAShowArrowCursor() ;
593 bool wxApp::OnInitGui()
595 if( !wxAppBase::OnInitGui() )
599 InstallStandardEventHandler( GetApplicationEventTarget() ) ;
601 InstallApplicationEventHandler(
602 GetwxAppEventHandlerUPP(),
603 GetEventTypeCount(eventList
), eventList
, wxTheApp
, (EventHandlerRef
*)&(wxTheApp
->m_macEventHandler
));
606 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
607 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
608 NewAEEventHandlerUPP(AEHandleODoc
) ,
610 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
611 NewAEEventHandlerUPP(AEHandleOApp
) ,
613 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
614 NewAEEventHandlerUPP(AEHandlePDoc
) ,
616 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
617 NewAEEventHandlerUPP(AEHandleQuit
) ,
620 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
621 NewAEEventHandlerProc(AEHandleODoc
) ,
623 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
624 NewAEEventHandlerProc(AEHandleOApp
) ,
626 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
627 NewAEEventHandlerProc(AEHandlePDoc
) ,
629 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
630 NewAEEventHandlerProc(AEHandleQuit
) ,
637 void wxApp::CleanUp()
639 wxToolTip::RemoveToolTips() ;
641 // One last chance for pending objects to be cleaned up
642 wxTheApp
->DeletePendingObjects();
644 wxMacDestroyNotifierTable() ;
646 delete wxWinMacWindowList
;
647 wxWinMacWindowList
= NULL
;
649 delete wxWinMacControlList
;
650 wxWinMacControlList
= NULL
;
653 # if __option(profile)
654 ProfilerDump( (StringPtr
)"\papp.prof" ) ;
659 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
660 // close shared library resources from here since we don't have
661 // __wxterminate in Mach-O shared libraries
662 wxStAppResource::CloseSharedLibraryResource();
664 wxMacCleanupConverters() ;
666 UMACleanupToolbox() ;
667 if (s_macCursorRgn
) {
668 ::DisposeRgn((RgnHandle
)s_macCursorRgn
);
675 wxAppBase::CleanUp();
678 //----------------------------------------------------------------------
679 // misc initialization stuff
680 //----------------------------------------------------------------------
682 // extern variable for shared library resource id
683 // need to be able to find it with NSLookupAndBindSymbol
684 short gSharedLibraryResource
= kResFileNotOpened
;
686 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
687 CFBundleRef gSharedLibraryBundle
= NULL
;
688 #endif /* WXMAKINGDLL_CORE && __DARWIN__ */
690 wxStAppResource::wxStAppResource()
692 m_currentRefNum
= CurResFile() ;
693 if ( gSharedLibraryResource
!= kResFileNotOpened
)
695 UseResFile( gSharedLibraryResource
) ;
699 wxStAppResource::~wxStAppResource()
701 if ( m_currentRefNum
!= kResFileNotOpened
)
703 UseResFile( m_currentRefNum
) ;
707 void wxStAppResource::OpenSharedLibraryResource(const void *initBlock
)
709 gSharedLibraryResource
= kResFileNotOpened
;
711 #ifdef WXMAKINGDLL_CORE
712 if ( initBlock
!= NULL
) {
713 const CFragInitBlock
*theInitBlock
= (const CFragInitBlock
*)initBlock
;
714 FSSpec
*fileSpec
= NULL
;
716 if (theInitBlock
->fragLocator
.where
== kDataForkCFragLocator
) {
717 fileSpec
= theInitBlock
->fragLocator
.u
.onDisk
.fileSpec
;
719 else if (theInitBlock
->fragLocator
.where
== kResourceCFragLocator
) {
720 fileSpec
= theInitBlock
->fragLocator
.u
.inSegs
.fileSpec
;
723 if (fileSpec
!= NULL
) {
724 gSharedLibraryResource
= FSpOpenResFile(fileSpec
, fsRdPerm
);
729 // Open the shared library resource file if it is not yet open
732 const char *theLibPath
;
734 gSharedLibraryBundle
= CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWindows"));
735 if (gSharedLibraryBundle
!= NULL
) {
736 // wxWindows has been bundled into a framework
737 // load the framework resources
739 gSharedLibraryResource
= CFBundleOpenBundleResourceMap(gSharedLibraryBundle
);
742 // wxWindows is a simple dynamic shared library
743 // load the resources from the data fork of a separate resource file
747 OSErr theErr
= noErr
;
749 // get the library path
750 theSymbol
= NSLookupAndBindSymbol("_gSharedLibraryResource");
751 theModule
= NSModuleForSymbol(theSymbol
);
752 theLibPath
= NSLibraryNameForModule(theModule
);
754 // if we call wxLogDebug from here then, as wxTheApp hasn't been
755 // created yet when we're called from wxApp::Initialize(), wxLog
756 // is going to create a default stderr-based log target instead of
757 // the expected normal GUI one -- don't do it, if we really want
758 // to see this message just use fprintf() here
760 wxLogDebug( wxT("wxMac library installation name is '%s'"),
764 // allocate copy to replace .dylib.* extension with .rsrc
765 if (theLibPath
!= NULL
) {
766 theResPath
= theLibPath
;
767 // replace '_core' with '' in case of multi-lib build
768 theResPath
.Replace(wxT("_core"), wxEmptyString
);
769 // replace ".dylib" shared library extension with ".rsrc"
770 theResPath
.Replace(wxT(".dylib"), wxT(".rsrc"));
771 // Find the begining of the filename
772 theName
= theResPath
.AfterLast('/');
775 wxLogDebug( wxT("wxMac resources file name is '%s'"),
776 theResPath
.mb_str() );
779 theErr
= FSPathMakeRef((UInt8
*) theResPath
.mb_str(), &theResRef
, false);
780 if (theErr
!= noErr
) {
781 // try in current directory (using name only)
782 theErr
= FSPathMakeRef((UInt8
*) theName
.mb_str(), &theResRef
, false);
785 // open the resource file
786 if (theErr
== noErr
) {
787 theErr
= FSOpenResourceFile( &theResRef
, 0, NULL
, fsRdPerm
,
788 &gSharedLibraryResource
);
790 if (theErr
!= noErr
) {
793 wxT("unable to open wxMac resource file '%s'\n"),
794 theResPath
.mb_str() );
795 #endif // __WXDEBUG__
800 #endif /* __DARWIN__ */
802 #endif /* WXMAKINGDLL_CORE */
805 void wxStAppResource::CloseSharedLibraryResource()
807 #ifdef WXMAKINGDLL_CORE
808 // Close the shared library resource file
809 if (gSharedLibraryResource
!= kResFileNotOpened
) {
811 if (gSharedLibraryBundle
!= NULL
) {
812 CFBundleCloseBundleResourceMap(gSharedLibraryBundle
,
813 gSharedLibraryResource
);
814 gSharedLibraryBundle
= NULL
;
817 #endif /* __DARWIN__ */
819 CloseResFile(gSharedLibraryResource
);
821 gSharedLibraryResource
= kResFileNotOpened
;
823 #endif /* WXMAKINGDLL_CORE */
826 #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
828 // for shared libraries we have to manually get the correct resource
829 // ref num upon initializing and releasing when terminating, therefore
830 // the __wxinitialize and __wxterminate must be used
833 void __sinit(void); /* (generated by linker) */
834 pascal OSErr
__initialize(const CFragInitBlock
*theInitBlock
);
835 pascal void __terminate(void);
838 pascal OSErr
__wxinitialize(const CFragInitBlock
*theInitBlock
)
840 wxStAppResource::OpenSharedLibraryResource( theInitBlock
) ;
841 return __initialize( theInitBlock
) ;
844 pascal void __wxterminate(void)
846 wxStAppResource::CloseSharedLibraryResource() ;
850 #endif /* WXMAKINGDLL_CORE && !__DARWIN__ */
854 bool wxMacConvertEventToRecord( EventRef event
, EventRecord
*rec
)
856 bool converted
= ConvertEventRefToEventRecord( event
,rec
) ;
857 OSStatus err
= noErr
;
860 switch( GetEventClass( event
) )
862 case kEventClassKeyboard
:
865 switch( GetEventKind(event
) )
867 case kEventRawKeyDown
:
868 rec
->what
= keyDown
;
870 case kEventRawKeyRepeat
:
871 rec
->what
= autoKey
;
873 case kEventRawKeyUp
:
876 case kEventRawKeyModifiersChanged
:
877 rec
->what
= nullEvent
;
886 unsigned char charCode
;
888 GetMouse( &rec
->where
) ;
890 err
= GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
891 err
= GetEventParameter(event
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
892 err
= GetEventParameter(event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
893 rec
->modifiers
= modifiers
;
894 rec
->message
= (keyCode
<< 8 ) + charCode
;
898 case kEventClassTextInput
:
900 switch( GetEventKind( event
) )
902 case kEventTextInputUnicodeForKeyEvent
:
905 err
= GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent
) ;
909 unsigned char charCode
;
911 GetMouse( &rec
->where
) ;
912 rec
->what
= keyDown
;
913 err
= GetEventParameter(rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
914 err
= GetEventParameter(rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
915 err
= GetEventParameter(rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
916 rec
->modifiers
= modifiers
;
917 rec
->message
= (keyCode
<< 8 ) + charCode
;
933 pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
935 OSStatus result = eventNotHandledErr ;
938 switch ( GetEventClass( event ) )
940 case kEventClassKeyboard :
941 if ( wxMacConvertEventToRecord( event , &rec ) )
943 wxTheApp->MacHandleModifierEvents( &rec ) ;
944 wxTheApp->MacHandleOneEvent( &rec ) ;
948 case kEventClassTextInput :
949 if ( wxMacConvertEventToRecord( event , &rec ) )
951 wxTheApp->MacHandleModifierEvents( &rec ) ;
952 wxTheApp->MacHandleOneEvent( &rec ) ;
966 m_printMode
= wxPRINT_WINDOWS
;
969 m_macCurrentEvent
= NULL
;
970 m_macCurrentEventHandlerCallRef
= NULL
;
973 bool wxApp::Initialized()
981 int wxApp::MainLoop()
993 void wxApp::ExitMainLoop()
998 // Is a message/event pending?
999 bool wxApp::Pending()
1002 return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ;
1006 return EventAvail( everyEvent
, &event
) ;
1010 // Dispatch a message.
1011 void wxApp::Dispatch()
1016 void wxApp::OnIdle(wxIdleEvent
& event
)
1018 wxAppBase::OnIdle(event
);
1020 // If they are pending events, we must process them: pending events are
1021 // either events to the threads other than main or events posted with
1022 // wxPostEvent() functions
1023 wxMacProcessNotifierAndPendingEvents();
1025 if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
1026 wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
1029 void wxApp::WakeUpIdle()
1040 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
1043 GetTopWindow()->Close(TRUE
);
1046 // Default behaviour: close the application with prompts. The
1047 // user can veto the close, and therefore the end session.
1048 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
1052 if (!GetTopWindow()->Close(!event
.CanVeto()))
1057 extern "C" void wxCYield() ;
1063 // Yield to other processes
1065 bool wxApp::Yield(bool onlyIfNeeded
)
1069 if ( !onlyIfNeeded
)
1071 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1080 YieldToAnyThread() ;
1082 // by definition yield should handle all non-processed events
1086 OSStatus status
= noErr
;
1089 s_inReceiveEvent
= true ;
1090 status
= ReceiveNextEvent(0, NULL
,kEventDurationNoWait
,true,&theEvent
) ;
1091 s_inReceiveEvent
= false ;
1093 if ( status
== eventLoopTimedOutErr
)
1095 // make sure next time the event loop will trigger idle events
1096 sleepTime
= kEventDurationNoWait
;
1098 else if ( status
== eventLoopQuitErr
)
1100 // according to QA1061 this may also occur when a WakeUp Process
1105 MacHandleOneEvent( theEvent
) ;
1106 ReleaseEvent(theEvent
);
1108 } while( status
== noErr
) ;
1112 // having a larger value here leads to large performance slowdowns
1113 // so we cannot give background apps more processor time here
1114 // we do so however having a large sleep value in the main event loop
1117 while ( !IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, (RgnHandle
) wxApp::s_macCursorRgn
))
1119 MacHandleModifierEvents( &event
) ;
1120 MacHandleOneEvent( &event
);
1121 if ( event
.what
!= kHighLevelEvent
)
1122 SetRectRgn( (RgnHandle
) wxApp::s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1124 MacHandleModifierEvents( &event
) ;
1127 wxMacProcessNotifierAndPendingEvents() ;
1133 // platform specifics
1135 void wxApp::MacSuspend( bool convertClipboard
)
1138 // we have to deactive the top level windows manually
1140 wxWindowListNode
* node
= wxTopLevelWindows
.GetFirst();
1143 wxTopLevelWindow
* win
= (wxTopLevelWindow
*) node
->Data();
1145 #if 0 // having problems right now with that
1146 if (!win
->HasFlag(wxSTAY_ON_TOP
))
1149 win
->MacActivate( ((EventRecord
*) MacGetCurrentEvent())->when
, false ) ;
1151 node
= node
->GetNext();
1154 ::HideFloatingWindows() ;
1156 s_lastMouseDown
= 0 ;
1158 if( convertClipboard
)
1160 MacConvertPrivateToPublicScrap() ;
1164 extern wxList wxModalDialogs
;
1166 void wxApp::MacResume( bool convertClipboard
)
1168 s_lastMouseDown
= 0 ;
1169 if( convertClipboard
)
1171 MacConvertPublicToPrivateScrap() ;
1175 ::ShowFloatingWindows() ;
1176 // raise modal dialogs in case a non modal window was selected to activate the app
1178 wxNode
* node
= wxModalDialogs
.GetFirst();
1181 wxDialog
* dialog
= (wxDialog
*) node
->GetData();
1184 node
= node
->GetNext();
1189 void wxApp::MacConvertPrivateToPublicScrap()
1193 void wxApp::MacConvertPublicToPrivateScrap()
1197 void wxApp::MacDoOneEvent()
1202 s_inReceiveEvent
= true ;
1203 OSStatus status
= ReceiveNextEvent(0, NULL
,sleepTime
,true,&theEvent
) ;
1204 s_inReceiveEvent
= false ;
1205 if ( status
== eventLoopTimedOutErr
)
1207 if ( wxTheApp
->ProcessIdle() )
1208 sleepTime
= kEventDurationNoWait
;
1210 sleepTime
= kEventDurationForever
;
1212 else if ( status
== eventLoopQuitErr
)
1214 // according to QA1061 this may also occur when a WakeUp Process
1219 MacHandleOneEvent( theEvent
) ;
1220 ReleaseEvent(theEvent
);
1221 sleepTime
= kEventDurationNoWait
;
1226 EventMask eventMask
= everyEvent
;
1228 if (WaitNextEvent(eventMask
, &event
, sleepTime
, (RgnHandle
) s_macCursorRgn
))
1230 MacHandleModifierEvents( &event
) ;
1231 MacHandleOneEvent( &event
);
1235 MacHandleModifierEvents( &event
) ;
1237 WindowPtr window
= ::FrontWindow() ;
1239 ::IdleControls( window
) ;
1241 if ( wxTheApp
->ProcessIdle() )
1244 sleepTime
= GetCaretTime() / 2 ;
1246 if ( event
.what
!= kHighLevelEvent
)
1247 SetRectRgn( (RgnHandle
) s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1251 DeletePendingObjects() ;
1252 wxMacProcessNotifierAndPendingEvents() ;
1255 void wxApp::MacHandleOneEvent( WXEVENTREF evr
)
1258 EventTargetRef theTarget
;
1259 theTarget
= GetEventDispatcherTarget();
1260 m_macCurrentEvent
= evr
;
1261 SendEventToEventTarget ((EventRef
) evr
, theTarget
);
1263 EventRecord
* ev
= (EventRecord
*) evr
;
1264 m_macCurrentEvent
= ev
;
1266 wxApp::sm_lastMessageTime
= ev
->when
;
1271 MacHandleMouseDownEvent( ev
) ;
1272 if ( ev
->modifiers
& controlKey
)
1273 s_lastMouseDown
= 2;
1275 s_lastMouseDown
= 1;
1278 if ( s_lastMouseDown
== 2 )
1280 ev
->modifiers
|= controlKey
;
1284 ev
->modifiers
&= ~controlKey
;
1286 MacHandleMouseUpEvent( ev
) ;
1287 s_lastMouseDown
= 0;
1290 MacHandleActivateEvent( ev
) ;
1293 MacHandleUpdateEvent( ev
) ;
1297 MacHandleKeyDownEvent( ev
) ;
1300 MacHandleKeyUpEvent( ev
) ;
1303 MacHandleDiskEvent( ev
) ;
1306 MacHandleOSEvent( ev
) ;
1308 case kHighLevelEvent
:
1309 MacHandleHighLevelEvent( ev
) ;
1315 wxMacProcessNotifierAndPendingEvents() ;
1319 bool s_macIsInModalLoop
= false ;
1321 void wxApp::MacHandleModifierEvents( WXEVENTREF evr
)
1323 EventRecord
* ev
= (EventRecord
*) evr
;
1324 if ( ev
->modifiers
!= s_lastModifiers
&& wxWindow::FindFocus() != NULL
)
1326 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1328 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1329 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1330 event
.m_altDown
= ev
->modifiers
& optionKey
;
1331 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1333 event
.m_x
= ev
->where
.h
;
1334 event
.m_y
= ev
->where
.v
;
1335 event
.m_timeStamp
= ev
->when
;
1336 wxWindow
* focus
= wxWindow::FindFocus() ;
1337 event
.SetEventObject(focus
);
1339 if ( (ev
->modifiers
^ s_lastModifiers
) & controlKey
)
1341 event
.m_keyCode
= WXK_CONTROL
;
1342 event
.SetEventType( ( ev
->modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1343 focus
->GetEventHandler()->ProcessEvent( event
) ;
1345 if ( (ev
->modifiers
^ s_lastModifiers
) & shiftKey
)
1347 event
.m_keyCode
= WXK_SHIFT
;
1348 event
.SetEventType( ( ev
->modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1349 focus
->GetEventHandler()->ProcessEvent( event
) ;
1351 if ( (ev
->modifiers
^ s_lastModifiers
) & optionKey
)
1353 event
.m_keyCode
= WXK_ALT
;
1354 event
.SetEventType( ( ev
->modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1355 focus
->GetEventHandler()->ProcessEvent( event
) ;
1357 if ( ev
->modifiers
^ s_lastModifiers
) & cmdKey
)
1359 event
.m_keyCode
= WXK_COMMAND
;
1360 event
.SetEventType( ( ev
->modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1361 focus
->GetEventHandler()->ProcessEvent( event
) ;
1363 s_lastModifiers
= ev
->modifiers
;
1367 void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr
)
1369 // we must avoid reentrancy problems when processing high level events eg printing
1370 bool former
= s_inYield
;
1372 EventRecord
* ev
= (EventRecord
*) evr
;
1373 ::AEProcessAppleEvent( ev
) ;
1374 s_inYield
= former
;
1377 void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr
)
1379 EventRecord
* ev
= (EventRecord
*) evr
;
1380 wxToolTip::RemoveToolTips() ;
1383 WindowRef frontWindow
= ::FrontNonFloatingWindow() ;
1384 WindowAttributes frontWindowAttributes
= NULL
;
1386 ::GetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
1388 short windowPart
= ::FindWindow(ev
->where
, &window
);
1389 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1390 if ( wxPendingDelete
.Member(win
) )
1394 GetQDGlobalsScreenBits( &screenBits
);
1399 if ( s_macIsInModalLoop
)
1405 UInt32 menuresult
= MenuSelect(ev
->where
) ;
1406 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1407 s_lastMouseDown
= 0;
1411 SystemClick( ev
, window
) ;
1412 s_lastMouseDown
= 0;
1415 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1421 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1426 Point pt
= { 0, 0 } ;
1427 SetPortWindowPort(window
) ;
1428 LocalToGlobal( &pt
) ;
1430 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1431 -1 , wxSIZE_USE_EXISTING
);
1433 s_lastMouseDown
= 0;
1437 if (TrackGoAway(window
, ev
->where
))
1442 s_lastMouseDown
= 0;
1446 Rect newContentRect
;
1447 Rect constraintRect
;
1448 constraintRect
.top
= win
->GetMinHeight() ;
1449 if ( constraintRect
.top
== -1 )
1450 constraintRect
.top
= 0 ;
1451 constraintRect
.left
= win
->GetMinWidth() ;
1452 if ( constraintRect
.left
== -1 )
1453 constraintRect
.left
= 0 ;
1454 constraintRect
.right
= win
->GetMaxWidth() ;
1455 if ( constraintRect
.right
== -1 )
1456 constraintRect
.right
= 32000 ;
1457 constraintRect
.bottom
= win
->GetMaxHeight() ;
1458 if ( constraintRect
.bottom
== -1 )
1459 constraintRect
.bottom
= 32000 ;
1461 Boolean growResult
= ResizeWindow( window
, ev
->where
,
1462 &constraintRect
, &newContentRect
) ;
1465 win
->SetSize( newContentRect
.left
, newContentRect
.top
,
1466 newContentRect
.right
- newContentRect
.left
,
1467 newContentRect
.bottom
- newContentRect
.top
, wxSIZE_USE_EXISTING
);
1469 s_lastMouseDown
= 0;
1474 if (TrackBox(window
, ev
->where
, windowPart
))
1476 // TODO setup size event
1477 ZoomWindow( window
, windowPart
, false ) ;
1483 Point pt
= { 0, 0 } ;
1484 SetPortWindowPort(window
) ;
1485 LocalToGlobal( &pt
) ;
1488 GetWindowPortBounds(window
, &tempRect
) ;
1489 win
->SetSize( pt
.h
, pt
.v
, tempRect
.right
-tempRect
.left
,
1490 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1493 s_lastMouseDown
= 0;
1495 case inCollapseBox
:
1496 // TODO setup size event
1497 s_lastMouseDown
= 0;
1504 SetPortWindowPort(window
) ;
1507 if ( window
!= frontWindow
&& wxTheApp
->s_captureWindow
== NULL
)
1509 if ( s_macIsInModalLoop
)
1513 else if ( UMAIsWindowFloating( window
) )
1516 win
->MacMouseDown( ev
, windowPart
) ;
1521 win
->MacMouseDown( ev
, windowPart
) ;
1522 ::SelectWindow( window
) ;
1528 win
->MacMouseDown( ev
, windowPart
) ;
1536 void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr
)
1538 EventRecord
* ev
= (EventRecord
*) evr
;
1541 short windowPart
= inNoWindow
;
1542 if ( wxTheApp
->s_captureWindow
)
1544 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
1545 windowPart
= inContent
;
1549 windowPart
= ::FindWindow(ev
->where
, &window
) ;
1560 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1562 win
->MacMouseUp( ev
, windowPart
) ;
1570 long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
1571 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1576 case kHomeCharCode
:
1579 case kEnterCharCode
:
1580 retval
= WXK_RETURN
;
1585 case kHelpCharCode
:
1588 case kBackspaceCharCode
:
1594 case kPageUpCharCode
:
1595 retval
= WXK_PAGEUP
;
1597 case kPageDownCharCode
:
1598 retval
= WXK_PAGEDOWN
;
1600 case kReturnCharCode
:
1601 retval
= WXK_RETURN
;
1603 case kFunctionKeyCharCode
:
1655 case kEscapeCharCode
:
1656 retval
= WXK_ESCAPE
;
1658 case kLeftArrowCharCode
:
1661 case kRightArrowCharCode
:
1662 retval
= WXK_RIGHT
;
1664 case kUpArrowCharCode
:
1667 case kDownArrowCharCode
:
1670 case kDeleteCharCode
:
1671 retval
= WXK_DELETE
;
1680 void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr
)
1682 EventRecord
* ev
= (EventRecord
*) evr
;
1683 wxToolTip::RemoveToolTips() ;
1685 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1686 if ( HiWord( menuresult
) )
1688 if ( !s_macIsInModalLoop
)
1689 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1693 wxWindow
* focus
= wxWindow::FindFocus() ;
1695 if ( MacSendKeyDownEvent( focus
, ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) == false )
1698 // we must handle control keys the other way round, otherwise text content is updated too late
1699 // has not been handled -> perform default
1700 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
1701 if ( control
&& control
->GetMacControl() != NULL
)
1705 keychar
= short(ev
->message
& charCodeMask
);
1706 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1707 ::HandleControlKey( (ControlHandle
) control
->GetMacControl() , keycode
, keychar
, ev
->modifiers
) ;
1714 void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr
)
1716 EventRecord
* ev
= (EventRecord
*) evr
;
1717 wxToolTip::RemoveToolTips() ;
1719 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1720 if ( HiWord( menuresult
) )
1725 MacSendKeyUpEvent( wxWindow::FindFocus() , ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) ;
1731 bool wxApp::MacSendKeyDownEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
)
1738 keychar
= short(keymessage
& charCodeMask
);
1739 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
1741 if ( modifiers
& ( controlKey
|shiftKey
|optionKey
) )
1743 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1744 // and look at the character after
1746 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
);
1747 keychar
= short(keyInfo
& charCodeMask
);
1748 keycode
= short(keyInfo
& keyCodeMask
) >> 8 ;
1750 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1751 long realkeyval
= keyval
;
1752 if ( keyval
== keychar
)
1754 // 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)
1755 realkeyval
= short(keymessage
& charCodeMask
) ;
1756 keyval
= wxToupper( keyval
) ;
1759 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1760 bool handled
= false ;
1761 event
.m_shiftDown
= modifiers
& shiftKey
;
1762 event
.m_controlDown
= modifiers
& controlKey
;
1763 event
.m_altDown
= modifiers
& optionKey
;
1764 event
.m_metaDown
= modifiers
& cmdKey
;
1765 event
.m_keyCode
= keyval
;
1769 event
.m_timeStamp
= when
;
1770 event
.SetEventObject(focus
);
1771 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1772 if ( handled
&& event
.GetSkipped() )
1779 wxWindow
*ancestor
= focus
;
1782 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1785 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1786 handled
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1789 if (ancestor
->IsTopLevel())
1791 ancestor
= ancestor
->GetParent();
1794 #endif // wxUSE_ACCEL
1798 event
.Skip( FALSE
) ;
1799 event
.SetEventType( wxEVT_CHAR
) ;
1801 event
.m_keyCode
= realkeyval
;
1803 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1804 if ( handled
&& event
.GetSkipped() )
1808 (keyval
== WXK_TAB
) &&
1809 // CS: copied the change below from wxGTK
1810 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
1811 // have this style, yet choose not to process this particular TAB in which
1812 // case TAB must still work as a navigational character
1814 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1816 (focus
->GetParent()) &&
1817 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1819 wxNavigationKeyEvent new_event
;
1820 new_event
.SetEventObject( focus
);
1821 new_event
.SetDirection( !event
.ShiftDown() );
1822 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1823 new_event
.SetWindowChange( event
.ControlDown() );
1824 new_event
.SetCurrentFocus( focus
);
1825 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1826 if ( handled
&& new_event
.GetSkipped() )
1829 // backdoor handler for default return and command escape
1830 if ( !handled
&& (!focus
->IsKindOf(CLASSINFO(wxControl
) ) || !focus
->MacCanFocus() ) )
1832 // if window is not having a focus still testing for default enter or cancel
1833 // TODO add the UMA version for ActiveNonFloatingWindow
1834 wxWindow
* focus
= wxFindWinFromMacWindow( FrontWindow() ) ;
1837 if ( keyval
== WXK_RETURN
)
1839 wxButton
*def
= wxDynamicCast(focus
->GetDefaultItem(),
1841 if ( def
&& def
->IsEnabled() )
1843 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
1844 event
.SetEventObject(def
);
1845 def
->Command(event
);
1849 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1850 else if (keyval
== WXK_ESCAPE
|| (keyval
== '.' && modifiers
& cmdKey
) )
1852 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1853 new_event
.SetEventObject( focus
);
1854 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1861 bool wxApp::MacSendKeyUpEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
)
1868 keychar
= short(keymessage
& charCodeMask
);
1869 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
1870 if ( modifiers
& ( controlKey
|shiftKey
|optionKey
) )
1872 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1873 // and look at the character after
1875 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
);
1876 keychar
= short(keyInfo
& charCodeMask
);
1877 keycode
= short(keyInfo
& keyCodeMask
) >> 8 ;
1879 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1881 if ( keyval
== keychar
)
1883 keyval
= wxToupper( keyval
) ;
1885 bool handled
= false ;
1887 wxKeyEvent
event(wxEVT_KEY_UP
);
1888 event
.m_shiftDown
= modifiers
& shiftKey
;
1889 event
.m_controlDown
= modifiers
& controlKey
;
1890 event
.m_altDown
= modifiers
& optionKey
;
1891 event
.m_metaDown
= modifiers
& cmdKey
;
1892 event
.m_keyCode
= keyval
;
1896 event
.m_timeStamp
= when
;
1897 event
.SetEventObject(focus
);
1898 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1904 void wxApp::MacHandleActivateEvent( WXEVENTREF evr
)
1906 EventRecord
* ev
= (EventRecord
*) evr
;
1907 WindowRef window
= (WindowRef
) ev
->message
;
1910 bool activate
= (ev
->modifiers
& activeFlag
) ;
1911 WindowClass wclass
;
1912 ::GetWindowClass ( window
, &wclass
) ;
1913 if ( wclass
== kFloatingWindowClass
)
1915 // if it is a floater we activate/deactivate the front non-floating window instead
1916 window
= ::FrontNonFloatingWindow() ;
1918 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1920 win
->MacActivate( ev
->when
, activate
) ;
1924 void wxApp::MacHandleUpdateEvent( WXEVENTREF evr
)
1926 EventRecord
* ev
= (EventRecord
*) evr
;
1927 WindowRef window
= (WindowRef
) ev
->message
;
1928 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1931 if ( !wxPendingDelete
.Member(win
) )
1932 win
->MacUpdate( ev
->when
) ;
1936 // since there is no way of telling this foreign window to update itself
1937 // we have to invalidate the update region otherwise we keep getting the same
1938 // event over and over again
1939 BeginUpdate( window
) ;
1940 EndUpdate( window
) ;
1944 void wxApp::MacHandleDiskEvent( WXEVENTREF evr
)
1946 EventRecord
* ev
= (EventRecord
*) evr
;
1947 if ( HiWord( ev
->message
) != noErr
)
1951 SetPt( &point
, 100 , 100 ) ;
1953 err
= DIBadMount( point
, ev
->message
) ;
1954 wxASSERT( err
== noErr
) ;
1958 void wxApp::MacHandleOSEvent( WXEVENTREF evr
)
1960 EventRecord
* ev
= (EventRecord
*) evr
;
1961 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
1963 case suspendResumeMessage
:
1965 bool isResuming
= ev
->message
& resumeFlag
;
1966 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
1968 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
1971 WindowRef oldFrontWindow
= NULL
;
1972 WindowRef newFrontWindow
= NULL
;
1974 // in case we don't take care of activating ourselves, we have to synchronize
1975 // our idea of the active window with the process manager's - which it already activated
1977 if ( !doesActivate
)
1978 oldFrontWindow
= ::FrontNonFloatingWindow() ;
1980 MacResume( convertClipboard
) ;
1982 newFrontWindow
= ::FrontNonFloatingWindow() ;
1984 if ( oldFrontWindow
)
1986 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
1988 win
->MacActivate( ev
->when
, false ) ;
1990 if ( newFrontWindow
)
1992 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
1994 win
->MacActivate( ev
->when
, true ) ;
1999 MacSuspend( convertClipboard
) ;
2003 case mouseMovedMessage
:
2007 wxWindow
* currentMouseWindow
= NULL
;
2009 if (s_captureWindow
)
2011 currentMouseWindow
= s_captureWindow
;
2015 wxWindow::MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) ,
2016 ¤tMouseWindow
) ;
2019 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
2021 wxMouseEvent event
;
2023 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
2024 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
2026 event
.m_leftDown
= isDown
&& !controlDown
;
2027 event
.m_middleDown
= FALSE
;
2028 event
.m_rightDown
= isDown
&& controlDown
;
2029 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
2030 event
.m_controlDown
= ev
->modifiers
& controlKey
;
2031 event
.m_altDown
= ev
->modifiers
& optionKey
;
2032 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
2033 event
.m_x
= ev
->where
.h
;
2034 event
.m_y
= ev
->where
.v
;
2035 event
.m_timeStamp
= ev
->when
;
2036 event
.SetEventObject(this);
2038 if ( wxWindow::s_lastMouseWindow
)
2040 wxMouseEvent
eventleave(event
);
2041 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
2042 wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
2043 eventleave
.SetEventObject( wxWindow::s_lastMouseWindow
) ;
2045 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
2047 if ( currentMouseWindow
)
2049 wxMouseEvent
evententer(event
);
2050 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
2051 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
2052 evententer
.SetEventObject( currentMouseWindow
) ;
2053 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
2055 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
2058 short windowPart
= inNoWindow
;
2060 if ( s_captureWindow
)
2062 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
2063 windowPart
= inContent
;
2067 windowPart
= ::FindWindow(ev
->where
, &window
);
2074 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2076 win
->MacMouseMoved( ev
, windowPart
) ;
2083 UMAShowArrowCursor();
2093 UMAShowArrowCursor();
2104 void wxApp::MacHandleMenuCommand( wxUint32 id
)
2106 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
2107 wxFrame
* frame
= mbar
->GetFrame();
2108 wxCHECK_RET( mbar
!= NULL
&& frame
!= NULL
, wxT("error in menu item callback") );
2111 frame
->ProcessCommand(id
);
2116 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
2119 return; // no menu item selected
2121 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
2124 Str255 deskAccessoryName
;
2127 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
2128 GetPort(&savedPort
);
2129 OpenDeskAcc(deskAccessoryName
);
2136 GetMenuItemCommandID( GetMenuHandle(macMenuId
) , macMenuItemNum
, &id
) ;
2137 MacHandleMenuCommand( id
) ;