+ wxDataViewCtrl * const ctrl = cell->GetOwner()->GetOwner();
+ wxDataViewModel *model = ctrl->GetModel();
+
+ wxDataViewItem item(ctrl->GTKPathToItem(wxGtkTreePath(path)));
+
+ unsigned int model_col = cell->GetOwner()->GetModelColumn();
+
+ model->ChangeValue( value, item, model_col );
+}
+
+IMPLEMENT_CLASS(wxDataViewToggleRenderer, wxDataViewRenderer)
+
+wxDataViewToggleRenderer::wxDataViewToggleRenderer( const wxString &varianttype,
+ wxDataViewCellMode mode, int align ) :
+ wxDataViewRenderer( varianttype, mode, align )
+{
+ m_renderer = (GtkCellRenderer*) gtk_cell_renderer_toggle_new();
+
+ if (mode & wxDATAVIEW_CELL_ACTIVATABLE)
+ {
+ g_signal_connect_after( m_renderer, "toggled",
+ G_CALLBACK(wxGtkToggleRendererToggledCallback), this );
+ }
+ else
+ {
+ GValue gvalue = { 0, };
+ g_value_init( &gvalue, G_TYPE_BOOLEAN );
+ g_value_set_boolean( &gvalue, false );
+ g_object_set_property( G_OBJECT(m_renderer), "activatable", &gvalue );
+ g_value_unset( &gvalue );
+ }
+
+ SetMode(mode);
+ SetAlignment(align);
+}
+
+bool wxDataViewToggleRenderer::SetValue( const wxVariant &value )
+{
+ bool tmp = value;
+
+ GValue gvalue = { 0, };
+ g_value_init( &gvalue, G_TYPE_BOOLEAN );
+ g_value_set_boolean( &gvalue, tmp );
+ g_object_set_property( G_OBJECT(m_renderer), "active", &gvalue );
+ g_value_unset( &gvalue );
+
+ return true;
+}
+
+bool wxDataViewToggleRenderer::GetValue( wxVariant &value ) const
+{
+ GValue gvalue = { 0, };
+ g_value_init( &gvalue, G_TYPE_BOOLEAN );
+ g_object_get_property( G_OBJECT(m_renderer), "active", &gvalue );
+ value = g_value_get_boolean( &gvalue ) != 0;
+ g_value_unset( &gvalue );
+
+ return true;
+}
+
+// ---------------------------------------------------------
+// wxDataViewCustomRenderer
+// ---------------------------------------------------------
+
+#ifndef __WXGTK3__
+class wxDataViewCtrlDCImpl: public wxWindowDCImpl
+{
+public:
+ wxDataViewCtrlDCImpl( wxDC *owner, wxDataViewCtrl *window ) :
+ wxWindowDCImpl( owner )
+ {
+ GtkWidget *widget = window->m_treeview;
+ // Set later
+ m_gdkwindow = NULL;
+
+ m_window = window;
+
+ m_context = window->GTKGetPangoDefaultContext();
+ m_layout = pango_layout_new( m_context );
+ m_fontdesc = pango_font_description_copy(gtk_widget_get_style(widget)->font_desc);
+
+ m_cmap = gtk_widget_get_colormap( widget ? widget : window->m_widget );
+
+ // Set m_gdkwindow later
+ // SetUpDC();
+ }
+};
+
+class wxDataViewCtrlDC: public wxWindowDC
+{
+public:
+ wxDataViewCtrlDC( wxDataViewCtrl *window ) :
+ wxWindowDC( new wxDataViewCtrlDCImpl( this, window ) )
+ { }
+};
+#endif
+
+// ---------------------------------------------------------
+// wxDataViewCustomRenderer
+// ---------------------------------------------------------
+
+IMPLEMENT_CLASS(wxDataViewCustomRenderer, wxDataViewRenderer)
+
+wxDataViewCustomRenderer::wxDataViewCustomRenderer( const wxString &varianttype,
+ wxDataViewCellMode mode,
+ int align,
+ bool no_init )
+ : wxDataViewCustomRendererBase( varianttype, mode, align )
+{
+ m_dc = NULL;
+ m_text_renderer = NULL;
+ m_renderParams = NULL;
+
+ if (no_init)
+ m_renderer = NULL;
+ else
+ Init(mode, align);
+}
+
+void wxDataViewCustomRenderer::GtkInitTextRenderer()
+{
+ m_text_renderer = GTK_CELL_RENDERER_TEXT(gtk_cell_renderer_text_new());
+ g_object_ref_sink(m_text_renderer);
+
+ GtkApplyAlignment(GTK_CELL_RENDERER(m_text_renderer));
+}
+
+GtkCellRendererText *wxDataViewCustomRenderer::GtkGetTextRenderer() const
+{
+ if ( !m_text_renderer )
+ {
+ // we create it on demand so need to do it even from a const function
+ const_cast<wxDataViewCustomRenderer *>(this)->GtkInitTextRenderer();
+ }
+
+ return m_text_renderer;
+}
+
+void wxDataViewCustomRenderer::RenderText( const wxString &text,
+ int xoffset,
+ wxRect cell,
+ wxDC *WXUNUSED(dc),
+ int WXUNUSED(state) )
+{
+
+ GtkCellRendererText * const textRenderer = GtkGetTextRenderer();
+
+ GValue gvalue = { 0, };
+ g_value_init( &gvalue, G_TYPE_STRING );
+ g_value_set_string( &gvalue, wxGTK_CONV_FONT( text, GetOwner()->GetOwner()->GetFont() ) );
+ g_object_set_property( G_OBJECT(textRenderer), "text", &gvalue );
+ g_value_unset( &gvalue );
+
+ GtkApplyAttr(textRenderer, GetAttr());
+
+ GdkRectangle cell_area;
+ wxRectToGDKRect(cell, cell_area);
+ cell_area.x += xoffset;
+ cell_area.width -= xoffset;
+
+ gtk_cell_renderer_render( GTK_CELL_RENDERER(textRenderer),
+#ifdef __WXGTK3__
+ m_renderParams->cr,
+#else
+ m_renderParams->window,
+#endif
+ m_renderParams->widget,
+ m_renderParams->background_area,
+ &cell_area,
+#ifndef __WXGTK3__
+ m_renderParams->expose_area,
+#endif
+ GtkCellRendererState(m_renderParams->flags));
+}
+
+bool wxDataViewCustomRenderer::Init(wxDataViewCellMode mode, int align)
+{
+ GtkWxCellRenderer *renderer = (GtkWxCellRenderer *) gtk_wx_cell_renderer_new();
+ renderer->cell = this;
+
+ m_renderer = (GtkCellRenderer*) renderer;
+
+ SetMode(mode);
+ SetAlignment(align);
+
+ GtkInitHandlers();
+
+ return true;
+}
+
+wxDataViewCustomRenderer::~wxDataViewCustomRenderer()
+{
+ if (m_dc)
+ delete m_dc;
+
+ if (m_text_renderer)
+ g_object_unref(m_text_renderer);
+}
+
+wxDC *wxDataViewCustomRenderer::GetDC()
+{
+ if (m_dc == NULL)
+ {
+#ifdef __WXGTK3__
+ wxASSERT(m_renderParams);
+ cairo_t* cr = m_renderParams->cr;
+ wxASSERT(cr && cairo_status(cr) == 0);
+ m_dc = new wxGTKCairoDC(cr);
+#else
+ if (GetOwner() == NULL)
+ return NULL;
+ if (GetOwner()->GetOwner() == NULL)
+ return NULL;
+ m_dc = new wxDataViewCtrlDC( GetOwner()->GetOwner() );
+#endif
+ }
+
+ return m_dc;
+}
+
+// ---------------------------------------------------------
+// wxDataViewProgressRenderer
+// ---------------------------------------------------------
+
+IMPLEMENT_CLASS(wxDataViewProgressRenderer, wxDataViewCustomRenderer)
+
+wxDataViewProgressRenderer::wxDataViewProgressRenderer( const wxString &label,
+ const wxString &varianttype, wxDataViewCellMode mode, int align ) :
+ wxDataViewCustomRenderer( varianttype, mode, align, true )
+{
+ m_label = label;
+ m_value = 0;
+ m_renderer = (GtkCellRenderer*) gtk_cell_renderer_progress_new();
+
+ SetMode(mode);
+ SetAlignment(align);
+
+#if !wxUSE_UNICODE
+ // We can't initialize the renderer just yet because we don't have the
+ // pointer to the column that uses this renderer yet and so attempt to
+ // dereference GetOwner() to get the font that is used as a source of
+ // encoding in multibyte-to-Unicode conversion in GTKSetLabel() in
+ // non-Unicode builds would crash. So simply remember to do it later.
+ if ( !m_label.empty() )
+ m_needsToSetLabel = true;
+ else
+#endif // !wxUSE_UNICODE
+ {
+ GTKSetLabel();
+ }
+}
+
+wxDataViewProgressRenderer::~wxDataViewProgressRenderer()
+{
+}
+
+void wxDataViewProgressRenderer::GTKSetLabel()
+{
+ GValue gvalue = { 0, };
+ g_value_init( &gvalue, G_TYPE_STRING );
+
+ // Take care to not use GetOwner() here if the label is empty, we can be
+ // called from ctor when GetOwner() is still NULL in this case.
+ wxScopedCharBuffer buf;
+ if ( m_label.empty() )
+ buf = wxScopedCharBuffer::CreateNonOwned("");
+ else
+ buf = wxGTK_CONV_FONT(m_label, GetOwner()->GetOwner()->GetFont());
+
+ g_value_set_string( &gvalue, buf);
+ g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue );
+ g_value_unset( &gvalue );
+
+#if !wxUSE_UNICODE
+ m_needsToSetLabel = false;
+#endif // !wxUSE_UNICODE
+}
+
+bool wxDataViewProgressRenderer::SetValue( const wxVariant &value )
+{
+#if !wxUSE_UNICODE
+ if ( m_needsToSetLabel )
+ GTKSetLabel();
+#endif // !wxUSE_UNICODE
+
+ gint tmp = (long) value;
+ GValue gvalue = { 0, };
+ g_value_init( &gvalue, G_TYPE_INT );
+ g_value_set_int( &gvalue, tmp );
+ g_object_set_property( G_OBJECT(m_renderer), "value", &gvalue );
+ g_value_unset( &gvalue );
+
+ return true;
+}
+
+bool wxDataViewProgressRenderer::GetValue( wxVariant &WXUNUSED(value) ) const
+{
+ return false;
+}
+
+bool wxDataViewProgressRenderer::Render( wxRect cell, wxDC *dc, int WXUNUSED(state) )
+{
+ double pct = (double)m_value / 100.0;
+ wxRect bar = cell;
+ bar.width = (int)(cell.width * pct);
+ dc->SetPen( *wxTRANSPARENT_PEN );
+ dc->SetBrush( *wxBLUE_BRUSH );
+ dc->DrawRectangle( bar );
+
+ dc->SetBrush( *wxTRANSPARENT_BRUSH );
+ dc->SetPen( *wxBLACK_PEN );
+ dc->DrawRectangle( cell );
+
+ return true;
+}
+
+wxSize wxDataViewProgressRenderer::GetSize() const
+{
+ return wxSize(40,12);
+}
+
+// -------------------------------------
+// wxDataViewChoiceRenderer
+// -------------------------------------
+
+wxDataViewChoiceRenderer::wxDataViewChoiceRenderer( const wxArrayString &choices,
+ wxDataViewCellMode mode, int alignment ) :
+ wxDataViewCustomRenderer( "string", mode, alignment, true )
+{
+ m_choices = choices;
+ m_renderer = (GtkCellRenderer*) gtk_cell_renderer_combo_new();
+ GtkListStore *store = gtk_list_store_new( 1, G_TYPE_STRING );
+ for (size_t n = 0; n < m_choices.GetCount(); n++)
+ {
+ gtk_list_store_insert_with_values(
+ store, NULL, n, 0,
+ static_cast<const char *>(m_choices[n].utf8_str()), -1 );
+ }
+
+ g_object_set (m_renderer,
+ "model", store,
+ "text-column", 0,
+ "has-entry", FALSE,
+ NULL);
+
+ bool editable = (mode & wxDATAVIEW_CELL_EDITABLE) != 0;
+ g_object_set (m_renderer, "editable", editable, NULL);
+
+ SetAlignment(alignment);
+
+ g_signal_connect_after( m_renderer, "edited", G_CALLBACK(wxGtkTextRendererEditedCallback), this );
+
+ GtkInitHandlers();
+}
+
+bool wxDataViewChoiceRenderer::Render( wxRect rect, wxDC *dc, int state )
+{
+ RenderText( m_data, 0, rect, dc, state );
+ return true;
+}
+
+wxSize wxDataViewChoiceRenderer::GetSize() const
+{
+ return wxSize(70,20);
+}
+
+bool wxDataViewChoiceRenderer::SetValue( const wxVariant &value )
+{
+ GValue gvalue = { 0, };
+ g_value_init( &gvalue, G_TYPE_STRING );
+ g_value_set_string(&gvalue,
+ wxGTK_CONV_FONT(value.GetString(),
+ GetOwner()->GetOwner()->GetFont()));
+ g_object_set_property( G_OBJECT(m_renderer), "text", &gvalue );
+ g_value_unset( &gvalue );
+
+ return true;
+}
+
+bool wxDataViewChoiceRenderer::GetValue( wxVariant &value ) const
+{
+ GValue gvalue = { 0, };
+ g_value_init( &gvalue, G_TYPE_STRING );
+ g_object_get_property( G_OBJECT(m_renderer), "text", &gvalue );
+ wxString temp = wxGTK_CONV_BACK_FONT(g_value_get_string(&gvalue),
+ GetOwner()->GetOwner()->GetFont());
+ g_value_unset( &gvalue );
+ value = temp;
+
+ return true;
+}
+
+void wxDataViewChoiceRenderer::SetAlignment( int align )
+{
+ wxDataViewCustomRenderer::SetAlignment(align);
+
+#ifndef __WXGTK3__
+ if (gtk_check_version(2,10,0))
+ return;
+#endif
+
+ // horizontal alignment:
+ PangoAlignment pangoAlign = PANGO_ALIGN_LEFT;
+ if (align & wxALIGN_RIGHT)
+ pangoAlign = PANGO_ALIGN_RIGHT;
+ else if (align & wxALIGN_CENTER_HORIZONTAL)
+ pangoAlign = PANGO_ALIGN_CENTER;
+
+ GValue gvalue = { 0, };
+ g_value_init( &gvalue, gtk_cell_renderer_mode_get_type() );
+ g_value_set_enum( &gvalue, pangoAlign );
+ g_object_set_property( G_OBJECT(m_renderer), "alignment", &gvalue );
+ g_value_unset( &gvalue );
+}
+
+// ----------------------------------------------------------------------------
+// wxDataViewChoiceByIndexRenderer
+// ----------------------------------------------------------------------------
+
+wxDataViewChoiceByIndexRenderer::wxDataViewChoiceByIndexRenderer( const wxArrayString &choices,
+ wxDataViewCellMode mode, int alignment ) :
+ wxDataViewChoiceRenderer( choices, mode, alignment )
+{
+}
+
+void wxDataViewChoiceByIndexRenderer::GtkOnTextEdited(const char *itempath, const wxString& str)
+{
+ wxVariant value( (long) GetChoices().Index( str ) );
+
+ if (!Validate( value ))
+ return;
+
+ wxDataViewItem
+ item(GetOwner()->GetOwner()->GTKPathToItem(wxGtkTreePath(itempath)));
+
+ GtkOnCellChanged(value, item, GetOwner()->GetModelColumn());
+}
+
+bool wxDataViewChoiceByIndexRenderer::SetValue( const wxVariant &value )
+{
+ wxVariant string_value = GetChoice( value.GetLong() );
+ return wxDataViewChoiceRenderer::SetValue( string_value );
+}
+
+bool wxDataViewChoiceByIndexRenderer::GetValue( wxVariant &value ) const
+{
+ wxVariant string_value;
+ if (!wxDataViewChoiceRenderer::GetValue( string_value ))
+ return false;
+
+ value = (long) GetChoices().Index( string_value.GetString() );
+ return true;
+}
+
+// ---------------------------------------------------------
+// wxDataViewIconTextRenderer
+// ---------------------------------------------------------
+
+IMPLEMENT_CLASS(wxDataViewIconTextRenderer, wxDataViewCustomRenderer)
+
+wxDataViewIconTextRenderer::wxDataViewIconTextRenderer
+ (
+ const wxString &varianttype,
+ wxDataViewCellMode mode,
+ int align
+ )
+ : wxDataViewTextRenderer(varianttype, mode, align)
+{
+ m_rendererIcon = gtk_cell_renderer_pixbuf_new();
+}
+
+wxDataViewIconTextRenderer::~wxDataViewIconTextRenderer()
+{
+}
+
+void wxDataViewIconTextRenderer::GtkPackIntoColumn(GtkTreeViewColumn *column)
+{
+ // add the icon renderer first
+ gtk_tree_view_column_pack_start(column, m_rendererIcon, FALSE /* !expand */);
+
+ // add the text renderer too
+ wxDataViewRenderer::GtkPackIntoColumn(column);
+}
+
+bool wxDataViewIconTextRenderer::SetValue( const wxVariant &value )
+{
+ m_value << value;
+
+ SetTextValue(m_value.GetText());
+
+ const wxIcon& icon = m_value.GetIcon();
+ SetPixbufProp(m_rendererIcon, icon.IsOk() ? icon.GetPixbuf() : NULL);
+
+ return true;
+}
+
+bool wxDataViewIconTextRenderer::GetValue(wxVariant& value) const
+{
+ wxString str;
+ if ( !GetTextValue(str) )
+ return false;
+
+ // user doesn't have any way to edit the icon so leave it unchanged
+ value << wxDataViewIconText(str, m_value.GetIcon());
+
+ return true;
+}
+
+void
+wxDataViewIconTextRenderer::GtkOnCellChanged(const wxVariant& value,
+ const wxDataViewItem& item,
+ unsigned col)
+{
+ // we receive just the text part of our value as it's the only one which
+ // can be edited, but we need the full wxDataViewIconText value for the
+ // model
+ wxVariant valueIconText;
+ valueIconText << wxDataViewIconText(value.GetString(), m_value.GetIcon());
+ wxDataViewTextRenderer::GtkOnCellChanged(valueIconText, item, col);
+}
+
+// ---------------------------------------------------------
+// wxDataViewColumn
+// ---------------------------------------------------------
+
+
+static gboolean
+gtk_dataview_header_button_press_callback( GtkWidget *WXUNUSED(widget),
+ GdkEventButton *gdk_event,
+ wxDataViewColumn *column )
+{
+ if (gdk_event->type != GDK_BUTTON_PRESS)
+ return FALSE;
+
+ if (gdk_event->button == 1)
+ {
+ gs_lastLeftClickHeader = column;
+
+ wxDataViewCtrl *dv = column->GetOwner();
+ wxDataViewEvent event( wxEVT_DATAVIEW_COLUMN_HEADER_CLICK, dv->GetId() );
+ event.SetDataViewColumn( column );
+ event.SetModel( dv->GetModel() );
+ if (dv->HandleWindowEvent( event ))
+ return FALSE;
+ }
+
+ if (gdk_event->button == 3)
+ {
+ wxDataViewCtrl *dv = column->GetOwner();
+ wxDataViewEvent event( wxEVT_DATAVIEW_COLUMN_HEADER_RIGHT_CLICK, dv->GetId() );
+ event.SetDataViewColumn( column );
+ event.SetModel( dv->GetModel() );
+ if (dv->HandleWindowEvent( event ))
+ return FALSE;
+ }
+
+ return FALSE;
+}
+
+extern "C"
+{
+
+static void wxGtkTreeCellDataFunc( GtkTreeViewColumn *WXUNUSED(column),
+ GtkCellRenderer *renderer,
+ GtkTreeModel *model,
+ GtkTreeIter *iter,
+ gpointer data )
+{
+ g_return_if_fail (GTK_IS_WX_TREE_MODEL (model));
+ GtkWxTreeModel *tree_model = (GtkWxTreeModel *) model;
+
+ wxDataViewRenderer *cell = (wxDataViewRenderer*) data;
+
+ wxDataViewItem item( (void*) iter->user_data );
+
+ wxDataViewModel *wx_model = tree_model->internal->GetDataViewModel();
+
+ if (!wx_model->IsVirtualListModel())
+ {
+ gboolean visible;
+ if (wx_model->IsContainer( item ))
+ {
+ visible = wx_model->HasContainerColumns( item ) ||
+ (cell->GetOwner()->GetModelColumn() == 0);
+ }
+ else
+ {
+ visible = true;
+ }
+
+ GValue gvalue = { 0, };
+ g_value_init( &gvalue, G_TYPE_BOOLEAN );
+ g_value_set_boolean( &gvalue, visible );
+ g_object_set_property( G_OBJECT(renderer), "visible", &gvalue );
+ g_value_unset( &gvalue );
+
+ if ( !visible )
+ return;
+ }
+
+ wxVariant value;
+ wx_model->GetValue( value, item, cell->GetOwner()->GetModelColumn() );
+
+ if (value.GetType() != cell->GetVariantType())
+ {
+ wxLogError( wxT("Wrong type, required: %s but: %s"),
+ value.GetType().c_str(),
+ cell->GetVariantType().c_str() );
+ }
+
+ cell->SetValue( value );
+
+ // deal with disabled items
+ bool enabled = wx_model->IsEnabled( item, cell->GetOwner()->GetModelColumn() );
+
+ // a) this sets the appearance to disabled grey
+ GValue gvalue = { 0, };
+ g_value_init( &gvalue, G_TYPE_BOOLEAN );
+ g_value_set_boolean( &gvalue, enabled );
+ g_object_set_property( G_OBJECT(renderer), "sensitive", &gvalue );
+ g_value_unset( &gvalue );
+
+ // b) this actually disables the control/renderer
+ if (enabled)
+ cell->SetMode( cell->GtkGetMode() );
+ else
+ cell->SetMode( wxDATAVIEW_CELL_INERT );
+
+
+ // deal with attributes: if the renderer doesn't support them at all, we
+ // don't even need to query the model for them
+ if ( !cell->GtkSupportsAttrs() )
+ return;
+
+ // it can support attributes so check if this item has any
+ wxDataViewItemAttr attr;
+ if ( wx_model->GetAttr( item, cell->GetOwner()->GetModelColumn(), attr )
+ || !cell->GtkIsUsingDefaultAttrs() )
+ {
+ bool usingDefaultAttrs = !cell->GtkSetAttr(attr);
+ cell->GtkSetUsingDefaultAttrs(usingDefaultAttrs);
+ }
+ // else: no custom attributes specified and we're already using the default
+ // ones -- nothing to do
+
+}
+
+} // extern "C"
+
+#include <wx/listimpl.cpp>
+WX_DEFINE_LIST(wxDataViewColumnList)
+
+wxDataViewColumn::wxDataViewColumn( const wxString &title, wxDataViewRenderer *cell,
+ unsigned int model_column, int width,
+ wxAlignment align, int flags )
+ : wxDataViewColumnBase( cell, model_column )
+{
+ Init( align, flags, width );
+
+ SetTitle( title );
+}
+
+wxDataViewColumn::wxDataViewColumn( const wxBitmap &bitmap, wxDataViewRenderer *cell,
+ unsigned int model_column, int width,
+ wxAlignment align, int flags )
+ : wxDataViewColumnBase( bitmap, cell, model_column )
+{
+ Init( align, flags, width );
+
+ SetBitmap( bitmap );
+}
+
+void wxDataViewColumn::Init(wxAlignment align, int flags, int width)
+{
+ m_isConnected = false;
+
+ GtkTreeViewColumn *column = gtk_tree_view_column_new();
+ m_column = (GtkWidget*) column;
+
+ SetFlags( flags );
+ SetAlignment( align );
+
+ SetWidth( width );
+
+ // Create container for icon and label
+ GtkWidget* box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 1);
+ gtk_widget_show( box );
+ // gtk_container_set_border_width((GtkContainer*)box, 2);
+ m_image = gtk_image_new();
+ gtk_box_pack_start(GTK_BOX(box), m_image, FALSE, FALSE, 1);
+ m_label = gtk_label_new("");
+ gtk_box_pack_end( GTK_BOX(box), GTK_WIDGET(m_label), FALSE, FALSE, 1 );
+ gtk_tree_view_column_set_widget( column, box );
+
+ wxDataViewRenderer * const colRenderer = GetRenderer();
+ GtkCellRenderer * const cellRenderer = colRenderer->GetGtkHandle();
+
+ colRenderer->GtkPackIntoColumn(column);
+
+ gtk_tree_view_column_set_cell_data_func( column, cellRenderer,
+ wxGtkTreeCellDataFunc, (gpointer) colRenderer, NULL );
+}
+
+void wxDataViewColumn::OnInternalIdle()
+{
+ if (m_isConnected)
+ return;
+
+ if (gtk_widget_get_realized(GetOwner()->m_treeview))
+ {
+ GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
+ GtkWidget* button = gtk_tree_view_column_get_button(column);
+ if (button)
+ {
+ g_signal_connect(button, "button_press_event",
+ G_CALLBACK (gtk_dataview_header_button_press_callback), this);
+
+ // otherwise the event will be blocked by GTK+
+ gtk_tree_view_column_set_clickable( column, TRUE );
+
+ m_isConnected = true;
+ }
+ }
+}
+
+void wxDataViewColumn::SetOwner( wxDataViewCtrl *owner )
+{
+ wxDataViewColumnBase::SetOwner( owner );
+
+ GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
+
+ gtk_tree_view_column_set_title( column, wxGTK_CONV_FONT(GetTitle(), GetOwner()->GetFont() ) );
+}
+
+void wxDataViewColumn::SetTitle( const wxString &title )
+{
+ wxDataViewCtrl *ctrl = GetOwner();
+ gtk_label_set_text( GTK_LABEL(m_label), ctrl ? wxGTK_CONV_FONT(title, ctrl->GetFont())
+ : wxGTK_CONV_SYS(title) );
+ if (title.empty())
+ gtk_widget_hide( m_label );
+ else
+ gtk_widget_show( m_label );
+}
+
+wxString wxDataViewColumn::GetTitle() const
+{
+ return wxGTK_CONV_BACK_FONT(
+ gtk_label_get_text( GTK_LABEL(m_label) ),
+ GetOwner()->GetFont()
+ );
+}
+
+void wxDataViewColumn::SetBitmap( const wxBitmap &bitmap )
+{
+ wxDataViewColumnBase::SetBitmap( bitmap );
+
+ if (bitmap.IsOk())
+ {
+ GtkImage *gtk_image = GTK_IMAGE(m_image);
+
+ gtk_image_set_from_pixbuf(GTK_IMAGE(gtk_image), bitmap.GetPixbuf());
+ gtk_widget_show( m_image );
+ }
+ else
+ {
+ gtk_widget_hide( m_image );
+ }
+}
+
+void wxDataViewColumn::SetHidden( bool hidden )
+{
+ gtk_tree_view_column_set_visible( GTK_TREE_VIEW_COLUMN(m_column), !hidden );
+}
+
+void wxDataViewColumn::SetResizeable( bool resizable )
+{
+ gtk_tree_view_column_set_resizable( GTK_TREE_VIEW_COLUMN(m_column), resizable );
+}
+
+void wxDataViewColumn::SetAlignment( wxAlignment align )
+{
+ GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
+
+ gfloat xalign = 0.0;
+ if (align == wxALIGN_RIGHT)
+ xalign = 1.0;
+ if (align == wxALIGN_CENTER_HORIZONTAL ||
+ align == wxALIGN_CENTER)
+ xalign = 0.5;
+
+ gtk_tree_view_column_set_alignment( column, xalign );
+
+ if (m_renderer && m_renderer->GetAlignment() == -1)
+ m_renderer->GtkUpdateAlignment();
+}
+
+wxAlignment wxDataViewColumn::GetAlignment() const
+{
+ gfloat xalign = gtk_tree_view_column_get_alignment( GTK_TREE_VIEW_COLUMN(m_column) );
+
+ if (xalign == 1.0)
+ return wxALIGN_RIGHT;
+ if (xalign == 0.5)
+ return wxALIGN_CENTER_HORIZONTAL;
+
+ return wxALIGN_LEFT;
+}
+
+void wxDataViewColumn::SetSortable( bool sortable )
+{
+ GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
+
+ if ( sortable )
+ {
+ gtk_tree_view_column_set_sort_column_id( column, GetModelColumn() );
+ }
+ else
+ {
+ gtk_tree_view_column_set_sort_column_id( column, -1 );
+ gtk_tree_view_column_set_sort_indicator( column, FALSE );
+ gtk_tree_view_column_set_clickable( column, FALSE );
+ }
+}
+
+bool wxDataViewColumn::IsSortable() const
+{
+ GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
+ return gtk_tree_view_column_get_clickable( column ) != 0;
+}
+
+bool wxDataViewColumn::IsSortKey() const
+{
+ GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
+ return gtk_tree_view_column_get_sort_indicator( column ) != 0;
+}
+
+bool wxDataViewColumn::IsResizeable() const
+{
+ GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
+ return gtk_tree_view_column_get_resizable( column ) != 0;
+}
+
+bool wxDataViewColumn::IsHidden() const
+{
+ GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
+ return !gtk_tree_view_column_get_visible( column );
+}
+
+void wxDataViewColumn::SetSortOrder( bool ascending )
+{
+ GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
+
+ if (ascending)
+ gtk_tree_view_column_set_sort_order( column, GTK_SORT_ASCENDING );
+ else
+ gtk_tree_view_column_set_sort_order( column, GTK_SORT_DESCENDING );
+
+ gtk_tree_view_column_set_sort_indicator( column, TRUE );
+}
+
+bool wxDataViewColumn::IsSortOrderAscending() const
+{
+ GtkTreeViewColumn *column = GTK_TREE_VIEW_COLUMN(m_column);
+
+ return (gtk_tree_view_column_get_sort_order( column ) != GTK_SORT_DESCENDING);
+}
+
+void wxDataViewColumn::SetMinWidth( int width )
+{
+ gtk_tree_view_column_set_min_width( GTK_TREE_VIEW_COLUMN(m_column), width );
+}
+
+int wxDataViewColumn::GetMinWidth() const
+{
+ return gtk_tree_view_column_get_min_width( GTK_TREE_VIEW_COLUMN(m_column) );
+}
+
+int wxDataViewColumn::GetWidth() const
+{
+ return gtk_tree_view_column_get_width( GTK_TREE_VIEW_COLUMN(m_column) );
+}
+
+void wxDataViewColumn::SetWidth( int width )
+{
+ if ( width == wxCOL_WIDTH_AUTOSIZE )
+ {
+ // NB: this disables user resizing
+ gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column), GTK_TREE_VIEW_COLUMN_AUTOSIZE );
+ }
+ else
+ {
+ if ( width == wxCOL_WIDTH_DEFAULT )
+ {
+ // TODO find a better calculation
+ width = wxDVC_DEFAULT_WIDTH;
+ }
+
+ gtk_tree_view_column_set_sizing( GTK_TREE_VIEW_COLUMN(m_column), GTK_TREE_VIEW_COLUMN_FIXED );
+ gtk_tree_view_column_set_fixed_width( GTK_TREE_VIEW_COLUMN(m_column), width );
+ }
+}
+
+void wxDataViewColumn::SetReorderable( bool reorderable )
+{
+ gtk_tree_view_column_set_reorderable( GTK_TREE_VIEW_COLUMN(m_column), reorderable );
+}
+
+bool wxDataViewColumn::IsReorderable() const
+{
+ return gtk_tree_view_column_get_reorderable( GTK_TREE_VIEW_COLUMN(m_column) ) != 0;
+}
+
+//-----------------------------------------------------------------------------
+// wxGtkTreeModelNode
+//-----------------------------------------------------------------------------
+
+#if 0
+class wxGtkTreeModelChildWithPos
+{
+public:
+ unsigned int pos;
+ void *id;
+};
+
+static
+int wxGtkTreeModelChildWithPosCmp( const void* data1, const void* data2, const void* user_data )
+{
+ const wxGtkTreeModelChildWithPos* child1 = (const wxGtkTreeModelChildWithPos*) data1;
+ const wxGtkTreeModelChildWithPos* child2 = (const wxGtkTreeModelChildWithPos*) data2;
+ const wxDataViewCtrlInternal *internal = (const wxDataViewCtrlInternal *) user_data;
+ int ret = internal->GetDataViewModel()->Compare( child1->id, child2->id,
+ internal->GetSortColumn(), (internal->GetSortOrder() == GTK_SORT_DESCENDING) );
+
+ return ret;
+}
+#else
+static
+int LINKAGEMODE wxGtkTreeModelChildPtrCmp( void*** data1, void*** data2 )
+{
+ return gs_internal->GetDataViewModel()->Compare( wxDataViewItem(**data1), wxDataViewItem(**data2),
+ gs_internal->GetSortColumn(), (gs_internal->GetSortOrder() == GTK_SORT_ASCENDING) );
+}
+
+WX_DEFINE_ARRAY_PTR( void**, wxGtkTreeModelChildrenPtr );
+#endif
+
+void wxGtkTreeModelNode::Resort()
+{
+ size_t child_count = GetChildCount();
+ if (child_count == 0)
+ return;
+
+ size_t node_count = GetNodesCount();
+
+ if (child_count == 1)
+ {
+ if (node_count == 1)
+ {
+ wxGtkTreeModelNode *node = m_nodes.Item( 0 );
+ node->Resort();
+ }
+ return;
+ }
+
+ gint *new_order = new gint[child_count];
+
+#if 1
+ // m_children has the original *void
+ // ptrs points to these
+ wxGtkTreeModelChildrenPtr ptrs;
+ size_t i;
+ for (i = 0; i < child_count; i++)
+ ptrs.Add( &(m_children[i]) );
+ // Sort the ptrs
+ gs_internal = m_internal;
+ ptrs.Sort( &wxGtkTreeModelChildPtrCmp );
+
+ wxGtkTreeModelChildren temp;
+ void** base_ptr = &(m_children[0]);
+ // Transfer positions to new_order array and
+ // IDs to temp
+ for (i = 0; i < child_count; i++)
+ {
+ new_order[i] = ptrs[i] - base_ptr;
+ temp.Add( *ptrs[i] );
+ }
+
+ // Transfer IDs back to m_children
+ m_children.Clear();
+ WX_APPEND_ARRAY( temp, m_children );
+#endif
+#if 0
+ // Too slow
+
+ // Build up array with IDs and original positions
+ wxGtkTreeModelChildWithPos* temp = new wxGtkTreeModelChildWithPos[child_count];
+ size_t i;
+ for (i = 0; i < child_count; i++)
+ {
+ temp[i].pos = i;
+ temp[i].id = m_children[i];
+ }
+ // Sort array keeping original positions
+ wxQsort( temp, child_count, sizeof(wxGtkTreeModelChildWithPos),
+ &wxGtkTreeModelChildWithPosCmp, m_internal );
+ // Transfer positions to new_order array and
+ // IDs to m_children
+ m_children.Clear();
+ for (i = 0; i < child_count; i++)
+ {
+ new_order[i] = temp[i].pos;
+ m_children.Add( temp[i].id );
+ }
+ // Delete array
+ delete [] temp;
+#endif
+
+#if 0
+ // Too slow
+
+ wxGtkTreeModelChildren temp;
+ WX_APPEND_ARRAY( temp, m_children );
+
+ gs_internal = m_internal;
+ m_children.Sort( &wxGtkTreeModelChildCmp );
+
+ unsigned int pos;
+ for (pos = 0; pos < child_count; pos++)
+ {
+ void *id = m_children.Item( pos );
+ int old_pos = temp.Index( id );
+ new_order[pos] = old_pos;
+ }
+#endif
+
+ GtkTreeModel *gtk_tree_model = GTK_TREE_MODEL( m_internal->GetGtkModel() );
+
+ GtkTreeIter iter;
+ iter.user_data = GetItem().GetID();
+ iter.stamp = m_internal->GetGtkModel()->stamp;
+
+ gtk_tree_model_rows_reordered( gtk_tree_model,
+ wxGtkTreePath(m_internal->get_path(&iter)), &iter, new_order );
+
+ delete [] new_order;
+
+ unsigned int pos;
+ for (pos = 0; pos < node_count; pos++)
+ {
+ wxGtkTreeModelNode *node = m_nodes.Item( pos );
+ node->Resort();
+ }
+}
+
+//-----------------------------------------------------------------------------
+// wxDataViewCtrlInternal
+//-----------------------------------------------------------------------------
+
+wxDataViewCtrlInternal::wxDataViewCtrlInternal( wxDataViewCtrl *owner, wxDataViewModel *wx_model )
+{
+ m_owner = owner;
+ m_wx_model = wx_model;
+
+ m_root = NULL;
+ m_sort_order = GTK_SORT_ASCENDING;
+ m_sort_column = -1;
+ m_dataview_sort_column = NULL;
+
+ m_dragDataObject = NULL;
+ m_dropDataObject = NULL;
+
+ m_dirty = false;
+
+ m_gtk_model = wxgtk_tree_model_new();
+ m_gtk_model->internal = this;
+
+ m_notifier = new wxGtkDataViewModelNotifier( wx_model, this );
+
+ wx_model->AddNotifier( m_notifier );
+
+ // g_object_unref( gtk_model ); ???
+
+ if (!m_wx_model->IsVirtualListModel())
+ InitTree();
+
+ gtk_tree_view_set_model( GTK_TREE_VIEW(m_owner->GtkGetTreeView()), GTK_TREE_MODEL(m_gtk_model) );
+}
+
+wxDataViewCtrlInternal::~wxDataViewCtrlInternal()
+{
+ m_wx_model->RemoveNotifier( m_notifier );
+
+ // remove the model from the GtkTreeView before it gets destroyed
+ gtk_tree_view_set_model( GTK_TREE_VIEW( m_owner->GtkGetTreeView() ), NULL );
+
+ g_object_unref( m_gtk_model );
+
+ delete m_dragDataObject;
+ delete m_dropDataObject;
+}
+
+void wxDataViewCtrlInternal::ScheduleRefresh()
+{
+ m_dirty = true;
+}
+
+void wxDataViewCtrlInternal::OnInternalIdle()
+{
+ if (m_dirty)
+ {
+ GtkWidget *widget = m_owner->GtkGetTreeView();
+ gtk_widget_queue_draw( widget );
+ m_dirty = false;
+ }
+}
+
+void wxDataViewCtrlInternal::InitTree()
+{
+ wxDataViewItem item;
+ m_root = new wxGtkTreeModelNode( NULL, item, this );
+
+ BuildBranch( m_root );
+}
+
+void wxDataViewCtrlInternal::BuildBranch( wxGtkTreeModelNode *node )
+{
+ if (node->GetChildCount() == 0)
+ {
+ wxDataViewItemArray children;
+ unsigned int count = m_wx_model->GetChildren( node->GetItem(), children );
+
+ unsigned int pos;
+ for (pos = 0; pos < count; pos++)
+ {
+ wxDataViewItem child = children[pos];
+
+ if (m_wx_model->IsContainer( child ))
+ node->AddNode( new wxGtkTreeModelNode( node, child, this ) );
+ else
+ node->AddLeaf( child.GetID() );
+
+ // Don't send any events here
+ }
+ }
+}
+
+// GTK+ dnd iface
+
+bool wxDataViewCtrlInternal::EnableDragSource( const wxDataFormat &format )
+{
+ wxGtkString atom_str( gdk_atom_name( format ) );
+ m_dragSourceTargetEntryTarget = wxCharBuffer( atom_str );
+
+ m_dragSourceTargetEntry.target = m_dragSourceTargetEntryTarget.data();
+ m_dragSourceTargetEntry.flags = 0;
+ m_dragSourceTargetEntry.info = static_cast<guint>(-1);
+
+ gtk_tree_view_enable_model_drag_source( GTK_TREE_VIEW(m_owner->GtkGetTreeView() ),
+ GDK_BUTTON1_MASK, &m_dragSourceTargetEntry, 1, (GdkDragAction) GDK_ACTION_COPY );
+
+ return true;
+}
+
+bool wxDataViewCtrlInternal::EnableDropTarget( const wxDataFormat &format )
+{
+ wxGtkString atom_str( gdk_atom_name( format ) );
+ m_dropTargetTargetEntryTarget = wxCharBuffer( atom_str );
+
+ m_dropTargetTargetEntry.target = m_dropTargetTargetEntryTarget.data();
+ m_dropTargetTargetEntry.flags = 0;
+ m_dropTargetTargetEntry.info = static_cast<guint>(-1);
+
+ gtk_tree_view_enable_model_drag_dest( GTK_TREE_VIEW(m_owner->GtkGetTreeView() ),
+ &m_dropTargetTargetEntry, 1, (GdkDragAction) GDK_ACTION_COPY );
+
+ return true;
+}
+
+gboolean wxDataViewCtrlInternal::row_draggable( GtkTreeDragSource *WXUNUSED(drag_source),
+ GtkTreePath *path )
+{
+ delete m_dragDataObject;
+ m_dragDataObject = NULL;
+
+ wxDataViewItem item(GetOwner()->GTKPathToItem(path));
+ if ( !item )
+ return FALSE;
+
+ wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, m_owner->GetId() );
+ event.SetEventObject( m_owner );
+ event.SetItem( item );
+ event.SetModel( m_wx_model );
+ gint x, y;
+ gtk_widget_get_pointer(m_owner->GtkGetTreeView(), &x, &y);
+ event.SetPosition(x, y);
+ if (!m_owner->HandleWindowEvent( event ))
+ return FALSE;
+
+ if (!event.IsAllowed())
+ return FALSE;
+
+ wxDataObject *obj = event.GetDataObject();
+ if (!obj)
+ return FALSE;
+
+ m_dragDataObject = obj;
+
+ return TRUE;
+}
+
+gboolean
+wxDataViewCtrlInternal::drag_data_delete(GtkTreeDragSource *WXUNUSED(drag_source),
+ GtkTreePath *WXUNUSED(path))
+{
+ return FALSE;
+}
+
+gboolean wxDataViewCtrlInternal::drag_data_get( GtkTreeDragSource *WXUNUSED(drag_source),
+ GtkTreePath *path, GtkSelectionData *selection_data )
+{
+ wxDataViewItem item(GetOwner()->GTKPathToItem(path));
+ if ( !item )
+ return FALSE;
+
+ GdkAtom target = gtk_selection_data_get_target(selection_data);
+ if (!m_dragDataObject->IsSupported(target))
+ return FALSE;
+
+ size_t size = m_dragDataObject->GetDataSize(target);
+ if (size == 0)
+ return FALSE;
+
+ void *buf = malloc( size );
+
+ gboolean res = FALSE;
+ if (m_dragDataObject->GetDataHere(target, buf))
+ {
+ res = TRUE;
+
+ gtk_selection_data_set(selection_data, target,
+ 8, (const guchar*) buf, size );
+ }
+
+ free( buf );
+
+ return res;
+}
+
+gboolean
+wxDataViewCtrlInternal::drag_data_received(GtkTreeDragDest *WXUNUSED(drag_dest),
+ GtkTreePath *path,
+ GtkSelectionData *selection_data)
+{
+ wxDataViewItem item(GetOwner()->GTKPathToItem(path));
+ if ( !item )
+ return FALSE;
+
+ wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_DROP, m_owner->GetId() );
+ event.SetEventObject( m_owner );
+ event.SetItem( item );
+ event.SetModel( m_wx_model );
+ event.SetDataFormat(gtk_selection_data_get_target(selection_data));
+ event.SetDataSize(gtk_selection_data_get_length(selection_data));
+ event.SetDataBuffer(const_cast<guchar*>(gtk_selection_data_get_data(selection_data)));
+ if (!m_owner->HandleWindowEvent( event ))
+ return FALSE;
+
+ if (!event.IsAllowed())
+ return FALSE;
+
+ return TRUE;
+}
+
+gboolean
+wxDataViewCtrlInternal::row_drop_possible(GtkTreeDragDest *WXUNUSED(drag_dest),
+ GtkTreePath *path,
+ GtkSelectionData *selection_data)
+{
+ wxDataViewItem item(GetOwner()->GTKPathToItem(path));
+ if ( !item )
+ return FALSE;
+
+ wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, m_owner->GetId() );
+ event.SetEventObject( m_owner );
+ event.SetItem( item );
+ event.SetModel( m_wx_model );
+ event.SetDataFormat(gtk_selection_data_get_target(selection_data));
+ event.SetDataSize(gtk_selection_data_get_length(selection_data));
+ if (!m_owner->HandleWindowEvent( event ))
+ return FALSE;
+
+ if (!event.IsAllowed())
+ return FALSE;
+
+ return TRUE;
+}
+
+// notifications from wxDataViewModel
+
+bool wxDataViewCtrlInternal::Cleared()
+{
+ if (m_root)
+ {
+ delete m_root;
+ m_root = NULL;
+ }
+
+ InitTree();
+
+ ScheduleRefresh();
+
+ return true;
+}
+
+void wxDataViewCtrlInternal::Resort()
+{
+ if (!m_wx_model->IsVirtualListModel())
+ m_root->Resort();
+
+ ScheduleRefresh();
+}
+
+bool wxDataViewCtrlInternal::ItemAdded( const wxDataViewItem &parent, const wxDataViewItem &item )
+{
+ if (!m_wx_model->IsVirtualListModel())
+ {
+ wxGtkTreeModelNode *parent_node = FindNode( parent );
+ wxCHECK_MSG(parent_node, false,
+ "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
+
+ wxDataViewItemArray modelSiblings;
+ m_wx_model->GetChildren(parent, modelSiblings);
+ const int modelSiblingsSize = modelSiblings.size();
+
+ int posInModel = modelSiblings.Index(item, /*fromEnd=*/true);
+ wxCHECK_MSG( posInModel != wxNOT_FOUND, false, "adding non-existent item?" );
+
+ const wxGtkTreeModelChildren& nodeSiblings = parent_node->GetChildren();
+ const int nodeSiblingsSize = nodeSiblings.size();
+
+ int nodePos = 0;
+
+ if ( posInModel == modelSiblingsSize - 1 )
+ {
+ nodePos = nodeSiblingsSize;
+ }
+ else if ( modelSiblingsSize == nodeSiblingsSize + 1 )
+ {
+ // This is the simple case when our node tree already matches the
+ // model and only this one item is missing.
+ nodePos = posInModel;
+ }
+ else
+ {
+ // It's possible that a larger discrepancy between the model and
+ // our realization exists. This can happen e.g. when adding a bunch
+ // of items to the model and then calling ItemsAdded() just once
+ // afterwards. In this case, we must find the right position by
+ // looking at sibling items.
+
+ // append to the end if we won't find a better position:
+ nodePos = nodeSiblingsSize;
+
+ for ( int nextItemPos = posInModel + 1;
+ nextItemPos < modelSiblingsSize;
+ nextItemPos++ )
+ {
+ int nextNodePos = parent_node->FindChildByItem(modelSiblings[nextItemPos]);
+ if ( nextNodePos != wxNOT_FOUND )
+ {
+ nodePos = nextNodePos;
+ break;
+ }
+ }
+ }
+
+ if (m_wx_model->IsContainer( item ))
+ parent_node->InsertNode( new wxGtkTreeModelNode( parent_node, item, this ), nodePos );
+ else
+ parent_node->InsertLeaf( item.GetID(), nodePos );
+ }
+
+ ScheduleRefresh();
+
+ return true;
+}
+
+bool wxDataViewCtrlInternal::ItemDeleted( const wxDataViewItem &parent, const wxDataViewItem &item )
+{
+ if (!m_wx_model->IsVirtualListModel())
+ {
+ wxGtkTreeModelNode *parent_node = FindNode( parent );
+ wxASSERT_MSG(parent_node,
+ "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
+
+ parent_node->DeleteChild( item.GetID() );
+ }
+
+ ScheduleRefresh();
+
+ return true;
+}
+
+bool wxDataViewCtrlInternal::ItemChanged( const wxDataViewItem &item )
+{
+ wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, m_owner->GetId() );
+ event.SetEventObject( m_owner );
+ event.SetModel( m_owner->GetModel() );
+ event.SetItem( item );
+ m_owner->HandleWindowEvent( event );
+
+ return true;
+}
+
+bool wxDataViewCtrlInternal::ValueChanged( const wxDataViewItem &item, unsigned int view_column )
+{
+ wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, m_owner->GetId() );
+ event.SetEventObject( m_owner );
+ event.SetModel( m_owner->GetModel() );
+ event.SetColumn( view_column );
+ event.SetDataViewColumn( GetOwner()->GetColumn(view_column) );
+ event.SetItem( item );
+ m_owner->HandleWindowEvent( event );
+
+ return true;
+}
+
+// GTK+ model iface
+
+GtkTreeModelFlags wxDataViewCtrlInternal::get_flags()
+{
+ int flags = 0;
+
+ if ( m_wx_model->IsListModel() )
+ flags |= GTK_TREE_MODEL_LIST_ONLY;
+
+ if ( !m_wx_model->IsVirtualListModel() )
+ flags |= GTK_TREE_MODEL_ITERS_PERSIST;
+
+ return GtkTreeModelFlags(flags);
+}
+
+gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path )
+{
+
+ if (m_wx_model->IsVirtualListModel())
+ {
+ wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
+
+ unsigned int i = (unsigned int)gtk_tree_path_get_indices (path)[0];
+
+ if (i >= wx_model->GetCount())
+ return FALSE;
+
+ iter->stamp = m_gtk_model->stamp;
+ // user_data is just the index +1
+ iter->user_data = wxUIntToPtr(i+1);
+
+ return TRUE;
+ }
+ else
+ {
+ int depth = gtk_tree_path_get_depth( path );
+
+ wxGtkTreeModelNode *node = m_root;
+
+ int i;
+ for (i = 0; i < depth; i++)
+ {
+ BuildBranch( node );
+
+ gint pos = gtk_tree_path_get_indices (path)[i];
+ if (pos < 0) return FALSE;
+ if ((size_t)pos >= node->GetChildCount()) return FALSE;
+
+ void* id = node->GetChildren().Item( (size_t) pos );
+
+ if (i == depth-1)
+ {
+ iter->stamp = m_gtk_model->stamp;
+ iter->user_data = id;
+ return TRUE;
+ }
+
+ size_t count = node->GetNodes().GetCount();
+ size_t pos2;
+ for (pos2 = 0; pos2 < count; pos2++)
+ {
+ wxGtkTreeModelNode *child_node = node->GetNodes().Item( pos2 );
+ if (child_node->GetItem().GetID() == id)
+ {
+ node = child_node;
+ break;
+ }
+ }
+ }
+ }
+
+ return FALSE;
+}
+
+GtkTreePath *wxDataViewCtrlInternal::get_path( GtkTreeIter *iter )
+{
+ // When this is called from ItemDeleted(), the item is already
+ // deleted in the model.
+
+ GtkTreePath *retval = gtk_tree_path_new ();
+
+ if (m_wx_model->IsVirtualListModel())
+ {
+ // iter is root, add nothing
+ if (!iter->user_data)
+ return retval;
+
+ // user_data is just the index +1
+ int i = ( (wxUIntPtr) iter->user_data ) -1;
+ gtk_tree_path_append_index (retval, i);
+ }
+ else
+ {
+ void *id = iter->user_data;
+
+ wxGtkTreeModelNode *node = FindParentNode( iter );
+ while (node)
+ {
+ int pos = node->GetChildren().Index( id );
+
+ gtk_tree_path_prepend_index( retval, pos );
+
+ id = node->GetItem().GetID();
+ node = node->GetParent();
+ }
+ }
+
+ return retval;
+}
+
+gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter )
+{
+ if (m_wx_model->IsVirtualListModel())
+ {
+ wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
+
+ // user_data is just the index +1
+ int n = ( (wxUIntPtr) iter->user_data ) -1;
+
+ if (n == -1)
+ {
+ iter->user_data = NULL;
+ return FALSE;
+ }
+
+ if (n >= (int) wx_model->GetCount()-1)
+ {
+ iter->user_data = NULL;
+ return FALSE;
+ }
+
+ // user_data is just the index +1 (+2 because we need the next)
+ iter->user_data = wxUIntToPtr(n+2);
+ }
+ else
+ {
+ wxGtkTreeModelNode *parent = FindParentNode( iter );
+ if( parent == NULL )
+ {
+ iter->user_data = NULL;
+ return FALSE;
+ }
+
+ int pos = parent->GetChildren().Index( iter->user_data );
+
+ if (pos == (int) parent->GetChildCount()-1)
+ {
+ iter->user_data = NULL;
+ return FALSE;
+ }
+
+ iter->user_data = parent->GetChildren().Item( pos+1 );
+ }
+
+ return TRUE;
+}
+
+gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter *parent )
+{
+ if (m_wx_model->IsVirtualListModel())
+ {
+ // this is a list, nodes have no children
+ if (parent)
+ return FALSE;
+
+ iter->stamp = m_gtk_model->stamp;
+ iter->user_data = (gpointer) 1;
+
+ return TRUE;
+ }
+ else
+ {
+ if (iter == NULL)
+ {
+ if (m_root->GetChildCount() == 0) return FALSE;
+ iter->stamp = m_gtk_model->stamp;
+ iter->user_data = (gpointer) m_root->GetChildren().Item( 0 );
+ return TRUE;
+ }
+
+
+ wxDataViewItem item;
+ if (parent)
+ item = wxDataViewItem( (void*) parent->user_data );
+
+ if (!m_wx_model->IsContainer( item ))
+ return FALSE;
+
+ wxGtkTreeModelNode *parent_node = FindNode( parent );
+ wxASSERT_MSG(parent_node,
+ "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
+
+ BuildBranch( parent_node );
+
+ if (parent_node->GetChildCount() == 0)
+ return FALSE;
+
+ iter->stamp = m_gtk_model->stamp;
+ iter->user_data = (gpointer) parent_node->GetChildren().Item( 0 );
+ }
+
+ return TRUE;
+}
+
+gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter )
+{
+ if (m_wx_model->IsVirtualListModel())
+ {
+ wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
+
+ if (iter == NULL)
+ return (wx_model->GetCount() > 0);
+
+ // this is a list, nodes have no children
+ return FALSE;
+ }
+ else
+ {
+ if (iter == NULL)
+ return (m_root->GetChildCount() > 0);
+
+ wxDataViewItem item( (void*) iter->user_data );
+
+ bool is_container = m_wx_model->IsContainer( item );
+
+ if (!is_container)
+ return FALSE;
+
+ wxGtkTreeModelNode *node = FindNode( iter );
+ wxASSERT_MSG(node,
+ "Did you forget a call to ItemAdded()? The iterator is unknown to the wxGtkTreeModel");
+
+ BuildBranch( node );
+
+ return (node->GetChildCount() > 0);
+ }
+}
+
+gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter )
+{
+ if (m_wx_model->IsVirtualListModel())
+ {
+ wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
+
+ if (iter == NULL)
+ return (gint) wx_model->GetCount();
+
+ return 0;
+ }
+ else
+ {
+ if (iter == NULL)
+ return m_root->GetChildCount();
+
+ wxDataViewItem item( (void*) iter->user_data );
+
+ if (!m_wx_model->IsContainer( item ))
+ return 0;
+
+ wxGtkTreeModelNode *parent_node = FindNode( iter );
+ wxASSERT_MSG(parent_node,
+ "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
+
+ BuildBranch( parent_node );
+
+ return parent_node->GetChildCount();
+ }
+}
+
+gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter *parent, gint n )
+{
+ if (m_wx_model->IsVirtualListModel())
+ {
+ wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
+
+ if (parent)
+ return FALSE;
+
+ if (n < 0)
+ return FALSE;
+
+ if (n >= (gint) wx_model->GetCount())
+ return FALSE;
+
+ iter->stamp = m_gtk_model->stamp;
+ // user_data is just the index +1
+ iter->user_data = wxUIntToPtr(n+1);
+
+ return TRUE;
+ }
+ else
+ {
+ void* id = NULL;
+ if (parent) id = (void*) parent->user_data;
+ wxDataViewItem item( id );
+
+ if (!m_wx_model->IsContainer( item ))
+ return FALSE;
+
+ wxGtkTreeModelNode *parent_node = FindNode( parent );
+ wxASSERT_MSG(parent_node,
+ "Did you forget a call to ItemAdded()? The parent node is unknown to the wxGtkTreeModel");
+
+ BuildBranch( parent_node );
+
+ iter->stamp = m_gtk_model->stamp;
+ iter->user_data = parent_node->GetChildren().Item( n );
+
+ return TRUE;
+ }
+}
+
+gboolean wxDataViewCtrlInternal::iter_parent( GtkTreeIter *iter, GtkTreeIter *child )
+{
+ if (m_wx_model->IsVirtualListModel())
+ {
+ return FALSE;
+ }
+ else
+ {
+ wxGtkTreeModelNode *node = FindParentNode( child );
+ if (!node)
+ return FALSE;
+
+ iter->stamp = m_gtk_model->stamp;
+ iter->user_data = (gpointer) node->GetItem().GetID();
+
+ return TRUE;
+ }
+}
+
+// item can be deleted already in the model
+int wxDataViewCtrlInternal::GetIndexOf( const wxDataViewItem &parent, const wxDataViewItem &item )
+{
+ if (m_wx_model->IsVirtualListModel())
+ {
+ return wxPtrToUInt(item.GetID()) - 1;
+ }
+ else
+ {
+ wxGtkTreeModelNode *parent_node = FindNode( parent );
+ wxGtkTreeModelChildren &children = parent_node->GetChildren();
+ size_t j;
+ for (j = 0; j < children.GetCount(); j++)
+ {
+ if (children[j] == item.GetID())
+ return j;
+ }
+ }
+ return -1;
+}
+
+
+static wxGtkTreeModelNode*
+wxDataViewCtrlInternal_FindNode( wxDataViewModel * model, wxGtkTreeModelNode *treeNode, const wxDataViewItem &item )
+{
+ if( model == NULL )
+ return NULL;
+
+ ItemList list;
+ list.DeleteContents( true );
+ wxDataViewItem it( item );
+
+ while( it.IsOk() )
+ {
+ wxDataViewItem * pItem = new wxDataViewItem( it );
+ list.Insert( pItem );
+ it = model->GetParent( it );
+ }
+
+ wxGtkTreeModelNode * node = treeNode;
+ for( ItemList::compatibility_iterator n = list.GetFirst(); n; n = n->GetNext() )
+ {
+ if( node && node->GetNodes().GetCount() != 0 )
+ {
+ int len = node->GetNodes().GetCount();
+ wxGtkTreeModelNodes &nodes = node->GetNodes();
+ int j = 0;
+ for( ; j < len; j ++)
+ {
+ if( nodes[j]->GetItem() == *(n->GetData()))
+ {
+ node = nodes[j];
+ break;
+ }
+ }
+
+ if( j == len )
+ {
+ return NULL;
+ }
+ }
+ else
+ return NULL;
+ }
+ return node;
+
+}
+
+wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( GtkTreeIter *iter )
+{
+ if (!iter)
+ return m_root;
+
+ wxDataViewItem item( (void*) iter->user_data );
+ if (!item.IsOk())
+ return m_root;
+
+ wxGtkTreeModelNode *result = wxDataViewCtrlInternal_FindNode( m_wx_model, m_root, item );
+
+/*
+ if (!result)
+ {
+ wxLogDebug( "Not found %p", iter->user_data );
+ char *crash = NULL;
+ *crash = 0;
+ }
+ // TODO: remove this code
+*/
+
+ return result;
+}
+
+wxGtkTreeModelNode *wxDataViewCtrlInternal::FindNode( const wxDataViewItem &item )
+{
+ if (!item.IsOk())
+ return m_root;
+
+ wxGtkTreeModelNode *result = wxDataViewCtrlInternal_FindNode( m_wx_model, m_root, item );
+
+/*
+ if (!result)
+ {
+ wxLogDebug( "Not found %p", item.GetID() );
+ char *crash = NULL;
+ *crash = 0;
+ }
+ // TODO: remove this code
+*/
+
+ return result;
+}
+
+static wxGtkTreeModelNode*
+wxDataViewCtrlInternal_FindParentNode( wxDataViewModel * model, wxGtkTreeModelNode *treeNode, const wxDataViewItem &item )
+{
+ if( model == NULL )
+ return NULL;
+
+ ItemList list;
+ list.DeleteContents( true );
+ if( !item.IsOk() )
+ return NULL;
+
+ wxDataViewItem it( model->GetParent( item ) );
+ while( it.IsOk() )
+ {
+ wxDataViewItem * pItem = new wxDataViewItem( it );
+ list.Insert( pItem );
+ it = model->GetParent( it );
+ }
+
+ wxGtkTreeModelNode * node = treeNode;
+ for( ItemList::compatibility_iterator n = list.GetFirst(); n; n = n->GetNext() )
+ {
+ if( node && node->GetNodes().GetCount() != 0 )
+ {
+ int len = node->GetNodes().GetCount();
+ wxGtkTreeModelNodes nodes = node->GetNodes();
+ int j = 0;
+ for( ; j < len; j ++)
+ {
+ if( nodes[j]->GetItem() == *(n->GetData()))
+ {
+ node = nodes[j];
+ break;
+ }
+ }
+
+ if( j == len )
+ {
+ return NULL;
+ }
+ }
+ else
+ return NULL;
+ }
+ //Examine whether the node is item's parent node
+ int len = node->GetChildCount();
+ for( int i = 0; i < len ; i ++ )
+ {
+ if( node->GetChildren().Item( i ) == item.GetID() )
+ return node;
+ }
+ return NULL;
+}
+
+wxGtkTreeModelNode *wxDataViewCtrlInternal::FindParentNode( GtkTreeIter *iter )
+{
+ if (!iter)
+ return NULL;
+
+ wxDataViewItem item( (void*) iter->user_data );
+ if (!item.IsOk())
+ return NULL;
+
+ return wxDataViewCtrlInternal_FindParentNode( m_wx_model, m_root, item );
+}
+
+wxGtkTreeModelNode *wxDataViewCtrlInternal::FindParentNode( const wxDataViewItem &item )
+{
+ if (!item.IsOk())
+ return NULL;
+
+ return wxDataViewCtrlInternal_FindParentNode( m_wx_model, m_root, item );
+}
+
+//-----------------------------------------------------------------------------
+// wxDataViewCtrl signal callbacks
+//-----------------------------------------------------------------------------
+
+static void
+wxdataview_selection_changed_callback( GtkTreeSelection* WXUNUSED(selection), wxDataViewCtrl *dv )
+{
+ if (!gtk_widget_get_realized(dv->m_widget))
+ return;
+
+ wxDataViewEvent event( wxEVT_DATAVIEW_SELECTION_CHANGED, dv->GetId() );
+ event.SetItem( dv->GetSelection() );
+ event.SetModel( dv->GetModel() );
+ dv->HandleWindowEvent( event );
+}
+
+static void
+wxdataview_row_activated_callback( GtkTreeView* WXUNUSED(treeview), GtkTreePath *path,
+ GtkTreeViewColumn *WXUNUSED(column), wxDataViewCtrl *dv )
+{
+ wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_ACTIVATED, dv->GetId() );
+
+ wxDataViewItem item(dv->GTKPathToItem(path));
+ event.SetItem( item );
+ event.SetModel( dv->GetModel() );
+ dv->HandleWindowEvent( event );
+}
+
+static gboolean
+wxdataview_test_expand_row_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter,
+ GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv )
+{
+ wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_EXPANDING, dv->GetId() );
+
+ wxDataViewItem item( (void*) iter->user_data );;
+ event.SetItem( item );
+ event.SetModel( dv->GetModel() );
+ dv->HandleWindowEvent( event );
+
+ return !event.IsAllowed();
+}
+
+static void
+wxdataview_row_expanded_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter,
+ GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv )
+{
+ wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_EXPANDED, dv->GetId() );
+
+ wxDataViewItem item( (void*) iter->user_data );;
+ event.SetItem( item );
+ event.SetModel( dv->GetModel() );
+ dv->HandleWindowEvent( event );
+}
+
+static gboolean
+wxdataview_test_collapse_row_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter,
+ GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv )
+{
+ wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_COLLAPSING, dv->GetId() );
+
+ wxDataViewItem item( (void*) iter->user_data );;
+ event.SetItem( item );
+ event.SetModel( dv->GetModel() );
+ dv->HandleWindowEvent( event );
+
+ return !event.IsAllowed();
+}
+
+static void
+wxdataview_row_collapsed_callback( GtkTreeView* WXUNUSED(treeview), GtkTreeIter* iter,
+ GtkTreePath *WXUNUSED(path), wxDataViewCtrl *dv )
+{
+ wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_COLLAPSED, dv->GetId() );
+
+ wxDataViewItem item( (void*) iter->user_data );;
+ event.SetItem( item );
+ event.SetModel( dv->GetModel() );
+ dv->HandleWindowEvent( event );
+}
+
+//-----------------------------------------------------------------------------
+ // wxDataViewCtrl
+//-----------------------------------------------------------------------------
+
+void wxDataViewCtrl::AddChildGTK(wxWindowGTK* child)
+{
+ GtkWidget* treeview = GtkGetTreeView();
+
+ // Insert widget in GtkTreeView
+ if (gtk_widget_get_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 *WXUNUSED(gtk_alloc),
+ wxDataViewCtrl *win )
+{
+ wxWindowList::compatibility_iterator node = win->GetChildren().GetFirst();
+ while (node)
+ {
+ wxWindow *child = node->GetData();
+
+ GtkRequisition req;
+ gtk_widget_get_preferred_size(child->m_widget, NULL, &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();
+ }
+}
+
+
+//-----------------------------------------------------------------------------
+// "motion_notify_event"
+//-----------------------------------------------------------------------------
+
+static gboolean
+gtk_dataview_motion_notify_callback( GtkWidget *WXUNUSED(widget),
+ GdkEventMotion *gdk_event,
+ wxDataViewCtrl *dv )
+{
+ int x = gdk_event->x;
+ int y = gdk_event->y;
+ if (gdk_event->is_hint)
+ {
+#ifdef __WXGTK3__
+ gdk_window_get_device_position(gdk_event->window, gdk_event->device, &x, &y, NULL);
+#else
+ gdk_window_get_pointer(gdk_event->window, &x, &y, NULL);
+#endif
+ }
+
+ wxGtkTreePath path;
+ GtkTreeViewColumn *column = NULL;
+ gint cell_x = 0;
+ gint cell_y = 0;
+ if (gtk_tree_view_get_path_at_pos(
+ GTK_TREE_VIEW(dv->GtkGetTreeView()),
+ x, y,
+ path.ByRef(),
+ &column,
+ &cell_x,
+ &cell_y))
+ {
+ if (path)
+ {
+ GtkTreeIter iter;
+ dv->GtkGetInternal()->get_iter( &iter, path );
+ }
+ }
+
+
+ return FALSE;
+}
+
+//-----------------------------------------------------------------------------
+// "button_press_event"
+//-----------------------------------------------------------------------------
+
+static gboolean
+gtk_dataview_button_press_callback( GtkWidget *WXUNUSED(widget),
+ GdkEventButton *gdk_event,
+ wxDataViewCtrl *dv )
+{
+ if ((gdk_event->button == 3) && (gdk_event->type == GDK_BUTTON_PRESS))
+ {
+ wxGtkTreePath path;
+ GtkTreeViewColumn *column = NULL;
+ gint cell_x = 0;
+ gint cell_y = 0;
+ gtk_tree_view_get_path_at_pos
+ (
+ GTK_TREE_VIEW(dv->GtkGetTreeView()),
+ (int) gdk_event->x, (int) gdk_event->y,
+ path.ByRef(),
+ &column,
+ &cell_x,
+ &cell_y
+ );
+
+ wxDataViewEvent event( wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, dv->GetId() );
+ if (path)
+ event.SetItem(dv->GTKPathToItem(path));
+ event.SetModel( dv->GetModel() );
+ return dv->HandleWindowEvent( event );
+ }
+
+ return FALSE;
+}
+
+IMPLEMENT_DYNAMIC_CLASS(wxDataViewCtrl, wxDataViewCtrlBase)
+
+wxDataViewCtrl::~wxDataViewCtrl()
+{
+ // Stop editing before destroying the control to remove any event handlers
+ // which are added when editing started: if we didn't do this, the base
+ // class dtor would assert as it checks for any leftover handlers.
+ if ( m_treeview )
+ {
+ GtkTreeViewColumn *col;
+ gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview), NULL, &col);
+
+ wxDataViewColumn * const wxcol = FromGTKColumn(col);
+ if ( wxcol )
+ {
+ // This won't do anything if we're not editing it
+ wxcol->GetRenderer()->CancelEditing();
+ }
+
+ GTKDisconnect(m_treeview);
+ GtkTreeSelection* selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview));
+ if (selection)
+ GTKDisconnect(selection);
+ }
+
+ m_cols.Clear();
+
+ delete m_internal;
+}
+
+void wxDataViewCtrl::Init()
+{
+ m_treeview = NULL;
+ m_internal = NULL;
+
+ m_cols.DeleteContents( true );
+
+ m_uniformRowHeight = -1;
+}
+
+bool wxDataViewCtrl::Create(wxWindow *parent,
+ wxWindowID id,
+ const wxPoint& pos,
+ const wxSize& size,
+ long style,
+ const wxValidator& validator,
+ const wxString& name)
+{
+ if (!PreCreation( parent, pos, size ) ||
+ !CreateBase( parent, id, pos, size, style, validator, name ))
+ {
+ wxFAIL_MSG( wxT("wxDataViewCtrl creation failed") );
+ return false;
+ }
+
+ m_widget = gtk_scrolled_window_new (NULL, NULL);
+ g_object_ref(m_widget);
+
+ GTKScrolledWindowSetBorder(m_widget, style);
+
+ m_treeview = gtk_tree_view_new();
+ gtk_container_add (GTK_CONTAINER (m_widget), m_treeview);
+
+ m_focusWidget = GTK_WIDGET(m_treeview);
+
+ g_signal_connect (m_treeview, "size_allocate",
+ G_CALLBACK (gtk_dataviewctrl_size_callback), this);
+
+ bool fixed = (style & wxDV_VARIABLE_LINE_HEIGHT) == 0;
+ gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), fixed );
+
+ if (style & wxDV_MULTIPLE)
+ {
+ GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
+ gtk_tree_selection_set_mode( selection, GTK_SELECTION_MULTIPLE );
+ }
+
+ gtk_tree_view_set_headers_visible( GTK_TREE_VIEW(m_treeview), (style & wxDV_NO_HEADER) == 0 );
+
+#ifdef __WXGTK210__
+#ifndef __WXGTK3__
+ if (!gtk_check_version(2,10,0))
+#endif
+ {
+ GtkTreeViewGridLines grid = GTK_TREE_VIEW_GRID_LINES_NONE;
+
+ if ((style & wxDV_HORIZ_RULES) != 0 &&
+ (style & wxDV_VERT_RULES) != 0)
+ grid = GTK_TREE_VIEW_GRID_LINES_BOTH;
+ else if (style & wxDV_VERT_RULES)
+ grid = GTK_TREE_VIEW_GRID_LINES_VERTICAL;
+ else if (style & wxDV_HORIZ_RULES)
+ grid = GTK_TREE_VIEW_GRID_LINES_HORIZONTAL;
+
+ if (grid != GTK_TREE_VIEW_GRID_LINES_NONE)
+ gtk_tree_view_set_grid_lines( GTK_TREE_VIEW(m_treeview), grid );
+ }
+#endif
+
+ gtk_tree_view_set_rules_hint( GTK_TREE_VIEW(m_treeview), (style & wxDV_ROW_LINES) != 0 );