+ 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_COMMAND_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_COMMAND_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_COMMAND_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_COMMAND_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_COMMAND_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_COMMAND_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_size_request( child->m_widget, &req );
+
+ GtkAllocation alloc;
+ alloc.x = child->m_x;
+ alloc.y = child->m_y;
+ alloc.width = child->m_width;
+ alloc.height = child->m_height;
+ gtk_widget_size_allocate( child->m_widget, &alloc );
+
+ node = node->GetNext();
+ }
+}
+
+
+//-----------------------------------------------------------------------------
+// "motion_notify_event"
+//-----------------------------------------------------------------------------
+
+static gboolean
+gtk_dataview_motion_notify_callback( GtkWidget *WXUNUSED(widget),
+ GdkEventMotion *gdk_event,
+ wxDataViewCtrl *dv )
+{
+ if (gdk_event->is_hint)
+ {
+ int x = 0;
+ int y = 0;
+ GdkModifierType state;
+ gdk_window_get_pointer(gdk_event->window, &x, &y, &state);
+ gdk_event->x = x;
+ gdk_event->y = y;
+ }
+
+ 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()),
+ (int) gdk_event->x, (int) gdk_event->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_COMMAND_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();
+ }
+ }
+
+ m_cols.Clear();
+
+ delete m_internal;
+}
+
+void wxDataViewCtrl::Init()
+{
+ 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);
+
+#ifdef __WXGTK26__
+#ifndef __WXGTK3__
+ if (!gtk_check_version(2,6,0))
+#endif
+ {
+ bool fixed = (style & wxDV_VARIABLE_LINE_HEIGHT) == 0;
+ gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), fixed );
+ }
+#endif
+
+ 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;
+
+#ifdef __WXGTK26__
+#ifndef __WXGTK3__
+ if (!gtk_check_version(2,6,0))
+#endif
+ {
+ bool fixed = (((GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT) == 0) || (model->IsVirtualListModel()));
+ gtk_tree_view_set_fixed_height_mode( GTK_TREE_VIEW(m_treeview), fixed );
+ }
+#endif
+
+ 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 );
+
+#ifdef __WXGTK26__
+#ifndef __WXGTK3__
+ if (!gtk_check_version(2,6,0))
+#endif
+ {
+ 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 );
+ }
+#endif
+
+ 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 );
+
+#ifdef __WXGTK26__
+#ifndef __WXGTK3__
+ if (!gtk_check_version(2,6,0))
+#endif