Re: Subclassing a Gtk2::TreeStore




On Mon, 2007-10-29 at 14:50 +0100, Torsten Schoenfeld wrote:

I don't think my code is where I need it to be overridden. I don't have
any plans to call drag_data_received. It's called automatically by gtk+
as part of the treeview drag'n'drop mechanism. What I do want to do is
influence what it does. From what you say, I suspect I can't to this.

I see.  Unfortunately, it doesn't seem to be possible to override just
one interface method of some class (like row-drop-possible).  You have
to implement the whole interface, and that means implementing a
completely custom tree model.

in C, I would just subclass GtkListStore with:

  G_DEFINE_TYPE_WITH_CODE (MyListStore,
                           my_list_store,
                           GTK_TYPE_LIST_STORE,
                           G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_DRAG_SOURCE,
                                                  gtk_tree_drag_source_init));


and in gtk_tree_drag_source_init() I'd override the virtual functions of
the interface.

in Perl I would expect that the following code would be the equivalent:

  use Glib::Object::Subclass
      'Gtk2::ListStore',
      interfaces => [ 'Gtk2::TreeDragSource' ];

and the implementations:

  sub ROW_DRAGGABLE {
    my ($drag_source, $path) = @_;

    return is_my_row_draggable();
  }

  sub DRAG_DATA_GET {
    my ($drag_source, $path, $selection_data) = @_;

    # fill $selection_data with the contents of the $path

    return TRUE;
  }

which, as far as I can see from the code, is the case (usual disclaimer
applies: I haven't tested it with real Perl code). internally, the
TreeView widget will call gtk_tree_drag_source_row_draggable() which
will call into the Perl bindings, which in turn will call the
ROW_DRAGGABLE sub.

this is, by the way, what I meant by "override the override the
Gtk2::TreeDragDest interface method above, in order to control whether
the destination row is a valid drop point" in the original mail.

I'd say that, if this doesn't work, it should be considered a bug of the
Perl bindings, as the code works perfectly fine from C (I used it inside
the GtkFileChooser default implementation for GTK+ 2.12).

ciao,
 Emmanuele.

-- 
Emmanuele Bassi,
W: http://www.emmanuelebassi.net
B: http://log.emmanuelebassi.net




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