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
@@ -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); }
|
||||
|
@@ -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.
|
||||
|
@@ -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)
|
||||
|
@@ -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
|
||||
|
@@ -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)
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user