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 WXUNUSED(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 WXUNUSED(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 WXUNUSED(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 WXUNUSED(refcon
) )
130 // GD: UNUSED wxApp* app = (wxApp*) refcon ;
131 return wxTheApp
->MacHandleAEQuit( (AppleEvent
*) event
, reply
) ;
134 short wxApp::MacHandleAEODoc(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
137 ProcessSerialNumber PSN
;
138 PSN
.highLongOfPSN
= 0 ;
139 PSN
.lowLongOfPSN
= kCurrentProcess
;
140 SetFrontProcess( &PSN
) ;
144 short wxApp::MacHandleAEPDoc(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
149 short wxApp::MacHandleAEOApp(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(reply
))
154 short wxApp::MacHandleAEQuit(const WXEVENTREF
WXUNUSED(event
) , WXEVENTREF
WXUNUSED(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() ;
544 UMAShowArrowCursor() ;
549 void wxApp::CleanUp()
551 wxToolTip::RemoveToolTips() ;
553 // flush the logged messages if any and install a 'safer' log target: the
554 // default one (wxLogGui) can't be used after the resources are freed just
555 // below and the user suppliedo ne might be even more unsafe (using any
556 // wxWindows GUI function is unsafe starting from now)
557 wxLog::DontCreateOnDemand();
559 // this will flush the old messages if any
560 delete wxLog::SetActiveTarget(new wxLogStderr
);
563 // One last chance for pending objects to be cleaned up
564 wxTheApp
->DeletePendingObjects();
566 wxModule::CleanUpModules();
568 #if wxUSE_WX_RESOURCES
569 wxCleanUpResourceSystem();
572 wxDeleteStockObjects() ;
574 // Destroy all GDI lists, etc.
575 wxDeleteStockLists();
577 delete wxTheColourDatabase
;
578 wxTheColourDatabase
= NULL
;
580 wxBitmap::CleanUpHandlers();
585 wxMacDestroyNotifierTable() ;
586 if (wxWinMacWindowList
) {
587 delete wxWinMacWindowList
;
589 if (wxWinMacControlList
) {
590 delete wxWinMacControlList
;
592 delete wxPendingEvents
;
595 delete wxPendingEventsLocker
;
596 // If we don't do the following, we get an apparent memory leak.
597 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
600 wxClassInfo::CleanUpClasses();
603 # if __option(profile)
604 ProfilerDump( "\papp.prof" ) ;
612 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
613 // At this point we want to check if there are any memory
614 // blocks that aren't part of the wxDebugContext itself,
615 // as a special case. Then when dumping we need to ignore
616 // wxDebugContext, too.
617 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
619 wxLogDebug(wxT("There were memory leaks."));
620 wxDebugContext::Dump();
621 wxDebugContext::PrintStatistics();
623 // wxDebugContext::SetStream(NULL, NULL);
627 // do it as the very last thing because everything else can log messages
628 delete wxLog::SetActiveTarget(NULL
);
631 #if defined(WXMAKINGDLL) && defined(__DARWIN__)
632 // close shared library resources from here since we don't have
633 // __wxterminate in Mach-O shared libraries
634 wxStAppResource::CloseSharedLibraryResource();
637 UMACleanupToolbox() ;
638 if (s_macCursorRgn
) {
639 ::DisposeRgn((RgnHandle
)s_macCursorRgn
);
647 //----------------------------------------------------------------------
649 //----------------------------------------------------------------------
651 // extern variable for shared library resource id
652 // need to be able to find it with NSLookupAndBindSymbol
653 short gSharedLibraryResource
= kResFileNotOpened
;
655 #if defined(WXMAKINGDLL) && defined(__DARWIN__)
656 CFBundleRef gSharedLibraryBundle
= NULL
;
657 #endif /* WXMAKINGDLL && __DARWIN__ */
659 wxStAppResource::wxStAppResource()
661 m_currentRefNum
= CurResFile() ;
662 if ( gSharedLibraryResource
!= kResFileNotOpened
)
664 UseResFile( gSharedLibraryResource
) ;
668 wxStAppResource::~wxStAppResource()
670 if ( m_currentRefNum
!= kResFileNotOpened
)
672 UseResFile( m_currentRefNum
) ;
676 void wxStAppResource::OpenSharedLibraryResource(const void *initBlock
)
678 gSharedLibraryResource
= kResFileNotOpened
;
681 if ( initBlock
!= NULL
) {
682 const CFragInitBlock
*theInitBlock
= (const CFragInitBlock
*)initBlock
;
683 FSSpec
*fileSpec
= NULL
;
685 if (theInitBlock
->fragLocator
.where
== kDataForkCFragLocator
) {
686 fileSpec
= theInitBlock
->fragLocator
.u
.onDisk
.fileSpec
;
688 else if (theInitBlock
->fragLocator
.where
== kResourceCFragLocator
) {
689 fileSpec
= theInitBlock
->fragLocator
.u
.inSegs
.fileSpec
;
692 if (fileSpec
!= NULL
) {
693 gSharedLibraryResource
= FSpOpenResFile(fileSpec
, fsRdPerm
);
698 // Open the shared library resource file if it is not yet open
701 const char *theLibPath
;
703 gSharedLibraryBundle
= CFBundleGetBundleWithIdentifier(CFSTR("com.wxwindows.wxWindows"));
704 if (gSharedLibraryBundle
!= NULL
) {
705 // wxWindows has been bundled into a framework
706 // load the framework resources
708 gSharedLibraryResource
= CFBundleOpenBundleResourceMap(gSharedLibraryBundle
);
711 // wxWindows is a simple dynamic shared library
712 // load the resources from the data fork of a separate resource file
717 OSErr theErr
= noErr
;
719 // get the library path
720 theSymbol
= NSLookupAndBindSymbol("_gSharedLibraryResource");
721 theModule
= NSModuleForSymbol(theSymbol
);
722 theLibPath
= NSLibraryNameForModule(theModule
);
724 // allocate copy to replace .dylib.* extension with .rsrc
725 theResPath
= strdup(theLibPath
);
726 if (theResPath
!= NULL
) {
727 theName
= strrchr(theResPath
, '/');
728 if (theName
== NULL
) {
729 // no directory elements in path
730 theName
= theResPath
;
732 // find ".dylib" shared library extension
733 theExt
= strstr(theName
, ".dylib");
734 // overwrite extension with ".rsrc"
735 strcpy(theExt
, ".rsrc");
737 wxLogDebug( theResPath
);
739 theErr
= FSPathMakeRef((UInt8
*) theResPath
, &theResRef
, false);
740 if (theErr
!= noErr
) {
741 // try in current directory (using name only)
742 theErr
= FSPathMakeRef((UInt8
*) theName
, &theResRef
, false);
745 // free duplicated resource file path
748 // open the resource file
749 if (theErr
== noErr
) {
750 theErr
= FSOpenResourceFile( &theResRef
, 0, NULL
, fsRdPerm
,
751 &gSharedLibraryResource
);
755 #endif /* __DARWIN__ */
757 #endif /* WXMAKINGDLL */
760 void wxStAppResource::CloseSharedLibraryResource()
763 // Close the shared library resource file
764 if (gSharedLibraryResource
!= kResFileNotOpened
) {
766 if (gSharedLibraryBundle
!= NULL
) {
767 CFBundleCloseBundleResourceMap(gSharedLibraryBundle
,
768 gSharedLibraryResource
);
769 gSharedLibraryBundle
= NULL
;
772 #endif /* __DARWIN__ */
774 CloseResFile(gSharedLibraryResource
);
776 gSharedLibraryResource
= kResFileNotOpened
;
778 #endif /* WXMAKINGDLL */
781 #if defined(WXMAKINGDLL) && !defined(__DARWIN__)
783 // for shared libraries we have to manually get the correct resource
784 // ref num upon initializing and releasing when terminating, therefore
785 // the __wxinitialize and __wxterminate must be used
788 void __sinit(void); /* (generated by linker) */
789 pascal OSErr
__initialize(const CFragInitBlock
*theInitBlock
);
790 pascal void __terminate(void);
793 pascal OSErr
__wxinitialize(const CFragInitBlock
*theInitBlock
)
795 wxStAppResource::OpenSharedLibraryResource( theInitBlock
) ;
796 return __initialize( theInitBlock
) ;
799 pascal void __wxterminate(void)
801 wxStAppResource::CloseSharedLibraryResource() ;
805 #endif /* WXMAKINGDLL && !__DARWIN__ */
807 int WXDLLEXPORT
wxEntryStart( int WXUNUSED(argc
), char *WXUNUSED(argv
)[] )
809 return wxApp::Initialize();
812 int WXDLLEXPORT
wxEntryInitGui()
814 return wxTheApp
->OnInitGui();
817 void WXDLLEXPORT
wxEntryCleanup()
822 int wxEntry( int argc
, char *argv
[] , bool enterLoop
)
825 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
826 // This seems to be necessary since there are 'rogue'
827 // objects present at this point (perhaps global objects?)
828 // Setting a checkpoint will ignore them as far as the
829 // memory checking facility is concerned.
830 // Of course you may argue that memory allocated in globals should be
831 // checked, but this is a reasonable compromise.
832 wxDebugContext::SetCheckpoint();
835 if (!wxEntryStart(argc
, argv
)) {
838 // create the application object or ensure that one already exists
841 // The app may have declared a global application object, but we recommend
842 // the IMPLEMENT_APP macro is used instead, which sets an initializer
843 // function for delayed, dynamic app object construction.
844 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
845 wxT("No initializer - use IMPLEMENT_APP macro.") );
847 wxTheApp
= (wxApp
*) (*wxApp::GetInitializerFunction()) ();
850 wxCHECK_MSG( wxTheApp
, 0, wxT("You have to define an instance of wxApp!") );
853 // Mac OS X passes a process serial number command line argument when
854 // the application is launched from the Finder. This argument must be
855 // removed from the command line arguments before being handled by the
856 // application (otherwise applications would need to handle it)
860 strncpy(theArg
, argv
[1], 5);
862 if (strcmp(theArg
, "-psn_") == 0) {
863 // assume the argument is always the only one and remove it
868 argc
= 0 ; // currently we don't support files as parameters
870 // we could try to get the open apple events here to adjust argc and argv better
872 wxTheApp
->argc
= argc
;
873 wxTheApp
->argv
= argv
;
875 // GUI-specific initialization, such as creating an app context.
878 // Here frames insert themselves automatically
879 // into wxTopLevelWindows by getting created
884 if ( wxTheApp
->OnInit() )
888 retValue
= wxTheApp
->OnRun();
891 // We want to initialize, but not run or exit immediately.
894 //else: app initialization failed, so we skipped OnRun()
896 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
899 // Forcibly delete the window.
900 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
901 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
903 topWindow
->Close(TRUE
);
904 wxTheApp
->DeletePendingObjects();
909 wxTheApp
->SetTopWindow(NULL
);
922 bool wxMacConvertEventToRecord( EventRef event
, EventRecord
*rec
)
924 bool converted
= ConvertEventRefToEventRecord( event
,rec
) ;
925 OSStatus err
= noErr
;
928 switch( GetEventClass( event
) )
930 case kEventClassKeyboard
:
933 switch( GetEventKind(event
) )
935 case kEventRawKeyDown
:
936 rec
->what
= keyDown
;
938 case kEventRawKeyRepeat
:
939 rec
->what
= autoKey
;
941 case kEventRawKeyUp
:
944 case kEventRawKeyModifiersChanged
:
945 rec
->what
= nullEvent
;
954 unsigned char charCode
;
956 GetMouse( &rec
->where
) ;
958 err
= GetEventParameter(event
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
959 err
= GetEventParameter(event
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
960 err
= GetEventParameter(event
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
961 rec
->modifiers
= modifiers
;
962 rec
->message
= (keyCode
<< 8 ) + charCode
;
966 case kEventClassTextInput
:
968 switch( GetEventKind( event
) )
970 case kEventTextInputUnicodeForKeyEvent
:
973 err
= GetEventParameter( event
, kEventParamTextInputSendKeyboardEvent
,typeEventRef
,NULL
,sizeof(rawEvent
),NULL
,&rawEvent
) ;
977 unsigned char charCode
;
979 GetMouse( &rec
->where
) ;
980 rec
->what
= keyDown
;
981 err
= GetEventParameter(rawEvent
, kEventParamKeyModifiers
, typeUInt32
, NULL
, 4, NULL
, &modifiers
);
982 err
= GetEventParameter(rawEvent
, kEventParamKeyCode
, typeUInt32
, NULL
, 4, NULL
, &keyCode
);
983 err
= GetEventParameter(rawEvent
, kEventParamKeyMacCharCodes
, typeChar
, NULL
, 1, NULL
, &charCode
);
984 rec
->modifiers
= modifiers
;
985 rec
->message
= (keyCode
<< 8 ) + charCode
;
1000 pascal OSStatus
wxMacApplicationEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
)
1002 OSStatus result
= eventNotHandledErr
;
1005 switch ( GetEventClass( event
) )
1007 case kEventClassKeyboard
:
1008 if ( wxMacConvertEventToRecord( event
, &rec
) )
1010 wxTheApp
->MacHandleOneEvent( &rec
) ;
1014 case kEventClassTextInput
:
1015 if ( wxMacConvertEventToRecord( event
, &rec
) )
1017 wxTheApp
->MacHandleOneEvent( &rec
) ;
1029 bool wxApp::OnInit()
1031 if ( ! wxAppBase::OnInit() )
1034 #if 0 // TARGET_CARBON
1035 static const EventTypeSpec eventList
[] =
1037 { kEventClassKeyboard
, kEventRawKeyDown
} ,
1038 { kEventClassKeyboard
, kEventRawKeyRepeat
} ,
1039 { kEventClassKeyboard
, kEventRawKeyUp
} ,
1040 { kEventClassKeyboard
, kEventRawKeyModifiersChanged
} ,
1042 { kEventClassTextInput
, kEventTextInputUnicodeForKeyEvent
} ,
1045 InstallApplicationEventHandler(NewEventHandlerUPP(wxMacApplicationEventHandler
)
1046 , WXSIZEOF(eventList
), eventList
, this, NULL
);
1050 // Static member initialization
1051 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
1058 #if WXWIN_COMPATIBILITY_2_2
1059 m_wantDebugOutput
= TRUE
;
1065 m_printMode
= wxPRINT_WINDOWS
;
1066 m_exitOnFrameDelete
= TRUE
;
1070 bool wxApp::Initialized()
1078 int wxApp::MainLoop()
1090 // Returns TRUE if more time is needed.
1091 bool wxApp::ProcessIdle()
1094 event
.SetEventObject(this);
1095 ProcessEvent(event
);
1097 return event
.MoreRequested();
1100 void wxApp::ExitMainLoop()
1102 m_keepGoing
= FALSE
;
1105 // Is a message/event pending?
1106 bool wxApp::Pending()
1110 return EventAvail( everyEvent
, &event
) ;
1113 // Dispatch a message.
1114 void wxApp::Dispatch()
1119 void wxApp::OnIdle(wxIdleEvent
& event
)
1121 static bool s_inOnIdle
= FALSE
;
1123 // Avoid recursion (via ProcessEvent default case)
1130 // 'Garbage' collection of windows deleted with Close().
1131 DeletePendingObjects();
1133 // flush the logged messages if any
1134 wxLog
*pLog
= wxLog::GetActiveTarget();
1135 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
1138 // Send OnIdle events to all windows
1139 bool needMore
= SendIdleEvents();
1142 event
.RequestMore(TRUE
);
1144 // If they are pending events, we must process them: pending events are
1145 // either events to the threads other than main or events posted with
1146 // wxPostEvent() functions
1147 wxMacProcessNotifierAndPendingEvents();
1157 // Send idle event to all top-level windows
1158 bool wxApp::SendIdleEvents()
1160 bool needMore
= FALSE
;
1161 wxNode
* node
= wxTopLevelWindows
.First();
1164 wxWindow
* win
= (wxWindow
*) node
->Data();
1165 if (SendIdleEvents(win
))
1168 node
= node
->Next();
1173 // Send idle event to window and all subwindows
1174 bool wxApp::SendIdleEvents(wxWindow
* win
)
1176 bool needMore
= FALSE
;
1179 event
.SetEventObject(win
);
1180 win
->ProcessEvent(event
);
1182 if (event
.MoreRequested())
1185 wxNode
* node
= win
->GetChildren().First();
1188 wxWindow
* win
= (wxWindow
*) node
->Data();
1189 if (SendIdleEvents(win
))
1192 node
= node
->Next();
1197 void wxApp::DeletePendingObjects()
1199 wxNode
*node
= wxPendingDelete
.First();
1202 wxObject
*obj
= (wxObject
*)node
->Data();
1206 if (wxPendingDelete
.Member(obj
))
1209 // Deleting one object may have deleted other pending
1210 // objects, so start from beginning of list again.
1211 node
= wxPendingDelete
.First();
1217 wxLogError(_("Fatal error: exiting"));
1223 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
1226 GetTopWindow()->Close(TRUE
);
1229 // Default behaviour: close the application with prompts. The
1230 // user can veto the close, and therefore the end session.
1231 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
1235 if (!GetTopWindow()->Close(!event
.CanVeto()))
1240 extern "C" void wxCYield() ;
1246 // Yield to other processes
1248 bool wxApp::Yield(bool onlyIfNeeded
)
1250 static bool s_inYield
= FALSE
;
1254 if ( !onlyIfNeeded
)
1256 wxFAIL_MSG( wxT("wxYield called recursively" ) );
1265 YieldToAnyThread() ;
1269 long sleepTime
= 1 ; //::GetCaretTime();
1271 while ( !wxTheApp
->IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, (RgnHandle
) wxApp::s_macCursorRgn
))
1273 wxTheApp
->MacHandleOneEvent( &event
);
1274 if ( event
.what
!= kHighLevelEvent
)
1275 SetRectRgn( (RgnHandle
) wxApp::s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1278 wxMacProcessNotifierAndPendingEvents() ;
1285 // platform specifics
1287 void wxApp::MacSuspend( bool convertClipboard
)
1289 // we have to deactive the top level windows manually
1291 wxNode
* node
= wxTopLevelWindows
.First();
1294 wxTopLevelWindow
* win
= (wxTopLevelWindow
*) node
->Data();
1295 win
->MacActivate( MacGetCurrentEvent() , false ) ;
1297 node
= node
->Next();
1300 s_lastMouseDown
= 0 ;
1301 if( convertClipboard
)
1303 MacConvertPrivateToPublicScrap() ;
1306 ::HideFloatingWindows() ;
1309 extern wxList wxModalDialogs
;
1311 void wxApp::MacResume( bool convertClipboard
)
1313 s_lastMouseDown
= 0 ;
1314 if( convertClipboard
)
1316 MacConvertPublicToPrivateScrap() ;
1319 ::ShowFloatingWindows() ;
1321 // raise modal dialogs in case a non modal window was selected to activate the app
1323 wxNode
* node
= wxModalDialogs
.First();
1326 wxDialog
* dialog
= (wxDialog
*) node
->Data();
1329 node
= node
->Next();
1333 void wxApp::MacConvertPrivateToPublicScrap()
1337 void wxApp::MacConvertPublicToPrivateScrap()
1341 void wxApp::MacDoOneEvent()
1345 long sleepTime
= 1; // GetCaretTime() / 4 ;
1347 if (WaitNextEvent(everyEvent
, &event
, sleepTime
, (RgnHandle
) s_macCursorRgn
))
1349 MacHandleOneEvent( &event
);
1354 WindowPtr window
= ::FrontWindow() ;
1356 ::IdleControls( window
) ;
1358 wxTheApp
->ProcessIdle() ;
1360 if ( event
.what
!= kHighLevelEvent
)
1361 SetRectRgn( (RgnHandle
) s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1365 DeletePendingObjects() ;
1366 wxMacProcessNotifierAndPendingEvents() ;
1369 void wxApp::MacHandleOneEvent( WXEVENTREF evr
)
1371 EventRecord
* ev
= (EventRecord
*) evr
;
1372 m_macCurrentEvent
= ev
;
1374 wxApp::sm_lastMessageTime
= ev
->when
;
1379 MacHandleMouseDownEvent( ev
) ;
1380 if ( ev
->modifiers
& controlKey
)
1381 s_lastMouseDown
= 2;
1383 s_lastMouseDown
= 1;
1386 if ( s_lastMouseDown
== 2 )
1388 ev
->modifiers
|= controlKey
;
1392 ev
->modifiers
&= ~controlKey
;
1394 MacHandleMouseUpEvent( ev
) ;
1395 s_lastMouseDown
= 0;
1398 MacHandleActivateEvent( ev
) ;
1401 MacHandleUpdateEvent( ev
) ;
1405 MacHandleKeyDownEvent( ev
) ;
1408 MacHandleKeyUpEvent( ev
) ;
1411 MacHandleDiskEvent( ev
) ;
1414 MacHandleOSEvent( ev
) ;
1416 case kHighLevelEvent
:
1417 MacHandleHighLevelEvent( ev
) ;
1422 wxMacProcessNotifierAndPendingEvents() ;
1425 void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr
)
1427 EventRecord
* ev
= (EventRecord
*) evr
;
1428 ::AEProcessAppleEvent( ev
) ;
1431 bool s_macIsInModalLoop
= false ;
1433 void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr
)
1435 EventRecord
* ev
= (EventRecord
*) evr
;
1436 wxToolTip::RemoveToolTips() ;
1439 WindowRef frontWindow
= ::FrontNonFloatingWindow() ;
1440 WindowAttributes frontWindowAttributes
= NULL
;
1442 ::GetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
1444 short windowPart
= ::FindWindow(ev
->where
, &window
);
1445 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1446 if ( wxPendingDelete
.Member(win
) )
1450 GetQDGlobalsScreenBits( &screenBits
);
1455 if ( s_macIsInModalLoop
)
1461 UInt32 menuresult
= MenuSelect(ev
->where
) ;
1462 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1463 s_lastMouseDown
= 0;
1468 SystemClick( ev
, window
) ;
1469 s_lastMouseDown
= 0;
1473 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1479 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1484 Point pt
= { 0, 0 } ;
1485 SetPortWindowPort(window
) ;
1486 LocalToGlobal( &pt
) ;
1488 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1489 -1 , wxSIZE_USE_EXISTING
);
1491 s_lastMouseDown
= 0;
1495 if (TrackGoAway(window
, ev
->where
))
1500 s_lastMouseDown
= 0;
1504 int growResult
= GrowWindow(window
, ev
->where
, &screenBits
.bounds
);
1505 if (growResult
!= 0)
1507 int newWidth
= LoWord(growResult
);
1508 int newHeight
= HiWord(growResult
);
1509 int oldWidth
, oldHeight
;
1514 win
->GetSize(&oldWidth
, &oldHeight
);
1516 newWidth
= oldWidth
;
1518 newHeight
= oldHeight
;
1519 win
->SetSize( -1, -1, newWidth
, newHeight
, wxSIZE_USE_EXISTING
);
1522 s_lastMouseDown
= 0;
1527 if (TrackBox(window
, ev
->where
, windowPart
))
1529 // TODO setup size event
1530 ZoomWindow( window
, windowPart
, false ) ;
1535 GetWindowPortBounds(window
, &tempRect
) ;
1536 win
->SetSize( -1, -1, tempRect
.right
-tempRect
.left
,
1537 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1540 s_lastMouseDown
= 0;
1542 case inCollapseBox
:
1543 // TODO setup size event
1544 s_lastMouseDown
= 0;
1551 SetPortWindowPort(window
) ;
1554 if ( window
!= frontWindow
&& wxTheApp
->s_captureWindow
== NULL
)
1556 if ( s_macIsInModalLoop
)
1560 else if ( UMAIsWindowFloating( window
) )
1563 win
->MacMouseDown( ev
, windowPart
) ;
1568 win
->MacMouseDown( ev
, windowPart
) ;
1569 ::SelectWindow( window
) ;
1575 win
->MacMouseDown( ev
, windowPart
) ;
1584 void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr
)
1586 EventRecord
* ev
= (EventRecord
*) evr
;
1589 short windowPart
= inNoWindow
;
1590 if ( wxTheApp
->s_captureWindow
)
1592 window
= (WindowRef
) s_captureWindow
->MacGetRootWindow() ;
1593 windowPart
= inContent
;
1597 windowPart
= ::FindWindow(ev
->where
, &window
) ;
1608 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1610 win
->MacMouseUp( ev
, windowPart
) ;
1616 long wxMacTranslateKey(unsigned char key
, unsigned char code
) ;
1617 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1626 retval
= WXK_RETURN
;
1641 retval
= WXK_PAGEUP
;
1644 retval
= WXK_PAGEDOWN
;
1647 retval
= WXK_RETURN
;
1702 retval
= WXK_ESCAPE
;
1708 retval
= WXK_RIGHT
;
1717 retval
= WXK_DELETE
;
1725 void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr
)
1727 EventRecord
* ev
= (EventRecord
*) evr
;
1728 wxToolTip::RemoveToolTips() ;
1730 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1731 if ( HiWord( menuresult
) )
1733 if ( !s_macIsInModalLoop
)
1734 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1740 keychar
= short(ev
->message
& charCodeMask
);
1741 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1742 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1743 wxWindow
* focus
= wxWindow::FindFocus() ;
1745 if ( MacSendKeyDownEvent( focus
, keyval
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) == false )
1747 // has not been handled -> perform default
1748 wxControl
* control
= wxDynamicCast( focus
, wxControl
) ;
1749 if ( control
&& control
->GetMacControl() != NULL
)
1751 ::HandleControlKey( (ControlHandle
) control
->GetMacControl() , keycode
, keychar
, ev
->modifiers
) ;
1757 bool wxApp::MacSendKeyDownEvent( wxWindow
* focus
, long keyval
, long modifiers
, long when
, short wherex
, short wherey
)
1759 bool handled
= false ;
1760 // it is wxWindows Convention to have Ctrl Key Combinations at ASCII char value
1761 if ( modifiers
& controlKey
&& keyval
>= 0 && keyval
< 0x20 )
1765 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1766 event
.m_shiftDown
= modifiers
& shiftKey
;
1767 event
.m_controlDown
= modifiers
& controlKey
;
1768 event
.m_altDown
= modifiers
& optionKey
;
1769 event
.m_metaDown
= modifiers
& cmdKey
;
1770 event
.m_keyCode
= keyval
;
1774 event
.m_timeStamp
= when
;
1775 event
.SetEventObject(focus
);
1776 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1777 if ( handled
&& event
.GetSkipped() )
1784 wxWindow
*ancestor
= focus
;
1787 int command
= ancestor
->GetAcceleratorTable()->GetCommand( event
);
1790 wxCommandEvent
command_event( wxEVT_COMMAND_MENU_SELECTED
, command
);
1791 handled
= ancestor
->GetEventHandler()->ProcessEvent( command_event
);
1794 if (ancestor
->IsTopLevel())
1796 ancestor
= ancestor
->GetParent();
1799 #endif // wxUSE_ACCEL
1803 event
.Skip( FALSE
) ;
1804 event
.SetEventType( wxEVT_CHAR
) ;
1806 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1807 if ( handled
&& event
.GetSkipped() )
1811 (keyval
== WXK_TAB
) &&
1812 // CS: copied the change below from wxGTK
1813 // VZ: testing for wxTE_PROCESS_TAB shouldn't be done here the control may
1814 // have this style, yet choose not to process this particular TAB in which
1815 // case TAB must still work as a navigational character
1817 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1819 (focus
->GetParent()) &&
1820 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1822 wxNavigationKeyEvent new_event
;
1823 new_event
.SetEventObject( focus
);
1824 new_event
.SetDirection( !event
.ShiftDown() );
1825 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1826 new_event
.SetWindowChange( event
.ControlDown() );
1827 new_event
.SetCurrentFocus( focus
);
1828 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1829 if ( handled
&& new_event
.GetSkipped() )
1832 // backdoor handler for default return and command escape
1833 if ( !handled
&& (!focus
->IsKindOf(CLASSINFO(wxControl
) ) || !focus
->MacCanFocus() ) )
1835 // if window is not having a focus still testing for default enter or cancel
1836 // TODO add the UMA version for ActiveNonFloatingWindow
1837 wxWindow
* focus
= wxFindWinFromMacWindow( FrontWindow() ) ;
1840 if ( keyval
== WXK_RETURN
)
1842 wxButton
*def
= wxDynamicCast(focus
->GetDefaultItem(),
1844 if ( def
&& def
->IsEnabled() )
1846 wxCommandEvent
event(wxEVT_COMMAND_BUTTON_CLICKED
, def
->GetId() );
1847 event
.SetEventObject(def
);
1848 def
->Command(event
);
1852 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1853 else if (keyval
== WXK_ESCAPE
|| (keyval
== '.' && modifiers
& cmdKey
) )
1855 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1856 new_event
.SetEventObject( focus
);
1857 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1865 void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr
)
1867 EventRecord
* ev
= (EventRecord
*) evr
;
1868 wxToolTip::RemoveToolTips() ;
1870 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1871 if ( HiWord( menuresult
) )
1878 keychar
= short(ev
->message
& charCodeMask
);
1879 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1880 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1882 wxWindow
* focus
= wxWindow::FindFocus() ;
1883 bool handled
= MacSendKeyUpEvent( focus
, keyval
, ev
->modifiers
, ev
->when
, ev
->where
.h
, ev
->where
.v
) ;
1884 // we don't have to do anything under classic here
1888 bool wxApp::MacSendKeyUpEvent( wxWindow
* focus
, long keyval
, long modifiers
, long when
, short wherex
, short wherey
)
1890 bool handled
= false ;
1891 // it is wxWindows Convention to have Ctrl Key Combinations at ASCII char value
1892 if ( modifiers
& controlKey
&& keyval
>= 0 && keyval
< 0x20 )
1898 wxKeyEvent
event(wxEVT_KEY_UP
);
1899 event
.m_shiftDown
= modifiers
& shiftKey
;
1900 event
.m_controlDown
= modifiers
& controlKey
;
1901 event
.m_altDown
= modifiers
& optionKey
;
1902 event
.m_metaDown
= modifiers
& cmdKey
;
1903 event
.m_keyCode
= keyval
;
1907 event
.m_timeStamp
= when
;
1908 event
.SetEventObject(focus
);
1909 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1913 void wxApp::MacHandleActivateEvent( WXEVENTREF evr
)
1915 EventRecord
* ev
= (EventRecord
*) evr
;
1916 WindowRef window
= (WindowRef
) ev
->message
;
1919 bool activate
= (ev
->modifiers
& activeFlag
) ;
1920 WindowClass wclass
;
1921 ::GetWindowClass ( window
, &wclass
) ;
1922 if ( wclass
== kFloatingWindowClass
)
1924 // if it is a floater we activate/deactivate the front non-floating window instead
1925 window
= ::FrontNonFloatingWindow() ;
1927 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1929 win
->MacActivate( ev
, activate
) ;
1933 void wxApp::MacHandleUpdateEvent( WXEVENTREF evr
)
1935 EventRecord
* ev
= (EventRecord
*) evr
;
1936 WindowRef window
= (WindowRef
) ev
->message
;
1937 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
1940 if ( !wxPendingDelete
.Member(win
) )
1941 win
->MacUpdate( ev
->when
) ;
1945 // since there is no way of telling this foreign window to update itself
1946 // we have to invalidate the update region otherwise we keep getting the same
1947 // event over and over again
1948 BeginUpdate( window
) ;
1949 EndUpdate( window
) ;
1953 void wxApp::MacHandleDiskEvent( WXEVENTREF evr
)
1955 EventRecord
* ev
= (EventRecord
*) evr
;
1956 if ( HiWord( ev
->message
) != noErr
)
1961 SetPt( &point
, 100 , 100 ) ;
1963 err
= DIBadMount( point
, ev
->message
) ;
1964 wxASSERT( err
== noErr
) ;
1969 void wxApp::MacHandleOSEvent( WXEVENTREF evr
)
1971 EventRecord
* ev
= (EventRecord
*) evr
;
1972 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
1974 case suspendResumeMessage
:
1976 bool isResuming
= ev
->message
& resumeFlag
;
1978 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
1980 bool convertClipboard
= false;
1982 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
1985 WindowRef oldFrontWindow
= NULL
;
1986 WindowRef newFrontWindow
= NULL
;
1988 // in case we don't take care of activating ourselves, we have to synchronize
1989 // our idea of the active window with the process manager's - which it already activated
1991 if ( !doesActivate
)
1992 oldFrontWindow
= ::FrontNonFloatingWindow() ;
1994 MacResume( convertClipboard
) ;
1996 newFrontWindow
= ::FrontNonFloatingWindow() ;
1998 if ( oldFrontWindow
)
2000 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
2002 win
->MacActivate( ev
, false ) ;
2004 if ( newFrontWindow
)
2006 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
2008 win
->MacActivate( ev
, true ) ;
2013 MacSuspend( convertClipboard
) ;
2015 // in case this suspending did close an active window, another one might
2016 // have surfaced -> lets deactivate that one
2018 /* TODO : find out what to do on systems < 10 , perhaps FrontNonFloatingWindow
2019 WindowRef newActiveWindow = ::ActiveNonFloatingWindow() ;
2020 if ( newActiveWindow )
2022 wxWindow* win = wxFindWinFromMacWindow( newActiveWindow ) ;
2024 win->MacActivate( ev , false ) ;
2030 case mouseMovedMessage
:
2034 wxWindow
* currentMouseWindow
= NULL
;
2036 wxWindow::MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) ,
2037 ¤tMouseWindow
) ;
2038 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
2040 wxMouseEvent event
;
2042 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
2043 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
2045 event
.m_leftDown
= isDown
&& !controlDown
;
2046 event
.m_middleDown
= FALSE
;
2047 event
.m_rightDown
= isDown
&& controlDown
;
2048 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
2049 event
.m_controlDown
= ev
->modifiers
& controlKey
;
2050 event
.m_altDown
= ev
->modifiers
& optionKey
;
2051 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
2052 event
.m_x
= ev
->where
.h
;
2053 event
.m_y
= ev
->where
.v
;
2054 event
.m_timeStamp
= ev
->when
;
2055 event
.SetEventObject(this);
2057 if ( wxWindow::s_lastMouseWindow
)
2059 wxMouseEvent
eventleave(event
);
2060 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
);
2061 wxWindow::s_lastMouseWindow
->ScreenToClient( &eventleave
.m_x
, &eventleave
.m_y
);
2062 eventleave
.SetEventObject( wxWindow::s_lastMouseWindow
) ;
2064 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
2066 if ( currentMouseWindow
)
2068 wxMouseEvent
evententer(event
);
2069 evententer
.SetEventType( wxEVT_ENTER_WINDOW
);
2070 currentMouseWindow
->ScreenToClient( &evententer
.m_x
, &evententer
.m_y
);
2071 evententer
.SetEventObject( currentMouseWindow
) ;
2072 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
2074 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
2077 short windowPart
= ::FindWindow(ev
->where
, &window
);
2081 // fixes for setting the cursor back from dominic mazzoni
2083 UMAShowArrowCursor();
2086 UMAShowArrowCursor();
2090 // if ( s_lastMouseDown == 0 )
2091 // ev->modifiers |= btnState ;
2093 // Calling GetNextEvent with a zero event mask will always
2094 // pass back a null event. However, it fills the EventRecord
2095 // with the state of the modifier keys. This is needed since
2096 // the modifier state returned by WaitForNextEvent often is
2097 // wrong mouse move events. The attempt above to correct this
2098 // didn't always work (under OS X at least).
2101 ::GetNextEvent(0, &tmp
);
2102 ev
->modifiers
= tmp
.modifiers
;
2104 wxTopLevelWindowMac
* win
= wxFindWinFromMacWindow( window
) ;
2106 win
->MacMouseMoved( ev
, windowPart
) ;
2108 UMAShowArrowCursor();
2119 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
2122 return; // no menu item selected
2124 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
2127 Str255 deskAccessoryName
;
2130 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
2131 GetPort(&savedPort
);
2132 OpenDeskAcc(deskAccessoryName
);
2138 wxWindow
* frontwindow
= wxFindWinFromMacWindow( ::FrontWindow() ) ;
2139 if ( frontwindow
&& wxMenuBar::MacGetInstalledMenuBar() )
2140 wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow
->GetEventHandler() , 0 , macMenuId
, macMenuItemNum
) ;
2146 long wxApp::MacTranslateKey(char key, int mods)
2150 void wxApp::MacAdjustCursor()
2157 wxApp::macAdjustCursor()
2159 if (ev->what != kHighLevelEvent)
2161 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
2164 if (!theMacWxFrame->MacAdjustCursor(ev->where))
2165 ::SetCursor(&(qd.arrow));