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 { kEventClassMenu
, kEventMenuOpening
},
292 { kEventClassMenu
, kEventMenuClosed
},
294 { kEventClassApplication
, kEventAppActivated
} ,
295 { kEventClassApplication
, kEventAppDeactivated
} ,
296 // handling the quit event is not recommended by apple
297 // rather using the quit apple event - which we do
299 { kEventClassAppleEvent
, kEventAppleEvent
} ,
301 { kEventClassMouse
, kEventMouseDown
} ,
305 static pascal OSStatus
306 MenuEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
308 // FIXME: this doesn't work for multiple windows
309 wxWindow
*win
= wxTheApp
->GetTopWindow();
312 // VZ: we could find the menu from its handle here by examining all
313 // the menus in the menu bar recursively but knowing that neither
314 // wxMSW nor wxGTK do it why bother...
318 GetEventParameter(event
,
319 kEventParamDirectObject
,
321 sizeof(menuRef
), NULL
,
325 wxMenuEvent
wxevent(GetEventKind(event
) == kEventMenuOpening
328 wxevent
.SetEventObject(win
);
330 (void)win
->GetEventHandler()->ProcessEvent(wxevent
);
333 return eventNotHandledErr
;
336 // due to the rather low-level event API of wxWindows, we cannot use RunApplicationEventLoop
337 // but have to use ReceiveNextEvent dealing with events manually, therefore we also have
338 // deal with clicks in the menu bar explicitely
340 static pascal OSStatus
MouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
342 OSStatus result
= eventNotHandledErr
;
344 switch( GetEventKind(event
) )
346 case kEventMouseDown
:
351 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
352 sizeof( Point
), NULL
, &point
);
353 short windowPart
= ::FindWindow(point
, &window
);
355 if ( windowPart
== inMenuBar
)
357 MenuSelect( point
) ;
367 static pascal OSStatus
CommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
369 OSStatus result
= eventNotHandledErr
;
373 GetEventParameter( event
, kEventParamDirectObject
, typeHICommand
, NULL
,
374 sizeof( HICommand
), NULL
, &command
);
376 MenuCommand id
= command
.commandID
;
377 if ( id
== kHICommandPreferences
)
378 id
= wxApp::s_macPreferencesMenuItemId
;
380 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
381 wxMenu
* menu
= NULL
;
382 wxMenuItem
* item
= NULL
;
385 item
= mbar
->FindItem( id
, &menu
) ;
387 if ( item
== NULL
|| menu
== NULL
|| mbar
== NULL
)
390 switch( GetEventKind( event
) )
392 case kEventProcessCommand
:
394 if (item
->IsCheckable())
396 item
->Check( !item
->IsChecked() ) ;
399 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
403 case kEventCommandUpdateStatus
:
404 // eventually trigger an updateui round
414 static pascal OSStatus
ApplicationEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
416 OSStatus result
= eventNotHandledErr
;
417 switch ( GetEventKind( event
) )
419 case kEventAppActivated
:
422 wxTheApp
->MacResume( true ) ;
426 case kEventAppDeactivated
:
429 wxTheApp
->MacSuspend( true ) ;
439 pascal OSStatus
wxAppEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
441 OSStatus result
= eventNotHandledErr
;
442 switch( GetEventClass( event
) )
444 case kEventClassCommand
:
445 result
= CommandEventHandler( handler
, event
, data
) ;
447 case kEventClassApplication
:
448 result
= ApplicationEventHandler( handler
, event
, data
) ;
450 case kEventClassMenu
:
451 result
= MenuEventHandler( handler
, event
, data
) ;
453 case kEventClassMouse
:
454 result
= MouseEventHandler( handler
, event
, data
) ;
456 case kEventClassAppleEvent
:
459 wxMacConvertEventToRecord( event
, &rec
) ;
460 result
= AEProcessAppleEvent( &rec
) ;
470 DEFINE_ONE_SHOT_HANDLER_GETTER( wxAppEventHandler
)
474 #if defined(WXMAKINGDLL) && !defined(__DARWIN__)
475 // we know it's there ;-)
476 WXIMPORT
char std::__throws_bad_alloc
;
479 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
485 UMAInitToolbox( 4 ) ;
486 SetEventMask( everyEvent
) ;
487 UMAShowWatchCursor() ;
489 #if defined(WXMAKINGDLL) && defined(__DARWIN__)
490 // open shared library resources from here since we don't have
491 // __wxinitialize in Mach-O shared libraries
492 wxStAppResource::OpenSharedLibraryResource(NULL
);
496 // test the minimal configuration necessary
502 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
504 error
= kMacSTRWrongMachine
;
506 else if (theMachine
< gestaltMacPlus
)
508 error
= kMacSTRWrongMachine
;
510 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
512 error
= kMacSTROldSystem
;
514 else if ( theSystem
< 0x0860 )
516 error
= kMacSTROldSystem
;
518 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
520 error
= kMacSTRSmallSize
;
526 if ( !UMAHasAppearance() )
528 error = kMacSTRNoPre8Yet ;
534 // if we encountered any problems so far, give the error code and exit immediately
538 wxStAppResource resload
;
542 GetIndString(message
, 128, error
);
543 UMAShowArrowCursor() ;
544 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
545 itemHit
= Alert(128, nil
);
550 # if __option(profile)
551 ProfilerInit( collectDetailed
, bestTimeBase
, 20000 , 40 ) ;
556 // now avoid exceptions thrown for new (bad_alloc)
557 // FIXME CS for some changes outside wxMac does not compile anymore
559 std::__throws_bad_alloc
= 0 ;
563 wxMacSetupConverters() ;
565 s_macCursorRgn
= ::NewRgn() ;
567 // Mac OS X passes a process serial number command line argument when
568 // the application is launched from the Finder. This argument must be
569 // removed from the command line arguments before being handled by the
570 // application (otherwise applications would need to handle it)
573 static const wxChar
*ARG_PSN
= _T("-psn_");
574 if ( wxStrncmp(argv
[1], ARG_PSN
, sizeof(ARG_PSN
) - 1) == 0 )
576 // remove this argument
577 memmove(argv
, argv
+ 1, argc
--);
581 if ( !wxAppBase::Initialize(argc
, argv
) )
584 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
585 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
587 wxMacCreateNotifierTable() ;
589 UMAShowArrowCursor() ;
594 bool wxApp::OnInitGui()
596 if( !wxAppBase::OnInitGui() )
600 InstallStandardEventHandler( GetApplicationEventTarget() ) ;
602 InstallApplicationEventHandler(
603 GetwxAppEventHandlerUPP(),
604 GetEventTypeCount(eventList
), eventList
, wxTheApp
, (EventHandlerRef
*)&(wxTheApp
->m_macEventHandler
));
607 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
608 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
609 NewAEEventHandlerUPP(AEHandleODoc
) ,
611 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
612 NewAEEventHandlerUPP(AEHandleOApp
) ,
614 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
615 NewAEEventHandlerUPP(AEHandlePDoc
) ,
617 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
618 NewAEEventHandlerUPP(AEHandleQuit
) ,
621 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
622 NewAEEventHandlerProc(AEHandleODoc
) ,
624 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
625 NewAEEventHandlerProc(AEHandleOApp
) ,
627 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
628 NewAEEventHandlerProc(AEHandlePDoc
) ,
630 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
631 NewAEEventHandlerProc(AEHandleQuit
) ,
638 void wxApp::CleanUp()
640 wxToolTip::RemoveToolTips() ;
642 // One last chance for pending objects to be cleaned up
643 wxTheApp
->DeletePendingObjects();
645 wxMacDestroyNotifierTable() ;
647 delete wxWinMacWindowList
;
648 wxWinMacWindowList
= NULL
;
650 delete wxWinMacControlList
;
651 wxWinMacControlList
= NULL
;
654 # if __option(profile)
655 ProfilerDump( (StringPtr
)"\papp.prof" ) ;
660 #if defined(WXMAKINGDLL) && defined(__DARWIN__)
661 // close shared library resources from here since we don't have
662 // __wxterminate in Mach-O shared libraries
663 wxStAppResource::CloseSharedLibraryResource();
665 wxMacCleanupConverters() ;
667 UMACleanupToolbox() ;
668 if (s_macCursorRgn
) {
669 ::DisposeRgn((RgnHandle
)s_macCursorRgn
);
676 wxAppBase::CleanUp();
679 //----------------------------------------------------------------------
680 // misc initialization stuff
681 //----------------------------------------------------------------------
683 // extern variable for shared library resource id
684 // need to be able to find it with NSLookupAndBindSymbol
685 short gSharedLibraryResource
= kResFileNotOpened
;
687 #if defined(WXMAKINGDLL) && defined(__DARWIN__)
688 CFBundleRef gSharedLibraryBundle
= NULL
;
689 #endif /* WXMAKINGDLL && __DARWIN__ */
691 wxStAppResource::wxStAppResource()
693 m_currentRefNum
= CurResFile() ;
694 if ( gSharedLibraryResource
!= kResFileNotOpened
)
696 UseResFile( gSharedLibraryResource
) ;
700 wxStAppResource::~wxStAppResource()
702 if ( m_currentRefNum
!= kResFileNotOpened
)
704 UseResFile( m_currentRefNum
) ;
708 void wxStAppResource::OpenSharedLibraryResource(const void *initBlock
)
710 gSharedLibraryResource
= kResFileNotOpened
;
713 if ( initBlock
!= NULL
) {
714 const CFragInitBlock
*theInitBlock
= (const CFragInitBlock
*)initBlock
;
715 FSSpec
*fileSpec
= NULL
;
717 if (theInitBlock
->fragLocator
.where
== kDataForkCFragLocator
) {
718 fileSpec
= theInitBlock
->fragLocator
.u
.onDisk
.fileSpec
;
720 else if (theInitBlock
->fragLocator
.where
== kResourceCFragLocator
) {
721 fileSpec
= theInitBlock
->fragLocator
.u
.inSegs
.fileSpec
;
724 if (fileSpec
!= NULL
) {
725 gSharedLibraryResource
= FSpOpenResFile(fileSpec
, fsRdPerm
);
730 // Open the shared library resource file if it is not yet open
733 const char *theLibPath
;
735 gSharedLibraryBundle
= CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWindows"));
736 if (gSharedLibraryBundle
!= NULL
) {
737 // wxWindows has been bundled into a framework
738 // load the framework resources
740 gSharedLibraryResource
= CFBundleOpenBundleResourceMap(gSharedLibraryBundle
);
743 // wxWindows is a simple dynamic shared library
744 // load the resources from the data fork of a separate resource file
749 OSErr theErr
= noErr
;
751 // get the library path
752 theSymbol
= NSLookupAndBindSymbol("_gSharedLibraryResource");
753 theModule
= NSModuleForSymbol(theSymbol
);
754 theLibPath
= NSLibraryNameForModule(theModule
);
756 // if we call wxLogDebug from here then, as wxTheApp hasn't been
757 // created yet when we're called from wxApp::Initialize(), wxLog
758 // is going to create a default stderr-based log target instead of
759 // the expected normal GUI one -- don't do it, if we really want
760 // to see this message just use fprintf() here
762 wxLogDebug( wxT("wxMac library installation name is '%s'"),
766 // allocate copy to replace .dylib.* extension with .rsrc
767 theResPath
= strdup(theLibPath
);
768 if (theResPath
!= NULL
) {
769 theName
= strrchr(theResPath
, '/');
770 if (theName
== NULL
) {
771 // no directory elements in path
772 theName
= theResPath
;
774 // find ".dylib" shared library extension
775 theExt
= strstr(theName
, ".dylib");
776 // overwrite extension with ".rsrc"
777 strcpy(theExt
, ".rsrc");
780 wxLogDebug( wxT("wxMac resources file name is '%s'"),
784 theErr
= FSPathMakeRef((UInt8
*) theResPath
, &theResRef
, false);
785 if (theErr
!= noErr
) {
786 // try in current directory (using name only)
787 theErr
= FSPathMakeRef((UInt8
*) theName
, &theResRef
, false);
790 // open the resource file
791 if (theErr
== noErr
) {
792 theErr
= FSOpenResourceFile( &theResRef
, 0, NULL
, fsRdPerm
,
793 &gSharedLibraryResource
);
795 if (theErr
!= noErr
) {
798 wxT("unable to open wxMac resource file '%s'\n"),
800 #endif // __WXDEBUG__
803 // free duplicated resource file path
807 #endif /* __DARWIN__ */
809 #endif /* WXMAKINGDLL */
812 void wxStAppResource::CloseSharedLibraryResource()
815 // Close the shared library resource file
816 if (gSharedLibraryResource
!= kResFileNotOpened
) {
818 if (gSharedLibraryBundle
!= NULL
) {
819 CFBundleCloseBundleResourceMap(gSharedLibraryBundle
,
820 gSharedLibraryResource
);
821 gSharedLibraryBundle
= NULL
;
824 #endif /* __DARWIN__ */
826 CloseResFile(gSharedLibraryResource
);
828 gSharedLibraryResource
= kResFileNotOpened
;
830 #endif /* WXMAKINGDLL */
833 #if defined(WXMAKINGDLL) && !defined(__DARWIN__)
835 // for shared libraries we have to manually get the correct resource
836 // ref num upon initializing and releasing when terminating, therefore
837 // the __wxinitialize and __wxterminate must be used
840 void __sinit(void); /* (generated by linker) */
841 pascal OSErr
__initialize(const CFragInitBlock
*theInitBlock
);
842 pascal void __terminate(void);
845 pascal OSErr
__wxinitialize(const CFragInitBlock
*theInitBlock
)
847 wxStAppResource::OpenSharedLibraryResource( theInitBlock
) ;
848 return __initialize( theInitBlock
) ;
851 pascal void __wxterminate(void)
853 wxStAppResource::CloseSharedLibraryResource() ;
857 #endif /* WXMAKINGDLL && !__DARWIN__ */
861 bool wxMacConvertEventToRecord( EventRef event
, EventRecord
*rec
)
863 bool converted
= ConvertEventRefToEventRecord( event
,rec
) ;
864 OSStatus err
= noErr
;
867 switch( GetEventClass( event
) )
869 case kEventClassKeyboard
:
872 switch( GetEventKind(event
) )
874 case kEventRawKeyDown
:
875 rec
->what
= keyDown
;
877 case kEventRawKeyRepeat
:
878 rec
->what
= autoKey
;
880 case kEventRawKeyUp
:
883 case kEventRawKeyModifiersChanged
:
884 rec
->what
= nullEvent
;
893 unsigned char charCode
;
895 GetMouse( &rec
->where
) ;
897 err
= GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
898 err
= GetEventParameter(event
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
899 err
= GetEventParameter(event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
900 rec
->modifiers
= modifiers
;
901 rec
->message
= (keyCode
<< 8 ) + charCode
;
905 case kEventClassTextInput
:
907 switch( GetEventKind( event
) )
909 case kEventTextInputUnicodeForKeyEvent
:
912 err
= GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent
) ;
916 unsigned char charCode
;
918 GetMouse( &rec
->where
) ;
919 rec
->what
= keyDown
;
920 err
= GetEventParameter(rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
921 err
= GetEventParameter(rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
922 err
= GetEventParameter(rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
923 rec
->modifiers
= modifiers
;
924 rec
->message
= (keyCode
<< 8 ) + charCode
;
940 pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
942 OSStatus result = eventNotHandledErr ;
945 switch ( GetEventClass( event ) )
947 case kEventClassKeyboard :
948 if ( wxMacConvertEventToRecord( event , &rec ) )
950 wxTheApp->MacHandleModifierEvents( &rec ) ;
951 wxTheApp->MacHandleOneEvent( &rec ) ;
955 case kEventClassTextInput :
956 if ( wxMacConvertEventToRecord( event , &rec ) )
958 wxTheApp->MacHandleModifierEvents( &rec ) ;
959 wxTheApp->MacHandleOneEvent( &rec ) ;
979 m_printMode
= wxPRINT_WINDOWS
;
983 bool wxApp::Initialized()
991 int wxApp::MainLoop()
1003 void wxApp::ExitMainLoop()
1005 m_keepGoing
= FALSE
;
1008 // Is a message/event pending?
1009 bool wxApp::Pending()
1012 return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ;
1016 return EventAvail( everyEvent
, &event
) ;
1020 // Dispatch a message.
1021 void wxApp::Dispatch()
1026 void wxApp::OnIdle(wxIdleEvent
& event
)
1028 wxAppBase::OnIdle(event
);
1030 // If they are pending events, we must process them: pending events are
1031 // either events to the threads other than main or events posted with
1032 // wxPostEvent() functions
1033 wxMacProcessNotifierAndPendingEvents();
1035 if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
1036 wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
1039 void wxApp::WakeUpIdle()
1050 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
1053 GetTopWindow()->Close(TRUE
);
1056 // Default behaviour: close the application with prompts. The
1057 // user can veto the close, and therefore the end session.
1058 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
1062 if (!GetTopWindow()->Close(!event
.CanVeto()))
1067 extern "C" void wxCYield() ;
1073 // Yield to other processes
1075 bool wxApp::Yield(bool onlyIfNeeded
)
1079 if ( !onlyIfNeeded
)
1081 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1090 YieldToAnyThread() ;
1092 // by definition yield should handle all non-processed events
1096 OSStatus status
= noErr
;
1099 s_inReceiveEvent
= true ;
1100 status
= ReceiveNextEvent(0, NULL
,kEventDurationNoWait
,true,&theEvent
) ;
1101 s_inReceiveEvent
= false ;
1103 if ( status
== eventLoopTimedOutErr
)
1105 // make sure next time the event loop will trigger idle events
1106 sleepTime
= kEventDurationNoWait
;
1108 else if ( status
== eventLoopQuitErr
)
1110 // according to QA1061 this may also occur when a WakeUp Process
1115 MacHandleOneEvent( theEvent
) ;
1116 ReleaseEvent(theEvent
);
1118 } while( status
== noErr
) ;
1122 // having a larger value here leads to large performance slowdowns
1123 // so we cannot give background apps more processor time here
1124 // we do so however having a large sleep value in the main event loop
1127 while ( !IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, (RgnHandle
) wxApp::s_macCursorRgn
))
1129 MacHandleModifierEvents( &event
) ;
1130 MacHandleOneEvent( &event
);
1131 if ( event
.what
!= kHighLevelEvent
)
1132 SetRectRgn( (RgnHandle
) wxApp::s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1134 MacHandleModifierEvents( &event
) ;
1137 wxMacProcessNotifierAndPendingEvents() ;
1143 // platform specifics
1145 void wxApp::MacSuspend( bool convertClipboard
)
1148 // we have to deactive the top level windows manually
1150 wxWindowListNode
* node
= wxTopLevelWindows
.GetFirst();
1153 wxTopLevelWindow
* win
= (wxTopLevelWindow
*) node
->Data();
1155 #if 0 // having problems right now with that
1156 if (!win
->HasFlag(wxSTAY_ON_TOP
))
1159 win
->MacActivate( ((EventRecord
*) MacGetCurrentEvent())->when
, false ) ;
1161 node
= node
->GetNext();
1164 ::HideFloatingWindows() ;
1166 s_lastMouseDown
= 0 ;
1168 if( convertClipboard
)
1170 MacConvertPrivateToPublicScrap() ;
1174 extern wxList wxModalDialogs
;
1176 void wxApp::MacResume( bool convertClipboard
)
1178 s_lastMouseDown
= 0 ;
1179 if( convertClipboard
)
1181 MacConvertPublicToPrivateScrap() ;
1185 ::ShowFloatingWindows() ;
1186 // raise modal dialogs in case a non modal window was selected to activate the app
1188 wxNode
* node
= wxModalDialogs
.GetFirst();
1191 wxDialog
* dialog
= (wxDialog
*) node
->GetData();
1194 node
= node
->GetNext();
1199 void wxApp::MacConvertPrivateToPublicScrap()
1203 void wxApp::MacConvertPublicToPrivateScrap()
1207 void wxApp::MacDoOneEvent()
1212 s_inReceiveEvent
= true ;
1213 OSStatus status
= ReceiveNextEvent(0, NULL
,sleepTime
,true,&theEvent
) ;
1214 s_inReceiveEvent
= false ;
1215 if ( status
== eventLoopTimedOutErr
)
1217 if ( wxTheApp
->ProcessIdle() )
1218 sleepTime
= kEventDurationNoWait
;
1220 sleepTime
= kEventDurationForever
;
1222 else if ( status
== eventLoopQuitErr
)
1224 // according to QA1061 this may also occur when a WakeUp Process
1229 MacHandleOneEvent( theEvent
) ;
1230 ReleaseEvent(theEvent
);
1231 sleepTime
= kEventDurationNoWait
;
1236 EventMask eventMask
= everyEvent
;
1238 if (WaitNextEvent(eventMask
, &event
, sleepTime
, (RgnHandle
) s_macCursorRgn
))
1240 MacHandleModifierEvents( &event
) ;
1241 MacHandleOneEvent( &event
);
1245 MacHandleModifierEvents( &event
) ;
1247 WindowPtr window
= ::FrontWindow() ;
1249 ::IdleControls( window
) ;
1251 if ( wxTheApp
->ProcessIdle() )
1254 sleepTime
= GetCaretTime() / 2 ;
1256 if ( event
.what
!= kHighLevelEvent
)
1257 SetRectRgn( (RgnHandle
) s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1261 DeletePendingObjects() ;
1262 wxMacProcessNotifierAndPendingEvents() ;
1265 void wxApp::MacHandleOneEvent( WXEVENTREF evr
)
1268 EventTargetRef theTarget
;
1269 theTarget
= GetEventDispatcherTarget();
1270 m_macCurrentEvent
= evr
;
1271 SendEventToEventTarget ((EventRef
) evr
, theTarget
);
1273 EventRecord
* ev
= (EventRecord
*) evr
;
1274 m_macCurrentEvent
= ev
;
1276 wxApp::sm_lastMessageTime
= ev
->when
;
1281 MacHandleMouseDownEvent( ev
) ;
1282 if ( ev
->modifiers
& controlKey
)
1283 s_lastMouseDown
= 2;
1285 s_lastMouseDown
= 1;
1288 if ( s_lastMouseDown
== 2 )
1290 ev
->modifiers
|= controlKey
;
1294 ev
->modifiers
&= ~controlKey
;
1296 MacHandleMouseUpEvent( ev
) ;
1297 s_lastMouseDown
= 0;
1300 MacHandleActivateEvent( ev
) ;
1303 MacHandleUpdateEvent( ev
) ;
1307 MacHandleKeyDownEvent( ev
) ;
1310 MacHandleKeyUpEvent( ev
) ;
1313 MacHandleDiskEvent( ev
) ;
1316 MacHandleOSEvent( ev
) ;
1318 case kHighLevelEvent
:
1319 MacHandleHighLevelEvent( ev
) ;
1325 wxMacProcessNotifierAndPendingEvents() ;
1329 bool s_macIsInModalLoop
= false ;
1331 void wxApp::MacHandleModifierEvents( WXEVENTREF evr
)
1333 EventRecord
* ev
= (EventRecord
*) evr
;
1334 if ( ev
->modifiers
!= s_lastModifiers
&& wxWindow::FindFocus() != NULL
)
1336 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1338 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1339 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1340 event
.m_altDown
= ev
->modifiers
& optionKey
;
1341 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1343 event
.m_x
= ev
->where
.h
;
1344 event
.m_y
= ev
->where
.v
;
1345 event
.m_timeStamp
= ev
->when
;
1346 wxWindow
* focus
= wxWindow::FindFocus() ;
1347 event
.SetEventObject(focus
);
1349 if ( (ev
->modifiers
^ s_lastModifiers
) & controlKey
)
1351 event
.m_keyCode
= WXK_CONTROL
;
1352 event
.SetEventType( ( ev
->modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1353 focus
->GetEventHandler()->ProcessEvent( event
) ;
1355 if ( (ev
->modifiers
^ s_lastModifiers
) & shiftKey
)
1357 event
.m_keyCode
= WXK_SHIFT
;
1358 event
.SetEventType( ( ev
->modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1359 focus
->GetEventHandler()->ProcessEvent( event
) ;
1361 if ( (ev
->modifiers
^ s_lastModifiers
) & optionKey
)
1363 event
.m_keyCode
= WXK_ALT
;
1364 event
.SetEventType( ( ev
->modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1365 focus
->GetEventHandler()->ProcessEvent( event
) ;
1367 s_lastModifiers
= ev
->modifiers
;
1371 void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr
)
1373 // we must avoid reentrancy problems when processing high level events eg printing
1374 bool former
= s_inYield
;
1376 EventRecord
* ev
= (EventRecord
*) evr
;
1377 ::AEProcessAppleEvent( ev
) ;
1378 s_inYield
= former
;
1381 void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr
)
1383 EventRecord
* ev
= (EventRecord
*) evr
;
1384 wxToolTip::RemoveToolTips() ;
1387 WindowRef frontWindow
= ::FrontNonFloatingWindow() ;
1388 WindowAttributes frontWindowAttributes
= NULL
;
1390 ::GetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
1392 short windowPart
= ::FindWindow(ev
->where
, &window
);
1393 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1394 if ( wxPendingDelete
.Member(win
) )
1398 GetQDGlobalsScreenBits( &screenBits
);
1403 if ( s_macIsInModalLoop
)
1409 UInt32 menuresult
= MenuSelect(ev
->where
) ;
1410 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1411 s_lastMouseDown
= 0;
1415 SystemClick( ev
, window
) ;
1416 s_lastMouseDown
= 0;
1419 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1425 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1430 Point pt
= { 0, 0 } ;
1431 SetPortWindowPort(window
) ;
1432 LocalToGlobal( &pt
) ;
1434 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1435 -1 , wxSIZE_USE_EXISTING
);
1437 s_lastMouseDown
= 0;
1441 if (TrackGoAway(window
, ev
->where
))
1446 s_lastMouseDown
= 0;
1450 Rect newContentRect
;
1451 Rect constraintRect
;
1452 constraintRect
.top
= win
->GetMinHeight() ;
1453 if ( constraintRect
.top
== -1 )
1454 constraintRect
.top
= 0 ;
1455 constraintRect
.left
= win
->GetMinWidth() ;
1456 if ( constraintRect
.left
== -1 )
1457 constraintRect
.left
= 0 ;
1458 constraintRect
.right
= win
->GetMaxWidth() ;
1459 if ( constraintRect
.right
== -1 )
1460 constraintRect
.right
= 32000 ;
1461 constraintRect
.bottom
= win
->GetMaxHeight() ;
1462 if ( constraintRect
.bottom
== -1 )
1463 constraintRect
.bottom
= 32000 ;
1465 Boolean growResult
= ResizeWindow( window
, ev
->where
,
1466 &constraintRect
, &newContentRect
) ;
1469 win
->SetSize( newContentRect
.left
, newContentRect
.top
,
1470 newContentRect
.right
- newContentRect
.left
,
1471 newContentRect
.bottom
- newContentRect
.top
, wxSIZE_USE_EXISTING
);
1473 s_lastMouseDown
= 0;
1478 if (TrackBox(window
, ev
->where
, windowPart
))
1480 // TODO setup size event
1481 ZoomWindow( window
, windowPart
, false ) ;
1487 Point pt
= { 0, 0 } ;
1488 SetPortWindowPort(window
) ;
1489 LocalToGlobal( &pt
) ;
1492 GetWindowPortBounds(window
, &tempRect
) ;
1493 win
->SetSize( pt
.h
, pt
.v
, tempRect
.right
-tempRect
.left
,
1494 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1497 s_lastMouseDown
= 0;
1499 case inCollapseBox
:
1500 // TODO setup size event
1501 s_lastMouseDown
= 0;
1508 SetPortWindowPort(window
) ;
1511 if ( window
!= frontWindow
&& wxTheApp
->s_captureWindow
== NULL
)
1513 if ( s_macIsInModalLoop
)
1517 else if ( UMAIsWindowFloating( window
) )
1520 win
->MacMouseDown( ev
, windowPart
) ;
1525 win
->MacMouseDown( ev
, windowPart
) ;
1526 ::SelectWindow( window
) ;
1532 win
->MacMouseDown( ev
, windowPart
) ;
1540 void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr
)
1542 EventRecord
* ev
= (EventRecord
*) evr
;
1545 short windowPart
= inNoWindow
;
1546 if ( wxTheApp
->s_captureWindow
)
1548 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
1549 windowPart
= inContent
;
1553 windowPart
= ::FindWindow(ev
->where
, &window
) ;
1564 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1566 win
->MacMouseUp( ev
, windowPart
) ;
1574 long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
1575 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1580 case kHomeCharCode
:
1583 case kEnterCharCode
:
1584 retval
= WXK_RETURN
;
1589 case kHelpCharCode
:
1592 case kBackspaceCharCode
:
1598 case kPageUpCharCode
:
1599 retval
= WXK_PAGEUP
;
1601 case kPageDownCharCode
:
1602 retval
= WXK_PAGEDOWN
;
1604 case kReturnCharCode
:
1605 retval
= WXK_RETURN
;
1607 case kFunctionKeyCharCode
:
1659 case kEscapeCharCode
:
1660 retval
= WXK_ESCAPE
;
1662 case kLeftArrowCharCode
:
1665 case kRightArrowCharCode
:
1666 retval
= WXK_RIGHT
;
1668 case kUpArrowCharCode
:
1671 case kDownArrowCharCode
:
1674 case kDeleteCharCode
:
1675 retval
= WXK_DELETE
;
1684 void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr
)
1686 EventRecord
* ev
= (EventRecord
*) evr
;
1687 wxToolTip::RemoveToolTips() ;
1689 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1690 if ( HiWord( menuresult
) )
1692 if ( !s_macIsInModalLoop
)
1693 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1697 wxWindow
* focus
= wxWindow::FindFocus() ;
1699 if ( MacSendKeyDownEvent( focus
, ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) == false )
1701 // has not been handled -> perform default
1702 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
1703 if ( control
&& control
->GetMacControl() != NULL
)
1707 keychar
= short(ev
->message
& charCodeMask
);
1708 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1709 ::HandleControlKey( (ControlHandle
) control
->GetMacControl() , keycode
, keychar
, ev
->modifiers
) ;
1715 void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr
)
1717 EventRecord
* ev
= (EventRecord
*) evr
;
1718 wxToolTip::RemoveToolTips() ;
1720 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1721 if ( HiWord( menuresult
) )
1726 MacSendKeyUpEvent( wxWindow::FindFocus() , ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) ;
1732 bool wxApp::MacSendKeyDownEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
)
1739 keychar
= short(keymessage
& charCodeMask
);
1740 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
1742 if ( modifiers
& ( controlKey
|shiftKey
|optionKey
) )
1744 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1745 // and look at the character after
1747 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
);
1748 keychar
= short(keyInfo
& charCodeMask
);
1749 keycode
= short(keyInfo
& keyCodeMask
) >> 8 ;
1751 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1752 long realkeyval
= keyval
;
1753 if ( keyval
== keychar
)
1755 // 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)
1756 realkeyval
= short(keymessage
& charCodeMask
) ;
1757 keyval
= wxToupper( keyval
) ;
1760 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1761 bool handled
= false ;
1762 event
.m_shiftDown
= modifiers
& shiftKey
;
1763 event
.m_controlDown
= modifiers
& controlKey
;
1764 event
.m_altDown
= modifiers
& optionKey
;
1765 event
.m_metaDown
= modifiers
& cmdKey
;
1766 event
.m_keyCode
= keyval
;
1770 event
.m_timeStamp
= when
;
1771 event
.SetEventObject(focus
);
1772 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1773 if ( handled
&& event
.GetSkipped() )
1780 wxWindow
*ancestor
= focus
;
1783 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1786 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1787 handled
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1790 if (ancestor
->IsTopLevel())
1792 ancestor
= ancestor
->GetParent();
1795 #endif // wxUSE_ACCEL
1799 event
.Skip( FALSE
) ;
1800 event
.SetEventType( wxEVT_CHAR
) ;
1802 event
.m_keyCode
= realkeyval
;
1804 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1805 if ( handled
&& event
.GetSkipped() )
1809 (keyval
== WXK_TAB
) &&
1810 // CS: copied the change below from wxGTK
1811 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
1812 // have this style, yet choose not to process this particular TAB in which
1813 // case TAB must still work as a navigational character
1815 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1817 (focus
->GetParent()) &&
1818 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1820 wxNavigationKeyEvent new_event
;
1821 new_event
.SetEventObject( focus
);
1822 new_event
.SetDirection( !event
.ShiftDown() );
1823 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1824 new_event
.SetWindowChange( event
.ControlDown() );
1825 new_event
.SetCurrentFocus( focus
);
1826 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1827 if ( handled
&& new_event
.GetSkipped() )
1830 // backdoor handler for default return and command escape
1831 if ( !handled
&& (!focus
->IsKindOf(CLASSINFO(wxControl
) ) || !focus
->MacCanFocus() ) )
1833 // if window is not having a focus still testing for default enter or cancel
1834 // TODO add the UMA version for ActiveNonFloatingWindow
1835 wxWindow
* focus
= wxFindWinFromMacWindow( FrontWindow() ) ;
1838 if ( keyval
== WXK_RETURN
)
1840 wxButton
*def
= wxDynamicCast(focus
->GetDefaultItem(),
1842 if ( def
&& def
->IsEnabled() )
1844 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
1845 event
.SetEventObject(def
);
1846 def
->Command(event
);
1850 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1851 else if (keyval
== WXK_ESCAPE
|| (keyval
== '.' && modifiers
& cmdKey
) )
1853 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1854 new_event
.SetEventObject( focus
);
1855 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1862 bool wxApp::MacSendKeyUpEvent( wxWindow
* focus
, long keymessage
, long modifiers
, long when
, short wherex
, short wherey
)
1869 keychar
= short(keymessage
& charCodeMask
);
1870 keycode
= short(keymessage
& keyCodeMask
) >> 8 ;
1871 if ( modifiers
& ( controlKey
|shiftKey
|optionKey
) )
1873 // control interferes with some built-in keys like pgdown, return etc. therefore we remove the controlKey modifier
1874 // and look at the character after
1876 UInt32 keyInfo
= KeyTranslate((Ptr
)GetScriptManagerVariable(smKCHRCache
), ( modifiers
& (~(controlKey
|shiftKey
|optionKey
))) | keycode
, &state
);
1877 keychar
= short(keyInfo
& charCodeMask
);
1878 keycode
= short(keyInfo
& keyCodeMask
) >> 8 ;
1880 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1882 if ( keyval
== keychar
)
1884 keyval
= wxToupper( keyval
) ;
1886 bool handled
= false ;
1888 wxKeyEvent
event(wxEVT_KEY_UP
);
1889 event
.m_shiftDown
= modifiers
& shiftKey
;
1890 event
.m_controlDown
= modifiers
& controlKey
;
1891 event
.m_altDown
= modifiers
& optionKey
;
1892 event
.m_metaDown
= modifiers
& cmdKey
;
1893 event
.m_keyCode
= keyval
;
1897 event
.m_timeStamp
= when
;
1898 event
.SetEventObject(focus
);
1899 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1905 void wxApp::MacHandleActivateEvent( WXEVENTREF evr
)
1907 EventRecord
* ev
= (EventRecord
*) evr
;
1908 WindowRef window
= (WindowRef
) ev
->message
;
1911 bool activate
= (ev
->modifiers
& activeFlag
) ;
1912 WindowClass wclass
;
1913 ::GetWindowClass ( window
, &wclass
) ;
1914 if ( wclass
== kFloatingWindowClass
)
1916 // if it is a floater we activate/deactivate the front non-floating window instead
1917 window
= ::FrontNonFloatingWindow() ;
1919 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1921 win
->MacActivate( ev
->when
, activate
) ;
1925 void wxApp::MacHandleUpdateEvent( WXEVENTREF evr
)
1927 EventRecord
* ev
= (EventRecord
*) evr
;
1928 WindowRef window
= (WindowRef
) ev
->message
;
1929 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1932 if ( !wxPendingDelete
.Member(win
) )
1933 win
->MacUpdate( ev
->when
) ;
1937 // since there is no way of telling this foreign window to update itself
1938 // we have to invalidate the update region otherwise we keep getting the same
1939 // event over and over again
1940 BeginUpdate( window
) ;
1941 EndUpdate( window
) ;
1945 void wxApp::MacHandleDiskEvent( WXEVENTREF evr
)
1947 EventRecord
* ev
= (EventRecord
*) evr
;
1948 if ( HiWord( ev
->message
) != noErr
)
1952 SetPt( &point
, 100 , 100 ) ;
1954 err
= DIBadMount( point
, ev
->message
) ;
1955 wxASSERT( err
== noErr
) ;
1959 void wxApp::MacHandleOSEvent( WXEVENTREF evr
)
1961 EventRecord
* ev
= (EventRecord
*) evr
;
1962 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
1964 case suspendResumeMessage
:
1966 bool isResuming
= ev
->message
& resumeFlag
;
1967 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
1969 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
1972 WindowRef oldFrontWindow
= NULL
;
1973 WindowRef newFrontWindow
= NULL
;
1975 // in case we don't take care of activating ourselves, we have to synchronize
1976 // our idea of the active window with the process manager's - which it already activated
1978 if ( !doesActivate
)
1979 oldFrontWindow
= ::FrontNonFloatingWindow() ;
1981 MacResume( convertClipboard
) ;
1983 newFrontWindow
= ::FrontNonFloatingWindow() ;
1985 if ( oldFrontWindow
)
1987 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
1989 win
->MacActivate( ev
->when
, false ) ;
1991 if ( newFrontWindow
)
1993 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
1995 win
->MacActivate( ev
->when
, true ) ;
2000 MacSuspend( convertClipboard
) ;
2004 case mouseMovedMessage
:
2008 wxWindow
* currentMouseWindow
= NULL
;
2010 if (s_captureWindow
)
2012 currentMouseWindow
= s_captureWindow
;
2016 wxWindow::MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) ,
2017 ¤tMouseWindow
) ;
2020 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
2022 wxMouseEvent event
;
2024 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
2025 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
2027 event
.m_leftDown
= isDown
&& !controlDown
;
2028 event
.m_middleDown
= FALSE
;
2029 event
.m_rightDown
= isDown
&& controlDown
;
2030 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
2031 event
.m_controlDown
= ev
->modifiers
& controlKey
;
2032 event
.m_altDown
= ev
->modifiers
& optionKey
;
2033 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
2034 event
.m_x
= ev
->where
.h
;
2035 event
.m_y
= ev
->where
.v
;
2036 event
.m_timeStamp
= ev
->when
;
2037 event
.SetEventObject(this);
2039 if ( wxWindow::s_lastMouseWindow
)
2041 wxMouseEvent
eventleave(event
);
2042 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
2043 wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
2044 eventleave
.SetEventObject( wxWindow::s_lastMouseWindow
) ;
2046 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
2048 if ( currentMouseWindow
)
2050 wxMouseEvent
evententer(event
);
2051 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
2052 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
2053 evententer
.SetEventObject( currentMouseWindow
) ;
2054 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
2056 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
2059 short windowPart
= inNoWindow
;
2061 if ( s_captureWindow
)
2063 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
2064 windowPart
= inContent
;
2068 windowPart
= ::FindWindow(ev
->where
, &window
);
2075 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2077 win
->MacMouseMoved( ev
, windowPart
) ;
2084 UMAShowArrowCursor();
2094 UMAShowArrowCursor();
2105 void wxApp::MacHandleMenuCommand( wxUint32 id
)
2107 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
2108 wxFrame
* frame
= mbar
->GetFrame();
2109 wxCHECK_RET( mbar
!= NULL
&& frame
!= NULL
, wxT("error in menu item callback") );
2112 frame
->ProcessCommand(id
);
2117 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
2120 return; // no menu item selected
2122 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
2125 Str255 deskAccessoryName
;
2128 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
2129 GetPort(&savedPort
);
2130 OpenDeskAcc(deskAccessoryName
);
2137 GetMenuItemCommandID( GetMenuHandle(macMenuId
) , macMenuItemNum
, &id
) ;
2138 MacHandleMenuCommand( id
) ;