+
+ virtual bool ActivateCell(const wxRect& WXUNUSED(cell),
+ wxDataViewModel *WXUNUSED(model),
+ const wxDataViewItem &WXUNUSED(item),
+ unsigned int WXUNUSED(col),
+ const wxMouseEvent *mouseEvent)
+ {
+ wxString position;
+ if ( mouseEvent )
+ position = wxString::Format("via mouse at %d, %d", mouseEvent->m_x, mouseEvent->m_y);
+ else
+ position = "from keyboard";
+ wxLogMessage("MyCustomRenderer ActivateCell() %s", position);
+ return false;
+ }
+
+ virtual wxSize GetSize() const
+ {
+ return wxSize(60,20);
+ }
+
+ virtual bool SetValue( const wxVariant &value )
+ {
+ m_value = value.GetString();
+ return true;
+ }
+
+ virtual bool GetValue( wxVariant &WXUNUSED(value) ) const { return true; }
+
+private:
+ wxString m_value;
+};
+
+
+// ============================================================================
+// implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// MyApp
+// ----------------------------------------------------------------------------
+
+IMPLEMENT_APP(MyApp)
+
+bool MyApp::OnInit()
+{
+ if ( !wxApp::OnInit() )
+ return false;
+
+ MyFrame *frame =
+ new MyFrame(NULL, "wxDataViewCtrl sample", 40, 40, 1000, 540);
+
+ frame->Show(true);
+ return true;
+}
+
+
+// ----------------------------------------------------------------------------
+// MyFrame
+// ----------------------------------------------------------------------------
+
+enum
+{
+ ID_CLEARLOG = wxID_HIGHEST+1,
+ ID_BACKGROUND_COLOUR,
+ ID_FOREGROUND_COLOUR,
+ ID_STYLE_MENU,
+
+ // file menu
+ //ID_SINGLE, wxDV_SINGLE==0 so it's always present
+ ID_MULTIPLE,
+ ID_ROW_LINES,
+ ID_HORIZ_RULES,
+ ID_VERT_RULES,
+
+ ID_EXIT = wxID_EXIT,
+
+ // about menu
+ ID_ABOUT = wxID_ABOUT,
+
+
+ // control IDs
+
+ ID_MUSIC_CTRL = 50,
+ ID_ATTR_CTRL = 51,
+
+ ID_ADD_MOZART = 100,
+ ID_DELETE_SEL = 101,
+ ID_DELETE_YEAR = 102,
+ ID_SELECT_NINTH = 103,
+ ID_COLLAPSE = 104,
+ ID_EXPAND = 105,
+ ID_SHOW_CURRENT,
+ ID_SET_NINTH_CURRENT,
+
+ ID_PREPEND_LIST = 200,
+ ID_DELETE_LIST = 201,
+ ID_GOTO = 202,
+ ID_ADD_MANY = 203,
+ ID_HIDE_ATTRIBUTES = 204,
+ ID_SHOW_ATTRIBUTES = 205,
+
+ // Fourth page.
+ ID_DELETE_TREE_ITEM = 400,
+ ID_DELETE_ALL_TREE_ITEMS = 401,
+ ID_ADD_TREE_ITEM = 402,
+ ID_ADD_TREE_CONTAINER_ITEM = 403
+};
+
+BEGIN_EVENT_TABLE(MyFrame, wxFrame)
+ EVT_MENU_RANGE( ID_MULTIPLE, ID_VERT_RULES, MyFrame::OnStyleChange )
+ EVT_MENU( ID_EXIT, MyFrame::OnQuit )
+ EVT_MENU( ID_ABOUT, MyFrame::OnAbout )
+ EVT_MENU( ID_CLEARLOG, MyFrame::OnClearLog )
+
+ EVT_MENU( ID_FOREGROUND_COLOUR, MyFrame::OnSetForegroundColour )
+ EVT_MENU( ID_BACKGROUND_COLOUR, MyFrame::OnSetBackgroundColour )
+
+ EVT_NOTEBOOK_PAGE_CHANGED( wxID_ANY, MyFrame::OnPageChanged )
+
+ EVT_BUTTON( ID_ADD_MOZART, MyFrame::OnAddMozart )
+ EVT_BUTTON( ID_DELETE_SEL, MyFrame::OnDeleteSelected )
+ EVT_BUTTON( ID_DELETE_YEAR, MyFrame::OnDeleteYear )
+ EVT_BUTTON( ID_SELECT_NINTH, MyFrame::OnSelectNinth )
+ EVT_BUTTON( ID_COLLAPSE, MyFrame::OnCollapse )
+ EVT_BUTTON( ID_EXPAND, MyFrame::OnExpand )
+ EVT_BUTTON( ID_SHOW_CURRENT, MyFrame::OnShowCurrent )
+ EVT_BUTTON( ID_SET_NINTH_CURRENT, MyFrame::OnSetNinthCurrent )
+
+ EVT_BUTTON( ID_PREPEND_LIST, MyFrame::OnPrependList )
+ EVT_BUTTON( ID_DELETE_LIST, MyFrame::OnDeleteList )
+ EVT_BUTTON( ID_GOTO, MyFrame::OnGoto)
+ EVT_BUTTON( ID_ADD_MANY, MyFrame::OnAddMany)
+ EVT_BUTTON( ID_HIDE_ATTRIBUTES, MyFrame::OnHideAttributes)
+ EVT_BUTTON( ID_SHOW_ATTRIBUTES, MyFrame::OnShowAttributes)
+ // Fourth page.
+ EVT_BUTTON( ID_DELETE_TREE_ITEM, MyFrame::OnDeleteTreeItem )
+ EVT_BUTTON( ID_DELETE_ALL_TREE_ITEMS, MyFrame::OnDeleteAllTreeItems )
+ EVT_BUTTON( ID_ADD_TREE_ITEM, MyFrame::OnAddTreeItem )
+ EVT_BUTTON( ID_ADD_TREE_CONTAINER_ITEM, MyFrame::OnAddTreeContainerItem )
+
+ EVT_DATAVIEW_ITEM_VALUE_CHANGED( ID_MUSIC_CTRL, MyFrame::OnValueChanged )
+
+ EVT_DATAVIEW_ITEM_ACTIVATED(ID_MUSIC_CTRL, MyFrame::OnActivated )
+ EVT_DATAVIEW_ITEM_EXPANDING(ID_MUSIC_CTRL, MyFrame::OnExpanding)
+ EVT_DATAVIEW_ITEM_EXPANDED(ID_MUSIC_CTRL, MyFrame::OnExpanded)
+ EVT_DATAVIEW_ITEM_COLLAPSING(ID_MUSIC_CTRL, MyFrame::OnCollapsing)
+ EVT_DATAVIEW_ITEM_COLLAPSED(ID_MUSIC_CTRL, MyFrame::OnCollapsed)
+ EVT_DATAVIEW_SELECTION_CHANGED(ID_MUSIC_CTRL, MyFrame::OnSelectionChanged)
+
+ EVT_DATAVIEW_ITEM_START_EDITING(ID_MUSIC_CTRL, MyFrame::OnStartEditing)
+ EVT_DATAVIEW_ITEM_EDITING_STARTED(ID_MUSIC_CTRL, MyFrame::OnEditingStarted)
+ EVT_DATAVIEW_ITEM_EDITING_DONE(ID_MUSIC_CTRL, MyFrame::OnEditingDone)
+
+ EVT_DATAVIEW_COLUMN_HEADER_CLICK(ID_MUSIC_CTRL, MyFrame::OnHeaderClick)
+ EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(ID_MUSIC_CTRL, MyFrame::OnHeaderRightClick)
+ EVT_DATAVIEW_COLUMN_SORTED(ID_MUSIC_CTRL, MyFrame::OnSorted)
+
+ EVT_DATAVIEW_ITEM_CONTEXT_MENU(ID_MUSIC_CTRL, MyFrame::OnContextMenu)
+
+#if wxUSE_DRAG_AND_DROP
+ EVT_DATAVIEW_ITEM_BEGIN_DRAG( ID_MUSIC_CTRL, MyFrame::OnBeginDrag )
+ EVT_DATAVIEW_ITEM_DROP_POSSIBLE( ID_MUSIC_CTRL, MyFrame::OnDropPossible )
+ EVT_DATAVIEW_ITEM_DROP( ID_MUSIC_CTRL, MyFrame::OnDrop )
+#endif // wxUSE_DRAG_AND_DROP
+
+ EVT_DATAVIEW_COLUMN_HEADER_CLICK(ID_ATTR_CTRL, MyFrame::OnAttrHeaderClick)
+
+END_EVENT_TABLE()
+
+MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int h):
+ wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
+{
+ m_log = NULL;
+ m_col = NULL;
+
+ m_ctrl[0] = NULL;
+ m_ctrl[1] = NULL;
+ m_ctrl[2] = NULL;
+ m_ctrl[3] = NULL;
+
+ SetIcon(wxICON(sample));
+
+
+ // build the menus
+ // ----------------
+
+ wxMenu *style_menu = new wxMenu;
+ //style_menu->AppendCheckItem(ID_SINGLE, "Single selection"));
+ style_menu->AppendCheckItem(ID_MULTIPLE, "Multiple selection");
+ style_menu->AppendCheckItem(ID_ROW_LINES, "Alternating colours");
+ style_menu->AppendCheckItem(ID_HORIZ_RULES, "Display horizontal rules");
+ style_menu->AppendCheckItem(ID_VERT_RULES, "Display vertical rules");
+
+ wxMenu *file_menu = new wxMenu;
+ file_menu->Append(ID_CLEARLOG, "&Clear log\tCtrl-L");
+ file_menu->Append(ID_FOREGROUND_COLOUR, "Set &foreground colour...\tCtrl-S");
+ file_menu->Append(ID_BACKGROUND_COLOUR, "Set &background colour...\tCtrl-B");
+ file_menu->Append(ID_STYLE_MENU, "&Style", style_menu);
+ file_menu->AppendSeparator();
+ file_menu->Append(ID_EXIT, "E&xit");
+
+ wxMenu *about_menu = new wxMenu;
+ about_menu->Append(ID_ABOUT, "&About");
+
+ wxMenuBar *menu_bar = new wxMenuBar;
+ menu_bar->Append(file_menu, "&File");
+ menu_bar->Append(about_menu, "&About");
+
+ SetMenuBar(menu_bar);
+ CreateStatusBar();
+
+
+ // redirect logs from our event handlers to text control
+ m_log = new wxTextCtrl( this, wxID_ANY, wxString(), wxDefaultPosition,
+ wxDefaultSize, wxTE_MULTILINE );
+ m_log->SetMinSize(wxSize(-1, 100));
+ m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_log));
+ wxLogMessage( "This is the log window" );
+
+
+ // first page of the notebook
+ // --------------------------
+
+ m_notebook = new wxNotebook( this, wxID_ANY );
+
+ wxPanel *firstPanel = new wxPanel( m_notebook, wxID_ANY );
+
+ BuildDataViewCtrl(firstPanel, 0); // sets m_ctrl[0]
+
+ const wxSizerFlags border = wxSizerFlags().DoubleBorder();
+
+ wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
+ button_sizer->Add( new wxButton( firstPanel, ID_ADD_MOZART, "Add Mozart"), border );
+ button_sizer->Add( new wxButton( firstPanel, ID_DELETE_SEL, "Delete selected"), border );
+ button_sizer->Add( new wxButton( firstPanel, ID_DELETE_YEAR, "Delete \"Year\" column"), border );
+ button_sizer->Add( new wxButton( firstPanel, ID_SELECT_NINTH,"Select ninth symphony"), border );
+ button_sizer->Add( new wxButton( firstPanel, ID_COLLAPSE, "Collapse"), border );
+ button_sizer->Add( new wxButton( firstPanel, ID_EXPAND, "Expand"), border );
+
+ wxBoxSizer *sizerCurrent = new wxBoxSizer(wxHORIZONTAL);
+ sizerCurrent->Add(new wxButton(firstPanel, ID_SHOW_CURRENT,
+ "&Show current"), border);
+ sizerCurrent->Add(new wxButton(firstPanel, ID_SET_NINTH_CURRENT,
+ "Make &ninth symphony current"), border);
+
+ wxSizer *firstPanelSz = new wxBoxSizer( wxVERTICAL );
+ m_ctrl[0]->SetMinSize(wxSize(-1, 200));
+ firstPanelSz->Add(m_ctrl[0], 1, wxGROW|wxALL, 5);
+ firstPanelSz->Add(
+ new wxStaticText(firstPanel, wxID_ANY, "Most of the cells above are editable!"),
+ 0, wxGROW|wxALL, 5);
+ firstPanelSz->Add(button_sizer);
+ firstPanelSz->Add(sizerCurrent);
+ firstPanel->SetSizerAndFit(firstPanelSz);
+
+
+ // second page of the notebook
+ // ---------------------------
+
+ wxPanel *secondPanel = new wxPanel( m_notebook, wxID_ANY );
+
+ BuildDataViewCtrl(secondPanel, 1); // sets m_ctrl[1]
+
+ wxBoxSizer *button_sizer2 = new wxBoxSizer( wxHORIZONTAL );
+ button_sizer2->Add( new wxButton( secondPanel, ID_PREPEND_LIST,"Prepend"), 0, wxALL, 10 );
+ button_sizer2->Add( new wxButton( secondPanel, ID_DELETE_LIST, "Delete selected"), 0, wxALL, 10 );
+ button_sizer2->Add( new wxButton( secondPanel, ID_GOTO, "Goto 50"), 0, wxALL, 10 );
+ button_sizer2->Add( new wxButton( secondPanel, ID_ADD_MANY, "Add 1000"), 0, wxALL, 10 );
+ button_sizer2->Add( new wxButton( secondPanel, ID_HIDE_ATTRIBUTES, "Hide attributes"), 0, wxALL, 10 );
+ button_sizer2->Add( new wxButton( secondPanel, ID_SHOW_ATTRIBUTES, "Show attributes"), 0, wxALL, 10 );
+
+ wxSizer *secondPanelSz = new wxBoxSizer( wxVERTICAL );
+ secondPanelSz->Add(m_ctrl[1], 1, wxGROW|wxALL, 5);
+ secondPanelSz->Add(button_sizer2);
+ secondPanel->SetSizerAndFit(secondPanelSz);
+
+
+ // third page of the notebook
+ // ---------------------------
+
+ wxPanel *thirdPanel = new wxPanel( m_notebook, wxID_ANY );
+
+ BuildDataViewCtrl(thirdPanel, 2); // sets m_ctrl[2]
+
+ wxSizer *thirdPanelSz = new wxBoxSizer( wxVERTICAL );
+ thirdPanelSz->Add(m_ctrl[2], 1, wxGROW|wxALL, 5);
+ thirdPanel->SetSizerAndFit(thirdPanelSz);
+
+
+ // fourth page of the notebook
+ // ---------------------------
+
+ wxPanel *fourthPanel = new wxPanel( m_notebook, wxID_ANY );
+
+ BuildDataViewCtrl(fourthPanel, 3); // sets m_ctrl[3]
+ // Buttons
+ wxBoxSizer *button_sizer4 = new wxBoxSizer( wxHORIZONTAL );
+ button_sizer4->Add( new wxButton( fourthPanel, ID_DELETE_TREE_ITEM, "Delete Selected"), 0, wxALL, 10 );
+ button_sizer4->Add( new wxButton( fourthPanel, ID_DELETE_ALL_TREE_ITEMS, "Delete All"), 0, wxALL, 10 );
+ button_sizer4->Add( new wxButton( fourthPanel, ID_ADD_TREE_ITEM, "Add Item"), 0, wxALL, 10 );
+ button_sizer4->Add( new wxButton( fourthPanel, ID_ADD_TREE_CONTAINER_ITEM, "Add Container"), 0, wxALL, 10 );
+
+ wxSizer *fourthPanelSz = new wxBoxSizer( wxVERTICAL );
+ fourthPanelSz->Add(m_ctrl[3], 1, wxGROW|wxALL, 5);
+ fourthPanelSz->Add(button_sizer4);
+ fourthPanel->SetSizerAndFit(fourthPanelSz);
+
+
+
+ // complete GUI
+ // ------------
+
+ m_notebook->AddPage(firstPanel, "MyMusicTreeModel");
+ m_notebook->AddPage(secondPanel, "MyListModel");
+ m_notebook->AddPage(thirdPanel, "wxDataViewListCtrl");
+ m_notebook->AddPage(fourthPanel, "wxDataViewTreeCtrl");
+
+ wxSizer* mainSizer = new wxBoxSizer(wxVERTICAL);
+
+ mainSizer->Add( m_notebook, 1, wxGROW );
+ mainSizer->Add( m_log, 0, wxGROW );
+
+ SetSizerAndFit(mainSizer);
+}
+
+MyFrame::~MyFrame()
+{
+ delete wxLog::SetActiveTarget(m_logOld);
+}
+
+void MyFrame::BuildDataViewCtrl(wxPanel* parent, unsigned int nPanel, unsigned long style)
+{
+ switch (nPanel)
+ {
+ case 0: