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 #if !USE_SHARED_LIBRARY
56 IMPLEMENT_DYNAMIC_CLASS(wxApp
, wxEvtHandler
)
57 BEGIN_EVENT_TABLE(wxApp
, wxEvtHandler
)
58 EVT_IDLE(wxApp::OnIdle
)
63 const short kMacMinHeap
= (29 * 1024) ;
64 // platform specific static variables
66 const short kwxMacMenuBarResource
= 1 ;
67 const short kwxMacAppleMenuId
= 1 ;
69 RgnHandle
wxApp::s_macCursorRgn
= NULL
;
70 wxWindow
* wxApp::s_captureWindow
= NULL
;
71 int wxApp::s_lastMouseDown
= 0 ;
72 long wxApp::sm_lastMessageTime
= 0;
76 bool wxApp::s_macDefaultEncodingIsPC
= true ;
77 bool wxApp::s_macSupportPCMenuShortcuts
= true ;
78 long wxApp::s_macAboutMenuItemId
= wxID_ABOUT
;
79 wxString
wxApp::s_macHelpMenuTitleName
= "&Help" ;
81 OSErr
AEHandleODoc( AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
83 wxApp
* app
= (wxApp
*) refcon
;
84 return wxTheApp
->MacHandleAEODoc( event
, reply
) ;
87 OSErr
AEHandleOApp( AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
89 wxApp
* app
= (wxApp
*) refcon
;
90 return wxTheApp
->MacHandleAEOApp( event
, reply
) ;
93 OSErr
AEHandlePDoc( AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
95 wxApp
* app
= (wxApp
*) refcon
;
96 return wxTheApp
->MacHandleAEPDoc( event
, reply
) ;
99 OSErr
AEHandleQuit( AppleEvent
*event
, AppleEvent
*reply
, long refcon
)
101 wxApp
* app
= (wxApp
*) refcon
;
102 return wxTheApp
->MacHandleAEQuit( event
, reply
) ;
105 OSErr
wxApp::MacHandleAEODoc(AppleEvent
*event
, AppleEvent
*reply
)
107 ProcessSerialNumber PSN
;
108 PSN
.highLongOfPSN
= 0 ;
109 PSN
.lowLongOfPSN
= kCurrentProcess
;
110 SetFrontProcess( &PSN
) ;
114 OSErr
wxApp::MacHandleAEPDoc(AppleEvent
*event
, AppleEvent
*reply
)
119 OSErr
wxApp::MacHandleAEOApp(AppleEvent
*event
, AppleEvent
*reply
)
124 OSErr
wxApp::MacHandleAEQuit(AppleEvent
*event
, AppleEvent
*reply
)
126 wxWindow
* win
= GetTopWindow() ;
138 char StringMac
[] = "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f"
139 "\x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f"
140 "\xa0\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf"
141 "\xb1\xb4\xb5\xb6\xbb\xbc\xbe\xbf"
142 "\xc0\xc1\xc2\xc4\xc7\xc8\xc9\xcb\xcc\xcd\xce\xcf"
143 "\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xca\xdb" ;
145 char StringANSI
[] = "\xC4\xC5\xC7\xC9\xD1\xD6\xDC\xE1\xE0\xE2\xE4\xE3\xE5\xE7\xE9\xE8"
146 "\xEA\xEB\xED\xEC\xEE\xEF\xF1\xF3\xF2\xF4\xF6\xF5\xFA\xF9\xFB\xFC"
147 "\x86\xBA\xA2\xA3\xA7\x95\xB6\xDF\xAE\xA9\x99\xB4\xA8\xC6\xD8"
148 "\xB1\xA5\xB5\xF0\xAA\xBA\xE6\xF8"
149 "\xBF\xA1\xAC\x83\xAB\xBB\x85\xC0\xC3\xD5\x8C\x9C"
150 "\x96\x97\x93\x94\x91\x92\xF7\xFF\xA0\x80" ;
152 void wxMacConvertFromPC( const char *from
, char *to
, int len
)
157 for( int i
= 0 ; i
< len
; ++ i
)
159 c
= strchr( StringANSI
, *from
) ;
162 *to
= StringMac
[ c
- StringANSI
] ;
170 for( int i
= 0 ; i
< len
; ++ i
)
172 c
= strchr( StringANSI
, *from
) ;
175 *to
= StringMac
[ c
- StringANSI
] ;
187 void wxMacConvertToPC( const char *from
, char *to
, int len
)
192 for( int i
= 0 ; i
< len
; ++ i
)
194 c
= strchr( StringMac
, *from
) ;
197 *to
= StringANSI
[ c
- StringMac
] ;
205 for( int i
= 0 ; i
< len
; ++ i
)
207 c
= strchr( StringMac
, *from
) ;
210 *to
= StringANSI
[ c
- StringMac
] ;
222 void wxMacConvertFromPC( char * p
)
225 int len
= strlen ( p
) ;
227 wxMacConvertFromPC( ptr
, ptr
, len
) ;
230 void wxMacConvertFromPCForControls( char * p
)
233 int len
= strlen ( p
) ;
235 wxMacConvertFromPC( ptr
, ptr
, len
) ;
236 for ( int i
= 0 ; i
< strlen ( ptr
) ; i
++ )
238 if ( ptr
[i
] == '&' && ptr
[i
]+1 != ' ' )
240 memmove( &ptr
[i
] , &ptr
[i
+1] , strlen( &ptr
[i
+1] ) + 1) ;
245 void wxMacConvertFromPC( unsigned char *p
)
247 char *ptr
= (char*) p
+ 1 ;
250 wxMacConvertFromPC( ptr
, ptr
, len
) ;
253 extern char *wxBuffer
;
255 wxString
wxMacMakeMacStringFromPC( const char * p
)
257 const char *ptr
= p
;
258 int len
= strlen ( p
) ;
259 char *buf
= wxBuffer
;
261 if ( len
>= BUFSIZ
+ 512 )
263 buf
= new char [len
+1] ;
266 wxMacConvertFromPC( ptr
, buf
, len
) ;
268 wxString
result( buf
) ;
269 if ( buf
!= wxBuffer
)
275 void wxMacConvertToPC( char * p
)
278 int len
= strlen ( p
) ;
280 wxMacConvertToPC( ptr
, ptr
, len
) ;
283 void wxMacConvertToPC( unsigned char *p
)
285 char *ptr
= (char*) p
+ 1 ;
288 wxMacConvertToPC( ptr
, ptr
, len
) ;
291 wxString
wxMacMakePCStringFromMac( const char * p
)
293 const char *ptr
= p
;
294 int len
= strlen ( p
) ;
295 char *buf
= wxBuffer
;
297 if ( len
>= BUFSIZ
+ 512 )
299 buf
= new char [len
+1] ;
302 wxMacConvertToPC( ptr
, buf
, len
) ;
305 wxString
result( buf
) ;
306 if ( buf
!= wxBuffer
)
313 bool wxApp::Initialize()
319 UMAInitToolbox( 4 ) ;
320 UMAShowWatchCursor() ;
322 AEInstallEventHandler( kCoreEventClass
, kAEOpenDocuments
, NewAEEventHandlerProc(AEHandleODoc
) , (long) wxTheApp
, FALSE
) ;
323 AEInstallEventHandler( kCoreEventClass
, kAEOpenApplication
, NewAEEventHandlerProc(AEHandleOApp
) , (long) wxTheApp
, FALSE
) ;
324 AEInstallEventHandler( kCoreEventClass
, kAEPrintDocuments
, NewAEEventHandlerProc(AEHandlePDoc
) , (long) wxTheApp
, FALSE
) ;
325 AEInstallEventHandler( kCoreEventClass
, kAEQuitApplication
, NewAEEventHandlerProc(AEHandleQuit
) , (long) wxTheApp
, FALSE
) ;
327 GUSISetup(GUSIwithInternetSockets
);
331 // test the minimal configuration necessary
336 if (Gestalt(gestaltMachineType
, &theMachine
) != noErr
)
338 error
= kMacSTRWrongMachine
;
340 else if (theMachine
< gestaltMacPlus
)
342 error
= kMacSTRWrongMachine
;
344 else if (Gestalt(gestaltSystemVersion
, &theSystem
) != noErr
)
346 error
= kMacSTROldSystem
;
348 else if ( theSystem
< 0x0750 )
350 error
= kMacSTROldSystem
;
353 else if ((long)GetApplLimit() - (long)ApplicationZone() < kMacMinHeap
)
355 error
= kMacSTRSmallSize
;
361 if ( !UMAHasAppearance() )
363 error = kMacSTRNoPre8Yet ;
368 // if we encountered any problems so far, give the error code and exit immediately
375 GetIndString(message
, 128, error
);
376 UMAShowArrowCursor() ;
377 ParamText("\pFatal Error", message
, (ConstStr255Param
)"\p", (ConstStr255Param
)"\p");
378 itemHit
= Alert(128, nil
);
382 #if __option(profile)
383 ProfilerInit( collectDetailed
, bestTimeBase
, 20000 , 30 ) ;
386 // now avoid exceptions thrown for new (bad_alloc)
388 std::__throws_bad_alloc
= FALSE
;
390 s_macCursorRgn
= ::NewRgn() ;
393 wxBuffer
= new char[1500];
395 wxBuffer
= new char[BUFSIZ
+ 512];
399 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
401 streambuf* sBuf = new wxDebugStreamBuf;
402 ostream* oStr = new ostream(sBuf) ;
403 wxDebugContext::SetStream(oStr, sBuf);
407 wxClassInfo::InitializeClasses();
409 wxTheColourDatabase
= new wxColourDatabase(wxKEY_STRING
);
410 wxTheColourDatabase
->Initialize();
412 wxInitializeStockLists();
413 wxInitializeStockObjects();
415 #if wxUSE_WX_RESOURCES
416 wxInitializeResourceSystem();
419 wxBitmap::InitStandardHandlers();
421 wxModule::RegisterModules();
422 if (!wxModule::InitializeModules())
425 wxWinMacWindowList
= new wxList(wxKEY_INTEGER
);
426 wxWinMacControlList
= new wxList(wxKEY_INTEGER
);
428 UMAShowArrowCursor() ;
433 void wxApp::CleanUp()
435 wxModule::CleanUpModules();
437 #if wxUSE_WX_RESOURCES
438 wxCleanUpResourceSystem();
441 wxDeleteStockObjects() ;
443 // Destroy all GDI lists, etc.
445 delete wxTheBrushList
;
446 wxTheBrushList
= NULL
;
451 delete wxTheFontList
;
452 wxTheFontList
= NULL
;
454 delete wxTheBitmapList
;
455 wxTheBitmapList
= NULL
;
457 delete wxTheColourDatabase
;
458 wxTheColourDatabase
= NULL
;
460 wxBitmap::CleanUpHandlers();
465 if (wxWinMacWindowList
)
466 delete wxWinMacWindowList
;
468 wxClassInfo::CleanUpClasses();
470 #if __option(profile)
471 ProfilerDump( "\papp.prof" ) ;
478 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
479 // At this point we want to check if there are any memory
480 // blocks that aren't part of the wxDebugContext itself,
481 // as a special case. Then when dumping we need to ignore
482 // wxDebugContext, too.
483 if (wxDebugContext::CountObjectsLeft() > 0)
485 wxTrace("There were memory leaks.\n");
486 wxDebugContext::Dump();
487 wxDebugContext::PrintStatistics();
489 // wxDebugContext::SetStream(NULL, NULL);
492 // do it as the very last thing because everything else can log messages
493 wxLog::DontCreateOnDemand();
494 // do it as the very last thing because everything else can log messages
495 delete wxLog::SetActiveTarget(NULL
);
499 ::DisposeRgn(s_macCursorRgn
);
505 int wxEntry( int argc
, char *argv
[] )
508 #if (defined(__WXDEBUG__) && wxUSE_MEMORY_TRACING) || wxUSE_DEBUG_CONTEXT
509 // This seems to be necessary since there are 'rogue'
510 // objects present at this point (perhaps global objects?)
511 // Setting a checkpoint will ignore them as far as the
512 // memory checking facility is concerned.
513 // Of course you may argue that memory allocated in globals should be
514 // checked, but this is a reasonable compromise.
515 wxDebugContext::SetCheckpoint();
518 if (!wxApp::Initialize())
522 if (!wxApp::GetInitializerFunction())
524 printf( "wxWindows error: No initializer - use IMPLEMENT_APP macro.\n" );
528 wxTheApp
= (wxApp
*) (* wxApp::GetInitializerFunction()) ();
533 printf( "wxWindows error: wxTheApp == NULL\n" );
538 argc
= 1 ; // currently we don't support files as parameters
541 wxTheApp
->argc
= argc
;
542 wxTheApp
->argv
= argv
;
544 // GUI-specific initialization, such as creating an app context.
545 wxTheApp
->OnInitGui();
547 // we could try to get the open apple events here to adjust argc and argv better
550 // Here frames insert themselves automatically
551 // into wxTopLevelWindows by getting created
554 if (!wxTheApp
->OnInit()) return 0;
558 if (wxTheApp
->Initialized()) retValue
= wxTheApp
->OnRun();
560 if (wxTheApp
->GetTopWindow())
562 delete wxTheApp
->GetTopWindow();
563 wxTheApp
->SetTopWindow(NULL
);
566 wxTheApp
->DeletePendingObjects();
575 // Static member initialization
576 wxAppInitializerFunction
wxApp::m_appInitFn
= (wxAppInitializerFunction
) NULL
;
583 m_wantDebugOutput
= TRUE
;
588 m_printMode
= wxPRINT_WINDOWS
;
590 m_exitOnFrameDelete
= TRUE
;
594 bool wxApp::Initialized()
602 int wxApp::MainLoop()
614 // Returns TRUE if more time is needed.
615 bool wxApp::ProcessIdle()
618 event
.SetEventObject(this);
621 return event
.MoreRequested();
624 void wxApp::ExitMainLoop()
629 // Is a message/event pending?
630 bool wxApp::Pending()
634 return EventAvail( everyEvent
, &event
) ;
637 // Dispatch a message.
638 void wxApp::Dispatch()
643 void wxApp::OnIdle(wxIdleEvent
& event
)
645 static bool inOnIdle
= FALSE
;
647 // Avoid recursion (via ProcessEvent default case)
653 // 'Garbage' collection of windows deleted with Close().
654 DeletePendingObjects();
656 // flush the logged messages if any
657 wxLog
*pLog
= wxLog::GetActiveTarget();
658 if ( pLog
!= NULL
&& pLog
->HasPendingMessages() )
661 // Send OnIdle events to all windows
662 bool needMore
= SendIdleEvents();
665 event
.RequestMore(TRUE
);
672 // **** please implement me! ****
673 // Wake up the idle handler processor, even if it is in another thread...
676 // Send idle event to all top-level windows
677 bool wxApp::SendIdleEvents()
679 bool needMore
= FALSE
;
680 wxNode
* node
= wxTopLevelWindows
.First();
683 wxWindow
* win
= (wxWindow
*) node
->Data();
684 if (SendIdleEvents(win
))
692 // Send idle event to window and all subwindows
693 bool wxApp::SendIdleEvents(wxWindow
* win
)
695 bool needMore
= FALSE
;
698 event
.SetEventObject(win
);
699 win
->ProcessEvent(event
);
701 if (event
.MoreRequested())
704 wxNode
* node
= win
->GetChildren().First();
707 wxWindow
* win
= (wxWindow
*) node
->Data();
708 if (SendIdleEvents(win
))
716 void wxApp::DeletePendingObjects()
718 wxNode
*node
= wxPendingDelete
.First();
721 wxObject
*obj
= (wxObject
*)node
->Data();
725 if (wxPendingDelete
.Member(obj
))
728 // Deleting one object may have deleted other pending
729 // objects, so start from beginning of list again.
730 node
= wxPendingDelete
.First();
734 wxLog
* wxApp::CreateLogTarget()
739 wxWindow
* wxApp::GetTopWindow() const
743 else if (wxTopLevelWindows
.Number() > 0)
744 return (wxWindow
*) wxTopLevelWindows
.First()->Data();
755 // Yield to other processes
758 // YieldToAnyThread() ;
763 // platform specifics
765 void wxApp::MacSuspend( bool convertClipboard
)
767 s_lastMouseDown
= 0 ;
768 if( convertClipboard
)
770 MacConvertPrivateToPublicScrap() ;
773 UMAHideFloatingWindows() ;
776 void wxApp::MacResume( bool convertClipboard
)
778 s_lastMouseDown
= 0 ;
779 if( convertClipboard
)
781 MacConvertPublicToPrivateScrap() ;
784 UMAShowFloatingWindows() ;
787 void wxApp::MacConvertPrivateToPublicScrap()
793 void wxApp::MacConvertPublicToPrivateScrap()
798 void wxApp::MacDoOneEvent()
802 long sleepTime
= ::GetCaretTime();
804 if (WaitNextEvent(everyEvent
, &event
,sleepTime
, s_macCursorRgn
))
806 MacHandleOneEvent( &event
);
811 WindowPtr window
= UMAFrontWindow() ;
813 UMAIdleControls( window
) ;
815 wxTheApp
->ProcessIdle() ;
817 if ( event
.what
!= kHighLevelEvent
)
818 SetRectRgn( s_macCursorRgn
, event
.where
.h
- 1 , event
.where
.v
- 1, event
.where
.h
+ 1 , event
.where
.v
+ 1 ) ;
823 wxMacProcessSocketEvents() ;
827 void wxApp::MacHandleOneEvent( EventRecord
*ev
)
829 m_macCurrentEvent
= ev
;
831 wxApp::sm_lastMessageTime
= ev
->when
;
836 MacHandleMouseDownEvent( ev
) ;
837 if ( ev
->modifiers
& controlKey
)
843 if ( s_lastMouseDown
== 2 )
845 ev
->modifiers
|= controlKey
;
849 ev
->modifiers
&= ~controlKey
;
851 MacHandleMouseUpEvent( ev
) ;
855 MacHandleActivateEvent( ev
) ;
858 MacHandleUpdateEvent( ev
) ;
862 MacHandleKeyDownEvent( ev
) ;
865 MacHandleKeyUpEvent( ev
) ;
868 MacHandleDiskEvent( ev
) ;
871 MacHandleOSEvent( ev
) ;
873 case kHighLevelEvent
:
874 MacHandleHighLevelEvent( ev
) ;
881 void wxApp::MacHandleHighLevelEvent( EventRecord
*ev
)
883 ::AEProcessAppleEvent( ev
) ;
886 bool s_macIsInModalLoop
= false ;
888 void wxApp::MacHandleMouseDownEvent( EventRecord
*ev
)
891 WindowRef frontWindow
= UMAFrontNonFloatingWindow() ;
892 WindowAttributes frontWindowAttributes
= NULL
;
894 UMAGetWindowAttributes( frontWindow
, &frontWindowAttributes
) ;
896 short windowPart
= ::FindWindow(ev
->where
, &window
);
897 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
902 if ( s_macIsInModalLoop
)
908 UInt32 menuresult
= MenuSelect(ev
->where
) ;
909 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) );
914 SystemClick( ev
, window
) ;
918 if ( window
!= frontWindow
&& s_macIsInModalLoop
&& !(ev
->modifiers
& cmdKey
) )
924 DragWindow(window
, ev
->where
, &qd
.screenBits
.bounds
);
929 Point pt
= { 0, 0 } ;
932 LocalToGlobal( &pt
) ;
934 win
->SetSize( pt
.h
, pt
.v
, -1 ,
935 -1 , wxSIZE_USE_EXISTING
);
941 if (TrackGoAway(window
, ev
->where
))
949 int growResult
= GrowWindow(window
, ev
->where
, &qd
.screenBits
.bounds
);
952 int newWidth
= LoWord(growResult
);
953 int newHeight
= HiWord(growResult
);
954 int oldWidth
, oldHeight
;
956 win
->GetSize(&oldWidth
, &oldHeight
);
960 newHeight
= oldHeight
;
963 win
->SetSize( -1, -1, newWidth
, newHeight
, wxSIZE_USE_EXISTING
);
969 if (TrackBox(window
, ev
->where
, windowPart
))
971 // TODO setup size event
972 ZoomWindow( window
, windowPart
, false ) ;
974 win
->SetSize( -1, -1, window
->portRect
.right
-window
->portRect
.left
,
975 window
->portRect
.bottom
-window
->portRect
.top
, wxSIZE_USE_EXISTING
);
980 // TODO setup size event
985 if ( window
!= frontWindow
)
987 if ( s_macIsInModalLoop
)
991 else if ( UMAIsWindowFloating( window
) )
994 win
->MacMouseDown( ev
, windowPart
) ;
998 UMASelectWindow( window
) ;
1004 win
->MacMouseDown( ev
, windowPart
) ;
1013 void wxApp::MacHandleMouseUpEvent( EventRecord
*ev
)
1017 short windowPart
= ::FindWindow(ev
->where
, &window
);
1027 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1029 win
->MacMouseUp( ev
, windowPart
) ;
1035 long wxMacTranslateKey(unsigned char key
, unsigned char code
)
1044 retval
= WXK_RETURN
;
1059 retval
= WXK_PAGEUP
;
1062 retval
= WXK_PAGEDOWN
;
1065 retval
= WXK_RETURN
;
1120 retval
= WXK_ESCAPE
;
1126 retval
= WXK_RIGHT
;
1135 retval
= WXK_DELETE
;
1143 void wxApp::MacHandleKeyDownEvent( EventRecord
*ev
)
1145 UInt32 menuresult
= UMAMenuEvent(ev
) ;
1146 if ( HiWord( menuresult
) )
1147 MacHandleMenuSelect( HiWord( menuresult
) , LoWord( menuresult
) ) ;
1152 keychar
= short(ev
->message
& charCodeMask
);
1153 keycode
= short(ev
->message
& keyCodeMask
) >> 8 ;
1155 wxWindow
* focus
= wxWindow::FindFocus() ;
1158 long keyval
= wxMacTranslateKey(keychar
, keycode
) ;
1160 wxKeyEvent
event(wxEVT_KEY_DOWN
);
1161 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1162 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1163 event
.m_altDown
= ev
->modifiers
& optionKey
;
1164 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1165 event
.m_keyCode
= keyval
;
1166 event
.m_x
= ev
->where
.h
;
1167 event
.m_y
= ev
->where
.v
;
1168 event
.m_timeStamp
= ev
->when
;
1169 event
.SetEventObject(focus
);
1170 bool handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1176 wxWindow
*ancestor
= focus
;
1180 int command = ancestor->GetAcceleratorTable()->GetCommand( event );
1183 wxCommandEvent command_event( wxEVT_COMMAND_MENU_SELECTED, command );
1184 handled = ancestor->GetEventHandler()->ProcessEvent( command_event );
1187 if (ancestor->m_isFrame)
1189 ancestor = ancestor->GetParent();
1193 #endif // wxUSE_ACCEL
1197 wxKeyEvent
event(wxEVT_CHAR
);
1198 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1199 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1200 event
.m_altDown
= ev
->modifiers
& optionKey
;
1201 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1202 event
.m_keyCode
= keyval
;
1203 event
.m_x
= ev
->where
.h
;
1204 event
.m_y
= ev
->where
.v
;
1205 event
.m_timeStamp
= ev
->when
;
1206 event
.SetEventObject(focus
);
1207 handled
= focus
->GetEventHandler()->ProcessEvent( event
) ;
1210 (keyval
== WXK_TAB
) &&
1211 (!focus
->HasFlag(wxTE_PROCESS_TAB
)) &&
1212 (focus
->GetParent()) &&
1213 (focus
->GetParent()->HasFlag( wxTAB_TRAVERSAL
)) )
1215 wxNavigationKeyEvent new_event
;
1216 new_event
.SetEventObject( focus
);
1217 new_event
.SetDirection( !event
.ShiftDown() );
1218 /* CTRL-TAB changes the (parent) window, i.e. switch notebook page */
1219 new_event
.SetWindowChange( event
.ControlDown() );
1220 new_event
.SetCurrentFocus( focus
);
1221 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1223 /* generate wxID_CANCEL if command-. or <esc> has been pressed (typically in dialogs) */
1225 (keyval
== '.' && event
.ControlDown() ) )
1227 wxCommandEvent
new_event(wxEVT_COMMAND_BUTTON_CLICKED
,wxID_CANCEL
);
1228 new_event
.SetEventObject( focus
);
1229 handled
= focus
->GetEventHandler()->ProcessEvent( new_event
);
1235 void wxApp::MacHandleKeyUpEvent( EventRecord
*ev
)
1240 void wxApp::MacHandleActivateEvent( EventRecord
*ev
)
1242 WindowRef window
= (WindowRef
) ev
->message
;
1245 bool activate
= (ev
->modifiers
& activeFlag
) ;
1246 WindowClass wclass
;
1247 UMAGetWindowClass ( window
, &wclass
) ;
1248 if ( wclass
== kFloatingWindowClass
)
1250 // if it is a floater we activate/deactivate the front non-floating window instead
1251 window
= UMAFrontNonFloatingWindow() ;
1253 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1255 win
->MacActivate( ev
, activate
) ;
1259 void wxApp::MacHandleUpdateEvent( EventRecord
*ev
)
1261 WindowRef window
= (WindowRef
) ev
->message
;
1262 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1265 win
->MacUpdate( ev
) ;
1269 void wxApp::MacHandleDiskEvent( EventRecord
*ev
)
1271 if ( HiWord( ev
->message
) != noErr
)
1275 SetPt( &point
, 100 , 100 ) ;
1277 err
= DIBadMount( point
, ev
->message
) ;
1278 wxASSERT( err
== noErr
) ;
1282 void wxApp::MacHandleOSEvent( EventRecord
*ev
)
1284 switch( ( ev
->message
& osEvtMessageMask
) >> 24 )
1286 case suspendResumeMessage
:
1288 bool isResuming
= ev
->message
& resumeFlag
;
1289 bool convertClipboard
= ev
->message
& convertClipboardFlag
;
1290 bool doesActivate
= UMAGetProcessModeDoesActivateOnFGSwitch() ;
1293 WindowRef oldFrontWindow
= NULL
;
1294 WindowRef newFrontWindow
= NULL
;
1296 // in case we don't take care of activating ourselves, we have to synchronize
1297 // our idea of the active window with the process manager's - which it already activated
1299 if ( !doesActivate
)
1300 oldFrontWindow
= UMAFrontNonFloatingWindow() ;
1302 MacResume( convertClipboard
) ;
1304 newFrontWindow
= UMAFrontNonFloatingWindow() ;
1306 if ( oldFrontWindow
)
1308 wxWindow
* win
= wxFindWinFromMacWindow( oldFrontWindow
) ;
1310 win
->MacActivate( ev
, false ) ;
1312 if ( newFrontWindow
)
1314 wxWindow
* win
= wxFindWinFromMacWindow( newFrontWindow
) ;
1316 win
->MacActivate( ev
, true ) ;
1321 MacSuspend( convertClipboard
) ;
1323 // in case this suspending did close an active window, another one might
1324 // have surfaced -> lets deactivate that one
1326 WindowRef newActiveWindow
= UMAGetActiveNonFloatingWindow() ;
1327 if ( newActiveWindow
)
1329 wxWindow
* win
= wxFindWinFromMacWindow( newActiveWindow
) ;
1331 win
->MacActivate( ev
, false ) ;
1336 case mouseMovedMessage
:
1340 wxWindow
* currentMouseWindow
= NULL
;
1342 MacGetWindowFromPoint( wxPoint( ev
->where
.h
, ev
->where
.v
) , ¤tMouseWindow
) ;
1344 if ( currentMouseWindow
!= wxWindow::s_lastMouseWindow
)
1346 wxMouseEvent event
;
1348 bool isDown
= !(ev
->modifiers
& btnState
) ; // 1 is for up
1349 bool controlDown
= ev
->modifiers
& controlKey
; // for simulating right mouse
1351 event
.m_leftDown
= isDown
&& !controlDown
;
1352 event
.m_middleDown
= FALSE
;
1353 event
.m_rightDown
= isDown
&& controlDown
;
1354 event
.m_shiftDown
= ev
->modifiers
& shiftKey
;
1355 event
.m_controlDown
= ev
->modifiers
& controlKey
;
1356 event
.m_altDown
= ev
->modifiers
& optionKey
;
1357 event
.m_metaDown
= ev
->modifiers
& cmdKey
;
1358 event
.m_x
= ev
->where
.h
;
1359 event
.m_y
= ev
->where
.v
;
1360 event
.m_timeStamp
= ev
->when
;
1361 event
.SetEventObject(this);
1363 if ( wxWindow::s_lastMouseWindow
)
1365 wxMouseEvent
eventleave(event
) ;
1366 eventleave
.SetEventType( wxEVT_LEAVE_WINDOW
) ;
1367 wxWindow::s_lastMouseWindow
->GetEventHandler()->ProcessEvent(eventleave
);
1369 if ( currentMouseWindow
)
1371 wxMouseEvent
evententer(event
) ;
1372 evententer
.SetEventType( wxEVT_ENTER_WINDOW
) ;
1373 currentMouseWindow
->GetEventHandler()->ProcessEvent(evententer
);
1375 wxWindow::s_lastMouseWindow
= currentMouseWindow
;
1378 short windowPart
= ::FindWindow(ev
->where
, &window
);
1388 if ( s_lastMouseDown
== 0 )
1389 ev
->modifiers
|= btnState
;
1391 wxWindow
* win
= wxFindWinFromMacWindow( window
) ;
1393 win
->MacMouseMoved( ev
, windowPart
) ;
1403 void wxApp::MacHandleMenuSelect( int macMenuId
, int macMenuItemNum
)
1406 return; // no menu item selected
1408 if (macMenuId
== kwxMacAppleMenuId
&& macMenuItemNum
> 1)
1411 Str255 deskAccessoryName
;
1414 GetMenuItemText(GetMenuHandle(kwxMacAppleMenuId
), macMenuItemNum
, deskAccessoryName
);
1415 GetPort(&savedPort
);
1416 OpenDeskAcc(deskAccessoryName
);
1422 wxWindow
* frontwindow
= wxFindWinFromMacWindow( ::FrontWindow() ) ;
1423 if ( frontwindow
&& wxMenuBar::MacGetInstalledMenuBar() )
1424 wxMenuBar::MacGetInstalledMenuBar()->MacMenuSelect( frontwindow
->GetEventHandler() , 0 , macMenuId
, macMenuItemNum
) ;
1430 long wxApp::MacTranslateKey(char key, int mods)
1434 void wxApp::MacAdjustCursor()
1441 wxApp::macAdjustCursor()
1443 if (ev->what != kHighLevelEvent)
1445 wxWindow* theMacWxFrame = wxFrame::MacFindFrameOrDialog(::FrontWindow());
1448 if (!theMacWxFrame->MacAdjustCursor(ev->where))
1449 ::SetCursor(&(qd.arrow));