Add more tests for wxRendererNative::DrawHeaderButton().
Test using icons and bitmaps in it. Also show the native/default implementation of this method and not only our overridden version. See #12047. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64307 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
c93e68a85a
commit
945178c70e
@ -39,6 +39,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "wx/apptrait.h"
|
#include "wx/apptrait.h"
|
||||||
|
#include "wx/artprov.h"
|
||||||
#include "wx/renderer.h"
|
#include "wx/renderer.h"
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@ -64,13 +65,18 @@ public:
|
|||||||
wxDC& dc,
|
wxDC& dc,
|
||||||
const wxRect& rect,
|
const wxRect& rect,
|
||||||
int WXUNUSED(flags) = 0,
|
int WXUNUSED(flags) = 0,
|
||||||
wxHeaderSortIconType WXUNUSED(sortArrow) = wxHDR_SORT_ICON_NONE,
|
wxHeaderSortIconType WXUNUSED(sortArrow)
|
||||||
wxHeaderButtonParams* WXUNUSED(params) = NULL)
|
= wxHDR_SORT_ICON_NONE,
|
||||||
|
wxHeaderButtonParams* params = NULL)
|
||||||
{
|
{
|
||||||
wxDCBrushChanger setBrush(dc, *wxBLUE_BRUSH);
|
wxDCBrushChanger setBrush(dc, *wxBLUE_BRUSH);
|
||||||
wxDCTextColourChanger setFgCol(dc, *wxWHITE);
|
wxDCTextColourChanger setFgCol(dc, *wxWHITE);
|
||||||
dc.DrawRoundedRectangle(rect, 5);
|
dc.DrawRoundedRectangle(rect, 5);
|
||||||
dc.DrawLabel(wxT("MyRenderer"), wxNullBitmap, rect, wxALIGN_CENTER);
|
|
||||||
|
wxString label;
|
||||||
|
if ( params )
|
||||||
|
label = params->m_labelText;
|
||||||
|
dc.DrawLabel(label, wxNullBitmap, rect, wxALIGN_CENTER);
|
||||||
return rect.width;
|
return rect.width;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -119,6 +125,16 @@ private:
|
|||||||
void OnDrawHot(wxCommandEvent& event)
|
void OnDrawHot(wxCommandEvent& event)
|
||||||
{ OnToggleDrawFlag(event, wxCONTROL_CURRENT); }
|
{ OnToggleDrawFlag(event, wxCONTROL_CURRENT); }
|
||||||
|
|
||||||
|
void OnAlignLeft(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{ OnChangeAlign(wxALIGN_LEFT); }
|
||||||
|
void OnAlignCentre(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{ OnChangeAlign(wxALIGN_CENTRE); }
|
||||||
|
void OnAlignRight(wxCommandEvent& WXUNUSED(event))
|
||||||
|
{ OnChangeAlign(wxALIGN_RIGHT); }
|
||||||
|
|
||||||
|
void OnUseIcon(wxCommandEvent& event);
|
||||||
|
void OnUseBitmap(wxCommandEvent& event);
|
||||||
|
|
||||||
#if wxUSE_DYNLIB_CLASS
|
#if wxUSE_DYNLIB_CLASS
|
||||||
void OnLoad(wxCommandEvent& event);
|
void OnLoad(wxCommandEvent& event);
|
||||||
void OnUnload(wxCommandEvent& event);
|
void OnUnload(wxCommandEvent& event);
|
||||||
@ -127,6 +143,7 @@ private:
|
|||||||
void OnAbout(wxCommandEvent& event);
|
void OnAbout(wxCommandEvent& event);
|
||||||
|
|
||||||
void OnToggleDrawFlag(wxCommandEvent& event, int flag);
|
void OnToggleDrawFlag(wxCommandEvent& event, int flag);
|
||||||
|
void OnChangeAlign(int align);
|
||||||
|
|
||||||
class MyPanel *m_panel;
|
class MyPanel *m_panel;
|
||||||
|
|
||||||
@ -138,11 +155,21 @@ private:
|
|||||||
class MyPanel : public wxPanel
|
class MyPanel : public wxPanel
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
MyPanel(wxWindow *parent) : wxPanel(parent) { m_flags = 0; }
|
MyPanel(wxWindow *parent) : wxPanel(parent)
|
||||||
|
{
|
||||||
|
m_flags = 0;
|
||||||
|
m_align = wxALIGN_LEFT;
|
||||||
|
m_useIcon =
|
||||||
|
m_useBitmap = false;
|
||||||
|
}
|
||||||
|
|
||||||
int GetFlags() const { return m_flags; }
|
int GetFlags() const { return m_flags; }
|
||||||
void SetFlags(int flags) { m_flags = flags; }
|
void SetFlags(int flags) { m_flags = flags; }
|
||||||
|
|
||||||
|
void SetAlignment(int align) { m_align = align; }
|
||||||
|
void SetUseIcon(bool useIcon) { m_useIcon = useIcon; }
|
||||||
|
void SetUseBitmap(bool useBitmap) { m_useBitmap = useBitmap; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void OnPaint(wxPaintEvent&)
|
void OnPaint(wxPaintEvent&)
|
||||||
{
|
{
|
||||||
@ -151,7 +178,7 @@ private:
|
|||||||
wxRendererNative& renderer = wxRendererNative::Get();
|
wxRendererNative& renderer = wxRendererNative::Get();
|
||||||
|
|
||||||
int x1 = 10, // text offset
|
int x1 = 10, // text offset
|
||||||
x2 = 200, // drawing offset
|
x2 = 300, // drawing offset
|
||||||
y = 10;
|
y = 10;
|
||||||
|
|
||||||
const int lineHeight = dc.GetCharHeight();
|
const int lineHeight = dc.GetCharHeight();
|
||||||
@ -173,10 +200,32 @@ private:
|
|||||||
dc.DrawText("Using flags: " + flagsString, x1, y);
|
dc.DrawText("Using flags: " + flagsString, x1, y);
|
||||||
y += lineHeight*3;
|
y += lineHeight*3;
|
||||||
|
|
||||||
dc.DrawText("DrawHeaderButton() (overridden)", x1, y);
|
|
||||||
const wxCoord heightHdr = renderer.GetHeaderButtonHeight(this);
|
const wxCoord heightHdr = renderer.GetHeaderButtonHeight(this);
|
||||||
|
const wxCoord widthHdr = 120;
|
||||||
|
|
||||||
|
const wxHeaderSortIconType
|
||||||
|
hdrSortIcon = m_useIcon ? wxHDR_SORT_ICON_UP
|
||||||
|
: wxHDR_SORT_ICON_NONE;
|
||||||
|
|
||||||
|
wxHeaderButtonParams hdrParams;
|
||||||
|
hdrParams.m_labelText = "Header";
|
||||||
|
hdrParams.m_labelAlignment = m_align;
|
||||||
|
if ( m_useBitmap )
|
||||||
|
{
|
||||||
|
hdrParams.m_labelBitmap = wxArtProvider::GetBitmap(wxART_WARNING,
|
||||||
|
wxART_LIST);
|
||||||
|
}
|
||||||
|
|
||||||
|
dc.DrawText("DrawHeaderButton() (default)", x1, y);
|
||||||
|
wxRendererNative::GetDefault().DrawHeaderButton(this, dc,
|
||||||
|
wxRect(x2, y, widthHdr, heightHdr), m_flags,
|
||||||
|
hdrSortIcon, &hdrParams);
|
||||||
|
y += lineHeight + heightHdr;
|
||||||
|
|
||||||
|
dc.DrawText("DrawHeaderButton() (overridden)", x1, y);
|
||||||
renderer.DrawHeaderButton(this, dc,
|
renderer.DrawHeaderButton(this, dc,
|
||||||
wxRect(x2, y, 100, heightHdr), m_flags);
|
wxRect(x2, y, widthHdr, heightHdr), m_flags,
|
||||||
|
hdrSortIcon, &hdrParams);
|
||||||
y += lineHeight + heightHdr;
|
y += lineHeight + heightHdr;
|
||||||
|
|
||||||
dc.DrawText("DrawCheckBox()", x1, y);
|
dc.DrawText("DrawCheckBox()", x1, y);
|
||||||
@ -218,6 +267,9 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
int m_flags;
|
int m_flags;
|
||||||
|
int m_align;
|
||||||
|
bool m_useIcon,
|
||||||
|
m_useBitmap;
|
||||||
|
|
||||||
DECLARE_EVENT_TABLE()
|
DECLARE_EVENT_TABLE()
|
||||||
};
|
};
|
||||||
@ -240,6 +292,13 @@ enum
|
|||||||
Render_DrawChecked,
|
Render_DrawChecked,
|
||||||
Render_DrawHot,
|
Render_DrawHot,
|
||||||
|
|
||||||
|
Render_AlignLeft,
|
||||||
|
Render_AlignCentre,
|
||||||
|
Render_AlignRight,
|
||||||
|
|
||||||
|
Render_UseIcon,
|
||||||
|
Render_UseBitmap,
|
||||||
|
|
||||||
#if wxUSE_DYNLIB_CLASS
|
#if wxUSE_DYNLIB_CLASS
|
||||||
Render_Load,
|
Render_Load,
|
||||||
Render_Unload,
|
Render_Unload,
|
||||||
@ -268,6 +327,13 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|||||||
EVT_MENU(Render_DrawChecked, MyFrame::OnDrawChecked)
|
EVT_MENU(Render_DrawChecked, MyFrame::OnDrawChecked)
|
||||||
EVT_MENU(Render_DrawHot, MyFrame::OnDrawHot)
|
EVT_MENU(Render_DrawHot, MyFrame::OnDrawHot)
|
||||||
|
|
||||||
|
EVT_MENU(Render_AlignLeft, MyFrame::OnAlignLeft)
|
||||||
|
EVT_MENU(Render_AlignCentre, MyFrame::OnAlignCentre)
|
||||||
|
EVT_MENU(Render_AlignRight, MyFrame::OnAlignRight)
|
||||||
|
|
||||||
|
EVT_MENU(Render_UseIcon, MyFrame::OnUseIcon)
|
||||||
|
EVT_MENU(Render_UseBitmap, MyFrame::OnUseBitmap)
|
||||||
|
|
||||||
#if wxUSE_DYNLIB_CLASS
|
#if wxUSE_DYNLIB_CLASS
|
||||||
EVT_MENU(Render_Load, MyFrame::OnLoad)
|
EVT_MENU(Render_Load, MyFrame::OnLoad)
|
||||||
EVT_MENU(Render_Unload,MyFrame::OnUnload)
|
EVT_MENU(Render_Unload,MyFrame::OnUnload)
|
||||||
@ -340,6 +406,16 @@ MyFrame::MyFrame()
|
|||||||
menuFile->AppendCheckItem(Render_DrawHot,
|
menuFile->AppendCheckItem(Render_DrawHot,
|
||||||
"Draw in &hot state\tCtrl-H");
|
"Draw in &hot state\tCtrl-H");
|
||||||
menuFile->AppendSeparator();
|
menuFile->AppendSeparator();
|
||||||
|
|
||||||
|
menuFile->AppendRadioItem(Render_AlignLeft, "&Left align\tCtrl-1");
|
||||||
|
menuFile->AppendRadioItem(Render_AlignCentre, "C&entre align\tCtrl-2");
|
||||||
|
menuFile->AppendRadioItem(Render_AlignRight, "&Right align\tCtrl-3");
|
||||||
|
menuFile->AppendSeparator();
|
||||||
|
|
||||||
|
menuFile->AppendCheckItem(Render_UseIcon, "Draw &icon\tCtrl-I");
|
||||||
|
menuFile->AppendCheckItem(Render_UseBitmap, "Draw &bitmap\tCtrl-B");
|
||||||
|
menuFile->AppendSeparator();
|
||||||
|
|
||||||
#if wxUSE_DYNLIB_CLASS
|
#if wxUSE_DYNLIB_CLASS
|
||||||
menuFile->Append(Render_Load, wxT("&Load renderer...\tCtrl-L"));
|
menuFile->Append(Render_Load, wxT("&Load renderer...\tCtrl-L"));
|
||||||
menuFile->Append(Render_Unload, wxT("&Unload renderer\tCtrl-U"));
|
menuFile->Append(Render_Unload, wxT("&Unload renderer\tCtrl-U"));
|
||||||
@ -391,6 +467,24 @@ void MyFrame::OnToggleDrawFlag(wxCommandEvent& event, int flag)
|
|||||||
m_panel->Refresh();
|
m_panel->Refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnChangeAlign(int align)
|
||||||
|
{
|
||||||
|
m_panel->SetAlignment(align);
|
||||||
|
m_panel->Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnUseIcon(wxCommandEvent& event)
|
||||||
|
{
|
||||||
|
m_panel->SetUseIcon(event.IsChecked());
|
||||||
|
m_panel->Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyFrame::OnUseBitmap(wxCommandEvent& event)
|
||||||
|
{
|
||||||
|
m_panel->SetUseBitmap(event.IsChecked());
|
||||||
|
m_panel->Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
#if wxUSE_DYNLIB_CLASS
|
#if wxUSE_DYNLIB_CLASS
|
||||||
|
|
||||||
void MyFrame::OnLoad(wxCommandEvent& WXUNUSED(event))
|
void MyFrame::OnLoad(wxCommandEvent& WXUNUSED(event))
|
||||||
|
Loading…
Reference in New Issue
Block a user