#include "mondrian.xpm"
#endif
-// -------------------- wxDataViewControl --------------------
+#include "wx/dataview.h"
-// wxDataViewStore
-
-class wxDataViewStore
-{
-public:
- wxDataViewStore() { }
- virtual ~wxDataViewStore() { }
-
-protected:
- DECLARE_NO_COPY_CLASS(wxDataViewStore)
-};
-
-
-// wxDataViewListStoreBase
-
-class wxDataViewListStoreBase: public wxDataViewStore
-{
-public:
- wxDataViewListStoreBase() { }
-
- virtual bool AppendRow() = 0;
-
-protected:
- DECLARE_NO_COPY_CLASS(wxDataViewListStoreBase)
-};
-
-
-// wxDataViewCtrlBase
-
-class wxDataViewCtrlBase: public wxControl
-{
-public:
- wxDataViewCtrlBase();
-
- // Define public API here
-
- virtual bool AppendStringColumn( const wxString &label, int index ) = 0;
-
- virtual bool AssociateStore( wxDataViewStore *store );
- wxDataViewStore* GetStore();
-
-private:
- wxDataViewStore *m_store;
-
-protected:
- DECLARE_NO_COPY_CLASS(wxDataViewCtrlBase)
-};
-
-
-// -------------------- GTK2 header --------------------
-
-#ifdef __WXGTK20__
-
-#include "wx/gtk/private.h"
-
-class wxDataViewListStore: public wxDataViewListStoreBase
-{
-public:
- wxDataViewListStore();
-
- // interface
- virtual bool AppendRow();
-
- // implementation
- GtkListStore* GetGtkListStore() { return m_store; }
-
-private:
- GtkListStore *m_store;
-
-protected:
- DECLARE_NO_COPY_CLASS(wxDataViewListStore)
-};
+// -------------------------------------
+// MyTextModel
+// -------------------------------------
-class wxDataViewCtrl: public wxDataViewCtrlBase
+class MyTextModel: public wxDataViewListModel
{
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, int index );
-
- virtual bool AssociateStore( wxDataViewStore *store );
-
-
-private:
- DECLARE_DYNAMIC_CLASS(wxDataViewCtrl)
- DECLARE_NO_COPY_CLASS(wxDataViewCtrl)
-};
-
-#endif
-
-// -------------------- wxDataViewControl --------------------
-
-wxDataViewCtrlBase::wxDataViewCtrlBase()
-{
- m_store = NULL;
+ MyTextModel() {}
+
+ virtual size_t GetNumberOfRows()
+ { return 1000; }
+ virtual size_t GetNumberOfCols()
+ { return 3; }
+ // as reported by wxVariant
+ virtual wxString GetColType( size_t col )
+ { return wxT("string"); }
+ virtual wxVariant GetValue( size_t col, size_t row )
+ { wxString tmp;
+ tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col );
+ return tmp;
+ }
}
-bool wxDataViewCtrlBase::AssociateStore( wxDataViewStore *store )
-{
- m_store = store;
-
- return true;
-}
-
-wxDataViewStore* wxDataViewCtrlBase::GetStore()
-{
- return m_store;
-}
-
-IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl,wxControl)
-
-// -------------------- GTK2 implementaion --------------------
-
-#ifdef __WXGTK20__
-
-// wxDataViewListStore
-
-wxDataViewListStore::wxDataViewListStore()
-{
- m_store = gtk_list_store_new( 3, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING );
-}
-
-bool wxDataViewListStore::AppendRow()
-{
- GtkTreeIter iter;
- gtk_list_store_append( m_store, &iter );
-
- return true;
-}
-
-
-// wxDataViewCtrl
-
-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, int index )
-{
- 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::AssociateStore( wxDataViewStore *store )
-{
- wxDataViewCtrlBase::AssociateStore( store );
-
- // 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
-
-// -------------------- wxDataViewControl --------------------
+// -------------------------------------
+// MyApp
+// -------------------------------------
class MyApp: public wxApp
{
bool OnInit(void);
};
+// -------------------------------------
+// MyFrame
+// -------------------------------------
+
class MyFrame: public wxFrame
{
public:
wxDataViewCtrl* dataview;
};
-// ID for the menu commands
+// -------------------------------------
+// MyApp
+// -------------------------------------
+
#define DYNAMIC_QUIT wxID_EXIT
#define DYNAMIC_ABOUT wxID_ABOUT
-// Create a new application object
IMPLEMENT_APP (MyApp)
-// `Main program' equivalent, creating windows and returning main app frame
bool MyApp::OnInit(void)
{
- // Create the main frame window
MyFrame *frame = new MyFrame(NULL, _T("Dynamic wxWidgets App"), 50, 50, 450, 340);
- // Show the frame
frame->Show(true);
SetTopWindow(frame);
// MyFrame
// -------------------------------------
-// My frame constructor
MyFrame::MyFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
{
- // Give it an icon
#ifdef __WXMSW__
SetIcon(wxIcon(_T("mondrian")));
#else
SetIcon(wxIcon(mondrian_xpm));
#endif
- // Make a menubar
wxMenu *file_menu = new wxMenu;
file_menu->Append(DYNAMIC_ABOUT, _T("&About"));
dataview = new wxDataViewCtrl( this, -1 );
- dataview->AppendStringColumn( wxT("first"), 0 );
- dataview->AppendStringColumn( wxT("second"), 1 );
- dataview->AppendStringColumn( wxT("third"), 2 );
-
- wxDataViewListStore *store = new wxDataViewListStore;
- store->AppendRow();
- store->AppendRow();
- store->AppendRow();
- store->AppendRow();
+ dataview->AppendStringColumn( wxT("first") );
+ dataview->AppendStringColumn( wxT("second") );
+ dataview->AppendStringColumn( wxT("third") );
- dataview->AssociateStore( store );
+ MyTextModel *model = new MyTextModel;
+ dataview->AssociateModel( Model );
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )