Merge branch 'mswdc-draw-point-checkbox' of https://github.com/MaartenBent/wxWidgets

Draw the same shape in wxDC::DrawCheckMark() under all platforms and
provide wxRenderer::DrawCheckMark() for drawing the platform-specific
shape.

Also fix wxGCDC::DrawPoint() to use the default one point wide pen.

See https://github.com/wxWidgets/wxWidgets/pull/1471
This commit is contained in:
Vadim Zeitlin
2019-08-20 13:20:48 +02:00
10 changed files with 192 additions and 36 deletions

View File

@@ -70,6 +70,9 @@ Changes in behaviour not resulting in compilation errors
return to the previous behaviour, you need to explicitly create controls of
smaller size.
- wxDC::DrawCheckMark() draws the same shape under all platforms now, use the
new wxRendererNative::DrawCheckMark() to draw MSW-specific themed check mark.
Changes in behaviour which may result in build errors
-----------------------------------------------------

View File

@@ -202,8 +202,6 @@ public:
virtual void DoDrawArc(wxCoord x1, wxCoord y1,
wxCoord x2, wxCoord y2,
wxCoord xc, wxCoord yc) wxOVERRIDE;
virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
wxCoord width, wxCoord height) wxOVERRIDE;
virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
double sa, double ea) wxOVERRIDE;

View File

@@ -250,9 +250,20 @@ public:
const wxRect& rect,
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.
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.
virtual wxSize GetExpanderSize(wxWindow *win) = 0;
@@ -479,9 +490,18 @@ public:
int flags = 0) wxOVERRIDE
{ 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
{ return m_rendererNative.GetCheckBoxSize(win); }
virtual wxSize GetCheckMarkSize(wxWindow *win) wxOVERRIDE
{ return m_rendererNative.GetCheckMarkSize(win); }
virtual wxSize GetExpanderSize(wxWindow *win) wxOVERRIDE
{ return m_rendererNative.GetExpanderSize(win); }

View File

@@ -234,8 +234,13 @@ public:
virtual void DrawCheckBox(wxWindow *win, wxDC& dc,
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 GetCheckMarkSize(wxWindow *win);
virtual wxSize GetExpanderSize(wxWindow* win);
virtual void DrawPushButton(wxWindow *win, wxDC& dc,
@@ -532,6 +537,17 @@ public:
wxTitleBarButton button,
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.
*/
@@ -560,6 +576,16 @@ public:
*/
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.

View File

@@ -123,11 +123,8 @@ public:
{ if ( !m_renderer ) return false;
return m_renderer == wxGraphicsRenderer::GetDefaultRenderer();
}
bool IsRendererName(const wxString& name) const
{ if ( !m_renderer ) return name.empty();
return m_renderer->GetName() == name;
}
wxGraphicsRenderer* GetRenderer() const { return m_renderer; }
void EnableAntiAliasing(bool use) { m_useAntiAliasing = use; Refresh(); }
#endif // wxUSE_GRAPHICS_CONTEXT
void UseBuffer(bool use) { m_useBuffer = use; Refresh(); }
void ShowBoundingBox(bool show) { m_showBBox = show; Refresh(); }
@@ -176,6 +173,7 @@ private:
wxPoint m_currentpoint;
#if wxUSE_GRAPHICS_CONTEXT
wxGraphicsRenderer* m_renderer;
bool m_useAntiAliasing;
#endif
bool m_useBuffer;
bool m_showBBox;
@@ -206,7 +204,7 @@ public:
void OnGraphicContextNoneUpdateUI(wxUpdateUIEvent& event)
{
event.Check(m_canvas->IsRendererName(wxEmptyString));
event.Check(m_canvas->GetRenderer() == NULL);
}
void OnGraphicContextDefault(wxCommandEvent& WXUNUSED(event))
@@ -227,7 +225,7 @@ public:
void OnGraphicContextCairoUpdateUI(wxUpdateUIEvent& event)
{
event.Check(m_canvas->IsRendererName("cairo"));
event.Check(m_canvas->GetRenderer() == wxGraphicsRenderer::GetCairoRenderer());
}
#endif // wxUSE_CAIRO
#ifdef __WXMSW__
@@ -239,7 +237,7 @@ public:
void OnGraphicContextGDIPlusUpdateUI(wxUpdateUIEvent& event)
{
event.Check(m_canvas->IsRendererName("gdiplus"));
event.Check(m_canvas->GetRenderer() == wxGraphicsRenderer::GetGDIPlusRenderer());
}
#endif
#if wxUSE_GRAPHICS_DIRECT2D
@@ -250,10 +248,19 @@ public:
void OnGraphicContextDirect2DUpdateUI(wxUpdateUIEvent& event)
{
event.Check(m_canvas->IsRendererName("direct2d"));
event.Check(m_canvas->GetRenderer() == wxGraphicsRenderer::GetDirect2DRenderer());
}
#endif
#endif // __WXMSW__
void OnAntiAliasing(wxCommandEvent& event)
{
m_canvas->EnableAntiAliasing(event.IsChecked());
}
void OnAntiAliasingUpdateUI(wxUpdateUIEvent& event)
{
event.Enable(m_canvas->GetRenderer() != NULL);
}
#endif // wxUSE_GRAPHICS_CONTEXT
void OnBuffer(wxCommandEvent& event);
@@ -339,6 +346,9 @@ enum
File_BBox,
File_Clip,
File_Buffer,
#if wxUSE_GRAPHICS_CONTEXT
File_AntiAliasing,
#endif
File_Copy,
File_Save,
@@ -523,6 +533,7 @@ MyCanvas::MyCanvas(MyFrame *parent)
m_rubberBand = false;
#if wxUSE_GRAPHICS_CONTEXT
m_renderer = NULL;
m_useAntiAliasing = true;
#endif
m_useBuffer = false;
m_showBBox = false;
@@ -1826,6 +1837,8 @@ void MyCanvas::Draw(wxDC& pdc)
return;
}
context->SetAntialiasMode(m_useAntiAliasing ? wxANTIALIAS_DEFAULT : wxANTIALIAS_NONE);
gdc.SetBackground(GetBackgroundColour());
gdc.SetGraphicsContext(context);
}
@@ -2098,6 +2111,8 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_UPDATE_UI (File_GC_Direct2D, MyFrame::OnGraphicContextDirect2DUpdateUI)
#endif
#endif // __WXMSW__
EVT_MENU (File_AntiAliasing, MyFrame::OnAntiAliasing)
EVT_UPDATE_UI (File_AntiAliasing, MyFrame::OnAntiAliasingUpdateUI)
#endif // wxUSE_GRAPHICS_CONTEXT
EVT_MENU (File_Buffer, MyFrame::OnBuffer)
@@ -2142,17 +2157,17 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
wxMenu *menuFile = new wxMenu;
#if wxUSE_GRAPHICS_CONTEXT
menuFile->AppendCheckItem(File_GC_Default, "Use default wx&GraphicContext\tCtrl-Y");
m_menuItemUseDC = menuFile->AppendRadioItem(File_DC, "Use wx&DC\tShift-Ctrl-Y");
menuFile->AppendCheckItem(File_GC_Default, "Use default wx&GraphicContext\t1");
m_menuItemUseDC = menuFile->AppendRadioItem(File_DC, "Use wx&DC\t0");
#if wxUSE_CAIRO
menuFile->AppendRadioItem(File_GC_Cairo, "Use &Cairo\tCtrl-O");
menuFile->AppendRadioItem(File_GC_Cairo, "Use &Cairo\t2");
#endif // wxUSE_CAIRO
#ifdef __WXMSW__
#if wxUSE_GRAPHICS_GDIPLUS
menuFile->AppendRadioItem(File_GC_GDIPlus, "Use &GDI+\tCtrl-+");
menuFile->AppendRadioItem(File_GC_GDIPlus, "Use &GDI+\t3");
#endif
#if wxUSE_GRAPHICS_DIRECT2D
menuFile->AppendRadioItem(File_GC_Direct2D, "Use &Direct2D\tCtrl-2");
menuFile->AppendRadioItem(File_GC_Direct2D, "Use &Direct2D\t4");
#endif
#endif // __WXMSW__
#endif // wxUSE_GRAPHICS_CONTEXT
@@ -2161,6 +2176,12 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
"Show extents used in drawing operations");
menuFile->AppendCheckItem(File_Clip, "&Clip\tCtrl-C", "Clip/unclip drawing");
menuFile->AppendCheckItem(File_Buffer, "&Use wx&BufferedPaintDC\tCtrl-Z", "Buffer painting");
#if wxUSE_GRAPHICS_CONTEXT
menuFile->AppendCheckItem(File_AntiAliasing,
"&Anti-Aliasing in wxGraphicContext\tCtrl-Shift-A",
"Enable Anti-Aliasing in wxGraphicContext")
->Check();
#endif
menuFile->AppendSeparator();
#if wxUSE_METAFILE && defined(wxMETAFILE_IS_ENH)
menuFile->Append(File_Copy, "Copy to clipboard");

View File

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

View File

@@ -752,6 +752,9 @@ void wxGCDCImpl::DoDrawPoint( wxCoord x, wxCoord y )
if (!m_logicalFunctionSupported)
return;
wxPen pointPen(m_pen.GetColour());
wxDCPenChanger penChanger(*GetOwner(), pointPen);
#if defined(__WXMSW__) && wxUSE_GRAPHICS_GDIPLUS
// single point path does not work with GDI+
if (m_graphicContext->GetRenderer() == wxGraphicsRenderer::GetGDIPlusRenderer())

View File

@@ -106,8 +106,15 @@ public:
const wxRect& rect,
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 GetCheckMarkSize(wxWindow *win) wxOVERRIDE;
virtual wxSize GetExpanderSize(wxWindow *win) wxOVERRIDE;
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)
{
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));
}
wxSize wxRendererGeneric::GetCheckMarkSize(wxWindow *win)
{
return GetCheckBoxSize(win);
}
wxSize wxRendererGeneric::GetExpanderSize(wxWindow *win)
{
wxCHECK_MSG( win, wxSize(0, 0), "Must have a valid window" );

View File

@@ -861,24 +861,6 @@ void wxMSWDCImpl::DoDrawArc(wxCoord x1, wxCoord y1,
CalcBoundingBox(xc + r, yc + r);
}
void wxMSWDCImpl::DoDrawCheckMark(wxCoord x1, wxCoord y1,
wxCoord width, wxCoord height)
{
wxCoord x2 = x1 + width,
y2 = y1 + height;
RECT rect;
rect.left = x1;
rect.top = y1;
rect.right = x2;
rect.bottom = y2;
DrawFrameControl(GetHdc(), &rect, DFC_MENU, DFCS_MENUCHECK);
CalcBoundingBox(x1, y1);
CalcBoundingBox(x2, y2);
}
void wxMSWDCImpl::DoDrawPoint(wxCoord x, wxCoord y)
{
COLORREF color = 0x00ffffff;

View File

@@ -135,6 +135,14 @@ public:
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,
wxDC& dc,
const wxRect& rect,
@@ -230,6 +238,15 @@ public:
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,
wxDC& dc,
const wxRect& rect,
@@ -273,6 +290,8 @@ public:
virtual wxSize GetCheckBoxSize(wxWindow *win) wxOVERRIDE;
virtual wxSize GetCheckMarkSize(wxWindow* win) wxOVERRIDE;
virtual wxSize GetExpanderSize(wxWindow *win) wxOVERRIDE;
virtual void DrawGauge(wxWindow* win,
@@ -309,6 +328,12 @@ private:
const wxRect& rect,
int flags);
bool DoDrawCheckMark(int kind,
wxWindow *win,
wxDC& dc,
const wxRect& rect,
int flags);
wxDECLARE_NO_COPY_CLASS(wxRendererXP);
};
@@ -736,6 +761,38 @@ wxRendererXP::DoDrawXPButton(int kind,
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
wxRendererXP::DoDrawButtonLike(HTHEME htheme,
int part,
@@ -852,6 +909,23 @@ wxSize wxRendererXP::GetCheckBoxSize(wxWindow* 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)
{
wxCHECK_MSG( win, wxSize(0, 0), "Must have a valid window" );