#endif
#ifndef WX_PRECOMP
-#include "wx/wx.h"
+ #include "wx/wx.h"
#endif
+#include "wx/datetime.h"
+
#ifndef __WXMSW__
-#include "mondrian.xpm"
+ #include "../sample.xpm"
#endif
#include "wx/dataview.h"
class MyTextModel: public wxDataViewListModel
{
public:
- MyTextModel()
+ MyTextModel()
{
size_t i;
for (i = 0; i < 1000; i++)
for (i = 0; i < 1000; i++)
{ m_progress.Add( i/10 ); }
for (i = 0; i < 1000; i++)
- {
+ {
wxDateTime *date = new wxDateTime( wxDateTime::Now() );
- m_dates.Append( date );
+ m_dates.Append( date );
}
}
-
- virtual size_t GetNumberOfRows()
+
+ virtual size_t GetNumberOfRows()
{ return 1000; }
virtual size_t GetNumberOfCols()
{ return 7; }
-
+
// as reported by wxVariant
virtual wxString GetColType( size_t col )
{
if (col == 6)
return wxT("datetime");
-
+
if (col == 5)
return wxT("long");
-
+
if (col == 3)
return wxT("bool");
-
- return wxT("string");
+
+ return wxT("string");
}
-
+
virtual void GetValue( wxVariant &variant, size_t col, size_t row )
{
if (col == 6)
if (col == 3)
{
variant = (bool) m_bools[row];
- } else
+ } else
if (col == 2)
{
variant = m_list[row];
}
else
{
- wxString tmp;
- tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col );
+ wxString tmp;
+ tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col );
variant = tmp;
}
}
}
return true;
}
-
+
wxArrayString m_list;
wxArrayInt m_bools;
wxArrayString m_colours;
{
public:
MyCustomCell() :
- wxDataViewCustomCell( wxT("string"), wxDATAVIEW_CELL_ACTIVATABLE )
- {
- m_colour = wxT("black");
+ wxDataViewCustomCell( wxT("string"), wxDATAVIEW_CELL_ACTIVATABLE )
+ {
+ m_colour = wxT("black");
}
bool SetValue( const wxVariant &value )
{
m_colour = value.GetString();
return true;
}
- bool Render( wxRect rect, wxDC *dc, int state )
- {
+ bool Render( wxRect rect, wxDC *dc, int WXUNUSED(state) )
+ {
dc->SetPen( *wxBLACK_PEN );
if (m_colour == wxT("red"))
dc->SetBrush( *wxRED_BRUSH );
else if (m_colour == wxT("green"))
dc->SetBrush( *wxGREEN_BRUSH );
- else
+ else
dc->SetBrush( *wxBLACK_BRUSH );
dc->DrawRectangle( rect );
return true;
{
return wxSize(20,8);
}
- bool Activate( wxRect rect,
- wxDataViewListModel *model, size_t col, size_t row )
+ bool Activate( wxRect WXUNUSED(rect),
+ wxDataViewListModel *WXUNUSED(model),
+ size_t WXUNUSED(col),
+ size_t WXUNUSED(row) )
{
return false;
}
private:
- wxString m_colour;
+ wxString m_colour;
};
// -------------------------------------
virtual size_t GetNumberOfRows() { return m_list.GetCount(); }
virtual size_t GetNumberOfCols() { return 2; }
- virtual wxString GetColType( size_t col ) { return wxT("string"); }
+ virtual wxString GetColType( size_t WXUNUSED(col) ) { return wxT("string"); }
virtual void GetValue( wxVariant &variant, size_t col, size_t row )
{
if (col == 0)
return;
}
wxString tmp;
- tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col );
+ tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col );
variant = tmp;
}
virtual bool SetValue( wxVariant &variant, size_t col, size_t row )
return true;
}
return false;
-
+
}
wxArrayString m_list;
public:
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
-
+
private:
wxDataViewCtrl* dataview_left;
wxDataViewCtrl* dataview_right;
ID_INSERT_ROW_LEFT,
ID_DELETE_ROW_LEFT,
ID_EDIT_ROW_LEFT,
-
+
ID_APPEND_ROW_RIGHT,
ID_PREPEND_ROW_RIGHT,
ID_INSERT_ROW_RIGHT,
public:
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
-
+
void OnAppendRowLeft(wxCommandEvent& event);
void OnPrependRowLeft(wxCommandEvent& event);
void OnInsertRowLeft(wxCommandEvent& event);
void OnDeleteRowLeft(wxCommandEvent& event);
void OnEditRowLeft(wxCommandEvent& event);
-
+
void OnAppendRowRight(wxCommandEvent& event);
void OnPrependRowRight(wxCommandEvent& event);
void OnInsertRowRight(wxCommandEvent& event);
void OnDeleteRowRight(wxCommandEvent& event);
void OnEditRowRight(wxCommandEvent& event);
-
+
private:
wxDataViewCtrl* dataview_left;
wxDataViewCtrl* dataview_right;
-
+
DECLARE_EVENT_TABLE()
};
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))
{
-#ifdef __WXMSW__
- SetIcon(wxIcon(_T("mondrian")));
-#else
- SetIcon(wxIcon(mondrian_xpm));
-#endif
+ SetIcon(wxICON(sample));
wxMenu *file_menu = new wxMenu;
wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MyFrame::OnAbout) );
CreateStatusBar();
-
-
+
+ wxPanel *panel = new wxPanel( this, wxID_ANY );
+
+
// Left wxDataViewCtrl
- dataview_left = new wxDataViewCtrl( this, -1 );
-
+ dataview_left = new wxDataViewCtrl( panel, wxID_ANY );
+
MyTextModel *model = new MyTextModel;
dataview_left->AssociateModel( model );
-
+
dataview_left->AppendTextColumn( wxT("first"), 0 );
dataview_left->AppendTextColumn( wxT("second"), 1 );
wxDataViewTextCell *text_cell = new wxDataViewTextCell( wxT("string"), wxDATAVIEW_CELL_EDITABLE );
wxDataViewColumn *column = new wxDataViewColumn( wxT("editable"), text_cell, 2 );
dataview_left->AppendColumn( column );
-
+
dataview_left->AppendToggleColumn( wxT("fourth"), 3 );
-
+
MyCustomCell *custom_cell = new MyCustomCell;
column = new wxDataViewColumn( wxT("custom"), custom_cell, 4 );
dataview_left->AppendColumn( column );
-
+
dataview_left->AppendProgressColumn( wxT("progress"), 5 );
-
+
dataview_left->AppendDateColumn( wxT("date"), 6 );
-
+
// Right wxDataViewCtrl using the same model
- dataview_right = new wxDataViewCtrl( this, -1 );
+ dataview_right = new wxDataViewCtrl( panel, wxID_ANY );
dataview_right->AssociateModel( model );
text_cell = new wxDataViewTextCell( wxT("string"), wxDATAVIEW_CELL_EDITABLE );
dataview_right->AppendTextColumn( wxT("first"), 0 );
dataview_right->AppendTextColumn( wxT("second"), 1 );
wxDataViewToggleCell *toggle_cell = new wxDataViewToggleCell( wxT("bool"), wxDATAVIEW_CELL_ACTIVATABLE );
- column = new wxDataViewColumn( wxT("bool"), toggle_cell, 3 );
+ column = new wxDataViewColumn( wxT("bool"), toggle_cell, 3, 30 );
dataview_right->AppendColumn( column );
dataview_right->AppendDateColumn( wxT("date"), 6 );
-
+
// layout dataview controls.
-
+
wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
sizer->Add( dataview_left, 3, wxGROW );
sizer->Add(10,10);
sizer->Add( dataview_right, 2, wxGROW );
- SetSizer( sizer );
+ panel->SetSizer( sizer );
}
void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event) )
MySortingFrame::MySortingFrame(wxFrame *frame, wxChar *title, int x, int y, int w, int h):
wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
{
-#ifdef __WXMSW__
- SetIcon(wxIcon(_T("mondrian")));
-#else
- SetIcon(wxIcon(mondrian_xpm));
-#endif
+ SetIcon(wxICON(sample));
wxMenu *file_menu = new wxMenu;
wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MySortingFrame::OnAbout) );
CreateStatusBar();
-
-
+
+
// Left wxDataViewCtrl
- dataview_left = new wxDataViewCtrl( this, -1 );
+ dataview_left = new wxDataViewCtrl( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxDV_MULTIPLE );
MyUnsortedTextModel *model = new MyUnsortedTextModel;
dataview_left->AssociateModel( model );
wxDataViewColumn *column = new wxDataViewColumn( wxT("editable"), text_cell, 0 );
dataview_left->AppendColumn( column );
dataview_left->AppendTextColumn( wxT("second"), 1 );
-
+
// Right wxDataViewCtrl using the sorting model
- dataview_right = new wxDataViewCtrl( this, -1 );
- wxDataViewSortedListModel *sorted_model =
+ dataview_right = new wxDataViewCtrl( this, wxID_ANY );
+ wxDataViewSortedListModel *sorted_model =
new wxDataViewSortedListModel( model );
dataview_right->AssociateModel( sorted_model );
text_cell = new wxDataViewTextCell( wxT("string"), wxDATAVIEW_CELL_EDITABLE );
dataview_right->AppendTextColumn( wxT("second"), 1 );
// layout dataview controls.
-
+
wxBoxSizer *top_sizer = new wxBoxSizer( wxHORIZONTAL );
top_sizer->Add( dataview_left, 1, wxGROW );
top_sizer->Add(10,10);
top_sizer->Add( dataview_right, 1, wxGROW );
-
+
wxBoxSizer *button_sizer = new wxBoxSizer( wxHORIZONTAL );
button_sizer->Add( 10, 10, 1 );
wxFlexGridSizer *left_sizer = new wxFlexGridSizer( 2 );
right_sizer->Add( new wxButton( this, ID_EDIT_ROW_RIGHT, wxT("Edit") ), 0, wxALL, 5 );
button_sizer->Add( right_sizer );
button_sizer->Add( 10, 10, 1 );
-
+
wxBoxSizer *main_sizer = new wxBoxSizer( wxVERTICAL );
main_sizer->Add( top_sizer, 1, wxGROW );
main_sizer->Add( button_sizer, 0, wxGROW );
-
+
SetSizer( main_sizer );
}
dialog.ShowModal();
}
-void MySortingFrame::OnAppendRowLeft(wxCommandEvent& event)
+void MySortingFrame::OnAppendRowLeft(wxCommandEvent& WXUNUSED(event))
{
}
-void MySortingFrame::OnPrependRowLeft(wxCommandEvent& event)
+void MySortingFrame::OnPrependRowLeft(wxCommandEvent& WXUNUSED(event))
{
}
-void MySortingFrame::OnInsertRowLeft(wxCommandEvent& event)
+void MySortingFrame::OnInsertRowLeft(wxCommandEvent& WXUNUSED(event))
{
}
-void MySortingFrame::OnDeleteRowLeft(wxCommandEvent& event)
+void MySortingFrame::OnDeleteRowLeft(wxCommandEvent& WXUNUSED(event))
{
}
-void MySortingFrame::OnEditRowLeft(wxCommandEvent& event)
+void MySortingFrame::OnEditRowLeft(wxCommandEvent& WXUNUSED(event))
{
}
-void MySortingFrame::OnAppendRowRight(wxCommandEvent& event)
+void MySortingFrame::OnAppendRowRight(wxCommandEvent& WXUNUSED(event))
{
}
-void MySortingFrame::OnPrependRowRight(wxCommandEvent& event)
+void MySortingFrame::OnPrependRowRight(wxCommandEvent& WXUNUSED(event))
{
}
-void MySortingFrame::OnInsertRowRight(wxCommandEvent& event)
+void MySortingFrame::OnInsertRowRight(wxCommandEvent& WXUNUSED(event))
{
}
-void MySortingFrame::OnDeleteRowRight(wxCommandEvent& event)
+void MySortingFrame::OnDeleteRowRight(wxCommandEvent& WXUNUSED(event))
{
}
-void MySortingFrame::OnEditRowRight(wxCommandEvent& event)
+void MySortingFrame::OnEditRowRight(wxCommandEvent& WXUNUSED(event))
{
}