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;
94 bool wxApp::s_macDefaultEncodingIsPC
= true ;
95 bool wxApp::s_macSupportPCMenuShortcuts
= true ;
96 long wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
97 wxString
wxApp::s_macHelpMenuTitleName
= "&Help" ;
99 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
100 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
102 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
105 wxApp
* app
= (wxApp
*) refcon
;
106 return wxTheApp
->MacHandleAEODoc( (AppleEvent
*) event
, reply
) ;
109 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
110 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
112 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
115 wxApp
* app
= (wxApp
*) refcon
;
116 return wxTheApp
->MacHandleAEOApp( (AppleEvent
*) event
, reply
) ;
119 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
120 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
122 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
125 wxApp
* app
= (wxApp
*) refcon
;
126 return wxTheApp
->MacHandleAEPDoc( (AppleEvent
*) event
, reply
) ;
129 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
130 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
132 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
135 wxApp
* app
= (wxApp
*) refcon
;
136 return wxTheApp
->MacHandleAEQuit( (AppleEvent
*) event
, reply
) ;
139 OSErr
wxApp::MacHandleAEODoc(const AppleEvent
*event
, AppleEvent
*reply
)
141 ProcessSerialNumber PSN
;
142 PSN
.highLongOfPSN
= 0 ;
143 PSN
.lowLongOfPSN
= kCurrentProcess
;
144 SetFrontProcess( &PSN
) ;
148 OSErr
wxApp::MacHandleAEPDoc(const AppleEvent
*event
, AppleEvent
*reply
)
153 OSErr
wxApp::MacHandleAEOApp(const AppleEvent
*event
, AppleEvent
*reply
)
158 OSErr
wxApp::MacHandleAEQuit(const AppleEvent
*event
, AppleEvent
*reply
)
160 wxWindow
* win
= GetTopWindow() ;
172 char StringMac
[] = "\x0d\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
173 "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
174 "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf"
175 "\xb1\xb4\xb5\xb6\xbb\xbc\xbe\xbf"
176 "\xc0\xc1\xc2\xc4\xc7\xc8\xc9\xcb\xcc\xcd\xce\xcf"
177 "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xca\xdb" ;
179 char StringANSI
[] = "\x0a\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8"
180 "\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC"
181 "\x86\xBA\xA2\xA3\xA7\x95\xB6\xDF\xAE\xA9\x99\xB4\xA8\xC6\xD8"
182 "\xB1\xA5\xB5\xF0\xAA\xBA\xE6\xF8"
183 "\xBF\xA1\xAC\x83\xAB\xBB\x85\xC0\xC3\xD5\x8C\x9C"
184 "\x96\x97\x93\x94\x91\x92\xF7\xFF\xA0\x80" ;
186 void wxMacConvertFromPC( const char *from
, char *to
, int len
)
191 for( int i
= 0 ; i
< len
; ++ i
)
193 c
= strchr( StringANSI
, *from
) ;
196 *to
= StringMac
[ c
- StringANSI
] ;
204 for( int i
= 0 ; i
< len
; ++ i
)
206 c
= strchr( StringANSI
, *from
) ;
209 *to
= StringMac
[ c
- StringANSI
] ;
221 void wxMacConvertToPC( const char *from
, char *to
, int len
)
226 for( int i
= 0 ; i
< len
; ++ i
)
228 c
= strchr( StringMac
, *from
) ;
231 *to
= StringANSI
[ c
- StringMac
] ;
239 for( int i
= 0 ; i
< len
; ++ i
)
241 c
= strchr( StringMac
, *from
) ;
244 *to
= StringANSI
[ c
- StringMac
] ;
256 void wxMacConvertFromPC( char * p
)
259 int len
= strlen ( p
) ;
261 wxMacConvertFromPC( ptr
, ptr
, len
) ;
264 void wxMacConvertFromPCForControls( char * p
)
267 int len
= strlen ( p
) ;
269 wxMacConvertFromPC( ptr
, ptr
, len
) ;
270 for ( int i
= 0 ; i
< strlen ( ptr
) ; i
++ )
272 if ( ptr
[i
] == '&' && ptr
[i
]+1 != ' ' )
274 memmove( &ptr
[i
] , &ptr
[i
+1] , strlen( &ptr
[i
+1] ) + 1) ;
279 void wxMacConvertFromPC( unsigned char *p
)
281 char *ptr
= (char*) p
+ 1 ;
284 wxMacConvertFromPC( ptr
, ptr
, len
) ;
287 extern char *wxBuffer
;
289 wxString
wxMacMakeMacStringFromPC( const char * p
)
291 const char *ptr
= p
;
292 int len
= strlen ( p
) ;
293 char *buf
= wxBuffer
;
295 if ( len
>= BUFSIZ
+ 512 )
297 buf
= new char [len
+1] ;
300 wxMacConvertFromPC( ptr
, buf
, len
) ;
302 wxString
result( buf
) ;
303 if ( buf
!= wxBuffer
)
309 void wxMacConvertToPC( char * p
)
312 int len
= strlen ( p
) ;
314 wxMacConvertToPC( ptr
, ptr
, len
) ;
317 void wxMacConvertToPC( unsigned char *p
)
319 char *ptr
= (char*) p
+ 1 ;
322 wxMacConvertToPC( ptr
, ptr
, len
) ;
325 wxString
wxMacMakePCStringFromMac( const char * p
)
327 const char *ptr
= p
;
328 int len
= strlen ( p
) ;
329 char *buf
= wxBuffer
;
331 if ( len
>= BUFSIZ
+ 512 )
333 buf
= new char [len
+1] ;
336 wxMacConvertToPC( ptr
, buf
, len
) ;
339 wxString
result( buf
) ;
340 if ( buf
!= wxBuffer
)
347 bool wxApp::Initialize()
353 UMAInitToolbox( 4 ) ;
354 SetEventMask( everyEvent
) ;
355 UMAShowWatchCursor() ;
357 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
358 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
, NewAEEventHandlerUPP(AEHandleODoc
) ,
359 (long) wxTheApp
, FALSE
) ;
360 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
, NewAEEventHandlerUPP(AEHandleOApp
) ,
361 (long) wxTheApp
, FALSE
) ;
362 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
, NewAEEventHandlerUPP(AEHandlePDoc
) ,
363 (long) wxTheApp
, FALSE
) ;
364 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
, NewAEEventHandlerUPP(AEHandleQuit
) ,
365 (long) wxTheApp
, FALSE
) ;
367 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
, NewAEEventHandlerProc(AEHandleODoc
) ,
368 (long) wxTheApp
, FALSE
) ;
369 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
, NewAEEventHandlerProc(AEHandleOApp
) ,
370 (long) wxTheApp
, FALSE
) ;
371 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
, NewAEEventHandlerProc(AEHandlePDoc
) ,
372 (long) wxTheApp
, FALSE
) ;
373 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
, NewAEEventHandlerProc(AEHandleQuit
) ,
374 (long) wxTheApp
, FALSE
) ;
379 // test the minimal configuration necessary
385 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
387 error
= kMacSTRWrongMachine
;
389 else if (theMachine
< gestaltMacPlus
)
391 error
= kMacSTRWrongMachine
;
393 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
395 error
= kMacSTROldSystem
;
397 else if ( theSystem
< 0x0750 )
399 error
= kMacSTROldSystem
;
401 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
403 error
= kMacSTRSmallSize
;
409 if ( !UMAHasAppearance() )
411 error = kMacSTRNoPre8Yet ;
417 // if we encountered any problems so far, give the error code and exit immediately
424 GetIndString(message
, 128, error
);
425 UMAShowArrowCursor() ;
426 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
427 itemHit
= Alert(128, nil
);
432 #if __option(profile)
433 ProfilerInit( collectDetailed
, bestTimeBase
, 20000 , 40 ) ;
437 // now avoid exceptions thrown for new (bad_alloc)
440 std::__throws_bad_alloc
= FALSE
;
443 s_macCursorRgn
= ::NewRgn() ;
446 wxBuffer
= new char[1500];
448 wxBuffer
= new char[BUFSIZ
+ 512];
451 wxClassInfo::InitializeClasses();
454 // wxGetResource(wxT("wxWindows"), wxT("OsVersion"), &wxOsVersion);
458 wxPendingEventsLocker
= new wxCriticalSection
;
460 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
461 wxTheColourDatabase
->Initialize();
465 // flush the logged messages if any and install a 'safer' log target: the
466 // default one (wxLogGui) can't be used after the resources are freed just
467 // below and the user suppliedo ne might be even more unsafe (using any
468 // wxWindows GUI function is unsafe starting from now)
469 wxLog::DontCreateOnDemand();
471 // this will flush the old messages if any
472 delete wxLog::SetActiveTarget(new wxLogStderr
);
476 wxInitializeStockLists();
477 wxInitializeStockObjects();
479 #if wxUSE_WX_RESOURCES
480 wxInitializeResourceSystem();
483 wxBitmap::InitStandardHandlers();
485 wxModule::RegisterModules();
486 if (!wxModule::InitializeModules()) {
490 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
491 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
493 wxMacCreateNotifierTable() ;
495 UMAShowArrowCursor() ;
500 void wxApp::CleanUp()
503 // flush the logged messages if any and install a 'safer' log target: the
504 // default one (wxLogGui) can't be used after the resources are freed just
505 // below and the user suppliedo ne might be even more unsafe (using any
506 // wxWindows GUI function is unsafe starting from now)
507 wxLog::DontCreateOnDemand();
509 // this will flush the old messages if any
510 delete wxLog::SetActiveTarget(new wxLogStderr
);
513 // One last chance for pending objects to be cleaned up
514 wxTheApp
->DeletePendingObjects();
516 wxModule::CleanUpModules();
518 #if wxUSE_WX_RESOURCES
519 wxCleanUpResourceSystem();
522 wxDeleteStockObjects() ;
524 // Destroy all GDI lists, etc.
525 wxDeleteStockLists();
527 delete wxTheColourDatabase
;
528 wxTheColourDatabase
= NULL
;
530 wxBitmap::CleanUpHandlers();
535 wxMacDestroyNotifierTable() ;
536 if (wxWinMacWindowList
)
537 delete wxWinMacWindowList
;
539 delete wxPendingEvents
;
541 delete wxPendingEventsLocker
;
542 // If we don't do the following, we get an apparent memory leak.
543 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
546 wxClassInfo::CleanUpClasses();
549 #if __option(profile)
550 ProfilerDump( "\papp.prof" ) ;
558 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
559 // At this point we want to check if there are any memory
560 // blocks that aren't part of the wxDebugContext itself,
561 // as a special case. Then when dumping we need to ignore
562 // wxDebugContext, too.
563 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
565 wxLogDebug(wxT("There were memory leaks."));
566 wxDebugContext::Dump();
567 wxDebugContext::PrintStatistics();
569 // wxDebugContext::SetStream(NULL, NULL);
573 // do it as the very last thing because everything else can log messages
574 delete wxLog::SetActiveTarget(NULL
);
577 UMACleanupToolbox() ;
579 ::DisposeRgn(s_macCursorRgn
);
586 int wxEntry( int argc
, char *argv
[] , bool enterLoop
)
589 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
590 // This seems to be necessary since there are 'rogue'
591 // objects present at this point (perhaps global objects?)
592 // Setting a checkpoint will ignore them as far as the
593 // memory checking facility is concerned.
594 // Of course you may argue that memory allocated in globals should be
595 // checked, but this is a reasonable compromise.
596 wxDebugContext::SetCheckpoint();
599 if (!wxApp::Initialize()) {
602 // create the application object or ensure that one already exists
605 // The app may have declared a global application object, but we recommend
606 // the IMPLEMENT_APP macro is used instead, which sets an initializer
607 // function for delayed, dynamic app object construction.
608 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
609 wxT("No initializer - use IMPLEMENT_APP macro.") );
611 wxTheApp
= (wxApp
*) (*wxApp::GetInitializerFunction()) ();
614 wxCHECK_MSG( wxTheApp
, 0, wxT("You have to define an instance of wxApp!") );
617 argc
= 0 ; // currently we don't support files as parameters
620 wxTheApp
->argc
= argc
;
621 wxTheApp
->argv
= argv
;
623 // GUI-specific initialization, such as creating an app context.
624 wxTheApp
->OnInitGui();
626 // we could try to get the open apple events here to adjust argc and argv better
629 // Here frames insert themselves automatically
630 // into wxTopLevelWindows by getting created
635 if ( wxTheApp
->OnInit() )
639 retValue
= wxTheApp
->OnRun();
642 // We want to initialize, but not run or exit immediately.
645 //else: app initialization failed, so we skipped OnRun()
647 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
650 // Forcibly delete the window.
651 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
652 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
654 topWindow
->Close(TRUE
);
655 wxTheApp
->DeletePendingObjects();
660 wxTheApp
->SetTopWindow(NULL
);
671 // Static member initialization
672 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
679 m_wantDebugOutput
= TRUE
;
684 m_printMode
= wxPRINT_WINDOWS
;
685 m_exitOnFrameDelete
= TRUE
;
689 bool wxApp::Initialized()
697 int wxApp::MainLoop()
709 // Returns TRUE if more time is needed.
710 bool wxApp::ProcessIdle()
713 event
.SetEventObject(this);
716 return event
.MoreRequested();
719 void wxApp::ExitMainLoop()
724 // Is a message/event pending?
725 bool wxApp::Pending()
729 return EventAvail( everyEvent
, &event
) ;
732 // Dispatch a message.
733 void wxApp::Dispatch()
738 void wxApp::OnIdle(wxIdleEvent
& event
)
740 static bool s_inOnIdle
= FALSE
;
742 // Avoid recursion (via ProcessEvent default case)
749 // 'Garbage' collection of windows deleted with Close().
750 DeletePendingObjects();
752 // flush the logged messages if any
753 wxLog
*pLog
= wxLog::GetActiveTarget();
754 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
757 // Send OnIdle events to all windows
758 bool needMore
= SendIdleEvents();
761 event
.RequestMore(TRUE
);
763 // If they are pending events, we must process them: pending events are
764 // either events to the threads other than main or events posted with
765 // wxPostEvent() functions
766 wxMacProcessNotifierAndPendingEvents();
776 // Send idle event to all top-level windows
777 bool wxApp::SendIdleEvents()
779 bool needMore
= FALSE
;
780 wxNode
* node
= wxTopLevelWindows
.First();
783 wxWindow
* win
= (wxWindow
*) node
->Data();
784 if (SendIdleEvents(win
))
792 // Send idle event to window and all subwindows
793 bool wxApp::SendIdleEvents(wxWindow
* win
)
795 bool needMore
= FALSE
;
798 event
.SetEventObject(win
);
799 win
->ProcessEvent(event
);
801 if (event
.MoreRequested())
804 wxNode
* node
= win
->GetChildren().First();
807 wxWindow
* win
= (wxWindow
*) node
->Data();
808 if (SendIdleEvents(win
))
816 void wxApp::DeletePendingObjects()
818 wxNode
*node
= wxPendingDelete
.First();
821 wxObject
*obj
= (wxObject
*)node
->Data();
825 if (wxPendingDelete
.Member(obj
))
828 // Deleting one object may have deleted other pending
829 // objects, so start from beginning of list again.
830 node
= wxPendingDelete
.First();
835 wxApp::GetStdIcon(int which
) const
839 case wxICON_INFORMATION
:
840 return wxIcon("wxICON_INFO");
842 case wxICON_QUESTION
:
843 return wxIcon("wxICON_QUESTION");
845 case wxICON_EXCLAMATION
:
846 return wxIcon("wxICON_WARNING");
849 wxFAIL_MSG(wxT("requested non existent standard icon"));
850 // still fall through
853 return wxIcon("wxICON_ERROR");
859 wxLogError(_("Fatal error: exiting"));
865 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
868 GetTopWindow()->Close(TRUE
);
871 // Default behaviour: close the application with prompts. The
872 // user can veto the close, and therefore the end session.
873 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
877 if (!GetTopWindow()->Close(!event
.CanVeto()))
882 extern "C" void wxCYield() ;
888 // Yield to other processes
890 static bool gs_inYield
= FALSE
;
896 wxFAIL_MSG( wxT("wxYield called recursively" ) );
906 long sleepTime
= 1 ; //::GetCaretTime();
908 while ( !wxTheApp
->IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, wxApp::s_macCursorRgn
))
910 wxTheApp
->MacHandleOneEvent( &event
);
911 if ( event
.what
!= kHighLevelEvent
)
912 SetRectRgn( wxApp::s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
915 wxMacProcessNotifierAndPendingEvents() ;
922 // Yield to incoming messages; but fail silently if recursion is detected.
923 bool wxYieldIfNeeded()
931 // platform specifics
933 void wxApp::MacSuspend( bool convertClipboard
)
935 // we have to deactive the window manually
937 wxWindow
* window
= GetTopWindow() ;
939 window
->MacActivate( MacGetCurrentEvent() , false ) ;
941 s_lastMouseDown
= 0 ;
942 if( convertClipboard
)
944 MacConvertPrivateToPublicScrap() ;
947 UMAHideFloatingWindows() ;
950 void wxApp::MacResume( bool convertClipboard
)
952 s_lastMouseDown
= 0 ;
953 if( convertClipboard
)
955 MacConvertPublicToPrivateScrap() ;
958 UMAShowFloatingWindows() ;
961 void wxApp::MacConvertPrivateToPublicScrap()
965 void wxApp::MacConvertPublicToPrivateScrap()
969 void wxApp::MacDoOneEvent()
973 long sleepTime
= 1 ; // GetCaretTime() / 4 ;
975 if (WaitNextEvent(everyEvent
, &event
,sleepTime
, s_macCursorRgn
))
977 MacHandleOneEvent( &event
);
982 WindowPtr window
= UMAFrontWindow() ;
984 UMAIdleControls( window
) ;
986 wxTheApp
->ProcessIdle() ;
988 if ( event
.what
!= kHighLevelEvent
)
989 SetRectRgn( s_macCursorRgn
, event
.where
.h
, event
.where
.v
, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
993 DeletePendingObjects() ;
994 wxMacProcessNotifierAndPendingEvents() ;
997 void wxApp::MacHandleOneEvent( EventRecord
*ev
)
999 m_macCurrentEvent
= ev
;
1001 wxApp::sm_lastMessageTime
= ev
->when
;
1006 MacHandleMouseDownEvent( ev
) ;
1007 if ( ev
->modifiers
& controlKey
)
1008 s_lastMouseDown
= 2;
1010 s_lastMouseDown
= 1;
1013 if ( s_lastMouseDown
== 2 )
1015 ev
->modifiers
|= controlKey
;
1019 ev
->modifiers
&= ~controlKey
;
1021 MacHandleMouseUpEvent( ev
) ;
1022 s_lastMouseDown
= 0;
1025 MacHandleActivateEvent( ev
) ;
1028 MacHandleUpdateEvent( ev
) ;
1032 MacHandleKeyDownEvent( ev
) ;
1035 MacHandleKeyUpEvent( ev
) ;
1038 MacHandleDiskEvent( ev
) ;
1041 MacHandleOSEvent( ev
) ;
1043 case kHighLevelEvent
:
1044 MacHandleHighLevelEvent( ev
) ;
1049 wxMacProcessNotifierAndPendingEvents() ;
1052 void wxApp::MacHandleHighLevelEvent( EventRecord
*ev
)
1054 ::AEProcessAppleEvent( ev
) ;
1057 bool s_macIsInModalLoop
= false ;
1059 void wxApp::MacHandleMouseDownEvent( EventRecord
*ev
)
1061 wxToolTip::RemoveToolTips() ;
1064 WindowRef frontWindow
= UMAFrontNonFloatingWindow() ;
1065 WindowAttributes frontWindowAttributes
= NULL
;
1067 UMAGetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
1069 short windowPart
= ::FindWindow(ev
->where
, &window
);
1070 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1071 if ( wxPendingDelete
.Member(win
) )
1075 GetQDGlobalsScreenBits( &screenBits
);
1080 if ( s_macIsInModalLoop
)
1086 UInt32 menuresult
= MenuSelect(ev
->where
) ;
1087 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1088 s_lastMouseDown
= 0;
1093 SystemClick( ev
, window
) ;
1094 s_lastMouseDown
= 0;
1098 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1104 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1109 Point pt
= { 0, 0 } ;
1111 SetPort( GetWindowPort(window
) ) ;
1113 SetPort( (window
) ) ;
1115 SetOrigin( 0 , 0 ) ;
1116 LocalToGlobal( &pt
) ;
1118 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1119 -1 , wxSIZE_USE_EXISTING
);
1121 s_lastMouseDown
= 0;
1125 if (TrackGoAway(window
, ev
->where
))
1130 s_lastMouseDown
= 0;
1134 int growResult
= GrowWindow(window
, ev
->where
, &screenBits
.bounds
);
1135 if (growResult
!= 0)
1137 int newWidth
= LoWord(growResult
);
1138 int newHeight
= HiWord(growResult
);
1139 int oldWidth
, oldHeight
;
1144 win
->GetSize(&oldWidth
, &oldHeight
);
1146 newWidth
= oldWidth
;
1148 newHeight
= oldHeight
;
1149 win
->SetSize( -1, -1, newWidth
, newHeight
, wxSIZE_USE_EXISTING
);
1152 s_lastMouseDown
= 0;
1157 if (TrackBox(window
, ev
->where
, windowPart
))
1159 // TODO setup size event
1160 ZoomWindow( window
, windowPart
, false ) ;
1165 GetWindowPortBounds(window
, &tempRect
) ;
1166 win
->SetSize( -1, -1, tempRect
.right
-tempRect
.left
,
1167 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1170 s_lastMouseDown
= 0;
1172 case inCollapseBox
:
1173 // TODO setup size event
1174 s_lastMouseDown
= 0;
1182 SetPort( GetWindowPort(window
) ) ;
1184 SetPort( (window
) ) ;
1186 SetOrigin( 0 , 0 ) ;
1189 if ( window
!= frontWindow
&& wxTheApp
->s_captureWindow
== NULL
)
1191 if ( s_macIsInModalLoop
)
1195 else if ( UMAIsWindowFloating( window
) )
1198 win
->MacMouseDown( ev
, windowPart
) ;
1203 win
->MacMouseDown( ev
, windowPart
) ;
1204 UMASelectWindow( window
) ;
1210 win
->MacMouseDown( ev
, windowPart
) ;
1219 void wxApp::MacHandleMouseUpEvent( EventRecord
*ev
)
1223 short windowPart
= ::FindWindow(ev
->where
, &window
);
1233 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1235 win
->MacMouseUp( ev
, windowPart
) ;
1241 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1250 retval
= WXK_RETURN
;
1265 retval
= WXK_PAGEUP
;
1268 retval
= WXK_PAGEDOWN
;
1271 retval
= WXK_RETURN
;
1326 retval
= WXK_ESCAPE
;
1332 retval
= WXK_RIGHT
;
1341 retval
= WXK_DELETE
;
1349 void wxApp::MacHandleKeyDownEvent( EventRecord
*ev
)
1351 wxToolTip::RemoveToolTips() ;
1353 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1354 if ( HiWord( menuresult
) )
1356 if ( !s_macIsInModalLoop
)
1357 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1363 keychar
= short(ev
->message
& charCodeMask
);
1364 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1366 wxWindow
* focus
= wxWindow::FindFocus() ;
1369 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1371 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1372 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1373 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1374 event
.m_altDown
= ev
->modifiers
& optionKey
;
1375 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1376 event
.m_keyCode
= keyval
;
1377 event
.m_x
= ev
->where
.h
;
1378 event
.m_y
= ev
->where
.v
;
1379 event
.m_timeStamp
= ev
->when
;
1380 event
.SetEventObject(focus
);
1381 bool handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1387 wxWindow
*ancestor
= focus
;
1391 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1394 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1395 handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
1398 if (ancestor->m_isFrame)
1400 ancestor = ancestor->GetParent();
1404 #endif // wxUSE_ACCEL
1408 wxKeyEvent
event(wxEVT_CHAR
);
1409 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1410 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1411 event
.m_altDown
= ev
->modifiers
& optionKey
;
1412 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1413 event
.m_keyCode
= keyval
;
1414 event
.m_x
= ev
->where
.h
;
1415 event
.m_y
= ev
->where
.v
;
1416 event
.m_timeStamp
= ev
->when
;
1417 event
.SetEventObject(focus
);
1418 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1421 (keyval
== WXK_TAB
) &&
1422 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1423 (focus
->GetParent()) &&
1424 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1426 wxNavigationKeyEvent new_event
;
1427 new_event
.SetEventObject( focus
);
1428 new_event
.SetDirection( !event
.ShiftDown() );
1429 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1430 new_event
.SetWindowChange( event
.ControlDown() );
1431 new_event
.SetCurrentFocus( focus
);
1432 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1434 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1436 (keyval
== '.' && event
.ControlDown() ) )
1438 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1439 new_event
.SetEventObject( focus
);
1440 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1446 void wxApp::MacHandleKeyUpEvent( EventRecord
*ev
)
1448 wxToolTip::RemoveToolTips() ;
1450 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1451 if ( HiWord( menuresult
) )
1458 keychar
= short(ev
->message
& charCodeMask
);
1459 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1461 wxWindow
* focus
= wxWindow::FindFocus() ;
1464 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1466 wxKeyEvent
event(wxEVT_KEY_UP
);
1467 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1468 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1469 event
.m_altDown
= ev
->modifiers
& optionKey
;
1470 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1471 event
.m_keyCode
= keyval
;
1472 event
.m_x
= ev
->where
.h
;
1473 event
.m_y
= ev
->where
.v
;
1474 event
.m_timeStamp
= ev
->when
;
1475 event
.SetEventObject(focus
);
1476 bool handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1481 void wxApp::MacHandleActivateEvent( EventRecord
*ev
)
1483 WindowRef window
= (WindowRef
) ev
->message
;
1486 bool activate
= (ev
->modifiers
& activeFlag
) ;
1487 WindowClass wclass
;
1488 UMAGetWindowClass ( window
, &wclass
) ;
1489 if ( wclass
== kFloatingWindowClass
)
1491 // if it is a floater we activate/deactivate the front non-floating window instead
1492 window
= UMAFrontNonFloatingWindow() ;
1494 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1496 win
->MacActivate( ev
, activate
) ;
1500 void wxApp::MacHandleUpdateEvent( EventRecord
*ev
)
1502 WindowRef window
= (WindowRef
) ev
->message
;
1503 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1506 if ( !wxPendingDelete
.Member(win
) )
1507 win
->MacUpdate( ev
) ;
1511 // since there is no way of telling this foreign window to update itself
1512 // we have to invalidate the update region otherwise we keep getting the same
1513 // event over and over again
1514 BeginUpdate( window
) ;
1515 EndUpdate( window
) ;
1519 void wxApp::MacHandleDiskEvent( EventRecord
*ev
)
1521 if ( HiWord( ev
->message
) != noErr
)
1526 SetPt( &point
, 100 , 100 ) ;
1528 err
= DIBadMount( point
, ev
->message
) ;
1529 wxASSERT( err
== noErr
) ;
1534 void wxApp::MacHandleOSEvent( EventRecord
*ev
)
1536 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
1538 case suspendResumeMessage
:
1540 bool isResuming
= ev
->message
& resumeFlag
;
1542 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
1544 bool convertClipboard
= false;
1546 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
1549 WindowRef oldFrontWindow
= NULL
;
1550 WindowRef newFrontWindow
= NULL
;
1552 // in case we don't take care of activating ourselves, we have to synchronize
1553 // our idea of the active window with the process manager's - which it already activated
1555 if ( !doesActivate
)
1556 oldFrontWindow
= UMAFrontNonFloatingWindow() ;
1558 MacResume( convertClipboard
) ;
1560 newFrontWindow
= UMAFrontNonFloatingWindow() ;
1562 if ( oldFrontWindow
)
1564 wxWindow
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
1566 win
->MacActivate( ev
, false ) ;
1568 if ( newFrontWindow
)
1570 wxWindow
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
1572 win
->MacActivate( ev
, true ) ;
1577 MacSuspend( convertClipboard
) ;
1579 // in case this suspending did close an active window, another one might
1580 // have surfaced -> lets deactivate that one
1582 WindowRef newActiveWindow
= UMAGetActiveNonFloatingWindow() ;
1583 if ( newActiveWindow
)
1585 wxWindow
* win
= wxFindWinFromMacWindow( newActiveWindow
) ;
1587 win
->MacActivate( ev
, false ) ;
1592 case mouseMovedMessage
:
1596 wxWindow
* currentMouseWindow
= NULL
;
1598 wxWindow::MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) ,
1599 ¤tMouseWindow
) ;
1601 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
1603 wxMouseEvent event
;
1605 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1606 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1608 event
.m_leftDown
= isDown
&& !controlDown
;
1609 event
.m_middleDown
= FALSE
;
1610 event
.m_rightDown
= isDown
&& controlDown
;
1611 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1612 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1613 event
.m_altDown
= ev
->modifiers
& optionKey
;
1614 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1615 event
.m_x
= ev
->where
.h
;
1616 event
.m_y
= ev
->where
.v
;
1617 event
.m_timeStamp
= ev
->when
;
1618 event
.SetEventObject(this);
1620 if ( wxWindow::s_lastMouseWindow
)
1622 wxMouseEvent
eventleave(event
) ;
1623 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
) ;
1624 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
1626 if ( currentMouseWindow
)
1628 wxMouseEvent
evententer(event
) ;
1629 evententer
.SetEventType( wxEVT_ENTER_WINDOW
) ;
1630 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
1632 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
1635 short windowPart
= ::FindWindow(ev
->where
, &window
);
1639 // fixes for setting the cursor back from dominic mazzoni
1641 UMAShowArrowCursor();
1644 UMAShowArrowCursor();
1648 if ( s_lastMouseDown
== 0 )
1649 ev
->modifiers
|= btnState
;
1651 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1653 win
->MacMouseMoved( ev
, windowPart
) ;
1655 UMAShowArrowCursor();
1666 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
1669 return; // no menu item selected
1671 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
1674 Str255 deskAccessoryName
;
1677 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
1678 GetPort(&savedPort
);
1679 OpenDeskAcc(deskAccessoryName
);
1685 wxWindow
* frontwindow
= wxFindWinFromMacWindow( ::FrontWindow() ) ;
1686 if ( frontwindow
&& wxMenuBar::MacGetInstalledMenuBar() )
1687 wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow
->GetEventHandler() , 0 , macMenuId
, macMenuItemNum
) ;
1693 long wxApp::MacTranslateKey(char key, int mods)
1697 void wxApp::MacAdjustCursor()
1704 wxApp::macAdjustCursor()
1706 if (ev->what != kHighLevelEvent)
1708 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1711 if (!theMacWxFrame->MacAdjustCursor(ev->where))
1712 ::SetCursor(&(qd.arrow));