-/////////////////////////////////////////////////////////////////////////////\r
-// Name: mymodels.h\r
-// Purpose: wxDataViewCtrl wxWidgets sample\r
-// Author: Robert Roebling\r
-// Modified by: Francesco Montorsi, Bo Yang\r
-// Created: 06/01/06\r
-// RCS-ID: $Id$\r
-// Copyright: (c) Robert Roebling\r
-// Licence: wxWindows license\r
-/////////////////////////////////////////////////////////////////////////////\r
-\r
-\r
-// ----------------------------------------------------------------------------\r
-// MyMusicTreeModelNode: a node inside MyMusicTreeModel\r
-// ----------------------------------------------------------------------------\r
-\r
-class MyMusicTreeModelNode;\r
-WX_DEFINE_ARRAY_PTR( MyMusicTreeModelNode*, MyMusicTreeModelNodePtrArray );\r
-\r
-class MyMusicTreeModelNode\r
-{\r
-public:\r
- MyMusicTreeModelNode( MyMusicTreeModelNode* parent,\r
- const wxString &title, const wxString &artist, \r
- unsigned int year )\r
- {\r
- m_parent = parent;\r
-\r
- m_title = title;\r
- m_artist = artist;\r
- m_year = year;\r
- m_quality = "good";\r
- }\r
-\r
- MyMusicTreeModelNode( MyMusicTreeModelNode* parent,\r
- const wxString &branch )\r
- {\r
- m_parent = parent;\r
-\r
- m_title = branch;\r
- m_year = -1;\r
- }\r
-\r
- ~MyMusicTreeModelNode()\r
- {\r
- // free all our children nodes\r
- size_t count = m_children.GetCount();\r
- for (size_t i = 0; i < count; i++)\r
- {\r
- MyMusicTreeModelNode *child = m_children[i];\r
- delete child;\r
- }\r
- }\r
-\r
- bool IsContainer() const\r
- { return m_children.GetCount()>0; }\r
-\r
- MyMusicTreeModelNode* GetParent()\r
- { return m_parent; }\r
- MyMusicTreeModelNodePtrArray& GetChildren()\r
- { return m_children; }\r
- MyMusicTreeModelNode* GetNthChild( unsigned int n )\r
- { return m_children.Item( n ); }\r
- void Insert( MyMusicTreeModelNode* child, unsigned int n)\r
- { m_children.Insert( child, n); }\r
- void Append( MyMusicTreeModelNode* child )\r
- { m_children.Add( child ); }\r
- unsigned int GetChildCount() const\r
- { return m_children.GetCount(); }\r
-\r
-public: // public to avoid getters/setters\r
- wxString m_title;\r
- wxString m_artist;\r
- int m_year;\r
- wxString m_quality;\r
-\r
-private:\r
- MyMusicTreeModelNode *m_parent;\r
- MyMusicTreeModelNodePtrArray m_children;\r
-};\r
-\r
-\r
-// ----------------------------------------------------------------------------\r
-// MyMusicTreeModel\r
-// ----------------------------------------------------------------------------\r
-\r
-/*\r
-Implement this data model\r
- Title Artist Year Judgement\r
---------------------------------------------------------------------------\r
-1: My Music:\r
- 2: Pop music\r
- 3: You are not alone Michael Jackson 1995 good\r
- 4: Take a bow Madonna 1994 good\r
- 5: Classical music\r
- 6: Ninth Symphony Ludwig v. Beethoven 1824 good\r
- 7: German Requiem Johannes Brahms 1868 good\r
-*/\r
-\r
-class MyMusicTreeModel: public wxDataViewModel\r
-{\r
-public:\r
- MyMusicTreeModel();\r
- ~MyMusicTreeModel()\r
- {\r
- delete m_root;\r
- }\r
-\r
- // helper method for wxLog\r
-\r
- wxString GetTitle( const wxDataViewItem &item ) const;\r
- int GetYear( const wxDataViewItem &item ) const;\r
-\r
- // helper methods to change the model\r
-\r
- void AddToClassical( const wxString &title, const wxString &artist, \r
- unsigned int year );\r
- void Delete( const wxDataViewItem &item );\r
-\r
- wxDataViewItem GetNinthItem() const\r
- {\r
- return wxDataViewItem( m_ninth );\r
- }\r
-\r
- // override sorting to always sort branches ascendingly\r
-\r
- int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,\r
- unsigned int column, bool ascending );\r
-\r
- // implementation of base class virtuals to define model\r
-\r
- virtual unsigned int GetColumnCount() const\r
- {\r
- return 6;\r
- }\r
-\r
- virtual wxString GetColumnType( unsigned int col ) const\r
- {\r
- if (col == 2)\r
- return wxT("long");\r
-\r
- return wxT("string");\r
- }\r
-\r
- virtual void GetValue( wxVariant &variant,\r
- const wxDataViewItem &item, unsigned int col ) const;\r
- virtual bool SetValue( const wxVariant &variant,\r
- const wxDataViewItem &item, unsigned int col );\r
-\r
- virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const;\r
- virtual bool IsContainer( const wxDataViewItem &item ) const;\r
- virtual unsigned int GetChildren( const wxDataViewItem &parent, \r
- wxDataViewItemArray &array ) const;\r
-\r
-private:\r
- MyMusicTreeModelNode* m_root;\r
-\r
- // pointers to some "special" nodes of the tree:\r
- MyMusicTreeModelNode* m_pop;\r
- MyMusicTreeModelNode* m_classical;\r
- MyMusicTreeModelNode* m_ninth;\r
-\r
- // ??\r
- bool m_classicalMusicIsKnownToControl;\r
-};\r
-\r
-\r
-// ----------------------------------------------------------------------------\r
-// MyListModel\r
-// ----------------------------------------------------------------------------\r
-\r
-class MyListModel: public wxDataViewVirtualListModel\r
-{\r
-public:\r
- MyListModel();\r
-\r
- // helper methods to change the model\r
-\r
- void Prepend( const wxString &text );\r
- void DeleteItem( const wxDataViewItem &item );\r
- void DeleteItems( const wxDataViewItemArray &items );\r
- void AddMany();\r
-\r
-\r
- // implementation of base class virtuals to define model\r
-\r
- virtual unsigned int GetColumnCount() const\r
- {\r
- return 3;\r
- }\r
-\r
- virtual wxString GetColumnType( unsigned int col ) const\r
- {\r
- if (col == 1)\r
- return wxT("wxDataViewIconText");\r
-\r
- return wxT("string");\r
- }\r
-\r
- virtual unsigned int GetRowCount()\r
- {\r
- return m_array.GetCount();\r
- }\r
-\r
- virtual void GetValueByRow( wxVariant &variant,\r
- unsigned int row, unsigned int col ) const;\r
- virtual bool GetAttrByRow( unsigned int row, unsigned int col, wxDataViewItemAttr &attr );\r
- virtual bool SetValueByRow( const wxVariant &variant,\r
- unsigned int row, unsigned int col );\r
-\r
-private:\r
- wxArrayString m_array;\r
- wxIcon m_icon[2];\r
- int m_virtualItems;\r
-};\r
-\r
+/////////////////////////////////////////////////////////////////////////////
+// Name: mymodels.h
+// Purpose: wxDataViewCtrl wxWidgets sample
+// Author: Robert Roebling
+// Modified by: Francesco Montorsi, Bo Yang
+// Created: 06/01/06
+// RCS-ID: $Id$
+// Copyright: (c) Robert Roebling
+// Licence: wxWindows license
+/////////////////////////////////////////////////////////////////////////////
+
+
+// ----------------------------------------------------------------------------
+// MyMusicTreeModelNode: a node inside MyMusicTreeModel
+// ----------------------------------------------------------------------------
+
+class MyMusicTreeModelNode;
+WX_DEFINE_ARRAY_PTR( MyMusicTreeModelNode*, MyMusicTreeModelNodePtrArray );
+
+class MyMusicTreeModelNode
+{
+public:
+ MyMusicTreeModelNode( MyMusicTreeModelNode* parent,
+ const wxString &title, const wxString &artist,
+ unsigned int year )
+ {
+ m_parent = parent;
+
+ m_title = title;
+ m_artist = artist;
+ m_year = year;
+ m_quality = "good";
+
+ m_container = false;
+ }
+
+ MyMusicTreeModelNode( MyMusicTreeModelNode* parent,
+ const wxString &branch )
+ {
+ m_parent = parent;
+
+ m_title = branch;
+ m_year = -1;
+
+ m_container = true;
+ }
+
+ ~MyMusicTreeModelNode()
+ {
+ // free all our children nodes
+ size_t count = m_children.GetCount();
+ for (size_t i = 0; i < count; i++)
+ {
+ MyMusicTreeModelNode *child = m_children[i];
+ delete child;
+ }
+ }
+
+ bool IsContainer() const
+ { return m_container; }
+
+ MyMusicTreeModelNode* GetParent()
+ { return m_parent; }
+ MyMusicTreeModelNodePtrArray& GetChildren()
+ { return m_children; }
+ MyMusicTreeModelNode* GetNthChild( unsigned int n )
+ { return m_children.Item( n ); }
+ void Insert( MyMusicTreeModelNode* child, unsigned int n)
+ { m_children.Insert( child, n); }
+ void Append( MyMusicTreeModelNode* child )
+ { m_children.Add( child ); }
+ unsigned int GetChildCount() const
+ { return m_children.GetCount(); }
+
+public: // public to avoid getters/setters
+ wxString m_title;
+ wxString m_artist;
+ int m_year;
+ wxString m_quality;
+
+ // TODO/FIXME:
+ // the GTK version of wxDVC (in particular wxDataViewCtrlInternal::ItemAdded)
+ // needs to know in advance if a node is or _will be_ a container.
+ // Thus implementing:
+ // bool IsContainer() const
+ // { return m_children.GetCount()>0; }
+ // doesn't work with wxGTK when MyMusicTreeModel::AddToClassical is called
+ // AND the classical node was removed (a new node temporary without children
+ // would be added to the control)
+ bool m_container;
+
+private:
+ MyMusicTreeModelNode *m_parent;
+ MyMusicTreeModelNodePtrArray m_children;
+};
+
+
+// ----------------------------------------------------------------------------
+// MyMusicTreeModel
+// ----------------------------------------------------------------------------
+
+/*
+Implement this data model
+ Title Artist Year Judgement
+--------------------------------------------------------------------------
+1: My Music:
+ 2: Pop music
+ 3: You are not alone Michael Jackson 1995 good
+ 4: Take a bow Madonna 1994 good
+ 5: Classical music
+ 6: Ninth Symphony Ludwig v. Beethoven 1824 good
+ 7: German Requiem Johannes Brahms 1868 good
+*/
+
+class MyMusicTreeModel: public wxDataViewModel
+{
+public:
+ MyMusicTreeModel();
+ ~MyMusicTreeModel()
+ {
+ delete m_root;
+ }
+
+ // helper method for wxLog
+
+ wxString GetTitle( const wxDataViewItem &item ) const;
+ wxString GetArtist( const wxDataViewItem &item ) const;
+ int GetYear( const wxDataViewItem &item ) const;
+
+ // helper methods to change the model
+
+ void AddToClassical( const wxString &title, const wxString &artist,
+ unsigned int year );
+ void Delete( const wxDataViewItem &item );
+
+ wxDataViewItem GetNinthItem() const
+ {
+ return wxDataViewItem( m_ninth );
+ }
+
+ // override sorting to always sort branches ascendingly
+
+ int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
+ unsigned int column, bool ascending ) const;
+
+ // implementation of base class virtuals to define model
+
+ virtual unsigned int GetColumnCount() const
+ {
+ return 6;
+ }
+
+ virtual wxString GetColumnType( unsigned int col ) const
+ {
+ if (col == 2)
+ return wxT("long");
+
+ return wxT("string");
+ }
+
+ virtual void GetValue( wxVariant &variant,
+ const wxDataViewItem &item, unsigned int col ) const;
+ virtual bool SetValue( const wxVariant &variant,
+ const wxDataViewItem &item, unsigned int col );
+
+ virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const;
+ virtual bool IsContainer( const wxDataViewItem &item ) const;
+ virtual unsigned int GetChildren( const wxDataViewItem &parent,
+ wxDataViewItemArray &array ) const;
+
+private:
+ MyMusicTreeModelNode* m_root;
+
+ // pointers to some "special" nodes of the tree:
+ MyMusicTreeModelNode* m_pop;
+ MyMusicTreeModelNode* m_classical;
+ MyMusicTreeModelNode* m_ninth;
+
+ // ??
+ bool m_classicalMusicIsKnownToControl;
+};
+
+
+// ----------------------------------------------------------------------------
+// MyListModel
+// ----------------------------------------------------------------------------
+
+class MyListModel: public wxDataViewVirtualListModel
+{
+public:
+ MyListModel();
+
+ // helper methods to change the model
+
+ void Prepend( const wxString &text );
+ void DeleteItem( const wxDataViewItem &item );
+ void DeleteItems( const wxDataViewItemArray &items );
+ void AddMany();
+
+
+ // implementation of base class virtuals to define model
+
+ virtual unsigned int GetColumnCount() const
+ {
+ return 3;
+ }
+
+ virtual wxString GetColumnType( unsigned int col ) const
+ {
+ if (col == 1)
+ return wxT("wxDataViewIconText");
+
+ return wxT("string");
+ }
+
+ virtual unsigned int GetRowCount()
+ {
+ return m_textColValues.GetCount();
+ }
+
+ virtual void GetValueByRow( wxVariant &variant,
+ unsigned int row, unsigned int col ) const;
+ virtual bool GetAttrByRow( unsigned int row, unsigned int col, wxDataViewItemAttr &attr );
+ virtual bool SetValueByRow( const wxVariant &variant,
+ unsigned int row, unsigned int col );
+
+private:
+ wxArrayString m_textColValues;
+ wxArrayString m_iconColValues;
+ wxIcon m_icon[2];
+ int m_virtualItems;
+};
+