+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 );
+
+ gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (m_widget),
+ GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+ gtk_widget_show (m_treeview);
+
+ m_parent->DoAddChild( this );
+
+ PostCreation(size);
+
+ GtkEnableSelectionEvents();
+
+ g_signal_connect_after (m_treeview, "row-activated",
+ G_CALLBACK (wxdataview_row_activated_callback), this);
+
+ g_signal_connect (m_treeview, "test-collapse-row",
+ G_CALLBACK (wxdataview_test_collapse_row_callback), this);
+
+ g_signal_connect_after (m_treeview, "row-collapsed",
+ G_CALLBACK (wxdataview_row_collapsed_callback), this);
+
+ g_signal_connect (m_treeview, "test-expand-row",
+ G_CALLBACK (wxdataview_test_expand_row_callback), this);
+
+ g_signal_connect_after (m_treeview, "row-expanded",
+ G_CALLBACK (wxdataview_row_expanded_callback), this);
+
+ g_signal_connect (m_treeview, "motion_notify_event",
+ G_CALLBACK (gtk_dataview_motion_notify_callback), this);
+
+ g_signal_connect (m_treeview, "button_press_event",
+ G_CALLBACK (gtk_dataview_button_press_callback), this);
+
+ return true;
+}
+
+wxDataViewItem wxDataViewCtrl::GTKPathToItem(GtkTreePath *path) const
+{
+ GtkTreeIter iter;
+ return wxDataViewItem(path && m_internal->get_iter(&iter, path)
+ ? iter.user_data
+ : NULL);
+}
+
+void wxDataViewCtrl::OnInternalIdle()
+{
+ wxWindow::OnInternalIdle();
+
+ m_internal->OnInternalIdle();
+
+ unsigned int cols = GetColumnCount();
+ unsigned int i;
+ for (i = 0; i < cols; i++)
+ {
+ wxDataViewColumn *col = GetColumn( i );
+ col->OnInternalIdle();
+ }
+
+ if (m_ensureVisibleDefered.IsOk())
+ {
+ ExpandAncestors(m_ensureVisibleDefered);
+ GtkTreeIter iter;
+ iter.user_data = (gpointer) m_ensureVisibleDefered.GetID();
+ wxGtkTreePath path(m_internal->get_path( &iter ));
+ gtk_tree_view_scroll_to_cell( GTK_TREE_VIEW(m_treeview), path, NULL, false, 0.0, 0.0 );
+ m_ensureVisibleDefered = wxDataViewItem(0);
+ }
+}
+
+bool wxDataViewCtrl::AssociateModel( wxDataViewModel *model )
+{
+ wxDELETE(m_internal);
+
+ if (!wxDataViewCtrlBase::AssociateModel( model ))
+ return false;
+
+ bool fixed = (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) == 0) || (model->IsVirtualListModel()));
+ gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), fixed );
+
+ m_internal = new wxDataViewCtrlInternal( this, model );
+
+ return true;
+}
+
+bool wxDataViewCtrl::EnableDragSource( const wxDataFormat &format )
+{
+ return m_internal->EnableDragSource( format );
+}
+
+bool wxDataViewCtrl::EnableDropTarget( const wxDataFormat &format )
+{
+ return m_internal->EnableDropTarget( format );
+}
+
+bool wxDataViewCtrl::AppendColumn( wxDataViewColumn *col )
+{
+ if (!wxDataViewCtrlBase::AppendColumn(col))
+ return false;
+
+ m_cols.Append( col );
+
+ if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) ) !=
+ GTK_TREE_VIEW_COLUMN_FIXED)
+ {
+ gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), FALSE );
+ }
+
+ gtk_tree_view_append_column( GTK_TREE_VIEW(m_treeview),
+ GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) );
+
+ return true;
+}
+
+bool wxDataViewCtrl::PrependColumn( wxDataViewColumn *col )
+{
+ if (!wxDataViewCtrlBase::PrependColumn(col))
+ return false;
+
+ m_cols.Insert( col );
+
+ if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) ) !=
+ GTK_TREE_VIEW_COLUMN_FIXED)
+ {
+ gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), FALSE );
+ }
+
+ gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview),
+ GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()), 0 );
+
+ return true;
+}
+
+bool wxDataViewCtrl::InsertColumn( unsigned int pos, wxDataViewColumn *col )
+{
+ if (!wxDataViewCtrlBase::InsertColumn(pos,col))
+ return false;
+
+ m_cols.Insert( pos, col );
+
+ if (gtk_tree_view_column_get_sizing( GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) ) !=
+ GTK_TREE_VIEW_COLUMN_FIXED)
+ {
+ gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), FALSE );
+ }
+
+ gtk_tree_view_insert_column( GTK_TREE_VIEW(m_treeview),
+ GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()), pos );
+
+ return true;
+}
+
+unsigned int wxDataViewCtrl::GetColumnCount() const
+{
+ return m_cols.GetCount();
+}
+
+wxDataViewColumn* wxDataViewCtrl::FromGTKColumn(GtkTreeViewColumn *gtk_col) const
+{
+ if ( !gtk_col )
+ return NULL;
+
+ wxDataViewColumnList::const_iterator iter;
+ for (iter = m_cols.begin(); iter != m_cols.end(); ++iter)
+ {
+ wxDataViewColumn *col = *iter;
+ if (GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) == gtk_col)
+ {
+ return col;
+ }
+ }
+
+ wxFAIL_MSG( "No matching column?" );
+
+ return NULL;
+}
+
+wxDataViewColumn* wxDataViewCtrl::GetColumn( unsigned int pos ) const
+{
+ GtkTreeViewColumn *gtk_col = gtk_tree_view_get_column( GTK_TREE_VIEW(m_treeview), pos );
+
+ return FromGTKColumn(gtk_col);
+}
+
+bool wxDataViewCtrl::DeleteColumn( wxDataViewColumn *column )
+{
+ gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview),
+ GTK_TREE_VIEW_COLUMN(column->GetGtkHandle()) );
+
+ m_cols.DeleteObject( column );
+
+ return true;
+}
+
+bool wxDataViewCtrl::ClearColumns()
+{
+ wxDataViewColumnList::iterator iter;
+ for (iter = m_cols.begin(); iter != m_cols.end(); ++iter)
+ {
+ wxDataViewColumn *col = *iter;
+ gtk_tree_view_remove_column( GTK_TREE_VIEW(m_treeview),
+ GTK_TREE_VIEW_COLUMN(col->GetGtkHandle()) );
+ }
+
+ m_cols.Clear();
+
+ return true;
+}
+
+int wxDataViewCtrl::GetColumnPosition( const wxDataViewColumn *column ) const
+{
+ GtkTreeViewColumn *gtk_column = GTK_TREE_VIEW_COLUMN(column->GetGtkHandle());
+
+ wxGtkList list(gtk_tree_view_get_columns(GTK_TREE_VIEW(m_treeview)));
+
+ return g_list_index( list, (gconstpointer) gtk_column );
+}
+
+wxDataViewColumn *wxDataViewCtrl::GetSortingColumn() const
+{
+ return m_internal->GetDataViewSortColumn();
+}
+
+void wxDataViewCtrl::Expand( const wxDataViewItem & item )
+{
+ GtkTreeIter iter;
+ iter.user_data = item.GetID();
+ wxGtkTreePath path(m_internal->get_path( &iter ));
+ gtk_tree_view_expand_row( GTK_TREE_VIEW(m_treeview), path, false );
+}
+
+void wxDataViewCtrl::Collapse( const wxDataViewItem & item )
+{
+ GtkTreeIter iter;
+ iter.user_data = item.GetID();
+ wxGtkTreePath path(m_internal->get_path( &iter ));
+ gtk_tree_view_collapse_row( GTK_TREE_VIEW(m_treeview), path );
+}
+
+bool wxDataViewCtrl::IsExpanded( const wxDataViewItem & item ) const
+{
+ GtkTreeIter iter;
+ iter.user_data = item.GetID();
+ wxGtkTreePath path(m_internal->get_path( &iter ));
+ return gtk_tree_view_row_expanded( GTK_TREE_VIEW(m_treeview), path ) != 0;
+}
+
+wxDataViewItem wxDataViewCtrl::DoGetCurrentItem() const
+{
+ // The tree doesn't have any current item if it hadn't been created yet but
+ // it's arguably not an error to call this function in this case so just
+ // return an invalid item without asserting.
+ if ( !m_treeview )
+ return wxDataViewItem();
+
+ wxGtkTreePath path;
+ gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview), path.ByRef(), NULL);
+
+ return GTKPathToItem(path);
+}
+
+void wxDataViewCtrl::DoSetCurrentItem(const wxDataViewItem& item)
+{
+ wxCHECK_RET( m_treeview,
+ "Current item can't be set before creating the control." );
+
+ // We need to make sure the model knows about this item or the path would
+ // be invalid and gtk_tree_view_set_cursor() would silently do nothing.
+ ExpandAncestors(item);
+
+ // We also need to preserve the existing selection from changing.
+ // Unfortunately the only way to do it seems to use our own selection
+ // function and forbid any selection changes during set cursor call.
+ wxGtkTreeSelectionLock
+ lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview)));
+
+ // Do move the cursor now.
+ GtkTreeIter iter;
+ iter.user_data = item.GetID();
+ wxGtkTreePath path(m_internal->get_path( &iter ));
+
+ gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview), path, NULL, FALSE);
+}
+
+wxDataViewColumn *wxDataViewCtrl::GetCurrentColumn() const
+{
+ // The tree doesn't have any current item if it hadn't been created yet but
+ // it's arguably not an error to call this function in this case so just
+ // return NULL without asserting.
+ if ( !m_treeview )
+ return NULL;
+
+ GtkTreeViewColumn *col;
+ gtk_tree_view_get_cursor(GTK_TREE_VIEW(m_treeview), NULL, &col);
+ return FromGTKColumn(col);
+}
+
+void wxDataViewCtrl::EditItem(const wxDataViewItem& item, const wxDataViewColumn *column)
+{
+ wxCHECK_RET( m_treeview,
+ "Current item can't be set before creating the control." );
+ wxCHECK_RET( item.IsOk(), "invalid item" );
+ wxCHECK_RET( column, "no column provided" );
+
+ // We need to make sure the model knows about this item or the path would
+ // be invalid and gtk_tree_view_set_cursor() would silently do nothing.
+ ExpandAncestors(item);
+
+ GtkTreeViewColumn *gcolumn = GTK_TREE_VIEW_COLUMN(column->GetGtkHandle());
+
+ // We also need to preserve the existing selection from changing.
+ // Unfortunately the only way to do it seems to use our own selection
+ // function and forbid any selection changes during set cursor call.
+ wxGtkTreeSelectionLock
+ lock(gtk_tree_view_get_selection(GTK_TREE_VIEW(m_treeview)));
+
+ // Do move the cursor now.
+ GtkTreeIter iter;
+ iter.user_data = item.GetID();
+ wxGtkTreePath path(m_internal->get_path( &iter ));
+
+ gtk_tree_view_set_cursor(GTK_TREE_VIEW(m_treeview), path, gcolumn, TRUE);
+}
+
+int wxDataViewCtrl::GetSelectedItemsCount() const
+{
+ GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
+
+ return gtk_tree_selection_count_selected_rows(selection);
+}
+
+int wxDataViewCtrl::GetSelections( wxDataViewItemArray & sel ) const
+{
+ sel.Clear();
+
+ GtkTreeSelection *selection = gtk_tree_view_get_selection( GTK_TREE_VIEW(m_treeview) );
+ if (HasFlag(wxDV_MULTIPLE))