class MyMusicModelNode
{
public:
- MyMusicModelNode( MyMusicModelNode* parent, const wxUint32 id,
+ MyMusicModelNode( MyMusicModelNode* parent,
const wxString &title, const wxString &artist, const wxString &year )
{
m_parent = parent;
- m_id = id;
m_title = title;
m_artist = artist;
m_year = year;
m_isContainer = false;
}
- MyMusicModelNode( MyMusicModelNode* parent, const wxUint32 id,
+ MyMusicModelNode( MyMusicModelNode* parent,
const wxString &branch )
{
m_parent = parent;
- m_id = id;
m_title = branch;
m_isContainer = true;
}
}
}
- wxUint32 GetID() { return m_id; }
bool IsContainer() { return m_isContainer; }
MyMusicModelNode* GetParent() { return m_parent; }
private:
MyMusicModelNode *m_parent;
MyMusicModelNodes m_children;
- wxUint32 m_id;
bool m_isContainer;
};
MyMusicModel()
{
- m_idCounter = 0;
- m_root = new MyMusicModelNode( NULL, GetNewId(), "My Music" );
- m_pop = new MyMusicModelNode( m_root, GetNewId(), "Pop music" );
+ m_root = new MyMusicModelNode( NULL, "My Music" );
+ m_pop = new MyMusicModelNode( m_root, "Pop music" );
m_root->Append( m_pop );
- m_pop->Append( new MyMusicModelNode( m_pop, GetNewId(),
+ m_pop->Append( new MyMusicModelNode( m_pop,
"You are not alone", "Michael Jackson", "1995" ) );
- m_pop->Append( new MyMusicModelNode( m_pop, GetNewId(),
+ m_pop->Append( new MyMusicModelNode( m_pop,
"Take a bow", "Madonna", "1994" ) );
- m_classical = new MyMusicModelNode( m_root, GetNewId(), "Classical music" );
+ m_classical = new MyMusicModelNode( m_root, "Classical music" );
m_root->Append( m_classical );
- m_classical->Append( new MyMusicModelNode( m_classical, GetNewId(),
+ m_classical->Append( new MyMusicModelNode( m_classical,
"Ninth symphony", "Ludwig van Beethoven", "1824" ) );
- m_classical->Append( new MyMusicModelNode( m_classical, GetNewId(),
+ m_classical->Append( new MyMusicModelNode( m_classical,
"German Requiem", "Johannes Brahms", "1868" ) );
m_classicalMusicIsKnownToControl = false;
}
{
// add to data
MyMusicModelNode *child_node =
- new MyMusicModelNode( m_classical, GetNewId(), title, artist, year );
+ new MyMusicModelNode( m_classical, title, artist, year );
m_classical->Append( child_node );
if (m_classicalMusicIsKnownToControl)
{
// notify control
- wxDataViewItem child( child_node->GetID() );
- wxDataViewItem parent( m_classical->GetID() );
+ wxDataViewItem child( (void*) child_node );
+ wxDataViewItem parent( (void*) m_classical );
ItemAdded( parent, child );
}
}
void Delete( const wxDataViewItem &item )
{
- MyMusicModelNode *node = FindNode( item );
+ MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
node->GetParent()->GetChildren().Remove( node );
delete node;
virtual void GetValue( wxVariant &variant,
const wxDataViewItem &item, unsigned int col ) const
{
- MyMusicModelNode *node = FindNode( item );
+ MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
switch (col)
{
case 0: variant = node->m_title; break;
virtual bool SetValue( const wxVariant &variant,
const wxDataViewItem &item, unsigned int col )
{
- MyMusicModelNode *node = FindNode( item );
+ MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
switch (col)
{
case 0: node->m_title = variant.GetString(); break;
virtual bool HasChildren( const wxDataViewItem &item ) const
{
- if (item.GetID() == 0)
+ MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
+ if (!node)
return true;
- MyMusicModelNode *node = FindNode( item );
return node->IsContainer();
}
virtual wxDataViewItem GetFirstChild( const wxDataViewItem &parent ) const
{
- if (parent.GetID() == 0)
- return wxDataViewItem( m_root->GetID() );
+ MyMusicModelNode *node = (MyMusicModelNode*) parent.GetID();
+ if (!node)
+ return wxDataViewItem( (void*) m_root );
- MyMusicModelNode *node = FindNode( parent );
-
if (node->GetChildCount() == 0)
return wxDataViewItem( 0 );
}
MyMusicModelNode *first_child = node->GetChildren().Item( 0 );
- return wxDataViewItem( first_child->GetID() );
+ return wxDataViewItem( (void*) first_child );
}
virtual wxDataViewItem GetNextSibling( const wxDataViewItem &item ) const
{
- MyMusicModelNode *node = FindNode( item );
+ MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
MyMusicModelNode *parent = node->GetParent();
if (!parent)
return wxDataViewItem(0);
return wxDataViewItem(0);
node = parent->GetChildren().Item( pos+1 );
- return wxDataViewItem( node->GetID() );
+ return wxDataViewItem( (void*) node );
}
private:
- wxUint32 GetNewId() { m_idCounter++; return m_idCounter; }
-
- MyMusicModelNode *FindNodeRec( MyMusicModelNode *node, const wxDataViewItem &item ) const
- {
- if (node->GetID() == item.GetID())
- return node;
-
- size_t count = node->GetChildCount();
- size_t i;
- for (i = 0; i < count; i++)
- {
- MyMusicModelNode *child = node->GetChildren().Item( i );
- MyMusicModelNode *node2 = FindNodeRec( child, item );
- if (node2)
- return node2;
- }
- return NULL;
- }
-
- MyMusicModelNode *FindNode( const wxDataViewItem &item ) const
- {
- if (item.GetID() == 0)
- return NULL;
-
- if (!m_root)
- return NULL;
-
- return FindNodeRec( m_root, item );
- }
-
MyMusicModelNode* m_root;
MyMusicModelNode* m_pop;
MyMusicModelNode* m_classical;
bool m_classicalMusicIsKnownToControl;
- wxUint32 m_idCounter;
};
// -------------------------------------
m_dataview->AppendTextColumn( "Title", 0, wxDATAVIEW_CELL_INERT, 200,
DEFAULT_ALIGN, wxDATAVIEW_COL_SORTABLE );
- m_dataview->AppendTextColumn( "Artist", 1, wxDATAVIEW_CELL_INERT, 200,
+ m_dataview->AppendTextColumn( "Artist", 1, wxDATAVIEW_CELL_EDITABLE, 200,
DEFAULT_ALIGN, wxDATAVIEW_COL_SORTABLE );
m_dataview->AppendTextColumn( "Year", 2, wxDATAVIEW_CELL_INERT, 50,
DEFAULT_ALIGN );