X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a01d9a255c8887521b4d47c15b6637bf38c4b688..0c1cc9483ecba053bc9a0983a4a8d48898e334f2:/src/mac/carbon/window.cpp diff --git a/src/mac/carbon/window.cpp b/src/mac/carbon/window.cpp index e4d51d52a0..acb4a6b6cb 100644 --- a/src/mac/carbon/window.cpp +++ b/src/mac/carbon/window.cpp @@ -66,18 +66,6 @@ #define MAC_SCROLLBAR_SIZE 15 #define MAC_SMALL_SCROLLBAR_SIZE 11 -#ifndef __DARWIN__ -#include -#include -#include -#endif - -#if TARGET_API_MAC_OSX -#ifndef __HIVIEW__ - #include -#endif -#endif - #include #ifdef __WXUNIVERSAL__ @@ -89,11 +77,7 @@ BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase) EVT_NC_PAINT(wxWindowMac::OnNcPaint) EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground) -#if TARGET_API_MAC_OSX EVT_PAINT(wxWindowMac::OnPaint) -#endif - EVT_SET_FOCUS(wxWindowMac::OnSetFocus) - EVT_KILL_FOCUS(wxWindowMac::OnSetFocus) EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent) END_EVENT_TABLE() @@ -165,15 +149,16 @@ static const EventTypeSpec eventList[] = { kEventClassTextInput, kEventTextInputUpdateActiveInputArea } , { kEventClassControl , kEventControlDraw } , -#if TARGET_API_MAC_OSX + { kEventClassControl , kEventControlVisibilityChanged } , { kEventClassControl , kEventControlEnabledStateChanged } , { kEventClassControl , kEventControlHiliteChanged } , { kEventClassControl , kEventControlActivate } , { kEventClassControl , kEventControlDeactivate } , -#endif + { kEventClassControl , kEventControlSetFocusPart } , + { kEventClassControl , kEventControlFocusPartChanged } , { kEventClassService , kEventServiceGetTypes }, { kEventClassService , kEventServiceCopy }, @@ -196,7 +181,6 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl switch ( GetEventKind( event ) ) { -#if TARGET_API_MAC_OSX case kEventControlDraw : { RgnHandle updateRgn = NULL ; @@ -205,7 +189,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl if ( cEvent.GetParameter(kEventParamRgnHandle, &updateRgn) != noErr ) { - updateRgn = (RgnHandle) visRegion.GetWXHRGN() ; + HIShapeGetAsQDRgn( visRegion.GetWXHRGN(), updateRgn ); } else { @@ -221,9 +205,6 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl } } - Rect rgnBounds ; - GetRegionBounds( updateRgn , &rgnBounds ) ; - #if wxMAC_DEBUG_REDRAW if ( thisWindow->MacIsUserPane() ) { @@ -251,17 +232,21 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl bool created = false ; CGContextRef cgContext = NULL ; OSStatus err = cEvent.GetParameter(kEventParamCGContextRef, &cgContext) ; - wxASSERT_MSG( err == noErr , wxT("Unable to retrieve CGContextRef") ) ; + if ( err != noErr ) + { + wxFAIL_MSG("Unable to retrieve CGContextRef"); + } + thisWindow->MacSetCGContextRef( cgContext ) ; { wxMacCGContextStateSaver sg( cgContext ) ; - float alpha = 1.0 ; + CGFloat alpha = (CGFloat)1.0 ; { wxWindow* iter = thisWindow ; while ( iter ) { - alpha *= (float) iter->GetTransparent()/255.0 ; + alpha *= (CGFloat)( iter->GetTransparent()/255.0 ) ; if ( iter->IsTopLevel() ) iter = NULL ; else @@ -277,6 +262,8 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl CGContextClearRect( cgContext, bounds ); } + + if ( thisWindow->MacDoRedraw( updateRgn , cEvent.GetTicks() ) ) result = noErr ; @@ -293,11 +280,17 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl break ; case kEventControlVisibilityChanged : - thisWindow->MacVisibilityChanged() ; + // we might have two native controls attributed to the same wxWindow instance + // eg a scrollview and an embedded textview, make sure we only fire for the 'outer' + // control, as otherwise native and wx visibility are different + if ( thisWindow->GetPeer() != NULL && thisWindow->GetPeer()->GetControlRef() == controlRef ) + { + thisWindow->MacVisibilityChanged() ; + } break ; case kEventControlEnabledStateChanged : - thisWindow->MacEnabledStateChanged() ; + thisWindow->MacEnabledStateChanged(); break ; case kEventControlHiliteChanged : @@ -316,28 +309,34 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl thisWindow->Refresh(); #endif break ; -#endif // TARGET_API_MAC_OSX - // we emulate this event under Carbon CFM - case kEventControlSetFocusPart : + // + // focus handling + // different handling on OS X + // + + case kEventControlFocusPartChanged : + // the event is emulated by wxmac for systems lower than 10.5 { - Boolean focusEverything = false ; - ControlPartCode controlPart = cEvent.GetParameter(kEventParamControlPart , typeControlPartCode ); + ControlPartCode previousControlPart = cEvent.GetParameter(kEventParamControlPreviousPart , typeControlPartCode ); + ControlPartCode currentControlPart = cEvent.GetParameter(kEventParamControlCurrentPart , typeControlPartCode ); - if ( cEvent.GetParameter(kEventParamControlFocusEverything , &focusEverything ) == noErr ) + if ( thisWindow->MacGetTopLevelWindow() && thisWindow->GetPeer()->NeedsFocusRect() ) { + thisWindow->MacInvalidateBorders(); } - if ( thisWindow->MacIsUserPane() ) - result = noErr ; - - if ( controlPart == kControlFocusNoPart ) + if ( currentControlPart == 0 ) { + // kill focus #if wxUSE_CARET if ( thisWindow->GetCaret() ) thisWindow->GetCaret()->OnKillFocus(); #endif + wxLogTrace(_T("Focus"), _T("focus lost(%p)"), wx_static_cast(void*, thisWindow)); + + // remove this as soon as posting the synthesized event works properly static bool inKillFocusEvent = false ; if ( !inKillFocusEvent ) @@ -345,15 +344,17 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl inKillFocusEvent = true ; wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId()); event.SetEventObject(thisWindow); - thisWindow->GetEventHandler()->ProcessEvent(event) ; + thisWindow->HandleWindowEvent(event) ; inKillFocusEvent = false ; } } - else + else if ( previousControlPart == 0 ) { + // set focus // panel wants to track the window which was the last to have focus in it - wxChildFocusEvent eventFocus(thisWindow); - thisWindow->GetEventHandler()->ProcessEvent(eventFocus); + wxLogTrace(_T("Focus"), _T("focus set(%p)"), wx_static_cast(void*, thisWindow)); + wxChildFocusEvent eventFocus((wxWindow*)thisWindow); + thisWindow->HandleWindowEvent(eventFocus); #if wxUSE_CARET if ( thisWindow->GetCaret() ) @@ -362,7 +363,97 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId()); event.SetEventObject(thisWindow); - thisWindow->GetEventHandler()->ProcessEvent(event) ; + thisWindow->HandleWindowEvent(event) ; + } + } + break; + case kEventControlSetFocusPart : + { +#ifdef __WXMAC_OSX__ + Boolean focusEverything = false ; + if ( cEvent.GetParameter(kEventParamControlFocusEverything , &focusEverything ) == noErr ) + { + // put a breakpoint here to catch focus everything events + } +#endif + ControlPartCode controlPart = cEvent.GetParameter(kEventParamControlPart , typeControlPartCode ); + + ControlPartCode previousControlPart = 0; + verify_noerr( HIViewGetFocusPart(controlRef, &previousControlPart)); + + if ( thisWindow->MacIsUserPane() ) + { + if ( controlPart != kControlFocusNoPart ) + cEvent.SetParameter( kEventParamControlPart, typeControlPartCode, 1 ) ; + result = noErr ; + } + else + result = CallNextEventHandler(handler, event); + + if ( UMAGetSystemVersion() < 0x1050 ) + { +// set back to 0 if problems arise +#if 1 + ControlPartCode currentControlPart = cEvent.GetParameter(kEventParamControlPart , typeControlPartCode ); + // synthesize the event focus changed event + EventRef evRef = NULL ; + + OSStatus err = MacCreateEvent( + NULL , kEventClassControl , kEventControlFocusPartChanged , TicksToEventTime( TickCount() ) , + kEventAttributeUserEvent , &evRef ); + verify_noerr( err ); + + wxMacCarbonEvent iEvent( evRef ) ; + iEvent.SetParameter( kEventParamDirectObject , controlRef ) ; + iEvent.SetParameter( kEventParamControlPreviousPart, typeControlPartCode, previousControlPart ) ; + iEvent.SetParameter( kEventParamControlCurrentPart, typeControlPartCode, currentControlPart ) ; + +#if 0 + // TODO test this first, avoid double posts etc... + PostEventToQueue( GetMainEventQueue(), evRef , kEventPriorityHigh ); +#else + wxMacWindowControlEventHandler( NULL , evRef , data ) ; +#endif + ReleaseEvent( evRef ) ; +#else + // old implementation, to be removed if the new one works + if ( controlPart == kControlFocusNoPart ) + { +#if wxUSE_CARET + if ( thisWindow->GetCaret() ) + thisWindow->GetCaret()->OnKillFocus(); +#endif + + wxLogTrace(_T("Focus"), _T("focus lost(%p)"), wx_static_cast(void*, thisWindow)); + + static bool inKillFocusEvent = false ; + + if ( !inKillFocusEvent ) + { + inKillFocusEvent = true ; + wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId()); + event.SetEventObject(thisWindow); + thisWindow->HandleWindowEvent(event) ; + inKillFocusEvent = false ; + } + } + else + { + // panel wants to track the window which was the last to have focus in it + wxLogTrace(_T("Focus"), _T("focus set(%p)"), wx_static_cast(void*, thisWindow)); + wxChildFocusEvent eventFocus((wxWindow*)thisWindow); + thisWindow->HandleWindowEvent(eventFocus); + + #if wxUSE_CARET + if ( thisWindow->GetCaret() ) + thisWindow->GetCaret()->OnSetFocus(); + #endif + + wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId()); + event.SetEventObject(thisWindow); + thisWindow->HandleWindowEvent(event) ; + } +#endif } } break ; @@ -373,7 +464,7 @@ static pascal OSStatus wxMacWindowControlEventHandler( EventHandlerCallRef handl case kEventControlGetClickActivation : { - // fix to always have a proper activation for DataBrowser controls (stay in bkgnd otherwise) + // fix to always have a proper activation for DataBrowser controls (stay in bkgnd otherwise) WindowRef owner = cEvent.GetParameter(kEventParamWindowRef); if ( !IsWindowActive(owner) ) { @@ -524,7 +615,7 @@ pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , Even charBuf[ numChars - 1 ] = 0; #if SIZEOF_WCHAR_T == 2 uniChars = (wchar_t*) charBuf ; -/* memcpy( uniChars , charBuf , numChars * 2 ) ;*/ // is there any point in copying charBuf over itself? (in fact, memcpy isn't even guaranteed to work correctly if the source and destination ranges overlap...) +/* memcpy( uniChars , charBuf , numChars * 2 ) ;*/ // is there any point in copying charBuf over itself? (in fact, memcpy isn't even guaranteed to work correctly if the source and destination ranges overlap...) #else // the resulting string will never have more chars than the utf16 version, so this is safe wxMBConvUTF16 converter ; @@ -546,29 +637,29 @@ pascal OSStatus wxMacUnicodeTextEventHandler( EventHandlerCallRef handler , Even UInt32 message = uniChars[pos] < 128 ? (char)uniChars[pos] : '?'; /* - NB: faking a charcode here is problematic. The kEventTextInputUpdateActiveInputArea event is sent - multiple times to update the active range during inline input, so this handler will often receive - uncommited text, which should usually not trigger side effects. It might be a good idea to check the - kEventParamTextInputSendFixLen parameter and verify if input is being confirmed (see CarbonEvents.h). - On the other hand, it can be useful for some applications to react to uncommitted text (for example, - to update a status display), as long as it does not disrupt the inline input session. Ideally, wx - should add new event types to support advanced text input. For now, I would keep things as they are. - - However, the code that was being used caused additional problems: + NB: faking a charcode here is problematic. The kEventTextInputUpdateActiveInputArea event is sent + multiple times to update the active range during inline input, so this handler will often receive + uncommited text, which should usually not trigger side effects. It might be a good idea to check the + kEventParamTextInputSendFixLen parameter and verify if input is being confirmed (see CarbonEvents.h). + On the other hand, it can be useful for some applications to react to uncommitted text (for example, + to update a status display), as long as it does not disrupt the inline input session. Ideally, wx + should add new event types to support advanced text input. For now, I would keep things as they are. + + However, the code that was being used caused additional problems: UInt32 message = (0 << 8) + ((char)uniChars[pos] ); - Since it simply truncated the unichar to the last byte, it ended up causing weird bugs with inline - input, such as switching to another field when one attempted to insert the character U+4E09 (the kanji - for "three"), because it was truncated to 09 (kTabCharCode), which was later "converted" to WXK_TAB - (still 09) in wxMacTranslateKey; or triggering the default button when one attempted to insert U+840D - (the kanji for "name"), which got truncated to 0D and interpreted as a carriage return keypress. - Note that even single-byte characters could have been misinterpreted, since MacRoman charcodes only - overlap with Unicode within the (7-bit) ASCII range. - But simply passing a NUL charcode would disable text updated events, because wxTextCtrl::OnChar checks - for codes within a specific range. Therefore I went for the solution seen above, which keeps ASCII - characters as they are and replaces the rest with '?', ensuring that update events are triggered. - It would be better to change wxTextCtrl::OnChar to look at the actual unicode character instead, but - I don't have time to look into that right now. - -- CL + Since it simply truncated the unichar to the last byte, it ended up causing weird bugs with inline + input, such as switching to another field when one attempted to insert the character U+4E09 (the kanji + for "three"), because it was truncated to 09 (kTabCharCode), which was later "converted" to WXK_TAB + (still 09) in wxMacTranslateKey; or triggering the default button when one attempted to insert U+840D + (the kanji for "name"), which got truncated to 0D and interpreted as a carriage return keypress. + Note that even single-byte characters could have been misinterpreted, since MacRoman charcodes only + overlap with Unicode within the (7-bit) ASCII range. + But simply passing a NUL charcode would disable text updated events, because wxTextCtrl::OnChar checks + for codes within a specific range. Therefore I went for the solution seen above, which keeps ASCII + characters as they are and replaces the rest with '?', ensuring that update events are triggered. + It would be better to change wxTextCtrl::OnChar to look at the actual unicode character instead, but + I don't have time to look into that right now. + -- CL */ if ( wxTheApp->MacSendCharEvent( focus , message , 0 , when , 0 , 0 , uniChars[pos] ) ) @@ -698,134 +789,6 @@ pascal OSStatus wxMacWindowEventHandler( EventHandlerCallRef handler , EventRef DEFINE_ONE_SHOT_HANDLER_GETTER( wxMacWindowEventHandler ) -#if !TARGET_API_MAC_OSX - -// --------------------------------------------------------------------------- -// UserPane events for non OSX builds -// --------------------------------------------------------------------------- - -static pascal void wxMacControlUserPaneDrawProc(ControlRef control, SInt16 part) -{ - wxWindow * win = wxFindControlFromMacControl(control) ; - if ( win ) - win->MacControlUserPaneDrawProc(part) ; -} -wxMAC_DEFINE_PROC_GETTER( ControlUserPaneDrawUPP , wxMacControlUserPaneDrawProc ) ; - -static pascal ControlPartCode wxMacControlUserPaneHitTestProc(ControlRef control, Point where) -{ - wxWindow * win = wxFindControlFromMacControl(control) ; - if ( win ) - return win->MacControlUserPaneHitTestProc(where.h , where.v) ; - else - return kControlNoPart ; -} -wxMAC_DEFINE_PROC_GETTER( ControlUserPaneHitTestUPP , wxMacControlUserPaneHitTestProc ) ; - -static pascal ControlPartCode wxMacControlUserPaneTrackingProc(ControlRef control, Point startPt, ControlActionUPP actionProc) -{ - wxWindow * win = wxFindControlFromMacControl(control) ; - if ( win ) - return win->MacControlUserPaneTrackingProc( startPt.h , startPt.v , (void*) actionProc) ; - else - return kControlNoPart ; -} -wxMAC_DEFINE_PROC_GETTER( ControlUserPaneTrackingUPP , wxMacControlUserPaneTrackingProc ) ; - -static pascal void wxMacControlUserPaneIdleProc(ControlRef control) -{ - wxWindow * win = wxFindControlFromMacControl(control) ; - if ( win ) - win->MacControlUserPaneIdleProc() ; -} -wxMAC_DEFINE_PROC_GETTER( ControlUserPaneIdleUPP , wxMacControlUserPaneIdleProc ) ; - -static pascal ControlPartCode wxMacControlUserPaneKeyDownProc(ControlRef control, SInt16 keyCode, SInt16 charCode, SInt16 modifiers) -{ - wxWindow * win = wxFindControlFromMacControl(control) ; - if ( win ) - return win->MacControlUserPaneKeyDownProc(keyCode,charCode,modifiers) ; - else - return kControlNoPart ; -} -wxMAC_DEFINE_PROC_GETTER( ControlUserPaneKeyDownUPP , wxMacControlUserPaneKeyDownProc ) ; - -static pascal void wxMacControlUserPaneActivateProc(ControlRef control, Boolean activating) -{ - wxWindow * win = wxFindControlFromMacControl(control) ; - if ( win ) - win->MacControlUserPaneActivateProc(activating) ; -} -wxMAC_DEFINE_PROC_GETTER( ControlUserPaneActivateUPP , wxMacControlUserPaneActivateProc ) ; - -static pascal ControlPartCode wxMacControlUserPaneFocusProc(ControlRef control, ControlFocusPart action) -{ - wxWindow * win = wxFindControlFromMacControl(control) ; - if ( win ) - return win->MacControlUserPaneFocusProc(action) ; - else - return kControlNoPart ; -} -wxMAC_DEFINE_PROC_GETTER( ControlUserPaneFocusUPP , wxMacControlUserPaneFocusProc ) ; - -static pascal void wxMacControlUserPaneBackgroundProc(ControlRef control, ControlBackgroundPtr info) -{ - wxWindow * win = wxFindControlFromMacControl(control) ; - if ( win ) - win->MacControlUserPaneBackgroundProc(info) ; -} -wxMAC_DEFINE_PROC_GETTER( ControlUserPaneBackgroundUPP , wxMacControlUserPaneBackgroundProc ) ; - -void wxWindowMac::MacControlUserPaneDrawProc(wxInt16 part) -{ - int x = 0 , y = 0; - RgnHandle rgn = NewRgn() ; - GetClip( rgn ) ; - MacWindowToRootWindow( &x, &y ) ; - OffsetRgn( rgn , -x , -y ) ; - wxMacWindowStateSaver sv( this ) ; - SectRgn( rgn , (RgnHandle) MacGetVisibleRegion().GetWXHRGN() , rgn ) ; - MacDoRedraw( rgn , 0 ) ; - DisposeRgn( rgn ) ; -} - -wxInt16 wxWindowMac::MacControlUserPaneHitTestProc(wxInt16 x, wxInt16 y) -{ - return kControlNoPart ; -} - -wxInt16 wxWindowMac::MacControlUserPaneTrackingProc(wxInt16 x, wxInt16 y, void* actionProc) -{ - return kControlNoPart ; -} - -void wxWindowMac::MacControlUserPaneIdleProc() -{ -} - -wxInt16 wxWindowMac::MacControlUserPaneKeyDownProc(wxInt16 keyCode, wxInt16 charCode, wxInt16 modifiers) -{ - return kControlNoPart ; -} - -void wxWindowMac::MacControlUserPaneActivateProc(bool activating) -{ -} - -wxInt16 wxWindowMac::MacControlUserPaneFocusProc(wxInt16 action) -{ - if ( AcceptsFocus() ) - return 1 ; - else - return kControlNoPart ; -} - -void wxWindowMac::MacControlUserPaneBackgroundProc(void* info) -{ -} - -#endif - // --------------------------------------------------------------------------- // Scrollbar Tracking for all // --------------------------------------------------------------------------- @@ -912,7 +875,6 @@ wxWindowMac::wxWindowMac(wxWindowMac *parent, void wxWindowMac::Init() { m_peer = NULL ; - m_frozenness = 0 ; m_macAlpha = 255 ; m_cgContextRef = NULL ; @@ -927,9 +889,6 @@ void wxWindowMac::Init() m_macIsUserPane = true; m_clipChildren = false ; m_cachedClippedRectValid = false ; - - // we need a valid font for the encodings - wxWindowBase::SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); } wxWindowMac::~wxWindowMac() @@ -1012,20 +971,6 @@ void wxWindowMac::MacInstallEventHandler( WXWidget control ) InstallControlEventHandler( (ControlRef)control , GetwxMacWindowEventHandlerUPP(), GetEventTypeCount(eventList), eventList, this, (EventHandlerRef *)&m_macControlEventHandler); - -#if !TARGET_API_MAC_OSX - if ( (ControlRef) control == m_peer->GetControlRef() ) - { - m_peer->SetData(kControlEntireControl, kControlUserPaneDrawProcTag, GetwxMacControlUserPaneDrawProc()) ; - m_peer->SetData(kControlEntireControl, kControlUserPaneHitTestProcTag, GetwxMacControlUserPaneHitTestProc()) ; - m_peer->SetData(kControlEntireControl, kControlUserPaneTrackingProcTag, GetwxMacControlUserPaneTrackingProc()) ; - m_peer->SetData(kControlEntireControl, kControlUserPaneIdleProcTag, GetwxMacControlUserPaneIdleProc()) ; - m_peer->SetData(kControlEntireControl, kControlUserPaneKeyDownProcTag, GetwxMacControlUserPaneKeyDownProc()) ; - m_peer->SetData(kControlEntireControl, kControlUserPaneActivateProcTag, GetwxMacControlUserPaneActivateProc()) ; - m_peer->SetData(kControlEntireControl, kControlUserPaneFocusProcTag, GetwxMacControlUserPaneFocusProc()) ; - m_peer->SetData(kControlEntireControl, kControlUserPaneBackgroundProcTag, GetwxMacControlUserPaneBackgroundProc()) ; - } -#endif } // Constructor @@ -1162,7 +1107,7 @@ void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant ) m_peer->SetData(kControlEntireControl, kControlSizeTag, &size ) ; wxFont font ; - font.MacCreateThemeFont( themeFont ) ; + font.MacCreateFromThemeFont( themeFont ) ; SetFont( font ) ; } @@ -1170,7 +1115,7 @@ void wxWindowMac::MacUpdateControlFont() { m_peer->SetFont( GetFont() , GetForegroundColour() , GetWindowStyle() ) ; // do not trigger refreshes upon invisible and possible partly created objects - if ( MacIsReallyShown() ) + if ( IsShownOnScreen() ) Refresh() ; } @@ -1241,43 +1186,6 @@ void wxWindowMac::SetFocus() return ; SetUserFocusWindow( (WindowRef)MacGetTopLevelWindowRef() ); - -#if !TARGET_API_MAC_OSX - // emulate carbon events when running under CarbonLib where they are not natively available - if ( former ) - { - EventRef evRef = NULL ; - - err = MacCreateEvent( - NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , - kEventAttributeUserEvent , &evRef ); - verify_noerr( err ); - - wxMacCarbonEvent cEvent( evRef ) ; - cEvent.SetParameter( kEventParamDirectObject , (ControlRef) former->GetHandle() ) ; - cEvent.SetParameter(kEventParamControlPart , typeControlPartCode , kControlFocusNoPart ) ; - - wxMacWindowEventHandler( NULL , evRef , former ) ; - ReleaseEvent( evRef ) ; - } - - // send new focus event - { - EventRef evRef = NULL ; - - err = MacCreateEvent( - NULL , kEventClassControl , kEventControlSetFocusPart , TicksToEventTime( TickCount() ) , - kEventAttributeUserEvent , &evRef ); - verify_noerr( err ); - - wxMacCarbonEvent cEvent( evRef ) ; - cEvent.SetParameter( kEventParamDirectObject , (ControlRef) GetHandle() ) ; - cEvent.SetParameter(kEventParamControlPart , typeControlPartCode , kControlFocusNextPart ) ; - - wxMacWindowEventHandler( NULL , evRef , this ) ; - ReleaseEvent( evRef ) ; - } -#endif } void wxWindowMac::DoCaptureMouse() @@ -1684,23 +1592,17 @@ bool wxWindowMac::SetCursor(const wxCursor& cursor) pt.h = hiPoint.x; pt.v = hiPoint.y; #else - CGrafPtr savePort ; - Boolean swapped = QDSwapPort( GetWindowPort( window ) , &savePort ) ; - - // TODO: If we ever get a GetCurrentEvent... replacement - // for the mouse position, use it... - - - GetMouse( &pt ) ; + GetGlobalMouse( &pt ); + int x = pt.h; + int y = pt.v; + ScreenToClient(&x, &y); + pt.h = x; + pt.v = y; #endif control = FindControlUnderMouse( pt , window , &part ) ; if ( control ) mouseWin = wxFindControlFromMacControl( control ) ; -#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5 - if ( swapped ) - QDSwapPort( savePort , NULL ) ; -#endif } if ( mouseWin == this && !wxIsBusy() ) @@ -1778,12 +1680,12 @@ void wxWindowMac::MacInvalidateBorders() if ( m_peer == NULL ) return ; - bool vis = MacIsReallyShown() ; + bool vis = IsShownOnScreen() ; if ( !vis ) return ; int outerBorder = MacGetLeftBorderSize() ; - if ( m_peer->NeedsFocusRect() && m_peer->HasFocus() ) + if ( m_peer->NeedsFocusRect() /* && m_peer->HasFocus() */ ) outerBorder += 4 ; if ( outerBorder == 0 ) @@ -1879,7 +1781,7 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) wxPoint point(actualX, actualY); wxMoveEvent event(point, m_windowId); event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event) ; + HandleWindowEvent(event) ; } if ( doResize ) @@ -1888,7 +1790,7 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) wxSize size(actualWidth, actualHeight); wxSizeEvent event(size, m_windowId); event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); + HandleWindowEvent(event); } } } @@ -2047,7 +1949,7 @@ void wxWindowMac::SetLabel(const wxString& title) m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics) ) ; // do not trigger refreshes upon invisible and possible partly created objects - if ( MacIsReallyShown() ) + if ( IsShownOnScreen() ) Refresh() ; } @@ -2058,17 +1960,12 @@ wxString wxWindowMac::GetLabel() const bool wxWindowMac::Show(bool show) { - bool former = MacIsReallyShown() ; if ( !wxWindowBase::Show(show) ) return false; - // TODO: use visibilityChanged Carbon Event for OSX if ( m_peer ) m_peer->SetVisibility( show , true ) ; - if ( former != MacIsReallyShown() ) - MacPropagateVisibilityChanged() ; - return true; } @@ -2077,53 +1974,6 @@ void wxWindowMac::DoEnable(bool enable) m_peer->Enable( enable ) ; } -// -// status change propagations (will be not necessary for OSX later ) -// - -void wxWindowMac::MacPropagateVisibilityChanged() -{ -#if !TARGET_API_MAC_OSX - MacVisibilityChanged() ; - - wxWindowMac *child; - wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); - while ( node ) - { - child = node->GetData(); - if ( child->IsShown() ) - child->MacPropagateVisibilityChanged() ; - - node = node->GetNext(); - } -#endif -} - -void wxWindowMac::OnEnabled(bool WXUNUSED(enabled)) -{ -#if !TARGET_API_MAC_OSX - MacEnabledStateChanged() ; -#endif -} - -void wxWindowMac::MacPropagateHiliteChanged() -{ -#if !TARGET_API_MAC_OSX - MacHiliteChanged() ; - - wxWindowMac *child; - wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); - while ( node ) - { - child = node->GetData(); - if (child /* && child->IsEnabled() */) - child->MacPropagateHiliteChanged() ; - - node = node->GetNext(); - } -#endif -} - // // status change notifications // @@ -2138,37 +1988,13 @@ void wxWindowMac::MacHiliteChanged() void wxWindowMac::MacEnabledStateChanged() { + OnEnabled( m_peer->IsEnabled() ); } // // status queries on the inherited window's state // -bool wxWindowMac::MacIsReallyShown() -{ - // only under OSX the visibility of the TLW is taken into account - if ( m_isBeingDeleted ) - return false ; - -#if TARGET_API_MAC_OSX - if ( m_peer && m_peer->Ok() ) - return m_peer->IsVisible(); -#endif - - wxWindow* win = this ; - while ( win->IsShown() ) - { - if ( win->IsTopLevel() ) - return true ; - - win = win->GetParent() ; - if ( win == NULL ) - return true ; - } - - return false ; -} - bool wxWindowMac::MacIsReallyEnabled() { return m_peer->IsEnabled() ; @@ -2230,7 +2056,7 @@ void wxWindowMac::Refresh(bool WXUNUSED(eraseBack), const wxRect *rect) if ( m_peer == NULL ) return ; - if ( !MacIsReallyShown() ) + if ( !IsShownOnScreen() ) return ; if ( rect ) @@ -2246,38 +2072,25 @@ void wxWindowMac::Refresh(bool WXUNUSED(eraseBack), const wxRect *rect) } } -void wxWindowMac::Freeze() +void wxWindowMac::DoFreeze() { #if TARGET_API_MAC_OSX - if ( !m_frozenness++ ) - { - if ( m_peer && m_peer->Ok() ) - m_peer->SetDrawingEnabled( false ) ; - } + if ( m_peer && m_peer->Ok() ) + m_peer->SetDrawingEnabled( false ) ; #endif } -void wxWindowMac::Thaw() +void wxWindowMac::DoThaw() { #if TARGET_API_MAC_OSX - wxASSERT_MSG( m_frozenness > 0, wxT("Thaw() without matching Freeze()") ); - - if ( !--m_frozenness ) + if ( m_peer && m_peer->Ok() ) { - if ( m_peer && m_peer->Ok() ) - { - m_peer->SetDrawingEnabled( true ) ; - m_peer->InvalidateWithChildren() ; - } + m_peer->SetDrawingEnabled( true ) ; + m_peer->InvalidateWithChildren() ; } #endif } -bool wxWindowMac::IsFrozen() const -{ - return m_frozenness != 0; -} - wxWindowMac *wxGetActiveWindow() { // actually this is a windows-only concept @@ -2294,17 +2107,28 @@ void wxWindowMac::OnEraseBackground(wxEraseEvent& event) { if ( MacGetTopLevelWindow() == NULL ) return ; - +/* #if TARGET_API_MAC_OSX if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT ) { - event.Skip() ; } else #endif +*/ + if ( GetBackgroundStyle() == wxBG_STYLE_COLOUR ) { event.GetDC()->Clear() ; } + else if ( GetBackgroundStyle() == wxBG_STYLE_CUSTOM ) + { + // don't skip the event here, custom background means that the app + // is drawing it itself in its OnPaint(), so don't draw it at all + // now to avoid flicker + } + else + { + event.Skip() ; + } } void wxWindowMac::OnNcPaint( wxNcPaintEvent& event ) @@ -2413,21 +2237,21 @@ void wxWindowMac::MacPaintGrowBox() CGContextRef cgContext = (CGContextRef) MacGetCGContextRef() ; wxASSERT( cgContext ) ; - + m_peer->GetRect( &rect ) ; int size = m_hScrollBar ? m_hScrollBar->GetSize().y : ( m_vScrollBar ? m_vScrollBar->GetSize().x : MAC_SCROLLBAR_SIZE ) ; CGRect cgrect = CGRectMake( rect.right - size , rect.bottom - size , size , size ) ; CGPoint cgpoint = CGPointMake( rect.right - size , rect.bottom - size ) ; CGContextSaveGState( cgContext ); - + if ( m_backgroundColour.Ok() ) { - CGContextSetFillColorWithColor( cgContext, m_backgroundColour.GetCGColor() ); + CGContextSetFillColorWithColor( cgContext, m_backgroundColour.GetCGColor() ); } else { - CGContextSetRGBFillColor( cgContext, 1.0, 1.0 , 1.0 , 1.0 ); + CGContextSetRGBFillColor( cgContext, (CGFloat) 1.0, (CGFloat)1.0 ,(CGFloat) 1.0 , (CGFloat)1.0 ); } CGContextFillRect( cgContext, cgrect ); CGContextRestoreGState( cgContext ); @@ -2538,7 +2362,7 @@ void wxWindowMac::DoUpdateScrollbarVisibility() { wxSizeEvent event(GetSize(), m_windowId); event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); + HandleWindowEvent(event); } } @@ -2650,7 +2474,7 @@ void wxWindowMac::MacOnScroll( wxScrollEvent &event ) else if (event.GetEventType() == wxEVT_SCROLL_THUMBRELEASE) wevent.SetEventType( wxEVT_SCROLLWIN_THUMBRELEASE ); - GetEventHandler()->ProcessEvent(wevent); + HandleWindowEvent(wevent); } } @@ -2662,59 +2486,11 @@ wxWindowMac *wxWindowBase::DoFindFocus() return wxFindControlFromMacControl( control ) ; } -void wxWindowMac::OnSetFocus( wxFocusEvent& event ) -{ - // panel wants to track the window which was the last to have focus in it, - // so we want to set ourselves as the window which last had focus - // - // notice that it's also important to do it upwards the tree because - // otherwise when the top level panel gets focus, it won't set it back to - // us, but to some other sibling - - // CS: don't know if this is still needed: - //wxChildFocusEvent eventFocus(this); - //(void)GetEventHandler()->ProcessEvent(eventFocus); - - if ( MacGetTopLevelWindow() && m_peer->NeedsFocusRect() ) - { - GetParent()->Refresh() ; - wxMacWindowStateSaver sv( this ) ; - Rect rect ; - - m_peer->GetRect( &rect ) ; - // auf den umgebenden Rahmen zurチᅡ゚ck - InsetRect( &rect, -1 , -1 ) ; - - wxTopLevelWindowMac* top = MacGetTopLevelWindow(); - if ( top ) - { - wxPoint pt(0, 0) ; - wxMacControl::Convert( &pt , GetParent()->m_peer , top->m_peer ) ; - rect.left += pt.x ; - rect.right += pt.x ; - rect.top += pt.y ; - rect.bottom += pt.y ; - } - - bool bIsFocusEvent = (event.GetEventType() == wxEVT_SET_FOCUS); - DrawThemeFocusRect( &rect , bIsFocusEvent ) ; - if ( !bIsFocusEvent ) - { - // as this erases part of the frame we have to redraw borders - // and because our z-ordering is not always correct (staticboxes) - // we have to invalidate things, we cannot simple redraw - MacInvalidateBorders() ; - } - } - - event.Skip(); -} - void wxWindowMac::OnInternalIdle() { // This calls the UI-update mechanism (querying windows for // menu/toolbar/control state information) - if (wxUpdateUIEvent::CanUpdate(this) && IsShown()) + if (wxUpdateUIEvent::CanUpdate(this) && IsShownOnScreen()) UpdateWindowUI(wxUPDATE_UI_FROMIDLE); } @@ -2743,7 +2519,7 @@ bool wxWindowMac::MacSetupCursor( const wxPoint& pt ) { wxSetCursorEvent event( pt.x , pt.y ); - bool processedEvtSetCursor = GetEventHandler()->ProcessEvent(event); + bool processedEvtSetCursor = HandleWindowEvent(event); if ( processedEvtSetCursor && event.HasCursor() ) { cursor = event.GetCursor() ; @@ -2786,13 +2562,9 @@ void wxWindowMac::ClearBackground() void wxWindowMac::Update() { -#if TARGET_API_MAC_OSX wxTopLevelWindowMac* top = MacGetTopLevelWindow(); if (top) top->MacPerformUpdates() ; -#else - ::Draw1Control( m_peer->GetControlRef() ) ; -#endif } wxTopLevelWindowMac* wxWindowMac::MacGetTopLevelWindow() const @@ -2830,7 +2602,7 @@ const wxRegion& wxWindowMac::MacGetVisibleRegion( bool includeOuterStructures ) { static wxRegion emptyrgn ; - if ( !m_isBeingDeleted && MacIsReallyShown() /*m_peer->IsVisible() */ ) + if ( !m_isBeingDeleted && IsShownOnScreen() ) { MacUpdateClippedRects() ; if ( includeOuterStructures ) @@ -2934,7 +2706,7 @@ void wxWindowMac::MacUpdateClippedRects() const /* This function must not change the updatergn ! */ -bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time ) +bool wxWindowMac::MacDoRedraw( void* updatergnr , long time ) { bool handled = false ; Rect updatebounds ; @@ -2959,13 +2731,13 @@ bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time ) // the grow-box area of a scrolled window (scroll sample) wxDC* dc = new wxWindowDC(this); if ( IsTopLevel() ) - dc->SetClippingRegion(wxRegion(updatergn)); + dc->SetClippingRegion(wxRegion(HIShapeCreateWithQDRgn(updatergn))); else - dc->SetClippingRegion(wxRegion(newupdate)); + dc->SetClippingRegion(wxRegion(HIShapeCreateWithQDRgn(newupdate))); wxEraseEvent eevent( GetId(), dc ); eevent.SetEventObject( this ); - GetEventHandler()->ProcessEvent( eevent ); + HandleWindowEvent( eevent ); delete dc ; } @@ -2973,7 +2745,7 @@ bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time ) // calculate a client-origin version of the update rgn and set m_updateRegion to that OffsetRgn( newupdate , -origin.x , -origin.y ) ; - m_updateRegion = newupdate ; + m_updateRegion = wxRegion(HIShapeCreateWithQDRgn(newupdate)) ; DisposeRgn( newupdate ) ; if ( !m_updateRegion.Empty() ) @@ -2983,7 +2755,7 @@ bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time ) wxPaintEvent event; event.SetTimestamp(time); event.SetEventObject(this); - GetEventHandler()->ProcessEvent(event); + HandleWindowEvent(event); handled = true ; } @@ -3022,7 +2794,7 @@ bool wxWindowMac::MacDoRedraw( WXHRGN updatergnr , long time ) // paint custom borders wxNcPaintEvent eventNc( child->GetId() ); eventNc.SetEventObject( child ); - if ( !child->GetEventHandler()->ProcessEvent( eventNc ) ) + if ( !child->HandleWindowEvent( eventNc ) ) { child->MacPaintBorders(0, 0) ; } @@ -3357,7 +3129,8 @@ void wxWindowMac::OnMouseEvent( wxMouseEvent &event ) wxContextMenuEvent evtCtx(wxEVT_CONTEXT_MENU, this->GetId(), this->ClientToScreen(event.GetPosition())); - if ( ! GetEventHandler()->ProcessEvent(evtCtx) ) + evtCtx.SetEventObject(this); + if ( ! HandleWindowEvent(evtCtx) ) event.Skip() ; } else @@ -3434,3 +3207,29 @@ wxByte wxWindowMac::GetTransparent() const { return m_macAlpha ; } + +bool wxWindowMac::IsShownOnScreen() const +{ +#if TARGET_API_MAC_OSX + if ( m_peer && m_peer->Ok() ) + { + bool peerVis = m_peer->IsVisible(); + bool wxVis = wxWindowBase::IsShownOnScreen(); + if( peerVis != wxVis ) + { + // CS : put a breakpoint here to investigate differences + // between native an wx visibilities + // the only place where I've encountered them until now + // are the hiding/showing sequences where the vis-changed event is + // first sent to the innermost control, while wx does things + // from the outmost control + wxVis = wxWindowBase::IsShownOnScreen(); + return wxVis; + } + + return m_peer->IsVisible(); + } +#endif + + return wxWindowBase::IsShownOnScreen(); +}