#if wxUSE_DATAVIEWCTRL
+#include "wx/control.h"
+#include "wx/textctrl.h"
+#include "wx/bitmap.h"
+
// ----------------------------------------------------------------------------
// wxDataViewCtrl flags
// ----------------------------------------------------------------------------
-#include "wx/control.h"
-#include "wx/textctrl.h"
-#include "wx/bitmap.h"
+// ----------------------------------------------------------------------------
+// wxDataViewCtrl globals
+// ----------------------------------------------------------------------------
extern WXDLLEXPORT_DATA(const wxChar) wxDataViewCtrlNameStr[];
+// ---------------------------------------------------------
+// wxDataViewModel
+// ---------------------------------------------------------
+
+class wxDataViewModel: public wxObject
+{
+public:
+ wxDataViewModel() { }
+ virtual ~wxDataViewModel() { }
+
+protected:
+ DECLARE_NO_COPY_CLASS(wxDataViewModel)
+};
+
+// ---------------------------------------------------------
+// wxDataViewListModelNotifier
+// ---------------------------------------------------------
+
+class wxDataViewListModelNotifier
+{
+public:
+ wxDataViewListModelNotifier() { }
+ virtual ~wxDataViewListModelNotifier() { }
+
+ virtual bool RowAppended() = 0;
+ virtual bool RowPrepended() = 0;
+ virtual bool RowInserted( size_t before ) = 0;
+ virtual bool RowDeleted( size_t row ) = 0;
+ virtual bool RowChanged( size_t row ) = 0;
+ virtual bool ValueChanged( size_t row, size_t col ) = 0;
+ virtual bool Cleared() = 0;
+}
+
+// ---------------------------------------------------------
+// wxDataViewListModel
+// ---------------------------------------------------------
+
+class wxDataViewListModel: public wxDataViewModel
+{
+public:
+ wxDataViewListModel();
+ virtual ~wxDataViewListModel();
+
+ virtual size_t GetNumberOfRows() = 0;
+ virtual size_t GetNumberOfCols() = 0;
+ // as reported by wxVariant
+ virtual wxString GetColType( size_t col ) = 0;
+ virtual wxVariant GetValue( size_t col, size_t row ) = 0;
+
+ // delegated notifiers
+ bool RowAppended();
+ bool RowPrepended();
+ bool RowInserted( size_t before );
+ bool RowDeleted( size_t row );
+ bool RowChanged( size_t row );
+ bool ValueChanged( size_t row, size_t col );
+ bool Cleared();
+
+ void SetNotifier( wxDataViewListModelNotifier *notifier );
+ wxDataViewListModelNotifier* GetNotifier();
+
+private:
+ wxDataViewListModelNotifier *m_notifier;
+
+protected:
+ DECLARE_NO_COPY_CLASS(wxDataViewListModel)
+};
+
+// ---------------------------------------------------------
+// wxDataViewCtrlBase
+// ---------------------------------------------------------
+
+class wxDataViewCtrlBase: public wxControl
+{
+public:
+ wxDataViewCtrlBase();
+ ~wxDataViewCtrlBase();
+
+ virtual bool AppendStringColumn( const wxString &label ) = 0;
+
+ virtual bool AssociateModel( wxDataViewModel *model );
+ wxDataViewModel* GetModel();
+
+private:
+ wxDataViewModel *m_model;
+protected:
+ DECLARE_NO_COPY_CLASS(wxDataViewCtrlBase)
+};
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: wx/gtk/dataview.h
+// Purpose: wxDataViewCtrl GTK+2 implementation header
+// Author: Robert Roebling
+// Id: $Id$
+// Copyright: (c) 1998 Robert Roebling
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __GTKDATAVIEWCTRLH__
+#define __GTKDATAVIEWCTRLH__
+
+#include "wx/defs.h"
+#include "wx/object.h"
+#include "wx/list.h"
+#include "wx/control.h"
+
+// ---------------------------------------------------------
+// classes
+// ---------------------------------------------------------
+
+class WXDLLIMPEXP_CORE wxDataViewCtrl;
+
+// ---------------------------------------------------------
+// wxDataViewCtrl
+// ---------------------------------------------------------
+
+class WXDLLIMPEXP_CORE wxDataViewCtrl: public wxDataViewCtrlBase
+{
+public:
+ wxDataViewCtrl()
+ {
+ Init();
+ }
+
+ wxDataViewCtrl( wxWindow *parent, wxWindowID id,
+ const wxPoint& pos = wxDefaultPosition,
+ const wxSize& size = wxDefaultSize, long style = 0,
+ const wxValidator& validator = wxDefaultValidator )
+ {
+ Create(parent, id, pos, size, style, validator );
+ }
+
+ virtual ~wxDataViewCtrl();
+
+ void Init();
+
+ bool Create(wxWindow *parent, wxWindowID id,
+ const wxPoint& pos = wxDefaultPosition,
+ const wxSize& size = wxDefaultSize, long style = 0,
+ const wxValidator& validator = wxDefaultValidator );
+
+ virtual bool AppendStringColumn( const wxString &label );
+
+ virtual bool AssociateModel( wxDataViewStore *model );
+
+
+private:
+ DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
+ DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
+};
+
+
+#endif // __GTKDATAVIEWCTRLH__
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: src/common/datavcmn.cpp
+// Purpose: wxDataViewCtrl base classes and common parts
+// Author: Robert Roebling
+// Created: 2006/02/20
+// RCS-ID: $Id$
+// Copyright: (c) 2006, Robert Roebling
+// Licence: wxWindows licence
+/////////////////////////////////////////////////////////////////////////////
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+ #pragma hdrstop
+#endif
+
+#include "wx/dataview.h"
+#include "wx/log.h"
+#include "wx/image.h"
+
+// ---------------------------------------------------------
+// wxDataViewModel
+// ---------------------------------------------------------
+
+IMPLEMENT_ABSTRACT_CLASS(wxDataViewModel, wxObject)
+
+// ---------------------------------------------------------
+// wxDataViewListModel
+// ---------------------------------------------------------
+
+IMPLEMENT_ABSTRACT_CLASS(wxDataViewListModel, wxDataViewModel)
+
+wxDataViewListModel::wxDataViewListModel()
+{
+ m_notifier = NULL;
+}
+
+wxDataViewListModel::~wxDataViewListModel()
+{
+ if (m_notifier)
+ delete m_notifier;
+}
+
+bool wxDataViewListModel::RowAppended()
+{
+ if (m_notifier)
+ return m_notifier->RowAppended();
+
+ return false;
+}
+
+bool wxDataViewListModel::RowPrepended()
+{
+ if (m_notifier)
+ return m_notifier->RowPrepended();
+
+ return false;
+}
+
+bool wxDataViewListModel::RowInserted( size_t before )
+{
+ if (m_notifier)
+ return m_notifier->RowInserted( before );
+
+ return false;
+}
+
+bool wxDataViewListModel::RowDeleted( size_t row )
+{
+ if (m_notifier)
+ return m_notifier->RowDeleted( row );
+
+ return false;
+}
+
+bool wxDataViewListModel::RowChanged( size_t row )
+{
+ if (m_notifier)
+ return m_notifier->RowChanged( row );
+
+ return false;
+}
+
+bool wxDataViewListModel::ValueChanged( size_t row, size_t col )
+{
+ if (m_notifier)
+ return m_notifier->RowAppended();
+
+ return false;
+}
+
+bool wxDataViewListModel::Cleared()
+{
+ if (m_notifier)
+ return m_notifier->Cleared();
+
+ return false;
+}
+
+void wxDataViewListModel::SetNotifier( wxDataViewListModelNotifier *notifier )
+{
+ if (m_notifier)
+ delete m_notifier;
+
+ m_notifier = notifier;
+}
+
+wxDataViewListModelNotifier* wxDataViewListModel::GetNotifier()
+{
+ return m_notifier;
+}
+
+// ---------------------------------------------------------
+// wxDataViewCtrlBase
+// ---------------------------------------------------------
+
+IMPLEMENT_ABSTRACT_CLASS(wxDataViewCtrlBase, wxControl)
+
+wxDataViewCtrlBase::wxDataViewCtrlBase()
+{
+ m_model = NULL;
+}
+
+wxDataViewCtrlBase::~wxDataViewCtrlBase()
+{
+ if (m_model)
+ delete m_model;
+}
+
+bool wxDataViewCtrlBase::AssociateModel( wxDataViewModel *model )
+{
+ if (m_model)
+ delete m_model;
+
+ m_model = model;
+
+ return true;
+}
+
+wxDataViewModel* wxDataViewCtrlBase::GetModel()
+{
+ return m_model;
+}
+
GtkWxListStore *list_store = GTK_LIST_STORE (object);
/* we need to sort out, which class deletes what */
- delete model;
+ /* delete model; */
/* must chain up */
(* parent_class->finalize) (object);
GtkWxListStore *list_store = (GtkWxListStore *) tree_model;
g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model), 0);
- return list_store->model->GetColumns();
+ return list_store->model->GetNumberOfCols();
}
static GType
GtkWxListStore *list_store = (GtkWxListStore *) tree_model;
g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model), G_TYPE_INVALID);
- GType gtype = G_TYPE_INVALID;
+ GType gtype = G_TYPE_STRING;
+
#if 0
- list_store->model->GetColumnType( index );
+ wxString wxtype = list_store->model->GetColType( index );
// convert wxtype to GType
gtype = ..
#endif
g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model), FALSE);
g_return_val_if_fail (gtk_tree_path_get_depth (path) > 0, FALSE);
-#if 0
- i = gtk_tree_path_get_indices (path)[0];
-
- if (i >= list_store->length)
- return FALSE;
+ i = gtk_tree_path_get_indices (path)[0];
- list = g_slist_nth (G_SLIST (list_store->root), i);
-
- /* If this fails, list_store->length has gotten mangled. */
- g_assert (list);
+ if (i >= list_store->model->GetCount())
+ return FALSE;
- iter->stamp = list_store->stamp;
- iter->user_data = list;
-#endif
+ iter->stamp = list_store->stamp;
+ // user_data is just the index
+ iter->user_data = (gpointer) i;
return TRUE;
}
GtkWxListStore *list_store = (GtkListStore *) tree_model;
g_return_val_if_fail (GTK_IS_WX_LIST_STORE (tree_model), NULL);
-#if 0
- g_return_val_if_fail (iter->stamp == GTK_WX_LIST_STORE (tree_model)->stamp, NULL);
+ g_return_val_if_fail (iter->stamp == GTK_WX_LIST_STORE (tree_model)->stamp, NULL);
- GtkTreePath *retval;
- GSList *list;
- gint i = 0;
-
- if (G_SLIST (iter->user_data) == G_SLIST (GTK_LIST_STORE (tree_model)->tail))
- {
- retval = gtk_tree_path_new ();
- gtk_tree_path_append_index (retval, GTK_LIST_STORE (tree_model)->length - 1);
- return retval;
- }
-
- for (list = G_SLIST (GTK_LIST_STORE (tree_model)->root); list; list = list->next)
- {
- if (list == G_SLIST (iter->user_data))
- break;
- i++;
- }
- if (list == NULL)
- return NULL;
-
- retval = gtk_tree_path_new ();
- gtk_tree_path_append_index (retval, i);
- return retval;
-#endif
-
- return NULL;
+ GtkTreePath *retval = gtk_tree_path_new ();
+ // user_data is just the index
+ int i = (int) item->user_data;
+ gtk_tree_path_append_index (retval, i);
+ return retval;
}
static void
{
GtkWxListStore *list_store = (GtkListStore *) tree_model;
g_return_if_fail (GTK_IS_WX_LIST_STORE (tree_model) );
+
+ g_value_init( value, G_TYPE_STRING );
+ g_value_set_string( value, "Hello" );
#if 0
GtkTreeDataList *list;
// wxDataViewCtrl
//-----------------------------------------------------------------------------
-IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl,wxControl)
+IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase)
+
+wxDataViewCtrl::~wxDataViewCtrl()
+{
+}
+
+void wxDataViewCtrl::Init()
+{
+}
+
+bool wxDataViewCtrl::Create(wxWindow *parent, wxWindowID id,
+ const wxPoint& pos, const wxSize& size,
+ long style, const wxValidator& validator )
+{
+ Init();
+
+ m_needParent = TRUE;
+ m_acceptsFocus = TRUE;
+
+ if (!PreCreation( parent, pos, size ) ||
+ !CreateBase( parent, id, pos, size, style, validator ))
+ {
+ wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
+ return FALSE;
+ }
+
+ m_widget = gtk_tree_view_new();
+
+ m_parent->DoAddChild( this );
+
+ PostCreation(size);
+
+ 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", index, NULL );
+
+ gtk_tree_view_append_column( GTK_TREE_VIEW(m_widget), column );
+
+ return true;
+}
+
+bool wxDataViewCtrl::AssociateModel( wxDataViewStore *model )
+{
+ if (!wxDataViewCtrlBase::AssociateModel( model ))
+ return false;
+
+ // Right now we only have the GTK+ port's
+ // list store variant, so cast to that...
+
+ wxDataViewListStore *liststore = (wxDataViewListStore*) store;
+
+ gtk_tree_view_set_model( GTK_TREE_VIEW(m_widget), GTK_TREE_MODEL(liststore->GetGtkListStore()) );
+
+ return true;
+}
#endif // wxUSE_DATAVIEWCTRL