1 /////////////////////////////////////////////////////////////////////////////
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "app.h"
19 #include "wx/gdicmn.h"
22 #include "wx/cursor.h"
24 #include "wx/palette.h"
26 #include "wx/dialog.h"
27 #include "wx/msgdlg.h"
29 #include "wx/module.h"
30 #include "wx/memory.h"
32 #if wxUSE_WX_RESOURCES
33 #include "wx/resource.h"
46 #include <wx/mac/uma.h>
48 extern char *wxBuffer
;
49 extern wxList wxPendingDelete
;
50 extern wxList
*wxWinMacWindowList
;
51 extern wxList
*wxWinMacControlList
;
53 wxApp
*wxTheApp
= NULL
;
55 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
56 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
57 EVT_IDLE(wxApp::OnIdle
)
61 const short kMacMinHeap
= (29 * 1024) ;
62 // platform specific static variables
64 const short kwxMacMenuBarResource
= 1 ;
65 const short kwxMacAppleMenuId
= 1 ;
67 RgnHandle
wxApp::s_macCursorRgn
= NULL
;
68 wxWindow
* wxApp::s_captureWindow
= NULL
;
69 int wxApp::s_lastMouseDown
= 0 ;
70 long wxApp::sm_lastMessageTime
= 0;
74 bool wxApp::s_macDefaultEncodingIsPC
= true ;
75 bool wxApp::s_macSupportPCMenuShortcuts
= true ;
76 long wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
77 wxString
wxApp::s_macHelpMenuTitleName
= "&Help" ;
79 OSErr
AEHandleODoc( AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
81 wxApp
* app
= (wxApp
*) refcon
;
82 return wxTheApp
->MacHandleAEODoc( event
, reply
) ;
85 OSErr
AEHandleOApp( AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
87 wxApp
* app
= (wxApp
*) refcon
;
88 return wxTheApp
->MacHandleAEOApp( event
, reply
) ;
91 OSErr
AEHandlePDoc( AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
93 wxApp
* app
= (wxApp
*) refcon
;
94 return wxTheApp
->MacHandleAEPDoc( event
, reply
) ;
97 OSErr
AEHandleQuit( AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
99 wxApp
* app
= (wxApp
*) refcon
;
100 return wxTheApp
->MacHandleAEQuit( event
, reply
) ;
103 OSErr
wxApp::MacHandleAEODoc(AppleEvent
*event
, AppleEvent
*reply
)
105 ProcessSerialNumber PSN
;
106 PSN
.highLongOfPSN
= 0 ;
107 PSN
.lowLongOfPSN
= kCurrentProcess
;
108 SetFrontProcess( &PSN
) ;
112 OSErr
wxApp::MacHandleAEPDoc(AppleEvent
*event
, AppleEvent
*reply
)
117 OSErr
wxApp::MacHandleAEOApp(AppleEvent
*event
, AppleEvent
*reply
)
122 OSErr
wxApp::MacHandleAEQuit(AppleEvent
*event
, AppleEvent
*reply
)
124 wxWindow
* win
= GetTopWindow() ;
136 char StringMac
[] = "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
137 "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
138 "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf"
139 "\xb1\xb4\xb5\xb6\xbb\xbc\xbe\xbf"
140 "\xc0\xc1\xc2\xc4\xc7\xc8\xc9\xcb\xcc\xcd\xce\xcf"
141 "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xca\xdb" ;
143 char StringANSI
[] = "\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8"
144 "\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC"
145 "\x86\xBA\xA2\xA3\xA7\x95\xB6\xDF\xAE\xA9\x99\xB4\xA8\xC6\xD8"
146 "\xB1\xA5\xB5\xF0\xAA\xBA\xE6\xF8"
147 "\xBF\xA1\xAC\x83\xAB\xBB\x85\xC0\xC3\xD5\x8C\x9C"
148 "\x96\x97\x93\x94\x91\x92\xF7\xFF\xA0\x80" ;
150 void wxMacConvertFromPC( const char *from
, char *to
, int len
)
155 for( int i
= 0 ; i
< len
; ++ i
)
157 c
= strchr( StringANSI
, *from
) ;
160 *to
= StringMac
[ c
- StringANSI
] ;
168 for( int i
= 0 ; i
< len
; ++ i
)
170 c
= strchr( StringANSI
, *from
) ;
173 *to
= StringMac
[ c
- StringANSI
] ;
185 void wxMacConvertToPC( const char *from
, char *to
, int len
)
190 for( int i
= 0 ; i
< len
; ++ i
)
192 c
= strchr( StringMac
, *from
) ;
195 *to
= StringANSI
[ c
- StringMac
] ;
203 for( int i
= 0 ; i
< len
; ++ i
)
205 c
= strchr( StringMac
, *from
) ;
208 *to
= StringANSI
[ c
- StringMac
] ;
220 void wxMacConvertFromPC( char * p
)
223 int len
= strlen ( p
) ;
225 wxMacConvertFromPC( ptr
, ptr
, len
) ;
228 void wxMacConvertFromPCForControls( char * p
)
231 int len
= strlen ( p
) ;
233 wxMacConvertFromPC( ptr
, ptr
, len
) ;
234 for ( int i
= 0 ; i
< strlen ( ptr
) ; i
++ )
236 if ( ptr
[i
] == '&' && ptr
[i
]+1 != ' ' )
238 memmove( &ptr
[i
] , &ptr
[i
+1] , strlen( &ptr
[i
+1] ) + 1) ;
243 void wxMacConvertFromPC( unsigned char *p
)
245 char *ptr
= (char*) p
+ 1 ;
248 wxMacConvertFromPC( ptr
, ptr
, len
) ;
251 extern char *wxBuffer
;
253 wxString
wxMacMakeMacStringFromPC( const char * p
)
255 const char *ptr
= p
;
256 int len
= strlen ( p
) ;
257 char *buf
= wxBuffer
;
259 if ( len
>= BUFSIZ
+ 512 )
261 buf
= new char [len
+1] ;
264 wxMacConvertFromPC( ptr
, buf
, len
) ;
266 wxString
result( buf
) ;
267 if ( buf
!= wxBuffer
)
273 void wxMacConvertToPC( char * p
)
276 int len
= strlen ( p
) ;
278 wxMacConvertToPC( ptr
, ptr
, len
) ;
281 void wxMacConvertToPC( unsigned char *p
)
283 char *ptr
= (char*) p
+ 1 ;
286 wxMacConvertToPC( ptr
, ptr
, len
) ;
289 wxString
wxMacMakePCStringFromMac( 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 wxMacConvertToPC( ptr
, buf
, len
) ;
303 wxString
result( buf
) ;
304 if ( buf
!= wxBuffer
)
311 bool wxApp::Initialize()
317 UMAInitToolbox( 4 ) ;
318 UMAShowWatchCursor() ;
320 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
, NewAEEventHandlerProc(AEHandleODoc
) , (long) wxTheApp
, FALSE
) ;
321 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
, NewAEEventHandlerProc(AEHandleOApp
) , (long) wxTheApp
, FALSE
) ;
322 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
, NewAEEventHandlerProc(AEHandlePDoc
) , (long) wxTheApp
, FALSE
) ;
323 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
, NewAEEventHandlerProc(AEHandleQuit
) , (long) wxTheApp
, FALSE
) ;
325 GUSISetup(GUSIwithInternetSockets
);
329 // test the minimal configuration necessary
334 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
336 error
= kMacSTRWrongMachine
;
338 else if (theMachine
< gestaltMacPlus
)
340 error
= kMacSTRWrongMachine
;
342 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
344 error
= kMacSTROldSystem
;
346 else if ( theSystem
< 0x0750 )
348 error
= kMacSTROldSystem
;
351 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
353 error
= kMacSTRSmallSize
;
359 if ( !UMAHasAppearance() )
361 error = kMacSTRNoPre8Yet ;
366 // if we encountered any problems so far, give the error code and exit immediately
373 GetIndString(message
, 128, error
);
374 UMAShowArrowCursor() ;
375 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
376 itemHit
= Alert(128, nil
);
380 #if __option(profile)
381 ProfilerInit( collectDetailed
, bestTimeBase
, 20000 , 30 ) ;
384 // now avoid exceptions thrown for new (bad_alloc)
386 std::__throws_bad_alloc
= FALSE
;
388 s_macCursorRgn
= ::NewRgn() ;
391 wxBuffer
= new char[1500];
393 wxBuffer
= new char[BUFSIZ
+ 512];
397 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
399 streambuf* sBuf = new wxDebugStreamBuf;
400 ostream* oStr = new ostream(sBuf) ;
401 wxDebugContext::SetStream(oStr, sBuf);
405 wxClassInfo::InitializeClasses();
407 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
408 wxTheColourDatabase
->Initialize();
410 wxInitializeStockLists();
411 wxInitializeStockObjects();
413 #if wxUSE_WX_RESOURCES
414 wxInitializeResourceSystem();
417 wxBitmap::InitStandardHandlers();
419 wxModule::RegisterModules();
420 if (!wxModule::InitializeModules())
423 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
424 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
426 UMAShowArrowCursor() ;
431 void wxApp::CleanUp()
433 wxModule::CleanUpModules();
435 #if wxUSE_WX_RESOURCES
436 wxCleanUpResourceSystem();
439 wxDeleteStockObjects() ;
441 // Destroy all GDI lists, etc.
443 delete wxTheBrushList
;
444 wxTheBrushList
= NULL
;
449 delete wxTheFontList
;
450 wxTheFontList
= NULL
;
452 delete wxTheBitmapList
;
453 wxTheBitmapList
= NULL
;
455 delete wxTheColourDatabase
;
456 wxTheColourDatabase
= NULL
;
458 wxBitmap::CleanUpHandlers();
463 if (wxWinMacWindowList
)
464 delete wxWinMacWindowList
;
466 wxClassInfo::CleanUpClasses();
468 #if __option(profile)
469 ProfilerDump( "\papp.prof" ) ;
476 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
477 // At this point we want to check if there are any memory
478 // blocks that aren't part of the wxDebugContext itself,
479 // as a special case. Then when dumping we need to ignore
480 // wxDebugContext, too.
481 if (wxDebugContext::CountObjectsLeft() > 0)
483 wxTrace("There were memory leaks.\n");
484 wxDebugContext::Dump();
485 wxDebugContext::PrintStatistics();
487 // wxDebugContext::SetStream(NULL, NULL);
490 // do it as the very last thing because everything else can log messages
491 wxLog::DontCreateOnDemand();
492 // do it as the very last thing because everything else can log messages
493 delete wxLog::SetActiveTarget(NULL
);
497 ::DisposeRgn(s_macCursorRgn
);
503 int wxEntry( int argc
, char *argv
[] )
506 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
507 // This seems to be necessary since there are 'rogue'
508 // objects present at this point (perhaps global objects?)
509 // Setting a checkpoint will ignore them as far as the
510 // memory checking facility is concerned.
511 // Of course you may argue that memory allocated in globals should be
512 // checked, but this is a reasonable compromise.
513 wxDebugContext::SetCheckpoint();
516 if (!wxApp::Initialize())
520 if (!wxApp::GetInitializerFunction())
522 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
526 wxTheApp
= (wxApp
*) (* wxApp::GetInitializerFunction()) ();
531 printf( "wxWindows error: wxTheApp == NULL\n" );
536 argc
= 1 ; // currently we don't support files as parameters
539 wxTheApp
->argc
= argc
;
540 wxTheApp
->argv
= argv
;
542 // GUI-specific initialization, such as creating an app context.
543 wxTheApp
->OnInitGui();
545 // we could try to get the open apple events here to adjust argc and argv better
548 // Here frames insert themselves automatically
549 // into wxTopLevelWindows by getting created
552 if (!wxTheApp
->OnInit()) return 0;
556 if (wxTheApp
->Initialized()) retValue
= wxTheApp
->OnRun();
558 if (wxTheApp
->GetTopWindow())
560 delete wxTheApp
->GetTopWindow();
561 wxTheApp
->SetTopWindow(NULL
);
564 wxTheApp
->DeletePendingObjects();
573 // Static member initialization
574 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
581 m_wantDebugOutput
= TRUE
;
586 m_printMode
= wxPRINT_WINDOWS
;
588 m_exitOnFrameDelete
= TRUE
;
592 bool wxApp::Initialized()
600 int wxApp::MainLoop()
612 // Returns TRUE if more time is needed.
613 bool wxApp::ProcessIdle()
616 event
.SetEventObject(this);
619 return event
.MoreRequested();
622 void wxApp::ExitMainLoop()
627 // Is a message/event pending?
628 bool wxApp::Pending()
632 return EventAvail( everyEvent
, &event
) ;
635 // Dispatch a message.
636 void wxApp::Dispatch()
641 void wxApp::OnIdle(wxIdleEvent
& event
)
643 static bool inOnIdle
= FALSE
;
645 // Avoid recursion (via ProcessEvent default case)
651 // 'Garbage' collection of windows deleted with Close().
652 DeletePendingObjects();
654 // flush the logged messages if any
655 wxLog
*pLog
= wxLog::GetActiveTarget();
656 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
659 // Send OnIdle events to all windows
660 bool needMore
= SendIdleEvents();
663 event
.RequestMore(TRUE
);
670 // **** please implement me! ****
671 // Wake up the idle handler processor, even if it is in another thread...
674 // Send idle event to all top-level windows
675 bool wxApp::SendIdleEvents()
677 bool needMore
= FALSE
;
678 wxNode
* node
= wxTopLevelWindows
.First();
681 wxWindow
* win
= (wxWindow
*) node
->Data();
682 if (SendIdleEvents(win
))
690 // Send idle event to window and all subwindows
691 bool wxApp::SendIdleEvents(wxWindow
* win
)
693 bool needMore
= FALSE
;
696 event
.SetEventObject(win
);
697 win
->ProcessEvent(event
);
699 if (event
.MoreRequested())
702 wxNode
* node
= win
->GetChildren().First();
705 wxWindow
* win
= (wxWindow
*) node
->Data();
706 if (SendIdleEvents(win
))
714 void wxApp::DeletePendingObjects()
716 wxNode
*node
= wxPendingDelete
.First();
719 wxObject
*obj
= (wxObject
*)node
->Data();
723 if (wxPendingDelete
.Member(obj
))
726 // Deleting one object may have deleted other pending
727 // objects, so start from beginning of list again.
728 node
= wxPendingDelete
.First();
732 wxLog
* wxApp::CreateLogTarget()
737 wxWindow
* wxApp::GetTopWindow() const
741 else if (wxTopLevelWindows
.Number() > 0)
742 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
753 // Yield to other processes
756 // YieldToAnyThread() ;
761 // platform specifics
763 void wxApp::MacSuspend( bool convertClipboard
)
765 s_lastMouseDown
= 0 ;
766 if( convertClipboard
)
768 MacConvertPrivateToPublicScrap() ;
771 UMAHideFloatingWindows() ;
774 void wxApp::MacResume( bool convertClipboard
)
776 s_lastMouseDown
= 0 ;
777 if( convertClipboard
)
779 MacConvertPublicToPrivateScrap() ;
782 UMAShowFloatingWindows() ;
785 void wxApp::MacConvertPrivateToPublicScrap()
791 void wxApp::MacConvertPublicToPrivateScrap()
796 void wxApp::MacDoOneEvent()
800 long sleepTime
= ::GetCaretTime();
802 if (WaitNextEvent(everyEvent
, &event
,sleepTime
, s_macCursorRgn
))
804 MacHandleOneEvent( &event
);
809 WindowPtr window
= UMAFrontWindow() ;
811 UMAIdleControls( window
) ;
813 wxTheApp
->ProcessIdle() ;
815 if ( event
.what
!= kHighLevelEvent
)
816 SetRectRgn( s_macCursorRgn
, event
.where
.h
- 1 , event
.where
.v
- 1, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
821 wxMacProcessSocketEvents() ;
825 void wxApp::MacHandleOneEvent( EventRecord
*ev
)
827 m_macCurrentEvent
= ev
;
829 wxApp::sm_lastMessageTime
= ev
->when
;
834 MacHandleMouseDownEvent( ev
) ;
835 if ( ev
->modifiers
& controlKey
)
841 if ( s_lastMouseDown
== 2 )
843 ev
->modifiers
|= controlKey
;
847 ev
->modifiers
&= ~controlKey
;
849 MacHandleMouseUpEvent( ev
) ;
853 MacHandleActivateEvent( ev
) ;
856 MacHandleUpdateEvent( ev
) ;
860 MacHandleKeyDownEvent( ev
) ;
863 MacHandleKeyUpEvent( ev
) ;
866 MacHandleDiskEvent( ev
) ;
869 MacHandleOSEvent( ev
) ;
871 case kHighLevelEvent
:
872 MacHandleHighLevelEvent( ev
) ;
879 void wxApp::MacHandleHighLevelEvent( EventRecord
*ev
)
881 ::AEProcessAppleEvent( ev
) ;
884 bool s_macIsInModalLoop
= false ;
886 void wxApp::MacHandleMouseDownEvent( EventRecord
*ev
)
889 WindowRef frontWindow
= UMAFrontNonFloatingWindow() ;
890 WindowAttributes frontWindowAttributes
= NULL
;
892 UMAGetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
894 short windowPart
= ::FindWindow(ev
->where
, &window
);
895 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
900 if ( s_macIsInModalLoop
)
906 UInt32 menuresult
= MenuSelect(ev
->where
) ;
907 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
912 SystemClick( ev
, window
) ;
916 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
922 DragWindow(window
, ev
->where
, &qd
.screenBits
.bounds
);
927 Point pt
= { 0, 0 } ;
930 LocalToGlobal( &pt
) ;
932 win
->SetSize( pt
.h
, pt
.v
, -1 ,
933 -1 , wxSIZE_USE_EXISTING
);
939 if (TrackGoAway(window
, ev
->where
))
947 int growResult
= GrowWindow(window
, ev
->where
, &qd
.screenBits
.bounds
);
950 int newWidth
= LoWord(growResult
);
951 int newHeight
= HiWord(growResult
);
952 int oldWidth
, oldHeight
;
954 win
->GetSize(&oldWidth
, &oldHeight
);
958 newHeight
= oldHeight
;
961 win
->SetSize( -1, -1, newWidth
, newHeight
, wxSIZE_USE_EXISTING
);
967 if (TrackBox(window
, ev
->where
, windowPart
))
969 // TODO setup size event
970 ZoomWindow( window
, windowPart
, false ) ;
972 win
->SetSize( -1, -1, window
->portRect
.right
-window
->portRect
.left
,
973 window
->portRect
.bottom
-window
->portRect
.top
, wxSIZE_USE_EXISTING
);
978 // TODO setup size event
983 if ( window
!= frontWindow
)
985 if ( s_macIsInModalLoop
)
989 else if ( UMAIsWindowFloating( window
) )
992 win
->MacMouseDown( ev
, windowPart
) ;
996 UMASelectWindow( window
) ;
1002 win
->MacMouseDown( ev
, windowPart
) ;
1011 void wxApp::MacHandleMouseUpEvent( EventRecord
*ev
)
1015 short windowPart
= ::FindWindow(ev
->where
, &window
);
1025 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1027 win
->MacMouseUp( ev
, windowPart
) ;
1033 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1042 retval
= WXK_RETURN
;
1057 retval
= WXK_PAGEUP
;
1060 retval
= WXK_PAGEDOWN
;
1063 retval
= WXK_RETURN
;
1118 retval
= WXK_ESCAPE
;
1124 retval
= WXK_RIGHT
;
1133 retval
= WXK_DELETE
;
1141 void wxApp::MacHandleKeyDownEvent( EventRecord
*ev
)
1143 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1144 if ( HiWord( menuresult
) )
1145 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1150 keychar
= short(ev
->message
& charCodeMask
);
1151 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1153 wxWindow
* focus
= wxWindow::FindFocus() ;
1156 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1158 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1159 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1160 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1161 event
.m_altDown
= ev
->modifiers
& optionKey
;
1162 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1163 event
.m_keyCode
= keyval
;
1164 event
.m_x
= ev
->where
.h
;
1165 event
.m_y
= ev
->where
.v
;
1166 event
.m_timeStamp
= ev
->when
;
1167 event
.SetEventObject(focus
);
1168 bool handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1174 wxWindow
*ancestor
= focus
;
1178 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1181 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1182 handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
1185 if (ancestor->m_isFrame)
1187 ancestor = ancestor->GetParent();
1191 #endif // wxUSE_ACCEL
1195 wxKeyEvent
event(wxEVT_CHAR
);
1196 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1197 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1198 event
.m_altDown
= ev
->modifiers
& optionKey
;
1199 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1200 event
.m_keyCode
= keyval
;
1201 event
.m_x
= ev
->where
.h
;
1202 event
.m_y
= ev
->where
.v
;
1203 event
.m_timeStamp
= ev
->when
;
1204 event
.SetEventObject(focus
);
1205 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1208 (keyval
== WXK_TAB
) &&
1209 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1210 (focus
->GetParent()) &&
1211 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1213 wxNavigationKeyEvent new_event
;
1214 new_event
.SetEventObject( focus
);
1215 new_event
.SetDirection( !event
.ShiftDown() );
1216 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1217 new_event
.SetWindowChange( event
.ControlDown() );
1218 new_event
.SetCurrentFocus( focus
);
1219 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1221 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1223 (keyval
== '.' && event
.ControlDown() ) )
1225 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1226 new_event
.SetEventObject( focus
);
1227 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1233 void wxApp::MacHandleKeyUpEvent( EventRecord
*ev
)
1238 void wxApp::MacHandleActivateEvent( EventRecord
*ev
)
1240 WindowRef window
= (WindowRef
) ev
->message
;
1243 bool activate
= (ev
->modifiers
& activeFlag
) ;
1244 WindowClass wclass
;
1245 UMAGetWindowClass ( window
, &wclass
) ;
1246 if ( wclass
== kFloatingWindowClass
)
1248 // if it is a floater we activate/deactivate the front non-floating window instead
1249 window
= UMAFrontNonFloatingWindow() ;
1251 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1253 win
->MacActivate( ev
, activate
) ;
1257 void wxApp::MacHandleUpdateEvent( EventRecord
*ev
)
1259 WindowRef window
= (WindowRef
) ev
->message
;
1260 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1263 win
->MacUpdate( ev
) ;
1267 void wxApp::MacHandleDiskEvent( EventRecord
*ev
)
1269 if ( HiWord( ev
->message
) != noErr
)
1273 SetPt( &point
, 100 , 100 ) ;
1275 err
= DIBadMount( point
, ev
->message
) ;
1276 wxASSERT( err
== noErr
) ;
1280 void wxApp::MacHandleOSEvent( EventRecord
*ev
)
1282 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
1284 case suspendResumeMessage
:
1286 bool isResuming
= ev
->message
& resumeFlag
;
1287 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
1288 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
1291 WindowRef oldFrontWindow
= NULL
;
1292 WindowRef newFrontWindow
= NULL
;
1294 // in case we don't take care of activating ourselves, we have to synchronize
1295 // our idea of the active window with the process manager's - which it already activated
1297 if ( !doesActivate
)
1298 oldFrontWindow
= UMAFrontNonFloatingWindow() ;
1300 MacResume( convertClipboard
) ;
1302 newFrontWindow
= UMAFrontNonFloatingWindow() ;
1304 if ( oldFrontWindow
)
1306 wxWindow
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
1308 win
->MacActivate( ev
, false ) ;
1310 if ( newFrontWindow
)
1312 wxWindow
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
1314 win
->MacActivate( ev
, true ) ;
1319 MacSuspend( convertClipboard
) ;
1321 // in case this suspending did close an active window, another one might
1322 // have surfaced -> lets deactivate that one
1324 WindowRef newActiveWindow
= UMAGetActiveNonFloatingWindow() ;
1325 if ( newActiveWindow
)
1327 wxWindow
* win
= wxFindWinFromMacWindow( newActiveWindow
) ;
1329 win
->MacActivate( ev
, false ) ;
1334 case mouseMovedMessage
:
1338 wxWindow
* currentMouseWindow
= NULL
;
1340 MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) , ¤tMouseWindow
) ;
1342 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
1344 wxMouseEvent event
;
1346 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1347 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1349 event
.m_leftDown
= isDown
&& !controlDown
;
1350 event
.m_middleDown
= FALSE
;
1351 event
.m_rightDown
= isDown
&& controlDown
;
1352 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1353 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1354 event
.m_altDown
= ev
->modifiers
& optionKey
;
1355 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1356 event
.m_x
= ev
->where
.h
;
1357 event
.m_y
= ev
->where
.v
;
1358 event
.m_timeStamp
= ev
->when
;
1359 event
.SetEventObject(this);
1361 if ( wxWindow::s_lastMouseWindow
)
1363 wxMouseEvent
eventleave(event
) ;
1364 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
) ;
1365 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
1367 if ( currentMouseWindow
)
1369 wxMouseEvent
evententer(event
) ;
1370 evententer
.SetEventType( wxEVT_ENTER_WINDOW
) ;
1371 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
1373 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
1376 short windowPart
= ::FindWindow(ev
->where
, &window
);
1386 if ( s_lastMouseDown
== 0 )
1387 ev
->modifiers
|= btnState
;
1389 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1391 win
->MacMouseMoved( ev
, windowPart
) ;
1401 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
1404 return; // no menu item selected
1406 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
1409 Str255 deskAccessoryName
;
1412 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
1413 GetPort(&savedPort
);
1414 OpenDeskAcc(deskAccessoryName
);
1420 wxWindow
* frontwindow
= wxFindWinFromMacWindow( ::FrontWindow() ) ;
1421 if ( frontwindow
&& wxMenuBar::MacGetInstalledMenuBar() )
1422 wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow
->GetEventHandler() , 0 , macMenuId
, macMenuItemNum
) ;
1428 long wxApp::MacTranslateKey(char key, int mods)
1432 void wxApp::MacAdjustCursor()
1439 wxApp::macAdjustCursor()
1441 if (ev->what != kHighLevelEvent)
1443 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1446 if (!theMacWxFrame->MacAdjustCursor(ev->where))
1447 ::SetCursor(&(qd.arrow));