From fa28826dd3836d6d50c92ca8de1e97dd4c8cf3bc Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Wed, 22 Feb 2006 00:19:04 +0000 Subject: [PATCH] Added wxDataViewColumn git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37665 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dataview.h | 56 ++++++++++++++++++++++++++++-- include/wx/gtk/dataview.h | 27 +++++++++++++-- src/common/datavcmn.cpp | 57 +++++++++++++++++++++++++++++++ src/gtk/dataview.cpp | 72 ++++++++++++++++++++++++++++++++------- 4 files changed, 193 insertions(+), 19 deletions(-) diff --git a/include/wx/dataview.h b/include/wx/dataview.h index 47b2edef57..fcb1dd20e4 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -29,6 +29,9 @@ // wxDataViewCtrl globals // ---------------------------------------------------------------------------- +class WXDLLIMPEXP_CORE wxDataViewCtrl; +class WXDLLIMPEXP_CORE wxDataViewColumn; + extern WXDLLEXPORT_DATA(const wxChar) wxDataViewCtrlNameStr[]; // --------------------------------------------------------- @@ -99,6 +102,48 @@ protected: DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewListModel) }; +// --------------------------------------------------------- +// wxDataViewColumn +// --------------------------------------------------------- + +enum wxDataViewColumnType +{ + wxDATAVIEW_COL_TEXT, + wxDATAVIEW_COL_ICON, + wxDATAVIEW_COL_ICONTEXT, + wxDATAVIEW_COL_CHECK, + wxDATAVIEW_COL_DATETIME, + wxDATAVIEW_COL_PROGRESS, + wxDATAVIEW_COL_CHOICE, + wxDATAVIEW_COL_CUSTOM +}; + +enum wxDataViewColumnFlags +{ + wxDATAVIEW_COL_RESIZABLE = 1, + wxDATAVIEW_COL_SORTABLE = 2, + wxDATAVIEW_COL_HIDDEN = 4 +}; + +class wxDataViewColumnBase: public wxObject +{ +public: + wxDataViewColumnBase( const wxString &title, wxDataViewCtrl *ctrl, + wxDataViewColumnType kind, int flags = 0 ); + + virtual void SetTitle( const wxString &title ); + virtual wxString GetTitle(); + +private: + wxDataViewCtrl *m_ctrl; + wxDataViewColumnType m_kind; + int m_flags; + wxString m_title; + +protected: + DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase) +}; + // --------------------------------------------------------- // wxDataViewCtrlBase // --------------------------------------------------------- @@ -109,20 +154,25 @@ public: wxDataViewCtrlBase(); ~wxDataViewCtrlBase(); - virtual bool AppendStringColumn( const wxString &label ) = 0; virtual bool AssociateModel( wxDataViewListModel *model ); wxDataViewListModel* GetModel(); + virtual bool AppendStringColumn( const wxString &label ); + virtual bool AppendColumn( wxDataViewColumn *col ); + virtual size_t GetNumberOfColumns(); + virtual bool DeleteColumn( size_t pos ); + virtual bool ClearColumns(); + virtual wxDataViewColumn* GetColumn( size_t pos ); + private: wxDataViewListModel *m_model; + wxList m_cols; protected: DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCtrlBase) }; - - #if defined(__WXGTK20__) #include "wx/gtk/dataview.h" #elif defined(__WXMAC__) diff --git a/include/wx/gtk/dataview.h b/include/wx/gtk/dataview.h index 4da012ab87..e9a485ea30 100644 --- a/include/wx/gtk/dataview.h +++ b/include/wx/gtk/dataview.h @@ -21,6 +21,29 @@ class WXDLLIMPEXP_CORE wxDataViewCtrl; +// --------------------------------------------------------- +// wxDataViewColumn +// --------------------------------------------------------- + +class WXDLLIMPEXP_CORE wxDataViewColumn: public wxDataViewColumnBase +{ +public: + wxDataViewColumn( const wxString &title, wxDataViewCtrl *ctrl, + wxDataViewColumnType kind, int flags = 0 ); + virtual ~wxDataViewColumn(); + + virtual void SetTitle( const wxString &title ); + + // implementation + void* GetGtkHandle() { return m_column; } + +private: + void* m_column; + +protected: + DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumn) +}; + // --------------------------------------------------------- // wxDataViewCtrl // --------------------------------------------------------- @@ -50,10 +73,8 @@ public: const wxSize& size = wxDefaultSize, long style = 0, const wxValidator& validator = wxDefaultValidator ); - virtual bool AppendStringColumn( const wxString &label ); - virtual bool AssociateModel( wxDataViewListModel *model ); - + virtual bool AppendColumn( wxDataViewColumn *col ); private: DECLARE_DYNAMIC_CLASS(wxDataViewCtrl) diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 2cd8efd21b..3659c54e6d 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -112,6 +112,31 @@ wxDataViewListModelNotifier* wxDataViewListModel::GetNotifier() return m_notifier; } +// --------------------------------------------------------- +// wxDataViewColumnBase +// --------------------------------------------------------- + +IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase, wxObject) + +wxDataViewColumnBase::wxDataViewColumnBase( const wxString &title, wxDataViewCtrl *ctrl, + wxDataViewColumnType kind, int flags) +{ + m_ctrl = ctrl; + m_kind = kind; + m_flags = flags; + m_title = title; +} + +void wxDataViewColumnBase::SetTitle( const wxString &title ) +{ + m_title = title; +} + +wxString wxDataViewColumnBase::GetTitle() +{ + return m_title; +} + // --------------------------------------------------------- // wxDataViewCtrlBase // --------------------------------------------------------- @@ -121,6 +146,7 @@ IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase, wxControl) wxDataViewCtrlBase::wxDataViewCtrlBase() { m_model = NULL; + m_cols.DeleteContents( true ); } wxDataViewCtrlBase::~wxDataViewCtrlBase() @@ -144,3 +170,34 @@ wxDataViewListModel* wxDataViewCtrlBase::GetModel() return m_model; } +bool wxDataViewCtrlBase::AppendStringColumn( const wxString &label ) +{ + return AppendColumn( new wxDataViewColumn( label, (wxDataViewCtrl*) this, wxDATAVIEW_COL_TEXT ) ); +} + +bool wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col ) +{ + m_cols.Append( (wxObject*) col ); + return true; +} + +size_t wxDataViewCtrlBase::GetNumberOfColumns() +{ + return m_cols.GetCount(); +} + +bool wxDataViewCtrlBase::DeleteColumn( size_t pos ) +{ + return false; +} + +bool wxDataViewCtrlBase::ClearColumns() +{ + return false; +} + +wxDataViewColumn* wxDataViewCtrlBase::GetColumn( size_t pos ) +{ + return (wxDataViewColumn*) m_cols[ pos ]; +} + diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 79b977e885..711516b578 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -502,6 +502,53 @@ bool wxGtkDataViewListModelNotifier::Cleared() } +// --------------------------------------------------------- +// wxDataViewColumn +// --------------------------------------------------------- + +IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn, wxDataViewColumnBase) + +wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewCtrl *ctrl, + wxDataViewColumnType kind, int flags ) : + wxDataViewColumnBase( title, ctrl, kind, flags ) +{ + GtkCellRenderer *renderer = NULL; + + if (kind == wxDATAVIEW_COL_TEXT) + { + renderer = gtk_cell_renderer_text_new(); + } else + if (kind == wxDATAVIEW_COL_CHECK) + { + renderer = gtk_cell_renderer_toggle_new(); + } else + if (kind == wxDATAVIEW_COL_ICON) + { + renderer = gtk_cell_renderer_pixbuf_new(); + } + else + return; + + GtkTreeViewColumn *column = + gtk_tree_view_column_new_with_attributes( wxGTK_CONV(title), renderer, "text", 0, NULL ); + + // bind to data here... not above. + + m_column = (void*) column; +} + +wxDataViewColumn::~wxDataViewColumn() +{ +} + +void wxDataViewColumn::SetTitle( const wxString &title ) +{ + wxDataViewColumnBase::SetTitle( title ); + + GtkTreeViewColumn *column = (GtkTreeViewColumn *)m_column; + gtk_tree_view_column_set_title( column, wxGTK_CONV(title) ); +} + //----------------------------------------------------------------------------- // wxDataViewCtrl //----------------------------------------------------------------------------- @@ -541,19 +588,6 @@ bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id, return true; } -bool wxDataViewCtrl::AppendStringColumn( const wxString &label ) -{ - GtkCellRenderer *renderer - = gtk_cell_renderer_text_new(); - - GtkTreeViewColumn *column - = gtk_tree_view_column_new_with_attributes( wxGTK_CONV(label), renderer, "text", -1, NULL ); - - gtk_tree_view_append_column( GTK_TREE_VIEW(m_widget), column ); - - return true; -} - bool wxDataViewCtrl::AssociateModel( wxDataViewListModel *model ) { if (!wxDataViewCtrlBase::AssociateModel( model )) @@ -572,6 +606,18 @@ bool wxDataViewCtrl::AssociateModel( wxDataViewListModel *model ) return true; } +bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col ) +{ + if (!wxDataViewCtrlBase::AppendColumn(col)) + return false; + + GtkTreeViewColumn *column = (GtkTreeViewColumn *)col->GetGtkHandle(); + + gtk_tree_view_append_column( GTK_TREE_VIEW(m_widget), column ); + + return true; +} + #endif // wxUSE_DATAVIEWCTRL -- 2.45.2