virtual bool AppendTextColumn( const wxString &label, size_t model_column );
virtual bool AppendToggleColumn( const wxString &label, size_t model_column );
virtual bool AppendProgressColumn( const wxString &label, size_t model_column );
+ virtual bool AppendDateColumn( const wxString &label, size_t model_column );
virtual bool AppendColumn( wxDataViewColumn *col );
virtual size_t GetNumberOfColumns();
virtual bool DeleteColumn( size_t pos );
virtual bool Render( wxRect cell, wxDC *dc, int state ) = 0;
virtual wxSize GetSize() = 0;
- virtual bool Activate( wxRect cell ) { return false; };
+
+ virtual bool Activate( wxRect cell,
+ wxDataViewListModel *model, size_t col, size_t row )
+ { return false; }
+
+ virtual bool LeftClick( wxPoint cursor, wxRect cell,
+ wxDataViewListModel *model, size_t col, size_t row )
+ { return false; }
+ virtual bool RightClick( wxPoint cursor, wxRect cell,
+ wxDataViewListModel *model, size_t col, size_t row )
+ { return false; }
+ virtual bool StartDrag( wxPoint cursor, wxRect cell,
+ wxDataViewListModel *model, size_t col, size_t row )
+ { return false; }
// Create DC on request
virtual wxDC *GetDC();
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewProgressCell)
};
+// ---------------------------------------------------------
+// wxDataViewDateCell
+// ---------------------------------------------------------
+
+class wxDataViewDateCell: public wxDataViewCustomCell
+{
+public:
+ wxDataViewDateCell( const wxString &varianttype = wxT("datetime"),
+ wxDataViewCellMode mode = wxDATAVIEW_CELL_ACTIVATABLE );
+
+ bool SetValue( const wxVariant &value );
+
+ virtual bool Render( wxRect cell, wxDC *dc, int state );
+ virtual wxSize GetSize();
+ virtual bool Activate( wxRect cell,
+ wxDataViewListModel *model, size_t col, size_t row );
+
+private:
+ wxDateTime m_date;
+
+protected:
+ DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewDateCell)
+};
+
// ---------------------------------------------------------
// wxDataViewColumn
// ---------------------------------------------------------
// MyTextModel
// -------------------------------------
+WX_DECLARE_LIST(wxDateTime,wxArrayDate);
+#include <wx/listimpl.cpp>
+WX_DEFINE_LIST(wxArrayDate);
+
class MyTextModel: public wxDataViewListModel
{
public:
{ m_colours.Add( wxT("red") ); m_colours.Add( wxT("green") ); }
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 );
+ }
}
virtual size_t GetNumberOfRows()
{ return 1000; }
virtual size_t GetNumberOfCols()
- { return 6; }
+ { return 7; }
// as reported by wxVariant
virtual wxString GetColType( size_t col )
{
+ if (col == 6)
+ return wxT("datetime");
+
if (col == 5)
return wxT("long");
virtual wxVariant GetValue( size_t col, size_t row )
{
+ if (col == 6)
+ {
+ return (wxDateTime) *m_dates[row];
+ } else
if (col == 5)
{
return (long) m_progress[row];
}
virtual bool SetValue( wxVariant &value, size_t col, size_t row )
{
+ if (col == 6)
+ {
+ *m_dates[row] = value.GetDateTime();
+ } else
if (col == 3)
{
m_bools[row] = (int) value.GetBool();
wxArrayInt m_bools;
wxArrayString m_colours;
wxArrayInt m_progress;
+ wxArrayDate m_dates;
};
// -------------------------------------
return true;
}
bool Render( wxRect rect, wxDC *dc, int state )
- {
+ {
dc->SetPen( *wxBLACK_PEN );
if (m_colour == wxT("red"))
dc->SetBrush( *wxRED_BRUSH );
{
return wxSize(20,8);
}
- bool Activate( wxRect rect )
+ bool Activate( wxRect rect,
+ wxDataViewListModel *model, size_t col, size_t row )
{
- wxPrintf( wxT("activate\n") );
return false;
}
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->AssociateModel( model );
dataview_right->AppendColumn( column );
wxBoxSizer *sizer = new wxBoxSizer( wxHORIZONTAL );
- sizer->Add( dataview_left, 1, wxGROW );
+ sizer->Add( dataview_left, 3, wxGROW );
sizer->Add(10,10);
- sizer->Add( dataview_right, 1, wxGROW );
+ sizer->Add( dataview_right, 2, wxGROW );
SetSizer( sizer );
}
return AppendColumn( new wxDataViewColumn( label, new wxDataViewProgressCell(), model_column ) );
}
+bool wxDataViewCtrlBase::AppendDateColumn( const wxString &label, size_t model_column )
+{
+ return AppendColumn( new wxDataViewColumn( label, new wxDataViewDateCell(), model_column ) );
+}
+
bool wxDataViewCtrlBase::AppendColumn( wxDataViewColumn *col )
{
m_cols.Append( (wxObject*) col );
#include <gtk/gtktreemodel.h>
#include <gtk/gtktreednd.h>
+#include <gdk/gdkkeysyms.h>
+
//-----------------------------------------------------------------------------
// classes
//-----------------------------------------------------------------------------
/*< private >*/
wxDataViewCustomCell *cell;
+ guint32 last_click;
};
struct _GtkWxCellRendererClass
gtk_wx_cell_renderer_init (GtkWxCellRenderer *cell)
{
cell->cell = NULL;
+ cell->last_click = 0;
}
static void
{
wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
wxWindowDC* dc = (wxWindowDC*) cell->GetDC();
- dc->m_window = window;
+ if (dc->m_window == NULL)
+ {
+ dc->m_window = window;
+ dc->SetUpDC();
+ }
int state = 0;
if (flags & GTK_CELL_RENDERER_SELECTED)
rect.height -= renderer->ypad * 2;
wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
+
+ wxDataViewListModel *model = cell->GetOwner()->GetOwner()->GetModel();
+
+ GtkTreePath *treepath = gtk_tree_path_new_from_string( path );
+ size_t model_row = (size_t)gtk_tree_path_get_indices (treepath)[0];
+ gtk_tree_path_free( treepath );
+
+ size_t model_col = cell->GetOwner()->GetModelColumn();
+
+ if (event->type == GDK_BUTTON_PRESS)
+ {
+ GdkEventButton *button_event = (GdkEventButton*) event;
+ wxPoint pt( ((int) button_event->x) - renderrect.x,
+ ((int) button_event->y) - renderrect.y );
- return cell->Activate( renderrect );
+ bool ret = false;
+ if (button_event->button == 1)
+ {
+ if (cell->LeftClick( pt, renderrect, model, model_col, model_row ))
+ ret = true;
+ if (button_event->time - wxrenderer->last_click < 400)
+ if (cell->Activate( renderrect, model, model_col, model_row ))
+ ret = true;
+ }
+ if (button_event->button == 3)
+ {
+ if (cell->RightClick( pt, renderrect, model, model_col, model_row ))
+ ret = true;
+ }
+
+ wxrenderer->last_click = button_event->time;
+
+ return ret;
+ }
+
+ if (event->type == GDK_KEY_PRESS)
+ {
+ wxPrintf( wxT("key\n") );
+ GdkEventKey *key_event = (GdkEventKey*) event;
+ if ((key_event->keyval == GDK_Return) ||
+ (key_event->keyval == GDK_Linefeed) ||
+ (key_event->keyval == GDK_Execute))
+ {
+ return cell->Activate( renderrect, model, model_col, model_row );
+ }
+ }
+
+ return false;
}
// ---------------------------------------------------------
GtkWidget *widget = window->m_treeview;
// Set later
m_window = NULL;
-
+
m_context = window->GtkGetPangoDefaultContext();
m_layout = pango_layout_new( m_context );
m_fontdesc = pango_font_description_copy( widget->style->font_desc );
m_cmap = gtk_widget_get_colormap( widget ? widget : window->m_widget );
- SetUpDC();
-
- m_owner = window;
+ // Set m_window later
+ // SetUpDC();
+ // m_owner = window;
}
};
wxDC *wxDataViewCustomCell::GetDC()
{
if (m_dc == NULL)
+ {
+ if (GetOwner() == NULL)
+ return NULL;
+ if (GetOwner()->GetOwner() == NULL)
+ return NULL;
m_dc = new wxDataViewCtrlDC( GetOwner()->GetOwner() );
+ }
return m_dc;
}
return wxSize(40,12);
}
+// ---------------------------------------------------------
+// wxDataViewDateCell
+// ---------------------------------------------------------
+
+IMPLEMENT_ABSTRACT_CLASS(wxDataViewDateCell, wxDataViewCustomCell)
+
+wxDataViewDateCell::wxDataViewDateCell( const wxString &varianttype,
+ wxDataViewCellMode mode ) :
+ wxDataViewCustomCell( varianttype, mode )
+{
+}
+
+bool wxDataViewDateCell::SetValue( const wxVariant &value )
+{
+ m_date = value.GetDateTime();
+
+ return true;
+}
+
+bool wxDataViewDateCell::Render( wxRect cell, wxDC *dc, int state )
+{
+ dc->SetFont( GetOwner()->GetOwner()->GetFont() );
+ wxString tmp = m_date.FormatDate();
+ dc->DrawText( tmp, cell.x, cell.y );
+
+ return true;
+}
+
+wxSize wxDataViewDateCell::GetSize()
+{
+ wxDataViewCtrl* view = GetOwner()->GetOwner();
+ wxString tmp = m_date.FormatDate();
+ wxCoord x,y,d;
+ view->GetTextExtent( tmp, &x, &y, &d );
+ return wxSize(x,y+d);
+}
+
+bool wxDataViewDateCell::Activate( wxRect cell, wxDataViewListModel *model, size_t col, size_t row )
+{
+
+ return true;
+}
+
// ---------------------------------------------------------
// wxDataViewColumn
// ---------------------------------------------------------