Gtk2::CellLayout

Section: User Contributed Perl Documentation (3)
Updated: 2008-05-05
Index Return to Main Contents
 

NAME

Gtk2::CellLayout  

SYNOPSIS

 # This is an abstract interface; the CellLayout interface is
 # implemented by concrete classes like ComboBox and TreeViewColumn.
 # See the discussion for details on creating your own CellLayout.
 # This synopsis assumes you already have an instance in $cell_layout.

 # Add a cell renderer that shows the pixbuf in column 2 of the
 # associated TreeModel.  It will take up only the necessary space
 # ("expand" => FALSE).
 my $cell = Gtk2::CellRendererPixbuf->new ();
 $cell_layout->pack_start ($cell, FALSE);
 $cell_layout->add_attribute ($cell, pixbuf => 2);

 # Add another cell renderer that gets the "text" property from
 # column 3 of the associated TreeModel, and takes up all remaining
 # horizontal space ("expand" => TRUE).
 my $cell = Gtk2::CellRendererText->new (); 
 $cell_layout->pack_start ($cell, TRUE);
 $cell_layout->add_attribute ($cell, text => 3);

 

DESCRIPTION

Gtk2::CellLayout is an interface to be implemented by all objects which want to provide a Gtk2::TreeViewColumn-like API for packing cells, setting attributes and data funcs.  

HIERARCHY

  Glib::Interface
  +----Gtk2::CellLayout

 

METHODS

 

$cell_layout->add_attribute ($cell, $attribute, $column)

* $cell (Gtk2::CellRenderer)
* $attribute (string)
* $column (integer)

Adds an attribute mapping to the list in $cell_layout. The $column is the column of the model from which to get a value, and the $attribute is the property of $cell to be set from the value. So, for example, if column 2 of the model contains strings, you could have the ``text'' attribute of a Gtk2::CellRendererText get its values from column 2.

 

$cell_layout->set_attributes ($cell, ...)

* $cell (Gtk2::CellRenderer)
* ... (list) list of property name and column number pairs.

Sets the pairs in the ... list as the attributes of $cell_layout, as with repeated calls to "add_attribute". All existing attributes are removed, and replaced with the new attributes.

 

$cell_layout->set_cell_data_func ($cell, $func, $func_data=undef)

* $cell (Gtk2::CellRenderer)
* $func (scalar)
* $func_data (scalar)

Sets up $cell_layout to call $func to set up attributes of $cell, instead of the standard attribute mapping. $func may be undef to remove an older callback. $func will receive these parameters:

$cell_layout The cell layout instance
$cell The cell renderer to set up
$model The tree model
$iter TreeIter of the row for which to set the values
$data The $func_data passed to set_cell_data_func
 

$cell_layout->clear

Unsets all the mappings on all renderers on $cell_layout and removes all renderers attached to it.
 

$cell_layout->clear_attributes ($cell)

* $cell (Gtk2::CellRenderer)

Clears all existing attributes previously set with for $cell with "add_attribute" or "set_attributes".

 

$cell_layout->pack_end ($cell, $expand)

* $cell (Gtk2::CellRenderer)
* $expand (boolean)

Like "pack_start", but adds from the end of the layout instead of the beginning.

 

$cell_layout->pack_start ($cell, $expand)

* $cell (Gtk2::CellRenderer)
* $expand (boolean)

Packs $cell into the beginning of $cell_layout. If $expand is false, then $cell is allocated no more space than it needs. Any unused space is divided evenly between cells for which $expand is true.

 

$cell_layout->reorder ($cell, $position)

* $cell (Gtk2::CellRenderer)
* $position (integer)

Re-insert $cell at $position. $cell must already be packed into $cell_layout.

 

CREATING A CUSTOM CELL LAYOUT

GTK+ provides several CellLayout implementations, such as Gtk2::TreeViewColumn and Gtk2::ComboBox. To create your own object that implements the CellLayout interface and therefore can be used to display CellRenderers, you need to add Gtk2::CellLayout to your class's ``interfaces'' list, like this:

  package MyLayout;
  use Gtk2;
  use Glib::Object::Subclass
      Gtk2::Widget::,
      interfaces => [ Gtk2::CellLayout:: ],
      ;

This will cause perl to call several virtual methods with ALL_CAPS_NAMES when GTK+ attempts to perform certain actions. You simply provide (or override) those methods with perl code. The methods map rather directly to the object interface, so it should be easy to figure out what they should do. Those methods are:

PACK_START ($cell_layout, $cell, $expand)
PACK_END ($cell_layout, $cell, $expand)
CLEAR ($cell_layout)
ADD_ATTRIBUTE ($cell_layout, $cell, $attribute, $column)
SET_CELL_DATA_FUNC ($cell_layout, $cell, $func, $data)
CLEAR_ATTRIBUTES ($cell_layout, $cell)
REORDER ($cell_layout, $cell, $position)
list = GET_CELLS ($cell_layout)
 

SEE ALSO

Gtk2, Glib::Interface  

COPYRIGHT

Copyright (C) 2003-2008 by the gtk2-perl team.

This software is licensed under the LGPL. See Gtk2 for a full notice.


 

Index

NAME
SYNOPSIS
DESCRIPTION
HIERARCHY
METHODS
$cell_layout->add_attribute ($cell, $attribute, $column)
$cell_layout->set_attributes ($cell, ...)
$cell_layout->set_cell_data_func ($cell, $func, $func_data=undef)
$cell_layout->clear
$cell_layout->clear_attributes ($cell)
$cell_layout->pack_end ($cell, $expand)
$cell_layout->pack_start ($cell, $expand)
$cell_layout->reorder ($cell, $position)
CREATING A CUSTOM CELL LAYOUT
SEE ALSO
COPYRIGHT

linux.jgfs.net manual pages