void InitStatics(); // BAD
};
+//-----------------------------------------------------------------------------
+// wxDataViewEditorCtrlEvtHandler
+//-----------------------------------------------------------------------------
+
+class wxDataViewEditorCtrlEvtHandler: public wxEvtHandler
+{
+public:
+ wxDataViewEditorCtrlEvtHandler( wxControl *editor, wxDataViewRenderer *owner );
+
+ void AcceptChangesAndFinish();
+
+protected:
+ void OnChar( wxKeyEvent &event );
+ void OnKillFocus( wxFocusEvent &event );
+
+private:
+ wxDataViewRenderer *m_owner;
+ wxControl *m_editorCtrl;
+ bool m_finished;
+
+private:
+ DECLARE_EVENT_TABLE()
+};
+
// ---------------------------------------------------------
// wxDataViewRendererBase
// ---------------------------------------------------------
virtual void SetAlignment( int align ) = 0;
virtual int GetAlignment() const = 0;
+ // in-place editing
+ virtual bool HasEditorCtrl()
+ { return false; }
+ virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
+ { return NULL; }
+ virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value )
+ { return false; }
+
+ virtual bool StartEditing( unsigned int row, wxRect labelRect );
+ virtual void CancelEditing();
+ virtual bool FinishEditing();
+
+ wxControl *GetEditorCtrl() { return m_editorCtrl; }
+
protected:
wxString m_variantType;
wxDataViewColumn *m_owner;
+ wxControl *m_editorCtrl;
+ unsigned int m_row; // for m_editorCtrl
// internal utility:
const wxDataViewCtrl* GetView() const;
class WXDLLIMPEXP_ADV wxDataViewMainWindow;
class WXDLLIMPEXP_ADV wxDataViewHeaderWindow;
-//-----------------------------------------------------------------------------
-// wxDataViewEditorCtrlEvtHandler
-//-----------------------------------------------------------------------------
-
-class wxDataViewEditorCtrlEvtHandler: public wxEvtHandler
-{
-public:
- wxDataViewEditorCtrlEvtHandler( wxControl *editor, wxDataViewRenderer *owner );
-
- void AcceptChangesAndFinish();
-
-protected:
- void OnChar( wxKeyEvent &event );
- void OnKillFocus( wxFocusEvent &event );
-
-private:
- wxDataViewRenderer *m_owner;
- wxControl *m_editorCtrl;
- bool m_finished;
-
-private:
- DECLARE_EVENT_TABLE()
-};
-
// ---------------------------------------------------------
// wxDataViewRenderer
// ---------------------------------------------------------
// Create DC on request
virtual wxDC *GetDC();
- // in-place editing
- virtual bool HasEditorCtrl()
- { return false; }
- virtual wxControl* CreateEditorCtrl( wxWindow *parent, wxRect labelRect, const wxVariant &value )
- { return NULL; }
- virtual bool GetValueFromEditorCtrl( wxControl* editor, wxVariant &value )
- { return false; }
-
- virtual bool StartEditing( unsigned int row, wxRect labelRect );
- virtual void CancelEditing();
- virtual bool FinishEditing();
-
private:
wxDC *m_dc;
int m_align;
wxDataViewCellMode m_mode;
- wxControl *m_editorCtrl;
- unsigned int m_row; // for m_editorCtrl
protected:
DECLARE_DYNAMIC_CLASS_NO_COPY(wxDataViewRenderer)
// updates the header window after a change in a column setting
void OnColumnChange();
- wxDataViewMainWindow* GetMainWindow() { return m_clientArea; }
+ wxWindow *GetMainWindow() { return (wxWindow*) m_clientArea; }
private:
wxDataViewListModelNotifier *m_notifier;
static wxVisualAttributes
GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL);
+ GtkWidget *GtkGetTreeView() { return m_treeview; }
+ wxWindow *GetMainWindow() { return (wxWindow*) this; }
+
private:
friend class wxDataViewCtrlDC;
friend class wxDataViewColumn;
#include "wx/choicdlg.h"
#include "wx/numdlg.h"
#include "wx/dataview.h"
+#include "wx/spinctrl.h"
#ifndef __WXMSW__
#include "../sample.xpm"
{
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;
{
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;
};
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.
int WXUNUSED(align) )
{
m_variantType = varianttype;
+ m_editorCtrl = NULL;
+ m_row = (unsigned int) -1;
}
const wxDataViewCtrl* wxDataViewRendererBase::GetView() const
return wx_const_cast(wxDataViewRendererBase*, this)->GetOwner()->GetOwner();
}
+bool wxDataViewRendererBase::StartEditing( unsigned int row, wxRect labelRect )
+{
+ m_row = row; // remember for later
+
+ unsigned int col = GetOwner()->GetModelColumn();
+ wxVariant value;
+ GetOwner()->GetOwner()->GetModel()->GetValue( value, col, row );
+
+ m_editorCtrl = CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect, value );
+
+ m_editorCtrl->PushEventHandler(
+ new wxDataViewEditorCtrlEvtHandler( m_editorCtrl, (wxDataViewRenderer*) this ) );
+
+ m_editorCtrl->SetFocus();
+
+ return true;
+}
+
+void wxDataViewRendererBase::CancelEditing()
+{
+ // m_editorCtrl->PopEventHandler( true );
+
+ delete m_editorCtrl;
+
+ GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
+}
+
+bool wxDataViewRendererBase::FinishEditing()
+{
+ // m_editorCtrl->PopEventHandler( true );
+
+ wxVariant value;
+ GetValueFromEditorCtrl( m_editorCtrl, value );
+
+ delete m_editorCtrl;
+
+ GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
+
+ if (!Validate(value))
+ return false;
+
+ unsigned int col = GetOwner()->GetModelColumn();
+ GetOwner()->GetOwner()->GetModel()->SetValue( value, col, m_row );
+ GetOwner()->GetOwner()->GetModel()->ValueChanged( col, m_row );
+
+ return true;
+}
+
+//-----------------------------------------------------------------------------
+// wxDataViewEditorCtrlEvtHandler
+//-----------------------------------------------------------------------------
+
+BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler, wxEvtHandler)
+ EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar)
+ EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus)
+END_EVENT_TABLE()
+
+wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
+ wxControl *editorCtrl,
+ wxDataViewRenderer *owner )
+{
+ m_owner = owner;
+ m_editorCtrl = editorCtrl;
+
+ m_finished = false;
+}
+
+void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event )
+{
+ switch ( event.m_keyCode )
+ {
+ case WXK_RETURN:
+ m_finished = true;
+ m_owner->FinishEditing();
+ break;
+
+ case WXK_ESCAPE:
+ m_finished = true;
+ m_owner->CancelEditing();
+ break;
+
+ default:
+ event.Skip();
+ }
+}
+
+void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent &event )
+{
+ if (!m_finished)
+ {
+ m_finished = true;
+ m_owner->FinishEditing();
+ }
+
+ // We must let the native text control handle focus
+ event.Skip();
+}
+
// ---------------------------------------------------------
// wxDataViewColumnBase
// ---------------------------------------------------------
return m_dc;
}
-bool wxDataViewRenderer::StartEditing( unsigned int row, wxRect labelRect )
-{
- GetView()->CalcScrolledPosition( labelRect.x, labelRect.y,
- &labelRect.x, &labelRect.y);
-
- m_row = row; // remember for later
-
- unsigned int col = GetOwner()->GetModelColumn();
- wxVariant value;
- GetOwner()->GetOwner()->GetModel()->GetValue( value, col, row );
-
- m_editorCtrl = CreateEditorCtrl( GetOwner()->GetOwner()->GetMainWindow(), labelRect, value );
-
- m_editorCtrl->PushEventHandler( new wxDataViewEditorCtrlEvtHandler( m_editorCtrl, this ) );
-
- m_editorCtrl->SetFocus();
-
- return true;
-}
-
-void wxDataViewRenderer::CancelEditing()
-{
- // m_editorCtrl->PopEventHandler( true );
-
- delete m_editorCtrl;
-
- GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
-}
-
-bool wxDataViewRenderer::FinishEditing()
-{
- // m_editorCtrl->PopEventHandler( true );
-
- wxVariant value;
- GetValueFromEditorCtrl( m_editorCtrl, value );
-
- delete m_editorCtrl;
-
- GetOwner()->GetOwner()->GetMainWindow()->SetFocus();
-
- if (!Validate(value))
- return false;
-
- unsigned int col = GetOwner()->GetModelColumn();
- GetOwner()->GetOwner()->GetModel()->SetValue( value, col, m_row );
- GetOwner()->GetOwner()->GetModel()->ValueChanged( col, m_row );
-
- return true;
-}
-
-//-----------------------------------------------------------------------------
-// wxDataViewEditorCtrlEvtHandler
-//-----------------------------------------------------------------------------
-
-BEGIN_EVENT_TABLE(wxDataViewEditorCtrlEvtHandler, wxEvtHandler)
- EVT_CHAR (wxDataViewEditorCtrlEvtHandler::OnChar)
- EVT_KILL_FOCUS (wxDataViewEditorCtrlEvtHandler::OnKillFocus)
-END_EVENT_TABLE()
-
-wxDataViewEditorCtrlEvtHandler::wxDataViewEditorCtrlEvtHandler(
- wxControl *editorCtrl,
- wxDataViewRenderer *owner )
-{
- m_owner = owner;
- m_editorCtrl = editorCtrl;
-
- m_finished = false;
-}
-
-void wxDataViewEditorCtrlEvtHandler::OnChar( wxKeyEvent &event )
-{
- switch ( event.m_keyCode )
- {
- case WXK_RETURN:
- m_finished = true;
- m_owner->FinishEditing();
- break;
-
- case WXK_ESCAPE:
- m_finished = true;
- m_owner->CancelEditing();
- break;
-
- default:
- event.Skip();
- }
-}
-
-void wxDataViewEditorCtrlEvtHandler::OnKillFocus( wxFocusEvent &event )
-{
- if (!m_finished)
- {
- m_finished = true;
- m_owner->FinishEditing();
- }
-
- // We must let the native text control handle focus
- event.Skip();
-}
-
// ---------------------------------------------------------
// wxDataViewCustomRenderer
// ---------------------------------------------------------
if ( m_dirty )
wxSafeYield();
-
int xpos = 0;
unsigned int cols = GetOwner()->GetColumnCount();
unsigned int i;
wxRect labelRect( xpos, m_currentRow * m_lineHeight,
m_currentCol->GetWidth(), m_lineHeight );
+ GetOwner()->CalcScrolledPosition( labelRect.x, labelRect.y,
+ &labelRect.x, &labelRect.y);
+
m_currentCol->GetRenderer()->StartEditing( m_currentRow, labelRect );
}
GdkRectangle *background_area,
GdkRectangle *cell_area,
GtkCellRendererState flags );
+static GtkCellEditable *gtk_wx_cell_renderer_start_editing(
+ GtkCellRenderer *cell,
+ GdkEvent *event,
+ GtkWidget *widget,
+ const gchar *path,
+ GdkRectangle *background_area,
+ GdkRectangle *cell_area,
+ GtkCellRendererState flags );
+
static GObjectClass *cell_parent_class = NULL;
cell_class->get_size = gtk_wx_cell_renderer_get_size;
cell_class->render = gtk_wx_cell_renderer_render;
cell_class->activate = gtk_wx_cell_renderer_activate;
+ cell_class->start_editing = gtk_wx_cell_renderer_start_editing;
}
static void
return (GtkCellRenderer*) g_object_new (GTK_TYPE_WX_CELL_RENDERER, NULL);
}
+
+
+static GtkCellEditable *gtk_wx_cell_renderer_start_editing(
+ GtkCellRenderer *renderer,
+ GdkEvent *event,
+ GtkWidget *widget,
+ const gchar *path,
+ GdkRectangle *background_area,
+ GdkRectangle *cell_area,
+ GtkCellRendererState flags )
+{
+ GtkWxCellRenderer *wxrenderer = (GtkWxCellRenderer *) renderer;
+ wxDataViewCustomRenderer *cell = wxrenderer->cell;
+ if (!cell->HasEditorCtrl())
+ return NULL;
+
+ GdkRectangle rect;
+ gtk_wx_cell_renderer_get_size (renderer, widget, cell_area,
+ &rect.x,
+ &rect.y,
+ &rect.width,
+ &rect.height);
+
+ rect.x += cell_area->x;
+ rect.y += cell_area->y;
+// rect.width -= renderer->xpad * 2;
+// rect.height -= renderer->ypad * 2;
+
+// wxRect renderrect( rect.x, rect.y, rect.width, rect.height );
+ wxRect renderrect( cell_area->x, cell_area->y, cell_area->width, cell_area->height );
+
+ wxDataViewListModel *model = cell->GetOwner()->GetOwner()->GetModel();
+
+ GtkTreePath *treepath = gtk_tree_path_new_from_string( path );
+ unsigned int model_row = (unsigned int)gtk_tree_path_get_indices (treepath)[0];
+ gtk_tree_path_free( treepath );
+
+ cell->StartEditing( model_row, renderrect );
+
+ return NULL;
+}
+
static void
gtk_wx_cell_renderer_get_size (GtkCellRenderer *renderer,
GtkWidget *widget,
// wxDataViewCtrl
//-----------------------------------------------------------------------------
+//-----------------------------------------------------------------------------
+// InsertChild for wxDataViewCtrl
+//-----------------------------------------------------------------------------
+
+static void wxInsertChildInDataViewCtrl( wxWindowGTK* parent, wxWindowGTK* child )
+{
+ wxDataViewCtrl * dvc = (wxDataViewCtrl*) parent;
+ GtkWidget *treeview = dvc->GtkGetTreeView();
+
+ // Insert widget in GtkTreeView
+ if (GTK_WIDGET_REALIZED(treeview))
+ gtk_widget_set_parent_window( child->m_widget,
+ gtk_tree_view_get_bin_window( GTK_TREE_VIEW(treeview) ) );
+ gtk_widget_set_parent( child->m_widget, treeview );
+}
+
+static
+void gtk_dataviewctrl_size_callback( GtkWidget *WXUNUSED(widget),
+ GtkAllocation *alloc,
+ wxDataViewCtrl *win )
+{
+
+ wxWindowList::Node *node = win->GetChildren().GetFirst();
+ while (node)
+ {
+ wxWindow *child = node->GetData();
+
+ GtkRequisition req;
+ gtk_widget_size_request( child->m_widget, &req );
+
+ GtkAllocation alloc;
+ alloc.x = child->m_x;
+ alloc.y = child->m_y;
+ alloc.width = child->m_width;
+ alloc.height = child->m_height;
+ gtk_widget_size_allocate( child->m_widget, &alloc );
+
+ node = node->GetNext();
+ }
+}
+
+
+
IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase)
wxDataViewCtrl::~wxDataViewCtrl()
return false;
}
+ m_insertCallback = wxInsertChildInDataViewCtrl;
+
m_widget = gtk_scrolled_window_new (NULL, NULL);
GtkScrolledWindowSetBorder(m_widget, style);
m_treeview = gtk_tree_view_new();
gtk_container_add (GTK_CONTAINER (m_widget), m_treeview);
+
+ g_signal_connect (m_treeview, "size_allocate",
+ G_CALLBACK (gtk_dataviewctrl_size_callback), this);
#ifdef __WXGTK26__
if (!gtk_check_version(2,6,0))