Re: GtkTreeView and scroll bar



El vie, 19-03-2004 a las 20:27, Federico Mena Quintero escribió:
Hi, Federico
Tkanks for your attention.

> If you use a GtkListStore or GtkTreeStore as your data model, you may
be
> able to just use gtk_tree_view_enable_model_drag_source() and
> gtk_tree_view_enable_model_drag_dest() to enable automatic
> drag-and-drop.  You may also need to do this:
> 

I have define a widget that is subclass of GtkTreeView.
The instance_init method of this class, initialize drag&drop functions :

static void 
_f_widget_article_management_tree_view_init(FWidgetArticleManagementTreeView *f_tree, 
                                           
FWidgetArticleManagementTreeViewClass *klass)
{
  GtkTreeView *treeview = GTK_TREE_VIEW(f_tree);
  GtkTreeSelection *select;

  f_tree->num_columns = 0;
  f_tree->column_ids = NULL;
  
  /* Enable drag and drop */
  gtk_tree_view_enable_model_drag_source (treeview,
                                          GDK_BUTTON1_MASK,
                                          row_targets,
                                          G_N_ELEMENTS (row_targets),
                                          GDK_ACTION_MOVE);

  gtk_tree_view_enable_model_drag_dest (treeview,
                                        row_targets,
                                        G_N_ELEMENTS (row_targets),
                                        GDK_ACTION_MOVE);

> 1. Create a derived class from GtkListStore or GtkTreeStore
> 
> I've create a FWidgetArticleManagementTreeViewModel class, that is 
> a subclass of GtkTreeStore.
> 
> 
GType f_widget_article_management_tree_view_model_get_type(void)
{
  static GType type = 0;
  
  if (type == 0){
    static const GTypeInfo info = {
      sizeof (FWidgetArticleManagementTreeViewModelClass),
      NULL, /* base_init */
      NULL, /* base_finalize */
      (GClassInitFunc)
_f_widget_article_management_tree_view_model_class_init,
      NULL, /* class_finalize */
      NULL, /* class_data */
      sizeof (FWidgetArticleManagementTreeViewModel),
      16,   /* n_preallocs */
      (GInstanceInitFunc)
_f_widget_article_management_tree_view_model_init,
      NULL
    };

    static const GInterfaceInfo drag_source_info = {
      (GInterfaceInitFunc)
_f_widget_article_management_tree_view_model_drag_source_init,
      NULL,
      NULL
    };
    
    static const GInterfaceInfo drag_dest_info = {
      (GInterfaceInitFunc) 
_f_widget_article_management_tree_view_model_drag_dest_init,
      NULL,
      NULL
    };

    type = g_type_register_static (GTK_TYPE_TREE_STORE, 
                                  
"FWidgetArticleManagementTreeViewModel", 
                                   &info, 
                                   (GTypeFlags) 0);

    g_type_add_interface_static (type,
                                 GTK_TYPE_TREE_DRAG_SOURCE,
                                 &drag_source_info);
    g_type_add_interface_static (type,
                                 GTK_TYPE_TREE_DRAG_DEST,
                                 &drag_dest_info);
  }
  else type = g_type_from_name
("FWidgetArticleManagementTreeViewModel");
  
  return type;
}

> 2. Create your own custom implementations of GtkTreeDragSourceIface or
> GtkTreeDragDestIface, overriding the default ones.

I,ve  overriding this methods :

static void
_f_widget_article_management_tree_view_model_drag_source_init
(GtkTreeDragSourceIface *iface)
{
  iface->drag_data_get = 
_f_widget_article_management_tree_view_model_drag_data_get;
  iface->drag_data_delete = 
_f_widget_article_management_tree_view_model_drag_data_delete;
}

static void
_f_widget_article_management_tree_view_model_drag_dest_init
(GtkTreeDragDestIface *iface)
{
  iface->drag_data_received = 
_f_widget_article_management_tree_view_model_drag_data_received;
  iface->row_drop_possible = 
_f_widget_article_management_tree_view_model_row_drop_possible;
}

> If you use gtk_tree_view_enable_model_drag_dest(), then the tree will
be
> scrolled automatically when you drag over it.
> 

I thought that, but my treeview does not change scroll bar on drag&drop
operations.  

> If this doesn't fit your needs, you have to handle the GtkWidget
> drag-and-drop signals yourself.  GtkTreeView has some helper functions
> that you can use to figure out the destination row and such; see
> gtk_tree_view_get_dest_row_at_pos(), for example.  Scrolling by hand
is
> more complicated; you should look at the GtkTreeView sources to see
how
> it's done.
> 
Triying to solve this, i've connect 

g_signal_connect (sections_widget, 
                  "drag_motion",
                  G_CALLBACK
(_f_warehouse_controller_article_management_on_drag_motion),
                  controller);


This function try tu move the scroll bar when drag_motion signal has
been emited. I use 

gtk_tree_view_scroll_to_point(treeview, 5, -1);

however the sroll bar does not move.

I don't know how is the problem. The drag&drop operations were performed
fine. The only problem is the scroll bar. 

Have you got an idea what's may be the problem ?
Thanks.

-- 
Javier Fernandez <jfernandez igalia com>
Igalia



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]