diff --git a/include/wx/renderer.h b/include/wx/renderer.h index 4a4b92375a..da22e391cb 100644 --- a/include/wx/renderer.h +++ b/include/wx/renderer.h @@ -259,7 +259,7 @@ public: int flags = 0) = 0; // Returns the default size of a check box. - virtual wxSize GetCheckBoxSize(wxWindow *win) = 0; + virtual wxSize GetCheckBoxSize(wxWindow *win, int flags = 0) = 0; // Returns the default size of a check mark. virtual wxSize GetCheckMarkSize(wxWindow *win) = 0; @@ -496,8 +496,8 @@ public: int flags = 0) wxOVERRIDE { m_rendererNative.DrawCheckMark( win, dc, rect, flags ); } - virtual wxSize GetCheckBoxSize(wxWindow *win) wxOVERRIDE - { return m_rendererNative.GetCheckBoxSize(win); } + virtual wxSize GetCheckBoxSize(wxWindow *win, int flags = 0) wxOVERRIDE + { return m_rendererNative.GetCheckBoxSize(win, flags); } virtual wxSize GetCheckMarkSize(wxWindow *win) wxOVERRIDE { return m_rendererNative.GetCheckMarkSize(win); } diff --git a/interface/wx/renderer.h b/interface/wx/renderer.h index 0cb0685fc7..c73779682a 100644 --- a/interface/wx/renderer.h +++ b/interface/wx/renderer.h @@ -237,7 +237,7 @@ public: virtual void DrawCheckMark(wxWindow *win, wxDC& dc, const wxRect& rect, int flags = 0 ); - virtual wxSize GetCheckBoxSize(wxWindow *win); + virtual wxSize GetCheckBoxSize(wxWindow *win, int flags = 0); virtual wxSize GetCheckMarkSize(wxWindow *win); @@ -573,8 +573,13 @@ public: @param win A valid, i.e. non-null, window pointer which is used to get the theme defining the checkbox size under some platforms. + + @param flags The only acceptable flag is @c wxCONTROL_CELL which means + that just the size of the checkbox itself is returned, without any + margins that are included by default. This parameter is only + available in wxWidgets 3.1.4 or later. */ - virtual wxSize GetCheckBoxSize(wxWindow* win) = 0; + virtual wxSize GetCheckBoxSize(wxWindow* win, int flags = 0) = 0; /** Returns the size of a check mark. diff --git a/src/generic/renderg.cpp b/src/generic/renderg.cpp index 4a328ffaa8..b8fc63a3c0 100644 --- a/src/generic/renderg.cpp +++ b/src/generic/renderg.cpp @@ -111,7 +111,7 @@ public: const wxRect& rect, int flags = 0) wxOVERRIDE; - virtual wxSize GetCheckBoxSize(wxWindow *win) wxOVERRIDE; + virtual wxSize GetCheckBoxSize(wxWindow *win, int flags = 0) wxOVERRIDE; virtual wxSize GetCheckMarkSize(wxWindow *win) wxOVERRIDE; @@ -731,7 +731,7 @@ wxRendererGeneric::DrawCheckMark(wxWindow *WXUNUSED(win), dc.DrawCheckMark(rect); } -wxSize wxRendererGeneric::GetCheckBoxSize(wxWindow *win) +wxSize wxRendererGeneric::GetCheckBoxSize(wxWindow *win, int WXUNUSED(flags)) { wxCHECK_MSG( win, wxSize(0, 0), "Must have a valid window" ); @@ -740,7 +740,7 @@ wxSize wxRendererGeneric::GetCheckBoxSize(wxWindow *win) wxSize wxRendererGeneric::GetCheckMarkSize(wxWindow *win) { - return GetCheckBoxSize(win); + return GetCheckBoxSize(win, wxCONTROL_CELL); } wxSize wxRendererGeneric::GetExpanderSize(wxWindow *win) diff --git a/src/gtk/renderer.cpp b/src/gtk/renderer.cpp index e2dddc134a..9aa438b8ee 100644 --- a/src/gtk/renderer.cpp +++ b/src/gtk/renderer.cpp @@ -133,7 +133,7 @@ public: virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0) wxOVERRIDE; - virtual wxSize GetCheckBoxSize(wxWindow *win) wxOVERRIDE; + virtual wxSize GetCheckBoxSize(wxWindow *win, int flags = 0) wxOVERRIDE; virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win) wxOVERRIDE; }; @@ -569,7 +569,7 @@ static void CheckBoxSize(wxGtkStyleContext& sc, int& w, int& h, GtkBorder* extra #endif // __WXGTK3__ wxSize -wxRendererGTK::GetCheckBoxSize(wxWindow* win) +wxRendererGTK::GetCheckBoxSize(wxWindow* win, int flags) { wxSize size; // Even though we don't use the window in this implementation, still check @@ -578,6 +578,8 @@ wxRendererGTK::GetCheckBoxSize(wxWindow* win) wxCHECK_MSG(win, size, "Must have a valid window"); #ifdef __WXGTK3__ + wxUnusedVar(flags); + wxGtkStyleContext sc(win->GetContentScaleFactor()); sc.AddCheckButton(); if (gtk_check_version(3,20,0) == NULL) @@ -597,13 +599,27 @@ wxRendererGTK::GetCheckBoxSize(wxWindow* win) g_value_unset(&value); } #else // !__WXGTK3__ - gint indicator_size, indicator_spacing; + gint indicator_size, indicator_spacing, focus_width, focus_pad; gtk_widget_style_get(wxGTKPrivate::GetCheckButtonWidget(), "indicator_size", &indicator_size, "indicator_spacing", &indicator_spacing, + "focus-line-width", &focus_width, + "focus-padding", &focus_pad, NULL); - size.x = size.y = indicator_size + indicator_spacing * 2; + size.x = indicator_size + indicator_spacing * 2; + + // If wxCONTROL_CELL is set then we want to get the size of wxCheckBox + // control to draw the check mark centered and at the same position as + // wxCheckBox do. So we should add margins instead of removing. + // See gtk_real_check_button_draw_indicator: + // https://github.com/GNOME/gtk/blob/GTK_2_16_0/gtk/gtkcheckbutton.c#L374 + if ( flags & wxCONTROL_CELL ) + { + size.x += 2 * (focus_width + focus_pad); + } + + size.y = size.x; #endif // !__WXGTK3__ return size; @@ -618,10 +634,12 @@ wxRendererGTK::DrawCheckBox(wxWindow*, #ifndef __WXGTK3__ GtkWidget *button = wxGTKPrivate::GetCheckButtonWidget(); - gint indicator_size, indicator_spacing; + gint indicator_size, indicator_spacing, focus_width, focus_pad; gtk_widget_style_get(button, "indicator_size", &indicator_size, "indicator_spacing", &indicator_spacing, + "focus-line-width", &focus_width, + "focus-padding", &focus_pad, NULL); GtkStateType state; @@ -710,6 +728,16 @@ wxRendererGTK::DrawCheckBox(wxWindow*, if (gdk_window == NULL) return; + gint offsetX = indicator_spacing; + + // If wxCONTROL_CELL is set then we want to draw the check mark + // at the same position as wxCheckBox do. + // See wxRendererGTK::GetCheckBoxSize. + if ( flags & wxCONTROL_CELL ) + { + offsetX += focus_width + focus_pad; + } + gtk_paint_check ( gtk_widget_get_style(button), @@ -719,8 +747,8 @@ wxRendererGTK::DrawCheckBox(wxWindow*, NULL, button, "cellcheck", - dc.LogicalToDeviceX(rect.x) + indicator_spacing, - dc.LogicalToDeviceY(rect.y) + indicator_spacing, + dc.LogicalToDeviceX(rect.x) + offsetX, + dc.LogicalToDeviceY(rect.y) + (rect.height - indicator_size) / 2, indicator_size, indicator_size ); #endif diff --git a/src/msw/renderer.cpp b/src/msw/renderer.cpp index 6645283603..71ca2a489b 100644 --- a/src/msw/renderer.cpp +++ b/src/msw/renderer.cpp @@ -162,7 +162,7 @@ public: wxTitleBarButton button, int flags = 0) wxOVERRIDE; - virtual wxSize GetCheckBoxSize(wxWindow *win) wxOVERRIDE; + virtual wxSize GetCheckBoxSize(wxWindow *win, int flags = 0) wxOVERRIDE; virtual int GetHeaderButtonHeight(wxWindow *win) wxOVERRIDE; @@ -288,7 +288,7 @@ public: wxTitleBarButton button, int flags = 0) wxOVERRIDE; - virtual wxSize GetCheckBoxSize(wxWindow *win) wxOVERRIDE; + virtual wxSize GetCheckBoxSize(wxWindow *win, int flags = 0) wxOVERRIDE; virtual wxSize GetCheckMarkSize(wxWindow* win) wxOVERRIDE; @@ -548,7 +548,7 @@ wxRendererMSW::DrawTitleBarBitmap(wxWindow *win, DoDrawFrameControl(DFC_CAPTION, kind, win, dc, rect, flags); } -wxSize wxRendererMSW::GetCheckBoxSize(wxWindow* win) +wxSize wxRendererMSW::GetCheckBoxSize(wxWindow* win, int WXUNUSED(flags)) { // We must have a valid window in order to return the size which is correct // for the display this window is on. @@ -893,7 +893,7 @@ wxRendererXP::DrawTitleBarBitmap(wxWindow *win, DoDrawButtonLike(hTheme, part, dc, rect, flags); } -wxSize wxRendererXP::GetCheckBoxSize(wxWindow* win) +wxSize wxRendererXP::GetCheckBoxSize(wxWindow* win, int flags) { wxCHECK_MSG( win, wxSize(0, 0), "Must have a valid window" ); @@ -907,7 +907,7 @@ wxSize wxRendererXP::GetCheckBoxSize(wxWindow* win) return wxSize(checkSize.cx, checkSize.cy); } } - return m_rendererNative.GetCheckBoxSize(win); + return m_rendererNative.GetCheckBoxSize(win, flags); } wxSize wxRendererXP::GetCheckMarkSize(wxWindow* win) diff --git a/src/osx/carbon/renderer.cpp b/src/osx/carbon/renderer.cpp index a7bc8dcc06..933ca65ebf 100644 --- a/src/osx/carbon/renderer.cpp +++ b/src/osx/carbon/renderer.cpp @@ -90,7 +90,7 @@ public: const wxRect& rect, int flags = 0) wxOVERRIDE; - virtual wxSize GetCheckBoxSize(wxWindow* win) wxOVERRIDE; + virtual wxSize GetCheckBoxSize(wxWindow* win, int flags = 0) wxOVERRIDE; virtual void DrawComboBoxDropButton(wxWindow *win, wxDC& dc, @@ -491,7 +491,7 @@ wxRendererMac::DrawCheckBox(wxWindow *win, kind, kThemeAdornmentNone); } -wxSize wxRendererMac::GetCheckBoxSize(wxWindow* win) +wxSize wxRendererMac::GetCheckBoxSize(wxWindow* win, int WXUNUSED(flags)) { // Even though we don't use the window in this implementation, still check // that it's valid to avoid surprises when running the same code under the