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"
35 #if wxUSE_WX_RESOURCES
36 #include "wx/resource.h"
51 #include "wx/mac/uma.h"
52 #include "wx/mac/macnotfy.h"
56 #include <CoreServices/CoreServices.h>
58 #include <OpenTransport.h>
59 #include <OpenTptInternet.h>
63 extern char *wxBuffer
;
64 extern wxList wxPendingDelete
;
65 extern wxList
*wxWinMacWindowList
;
66 extern wxList
*wxWinMacControlList
;
68 wxApp
*wxTheApp
= NULL
;
70 #if !USE_SHARED_LIBRARY
71 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
72 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
73 EVT_IDLE(wxApp::OnIdle
)
74 EVT_END_SESSION(wxApp::OnEndSession
)
75 EVT_QUERY_END_SESSION(wxApp::OnQueryEndSession
)
80 const short kMacMinHeap
= (29 * 1024) ;
81 // platform specific static variables
83 const short kwxMacMenuBarResource
= 1 ;
84 const short kwxMacAppleMenuId
= 1 ;
86 RgnHandle
wxApp::s_macCursorRgn
= NULL
;
87 wxWindow
* wxApp::s_captureWindow
= NULL
;
88 int wxApp::s_lastMouseDown
= 0 ;
89 long wxApp::sm_lastMessageTime
= 0;
93 bool wxApp::s_macDefaultEncodingIsPC
= true ;
94 bool wxApp::s_macSupportPCMenuShortcuts
= true ;
95 long wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
96 wxString
wxApp::s_macHelpMenuTitleName
= "&Help" ;
98 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
99 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
101 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
104 wxApp
* app
= (wxApp
*) refcon
;
105 return wxTheApp
->MacHandleAEODoc( (AppleEvent
*) event
, reply
) ;
108 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
109 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
111 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
114 wxApp
* app
= (wxApp
*) refcon
;
115 return wxTheApp
->MacHandleAEOApp( (AppleEvent
*) event
, reply
) ;
118 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
119 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
121 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
124 wxApp
* app
= (wxApp
*) refcon
;
125 return wxTheApp
->MacHandleAEPDoc( (AppleEvent
*) event
, reply
) ;
128 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
129 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
131 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
134 wxApp
* app
= (wxApp
*) refcon
;
135 return wxTheApp
->MacHandleAEQuit( (AppleEvent
*) event
, reply
) ;
138 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
)
346 bool wxApp::Initialize()
352 UMAInitToolbox( 4 ) ;
353 SetEventMask( everyEvent
) ;
354 UMAShowWatchCursor() ;
356 #if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340)
357 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
, NewAEEventHandlerUPP(AEHandleODoc
) ,
358 (long) wxTheApp
, FALSE
) ;
359 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
, NewAEEventHandlerUPP(AEHandleOApp
) ,
360 (long) wxTheApp
, FALSE
) ;
361 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
, NewAEEventHandlerUPP(AEHandlePDoc
) ,
362 (long) wxTheApp
, FALSE
) ;
363 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
, NewAEEventHandlerUPP(AEHandleQuit
) ,
364 (long) wxTheApp
, FALSE
) ;
366 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
, NewAEEventHandlerProc(AEHandleODoc
) ,
367 (long) wxTheApp
, FALSE
) ;
368 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
, NewAEEventHandlerProc(AEHandleOApp
) ,
369 (long) wxTheApp
, FALSE
) ;
370 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
, NewAEEventHandlerProc(AEHandlePDoc
) ,
371 (long) wxTheApp
, FALSE
) ;
372 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
, NewAEEventHandlerProc(AEHandleQuit
) ,
373 (long) wxTheApp
, FALSE
) ;
378 // test the minimal configuration necessary
384 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
386 error
= kMacSTRWrongMachine
;
388 else if (theMachine
< gestaltMacPlus
)
390 error
= kMacSTRWrongMachine
;
392 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
394 error
= kMacSTROldSystem
;
396 else if ( theSystem
< 0x0750 )
398 error
= kMacSTROldSystem
;
400 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
402 error
= kMacSTRSmallSize
;
408 if ( !UMAHasAppearance() )
410 error = kMacSTRNoPre8Yet ;
416 // if we encountered any problems so far, give the error code and exit immediately
423 GetIndString(message
, 128, error
);
424 UMAShowArrowCursor() ;
425 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
426 itemHit
= Alert(128, nil
);
431 #if __option(profile)
432 ProfilerInit( collectDetailed
, bestTimeBase
, 20000 , 40 ) ;
436 // now avoid exceptions thrown for new (bad_alloc)
439 std::__throws_bad_alloc
= FALSE
;
442 s_macCursorRgn
= ::NewRgn() ;
445 wxBuffer
= new char[1500];
447 wxBuffer
= new char[BUFSIZ
+ 512];
450 wxClassInfo::InitializeClasses();
453 // wxGetResource(wxT("wxWindows"), wxT("OsVersion"), &wxOsVersion);
457 wxPendingEventsLocker
= new wxCriticalSection
;
459 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
460 wxTheColourDatabase
->Initialize();
463 // flush the logged messages if any and install a 'safer' log target: the
464 // default one (wxLogGui) can't be used after the resources are freed just
465 // below and the user suppliedo ne might be even more unsafe (using any
466 // wxWindows GUI function is unsafe starting from now)
467 wxLog::DontCreateOnDemand();
469 // this will flush the old messages if any
470 delete wxLog::SetActiveTarget(new wxLogStderr
);
473 wxInitializeStockLists();
474 wxInitializeStockObjects();
476 #if wxUSE_WX_RESOURCES
477 wxInitializeResourceSystem();
480 wxBitmap::InitStandardHandlers();
482 wxModule::RegisterModules();
483 if (!wxModule::InitializeModules()) {
487 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
488 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
490 wxMacCreateNotifierTable() ;
492 UMAShowArrowCursor() ;
497 void wxApp::CleanUp()
500 // flush the logged messages if any and install a 'safer' log target: the
501 // default one (wxLogGui) can't be used after the resources are freed just
502 // below and the user suppliedo ne might be even more unsafe (using any
503 // wxWindows GUI function is unsafe starting from now)
504 wxLog::DontCreateOnDemand();
506 // this will flush the old messages if any
507 delete wxLog::SetActiveTarget(new wxLogStderr
);
510 // One last chance for pending objects to be cleaned up
511 wxTheApp
->DeletePendingObjects();
513 wxModule::CleanUpModules();
515 #if wxUSE_WX_RESOURCES
516 wxCleanUpResourceSystem();
519 wxDeleteStockObjects() ;
521 // Destroy all GDI lists, etc.
522 wxDeleteStockLists();
524 delete wxTheColourDatabase
;
525 wxTheColourDatabase
= NULL
;
527 wxBitmap::CleanUpHandlers();
532 wxMacDestroyNotifierTable() ;
533 if (wxWinMacWindowList
)
534 delete wxWinMacWindowList
;
536 delete wxPendingEvents
;
538 delete wxPendingEventsLocker
;
539 // If we don't do the following, we get an apparent memory leak.
540 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
543 wxClassInfo::CleanUpClasses();
546 #if __option(profile)
547 ProfilerDump( "\papp.prof" ) ;
555 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
556 // At this point we want to check if there are any memory
557 // blocks that aren't part of the wxDebugContext itself,
558 // as a special case. Then when dumping we need to ignore
559 // wxDebugContext, too.
560 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
562 wxLogDebug(wxT("There were memory leaks."));
563 wxDebugContext::Dump();
564 wxDebugContext::PrintStatistics();
566 // wxDebugContext::SetStream(NULL, NULL);
570 // do it as the very last thing because everything else can log messages
571 delete wxLog::SetActiveTarget(NULL
);
574 UMACleanupToolbox() ;
576 ::DisposeRgn(s_macCursorRgn
);
583 int wxEntry( int argc
, char *argv
[] , bool enterLoop
)
586 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
587 // This seems to be necessary since there are 'rogue'
588 // objects present at this point (perhaps global objects?)
589 // Setting a checkpoint will ignore them as far as the
590 // memory checking facility is concerned.
591 // Of course you may argue that memory allocated in globals should be
592 // checked, but this is a reasonable compromise.
593 wxDebugContext::SetCheckpoint();
596 if (!wxApp::Initialize()) {
599 // create the application object or ensure that one already exists
602 // The app may have declared a global application object, but we recommend
603 // the IMPLEMENT_APP macro is used instead, which sets an initializer
604 // function for delayed, dynamic app object construction.
605 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
606 wxT("No initializer - use IMPLEMENT_APP macro.") );
608 wxTheApp
= (wxApp
*) (*wxApp::GetInitializerFunction()) ();
611 wxCHECK_MSG( wxTheApp
, 0, wxT("You have to define an instance of wxApp!") );
614 argc
= 0 ; // currently we don't support files as parameters
617 wxTheApp
->argc
= argc
;
618 wxTheApp
->argv
= argv
;
620 // GUI-specific initialization, such as creating an app context.
621 wxTheApp
->OnInitGui();
623 // we could try to get the open apple events here to adjust argc and argv better
626 // Here frames insert themselves automatically
627 // into wxTopLevelWindows by getting created
632 if ( wxTheApp
->OnInit() )
636 retValue
= wxTheApp
->OnRun();
639 // We want to initialize, but not run or exit immediately.
642 //else: app initialization failed, so we skipped OnRun()
644 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
647 // Forcibly delete the window.
648 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
649 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
651 topWindow
->Close(TRUE
);
652 wxTheApp
->DeletePendingObjects();
657 wxTheApp
->SetTopWindow(NULL
);
668 // Static member initialization
669 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
676 m_wantDebugOutput
= TRUE
;
681 m_printMode
= wxPRINT_WINDOWS
;
682 m_exitOnFrameDelete
= TRUE
;
686 bool wxApp::Initialized()
694 int wxApp::MainLoop()
706 // Returns TRUE if more time is needed.
707 bool wxApp::ProcessIdle()
710 event
.SetEventObject(this);
713 return event
.MoreRequested();
716 void wxApp::ExitMainLoop()
721 // Is a message/event pending?
722 bool wxApp::Pending()
726 return EventAvail( everyEvent
, &event
) ;
729 // Dispatch a message.
730 void wxApp::Dispatch()
735 void wxApp::OnIdle(wxIdleEvent
& event
)
737 static bool s_inOnIdle
= FALSE
;
739 // Avoid recursion (via ProcessEvent default case)
746 // 'Garbage' collection of windows deleted with Close().
747 DeletePendingObjects();
749 // flush the logged messages if any
750 wxLog
*pLog
= wxLog::GetActiveTarget();
751 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
754 // Send OnIdle events to all windows
755 bool needMore
= SendIdleEvents();
758 event
.RequestMore(TRUE
);
760 // If they are pending events, we must process them: pending events are
761 // either events to the threads other than main or events posted with
762 // wxPostEvent() functions
763 wxMacProcessNotifierAndPendingEvents();
773 // Send idle event to all top-level windows
774 bool wxApp::SendIdleEvents()
776 bool needMore
= FALSE
;
777 wxNode
* node
= wxTopLevelWindows
.First();
780 wxWindow
* win
= (wxWindow
*) node
->Data();
781 if (SendIdleEvents(win
))
789 // Send idle event to window and all subwindows
790 bool wxApp::SendIdleEvents(wxWindow
* win
)
792 bool needMore
= FALSE
;
795 event
.SetEventObject(win
);
796 win
->ProcessEvent(event
);
798 if (event
.MoreRequested())
801 wxNode
* node
= win
->GetChildren().First();
804 wxWindow
* win
= (wxWindow
*) node
->Data();
805 if (SendIdleEvents(win
))
813 void wxApp::DeletePendingObjects()
815 wxNode
*node
= wxPendingDelete
.First();
818 wxObject
*obj
= (wxObject
*)node
->Data();
822 if (wxPendingDelete
.Member(obj
))
825 // Deleting one object may have deleted other pending
826 // objects, so start from beginning of list again.
827 node
= wxPendingDelete
.First();
832 wxApp::GetStdIcon(int which
) const
836 case wxICON_INFORMATION
:
837 return wxIcon("wxICON_INFO");
839 case wxICON_QUESTION
:
840 return wxIcon("wxICON_QUESTION");
842 case wxICON_EXCLAMATION
:
843 return wxIcon("wxICON_WARNING");
846 wxFAIL_MSG(wxT("requested non existent standard icon"));
847 // still fall through
850 return wxIcon("wxICON_ERROR");
856 wxLogError(_("Fatal error: exiting"));
862 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
865 GetTopWindow()->Close(TRUE
);
868 // Default behaviour: close the application with prompts. The
869 // user can veto the close, and therefore the end session.
870 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
874 if (!GetTopWindow()->Close(!event
.CanVeto()))
879 extern "C" void wxCYield() ;
885 // Yield to other processes
887 static bool gs_inYield
= FALSE
;
893 wxFAIL_MSG( wxT("wxYield called recursively" ) );
903 long sleepTime
= 0 ; //::GetCaretTime();
905 while ( !wxTheApp
->IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, wxApp::s_macCursorRgn
))
907 wxTheApp
->MacHandleOneEvent( &event
);
910 wxMacProcessNotifierAndPendingEvents() ;
917 // Yield to incoming messages; but fail silently if recursion is detected.
918 bool wxYieldIfNeeded()
926 // platform specifics
928 void wxApp::MacSuspend( bool convertClipboard
)
930 // we have to deactive the window manually
932 wxWindow
* window
= GetTopWindow() ;
934 window
->MacActivate( MacGetCurrentEvent() , false ) ;
936 s_lastMouseDown
= 0 ;
937 if( convertClipboard
)
939 MacConvertPrivateToPublicScrap() ;
942 UMAHideFloatingWindows() ;
945 void wxApp::MacResume( bool convertClipboard
)
947 s_lastMouseDown
= 0 ;
948 if( convertClipboard
)
950 MacConvertPublicToPrivateScrap() ;
953 UMAShowFloatingWindows() ;
956 void wxApp::MacConvertPrivateToPublicScrap()
960 void wxApp::MacConvertPublicToPrivateScrap()
964 void wxApp::MacDoOneEvent()
968 long sleepTime
= 1 ; // GetCaretTime() / 4 ;
970 if (WaitNextEvent(everyEvent
, &event
,sleepTime
, s_macCursorRgn
))
972 MacHandleOneEvent( &event
);
977 WindowPtr window
= UMAFrontWindow() ;
979 UMAIdleControls( window
) ;
981 wxTheApp
->ProcessIdle() ;
983 if ( event
.what
!= kHighLevelEvent
)
984 SetRectRgn( s_macCursorRgn
, event
.where
.h
- 1 , event
.where
.v
- 1, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
988 DeletePendingObjects() ;
989 wxMacProcessNotifierAndPendingEvents() ;
992 void wxApp::MacHandleOneEvent( EventRecord
*ev
)
994 m_macCurrentEvent
= ev
;
996 wxApp::sm_lastMessageTime
= ev
->when
;
1001 MacHandleMouseDownEvent( ev
) ;
1002 if ( ev
->modifiers
& controlKey
)
1003 s_lastMouseDown
= 2;
1005 s_lastMouseDown
= 1;
1008 if ( s_lastMouseDown
== 2 )
1010 ev
->modifiers
|= controlKey
;
1014 ev
->modifiers
&= ~controlKey
;
1016 MacHandleMouseUpEvent( ev
) ;
1017 s_lastMouseDown
= 0;
1020 MacHandleActivateEvent( ev
) ;
1023 MacHandleUpdateEvent( ev
) ;
1027 MacHandleKeyDownEvent( ev
) ;
1030 MacHandleKeyUpEvent( ev
) ;
1033 MacHandleDiskEvent( ev
) ;
1036 MacHandleOSEvent( ev
) ;
1038 case kHighLevelEvent
:
1039 MacHandleHighLevelEvent( ev
) ;
1044 wxMacProcessNotifierAndPendingEvents() ;
1047 void wxApp::MacHandleHighLevelEvent( EventRecord
*ev
)
1049 ::AEProcessAppleEvent( ev
) ;
1052 bool s_macIsInModalLoop
= false ;
1054 void wxApp::MacHandleMouseDownEvent( EventRecord
*ev
)
1056 wxToolTip::RemoveToolTips() ;
1059 WindowRef frontWindow
= UMAFrontNonFloatingWindow() ;
1060 WindowAttributes frontWindowAttributes
= NULL
;
1062 UMAGetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
1064 short windowPart
= ::FindWindow(ev
->where
, &window
);
1065 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1066 if ( wxPendingDelete
.Member(win
) )
1070 GetQDGlobalsScreenBits( &screenBits
);
1075 if ( s_macIsInModalLoop
)
1081 UInt32 menuresult
= MenuSelect(ev
->where
) ;
1082 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1083 s_lastMouseDown
= 0;
1088 SystemClick( ev
, window
) ;
1089 s_lastMouseDown
= 0;
1093 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1099 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1104 Point pt
= { 0, 0 } ;
1106 SetPort( GetWindowPort(window
) ) ;
1108 SetPort( (window
) ) ;
1110 SetOrigin( 0 , 0 ) ;
1111 LocalToGlobal( &pt
) ;
1113 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1114 -1 , wxSIZE_USE_EXISTING
);
1116 s_lastMouseDown
= 0;
1120 if (TrackGoAway(window
, ev
->where
))
1125 s_lastMouseDown
= 0;
1129 int growResult
= GrowWindow(window
, ev
->where
, &screenBits
.bounds
);
1130 if (growResult
!= 0)
1132 int newWidth
= LoWord(growResult
);
1133 int newHeight
= HiWord(growResult
);
1134 int oldWidth
, oldHeight
;
1139 win
->GetSize(&oldWidth
, &oldHeight
);
1141 newWidth
= oldWidth
;
1143 newHeight
= oldHeight
;
1144 win
->SetSize( -1, -1, newWidth
, newHeight
, wxSIZE_USE_EXISTING
);
1147 s_lastMouseDown
= 0;
1152 if (TrackBox(window
, ev
->where
, windowPart
))
1154 // TODO setup size event
1155 ZoomWindow( window
, windowPart
, false ) ;
1160 GetWindowPortBounds(window
, &tempRect
) ;
1161 win
->SetSize( -1, -1, tempRect
.right
-tempRect
.left
,
1162 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1165 s_lastMouseDown
= 0;
1167 case inCollapseBox
:
1168 // TODO setup size event
1169 s_lastMouseDown
= 0;
1177 SetPort( GetWindowPort(window
) ) ;
1179 SetPort( (window
) ) ;
1181 SetOrigin( 0 , 0 ) ;
1184 if ( window
!= frontWindow
&& wxTheApp
->s_captureWindow
== NULL
)
1186 if ( s_macIsInModalLoop
)
1190 else if ( UMAIsWindowFloating( window
) )
1193 win
->MacMouseDown( ev
, windowPart
) ;
1197 UMASelectWindow( window
) ;
1203 win
->MacMouseDown( ev
, windowPart
) ;
1212 void wxApp::MacHandleMouseUpEvent( EventRecord
*ev
)
1216 short windowPart
= ::FindWindow(ev
->where
, &window
);
1226 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1228 win
->MacMouseUp( ev
, windowPart
) ;
1234 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1243 retval
= WXK_RETURN
;
1258 retval
= WXK_PAGEUP
;
1261 retval
= WXK_PAGEDOWN
;
1264 retval
= WXK_RETURN
;
1319 retval
= WXK_ESCAPE
;
1325 retval
= WXK_RIGHT
;
1334 retval
= WXK_DELETE
;
1342 void wxApp::MacHandleKeyDownEvent( EventRecord
*ev
)
1344 wxToolTip::RemoveToolTips() ;
1346 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1347 if ( HiWord( menuresult
) )
1349 if ( !s_macIsInModalLoop
)
1350 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1356 keychar
= short(ev
->message
& charCodeMask
);
1357 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1359 wxWindow
* focus
= wxWindow::FindFocus() ;
1362 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1364 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1365 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1366 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1367 event
.m_altDown
= ev
->modifiers
& optionKey
;
1368 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1369 event
.m_keyCode
= keyval
;
1370 event
.m_x
= ev
->where
.h
;
1371 event
.m_y
= ev
->where
.v
;
1372 event
.m_timeStamp
= ev
->when
;
1373 event
.SetEventObject(focus
);
1374 bool handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1380 wxWindow
*ancestor
= focus
;
1384 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1387 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1388 handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
1391 if (ancestor->m_isFrame)
1393 ancestor = ancestor->GetParent();
1397 #endif // wxUSE_ACCEL
1401 wxKeyEvent
event(wxEVT_CHAR
);
1402 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1403 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1404 event
.m_altDown
= ev
->modifiers
& optionKey
;
1405 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1406 event
.m_keyCode
= keyval
;
1407 event
.m_x
= ev
->where
.h
;
1408 event
.m_y
= ev
->where
.v
;
1409 event
.m_timeStamp
= ev
->when
;
1410 event
.SetEventObject(focus
);
1411 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1414 (keyval
== WXK_TAB
) &&
1415 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1416 (focus
->GetParent()) &&
1417 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1419 wxNavigationKeyEvent new_event
;
1420 new_event
.SetEventObject( focus
);
1421 new_event
.SetDirection( !event
.ShiftDown() );
1422 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1423 new_event
.SetWindowChange( event
.ControlDown() );
1424 new_event
.SetCurrentFocus( focus
);
1425 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1427 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1429 (keyval
== '.' && event
.ControlDown() ) )
1431 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1432 new_event
.SetEventObject( focus
);
1433 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1439 void wxApp::MacHandleKeyUpEvent( EventRecord
*ev
)
1441 wxToolTip::RemoveToolTips() ;
1443 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1444 if ( HiWord( menuresult
) )
1451 keychar
= short(ev
->message
& charCodeMask
);
1452 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1454 wxWindow
* focus
= wxWindow::FindFocus() ;
1457 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1459 wxKeyEvent
event(wxEVT_KEY_UP
);
1460 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1461 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1462 event
.m_altDown
= ev
->modifiers
& optionKey
;
1463 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1464 event
.m_keyCode
= keyval
;
1465 event
.m_x
= ev
->where
.h
;
1466 event
.m_y
= ev
->where
.v
;
1467 event
.m_timeStamp
= ev
->when
;
1468 event
.SetEventObject(focus
);
1469 bool handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1474 void wxApp::MacHandleActivateEvent( EventRecord
*ev
)
1476 WindowRef window
= (WindowRef
) ev
->message
;
1479 bool activate
= (ev
->modifiers
& activeFlag
) ;
1480 WindowClass wclass
;
1481 UMAGetWindowClass ( window
, &wclass
) ;
1482 if ( wclass
== kFloatingWindowClass
)
1484 // if it is a floater we activate/deactivate the front non-floating window instead
1485 window
= UMAFrontNonFloatingWindow() ;
1487 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1489 win
->MacActivate( ev
, activate
) ;
1493 void wxApp::MacHandleUpdateEvent( EventRecord
*ev
)
1495 WindowRef window
= (WindowRef
) ev
->message
;
1496 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1499 if ( !wxPendingDelete
.Member(win
) )
1500 win
->MacUpdate( ev
) ;
1504 // since there is no way of telling this foreign window to update itself
1505 // we have to invalidate the update region otherwise we keep getting the same
1506 // event over and over again
1507 BeginUpdate( window
) ;
1508 EndUpdate( window
) ;
1512 void wxApp::MacHandleDiskEvent( EventRecord
*ev
)
1514 if ( HiWord( ev
->message
) != noErr
)
1519 SetPt( &point
, 100 , 100 ) ;
1521 err
= DIBadMount( point
, ev
->message
) ;
1522 wxASSERT( err
== noErr
) ;
1527 void wxApp::MacHandleOSEvent( EventRecord
*ev
)
1529 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
1531 case suspendResumeMessage
:
1533 bool isResuming
= ev
->message
& resumeFlag
;
1535 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
1537 bool convertClipboard
= false;
1539 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
1542 WindowRef oldFrontWindow
= NULL
;
1543 WindowRef newFrontWindow
= NULL
;
1545 // in case we don't take care of activating ourselves, we have to synchronize
1546 // our idea of the active window with the process manager's - which it already activated
1548 if ( !doesActivate
)
1549 oldFrontWindow
= UMAFrontNonFloatingWindow() ;
1551 MacResume( convertClipboard
) ;
1553 newFrontWindow
= UMAFrontNonFloatingWindow() ;
1555 if ( oldFrontWindow
)
1557 wxWindow
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
1559 win
->MacActivate( ev
, false ) ;
1561 if ( newFrontWindow
)
1563 wxWindow
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
1565 win
->MacActivate( ev
, true ) ;
1570 MacSuspend( convertClipboard
) ;
1572 // in case this suspending did close an active window, another one might
1573 // have surfaced -> lets deactivate that one
1575 WindowRef newActiveWindow
= UMAGetActiveNonFloatingWindow() ;
1576 if ( newActiveWindow
)
1578 wxWindow
* win
= wxFindWinFromMacWindow( newActiveWindow
) ;
1580 win
->MacActivate( ev
, false ) ;
1585 case mouseMovedMessage
:
1589 wxWindow
* currentMouseWindow
= NULL
;
1591 wxWindow::MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) ,
1592 ¤tMouseWindow
) ;
1594 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
1596 wxMouseEvent event
;
1598 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1599 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1601 event
.m_leftDown
= isDown
&& !controlDown
;
1602 event
.m_middleDown
= FALSE
;
1603 event
.m_rightDown
= isDown
&& controlDown
;
1604 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1605 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1606 event
.m_altDown
= ev
->modifiers
& optionKey
;
1607 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1608 event
.m_x
= ev
->where
.h
;
1609 event
.m_y
= ev
->where
.v
;
1610 event
.m_timeStamp
= ev
->when
;
1611 event
.SetEventObject(this);
1613 if ( wxWindow::s_lastMouseWindow
)
1615 wxMouseEvent
eventleave(event
) ;
1616 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
) ;
1617 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
1619 if ( currentMouseWindow
)
1621 wxMouseEvent
evententer(event
) ;
1622 evententer
.SetEventType( wxEVT_ENTER_WINDOW
) ;
1623 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
1625 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
1628 short windowPart
= ::FindWindow(ev
->where
, &window
);
1632 // fixes for setting the cursor back from dominic mazzoni
1634 UMAShowArrowCursor();
1637 UMAShowArrowCursor();
1641 if ( s_lastMouseDown
== 0 )
1642 ev
->modifiers
|= btnState
;
1644 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1646 win
->MacMouseMoved( ev
, windowPart
) ;
1648 UMAShowArrowCursor();
1659 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
1662 return; // no menu item selected
1664 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
1667 Str255 deskAccessoryName
;
1670 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
1671 GetPort(&savedPort
);
1672 OpenDeskAcc(deskAccessoryName
);
1678 wxWindow
* frontwindow
= wxFindWinFromMacWindow( ::FrontWindow() ) ;
1679 if ( frontwindow
&& wxMenuBar::MacGetInstalledMenuBar() )
1680 wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow
->GetEventHandler() , 0 , macMenuId
, macMenuItemNum
) ;
1686 long wxApp::MacTranslateKey(char key, int mods)
1690 void wxApp::MacAdjustCursor()
1697 wxApp::macAdjustCursor()
1699 if (ev->what != kHighLevelEvent)
1701 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1704 if (!theMacWxFrame->MacAdjustCursor(ev->where))
1705 ::SetCursor(&(qd.arrow));