X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/8461e4c253d4cec65e8f0320246a56d22555eb5e..63f8abca79edfcf92641b21b0a16687ac84d152b:/src/mac/carbon/app.cpp diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index ade0e6938e..8eb151e595 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -15,6 +15,7 @@ #include "wx/window.h" #include "wx/frame.h" +#include "wx/button.h" #include "wx/app.h" #include "wx/utils.h" #include "wx/gdicmn.h" @@ -56,8 +57,11 @@ #ifdef __DARWIN__ #include #else - #include - #include + #include + #include + #include + #include + #include #endif #endif @@ -84,7 +88,7 @@ const short kMacMinHeap = (29 * 1024) ; const short kwxMacMenuBarResource = 1 ; const short kwxMacAppleMenuId = 1 ; -RgnHandle wxApp::s_macCursorRgn = NULL; +WXHRGN wxApp::s_macCursorRgn = NULL; wxWindow* wxApp::s_captureWindow = NULL ; int wxApp::s_lastMouseDown = 0 ; long wxApp::sm_lastMessageTime = 0; @@ -94,47 +98,37 @@ bool wxApp::s_macSupportPCMenuShortcuts = true ; long wxApp::s_macAboutMenuItemId = wxID_ABOUT ; wxString wxApp::s_macHelpMenuTitleName = "&Help" ; -#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) +pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long refcon ) ; +pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long refcon ) ; +pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long refcon ) ; +pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long refcon ) ; + + pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , long refcon ) -#else -pascal OSErr AEHandleODoc( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) -#endif { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEODoc( (AppleEvent*) event , reply) ; } -#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , long refcon ) -#else -pascal OSErr AEHandleOApp( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) -#endif { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEOApp( (AppleEvent*) event , reply ) ; } -#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , long refcon ) -#else -pascal OSErr AEHandlePDoc( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) -#endif { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEPDoc( (AppleEvent*) event , reply ) ; } -#if defined(UNIVERSAL_INTERFACES_VERSION) && (UNIVERSAL_INTERFACES_VERSION >= 0x0340) pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , long refcon ) -#else -pascal OSErr AEHandleQuit( const AppleEvent *event , AppleEvent *reply , unsigned long refcon ) -#endif { wxApp* app = (wxApp*) refcon ; return wxTheApp->MacHandleAEQuit( (AppleEvent*) event , reply) ; } -OSErr wxApp::MacHandleAEODoc(const AppleEvent *event , AppleEvent *reply) +short wxApp::MacHandleAEODoc(const WXEVENTREF event , WXEVENTREF reply) { SysBeep(40) ; ProcessSerialNumber PSN ; @@ -144,17 +138,17 @@ OSErr wxApp::MacHandleAEODoc(const AppleEvent *event , AppleEvent *reply) return noErr ; } -OSErr wxApp::MacHandleAEPDoc(const AppleEvent *event , AppleEvent *reply) +short wxApp::MacHandleAEPDoc(const WXEVENTREF event , WXEVENTREF reply) { return noErr ; } -OSErr wxApp::MacHandleAEOApp(const AppleEvent *event , AppleEvent *reply) +short wxApp::MacHandleAEOApp(const WXEVENTREF event , WXEVENTREF reply) { return noErr ; } -OSErr wxApp::MacHandleAEQuit(const AppleEvent *event , AppleEvent *reply) +short wxApp::MacHandleAEQuit(const WXEVENTREF event , WXEVENTREF reply) { wxWindow* win = GetTopWindow() ; if ( win ) @@ -430,7 +424,7 @@ bool wxApp::Initialize() { error = kMacSTROldSystem ; } - else if ( theSystem < 0x0750 ) + else if ( theSystem < 0x0860 ) { error = kMacSTROldSystem ; } @@ -535,6 +529,7 @@ bool wxApp::Initialize() void wxApp::CleanUp() { + wxToolTip::RemoveToolTips() ; #if wxUSE_LOG // flush the logged messages if any and install a 'safer' log target: the // default one (wxLogGui) can't be used after the resources are freed just @@ -572,6 +567,9 @@ void wxApp::CleanUp() if (wxWinMacWindowList) delete wxWinMacWindowList ; + if (wxWinMacControlList) + delete wxWinMacControlList ; + delete wxPendingEvents; #if wxUSE_THREADS delete wxPendingEventsLocker; @@ -612,13 +610,35 @@ void wxApp::CleanUp() UMACleanupToolbox() ; if (s_macCursorRgn) - ::DisposeRgn(s_macCursorRgn); + ::DisposeRgn((RgnHandle)s_macCursorRgn); #if 0 TerminateAE() ; #endif } +//---------------------------------------------------------------------- +// wxEntry +//---------------------------------------------------------------------- + +int wxEntryStart( int argc, char *argv[] ) +{ + return wxApp::Initialize(); +} + + +int wxEntryInitGui() +{ + return wxTheApp->OnInitGui(); +} + + +void wxEntryCleanup() +{ + wxApp::CleanUp(); +} + + int wxEntry( int argc, char *argv[] , bool enterLoop ) { #ifdef __MWERKS__ @@ -632,7 +652,7 @@ int wxEntry( int argc, char *argv[] , bool enterLoop ) wxDebugContext::SetCheckpoint(); #endif #endif - if (!wxApp::Initialize()) { + if (!wxEntryStart(argc, argv)) { return 0; } // create the application object or ensure that one already exists @@ -649,24 +669,23 @@ int wxEntry( int argc, char *argv[] , bool enterLoop ) wxCHECK_MSG( wxTheApp, 0, wxT("You have to define an instance of wxApp!") ); -#ifdef __WXMAC__ - argc = 0 ; // currently we don't support files as parameters +#ifndef __DARWIN__ + argc = 0 ; // currently we don't support files as parameters #endif + // we could try to get the open apple events here to adjust argc and argv better - wxTheApp->argc = argc; - wxTheApp->argv = argv; + wxTheApp->argc = argc; + wxTheApp->argv = argv; - // GUI-specific initialization, such as creating an app context. - wxTheApp->OnInitGui(); + // GUI-specific initialization, such as creating an app context. + wxEntryInitGui(); - // we could try to get the open apple events here to adjust argc and argv better + // Here frames insert themselves automatically + // into wxTopLevelWindows by getting created + // in OnInit(). - // Here frames insert themselves automatically - // into wxTopLevelWindows by getting created - // in OnInit(). - - int retValue = 0; + int retValue = 0; if ( wxTheApp->OnInit() ) { @@ -699,7 +718,7 @@ int wxEntry( int argc, char *argv[] , bool enterLoop ) wxTheApp->OnExit(); - wxApp::CleanUp(); + wxEntryCleanup(); return retValue; } @@ -946,11 +965,11 @@ bool wxApp::Yield(bool onlyIfNeeded) long sleepTime = 1 ; //::GetCaretTime(); - while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, wxApp::s_macCursorRgn)) + while ( !wxTheApp->IsExiting() && WaitNextEvent(everyEvent, &event,sleepTime, (RgnHandle) wxApp::s_macCursorRgn)) { wxTheApp->MacHandleOneEvent( &event ); if ( event.what != kHighLevelEvent ) - SetRectRgn( wxApp::s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; + SetRectRgn( (RgnHandle) wxApp::s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; } wxMacProcessNotifierAndPendingEvents() ; @@ -964,19 +983,24 @@ bool wxApp::Yield(bool onlyIfNeeded) void wxApp::MacSuspend( bool convertClipboard ) { - // we have to deactive the window manually + // we have to deactive the top level windows manually - wxWindow* window = GetTopWindow() ; - if ( window ) - window->MacActivate( MacGetCurrentEvent() , false ) ; + wxNode* node = wxTopLevelWindows.First(); + while (node) + { + wxTopLevelWindow* win = (wxTopLevelWindow*) node->Data(); + win->MacActivate( MacGetCurrentEvent() , false ) ; - s_lastMouseDown = 0 ; - if( convertClipboard ) - { - MacConvertPrivateToPublicScrap() ; - } + node = node->Next(); + } - UMAHideFloatingWindows() ; + s_lastMouseDown = 0 ; + if( convertClipboard ) + { + MacConvertPrivateToPublicScrap() ; + } + + ::HideFloatingWindows() ; } void wxApp::MacResume( bool convertClipboard ) @@ -987,7 +1011,7 @@ void wxApp::MacResume( bool convertClipboard ) MacConvertPublicToPrivateScrap() ; } - UMAShowFloatingWindows() ; + ::ShowFloatingWindows() ; } void wxApp::MacConvertPrivateToPublicScrap() @@ -1002,32 +1026,33 @@ void wxApp::MacDoOneEvent() { EventRecord event ; - long sleepTime = 1 ; // GetCaretTime() / 4 ; + long sleepTime = 1; // GetCaretTime() / 4 ; - if (WaitNextEvent(everyEvent, &event,sleepTime, s_macCursorRgn)) + if (WaitNextEvent(everyEvent, &event, sleepTime, (RgnHandle) s_macCursorRgn)) { - MacHandleOneEvent( &event ); + MacHandleOneEvent( &event ); } else { // idlers - WindowPtr window = UMAFrontWindow() ; + WindowPtr window = ::FrontWindow() ; if ( window ) - UMAIdleControls( window ) ; + ::IdleControls( window ) ; wxTheApp->ProcessIdle() ; } if ( event.what != kHighLevelEvent ) - SetRectRgn( s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; + SetRectRgn( (RgnHandle) s_macCursorRgn , event.where.h , event.where.v , event.where.h + 1 , event.where.v + 1 ) ; // repeaters - DeletePendingObjects() ; + DeletePendingObjects() ; wxMacProcessNotifierAndPendingEvents() ; } -void wxApp::MacHandleOneEvent( EventRecord *ev ) +void wxApp::MacHandleOneEvent( WXEVENTREF evr ) { + EventRecord* ev = (EventRecord*) evr ; m_macCurrentEvent = ev ; wxApp::sm_lastMessageTime = ev->when ; @@ -1081,25 +1106,27 @@ void wxApp::MacHandleOneEvent( EventRecord *ev ) wxMacProcessNotifierAndPendingEvents() ; } -void wxApp::MacHandleHighLevelEvent( EventRecord *ev ) +void wxApp::MacHandleHighLevelEvent( WXEVENTREF evr ) { + EventRecord* ev = (EventRecord*) evr ; ::AEProcessAppleEvent( ev ) ; } bool s_macIsInModalLoop = false ; -void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) +void wxApp::MacHandleMouseDownEvent( WXEVENTREF evr ) { + EventRecord* ev = (EventRecord*) evr ; wxToolTip::RemoveToolTips() ; WindowRef window; - WindowRef frontWindow = UMAFrontNonFloatingWindow() ; + WindowRef frontWindow = ::FrontNonFloatingWindow() ; WindowAttributes frontWindowAttributes = NULL ; if ( frontWindow ) - UMAGetWindowAttributes( frontWindow , &frontWindowAttributes ) ; + ::GetWindowAttributes( frontWindow , &frontWindowAttributes ) ; short windowPart = ::FindWindow(ev->where, &window); - wxWindow* win = wxFindWinFromMacWindow( window ) ; + wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; if ( wxPendingDelete.Member(win) ) return ; @@ -1139,12 +1166,7 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) GrafPtr port ; GetPort( &port ) ; Point pt = { 0, 0 } ; - #if TARGET_CARBON - SetPort( GetWindowPort(window) ) ; - #else - SetPort( (window) ) ; - #endif - SetOrigin( 0 , 0 ) ; + SetPortWindowPort(window) ; LocalToGlobal( &pt ) ; SetPort( port ) ; win->SetSize( pt.h , pt.v , -1 , @@ -1210,12 +1232,7 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) { GrafPtr port ; GetPort( &port ) ; - #if TARGET_CARBON - SetPort( GetWindowPort(window) ) ; - #else - SetPort( (window) ) ; - #endif - SetOrigin( 0 , 0 ) ; + SetPortWindowPort(window) ; SetPort( port ) ; } if ( window != frontWindow && wxTheApp->s_captureWindow == NULL ) @@ -1233,7 +1250,7 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) { if ( win ) win->MacMouseDown( ev , windowPart ) ; - UMASelectWindow( window ) ; + ::SelectWindow( window ) ; } } else @@ -1248,11 +1265,21 @@ void wxApp::MacHandleMouseDownEvent( EventRecord *ev ) } } -void wxApp::MacHandleMouseUpEvent( EventRecord *ev ) +void wxApp::MacHandleMouseUpEvent( WXEVENTREF evr ) { + EventRecord* ev = (EventRecord*) evr ; WindowRef window; - short windowPart = ::FindWindow(ev->where, &window); + short windowPart = inNoWindow ; + if ( wxTheApp->s_captureWindow ) + { + window = (WindowRef) s_captureWindow->MacGetRootWindow() ; + windowPart = inContent ; + } + else + { + windowPart = ::FindWindow(ev->where, &window) ; + } switch (windowPart) { @@ -1262,7 +1289,7 @@ void wxApp::MacHandleMouseUpEvent( EventRecord *ev ) break ; default: { - wxWindow* win = wxFindWinFromMacWindow( window ) ; + wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; if ( win ) win->MacMouseUp( ev , windowPart ) ; } @@ -1270,6 +1297,7 @@ void wxApp::MacHandleMouseUpEvent( EventRecord *ev ) } } +long wxMacTranslateKey(unsigned char key, unsigned char code) ; long wxMacTranslateKey(unsigned char key, unsigned char code) { long retval = key ; @@ -1378,8 +1406,9 @@ long wxMacTranslateKey(unsigned char key, unsigned char code) return retval; } -void wxApp::MacHandleKeyDownEvent( EventRecord *ev ) +void wxApp::MacHandleKeyDownEvent( WXEVENTREF evr ) { + EventRecord* ev = (EventRecord*) evr ; wxToolTip::RemoveToolTips() ; UInt32 menuresult = UMAMenuEvent(ev) ; @@ -1394,11 +1423,11 @@ void wxApp::MacHandleKeyDownEvent( EventRecord *ev ) short keychar ; keychar = short(ev->message & charCodeMask); keycode = short(ev->message & keyCodeMask) >> 8 ; - + long keyval = wxMacTranslateKey(keychar, keycode) ; + bool handled = false ; wxWindow* focus = wxWindow::FindFocus() ; if ( focus ) { - long keyval = wxMacTranslateKey(keychar, keycode) ; wxKeyEvent event(wxEVT_KEY_DOWN); event.m_shiftDown = ev->modifiers & shiftKey; @@ -1410,7 +1439,7 @@ void wxApp::MacHandleKeyDownEvent( EventRecord *ev ) event.m_y = ev->where.v; event.m_timeStamp = ev->when; event.SetEventObject(focus); - bool handled = focus->GetEventHandler()->ProcessEvent( event ) ; + handled = focus->GetEventHandler()->ProcessEvent( event ) ; if ( !handled ) { #if wxUSE_ACCEL @@ -1463,20 +1492,41 @@ void wxApp::MacHandleKeyDownEvent( EventRecord *ev ) new_event.SetCurrentFocus( focus ); handled = focus->GetEventHandler()->ProcessEvent( new_event ); } + } + if ( !handled ) + { + // if window is not having a focus still testing for default enter or cancel + // TODO add the UMA version for ActiveNonFloatingWindow + focus = wxFindWinFromMacWindow( FrontWindow() ) ; + if ( focus ) + { + if ( keyval == WXK_RETURN ) + { + wxButton *def = wxDynamicCast(focus->GetDefaultItem(), + wxButton); + if ( def && def->IsEnabled() ) + { + wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, def->GetId() ); + event.SetEventObject(def); + def->Command(event); + return ; + } + } /* generate wxID_CANCEL if command-. or has been pressed (typically in dialogs) */ - if ( (!handled) && - (keyval == '.' && event.ControlDown() ) ) + else if (keyval == WXK_ESCAPE || (keyval == '.' && ev->modifiers & cmdKey ) ) { - wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL); - new_event.SetEventObject( focus ); - handled = focus->GetEventHandler()->ProcessEvent( new_event ); + wxCommandEvent new_event(wxEVT_COMMAND_BUTTON_CLICKED,wxID_CANCEL); + new_event.SetEventObject( focus ); + handled = focus->GetEventHandler()->ProcessEvent( new_event ); } + } } } } -void wxApp::MacHandleKeyUpEvent( EventRecord *ev ) +void wxApp::MacHandleKeyUpEvent( WXEVENTREF evr ) { + EventRecord* ev = (EventRecord*) evr ; wxToolTip::RemoveToolTips() ; UInt32 menuresult = UMAMenuEvent(ev) ; @@ -1510,33 +1560,35 @@ void wxApp::MacHandleKeyUpEvent( EventRecord *ev ) } } -void wxApp::MacHandleActivateEvent( EventRecord *ev ) +void wxApp::MacHandleActivateEvent( WXEVENTREF evr ) { + EventRecord* ev = (EventRecord*) evr ; WindowRef window = (WindowRef) ev->message ; if ( window ) { bool activate = (ev->modifiers & activeFlag ) ; WindowClass wclass ; - UMAGetWindowClass ( window , &wclass ) ; + ::GetWindowClass ( window , &wclass ) ; if ( wclass == kFloatingWindowClass ) { // if it is a floater we activate/deactivate the front non-floating window instead - window = UMAFrontNonFloatingWindow() ; + window = ::FrontNonFloatingWindow() ; } - wxWindow* win = wxFindWinFromMacWindow( window ) ; + wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; if ( win ) win->MacActivate( ev , activate ) ; } } -void wxApp::MacHandleUpdateEvent( EventRecord *ev ) +void wxApp::MacHandleUpdateEvent( WXEVENTREF evr ) { + EventRecord* ev = (EventRecord*) evr ; WindowRef window = (WindowRef) ev->message ; - wxWindow * win = wxFindWinFromMacWindow( window ) ; + wxTopLevelWindowMac * win = wxFindWinFromMacWindow( window ) ; if ( win ) { if ( !wxPendingDelete.Member(win) ) - win->MacUpdate( ev ) ; + win->MacUpdate( ev->when ) ; } else { @@ -1548,8 +1600,9 @@ void wxApp::MacHandleUpdateEvent( EventRecord *ev ) } } -void wxApp::MacHandleDiskEvent( EventRecord *ev ) +void wxApp::MacHandleDiskEvent( WXEVENTREF evr ) { + EventRecord* ev = (EventRecord*) evr ; if ( HiWord( ev->message ) != noErr ) { #if !TARGET_CARBON @@ -1563,8 +1616,9 @@ void wxApp::MacHandleDiskEvent( EventRecord *ev ) } } -void wxApp::MacHandleOSEvent( EventRecord *ev ) +void wxApp::MacHandleOSEvent( WXEVENTREF evr ) { + EventRecord* ev = (EventRecord*) evr ; switch( ( ev->message & osEvtMessageMask ) >> 24 ) { case suspendResumeMessage : @@ -1585,21 +1639,21 @@ void wxApp::MacHandleOSEvent( EventRecord *ev ) // our idea of the active window with the process manager's - which it already activated if ( !doesActivate ) - oldFrontWindow = UMAFrontNonFloatingWindow() ; + oldFrontWindow = ::FrontNonFloatingWindow() ; MacResume( convertClipboard ) ; - newFrontWindow = UMAFrontNonFloatingWindow() ; + newFrontWindow = ::FrontNonFloatingWindow() ; if ( oldFrontWindow ) { - wxWindow* win = wxFindWinFromMacWindow( oldFrontWindow ) ; + wxTopLevelWindowMac* win = wxFindWinFromMacWindow( oldFrontWindow ) ; if ( win ) win->MacActivate( ev , false ) ; } if ( newFrontWindow ) { - wxWindow* win = wxFindWinFromMacWindow( newFrontWindow ) ; + wxTopLevelWindowMac* win = wxFindWinFromMacWindow( newFrontWindow ) ; if ( win ) win->MacActivate( ev , true ) ; } @@ -1611,13 +1665,15 @@ void wxApp::MacHandleOSEvent( EventRecord *ev ) // in case this suspending did close an active window, another one might // have surfaced -> lets deactivate that one - WindowRef newActiveWindow = UMAGetActiveNonFloatingWindow() ; +/* TODO : find out what to do on systems < 10 , perhaps FrontNonFloatingWindow + WindowRef newActiveWindow = ::ActiveNonFloatingWindow() ; if ( newActiveWindow ) { wxWindow* win = wxFindWinFromMacWindow( newActiveWindow ) ; if ( win ) win->MacActivate( ev , false ) ; } +*/ } } break ; @@ -1629,7 +1685,6 @@ void wxApp::MacHandleOSEvent( EventRecord *ev ) wxWindow::MacGetWindowFromPoint( wxPoint( ev->where.h , ev->where.v ) , ¤tMouseWindow ) ; - if ( currentMouseWindow != wxWindow::s_lastMouseWindow ) { wxMouseEvent event ; @@ -1648,17 +1703,21 @@ void wxApp::MacHandleOSEvent( EventRecord *ev ) event.m_y = ev->where.v; event.m_timeStamp = ev->when; event.SetEventObject(this); - + if ( wxWindow::s_lastMouseWindow ) { - wxMouseEvent eventleave(event ) ; - eventleave.SetEventType( wxEVT_LEAVE_WINDOW ) ; + wxMouseEvent eventleave(event); + eventleave.SetEventType( wxEVT_LEAVE_WINDOW ); + wxWindow::s_lastMouseWindow->ScreenToClient( &eventleave.m_x, &eventleave.m_y ); + wxWindow::s_lastMouseWindow->GetEventHandler()->ProcessEvent(eventleave); } if ( currentMouseWindow ) { - wxMouseEvent evententer(event ) ; - evententer.SetEventType( wxEVT_ENTER_WINDOW ) ; + wxMouseEvent evententer(event); + evententer.SetEventType( wxEVT_ENTER_WINDOW ); + currentMouseWindow->ScreenToClient( &evententer.m_x, &evententer.m_y ); + currentMouseWindow->GetEventHandler()->ProcessEvent(evententer); } wxWindow::s_lastMouseWindow = currentMouseWindow ; @@ -1677,10 +1736,21 @@ void wxApp::MacHandleOSEvent( EventRecord *ev ) break ; default: { - if ( s_lastMouseDown == 0 ) - ev->modifiers |= btnState ; - - wxWindow* win = wxFindWinFromMacWindow( window ) ; + // if ( s_lastMouseDown == 0 ) + // ev->modifiers |= btnState ; + + // Calling GetNextEvent with a zero event mask will always + // pass back a null event. However, it fills the EventRecord + // with the state of the modifier keys. This is needed since + // the modifier state returned by WaitForNextEvent often is + // wrong mouse move events. The attempt above to correct this + // didn't always work (under OS X at least). + + EventRecord tmp; + ::GetNextEvent(0, &tmp); + ev->modifiers = tmp.modifiers; + + wxTopLevelWindowMac* win = wxFindWinFromMacWindow( window ) ; if ( win ) win->MacMouseMoved( ev , windowPart ) ; else