2006-01-08 11:23:03 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: dataview.cpp
|
2007-02-23 02:57:46 -05:00
|
|
|
// Purpose: wxDataViewCtrl wxWidgets sample
|
2006-01-08 11:23:03 -05:00
|
|
|
// Author: Robert Roebling
|
2007-08-19 15:03:01 -04:00
|
|
|
// Modified by: Francesco Montorsi, Bo Yang
|
2006-01-08 11:23:03 -05:00
|
|
|
// 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
|
2006-07-20 07:57:15 -04:00
|
|
|
#include "wx/wx.h"
|
2006-01-08 11:23:03 -05:00
|
|
|
#endif
|
|
|
|
|
2006-03-23 16:28:24 -05:00
|
|
|
#include "wx/datetime.h"
|
2007-02-17 07:32:38 -05:00
|
|
|
#include "wx/splitter.h"
|
|
|
|
#include "wx/aboutdlg.h"
|
2007-02-23 02:57:46 -05:00
|
|
|
#include "wx/choicdlg.h"
|
|
|
|
#include "wx/numdlg.h"
|
|
|
|
#include "wx/dataview.h"
|
2007-04-17 08:08:10 -04:00
|
|
|
#include "wx/spinctrl.h"
|
2006-03-23 16:28:24 -05:00
|
|
|
|
2006-01-08 11:23:03 -05:00
|
|
|
#ifndef __WXMSW__
|
2006-07-20 07:57:15 -04:00
|
|
|
#include "../sample.xpm"
|
2006-01-08 11:23:03 -05:00
|
|
|
#endif
|
|
|
|
|
2006-09-26 18:17:00 -04:00
|
|
|
#include "null.xpm"
|
|
|
|
|
2007-12-01 14:01:47 -05:00
|
|
|
/* XPM */
|
|
|
|
static const char *small1_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.",
|
|
|
|
".+++++. .......",
|
|
|
|
"....... ",
|
|
|
|
" ",
|
|
|
|
" "
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-02-23 02:57:46 -05:00
|
|
|
|
|
|
|
#define DEFAULT_ALIGN wxALIGN_LEFT
|
|
|
|
#define DATAVIEW_DEFAULT_STYLE (wxDV_MULTIPLE|wxDV_HORIZ_RULES|wxDV_VERT_RULES)
|
|
|
|
|
|
|
|
|
2006-02-21 12:31:36 -05:00
|
|
|
// -------------------------------------
|
2007-07-05 10:59:16 -04:00
|
|
|
// MyMusicModel
|
2006-02-21 12:31:36 -05:00
|
|
|
// -------------------------------------
|
2006-01-08 11:23:03 -05:00
|
|
|
|
2007-07-05 10:59:16 -04:00
|
|
|
/*
|
|
|
|
Implement this data model
|
|
|
|
Title Artist Year
|
|
|
|
-------------------------------------------------------------
|
|
|
|
1: My Music:
|
|
|
|
2: Pop music
|
|
|
|
3: You are not alone Michael Jackson 1995
|
|
|
|
4: Take a bow Madonna 1994
|
|
|
|
5: Classical music
|
|
|
|
6: Ninth Symphony Ludwig v. Beethoven 1824
|
|
|
|
7: German Requiem Johannes Brahms 1868
|
|
|
|
*/
|
2006-02-26 10:48:42 -05:00
|
|
|
|
2007-07-14 09:54:14 -04:00
|
|
|
|
|
|
|
|
|
|
|
class MyMusicModelNode;
|
|
|
|
WX_DEFINE_ARRAY_PTR( MyMusicModelNode*, MyMusicModelNodes );
|
|
|
|
|
|
|
|
class MyMusicModelNode
|
|
|
|
{
|
|
|
|
public:
|
2007-07-16 07:15:10 -04:00
|
|
|
MyMusicModelNode( MyMusicModelNode* parent,
|
2007-08-26 11:24:41 -04:00
|
|
|
const wxString &title, const wxString &artist, int year )
|
2007-07-14 09:54:14 -04:00
|
|
|
{
|
|
|
|
m_parent = parent;
|
|
|
|
m_title = title;
|
|
|
|
m_artist = artist;
|
|
|
|
m_year = year;
|
|
|
|
m_isContainer = false;
|
|
|
|
}
|
|
|
|
|
2007-07-16 07:15:10 -04:00
|
|
|
MyMusicModelNode( MyMusicModelNode* parent,
|
2007-07-14 09:54:14 -04:00
|
|
|
const wxString &branch )
|
|
|
|
{
|
|
|
|
m_parent = parent;
|
|
|
|
m_title = branch;
|
2007-08-26 11:24:41 -04:00
|
|
|
m_year = -1;
|
2007-07-14 09:54:14 -04:00
|
|
|
m_isContainer = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
~MyMusicModelNode()
|
|
|
|
{
|
|
|
|
size_t count = m_children.GetCount();
|
|
|
|
size_t i;
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
{
|
|
|
|
MyMusicModelNode *child = m_children[i];
|
|
|
|
delete child;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsContainer() { return m_isContainer; }
|
|
|
|
|
|
|
|
MyMusicModelNode* GetParent() { return m_parent; }
|
|
|
|
MyMusicModelNodes &GetChildren() { return m_children; }
|
|
|
|
MyMusicModelNode* GetNthChild( unsigned int n ) { return m_children.Item( n ); }
|
|
|
|
void Insert( MyMusicModelNode* child, unsigned int n) { m_children.Insert( child, n); }
|
|
|
|
void Append( MyMusicModelNode* child ) { m_children.Add( child ); }
|
|
|
|
unsigned int GetChildCount() { return m_children.GetCount(); }
|
|
|
|
|
|
|
|
public:
|
|
|
|
wxString m_title;
|
|
|
|
wxString m_artist;
|
2007-08-26 11:24:41 -04:00
|
|
|
int m_year;
|
2007-07-14 09:54:14 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
MyMusicModelNode *m_parent;
|
|
|
|
MyMusicModelNodes m_children;
|
|
|
|
bool m_isContainer;
|
|
|
|
};
|
|
|
|
|
2007-07-09 06:38:22 -04:00
|
|
|
|
2007-07-05 10:59:16 -04:00
|
|
|
class MyMusicModel: public wxDataViewModel
|
2006-01-08 11:23:03 -05:00
|
|
|
{
|
|
|
|
public:
|
2007-07-15 10:08:08 -04:00
|
|
|
|
|
|
|
// constructor
|
|
|
|
|
2007-07-14 09:54:14 -04:00
|
|
|
MyMusicModel()
|
|
|
|
{
|
2007-07-16 07:15:10 -04:00
|
|
|
m_root = new MyMusicModelNode( NULL, "My Music" );
|
|
|
|
m_pop = new MyMusicModelNode( m_root, "Pop music" );
|
2007-07-14 09:54:14 -04:00
|
|
|
m_root->Append( m_pop );
|
2007-07-16 07:15:10 -04:00
|
|
|
m_pop->Append( new MyMusicModelNode( m_pop,
|
2007-08-26 11:24:41 -04:00
|
|
|
"You are not alone", "Michael Jackson", 1995 ) );
|
2007-07-16 07:15:10 -04:00
|
|
|
m_pop->Append( new MyMusicModelNode( m_pop,
|
2007-08-26 11:24:41 -04:00
|
|
|
"Take a bow", "Madonna", 1994 ) );
|
2007-07-16 07:15:10 -04:00
|
|
|
m_classical = new MyMusicModelNode( m_root, "Classical music" );
|
2007-07-14 09:54:14 -04:00
|
|
|
m_root->Append( m_classical );
|
2007-07-16 07:15:10 -04:00
|
|
|
m_classical->Append( new MyMusicModelNode( m_classical,
|
2007-08-26 11:24:41 -04:00
|
|
|
"Ninth symphony", "Ludwig van Beethoven", 1824 ) );
|
2007-07-16 07:15:10 -04:00
|
|
|
m_classical->Append( new MyMusicModelNode( m_classical,
|
2007-08-26 11:24:41 -04:00
|
|
|
"German Requiem", "Johannes Brahms", 1868 ) );
|
2007-07-14 11:47:01 -04:00
|
|
|
m_classicalMusicIsKnownToControl = false;
|
2007-07-14 09:54:14 -04:00
|
|
|
}
|
|
|
|
|
2007-09-14 17:02:18 -04:00
|
|
|
// helper method for wxLog
|
|
|
|
|
|
|
|
wxString GetTitle( const wxDataViewItem &item )
|
|
|
|
{
|
|
|
|
MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
|
|
|
|
if (!node)
|
|
|
|
return wxEmptyString;
|
|
|
|
|
|
|
|
return node->m_title;
|
|
|
|
}
|
|
|
|
|
2007-07-15 10:08:08 -04:00
|
|
|
// helper methods to change the model
|
|
|
|
|
2007-08-26 11:24:41 -04:00
|
|
|
void AddToClassical( const wxString &title, const wxString &artist, int year )
|
2007-07-14 09:54:14 -04:00
|
|
|
{
|
|
|
|
// add to data
|
|
|
|
MyMusicModelNode *child_node =
|
2007-07-16 07:15:10 -04:00
|
|
|
new MyMusicModelNode( m_classical, title, artist, year );
|
2007-08-19 15:03:01 -04:00
|
|
|
|
2007-07-14 09:54:14 -04:00
|
|
|
m_classical->Append( child_node );
|
|
|
|
|
2007-07-14 11:47:01 -04:00
|
|
|
if (m_classicalMusicIsKnownToControl)
|
|
|
|
{
|
|
|
|
// notify control
|
2007-07-16 07:15:10 -04:00
|
|
|
wxDataViewItem child( (void*) child_node );
|
|
|
|
wxDataViewItem parent( (void*) m_classical );
|
2007-07-14 11:47:01 -04:00
|
|
|
ItemAdded( parent, child );
|
|
|
|
}
|
2007-07-14 09:54:14 -04:00
|
|
|
}
|
2007-07-15 10:08:08 -04:00
|
|
|
|
|
|
|
void Delete( const wxDataViewItem &item )
|
|
|
|
{
|
2007-07-16 07:15:10 -04:00
|
|
|
MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
|
2007-07-25 14:46:01 -04:00
|
|
|
wxDataViewItem parent( node->GetParent() );
|
2007-07-15 10:08:08 -04:00
|
|
|
|
2007-08-03 07:47:42 -04:00
|
|
|
node->GetParent()->GetChildren().Remove( node );
|
|
|
|
delete node;
|
2007-08-26 11:24:41 -04:00
|
|
|
|
|
|
|
// notify control
|
|
|
|
ItemDeleted( parent, item );
|
2007-07-15 10:08:08 -04:00
|
|
|
}
|
|
|
|
|
2007-07-19 10:03:43 -04:00
|
|
|
// override sorting to always sort branches ascendingly
|
|
|
|
|
2007-08-19 10:12:52 -04:00
|
|
|
int Compare( const wxDataViewItem &item1, const wxDataViewItem &item2,
|
|
|
|
unsigned int column, bool ascending )
|
2007-07-19 10:03:43 -04:00
|
|
|
{
|
2007-07-20 05:01:52 -04:00
|
|
|
if (IsContainer(item1) && IsContainer(item2))
|
2007-07-19 10:03:43 -04:00
|
|
|
{
|
|
|
|
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
|
|
|
|
unsigned long litem1 = (unsigned long) item1.GetID();
|
|
|
|
unsigned long litem2 = (unsigned long) item2.GetID();
|
|
|
|
|
|
|
|
return litem1-litem2;
|
|
|
|
}
|
|
|
|
|
2007-08-19 10:12:52 -04:00
|
|
|
return wxDataViewModel::Compare( item1, item2, column, ascending );
|
2007-07-19 10:03:43 -04:00
|
|
|
}
|
|
|
|
|
2007-07-15 10:08:08 -04:00
|
|
|
// implementation of base class virtuals to define model
|
2007-07-05 10:59:16 -04:00
|
|
|
|
|
|
|
virtual unsigned int GetColumnCount() const
|
2006-02-23 08:34:15 -05:00
|
|
|
{
|
2007-07-05 15:55:00 -04:00
|
|
|
return 3;
|
2006-02-23 08:34:15 -05:00
|
|
|
}
|
2006-03-23 16:28:24 -05:00
|
|
|
|
2007-02-23 02:57:46 -05:00
|
|
|
virtual wxString GetColumnType( unsigned int col ) const
|
2007-07-05 10:59:16 -04:00
|
|
|
{
|
2007-08-26 11:24:41 -04:00
|
|
|
if (col == 2)
|
|
|
|
return "long";
|
|
|
|
|
2007-07-05 10:59:16 -04:00
|
|
|
return "string";
|
|
|
|
}
|
2006-03-23 16:28:24 -05:00
|
|
|
|
2007-07-05 10:59:16 -04:00
|
|
|
virtual void GetValue( wxVariant &variant,
|
|
|
|
const wxDataViewItem &item, unsigned int col ) const
|
|
|
|
{
|
2007-07-16 07:15:10 -04:00
|
|
|
MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
|
2007-07-14 09:54:14 -04:00
|
|
|
switch (col)
|
2006-02-24 08:19:23 -05:00
|
|
|
{
|
2007-07-14 09:54:14 -04:00
|
|
|
case 0: variant = node->m_title; break;
|
|
|
|
case 1: variant = node->m_artist; break;
|
2007-08-26 11:24:41 -04:00
|
|
|
case 2: variant = (long) node->m_year; break;
|
2007-08-22 17:18:06 -04:00
|
|
|
default:
|
|
|
|
{
|
|
|
|
wxLogError( "MyMusicModel::GetValue: wrong column" );
|
2007-08-26 11:24:41 -04:00
|
|
|
|
|
|
|
// provoke a crash when mouse button down
|
2007-08-22 17:18:06 -04:00
|
|
|
wxMouseState state = wxGetMouseState();
|
|
|
|
if (state.ShiftDown())
|
|
|
|
{
|
|
|
|
char *crash = 0;
|
|
|
|
*crash = 0;
|
|
|
|
}
|
|
|
|
}
|
2006-02-23 08:34:15 -05:00
|
|
|
}
|
2006-02-24 13:19:55 -05:00
|
|
|
}
|
2007-02-23 02:57:46 -05:00
|
|
|
|
2007-07-05 10:59:16 -04:00
|
|
|
virtual bool SetValue( const wxVariant &variant,
|
|
|
|
const wxDataViewItem &item, unsigned int col )
|
2007-02-23 02:57:46 -05:00
|
|
|
{
|
2007-07-16 07:15:10 -04:00
|
|
|
MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
|
2007-07-14 09:54:14 -04:00
|
|
|
switch (col)
|
|
|
|
{
|
2007-08-29 16:09:28 -04:00
|
|
|
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;
|
2007-07-14 09:54:14 -04:00
|
|
|
default: wxLogError( "MyMusicModel::SetValue: wrong column" );
|
|
|
|
}
|
2007-08-29 16:09:28 -04:00
|
|
|
return false;
|
2007-02-23 02:57:46 -05:00
|
|
|
}
|
|
|
|
|
2007-07-20 05:01:52 -04:00
|
|
|
virtual wxDataViewItem GetParent( const wxDataViewItem &item ) const
|
2006-03-23 16:28:24 -05:00
|
|
|
{
|
2007-07-20 05:01:52 -04:00
|
|
|
// the invisble root node has no parent
|
|
|
|
if (!item.IsOk())
|
|
|
|
return wxDataViewItem(0);
|
|
|
|
|
2007-07-16 07:15:10 -04:00
|
|
|
MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
|
2007-07-20 05:01:52 -04:00
|
|
|
|
|
|
|
// "MyMusic" also has no parent
|
|
|
|
if (node == m_root)
|
|
|
|
return wxDataViewItem(0);
|
|
|
|
|
|
|
|
return wxDataViewItem( (void*) node->GetParent() );
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool IsContainer( const wxDataViewItem &item ) const
|
|
|
|
{
|
|
|
|
// the invisble root node can have children (in
|
|
|
|
// our model always "MyMusic")
|
|
|
|
if (!item.IsOk())
|
2007-07-14 09:54:14 -04:00
|
|
|
return true;
|
|
|
|
|
2007-07-20 05:01:52 -04:00
|
|
|
MyMusicModelNode *node = (MyMusicModelNode*) item.GetID();
|
2007-07-14 09:54:14 -04:00
|
|
|
return node->IsContainer();
|
2006-02-24 13:19:55 -05:00
|
|
|
}
|
2007-07-05 10:59:16 -04:00
|
|
|
|
2007-08-31 05:44:59 -04:00
|
|
|
virtual unsigned int GetChildren( const wxDataViewItem &parent, wxDataViewItemArray &array ) const
|
2007-04-17 08:08:10 -04:00
|
|
|
{
|
2007-07-16 07:15:10 -04:00
|
|
|
MyMusicModelNode *node = (MyMusicModelNode*) parent.GetID();
|
|
|
|
if (!node)
|
2007-08-31 05:44:59 -04:00
|
|
|
{
|
|
|
|
array.Add( wxDataViewItem( (void*) m_root ) );
|
|
|
|
return 1;
|
|
|
|
}
|
2007-07-14 09:54:14 -04:00
|
|
|
|
2007-07-14 11:47:01 -04:00
|
|
|
if (node == m_classical)
|
|
|
|
{
|
|
|
|
MyMusicModel *model = (MyMusicModel*)(const MyMusicModel*) this;
|
|
|
|
model->m_classicalMusicIsKnownToControl = true;
|
|
|
|
}
|
2007-04-17 08:08:10 -04:00
|
|
|
|
2007-08-31 05:44:59 -04:00
|
|
|
if (node->GetChildCount() == 0)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int count = node->GetChildren().GetCount();
|
|
|
|
unsigned int pos;
|
|
|
|
for (pos = 0; pos < count; pos++)
|
|
|
|
{
|
|
|
|
MyMusicModelNode *child = node->GetChildren().Item( pos );
|
|
|
|
array.Add( wxDataViewItem( (void*) child ) );
|
|
|
|
}
|
|
|
|
return count;
|
2007-02-23 02:57:46 -05:00
|
|
|
}
|
2007-07-14 09:54:14 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
MyMusicModelNode* m_root;
|
|
|
|
MyMusicModelNode* m_pop;
|
|
|
|
MyMusicModelNode* m_classical;
|
2007-07-14 11:47:01 -04:00
|
|
|
bool m_classicalMusicIsKnownToControl;
|
2006-02-28 16:41:13 -05:00
|
|
|
};
|
|
|
|
|
2007-07-21 19:07:03 -04:00
|
|
|
class MyListModel: public wxDataViewIndexListModel
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MyListModel() :
|
2007-12-01 14:01:47 -05:00
|
|
|
#ifdef __WXMAC__
|
|
|
|
wxDataViewIndexListModel( 1000 )
|
|
|
|
#else
|
|
|
|
wxDataViewIndexListModel( 100000 )
|
|
|
|
#endif
|
2007-07-21 19:07:03 -04:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
for (i = 0; i < 100; i++)
|
|
|
|
{
|
|
|
|
wxString str;
|
|
|
|
str.Printf( "row number %d", i );
|
|
|
|
m_array.Add( str );
|
|
|
|
}
|
2007-08-29 07:48:12 -04:00
|
|
|
|
|
|
|
m_icon = wxIcon( null_xpm );
|
2007-07-21 19:07:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// helper methods to change the model
|
|
|
|
|
|
|
|
void Prepend( const wxString &text )
|
|
|
|
{
|
|
|
|
m_array.Insert( text, 0 );
|
|
|
|
RowPrepended();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DeleteItem( const wxDataViewItem &item )
|
|
|
|
{
|
|
|
|
unsigned int row = GetRow( item );
|
|
|
|
m_array.RemoveAt( row );
|
|
|
|
RowDeleted( row );
|
|
|
|
}
|
|
|
|
|
|
|
|
// implementation of base class virtuals to define model
|
|
|
|
|
|
|
|
virtual unsigned int GetColumnCount() const
|
|
|
|
{
|
2007-08-29 07:48:12 -04:00
|
|
|
return 3;
|
2007-07-21 19:07:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual wxString GetColumnType( unsigned int col ) const
|
|
|
|
{
|
2007-08-29 07:48:12 -04:00
|
|
|
if (col == 1)
|
|
|
|
return "wxDataViewIconText";
|
|
|
|
|
2007-07-21 19:07:03 -04:00
|
|
|
return "string";
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual unsigned int GetRowCount()
|
|
|
|
{
|
|
|
|
return m_array.GetCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void GetValue( wxVariant &variant,
|
|
|
|
unsigned int row, unsigned int col ) const
|
|
|
|
{
|
|
|
|
if (col==0)
|
|
|
|
{
|
2007-12-01 14:01:47 -05:00
|
|
|
if (row >= m_array.GetCount())
|
|
|
|
{
|
|
|
|
wxString str;
|
|
|
|
str.Printf( "row %d", row );
|
|
|
|
variant = str;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
variant = m_array[ row ];
|
|
|
|
}
|
2007-08-29 07:48:12 -04:00
|
|
|
} else
|
|
|
|
if (col==1)
|
|
|
|
{
|
|
|
|
wxDataViewIconText data( "test", m_icon );
|
|
|
|
variant << data;
|
2007-11-08 17:51:58 -05:00
|
|
|
} else
|
|
|
|
if (col==2)
|
2007-07-21 19:07:03 -04:00
|
|
|
{
|
2007-11-08 17:51:58 -05:00
|
|
|
if ((row % 2) == 1)
|
|
|
|
variant = "Blue";
|
|
|
|
else
|
|
|
|
variant = "Italic";
|
2007-07-21 19:07:03 -04:00
|
|
|
}
|
|
|
|
}
|
2007-11-08 17:51:58 -05:00
|
|
|
|
|
|
|
virtual bool GetAttr( unsigned int row, unsigned int col, wxDataViewItemAttr &attr )
|
|
|
|
{
|
|
|
|
if (col != 2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if ((row % 2) == 1)
|
|
|
|
attr.SetColour( *wxBLUE );
|
|
|
|
else
|
|
|
|
attr.SetItalic( true );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2007-07-21 19:07:03 -04:00
|
|
|
|
|
|
|
virtual bool SetValue( const wxVariant &variant,
|
|
|
|
unsigned int row, unsigned int col )
|
|
|
|
{
|
|
|
|
if (col == 0)
|
|
|
|
{
|
2007-12-01 14:01:47 -05:00
|
|
|
if (row >= m_array.GetCount())
|
|
|
|
return false;
|
|
|
|
|
2007-07-21 19:07:03 -04:00
|
|
|
m_array[row] = variant.GetString();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxArrayString m_array;
|
2007-08-29 07:48:12 -04:00
|
|
|
wxIcon m_icon;
|
2007-07-21 19:07:03 -04:00
|
|
|
};
|
|
|
|
|
2006-02-21 12:31:36 -05:00
|
|
|
// -------------------------------------
|
|
|
|
// MyApp
|
|
|
|
// -------------------------------------
|
2006-01-08 11:23:03 -05:00
|
|
|
|
|
|
|
class MyApp: public wxApp
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool OnInit(void);
|
2007-02-17 07:32:38 -05:00
|
|
|
int OnExit();
|
2006-01-08 11:23:03 -05:00
|
|
|
};
|
|
|
|
|
2006-02-21 12:31:36 -05:00
|
|
|
// -------------------------------------
|
|
|
|
// MyFrame
|
|
|
|
// -------------------------------------
|
|
|
|
|
2007-02-17 07:32:38 -05:00
|
|
|
class MyFrame : public wxFrame
|
2006-01-08 11:23:03 -05:00
|
|
|
{
|
|
|
|
public:
|
2007-10-16 07:41:46 -04:00
|
|
|
MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int h);
|
2006-01-08 11:23:03 -05:00
|
|
|
|
|
|
|
public:
|
|
|
|
void OnQuit(wxCommandEvent& event);
|
|
|
|
void OnAbout(wxCommandEvent& event);
|
2007-07-21 19:07:03 -04:00
|
|
|
|
|
|
|
void OnAddMozart(wxCommandEvent& event);
|
|
|
|
void OnDeleteMusic(wxCommandEvent& event);
|
2007-10-18 16:56:38 -04:00
|
|
|
void OnDeleteYear(wxCommandEvent& event);
|
2007-07-21 19:07:03 -04:00
|
|
|
|
|
|
|
void OnPrependList(wxCommandEvent& event);
|
|
|
|
void OnDeleteList(wxCommandEvent& event);
|
2006-03-23 16:28:24 -05:00
|
|
|
|
2007-07-24 05:15:04 -04:00
|
|
|
void OnValueChanged( wxDataViewEvent &event );
|
2007-08-19 17:20:24 -04:00
|
|
|
|
2007-08-19 15:03:01 -04:00
|
|
|
void OnActivated( wxDataViewEvent &event );
|
2007-08-19 17:20:24 -04:00
|
|
|
void OnExpanding( wxDataViewEvent &event );
|
|
|
|
void OnExpanded( wxDataViewEvent &event );
|
|
|
|
void OnCollapsing( wxDataViewEvent &event );
|
|
|
|
void OnCollapsed( wxDataViewEvent &event );
|
2007-09-14 16:30:05 -04:00
|
|
|
void OnSelectionChanged( wxDataViewEvent &event );
|
2007-08-19 17:20:24 -04:00
|
|
|
|
2007-08-25 16:43:47 -04:00
|
|
|
void OnEditingStarted( wxDataViewEvent &event );
|
|
|
|
void OnEditingDone( wxDataViewEvent &event );
|
|
|
|
|
2007-08-19 15:03:01 -04:00
|
|
|
void OnHeaderClick( wxDataViewEvent &event );
|
|
|
|
void OnHeaderRightClick( wxDataViewEvent &event );
|
|
|
|
void OnSorted( wxDataViewEvent &event );
|
|
|
|
|
|
|
|
void OnRightClick( wxMouseEvent &event );
|
|
|
|
void OnGoto( wxCommandEvent &event);
|
2007-07-24 05:15:04 -04:00
|
|
|
|
2006-01-08 11:23:03 -05:00
|
|
|
private:
|
2007-07-21 19:07:03 -04:00
|
|
|
wxDataViewCtrl* m_musicCtrl;
|
|
|
|
wxObjectDataPtr<MyMusicModel> m_music_model;
|
|
|
|
|
|
|
|
wxDataViewCtrl* m_listCtrl;
|
|
|
|
wxObjectDataPtr<MyListModel> m_list_model;
|
2007-08-24 07:21:52 -04:00
|
|
|
|
|
|
|
wxDataViewColumn * m_col;
|
2007-07-21 19:07:03 -04:00
|
|
|
|
2007-07-14 09:54:14 -04:00
|
|
|
wxTextCtrl * m_log;
|
2007-08-19 15:03:01 -04:00
|
|
|
wxLog *m_logOld;
|
2006-10-06 05:50:45 -04:00
|
|
|
|
2006-02-28 16:41:13 -05:00
|
|
|
private:
|
2006-02-28 17:27:09 -05:00
|
|
|
DECLARE_EVENT_TABLE()
|
2006-02-28 16:41:13 -05:00
|
|
|
};
|
|
|
|
|
2006-02-21 12:31:36 -05:00
|
|
|
// -------------------------------------
|
|
|
|
// MyApp
|
|
|
|
// -------------------------------------
|
|
|
|
|
2007-02-17 07:32:38 -05:00
|
|
|
IMPLEMENT_APP(MyApp)
|
2006-01-08 11:23:03 -05:00
|
|
|
|
|
|
|
bool MyApp::OnInit(void)
|
|
|
|
{
|
2007-02-03 19:34:18 -05:00
|
|
|
if ( !wxApp::OnInit() )
|
|
|
|
return false;
|
|
|
|
|
2007-02-17 07:32:38 -05:00
|
|
|
// build the first frame
|
|
|
|
MyFrame *frame =
|
2007-08-26 11:24:41 -04:00
|
|
|
new MyFrame(NULL, wxT("wxDataViewCtrl feature test"), 40, 40, 800, 440);
|
2006-01-08 11:23:03 -05:00
|
|
|
frame->Show(true);
|
|
|
|
|
|
|
|
SetTopWindow(frame);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2007-02-17 07:32:38 -05:00
|
|
|
int MyApp::OnExit()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-08 11:23:03 -05:00
|
|
|
// -------------------------------------
|
|
|
|
// MyFrame
|
|
|
|
// -------------------------------------
|
|
|
|
|
2007-02-17 07:32:38 -05:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
// file menu
|
|
|
|
ID_ABOUT = wxID_ABOUT,
|
|
|
|
ID_EXIT = wxID_EXIT,
|
2007-07-14 09:54:14 -04:00
|
|
|
|
2007-07-24 05:15:04 -04:00
|
|
|
ID_MUSIC_CTRL = 50,
|
|
|
|
|
2007-07-21 19:07:03 -04:00
|
|
|
ID_ADD_MOZART = 100,
|
|
|
|
ID_DELETE_MUSIC = 101,
|
2007-10-18 16:56:38 -04:00
|
|
|
ID_DELETE_YEAR = 102,
|
2007-07-21 19:07:03 -04:00
|
|
|
|
|
|
|
ID_PREPEND_LIST = 200,
|
2007-08-19 15:03:01 -04:00
|
|
|
ID_DELETE_LIST = 201,
|
2007-08-26 11:24:41 -04:00
|
|
|
ID_GOTO = 202
|
2007-02-17 07:32:38 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
|
|
|
EVT_MENU( ID_ABOUT, MyFrame::OnAbout )
|
|
|
|
EVT_MENU( ID_EXIT, MyFrame::OnQuit )
|
2007-07-21 19:07:03 -04:00
|
|
|
EVT_BUTTON( ID_ADD_MOZART, MyFrame::OnAddMozart )
|
|
|
|
EVT_BUTTON( ID_DELETE_MUSIC, MyFrame::OnDeleteMusic )
|
2007-10-18 16:56:38 -04:00
|
|
|
EVT_BUTTON( ID_DELETE_YEAR, MyFrame::OnDeleteYear )
|
2007-07-21 19:07:03 -04:00
|
|
|
EVT_BUTTON( ID_PREPEND_LIST, MyFrame::OnPrependList )
|
|
|
|
EVT_BUTTON( ID_DELETE_LIST, MyFrame::OnDeleteList )
|
2007-08-19 15:03:01 -04:00
|
|
|
EVT_BUTTON( ID_GOTO, MyFrame::OnGoto)
|
2007-08-19 17:20:24 -04:00
|
|
|
|
2007-10-10 06:29:21 -04:00
|
|
|
EVT_DATAVIEW_ITEM_VALUE_CHANGED( ID_MUSIC_CTRL, MyFrame::OnValueChanged )
|
2007-08-19 17:20:24 -04:00
|
|
|
|
2007-08-19 15:03:01 -04:00
|
|
|
EVT_DATAVIEW_ITEM_ACTIVATED(ID_MUSIC_CTRL, MyFrame::OnActivated )
|
2007-08-19 17:20:24 -04:00
|
|
|
EVT_DATAVIEW_ITEM_EXPANDING(ID_MUSIC_CTRL, MyFrame::OnExpanding)
|
|
|
|
EVT_DATAVIEW_ITEM_EXPANDED(ID_MUSIC_CTRL, MyFrame::OnExpanded)
|
|
|
|
EVT_DATAVIEW_ITEM_COLLAPSING(ID_MUSIC_CTRL, MyFrame::OnCollapsing)
|
|
|
|
EVT_DATAVIEW_ITEM_COLLAPSED(ID_MUSIC_CTRL, MyFrame::OnCollapsed)
|
2007-09-14 16:30:05 -04:00
|
|
|
EVT_DATAVIEW_SELECTION_CHANGED(ID_MUSIC_CTRL, MyFrame::OnSelectionChanged)
|
2007-08-19 17:20:24 -04:00
|
|
|
|
2007-08-25 16:43:47 -04:00
|
|
|
EVT_DATAVIEW_ITEM_EDITING_STARTED(ID_MUSIC_CTRL, MyFrame::OnEditingStarted)
|
|
|
|
EVT_DATAVIEW_ITEM_EDITING_DONE(ID_MUSIC_CTRL, MyFrame::OnEditingDone)
|
|
|
|
|
2007-08-19 15:03:01 -04:00
|
|
|
EVT_DATAVIEW_COLUMN_HEADER_CLICK(ID_MUSIC_CTRL, MyFrame::OnHeaderClick)
|
|
|
|
EVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICKED(ID_MUSIC_CTRL, MyFrame::OnHeaderRightClick)
|
|
|
|
EVT_DATAVIEW_COLUMN_SORTED(ID_MUSIC_CTRL, MyFrame::OnSorted)
|
2007-08-19 17:20:24 -04:00
|
|
|
|
2007-08-19 15:03:01 -04:00
|
|
|
EVT_RIGHT_UP(MyFrame::OnRightClick)
|
2007-02-17 07:32:38 -05:00
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
2007-10-16 07:41:46 -04:00
|
|
|
MyFrame::MyFrame(wxFrame *frame, const wxString &title, int x, int y, int w, int h):
|
2006-01-08 11:23:03 -05:00
|
|
|
wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
|
|
|
|
{
|
2007-07-24 05:15:04 -04:00
|
|
|
m_log = NULL;
|
2007-08-24 07:21:52 -04:00
|
|
|
m_col = NULL;
|
2007-07-24 05:15:04 -04:00
|
|
|
|
2006-07-20 07:57:15 -04:00
|
|
|
SetIcon(wxICON(sample));
|
2006-01-08 11:23:03 -05:00
|
|
|
|
2007-02-17 07:32:38 -05:00
|
|
|
// build the menus:
|
|
|
|
|
2006-01-08 11:23:03 -05:00
|
|
|
wxMenu *file_menu = new wxMenu;
|
2007-07-05 10:59:16 -04:00
|
|
|
file_menu->Append(ID_ABOUT, "&About");
|
2007-02-17 07:32:38 -05:00
|
|
|
file_menu->AppendSeparator();
|
2007-07-05 10:59:16 -04:00
|
|
|
file_menu->Append(ID_EXIT, "E&xit");
|
2006-01-08 11:23:03 -05:00
|
|
|
|
|
|
|
wxMenuBar *menu_bar = new wxMenuBar;
|
2007-07-05 10:59:16 -04:00
|
|
|
menu_bar->Append(file_menu, "&File");
|
2007-02-17 07:32:38 -05:00
|
|
|
|
2006-01-08 11:23:03 -05:00
|
|
|
SetMenuBar(menu_bar);
|
2007-02-17 07:32:38 -05:00
|
|
|
CreateStatusBar();
|
2006-01-08 11:23:03 -05:00
|
|
|
|
2007-07-14 09:54:14 -04:00
|
|
|
wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
|
2007-07-21 19:07:03 -04:00
|
|
|
wxBoxSizer *data_sizer = new wxBoxSizer( wxHORIZONTAL );
|
2006-01-08 11:23:03 -05:00
|
|
|
|
2007-07-21 19:07:03 -04:00
|
|
|
// MyMusic
|
2006-03-23 16:28:24 -05:00
|
|
|
|
2007-07-24 05:15:04 -04:00
|
|
|
m_musicCtrl = new wxDataViewCtrl( this, ID_MUSIC_CTRL, wxDefaultPosition,
|
2007-08-19 15:03:01 -04:00
|
|
|
wxDefaultSize, wxDV_MULTIPLE );
|
2007-12-01 14:01:47 -05:00
|
|
|
|
2007-07-21 19:07:03 -04:00
|
|
|
m_music_model = new MyMusicModel;
|
|
|
|
m_musicCtrl->AssociateModel( m_music_model.get() );
|
|
|
|
|
2007-11-08 17:51:58 -05:00
|
|
|
/* wxDataViewColumn *col = */ m_musicCtrl->AppendTextColumn( "Title", 0, wxDATAVIEW_CELL_INERT, 200,
|
2007-07-09 14:29:05 -04:00
|
|
|
DEFAULT_ALIGN, wxDATAVIEW_COL_SORTABLE );
|
2007-08-22 17:18:06 -04:00
|
|
|
#if 0
|
|
|
|
// Call this and sorting is enabled
|
|
|
|
// immediatly upon start up.
|
|
|
|
col->SetSortOrder( true );
|
|
|
|
#endif
|
|
|
|
|
2007-08-26 11:24:41 -04:00
|
|
|
m_musicCtrl->AppendTextColumn( "Artist", 1, wxDATAVIEW_CELL_EDITABLE, 150,
|
2007-07-09 14:29:05 -04:00
|
|
|
DEFAULT_ALIGN, wxDATAVIEW_COL_SORTABLE );
|
2007-08-26 11:24:41 -04:00
|
|
|
|
2007-10-20 16:15:05 -04:00
|
|
|
wxDataViewSpinRenderer *sr = new wxDataViewSpinRenderer( 0, 2010 );
|
2007-08-26 11:24:41 -04:00
|
|
|
wxDataViewColumn *column = new wxDataViewColumn( "year", sr, 2, -1, wxALIGN_CENTRE, wxDATAVIEW_COL_SORTABLE );
|
|
|
|
m_musicCtrl->AppendColumn( column );
|
2007-07-14 09:54:14 -04:00
|
|
|
|
2007-07-21 19:07:03 -04:00
|
|
|
data_sizer->Add( m_musicCtrl, 3, wxGROW );
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
|
|
|
|
// MyList
|
|
|
|
|
|
|
|
m_listCtrl = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition,
|
2007-08-19 15:03:01 -04:00
|
|
|
wxDefaultSize, wxDV_MULTIPLE );
|
2007-07-21 19:07:03 -04:00
|
|
|
|
|
|
|
m_list_model = new MyListModel;
|
|
|
|
m_listCtrl->AssociateModel( m_list_model.get() );
|
|
|
|
|
|
|
|
m_listCtrl->AppendTextColumn( "editable string", 0, wxDATAVIEW_CELL_EDITABLE, 120 );
|
2007-08-31 05:14:49 -04:00
|
|
|
m_listCtrl->AppendIconTextColumn( "icon", 1, wxDATAVIEW_CELL_INERT, 60 );
|
2007-11-08 17:51:58 -05:00
|
|
|
|
|
|
|
wxDataViewTextRendererAttr *ra = new wxDataViewTextRendererAttr;
|
|
|
|
column = new wxDataViewColumn( "attributes", ra, 2 );
|
|
|
|
m_listCtrl->AppendColumn( column );
|
2007-07-21 19:07:03 -04:00
|
|
|
|
|
|
|
data_sizer->Add( m_listCtrl, 2, wxGROW );
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
main_sizer->Add( data_sizer, 2, wxGROW );
|
2007-07-14 09:54:14 -04:00
|
|
|
|
|
|
|
wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
|
|
|
|
|
2007-07-21 19:07:03 -04:00
|
|
|
button_sizer->Add( new wxButton( this, ID_ADD_MOZART, "Add Mozart"), 0, wxALL, 10 );
|
|
|
|
button_sizer->Add( new wxButton( this, ID_DELETE_MUSIC, "Delete selected"), 0, wxALL, 10 );
|
2007-10-18 16:56:38 -04:00
|
|
|
button_sizer->Add( new wxButton( this, ID_DELETE_YEAR, "Delete \"Year\" column"), 0, wxALL, 10 );
|
2007-07-21 19:07:03 -04:00
|
|
|
button_sizer->Add( 10, 10, 1 );
|
|
|
|
button_sizer->Add( new wxButton( this, ID_PREPEND_LIST, "Prepend"), 0, wxALL, 10 );
|
|
|
|
button_sizer->Add( new wxButton( this, ID_DELETE_LIST, "Delete selected"), 0, wxALL, 10 );
|
2007-08-19 15:03:01 -04:00
|
|
|
button_sizer->Add( new wxButton( this, ID_GOTO, "Goto 50"), 0, wxALL, 10 );
|
2007-07-14 09:54:14 -04:00
|
|
|
|
2007-07-21 19:07:03 -04:00
|
|
|
main_sizer->Add( button_sizer, 0, wxGROW, 0 );
|
2007-12-01 14:01:47 -05:00
|
|
|
|
|
|
|
wxBoxSizer *bottom_sizer = new wxBoxSizer( wxHORIZONTAL );
|
2007-07-14 09:54:14 -04:00
|
|
|
|
|
|
|
m_log = new wxTextCtrl( this, -1, "", wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE );
|
2007-08-19 15:03:01 -04:00
|
|
|
m_logOld = wxLog::SetActiveTarget(new wxLogTextCtrl(m_log));
|
|
|
|
wxLogMessage("This is the log window");
|
|
|
|
|
2007-12-01 14:01:47 -05:00
|
|
|
bottom_sizer->Add( m_log, 1, wxGROW );
|
|
|
|
|
|
|
|
// wxDataViewTreeStore
|
2007-10-16 07:41:46 -04:00
|
|
|
|
2007-12-01 14:01:47 -05:00
|
|
|
wxDataViewCtrl *treectrl = new wxDataViewCtrl( this, -1,
|
2007-10-16 07:41:46 -04:00
|
|
|
wxDefaultPosition, wxSize(300,200), wxDV_NO_HEADER );
|
|
|
|
|
|
|
|
wxDataViewTreeStore *store = new wxDataViewTreeStore;
|
|
|
|
wxDataViewItem parent = store->AppendContainer( wxDataViewItem(0), "Root 1", wxIcon(small1_xpm) );
|
2007-10-16 17:48:01 -04:00
|
|
|
wxDataViewItem child = store->AppendItem( parent, "Child 1", wxIcon(small1_xpm) );
|
|
|
|
child = store->AppendItem( parent, "Child 2", wxIcon(small1_xpm) );
|
|
|
|
child = store->AppendItem( parent, "Child 3", wxIcon(small1_xpm) );
|
2007-10-16 07:41:46 -04:00
|
|
|
treectrl->AssociateModel( store );
|
|
|
|
store->DecRef();
|
2007-10-18 11:07:11 -04:00
|
|
|
|
2007-10-23 17:11:48 -04:00
|
|
|
treectrl->AppendIconTextColumn( "no label", 0, wxDATAVIEW_CELL_INERT, 200 );
|
|
|
|
|
2007-12-01 14:01:47 -05:00
|
|
|
bottom_sizer->Add( treectrl );
|
2007-10-23 17:11:48 -04:00
|
|
|
|
2007-12-01 14:01:47 -05:00
|
|
|
// wxDataViewTreeCtrl
|
|
|
|
|
|
|
|
wxDataViewTreeCtrl *treectrl2 = new wxDataViewTreeCtrl( this, -1, wxDefaultPosition, wxSize(300,200) );
|
2007-12-01 15:43:02 -05:00
|
|
|
|
2007-12-01 14:01:47 -05:00
|
|
|
wxImageList *ilist = new wxImageList;
|
|
|
|
ilist->Add( wxIcon(small1_xpm) );
|
2007-12-01 15:43:02 -05:00
|
|
|
treectrl2->SetImageList( ilist );
|
|
|
|
|
2007-12-01 14:01:47 -05:00
|
|
|
parent = treectrl2->AppendContainer( wxDataViewItem(0), "Root 1", 0 );
|
|
|
|
child = treectrl2->AppendItem( parent, "Child 1", 0 );
|
|
|
|
child = treectrl2->AppendItem( parent, "Child 2", 0 );
|
|
|
|
child = treectrl2->AppendItem( parent, "Child 3", 0 );
|
|
|
|
|
|
|
|
bottom_sizer->Add( treectrl2 );
|
|
|
|
|
|
|
|
// main sizer
|
|
|
|
|
|
|
|
main_sizer->Add( bottom_sizer, 0, wxGROW );
|
2007-10-16 07:41:46 -04:00
|
|
|
|
2007-12-01 14:01:47 -05:00
|
|
|
SetSizer( main_sizer );
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
Close(true);
|
2007-10-16 07:41:46 -04:00
|
|
|
}
|
|
|
|
|
2007-07-21 19:07:03 -04:00
|
|
|
void MyFrame::OnAddMozart(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2007-08-26 11:24:41 -04:00
|
|
|
m_music_model->AddToClassical( "Kleine Nachtmusik", "Wolfgang Mozart", 1787 );
|
2007-07-21 19:07:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnDeleteMusic(wxCommandEvent& WXUNUSED(event) )
|
2007-07-14 09:54:14 -04:00
|
|
|
{
|
2007-08-19 15:03:01 -04:00
|
|
|
wxDataViewItemArray items;
|
|
|
|
int len = m_musicCtrl->GetSelections( items );
|
|
|
|
for( int i = 0; i < len; i ++ )
|
|
|
|
if (items[i].IsOk())
|
|
|
|
m_music_model->Delete( items[i] );
|
2007-07-15 10:08:08 -04:00
|
|
|
}
|
|
|
|
|
2007-10-18 16:56:38 -04:00
|
|
|
void MyFrame::OnDeleteYear( wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
|
|
|
m_musicCtrl->DeleteColumn( m_musicCtrl->GetColumn( 2 ) );
|
|
|
|
FindWindow( ID_DELETE_YEAR )->Disable();
|
|
|
|
}
|
|
|
|
|
2007-07-21 19:07:03 -04:00
|
|
|
void MyFrame::OnPrependList( wxCommandEvent& WXUNUSED(event) )
|
2007-07-15 10:08:08 -04:00
|
|
|
{
|
2007-07-21 19:07:03 -04:00
|
|
|
m_list_model->Prepend( "Test" );
|
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnDeleteList( wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2007-08-19 15:03:01 -04:00
|
|
|
wxDataViewItemArray items;
|
|
|
|
int len = m_listCtrl->GetSelections( items );
|
|
|
|
for( int i = 0; i < len; i ++ )
|
|
|
|
if (items[i].IsOk())
|
|
|
|
m_list_model->DeleteItem( items[i] );
|
2007-07-14 09:54:14 -04:00
|
|
|
}
|
|
|
|
|
2007-07-24 05:15:04 -04:00
|
|
|
void MyFrame::OnValueChanged( wxDataViewEvent &event )
|
|
|
|
{
|
|
|
|
if (!m_log)
|
|
|
|
return;
|
|
|
|
|
2007-10-10 06:29:21 -04:00
|
|
|
wxLogMessage( "EVT_DATAVIEW_ITEM_VALUE_CHANGED, Item Id: %d; Column: %d", event.GetItem().GetID(), event.GetColumn() );
|
2007-08-19 15:03:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnActivated( wxDataViewEvent &event )
|
|
|
|
{
|
|
|
|
if(!m_log)
|
|
|
|
return;
|
|
|
|
|
2007-09-14 17:02:18 -04:00
|
|
|
wxString title = m_music_model->GetTitle( event.GetItem() );
|
|
|
|
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_ACTIVATED, Item: %s", title );
|
2007-08-19 15:03:01 -04:00
|
|
|
}
|
|
|
|
|
2007-09-14 16:30:05 -04:00
|
|
|
void MyFrame::OnSelectionChanged( wxDataViewEvent &event )
|
2007-08-19 18:57:13 -04:00
|
|
|
{
|
|
|
|
if(!m_log)
|
|
|
|
return;
|
|
|
|
|
2007-09-14 17:02:18 -04:00
|
|
|
wxString title = m_music_model->GetTitle( event.GetItem() );
|
|
|
|
if (title.empty())
|
|
|
|
title = "None";
|
|
|
|
|
|
|
|
wxLogMessage("wxEVT_COMMAND_DATAVIEW_SELECTION_CHANGED, First selected Item: %s", title );
|
2007-08-19 18:57:13 -04:00
|
|
|
}
|
|
|
|
|
2007-08-19 17:20:24 -04:00
|
|
|
void MyFrame::OnExpanding( wxDataViewEvent &event )
|
|
|
|
{
|
|
|
|
if (!m_log)
|
|
|
|
return;
|
|
|
|
|
2007-09-14 17:02:18 -04:00
|
|
|
wxString title = m_music_model->GetTitle( event.GetItem() );
|
|
|
|
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDING, Item: %s", title );
|
2007-08-19 17:20:24 -04:00
|
|
|
}
|
|
|
|
|
2007-08-25 16:43:47 -04:00
|
|
|
|
|
|
|
void MyFrame::OnEditingStarted( wxDataViewEvent &event )
|
|
|
|
{
|
|
|
|
if (!m_log)
|
|
|
|
return;
|
|
|
|
|
2007-09-14 17:02:18 -04:00
|
|
|
wxString title = m_music_model->GetTitle( event.GetItem() );
|
|
|
|
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_STARTED, Item: %s", title );
|
2007-08-25 16:43:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnEditingDone( wxDataViewEvent &event )
|
|
|
|
{
|
|
|
|
if (!m_log)
|
|
|
|
return;
|
|
|
|
|
2007-09-14 17:02:18 -04:00
|
|
|
wxString title = m_music_model->GetTitle( event.GetItem() );
|
|
|
|
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_EDITING_DONE, Item: %s", title );
|
2007-08-25 16:43:47 -04:00
|
|
|
}
|
|
|
|
|
2007-08-19 17:20:24 -04:00
|
|
|
void MyFrame::OnExpanded( wxDataViewEvent &event )
|
|
|
|
{
|
|
|
|
if (!m_log)
|
|
|
|
return;
|
|
|
|
|
2007-09-14 17:02:18 -04:00
|
|
|
wxString title = m_music_model->GetTitle( event.GetItem() );
|
|
|
|
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_EXPANDED, Item: %s", title );
|
2007-08-19 17:20:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnCollapsing( wxDataViewEvent &event )
|
|
|
|
{
|
|
|
|
if (!m_log)
|
|
|
|
return;
|
|
|
|
|
2007-09-14 17:02:18 -04:00
|
|
|
wxString title = m_music_model->GetTitle( event.GetItem() );
|
|
|
|
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSING, Item: %s", title );
|
2007-08-19 17:20:24 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnCollapsed( wxDataViewEvent &event )
|
|
|
|
{
|
|
|
|
if (!m_log)
|
|
|
|
return;
|
2007-09-14 17:02:18 -04:00
|
|
|
|
|
|
|
wxString title = m_music_model->GetTitle( event.GetItem() );
|
|
|
|
wxLogMessage("wxEVT_COMMAND_DATAVIEW_ITEM_COLLAPSED, Item: %s", title );
|
2007-08-19 17:20:24 -04:00
|
|
|
}
|
|
|
|
|
2007-08-19 15:03:01 -04:00
|
|
|
void MyFrame::OnHeaderClick( wxDataViewEvent &event )
|
|
|
|
{
|
|
|
|
if(!m_log)
|
|
|
|
return;
|
2007-09-14 16:30:05 -04:00
|
|
|
|
|
|
|
int pos = m_musicCtrl->GetColumnPosition( event.GetDataViewColumn() );
|
2007-08-19 15:03:01 -04:00
|
|
|
|
2007-09-14 16:30:05 -04:00
|
|
|
wxLogMessage("wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_CLICK, Column position: %d", pos );
|
2007-08-19 15:03:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnHeaderRightClick( wxDataViewEvent &event )
|
|
|
|
{
|
|
|
|
if(!m_log)
|
|
|
|
return;
|
|
|
|
|
2007-09-14 16:36:19 -04:00
|
|
|
int pos = m_musicCtrl->GetColumnPosition( event.GetDataViewColumn() );
|
|
|
|
|
|
|
|
wxLogMessage("wxEVT_COMMAND_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, Column position: %d", pos );
|
2007-08-19 15:03:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnSorted( wxDataViewEvent &event )
|
|
|
|
{
|
|
|
|
if(!m_log)
|
|
|
|
return;
|
|
|
|
|
2007-09-14 17:02:18 -04:00
|
|
|
int pos = m_musicCtrl->GetColumnPosition( event.GetDataViewColumn() );
|
|
|
|
|
|
|
|
wxLogMessage("wxEVT_COMMAND_DATAVIEW_COLUMN_SORTED, Column position: %d", pos );
|
2007-08-19 15:03:01 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void MyFrame::OnRightClick( wxMouseEvent &event )
|
|
|
|
{
|
|
|
|
if(!m_log)
|
|
|
|
return;
|
|
|
|
|
|
|
|
wxLogMessage("wxEVT_MOUSE_RIGHT_UP, Click Point is X: %d, Y: %d", event.GetX(), event.GetY());
|
|
|
|
}
|
|
|
|
|
2007-10-23 19:02:39 -04:00
|
|
|
void MyFrame::OnGoto(wxCommandEvent& WXUNUSED(event))
|
2007-08-19 15:03:01 -04:00
|
|
|
{
|
2007-08-19 17:20:24 -04:00
|
|
|
wxDataViewItem item = m_list_model->GetItem( 50 );
|
2007-08-24 07:21:52 -04:00
|
|
|
m_listCtrl->EnsureVisible(item,m_col);
|
2007-07-24 05:15:04 -04:00
|
|
|
}
|
|
|
|
|
2006-01-08 11:23:03 -05:00
|
|
|
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event) )
|
|
|
|
{
|
2007-02-17 07:32:38 -05:00
|
|
|
wxAboutDialogInfo info;
|
|
|
|
info.SetName(_("DataView sample"));
|
|
|
|
info.SetDescription(_("This sample demonstrates the dataview control handling"));
|
|
|
|
info.SetCopyright(_T("(C) 2007 Robert Roebling"));
|
2006-01-08 11:23:03 -05:00
|
|
|
|
2007-02-17 07:32:38 -05:00
|
|
|
wxAboutBox(info);
|
2006-01-08 11:23:03 -05:00
|
|
|
}
|
|
|
|
|