#include "wx/choicdlg.h"
#include "wx/numdlg.h"
#include "wx/dataview.h"
+#include "wx/spinctrl.h"
#ifndef __WXMSW__
#include "../sample.xpm"
variant = tmp;
}
}
- virtual bool SetValue( wxVariant &value, unsigned int col, unsigned int row )
+ virtual bool SetValue( const wxVariant &value, unsigned int col, unsigned int row )
{
if (col == 6)
{
{
wxMessageDialog dlg( NULL, wxT("string too long") , wxT("Error") );
dlg.ShowModal();
- // Activate();
return false;
}
wxString m_colour;
};
+// -------------------------------------
+// MySpinCtrlInPlaceRenderer
+// -------------------------------------
+
+class MySpinCtrlInPlaceRenderer: public wxDataViewCustomRenderer
+{
+public:
+ MySpinCtrlInPlaceRenderer() :
+ wxDataViewCustomRenderer( wxT("long"), wxDATAVIEW_CELL_EDITABLE ) { }
+
+
+ virtual bool HasEditorCtrl()
+ {
+ return true;
+ }
+ virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
+ {
+ long l = value;
+ return new wxSpinCtrl( parent, wxID_ANY, wxEmptyString,
+ labelRect.GetTopLeft(), labelRect.GetSize(), 0, 0, 100, l );
+ }
+ virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value )
+ {
+ wxSpinCtrl *sc = (wxSpinCtrl*) editor;
+ long l = sc->GetValue();
+ value = l;
+ return true;
+ }
+
+ bool Render( wxRect rect, wxDC *dc, int WXUNUSED(state) )
+ {
+ wxString str;
+ str.Printf( wxT("%d"), (int) m_data );
+ dc->SetTextForeground( *wxBLACK );
+ dc->DrawText( str, rect.x, rect.y );
+ return true;
+ }
+ wxSize GetSize() const
+ {
+ return wxSize(80,16);
+ }
+ bool SetValue( const wxVariant &value )
+ {
+ m_data = value.GetLong();
+ return true;
+ }
+ bool GetValue( wxVariant &value ) const
+ {
+ value = m_data;
+ return true;
+ }
+
+
+private:
+ long m_data;
+};
+
// -------------------------------------
// MyUnsortedTextModel
// -------------------------------------
m_list.Add( wxT("of") );
m_list.Add( wxT("words.") );
+ m_ilist.Add( 0 );
+ m_ilist.Add( 1);
+ m_ilist.Add( 2 );
+ m_ilist.Add( 3 );
+ m_ilist.Add( 4 );
+ m_ilist.Add( 5 );
+ m_ilist.Add( 6 );
+
m_bitmap = wxBitmap( null_xpm );
}
virtual unsigned int GetColumnCount() const
{
- return 2;
+ return 4;
}
virtual wxString GetColumnType( unsigned int WXUNUSED(col) ) const
{
variant = m_list[row];
return;
- }
+ } else
if ((col == 2) || (col == 3))
{
variant << m_bitmap;
return;
+ } else
+ if (col == 4)
+ {
+ variant = (long) m_ilist[row];
+ return;
}
+
wxString tmp;
tmp.Printf( wxT("item(%d;%d)"), (int)row, (int)col );
variant = tmp;
}
- virtual bool SetValue( wxVariant &variant, unsigned int col, unsigned int row )
+ virtual bool SetValue( const wxVariant &variant, unsigned int col, unsigned int row )
{
if (col == 0)
{
m_list[row] = variant.GetString();
return true;
+ } else
+ if (col == 4)
+ {
+ m_ilist[row] = variant.GetLong();
+ return true;
}
return false;
void AppendRow( const wxString &text )
{
m_list.Add( text );
+ m_ilist.Add( 0 );
RowAppended();
}
void PrependRow( const wxString &text )
{
m_list.Insert( text, 0 );
+ m_ilist.Insert( 0, 0 );
RowPrepended();
}
void InsertRowAt1( const wxString &text )
{
m_list.Insert( text, 1 );
+ m_ilist.Insert( 0, 1 );
RowInserted( 1 );
}
void DeleteRow( unsigned int index )
{
m_list.RemoveAt( index );
+ m_ilist.RemoveAt( index );
RowDeleted( index );
}
wxArrayString m_list;
+ wxArrayInt m_ilist;
wxBitmap m_bitmap;
};
style |= wxDV_MULTIPLE;
if (GetMenuBar()->FindItem(ID_NO_HEADER_MODE)->IsChecked())
style |= wxDV_NO_HEADER;
+#if 0
if (GetMenuBar()->FindItem(ID_HORIZ_RULES_MODE)->IsChecked())
style |= wxDV_HORIZ_RULES;
if (GetMenuBar()->FindItem(ID_VERT_RULES_MODE)->IsChecked())
style |= wxDV_VERT_RULES;
+#endif
// Left wxDataViewCtrl
wxDefaultSize, style );
+ wxDataViewTextRenderer *text_renderer;
+ wxDataViewColumn *column;
+
wxObjectDataPtr<MyTextModel> model(new MyTextModel);
dataview_left->AssociateModel( model.get() );
dataview_left->AppendTextColumn( wxT("Second"), 1, wxDATAVIEW_CELL_INERT, -1,
DEFAULT_ALIGN );
- wxDataViewTextRenderer *text_renderer =
- new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_EDITABLE );
- wxDataViewColumn *column = new wxDataViewColumn( wxT("editable"), text_renderer, 2,
- -1, DEFAULT_ALIGN );
+ text_renderer = new wxDataViewTextRenderer( wxT("string"), wxDATAVIEW_CELL_EDITABLE );
+ column = new wxDataViewColumn( wxT("editable"), text_renderer, 2, -1, DEFAULT_ALIGN );
dataview_left->AppendColumn( column );
dataview_left->AppendToggleColumn( wxT("fourth"), 3, wxDATAVIEW_CELL_INERT, -1,
dataview_left->AppendDateColumn( wxT("date"), 6, wxDATAVIEW_CELL_INERT, -1, DEFAULT_ALIGN );
-
// Right wxDataViewCtrl using the same model
dataview_right = new wxDataViewCtrl( m_panelRight, wxID_ANY );
dataview_right->AssociateModel( model.get() );
dataview_right->AppendColumn( column );
dataview_right->AppendTextColumn( wxT("second"), 1 );
+
+ MySpinCtrlInPlaceRenderer *sr = new MySpinCtrlInPlaceRenderer;
+ column = new wxDataViewColumn( wxT("spin"), sr, 4, -1, wxALIGN_CENTER );
+ dataview_right->AppendColumn( column );
// layout dataview controls.