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)
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
;
76 static bool s_inOnIdle
= FALSE
;
79 static bool s_inReceiveEvent
= FALSE
;
80 static EventTime sleepTime
= kEventDurationNoWait
;
82 static long sleepTime
= 0 ;
85 #if !USE_SHARED_LIBRARY
86 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
87 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
88 EVT_IDLE(wxApp::OnIdle
)
89 EVT_END_SESSION(wxApp::OnEndSession
)
90 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
95 const short kMacMinHeap
= (29 * 1024) ;
96 // platform specific static variables
98 const short kwxMacMenuBarResource
= 1 ;
99 const short kwxMacAppleMenuId
= 1 ;
101 WXHRGN
wxApp::s_macCursorRgn
= NULL
;
102 wxWindow
* wxApp::s_captureWindow
= NULL
;
103 int wxApp::s_lastMouseDown
= 0 ;
104 long wxApp::sm_lastMessageTime
= 0;
105 long wxApp::s_lastModifiers
= 0 ;
108 bool wxApp::s_macDefaultEncodingIsPC
= true ;
109 bool wxApp::s_macSupportPCMenuShortcuts
= true ;
110 long wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
111 long wxApp::s_macPreferencesMenuItemId
= 0 ;
112 long wxApp::s_macExitMenuItemId
= wxID_EXIT
;
113 wxString
wxApp::s_macHelpMenuTitleName
= wxT("&Help") ;
115 //----------------------------------------------------------------------
116 // Core Apple Event Support
117 //----------------------------------------------------------------------
119 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
120 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
121 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
122 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
124 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
126 return wxTheApp
->MacHandleAEODoc( (AppleEvent
*) event
, reply
) ;
129 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
131 return wxTheApp
->MacHandleAEOApp( (AppleEvent
*) event
, reply
) ;
134 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
136 return wxTheApp
->MacHandleAEPDoc( (AppleEvent
*) event
, reply
) ;
139 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
141 return wxTheApp
->MacHandleAEQuit( (AppleEvent
*) event
, reply
) ;
144 // AEODoc Calls MacOpenFile on each of the files passed
146 short wxApp::MacHandleAEODoc(const WXEVENTREF event
, WXEVENTREF
WXUNUSED(reply
))
150 DescType returnedType
;
156 err
= AEGetParamDesc((AppleEvent
*)event
, keyDirectObject
, typeAEList
,&docList
);
160 err
= AECountItems(&docList
, &itemsInList
);
164 ProcessSerialNumber PSN
;
165 PSN
.highLongOfPSN
= 0 ;
166 PSN
.lowLongOfPSN
= kCurrentProcess
;
167 SetFrontProcess( &PSN
) ;
169 for (i
= 1; i
<= itemsInList
; i
++) {
170 AEGetNthPtr(&docList
, i
, typeFSS
, &keywd
, &returnedType
,
171 (Ptr
) & theSpec
, sizeof(theSpec
), &actualSize
);
172 wxString fName
= wxMacFSSpec2MacFilename(&theSpec
);
178 // AEPDoc Calls MacPrintFile on each of the files passed
180 short wxApp::MacHandleAEPDoc(const WXEVENTREF event
, WXEVENTREF
WXUNUSED(reply
))
184 DescType returnedType
;
190 err
= AEGetParamDesc((AppleEvent
*)event
, keyDirectObject
, typeAEList
,&docList
);
194 err
= AECountItems(&docList
, &itemsInList
);
198 ProcessSerialNumber PSN
;
199 PSN
.highLongOfPSN
= 0 ;
200 PSN
.lowLongOfPSN
= kCurrentProcess
;
201 SetFrontProcess( &PSN
) ;
203 for (i
= 1; i
<= itemsInList
; i
++) {
204 AEGetNthPtr(&docList
, i
, typeFSS
, &keywd
, &returnedType
,
205 (Ptr
) & theSpec
, sizeof(theSpec
), &actualSize
);
206 wxString fName
= wxMacFSSpec2MacFilename(&theSpec
);
212 // AEOApp calls MacNewFile
214 short wxApp::MacHandleAEOApp(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
220 // AEQuit attempts to quit the application
222 short wxApp::MacHandleAEQuit(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
224 /* wxWindow* win = GetTopWindow() ;
237 //----------------------------------------------------------------------
238 // Support Routines linking the Mac...File Calls to the Document Manager
239 //----------------------------------------------------------------------
241 void wxApp::MacOpenFile(const wxString
& fileName
)
243 wxDocManager
* dm
= wxDocManager::GetDocumentManager() ;
245 dm
->CreateDocument(fileName
, wxDOC_SILENT
) ;
248 void wxApp::MacPrintFile(const wxString
& fileName
)
250 wxDocManager
* dm
= wxDocManager::GetDocumentManager() ;
253 wxDocument
*doc
= dm
->CreateDocument(fileName
, wxDOC_SILENT
) ;
256 wxView
* view
= doc
->GetFirstView() ;
259 wxPrintout
*printout
= view
->OnCreatePrintout();
263 printer
.Print(view
->GetFrame(), printout
, TRUE
);
269 doc
->DeleteAllViews();
270 dm
->RemoveDocument(doc
) ;
276 void wxApp::MacNewFile()
280 //----------------------------------------------------------------------
281 // Carbon Event Handler
282 //----------------------------------------------------------------------
286 static const EventTypeSpec eventList
[] =
288 { kEventClassCommand
, kEventProcessCommand
} ,
289 { kEventClassCommand
, kEventCommandUpdateStatus
} ,
291 { kEventClassApplication
, kEventAppActivated
} ,
292 { kEventClassApplication
, kEventAppDeactivated
} ,
293 // handling the quit event is not recommended by apple
294 // rather using the quit apple event - which we do
296 { kEventClassAppleEvent
, kEventAppleEvent
} ,
298 { kEventClassMouse
, kEventMouseDown
} ,
302 static pascal OSStatus
MenuEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
304 return eventNotHandledErr
;
307 // due to the rather low-level event API of wxWindows, we cannot use RunApplicationEventLoop
308 // but have to use ReceiveNextEvent dealing with events manually, therefore we also have
309 // deal with clicks in the menu bar explicitely
311 static pascal OSStatus
MouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
313 OSStatus result
= eventNotHandledErr
;
315 switch( GetEventKind(event
) )
317 case kEventMouseDown
:
322 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
323 sizeof( Point
), NULL
, &point
);
324 short windowPart
= ::FindWindow(point
, &window
);
326 if ( windowPart
== inMenuBar
)
328 MenuSelect( point
) ;
338 static pascal OSStatus
CommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
340 OSStatus result
= eventNotHandledErr
;
344 GetEventParameter( event
, kEventParamDirectObject
, typeHICommand
, NULL
,
345 sizeof( HICommand
), NULL
, &command
);
347 MenuCommand id
= command
.commandID
;
348 if ( id
== kHICommandPreferences
)
349 id
= wxApp::s_macPreferencesMenuItemId
;
351 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
352 wxMenu
* menu
= NULL
;
353 wxMenuItem
* item
= NULL
;
356 item
= mbar
->FindItem( id
, &menu
) ;
358 if ( item
== NULL
|| menu
== NULL
|| mbar
== NULL
)
361 switch( GetEventKind( event
) )
363 case kEventProcessCommand
:
365 if (item
->IsCheckable())
367 item
->Check( !item
->IsChecked() ) ;
370 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
374 case kEventCommandUpdateStatus
:
375 // eventually trigger an updateui round
385 static pascal OSStatus
ApplicationEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
387 OSStatus result
= eventNotHandledErr
;
388 switch ( GetEventKind( event
) )
390 case kEventAppActivated
:
393 wxTheApp
->MacResume( true ) ;
397 case kEventAppDeactivated
:
400 wxTheApp
->MacSuspend( true ) ;
410 pascal OSStatus
wxAppEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
412 OSStatus result
= eventNotHandledErr
;
413 switch( GetEventClass( event
) )
415 case kEventClassCommand
:
416 result
= CommandEventHandler( handler
, event
, data
) ;
418 case kEventClassApplication
:
419 result
= ApplicationEventHandler( handler
, event
, data
) ;
421 case kEventClassMenu
:
422 result
= MenuEventHandler( handler
, event
, data
) ;
424 case kEventClassMouse
:
425 result
= MouseEventHandler( handler
, event
, data
) ;
427 case kEventClassAppleEvent
:
430 wxMacConvertEventToRecord( event
, &rec
) ;
431 result
= AEProcessAppleEvent( &rec
) ;
441 DEFINE_ONE_SHOT_HANDLER_GETTER( wxAppEventHandler
)
445 #if defined(WXMAKINGDLL) && !defined(__DARWIN__)
446 // we know it's there ;-)
447 WXIMPORT
char std::__throws_bad_alloc
;
450 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
456 UMAInitToolbox( 4 ) ;
457 SetEventMask( everyEvent
) ;
458 UMAShowWatchCursor() ;
460 #if defined(WXMAKINGDLL) && defined(__DARWIN__)
461 // open shared library resources from here since we don't have
462 // __wxinitialize in Mach-O shared libraries
463 wxStAppResource::OpenSharedLibraryResource(NULL
);
467 // test the minimal configuration necessary
473 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
475 error
= kMacSTRWrongMachine
;
477 else if (theMachine
< gestaltMacPlus
)
479 error
= kMacSTRWrongMachine
;
481 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
483 error
= kMacSTROldSystem
;
485 else if ( theSystem
< 0x0860 )
487 error
= kMacSTROldSystem
;
489 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
491 error
= kMacSTRSmallSize
;
497 if ( !UMAHasAppearance() )
499 error = kMacSTRNoPre8Yet ;
505 // if we encountered any problems so far, give the error code and exit immediately
509 wxStAppResource resload
;
513 GetIndString(message
, 128, error
);
514 UMAShowArrowCursor() ;
515 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
516 itemHit
= Alert(128, nil
);
521 # if __option(profile)
522 ProfilerInit( collectDetailed
, bestTimeBase
, 20000 , 40 ) ;
527 // now avoid exceptions thrown for new (bad_alloc)
528 // FIXME CS for some changes outside wxMac does not compile anymore
530 std::__throws_bad_alloc
= 0 ;
534 wxMacSetupConverters() ;
536 s_macCursorRgn
= ::NewRgn() ;
538 // Mac OS X passes a process serial number command line argument when
539 // the application is launched from the Finder. This argument must be
540 // removed from the command line arguments before being handled by the
541 // application (otherwise applications would need to handle it)
544 static const wxChar
*ARG_PSN
= _T("-psn_");
545 if ( wxStrncmp(argv
[1], ARG_PSN
, sizeof(ARG_PSN
) - 1) == 0 )
547 // remove this argument
548 memmove(argv
, argv
+ 1, argc
--);
552 if ( !wxAppBase::Initialize(argc
, argv
) )
555 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
556 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
558 wxMacCreateNotifierTable() ;
560 UMAShowArrowCursor() ;
565 bool wxApp::OnInitGui()
567 if( !wxAppBase::OnInitGui() )
571 InstallStandardEventHandler( GetApplicationEventTarget() ) ;
573 InstallApplicationEventHandler(
574 GetwxAppEventHandlerUPP(),
575 GetEventTypeCount(eventList
), eventList
, wxTheApp
, (EventHandlerRef
*)&(wxTheApp
->m_macEventHandler
));
578 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
579 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
580 NewAEEventHandlerUPP(AEHandleODoc
) ,
582 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
583 NewAEEventHandlerUPP(AEHandleOApp
) ,
585 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
586 NewAEEventHandlerUPP(AEHandlePDoc
) ,
588 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
589 NewAEEventHandlerUPP(AEHandleQuit
) ,
592 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
593 NewAEEventHandlerProc(AEHandleODoc
) ,
595 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
596 NewAEEventHandlerProc(AEHandleOApp
) ,
598 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
599 NewAEEventHandlerProc(AEHandlePDoc
) ,
601 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
602 NewAEEventHandlerProc(AEHandleQuit
) ,
609 void wxApp::CleanUp()
611 wxToolTip::RemoveToolTips() ;
613 // One last chance for pending objects to be cleaned up
614 wxTheApp
->DeletePendingObjects();
616 wxMacDestroyNotifierTable() ;
618 delete wxWinMacWindowList
;
619 wxWinMacWindowList
= NULL
;
621 delete wxWinMacControlList
;
622 wxWinMacControlList
= NULL
;
625 # if __option(profile)
626 ProfilerDump( (StringPtr
)"\papp.prof" ) ;
631 #if defined(WXMAKINGDLL) && defined(__DARWIN__)
632 // close shared library resources from here since we don't have
633 // __wxterminate in Mach-O shared libraries
634 wxStAppResource::CloseSharedLibraryResource();
636 wxMacCleanupConverters() ;
638 UMACleanupToolbox() ;
639 if (s_macCursorRgn
) {
640 ::DisposeRgn((RgnHandle
)s_macCursorRgn
);
647 wxAppBase::CleanUp();
650 //----------------------------------------------------------------------
651 // misc initialization stuff
652 //----------------------------------------------------------------------
654 // extern variable for shared library resource id
655 // need to be able to find it with NSLookupAndBindSymbol
656 short gSharedLibraryResource
= kResFileNotOpened
;
658 #if defined(WXMAKINGDLL) && defined(__DARWIN__)
659 CFBundleRef gSharedLibraryBundle
= NULL
;
660 #endif /* WXMAKINGDLL && __DARWIN__ */
662 wxStAppResource::wxStAppResource()
664 m_currentRefNum
= CurResFile() ;
665 if ( gSharedLibraryResource
!= kResFileNotOpened
)
667 UseResFile( gSharedLibraryResource
) ;
671 wxStAppResource::~wxStAppResource()
673 if ( m_currentRefNum
!= kResFileNotOpened
)
675 UseResFile( m_currentRefNum
) ;
679 void wxStAppResource::OpenSharedLibraryResource(const void *initBlock
)
681 gSharedLibraryResource
= kResFileNotOpened
;
684 if ( initBlock
!= NULL
) {
685 const CFragInitBlock
*theInitBlock
= (const CFragInitBlock
*)initBlock
;
686 FSSpec
*fileSpec
= NULL
;
688 if (theInitBlock
->fragLocator
.where
== kDataForkCFragLocator
) {
689 fileSpec
= theInitBlock
->fragLocator
.u
.onDisk
.fileSpec
;
691 else if (theInitBlock
->fragLocator
.where
== kResourceCFragLocator
) {
692 fileSpec
= theInitBlock
->fragLocator
.u
.inSegs
.fileSpec
;
695 if (fileSpec
!= NULL
) {
696 gSharedLibraryResource
= FSpOpenResFile(fileSpec
, fsRdPerm
);
701 // Open the shared library resource file if it is not yet open
704 const char *theLibPath
;
706 gSharedLibraryBundle
= CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWindows"));
707 if (gSharedLibraryBundle
!= NULL
) {
708 // wxWindows has been bundled into a framework
709 // load the framework resources
711 gSharedLibraryResource
= CFBundleOpenBundleResourceMap(gSharedLibraryBundle
);
714 // wxWindows is a simple dynamic shared library
715 // load the resources from the data fork of a separate resource file
720 OSErr theErr
= noErr
;
722 // get the library path
723 theSymbol
= NSLookupAndBindSymbol("_gSharedLibraryResource");
724 theModule
= NSModuleForSymbol(theSymbol
);
725 theLibPath
= NSLibraryNameForModule(theModule
);
727 // if we call wxLogDebug from here then, as wxTheApp hasn't been
728 // created yet when we're called from wxApp::Initialize(), wxLog
729 // is going to create a default stderr-based log target instead of
730 // the expected normal GUI one -- don't do it, if we really want
731 // to see this message just use fprintf() here
733 wxLogDebug( wxT("wxMac library installation name is '%s'"),
737 // allocate copy to replace .dylib.* extension with .rsrc
738 theResPath
= strdup(theLibPath
);
739 if (theResPath
!= NULL
) {
740 theName
= strrchr(theResPath
, '/');
741 if (theName
== NULL
) {
742 // no directory elements in path
743 theName
= theResPath
;
745 // find ".dylib" shared library extension
746 theExt
= strstr(theName
, ".dylib");
747 // overwrite extension with ".rsrc"
748 strcpy(theExt
, ".rsrc");
751 wxLogDebug( wxT("wxMac resources file name is '%s'"),
755 theErr
= FSPathMakeRef((UInt8
*) theResPath
, &theResRef
, false);
756 if (theErr
!= noErr
) {
757 // try in current directory (using name only)
758 theErr
= FSPathMakeRef((UInt8
*) theName
, &theResRef
, false);
761 // open the resource file
762 if (theErr
== noErr
) {
763 theErr
= FSOpenResourceFile( &theResRef
, 0, NULL
, fsRdPerm
,
764 &gSharedLibraryResource
);
766 if (theErr
!= noErr
) {
769 wxT("unable to open wxMac resource file '%s'\n"),
771 #endif // __WXDEBUG__
774 // free duplicated resource file path
778 #endif /* __DARWIN__ */
780 #endif /* WXMAKINGDLL */
783 void wxStAppResource::CloseSharedLibraryResource()
786 // Close the shared library resource file
787 if (gSharedLibraryResource
!= kResFileNotOpened
) {
789 if (gSharedLibraryBundle
!= NULL
) {
790 CFBundleCloseBundleResourceMap(gSharedLibraryBundle
,
791 gSharedLibraryResource
);
792 gSharedLibraryBundle
= NULL
;
795 #endif /* __DARWIN__ */
797 CloseResFile(gSharedLibraryResource
);
799 gSharedLibraryResource
= kResFileNotOpened
;
801 #endif /* WXMAKINGDLL */
804 #if defined(WXMAKINGDLL) && !defined(__DARWIN__)
806 // for shared libraries we have to manually get the correct resource
807 // ref num upon initializing and releasing when terminating, therefore
808 // the __wxinitialize and __wxterminate must be used
811 void __sinit(void); /* (generated by linker) */
812 pascal OSErr
__initialize(const CFragInitBlock
*theInitBlock
);
813 pascal void __terminate(void);
816 pascal OSErr
__wxinitialize(const CFragInitBlock
*theInitBlock
)
818 wxStAppResource::OpenSharedLibraryResource( theInitBlock
) ;
819 return __initialize( theInitBlock
) ;
822 pascal void __wxterminate(void)
824 wxStAppResource::CloseSharedLibraryResource() ;
828 #endif /* WXMAKINGDLL && !__DARWIN__ */
832 bool wxMacConvertEventToRecord( EventRef event
, EventRecord
*rec
)
834 bool converted
= ConvertEventRefToEventRecord( event
,rec
) ;
835 OSStatus err
= noErr
;
838 switch( GetEventClass( event
) )
840 case kEventClassKeyboard
:
843 switch( GetEventKind(event
) )
845 case kEventRawKeyDown
:
846 rec
->what
= keyDown
;
848 case kEventRawKeyRepeat
:
849 rec
->what
= autoKey
;
851 case kEventRawKeyUp
:
854 case kEventRawKeyModifiersChanged
:
855 rec
->what
= nullEvent
;
864 unsigned char charCode
;
866 GetMouse( &rec
->where
) ;
868 err
= GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
869 err
= GetEventParameter(event
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
870 err
= GetEventParameter(event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
871 rec
->modifiers
= modifiers
;
872 rec
->message
= (keyCode
<< 8 ) + charCode
;
876 case kEventClassTextInput
:
878 switch( GetEventKind( event
) )
880 case kEventTextInputUnicodeForKeyEvent
:
883 err
= GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent
) ;
887 unsigned char charCode
;
889 GetMouse( &rec
->where
) ;
890 rec
->what
= keyDown
;
891 err
= GetEventParameter(rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
892 err
= GetEventParameter(rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
893 err
= GetEventParameter(rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
894 rec
->modifiers
= modifiers
;
895 rec
->message
= (keyCode
<< 8 ) + charCode
;
911 pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
913 OSStatus result = eventNotHandledErr ;
916 switch ( GetEventClass( event ) )
918 case kEventClassKeyboard :
919 if ( wxMacConvertEventToRecord( event , &rec ) )
921 wxTheApp->MacHandleModifierEvents( &rec ) ;
922 wxTheApp->MacHandleOneEvent( &rec ) ;
926 case kEventClassTextInput :
927 if ( wxMacConvertEventToRecord( event , &rec ) )
929 wxTheApp->MacHandleModifierEvents( &rec ) ;
930 wxTheApp->MacHandleOneEvent( &rec ) ;
947 #if WXWIN_COMPATIBILITY_2_2
948 m_wantDebugOutput
= TRUE
;
954 m_printMode
= wxPRINT_WINDOWS
;
958 bool wxApp::Initialized()
966 int wxApp::MainLoop()
978 // Returns TRUE if more time is needed.
979 bool wxApp::ProcessIdle()
982 event
.SetEventObject(this);
985 return event
.MoreRequested();
988 void wxApp::ExitMainLoop()
993 // Is a message/event pending?
994 bool wxApp::Pending()
997 return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ;
1001 return EventAvail( everyEvent
, &event
) ;
1005 // Dispatch a message.
1006 void wxApp::Dispatch()
1011 void wxApp::OnIdle(wxIdleEvent
& event
)
1013 // Avoid recursion (via ProcessEvent default case)
1020 // 'Garbage' collection of windows deleted with Close().
1021 DeletePendingObjects();
1023 // flush the logged messages if any
1024 wxLog
*pLog
= wxLog::GetActiveTarget();
1025 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
1028 // Send OnIdle events to all windows
1029 bool needMore
= SendIdleEvents();
1032 event
.RequestMore(TRUE
);
1034 // If they are pending events, we must process them: pending events are
1035 // either events to the threads other than main or events posted with
1036 // wxPostEvent() functions
1037 wxMacProcessNotifierAndPendingEvents();
1040 if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
1041 wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
1044 void wxApp::WakeUpIdle()
1049 // Send idle event to all top-level windows
1050 bool wxApp::SendIdleEvents()
1052 bool needMore
= FALSE
;
1053 wxWindowListNode
* node
= wxTopLevelWindows
.GetFirst();
1056 wxWindow
* win
= node
->GetData();
1057 if (SendIdleEvents(win
))
1060 node
= node
->GetNext();
1065 // Send idle event to window and all subwindows
1066 bool wxApp::SendIdleEvents(wxWindow
* win
)
1068 bool needMore
= FALSE
;
1071 event
.SetEventObject(win
);
1072 win
->ProcessEvent(event
);
1074 if (event
.MoreRequested())
1077 wxWindowListNode
* node
= win
->GetChildren().GetFirst();
1080 wxWindow
* win
= node
->GetData();
1081 if (SendIdleEvents(win
))
1084 node
= node
->GetNext();
1095 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
1098 GetTopWindow()->Close(TRUE
);
1101 // Default behaviour: close the application with prompts. The
1102 // user can veto the close, and therefore the end session.
1103 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
1107 if (!GetTopWindow()->Close(!event
.CanVeto()))
1112 extern "C" void wxCYield() ;
1118 // Yield to other processes
1120 bool wxApp::Yield(bool onlyIfNeeded
)
1124 if ( !onlyIfNeeded
)
1126 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1135 YieldToAnyThread() ;
1137 // by definition yield should handle all non-processed events
1141 OSStatus status
= noErr
;
1144 s_inReceiveEvent
= true ;
1145 status
= ReceiveNextEvent(0, NULL
,kEventDurationNoWait
,true,&theEvent
) ;
1146 s_inReceiveEvent
= false ;
1148 if ( status
== eventLoopTimedOutErr
)
1150 // make sure next time the event loop will trigger idle events
1151 sleepTime
= kEventDurationNoWait
;
1153 else if ( status
== eventLoopQuitErr
)
1155 // according to QA1061 this may also occur when a WakeUp Process
1160 MacHandleOneEvent( theEvent
) ;
1161 ReleaseEvent(theEvent
);
1163 } while( status
== noErr
) ;
1167 // having a larger value here leads to large performance slowdowns
1168 // so we cannot give background apps more processor time here
1169 // we do so however having a large sleep value in the main event loop
1172 while ( !IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, (RgnHandle
) wxApp::s_macCursorRgn
))
1174 MacHandleModifierEvents( &event
) ;
1175 MacHandleOneEvent( &event
);
1176 if ( event
.what
!= kHighLevelEvent
)
1177 SetRectRgn( (RgnHandle
) wxApp::s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1179 MacHandleModifierEvents( &event
) ;
1182 wxMacProcessNotifierAndPendingEvents() ;
1188 // platform specifics
1190 void wxApp::MacSuspend( bool convertClipboard
)
1193 // we have to deactive the top level windows manually
1195 wxWindowListNode
* node
= wxTopLevelWindows
.GetFirst();
1198 wxTopLevelWindow
* win
= (wxTopLevelWindow
*) node
->Data();
1200 #if 0 // having problems right now with that
1201 if (!win
->HasFlag(wxSTAY_ON_TOP
))
1204 win
->MacActivate( ((EventRecord
*) MacGetCurrentEvent())->when
, false ) ;
1206 node
= node
->GetNext();
1209 ::HideFloatingWindows() ;
1211 s_lastMouseDown
= 0 ;
1213 if( convertClipboard
)
1215 MacConvertPrivateToPublicScrap() ;
1219 extern wxList wxModalDialogs
;
1221 void wxApp::MacResume( bool convertClipboard
)
1223 s_lastMouseDown
= 0 ;
1224 if( convertClipboard
)
1226 MacConvertPublicToPrivateScrap() ;
1230 ::ShowFloatingWindows() ;
1231 // raise modal dialogs in case a non modal window was selected to activate the app
1233 wxNode
* node
= wxModalDialogs
.GetFirst();
1236 wxDialog
* dialog
= (wxDialog
*) node
->GetData();
1239 node
= node
->GetNext();
1244 void wxApp::MacConvertPrivateToPublicScrap()
1248 void wxApp::MacConvertPublicToPrivateScrap()
1252 void wxApp::MacDoOneEvent()
1257 s_inReceiveEvent
= true ;
1258 OSStatus status
= ReceiveNextEvent(0, NULL
,sleepTime
,true,&theEvent
) ;
1259 s_inReceiveEvent
= false ;
1260 if ( status
== eventLoopTimedOutErr
)
1262 if ( wxTheApp
->ProcessIdle() )
1263 sleepTime
= kEventDurationNoWait
;
1265 sleepTime
= kEventDurationForever
;
1267 else if ( status
== eventLoopQuitErr
)
1269 // according to QA1061 this may also occur when a WakeUp Process
1274 MacHandleOneEvent( theEvent
) ;
1275 ReleaseEvent(theEvent
);
1276 sleepTime
= kEventDurationNoWait
;
1281 EventMask eventMask
= everyEvent
;
1283 if (WaitNextEvent(eventMask
, &event
, sleepTime
, (RgnHandle
) s_macCursorRgn
))
1285 MacHandleModifierEvents( &event
) ;
1286 MacHandleOneEvent( &event
);
1290 MacHandleModifierEvents( &event
) ;
1292 WindowPtr window
= ::FrontWindow() ;
1294 ::IdleControls( window
) ;
1296 if ( wxTheApp
->ProcessIdle() )
1299 sleepTime
= GetCaretTime() / 2 ;
1301 if ( event
.what
!= kHighLevelEvent
)
1302 SetRectRgn( (RgnHandle
) s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1306 DeletePendingObjects() ;
1307 wxMacProcessNotifierAndPendingEvents() ;
1310 void wxApp::MacHandleOneEvent( WXEVENTREF evr
)
1313 EventTargetRef theTarget
;
1314 theTarget
= GetEventDispatcherTarget();
1315 m_macCurrentEvent
= evr
;
1316 SendEventToEventTarget ((EventRef
) evr
, theTarget
);
1318 EventRecord
* ev
= (EventRecord
*) evr
;
1319 m_macCurrentEvent
= ev
;
1321 wxApp::sm_lastMessageTime
= ev
->when
;
1326 MacHandleMouseDownEvent( ev
) ;
1327 if ( ev
->modifiers
& controlKey
)
1328 s_lastMouseDown
= 2;
1330 s_lastMouseDown
= 1;
1333 if ( s_lastMouseDown
== 2 )
1335 ev
->modifiers
|= controlKey
;
1339 ev
->modifiers
&= ~controlKey
;
1341 MacHandleMouseUpEvent( ev
) ;
1342 s_lastMouseDown
= 0;
1345 MacHandleActivateEvent( ev
) ;
1348 MacHandleUpdateEvent( ev
) ;
1352 MacHandleKeyDownEvent( ev
) ;
1355 MacHandleKeyUpEvent( ev
) ;
1358 MacHandleDiskEvent( ev
) ;
1361 MacHandleOSEvent( ev
) ;
1363 case kHighLevelEvent
:
1364 MacHandleHighLevelEvent( ev
) ;
1370 wxMacProcessNotifierAndPendingEvents() ;
1374 bool s_macIsInModalLoop
= false ;
1376 void wxApp::MacHandleModifierEvents( WXEVENTREF evr
)
1378 EventRecord
* ev
= (EventRecord
*) evr
;
1379 if ( ev
->modifiers
!= s_lastModifiers
&& wxWindow::FindFocus() != NULL
)
1381 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1383 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1384 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1385 event
.m_altDown
= ev
->modifiers
& optionKey
;
1386 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1388 event
.m_x
= ev
->where
.h
;
1389 event
.m_y
= ev
->where
.v
;
1390 event
.m_timeStamp
= ev
->when
;
1391 wxWindow
* focus
= wxWindow::FindFocus() ;
1392 event
.SetEventObject(focus
);
1394 if ( (ev
->modifiers
^ s_lastModifiers
) & controlKey
)
1396 event
.m_keyCode
= WXK_CONTROL
;
1397 event
.SetEventType( ( ev
->modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1398 focus
->GetEventHandler()->ProcessEvent( event
) ;
1400 if ( (ev
->modifiers
^ s_lastModifiers
) & shiftKey
)
1402 event
.m_keyCode
= WXK_SHIFT
;
1403 event
.SetEventType( ( ev
->modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1404 focus
->GetEventHandler()->ProcessEvent( event
) ;
1406 if ( (ev
->modifiers
^ s_lastModifiers
) & optionKey
)
1408 event
.m_keyCode
= WXK_ALT
;
1409 event
.SetEventType( ( ev
->modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1410 focus
->GetEventHandler()->ProcessEvent( event
) ;
1412 s_lastModifiers
= ev
->modifiers
;
1416 void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr
)
1418 // we must avoid reentrancy problems when processing high level events eg printing
1419 bool former
= s_inYield
;
1421 EventRecord
* ev
= (EventRecord
*) evr
;
1422 ::AEProcessAppleEvent( ev
) ;
1423 s_inYield
= former
;
1426 void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr
)
1428 EventRecord
* ev
= (EventRecord
*) evr
;
1429 wxToolTip::RemoveToolTips() ;
1432 WindowRef frontWindow
= ::FrontNonFloatingWindow() ;
1433 WindowAttributes frontWindowAttributes
= NULL
;
1435 ::GetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
1437 short windowPart
= ::FindWindow(ev
->where
, &window
);
1438 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1439 if ( wxPendingDelete
.Member(win
) )
1443 GetQDGlobalsScreenBits( &screenBits
);
1448 if ( s_macIsInModalLoop
)
1454 UInt32 menuresult
= MenuSelect(ev
->where
) ;
1455 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1456 s_lastMouseDown
= 0;
1460 SystemClick( ev
, window
) ;
1461 s_lastMouseDown
= 0;
1464 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1470 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1475 Point pt
= { 0, 0 } ;
1476 SetPortWindowPort(window
) ;
1477 LocalToGlobal( &pt
) ;
1479 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1480 -1 , wxSIZE_USE_EXISTING
);
1482 s_lastMouseDown
= 0;
1486 if (TrackGoAway(window
, ev
->where
))
1491 s_lastMouseDown
= 0;
1495 Rect newContentRect
;
1496 Rect constraintRect
;
1497 constraintRect
.top
= win
->GetMinHeight() ;
1498 if ( constraintRect
.top
== -1 )
1499 constraintRect
.top
= 0 ;
1500 constraintRect
.left
= win
->GetMinWidth() ;
1501 if ( constraintRect
.left
== -1 )
1502 constraintRect
.left
= 0 ;
1503 constraintRect
.right
= win
->GetMaxWidth() ;
1504 if ( constraintRect
.right
== -1 )
1505 constraintRect
.right
= 32000 ;
1506 constraintRect
.bottom
= win
->GetMaxHeight() ;
1507 if ( constraintRect
.bottom
== -1 )
1508 constraintRect
.bottom
= 32000 ;
1510 Boolean growResult
= ResizeWindow( window
, ev
->where
,
1511 &constraintRect
, &newContentRect
) ;
1514 win
->SetSize( newContentRect
.left
, newContentRect
.top
,
1515 newContentRect
.right
- newContentRect
.left
,
1516 newContentRect
.bottom
- newContentRect
.top
, wxSIZE_USE_EXISTING
);
1518 s_lastMouseDown
= 0;
1523 if (TrackBox(window
, ev
->where
, windowPart
))
1525 // TODO setup size event
1526 ZoomWindow( window
, windowPart
, false ) ;
1532 Point pt
= { 0, 0 } ;
1533 SetPortWindowPort(window
) ;
1534 LocalToGlobal( &pt
) ;
1537 GetWindowPortBounds(window
, &tempRect
) ;
1538 win
->SetSize( pt
.h
, pt
.v
, tempRect
.right
-tempRect
.left
,
1539 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1542 s_lastMouseDown
= 0;
1544 case inCollapseBox
:
1545 // TODO setup size event
1546 s_lastMouseDown
= 0;
1553 SetPortWindowPort(window
) ;
1556 if ( window
!= frontWindow
&& wxTheApp
->s_captureWindow
== NULL
)
1558 if ( s_macIsInModalLoop
)
1562 else if ( UMAIsWindowFloating( window
) )
1565 win
->MacMouseDown( ev
, windowPart
) ;
1570 win
->MacMouseDown( ev
, windowPart
) ;
1571 ::SelectWindow( window
) ;
1577 win
->MacMouseDown( ev
, windowPart
) ;
1585 void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr
)
1587 EventRecord
* ev
= (EventRecord
*) evr
;
1590 short windowPart
= inNoWindow
;
1591 if ( wxTheApp
->s_captureWindow
)
1593 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
1594 windowPart
= inContent
;
1598 windowPart
= ::FindWindow(ev
->where
, &window
) ;
1609 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1611 win
->MacMouseUp( ev
, windowPart
) ;
1619 long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
1620 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1625 case kHomeCharCode
:
1628 case kEnterCharCode
:
1629 retval
= WXK_RETURN
;
1634 case kHelpCharCode
:
1637 case kBackspaceCharCode
:
1643 case kPageUpCharCode
:
1644 retval
= WXK_PAGEUP
;
1646 case kPageDownCharCode
:
1647 retval
= WXK_PAGEDOWN
;
1649 case kReturnCharCode
:
1650 retval
= WXK_RETURN
;
1652 case kFunctionKeyCharCode
:
1704 case kEscapeCharCode
:
1705 retval
= WXK_ESCAPE
;
1707 case kLeftArrowCharCode
:
1710 case kRightArrowCharCode
:
1711 retval
= WXK_RIGHT
;
1713 case kUpArrowCharCode
:
1716 case kDownArrowCharCode
:
1719 case kDeleteCharCode
:
1720 retval
= WXK_DELETE
;
1729 void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr
)
1731 EventRecord
* ev
= (EventRecord
*) evr
;
1732 wxToolTip::RemoveToolTips() ;
1734 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1735 if ( HiWord( menuresult
) )
1737 if ( !s_macIsInModalLoop
)
1738 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1742 wxWindow
* focus
= wxWindow::FindFocus() ;
1744 if ( MacSendKeyDownEvent( focus
, ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) == false )
1746 // has not been handled -> perform default
1747 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
1748 if ( control
&& control
->GetMacControl() != NULL
)
1752 keychar
= short(ev
->message
& charCodeMask
);
1753 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1754 ::HandleControlKey( (ControlHandle
) control
->GetMacControl() , keycode
, keychar
, ev
->modifiers
) ;
1760 void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr
)
1762 EventRecord
* ev
= (EventRecord
*) evr
;
1763 wxToolTip::RemoveToolTips() ;
1765 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1766 if ( HiWord( menuresult
) )
1771 MacSendKeyUpEvent( wxWindow::FindFocus() , ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) ;
1777 bool wxApp::MacSendKeyDownEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
)
1784 keychar
= short(keymessage
& charCodeMask
);
1785 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
1787 if ( modifiers
& ( controlKey
|shiftKey
|optionKey
) )
1789 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1790 // and look at the character after
1792 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
);
1793 keychar
= short(keyInfo
& charCodeMask
);
1794 keycode
= short(keyInfo
& keyCodeMask
) >> 8 ;
1796 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1797 long realkeyval
= keyval
;
1798 if ( keyval
== keychar
)
1800 // 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)
1801 realkeyval
= short(keymessage
& charCodeMask
) ;
1802 keyval
= wxToupper( keyval
) ;
1805 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1806 bool handled
= false ;
1807 event
.m_shiftDown
= modifiers
& shiftKey
;
1808 event
.m_controlDown
= modifiers
& controlKey
;
1809 event
.m_altDown
= modifiers
& optionKey
;
1810 event
.m_metaDown
= modifiers
& cmdKey
;
1811 event
.m_keyCode
= keyval
;
1815 event
.m_timeStamp
= when
;
1816 event
.SetEventObject(focus
);
1817 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1818 if ( handled
&& event
.GetSkipped() )
1825 wxWindow
*ancestor
= focus
;
1828 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1831 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1832 handled
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1835 if (ancestor
->IsTopLevel())
1837 ancestor
= ancestor
->GetParent();
1840 #endif // wxUSE_ACCEL
1844 event
.Skip( FALSE
) ;
1845 event
.SetEventType( wxEVT_CHAR
) ;
1847 event
.m_keyCode
= realkeyval
;
1849 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1850 if ( handled
&& event
.GetSkipped() )
1854 (keyval
== WXK_TAB
) &&
1855 // CS: copied the change below from wxGTK
1856 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
1857 // have this style, yet choose not to process this particular TAB in which
1858 // case TAB must still work as a navigational character
1860 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1862 (focus
->GetParent()) &&
1863 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1865 wxNavigationKeyEvent new_event
;
1866 new_event
.SetEventObject( focus
);
1867 new_event
.SetDirection( !event
.ShiftDown() );
1868 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1869 new_event
.SetWindowChange( event
.ControlDown() );
1870 new_event
.SetCurrentFocus( focus
);
1871 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1872 if ( handled
&& new_event
.GetSkipped() )
1875 // backdoor handler for default return and command escape
1876 if ( !handled
&& (!focus
->IsKindOf(CLASSINFO(wxControl
) ) || !focus
->MacCanFocus() ) )
1878 // if window is not having a focus still testing for default enter or cancel
1879 // TODO add the UMA version for ActiveNonFloatingWindow
1880 wxWindow
* focus
= wxFindWinFromMacWindow( FrontWindow() ) ;
1883 if ( keyval
== WXK_RETURN
)
1885 wxButton
*def
= wxDynamicCast(focus
->GetDefaultItem(),
1887 if ( def
&& def
->IsEnabled() )
1889 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
1890 event
.SetEventObject(def
);
1891 def
->Command(event
);
1895 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1896 else if (keyval
== WXK_ESCAPE
|| (keyval
== '.' && modifiers
& cmdKey
) )
1898 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1899 new_event
.SetEventObject( focus
);
1900 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1907 bool wxApp::MacSendKeyUpEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
)
1914 keychar
= short(keymessage
& charCodeMask
);
1915 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
1916 if ( modifiers
& ( controlKey
|shiftKey
|optionKey
) )
1918 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1919 // and look at the character after
1921 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
);
1922 keychar
= short(keyInfo
& charCodeMask
);
1923 keycode
= short(keyInfo
& keyCodeMask
) >> 8 ;
1925 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1927 if ( keyval
== keychar
)
1929 keyval
= wxToupper( keyval
) ;
1931 bool handled
= false ;
1933 wxKeyEvent
event(wxEVT_KEY_UP
);
1934 event
.m_shiftDown
= modifiers
& shiftKey
;
1935 event
.m_controlDown
= modifiers
& controlKey
;
1936 event
.m_altDown
= modifiers
& optionKey
;
1937 event
.m_metaDown
= modifiers
& cmdKey
;
1938 event
.m_keyCode
= keyval
;
1942 event
.m_timeStamp
= when
;
1943 event
.SetEventObject(focus
);
1944 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1950 void wxApp::MacHandleActivateEvent( WXEVENTREF evr
)
1952 EventRecord
* ev
= (EventRecord
*) evr
;
1953 WindowRef window
= (WindowRef
) ev
->message
;
1956 bool activate
= (ev
->modifiers
& activeFlag
) ;
1957 WindowClass wclass
;
1958 ::GetWindowClass ( window
, &wclass
) ;
1959 if ( wclass
== kFloatingWindowClass
)
1961 // if it is a floater we activate/deactivate the front non-floating window instead
1962 window
= ::FrontNonFloatingWindow() ;
1964 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1966 win
->MacActivate( ev
->when
, activate
) ;
1970 void wxApp::MacHandleUpdateEvent( WXEVENTREF evr
)
1972 EventRecord
* ev
= (EventRecord
*) evr
;
1973 WindowRef window
= (WindowRef
) ev
->message
;
1974 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1977 if ( !wxPendingDelete
.Member(win
) )
1978 win
->MacUpdate( ev
->when
) ;
1982 // since there is no way of telling this foreign window to update itself
1983 // we have to invalidate the update region otherwise we keep getting the same
1984 // event over and over again
1985 BeginUpdate( window
) ;
1986 EndUpdate( window
) ;
1990 void wxApp::MacHandleDiskEvent( WXEVENTREF evr
)
1992 EventRecord
* ev
= (EventRecord
*) evr
;
1993 if ( HiWord( ev
->message
) != noErr
)
1997 SetPt( &point
, 100 , 100 ) ;
1999 err
= DIBadMount( point
, ev
->message
) ;
2000 wxASSERT( err
== noErr
) ;
2004 void wxApp::MacHandleOSEvent( WXEVENTREF evr
)
2006 EventRecord
* ev
= (EventRecord
*) evr
;
2007 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
2009 case suspendResumeMessage
:
2011 bool isResuming
= ev
->message
& resumeFlag
;
2012 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
2014 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
2017 WindowRef oldFrontWindow
= NULL
;
2018 WindowRef newFrontWindow
= NULL
;
2020 // in case we don't take care of activating ourselves, we have to synchronize
2021 // our idea of the active window with the process manager's - which it already activated
2023 if ( !doesActivate
)
2024 oldFrontWindow
= ::FrontNonFloatingWindow() ;
2026 MacResume( convertClipboard
) ;
2028 newFrontWindow
= ::FrontNonFloatingWindow() ;
2030 if ( oldFrontWindow
)
2032 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
2034 win
->MacActivate( ev
->when
, false ) ;
2036 if ( newFrontWindow
)
2038 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
2040 win
->MacActivate( ev
->when
, true ) ;
2045 MacSuspend( convertClipboard
) ;
2049 case mouseMovedMessage
:
2053 wxWindow
* currentMouseWindow
= NULL
;
2055 if (s_captureWindow
)
2057 currentMouseWindow
= s_captureWindow
;
2061 wxWindow::MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) ,
2062 ¤tMouseWindow
) ;
2065 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
2067 wxMouseEvent event
;
2069 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
2070 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
2072 event
.m_leftDown
= isDown
&& !controlDown
;
2073 event
.m_middleDown
= FALSE
;
2074 event
.m_rightDown
= isDown
&& controlDown
;
2075 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
2076 event
.m_controlDown
= ev
->modifiers
& controlKey
;
2077 event
.m_altDown
= ev
->modifiers
& optionKey
;
2078 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
2079 event
.m_x
= ev
->where
.h
;
2080 event
.m_y
= ev
->where
.v
;
2081 event
.m_timeStamp
= ev
->when
;
2082 event
.SetEventObject(this);
2084 if ( wxWindow::s_lastMouseWindow
)
2086 wxMouseEvent
eventleave(event
);
2087 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
2088 wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
2089 eventleave
.SetEventObject( wxWindow::s_lastMouseWindow
) ;
2091 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
2093 if ( currentMouseWindow
)
2095 wxMouseEvent
evententer(event
);
2096 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
2097 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
2098 evententer
.SetEventObject( currentMouseWindow
) ;
2099 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
2101 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
2104 short windowPart
= inNoWindow
;
2106 if ( s_captureWindow
)
2108 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
2109 windowPart
= inContent
;
2113 windowPart
= ::FindWindow(ev
->where
, &window
);
2120 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2122 win
->MacMouseMoved( ev
, windowPart
) ;
2129 UMAShowArrowCursor();
2139 UMAShowArrowCursor();
2150 void wxApp::MacHandleMenuCommand( wxUint32 id
)
2152 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
2153 wxFrame
* frame
= mbar
->GetFrame();
2154 wxCHECK_RET( mbar
!= NULL
&& frame
!= NULL
, wxT("error in menu item callback") );
2157 frame
->ProcessCommand(id
);
2162 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
2165 return; // no menu item selected
2167 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
2170 Str255 deskAccessoryName
;
2173 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
2174 GetPort(&savedPort
);
2175 OpenDeskAcc(deskAccessoryName
);
2182 GetMenuItemCommandID( GetMenuHandle(macMenuId
) , macMenuItemNum
, &id
) ;
2183 MacHandleMenuCommand( id
) ;