1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "app.h"
16 #include "wx/window.h"
20 #include "wx/gdicmn.h"
23 #include "wx/cursor.h"
26 #include "wx/palette.h"
28 #include "wx/dialog.h"
29 #include "wx/msgdlg.h"
31 #include "wx/module.h"
32 #include "wx/memory.h"
33 #include "wx/tooltip.h"
34 #include "wx/textctrl.h"
36 #if wxUSE_WX_RESOURCES
37 #include "wx/resource.h"
52 #include "wx/mac/uma.h"
53 #include "wx/mac/macnotfy.h"
57 #include <CoreServices/CoreServices.h>
59 #include <OpenTransport.h>
60 #include <OpenTptInternet.h>
64 extern char *wxBuffer
;
65 extern wxList wxPendingDelete
;
66 extern wxList
*wxWinMacWindowList
;
67 extern wxList
*wxWinMacControlList
;
69 wxApp
*wxTheApp
= NULL
;
71 #if !USE_SHARED_LIBRARY
72 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
73 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
74 EVT_IDLE(wxApp::OnIdle
)
75 EVT_END_SESSION(wxApp::OnEndSession
)
76 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
81 const short kMacMinHeap
= (29 * 1024) ;
82 // platform specific static variables
84 const short kwxMacMenuBarResource
= 1 ;
85 const short kwxMacAppleMenuId
= 1 ;
87 RgnHandle
wxApp::s_macCursorRgn
= NULL
;
88 wxWindow
* wxApp::s_captureWindow
= NULL
;
89 int wxApp::s_lastMouseDown
= 0 ;
90 long wxApp::sm_lastMessageTime
= 0;
92 bool wxApp::s_macDefaultEncodingIsPC
= true ;
93 bool wxApp::s_macSupportPCMenuShortcuts
= true ;
94 long wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
95 wxString
wxApp::s_macHelpMenuTitleName
= "&Help" ;
97 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
98 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
100 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
103 wxApp
* app
= (wxApp
*) refcon
;
104 return wxTheApp
->MacHandleAEODoc( (AppleEvent
*) event
, reply
) ;
107 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
108 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
110 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
113 wxApp
* app
= (wxApp
*) refcon
;
114 return wxTheApp
->MacHandleAEOApp( (AppleEvent
*) event
, reply
) ;
117 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
118 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
120 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
123 wxApp
* app
= (wxApp
*) refcon
;
124 return wxTheApp
->MacHandleAEPDoc( (AppleEvent
*) event
, reply
) ;
127 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
128 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
130 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
133 wxApp
* app
= (wxApp
*) refcon
;
134 return wxTheApp
->MacHandleAEQuit( (AppleEvent
*) event
, reply
) ;
137 OSErr
wxApp::MacHandleAEODoc(const AppleEvent
*event
, AppleEvent
*reply
)
140 ProcessSerialNumber PSN
;
141 PSN
.highLongOfPSN
= 0 ;
142 PSN
.lowLongOfPSN
= kCurrentProcess
;
143 SetFrontProcess( &PSN
) ;
147 OSErr
wxApp::MacHandleAEPDoc(const AppleEvent
*event
, AppleEvent
*reply
)
152 OSErr
wxApp::MacHandleAEOApp(const AppleEvent
*event
, AppleEvent
*reply
)
157 OSErr
wxApp::MacHandleAEQuit(const AppleEvent
*event
, AppleEvent
*reply
)
159 wxWindow
* win
= GetTopWindow() ;
171 char StringMac
[] = "\x0d\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
172 "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
173 "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf"
174 "\xb1\xb4\xb5\xb6\xbb\xbc\xbe\xbf"
175 "\xc0\xc1\xc2\xc4\xc7\xc8\xc9\xcb\xcc\xcd\xce\xcf"
176 "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xca\xdb" ;
178 char StringANSI
[] = "\x0a\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8"
179 "\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC"
180 "\x86\xBA\xA2\xA3\xA7\x95\xB6\xDF\xAE\xA9\x99\xB4\xA8\xC6\xD8"
181 "\xB1\xA5\xB5\xF0\xAA\xBA\xE6\xF8"
182 "\xBF\xA1\xAC\x83\xAB\xBB\x85\xC0\xC3\xD5\x8C\x9C"
183 "\x96\x97\x93\x94\x91\x92\xF7\xFF\xA0\x80" ;
185 void wxMacConvertFromPC( const char *from
, char *to
, int len
)
190 for( int i
= 0 ; i
< len
; ++ i
)
192 c
= strchr( StringANSI
, *from
) ;
195 *to
= StringMac
[ c
- StringANSI
] ;
203 for( int i
= 0 ; i
< len
; ++ i
)
205 c
= strchr( StringANSI
, *from
) ;
208 *to
= StringMac
[ c
- StringANSI
] ;
220 void wxMacConvertToPC( const char *from
, char *to
, int len
)
225 for( int i
= 0 ; i
< len
; ++ i
)
227 c
= strchr( StringMac
, *from
) ;
230 *to
= StringANSI
[ c
- StringMac
] ;
238 for( int i
= 0 ; i
< len
; ++ i
)
240 c
= strchr( StringMac
, *from
) ;
243 *to
= StringANSI
[ c
- StringMac
] ;
255 void wxMacConvertFromPC( char * p
)
258 int len
= strlen ( p
) ;
260 wxMacConvertFromPC( ptr
, ptr
, len
) ;
263 void wxMacConvertFromPCForControls( char * p
)
266 int len
= strlen ( p
) ;
268 wxMacConvertFromPC( ptr
, ptr
, len
) ;
269 for ( int i
= 0 ; i
< strlen ( ptr
) ; i
++ )
271 if ( ptr
[i
] == '&' && ptr
[i
]+1 != ' ' )
273 memmove( &ptr
[i
] , &ptr
[i
+1] , strlen( &ptr
[i
+1] ) + 1) ;
278 void wxMacConvertFromPC( unsigned char *p
)
280 char *ptr
= (char*) p
+ 1 ;
283 wxMacConvertFromPC( ptr
, ptr
, len
) ;
286 extern char *wxBuffer
;
288 wxString
wxMacMakeMacStringFromPC( const char * p
)
290 const char *ptr
= p
;
291 int len
= strlen ( p
) ;
292 char *buf
= wxBuffer
;
294 if ( len
>= BUFSIZ
+ 512 )
296 buf
= new char [len
+1] ;
299 wxMacConvertFromPC( ptr
, buf
, len
) ;
301 wxString
result( buf
) ;
302 if ( buf
!= wxBuffer
)
308 void wxMacConvertToPC( char * p
)
311 int len
= strlen ( p
) ;
313 wxMacConvertToPC( ptr
, ptr
, len
) ;
316 void wxMacConvertToPC( unsigned char *p
)
318 char *ptr
= (char*) p
+ 1 ;
321 wxMacConvertToPC( ptr
, ptr
, len
) ;
324 wxString
wxMacMakePCStringFromMac( const char * p
)
326 const char *ptr
= p
;
327 int len
= strlen ( p
) ;
328 char *buf
= wxBuffer
;
330 if ( len
>= BUFSIZ
+ 512 )
332 buf
= new char [len
+1] ;
335 wxMacConvertToPC( ptr
, buf
, len
) ;
338 wxString
result( buf
) ;
339 if ( buf
!= wxBuffer
)
344 wxString
wxMacMakeStringFromMacString( const char* from
, bool mac2pcEncoding
)
348 return wxMacMakePCStringFromMac( from
) ;
352 return wxString( from
) ;
356 wxString
wxMacMakeStringFromPascal( StringPtr from
, bool mac2pcEncoding
)
358 // this is safe since a pascal string can never be larger than 256 bytes
360 CopyPascalStringToC( from
, s
) ;
363 return wxMacMakePCStringFromMac( s
) ;
367 return wxString( s
) ;
371 void wxMacStringToPascal( const char * from
, StringPtr to
, bool pc2macEncoding
)
375 CopyCStringToPascal( wxMacMakeMacStringFromPC( from
) , to
) ;
379 CopyCStringToPascal( from
, to
) ;
383 bool wxApp::Initialize()
389 UMAInitToolbox( 4 ) ;
390 SetEventMask( everyEvent
) ;
391 UMAShowWatchCursor() ;
393 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
394 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
, NewAEEventHandlerUPP(AEHandleODoc
) ,
395 (long) wxTheApp
, FALSE
) ;
396 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
, NewAEEventHandlerUPP(AEHandleOApp
) ,
397 (long) wxTheApp
, FALSE
) ;
398 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
, NewAEEventHandlerUPP(AEHandlePDoc
) ,
399 (long) wxTheApp
, FALSE
) ;
400 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
, NewAEEventHandlerUPP(AEHandleQuit
) ,
401 (long) wxTheApp
, FALSE
) ;
403 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
, NewAEEventHandlerProc(AEHandleODoc
) ,
404 (long) wxTheApp
, FALSE
) ;
405 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
, NewAEEventHandlerProc(AEHandleOApp
) ,
406 (long) wxTheApp
, FALSE
) ;
407 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
, NewAEEventHandlerProc(AEHandlePDoc
) ,
408 (long) wxTheApp
, FALSE
) ;
409 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
, NewAEEventHandlerProc(AEHandleQuit
) ,
410 (long) wxTheApp
, FALSE
) ;
415 // test the minimal configuration necessary
421 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
423 error
= kMacSTRWrongMachine
;
425 else if (theMachine
< gestaltMacPlus
)
427 error
= kMacSTRWrongMachine
;
429 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
431 error
= kMacSTROldSystem
;
433 else if ( theSystem
< 0x0750 )
435 error
= kMacSTROldSystem
;
437 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
439 error
= kMacSTRSmallSize
;
445 if ( !UMAHasAppearance() )
447 error = kMacSTRNoPre8Yet ;
453 // if we encountered any problems so far, give the error code and exit immediately
460 GetIndString(message
, 128, error
);
461 UMAShowArrowCursor() ;
462 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
463 itemHit
= Alert(128, nil
);
468 #if __option(profile)
469 ProfilerInit( collectDetailed
, bestTimeBase
, 20000 , 40 ) ;
473 // now avoid exceptions thrown for new (bad_alloc)
476 std::__throws_bad_alloc
= FALSE
;
479 s_macCursorRgn
= ::NewRgn() ;
482 wxBuffer
= new char[1500];
484 wxBuffer
= new char[BUFSIZ
+ 512];
487 wxClassInfo::InitializeClasses();
490 // wxGetResource(wxT("wxWindows"), wxT("OsVersion"), &wxOsVersion);
494 wxPendingEventsLocker
= new wxCriticalSection
;
496 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
497 wxTheColourDatabase
->Initialize();
501 // flush the logged messages if any and install a 'safer' log target: the
502 // default one (wxLogGui) can't be used after the resources are freed just
503 // below and the user suppliedo ne might be even more unsafe (using any
504 // wxWindows GUI function is unsafe starting from now)
505 wxLog::DontCreateOnDemand();
507 // this will flush the old messages if any
508 delete wxLog::SetActiveTarget(new wxLogStderr
);
512 wxInitializeStockLists();
513 wxInitializeStockObjects();
515 #if wxUSE_WX_RESOURCES
516 wxInitializeResourceSystem();
519 wxBitmap::InitStandardHandlers();
521 wxModule::RegisterModules();
522 if (!wxModule::InitializeModules()) {
526 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
527 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
529 wxMacCreateNotifierTable() ;
531 UMAShowArrowCursor() ;
536 void wxApp::CleanUp()
539 // flush the logged messages if any and install a 'safer' log target: the
540 // default one (wxLogGui) can't be used after the resources are freed just
541 // below and the user suppliedo ne might be even more unsafe (using any
542 // wxWindows GUI function is unsafe starting from now)
543 wxLog::DontCreateOnDemand();
545 // this will flush the old messages if any
546 delete wxLog::SetActiveTarget(new wxLogStderr
);
549 // One last chance for pending objects to be cleaned up
550 wxTheApp
->DeletePendingObjects();
552 wxModule::CleanUpModules();
554 #if wxUSE_WX_RESOURCES
555 wxCleanUpResourceSystem();
558 wxDeleteStockObjects() ;
560 // Destroy all GDI lists, etc.
561 wxDeleteStockLists();
563 delete wxTheColourDatabase
;
564 wxTheColourDatabase
= NULL
;
566 wxBitmap::CleanUpHandlers();
571 wxMacDestroyNotifierTable() ;
572 if (wxWinMacWindowList
)
573 delete wxWinMacWindowList
;
575 delete wxPendingEvents
;
577 delete wxPendingEventsLocker
;
578 // If we don't do the following, we get an apparent memory leak.
579 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
582 wxClassInfo::CleanUpClasses();
585 #if __option(profile)
586 ProfilerDump( "\papp.prof" ) ;
594 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
595 // At this point we want to check if there are any memory
596 // blocks that aren't part of the wxDebugContext itself,
597 // as a special case. Then when dumping we need to ignore
598 // wxDebugContext, too.
599 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
601 wxLogDebug(wxT("There were memory leaks."));
602 wxDebugContext::Dump();
603 wxDebugContext::PrintStatistics();
605 // wxDebugContext::SetStream(NULL, NULL);
609 // do it as the very last thing because everything else can log messages
610 delete wxLog::SetActiveTarget(NULL
);
613 UMACleanupToolbox() ;
615 ::DisposeRgn(s_macCursorRgn
);
622 int wxEntry( int argc
, char *argv
[] , bool enterLoop
)
625 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
626 // This seems to be necessary since there are 'rogue'
627 // objects present at this point (perhaps global objects?)
628 // Setting a checkpoint will ignore them as far as the
629 // memory checking facility is concerned.
630 // Of course you may argue that memory allocated in globals should be
631 // checked, but this is a reasonable compromise.
632 wxDebugContext::SetCheckpoint();
635 if (!wxApp::Initialize()) {
638 // create the application object or ensure that one already exists
641 // The app may have declared a global application object, but we recommend
642 // the IMPLEMENT_APP macro is used instead, which sets an initializer
643 // function for delayed, dynamic app object construction.
644 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
645 wxT("No initializer - use IMPLEMENT_APP macro.") );
647 wxTheApp
= (wxApp
*) (*wxApp::GetInitializerFunction()) ();
650 wxCHECK_MSG( wxTheApp
, 0, wxT("You have to define an instance of wxApp!") );
653 argc
= 0 ; // currently we don't support files as parameters
656 wxTheApp
->argc
= argc
;
657 wxTheApp
->argv
= argv
;
659 // GUI-specific initialization, such as creating an app context.
660 wxTheApp
->OnInitGui();
662 // we could try to get the open apple events here to adjust argc and argv better
665 // Here frames insert themselves automatically
666 // into wxTopLevelWindows by getting created
671 if ( wxTheApp
->OnInit() )
675 retValue
= wxTheApp
->OnRun();
678 // We want to initialize, but not run or exit immediately.
681 //else: app initialization failed, so we skipped OnRun()
683 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
686 // Forcibly delete the window.
687 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
688 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
690 topWindow
->Close(TRUE
);
691 wxTheApp
->DeletePendingObjects();
696 wxTheApp
->SetTopWindow(NULL
);
707 // Static member initialization
708 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
715 m_wantDebugOutput
= TRUE
;
720 m_printMode
= wxPRINT_WINDOWS
;
721 m_exitOnFrameDelete
= TRUE
;
725 bool wxApp::Initialized()
733 int wxApp::MainLoop()
745 // Returns TRUE if more time is needed.
746 bool wxApp::ProcessIdle()
749 event
.SetEventObject(this);
752 return event
.MoreRequested();
755 void wxApp::ExitMainLoop()
760 // Is a message/event pending?
761 bool wxApp::Pending()
765 return EventAvail( everyEvent
, &event
) ;
768 // Dispatch a message.
769 void wxApp::Dispatch()
774 void wxApp::OnIdle(wxIdleEvent
& event
)
776 static bool s_inOnIdle
= FALSE
;
778 // Avoid recursion (via ProcessEvent default case)
785 // 'Garbage' collection of windows deleted with Close().
786 DeletePendingObjects();
788 // flush the logged messages if any
789 wxLog
*pLog
= wxLog::GetActiveTarget();
790 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
793 // Send OnIdle events to all windows
794 bool needMore
= SendIdleEvents();
797 event
.RequestMore(TRUE
);
799 // If they are pending events, we must process them: pending events are
800 // either events to the threads other than main or events posted with
801 // wxPostEvent() functions
802 wxMacProcessNotifierAndPendingEvents();
812 // Send idle event to all top-level windows
813 bool wxApp::SendIdleEvents()
815 bool needMore
= FALSE
;
816 wxNode
* node
= wxTopLevelWindows
.First();
819 wxWindow
* win
= (wxWindow
*) node
->Data();
820 if (SendIdleEvents(win
))
828 // Send idle event to window and all subwindows
829 bool wxApp::SendIdleEvents(wxWindow
* win
)
831 bool needMore
= FALSE
;
834 event
.SetEventObject(win
);
835 win
->ProcessEvent(event
);
837 if (event
.MoreRequested())
840 wxNode
* node
= win
->GetChildren().First();
843 wxWindow
* win
= (wxWindow
*) node
->Data();
844 if (SendIdleEvents(win
))
852 void wxApp::DeletePendingObjects()
854 wxNode
*node
= wxPendingDelete
.First();
857 wxObject
*obj
= (wxObject
*)node
->Data();
861 if (wxPendingDelete
.Member(obj
))
864 // Deleting one object may have deleted other pending
865 // objects, so start from beginning of list again.
866 node
= wxPendingDelete
.First();
871 wxApp::GetStdIcon(int which
) const
875 case wxICON_INFORMATION
:
876 return wxIcon("wxICON_INFO");
878 case wxICON_QUESTION
:
879 return wxIcon("wxICON_QUESTION");
881 case wxICON_EXCLAMATION
:
882 return wxIcon("wxICON_WARNING");
885 wxFAIL_MSG(wxT("requested non existent standard icon"));
886 // still fall through
889 return wxIcon("wxICON_ERROR");
895 wxLogError(_("Fatal error: exiting"));
901 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
904 GetTopWindow()->Close(TRUE
);
907 // Default behaviour: close the application with prompts. The
908 // user can veto the close, and therefore the end session.
909 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
913 if (!GetTopWindow()->Close(!event
.CanVeto()))
918 extern "C" void wxCYield() ;
924 // Yield to other processes
926 static bool gs_inYield
= FALSE
;
932 wxFAIL_MSG( wxT("wxYield called recursively" ) );
942 long sleepTime
= 1 ; //::GetCaretTime();
944 while ( !wxTheApp
->IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, wxApp::s_macCursorRgn
))
946 wxTheApp
->MacHandleOneEvent( &event
);
947 if ( event
.what
!= kHighLevelEvent
)
948 SetRectRgn( wxApp::s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
951 wxMacProcessNotifierAndPendingEvents() ;
958 // Yield to incoming messages; but fail silently if recursion is detected.
959 bool wxYieldIfNeeded()
967 // platform specifics
969 void wxApp::MacSuspend( bool convertClipboard
)
971 // we have to deactive the window manually
973 wxWindow
* window
= GetTopWindow() ;
975 window
->MacActivate( MacGetCurrentEvent() , false ) ;
977 s_lastMouseDown
= 0 ;
978 if( convertClipboard
)
980 MacConvertPrivateToPublicScrap() ;
983 UMAHideFloatingWindows() ;
986 void wxApp::MacResume( bool convertClipboard
)
988 s_lastMouseDown
= 0 ;
989 if( convertClipboard
)
991 MacConvertPublicToPrivateScrap() ;
994 UMAShowFloatingWindows() ;
997 void wxApp::MacConvertPrivateToPublicScrap()
1001 void wxApp::MacConvertPublicToPrivateScrap()
1005 void wxApp::MacDoOneEvent()
1009 long sleepTime
= 1 ; // GetCaretTime() / 4 ;
1011 if (WaitNextEvent(everyEvent
, &event
,sleepTime
, s_macCursorRgn
))
1013 MacHandleOneEvent( &event
);
1018 WindowPtr window
= UMAFrontWindow() ;
1020 UMAIdleControls( window
) ;
1022 wxTheApp
->ProcessIdle() ;
1024 if ( event
.what
!= kHighLevelEvent
)
1025 SetRectRgn( s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
1029 DeletePendingObjects() ;
1030 wxMacProcessNotifierAndPendingEvents() ;
1033 void wxApp::MacHandleOneEvent( EventRecord
*ev
)
1035 m_macCurrentEvent
= ev
;
1037 wxApp::sm_lastMessageTime
= ev
->when
;
1042 MacHandleMouseDownEvent( ev
) ;
1043 if ( ev
->modifiers
& controlKey
)
1044 s_lastMouseDown
= 2;
1046 s_lastMouseDown
= 1;
1049 if ( s_lastMouseDown
== 2 )
1051 ev
->modifiers
|= controlKey
;
1055 ev
->modifiers
&= ~controlKey
;
1057 MacHandleMouseUpEvent( ev
) ;
1058 s_lastMouseDown
= 0;
1061 MacHandleActivateEvent( ev
) ;
1064 MacHandleUpdateEvent( ev
) ;
1068 MacHandleKeyDownEvent( ev
) ;
1071 MacHandleKeyUpEvent( ev
) ;
1074 MacHandleDiskEvent( ev
) ;
1077 MacHandleOSEvent( ev
) ;
1079 case kHighLevelEvent
:
1080 MacHandleHighLevelEvent( ev
) ;
1085 wxMacProcessNotifierAndPendingEvents() ;
1088 void wxApp::MacHandleHighLevelEvent( EventRecord
*ev
)
1090 ::AEProcessAppleEvent( ev
) ;
1093 bool s_macIsInModalLoop
= false ;
1095 void wxApp::MacHandleMouseDownEvent( EventRecord
*ev
)
1097 wxToolTip::RemoveToolTips() ;
1100 WindowRef frontWindow
= UMAFrontNonFloatingWindow() ;
1101 WindowAttributes frontWindowAttributes
= NULL
;
1103 UMAGetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
1105 short windowPart
= ::FindWindow(ev
->where
, &window
);
1106 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1107 if ( wxPendingDelete
.Member(win
) )
1111 GetQDGlobalsScreenBits( &screenBits
);
1116 if ( s_macIsInModalLoop
)
1122 UInt32 menuresult
= MenuSelect(ev
->where
) ;
1123 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1124 s_lastMouseDown
= 0;
1129 SystemClick( ev
, window
) ;
1130 s_lastMouseDown
= 0;
1134 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1140 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1145 Point pt
= { 0, 0 } ;
1147 SetPort( GetWindowPort(window
) ) ;
1149 SetPort( (window
) ) ;
1151 SetOrigin( 0 , 0 ) ;
1152 LocalToGlobal( &pt
) ;
1154 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1155 -1 , wxSIZE_USE_EXISTING
);
1157 s_lastMouseDown
= 0;
1161 if (TrackGoAway(window
, ev
->where
))
1166 s_lastMouseDown
= 0;
1170 int growResult
= GrowWindow(window
, ev
->where
, &screenBits
.bounds
);
1171 if (growResult
!= 0)
1173 int newWidth
= LoWord(growResult
);
1174 int newHeight
= HiWord(growResult
);
1175 int oldWidth
, oldHeight
;
1180 win
->GetSize(&oldWidth
, &oldHeight
);
1182 newWidth
= oldWidth
;
1184 newHeight
= oldHeight
;
1185 win
->SetSize( -1, -1, newWidth
, newHeight
, wxSIZE_USE_EXISTING
);
1188 s_lastMouseDown
= 0;
1193 if (TrackBox(window
, ev
->where
, windowPart
))
1195 // TODO setup size event
1196 ZoomWindow( window
, windowPart
, false ) ;
1201 GetWindowPortBounds(window
, &tempRect
) ;
1202 win
->SetSize( -1, -1, tempRect
.right
-tempRect
.left
,
1203 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1206 s_lastMouseDown
= 0;
1208 case inCollapseBox
:
1209 // TODO setup size event
1210 s_lastMouseDown
= 0;
1218 SetPort( GetWindowPort(window
) ) ;
1220 SetPort( (window
) ) ;
1222 SetOrigin( 0 , 0 ) ;
1225 if ( window
!= frontWindow
&& wxTheApp
->s_captureWindow
== NULL
)
1227 if ( s_macIsInModalLoop
)
1231 else if ( UMAIsWindowFloating( window
) )
1234 win
->MacMouseDown( ev
, windowPart
) ;
1239 win
->MacMouseDown( ev
, windowPart
) ;
1240 UMASelectWindow( window
) ;
1246 win
->MacMouseDown( ev
, windowPart
) ;
1255 void wxApp::MacHandleMouseUpEvent( EventRecord
*ev
)
1259 short windowPart
= ::FindWindow(ev
->where
, &window
);
1269 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1271 win
->MacMouseUp( ev
, windowPart
) ;
1277 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1286 retval
= WXK_RETURN
;
1301 retval
= WXK_PAGEUP
;
1304 retval
= WXK_PAGEDOWN
;
1307 retval
= WXK_RETURN
;
1362 retval
= WXK_ESCAPE
;
1368 retval
= WXK_RIGHT
;
1377 retval
= WXK_DELETE
;
1385 void wxApp::MacHandleKeyDownEvent( EventRecord
*ev
)
1387 wxToolTip::RemoveToolTips() ;
1389 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1390 if ( HiWord( menuresult
) )
1392 if ( !s_macIsInModalLoop
)
1393 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1399 keychar
= short(ev
->message
& charCodeMask
);
1400 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1402 wxWindow
* focus
= wxWindow::FindFocus() ;
1405 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1407 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1408 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1409 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1410 event
.m_altDown
= ev
->modifiers
& optionKey
;
1411 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1412 event
.m_keyCode
= keyval
;
1413 event
.m_x
= ev
->where
.h
;
1414 event
.m_y
= ev
->where
.v
;
1415 event
.m_timeStamp
= ev
->when
;
1416 event
.SetEventObject(focus
);
1417 bool handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1423 wxWindow
*ancestor
= focus
;
1427 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1430 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1431 handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
1434 if (ancestor->m_isFrame)
1436 ancestor = ancestor->GetParent();
1440 #endif // wxUSE_ACCEL
1444 wxKeyEvent
event(wxEVT_CHAR
);
1445 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1446 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1447 event
.m_altDown
= ev
->modifiers
& optionKey
;
1448 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1449 event
.m_keyCode
= keyval
;
1450 event
.m_x
= ev
->where
.h
;
1451 event
.m_y
= ev
->where
.v
;
1452 event
.m_timeStamp
= ev
->when
;
1453 event
.SetEventObject(focus
);
1454 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1457 (keyval
== WXK_TAB
) &&
1458 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1459 (focus
->GetParent()) &&
1460 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1462 wxNavigationKeyEvent new_event
;
1463 new_event
.SetEventObject( focus
);
1464 new_event
.SetDirection( !event
.ShiftDown() );
1465 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1466 new_event
.SetWindowChange( event
.ControlDown() );
1467 new_event
.SetCurrentFocus( focus
);
1468 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1470 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1472 (keyval
== '.' && event
.ControlDown() ) )
1474 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1475 new_event
.SetEventObject( focus
);
1476 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1482 void wxApp::MacHandleKeyUpEvent( EventRecord
*ev
)
1484 wxToolTip::RemoveToolTips() ;
1486 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1487 if ( HiWord( menuresult
) )
1494 keychar
= short(ev
->message
& charCodeMask
);
1495 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1497 wxWindow
* focus
= wxWindow::FindFocus() ;
1500 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1502 wxKeyEvent
event(wxEVT_KEY_UP
);
1503 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1504 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1505 event
.m_altDown
= ev
->modifiers
& optionKey
;
1506 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1507 event
.m_keyCode
= keyval
;
1508 event
.m_x
= ev
->where
.h
;
1509 event
.m_y
= ev
->where
.v
;
1510 event
.m_timeStamp
= ev
->when
;
1511 event
.SetEventObject(focus
);
1512 bool handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1517 void wxApp::MacHandleActivateEvent( EventRecord
*ev
)
1519 WindowRef window
= (WindowRef
) ev
->message
;
1522 bool activate
= (ev
->modifiers
& activeFlag
) ;
1523 WindowClass wclass
;
1524 UMAGetWindowClass ( window
, &wclass
) ;
1525 if ( wclass
== kFloatingWindowClass
)
1527 // if it is a floater we activate/deactivate the front non-floating window instead
1528 window
= UMAFrontNonFloatingWindow() ;
1530 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1532 win
->MacActivate( ev
, activate
) ;
1536 void wxApp::MacHandleUpdateEvent( EventRecord
*ev
)
1538 WindowRef window
= (WindowRef
) ev
->message
;
1539 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1542 if ( !wxPendingDelete
.Member(win
) )
1543 win
->MacUpdate( ev
) ;
1547 // since there is no way of telling this foreign window to update itself
1548 // we have to invalidate the update region otherwise we keep getting the same
1549 // event over and over again
1550 BeginUpdate( window
) ;
1551 EndUpdate( window
) ;
1555 void wxApp::MacHandleDiskEvent( EventRecord
*ev
)
1557 if ( HiWord( ev
->message
) != noErr
)
1562 SetPt( &point
, 100 , 100 ) ;
1564 err
= DIBadMount( point
, ev
->message
) ;
1565 wxASSERT( err
== noErr
) ;
1570 void wxApp::MacHandleOSEvent( EventRecord
*ev
)
1572 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
1574 case suspendResumeMessage
:
1576 bool isResuming
= ev
->message
& resumeFlag
;
1578 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
1580 bool convertClipboard
= false;
1582 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
1585 WindowRef oldFrontWindow
= NULL
;
1586 WindowRef newFrontWindow
= NULL
;
1588 // in case we don't take care of activating ourselves, we have to synchronize
1589 // our idea of the active window with the process manager's - which it already activated
1591 if ( !doesActivate
)
1592 oldFrontWindow
= UMAFrontNonFloatingWindow() ;
1594 MacResume( convertClipboard
) ;
1596 newFrontWindow
= UMAFrontNonFloatingWindow() ;
1598 if ( oldFrontWindow
)
1600 wxWindow
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
1602 win
->MacActivate( ev
, false ) ;
1604 if ( newFrontWindow
)
1606 wxWindow
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
1608 win
->MacActivate( ev
, true ) ;
1613 MacSuspend( convertClipboard
) ;
1615 // in case this suspending did close an active window, another one might
1616 // have surfaced -> lets deactivate that one
1618 WindowRef newActiveWindow
= UMAGetActiveNonFloatingWindow() ;
1619 if ( newActiveWindow
)
1621 wxWindow
* win
= wxFindWinFromMacWindow( newActiveWindow
) ;
1623 win
->MacActivate( ev
, false ) ;
1628 case mouseMovedMessage
:
1632 wxWindow
* currentMouseWindow
= NULL
;
1634 wxWindow::MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) ,
1635 ¤tMouseWindow
) ;
1637 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
1639 wxMouseEvent event
;
1641 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1642 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1644 event
.m_leftDown
= isDown
&& !controlDown
;
1645 event
.m_middleDown
= FALSE
;
1646 event
.m_rightDown
= isDown
&& controlDown
;
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_x
= ev
->where
.h
;
1652 event
.m_y
= ev
->where
.v
;
1653 event
.m_timeStamp
= ev
->when
;
1654 event
.SetEventObject(this);
1656 if ( wxWindow::s_lastMouseWindow
)
1658 wxMouseEvent
eventleave(event
) ;
1659 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
) ;
1660 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
1662 if ( currentMouseWindow
)
1664 wxMouseEvent
evententer(event
) ;
1665 evententer
.SetEventType( wxEVT_ENTER_WINDOW
) ;
1666 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
1668 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
1671 short windowPart
= ::FindWindow(ev
->where
, &window
);
1675 // fixes for setting the cursor back from dominic mazzoni
1677 UMAShowArrowCursor();
1680 UMAShowArrowCursor();
1684 if ( s_lastMouseDown
== 0 )
1685 ev
->modifiers
|= btnState
;
1687 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1689 win
->MacMouseMoved( ev
, windowPart
) ;
1691 UMAShowArrowCursor();
1702 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
1705 return; // no menu item selected
1707 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
1710 Str255 deskAccessoryName
;
1713 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
1714 GetPort(&savedPort
);
1715 OpenDeskAcc(deskAccessoryName
);
1721 wxWindow
* frontwindow
= wxFindWinFromMacWindow( ::FrontWindow() ) ;
1722 if ( frontwindow
&& wxMenuBar::MacGetInstalledMenuBar() )
1723 wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow
->GetEventHandler() , 0 , macMenuId
, macMenuItemNum
) ;
1729 long wxApp::MacTranslateKey(char key, int mods)
1733 void wxApp::MacAdjustCursor()
1740 wxApp::macAdjustCursor()
1742 if (ev->what != kHighLevelEvent)
1744 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1747 if (!theMacWxFrame->MacAdjustCursor(ev->where))
1748 ::SetCursor(&(qd.arrow));