]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxDataViewColumn
authorRobert Roebling <robert@roebling.de>
Wed, 22 Feb 2006 00:19:04 +0000 (00:19 +0000)
committerRobert Roebling <robert@roebling.de>
Wed, 22 Feb 2006 00:19:04 +0000 (00:19 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@37665 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/dataview.h
include/wx/gtk/dataview.h
src/common/datavcmn.cpp
src/gtk/dataview.cpp

index 47b2edef5735af34d0e33857074d6a1cf546bd9d..fcb1dd20e40b9004891f1b8a6bdb9666f0b1c599 100644 (file)
@@ -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__)
index 4da012ab872f0352b257e67276d7cb62bb765ead..e9a485ea3029bbdc195a574bc9661a8fa19171f6 100644 (file)
 
 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)
index 2cd8efd21b8eda40d986253a873b129fe581ada1..3659c54e6d8259f2eba8d939c49761040ee5c319 100644 (file)
@@ -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 ];
+}
+
index 79b977e88593f4ed9c90d262fe80e151b571d387..711516b578501d29d0843cd6166689dee5801a5e 100644 (file)
@@ -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