X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/ce00f59b5b169752d2f05ce3bb1a88ddc1b38b4c..47e175a24f862aa8b7ca7dd4a2bb5957991e7f2d:/src/osx/carbon/renderer.cpp diff --git a/src/osx/carbon/renderer.cpp b/src/osx/carbon/renderer.cpp index 2481dd2242..343cf63f44 100644 --- a/src/osx/carbon/renderer.cpp +++ b/src/osx/carbon/renderer.cpp @@ -31,6 +31,7 @@ #include "wx/renderer.h" #include "wx/graphics.h" #include "wx/dcgraph.h" +#include "wx/splitter.h" #include "wx/osx/private.h" #ifdef wxHAS_DRAW_TITLE_BAR_BITMAP @@ -39,12 +40,17 @@ #endif // wxHAS_DRAW_TITLE_BAR_BITMAP -// check if we're currently in a paint event -inline bool wxInPaintEvent(wxWindow* win, wxDC& dc) +// check if we're having a CGContext we can draw into +inline bool wxHasCGContext(wxWindow* WXUNUSED(win), wxDC& dc) { - return win->MacGetCGContextRef() != NULL || - // wxMemoryDC's also have a valid CGContext. - dc.IsKindOf( CLASSINFO(wxMemoryDC) ); + wxGCDCImpl* gcdc = wxDynamicCast( dc.GetImpl() , wxGCDCImpl); + + if ( gcdc ) + { + if ( gcdc->GetGraphicsContext()->GetNativeContext() ) + return true; + } + return false; } @@ -62,6 +68,8 @@ public: virtual int GetHeaderButtonHeight(wxWindow *win); + virtual int GetHeaderButtonMargin(wxWindow *win); + // draw the expanded/collapsed icon for a tree control item virtual void DrawTreeItemButton( wxWindow *win, wxDC& dc, @@ -116,6 +124,8 @@ public: int flags = 0); #endif // wxHAS_DRAW_TITLE_BAR_BITMAP + virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win); + private: void DrawMacThemeButton(wxWindow *win, wxDC& dc, @@ -156,7 +166,7 @@ int wxRendererMac::DrawHeaderButton( wxWindow *win, dc.SetBrush( *wxTRANSPARENT_BRUSH ); HIRect headerRect = CGRectMake( x, y, w, h ); - if ( !wxInPaintEvent(win, dc) ) + if ( !wxHasCGContext(win, dc) ) { win->Refresh( &rect ); } @@ -175,7 +185,7 @@ int wxRendererMac::DrawHeaderButton( wxWindow *win, drawInfo.version = 0; drawInfo.kind = kThemeListHeaderButton; drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive; - drawInfo.value = (flags & wxCONTROL_SELECTED) ? kThemeButtonOn : kThemeButtonOff; + drawInfo.value = (flags & wxCONTROL_PRESSED) ? kThemeButtonOn : kThemeButtonOff; drawInfo.adornment = kThemeAdornmentNone; // The down arrow is drawn automatically, change it to an up arrow if needed. @@ -185,7 +195,7 @@ int wxRendererMac::DrawHeaderButton( wxWindow *win, HIThemeDrawButton( &headerRect, &drawInfo, cgContext, kHIThemeOrientationNormal, &labelRect ); // If we don't want any arrows we need to draw over the one already there - if ( (flags & wxCONTROL_SELECTED) && (sortArrow == wxHDR_SORT_ICON_NONE) ) + if ( (flags & wxCONTROL_PRESSED) && (sortArrow == wxHDR_SORT_ICON_NONE) ) { // clip to the header rectangle CGContextSaveGState( cgContext ); @@ -201,12 +211,12 @@ int wxRendererMac::DrawHeaderButton( wxWindow *win, // Reserve room for the arrows before writing the label, and turn off the // flags we've already handled wxRect newRect(rect); - if ( (flags & wxCONTROL_SELECTED) && (sortArrow != wxHDR_SORT_ICON_NONE) ) + if ( (flags & wxCONTROL_PRESSED) && (sortArrow != wxHDR_SORT_ICON_NONE) ) { newRect.width -= 12; sortArrow = wxHDR_SORT_ICON_NONE; } - flags &= ~wxCONTROL_SELECTED; + flags &= ~wxCONTROL_PRESSED; return DrawHeaderButtonContents(win, dc, newRect, flags, sortArrow, params); } @@ -225,6 +235,12 @@ int wxRendererMac::GetHeaderButtonHeight(wxWindow* WXUNUSED(win)) return -1; } +int wxRendererMac::GetHeaderButtonMargin(wxWindow *WXUNUSED(win)) +{ + wxFAIL_MSG( "GetHeaderButtonMargin() not implemented" ); + return -1; +} + void wxRendererMac::DrawTreeItemButton( wxWindow *win, wxDC& dc, const wxRect& rect, @@ -239,7 +255,7 @@ void wxRendererMac::DrawTreeItemButton( wxWindow *win, dc.SetBrush( *wxTRANSPARENT_BRUSH ); HIRect headerRect = CGRectMake( x, y, w, h ); - if ( !wxInPaintEvent(win, dc) ) + if ( !wxHasCGContext(win, dc) ) { win->Refresh( &rect ); } @@ -266,6 +282,37 @@ void wxRendererMac::DrawTreeItemButton( wxWindow *win, } } +wxSplitterRenderParams +wxRendererMac::GetSplitterParams(const wxWindow *win) +{ + // see below + SInt32 sashWidth, + border; +#if wxOSX_USE_COCOA + if ( win->HasFlag(wxSP_3DSASH) ) + GetThemeMetric( kThemeMetricPaneSplitterHeight, &sashWidth ); // Cocoa == Carbon == 7 + else if ( win->HasFlag(wxSP_NOSASH) ) // actually Cocoa doesn't allow 0 + sashWidth = 0; + else // no 3D effect - Cocoa [NSSplitView dividerThickNess] for NSSplitViewDividerStyleThin + sashWidth = 1; +#else // Carbon + if ( win->HasFlag(wxSP_3DSASH) ) + GetThemeMetric( kThemeMetricPaneSplitterHeight, &sashWidth ); + else if ( win->HasFlag(wxSP_NOSASH) ) + sashWidth = 0; + else // no 3D effect + GetThemeMetric( kThemeMetricSmallPaneSplitterHeight, &sashWidth ); +#endif // Cocoa/Carbon + + if ( win->HasFlag(wxSP_3DBORDER) ) + border = 2; + else // no 3D effect + border = 0; + + return wxSplitterRenderParams(sashWidth, border, false); +} + + void wxRendererMac::DrawSplitterSash( wxWindow *win, wxDC& dc, const wxSize& size, @@ -275,7 +322,9 @@ void wxRendererMac::DrawSplitterSash( wxWindow *win, { bool hasMetal = win->MacGetTopLevelWindow()->GetExtraStyle() & wxFRAME_EX_METAL; SInt32 height; - GetThemeMetric( kThemeMetricSmallPaneSplitterHeight, &height ); + + height = wxRendererNative::Get().GetSplitterParams(win).widthSash; + HIRect splitterRect; if (orient == wxVERTICAL) splitterRect = CGRectMake( position, 0, height, size.y ); @@ -285,7 +334,7 @@ void wxRendererMac::DrawSplitterSash( wxWindow *win, // under compositing we should only draw when called by the OS, otherwise just issue a redraw command // strange redraw errors occur if we don't do this - if ( !wxInPaintEvent(win, dc) ) + if ( !wxHasCGContext(win, dc) ) { wxRect rect( (int) splitterRect.origin.x, (int) splitterRect.origin.y, (int) splitterRect.size.width, (int) splitterRect.size.height ); @@ -310,11 +359,14 @@ void wxRendererMac::DrawSplitterSash( wxWindow *win, CGContextFillRect(cgContext,splitterRect); } - HIThemeSplitterDrawInfo drawInfo; - drawInfo.version = 0; - drawInfo.state = kThemeStateActive; - drawInfo.adornment = hasMetal ? kHIThemeSplitterAdornmentMetal : kHIThemeSplitterAdornmentNone; - HIThemeDrawPaneSplitter( &splitterRect, &drawInfo, cgContext, kHIThemeOrientationNormal ); + if ( win->HasFlag(wxSP_3DSASH) ) + { + HIThemeSplitterDrawInfo drawInfo; + drawInfo.version = 0; + drawInfo.state = kThemeStateActive; + drawInfo.adornment = hasMetal ? kHIThemeSplitterAdornmentMetal : kHIThemeSplitterAdornmentNone; + HIThemeDrawPaneSplitter( &splitterRect, &drawInfo, cgContext, kHIThemeOrientationNormal ); + } } } @@ -355,7 +407,7 @@ wxRendererMac::DrawMacThemeButton(wxWindow *win, dc.SetBrush( *wxTRANSPARENT_BRUSH ); HIRect headerRect = CGRectMake( x, y, w, h ); - if ( !wxInPaintEvent(win, dc) ) + if ( !wxHasCGContext(win, dc) ) { win->Refresh( &rect ); } @@ -372,7 +424,7 @@ wxRendererMac::DrawMacThemeButton(wxWindow *win, drawInfo.version = 0; drawInfo.kind = kind; drawInfo.state = (flags & wxCONTROL_DISABLED) ? kThemeStateInactive : kThemeStateActive; - drawInfo.value = (flags & wxCONTROL_SELECTED) ? kThemeButtonOn : kThemeButtonOff; + drawInfo.value = (flags & wxCONTROL_PRESSED) ? kThemeButtonOn : kThemeButtonOff; if (flags & wxCONTROL_UNDETERMINED) drawInfo.value = kThemeButtonMixed; drawInfo.adornment = adornment; @@ -390,7 +442,7 @@ wxRendererMac::DrawCheckBox(wxWindow *win, int flags) { if (flags & wxCONTROL_CHECKED) - flags |= wxCONTROL_SELECTED; + flags |= wxCONTROL_PRESSED; int kind; @@ -542,7 +594,7 @@ void wxRendererMac::DrawRadioBitmap(wxWindow* win, wxDC& dc, kind = kThemeRadioButton; if (flags & wxCONTROL_CHECKED) - flags |= wxCONTROL_SELECTED; + flags |= wxCONTROL_PRESSED; DrawMacThemeButton(win, dc, rect, flags, kind, kThemeAdornmentNone); @@ -563,7 +615,7 @@ void wxRendererMac::DrawTextCtrl(wxWindow* win, wxDC& dc, dc.SetBrush( *wxTRANSPARENT_BRUSH ); HIRect hiRect = CGRectMake( x, y, w, h ); - if ( !wxInPaintEvent(win, dc) ) + if ( !wxHasCGContext(win, dc) ) { win->Refresh( &rect ); }