From 736fe67c66e0f5a552f3b45e13d288f5c650c46e Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Thu, 18 Oct 2007 20:56:38 +0000 Subject: [PATCH] Added PrependColumn methods and short cuts. Added test for DeleteColumn to sample git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49233 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dataview.h | 54 ++++++++++++- include/wx/generic/dataview.h | 1 + include/wx/gtk/dataview.h | 1 + samples/dataview/dataview.cpp | 10 +++ src/common/datavcmn.cpp | 140 ++++++++++++++++++++++++++++++++++ src/generic/datavgen.cpp | 10 +++ src/gtk/dataview.cpp | 13 ++++ 7 files changed, 227 insertions(+), 2 deletions(-) diff --git a/include/wx/dataview.h b/include/wx/dataview.h index ff88b73783..7eeaee8533 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -457,6 +457,55 @@ public: wxDataViewModel* GetModel(); // short cuts + wxDataViewColumn *PrependTextColumn( const wxString &label, unsigned int model_column, + wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, + wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL), + int flags = wxDATAVIEW_COL_RESIZABLE ); + wxDataViewColumn *PrependIconTextColumn( const wxString &label, unsigned int model_column, + wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, + wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL), + int flags = wxDATAVIEW_COL_RESIZABLE ); + wxDataViewColumn *PrependToggleColumn( const wxString &label, unsigned int model_column, + wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH, + wxAlignment align = wxALIGN_CENTER, + int flags = wxDATAVIEW_COL_RESIZABLE ); + wxDataViewColumn *PrependProgressColumn( const wxString &label, unsigned int model_column, + wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH, + wxAlignment align = wxALIGN_CENTER, + int flags = wxDATAVIEW_COL_RESIZABLE ); + wxDataViewColumn *PrependDateColumn( const wxString &label, unsigned int model_column, + wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1, + wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL), + int flags = wxDATAVIEW_COL_RESIZABLE ); + wxDataViewColumn *PrependBitmapColumn( const wxString &label, unsigned int model_column, + wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, + wxAlignment align = wxALIGN_CENTER, + int flags = wxDATAVIEW_COL_RESIZABLE ); + wxDataViewColumn *PrependTextColumn( const wxBitmap &label, unsigned int model_column, + wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, + wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL), + int flags = wxDATAVIEW_COL_RESIZABLE ); + wxDataViewColumn *PrependIconTextColumn( const wxBitmap &label, unsigned int model_column, + wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, + wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL), + int flags = wxDATAVIEW_COL_RESIZABLE ); + wxDataViewColumn *PrependToggleColumn( const wxBitmap &label, unsigned int model_column, + wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_TOGGLE_DEFAULT_WIDTH, + wxAlignment align = wxALIGN_CENTER, + int flags = wxDATAVIEW_COL_RESIZABLE ); + wxDataViewColumn *PrependProgressColumn( const wxBitmap &label, unsigned int model_column, + wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = wxDVC_DEFAULT_WIDTH, + wxAlignment align = wxALIGN_CENTER, + int flags = wxDATAVIEW_COL_RESIZABLE ); + wxDataViewColumn *PrependDateColumn( const wxBitmap &label, unsigned int model_column, + wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1, + wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL), + int flags = wxDATAVIEW_COL_RESIZABLE ); + wxDataViewColumn *PrependBitmapColumn( const wxBitmap &label, unsigned int model_column, + wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, + wxAlignment align = wxALIGN_CENTER, + int flags = wxDATAVIEW_COL_RESIZABLE ); + wxDataViewColumn *AppendTextColumn( const wxString &label, unsigned int model_column, wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL), @@ -501,12 +550,13 @@ public: wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE, int width = -1, wxAlignment align = (wxAlignment)(wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL), int flags = wxDATAVIEW_COL_RESIZABLE ); - wxDataViewColumn *AppendBitmapColumn( const wxBitmap &label, unsigned int model_column, wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT, int width = -1, wxAlignment align = wxALIGN_CENTER, int flags = wxDATAVIEW_COL_RESIZABLE ); - + + + virtual bool PrependColumn( wxDataViewColumn *col ); virtual bool AppendColumn( wxDataViewColumn *col ); virtual unsigned int GetColumnCount() const = 0; diff --git a/include/wx/generic/dataview.h b/include/wx/generic/dataview.h index 55f0bce58b..3eac1231fe 100644 --- a/include/wx/generic/dataview.h +++ b/include/wx/generic/dataview.h @@ -383,6 +383,7 @@ public: virtual bool AssociateModel( wxDataViewModel *model ); virtual bool AppendColumn( wxDataViewColumn *col ); + virtual bool PrependColumn( wxDataViewColumn *col ); virtual void DoSetExpanderColumn(); virtual void DoSetIndent(); diff --git a/include/wx/gtk/dataview.h b/include/wx/gtk/dataview.h index 8a3ac99e48..a079cba9c5 100644 --- a/include/wx/gtk/dataview.h +++ b/include/wx/gtk/dataview.h @@ -339,6 +339,7 @@ public: virtual bool AssociateModel( wxDataViewModel *model ); + virtual bool PrependColumn( wxDataViewColumn *col ); virtual bool AppendColumn( wxDataViewColumn *col ); virtual unsigned int GetColumnCount() const; virtual wxDataViewColumn* GetColumn( unsigned int pos ) const; diff --git a/samples/dataview/dataview.cpp b/samples/dataview/dataview.cpp index e560e6d58d..e6753a96ca 100644 --- a/samples/dataview/dataview.cpp +++ b/samples/dataview/dataview.cpp @@ -497,6 +497,7 @@ public: void OnAddMozart(wxCommandEvent& event); void OnDeleteMusic(wxCommandEvent& event); + void OnDeleteYear(wxCommandEvent& event); void OnPrependList(wxCommandEvent& event); void OnDeleteList(wxCommandEvent& event); @@ -578,6 +579,7 @@ enum ID_ADD_MOZART = 100, ID_DELETE_MUSIC = 101, + ID_DELETE_YEAR = 102, ID_PREPEND_LIST = 200, ID_DELETE_LIST = 201, @@ -590,6 +592,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU( ID_EXIT, MyFrame::OnQuit ) EVT_BUTTON( ID_ADD_MOZART, MyFrame::OnAddMozart ) EVT_BUTTON( ID_DELETE_MUSIC, MyFrame::OnDeleteMusic ) + EVT_BUTTON( ID_DELETE_YEAR, MyFrame::OnDeleteYear ) EVT_BUTTON( ID_PREPEND_LIST, MyFrame::OnPrependList ) EVT_BUTTON( ID_DELETE_LIST, MyFrame::OnDeleteList ) EVT_BUTTON( ID_GOTO, MyFrame::OnGoto) @@ -689,6 +692,7 @@ MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int button_sizer->Add( new wxButton( this, ID_ADD_MOZART, "Add Mozart"), 0, wxALL, 10 ); button_sizer->Add( new wxButton( this, ID_DELETE_MUSIC, "Delete selected"), 0, wxALL, 10 ); + button_sizer->Add( new wxButton( this, ID_DELETE_YEAR, "Delete \"Year\" column"), 0, wxALL, 10 ); button_sizer->Add( 10, 10, 1 ); button_sizer->Add( new wxButton( this, ID_PREPEND_LIST, "Prepend"), 0, wxALL, 10 ); button_sizer->Add( new wxButton( this, ID_DELETE_LIST, "Delete selected"), 0, wxALL, 10 ); @@ -786,6 +790,12 @@ void MyFrame::OnDeleteMusic(wxCommandEvent& WXUNUSED(event) ) m_music_model->Delete( items[i] ); } +void MyFrame::OnDeleteYear( wxCommandEvent& WXUNUSED(event) ) +{ + m_musicCtrl->DeleteColumn( m_musicCtrl->GetColumn( 2 ) ); + FindWindow( ID_DELETE_YEAR )->Disable(); +} + void MyFrame::OnPrependList( wxCommandEvent& WXUNUSED(event) ) { m_list_model->Prepend( "Test" ); diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 27780cae7d..5bf1a59021 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -803,6 +803,139 @@ wxDataViewCtrlBase::AppendBitmapColumn( const wxBitmap &label, unsigned int mode return ret; } +wxDataViewColumn * +wxDataViewCtrlBase::PrependTextColumn( const wxString &label, unsigned int model_column, + wxDataViewCellMode mode, int width, wxAlignment align, int flags ) +{ + wxDataViewColumn *ret = new wxDataViewColumn( label, + new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), + model_column, width, align, flags ); + PrependColumn( ret ); + return ret; +} + +wxDataViewColumn * +wxDataViewCtrlBase::PrependIconTextColumn( const wxString &label, unsigned int model_column, + wxDataViewCellMode mode, int width, wxAlignment align, int flags ) +{ + wxDataViewColumn *ret = new wxDataViewColumn( label, + new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ), + model_column, width, align, flags ); + PrependColumn( ret ); + return ret; +} + +wxDataViewColumn * +wxDataViewCtrlBase::PrependToggleColumn( const wxString &label, unsigned int model_column, + wxDataViewCellMode mode, int width, wxAlignment align, int flags ) +{ + + wxDataViewColumn *ret = new wxDataViewColumn( label, + new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), + model_column, width, align, flags ); + PrependColumn( ret ); + return ret; +} + +wxDataViewColumn * +wxDataViewCtrlBase::PrependProgressColumn( const wxString &label, unsigned int model_column, + wxDataViewCellMode mode, int width, wxAlignment align, int flags ) +{ + wxDataViewColumn *ret = new wxDataViewColumn( label, + new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), + model_column, width, align, flags ); + PrependColumn( ret ); + return ret; +} + +wxDataViewColumn * +wxDataViewCtrlBase::PrependDateColumn( const wxString &label, unsigned int model_column, + wxDataViewCellMode mode, int width, wxAlignment align, int flags ) +{ + wxDataViewColumn *ret = new wxDataViewColumn( label, + new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), + model_column, width, align, flags ); + PrependColumn( ret ); + return ret; +} + +wxDataViewColumn * +wxDataViewCtrlBase::PrependBitmapColumn( const wxString &label, unsigned int model_column, + wxDataViewCellMode mode, int width, wxAlignment align, int flags ) +{ + wxDataViewColumn *ret = new wxDataViewColumn( label, + new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), + model_column, width, align, flags ); + PrependColumn( ret ); + return ret; +} + +wxDataViewColumn * +wxDataViewCtrlBase::PrependTextColumn( const wxBitmap &label, unsigned int model_column, + wxDataViewCellMode mode, int width, wxAlignment align, int flags ) +{ + wxDataViewColumn *ret = new wxDataViewColumn( label, + new wxDataViewTextRenderer( wxT("string"), mode, (int)align ), + model_column, width, align, flags ); + PrependColumn( ret ); + return ret; +} + +wxDataViewColumn * +wxDataViewCtrlBase::PrependIconTextColumn( const wxBitmap &label, unsigned int model_column, + wxDataViewCellMode mode, int width, wxAlignment align, int flags ) +{ + wxDataViewColumn *ret = new wxDataViewColumn( label, + new wxDataViewIconTextRenderer( wxT("wxDataViewIconText"), mode, (int)align ), + model_column, width, align, flags ); + PrependColumn( ret ); + return ret; +} + +wxDataViewColumn * +wxDataViewCtrlBase::PrependToggleColumn( const wxBitmap &label, unsigned int model_column, + wxDataViewCellMode mode, int width, wxAlignment align, int flags ) +{ + wxDataViewColumn *ret = new wxDataViewColumn( label, + new wxDataViewToggleRenderer( wxT("bool"), mode, (int)align ), + model_column, width, align, flags ); + PrependColumn( ret ); + return ret; +} + +wxDataViewColumn * +wxDataViewCtrlBase::PrependProgressColumn( const wxBitmap &label, unsigned int model_column, + wxDataViewCellMode mode, int width, wxAlignment align, int flags ) +{ + wxDataViewColumn *ret = new wxDataViewColumn( label, + new wxDataViewProgressRenderer( wxEmptyString, wxT("long"), mode, (int)align ), + model_column, width, align, flags ); + PrependColumn( ret ); + return ret; +} + +wxDataViewColumn * +wxDataViewCtrlBase::PrependDateColumn( const wxBitmap &label, unsigned int model_column, + wxDataViewCellMode mode, int width, wxAlignment align, int flags ) +{ + wxDataViewColumn *ret = new wxDataViewColumn( label, + new wxDataViewDateRenderer( wxT("datetime"), mode, (int)align ), + model_column, width, align, flags ); + PrependColumn( ret ); + return ret; +} + +wxDataViewColumn * +wxDataViewCtrlBase::PrependBitmapColumn( const wxBitmap &label, unsigned int model_column, + wxDataViewCellMode mode, int width, wxAlignment align, int flags ) +{ + wxDataViewColumn *ret = new wxDataViewColumn( label, + new wxDataViewBitmapRenderer( wxT("wxBitmap"), mode, (int)align ), + model_column, width, align, flags ); + PrependColumn( ret ); + return ret; +} + bool wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col ) { @@ -810,6 +943,13 @@ wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col ) return true; } +bool +wxDataViewCtrlBase::PrependColumn( wxDataViewColumn *col ) +{ + col->SetOwner( (wxDataViewCtrl*) this ); + return true; +} + // --------------------------------------------------------- // wxDataViewEvent // --------------------------------------------------------- diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 163a6fa0eb..8c9cd03309 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -3759,6 +3759,16 @@ bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col ) return true; } +bool wxDataViewCtrl::PrependColumn( wxDataViewColumn *col ) +{ + if (!wxDataViewCtrlBase::PrependColumn(col)) + return false; + + m_cols.Insert( col ); + OnColumnChange(); + return true; +} + void wxDataViewCtrl::OnColumnChange() { if (m_headerArea) diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index f7cde98bba..cd82fc102c 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -3154,6 +3154,19 @@ bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col ) return true; } +bool wxDataViewCtrl::PrependColumn( wxDataViewColumn *col ) +{ + if (!wxDataViewCtrlBase::PrependColumn(col)) + return false; + + m_cols.Insert( col ); + + gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview), + GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()), 0 ); + + return true; +} + unsigned int wxDataViewCtrl::GetColumnCount() const { return m_cols.GetCount(); -- 2.45.2