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 <OT/OpenTransport.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 pascal OSErr
AEHandleODoc( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
100 wxApp
* app
= (wxApp
*) refcon
;
101 return wxTheApp
->MacHandleAEODoc( (AppleEvent
*) event
, reply
) ;
104 pascal OSErr
AEHandleOApp( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
106 wxApp
* app
= (wxApp
*) refcon
;
107 return wxTheApp
->MacHandleAEOApp( (AppleEvent
*) event
, reply
) ;
110 pascal OSErr
AEHandlePDoc( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
112 wxApp
* app
= (wxApp
*) refcon
;
113 return wxTheApp
->MacHandleAEPDoc( (AppleEvent
*) event
, reply
) ;
116 pascal OSErr
AEHandleQuit( const AppleEvent
*event
, AppleEvent
*reply
, unsigned long refcon
)
118 wxApp
* app
= (wxApp
*) refcon
;
119 return wxTheApp
->MacHandleAEQuit( (AppleEvent
*) event
, reply
) ;
122 OSErr
wxApp::MacHandleAEODoc(const AppleEvent
*event
, AppleEvent
*reply
)
124 ProcessSerialNumber PSN
;
125 PSN
.highLongOfPSN
= 0 ;
126 PSN
.lowLongOfPSN
= kCurrentProcess
;
127 SetFrontProcess( &PSN
) ;
131 OSErr
wxApp::MacHandleAEPDoc(const AppleEvent
*event
, AppleEvent
*reply
)
136 OSErr
wxApp::MacHandleAEOApp(const AppleEvent
*event
, AppleEvent
*reply
)
141 OSErr
wxApp::MacHandleAEQuit(const AppleEvent
*event
, AppleEvent
*reply
)
143 wxWindow
* win
= GetTopWindow() ;
155 char StringMac
[] = "\x0d\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
156 "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
157 "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf"
158 "\xb1\xb4\xb5\xb6\xbb\xbc\xbe\xbf"
159 "\xc0\xc1\xc2\xc4\xc7\xc8\xc9\xcb\xcc\xcd\xce\xcf"
160 "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xca\xdb" ;
162 char StringANSI
[] = "\x0a\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8"
163 "\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC"
164 "\x86\xBA\xA2\xA3\xA7\x95\xB6\xDF\xAE\xA9\x99\xB4\xA8\xC6\xD8"
165 "\xB1\xA5\xB5\xF0\xAA\xBA\xE6\xF8"
166 "\xBF\xA1\xAC\x83\xAB\xBB\x85\xC0\xC3\xD5\x8C\x9C"
167 "\x96\x97\x93\x94\x91\x92\xF7\xFF\xA0\x80" ;
169 void wxMacConvertFromPC( const char *from
, char *to
, int len
)
174 for( int i
= 0 ; i
< len
; ++ i
)
176 c
= strchr( StringANSI
, *from
) ;
179 *to
= StringMac
[ c
- StringANSI
] ;
187 for( int i
= 0 ; i
< len
; ++ i
)
189 c
= strchr( StringANSI
, *from
) ;
192 *to
= StringMac
[ c
- StringANSI
] ;
204 void wxMacConvertToPC( const char *from
, char *to
, int len
)
209 for( int i
= 0 ; i
< len
; ++ i
)
211 c
= strchr( StringMac
, *from
) ;
214 *to
= StringANSI
[ c
- StringMac
] ;
222 for( int i
= 0 ; i
< len
; ++ i
)
224 c
= strchr( StringMac
, *from
) ;
227 *to
= StringANSI
[ c
- StringMac
] ;
239 void wxMacConvertFromPC( char * p
)
242 int len
= strlen ( p
) ;
244 wxMacConvertFromPC( ptr
, ptr
, len
) ;
247 void wxMacConvertFromPCForControls( char * p
)
250 int len
= strlen ( p
) ;
252 wxMacConvertFromPC( ptr
, ptr
, len
) ;
253 for ( int i
= 0 ; i
< strlen ( ptr
) ; i
++ )
255 if ( ptr
[i
] == '&' && ptr
[i
]+1 != ' ' )
257 memmove( &ptr
[i
] , &ptr
[i
+1] , strlen( &ptr
[i
+1] ) + 1) ;
262 void wxMacConvertFromPC( unsigned char *p
)
264 char *ptr
= (char*) p
+ 1 ;
267 wxMacConvertFromPC( ptr
, ptr
, len
) ;
270 extern char *wxBuffer
;
272 wxString
wxMacMakeMacStringFromPC( const char * p
)
274 const char *ptr
= p
;
275 int len
= strlen ( p
) ;
276 char *buf
= wxBuffer
;
278 if ( len
>= BUFSIZ
+ 512 )
280 buf
= new char [len
+1] ;
283 wxMacConvertFromPC( ptr
, buf
, len
) ;
285 wxString
result( buf
) ;
286 if ( buf
!= wxBuffer
)
292 void wxMacConvertToPC( char * p
)
295 int len
= strlen ( p
) ;
297 wxMacConvertToPC( ptr
, ptr
, len
) ;
300 void wxMacConvertToPC( unsigned char *p
)
302 char *ptr
= (char*) p
+ 1 ;
305 wxMacConvertToPC( ptr
, ptr
, len
) ;
308 wxString
wxMacMakePCStringFromMac( const char * p
)
310 const char *ptr
= p
;
311 int len
= strlen ( p
) ;
312 char *buf
= wxBuffer
;
314 if ( len
>= BUFSIZ
+ 512 )
316 buf
= new char [len
+1] ;
319 wxMacConvertToPC( ptr
, buf
, len
) ;
322 wxString
result( buf
) ;
323 if ( buf
!= wxBuffer
)
330 bool wxApp::Initialize()
336 UMAInitToolbox( 4 ) ;
337 UMAShowWatchCursor() ;
340 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
, AEHandleODoc
,
341 (long) wxTheApp
, FALSE
) ;
342 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
, AEHandleOApp
,
343 (long) wxTheApp
, FALSE
) ;
344 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
, AEHandlePDoc
,
345 (long) wxTheApp
, FALSE
) ;
346 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
, AEHandleQuit
,
347 (long) wxTheApp
, FALSE
) ;
349 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
, NewAEEventHandlerProc(AEHandleODoc
) ,
350 (long) wxTheApp
, FALSE
) ;
351 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
, NewAEEventHandlerProc(AEHandleOApp
) ,
352 (long) wxTheApp
, FALSE
) ;
353 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
, NewAEEventHandlerProc(AEHandlePDoc
) ,
354 (long) wxTheApp
, FALSE
) ;
355 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
, NewAEEventHandlerProc(AEHandleQuit
) ,
356 (long) wxTheApp
, FALSE
) ;
361 // test the minimal configuration necessary
366 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
368 error
= kMacSTRWrongMachine
;
370 else if (theMachine
< gestaltMacPlus
)
372 error
= kMacSTRWrongMachine
;
374 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
376 error
= kMacSTROldSystem
;
378 else if ( theSystem
< 0x0750 )
380 error
= kMacSTROldSystem
;
383 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
385 error
= kMacSTRSmallSize
;
391 if ( !UMAHasAppearance() )
393 error = kMacSTRNoPre8Yet ;
399 // if we encountered any problems so far, give the error code and exit immediately
406 GetIndString(message
, 128, error
);
407 UMAShowArrowCursor() ;
408 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
409 itemHit
= Alert(128, nil
);
414 #if __option(profile)
415 ProfilerInit( collectDetailed
, bestTimeBase
, 20000 , 40 ) ;
419 // now avoid exceptions thrown for new (bad_alloc)
422 std::__throws_bad_alloc
= FALSE
;
425 s_macCursorRgn
= ::NewRgn() ;
428 wxBuffer
= new char[1500];
430 wxBuffer
= new char[BUFSIZ
+ 512];
433 wxClassInfo::InitializeClasses();
436 // wxGetResource(wxT("wxWindows"), wxT("OsVersion"), &wxOsVersion);
440 wxPendingEventsLocker
= new wxCriticalSection
;
442 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
443 wxTheColourDatabase
->Initialize();
445 wxInitializeStockLists();
446 wxInitializeStockObjects();
448 #if wxUSE_WX_RESOURCES
449 wxInitializeResourceSystem();
452 wxBitmap::InitStandardHandlers();
454 wxModule::RegisterModules();
455 if (!wxModule::InitializeModules()) {
459 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
460 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
462 wxMacCreateNotifierTable() ;
464 UMAShowArrowCursor() ;
469 void wxApp::CleanUp()
472 // flush the logged messages if any and install a 'safer' log target: the
473 // default one (wxLogGui) can't be used after the resources are freed just
474 // below and the user suppliedo ne might be even more unsafe (using any
475 // wxWindows GUI function is unsafe starting from now)
476 wxLog::DontCreateOnDemand();
478 // this will flush the old messages if any
479 delete wxLog::SetActiveTarget(new wxLogStderr
);
482 // One last chance for pending objects to be cleaned up
483 wxTheApp
->DeletePendingObjects();
485 wxModule::CleanUpModules();
487 #if wxUSE_WX_RESOURCES
488 wxCleanUpResourceSystem();
491 wxDeleteStockObjects() ;
493 // Destroy all GDI lists, etc.
494 wxDeleteStockLists();
496 delete wxTheColourDatabase
;
497 wxTheColourDatabase
= NULL
;
499 wxBitmap::CleanUpHandlers();
504 wxMacDestroyNotifierTable() ;
505 if (wxWinMacWindowList
)
506 delete wxWinMacWindowList
;
508 delete wxPendingEvents
;
510 delete wxPendingEventsLocker
;
511 // If we don't do the following, we get an apparent memory leak.
512 ((wxEvtHandler
&) wxDefaultValidator
).ClearEventLocker();
515 wxClassInfo::CleanUpClasses();
518 #if __option(profile)
519 ProfilerDump( "\papp.prof" ) ;
527 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
528 // At this point we want to check if there are any memory
529 // blocks that aren't part of the wxDebugContext itself,
530 // as a special case. Then when dumping we need to ignore
531 // wxDebugContext, too.
532 if (wxDebugContext::CountObjectsLeft(TRUE
) > 0)
534 wxLogDebug(wxT("There were memory leaks."));
535 wxDebugContext::Dump();
536 wxDebugContext::PrintStatistics();
538 // wxDebugContext::SetStream(NULL, NULL);
542 // do it as the very last thing because everything else can log messages
543 delete wxLog::SetActiveTarget(NULL
);
546 UMACleanupToolbox() ;
548 ::DisposeRgn(s_macCursorRgn
);
555 int wxEntry( int argc
, char *argv
[] , bool enterLoop
)
558 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
559 // This seems to be necessary since there are 'rogue'
560 // objects present at this point (perhaps global objects?)
561 // Setting a checkpoint will ignore them as far as the
562 // memory checking facility is concerned.
563 // Of course you may argue that memory allocated in globals should be
564 // checked, but this is a reasonable compromise.
565 wxDebugContext::SetCheckpoint();
568 if (!wxApp::Initialize()) {
571 // create the application object or ensure that one already exists
574 // The app may have declared a global application object, but we recommend
575 // the IMPLEMENT_APP macro is used instead, which sets an initializer
576 // function for delayed, dynamic app object construction.
577 wxCHECK_MSG( wxApp::GetInitializerFunction(), 0,
578 wxT("No initializer - use IMPLEMENT_APP macro.") );
580 wxTheApp
= (wxApp
*) (*wxApp::GetInitializerFunction()) ();
583 wxCHECK_MSG( wxTheApp
, 0, wxT("You have to define an instance of wxApp!") );
586 argc
= 0 ; // currently we don't support files as parameters
589 wxTheApp
->argc
= argc
;
590 wxTheApp
->argv
= argv
;
592 // GUI-specific initialization, such as creating an app context.
593 wxTheApp
->OnInitGui();
595 // we could try to get the open apple events here to adjust argc and argv better
598 // Here frames insert themselves automatically
599 // into wxTopLevelWindows by getting created
604 if ( wxTheApp
->OnInit() )
608 retValue
= wxTheApp
->OnRun();
611 // We want to initialize, but not run or exit immediately.
614 //else: app initialization failed, so we skipped OnRun()
616 wxWindow
*topWindow
= wxTheApp
->GetTopWindow();
619 // Forcibly delete the window.
620 if ( topWindow
->IsKindOf(CLASSINFO(wxFrame
)) ||
621 topWindow
->IsKindOf(CLASSINFO(wxDialog
)) )
623 topWindow
->Close(TRUE
);
624 wxTheApp
->DeletePendingObjects();
629 wxTheApp
->SetTopWindow(NULL
);
640 // Static member initialization
641 wxAppInitializerFunction
wxAppBase::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
648 m_wantDebugOutput
= TRUE
;
653 m_printMode
= wxPRINT_WINDOWS
;
654 m_exitOnFrameDelete
= TRUE
;
658 bool wxApp::Initialized()
666 int wxApp::MainLoop()
678 // Returns TRUE if more time is needed.
679 bool wxApp::ProcessIdle()
682 event
.SetEventObject(this);
685 return event
.MoreRequested();
688 void wxApp::ExitMainLoop()
693 // Is a message/event pending?
694 bool wxApp::Pending()
698 return EventAvail( everyEvent
, &event
) ;
701 // Dispatch a message.
702 void wxApp::Dispatch()
707 void wxApp::OnIdle(wxIdleEvent
& event
)
709 static bool s_inOnIdle
= FALSE
;
711 // Avoid recursion (via ProcessEvent default case)
718 // 'Garbage' collection of windows deleted with Close().
719 DeletePendingObjects();
721 // flush the logged messages if any
722 wxLog
*pLog
= wxLog::GetActiveTarget();
723 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
726 // Send OnIdle events to all windows
727 bool needMore
= SendIdleEvents();
730 event
.RequestMore(TRUE
);
732 // If they are pending events, we must process them: pending events are
733 // either events to the threads other than main or events posted with
734 // wxPostEvent() functions
735 wxMacProcessNotifierAndPendingEvents();
745 // Send idle event to all top-level windows
746 bool wxApp::SendIdleEvents()
748 bool needMore
= FALSE
;
749 wxNode
* node
= wxTopLevelWindows
.First();
752 wxWindow
* win
= (wxWindow
*) node
->Data();
753 if (SendIdleEvents(win
))
761 // Send idle event to window and all subwindows
762 bool wxApp::SendIdleEvents(wxWindow
* win
)
764 bool needMore
= FALSE
;
767 event
.SetEventObject(win
);
768 win
->ProcessEvent(event
);
770 if (event
.MoreRequested())
773 wxNode
* node
= win
->GetChildren().First();
776 wxWindow
* win
= (wxWindow
*) node
->Data();
777 if (SendIdleEvents(win
))
785 void wxApp::DeletePendingObjects()
787 wxNode
*node
= wxPendingDelete
.First();
790 wxObject
*obj
= (wxObject
*)node
->Data();
794 if (wxPendingDelete
.Member(obj
))
797 // Deleting one object may have deleted other pending
798 // objects, so start from beginning of list again.
799 node
= wxPendingDelete
.First();
804 wxApp::GetStdIcon(int which
) const
808 case wxICON_INFORMATION
:
809 return wxIcon("wxICON_INFO");
811 case wxICON_QUESTION
:
812 return wxIcon("wxICON_QUESTION");
814 case wxICON_EXCLAMATION
:
815 return wxIcon("wxICON_WARNING");
818 wxFAIL_MSG(wxT("requested non existent standard icon"));
819 // still fall through
822 return wxIcon("wxICON_ERROR");
828 wxLogError(_("Fatal error: exiting"));
834 void wxApp::OnEndSession(wxCloseEvent
& WXUNUSED(event
))
837 GetTopWindow()->Close(TRUE
);
840 // Default behaviour: close the application with prompts. The
841 // user can veto the close, and therefore the end session.
842 void wxApp::OnQueryEndSession(wxCloseEvent
& event
)
846 if (!GetTopWindow()->Close(!event
.CanVeto()))
851 extern "C" void wxCYield() ;
857 // Yield to other processes
859 static bool gs_inYield
= FALSE
;
865 wxFAIL_MSG( wxT("wxYield called recursively" ) );
875 long sleepTime
= 0 ; //::GetCaretTime();
877 while ( !wxTheApp
->IsExiting() && WaitNextEvent(everyEvent
, &event
,sleepTime
, wxApp::s_macCursorRgn
))
879 wxTheApp
->MacHandleOneEvent( &event
);
882 wxMacProcessNotifierAndPendingEvents() ;
889 // Yield to incoming messages; but fail silently if recursion is detected.
890 bool wxYieldIfNeeded()
898 // platform specifics
900 void wxApp::MacSuspend( bool convertClipboard
)
902 // we have to deactive the window manually
904 wxWindow
* window
= GetTopWindow() ;
906 window
->MacActivate( MacGetCurrentEvent() , false ) ;
908 s_lastMouseDown
= 0 ;
909 if( convertClipboard
)
911 MacConvertPrivateToPublicScrap() ;
914 UMAHideFloatingWindows() ;
917 void wxApp::MacResume( bool convertClipboard
)
919 s_lastMouseDown
= 0 ;
920 if( convertClipboard
)
922 MacConvertPublicToPrivateScrap() ;
925 UMAShowFloatingWindows() ;
928 void wxApp::MacConvertPrivateToPublicScrap()
932 void wxApp::MacConvertPublicToPrivateScrap()
936 void wxApp::MacDoOneEvent()
940 long sleepTime
= ::GetCaretTime();
942 if (WaitNextEvent(everyEvent
, &event
,sleepTime
, s_macCursorRgn
))
944 MacHandleOneEvent( &event
);
949 WindowPtr window
= UMAFrontWindow() ;
951 UMAIdleControls( window
) ;
953 wxTheApp
->ProcessIdle() ;
955 if ( event
.what
!= kHighLevelEvent
)
956 SetRectRgn( s_macCursorRgn
, event
.where
.h
- 1 , event
.where
.v
- 1, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
960 wxMacProcessNotifierAndPendingEvents() ;
963 void wxApp::MacHandleOneEvent( EventRecord
*ev
)
965 m_macCurrentEvent
= ev
;
967 wxApp::sm_lastMessageTime
= ev
->when
;
972 MacHandleMouseDownEvent( ev
) ;
973 if ( ev
->modifiers
& controlKey
)
979 if ( s_lastMouseDown
== 2 )
981 ev
->modifiers
|= controlKey
;
985 ev
->modifiers
&= ~controlKey
;
987 MacHandleMouseUpEvent( ev
) ;
991 MacHandleActivateEvent( ev
) ;
994 MacHandleUpdateEvent( ev
) ;
998 MacHandleKeyDownEvent( ev
) ;
1001 MacHandleKeyUpEvent( ev
) ;
1004 MacHandleDiskEvent( ev
) ;
1007 MacHandleOSEvent( ev
) ;
1009 case kHighLevelEvent
:
1010 MacHandleHighLevelEvent( ev
) ;
1015 wxMacProcessNotifierAndPendingEvents() ;
1018 void wxApp::MacHandleHighLevelEvent( EventRecord
*ev
)
1020 ::AEProcessAppleEvent( ev
) ;
1023 bool s_macIsInModalLoop
= false ;
1025 void wxApp::MacHandleMouseDownEvent( EventRecord
*ev
)
1027 wxToolTip::RemoveToolTips() ;
1030 WindowRef frontWindow
= UMAFrontNonFloatingWindow() ;
1031 WindowAttributes frontWindowAttributes
= NULL
;
1033 UMAGetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
1035 short windowPart
= ::FindWindow(ev
->where
, &window
);
1036 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1039 GetQDGlobalsScreenBits( &screenBits
);
1044 if ( s_macIsInModalLoop
)
1050 UInt32 menuresult
= MenuSelect(ev
->where
) ;
1051 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
1052 s_lastMouseDown
= 0;
1057 SystemClick( ev
, window
) ;
1058 s_lastMouseDown
= 0;
1062 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
1068 DragWindow(window
, ev
->where
, &screenBits
.bounds
);
1073 Point pt
= { 0, 0 } ;
1075 SetPort( GetWindowPort(window
) ) ;
1077 SetPort( (window
) ) ;
1079 SetOrigin( 0 , 0 ) ;
1080 LocalToGlobal( &pt
) ;
1082 win
->SetSize( pt
.h
, pt
.v
, -1 ,
1083 -1 , wxSIZE_USE_EXISTING
);
1085 s_lastMouseDown
= 0;
1089 if (TrackGoAway(window
, ev
->where
))
1094 s_lastMouseDown
= 0;
1098 int growResult
= GrowWindow(window
, ev
->where
, &screenBits
.bounds
);
1099 if (growResult
!= 0)
1101 int newWidth
= LoWord(growResult
);
1102 int newHeight
= HiWord(growResult
);
1103 int oldWidth
, oldHeight
;
1108 win
->GetSize(&oldWidth
, &oldHeight
);
1110 newWidth
= oldWidth
;
1112 newHeight
= oldHeight
;
1113 win
->SetSize( -1, -1, newWidth
, newHeight
, wxSIZE_USE_EXISTING
);
1116 s_lastMouseDown
= 0;
1121 if (TrackBox(window
, ev
->where
, windowPart
))
1123 // TODO setup size event
1124 ZoomWindow( window
, windowPart
, false ) ;
1129 GetWindowPortBounds(window
, &tempRect
) ;
1130 win
->SetSize( -1, -1, tempRect
.right
-tempRect
.left
,
1131 tempRect
.bottom
-tempRect
.top
, wxSIZE_USE_EXISTING
);
1134 s_lastMouseDown
= 0;
1136 case inCollapseBox
:
1137 // TODO setup size event
1138 s_lastMouseDown
= 0;
1146 SetPort( GetWindowPort(window
) ) ;
1148 SetPort( (window
) ) ;
1150 SetOrigin( 0 , 0 ) ;
1153 if ( window
!= frontWindow
)
1155 if ( s_macIsInModalLoop
)
1159 else if ( UMAIsWindowFloating( window
) )
1162 win
->MacMouseDown( ev
, windowPart
) ;
1166 UMASelectWindow( window
) ;
1172 win
->MacMouseDown( ev
, windowPart
) ;
1181 void wxApp::MacHandleMouseUpEvent( EventRecord
*ev
)
1185 short windowPart
= ::FindWindow(ev
->where
, &window
);
1195 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1197 win
->MacMouseUp( ev
, windowPart
) ;
1203 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1212 retval
= WXK_RETURN
;
1227 retval
= WXK_PAGEUP
;
1230 retval
= WXK_PAGEDOWN
;
1233 retval
= WXK_RETURN
;
1288 retval
= WXK_ESCAPE
;
1294 retval
= WXK_RIGHT
;
1303 retval
= WXK_DELETE
;
1311 void wxApp::MacHandleKeyDownEvent( EventRecord
*ev
)
1313 wxToolTip::RemoveToolTips() ;
1315 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1316 if ( HiWord( menuresult
) )
1318 if ( !s_macIsInModalLoop
)
1319 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1325 keychar
= short(ev
->message
& charCodeMask
);
1326 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1328 wxWindow
* focus
= wxWindow::FindFocus() ;
1331 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1333 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1334 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1335 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1336 event
.m_altDown
= ev
->modifiers
& optionKey
;
1337 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1338 event
.m_keyCode
= keyval
;
1339 event
.m_x
= ev
->where
.h
;
1340 event
.m_y
= ev
->where
.v
;
1341 event
.m_timeStamp
= ev
->when
;
1342 event
.SetEventObject(focus
);
1343 bool handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1349 wxWindow
*ancestor
= focus
;
1353 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1356 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1357 handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
1360 if (ancestor->m_isFrame)
1362 ancestor = ancestor->GetParent();
1366 #endif // wxUSE_ACCEL
1370 wxKeyEvent
event(wxEVT_CHAR
);
1371 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1372 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1373 event
.m_altDown
= ev
->modifiers
& optionKey
;
1374 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1375 event
.m_keyCode
= keyval
;
1376 event
.m_x
= ev
->where
.h
;
1377 event
.m_y
= ev
->where
.v
;
1378 event
.m_timeStamp
= ev
->when
;
1379 event
.SetEventObject(focus
);
1380 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1383 (keyval
== WXK_TAB
) &&
1384 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1385 (focus
->GetParent()) &&
1386 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1388 wxNavigationKeyEvent new_event
;
1389 new_event
.SetEventObject( focus
);
1390 new_event
.SetDirection( !event
.ShiftDown() );
1391 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1392 new_event
.SetWindowChange( event
.ControlDown() );
1393 new_event
.SetCurrentFocus( focus
);
1394 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1396 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1398 (keyval
== '.' && event
.ControlDown() ) )
1400 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1401 new_event
.SetEventObject( focus
);
1402 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1408 void wxApp::MacHandleKeyUpEvent( EventRecord
*ev
)
1413 void wxApp::MacHandleActivateEvent( EventRecord
*ev
)
1415 WindowRef window
= (WindowRef
) ev
->message
;
1418 bool activate
= (ev
->modifiers
& activeFlag
) ;
1419 WindowClass wclass
;
1420 UMAGetWindowClass ( window
, &wclass
) ;
1421 if ( wclass
== kFloatingWindowClass
)
1423 // if it is a floater we activate/deactivate the front non-floating window instead
1424 window
= UMAFrontNonFloatingWindow() ;
1426 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1428 win
->MacActivate( ev
, activate
) ;
1432 void wxApp::MacHandleUpdateEvent( EventRecord
*ev
)
1434 WindowRef window
= (WindowRef
) ev
->message
;
1435 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1438 win
->MacUpdate( ev
) ;
1442 // since there is no way of telling this foreign window to update itself
1443 // we have to invalidate the update region otherwise we keep getting the same
1444 // event over and over again
1445 BeginUpdate( window
) ;
1446 EndUpdate( window
) ;
1450 void wxApp::MacHandleDiskEvent( EventRecord
*ev
)
1452 if ( HiWord( ev
->message
) != noErr
)
1457 SetPt( &point
, 100 , 100 ) ;
1459 err
= DIBadMount( point
, ev
->message
) ;
1460 wxASSERT( err
== noErr
) ;
1465 void wxApp::MacHandleOSEvent( EventRecord
*ev
)
1467 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
1469 case suspendResumeMessage
:
1471 bool isResuming
= ev
->message
& resumeFlag
;
1472 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
1473 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
1476 WindowRef oldFrontWindow
= NULL
;
1477 WindowRef newFrontWindow
= NULL
;
1479 // in case we don't take care of activating ourselves, we have to synchronize
1480 // our idea of the active window with the process manager's - which it already activated
1482 if ( !doesActivate
)
1483 oldFrontWindow
= UMAFrontNonFloatingWindow() ;
1485 MacResume( convertClipboard
) ;
1487 newFrontWindow
= UMAFrontNonFloatingWindow() ;
1489 if ( oldFrontWindow
)
1491 wxWindow
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
1493 win
->MacActivate( ev
, false ) ;
1495 if ( newFrontWindow
)
1497 wxWindow
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
1499 win
->MacActivate( ev
, true ) ;
1504 MacSuspend( convertClipboard
) ;
1506 // in case this suspending did close an active window, another one might
1507 // have surfaced -> lets deactivate that one
1509 WindowRef newActiveWindow
= UMAGetActiveNonFloatingWindow() ;
1510 if ( newActiveWindow
)
1512 wxWindow
* win
= wxFindWinFromMacWindow( newActiveWindow
) ;
1514 win
->MacActivate( ev
, false ) ;
1519 case mouseMovedMessage
:
1523 wxWindow
* currentMouseWindow
= NULL
;
1525 wxWindow::MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) ,
1526 ¤tMouseWindow
) ;
1528 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
1530 wxMouseEvent event
;
1532 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1533 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1535 event
.m_leftDown
= isDown
&& !controlDown
;
1536 event
.m_middleDown
= FALSE
;
1537 event
.m_rightDown
= isDown
&& controlDown
;
1538 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1539 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1540 event
.m_altDown
= ev
->modifiers
& optionKey
;
1541 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1542 event
.m_x
= ev
->where
.h
;
1543 event
.m_y
= ev
->where
.v
;
1544 event
.m_timeStamp
= ev
->when
;
1545 event
.SetEventObject(this);
1547 if ( wxWindow::s_lastMouseWindow
)
1549 wxMouseEvent
eventleave(event
) ;
1550 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
) ;
1551 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
1553 if ( currentMouseWindow
)
1555 wxMouseEvent
evententer(event
) ;
1556 evententer
.SetEventType( wxEVT_ENTER_WINDOW
) ;
1557 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
1559 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
1562 short windowPart
= ::FindWindow(ev
->where
, &window
);
1566 // fixes for setting the cursor back from dominic mazzoni
1568 UMAShowArrowCursor();
1571 UMAShowArrowCursor();
1575 if ( s_lastMouseDown
== 0 )
1576 ev
->modifiers
|= btnState
;
1578 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1580 win
->MacMouseMoved( ev
, windowPart
) ;
1582 UMAShowArrowCursor();
1593 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
1596 return; // no menu item selected
1598 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
1601 Str255 deskAccessoryName
;
1604 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
1605 GetPort(&savedPort
);
1606 OpenDeskAcc(deskAccessoryName
);
1612 wxWindow
* frontwindow
= wxFindWinFromMacWindow( ::FrontWindow() ) ;
1613 if ( frontwindow
&& wxMenuBar::MacGetInstalledMenuBar() )
1614 wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow
->GetEventHandler() , 0 , macMenuId
, macMenuItemNum
) ;
1620 long wxApp::MacTranslateKey(char key, int mods)
1624 void wxApp::MacAdjustCursor()
1631 wxApp::macAdjustCursor()
1633 if (ev->what != kHighLevelEvent)
1635 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1638 if (!theMacWxFrame->MacAdjustCursor(ev->where))
1639 ::SetCursor(&(qd.arrow));