Ross McFarland > Gtk2-1.043 > xs/GtkTreeModel.xs

Download:
Gtk2-Perl/Gtk2-1.043.tar.gz

Annotate this POD

CPAN RT

New  1
Open  7
View/Report Bugs
Source   Latest Release: Gtk2-1.203

DESCRIPTION ^

The Gtk2::TreeModel provides a generic tree interface for use by the Gtk2::TreeView widget. It is an abstract interface, designed to be usable with any appropriate data structure.

FIXME FIXME say more here

CREATING A CUSTOM TREE MODEL ^

GTK+ provides two model implementations, Gtk2::TreeStore and Gtk2::ListStore, which should be sufficient in most cases. For some cases, however, it is advantageous to provide a custom tree model implementation. It is possible to create custom tree models in Perl, because we're cool like that.

To do this, you create a Glib::Object derivative which implements the Gtk2::TreeModel interface; this is gtk2-perl-speak for "you have to add a special key when you register your object type." For example:

  package MyModel;
  use Gtk2;
  use Glib::Object::Subclass
      Glib::Object::,
      interfaces => [ Gtk2::TreeModel:: ],
      ;

This will cause perl to call several virtual methods with ALL_CAPS_NAMES when Gtk+ attempts to perform certain actions on the model. You simply provide (or override) those methods.

TREE ITERS

Gtk2::TreeIter is normally an opaque object, but on the implementation side of a Gtk2::TreeModel, you have to define what's inside. The virtual methods described below deal with iters as a reference to an array containing four values:

o stamp (integer)

A number unique to this model.

o user_data (integer)

An arbitrary integer value.

o user_data2 (scalar)

An arbitrary scalar. Will not persist. May be undef.

o user_data3 (scalar)

An arbitrary scalar. Will not persist. May be undef.

VIRTUAL METHODS

An implementation of

treemodelflags = GET_FLAGS ($model)
integer = GET_N_COLUMNS ($model)
string = GET_COLUMN_TYPE ($model, $index)
ARRAYREF = GET_ITER ($model, $path)

See above for a description of what goes in the returned array reference.

treepath = GET_PATH ($model, ARRAYREF)
scalar = GET_VALUE ($model, ARRAYREF, $column)

Implements $treemodel->get().

ARRAYREF = ITER_NEXT ($model, ARRAYREF)
ARRAYREF = ITER_CHILDREN ($model, ARRAYREF)
boolean = ITER_HAS_CHILD ($model, ARRAYREF)
integer = ITER_N_CHILDREN ($model, ARRAYREF)
ARRAYREF = ITER_NTH_CHILD ($model, ARRAYREF, $n)
ARRAYREF = ITER_PARENT ($model, ARRAYREF)
REF_NODE ($model, ARRAYREF)

Optional.

REF_NODE ($model, ARRAYREF)

Optional.

The C API reference docs for this function say to mark the end of the list with a -1, but Perl doesn't need list terminators, so don't do that.

This is specially implemented to be available for all gtk+ versions.

Fetch and return the model's values in the row pointed to by $iter. If you specify no column indices, it returns the values for all of the columns, otherwise, returns just those columns' values (in order).

This overrides overrides Glib::Object's get, so you'll want to use $object->get_property to get object properties.

Emits the "rows-reordered" signal on $tree_model/ This should be called by models with their rows have been reordered.

syntax highlighting: