X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/58d439cf5a3d65cdb964973e111ab9dd208deab9..6604fd4c23f2a4f392d460ae2d07efd6db359234:/src/osx/window_osx.cpp diff --git a/src/osx/window_osx.cpp b/src/osx/window_osx.cpp index 237a0ad691..f9016f4511 100644 --- a/src/osx/window_osx.cpp +++ b/src/osx/window_osx.cpp @@ -67,8 +67,6 @@ #include "wx/osx/uma.h" #else #include "wx/osx/private.h" -// bring in themeing -#include #endif #define MAC_SCROLLBAR_SIZE 15 @@ -83,8 +81,6 @@ #endif BEGIN_EVENT_TABLE(wxWindowMac, wxWindowBase) - EVT_NC_PAINT(wxWindowMac::OnNcPaint) - EVT_ERASE_BACKGROUND(wxWindowMac::OnEraseBackground) EVT_MOUSE_EVENTS(wxWindowMac::OnMouseEvent) END_EVENT_TABLE() @@ -130,6 +126,7 @@ void wxWindowMac::Init() m_vScrollBar = NULL ; m_hScrollBarAlwaysShown = false; m_vScrollBarAlwaysShown = false; + m_growBox = NULL ; m_macIsUserPane = true; m_clipChildren = false ; @@ -195,13 +192,11 @@ wxWindowMac::~wxWindowMac() WXWidget wxWindowMac::GetHandle() const { - return (WXWidget) m_peer->GetWXWidget() ; + if ( m_peer ) + return (WXWidget) m_peer->GetWXWidget() ; + return NULL; } -// -// TODO END move to window_osx.cpp -// - // --------------------------------------------------------------------------- // Utility Routines to move between different coordinate systems // --------------------------------------------------------------------------- @@ -246,7 +241,11 @@ bool wxWindowMac::Create(wxWindowMac *parent, #ifndef __WXUNIVERSAL__ // Don't give scrollbars to wxControls unless they ask for them - if ( (! IsKindOf(CLASSINFO(wxControl)) && ! IsKindOf(CLASSINFO(wxStatusBar))) + if ( (! IsKindOf(CLASSINFO(wxControl)) +#if wxUSE_STATUSBAR + && ! IsKindOf(CLASSINFO(wxStatusBar)) +#endif + ) || (IsKindOf(CLASSINFO(wxControl)) && ((style & wxHSCROLL) || (style & wxVSCROLL)))) { MacCreateScrollBars( style ) ; @@ -261,10 +260,14 @@ bool wxWindowMac::Create(wxWindowMac *parent, void wxWindowMac::MacChildAdded() { +#if wxUSE_SCROLLBAR if ( m_vScrollBar ) m_vScrollBar->Raise() ; if ( m_hScrollBar ) m_hScrollBar->Raise() ; + if ( m_growBox ) + m_growBox->Raise() ; +#endif } void wxWindowMac::MacPostControlCreate(const wxPoint& WXUNUSED(pos), const wxSize& size) @@ -329,76 +332,42 @@ void wxWindowMac::DoSetWindowVariant( wxWindowVariant variant ) break ; default: - wxFAIL_MSG(_T("unexpected window variant")); + wxFAIL_MSG(wxT("unexpected window variant")); break ; } m_peer->SetData(kControlEntireControl, kControlSizeTag, &size ) ; #endif -#if wxOSX_USE_COCOA_OR_CARBON wxFont font ; -#if wxOSX_USE_ATSU_TEXT - ThemeFontID themeFont = kThemeSystemFont ; - - // we will get that from the settings later - // and make this NORMAL later, but first - // we have a few calculations that we must fix + wxOSXSystemFont systemFont = wxOSX_SYSTEM_FONT_NORMAL ; switch ( variant ) { case wxWINDOW_VARIANT_NORMAL : - themeFont = kThemeSystemFont ; + systemFont = wxOSX_SYSTEM_FONT_NORMAL ; break ; case wxWINDOW_VARIANT_SMALL : - themeFont = kThemeSmallSystemFont ; + systemFont = wxOSX_SYSTEM_FONT_SMALL ; break ; case wxWINDOW_VARIANT_MINI : - // not always defined in the headers - themeFont = 109 ; + systemFont = wxOSX_SYSTEM_FONT_MINI ; break ; case wxWINDOW_VARIANT_LARGE : - themeFont = kThemeSystemFont ; + systemFont = wxOSX_SYSTEM_FONT_NORMAL ; break ; default: - wxFAIL_MSG(_T("unexpected window variant")); + wxFAIL_MSG(wxT("unexpected window variant")); break ; } - font.MacCreateFromThemeFont( themeFont ) ; -#else - CTFontUIFontType themeFont = kCTFontSystemFontType ; - switch ( variant ) - { - case wxWINDOW_VARIANT_NORMAL : - themeFont = kCTFontSystemFontType; - break ; - - case wxWINDOW_VARIANT_SMALL : - themeFont = kCTFontSmallSystemFontType; - break ; - - case wxWINDOW_VARIANT_MINI : - themeFont = kCTFontMiniSystemFontType; - break ; - - case wxWINDOW_VARIANT_LARGE : - themeFont = kCTFontSystemFontType; - break ; - - default: - wxFAIL_MSG(_T("unexpected window variant")); - break ; - } - font.MacCreateFromUIFont( themeFont ) ; -#endif + font.CreateSystemFont( systemFont ) ; SetFont( font ) ; -#endif } void wxWindowMac::MacUpdateControlFont() @@ -441,11 +410,25 @@ bool wxWindowMac::SetBackgroundColour(const wxColour& col ) return true ; } +static bool wxIsWindowOrParentDisabled(wxWindow* w) +{ + while (w && !w->IsTopLevel()) + { + if (!w->IsEnabled()) + return true; + w = w->GetParent(); + } + return false; +} + void wxWindowMac::SetFocus() { if ( !AcceptsFocus() ) return ; + if (wxIsWindowOrParentDisabled((wxWindow*) this)) + return; + wxWindow* former = FindFocus() ; if ( former == this ) return ; @@ -504,8 +487,8 @@ bool wxWindowMac::MacGetBoundsForControl( x = (int)pos.x; y = (int)pos.y; - w = WidthDefault( size.x ); - h = HeightDefault( size.y ); + w = WidthDefault( size.x ); + h = HeightDefault( size.y ); x += MacGetLeftBorderSize() ; y += MacGetTopBorderSize() ; @@ -541,7 +524,7 @@ void wxWindowMac::DoGetSize(int *x, int *y) const void wxWindowMac::DoGetPosition(int *x, int *y) const { int x1, y1; - + m_peer->GetPosition( x1, y1 ) ; // get the wx window position from the native one @@ -670,13 +653,13 @@ wxSize wxWindowMac::DoGetSizeFromClientSize( const wxSize & size ) const int innerwidth, innerheight; int left, top; int outerwidth, outerheight; - + m_peer->GetContentArea( left, top, innerwidth, innerheight ); m_peer->GetSize( outerwidth, outerheight ); - + sizeTotal.x += outerwidth-innerwidth; sizeTotal.y += outerheight-innerheight; - + sizeTotal.x += MacGetLeftBorderSize() + MacGetRightBorderSize() ; sizeTotal.y += MacGetTopBorderSize() + MacGetBottomBorderSize() ; @@ -689,15 +672,16 @@ void wxWindowMac::DoGetClientSize( int *x, int *y ) const int ww, hh; int left, top; - - m_peer->GetContentArea( left, top, ww, hh ); + m_peer->GetContentArea( left, top, ww, hh ); +#if wxUSE_SCROLLBAR if (m_hScrollBar && m_hScrollBar->IsShown() ) hh -= m_hScrollBar->GetSize().y ; if (m_vScrollBar && m_vScrollBar->IsShown() ) ww -= m_vScrollBar->GetSize().x ; +#endif if (x) *x = ww; if (y) @@ -782,19 +766,17 @@ void wxWindowMac::MacInvalidateBorders() return ; int outerBorder = MacGetLeftBorderSize() ; -#if wxOSX_USE_CARBON - if ( m_peer->NeedsFocusRect() /* && m_peer->HasFocus() */ ) + + if ( m_peer->NeedsFocusRect() ) outerBorder += 4 ; -#endif if ( outerBorder == 0 ) return ; // now we know that we have something to do at all - int tx,ty,tw,th; - + m_peer->GetSize( tw, th ); m_peer->GetPosition( tx, ty ); @@ -802,7 +784,7 @@ void wxWindowMac::MacInvalidateBorders() wxRect rightupdate( tx+tw, ty, outerBorder, th ); wxRect topupdate( tx-outerBorder, ty-outerBorder, tw + 2 * outerBorder, outerBorder ); wxRect bottomupdate( tx-outerBorder, ty + th, tw + 2 * outerBorder, outerBorder ); - + if (GetParent()) { GetParent()->m_peer->SetNeedsDisplay(&leftupdate); GetParent()->m_peer->SetNeedsDisplay(&rightupdate); @@ -833,6 +815,8 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) int actualX = x; int actualY = y; +#if 0 + // min and max sizes are only for sizers, not for explicit size setting if ((m_minWidth != -1) && (actualWidth < m_minWidth)) actualWidth = m_minWidth; if ((m_minHeight != -1) && (actualHeight < m_minHeight)) @@ -841,6 +825,7 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) actualWidth = m_maxWidth; if ((m_maxHeight != -1) && (actualHeight > m_maxHeight)) actualHeight = m_maxHeight; +#endif bool doMove = false, doResize = false ; @@ -866,7 +851,7 @@ void wxWindowMac::DoMoveWindow(int x, int y, int width, int height) MacInvalidateBorders() ; m_cachedClippedRectValid = false ; - + m_peer->Move( bounds.x, bounds.y, bounds.width, bounds.height); wxWindowMac::MacSuperChangedPosition() ; // like this only children will be notified @@ -902,7 +887,7 @@ wxSize wxWindowMac::DoGetBestSize() const else { wxRect r ; - + m_peer->GetBestRect(&r); if ( r.GetWidth() == 0 && r.GetHeight() == 0 ) @@ -912,25 +897,30 @@ wxSize wxWindowMac::DoGetBestSize() const r.width = r.height = 16 ; - if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) + if ( 0 ) + { + } +#if wxUSE_SCROLLBAR + else if ( IsKindOf( CLASSINFO( wxScrollBar ) ) ) { r.height = 16 ; } - #if wxUSE_SPINBTN +#endif +#if wxUSE_SPINBTN else if ( IsKindOf( CLASSINFO( wxSpinButton ) ) ) { r.height = 24 ; } - #endif +#endif else { // return wxWindowBase::DoGetBestSize() ; } } - int bestWidth = r.width + MacGetLeftBorderSize() + + int bestWidth = r.width + MacGetLeftBorderSize() + MacGetRightBorderSize(); - int bestHeight = r.height + MacGetTopBorderSize() + + int bestHeight = r.height + MacGetTopBorderSize() + MacGetBottomBorderSize(); if ( bestHeight < 10 ) bestHeight = 13 ; @@ -1042,8 +1032,13 @@ void wxWindowMac::DoSetClientSize(int clientwidth, int clientheight) void wxWindowMac::SetLabel(const wxString& title) { + if ( title == m_label ) + return; + m_label = title ; + InvalidateBestSize(); + if ( m_peer && m_peer->IsOk() ) m_peer->SetLabel( wxStripMenuCodes(m_label, wxStrip_Mnemonics), GetFont().GetEncoding() ) ; @@ -1065,6 +1060,22 @@ bool wxWindowMac::Show(bool show) if ( m_peer ) m_peer->SetVisibility( show ) ; + wxShowEvent eventShow(GetId(), show); + eventShow.SetEventObject(this); + + HandleWindowEvent(eventShow); + + return true; +} + +bool wxWindowMac::OSXShowWithEffect(bool show, + wxShowEffect effect, + unsigned timeout) +{ + if ( effect == wxSHOW_EFFECT_NONE || + !m_peer || !m_peer->ShowWithEffect(show, effect, timeout) ) + return Show(show); + return true; } @@ -1124,8 +1135,11 @@ int wxWindowMac::GetCharWidth() const return width; } -void wxWindowMac::GetTextExtent(const wxString& str, int *x, int *y, - int *descent, int *externalLeading, const wxFont *theFont ) const +void wxWindowMac::DoGetTextExtent(const wxString& str, + int *x, int *y, + int *descent, + int *externalLeading, + const wxFont *theFont) const { const wxFont *fontToUse = theFont; wxFont tempFont; @@ -1140,9 +1154,9 @@ void wxWindowMac::GetTextExtent(const wxString& str, int *x, int *y, wxDouble h , d , e , w; ctx->GetTextExtent( str, &w, &h, &d, &e ); - + delete ctx; - + if ( externalLeading ) *externalLeading = (wxCoord)(e+0.5); if ( descent ) @@ -1165,7 +1179,7 @@ void wxWindowMac::Refresh(bool WXUNUSED(eraseBack), const wxRect *rect) if ( !IsShownOnScreen() ) return ; - + m_peer->SetNeedsDisplay( rect ) ; } @@ -1195,46 +1209,37 @@ wxWindow *wxGetActiveWindow() } // Coordinates relative to the window -void wxWindowMac::WarpPointer(int WXUNUSED(x_pos), int WXUNUSED(y_pos)) +void wxWindowMac::WarpPointer(int x_pos, int y_pos) { - // We really don't move the mouse programmatically under Mac. -} - -void wxWindowMac::OnEraseBackground(wxEraseEvent& event) -{ - if ( MacGetTopLevelWindow() == NULL ) - return ; -/* -#if TARGET_API_MAC_OSX - if ( !m_backgroundColour.Ok() || GetBackgroundStyle() == wxBG_STYLE_TRANSPARENT ) - { - } - else +#if wxOSX_USE_COCOA_OR_CARBON + int x = x_pos; + int y = y_pos; + DoClientToScreen(&x, &y); + CGPoint cgpoint = CGPointMake( x, y ); + CGWarpMouseCursorPosition( cgpoint ); + + // At least GTK sends a mouse moved event after WarpMouse + wxMouseEvent event(wxEVT_MOTION); + event.m_x = x_pos; + event.m_y = y_pos; + wxMouseState mState = ::wxGetMouseState(); + + event.m_altDown = mState.AltDown(); + event.m_controlDown = mState.ControlDown(); + event.m_leftDown = mState.LeftIsDown(); + event.m_middleDown = mState.MiddleIsDown(); + event.m_rightDown = mState.RightIsDown(); + event.m_metaDown = mState.MetaDown(); + event.m_shiftDown = mState.ShiftDown(); + event.SetId(GetId()); + event.SetEventObject(this); + GetEventHandler()->ProcessEvent(event); #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 ) -{ - event.Skip() ; } int wxWindowMac::GetScrollPos(int orient) const { +#if wxUSE_SCROLLBAR if ( orient == wxHORIZONTAL ) { if ( m_hScrollBar ) @@ -1245,7 +1250,7 @@ int wxWindowMac::GetScrollPos(int orient) const if ( m_vScrollBar ) return m_vScrollBar->GetThumbPosition() ; } - +#endif return 0; } @@ -1253,6 +1258,7 @@ int wxWindowMac::GetScrollPos(int orient) const // of positions that we can scroll. int wxWindowMac::GetScrollRange(int orient) const { +#if wxUSE_SCROLLBAR if ( orient == wxHORIZONTAL ) { if ( m_hScrollBar ) @@ -1263,12 +1269,13 @@ int wxWindowMac::GetScrollRange(int orient) const if ( m_vScrollBar ) return m_vScrollBar->GetRange() ; } - +#endif return 0; } int wxWindowMac::GetScrollThumb(int orient) const { +#if wxUSE_SCROLLBAR if ( orient == wxHORIZONTAL ) { if ( m_hScrollBar ) @@ -1279,12 +1286,13 @@ int wxWindowMac::GetScrollThumb(int orient) const if ( m_vScrollBar ) return m_vScrollBar->GetThumbSize() ; } - +#endif return 0; } void wxWindowMac::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh)) { +#if wxUSE_SCROLLBAR if ( orient == wxHORIZONTAL ) { if ( m_hScrollBar ) @@ -1295,6 +1303,7 @@ void wxWindowMac::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh)) if ( m_vScrollBar ) m_vScrollBar->SetThumbPosition( pos ) ; } +#endif } void @@ -1328,13 +1337,15 @@ void wxWindowMac::MacPaintGrowBox() if ( IsTopLevel() ) return ; +#if wxUSE_SCROLLBAR if ( MacHasScrollBarCorner() ) { +#if 0 CGContextRef cgContext = (CGContextRef) MacGetCGContextRef() ; wxASSERT( cgContext ) ; int tx,ty,tw,th; - + m_peer->GetSize( tw, th ); m_peer->GetPosition( tx, ty ); @@ -1355,7 +1366,18 @@ void wxWindowMac::MacPaintGrowBox() } CGContextFillRect( cgContext, cgrect ); CGContextRestoreGState( cgContext ); +#else + if (m_growBox) + { + if ( m_backgroundColour.Ok() ) + m_growBox->SetBackgroundColour(m_backgroundColour); + else + m_growBox->SetBackgroundColour(*wxWHITE); + } +#endif } + +#endif } void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin) , int WXUNUSED(rightOrigin) ) @@ -1367,7 +1389,7 @@ void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin) , int WXUNUSED(right // back to the surrounding frame rectangle int tx,ty,tw,th; - + m_peer->GetSize( tw, th ); m_peer->GetPosition( tx, ty ); @@ -1381,66 +1403,55 @@ void wxWindowMac::MacPaintBorders( int WXUNUSED(leftOrigin) , int WXUNUSED(right CGRect cgrect = CGRectMake( rect.left , rect.top , rect.right - rect.left , rect.bottom - rect.top ) ; - HIThemeFrameDrawInfo info ; - memset( &info, 0 , sizeof(info) ) ; - - info.version = 0 ; - info.kind = 0 ; - info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ; - info.isFocused = hasFocus ; - CGContextRef cgContext = (CGContextRef) GetParent()->MacGetCGContextRef() ; wxASSERT( cgContext ) ; - if ( HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) + if ( m_peer->NeedsFrame() ) { - info.kind = kHIThemeFrameTextFieldSquare ; - HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ; - } - else if ( HasFlag(wxSIMPLE_BORDER) ) - { - info.kind = kHIThemeFrameListBox ; - HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ; + HIThemeFrameDrawInfo info ; + memset( &info, 0 , sizeof(info) ) ; + + info.version = 0 ; + info.kind = 0 ; + info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ; + info.isFocused = hasFocus ; + + if ( HasFlag(wxRAISED_BORDER) || HasFlag(wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER) ) + { + info.kind = kHIThemeFrameTextFieldSquare ; + HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ; + } + else if ( HasFlag(wxSIMPLE_BORDER) ) + { + info.kind = kHIThemeFrameListBox ; + HIThemeDrawFrame( &cgrect , &info , cgContext , kHIThemeOrientationNormal ) ; + } } - else if ( hasFocus ) + + if ( hasFocus ) { HIThemeDrawFocusRect( &cgrect , true , cgContext , kHIThemeOrientationNormal ) ; } -#if 0 // TODO REMOVE now done in a separate call earlier in drawing the window itself - m_peer->GetRect( &rect ) ; - if ( MacHasScrollBarCorner() ) - { - int variant = (m_hScrollBar == NULL ? m_vScrollBar : m_hScrollBar ) ->GetWindowVariant(); - 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 ) ; - HIThemeGrowBoxDrawInfo info ; - memset( &info, 0, sizeof(info) ) ; - info.version = 0 ; - info.state = IsEnabled() ? kThemeStateActive : kThemeStateInactive ; - info.kind = kHIThemeGrowBoxKindNone ; - // contrary to the docs ...SizeSmall does not work - info.size = kHIThemeGrowBoxSizeNormal ; - info.direction = 0 ; - HIThemeDrawGrowBox( &cgpoint , &info , cgContext , kHIThemeOrientationNormal ) ; - } -#endif } #endif // wxOSX_USE_COCOA_OR_CARBON } void wxWindowMac::RemoveChild( wxWindowBase *child ) { +#if wxUSE_SCROLLBAR if ( child == m_hScrollBar ) m_hScrollBar = NULL ; if ( child == m_vScrollBar ) m_vScrollBar = NULL ; - + if ( child == m_growBox ) + m_growBox = NULL ; +#endif wxWindowBase::RemoveChild( child ) ; } void wxWindowMac::DoUpdateScrollbarVisibility() { +#if wxUSE_SCROLLBAR bool triggerSizeEvent = false; if ( m_hScrollBar ) @@ -1472,18 +1483,21 @@ void wxWindowMac::DoUpdateScrollbarVisibility() event.SetEventObject(this); HandleWindowEvent(event); } +#endif } // New function that will replace some of the above. void wxWindowMac::SetScrollbar(int orient, int pos, int thumb, int range, bool refresh) { +#if wxUSE_SCROLLBAR if ( orient == wxHORIZONTAL && m_hScrollBar ) m_hScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh); else if ( orient == wxVERTICAL && m_vScrollBar ) m_vScrollBar->SetScrollbar(pos, thumb, range, thumb, refresh); DoUpdateScrollbarVisibility(); +#endif } // Does a physical scroll @@ -1512,10 +1526,14 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) child = node->GetData(); if (child == NULL) continue; +#if wxUSE_SCROLLBAR if (child == m_vScrollBar) continue; if (child == m_hScrollBar) continue; + if (child == m_growBox) + continue; +#endif if (child->IsTopLevel()) continue; @@ -1536,6 +1554,7 @@ void wxWindowMac::ScrollWindow(int dx, int dy, const wxRect *rect) void wxWindowMac::MacOnScroll( wxScrollEvent &event ) { +#if wxUSE_SCROLLBAR if ( event.GetEventObject() == m_vScrollBar || event.GetEventObject() == m_hScrollBar ) { wxScrollWinEvent wevent; @@ -1562,18 +1581,12 @@ void wxWindowMac::MacOnScroll( wxScrollEvent &event ) HandleWindowEvent(wevent); } +#endif } -// Get the window with the focus wxWindow *wxWindowBase::DoFindFocus() { -#if wxOSX_USE_CARBON - ControlRef control ; - GetKeyboardFocus( GetUserFocusWindow() , &control ) ; - return wxFindWindowFromWXWidget( (WXWidget) control ) ; -#else - return NULL; -#endif + return wxFindWindowFromWXWidget(wxWidgetImpl::FindFocus()); } void wxWindowMac::OnInternalIdle() @@ -1733,7 +1746,7 @@ void wxWindowMac::MacUpdateClippedRects() const Rect rIncludingOuterStructures ; int tx,ty,tw,th; - + m_peer->GetSize( tw, th ); m_peer->GetPosition( tx, ty ); @@ -1820,37 +1833,62 @@ void wxWindowMac::MacUpdateClippedRects() const bool wxWindowMac::MacDoRedraw( long time ) { bool handled = false ; - + wxRegion formerUpdateRgn = m_updateRegion; wxRegion clientUpdateRgn = formerUpdateRgn; - wxSize sz = GetClientSize() ; - wxPoint origin = GetClientAreaOrigin() ; - - clientUpdateRgn.Intersect(origin.x , origin.y , origin.x + sz.x , origin.y + sz.y); - + const wxRect clientRect = GetClientRect(); + + clientUpdateRgn.Intersect(clientRect); + // first send an erase event to the entire update area + const wxBackgroundStyle bgStyle = GetBackgroundStyle(); + switch ( bgStyle ) { - // for the toplevel window this really is the entire area - // for all the others only their client area, otherwise they - // might be drawing with full alpha and eg put blue into - // the grow-box area of a scrolled window (scroll sample) - wxDC* dc = new wxWindowDC(this); - if ( IsTopLevel() ) - dc->SetDeviceClippingRegion(formerUpdateRgn); - else - dc->SetDeviceClippingRegion(clientUpdateRgn); + case wxBG_STYLE_ERASE: + case wxBG_STYLE_SYSTEM: + { + // for the toplevel window this really is the entire area for + // all the others only their client area, otherwise they might + // be drawing with full alpha and eg put blue into the grow-box + // area of a scrolled window (scroll sample) + wxWindowDC dc(this); + if ( IsTopLevel() ) + dc.SetDeviceClippingRegion(formerUpdateRgn); + else + dc.SetDeviceClippingRegion(clientUpdateRgn); + + if ( bgStyle == wxBG_STYLE_ERASE ) + { + wxEraseEvent eevent( GetId(), &dc ); + eevent.SetEventObject( this ); + if ( ProcessWindowEvent( eevent ) ) + break; + } + + if ( UseBgCol() ) + { + dc.SetBackground(GetBackgroundColour()); + dc.Clear(); + } + } + break; + + case wxBG_STYLE_PAINT: + case wxBG_STYLE_TRANSPARENT: + // nothing to do, user-defined EVT_PAINT handler will overwrite the + // entire window client area + break; - wxEraseEvent eevent( GetId(), dc ); - eevent.SetEventObject( this ); - HandleWindowEvent( eevent ); - delete dc ; + default: + wxFAIL_MSG( "unsupported background style" ); } MacPaintGrowBox(); - // calculate a client-origin version of the update rgn and set m_updateRegion to that - clientUpdateRgn.Offset( -origin.x , -origin.y ); + // calculate a client-origin version of the update rgn and set + // m_updateRegion to that + clientUpdateRgn.Offset(-clientRect.GetPosition()); m_updateRegion = clientUpdateRgn ; if ( !m_updateRegion.Empty() ) @@ -1882,10 +1920,14 @@ void wxWindowMac::MacPaintChildrenBorders() child = node->GetData(); if (child == NULL) continue; +#if wxUSE_SCROLLBAR if (child == m_vScrollBar) continue; if (child == m_hScrollBar) continue; + if (child == m_growBox) + continue; +#endif if (child->IsTopLevel()) continue; if (!child->IsShown()) @@ -1895,7 +1937,7 @@ void wxWindowMac::MacPaintChildrenBorders() child->GetPosition( &x, &y ); child->GetSize( &w, &h ); - + if ( m_updateRegion.Contains(clientOrigin.x+x-10, clientOrigin.y+y-10, w+20, h+20) ) { // paint custom borders @@ -1912,12 +1954,13 @@ void wxWindowMac::MacPaintChildrenBorders() WXWindow wxWindowMac::MacGetTopLevelWindowRef() const { - wxNonOwnedWindow* tlw = MacGetTopLevelWindow(); + wxNonOwnedWindow* tlw = MacGetTopLevelWindow(); return tlw ? tlw->GetWXWindow() : NULL ; } bool wxWindowMac::MacHasScrollBarCorner() const { +#if wxUSE_SCROLLBAR /* Returns whether the scroll bars in a wxScrolledWindow should be * shortened. Scroll bars should be shortened if either: * @@ -1978,10 +2021,14 @@ bool wxWindowMac::MacHasScrollBarCorner() const // No parent frame found return false ; } +#else + return false; +#endif } void wxWindowMac::MacCreateScrollBars( long style ) { +#if wxUSE_SCROLLBAR wxASSERT_MSG( m_vScrollBar == NULL && m_hScrollBar == NULL , wxT("attempt to create window twice") ) ; if ( style & ( wxVSCROLL | wxHSCROLL ) ) @@ -2013,22 +2060,32 @@ void wxWindowMac::MacCreateScrollBars( long style ) m_hScrollBar = new wxScrollBar((wxWindow*)this, wxID_ANY, hPoint, hSize , wxHORIZONTAL); m_hScrollBar->SetMinSize( wxDefaultSize ); } + + wxPoint gPoint(width - scrlsize, height - scrlsize); + wxSize gSize(scrlsize, scrlsize); + m_growBox = new wxPanel((wxWindow *)this, wxID_ANY, gPoint, gSize, 0); } // because the create does not take into account the client area origin // we might have a real position shift MacRepositionScrollBars() ; +#endif } bool wxWindowMac::MacIsChildOfClientArea( const wxWindow* child ) const { - bool result = ((child == NULL) || ((child != m_hScrollBar) && (child != m_vScrollBar))); + bool result = ((child == NULL) +#if wxUSE_SCROLLBAR + || ((child != m_hScrollBar) && (child != m_vScrollBar) && (child != m_growBox)) +#endif + ); return result ; } void wxWindowMac::MacRepositionScrollBars() { +#if wxUSE_SCROLLBAR if ( !m_hScrollBar && !m_vScrollBar ) return ; @@ -2051,11 +2108,29 @@ void wxWindowMac::MacRepositionScrollBars() m_vScrollBar->SetSize( vPoint.x , vPoint.y, vSize.x, vSize.y , wxSIZE_ALLOW_MINUS_ONE ); if ( m_hScrollBar ) m_hScrollBar->SetSize( hPoint.x , hPoint.y, hSize.x, hSize.y, wxSIZE_ALLOW_MINUS_ONE ); + if ( m_growBox ) + { + if ( MacHasScrollBarCorner() ) + { + m_growBox->SetSize( width - scrlsize, height - scrlsize, wxDefaultCoord, wxDefaultCoord, wxSIZE_USE_EXISTING ); + if ( !m_growBox->IsShown() ) + m_growBox->Show(); + } + else + { + if ( m_growBox->IsShown() ) + m_growBox->Hide(); + } + } +#endif } bool wxWindowMac::AcceptsFocus() const { - return m_peer->CanFocus() && wxWindowBase::AcceptsFocus(); + if ( MacIsUserPane() ) + return wxWindowBase::AcceptsFocus(); + else + return m_peer->CanFocus(); } void wxWindowMac::MacSuperChangedPosition() @@ -2097,25 +2172,28 @@ long wxWindowMac::MacGetLeftBorderSize() const SInt32 border = 0 ; - if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER)) + if ( m_peer && m_peer->NeedsFrame() ) { + if (HasFlag(wxRAISED_BORDER) || HasFlag( wxSUNKEN_BORDER) || HasFlag(wxDOUBLE_BORDER)) + { #if wxOSX_USE_COCOA_OR_CARBON - // this metric is only the 'outset' outside the simple frame rect - GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ; - border += 1; + // this metric is only the 'outset' outside the simple frame rect + GetThemeMetric( kThemeMetricEditTextFrameOutset , &border ) ; + border += 1; #else - border += 2; + border += 2; #endif - } - else if (HasFlag(wxSIMPLE_BORDER)) - { + } + else if (HasFlag(wxSIMPLE_BORDER)) + { #if wxOSX_USE_COCOA_OR_CARBON - // this metric is only the 'outset' outside the simple frame rect - GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; - border += 1; + // this metric is only the 'outset' outside the simple frame rect + GetThemeMetric( kThemeMetricListBoxFrameOutset , &border ) ; + border += 1; #else - border += 1; + border += 1; #endif + } } return border ; @@ -2204,7 +2282,7 @@ Rect wxMacGetBoundsForControl( wxWindowMac* window , const wxPoint& pos , const return bounds ; } -bool wxWindowMac::OSXHandleClicked( double timestampsec ) +bool wxWindowMac::OSXHandleClicked( double WXUNUSED(timestampsec) ) { return false; } @@ -2214,7 +2292,7 @@ wxInt32 wxWindowMac::MacControlHit(WXEVENTHANDLERREF WXUNUSED(handler) , WXEVENT #if wxOSX_USE_COCOA_OR_CARBON if ( OSXHandleClicked( GetEventTime((EventRef)event) ) ) return noErr; - + return eventNotHandledErr ; #else return 0; @@ -2229,6 +2307,8 @@ bool wxWindowMac::Reparent(wxWindowBase *newParentBase) m_peer->RemoveFromParent(); m_peer->Embed( GetParent()->GetPeer() ); + + MacChildAdded(); return true; } @@ -2320,7 +2400,7 @@ bool wxWindowMac::OSXHandleKeyEvent( wxKeyEvent& event ) } // -// wxWidgetImpl +// wxWidgetImpl // WX_DECLARE_HASH_MAP(WXWidget, wxWidgetImpl*, wxPointerHash, wxPointerEqual, MacControlMap); @@ -2332,7 +2412,7 @@ wxWindowMac *wxFindWindowFromWXWidget(WXWidget inControl ) wxWidgetImpl* impl = wxWidgetImpl::FindFromWXWidget( inControl ); if ( impl ) return impl->GetWXPeer(); - + return NULL; } @@ -2398,6 +2478,7 @@ void wxWidgetImpl::Init() m_isRootControl = false; m_wxPeer = NULL; m_needsFocusRect = false; + m_needsFrame = true; } void wxWidgetImpl::SetNeedsFocusRect( bool needs ) @@ -2410,3 +2491,12 @@ bool wxWidgetImpl::NeedsFocusRect() const return m_needsFocusRect; } +void wxWidgetImpl::SetNeedsFrame( bool needs ) +{ + m_needsFrame = needs; +} + +bool wxWidgetImpl::NeedsFrame() const +{ + return m_needsFrame; +}