1 /////////////////////////////////////////////////////////////////////////////
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "app.h"
18 #include "wx/window.h"
20 #include "wx/button.h"
23 #include "wx/gdicmn.h"
26 #include "wx/cursor.h"
29 #include "wx/palette.h"
31 #include "wx/dialog.h"
32 #include "wx/msgdlg.h"
34 #include "wx/module.h"
35 #include "wx/memory.h"
36 #include "wx/tooltip.h"
37 #include "wx/textctrl.h"
39 #include "wx/docview.h"
53 #include "wx/mac/uma.h"
54 #include "wx/mac/macnotfy.h"
57 # include <CoreServices/CoreServices.h>
58 # if defined(WXMAKINGDLL_CORE)
59 # include <mach-o/dyld.h>
64 # include <ToolUtils.h>
65 # include <DiskInit.h>
69 extern wxList wxPendingDelete
;
70 extern wxList
*wxWinMacWindowList
;
71 extern wxList
*wxWinMacControlList
;
73 // statics for implementation
75 static bool s_inYield
= FALSE
;
78 static bool s_inReceiveEvent
= FALSE
;
79 static EventTime sleepTime
= kEventDurationNoWait
;
81 static long sleepTime
= 0 ;
84 #if !USE_SHARED_LIBRARY
85 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
86 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
87 EVT_IDLE(wxApp::OnIdle
)
88 EVT_END_SESSION(wxApp::OnEndSession
)
89 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
94 const short kMacMinHeap
= (29 * 1024) ;
95 // platform specific static variables
97 const short kwxMacMenuBarResource
= 1 ;
98 const short kwxMacAppleMenuId
= 1 ;
100 WXHRGN
wxApp::s_macCursorRgn
= NULL
;
101 wxWindow
* wxApp::s_captureWindow
= NULL
;
102 int wxApp::s_lastMouseDown
= 0 ;
103 long wxApp::sm_lastMessageTime
= 0;
104 long wxApp::s_lastModifiers
= 0 ;
107 bool wxApp::s_macSupportPCMenuShortcuts
= true ;
108 long wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
109 long wxApp::s_macPreferencesMenuItemId
= wxID_PREFERENCES
;
110 long wxApp::s_macExitMenuItemId
= wxID_EXIT
;
111 wxString
wxApp::s_macHelpMenuTitleName
= wxT("&Help") ;
113 //----------------------------------------------------------------------
114 // Core Apple Event Support
115 //----------------------------------------------------------------------
117 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
118 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
119 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
120 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
122 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
124 return wxTheApp
->MacHandleAEODoc( (AppleEvent
*) event
, reply
) ;
127 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
129 return wxTheApp
->MacHandleAEOApp( (AppleEvent
*) event
, reply
) ;
132 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
134 return wxTheApp
->MacHandleAEPDoc( (AppleEvent
*) event
, reply
) ;
137 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, long WXUNUSED(refcon
) )
139 return wxTheApp
->MacHandleAEQuit( (AppleEvent
*) event
, reply
) ;
142 // AEODoc Calls MacOpenFile on each of the files passed
144 short wxApp::MacHandleAEODoc(const WXEVENTREF event
, WXEVENTREF
WXUNUSED(reply
))
148 DescType returnedType
;
154 err
= AEGetParamDesc((AppleEvent
*)event
, keyDirectObject
, typeAEList
,&docList
);
158 err
= AECountItems(&docList
, &itemsInList
);
162 ProcessSerialNumber PSN
;
163 PSN
.highLongOfPSN
= 0 ;
164 PSN
.lowLongOfPSN
= kCurrentProcess
;
165 SetFrontProcess( &PSN
) ;
167 for (i
= 1; i
<= itemsInList
; i
++) {
168 AEGetNthPtr(&docList
, i
, typeFSS
, &keywd
, &returnedType
,
169 (Ptr
) & theSpec
, sizeof(theSpec
), &actualSize
);
170 wxString fName
= wxMacFSSpec2MacFilename(&theSpec
);
176 // AEPDoc Calls MacPrintFile on each of the files passed
178 short wxApp::MacHandleAEPDoc(const WXEVENTREF event
, WXEVENTREF
WXUNUSED(reply
))
182 DescType returnedType
;
188 err
= AEGetParamDesc((AppleEvent
*)event
, keyDirectObject
, typeAEList
,&docList
);
192 err
= AECountItems(&docList
, &itemsInList
);
196 ProcessSerialNumber PSN
;
197 PSN
.highLongOfPSN
= 0 ;
198 PSN
.lowLongOfPSN
= kCurrentProcess
;
199 SetFrontProcess( &PSN
) ;
201 for (i
= 1; i
<= itemsInList
; i
++) {
202 AEGetNthPtr(&docList
, i
, typeFSS
, &keywd
, &returnedType
,
203 (Ptr
) & theSpec
, sizeof(theSpec
), &actualSize
);
204 wxString fName
= wxMacFSSpec2MacFilename(&theSpec
);
210 // AEOApp calls MacNewFile
212 short wxApp::MacHandleAEOApp(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
218 // AEQuit attempts to quit the application
220 short wxApp::MacHandleAEQuit(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
222 /* wxWindow* win = GetTopWindow() ;
235 //----------------------------------------------------------------------
236 // Support Routines linking the Mac...File Calls to the Document Manager
237 //----------------------------------------------------------------------
239 void wxApp::MacOpenFile(const wxString
& fileName
)
241 wxDocManager
* dm
= wxDocManager::GetDocumentManager() ;
243 dm
->CreateDocument(fileName
, wxDOC_SILENT
) ;
246 void wxApp::MacPrintFile(const wxString
& fileName
)
248 wxDocManager
* dm
= wxDocManager::GetDocumentManager() ;
251 wxDocument
*doc
= dm
->CreateDocument(fileName
, wxDOC_SILENT
) ;
254 wxView
* view
= doc
->GetFirstView() ;
257 wxPrintout
*printout
= view
->OnCreatePrintout();
261 printer
.Print(view
->GetFrame(), printout
, TRUE
);
267 doc
->DeleteAllViews();
268 dm
->RemoveDocument(doc
) ;
274 void wxApp::MacNewFile()
278 //----------------------------------------------------------------------
279 // Carbon Event Handler
280 //----------------------------------------------------------------------
284 static const EventTypeSpec eventList
[] =
286 { kEventClassCommand
, kEventProcessCommand
} ,
287 { kEventClassCommand
, kEventCommandUpdateStatus
} ,
289 { kEventClassMenu
, kEventMenuOpening
},
290 { kEventClassMenu
, kEventMenuClosed
},
292 { kEventClassApplication
, kEventAppActivated
} ,
293 { kEventClassApplication
, kEventAppDeactivated
} ,
294 // handling the quit event is not recommended by apple
295 // rather using the quit apple event - which we do
297 { kEventClassAppleEvent
, kEventAppleEvent
} ,
299 { kEventClassMouse
, kEventMouseDown
} ,
300 { kEventClassMouse
, kEventMouseMoved
} ,
301 { kEventClassMouse
, kEventMouseUp
} ,
302 { kEventClassMouse
, kEventMouseDragged
} ,
306 static pascal OSStatus
307 MenuEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
309 // FIXME: this doesn't work for multiple windows
310 wxWindow
*win
= wxTheApp
->GetTopWindow();
313 // VZ: we could find the menu from its handle here by examining all
314 // the menus in the menu bar recursively but knowing that neither
315 // wxMSW nor wxGTK do it why bother...
319 GetEventParameter(event
,
320 kEventParamDirectObject
,
322 sizeof(menuRef
), NULL
,
326 wxMenuEvent
wxevent(GetEventKind(event
) == kEventMenuOpening
329 wxevent
.SetEventObject(win
);
331 (void)win
->GetEventHandler()->ProcessEvent(wxevent
);
334 return eventNotHandledErr
;
337 // due to the rather low-level event API of wxWindows, we cannot use RunApplicationEventLoop
338 // but have to use ReceiveNextEvent dealing with events manually, therefore we also have
339 // deal with clicks in the menu bar explicitely
341 pascal OSStatus
wxMacWindowEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
343 static pascal OSStatus
MouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
345 OSStatus result
= eventNotHandledErr
;
348 UInt32 modifiers
= 0;
349 EventMouseButton button
= 0 ;
352 GetEventParameter( event
, kEventParamMouseLocation
, typeQDPoint
, NULL
,
353 sizeof( Point
), NULL
, &point
);
354 GetEventParameter( event
, kEventParamKeyModifiers
, typeUInt32
, NULL
,
355 sizeof( UInt32
), NULL
, &modifiers
);
356 GetEventParameter( event
, kEventParamMouseButton
, typeMouseButton
, NULL
,
357 sizeof( EventMouseButton
), NULL
, &button
);
358 GetEventParameter( event
, kEventParamClickCount
, typeUInt32
, NULL
,
359 sizeof( UInt32
), NULL
, &click
);
361 if ( button
== 0 || GetEventKind( event
) == kEventMouseUp
)
362 modifiers
+= btnState
;
365 switch( GetEventKind(event
) )
367 case kEventMouseDown
:
371 short windowPart
= ::FindWindow(point
, &window
);
373 if ( windowPart
== inMenuBar
)
375 MenuSelect( point
) ;
380 case kEventMouseDragged
:
383 if ( wxTheApp
->s_captureWindow
)
384 wxMacWindowEventHandler( handler
, event
, (void*) wxTheApp
->s_captureWindow
->MacGetTopLevelWindow() ) ;
387 case kEventMouseMoved
:
389 wxTheApp
->MacHandleMouseMovedEvent( point
.h
, point
.v
, modifiers
, EventTimeToTicks( GetEventTime( event
) ) ) ;
399 static pascal OSStatus
CommandEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
401 OSStatus result
= eventNotHandledErr
;
405 GetEventParameter( event
, kEventParamDirectObject
, typeHICommand
, NULL
,
406 sizeof( HICommand
), NULL
, &command
);
408 MenuCommand id
= command
.commandID
;
409 if ( id
== kHICommandPreferences
)
410 id
= wxApp::s_macPreferencesMenuItemId
;
412 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
413 wxMenu
* menu
= NULL
;
414 wxMenuItem
* item
= NULL
;
418 item
= mbar
->FindItem( id
, &menu
) ;
419 // it is not 100 % sure that an menu of id 0 is really ours, safety check
420 if ( id
== 0 && menu
!= NULL
&& menu
->GetHMenu() != command
.menu
.menuRef
)
427 if ( item
== NULL
|| menu
== NULL
|| mbar
== NULL
)
430 switch( GetEventKind( event
) )
432 case kEventProcessCommand
:
434 if (item
->IsCheckable())
436 item
->Check( !item
->IsChecked() ) ;
439 menu
->SendEvent( id
, item
->IsCheckable() ? item
->IsChecked() : -1 ) ;
443 case kEventCommandUpdateStatus
:
444 // eventually trigger an updateui round
454 static pascal OSStatus
ApplicationEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
456 OSStatus result
= eventNotHandledErr
;
457 switch ( GetEventKind( event
) )
459 case kEventAppActivated
:
462 wxTheApp
->MacResume( true ) ;
466 case kEventAppDeactivated
:
469 wxTheApp
->MacSuspend( true ) ;
479 pascal OSStatus
wxAppEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
481 OSStatus result
= eventNotHandledErr
;
482 switch( GetEventClass( event
) )
484 case kEventClassCommand
:
485 result
= CommandEventHandler( handler
, event
, data
) ;
487 case kEventClassApplication
:
488 result
= ApplicationEventHandler( handler
, event
, data
) ;
490 case kEventClassMenu
:
491 result
= MenuEventHandler( handler
, event
, data
) ;
493 case kEventClassMouse
:
494 result
= MouseEventHandler( handler
, event
, data
) ;
496 case kEventClassAppleEvent
:
499 wxMacConvertEventToRecord( event
, &rec
) ;
500 result
= AEProcessAppleEvent( &rec
) ;
510 DEFINE_ONE_SHOT_HANDLER_GETTER( wxAppEventHandler
)
514 #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
515 // we know it's there ;-)
516 WXIMPORT
char std::__throws_bad_alloc
;
519 bool wxApp::Initialize(int& argc
, wxChar
**argv
)
525 UMAInitToolbox( 4 ) ;
526 SetEventMask( everyEvent
) ;
527 UMAShowWatchCursor() ;
529 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
530 // open shared library resources from here since we don't have
531 // __wxinitialize in Mach-O shared libraries
532 wxStAppResource::OpenSharedLibraryResource(NULL
);
536 // test the minimal configuration necessary
542 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
544 error
= kMacSTRWrongMachine
;
546 else if (theMachine
< gestaltMacPlus
)
548 error
= kMacSTRWrongMachine
;
550 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
552 error
= kMacSTROldSystem
;
554 else if ( theSystem
< 0x0860 )
556 error
= kMacSTROldSystem
;
558 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
560 error
= kMacSTRSmallSize
;
566 if ( !UMAHasAppearance() )
568 error = kMacSTRNoPre8Yet ;
574 // if we encountered any problems so far, give the error code and exit immediately
578 wxStAppResource resload
;
582 GetIndString(message
, 128, error
);
583 UMAShowArrowCursor() ;
584 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
585 itemHit
= Alert(128, nil
);
590 # if __option(profile)
591 ProfilerInit( collectDetailed
, bestTimeBase
, 40000 , 50 ) ;
596 // now avoid exceptions thrown for new (bad_alloc)
597 // FIXME CS for some changes outside wxMac does not compile anymore
599 std::__throws_bad_alloc
= 0 ;
603 wxMacSetupConverters() ;
605 s_macCursorRgn
= ::NewRgn() ;
607 // Mac OS X passes a process serial number command line argument when
608 // the application is launched from the Finder. This argument must be
609 // removed from the command line arguments before being handled by the
610 // application (otherwise applications would need to handle it)
613 static const wxChar
*ARG_PSN
= _T("-psn_");
614 if ( wxStrncmp(argv
[1], ARG_PSN
, sizeof(ARG_PSN
) - 1) == 0 )
616 // remove this argument
617 memmove(argv
, argv
+ 1, argc
--);
621 if ( !wxAppBase::Initialize(argc
, argv
) )
624 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
625 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
627 wxMacCreateNotifierTable() ;
629 UMAShowArrowCursor() ;
634 bool wxApp::OnInitGui()
636 if( !wxAppBase::OnInitGui() )
640 InstallStandardEventHandler( GetApplicationEventTarget() ) ;
642 InstallApplicationEventHandler(
643 GetwxAppEventHandlerUPP(),
644 GetEventTypeCount(eventList
), eventList
, wxTheApp
, (EventHandlerRef
*)&(wxTheApp
->m_macEventHandler
));
647 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
648 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
649 NewAEEventHandlerUPP(AEHandleODoc
) ,
651 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
652 NewAEEventHandlerUPP(AEHandleOApp
) ,
654 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
655 NewAEEventHandlerUPP(AEHandlePDoc
) ,
657 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
658 NewAEEventHandlerUPP(AEHandleQuit
) ,
661 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
662 NewAEEventHandlerProc(AEHandleODoc
) ,
664 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
665 NewAEEventHandlerProc(AEHandleOApp
) ,
667 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
668 NewAEEventHandlerProc(AEHandlePDoc
) ,
670 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
671 NewAEEventHandlerProc(AEHandleQuit
) ,
678 void wxApp::CleanUp()
680 wxToolTip::RemoveToolTips() ;
682 // One last chance for pending objects to be cleaned up
683 wxTheApp
->DeletePendingObjects();
685 wxMacDestroyNotifierTable() ;
687 delete wxWinMacWindowList
;
688 wxWinMacWindowList
= NULL
;
690 delete wxWinMacControlList
;
691 wxWinMacControlList
= NULL
;
694 # if __option(profile)
695 ProfilerDump( (StringPtr
)"\papp.prof" ) ;
700 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
701 // close shared library resources from here since we don't have
702 // __wxterminate in Mach-O shared libraries
703 wxStAppResource::CloseSharedLibraryResource();
705 wxMacCleanupConverters() ;
707 UMACleanupToolbox() ;
708 if (s_macCursorRgn
) {
709 ::DisposeRgn((RgnHandle
)s_macCursorRgn
);
716 wxAppBase::CleanUp();
719 //----------------------------------------------------------------------
720 // misc initialization stuff
721 //----------------------------------------------------------------------
723 // extern variable for shared library resource id
724 // need to be able to find it with NSLookupAndBindSymbol
725 short gSharedLibraryResource
= kResFileNotOpened
;
727 #if defined(WXMAKINGDLL_CORE) && defined(__DARWIN__)
728 CFBundleRef gSharedLibraryBundle
= NULL
;
729 #endif /* WXMAKINGDLL_CORE && __DARWIN__ */
731 wxStAppResource::wxStAppResource()
733 m_currentRefNum
= CurResFile() ;
734 if ( gSharedLibraryResource
!= kResFileNotOpened
)
736 UseResFile( gSharedLibraryResource
) ;
740 wxStAppResource::~wxStAppResource()
742 if ( m_currentRefNum
!= kResFileNotOpened
)
744 UseResFile( m_currentRefNum
) ;
748 void wxStAppResource::OpenSharedLibraryResource(const void *initBlock
)
750 gSharedLibraryResource
= kResFileNotOpened
;
752 #ifdef WXMAKINGDLL_CORE
753 if ( initBlock
!= NULL
) {
754 const CFragInitBlock
*theInitBlock
= (const CFragInitBlock
*)initBlock
;
755 FSSpec
*fileSpec
= NULL
;
757 if (theInitBlock
->fragLocator
.where
== kDataForkCFragLocator
) {
758 fileSpec
= theInitBlock
->fragLocator
.u
.onDisk
.fileSpec
;
760 else if (theInitBlock
->fragLocator
.where
== kResourceCFragLocator
) {
761 fileSpec
= theInitBlock
->fragLocator
.u
.inSegs
.fileSpec
;
764 if (fileSpec
!= NULL
) {
765 gSharedLibraryResource
= FSpOpenResFile(fileSpec
, fsRdPerm
);
770 // Open the shared library resource file if it is not yet open
773 const char *theLibPath
;
775 gSharedLibraryBundle
= CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWindows"));
776 if (gSharedLibraryBundle
!= NULL
) {
777 // wxWindows has been bundled into a framework
778 // load the framework resources
780 gSharedLibraryResource
= CFBundleOpenBundleResourceMap(gSharedLibraryBundle
);
783 // wxWindows is a simple dynamic shared library
784 // load the resources from the data fork of a separate resource file
788 OSErr theErr
= noErr
;
790 // get the library path
791 theSymbol
= NSLookupAndBindSymbol("_gSharedLibraryResource");
792 theModule
= NSModuleForSymbol(theSymbol
);
793 theLibPath
= NSLibraryNameForModule(theModule
);
795 // if we call wxLogDebug from here then, as wxTheApp hasn't been
796 // created yet when we're called from wxApp::Initialize(), wxLog
797 // is going to create a default stderr-based log target instead of
798 // the expected normal GUI one -- don't do it, if we really want
799 // to see this message just use fprintf() here
801 wxLogDebug( wxT("wxMac library installation name is '%s'"),
805 // allocate copy to replace .dylib.* extension with .rsrc
806 if (theLibPath
!= NULL
) {
807 theResPath
= theLibPath
;
808 // replace '_core' with '' in case of multi-lib build
809 theResPath
.Replace(wxT("_core"), wxEmptyString
);
810 // replace ".dylib" shared library extension with ".rsrc"
811 theResPath
.Replace(wxT(".dylib"), wxT(".rsrc"));
812 // Find the begining of the filename
813 theName
= theResPath
.AfterLast('/');
816 wxLogDebug( wxT("wxMac resources file name is '%s'"),
817 theResPath
.mb_str() );
820 theErr
= FSPathMakeRef((UInt8
*) theResPath
.mb_str(), &theResRef
, false);
821 if (theErr
!= noErr
) {
822 // try in current directory (using name only)
823 theErr
= FSPathMakeRef((UInt8
*) theName
.mb_str(), &theResRef
, false);
826 // open the resource file
827 if (theErr
== noErr
) {
828 theErr
= FSOpenResourceFile( &theResRef
, 0, NULL
, fsRdPerm
,
829 &gSharedLibraryResource
);
831 if (theErr
!= noErr
) {
834 wxT("unable to open wxMac resource file '%s'\n"),
835 theResPath
.mb_str() );
836 #endif // __WXDEBUG__
841 #endif /* __DARWIN__ */
843 #endif /* WXMAKINGDLL_CORE */
846 void wxStAppResource::CloseSharedLibraryResource()
848 #ifdef WXMAKINGDLL_CORE
849 // Close the shared library resource file
850 if (gSharedLibraryResource
!= kResFileNotOpened
) {
852 if (gSharedLibraryBundle
!= NULL
) {
853 CFBundleCloseBundleResourceMap(gSharedLibraryBundle
,
854 gSharedLibraryResource
);
855 gSharedLibraryBundle
= NULL
;
858 #endif /* __DARWIN__ */
860 CloseResFile(gSharedLibraryResource
);
862 gSharedLibraryResource
= kResFileNotOpened
;
864 #endif /* WXMAKINGDLL_CORE */
867 #if defined(WXMAKINGDLL_CORE) && !defined(__DARWIN__)
869 // for shared libraries we have to manually get the correct resource
870 // ref num upon initializing and releasing when terminating, therefore
871 // the __wxinitialize and __wxterminate must be used
874 void __sinit(void); /* (generated by linker) */
875 pascal OSErr
__initialize(const CFragInitBlock
*theInitBlock
);
876 pascal void __terminate(void);
879 pascal OSErr
__wxinitialize(const CFragInitBlock
*theInitBlock
)
881 wxStAppResource::OpenSharedLibraryResource( theInitBlock
) ;
882 return __initialize( theInitBlock
) ;
885 pascal void __wxterminate(void)
887 wxStAppResource::CloseSharedLibraryResource() ;
891 #endif /* WXMAKINGDLL_CORE && !__DARWIN__ */
895 bool wxMacConvertEventToRecord( EventRef event
, EventRecord
*rec
)
897 bool converted
= ConvertEventRefToEventRecord( event
,rec
) ;
898 OSStatus err
= noErr
;
901 switch( GetEventClass( event
) )
903 case kEventClassKeyboard
:
906 switch( GetEventKind(event
) )
908 case kEventRawKeyDown
:
909 rec
->what
= keyDown
;
911 case kEventRawKeyRepeat
:
912 rec
->what
= autoKey
;
914 case kEventRawKeyUp
:
917 case kEventRawKeyModifiersChanged
:
918 rec
->what
= nullEvent
;
927 unsigned char charCode
;
929 GetMouse( &rec
->where
) ;
931 err
= GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
932 err
= GetEventParameter(event
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
933 err
= GetEventParameter(event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
934 rec
->modifiers
= modifiers
;
935 rec
->message
= (keyCode
<< 8 ) + charCode
;
939 case kEventClassTextInput
:
941 switch( GetEventKind( event
) )
943 case kEventTextInputUnicodeForKeyEvent
:
946 err
= GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent
) ;
950 unsigned char charCode
;
952 GetMouse( &rec
->where
) ;
953 rec
->what
= keyDown
;
954 err
= GetEventParameter(rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
955 err
= GetEventParameter(rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
956 err
= GetEventParameter(rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
957 rec
->modifiers
= modifiers
;
958 rec
->message
= (keyCode
<< 8 ) + charCode
;
974 pascal OSStatus wxMacApplicationEventHandler( EventHandlerCallRef handler , EventRef event , void *data )
976 OSStatus result = eventNotHandledErr ;
979 switch ( GetEventClass( event ) )
981 case kEventClassKeyboard :
982 if ( wxMacConvertEventToRecord( event , &rec ) )
984 wxTheApp->MacHandleModifierEvents( &rec ) ;
985 wxTheApp->MacHandleOneEvent( &rec ) ;
989 case kEventClassTextInput :
990 if ( wxMacConvertEventToRecord( event , &rec ) )
992 wxTheApp->MacHandleModifierEvents( &rec ) ;
993 wxTheApp->MacHandleOneEvent( &rec ) ;
1007 m_printMode
= wxPRINT_WINDOWS
;
1010 m_macCurrentEvent
= NULL
;
1012 m_macCurrentEventHandlerCallRef
= NULL
;
1016 bool wxApp::Initialized()
1024 int wxApp::MainLoop()
1036 void wxApp::ExitMainLoop()
1038 m_keepGoing
= FALSE
;
1041 // Is a message/event pending?
1042 bool wxApp::Pending()
1045 return GetNumEventsInQueue( GetMainEventQueue() ) > 0 ;
1049 return EventAvail( everyEvent
, &event
) ;
1053 // Dispatch a message.
1054 void wxApp::Dispatch()
1059 void wxApp::OnIdle(wxIdleEvent
& event
)
1061 wxAppBase::OnIdle(event
);
1063 // If they are pending events, we must process them: pending events are
1064 // either events to the threads other than main or events posted with
1065 // wxPostEvent() functions
1066 wxMacProcessNotifierAndPendingEvents();
1068 if(!wxMenuBar::MacGetInstalledMenuBar() && wxMenuBar::MacGetCommonMenuBar())
1069 wxMenuBar::MacGetCommonMenuBar()->MacInstallMenuBar();
1072 void wxApp::WakeUpIdle()
1083 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
1086 GetTopWindow()->Close(TRUE
);
1089 // Default behaviour: close the application with prompts. The
1090 // user can veto the close, and therefore the end session.
1091 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
1095 if (!GetTopWindow()->Close(!event
.CanVeto()))
1100 extern "C" void wxCYield() ;
1106 // Yield to other processes
1108 bool wxApp::Yield(bool onlyIfNeeded
)
1112 if ( !onlyIfNeeded
)
1114 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1123 YieldToAnyThread() ;
1125 // by definition yield should handle all non-processed events
1129 OSStatus status
= noErr
;
1132 s_inReceiveEvent
= true ;
1133 status
= ReceiveNextEvent(0, NULL
,kEventDurationNoWait
,true,&theEvent
) ;
1134 s_inReceiveEvent
= false ;
1136 if ( status
== eventLoopTimedOutErr
)
1138 // make sure next time the event loop will trigger idle events
1139 sleepTime
= kEventDurationNoWait
;
1141 else if ( status
== eventLoopQuitErr
)
1143 // according to QA1061 this may also occur when a WakeUp Process
1148 MacHandleOneEvent( theEvent
) ;
1149 ReleaseEvent(theEvent
);
1151 } while( status
== noErr
) ;
1155 // having a larger value here leads to large performance slowdowns
1156 // so we cannot give background apps more processor time here
1157 // we do so however having a large sleep value in the main event loop
1160 while ( !IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, (RgnHandle
) wxApp::s_macCursorRgn
))
1162 MacHandleModifierEvents( &event
) ;
1163 MacHandleOneEvent( &event
);
1164 if ( event
.what
!= kHighLevelEvent
)
1165 SetRectRgn( (RgnHandle
) wxApp::s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1167 MacHandleModifierEvents( &event
) ;
1170 wxMacProcessNotifierAndPendingEvents() ;
1176 // platform specifics
1178 void wxApp::MacSuspend( bool convertClipboard
)
1181 // we have to deactive the top level windows manually
1183 wxWindowListNode
* node
= wxTopLevelWindows
.GetFirst();
1186 wxTopLevelWindow
* win
= (wxTopLevelWindow
*) node
->Data();
1188 #if 0 // having problems right now with that
1189 if (!win
->HasFlag(wxSTAY_ON_TOP
))
1192 win
->MacActivate( ((EventRecord
*) MacGetCurrentEvent())->when
, false ) ;
1194 node
= node
->GetNext();
1197 ::HideFloatingWindows() ;
1199 s_lastMouseDown
= 0 ;
1201 if( convertClipboard
)
1203 MacConvertPrivateToPublicScrap() ;
1207 extern wxList wxModalDialogs
;
1209 void wxApp::MacResume( bool convertClipboard
)
1211 s_lastMouseDown
= 0 ;
1212 if( convertClipboard
)
1214 MacConvertPublicToPrivateScrap() ;
1218 ::ShowFloatingWindows() ;
1219 // raise modal dialogs in case a non modal window was selected to activate the app
1221 wxNode
* node
= wxModalDialogs
.GetFirst();
1224 wxDialog
* dialog
= (wxDialog
*) node
->GetData();
1227 node
= node
->GetNext();
1232 void wxApp::MacConvertPrivateToPublicScrap()
1236 void wxApp::MacConvertPublicToPrivateScrap()
1240 void wxApp::MacDoOneEvent()
1245 s_inReceiveEvent
= true ;
1246 OSStatus status
= ReceiveNextEvent(0, NULL
,sleepTime
,true,&theEvent
) ;
1247 s_inReceiveEvent
= false ;
1248 if ( status
== eventLoopTimedOutErr
)
1250 if ( wxTheApp
->ProcessIdle() )
1251 sleepTime
= kEventDurationNoWait
;
1253 sleepTime
= kEventDurationForever
;
1255 else if ( status
== eventLoopQuitErr
)
1257 // according to QA1061 this may also occur when a WakeUp Process
1262 MacHandleOneEvent( theEvent
) ;
1263 ReleaseEvent(theEvent
);
1264 sleepTime
= kEventDurationNoWait
;
1269 EventMask eventMask
= everyEvent
;
1271 if (WaitNextEvent(eventMask
, &event
, sleepTime
, (RgnHandle
) s_macCursorRgn
))
1273 MacHandleModifierEvents( &event
) ;
1274 MacHandleOneEvent( &event
);
1278 MacHandleModifierEvents( &event
) ;
1280 WindowPtr window
= ::FrontWindow() ;
1282 ::IdleControls( window
) ;
1284 if ( wxTheApp
->ProcessIdle() )
1287 sleepTime
= GetCaretTime() / 2 ;
1289 if ( event
.what
!= kHighLevelEvent
)
1290 SetRectRgn( (RgnHandle
) s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1294 DeletePendingObjects() ;
1295 wxMacProcessNotifierAndPendingEvents() ;
1298 void wxApp::MacHandleOneEvent( WXEVENTREF evr
)
1301 EventTargetRef theTarget
;
1302 theTarget
= GetEventDispatcherTarget();
1303 m_macCurrentEvent
= evr
;
1304 SendEventToEventTarget ((EventRef
) evr
, theTarget
);
1306 EventRecord
* ev
= (EventRecord
*) evr
;
1307 m_macCurrentEvent
= ev
;
1309 wxApp::sm_lastMessageTime
= ev
->when
;
1314 MacHandleMouseDownEvent( ev
) ;
1315 if ( ev
->modifiers
& controlKey
)
1316 s_lastMouseDown
= 2;
1318 s_lastMouseDown
= 1;
1321 if ( s_lastMouseDown
== 2 )
1323 ev
->modifiers
|= controlKey
;
1327 ev
->modifiers
&= ~controlKey
;
1329 MacHandleMouseUpEvent( ev
) ;
1330 s_lastMouseDown
= 0;
1333 MacHandleActivateEvent( ev
) ;
1336 MacHandleUpdateEvent( ev
) ;
1340 MacHandleKeyDownEvent( ev
) ;
1343 MacHandleKeyUpEvent( ev
) ;
1346 MacHandleDiskEvent( ev
) ;
1349 MacHandleOSEvent( ev
) ;
1351 case kHighLevelEvent
:
1352 MacHandleHighLevelEvent( ev
) ;
1358 wxMacProcessNotifierAndPendingEvents() ;
1362 bool s_macIsInModalLoop
= false ;
1364 void wxApp::MacHandleModifierEvents( WXEVENTREF evr
)
1366 EventRecord
* ev
= (EventRecord
*) evr
;
1367 if ( ev
->modifiers
!= s_lastModifiers
&& wxWindow::FindFocus() != NULL
)
1369 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1371 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1372 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1373 event
.m_altDown
= ev
->modifiers
& optionKey
;
1374 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1376 event
.m_x
= ev
->where
.h
;
1377 event
.m_y
= ev
->where
.v
;
1378 event
.m_timeStamp
= ev
->when
;
1379 wxWindow
* focus
= wxWindow::FindFocus() ;
1380 event
.SetEventObject(focus
);
1382 if ( (ev
->modifiers
^ s_lastModifiers
) & controlKey
)
1384 event
.m_keyCode
= WXK_CONTROL
;
1385 event
.SetEventType( ( ev
->modifiers
& controlKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1386 focus
->GetEventHandler()->ProcessEvent( event
) ;
1388 if ( (ev
->modifiers
^ s_lastModifiers
) & shiftKey
)
1390 event
.m_keyCode
= WXK_SHIFT
;
1391 event
.SetEventType( ( ev
->modifiers
& shiftKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1392 focus
->GetEventHandler()->ProcessEvent( event
) ;
1394 if ( (ev
->modifiers
^ s_lastModifiers
) & optionKey
)
1396 event
.m_keyCode
= WXK_ALT
;
1397 event
.SetEventType( ( ev
->modifiers
& optionKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1398 focus
->GetEventHandler()->ProcessEvent( event
) ;
1400 if ( ( ev
->modifiers
^ s_lastModifiers
) & cmdKey
)
1402 event
.m_keyCode
= WXK_COMMAND
;
1403 event
.SetEventType( ( ev
->modifiers
& cmdKey
) ? wxEVT_KEY_DOWN
: wxEVT_KEY_UP
) ;
1404 focus
->GetEventHandler()->ProcessEvent( event
) ;
1406 s_lastModifiers
= ev
->modifiers
;
1410 void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr
)
1412 // we must avoid reentrancy problems when processing high level events eg printing
1413 bool former
= s_inYield
;
1415 EventRecord
* ev
= (EventRecord
*) evr
;
1416 ::AEProcessAppleEvent( ev
) ;
1417 s_inYield
= former
;
1420 void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr
)
1422 EventRecord
* ev
= (EventRecord
*) evr
;
1423 wxToolTip::RemoveToolTips() ;
1426 WindowRef frontWindow
= ::FrontNonFloatingWindow() ;
1427 WindowAttributes frontWindowAttributes
= NULL
;
1429 ::GetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
1431 short windowPart
= ::FindWindow(ev
->where
, &window
);
1432 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1433 if ( wxPendingDelete
.Member(win
) )
1437 GetQDGlobalsScreenBits( &screenBits
);
1442 if ( s_macIsInModalLoop
)
1448 UInt32 menuresult
= MenuSelect(ev
->where
) ;
1449 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1450 s_lastMouseDown
= 0;
1454 SystemClick( ev
, window
) ;
1455 s_lastMouseDown
= 0;
1458 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1464 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1469 Point pt
= { 0, 0 } ;
1470 SetPortWindowPort(window
) ;
1471 LocalToGlobal( &pt
) ;
1473 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1474 -1 , wxSIZE_USE_EXISTING
);
1476 s_lastMouseDown
= 0;
1480 if (TrackGoAway(window
, ev
->where
))
1485 s_lastMouseDown
= 0;
1489 Rect newContentRect
;
1490 Rect constraintRect
;
1491 constraintRect
.top
= win
->GetMinHeight() ;
1492 if ( constraintRect
.top
== -1 )
1493 constraintRect
.top
= 0 ;
1494 constraintRect
.left
= win
->GetMinWidth() ;
1495 if ( constraintRect
.left
== -1 )
1496 constraintRect
.left
= 0 ;
1497 constraintRect
.right
= win
->GetMaxWidth() ;
1498 if ( constraintRect
.right
== -1 )
1499 constraintRect
.right
= 32000 ;
1500 constraintRect
.bottom
= win
->GetMaxHeight() ;
1501 if ( constraintRect
.bottom
== -1 )
1502 constraintRect
.bottom
= 32000 ;
1504 Boolean growResult
= ResizeWindow( window
, ev
->where
,
1505 &constraintRect
, &newContentRect
) ;
1508 win
->SetSize( newContentRect
.left
, newContentRect
.top
,
1509 newContentRect
.right
- newContentRect
.left
,
1510 newContentRect
.bottom
- newContentRect
.top
, wxSIZE_USE_EXISTING
);
1512 s_lastMouseDown
= 0;
1517 if (TrackBox(window
, ev
->where
, windowPart
))
1519 // TODO setup size event
1520 ZoomWindow( window
, windowPart
, false ) ;
1526 Point pt
= { 0, 0 } ;
1527 SetPortWindowPort(window
) ;
1528 LocalToGlobal( &pt
) ;
1531 GetWindowPortBounds(window
, &tempRect
) ;
1532 win
->SetSize( pt
.h
, pt
.v
, tempRect
.right
-tempRect
.left
,
1533 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1536 s_lastMouseDown
= 0;
1538 case inCollapseBox
:
1539 // TODO setup size event
1540 s_lastMouseDown
= 0;
1547 SetPortWindowPort(window
) ;
1550 if ( window
!= frontWindow
&& wxTheApp
->s_captureWindow
== NULL
)
1552 if ( s_macIsInModalLoop
)
1556 else if ( UMAIsWindowFloating( window
) )
1559 win
->MacMouseDown( ev
, windowPart
) ;
1563 // Activate window first
1564 ::SelectWindow( window
) ;
1568 win
->MacMouseDown( ev
, windowPart
) ;
1574 win
->MacMouseDown( ev
, windowPart
) ;
1582 void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr
)
1584 EventRecord
* ev
= (EventRecord
*) evr
;
1587 short windowPart
= inNoWindow
;
1588 if ( wxTheApp
->s_captureWindow
)
1590 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
1591 windowPart
= inContent
;
1595 windowPart
= ::FindWindow(ev
->where
, &window
) ;
1606 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1608 win
->MacMouseUp( ev
, windowPart
) ;
1616 long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
1617 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1622 case kHomeCharCode
:
1625 case kEnterCharCode
:
1626 retval
= WXK_RETURN
;
1631 case kHelpCharCode
:
1634 case kBackspaceCharCode
:
1640 case kPageUpCharCode
:
1641 retval
= WXK_PAGEUP
;
1643 case kPageDownCharCode
:
1644 retval
= WXK_PAGEDOWN
;
1646 case kReturnCharCode
:
1647 retval
= WXK_RETURN
;
1649 case kFunctionKeyCharCode
:
1701 case kEscapeCharCode
:
1702 retval
= WXK_ESCAPE
;
1704 case kLeftArrowCharCode
:
1707 case kRightArrowCharCode
:
1708 retval
= WXK_RIGHT
;
1710 case kUpArrowCharCode
:
1713 case kDownArrowCharCode
:
1716 case kDeleteCharCode
:
1717 retval
= WXK_DELETE
;
1726 void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr
)
1728 EventRecord
* ev
= (EventRecord
*) evr
;
1729 wxToolTip::RemoveToolTips() ;
1731 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1732 if ( HiWord( menuresult
) )
1734 if ( !s_macIsInModalLoop
)
1735 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1739 wxWindow
* focus
= wxWindow::FindFocus() ;
1741 if ( MacSendKeyDownEvent( focus
, ev
->message
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) == false )
1744 // we must handle control keys the other way round, otherwise text content is updated too late
1745 // has not been handled -> perform default
1746 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
1747 if ( control
&& control
->GetMacControl() != NULL
)
1751 keychar
= short(ev
->message
& charCodeMask
);
1752 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1753 ::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::MacHandleMouseMovedEvent(wxInt32 x
, wxInt32 y
,wxUint32 modifiers
, long timestamp
)
2154 wxWindow
* currentMouseWindow
= NULL
;
2156 if (s_captureWindow
)
2158 currentMouseWindow
= s_captureWindow
;
2162 wxWindow::MacGetWindowFromPoint( wxPoint( x
, y
) , ¤tMouseWindow
) ;
2165 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
2167 wxMouseEvent event
;
2169 bool isDown
= !(modifiers
& btnState
) ; // 1 is for up
2170 bool controlDown
= modifiers
& controlKey
; // for simulating right mouse
2172 event
.m_leftDown
= isDown
&& !controlDown
;
2174 event
.m_middleDown
= FALSE
;
2175 event
.m_rightDown
= isDown
&& controlDown
;
2177 event
.m_shiftDown
= modifiers
& shiftKey
;
2178 event
.m_controlDown
= modifiers
& controlKey
;
2179 event
.m_altDown
= modifiers
& optionKey
;
2180 event
.m_metaDown
= modifiers
& cmdKey
;
2184 event
.m_timeStamp
= timestamp
;
2186 if ( wxWindow::s_lastMouseWindow
)
2188 wxMouseEvent
eventleave(event
);
2189 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
2190 wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
2191 eventleave
.SetEventObject( wxWindow::s_lastMouseWindow
) ;
2194 wxToolTip::RelayEvent( wxWindow::s_lastMouseWindow
, eventleave
);
2195 #endif // wxUSE_TOOLTIPS
2196 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
2198 if ( currentMouseWindow
)
2200 wxMouseEvent
evententer(event
);
2201 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
2202 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
2203 evententer
.SetEventObject( currentMouseWindow
) ;
2205 wxToolTip::RelayEvent( currentMouseWindow
, evententer
);
2206 #endif // wxUSE_TOOLTIPS
2207 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
2209 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
2212 short windowPart
= inNoWindow
;
2214 if ( s_captureWindow
)
2216 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
2217 windowPart
= inContent
;
2221 Point pt
= { y
, x
} ;
2222 windowPart
= ::FindWindow(pt
, &window
);
2229 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2231 win
->MacFireMouseEvent( nullEvent
, x
, y
, modifiers
, timestamp
) ;
2238 UMAShowArrowCursor();
2248 UMAShowArrowCursor();
2255 void wxApp::MacHandleMenuCommand( wxUint32 id
)
2257 wxMenuBar
* mbar
= wxMenuBar::MacGetInstalledMenuBar() ;
2258 wxFrame
* frame
= mbar
->GetFrame();
2259 wxCHECK_RET( mbar
!= NULL
&& frame
!= NULL
, wxT("error in menu item callback") );
2262 frame
->ProcessCommand(id
);
2267 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
2270 return; // no menu item selected
2272 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
2275 Str255 deskAccessoryName
;
2278 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
2279 GetPort(&savedPort
);
2280 OpenDeskAcc(deskAccessoryName
);
2287 GetMenuItemCommandID( GetMenuHandle(macMenuId
) , macMenuItemNum
, &id
) ;
2288 MacHandleMenuCommand( id
) ;