Allow ignoring margins in wxRendererNative::GetCheckBoxSize()
Add ability to get the size of the checkbox without any margins by passing wxCONTROL_CELL flag: this can be useful when the checkbox is part of some "cell", e.g. wxGrid one, and doesn't need any extra margins around it. Currently wxCONTROL_CELL is only really used by wxGTK2 implementation.
This commit is contained in:
committed by
Vadim Zeitlin
parent
5ad2470504
commit
53ffbf6cf5
@@ -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
|
||||
|
Reference in New Issue
Block a user