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
;
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) && !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) && 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) && 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) && defined(__DARWIN__)
687 CFBundleRef gSharedLibraryBundle
= NULL
;
688 #endif /* WXMAKINGDLL && __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
;
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
748 OSErr theErr
= noErr
;
750 // get the library path
751 theSymbol
= NSLookupAndBindSymbol("_gSharedLibraryResource");
752 theModule
= NSModuleForSymbol(theSymbol
);
753 theLibPath
= NSLibraryNameForModule(theModule
);
755 // if we call wxLogDebug from here then, as wxTheApp hasn't been
756 // created yet when we're called from wxApp::Initialize(), wxLog
757 // is going to create a default stderr-based log target instead of
758 // the expected normal GUI one -- don't do it, if we really want
759 // to see this message just use fprintf() here
761 wxLogDebug( wxT("wxMac library installation name is '%s'"),
765 // allocate copy to replace .dylib.* extension with .rsrc
766 theResPath
= strdup(theLibPath
);
767 if (theResPath
!= NULL
) {
768 theName
= strrchr(theResPath
, '/');
769 if (theName
== NULL
) {
770 // no directory elements in path
771 theName
= theResPath
;
773 // find ".dylib" shared library extension
774 theExt
= strstr(theName
, ".dylib");
775 // overwrite extension with ".rsrc"
776 strcpy(theExt
, ".rsrc");
779 wxLogDebug( wxT("wxMac resources file name is '%s'"),
783 theErr
= FSPathMakeRef((UInt8
*) theResPath
, &theResRef
, false);
784 if (theErr
!= noErr
) {
785 // try in current directory (using name only)
786 theErr
= FSPathMakeRef((UInt8
*) theName
, &theResRef
, false);
789 // open the resource file
790 if (theErr
== noErr
) {
791 theErr
= FSOpenResourceFile( &theResRef
, 0, NULL
, fsRdPerm
,
792 &gSharedLibraryResource
);
794 if (theErr
!= noErr
) {
797 wxT("unable to open wxMac resource file '%s'\n"),
799 #endif // __WXDEBUG__
802 // free duplicated resource file path
806 #endif /* __DARWIN__ */
808 #endif /* WXMAKINGDLL */
811 void wxStAppResource::CloseSharedLibraryResource()
814 // Close the shared library resource file
815 if (gSharedLibraryResource
!= kResFileNotOpened
) {
817 if (gSharedLibraryBundle
!= NULL
) {
818 CFBundleCloseBundleResourceMap(gSharedLibraryBundle
,
819 gSharedLibraryResource
);
820 gSharedLibraryBundle
= NULL
;
823 #endif /* __DARWIN__ */
825 CloseResFile(gSharedLibraryResource
);
827 gSharedLibraryResource
= kResFileNotOpened
;
829 #endif /* WXMAKINGDLL */
832 #if defined(WXMAKINGDLL) && !defined(__DARWIN__)
834 // for shared libraries we have to manually get the correct resource
835 // ref num upon initializing and releasing when terminating, therefore
836 // the __wxinitialize and __wxterminate must be used
839 void __sinit(void); /* (generated by linker) */
840 pascal OSErr
__initialize(const CFragInitBlock
*theInitBlock
);
841 pascal void __terminate(void);
844 pascal OSErr
__wxinitialize(const CFragInitBlock
*theInitBlock
)
846 wxStAppResource::OpenSharedLibraryResource( theInitBlock
) ;
847 return __initialize( theInitBlock
) ;
850 pascal void __wxterminate(void)
852 wxStAppResource::CloseSharedLibraryResource() ;
856 #endif /* WXMAKINGDLL && !__DARWIN__ */
860 bool wxMacConvertEventToRecord( EventRef event
, EventRecord
*rec
)
862 bool converted
= ConvertEventRefToEventRecord( event
,rec
) ;
863 OSStatus err
= noErr
;
866 switch( GetEventClass( event
) )
868 case kEventClassKeyboard
:
871 switch( GetEventKind(event
) )
873 case kEventRawKeyDown
:
874 rec
->what
= keyDown
;
876 case kEventRawKeyRepeat
:
877 rec
->what
= autoKey
;
879 case kEventRawKeyUp
:
882 case kEventRawKeyModifiersChanged
:
883 rec
->what
= nullEvent
;
892 unsigned char charCode
;
894 GetMouse( &rec
->where
) ;
896 err
= GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
897 err
= GetEventParameter(event
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
898 err
= GetEventParameter(event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
899 rec
->modifiers
= modifiers
;
900 rec
->message
= (keyCode
<< 8 ) + charCode
;
904 case kEventClassTextInput
:
906 switch( GetEventKind( event
) )
908 case kEventTextInputUnicodeForKeyEvent
:
911 err
= GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent
) ;
915 unsigned char charCode
;
917 GetMouse( &rec
->where
) ;
918 rec
->what
= keyDown
;
919 err
= GetEventParameter(rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
920 err
= GetEventParameter(rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
921 err
= GetEventParameter(rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
922 rec
->modifiers
= modifiers
;
923 rec
->message
= (keyCode
<< 8 ) + charCode
;
939 pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
941 OSStatus result = eventNotHandledErr ;
944 switch ( GetEventClass( event ) )
946 case kEventClassKeyboard :
947 if ( wxMacConvertEventToRecord( event , &rec ) )
949 wxTheApp->MacHandleModifierEvents( &rec ) ;
950 wxTheApp->MacHandleOneEvent( &rec ) ;
954 case kEventClassTextInput :
955 if ( wxMacConvertEventToRecord( event , &rec ) )
957 wxTheApp->MacHandleModifierEvents( &rec ) ;
958 wxTheApp->MacHandleOneEvent( &rec ) ;
972 m_printMode
= wxPRINT_WINDOWS
;
975 m_macCurrentEvent
= NULL
;
976 m_macCurrentEventHandlerCallRef
= NULL
;
979 bool wxApp::Initialized()
987 int wxApp::MainLoop()
999 void wxApp::ExitMainLoop()
1001 m_keepGoing
= FALSE
;
1004 // Is a message/event pending?
1005 bool wxApp::Pending()
1008 return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ;
1012 return EventAvail( everyEvent
, &event
) ;
1016 // Dispatch a message.
1017 void wxApp::Dispatch()
1022 void wxApp::OnIdle(wxIdleEvent
& event
)
1024 wxAppBase::OnIdle(event
);
1026 // If they are pending events, we must process them: pending events are
1027 // either events to the threads other than main or events posted with
1028 // wxPostEvent() functions
1029 wxMacProcessNotifierAndPendingEvents();
1031 if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
1032 wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
1035 void wxApp::WakeUpIdle()
1046 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
1049 GetTopWindow()->Close(TRUE
);
1052 // Default behaviour: close the application with prompts. The
1053 // user can veto the close, and therefore the end session.
1054 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
1058 if (!GetTopWindow()->Close(!event
.CanVeto()))
1063 extern "C" void wxCYield() ;
1069 // Yield to other processes
1071 bool wxApp::Yield(bool onlyIfNeeded
)
1075 if ( !onlyIfNeeded
)
1077 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1086 YieldToAnyThread() ;
1088 // by definition yield should handle all non-processed events
1092 OSStatus status
= noErr
;
1095 s_inReceiveEvent
= true ;
1096 status
= ReceiveNextEvent(0, NULL
,kEventDurationNoWait
,true,&theEvent
) ;
1097 s_inReceiveEvent
= false ;
1099 if ( status
== eventLoopTimedOutErr
)
1101 // make sure next time the event loop will trigger idle events
1102 sleepTime
= kEventDurationNoWait
;
1104 else if ( status
== eventLoopQuitErr
)
1106 // according to QA1061 this may also occur when a WakeUp Process
1111 MacHandleOneEvent( theEvent
) ;
1112 ReleaseEvent(theEvent
);
1114 } while( status
== noErr
) ;
1118 // having a larger value here leads to large performance slowdowns
1119 // so we cannot give background apps more processor time here
1120 // we do so however having a large sleep value in the main event loop
1123 while ( !IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, (RgnHandle
) wxApp::s_macCursorRgn
))
1125 MacHandleModifierEvents( &event
) ;
1126 MacHandleOneEvent( &event
);
1127 if ( event
.what
!= kHighLevelEvent
)
1128 SetRectRgn( (RgnHandle
) wxApp::s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1130 MacHandleModifierEvents( &event
) ;
1133 wxMacProcessNotifierAndPendingEvents() ;
1139 // platform specifics
1141 void wxApp::MacSuspend( bool convertClipboard
)
1144 // we have to deactive the top level windows manually
1146 wxWindowListNode
* node
= wxTopLevelWindows
.GetFirst();
1149 wxTopLevelWindow
* win
= (wxTopLevelWindow
*) node
->Data();
1151 #if 0 // having problems right now with that
1152 if (!win
->HasFlag(wxSTAY_ON_TOP
))
1155 win
->MacActivate( ((EventRecord
*) MacGetCurrentEvent())->when
, false ) ;
1157 node
= node
->GetNext();
1160 ::HideFloatingWindows() ;
1162 s_lastMouseDown
= 0 ;
1164 if( convertClipboard
)
1166 MacConvertPrivateToPublicScrap() ;
1170 extern wxList wxModalDialogs
;
1172 void wxApp::MacResume( bool convertClipboard
)
1174 s_lastMouseDown
= 0 ;
1175 if( convertClipboard
)
1177 MacConvertPublicToPrivateScrap() ;
1181 ::ShowFloatingWindows() ;
1182 // raise modal dialogs in case a non modal window was selected to activate the app
1184 wxNode
* node
= wxModalDialogs
.GetFirst();
1187 wxDialog
* dialog
= (wxDialog
*) node
->GetData();
1190 node
= node
->GetNext();
1195 void wxApp::MacConvertPrivateToPublicScrap()
1199 void wxApp::MacConvertPublicToPrivateScrap()
1203 void wxApp::MacDoOneEvent()
1208 s_inReceiveEvent
= true ;
1209 OSStatus status
= ReceiveNextEvent(0, NULL
,sleepTime
,true,&theEvent
) ;
1210 s_inReceiveEvent
= false ;
1211 if ( status
== eventLoopTimedOutErr
)
1213 if ( wxTheApp
->ProcessIdle() )
1214 sleepTime
= kEventDurationNoWait
;
1216 sleepTime
= kEventDurationForever
;
1218 else if ( status
== eventLoopQuitErr
)
1220 // according to QA1061 this may also occur when a WakeUp Process
1225 MacHandleOneEvent( theEvent
) ;
1226 ReleaseEvent(theEvent
);
1227 sleepTime
= kEventDurationNoWait
;
1232 EventMask eventMask
= everyEvent
;
1234 if (WaitNextEvent(eventMask
, &event
, sleepTime
, (RgnHandle
) s_macCursorRgn
))
1236 MacHandleModifierEvents( &event
) ;
1237 MacHandleOneEvent( &event
);
1241 MacHandleModifierEvents( &event
) ;
1243 WindowPtr window
= ::FrontWindow() ;
1245 ::IdleControls( window
) ;
1247 if ( wxTheApp
->ProcessIdle() )
1250 sleepTime
= GetCaretTime() / 2 ;
1252 if ( event
.what
!= kHighLevelEvent
)
1253 SetRectRgn( (RgnHandle
) s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1257 DeletePendingObjects() ;
1258 wxMacProcessNotifierAndPendingEvents() ;
1261 void wxApp::MacHandleOneEvent( WXEVENTREF evr
)
1264 EventTargetRef theTarget
;
1265 theTarget
= GetEventDispatcherTarget();
1266 m_macCurrentEvent
= evr
;
1267 SendEventToEventTarget ((EventRef
) evr
, theTarget
);
1269 EventRecord
* ev
= (EventRecord
*) evr
;
1270 m_macCurrentEvent
= ev
;
1272 wxApp::sm_lastMessageTime
= ev
->when
;
1277 MacHandleMouseDownEvent( ev
) ;
1278 if ( ev
->modifiers
& controlKey
)
1279 s_lastMouseDown
= 2;
1281 s_lastMouseDown
= 1;
1284 if ( s_lastMouseDown
== 2 )
1286 ev
->modifiers
|= controlKey
;
1290 ev
->modifiers
&= ~controlKey
;
1292 MacHandleMouseUpEvent( ev
) ;
1293 s_lastMouseDown
= 0;
1296 MacHandleActivateEvent( ev
) ;
1299 MacHandleUpdateEvent( ev
) ;
1303 MacHandleKeyDownEvent( ev
) ;
1306 MacHandleKeyUpEvent( ev
) ;
1309 MacHandleDiskEvent( ev
) ;
1312 MacHandleOSEvent( ev
) ;
1314 case kHighLevelEvent
:
1315 MacHandleHighLevelEvent( ev
) ;
1321 wxMacProcessNotifierAndPendingEvents() ;
1325 bool s_macIsInModalLoop
= false ;
1327 void wxApp::MacHandleModifierEvents( WXEVENTREF evr
)
1329 EventRecord
* ev
= (EventRecord
*) evr
;
1330 if ( ev
->modifiers
!= s_lastModifiers
&& wxWindow::FindFocus() != NULL
)
1332 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1334 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1335 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1336 event
.m_altDown
= ev
->modifiers
& optionKey
;
1337 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1339 event
.m_x
= ev
->where
.h
;
1340 event
.m_y
= ev
->where
.v
;
1341 event
.m_timeStamp
= ev
->when
;
1342 wxWindow
* focus
= wxWindow::FindFocus() ;
1343 event
.SetEventObject(focus
);
1345 if ( (ev
->modifiers
^ s_lastModifiers
) & controlKey
)
1347 event
.m_keyCode
= WXK_CONTROL
;
1348 event
.SetEventType( ( ev
->modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1349 focus
->GetEventHandler()->ProcessEvent( event
) ;
1351 if ( (ev
->modifiers
^ s_lastModifiers
) & shiftKey
)
1353 event
.m_keyCode
= WXK_SHIFT
;
1354 event
.SetEventType( ( ev
->modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1355 focus
->GetEventHandler()->ProcessEvent( event
) ;
1357 if ( (ev
->modifiers
^ s_lastModifiers
) & optionKey
)
1359 event
.m_keyCode
= WXK_ALT
;
1360 event
.SetEventType( ( ev
->modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1361 focus
->GetEventHandler()->ProcessEvent( event
) ;
1363 if ( ev
->modifiers
^ s_lastModifiers
) & cmdKey
)
1365 event
.m_keyCode
= WXK_COMMAND
;
1366 event
.SetEventType( ( ev
->modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1367 focus
->GetEventHandler()->ProcessEvent( event
) ;
1369 s_lastModifiers
= ev
->modifiers
;
1373 void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr
)
1375 // we must avoid reentrancy problems when processing high level events eg printing
1376 bool former
= s_inYield
;
1378 EventRecord
* ev
= (EventRecord
*) evr
;
1379 ::AEProcessAppleEvent( ev
) ;
1380 s_inYield
= former
;
1383 void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr
)
1385 EventRecord
* ev
= (EventRecord
*) evr
;
1386 wxToolTip::RemoveToolTips() ;
1389 WindowRef frontWindow
= ::FrontNonFloatingWindow() ;
1390 WindowAttributes frontWindowAttributes
= NULL
;
1392 ::GetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
1394 short windowPart
= ::FindWindow(ev
->where
, &window
);
1395 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1396 if ( wxPendingDelete
.Member(win
) )
1400 GetQDGlobalsScreenBits( &screenBits
);
1405 if ( s_macIsInModalLoop
)
1411 UInt32 menuresult
= MenuSelect(ev
->where
) ;
1412 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1413 s_lastMouseDown
= 0;
1417 SystemClick( ev
, window
) ;
1418 s_lastMouseDown
= 0;
1421 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1427 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1432 Point pt
= { 0, 0 } ;
1433 SetPortWindowPort(window
) ;
1434 LocalToGlobal( &pt
) ;
1436 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1437 -1 , wxSIZE_USE_EXISTING
);
1439 s_lastMouseDown
= 0;
1443 if (TrackGoAway(window
, ev
->where
))
1448 s_lastMouseDown
= 0;
1452 Rect newContentRect
;
1453 Rect constraintRect
;
1454 constraintRect
.top
= win
->GetMinHeight() ;
1455 if ( constraintRect
.top
== -1 )
1456 constraintRect
.top
= 0 ;
1457 constraintRect
.left
= win
->GetMinWidth() ;
1458 if ( constraintRect
.left
== -1 )
1459 constraintRect
.left
= 0 ;
1460 constraintRect
.right
= win
->GetMaxWidth() ;
1461 if ( constraintRect
.right
== -1 )
1462 constraintRect
.right
= 32000 ;
1463 constraintRect
.bottom
= win
->GetMaxHeight() ;
1464 if ( constraintRect
.bottom
== -1 )
1465 constraintRect
.bottom
= 32000 ;
1467 Boolean growResult
= ResizeWindow( window
, ev
->where
,
1468 &constraintRect
, &newContentRect
) ;
1471 win
->SetSize( newContentRect
.left
, newContentRect
.top
,
1472 newContentRect
.right
- newContentRect
.left
,
1473 newContentRect
.bottom
- newContentRect
.top
, wxSIZE_USE_EXISTING
);
1475 s_lastMouseDown
= 0;
1480 if (TrackBox(window
, ev
->where
, windowPart
))
1482 // TODO setup size event
1483 ZoomWindow( window
, windowPart
, false ) ;
1489 Point pt
= { 0, 0 } ;
1490 SetPortWindowPort(window
) ;
1491 LocalToGlobal( &pt
) ;
1494 GetWindowPortBounds(window
, &tempRect
) ;
1495 win
->SetSize( pt
.h
, pt
.v
, tempRect
.right
-tempRect
.left
,
1496 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1499 s_lastMouseDown
= 0;
1501 case inCollapseBox
:
1502 // TODO setup size event
1503 s_lastMouseDown
= 0;
1510 SetPortWindowPort(window
) ;
1513 if ( window
!= frontWindow
&& wxTheApp
->s_captureWindow
== NULL
)
1515 if ( s_macIsInModalLoop
)
1519 else if ( UMAIsWindowFloating( window
) )
1522 win
->MacMouseDown( ev
, windowPart
) ;
1527 win
->MacMouseDown( ev
, windowPart
) ;
1528 ::SelectWindow( window
) ;
1534 win
->MacMouseDown( ev
, windowPart
) ;
1542 void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr
)
1544 EventRecord
* ev
= (EventRecord
*) evr
;
1547 short windowPart
= inNoWindow
;
1548 if ( wxTheApp
->s_captureWindow
)
1550 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
1551 windowPart
= inContent
;
1555 windowPart
= ::FindWindow(ev
->where
, &window
) ;
1566 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1568 win
->MacMouseUp( ev
, windowPart
) ;
1576 long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
1577 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1582 case kHomeCharCode
:
1585 case kEnterCharCode
:
1586 retval
= WXK_RETURN
;
1591 case kHelpCharCode
:
1594 case kBackspaceCharCode
:
1600 case kPageUpCharCode
:
1601 retval
= WXK_PAGEUP
;
1603 case kPageDownCharCode
:
1604 retval
= WXK_PAGEDOWN
;
1606 case kReturnCharCode
:
1607 retval
= WXK_RETURN
;
1609 case kFunctionKeyCharCode
:
1661 case kEscapeCharCode
:
1662 retval
= WXK_ESCAPE
;
1664 case kLeftArrowCharCode
:
1667 case kRightArrowCharCode
:
1668 retval
= WXK_RIGHT
;
1670 case kUpArrowCharCode
:
1673 case kDownArrowCharCode
:
1676 case kDeleteCharCode
:
1677 retval
= WXK_DELETE
;
1686 void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr
)
1688 EventRecord
* ev
= (EventRecord
*) evr
;
1689 wxToolTip::RemoveToolTips() ;
1691 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1692 if ( HiWord( menuresult
) )
1694 if ( !s_macIsInModalLoop
)
1695 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1699 wxWindow
* focus
= wxWindow::FindFocus() ;
1701 if ( MacSendKeyDownEvent( focus
, ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) == false )
1704 // we must handle control keys the other way round, otherwise text content is updated too late
1705 // has not been handled -> perform default
1706 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
1707 if ( control
&& control
->GetMacControl() != NULL
)
1711 keychar
= short(ev
->message
& charCodeMask
);
1712 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1713 ::HandleControlKey( (ControlHandle
) control
->GetMacControl() , keycode
, keychar
, ev
->modifiers
) ;
1720 void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr
)
1722 EventRecord
* ev
= (EventRecord
*) evr
;
1723 wxToolTip::RemoveToolTips() ;
1725 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1726 if ( HiWord( menuresult
) )
1731 MacSendKeyUpEvent( wxWindow::FindFocus() , ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) ;
1737 bool wxApp::MacSendKeyDownEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
)
1744 keychar
= short(keymessage
& charCodeMask
);
1745 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
1747 if ( modifiers
& ( controlKey
|shiftKey
|optionKey
) )
1749 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1750 // and look at the character after
1752 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
);
1753 keychar
= short(keyInfo
& charCodeMask
);
1754 keycode
= short(keyInfo
& keyCodeMask
) >> 8 ;
1756 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1757 long realkeyval
= keyval
;
1758 if ( keyval
== keychar
)
1760 // 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)
1761 realkeyval
= short(keymessage
& charCodeMask
) ;
1762 keyval
= wxToupper( keyval
) ;
1765 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1766 bool handled
= false ;
1767 event
.m_shiftDown
= modifiers
& shiftKey
;
1768 event
.m_controlDown
= modifiers
& controlKey
;
1769 event
.m_altDown
= modifiers
& optionKey
;
1770 event
.m_metaDown
= modifiers
& cmdKey
;
1771 event
.m_keyCode
= keyval
;
1775 event
.m_timeStamp
= when
;
1776 event
.SetEventObject(focus
);
1777 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1778 if ( handled
&& event
.GetSkipped() )
1785 wxWindow
*ancestor
= focus
;
1788 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1791 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1792 handled
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1795 if (ancestor
->IsTopLevel())
1797 ancestor
= ancestor
->GetParent();
1800 #endif // wxUSE_ACCEL
1804 event
.Skip( FALSE
) ;
1805 event
.SetEventType( wxEVT_CHAR
) ;
1807 event
.m_keyCode
= realkeyval
;
1809 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1810 if ( handled
&& event
.GetSkipped() )
1814 (keyval
== WXK_TAB
) &&
1815 // CS: copied the change below from wxGTK
1816 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
1817 // have this style, yet choose not to process this particular TAB in which
1818 // case TAB must still work as a navigational character
1820 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1822 (focus
->GetParent()) &&
1823 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1825 wxNavigationKeyEvent new_event
;
1826 new_event
.SetEventObject( focus
);
1827 new_event
.SetDirection( !event
.ShiftDown() );
1828 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1829 new_event
.SetWindowChange( event
.ControlDown() );
1830 new_event
.SetCurrentFocus( focus
);
1831 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1832 if ( handled
&& new_event
.GetSkipped() )
1835 // backdoor handler for default return and command escape
1836 if ( !handled
&& (!focus
->IsKindOf(CLASSINFO(wxControl
) ) || !focus
->MacCanFocus() ) )
1838 // if window is not having a focus still testing for default enter or cancel
1839 // TODO add the UMA version for ActiveNonFloatingWindow
1840 wxWindow
* focus
= wxFindWinFromMacWindow( FrontWindow() ) ;
1843 if ( keyval
== WXK_RETURN
)
1845 wxButton
*def
= wxDynamicCast(focus
->GetDefaultItem(),
1847 if ( def
&& def
->IsEnabled() )
1849 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
1850 event
.SetEventObject(def
);
1851 def
->Command(event
);
1855 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1856 else if (keyval
== WXK_ESCAPE
|| (keyval
== '.' && modifiers
& cmdKey
) )
1858 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1859 new_event
.SetEventObject( focus
);
1860 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1867 bool wxApp::MacSendKeyUpEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
)
1874 keychar
= short(keymessage
& charCodeMask
);
1875 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
1876 if ( modifiers
& ( controlKey
|shiftKey
|optionKey
) )
1878 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1879 // and look at the character after
1881 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
);
1882 keychar
= short(keyInfo
& charCodeMask
);
1883 keycode
= short(keyInfo
& keyCodeMask
) >> 8 ;
1885 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1887 if ( keyval
== keychar
)
1889 keyval
= wxToupper( keyval
) ;
1891 bool handled
= false ;
1893 wxKeyEvent
event(wxEVT_KEY_UP
);
1894 event
.m_shiftDown
= modifiers
& shiftKey
;
1895 event
.m_controlDown
= modifiers
& controlKey
;
1896 event
.m_altDown
= modifiers
& optionKey
;
1897 event
.m_metaDown
= modifiers
& cmdKey
;
1898 event
.m_keyCode
= keyval
;
1902 event
.m_timeStamp
= when
;
1903 event
.SetEventObject(focus
);
1904 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1910 void wxApp::MacHandleActivateEvent( WXEVENTREF evr
)
1912 EventRecord
* ev
= (EventRecord
*) evr
;
1913 WindowRef window
= (WindowRef
) ev
->message
;
1916 bool activate
= (ev
->modifiers
& activeFlag
) ;
1917 WindowClass wclass
;
1918 ::GetWindowClass ( window
, &wclass
) ;
1919 if ( wclass
== kFloatingWindowClass
)
1921 // if it is a floater we activate/deactivate the front non-floating window instead
1922 window
= ::FrontNonFloatingWindow() ;
1924 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1926 win
->MacActivate( ev
->when
, activate
) ;
1930 void wxApp::MacHandleUpdateEvent( WXEVENTREF evr
)
1932 EventRecord
* ev
= (EventRecord
*) evr
;
1933 WindowRef window
= (WindowRef
) ev
->message
;
1934 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1937 if ( !wxPendingDelete
.Member(win
) )
1938 win
->MacUpdate( ev
->when
) ;
1942 // since there is no way of telling this foreign window to update itself
1943 // we have to invalidate the update region otherwise we keep getting the same
1944 // event over and over again
1945 BeginUpdate( window
) ;
1946 EndUpdate( window
) ;
1950 void wxApp::MacHandleDiskEvent( WXEVENTREF evr
)
1952 EventRecord
* ev
= (EventRecord
*) evr
;
1953 if ( HiWord( ev
->message
) != noErr
)
1957 SetPt( &point
, 100 , 100 ) ;
1959 err
= DIBadMount( point
, ev
->message
) ;
1960 wxASSERT( err
== noErr
) ;
1964 void wxApp::MacHandleOSEvent( WXEVENTREF evr
)
1966 EventRecord
* ev
= (EventRecord
*) evr
;
1967 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
1969 case suspendResumeMessage
:
1971 bool isResuming
= ev
->message
& resumeFlag
;
1972 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
1974 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
1977 WindowRef oldFrontWindow
= NULL
;
1978 WindowRef newFrontWindow
= NULL
;
1980 // in case we don't take care of activating ourselves, we have to synchronize
1981 // our idea of the active window with the process manager's - which it already activated
1983 if ( !doesActivate
)
1984 oldFrontWindow
= ::FrontNonFloatingWindow() ;
1986 MacResume( convertClipboard
) ;
1988 newFrontWindow
= ::FrontNonFloatingWindow() ;
1990 if ( oldFrontWindow
)
1992 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
1994 win
->MacActivate( ev
->when
, false ) ;
1996 if ( newFrontWindow
)
1998 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
2000 win
->MacActivate( ev
->when
, true ) ;
2005 MacSuspend( convertClipboard
) ;
2009 case mouseMovedMessage
:
2013 wxWindow
* currentMouseWindow
= NULL
;
2015 if (s_captureWindow
)
2017 currentMouseWindow
= s_captureWindow
;
2021 wxWindow::MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) ,
2022 ¤tMouseWindow
) ;
2025 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
2027 wxMouseEvent event
;
2029 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
2030 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
2032 event
.m_leftDown
= isDown
&& !controlDown
;
2033 event
.m_middleDown
= FALSE
;
2034 event
.m_rightDown
= isDown
&& controlDown
;
2035 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
2036 event
.m_controlDown
= ev
->modifiers
& controlKey
;
2037 event
.m_altDown
= ev
->modifiers
& optionKey
;
2038 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
2039 event
.m_x
= ev
->where
.h
;
2040 event
.m_y
= ev
->where
.v
;
2041 event
.m_timeStamp
= ev
->when
;
2042 event
.SetEventObject(this);
2044 if ( wxWindow::s_lastMouseWindow
)
2046 wxMouseEvent
eventleave(event
);
2047 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
2048 wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
2049 eventleave
.SetEventObject( wxWindow::s_lastMouseWindow
) ;
2051 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
2053 if ( currentMouseWindow
)
2055 wxMouseEvent
evententer(event
);
2056 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
2057 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
2058 evententer
.SetEventObject( currentMouseWindow
) ;
2059 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
2061 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
2064 short windowPart
= inNoWindow
;
2066 if ( s_captureWindow
)
2068 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
2069 windowPart
= inContent
;
2073 windowPart
= ::FindWindow(ev
->where
, &window
);
2080 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2082 win
->MacMouseMoved( ev
, windowPart
) ;
2089 UMAShowArrowCursor();
2099 UMAShowArrowCursor();
2110 void wxApp::MacHandleMenuCommand( wxUint32 id
)
2112 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
2113 wxFrame
* frame
= mbar
->GetFrame();
2114 wxCHECK_RET( mbar
!= NULL
&& frame
!= NULL
, wxT("error in menu item callback") );
2117 frame
->ProcessCommand(id
);
2122 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
2125 return; // no menu item selected
2127 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
2130 Str255 deskAccessoryName
;
2133 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
2134 GetPort(&savedPort
);
2135 OpenDeskAcc(deskAccessoryName
);
2142 GetMenuItemCommandID( GetMenuHandle(macMenuId
) , macMenuItemNum
, &id
) ;
2143 MacHandleMenuCommand( id
) ;