Add wxDataViewCtrl::GenericGetHeader() accessor

And show how to use it to increase the header size in the sample.
This commit is contained in:
Vadim Zeitlin 2016-04-22 01:12:21 +02:00
parent bed7d9fe74
commit bed710d9a7
4 changed files with 47 additions and 0 deletions

View File

@ -30,6 +30,7 @@
class WXDLLIMPEXP_FWD_CORE wxImageList;
class WXDLLIMPEXP_FWD_CORE wxItemAttr;
class WXDLLIMPEXP_FWD_CORE wxHeaderCtrl;
#if !(defined(__WXGTK20__) || defined(__WXOSX__) ) || defined(__WXUNIVERSAL__)
// #if !(defined(__WXOSX__)) || defined(__WXUNIVERSAL__)

View File

@ -263,6 +263,11 @@ public:
wxColour GetAlternateRowColour() const { return m_alternateRowColour; }
void SetAlternateRowColour(const wxColour& colour);
// The returned pointer is null if the control has wxDV_NO_HEADER style.
//
// This method is only available in the generic versions.
wxHeaderCtrl* GenericGetHeader() const;
protected:
void EnsureVisibleRowCol( int row, int column );

View File

@ -35,6 +35,10 @@
#include "wx/itemattr.h"
#include "wx/notebook.h"
#ifdef wxHAS_GENERIC_DATAVIEWCTRL
#include "wx/headerctrl.h"
#endif // wxHAS_GENERIC_DATAVIEWCTRL
#include "mymodels.h"
// ----------------------------------------------------------------------------
@ -76,6 +80,9 @@ private:
void OnStyleChange(wxCommandEvent& event);
void OnSetBackgroundColour(wxCommandEvent& event);
void OnCustomHeaderAttr(wxCommandEvent& event);
#ifdef wxHAS_GENERIC_DATAVIEWCTRL
void OnCustomHeaderHeight(wxCommandEvent& event);
#endif // wxHAS_GENERIC_DATAVIEWCTRL
void OnSetForegroundColour(wxCommandEvent& event);
void OnIncIndent(wxCommandEvent& event);
void OnDecIndent(wxCommandEvent& event);
@ -293,6 +300,9 @@ enum
ID_BACKGROUND_COLOUR,
ID_FOREGROUND_COLOUR,
ID_CUSTOM_HEADER_ATTR,
#ifdef wxHAS_GENERIC_DATAVIEWCTRL
ID_CUSTOM_HEADER_HEIGHT,
#endif // wxHAS_GENERIC_DATAVIEWCTRL
ID_STYLE_MENU,
ID_INC_INDENT,
ID_DEC_INDENT,
@ -348,6 +358,9 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU( ID_FOREGROUND_COLOUR, MyFrame::OnSetForegroundColour )
EVT_MENU( ID_BACKGROUND_COLOUR, MyFrame::OnSetBackgroundColour )
EVT_MENU( ID_CUSTOM_HEADER_ATTR, MyFrame::OnCustomHeaderAttr )
#ifdef wxHAS_GENERIC_DATAVIEWCTRL
EVT_MENU( ID_CUSTOM_HEADER_HEIGHT, MyFrame::OnCustomHeaderHeight )
#endif // wxHAS_GENERIC_DATAVIEWCTRL
EVT_MENU( ID_INC_INDENT, MyFrame::OnIncIndent )
EVT_MENU( ID_DEC_INDENT, MyFrame::OnDecIndent )
@ -436,6 +449,9 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
file_menu->Append(ID_FOREGROUND_COLOUR, "Set &foreground colour...\tCtrl-S");
file_menu->Append(ID_BACKGROUND_COLOUR, "Set &background colour...\tCtrl-B");
file_menu->AppendCheckItem(ID_CUSTOM_HEADER_ATTR, "C&ustom header attributes");
#ifdef wxHAS_GENERIC_DATAVIEWCTRL
file_menu->AppendCheckItem(ID_CUSTOM_HEADER_HEIGHT, "Custom header &height");
#endif // wxHAS_GENERIC_DATAVIEWCTRL
file_menu->Append(ID_STYLE_MENU, "&Style", style_menu);
file_menu->Append(ID_INC_INDENT, "&Increase indent\tCtrl-I");
file_menu->Append(ID_DEC_INDENT, "&Decrease indent\tShift-Ctrl-I");
@ -808,6 +824,26 @@ void MyFrame::OnCustomHeaderAttr(wxCommandEvent& event)
wxLogMessage("Sorry, header attributes not supported on this platform");
}
#ifdef wxHAS_GENERIC_DATAVIEWCTRL
void MyFrame::OnCustomHeaderHeight(wxCommandEvent& event)
{
wxDataViewCtrl * const dvc = m_ctrl[m_notebook->GetSelection()];
wxHeaderCtrl* const header = dvc->GenericGetHeader();
if ( !header )
{
wxLogMessage("No header");
return;
}
// Use a big height to show that this works.
wxSize size = event.IsChecked() ? FromDIP(wxSize(0, 80)) : wxDefaultSize;
header->SetMinSize(size);
header->Refresh();
dvc->Layout();
}
#endif // wxHAS_GENERIC_DATAVIEWCTRL
void MyFrame::OnIncIndent(wxCommandEvent& WXUNUSED(event))
{
wxDataViewCtrl * const dvc = m_ctrl[m_notebook->GetSelection()];

View File

@ -4625,6 +4625,11 @@ wxBorder wxDataViewCtrl::GetDefaultBorder() const
return wxBORDER_THEME;
}
wxHeaderCtrl* wxDataViewCtrl::GenericGetHeader() const
{
return m_headerArea;
}
#ifdef __WXMSW__
WXLRESULT wxDataViewCtrl::MSWWindowProc(WXUINT nMsg,
WXWPARAM wParam,