From: Carl Hetherington Date: Mon, 9 Nov 2015 14:27:20 +0000 (+0000) Subject: Add test file. X-Git-Tag: v2.5.1~5 X-Git-Url: https://git.carlh.net/gitweb/?p=dcpomatic.git;a=commitdiff_plain;h=afb3307e9da4f306d8f91611b4db43b08bbfa389;hp=294704d07de1fd6981362d85a26e4a83a6ef08fa Add test file. --- diff --git a/hacks/data_view_model.cc b/hacks/data_view_model.cc new file mode 100644 index 000000000..9dd243691 --- /dev/null +++ b/hacks/data_view_model.cc @@ -0,0 +1,111 @@ +#include +#include +#include +#include + +using std::cout; + +class Model : public wxDataViewModel +{ +public: + Model () + { + _content.push_back ("cock"); + _content.push_back ("piss"); + _content.push_back ("partridge"); + + update (""); + } + + unsigned int GetColumnCount () const { + return 1; + } + + wxString GetColumnType (unsigned int) const { + return "string"; + } + + void GetValue (wxVariant& val, const wxDataViewItem& item, unsigned int column) const { + val = wxVariant (_content[((size_t) item.GetID()) - 1]); + } + + bool SetValue (const wxVariant &, const wxDataViewItem &, unsigned int) { + return true; + } + + wxDataViewItem GetParent(const wxDataViewItem& item) const { + return wxDataViewItem (0); + } + + bool IsContainer(const wxDataViewItem &) const { + return false; + } + + unsigned GetChildren(const wxDataViewItem& item, wxDataViewItemArray& children) const { + if (item.IsOk ()) { + return 0; + } + + for (int i = 0; i < _data.GetCount(); ++i) { + children.Add (_data[i]); + } + + return _data.GetCount (); + } + + void set_search (wxTextCtrl* search) + { + Cleared (); + update (search->GetValue ()); + } + + void update (wxString search) + { + _data.Clear (); + Cleared (); + + for (size_t i = 0; i < _content.size(); ++i) { + if (search.IsEmpty() || _content[i].Find(search) != wxNOT_FOUND) { + _data.Add (wxDataViewItem ((void *) (i + 1))); + } + } + + ItemsAdded (wxDataViewItem (0), _data); + } + +private: + std::vector _content; + wxDataViewItemArray _data; +}; + +class App : public wxApp +{ +public: + bool OnInit () { + if (!wxApp::OnInit()) { + return false; + } + + wxFrame* frame = new wxFrame (0, wxID_ANY, "Test"); + + wxDataViewCtrl* ctrl = new wxDataViewCtrl (frame, wxID_ANY, wxDefaultPosition, wxSize (300, 600), wxDV_NO_HEADER); + wxDataViewTextRenderer* renderer = new wxDataViewTextRenderer ("string", wxDATAVIEW_CELL_INERT); + wxDataViewColumn* column = new wxDataViewColumn ("string", renderer, 0, 100, wxAlignment(wxALIGN_LEFT)); + Model* model = new Model; + ctrl->AssociateModel (model); + ctrl->AppendColumn (column); + ctrl->SetExpanderColumn (column); + + wxTextCtrl* search = new wxTextCtrl (frame, wxID_ANY); + search->Bind (wxEVT_COMMAND_TEXT_UPDATED, boost::bind (&Model::set_search, model, search)); + + wxSizer* sizer = new wxBoxSizer (wxVERTICAL); + sizer->Add (search); + sizer->Add (ctrl); + frame->SetSizerAndFit (sizer); + frame->Show (true); + return true; + } +}; + +IMPLEMENT_APP(App)