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 UMAShowWatchCursor() ;
356 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
, AEHandleODoc
,
357 (long) wxTheApp
, FALSE
) ;
358 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
, AEHandleOApp
,
359 (long) wxTheApp
, FALSE
) ;
360 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
, AEHandlePDoc
,
361 (long) wxTheApp
, FALSE
) ;
362 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
, AEHandleQuit
,
363 (long) wxTheApp
, FALSE
) ;
365 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
, NewAEEventHandlerProc(AEHandleODoc
) ,
366 (long) wxTheApp
, FALSE
) ;
367 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
, NewAEEventHandlerProc(AEHandleOApp
) ,
368 (long) wxTheApp
, FALSE
) ;
369 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
, NewAEEventHandlerProc(AEHandlePDoc
) ,
370 (long) wxTheApp
, FALSE
) ;
371 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
, NewAEEventHandlerProc(AEHandleQuit
) ,
372 (long) wxTheApp
, FALSE
) ;
377 // test the minimal configuration necessary
383 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
385 error
= kMacSTRWrongMachine
;
387 else if (theMachine
< gestaltMacPlus
)
389 error
= kMacSTRWrongMachine
;
391 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
393 error
= kMacSTROldSystem
;
395 else if ( theSystem
< 0x0750 )
397 error
= kMacSTROldSystem
;
399 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
401 error
= kMacSTRSmallSize
;
407 if ( !UMAHasAppearance() )
409 error = kMacSTRNoPre8Yet ;
415 // if we encountered any problems so far, give the error code and exit immediately
422 GetIndString(message
, 128, error
);
423 UMAShowArrowCursor() ;
424 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
425 itemHit
= Alert(128, nil
);
430 #if __option(profile)
431 ProfilerInit( collectDetailed
, bestTimeBase
, 20000 , 40 ) ;
435 // now avoid exceptions thrown for new (bad_alloc)
438 std::__throws_bad_alloc
= FALSE
;
441 s_macCursorRgn
= ::NewRgn() ;
444 wxBuffer
= new char[1500];
446 wxBuffer
= new char[BUFSIZ
+ 512];
449 wxClassInfo::InitializeClasses();
452 // wxGetResource(wxT("wxWindows"), wxT("OsVersion"), &wxOsVersion);
456 wxPendingEventsLocker
= new wxCriticalSection
;
458 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
459 wxTheColourDatabase
->Initialize();
461 wxInitializeStockLists();
462 wxInitializeStockObjects();
464 #if wxUSE_WX_RESOURCES
465 wxInitializeResourceSystem();
468 wxBitmap::InitStandardHandlers();
470 wxModule::RegisterModules();
471 if (!wxModule::InitializeModules()) {
475 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
476 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
478 wxMacCreateNotifierTable() ;
480 UMAShowArrowCursor() ;
485 void wxApp::CleanUp()
488 // flush the logged messages if any and install a 'safer' log target: the
489 // default one (wxLogGui) can't be used after the resources are freed just
490 // below and the user suppliedo ne might be even more unsafe (using any
491 // wxWindows GUI function is unsafe starting from now)
492 wxLog::DontCreateOnDemand();
494 // this will flush the old messages if any
495 delete wxLog::SetActiveTarget(new wxLogStderr
);
498 // One last chance for pending objects to be cleaned up
499 wxTheApp
->DeletePendingObjects();
501 wxModule::CleanUpModules();
503 #if wxUSE_WX_RESOURCES
504 wxCleanUpResourceSystem();
507 wxDeleteStockObjects() ;
509 // Destroy all GDI lists, etc.
510 wxDeleteStockLists();
512 delete wxTheColourDatabase
;
513 wxTheColourDatabase
= NULL
;
515 wxBitmap::CleanUpHandlers();
520 wxMacDestroyNotifierTable() ;
521 if (wxWinMacWindowList
)
522 delete wxWinMacWindowList
;
524 delete wxPendingEvents
;
526 delete wxPendingEventsLocker
;
527 // If we don't do the following, we get an apparent memory leak.
528 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
531 wxClassInfo::CleanUpClasses();
534 #if __option(profile)
535 ProfilerDump( "\papp.prof" ) ;
543 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
544 // At this point we want to check if there are any memory
545 // blocks that aren't part of the wxDebugContext itself,
546 // as a special case. Then when dumping we need to ignore
547 // wxDebugContext, too.
548 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
550 wxLogDebug(wxT("There were memory leaks."));
551 wxDebugContext::Dump();
552 wxDebugContext::PrintStatistics();
554 // wxDebugContext::SetStream(NULL, NULL);
558 // do it as the very last thing because everything else can log messages
559 delete wxLog::SetActiveTarget(NULL
);
562 UMACleanupToolbox() ;
564 ::DisposeRgn(s_macCursorRgn
);
571 int wxEntry( int argc
, char *argv
[] , bool enterLoop
)
574 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
575 // This seems to be necessary since there are 'rogue'
576 // objects present at this point (perhaps global objects?)
577 // Setting a checkpoint will ignore them as far as the
578 // memory checking facility is concerned.
579 // Of course you may argue that memory allocated in globals should be
580 // checked, but this is a reasonable compromise.
581 wxDebugContext::SetCheckpoint();
584 if (!wxApp::Initialize()) {
587 // create the application object or ensure that one already exists
590 // The app may have declared a global application object, but we recommend
591 // the IMPLEMENT_APP macro is used instead, which sets an initializer
592 // function for delayed, dynamic app object construction.
593 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
594 wxT("No initializer - use IMPLEMENT_APP macro.") );
596 wxTheApp
= (wxApp
*) (*wxApp::GetInitializerFunction()) ();
599 wxCHECK_MSG( wxTheApp
, 0, wxT("You have to define an instance of wxApp!") );
602 argc
= 0 ; // currently we don't support files as parameters
605 wxTheApp
->argc
= argc
;
606 wxTheApp
->argv
= argv
;
608 // GUI-specific initialization, such as creating an app context.
609 wxTheApp
->OnInitGui();
611 // we could try to get the open apple events here to adjust argc and argv better
614 // Here frames insert themselves automatically
615 // into wxTopLevelWindows by getting created
620 if ( wxTheApp
->OnInit() )
624 retValue
= wxTheApp
->OnRun();
627 // We want to initialize, but not run or exit immediately.
630 //else: app initialization failed, so we skipped OnRun()
632 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
635 // Forcibly delete the window.
636 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
637 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
639 topWindow
->Close(TRUE
);
640 wxTheApp
->DeletePendingObjects();
645 wxTheApp
->SetTopWindow(NULL
);
656 // Static member initialization
657 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
664 m_wantDebugOutput
= TRUE
;
669 m_printMode
= wxPRINT_WINDOWS
;
670 m_exitOnFrameDelete
= TRUE
;
674 bool wxApp::Initialized()
682 int wxApp::MainLoop()
694 // Returns TRUE if more time is needed.
695 bool wxApp::ProcessIdle()
698 event
.SetEventObject(this);
701 return event
.MoreRequested();
704 void wxApp::ExitMainLoop()
709 // Is a message/event pending?
710 bool wxApp::Pending()
714 return EventAvail( everyEvent
, &event
) ;
717 // Dispatch a message.
718 void wxApp::Dispatch()
723 void wxApp::OnIdle(wxIdleEvent
& event
)
725 static bool s_inOnIdle
= FALSE
;
727 // Avoid recursion (via ProcessEvent default case)
734 // 'Garbage' collection of windows deleted with Close().
735 DeletePendingObjects();
737 // flush the logged messages if any
738 wxLog
*pLog
= wxLog::GetActiveTarget();
739 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
742 // Send OnIdle events to all windows
743 bool needMore
= SendIdleEvents();
746 event
.RequestMore(TRUE
);
748 // If they are pending events, we must process them: pending events are
749 // either events to the threads other than main or events posted with
750 // wxPostEvent() functions
751 wxMacProcessNotifierAndPendingEvents();
761 // Send idle event to all top-level windows
762 bool wxApp::SendIdleEvents()
764 bool needMore
= FALSE
;
765 wxNode
* node
= wxTopLevelWindows
.First();
768 wxWindow
* win
= (wxWindow
*) node
->Data();
769 if (SendIdleEvents(win
))
777 // Send idle event to window and all subwindows
778 bool wxApp::SendIdleEvents(wxWindow
* win
)
780 bool needMore
= FALSE
;
783 event
.SetEventObject(win
);
784 win
->ProcessEvent(event
);
786 if (event
.MoreRequested())
789 wxNode
* node
= win
->GetChildren().First();
792 wxWindow
* win
= (wxWindow
*) node
->Data();
793 if (SendIdleEvents(win
))
801 void wxApp::DeletePendingObjects()
803 wxNode
*node
= wxPendingDelete
.First();
806 wxObject
*obj
= (wxObject
*)node
->Data();
810 if (wxPendingDelete
.Member(obj
))
813 // Deleting one object may have deleted other pending
814 // objects, so start from beginning of list again.
815 node
= wxPendingDelete
.First();
820 wxApp::GetStdIcon(int which
) const
824 case wxICON_INFORMATION
:
825 return wxIcon("wxICON_INFO");
827 case wxICON_QUESTION
:
828 return wxIcon("wxICON_QUESTION");
830 case wxICON_EXCLAMATION
:
831 return wxIcon("wxICON_WARNING");
834 wxFAIL_MSG(wxT("requested non existent standard icon"));
835 // still fall through
838 return wxIcon("wxICON_ERROR");
844 wxLogError(_("Fatal error: exiting"));
850 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
853 GetTopWindow()->Close(TRUE
);
856 // Default behaviour: close the application with prompts. The
857 // user can veto the close, and therefore the end session.
858 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
862 if (!GetTopWindow()->Close(!event
.CanVeto()))
867 extern "C" void wxCYield() ;
873 // Yield to other processes
875 static bool gs_inYield
= FALSE
;
881 wxFAIL_MSG( wxT("wxYield called recursively" ) );
891 long sleepTime
= 0 ; //::GetCaretTime();
893 while ( !wxTheApp
->IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, wxApp::s_macCursorRgn
))
895 wxTheApp
->MacHandleOneEvent( &event
);
898 wxMacProcessNotifierAndPendingEvents() ;
905 // Yield to incoming messages; but fail silently if recursion is detected.
906 bool wxYieldIfNeeded()
914 // platform specifics
916 void wxApp::MacSuspend( bool convertClipboard
)
918 // we have to deactive the window manually
920 wxWindow
* window
= GetTopWindow() ;
922 window
->MacActivate( MacGetCurrentEvent() , false ) ;
924 s_lastMouseDown
= 0 ;
925 if( convertClipboard
)
927 MacConvertPrivateToPublicScrap() ;
930 UMAHideFloatingWindows() ;
933 void wxApp::MacResume( bool convertClipboard
)
935 s_lastMouseDown
= 0 ;
936 if( convertClipboard
)
938 MacConvertPublicToPrivateScrap() ;
941 UMAShowFloatingWindows() ;
944 void wxApp::MacConvertPrivateToPublicScrap()
948 void wxApp::MacConvertPublicToPrivateScrap()
952 void wxApp::MacDoOneEvent()
956 long sleepTime
= ::GetCaretTime();
958 if (WaitNextEvent(everyEvent
, &event
,sleepTime
, s_macCursorRgn
))
960 MacHandleOneEvent( &event
);
965 WindowPtr window
= UMAFrontWindow() ;
967 UMAIdleControls( window
) ;
969 wxTheApp
->ProcessIdle() ;
971 if ( event
.what
!= kHighLevelEvent
)
972 SetRectRgn( s_macCursorRgn
, event
.where
.h
- 1 , event
.where
.v
- 1, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
976 wxMacProcessNotifierAndPendingEvents() ;
979 void wxApp::MacHandleOneEvent( EventRecord
*ev
)
981 m_macCurrentEvent
= ev
;
983 wxApp::sm_lastMessageTime
= ev
->when
;
988 MacHandleMouseDownEvent( ev
) ;
989 if ( ev
->modifiers
& controlKey
)
995 if ( s_lastMouseDown
== 2 )
997 ev
->modifiers
|= controlKey
;
1001 ev
->modifiers
&= ~controlKey
;
1003 MacHandleMouseUpEvent( ev
) ;
1004 s_lastMouseDown
= 0;
1007 MacHandleActivateEvent( ev
) ;
1010 MacHandleUpdateEvent( ev
) ;
1014 MacHandleKeyDownEvent( ev
) ;
1017 MacHandleKeyUpEvent( ev
) ;
1020 MacHandleDiskEvent( ev
) ;
1023 MacHandleOSEvent( ev
) ;
1025 case kHighLevelEvent
:
1026 MacHandleHighLevelEvent( ev
) ;
1031 wxMacProcessNotifierAndPendingEvents() ;
1034 void wxApp::MacHandleHighLevelEvent( EventRecord
*ev
)
1036 ::AEProcessAppleEvent( ev
) ;
1039 bool s_macIsInModalLoop
= false ;
1041 void wxApp::MacHandleMouseDownEvent( EventRecord
*ev
)
1043 wxToolTip::RemoveToolTips() ;
1046 WindowRef frontWindow
= UMAFrontNonFloatingWindow() ;
1047 WindowAttributes frontWindowAttributes
= NULL
;
1049 UMAGetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
1051 short windowPart
= ::FindWindow(ev
->where
, &window
);
1052 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1055 GetQDGlobalsScreenBits( &screenBits
);
1060 if ( s_macIsInModalLoop
)
1066 UInt32 menuresult
= MenuSelect(ev
->where
) ;
1067 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1068 s_lastMouseDown
= 0;
1073 SystemClick( ev
, window
) ;
1074 s_lastMouseDown
= 0;
1078 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1084 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1089 Point pt
= { 0, 0 } ;
1091 SetPort( GetWindowPort(window
) ) ;
1093 SetPort( (window
) ) ;
1095 SetOrigin( 0 , 0 ) ;
1096 LocalToGlobal( &pt
) ;
1098 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1099 -1 , wxSIZE_USE_EXISTING
);
1101 s_lastMouseDown
= 0;
1105 if (TrackGoAway(window
, ev
->where
))
1110 s_lastMouseDown
= 0;
1114 int growResult
= GrowWindow(window
, ev
->where
, &screenBits
.bounds
);
1115 if (growResult
!= 0)
1117 int newWidth
= LoWord(growResult
);
1118 int newHeight
= HiWord(growResult
);
1119 int oldWidth
, oldHeight
;
1124 win
->GetSize(&oldWidth
, &oldHeight
);
1126 newWidth
= oldWidth
;
1128 newHeight
= oldHeight
;
1129 win
->SetSize( -1, -1, newWidth
, newHeight
, wxSIZE_USE_EXISTING
);
1132 s_lastMouseDown
= 0;
1137 if (TrackBox(window
, ev
->where
, windowPart
))
1139 // TODO setup size event
1140 ZoomWindow( window
, windowPart
, false ) ;
1145 GetWindowPortBounds(window
, &tempRect
) ;
1146 win
->SetSize( -1, -1, tempRect
.right
-tempRect
.left
,
1147 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1150 s_lastMouseDown
= 0;
1152 case inCollapseBox
:
1153 // TODO setup size event
1154 s_lastMouseDown
= 0;
1162 SetPort( GetWindowPort(window
) ) ;
1164 SetPort( (window
) ) ;
1166 SetOrigin( 0 , 0 ) ;
1169 if ( window
!= frontWindow
)
1171 if ( s_macIsInModalLoop
)
1175 else if ( UMAIsWindowFloating( window
) )
1178 win
->MacMouseDown( ev
, windowPart
) ;
1182 UMASelectWindow( window
) ;
1188 win
->MacMouseDown( ev
, windowPart
) ;
1197 void wxApp::MacHandleMouseUpEvent( EventRecord
*ev
)
1201 short windowPart
= ::FindWindow(ev
->where
, &window
);
1211 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1213 win
->MacMouseUp( ev
, windowPart
) ;
1219 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1228 retval
= WXK_RETURN
;
1243 retval
= WXK_PAGEUP
;
1246 retval
= WXK_PAGEDOWN
;
1249 retval
= WXK_RETURN
;
1304 retval
= WXK_ESCAPE
;
1310 retval
= WXK_RIGHT
;
1319 retval
= WXK_DELETE
;
1327 void wxApp::MacHandleKeyDownEvent( EventRecord
*ev
)
1329 wxToolTip::RemoveToolTips() ;
1331 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1332 if ( HiWord( menuresult
) )
1334 if ( !s_macIsInModalLoop
)
1335 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1341 keychar
= short(ev
->message
& charCodeMask
);
1342 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1344 wxWindow
* focus
= wxWindow::FindFocus() ;
1347 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1349 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1350 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1351 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1352 event
.m_altDown
= ev
->modifiers
& optionKey
;
1353 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1354 event
.m_keyCode
= keyval
;
1355 event
.m_x
= ev
->where
.h
;
1356 event
.m_y
= ev
->where
.v
;
1357 event
.m_timeStamp
= ev
->when
;
1358 event
.SetEventObject(focus
);
1359 bool handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1365 wxWindow
*ancestor
= focus
;
1369 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1372 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1373 handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
1376 if (ancestor->m_isFrame)
1378 ancestor = ancestor->GetParent();
1382 #endif // wxUSE_ACCEL
1386 wxKeyEvent
event(wxEVT_CHAR
);
1387 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1388 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1389 event
.m_altDown
= ev
->modifiers
& optionKey
;
1390 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1391 event
.m_keyCode
= keyval
;
1392 event
.m_x
= ev
->where
.h
;
1393 event
.m_y
= ev
->where
.v
;
1394 event
.m_timeStamp
= ev
->when
;
1395 event
.SetEventObject(focus
);
1396 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1399 (keyval
== WXK_TAB
) &&
1400 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1401 (focus
->GetParent()) &&
1402 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1404 wxNavigationKeyEvent new_event
;
1405 new_event
.SetEventObject( focus
);
1406 new_event
.SetDirection( !event
.ShiftDown() );
1407 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1408 new_event
.SetWindowChange( event
.ControlDown() );
1409 new_event
.SetCurrentFocus( focus
);
1410 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1412 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1414 (keyval
== '.' && event
.ControlDown() ) )
1416 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1417 new_event
.SetEventObject( focus
);
1418 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1424 void wxApp::MacHandleKeyUpEvent( EventRecord
*ev
)
1429 void wxApp::MacHandleActivateEvent( EventRecord
*ev
)
1431 WindowRef window
= (WindowRef
) ev
->message
;
1434 bool activate
= (ev
->modifiers
& activeFlag
) ;
1435 WindowClass wclass
;
1436 UMAGetWindowClass ( window
, &wclass
) ;
1437 if ( wclass
== kFloatingWindowClass
)
1439 // if it is a floater we activate/deactivate the front non-floating window instead
1440 window
= UMAFrontNonFloatingWindow() ;
1442 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1444 win
->MacActivate( ev
, activate
) ;
1448 void wxApp::MacHandleUpdateEvent( EventRecord
*ev
)
1450 WindowRef window
= (WindowRef
) ev
->message
;
1451 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1454 win
->MacUpdate( ev
) ;
1458 // since there is no way of telling this foreign window to update itself
1459 // we have to invalidate the update region otherwise we keep getting the same
1460 // event over and over again
1461 BeginUpdate( window
) ;
1462 EndUpdate( window
) ;
1466 void wxApp::MacHandleDiskEvent( EventRecord
*ev
)
1468 if ( HiWord( ev
->message
) != noErr
)
1473 SetPt( &point
, 100 , 100 ) ;
1475 err
= DIBadMount( point
, ev
->message
) ;
1476 wxASSERT( err
== noErr
) ;
1481 void wxApp::MacHandleOSEvent( EventRecord
*ev
)
1483 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
1485 case suspendResumeMessage
:
1487 bool isResuming
= ev
->message
& resumeFlag
;
1489 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
1491 bool convertClipboard
= false;
1493 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
1496 WindowRef oldFrontWindow
= NULL
;
1497 WindowRef newFrontWindow
= NULL
;
1499 // in case we don't take care of activating ourselves, we have to synchronize
1500 // our idea of the active window with the process manager's - which it already activated
1502 if ( !doesActivate
)
1503 oldFrontWindow
= UMAFrontNonFloatingWindow() ;
1505 MacResume( convertClipboard
) ;
1507 newFrontWindow
= UMAFrontNonFloatingWindow() ;
1509 if ( oldFrontWindow
)
1511 wxWindow
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
1513 win
->MacActivate( ev
, false ) ;
1515 if ( newFrontWindow
)
1517 wxWindow
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
1519 win
->MacActivate( ev
, true ) ;
1524 MacSuspend( convertClipboard
) ;
1526 // in case this suspending did close an active window, another one might
1527 // have surfaced -> lets deactivate that one
1529 WindowRef newActiveWindow
= UMAGetActiveNonFloatingWindow() ;
1530 if ( newActiveWindow
)
1532 wxWindow
* win
= wxFindWinFromMacWindow( newActiveWindow
) ;
1534 win
->MacActivate( ev
, false ) ;
1539 case mouseMovedMessage
:
1543 wxWindow
* currentMouseWindow
= NULL
;
1545 wxWindow::MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) ,
1546 ¤tMouseWindow
) ;
1548 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
1550 wxMouseEvent event
;
1552 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1553 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1555 event
.m_leftDown
= isDown
&& !controlDown
;
1556 event
.m_middleDown
= FALSE
;
1557 event
.m_rightDown
= isDown
&& controlDown
;
1558 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1559 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1560 event
.m_altDown
= ev
->modifiers
& optionKey
;
1561 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1562 event
.m_x
= ev
->where
.h
;
1563 event
.m_y
= ev
->where
.v
;
1564 event
.m_timeStamp
= ev
->when
;
1565 event
.SetEventObject(this);
1567 if ( wxWindow::s_lastMouseWindow
)
1569 wxMouseEvent
eventleave(event
) ;
1570 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
) ;
1571 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
1573 if ( currentMouseWindow
)
1575 wxMouseEvent
evententer(event
) ;
1576 evententer
.SetEventType( wxEVT_ENTER_WINDOW
) ;
1577 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
1579 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
1582 short windowPart
= ::FindWindow(ev
->where
, &window
);
1586 // fixes for setting the cursor back from dominic mazzoni
1588 UMAShowArrowCursor();
1591 UMAShowArrowCursor();
1595 if ( s_lastMouseDown
== 0 )
1596 ev
->modifiers
|= btnState
;
1598 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1600 win
->MacMouseMoved( ev
, windowPart
) ;
1602 UMAShowArrowCursor();
1613 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
1616 return; // no menu item selected
1618 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
1621 Str255 deskAccessoryName
;
1624 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
1625 GetPort(&savedPort
);
1626 OpenDeskAcc(deskAccessoryName
);
1632 wxWindow
* frontwindow
= wxFindWinFromMacWindow( ::FrontWindow() ) ;
1633 if ( frontwindow
&& wxMenuBar::MacGetInstalledMenuBar() )
1634 wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow
->GetEventHandler() , 0 , macMenuId
, macMenuItemNum
) ;
1640 long wxApp::MacTranslateKey(char key, int mods)
1644 void wxApp::MacAdjustCursor()
1651 wxApp::macAdjustCursor()
1653 if (ev->what != kHighLevelEvent)
1655 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1658 if (!theMacWxFrame->MacAdjustCursor(ev->where))
1659 ::SetCursor(&(qd.arrow));