Next: , Previous: GtkCellLayout, Up: Top


43 GtkCellRenderer

An object for rendering a single cell on a

43.1 Overview

The <gtk-cell-renderer> is a base class of a set of objects used for rendering a cell to a <gdk-drawable>. These objects are used primarily by the <gtk-tree-view> widget, though they aren't tied to them in any specific way. It is worth noting that <gtk-cell-renderer> is not a <gtk-widget> and cannot be treated as such.

The primary use of a <gtk-cell-renderer> is for drawing a certain graphical elements on a <gdk-drawable>. Typically, one cell renderer is used to draw many cells on the screen. To this extent, it isn't expected that a CellRenderer keep any permanent state around. Instead, any state is set just prior to use using <gobject>s property system. Then, the cell is measured using gtk-cell-renderer-get-size. Finally, the cell is rendered in the correct location using gtk-cell-renderer-render.

There are a number of rules that must be followed when writing a new <gtk-cell-renderer>. First and formost, it's important that a certain set of properties will always yield a cell renderer of the same size, barring a <gtk-style> change. The <gtk-cell-renderer> also has a number of generic properties that are expected to be honored by all children.

Beyond merely rendering a cell, cell renderers can optionally provide active user interface elements. A cell renderer can be activatable like <gtk-cell-renderer-toggle>, which toggles when it gets activated by a mouse click, or it can be editable like <gtk-cell-renderer-text>, which allows the user to edit the text using a <gtk-entry>. To make a cell renderer activatable or editable, you have to implement the activate or start-editing virtual functions, respectively.

43.2 Usage

— Class: <gtk-cell-renderer>

Derives from <gtk-object>.

This class defines the following slots:

mode
Editable mode of the CellRenderer
visible
Display the cell
sensitive
Display the cell sensitive
xalign
The x-align
yalign
The y-align
xpad
The xpad
ypad
The ypad
width
The fixed width
height
The fixed height
is-expander
Row has children
is-expanded
Row is an expander row, and is expanded
cell-background
Cell background color as a string
cell-background-gdk
Cell background color as a GdkColor
cell-background-set
Whether this tag affects the cell background color
— Signal on <gtk-cell-renderer>: editing-canceled

This signal gets emitted when the user cancels the process of editing a cell. For example, an editable cell renderer could be written to cancel editing when the user presses Escape.

See also: gtk-cell-renderer-editing-canceled

Since 2.4

— Signal on <gtk-cell-renderer>: editing-started (arg0 <gtk-cell-editable>) (arg1 <gchararray>)

This signal gets emitted when a cell starts to be edited. The indended use of this signal is to do special setup on editable, e.g. adding a <gtk-entry-completion> or setting up additional columns in a <gtk-combo-box>.

Note that GTK+ doesn't guarantee that cell renderers will continue to use the same kind of widget for editing in future releases, therefore you should check the type of editable before doing any specific setup, as in the following example:

          
          static void
          text_editing_started (GtkCellRenderer *cell,
                                GtkCellEditable *editable,
                                const gchar     *path,
                                gpointer         data)
          {
            if (GTK_IS_ENTRY (editable))
              {
                GtkEntry *entry = GTK_ENTRY (editable);
          
                /* ... create a GtkEntryCompletion */
          
                gtk_entry_set_completion (entry, completion);
              }
          }

Since 2.6

— Function: gtk-cell-renderer-render (self <gtk-cell-renderer>) (window <gdk-window>) (widget <gtk-widget>) (background_area <gdk-rectangle>) (cell_area <gdk-rectangle>) (expose_area <gdk-rectangle>) (flags <gtk-cell-renderer-state>)
— Method: render

Invokes the virtual render function of the <gtk-cell-renderer>. The three passed-in rectangles are areas of window. Most renderers will draw within cell-area; the xalign, yalign, xpad, and ypad fields of the <gtk-cell-renderer> should be honored with respect to cell-area. background-area includes the blank space around the cell, and also the area containing the tree expander; so the background-area rectangles for all cells tile to cover the entire window. expose-area is a clip rectangle.

cell
a <gtk-cell-renderer>
window
a <gdk-drawable> to draw to
widget
the widget owning window
background-area
entire cell area (including tree expanders and maybe padding on the sides)
cell-area
area normally rendered by a cell renderer
expose-area
area that actually needs updating
flags
flags that affect rendering
— Function: gtk-cell-renderer-activate (self <gtk-cell-renderer>) (event <gdk-event>) (widget <gtk-widget>) (path mchars) (background_area <gdk-rectangle>) (cell_area <gdk-rectangle>) (flags <gtk-cell-renderer-state>) ⇒  (ret bool)
— Method: activate

Passes an activate event to the cell renderer for possible processing. Some cell renderers may use events; for example, <gtk-cell-renderer-toggle> toggles when it gets a mouse click.

cell
a <gtk-cell-renderer>
event
a <gdk-event>
widget
widget that received the event
path
widget-dependent string representation of the event location; e.g. for <gtk-tree-view>, a string representation of <gtk-tree-path>
background-area
background area as passed to gtk-cell-renderer-render
cell-area
cell area as passed to gtk-cell-renderer-render
flags
render flags
ret
#t’ if the event was consumed/handled
— Function: gtk-cell-renderer-start-editing (self <gtk-cell-renderer>) (event <gdk-event>) (widget <gtk-widget>) (path mchars) (background_area <gdk-rectangle>) (cell_area <gdk-rectangle>) (flags <gtk-cell-renderer-state>) ⇒  (ret <gtk-cell-editable>)
— Method: start-editing

Passes an activate event to the cell renderer for possible processing.

cell
a <gtk-cell-renderer>
event
a <gdk-event>
widget
widget that received the event
path
widget-dependent string representation of the event location; e.g. for <gtk-tree-view>, a string representation of <gtk-tree-path>
background-area
background area as passed to gtk-cell-renderer-render
cell-area
cell area as passed to gtk-cell-renderer-render
flags
render flags
ret
A new <gtk-cell-editable>, or ‘#f
— Function: gtk-cell-renderer-editing-canceled (self <gtk-cell-renderer>)
— Method: editing-canceled

gtk_cell_renderer_editing_canceled’ has been deprecated since version 2.6 and should not be used in newly-written code. Use gtk-cell-renderer-stop-editing instead

Causes the cell renderer to emit the "editing-canceled" signal. This function is for use only by implementations of cell renderers that need to notify the client program that an editing process was canceled and the changes were not committed.

cell
A <gtk-cell-renderer>

Since 2.4

— Function: gtk-cell-renderer-stop-editing (self <gtk-cell-renderer>) (canceled bool)
— Method: stop-editing

Informs the cell renderer that the editing is stopped. If canceled is ‘#t’, the cell renderer will emit the "editing-canceled" signal. This function should be called by cell renderer implementations in response to the "editing-done" signal of <gtk-cell-editable>.

cell
A <gtk-cell-renderer>
canceled
#t’ if the editing has been canceled

Since 2.6

— Function: gtk-cell-renderer-get-fixed-size (self <gtk-cell-renderer>) ⇒  (width int) (height int)
— Method: get-fixed-size

Fills in width and height with the appropriate size of cell.

cell
A <gtk-cell-renderer>
width
location to fill in with the fixed width of the widget, or ‘#f
height
location to fill in with the fixed height of the widget, or ‘#f
— Function: gtk-cell-renderer-set-fixed-size (self <gtk-cell-renderer>) (width int) (height int)
— Method: set-fixed-size

Sets the renderer size to be explicit, independent of the properties set.

cell
A <gtk-cell-renderer>
width
the width of the cell renderer, or -1
height
the height of the cell renderer, or -1