From 6842a71a5badd7fccaf6031e355b9260e3bda47f Mon Sep 17 00:00:00 2001 From: Robert Roebling Date: Thu, 23 Feb 2006 02:04:46 +0000 Subject: [PATCH] added wxDataViewCell git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37675 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dataview.h | 70 ++++++++++++++++++++++++++++++--------- include/wx/gtk/dataview.h | 38 +++++++++++++++++++-- src/common/datavcmn.cpp | 32 ++++++++++++++---- src/gtk/dataview.cpp | 58 +++++++++++++++++++------------- 4 files changed, 152 insertions(+), 46 deletions(-) diff --git a/include/wx/dataview.h b/include/wx/dataview.h index fcb1dd20e4..01d160213f 100644 --- a/include/wx/dataview.h +++ b/include/wx/dataview.h @@ -31,6 +31,7 @@ class WXDLLIMPEXP_CORE wxDataViewCtrl; class WXDLLIMPEXP_CORE wxDataViewColumn; +class WXDLLIMPEXP_CORE wxDataViewCell; extern WXDLLEXPORT_DATA(const wxChar) wxDataViewCtrlNameStr[]; @@ -103,21 +104,52 @@ protected: }; // --------------------------------------------------------- -// wxDataViewColumn +// wxDataViewCellBase // --------------------------------------------------------- -enum wxDataViewColumnType +enum wxDataViewCellMode { - wxDATAVIEW_COL_TEXT, - wxDATAVIEW_COL_ICON, - wxDATAVIEW_COL_ICONTEXT, - wxDATAVIEW_COL_CHECK, - wxDATAVIEW_COL_DATETIME, - wxDATAVIEW_COL_PROGRESS, - wxDATAVIEW_COL_CHOICE, - wxDATAVIEW_COL_CUSTOM + wxDATAVIEW_CELL_INERT, + wxDATAVIEW_CELL_ACTIVATABLE, + wxDATAVIEW_CELL_EDITABLE }; +enum wxDataViewCellRenderState +{ + wxDATAVIEW_CELL_SELECTED = 1, + wxDATAVIEW_CELL_PRELIT = 2, + wxDATAVIEW_CELL_INSENSITIVE = 4, + wxDATAVIEW_CELL_FOCUSED = 8 +}; + +class wxDataViewCellBase: public wxObject +{ +public: + wxDataViewCellBase( const wxString &varianttype, wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT ); + + virtual bool SetValue( const wxVariant &value ) { return true; } + virtual bool GetValue( wxVariant &value ) { return true; } + virtual bool BeginEdit() { return true; } + virtual bool EndEdit() { return true; } + + virtual bool Render( wxRect cell, wxRect exposed, wxDC *dc, int state ) { return true; } + + void SetOwner( wxDataViewColumn *owner ) { m_owner = owner; } + wxDataViewColumn* GetOwner() { return m_owner; } + +private: + wxDataViewCellMode m_mode; + wxString m_variantType; + wxDataViewColumn *m_owner; + +protected: + DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCellBase) +}; + +// --------------------------------------------------------- +// wxDataViewColumnBase +// --------------------------------------------------------- + enum wxDataViewColumnFlags { wxDATAVIEW_COL_RESIZABLE = 1, @@ -128,17 +160,26 @@ enum wxDataViewColumnFlags class wxDataViewColumnBase: public wxObject { public: - wxDataViewColumnBase( const wxString &title, wxDataViewCtrl *ctrl, - wxDataViewColumnType kind, int flags = 0 ); + wxDataViewColumnBase( const wxString &title, wxDataViewCell *cell, size_t model_column, int flags = 0 ); + ~wxDataViewColumnBase(); virtual void SetTitle( const wxString &title ); virtual wxString GetTitle(); + + wxDataViewCell* GetCell() { return m_cell; } + + size_t GetModelColumn() { return m_model_column; } + + void SetOwner( wxDataViewCtrl *owner ) { m_owner = owner; } + wxDataViewCtrl *GetOwner() { return m_owner; } private: wxDataViewCtrl *m_ctrl; - wxDataViewColumnType m_kind; + wxDataViewCell *m_cell; + int m_model_column; int m_flags; wxString m_title; + wxDataViewCtrl *m_owner; protected: DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewColumnBase) @@ -153,12 +194,11 @@ class wxDataViewCtrlBase: public wxControl public: wxDataViewCtrlBase(); ~wxDataViewCtrlBase(); - virtual bool AssociateModel( wxDataViewListModel *model ); wxDataViewListModel* GetModel(); - virtual bool AppendStringColumn( const wxString &label ); + virtual bool AppendStringColumn( const wxString &label, size_t model_column ); virtual bool AppendColumn( wxDataViewColumn *col ); virtual size_t GetNumberOfColumns(); virtual bool DeleteColumn( size_t pos ); diff --git a/include/wx/gtk/dataview.h b/include/wx/gtk/dataview.h index e9a485ea30..1131a7430a 100644 --- a/include/wx/gtk/dataview.h +++ b/include/wx/gtk/dataview.h @@ -21,6 +21,40 @@ class WXDLLIMPEXP_CORE wxDataViewCtrl; +// --------------------------------------------------------- +// wxDataViewCell +// --------------------------------------------------------- + +class wxDataViewCell: public wxDataViewCellBase +{ +public: + wxDataViewCell( const wxString &varianttype, wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT ); + + // implementation + void* GetGtkHandle() { return m_renderer; } + +protected: + // holds the GTK handle + void* m_renderer; + +protected: + DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewCell) +}; + +// --------------------------------------------------------- +// wxDataViewTextCell +// --------------------------------------------------------- + +class wxDataViewTextCell: public wxDataViewCell +{ +public: + wxDataViewTextCell( const wxString &varianttype = wxT("string"), + wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT ); + +protected: + DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewTextCell) +}; + // --------------------------------------------------------- // wxDataViewColumn // --------------------------------------------------------- @@ -28,8 +62,7 @@ class WXDLLIMPEXP_CORE wxDataViewCtrl; class WXDLLIMPEXP_CORE wxDataViewColumn: public wxDataViewColumnBase { public: - wxDataViewColumn( const wxString &title, wxDataViewCtrl *ctrl, - wxDataViewColumnType kind, int flags = 0 ); + wxDataViewColumn( const wxString &title, wxDataViewCell *cell, size_t model_column, int flags = 0 ); virtual ~wxDataViewColumn(); virtual void SetTitle( const wxString &title ); @@ -38,6 +71,7 @@ public: void* GetGtkHandle() { return m_column; } private: + // holds the GTK handle void* m_column; protected: diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 3659c54e6d..cf065b765a 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -112,19 +112,38 @@ wxDataViewListModelNotifier* wxDataViewListModel::GetNotifier() return m_notifier; } +// --------------------------------------------------------- +// wxDataViewCellBase +// --------------------------------------------------------- + +IMPLEMENT_ABSTRACT_CLASS(wxDataViewCellBase, wxObject) + +wxDataViewCellBase::wxDataViewCellBase( const wxString &varianttype, wxDataViewCellMode mode ) +{ + m_variantType = varianttype; + m_mode = mode; +} + // --------------------------------------------------------- // wxDataViewColumnBase // --------------------------------------------------------- IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumnBase, wxObject) -wxDataViewColumnBase::wxDataViewColumnBase( const wxString &title, wxDataViewCtrl *ctrl, - wxDataViewColumnType kind, int flags) +wxDataViewColumnBase::wxDataViewColumnBase( const wxString &title, wxDataViewCell *cell, size_t model_column, int flags) { - m_ctrl = ctrl; - m_kind = kind; + m_cell = cell; + m_model_column = model_column; m_flags = flags; m_title = title; + m_owner = NULL; + m_cell->SetOwner( (wxDataViewColumn*) this ); +} + +wxDataViewColumnBase::~wxDataViewColumnBase() +{ + if (m_cell) + delete m_cell; } void wxDataViewColumnBase::SetTitle( const wxString &title ) @@ -170,14 +189,15 @@ wxDataViewListModel* wxDataViewCtrlBase::GetModel() return m_model; } -bool wxDataViewCtrlBase::AppendStringColumn( const wxString &label ) +bool wxDataViewCtrlBase::AppendStringColumn( const wxString &label, size_t model_column ) { - return AppendColumn( new wxDataViewColumn( label, (wxDataViewCtrl*) this, wxDATAVIEW_COL_TEXT ) ); + return AppendColumn( new wxDataViewColumn( label, new wxDataViewTextCell(), model_column ) ); } bool wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col ) { m_cols.Append( (wxObject*) col ); + col->SetOwner( (wxDataViewCtrl*) this ); return true; } diff --git a/src/gtk/dataview.cpp b/src/gtk/dataview.cpp index 711516b578..35931d39bd 100644 --- a/src/gtk/dataview.cpp +++ b/src/gtk/dataview.cpp @@ -501,6 +501,29 @@ bool wxGtkDataViewListModelNotifier::Cleared() return false; } +// --------------------------------------------------------- +// wxDataViewCell +// --------------------------------------------------------- + +IMPLEMENT_ABSTRACT_CLASS(wxDataViewCell, wxDataViewCellBase) + +wxDataViewCell::wxDataViewCell( const wxString &varianttype, wxDataViewCellMode mode ) : + wxDataViewCellBase( varianttype, mode ) +{ + m_renderer = NULL; +} + +// --------------------------------------------------------- +// wxDataViewTextCell +// --------------------------------------------------------- + +IMPLEMENT_ABSTRACT_CLASS(wxDataViewTextCell, wxDataViewCell) + +wxDataViewTextCell::wxDataViewTextCell( const wxString &varianttype, wxDataViewCellMode mode ) : + wxDataViewCell( varianttype, mode ) +{ + m_renderer = (void*) gtk_cell_renderer_text_new(); +} // --------------------------------------------------------- // wxDataViewColumn @@ -508,32 +531,21 @@ bool wxGtkDataViewListModelNotifier::Cleared() IMPLEMENT_ABSTRACT_CLASS(wxDataViewColumn, wxDataViewColumnBase) -wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewCtrl *ctrl, - wxDataViewColumnType kind, int flags ) : - wxDataViewColumnBase( title, ctrl, kind, flags ) +wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewCell *cell, + size_t model_column, int flags ) : + wxDataViewColumnBase( title, cell, model_column, flags ) { - GtkCellRenderer *renderer = NULL; + GtkCellRenderer *renderer = (GtkCellRenderer *) cell->GetGtkHandle(); - 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. + GtkTreeViewColumn *column = gtk_tree_view_column_new(); + + gtk_tree_view_column_set_title( column, wxGTK_CONV(title) ); + gtk_tree_view_column_pack_start( column, renderer, TRUE ); + + // only correct for wxDataViewTextCell + gtk_tree_view_column_set_attributes( column, renderer, "text", model_column, NULL ); + m_column = (void*) column; } -- 2.45.2