Add more columns to Header control in widgets sample
Show column settings horizontally. Fix binding to header control events after it is recreated.
This commit is contained in:
parent
fd9df06d35
commit
a31cf55a8d
@ -48,6 +48,8 @@
|
||||
// HeaderCtrlWidgetsPage
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
#define NUMBER_OF_COLUMNS 4
|
||||
|
||||
class HeaderCtrlWidgetsPage : public WidgetsPage
|
||||
{
|
||||
public:
|
||||
@ -100,7 +102,7 @@ protected:
|
||||
wxCheckBox *chkAllowHide;
|
||||
wxCheckBox *chkWithBitmap;
|
||||
wxRadioBox *rbAlignments;
|
||||
} m_colSettings[2];
|
||||
} m_colSettings[NUMBER_OF_COLUMNS];
|
||||
|
||||
private:
|
||||
DECLARE_WIDGETS_PAGE(HeaderCtrlWidgetsPage)
|
||||
@ -116,8 +118,7 @@ private:
|
||||
#define HEADER_CTRL_FAMILY GENERIC_CTRLS
|
||||
#endif
|
||||
|
||||
IMPLEMENT_WIDGETS_PAGE(HeaderCtrlWidgetsPage,
|
||||
"Header", HEADER_CTRL_FAMILY);
|
||||
IMPLEMENT_WIDGETS_PAGE(HeaderCtrlWidgetsPage, "Header", HEADER_CTRL_FAMILY);
|
||||
|
||||
static const wxString gs_colAlignments[] = { "none", "left", "centre", "right" };
|
||||
static const wxAlignment gs_colAlignFlags[] = { wxALIGN_NOT, wxALIGN_LEFT, wxALIGN_CENTRE, wxALIGN_RIGHT };
|
||||
@ -127,8 +128,8 @@ static const wxAlignment gs_colAlignFlags[] = { wxALIGN_NOT, wxALIGN_LEFT, wxALI
|
||||
|
||||
void HeaderCtrlWidgetsPage::CreateContent()
|
||||
{
|
||||
// left pane
|
||||
wxSizer *sizerLeft = new wxBoxSizer(wxVERTICAL);
|
||||
// top pane
|
||||
wxSizer *sizerTop = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
||||
// header style
|
||||
wxSizer *sizerHeader = new wxStaticBoxSizer(wxVERTICAL, this, "&Header style");
|
||||
@ -136,7 +137,11 @@ void HeaderCtrlWidgetsPage::CreateContent()
|
||||
m_chkAllowHide = CreateCheckBoxAndAddToSizer(sizerHeader, "Alow &hide");
|
||||
m_chkBitmapOnRight = CreateCheckBoxAndAddToSizer(sizerHeader, "&Bitmap on right");
|
||||
ResetHeaderStyle();
|
||||
sizerLeft->Add(sizerHeader, wxSizerFlags().Expand());
|
||||
|
||||
sizerHeader->AddStretchSpacer();
|
||||
wxButton* btnReset = new wxButton(this, wxID_ANY, "&Reset");
|
||||
sizerHeader->Add(btnReset, wxSizerFlags().CenterHorizontal().Border());
|
||||
sizerTop->Add(sizerHeader, wxSizerFlags().Expand());
|
||||
|
||||
// column flags
|
||||
for ( int i = 0; i < (int)WXSIZEOF(m_colSettings); i++ )
|
||||
@ -150,25 +155,22 @@ void HeaderCtrlWidgetsPage::CreateContent()
|
||||
m_colSettings[i].rbAlignments = new wxRadioBox(this, wxID_ANY, "Alignment",
|
||||
wxDefaultPosition, wxDefaultSize, WXSIZEOF(gs_colAlignments), gs_colAlignments,
|
||||
2, wxRA_SPECIFY_COLS);
|
||||
sizerCol->Add(m_colSettings[i].rbAlignments, wxSizerFlags().Expand().Border(wxALL, 5));
|
||||
sizerCol->Add(m_colSettings[i].rbAlignments, wxSizerFlags().Expand().Border());
|
||||
ResetColumnStyle(i);
|
||||
sizerLeft->Add(sizerCol, wxSizerFlags().Expand().Border(wxTOP, 15));
|
||||
sizerTop->AddSpacer(15);
|
||||
sizerTop->Add(sizerCol, wxSizerFlags().Expand());
|
||||
}
|
||||
|
||||
sizerLeft->Add(5, 5, wxSizerFlags().Expand().Border(wxALL, 5)); // spacer
|
||||
wxButton* btnReset = new wxButton(this, wxID_ANY, "&Reset");
|
||||
sizerLeft->Add(btnReset, wxSizerFlags().CenterHorizontal().Border(wxALL, 15));
|
||||
|
||||
// right pane
|
||||
// bottom pane
|
||||
m_sizerHeader = new wxStaticBoxSizer(wxVERTICAL, this, "Header");
|
||||
RecreateWidget();
|
||||
|
||||
// the 2 panes compose the window
|
||||
wxSizer* sizerTop = new wxBoxSizer(wxHORIZONTAL);
|
||||
sizerTop->Add(sizerLeft, wxSizerFlags().Expand().DoubleBorder());
|
||||
sizerTop->Add(m_sizerHeader, wxSizerFlags(1).Expand().DoubleBorder());
|
||||
wxSizer* sizerAll = new wxBoxSizer(wxVERTICAL);
|
||||
sizerAll->Add(sizerTop, wxSizerFlags().Expand().Border());
|
||||
sizerAll->Add(m_sizerHeader, wxSizerFlags(1).Expand().Border());
|
||||
|
||||
SetSizer(sizerTop);
|
||||
SetSizer(sizerAll);
|
||||
|
||||
// Bind event handlers
|
||||
m_chkAllowReorder->Bind(wxEVT_CHECKBOX, &HeaderCtrlWidgetsPage::OnStyleCheckOrRadioBox, this);
|
||||
@ -185,10 +187,6 @@ void HeaderCtrlWidgetsPage::CreateContent()
|
||||
}
|
||||
btnReset->Bind(wxEVT_BUTTON, &HeaderCtrlWidgetsPage::OnResetButton, this);
|
||||
btnReset->Bind(wxEVT_UPDATE_UI, &HeaderCtrlWidgetsPage::OnUpdateUIResetButton, this);
|
||||
|
||||
m_header->Bind(wxEVT_HEADER_RESIZING, &HeaderCtrlWidgetsPage::OnResizing, this);
|
||||
m_header->Bind(wxEVT_HEADER_BEGIN_RESIZE, &HeaderCtrlWidgetsPage::OnBeginResize, this);
|
||||
m_header->Bind(wxEVT_HEADER_END_RESIZE, &HeaderCtrlWidgetsPage::OnEndResize, this);
|
||||
}
|
||||
|
||||
void HeaderCtrlWidgetsPage::RecreateWidget()
|
||||
@ -200,19 +198,24 @@ void HeaderCtrlWidgetsPage::RecreateWidget()
|
||||
m_header = new wxHeaderCtrlSimple(this, wxID_ANY,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
flags);
|
||||
wxASSERT(WXSIZEOF(m_colSettings) == 2);
|
||||
wxHeaderColumnSimple col1("First", 100, GetColumnAlignmentFlag(0), GetColumnStyleFlags(0));
|
||||
if ( m_colSettings[0].chkWithBitmap->IsChecked() )
|
||||
|
||||
m_header->Bind(wxEVT_HEADER_RESIZING, &HeaderCtrlWidgetsPage::OnResizing, this);
|
||||
m_header->Bind(wxEVT_HEADER_BEGIN_RESIZE, &HeaderCtrlWidgetsPage::OnBeginResize, this);
|
||||
m_header->Bind(wxEVT_HEADER_END_RESIZE, &HeaderCtrlWidgetsPage::OnEndResize, this);
|
||||
|
||||
for ( int i = 0; i < (int)WXSIZEOF(m_colSettings); i++ )
|
||||
{
|
||||
col1.SetBitmap(wxArtProvider::GetIcon(wxART_ERROR, wxART_BUTTON));
|
||||
wxHeaderColumnSimple col(wxString::Format("Column %d", i + 1),
|
||||
FromDIP(100),
|
||||
GetColumnAlignmentFlag(i),
|
||||
GetColumnStyleFlags(i));
|
||||
if ( m_colSettings[i].chkWithBitmap->IsChecked() )
|
||||
{
|
||||
const wxArtID icons[] = { wxART_ERROR, wxART_QUESTION, wxART_WARNING, wxART_INFORMATION };
|
||||
col.SetBitmap(wxArtProvider::GetIcon(icons[i % WXSIZEOF(icons)], wxART_BUTTON));
|
||||
}
|
||||
m_header->AppendColumn(col);
|
||||
}
|
||||
m_header->AppendColumn(col1);
|
||||
wxHeaderColumnSimple col2("Second", 200, GetColumnAlignmentFlag(1), GetColumnStyleFlags(1));
|
||||
if ( m_colSettings[1].chkWithBitmap->IsChecked() )
|
||||
{
|
||||
col2.SetBitmap(wxArtProvider::GetIcon(wxART_QUESTION, wxART_BUTTON));
|
||||
}
|
||||
m_header->AppendColumn(col2);
|
||||
|
||||
m_sizerHeader->AddStretchSpacer();
|
||||
m_sizerHeader->Add(m_header, wxSizerFlags().Expand());
|
||||
@ -310,19 +313,19 @@ void HeaderCtrlWidgetsPage::OnUpdateUIResetButton(wxUpdateUIEvent& evt)
|
||||
|
||||
void HeaderCtrlWidgetsPage::OnResizing(wxHeaderCtrlEvent& evt)
|
||||
{
|
||||
wxLogMessage("Column %i resizing, width = %i", evt.GetColumn(), evt.GetWidth());
|
||||
wxLogMessage("Column %i resizing, width = %i", evt.GetColumn() + 1, evt.GetWidth());
|
||||
evt.Skip();
|
||||
}
|
||||
|
||||
void HeaderCtrlWidgetsPage::OnBeginResize(wxHeaderCtrlEvent& evt)
|
||||
{
|
||||
wxLogMessage("Column %i resize began, width = %i", evt.GetColumn(), evt.GetWidth());
|
||||
wxLogMessage("Column %i resize began, width = %i", evt.GetColumn() + 1, evt.GetWidth());
|
||||
evt.Skip();
|
||||
}
|
||||
|
||||
void HeaderCtrlWidgetsPage::OnEndResize(wxHeaderCtrlEvent& evt)
|
||||
{
|
||||
wxLogMessage("Column %i resize ended, width = %i", evt.GetColumn(), evt.GetWidth());
|
||||
wxLogMessage("Column %i resize ended, width = %i", evt.GetColumn() + 1, evt.GetWidth());
|
||||
evt.Skip();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user