Add DrawCheckMark and GetCheckMarkSize to wxRendererNative

Show its use in the render sample. Also use the recently added GetExpanderSize
for the size of DrawTreeItemButton.
This commit is contained in:
Maarten Bent
2019-08-08 00:52:06 +02:00
parent 97320c312e
commit 2874dab7f0
5 changed files with 152 additions and 3 deletions

View File

@@ -250,9 +250,20 @@ public:
const wxRect& rect, const wxRect& rect,
int flags = 0) = 0; int flags = 0) = 0;
// draw check mark
//
// flags may use wxCONTROL_DISABLED
virtual void DrawCheckMark(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags = 0) = 0;
// Returns the default size of a check box. // Returns the default size of a check box.
virtual wxSize GetCheckBoxSize(wxWindow *win) = 0; virtual wxSize GetCheckBoxSize(wxWindow *win) = 0;
// Returns the default size of a check mark.
virtual wxSize GetCheckMarkSize(wxWindow *win) = 0;
// Returns the default size of a expander. // Returns the default size of a expander.
virtual wxSize GetExpanderSize(wxWindow *win) = 0; virtual wxSize GetExpanderSize(wxWindow *win) = 0;
@@ -479,9 +490,18 @@ public:
int flags = 0) wxOVERRIDE int flags = 0) wxOVERRIDE
{ m_rendererNative.DrawCheckBox( win, dc, rect, flags ); } { m_rendererNative.DrawCheckBox( win, dc, rect, flags ); }
virtual void DrawCheckMark(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags = 0) wxOVERRIDE
{ m_rendererNative.DrawCheckMark( win, dc, rect, flags ); }
virtual wxSize GetCheckBoxSize(wxWindow *win) wxOVERRIDE virtual wxSize GetCheckBoxSize(wxWindow *win) wxOVERRIDE
{ return m_rendererNative.GetCheckBoxSize(win); } { return m_rendererNative.GetCheckBoxSize(win); }
virtual wxSize GetCheckMarkSize(wxWindow *win) wxOVERRIDE
{ return m_rendererNative.GetCheckMarkSize(win); }
virtual wxSize GetExpanderSize(wxWindow *win) wxOVERRIDE virtual wxSize GetExpanderSize(wxWindow *win) wxOVERRIDE
{ return m_rendererNative.GetExpanderSize(win); } { return m_rendererNative.GetExpanderSize(win); }

View File

@@ -234,8 +234,13 @@ public:
virtual void DrawCheckBox(wxWindow *win, wxDC& dc, virtual void DrawCheckBox(wxWindow *win, wxDC& dc,
const wxRect& rect, int flags = 0 ); const wxRect& rect, int flags = 0 );
virtual void DrawCheckMark(wxWindow *win, wxDC& dc,
const wxRect& rect, int flags = 0 );
virtual wxSize GetCheckBoxSize(wxWindow *win); virtual wxSize GetCheckBoxSize(wxWindow *win);
virtual wxSize GetCheckMarkSize(wxWindow *win);
virtual wxSize GetExpanderSize(wxWindow* win); virtual wxSize GetExpanderSize(wxWindow* win);
virtual void DrawPushButton(wxWindow *win, wxDC& dc, virtual void DrawPushButton(wxWindow *win, wxDC& dc,
@@ -532,6 +537,17 @@ public:
wxTitleBarButton button, wxTitleBarButton button,
int flags = 0) = 0; int flags = 0) = 0;
/**
Draw a check mark.
@a flags may have the @c wxCONTROL_DISABLED bit set, see
@ref wxCONTROL_FLAGS.
@since 3.1.3
*/
virtual void DrawCheckMark(wxWindow* win, wxDC& dc, const wxRect& rect,
int flags = 0) = 0;
/** /**
Return the currently used renderer. Return the currently used renderer.
*/ */
@@ -560,6 +576,16 @@ public:
*/ */
virtual wxSize GetCheckBoxSize(wxWindow* win) = 0; virtual wxSize GetCheckBoxSize(wxWindow* win) = 0;
/**
Returns the size of a check mark.
@param win A valid, i.e. non-null, window pointer which is used to get
the theme defining the checkmark size under some platforms.
@since 3.1.3
*/
virtual wxSize GetCheckMarkSize(wxWindow* win) = 0;
/** /**
Returns the size of the expander used in tree-like controls. Returns the size of the expander used in tree-like controls.

View File

@@ -247,6 +247,12 @@ private:
wxRect(wxPoint(x2, y), sizeCheck), m_flags); wxRect(wxPoint(x2, y), sizeCheck), m_flags);
y += lineHeight + sizeCheck.y; y += lineHeight + sizeCheck.y;
dc.DrawText("DrawCheckMark()", x1, y);
const wxSize sizeMark = renderer.GetCheckMarkSize(this);
renderer.DrawCheckMark(this, dc,
wxRect(wxPoint(x2, y), sizeMark), m_flags);
y += lineHeight + sizeMark.y;
dc.DrawText("DrawRadioBitmap()", x1, y); dc.DrawText("DrawRadioBitmap()", x1, y);
renderer.DrawRadioBitmap(this, dc, renderer.DrawRadioBitmap(this, dc,
wxRect(wxPoint(x2, y), sizeCheck), m_flags); wxRect(wxPoint(x2, y), sizeCheck), m_flags);
@@ -259,9 +265,10 @@ private:
y += lineHeight + sizeCollapse.y; y += lineHeight + sizeCollapse.y;
dc.DrawText("DrawTreeItemButton()", x1, y); dc.DrawText("DrawTreeItemButton()", x1, y);
const wxSize sizeExpand = renderer.GetExpanderSize(this);
renderer.DrawTreeItemButton(this, dc, renderer.DrawTreeItemButton(this, dc,
wxRect(x2, y, 20, 20), m_flags); wxRect(wxPoint(x2, y), sizeExpand), m_flags);
y += lineHeight + 20; y += lineHeight + sizeExpand.y;
#ifdef wxHAS_DRAW_TITLE_BAR_BITMAP #ifdef wxHAS_DRAW_TITLE_BAR_BITMAP
dc.DrawText("DrawTitleBarBitmap()", x1, y); dc.DrawText("DrawTitleBarBitmap()", x1, y);

View File

@@ -106,8 +106,15 @@ public:
const wxRect& rect, const wxRect& rect,
int flags = 0) wxOVERRIDE; int flags = 0) wxOVERRIDE;
virtual void DrawCheckMark(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags = 0) wxOVERRIDE;
virtual wxSize GetCheckBoxSize(wxWindow *win) wxOVERRIDE; virtual wxSize GetCheckBoxSize(wxWindow *win) wxOVERRIDE;
virtual wxSize GetCheckMarkSize(wxWindow *win) wxOVERRIDE;
virtual wxSize GetExpanderSize(wxWindow *win) wxOVERRIDE; virtual wxSize GetExpanderSize(wxWindow *win) wxOVERRIDE;
virtual void DrawPushButton(wxWindow *win, virtual void DrawPushButton(wxWindow *win,
@@ -714,6 +721,16 @@ wxRendererGeneric::DrawCheckBox(wxWindow *WXUNUSED(win),
} }
} }
void
wxRendererGeneric::DrawCheckMark(wxWindow *WXUNUSED(win),
wxDC& dc,
const wxRect& rect,
int flags)
{
dc.SetPen(*(flags & wxCONTROL_DISABLED ? wxGREY_PEN : wxBLACK_PEN));
dc.DrawCheckMark(rect);
}
wxSize wxRendererGeneric::GetCheckBoxSize(wxWindow *win) wxSize wxRendererGeneric::GetCheckBoxSize(wxWindow *win)
{ {
wxCHECK_MSG( win, wxSize(0, 0), "Must have a valid window" ); wxCHECK_MSG( win, wxSize(0, 0), "Must have a valid window" );
@@ -721,6 +738,11 @@ wxSize wxRendererGeneric::GetCheckBoxSize(wxWindow *win)
return win->FromDIP(wxSize(16, 16)); return win->FromDIP(wxSize(16, 16));
} }
wxSize wxRendererGeneric::GetCheckMarkSize(wxWindow *win)
{
return GetCheckBoxSize(win);
}
wxSize wxRendererGeneric::GetExpanderSize(wxWindow *win) wxSize wxRendererGeneric::GetExpanderSize(wxWindow *win)
{ {
wxCHECK_MSG( win, wxSize(0, 0), "Must have a valid window" ); wxCHECK_MSG( win, wxSize(0, 0), "Must have a valid window" );

View File

@@ -135,6 +135,14 @@ public:
DoDrawButton(DFCS_BUTTONCHECK, win, dc, rect, flags); DoDrawButton(DFCS_BUTTONCHECK, win, dc, rect, flags);
} }
virtual void DrawCheckMark(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags = 0) wxOVERRIDE
{
DoDrawFrameControl(DFC_MENU, DFCS_MENUCHECK, win, dc, rect, flags);
}
virtual void DrawPushButton(wxWindow *win, virtual void DrawPushButton(wxWindow *win,
wxDC& dc, wxDC& dc,
const wxRect& rect, const wxRect& rect,
@@ -230,6 +238,15 @@ public:
m_rendererNative.DrawCheckBox(win, dc, rect, flags); m_rendererNative.DrawCheckBox(win, dc, rect, flags);
} }
virtual void DrawCheckMark(wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags = 0) wxOVERRIDE
{
if ( !DoDrawCheckMark(MENU_POPUPCHECK, win, dc, rect, flags) )
m_rendererNative.DrawCheckMark(win, dc, rect, flags);
}
virtual void DrawPushButton(wxWindow *win, virtual void DrawPushButton(wxWindow *win,
wxDC& dc, wxDC& dc,
const wxRect& rect, const wxRect& rect,
@@ -273,6 +290,8 @@ public:
virtual wxSize GetCheckBoxSize(wxWindow *win) wxOVERRIDE; virtual wxSize GetCheckBoxSize(wxWindow *win) wxOVERRIDE;
virtual wxSize GetCheckMarkSize(wxWindow* win) wxOVERRIDE;
virtual wxSize GetExpanderSize(wxWindow *win) wxOVERRIDE; virtual wxSize GetExpanderSize(wxWindow *win) wxOVERRIDE;
virtual void DrawGauge(wxWindow* win, virtual void DrawGauge(wxWindow* win,
@@ -309,6 +328,12 @@ private:
const wxRect& rect, const wxRect& rect,
int flags); int flags);
bool DoDrawCheckMark(int kind,
wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags);
wxDECLARE_NO_COPY_CLASS(wxRendererXP); wxDECLARE_NO_COPY_CLASS(wxRendererXP);
}; };
@@ -736,6 +761,38 @@ wxRendererXP::DoDrawXPButton(int kind,
return true; return true;
} }
bool
wxRendererXP::DoDrawCheckMark(int kind,
wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags)
{
wxUxThemeHandle hTheme(win, L"MENU");
if ( !hTheme )
return false;
wxCHECK_MSG( dc.GetImpl(), false, wxT("Invalid wxDC") );
RECT r = ConvertToRECT(dc, rect);
int state = MC_CHECKMARKNORMAL;
if ( flags & wxCONTROL_DISABLED )
state = MC_CHECKMARKDISABLED;
::DrawThemeBackground
(
hTheme,
GetHdcOf(dc.GetTempHDC()),
kind,
state,
&r,
NULL
);
return true;
}
void void
wxRendererXP::DoDrawButtonLike(HTHEME htheme, wxRendererXP::DoDrawButtonLike(HTHEME htheme,
int part, int part,
@@ -852,6 +909,23 @@ wxSize wxRendererXP::GetCheckBoxSize(wxWindow* win)
return m_rendererNative.GetCheckBoxSize(win); return m_rendererNative.GetCheckBoxSize(win);
} }
wxSize wxRendererXP::GetCheckMarkSize(wxWindow* win)
{
wxCHECK_MSG(win, wxSize(0, 0), "Must have a valid window");
wxUxThemeHandle hTheme(win, L"MENU");
if (hTheme)
{
if (::IsThemePartDefined(hTheme, MENU_POPUPCHECK, 0))
{
SIZE checkSize;
if (::GetThemePartSize(hTheme, NULL, MENU_POPUPCHECK, MC_CHECKMARKNORMAL, NULL, TS_DRAW, &checkSize) == S_OK)
return wxSize(checkSize.cx, checkSize.cy);
}
}
return m_rendererNative.GetCheckMarkSize(win);
}
wxSize wxRendererXP::GetExpanderSize(wxWindow* win) wxSize wxRendererXP::GetExpanderSize(wxWindow* win)
{ {
wxCHECK_MSG( win, wxSize(0, 0), "Must have a valid window" ); wxCHECK_MSG( win, wxSize(0, 0), "Must have a valid window" );