reorganize the sample splitting it in two source files and an additional header; most important: don't tile all the controls into the main frame: it becomes too big; rather use a notebook control to properly layout them

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59316 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Francesco Montorsi 2009-03-04 17:21:40 +00:00
parent d6e329cfbc
commit bf19b714f0
15 changed files with 959 additions and 716 deletions

View File

@ -51,6 +51,7 @@ DATAVIEW_CXXFLAGS = -D__WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p) \
DATAVIEW_OBJECTS = \
$(__dataview_os2_lib_res) \
dataview_dataview.o \
dataview_mymodels.o \
$(__dataview___win32rc)
### Conditionally set variables: ###
@ -183,6 +184,9 @@ dataview$(EXEEXT): $(DATAVIEW_OBJECTS) $(__dataview___win32rc)
dataview_dataview.o: $(srcdir)/dataview.cpp
$(CXXC) -c -o $@ $(DATAVIEW_CXXFLAGS) $(srcdir)/dataview.cpp
dataview_mymodels.o: $(srcdir)/mymodels.cpp
$(CXXC) -c -o $@ $(DATAVIEW_CXXFLAGS) $(srcdir)/mymodels.cpp
dataview_sample_rc.o: $(srcdir)/../sample.rc
$(WINDRES) -i$< -o$@ --define __WX$(TOOLKIT)__ $(__WXUNIV_DEFINE_p_2) $(__EXCEPTIONS_DEFINE_p_2) $(__RTTI_DEFINE_p_2) $(__THREAD_DEFINE_p_2) --include-dir $(srcdir) $(__DLLFLAG_p_2) --include-dir $(srcdir)/../../samples $(__RCDEFDIR_p_1) --include-dir $(top_srcdir)/include

View File

@ -4,7 +4,8 @@
<include file="../../build/bakefiles/common_samples.bkl"/>
<exe id="dataview" template="wx_sample" template_append="wx_append">
<sources>dataview.cpp</sources>
<sources>dataview.cpp mymodels.cpp</sources>
<headers>mymodels.h</headers>
<wx-lib>adv</wx-lib>
<wx-lib>core</wx-lib>
<wx-lib>base</wx-lib>

File diff suppressed because it is too large Load Diff

View File

@ -256,9 +256,21 @@ SOURCE=.\dataview.cpp
# End Source File
# Begin Source File
SOURCE=.\mymodels.cpp
# End Source File
# Begin Source File
SOURCE=.\..\sample.rc
# End Source File
# End Group
# Begin Group "Header Files"
# PROP Default_Filter ""
# Begin Source File
SOURCE=.\mymodels.h
# End Source File
# End Group
# End Target
# End Project

View File

@ -528,6 +528,17 @@
<File
RelativePath=".\dataview.cpp">
</File>
<File
RelativePath=".\mymodels.cpp">
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
<File
RelativePath=".\mymodels.h">
</File>
</Filter>
<Filter
Name="Resource Files"

View File

@ -791,6 +791,20 @@
RelativePath=".\dataview.cpp"
>
</File>
<File
RelativePath=".\mymodels.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\mymodels.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"

View File

@ -763,6 +763,20 @@
RelativePath=".\dataview.cpp"
>
</File>
<File
RelativePath=".\mymodels.cpp"
>
</File>
</Filter>
<Filter
Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File
RelativePath=".\mymodels.h"
>
</File>
</Filter>
<Filter
Name="Resource Files"

View File

@ -35,7 +35,8 @@ DATAVIEW_CXXFLAGS = $(__RUNTIME_LIBS_7) -I$(BCCDIR)\include $(__DEBUGINFO) \
$(__GFXCTX_DEFINE_p) -I$(SETUPHDIR) -I.\..\..\include -I. $(__DLLFLAG_p) \
-I.\..\..\samples -DNOPCH $(CPPFLAGS) $(CXXFLAGS)
DATAVIEW_OBJECTS = \
$(OBJS)\dataview_dataview.obj
$(OBJS)\dataview_dataview.obj \
$(OBJS)\dataview_mymodels.obj
### Conditionally set variables: ###
@ -240,6 +241,9 @@ $(OBJS)\dataview.exe: $(DATAVIEW_OBJECTS) $(OBJS)\dataview_sample.res
$(OBJS)\dataview_dataview.obj: .\dataview.cpp
$(CXX) -q -c -P -o$@ $(DATAVIEW_CXXFLAGS) .\dataview.cpp
$(OBJS)\dataview_mymodels.obj: .\mymodels.cpp
$(CXX) -q -c -P -o$@ $(DATAVIEW_CXXFLAGS) .\mymodels.cpp
$(OBJS)\dataview_sample.res: .\..\sample.rc
brcc32 -32 -r -fo$@ -i$(BCCDIR)\include -d__WXMSW__ $(__WXUNIV_DEFINE_p_1) $(__DEBUG_DEFINE_p_1) $(__EXCEPTIONS_DEFINE_p_1) $(__RTTI_DEFINE_p_1) $(__THREAD_DEFINE_p_1) $(__UNICODE_DEFINE_p_1) $(__MSLU_DEFINE_p_1) $(__GFXCTX_DEFINE_p_1) -i$(SETUPHDIR) -i.\..\..\include -i. $(__DLLFLAG_p_1) -i.\..\..\samples -dNOPCH .\..\sample.rc

View File

@ -29,6 +29,7 @@ DATAVIEW_CXXFLAGS = $(__DEBUGINFO) $(__OPTIMIZEFLAG_2) $(__THREADSFLAG) \
$(__EXCEPTIONSFLAG_6) -Wno-ctor-dtor-privacy $(CPPFLAGS) $(CXXFLAGS)
DATAVIEW_OBJECTS = \
$(OBJS)\dataview_dataview.o \
$(OBJS)\dataview_mymodels.o \
$(OBJS)\dataview_sample_rc.o
### Conditionally set variables: ###
@ -233,6 +234,9 @@ $(OBJS)\dataview.exe: $(DATAVIEW_OBJECTS) $(OBJS)\dataview_sample_rc.o
$(OBJS)\dataview_dataview.o: ./dataview.cpp
$(CXX) -c -o $@ $(DATAVIEW_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\dataview_mymodels.o: ./mymodels.cpp
$(CXX) -c -o $@ $(DATAVIEW_CXXFLAGS) $(CPPDEPS) $<
$(OBJS)\dataview_sample_rc.o: ./../sample.rc
windres --use-temp-file -i$< -o$@ --define __WXMSW__ $(__WXUNIV_DEFINE_p_1) $(__DEBUG_DEFINE_p_1) $(__EXCEPTIONS_DEFINE_p_1) $(__RTTI_DEFINE_p_1) $(__THREAD_DEFINE_p_1) $(__UNICODE_DEFINE_p_1) $(__MSLU_DEFINE_p_1) $(__GFXCTX_DEFINE_p_1) --include-dir $(SETUPHDIR) --include-dir ./../../include --include-dir . $(__DLLFLAG_p_1) --include-dir ./../../samples --define NOPCH

View File

@ -57,7 +57,8 @@ WX_CONFIG_FLAGS = $(WX_CONFIG_DEBUG_FLAG) $(WX_CONFIG_UNICODE_FLAG) \
DATAVIEW_CXXFLAGS = -I. `$(WX_CONFIG) --cxxflags $(WX_CONFIG_FLAGS)` $(CPPFLAGS) \
$(CXXFLAGS)
DATAVIEW_OBJECTS = \
dataview_dataview.o
dataview_dataview.o \
dataview_mymodels.o
### Conditionally set variables: ###
@ -98,11 +99,14 @@ test_for_selected_wxbuild:
@$(WX_CONFIG) $(WX_CONFIG_FLAGS)
dataview: $(DATAVIEW_OBJECTS)
$(CXX) -o $@ $(DATAVIEW_OBJECTS) `$(WX_CONFIG) $(WX_CONFIG_FLAGS) --libs adv,core,base` $(LDFLAGS)
$(CXX) -o $@ $(DATAVIEW_OBJECTS) $(LDFLAGS) `$(WX_CONFIG) $(WX_CONFIG_FLAGS) --libs adv,core,base`
dataview_dataview.o: ./dataview.cpp
$(CXX) -c -o $@ $(DATAVIEW_CXXFLAGS) $(CPPDEPS) $<
dataview_mymodels.o: ./mymodels.cpp
$(CXX) -c -o $@ $(DATAVIEW_CXXFLAGS) $(CPPDEPS) $<
.PHONY: all install uninstall clean

View File

@ -30,6 +30,7 @@ DATAVIEW_CXXFLAGS = /M$(__RUNTIME_LIBS_8)$(__DEBUGRUNTIME_3) /DWIN32 \
$(CPPFLAGS) $(CXXFLAGS)
DATAVIEW_OBJECTS = \
$(OBJS)\dataview_dataview.obj \
$(OBJS)\dataview_mymodels.obj \
$(OBJS)\dataview_sample.res
### Conditionally set variables: ###
@ -316,6 +317,9 @@ $(OBJS)\dataview.exe: $(DATAVIEW_OBJECTS) $(OBJS)\dataview_sample.res
$(OBJS)\dataview_dataview.obj: .\dataview.cpp
$(CXX) /c /nologo /TP /Fo$@ $(DATAVIEW_CXXFLAGS) .\dataview.cpp
$(OBJS)\dataview_mymodels.obj: .\mymodels.cpp
$(CXX) /c /nologo /TP /Fo$@ $(DATAVIEW_CXXFLAGS) .\mymodels.cpp
$(OBJS)\dataview_sample.res: .\..\sample.rc
rc /fo$@ /d WIN32 $(____DEBUGRUNTIME_2_p_1) $(__NO_VC_CRTDBG_p_1) /d __WXMSW__ $(__WXUNIV_DEFINE_p_1) $(__DEBUG_DEFINE_p_1) $(__EXCEPTIONS_DEFINE_p_1) $(__RTTI_DEFINE_p_1) $(__THREAD_DEFINE_p_1) $(__UNICODE_DEFINE_p_1) $(__MSLU_DEFINE_p_1) $(__GFXCTX_DEFINE_p_1) /i $(SETUPHDIR) /i .\..\..\include /i . $(__DLLFLAG_p_1) /d _WINDOWS /i .\..\..\samples /d NOPCH .\..\sample.rc

View File

@ -232,7 +232,8 @@ DATAVIEW_CXXFLAGS = $(__DEBUGINFO_0) $(__OPTIMIZEFLAG_2) $(__THREADSFLAG_5) &
-i=.\..\..\samples -dNOPCH $(__RTTIFLAG_7) $(__EXCEPTIONSFLAG_8) $(CPPFLAGS) &
$(CXXFLAGS)
DATAVIEW_OBJECTS = &
$(OBJS)\dataview_dataview.obj
$(OBJS)\dataview_dataview.obj &
$(OBJS)\dataview_mymodels.obj
all : $(OBJS)
@ -266,6 +267,9 @@ $(OBJS)\dataview.exe : $(DATAVIEW_OBJECTS) $(OBJS)\dataview_sample.res
$(OBJS)\dataview_dataview.obj : .AUTODEPEND .\dataview.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(DATAVIEW_CXXFLAGS) $<
$(OBJS)\dataview_mymodels.obj : .AUTODEPEND .\mymodels.cpp
$(CXX) -bt=nt -zq -fo=$^@ $(DATAVIEW_CXXFLAGS) $<
$(OBJS)\dataview_sample.res : .AUTODEPEND .\..\sample.rc
wrc -q -ad -bt=nt -r -fo=$^@ -d__WXMSW__ $(__WXUNIV_DEFINE_p) $(__DEBUG_DEFINE_p) $(__EXCEPTIONS_DEFINE_p) $(__RTTI_DEFINE_p) $(__THREAD_DEFINE_p) $(__UNICODE_DEFINE_p) $(__GFXCTX_DEFINE_p) -i=$(SETUPHDIR) -i=.\..\..\include -i=. $(__DLLFLAG_p) -i=.\..\..\samples -dNOPCH $<

View File

@ -0,0 +1,382 @@
/////////////////////////////////////////////////////////////////////////////
// Name: mymodels.cpp
// 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
/////////////////////////////////////////////////////////////////////////////
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "wx/dataview.h"
#include "mymodels.h"
// ----------------------------------------------------------------------------
// resources
// ----------------------------------------------------------------------------
#include "null.xpm"
// ----------------------------------------------------------------------------
// MyMusicTreeModel
// ----------------------------------------------------------------------------
MyMusicTreeModel::MyMusicTreeModel()
{
m_root = new MyMusicTreeModelNode( NULL, wxT("My Music" ));
m_pop = new MyMusicTreeModelNode( m_root, wxT("Pop music") );
m_root->Append( m_pop );
m_pop->Append( new MyMusicTreeModelNode( m_pop,
wxT("You are not alone"), wxT("Michael Jackson"), 1995 ) );
m_pop->Append( new MyMusicTreeModelNode( m_pop,
wxT("Take a bow"), wxT("Madonna"), 1994 ) );
m_classical = new MyMusicTreeModelNode( m_root, wxT("Classical music") );
m_root->Append( m_classical );
m_ninth = new MyMusicTreeModelNode( m_classical,
wxT("Ninth symphony"), wxT("Ludwig van Beethoven"), 1824 );
m_classical->Append( m_ninth );
m_classical->Append( new MyMusicTreeModelNode( m_classical,
wxT("German Requiem"), wxT("Johannes Brahms"), 1868 ) );
m_classicalMusicIsKnownToControl = false;
}
wxString MyMusicTreeModel::GetTitle( const wxDataViewItem &item ) const
{
MyMusicTreeModelNode *node = (MyMusicTreeModelNode*) item.GetID();
if (!node)
return wxEmptyString;
return node->m_title;
}
int MyMusicTreeModel::GetYear( const wxDataViewItem &item ) const
{
MyMusicTreeModelNode *node = (MyMusicTreeModelNode*) item.GetID();
if (!node)
return 2000;
return node->m_year;
}
void MyMusicTreeModel::AddToClassical( const wxString &title, const wxString &artist, int year )
{
// add to data
MyMusicTreeModelNode *child_node =
new MyMusicTreeModelNode( m_classical, title, artist, year );
m_classical->Append( child_node );
if (m_classicalMusicIsKnownToControl)
{
// notify control
wxDataViewItem child( (void*) child_node );
wxDataViewItem parent( (void*) m_classical );
ItemAdded( parent, child );
}
}
void MyMusicTreeModel::Delete( const wxDataViewItem &item )
{
MyMusicTreeModelNode *node = (MyMusicTreeModelNode*) item.GetID();
wxDataViewItem parent( node->GetParent() );
node->GetParent()->GetChildren().Remove( node );
delete node;
// notify control
ItemDeleted( parent, item );
}
int MyMusicTreeModel::Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
unsigned int column, bool ascending )
{
if (IsContainer(item1) && IsContainer(item2))
{
wxVariant value1,value2;
GetValue( value1, item1, 0 );
GetValue( value2, item2, 0 );
wxString str1 = value1.GetString();
wxString str2 = value2.GetString();
int res = str1.Cmp( str2 );
if (res) return res;
// items must be different
wxUIntPtr litem1 = (wxUIntPtr) item1.GetID();
wxUIntPtr litem2 = (wxUIntPtr) item2.GetID();
return litem1-litem2;
}
return wxDataViewModel::Compare( item1, item2, column, ascending );
}
void MyMusicTreeModel::GetValue( wxVariant &variant,
const wxDataViewItem &item, unsigned int col ) const
{
MyMusicTreeModelNode *node = (MyMusicTreeModelNode*) item.GetID();
switch (col)
{
case 0: variant = node->m_title; break;
case 1: variant = node->m_artist; break;
case 2: variant = (long) node->m_year; break;
case 3: variant = node->m_quality; break;
case 4:
// wxMac doesn't conceal the popularity progress renderer, return 0 for containers
if (IsContainer(item))
variant = (long) 0;
else
variant = (long) 80; // all music is very 80% popular
break;
case 5:
// Make size of red square depend on year
if (GetYear(item) < 1900)
variant = (long) 35;
else
variant = (long) 25;
break;
default:
{
wxLogError( wxT("MyMusicTreeModel::GetValue: wrong column %d"), col );
// provoke a crash when mouse button down
wxMouseState state = wxGetMouseState();
if (state.ShiftDown())
{
char *crash = 0;
*crash = 0;
}
}
}
}
bool MyMusicTreeModel::SetValue( const wxVariant &variant,
const wxDataViewItem &item, unsigned int col )
{
MyMusicTreeModelNode *node = (MyMusicTreeModelNode*) item.GetID();
switch (col)
{
case 0: node->m_title = variant.GetString(); return true;
case 1: node->m_artist = variant.GetString(); return true;
case 2: node->m_year = variant.GetLong(); return true;
case 3: node->m_quality = variant.GetString(); return true;
default: wxLogError( wxT("MyMusicTreeModel::SetValue: wrong column") );
}
return false;
}
wxDataViewItem MyMusicTreeModel::GetParent( const wxDataViewItem &item ) const
{
// the invisble root node has no parent
if (!item.IsOk())
return wxDataViewItem(0);
MyMusicTreeModelNode *node = (MyMusicTreeModelNode*) item.GetID();
// "MyMusic" also has no parent
if (node == m_root)
return wxDataViewItem(0);
return wxDataViewItem( (void*) node->GetParent() );
}
bool MyMusicTreeModel::IsContainer( const wxDataViewItem &item ) const
{
// the invisble root node can have children (in
// our model always "MyMusic")
if (!item.IsOk())
return true;
MyMusicTreeModelNode *node = (MyMusicTreeModelNode*) item.GetID();
return node->IsContainer();
}
unsigned int MyMusicTreeModel::GetChildren( const wxDataViewItem &parent, wxDataViewItemArray &array ) const
{
MyMusicTreeModelNode *node = (MyMusicTreeModelNode*) parent.GetID();
if (!node)
{
array.Add( wxDataViewItem( (void*) m_root ) );
return 1;
}
if (node == m_classical)
{
MyMusicTreeModel *model = (MyMusicTreeModel*)(const MyMusicTreeModel*) this;
model->m_classicalMusicIsKnownToControl = true;
}
if (node->GetChildCount() == 0)
{
return 0;
}
unsigned int count = node->GetChildren().GetCount();
unsigned int pos;
for (pos = 0; pos < count; pos++)
{
MyMusicTreeModelNode *child = node->GetChildren().Item( pos );
array.Add( wxDataViewItem( (void*) child ) );
}
return count;
}
// ----------------------------------------------------------------------------
// MyListModel
// ----------------------------------------------------------------------------
static int my_sort_reverse( int *v1, int *v2 )
{
return *v2-*v1;
}
static int my_sort( int *v1, int *v2 )
{
return *v1-*v2;
}
MyListModel::MyListModel() :
#ifdef __WXMAC__
wxDataViewVirtualListModel( 1000 + 100 )
#else
wxDataViewVirtualListModel( 100000 + 100 )
#endif
{
#ifdef __WXMAC__
m_virtualItems = 1000;
#else
m_virtualItems = 100000;
#endif
unsigned int i;
for (i = 0; i < 100; i++)
{
wxString str;
str.Printf( wxT("row number %d"), i );
m_array.Add( str );
}
m_icon = wxIcon( null_xpm );
}
void MyListModel::Prepend( const wxString &text )
{
m_array.Insert( text, 0 );
RowPrepended();
}
void MyListModel::DeleteItem( const wxDataViewItem &item )
{
unsigned int row = GetRow( item );
if (row >= m_array.GetCount())
return;
m_array.RemoveAt( row );
RowDeleted( row );
}
void MyListModel::DeleteItems( const wxDataViewItemArray &items )
{
wxArrayInt rows;
unsigned int i;
for (i = 0; i < items.GetCount(); i++)
{
unsigned int row = GetRow( items[i] );
if (row < m_array.GetCount())
rows.Add( row );
}
// Sort in descending order so that the last
// row will be deleted first. Otherwise the
// remaining indeces would all be wrong.
rows.Sort( my_sort_reverse );
for (i = 0; i < rows.GetCount(); i++)
m_array.RemoveAt( rows[i] );
// This is just to test if wxDataViewCtrl can
// cope with removing rows not sorted in
// descending order
rows.Sort( my_sort );
RowsDeleted( rows );
}
void MyListModel::AddMany()
{
m_virtualItems += 1000;
Reset( m_array.GetCount() + m_virtualItems );
}
void MyListModel::GetValueByRow( wxVariant &variant,
unsigned int row, unsigned int col ) const
{
if (col==0)
{
if (row >= m_array.GetCount())
{
wxString str;
str.Printf(wxT("row %d"), row - m_array.GetCount() );
variant = str;
}
else
{
variant = m_array[ row ];
}
} else
if (col==1)
{
wxDataViewIconText data( wxT("test"), m_icon );
variant << data;
} else
if (col==2)
{
if (row >= m_array.GetCount())
variant = wxT("plain");
else
variant = wxT("blue");
}
}
bool MyListModel::GetAttrByRow( unsigned int row, unsigned int col, wxDataViewItemAttr &attr )
{
if (col != 2)
return false;
if (row < m_array.GetCount())
{
attr.SetColour( *wxBLUE );
attr.SetItalic( true );
}
return true;
}
bool MyListModel::SetValueByRow( const wxVariant &variant,
unsigned int row, unsigned int col )
{
if (col == 0)
{
if (row >= m_array.GetCount())
return false;
m_array[row] = variant.GetString();
return true;
}
return false;
}

199
samples/dataview/mymodels.h Normal file
View File

@ -0,0 +1,199 @@
/////////////////////////////////////////////////////////////////////////////
// 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
/////////////////////////////////////////////////////////////////////////////
// ----------------------------------------------------------------------------
// 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 MyMusicTreeModelNode;
WX_DEFINE_ARRAY_PTR( MyMusicTreeModelNode*, MyMusicTreeModelNodes );
class MyMusicTreeModelNode
{
public:
MyMusicTreeModelNode( MyMusicTreeModelNode* parent,
const wxString &title, const wxString &artist, int year )
{
m_parent = parent;
m_title = title;
m_artist = artist;
m_year = year;
m_quality = "good";
m_isContainer = false;
}
MyMusicTreeModelNode( MyMusicTreeModelNode* parent,
const wxString &branch )
{
m_parent = parent;
m_title = branch;
m_year = -1;
m_isContainer = true;
}
~MyMusicTreeModelNode()
{
size_t count = m_children.GetCount();
size_t i;
for (i = 0; i < count; i++)
{
MyMusicTreeModelNode *child = m_children[i];
delete child;
}
}
bool IsContainer() { return m_isContainer; }
MyMusicTreeModelNode* GetParent() { return m_parent; }
MyMusicTreeModelNodes &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() { return m_children.GetCount(); }
public:
wxString m_title;
wxString m_artist;
int m_year;
wxString m_quality;
private:
MyMusicTreeModelNode *m_parent;
MyMusicTreeModelNodes m_children;
bool m_isContainer;
};
class MyMusicTreeModel: public wxDataViewModel
{
public:
MyMusicTreeModel();
~MyMusicTreeModel()
{
delete m_root;
}
// helper method for wxLog
wxString GetTitle( const wxDataViewItem &item ) const;
int GetYear( const wxDataViewItem &item ) const;
// helper methods to change the model
void AddToClassical( const wxString &title, const wxString &artist, int year );
void Delete( const wxDataViewItem &item );
// override sorting to always sort branches ascendingly
int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
unsigned int column, bool ascending );
// 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;
wxDataViewItem GetNinthItem() const
{
return wxDataViewItem( m_ninth );
}
private:
MyMusicTreeModelNode* m_root;
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_array.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_array;
wxIcon m_icon;
int m_virtualItems;
};

View File

@ -0,0 +1,28 @@
/* XPM */
static const char *wx_small_xpm[] = {
/* columns rows colors chars-per-pixel */
"16 16 6 1",
". c Black",
"o c #FFFFFF",
"X c #000080",
"O c #FFFF00",
" c None",
"+ c #FF0000",
/* pixels */
" ",
" ",
" ",
" ....... ",
" .XXXXX. ",
" .oXXXX. ",
" .oXXX.......",
".....oXXX.OOOOO.",
".+++.XXXX.oOOOO.",
".o++......oOOOO.",
".o++++. .oOOOO.",
".o++++. .OOOOO.",
".+++++. .......",
"....... ",
" ",
" "
};