example for DataView with wxDV_VARIABLE_LINE_HEIGHT flag
This commit is contained in:
@@ -165,11 +165,12 @@ private:
|
|||||||
|
|
||||||
// the controls stored in the various tabs of the main notebook:
|
// the controls stored in the various tabs of the main notebook:
|
||||||
|
|
||||||
wxDataViewCtrl* m_ctrl[4];
|
wxDataViewCtrl* m_ctrl[5];
|
||||||
|
|
||||||
// the models associated with the first two DVC:
|
// the models associated with the first two DVC:
|
||||||
|
|
||||||
wxObjectDataPtr<MyMusicTreeModel> m_music_model;
|
wxObjectDataPtr<MyMusicTreeModel> m_music_model;
|
||||||
|
wxObjectDataPtr<MyLongMusicTreeModel> m_long_music_model;
|
||||||
wxObjectDataPtr<MyListModel> m_list_model;
|
wxObjectDataPtr<MyListModel> m_list_model;
|
||||||
|
|
||||||
// other data:
|
// other data:
|
||||||
@@ -287,6 +288,53 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// MultiLineCustomRenderer
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class MultiLineCustomRenderer : public wxDataViewCustomRenderer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// a simple renderer that wraps each word on a new line
|
||||||
|
explicit MultiLineCustomRenderer()
|
||||||
|
: wxDataViewCustomRenderer("string", wxDATAVIEW_CELL_INERT, 0)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
virtual bool Render(wxRect rect, wxDC *dc, int state) wxOVERRIDE
|
||||||
|
{
|
||||||
|
RenderText(m_value, 0, rect, dc, state);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual wxSize GetSize() const wxOVERRIDE
|
||||||
|
{
|
||||||
|
wxSize txtSize = GetTextExtent(m_value);
|
||||||
|
int lines = m_value.Freq('\n') + 1;
|
||||||
|
txtSize.SetHeight(txtSize.GetHeight() * lines);
|
||||||
|
return txtSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool SetValue(const wxVariant &value) wxOVERRIDE
|
||||||
|
{
|
||||||
|
m_value = value.GetString();
|
||||||
|
m_value.Replace(" ", "\n");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual bool GetValue(wxVariant &WXUNUSED(value)) const wxOVERRIDE { return true; }
|
||||||
|
|
||||||
|
#if wxUSE_ACCESSIBILITY
|
||||||
|
virtual wxString GetAccessibleDescription() const wxOVERRIDE
|
||||||
|
{
|
||||||
|
return m_value;
|
||||||
|
}
|
||||||
|
#endif // wxUSE_ACCESSIBILITY
|
||||||
|
|
||||||
|
private:
|
||||||
|
wxString m_value;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// implementation
|
// implementation
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -459,6 +507,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
|
|||||||
m_ctrl[1] = NULL;
|
m_ctrl[1] = NULL;
|
||||||
m_ctrl[2] = NULL;
|
m_ctrl[2] = NULL;
|
||||||
m_ctrl[3] = NULL;
|
m_ctrl[3] = NULL;
|
||||||
|
m_ctrl[4] = NULL;
|
||||||
|
|
||||||
m_eventFromProgram = false;
|
m_eventFromProgram = false;
|
||||||
|
|
||||||
@@ -606,6 +655,16 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
|
|||||||
fourthPanelSz->Add(button_sizer4);
|
fourthPanelSz->Add(button_sizer4);
|
||||||
fourthPanel->SetSizerAndFit(fourthPanelSz);
|
fourthPanel->SetSizerAndFit(fourthPanelSz);
|
||||||
|
|
||||||
|
// fifth page of the notebook
|
||||||
|
// ---------------------------
|
||||||
|
|
||||||
|
wxPanel *fifthPanel = new wxPanel(m_notebook, wxID_ANY);
|
||||||
|
|
||||||
|
BuildDataViewCtrl(fifthPanel, 4); // sets m_ctrl[4]
|
||||||
|
|
||||||
|
wxSizer *fifthPanelSz = new wxBoxSizer(wxVERTICAL);
|
||||||
|
fifthPanelSz->Add(m_ctrl[4], 1, wxGROW | wxALL, 5);
|
||||||
|
fifthPanel->SetSizerAndFit(fifthPanelSz);
|
||||||
|
|
||||||
|
|
||||||
// complete GUI
|
// complete GUI
|
||||||
@@ -615,6 +674,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int
|
|||||||
m_notebook->AddPage(secondPanel, "MyListModel");
|
m_notebook->AddPage(secondPanel, "MyListModel");
|
||||||
m_notebook->AddPage(thirdPanel, "wxDataViewListCtrl");
|
m_notebook->AddPage(thirdPanel, "wxDataViewListCtrl");
|
||||||
m_notebook->AddPage(fourthPanel, "wxDataViewTreeCtrl");
|
m_notebook->AddPage(fourthPanel, "wxDataViewTreeCtrl");
|
||||||
|
m_notebook->AddPage(fifthPanel, "wxDataViewTreeCtrl Variable line height");
|
||||||
|
|
||||||
wxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
|
wxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
|
||||||
|
|
||||||
@@ -837,6 +897,35 @@ void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned l
|
|||||||
tc->Expand(cont);
|
tc->Expand(cont);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
{
|
||||||
|
wxASSERT(!m_ctrl[4] && !m_long_music_model);
|
||||||
|
m_ctrl[4] =
|
||||||
|
new wxDataViewCtrl( parent, wxID_ANY, wxDefaultPosition,
|
||||||
|
wxDefaultSize, style | wxDV_VARIABLE_LINE_HEIGHT );
|
||||||
|
|
||||||
|
m_long_music_model = new MyLongMusicTreeModel;
|
||||||
|
m_ctrl[4]->AssociateModel(m_long_music_model.get());
|
||||||
|
|
||||||
|
// column 0 of the view control:
|
||||||
|
MultiLineCustomRenderer *tr =
|
||||||
|
new MultiLineCustomRenderer();
|
||||||
|
wxDataViewColumn *column0 =
|
||||||
|
new wxDataViewColumn("title", tr, 0, 200, wxALIGN_LEFT,
|
||||||
|
wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_RESIZABLE);
|
||||||
|
m_ctrl[4]->AppendColumn(column0);
|
||||||
|
|
||||||
|
// column 1 of the view control:
|
||||||
|
tr = new MultiLineCustomRenderer();
|
||||||
|
wxDataViewColumn *column1 =
|
||||||
|
new wxDataViewColumn("artist", tr, 1, 150, wxALIGN_LEFT,
|
||||||
|
wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_REORDERABLE |
|
||||||
|
wxDATAVIEW_COL_RESIZABLE);
|
||||||
|
column1->SetMinWidth(150); // this column can't be resized to be smaller
|
||||||
|
m_ctrl[4]->AppendColumn(column1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1013,6 +1102,8 @@ void MyFrame::OnStyleChange( wxCommandEvent& WXUNUSED(event) )
|
|||||||
m_music_model.reset(NULL);
|
m_music_model.reset(NULL);
|
||||||
else if (nPanel == 1)
|
else if (nPanel == 1)
|
||||||
m_list_model.reset(NULL);
|
m_list_model.reset(NULL);
|
||||||
|
else if (nPanel == 4)
|
||||||
|
m_long_music_model.reset(NULL);
|
||||||
|
|
||||||
// rebuild the DVC for the selected panel:
|
// rebuild the DVC for the selected panel:
|
||||||
BuildDataViewCtrl((wxPanel*)m_notebook->GetPage(nPanel), nPanel, style);
|
BuildDataViewCtrl((wxPanel*)m_notebook->GetPage(nPanel), nPanel, style);
|
||||||
|
@@ -312,6 +312,19 @@ unsigned int MyMusicTreeModel::GetChildren( const wxDataViewItem &parent,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// MyLongMusicTreeModel
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
MyLongMusicTreeModel::MyLongMusicTreeModel() : MyMusicTreeModel()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 50; i++)
|
||||||
|
{
|
||||||
|
AddToClassical("The Four Seasons", "Antonio Vivaldi", 1721);
|
||||||
|
AddToClassical("La costanza trionfante degl'amori e de gl'odii", "Antonio Vivaldi", 1716);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// MyListModel
|
// MyListModel
|
||||||
|
@@ -188,6 +188,17 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// MyLongMusicTreeModel
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
class MyLongMusicTreeModel : public MyMusicTreeModel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MyLongMusicTreeModel();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// MyListModel
|
// MyListModel
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
Reference in New Issue
Block a user