1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
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 #if wxUSE_WX_RESOURCES
40 # include "wx/resource.h"
55 #include "wx/mac/uma.h"
56 #include "wx/mac/macnotfy.h"
59 # include <CoreServices/CoreServices.h>
60 # if defined(WXMAKINGDLL)
61 # include <mach-o/dyld.h>
66 # include <ToolUtils.h>
67 # include <DiskInit.h>
71 extern char *wxBuffer
;
72 extern wxList wxPendingDelete
;
73 extern wxList
*wxWinMacWindowList
;
74 extern wxList
*wxWinMacControlList
;
76 wxApp
*wxTheApp
= NULL
;
78 #if !USE_SHARED_LIBRARY
79 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
80 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
81 EVT_IDLE(wxApp::OnIdle
)
82 EVT_END_SESSION(wxApp::OnEndSession
)
83 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
88 const short kMacMinHeap
= (29 * 1024) ;
89 // platform specific static variables
91 const short kwxMacMenuBarResource
= 1 ;
92 const short kwxMacAppleMenuId
= 1 ;
94 WXHRGN
wxApp::s_macCursorRgn
= NULL
;
95 wxWindow
* wxApp::s_captureWindow
= NULL
;
96 int wxApp::s_lastMouseDown
= 0 ;
97 long wxApp::sm_lastMessageTime
= 0;
99 bool wxApp::s_macDefaultEncodingIsPC
= true ;
100 bool wxApp::s_macSupportPCMenuShortcuts
= true ;
101 long wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
102 wxString
wxApp::s_macHelpMenuTitleName
= "&Help" ;
104 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
105 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
106 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
107 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
) ;
110 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
112 // GD: UNUSED wxApp* app = (wxApp*) refcon ;
113 return wxTheApp
->MacHandleAEODoc( (AppleEvent
*) event
, reply
) ;
116 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
118 // GD: UNUSED wxApp* app = (wxApp*) refcon ;
119 return wxTheApp
->MacHandleAEOApp( (AppleEvent
*) event
, reply
) ;
122 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
124 // GD: UNUSED wxApp* app = (wxApp*) refcon ;
125 return wxTheApp
->MacHandleAEPDoc( (AppleEvent
*) event
, reply
) ;
128 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
130 // GD: UNUSED wxApp* app = (wxApp*) refcon ;
131 return wxTheApp
->MacHandleAEQuit( (AppleEvent
*) event
, reply
) ;
134 short wxApp::MacHandleAEODoc(const WXEVENTREF event
, WXEVENTREF reply
)
137 ProcessSerialNumber PSN
;
138 PSN
.highLongOfPSN
= 0 ;
139 PSN
.lowLongOfPSN
= kCurrentProcess
;
140 SetFrontProcess( &PSN
) ;
144 short wxApp::MacHandleAEPDoc(const WXEVENTREF event
, WXEVENTREF reply
)
149 short wxApp::MacHandleAEOApp(const WXEVENTREF event
, WXEVENTREF reply
)
154 short wxApp::MacHandleAEQuit(const WXEVENTREF event
, WXEVENTREF reply
)
156 wxWindow
* win
= GetTopWindow() ;
168 char StringMac
[] = "\x0d\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
169 "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
170 "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf"
171 "\xb1\xb4\xb5\xb6\xbb\xbc\xbe\xbf"
172 "\xc0\xc1\xc2\xc4\xc7\xc8\xc9\xcb\xcc\xcd\xce\xcf"
173 "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xca\xdb" ;
175 char StringANSI
[] = "\x0a\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8"
176 "\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC"
177 "\x86\xBA\xA2\xA3\xA7\x95\xB6\xDF\xAE\xA9\x99\xB4\xA8\xC6\xD8"
178 "\xB1\xA5\xB5\xF0\xAA\xBA\xE6\xF8"
179 "\xBF\xA1\xAC\x83\xAB\xBB\x85\xC0\xC3\xD5\x8C\x9C"
180 "\x96\x97\x93\x94\x91\x92\xF7\xFF\xA0\x80" ;
182 void wxMacConvertFromPC( const char *from
, char *to
, int len
)
187 for( int i
= 0 ; i
< len
; ++ i
)
189 c
= strchr( StringANSI
, *from
) ;
192 *to
= StringMac
[ c
- StringANSI
] ;
200 for( int i
= 0 ; i
< len
; ++ i
)
202 c
= strchr( StringANSI
, *from
) ;
205 *to
= StringMac
[ c
- StringANSI
] ;
217 void wxMacConvertToPC( const char *from
, char *to
, int len
)
222 for( int i
= 0 ; i
< len
; ++ i
)
224 c
= strchr( StringMac
, *from
) ;
227 *to
= StringANSI
[ c
- StringMac
] ;
235 for( int i
= 0 ; i
< len
; ++ i
)
237 c
= strchr( StringMac
, *from
) ;
240 *to
= StringANSI
[ c
- StringMac
] ;
252 void wxMacConvertFromPC( char * p
)
255 int len
= strlen ( p
) ;
257 wxMacConvertFromPC( ptr
, ptr
, len
) ;
260 void wxMacConvertFromPCForControls( char * p
)
263 int len
= strlen ( p
) ;
265 wxMacConvertFromPC( ptr
, ptr
, len
) ;
266 for ( unsigned int i
= 0 ; i
< strlen ( ptr
) ; i
++ )
268 if ( ptr
[i
] == '&' && ptr
[i
]+1 != ' ' )
270 memmove( &ptr
[i
] , &ptr
[i
+1] , strlen( &ptr
[i
+1] ) + 1) ;
275 void wxMacConvertFromPC( unsigned char *p
)
277 char *ptr
= (char*) p
+ 1 ;
280 wxMacConvertFromPC( ptr
, ptr
, len
) ;
283 extern char *wxBuffer
;
285 wxString
wxMacMakeMacStringFromPC( const char * p
)
287 const char *ptr
= p
;
288 int len
= strlen ( p
) ;
289 char *buf
= wxBuffer
;
291 if ( len
>= BUFSIZ
+ 512 )
293 buf
= new char [len
+1] ;
296 wxMacConvertFromPC( ptr
, buf
, len
) ;
298 wxString
result( buf
) ;
299 if ( buf
!= wxBuffer
)
305 void wxMacConvertToPC( char * p
)
308 int len
= strlen ( p
) ;
310 wxMacConvertToPC( ptr
, ptr
, len
) ;
313 void wxMacConvertToPC( unsigned char *p
)
315 char *ptr
= (char*) p
+ 1 ;
318 wxMacConvertToPC( ptr
, ptr
, len
) ;
321 wxString
wxMacMakePCStringFromMac( const char * p
)
323 const char *ptr
= p
;
324 int len
= strlen ( p
) ;
325 char *buf
= wxBuffer
;
327 if ( len
>= BUFSIZ
+ 512 )
329 buf
= new char [len
+1] ;
332 wxMacConvertToPC( ptr
, buf
, len
) ;
335 wxString
result( buf
) ;
336 if ( buf
!= wxBuffer
)
341 wxString
wxMacMakeStringFromMacString( const char* from
, bool mac2pcEncoding
)
345 return wxMacMakePCStringFromMac( from
) ;
349 return wxString( from
) ;
353 wxString
wxMacMakeStringFromPascal( StringPtr from
, bool mac2pcEncoding
)
355 // this is safe since a pascal string can never be larger than 256 bytes
357 CopyPascalStringToC( from
, s
) ;
360 return wxMacMakePCStringFromMac( s
) ;
364 return wxString( s
) ;
368 void wxMacStringToPascal( const char * from
, StringPtr to
, bool pc2macEncoding
)
372 CopyCStringToPascal( wxMacMakeMacStringFromPC( from
) , to
) ;
376 CopyCStringToPascal( from
, to
) ;
380 #if defined(WXMAKINGDLL) && !defined(__DARWIN__)
381 // we know it's there ;-)
382 WXIMPORT
char std::__throws_bad_alloc
;
385 bool wxApp::Initialize()
391 UMAInitToolbox( 4 ) ;
392 SetEventMask( everyEvent
) ;
393 UMAShowWatchCursor() ;
395 #if defined(WXMAKINGDLL) && defined(__DARWIN__)
396 // open shared library resources from here since we don't have
397 // __wxinitialize in Mach-O shared libraries
398 wxStAppResource::OpenSharedLibraryResource(NULL
);
401 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
402 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
403 NewAEEventHandlerUPP(AEHandleODoc
) ,
404 (long) wxTheApp
, FALSE
) ;
405 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
406 NewAEEventHandlerUPP(AEHandleOApp
) ,
407 (long) wxTheApp
, FALSE
) ;
408 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
409 NewAEEventHandlerUPP(AEHandlePDoc
) ,
410 (long) wxTheApp
, FALSE
) ;
411 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
412 NewAEEventHandlerUPP(AEHandleQuit
) ,
413 (long) wxTheApp
, FALSE
) ;
415 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
,
416 NewAEEventHandlerProc(AEHandleODoc
) ,
417 (long) wxTheApp
, FALSE
) ;
418 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
,
419 NewAEEventHandlerProc(AEHandleOApp
) ,
420 (long) wxTheApp
, FALSE
) ;
421 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
,
422 NewAEEventHandlerProc(AEHandlePDoc
) ,
423 (long) wxTheApp
, FALSE
) ;
424 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
,
425 NewAEEventHandlerProc(AEHandleQuit
) ,
426 (long) wxTheApp
, FALSE
) ;
430 // test the minimal configuration necessary
436 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
438 error
= kMacSTRWrongMachine
;
440 else if (theMachine
< gestaltMacPlus
)
442 error
= kMacSTRWrongMachine
;
444 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
446 error
= kMacSTROldSystem
;
448 else if ( theSystem
< 0x0860 )
450 error
= kMacSTROldSystem
;
452 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
454 error
= kMacSTRSmallSize
;
460 if ( !UMAHasAppearance() )
462 error = kMacSTRNoPre8Yet ;
468 // if we encountered any problems so far, give the error code and exit immediately
472 wxStAppResource resload
;
476 GetIndString(message
, 128, error
);
477 UMAShowArrowCursor() ;
478 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
479 itemHit
= Alert(128, nil
);
484 # if __option(profile)
485 ProfilerInit( collectDetailed
, bestTimeBase
, 20000 , 40 ) ;
490 // now avoid exceptions thrown for new (bad_alloc)
491 std::__throws_bad_alloc
= FALSE
;
494 s_macCursorRgn
= ::NewRgn() ;
496 wxBuffer
= new char[BUFSIZ
+ 512];
498 wxClassInfo::InitializeClasses();
501 // wxGetResource(wxT("wxWindows"), wxT("OsVersion"), &wxOsVersion);
505 wxPendingEventsLocker
= new wxCriticalSection
;
508 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
509 wxTheColourDatabase
->Initialize();
513 // flush the logged messages if any and install a 'safer' log target: the
514 // default one (wxLogGui) can't be used after the resources are freed just
515 // below and the user suppliedo ne might be even more unsafe (using any
516 // wxWindows GUI function is unsafe starting from now)
517 wxLog::DontCreateOnDemand();
519 // this will flush the old messages if any
520 delete wxLog::SetActiveTarget(new wxLogStderr
);
524 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
525 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
527 wxInitializeStockLists();
528 wxInitializeStockObjects();
530 #if wxUSE_WX_RESOURCES
531 wxInitializeResourceSystem();
534 wxBitmap::InitStandardHandlers();
536 wxModule::RegisterModules();
537 if (!wxModule::InitializeModules()) {
541 wxMacCreateNotifierTable() ;
543 UMAShowArrowCursor() ;
548 void wxApp::CleanUp()
550 wxToolTip::RemoveToolTips() ;
552 // flush the logged messages if any and install a 'safer' log target: the
553 // default one (wxLogGui) can't be used after the resources are freed just
554 // below and the user suppliedo ne might be even more unsafe (using any
555 // wxWindows GUI function is unsafe starting from now)
556 wxLog::DontCreateOnDemand();
558 // this will flush the old messages if any
559 delete wxLog::SetActiveTarget(new wxLogStderr
);
562 // One last chance for pending objects to be cleaned up
563 wxTheApp
->DeletePendingObjects();
565 wxModule::CleanUpModules();
567 #if wxUSE_WX_RESOURCES
568 wxCleanUpResourceSystem();
571 wxDeleteStockObjects() ;
573 // Destroy all GDI lists, etc.
574 wxDeleteStockLists();
576 delete wxTheColourDatabase
;
577 wxTheColourDatabase
= NULL
;
579 wxBitmap::CleanUpHandlers();
584 wxMacDestroyNotifierTable() ;
585 if (wxWinMacWindowList
) {
586 delete wxWinMacWindowList
;
588 if (wxWinMacControlList
) {
589 delete wxWinMacControlList
;
591 delete wxPendingEvents
;
594 delete wxPendingEventsLocker
;
595 // If we don't do the following, we get an apparent memory leak.
596 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
599 wxClassInfo::CleanUpClasses();
602 # if __option(profile)
603 ProfilerDump( "\papp.prof" ) ;
611 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
612 // At this point we want to check if there are any memory
613 // blocks that aren't part of the wxDebugContext itself,
614 // as a special case. Then when dumping we need to ignore
615 // wxDebugContext, too.
616 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
618 wxLogDebug(wxT("There were memory leaks."));
619 wxDebugContext::Dump();
620 wxDebugContext::PrintStatistics();
622 // wxDebugContext::SetStream(NULL, NULL);
626 // do it as the very last thing because everything else can log messages
627 delete wxLog::SetActiveTarget(NULL
);
630 #if defined(WXMAKINGDLL) && defined(__DARWIN__)
631 // close shared library resources from here since we don't have
632 // __wxterminate in Mach-O shared libraries
633 wxStAppResource::CloseSharedLibraryResource();
636 UMACleanupToolbox() ;
637 if (s_macCursorRgn
) {
638 ::DisposeRgn((RgnHandle
)s_macCursorRgn
);
646 //----------------------------------------------------------------------
648 //----------------------------------------------------------------------
650 // extern variable for shared library resource id
651 // need to be able to find it with NSLookupAndBindSymbol
652 short gSharedLibraryResource
= kResFileNotOpened
;
654 #if defined(WXMAKINGDLL) && defined(__DARWIN__)
655 CFBundleRef gSharedLibraryBundle
= NULL
;
656 #endif /* WXMAKINGDLL && __DARWIN__ */
658 wxStAppResource::wxStAppResource()
660 m_currentRefNum
= CurResFile() ;
661 if ( gSharedLibraryResource
!= kResFileNotOpened
)
663 UseResFile( gSharedLibraryResource
) ;
667 wxStAppResource::~wxStAppResource()
669 if ( m_currentRefNum
!= kResFileNotOpened
)
671 UseResFile( m_currentRefNum
) ;
675 void wxStAppResource::OpenSharedLibraryResource(const void *initBlock
)
677 gSharedLibraryResource
= kResFileNotOpened
;
680 if ( initBlock
!= NULL
) {
681 const CFragInitBlock
*theInitBlock
= (const CFragInitBlock
*)initBlock
;
682 FSSpec
*fileSpec
= NULL
;
684 if (theInitBlock
->fragLocator
.where
== kDataForkCFragLocator
) {
685 fileSpec
= theInitBlock
->fragLocator
.u
.onDisk
.fileSpec
;
687 else if (theInitBlock
->fragLocator
.where
== kResourceCFragLocator
) {
688 fileSpec
= theInitBlock
->fragLocator
.u
.inSegs
.fileSpec
;
691 if (fileSpec
!= NULL
) {
692 gSharedLibraryResource
= FSpOpenResFile(fileSpec
, fsRdPerm
);
697 // Open the shared library resource file if it is not yet open
700 const char *theLibPath
;
702 gSharedLibraryBundle
= CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWindows"));
703 if (gSharedLibraryBundle
!= NULL
) {
704 // wxWindows has been bundled into a framework
705 // load the framework resources
707 gSharedLibraryResource
= CFBundleOpenBundleResourceMap(gSharedLibraryBundle
);
710 // wxWindows is a simple dynamic shared library
711 // load the resources from the data fork of a separate resource file
716 OSErr theErr
= noErr
;
718 // get the library path
719 theSymbol
= NSLookupAndBindSymbol("_gSharedLibraryResource");
720 theModule
= NSModuleForSymbol(theSymbol
);
721 theLibPath
= NSLibraryNameForModule(theModule
);
723 // allocate copy to replace .dylib.* extension with .rsrc
724 theResPath
= strdup(theLibPath
);
725 if (theResPath
!= NULL
) {
726 theName
= strrchr(theResPath
, '/');
727 if (theName
== NULL
) {
728 // no directory elements in path
729 theName
= theResPath
;
731 // find ".dylib" shared library extension
732 theExt
= strstr(theName
, ".dylib");
733 // overwrite extension with ".rsrc"
734 strcpy(theExt
, ".rsrc");
736 wxLogDebug( theResPath
);
738 theErr
= FSPathMakeRef((UInt8
*) theResPath
, &theResRef
, false);
739 if (theErr
!= noErr
) {
740 // try in current directory (using name only)
741 theErr
= FSPathMakeRef((UInt8
*) theName
, &theResRef
, false);
744 // free duplicated resource file path
747 // open the resource file
748 if (theErr
== noErr
) {
749 theErr
= FSOpenResourceFile( &theResRef
, 0, NULL
, fsRdPerm
,
750 &gSharedLibraryResource
);
754 #endif /* __DARWIN__ */
756 #endif /* WXMAKINGDLL */
759 void wxStAppResource::CloseSharedLibraryResource()
762 // Close the shared library resource file
763 if (gSharedLibraryResource
!= kResFileNotOpened
) {
765 if (gSharedLibraryBundle
!= NULL
) {
766 CFBundleCloseBundleResourceMap(gSharedLibraryBundle
,
767 gSharedLibraryResource
);
768 gSharedLibraryBundle
= NULL
;
771 #endif /* __DARWIN__ */
773 CloseResFile(gSharedLibraryResource
);
775 gSharedLibraryResource
= kResFileNotOpened
;
777 #endif /* WXMAKINGDLL */
780 #if defined(WXMAKINGDLL) && !defined(__DARWIN__)
782 // for shared libraries we have to manually get the correct resource
783 // ref num upon initializing and releasing when terminating, therefore
784 // the __wxinitialize and __wxterminate must be used
787 void __sinit(void); /* (generated by linker) */
788 pascal OSErr
__initialize(const CFragInitBlock
*theInitBlock
);
789 pascal void __terminate(void);
792 pascal OSErr
__wxinitialize(const CFragInitBlock
*theInitBlock
)
794 wxStAppResource::OpenSharedLibraryResource( theInitBlock
) ;
795 return __initialize( theInitBlock
) ;
798 pascal void __wxterminate(void)
800 wxStAppResource::CloseSharedLibraryResource() ;
804 #endif /* WXMAKINGDLL && !__DARWIN__ */
806 int WXDLLEXPORT
wxEntryStart( int argc
, char *argv
[] )
808 return wxApp::Initialize();
811 int WXDLLEXPORT
wxEntryInitGui()
813 return wxTheApp
->OnInitGui();
816 void WXDLLEXPORT
wxEntryCleanup()
821 int wxEntry( int argc
, char *argv
[] , bool enterLoop
)
824 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
825 // This seems to be necessary since there are 'rogue'
826 // objects present at this point (perhaps global objects?)
827 // Setting a checkpoint will ignore them as far as the
828 // memory checking facility is concerned.
829 // Of course you may argue that memory allocated in globals should be
830 // checked, but this is a reasonable compromise.
831 wxDebugContext::SetCheckpoint();
834 if (!wxEntryStart(argc
, argv
)) {
837 // create the application object or ensure that one already exists
840 // The app may have declared a global application object, but we recommend
841 // the IMPLEMENT_APP macro is used instead, which sets an initializer
842 // function for delayed, dynamic app object construction.
843 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
844 wxT("No initializer - use IMPLEMENT_APP macro.") );
846 wxTheApp
= (wxApp
*) (*wxApp::GetInitializerFunction()) ();
849 wxCHECK_MSG( wxTheApp
, 0, wxT("You have to define an instance of wxApp!") );
852 // Mac OS X passes a process serial number command line argument when
853 // the application is launched from the Finder. This argument must be
854 // removed from the command line arguments before being handled by the
855 // application (otherwise applications would need to handle it)
859 strncpy(theArg
, argv
[1], 5);
861 if (strcmp(theArg
, "-psn_") == 0) {
862 // assume the argument is always the only one and remove it
867 argc
= 0 ; // currently we don't support files as parameters
869 // we could try to get the open apple events here to adjust argc and argv better
871 wxTheApp
->argc
= argc
;
872 wxTheApp
->argv
= argv
;
874 // GUI-specific initialization, such as creating an app context.
877 // Here frames insert themselves automatically
878 // into wxTopLevelWindows by getting created
883 if ( wxTheApp
->OnInit() )
887 retValue
= wxTheApp
->OnRun();
890 // We want to initialize, but not run or exit immediately.
893 //else: app initialization failed, so we skipped OnRun()
895 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
898 // Forcibly delete the window.
899 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
900 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
902 topWindow
->Close(TRUE
);
903 wxTheApp
->DeletePendingObjects();
908 wxTheApp
->SetTopWindow(NULL
);
919 // Static member initialization
920 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
927 #if WXWIN_COMPATIBILITY_2_2
928 m_wantDebugOutput
= TRUE
;
934 m_printMode
= wxPRINT_WINDOWS
;
935 m_exitOnFrameDelete
= TRUE
;
939 bool wxApp::Initialized()
947 int wxApp::MainLoop()
959 // Returns TRUE if more time is needed.
960 bool wxApp::ProcessIdle()
963 event
.SetEventObject(this);
966 return event
.MoreRequested();
969 void wxApp::ExitMainLoop()
974 // Is a message/event pending?
975 bool wxApp::Pending()
979 return EventAvail( everyEvent
, &event
) ;
982 // Dispatch a message.
983 void wxApp::Dispatch()
988 void wxApp::OnIdle(wxIdleEvent
& event
)
990 static bool s_inOnIdle
= FALSE
;
992 // Avoid recursion (via ProcessEvent default case)
999 // 'Garbage' collection of windows deleted with Close().
1000 DeletePendingObjects();
1002 // flush the logged messages if any
1003 wxLog
*pLog
= wxLog::GetActiveTarget();
1004 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
1007 // Send OnIdle events to all windows
1008 bool needMore
= SendIdleEvents();
1011 event
.RequestMore(TRUE
);
1013 // If they are pending events, we must process them: pending events are
1014 // either events to the threads other than main or events posted with
1015 // wxPostEvent() functions
1016 wxMacProcessNotifierAndPendingEvents();
1026 // Send idle event to all top-level windows
1027 bool wxApp::SendIdleEvents()
1029 bool needMore
= FALSE
;
1030 wxNode
* node
= wxTopLevelWindows
.First();
1033 wxWindow
* win
= (wxWindow
*) node
->Data();
1034 if (SendIdleEvents(win
))
1037 node
= node
->Next();
1042 // Send idle event to window and all subwindows
1043 bool wxApp::SendIdleEvents(wxWindow
* win
)
1045 bool needMore
= FALSE
;
1048 event
.SetEventObject(win
);
1049 win
->ProcessEvent(event
);
1051 if (event
.MoreRequested())
1054 wxNode
* node
= win
->GetChildren().First();
1057 wxWindow
* win
= (wxWindow
*) node
->Data();
1058 if (SendIdleEvents(win
))
1061 node
= node
->Next();
1066 void wxApp::DeletePendingObjects()
1068 wxNode
*node
= wxPendingDelete
.First();
1071 wxObject
*obj
= (wxObject
*)node
->Data();
1075 if (wxPendingDelete
.Member(obj
))
1078 // Deleting one object may have deleted other pending
1079 // objects, so start from beginning of list again.
1080 node
= wxPendingDelete
.First();
1086 wxLogError(_("Fatal error: exiting"));
1092 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
1095 GetTopWindow()->Close(TRUE
);
1098 // Default behaviour: close the application with prompts. The
1099 // user can veto the close, and therefore the end session.
1100 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
1104 if (!GetTopWindow()->Close(!event
.CanVeto()))
1109 extern "C" void wxCYield() ;
1115 // Yield to other processes
1117 bool wxApp::Yield(bool onlyIfNeeded
)
1119 static bool s_inYield
= FALSE
;
1123 if ( !onlyIfNeeded
)
1125 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1134 YieldToAnyThread() ;
1138 long sleepTime
= 1 ; //::GetCaretTime();
1140 while ( !wxTheApp
->IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, (RgnHandle
) wxApp::s_macCursorRgn
))
1142 wxTheApp
->MacHandleOneEvent( &event
);
1143 if ( event
.what
!= kHighLevelEvent
)
1144 SetRectRgn( (RgnHandle
) wxApp::s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1147 wxMacProcessNotifierAndPendingEvents() ;
1154 // platform specifics
1156 void wxApp::MacSuspend( bool convertClipboard
)
1158 // we have to deactive the top level windows manually
1160 wxNode
* node
= wxTopLevelWindows
.First();
1163 wxTopLevelWindow
* win
= (wxTopLevelWindow
*) node
->Data();
1164 win
->MacActivate( MacGetCurrentEvent() , false ) ;
1166 node
= node
->Next();
1169 s_lastMouseDown
= 0 ;
1170 if( convertClipboard
)
1172 MacConvertPrivateToPublicScrap() ;
1175 ::HideFloatingWindows() ;
1178 void wxApp::MacResume( bool convertClipboard
)
1180 s_lastMouseDown
= 0 ;
1181 if( convertClipboard
)
1183 MacConvertPublicToPrivateScrap() ;
1186 ::ShowFloatingWindows() ;
1189 void wxApp::MacConvertPrivateToPublicScrap()
1193 void wxApp::MacConvertPublicToPrivateScrap()
1197 void wxApp::MacDoOneEvent()
1201 long sleepTime
= 1; // GetCaretTime() / 4 ;
1203 if (WaitNextEvent(everyEvent
, &event
, sleepTime
, (RgnHandle
) s_macCursorRgn
))
1205 MacHandleOneEvent( &event
);
1210 WindowPtr window
= ::FrontWindow() ;
1212 ::IdleControls( window
) ;
1214 wxTheApp
->ProcessIdle() ;
1216 if ( event
.what
!= kHighLevelEvent
)
1217 SetRectRgn( (RgnHandle
) s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1221 DeletePendingObjects() ;
1222 wxMacProcessNotifierAndPendingEvents() ;
1225 void wxApp::MacHandleOneEvent( WXEVENTREF evr
)
1227 EventRecord
* ev
= (EventRecord
*) evr
;
1228 m_macCurrentEvent
= ev
;
1230 wxApp::sm_lastMessageTime
= ev
->when
;
1235 MacHandleMouseDownEvent( ev
) ;
1236 if ( ev
->modifiers
& controlKey
)
1237 s_lastMouseDown
= 2;
1239 s_lastMouseDown
= 1;
1242 if ( s_lastMouseDown
== 2 )
1244 ev
->modifiers
|= controlKey
;
1248 ev
->modifiers
&= ~controlKey
;
1250 MacHandleMouseUpEvent( ev
) ;
1251 s_lastMouseDown
= 0;
1254 MacHandleActivateEvent( ev
) ;
1257 MacHandleUpdateEvent( ev
) ;
1261 MacHandleKeyDownEvent( ev
) ;
1264 MacHandleKeyUpEvent( ev
) ;
1267 MacHandleDiskEvent( ev
) ;
1270 MacHandleOSEvent( ev
) ;
1272 case kHighLevelEvent
:
1273 MacHandleHighLevelEvent( ev
) ;
1278 wxMacProcessNotifierAndPendingEvents() ;
1281 void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr
)
1283 EventRecord
* ev
= (EventRecord
*) evr
;
1284 ::AEProcessAppleEvent( ev
) ;
1287 bool s_macIsInModalLoop
= false ;
1289 void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr
)
1291 EventRecord
* ev
= (EventRecord
*) evr
;
1292 wxToolTip::RemoveToolTips() ;
1295 WindowRef frontWindow
= ::FrontNonFloatingWindow() ;
1296 WindowAttributes frontWindowAttributes
= NULL
;
1298 ::GetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
1300 short windowPart
= ::FindWindow(ev
->where
, &window
);
1301 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1302 if ( wxPendingDelete
.Member(win
) )
1306 GetQDGlobalsScreenBits( &screenBits
);
1311 if ( s_macIsInModalLoop
)
1317 UInt32 menuresult
= MenuSelect(ev
->where
) ;
1318 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1319 s_lastMouseDown
= 0;
1324 SystemClick( ev
, window
) ;
1325 s_lastMouseDown
= 0;
1329 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1335 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1340 Point pt
= { 0, 0 } ;
1341 SetPortWindowPort(window
) ;
1342 LocalToGlobal( &pt
) ;
1344 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1345 -1 , wxSIZE_USE_EXISTING
);
1347 s_lastMouseDown
= 0;
1351 if (TrackGoAway(window
, ev
->where
))
1356 s_lastMouseDown
= 0;
1360 int growResult
= GrowWindow(window
, ev
->where
, &screenBits
.bounds
);
1361 if (growResult
!= 0)
1363 int newWidth
= LoWord(growResult
);
1364 int newHeight
= HiWord(growResult
);
1365 int oldWidth
, oldHeight
;
1370 win
->GetSize(&oldWidth
, &oldHeight
);
1372 newWidth
= oldWidth
;
1374 newHeight
= oldHeight
;
1375 win
->SetSize( -1, -1, newWidth
, newHeight
, wxSIZE_USE_EXISTING
);
1378 s_lastMouseDown
= 0;
1383 if (TrackBox(window
, ev
->where
, windowPart
))
1385 // TODO setup size event
1386 ZoomWindow( window
, windowPart
, false ) ;
1391 GetWindowPortBounds(window
, &tempRect
) ;
1392 win
->SetSize( -1, -1, tempRect
.right
-tempRect
.left
,
1393 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1396 s_lastMouseDown
= 0;
1398 case inCollapseBox
:
1399 // TODO setup size event
1400 s_lastMouseDown
= 0;
1407 SetPortWindowPort(window
) ;
1410 if ( window
!= frontWindow
&& wxTheApp
->s_captureWindow
== NULL
)
1412 if ( s_macIsInModalLoop
)
1416 else if ( UMAIsWindowFloating( window
) )
1419 win
->MacMouseDown( ev
, windowPart
) ;
1424 win
->MacMouseDown( ev
, windowPart
) ;
1425 ::SelectWindow( window
) ;
1431 win
->MacMouseDown( ev
, windowPart
) ;
1440 void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr
)
1442 EventRecord
* ev
= (EventRecord
*) evr
;
1445 short windowPart
= inNoWindow
;
1446 if ( wxTheApp
->s_captureWindow
)
1448 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
1449 windowPart
= inContent
;
1453 windowPart
= ::FindWindow(ev
->where
, &window
) ;
1464 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1466 win
->MacMouseUp( ev
, windowPart
) ;
1472 long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
1473 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1482 retval
= WXK_RETURN
;
1497 retval
= WXK_PAGEUP
;
1500 retval
= WXK_PAGEDOWN
;
1503 retval
= WXK_RETURN
;
1558 retval
= WXK_ESCAPE
;
1564 retval
= WXK_RIGHT
;
1573 retval
= WXK_DELETE
;
1581 void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr
)
1583 EventRecord
* ev
= (EventRecord
*) evr
;
1584 wxToolTip::RemoveToolTips() ;
1586 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1587 if ( HiWord( menuresult
) )
1589 if ( !s_macIsInModalLoop
)
1590 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1596 keychar
= short(ev
->message
& charCodeMask
);
1597 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1598 // it is wxWindows Convention to have Ctrl Key Combinations at ASCII char value
1599 if ( ev
->modifiers
& controlKey
&& keychar
>= 0 && keychar
< 0x20 )
1603 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1604 bool handled
= false ;
1605 wxWindow
* focus
= wxWindow::FindFocus() ;
1609 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1610 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1611 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1612 event
.m_altDown
= ev
->modifiers
& optionKey
;
1613 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1614 event
.m_keyCode
= keyval
;
1615 event
.m_x
= ev
->where
.h
;
1616 event
.m_y
= ev
->where
.v
;
1617 event
.m_timeStamp
= ev
->when
;
1618 event
.SetEventObject(focus
);
1619 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1620 if ( handled
&& event
.GetSkipped() )
1627 wxWindow
*ancestor
= focus
;
1630 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1633 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1634 handled
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1637 if (ancestor
->IsTopLevel())
1639 ancestor
= ancestor
->GetParent();
1642 #endif // wxUSE_ACCEL
1646 wxKeyEvent
event(wxEVT_CHAR
);
1647 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1648 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1649 event
.m_altDown
= ev
->modifiers
& optionKey
;
1650 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1651 event
.m_keyCode
= keyval
;
1652 event
.m_x
= ev
->where
.h
;
1653 event
.m_y
= ev
->where
.v
;
1654 event
.m_timeStamp
= ev
->when
;
1655 event
.SetEventObject(focus
);
1656 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1657 if ( handled
&& event
.GetSkipped() )
1661 (keyval
== WXK_TAB
) &&
1662 // CS: copied the change below from wxGTK
1663 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
1664 // have this style, yet choose not to process this particular TAB in which
1665 // case TAB must still work as a navigational character
1667 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1669 (focus
->GetParent()) &&
1670 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1672 wxNavigationKeyEvent new_event
;
1673 new_event
.SetEventObject( focus
);
1674 new_event
.SetDirection( !event
.ShiftDown() );
1675 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1676 new_event
.SetWindowChange( event
.ControlDown() );
1677 new_event
.SetCurrentFocus( focus
);
1678 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1679 if ( handled
&& new_event
.GetSkipped() )
1685 // if window is not having a focus still testing for default enter or cancel
1686 // TODO add the UMA version for ActiveNonFloatingWindow
1687 focus
= wxFindWinFromMacWindow( FrontWindow() ) ;
1690 if ( keyval
== WXK_RETURN
)
1692 wxButton
*def
= wxDynamicCast(focus
->GetDefaultItem(),
1694 if ( def
&& def
->IsEnabled() )
1696 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
1697 event
.SetEventObject(def
);
1698 def
->Command(event
);
1702 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1703 else if (keyval
== WXK_ESCAPE
|| (keyval
== '.' && ev
->modifiers
& cmdKey
) )
1705 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1706 new_event
.SetEventObject( focus
);
1707 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1714 void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr
)
1716 EventRecord
* ev
= (EventRecord
*) evr
;
1717 wxToolTip::RemoveToolTips() ;
1719 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1720 if ( HiWord( menuresult
) )
1727 keychar
= short(ev
->message
& charCodeMask
);
1728 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1730 wxWindow
* focus
= wxWindow::FindFocus() ;
1733 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1735 wxKeyEvent
event(wxEVT_KEY_UP
);
1736 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1737 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1738 event
.m_altDown
= ev
->modifiers
& optionKey
;
1739 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1740 event
.m_keyCode
= keyval
;
1741 event
.m_x
= ev
->where
.h
;
1742 event
.m_y
= ev
->where
.v
;
1743 event
.m_timeStamp
= ev
->when
;
1744 event
.SetEventObject(focus
);
1745 bool handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1750 void wxApp::MacHandleActivateEvent( WXEVENTREF evr
)
1752 EventRecord
* ev
= (EventRecord
*) evr
;
1753 WindowRef window
= (WindowRef
) ev
->message
;
1756 bool activate
= (ev
->modifiers
& activeFlag
) ;
1757 WindowClass wclass
;
1758 ::GetWindowClass ( window
, &wclass
) ;
1759 if ( wclass
== kFloatingWindowClass
)
1761 // if it is a floater we activate/deactivate the front non-floating window instead
1762 window
= ::FrontNonFloatingWindow() ;
1764 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1766 win
->MacActivate( ev
, activate
) ;
1770 void wxApp::MacHandleUpdateEvent( WXEVENTREF evr
)
1772 EventRecord
* ev
= (EventRecord
*) evr
;
1773 WindowRef window
= (WindowRef
) ev
->message
;
1774 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1777 if ( !wxPendingDelete
.Member(win
) )
1778 win
->MacUpdate( ev
->when
) ;
1782 // since there is no way of telling this foreign window to update itself
1783 // we have to invalidate the update region otherwise we keep getting the same
1784 // event over and over again
1785 BeginUpdate( window
) ;
1786 EndUpdate( window
) ;
1790 void wxApp::MacHandleDiskEvent( WXEVENTREF evr
)
1792 EventRecord
* ev
= (EventRecord
*) evr
;
1793 if ( HiWord( ev
->message
) != noErr
)
1798 SetPt( &point
, 100 , 100 ) ;
1800 err
= DIBadMount( point
, ev
->message
) ;
1801 wxASSERT( err
== noErr
) ;
1806 void wxApp::MacHandleOSEvent( WXEVENTREF evr
)
1808 EventRecord
* ev
= (EventRecord
*) evr
;
1809 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
1811 case suspendResumeMessage
:
1813 bool isResuming
= ev
->message
& resumeFlag
;
1815 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
1817 bool convertClipboard
= false;
1819 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
1822 WindowRef oldFrontWindow
= NULL
;
1823 WindowRef newFrontWindow
= NULL
;
1825 // in case we don't take care of activating ourselves, we have to synchronize
1826 // our idea of the active window with the process manager's - which it already activated
1828 if ( !doesActivate
)
1829 oldFrontWindow
= ::FrontNonFloatingWindow() ;
1831 MacResume( convertClipboard
) ;
1833 newFrontWindow
= ::FrontNonFloatingWindow() ;
1835 if ( oldFrontWindow
)
1837 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
1839 win
->MacActivate( ev
, false ) ;
1841 if ( newFrontWindow
)
1843 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
1845 win
->MacActivate( ev
, true ) ;
1850 MacSuspend( convertClipboard
) ;
1852 // in case this suspending did close an active window, another one might
1853 // have surfaced -> lets deactivate that one
1855 /* TODO : find out what to do on systems < 10 , perhaps FrontNonFloatingWindow
1856 WindowRef newActiveWindow = ::ActiveNonFloatingWindow() ;
1857 if ( newActiveWindow )
1859 wxWindow* win = wxFindWinFromMacWindow( newActiveWindow ) ;
1861 win->MacActivate( ev , false ) ;
1867 case mouseMovedMessage
:
1871 wxWindow
* currentMouseWindow
= NULL
;
1873 wxWindow::MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) ,
1874 ¤tMouseWindow
) ;
1875 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
1877 wxMouseEvent event
;
1879 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1880 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1882 event
.m_leftDown
= isDown
&& !controlDown
;
1883 event
.m_middleDown
= FALSE
;
1884 event
.m_rightDown
= isDown
&& controlDown
;
1885 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1886 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1887 event
.m_altDown
= ev
->modifiers
& optionKey
;
1888 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1889 event
.m_x
= ev
->where
.h
;
1890 event
.m_y
= ev
->where
.v
;
1891 event
.m_timeStamp
= ev
->when
;
1892 event
.SetEventObject(this);
1894 if ( wxWindow::s_lastMouseWindow
)
1896 wxMouseEvent
eventleave(event
);
1897 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
1898 wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
1899 eventleave
.SetEventObject( wxWindow::s_lastMouseWindow
) ;
1901 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
1903 if ( currentMouseWindow
)
1905 wxMouseEvent
evententer(event
);
1906 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
1907 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
1908 evententer
.SetEventObject( currentMouseWindow
) ;
1909 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
1911 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
1914 short windowPart
= ::FindWindow(ev
->where
, &window
);
1918 // fixes for setting the cursor back from dominic mazzoni
1920 UMAShowArrowCursor();
1923 UMAShowArrowCursor();
1927 // if ( s_lastMouseDown == 0 )
1928 // ev->modifiers |= btnState ;
1930 // Calling GetNextEvent with a zero event mask will always
1931 // pass back a null event. However, it fills the EventRecord
1932 // with the state of the modifier keys. This is needed since
1933 // the modifier state returned by WaitForNextEvent often is
1934 // wrong mouse move events. The attempt above to correct this
1935 // didn't always work (under OS X at least).
1938 ::GetNextEvent(0, &tmp
);
1939 ev
->modifiers
= tmp
.modifiers
;
1941 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1943 win
->MacMouseMoved( ev
, windowPart
) ;
1945 UMAShowArrowCursor();
1956 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
1959 return; // no menu item selected
1961 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
1964 Str255 deskAccessoryName
;
1967 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
1968 GetPort(&savedPort
);
1969 OpenDeskAcc(deskAccessoryName
);
1975 wxWindow
* frontwindow
= wxFindWinFromMacWindow( ::FrontWindow() ) ;
1976 if ( frontwindow
&& wxMenuBar::MacGetInstalledMenuBar() )
1977 wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow
->GetEventHandler() , 0 , macMenuId
, macMenuItemNum
) ;
1983 long wxApp::MacTranslateKey(char key, int mods)
1987 void wxApp::MacAdjustCursor()
1994 wxApp::macAdjustCursor()
1996 if (ev->what != kHighLevelEvent)
1998 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
2001 if (!theMacWxFrame->MacAdjustCursor(ev->where))
2002 ::SetCursor(&(qd.arrow));