ergtkcellrenderertext.c File Reference

#include <glib.h>
#include "ergtk_log.h"
#include "ergtkcellrenderertext.h"
Include dependency graph for ergtkcellrenderertext.c:

Go to the source code of this file.

Data Structures

struct  erGtkCellRendererTextPrivate

Enumerations

enum  prop_t {
  PROP_NOT_USED = 0, PROP_BORDER_WIDTH, PROP_BORDER_OFFSET, PROP_BORDER_COLOR,
  NUM_PROPS, PROP_NOT_USED = 0, PROP_FONT, PROP_HEIGHT,
  PROP_TEXT, PROP_COLOR, NUM_PROPS, PROP_NOT_USED = 0,
  PROP_NAVIGATE_MODE, NUM_PROPS
}

Functions

static void get_property_impl (GObject *object, guint param_id, GValue *value, GParamSpec *pspec)
static void set_property_impl (GObject *object, guint param_id, const GValue *value, GParamSpec *pspec)
static void get_size_impl (GtkCellRenderer *cell, GtkWidget *widget, GdkRectangle *cell_area, gint *x_offset, gint *y_offset, gint *width, gint *height)
static void render_impl (GtkCellRenderer *cell, GdkWindow *window, GtkWidget *widget, GdkRectangle *background_area, GdkRectangle *cell_area, GdkRectangle *expose_area, guint flags)
static void ergtk_cell_renderer_text_class_init (erGtkCellRendererTextClass *klass)
static void ergtk_cell_renderer_text_init (erGtkCellRendererText *thiz)
static void ergtk_cell_renderer_text_finalize (GObject *obj)
GType ergtk_cell_renderer_text_get_type (void)
 Returns the GObject type of an erGtkCellRendererText.
GtkCellRenderer * ergtk_cell_renderer_text_new (const guint n_lines)
 Create a new erGtkCellRendererText object.

Variables

static const gchar * PROPNAME_FONT = "font"
static const gchar * PROPNAME_HEIGHT = "height"
static const gchar * PROPNAME_TEXT = "text"
static const gchar * PROPNAME_COLOR = "foreground"
static GtkCellRendererTextClass * g_parent_class = NULL

Enumeration Type Documentation

enum prop_t

Copyright (C) 2009 iRex Technologies B.V. All rights reserved.

Enumerator:
PROP_NOT_USED 
PROP_BORDER_WIDTH 
PROP_BORDER_OFFSET 
PROP_BORDER_COLOR 
NUM_PROPS 
PROP_NOT_USED 
PROP_FONT 
PROP_HEIGHT 
PROP_TEXT 
PROP_COLOR 
NUM_PROPS 
PROP_NOT_USED 
PROP_NAVIGATE_MODE 
NUM_PROPS 

Definition at line 47 of file ergtkcellrenderertext.c.

00048         {
00049             PROP_NOT_USED = 0,  // not sure whether param_id zero is allowed
00050             PROP_FONT,          // font definition
00051             PROP_HEIGHT,        // line height
00052             PROP_TEXT,          // text to be displayed
00053             PROP_COLOR,
00054             NUM_PROPS
00055         } prop_t;


Function Documentation

static void ergtk_cell_renderer_text_class_init ( erGtkCellRendererTextClass klass  )  [static]

Definition at line 168 of file ergtkcellrenderertext.c.

References ergtk_cell_renderer_text_finalize(), ERGTK_CELL_RENDERER_TEXT_MAX_LINES, g_parent_class, get_property_impl(), get_size_impl(), NUM_PROPS, PROP_COLOR, PROP_FONT, PROP_HEIGHT, PROP_TEXT, PROPNAME_COLOR, PROPNAME_FONT, PROPNAME_HEIGHT, PROPNAME_TEXT, render_impl(), and set_property_impl().

Referenced by ergtk_cell_renderer_text_get_type().

00169 {
00170     GObjectClass         *object_class        = (GObjectClass *) klass;
00171     GtkCellRendererClass *cell_renderer_class = (GtkCellRendererClass *) klass;
00172 
00173     gint        line;
00174     GParamSpec  *pspec;
00175     GString     *prop_name = g_string_new("");
00176     GString     *prop_ext  = g_string_new("");
00177 
00178     // remember parent class struct, needed for chaining up to parent class
00179     g_parent_class = g_type_class_peek_parent(klass);
00180 
00181     // overload some virtual methods
00182     cell_renderer_class->render = render_impl;
00183     cell_renderer_class->get_size = get_size_impl;
00184     object_class->get_property  = get_property_impl;
00185     object_class->set_property  = set_property_impl;
00186     object_class->finalize      = ergtk_cell_renderer_text_finalize;
00187 
00188     // reserve space for instance private data
00189     g_type_class_add_private (klass, sizeof(erGtkCellRendererTextPrivate));
00190 
00191     // install custom properties
00192     for ( line = 0 ; line < ERGTK_CELL_RENDERER_TEXT_MAX_LINES ; line++ )
00193     {
00194         g_string_printf(prop_ext, "-%d", line);
00195 
00196         // font
00197         g_string_assign(prop_name, PROPNAME_FONT);
00198         g_string_append(prop_name, prop_ext->str);
00199         pspec = g_param_spec_string( prop_name->str,
00200                                      prop_name->str,
00201                                      "Font definition for n-th line",
00202                                      "",        // default
00203                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT );
00204         g_object_class_install_property( object_class, PROP_FONT + (line * NUM_PROPS), pspec);
00205 
00206         // line height
00207         g_string_assign(prop_name, PROPNAME_HEIGHT);
00208         g_string_append(prop_name, prop_ext->str);
00209         pspec = g_param_spec_uint( prop_name->str,
00210                                    prop_name->str,
00211                                    "Line height for n-th line",
00212                                    0,      // min.
00213                                    200,    // max.
00214                                    10,     // default
00215                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT );
00216         g_object_class_install_property( object_class, PROP_HEIGHT + (line * NUM_PROPS), pspec);
00217 
00218         // text
00219         g_string_assign(prop_name, PROPNAME_TEXT);
00220         g_string_append(prop_name, prop_ext->str);
00221         pspec = g_param_spec_string( prop_name->str,
00222                                      prop_name->str,
00223                                      "Text for n-th line",
00224                                      "",        // default
00225                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT );
00226         g_object_class_install_property( object_class, PROP_TEXT + (line * NUM_PROPS), pspec);
00227 
00228         // color
00229         g_string_assign(prop_name, PROPNAME_COLOR);
00230         g_string_append(prop_name, prop_ext->str);
00231         pspec = g_param_spec_string( prop_name->str,
00232                                      prop_name->str,
00233                                      "Color for n-th line",
00234                                      "black",      // default
00235                                      G_PARAM_READWRITE | G_PARAM_CONSTRUCT );
00236         g_object_class_install_property( object_class, PROP_COLOR + (line * NUM_PROPS), pspec);
00237     }
00238 
00239     // clean up
00240     if (prop_name) { g_string_free(prop_name, TRUE); }
00241     if (prop_ext ) { g_string_free(prop_ext , TRUE); }
00242 }

Here is the call graph for this function:

Here is the caller graph for this function:

static void ergtk_cell_renderer_text_finalize ( GObject *  obj  )  [static]

Definition at line 268 of file ergtkcellrenderertext.c.

References erGtkCellRendererTextPrivate::color, erGtkCellRendererTextPrivate::details, ERGTK_CELL_RENDERER_TEXT_GET_PRIVATE, ERGTK_CELL_RENDERER_TEXT_MAX_LINES, erGtkCellRendererTextPrivate::font, g_parent_class, IS_ERGTK_CELL_RENDERER_TEXT, and erGtkCellRendererTextPrivate::text.

Referenced by ergtk_cell_renderer_text_class_init().

00269 {
00270     g_return_if_fail( IS_ERGTK_CELL_RENDERER_TEXT(obj) );
00271 
00272     erGtkCellRendererTextPrivate *priv = ERGTK_CELL_RENDERER_TEXT_GET_PRIVATE(obj);
00273 
00274     gint    line;
00275 
00276     // destroy instance data
00277     //   private
00278     for ( line = 0 ; line < ERGTK_CELL_RENDERER_TEXT_MAX_LINES ; line++ )
00279     {
00280         g_free(priv->details[line].font);
00281         g_free(priv->details[line].text);
00282         g_free(priv->details[line].color);
00283     }
00284     //   public: none
00285 
00286     // chain to parent class
00287     ((GObjectClass*)g_parent_class)->finalize( obj );
00288 }

Here is the caller graph for this function:

GType ergtk_cell_renderer_text_get_type ( void   ) 

Returns the GObject type of an erGtkCellRendererText.

---------------------------------------------------------------------------

Name : ergtk_cell_renderer_text_get_type

Parameters:
-- 
Returns:
The GObject type of an erGtkCellRendererText

--------------------------------------------------------------------------

Definition at line 137 of file ergtkcellrenderertext.c.

References ergtk_cell_renderer_text_class_init(), and ergtk_cell_renderer_text_init().

00138 {
00139     static GType class_type = 0;
00140 
00141     if (class_type == 0)
00142     {
00143         static const GTypeInfo class_info =
00144         {
00145             sizeof(erGtkCellRendererTextClass),                     // class_size
00146             NULL,                                                   // base_init
00147             NULL,                                                   // base_finalize
00148             (GClassInitFunc) ergtk_cell_renderer_text_class_init,   // class_init
00149             NULL,                                                   // class_finalize
00150             NULL,                                                   // class_data
00151             sizeof(erGtkCellRendererText),                          // instance_size
00152             0,                                                      // n_preallocs
00153             (GInstanceInitFunc) ergtk_cell_renderer_text_init,      // instance_init
00154             NULL                                                    // value_table
00155         };
00156 
00157         class_type = g_type_register_static( GTK_TYPE_CELL_RENDERER_TEXT,   // parent_type
00158                                              "erGtkCellRendererText",       // type_name
00159                                              &class_info,                   // info
00160                                              0 );                           // flags
00161     }
00162 
00163     return class_type;
00164 }

Here is the call graph for this function:

static void ergtk_cell_renderer_text_init ( erGtkCellRendererText thiz  )  [static]

Definition at line 246 of file ergtkcellrenderertext.c.

References erGtkCellRendererTextPrivate::color, erGtkCellRendererTextPrivate::details, ERGTK_CELL_RENDERER_TEXT_GET_PRIVATE, ERGTK_CELL_RENDERER_TEXT_MAX_LINES, erGtkCellRendererTextPrivate::font, IS_ERGTK_CELL_RENDERER_TEXT, erGtkCellRendererTextPrivate::n_lines, and erGtkCellRendererTextPrivate::text.

Referenced by ergtk_cell_renderer_text_get_type().

00247 {
00248     g_return_if_fail( IS_ERGTK_CELL_RENDERER_TEXT(thiz) );
00249 
00250     erGtkCellRendererTextPrivate *priv = ERGTK_CELL_RENDERER_TEXT_GET_PRIVATE(thiz);
00251 
00252     gint    line;
00253 
00254     // instance data
00255     //   public
00256     //   private
00257     priv->n_lines = 1;
00258     for ( line = 0 ; line < ERGTK_CELL_RENDERER_TEXT_MAX_LINES ; line++ )
00259     {
00260         priv->details[line].font = NULL;
00261         priv->details[line].text = NULL;
00262         priv->details[line].color = NULL;
00263     }
00264 }

Here is the caller graph for this function:

GtkCellRenderer* ergtk_cell_renderer_text_new ( const guint  n_lines  ) 

Create a new erGtkCellRendererText object.

---------------------------------------------------------------------------

Name : ergtk_cell_renderer_text_new

Parameters:
[in] n_lines - the number of text lines to display
Returns:
Pointer to the newly created object, or NULL

--------------------------------------------------------------------------

Definition at line 292 of file ergtkcellrenderertext.c.

References ERGTK_CELL_RENDERER_TEXT_GET_PRIVATE, ERGTK_CELL_RENDERER_TEXT_MAX_LINES, ERGTK_CELL_RENDERER_TEXT_TYPE, and erGtkCellRendererTextPrivate::n_lines.

Referenced by create_back_listview(), create_contentview(), and create_settingsview().

00293 {
00294     erGtkCellRendererText        *thiz = (erGtkCellRendererText*) g_object_new(ERGTK_CELL_RENDERER_TEXT_TYPE, NULL);
00295     erGtkCellRendererTextPrivate *priv = ERGTK_CELL_RENDERER_TEXT_GET_PRIVATE(thiz);
00296 
00297     priv->n_lines = MIN( n_lines, ERGTK_CELL_RENDERER_TEXT_MAX_LINES );
00298 
00299     return (GtkCellRenderer*) thiz;
00300 }

Here is the caller graph for this function:

static void get_property_impl ( GObject *  object,
guint  param_id,
GValue *  value,
GParamSpec *  pspec 
) [static]

Definition at line 304 of file ergtkcellrenderertext.c.

References erGtkCellRendererTextPrivate::color, erGtkCellRendererTextPrivate::details, ERGTK_CELL_RENDERER_TEXT_GET_PRIVATE, ERGTK_CELL_RENDERER_TEXT_MAX_LINES, erGtkCellRendererTextPrivate::font, erGtkCellRendererTextPrivate::height, IS_ERGTK_CELL_RENDERER_TEXT, NUM_PROPS, PROP_COLOR, PROP_FONT, PROP_HEIGHT, PROP_NOT_USED, PROP_TEXT, and erGtkCellRendererTextPrivate::text.

Referenced by ergtk_cell_renderer_text_class_init().

00308 {
00309     g_return_if_fail( IS_ERGTK_CELL_RENDERER_TEXT(object) );
00310 
00311     erGtkCellRendererTextPrivate *priv = ERGTK_CELL_RENDERER_TEXT_GET_PRIVATE(object);
00312 
00313     const gint   line = param_id / NUM_PROPS;
00314     const prop_t prop = param_id % NUM_PROPS;
00315 
00316     if (   prop == PROP_NOT_USED
00317         || line >= ERGTK_CELL_RENDERER_TEXT_MAX_LINES )
00318     {
00319         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
00320         return;
00321     }
00322 
00323     switch (prop)
00324     {
00325         case PROP_FONT:
00326             g_value_set_string (value, priv->details[line].font);
00327             break; 
00328 
00329         case PROP_HEIGHT:
00330             g_value_set_uint (value, priv->details[line].height);
00331             break;
00332 
00333         case PROP_TEXT:
00334             g_value_set_string (value, priv->details[line].text);
00335             break;
00336 
00337         case PROP_COLOR:
00338             g_value_set_string (value, priv->details[line].color);
00339             break;
00340 
00341         default:
00342             ; // ignore
00343     }
00344 }

Here is the caller graph for this function:

static void get_size_impl ( GtkCellRenderer *  cell,
GtkWidget *  widget,
GdkRectangle *  cell_area,
gint *  x_offset,
gint *  y_offset,
gint *  width,
gint *  height 
) [static]

Definition at line 403 of file ergtkcellrenderertext.c.

Referenced by ergtk_cell_renderer_text_class_init().

00410 {
00411     static const int FIXED_HEIGHT = 60;
00412     static const int MIN_WIDTH = 100;
00413     gint calc_width  = cell->xpad * 2 + MIN_WIDTH;
00414     gint calc_height = cell->ypad * 2 + FIXED_HEIGHT;
00415 
00416     if (cell_area && cell_area->width > calc_width) calc_width = cell_area->width;
00417 
00418     if (width) *width = calc_width;
00419     if (height) *height = calc_height;
00420 
00421     if (cell_area) {
00422         if (x_offset) {
00423             *x_offset = cell->xalign * (cell_area->width - calc_width);
00424             *x_offset = MAX (*x_offset, 0);
00425         }
00426 
00427         if (y_offset) {
00428             *y_offset = cell->yalign * (cell_area->height - calc_height);
00429             *y_offset = MAX (*y_offset, 0);
00430         }
00431     }
00432 }

Here is the caller graph for this function:

static void render_impl ( GtkCellRenderer *  cell,
GdkWindow *  window,
GtkWidget *  widget,
GdkRectangle *  background_area,
GdkRectangle *  cell_area,
GdkRectangle *  expose_area,
guint  flags 
) [static]

Definition at line 437 of file ergtkcellrenderertext.c.

References erGtkCellRendererTextPrivate::color, erGtkCellRendererTextPrivate::details, ERGTK_CELL_RENDERER_TEXT_GET_PRIVATE, erGtkCellRendererTextPrivate::font, g_parent_class, erGtkCellRendererTextPrivate::height, IS_ERGTK_CELL_RENDERER_TEXT, LOGPRINTF, erGtkCellRendererTextPrivate::n_lines, PROPNAME_COLOR, PROPNAME_FONT, PROPNAME_TEXT, and erGtkCellRendererTextPrivate::text.

Referenced by ergtk_cell_renderer_text_class_init().

00444 {
00445     g_return_if_fail( IS_ERGTK_CELL_RENDERER_TEXT(cell) );
00446 
00447     erGtkCellRendererText        *thiz = (erGtkCellRendererText *) cell;
00448     erGtkCellRendererTextPrivate *priv = ERGTK_CELL_RENDERER_TEXT_GET_PRIVATE(thiz);
00449 
00450     guint           line;
00451     gint            height;
00452     gboolean        ok;
00453     const gint      max_y          = cell_area->y + cell_area->height;
00454     GdkRectangle    sub_cell_area  = *cell_area;
00455     GdkRectangle    sub_expose_area;
00456     const gchar     *font;
00457     const gchar     *text;
00458     const gchar     *color;
00459     gchar           *font_default = NULL;
00460 
00461     // get default font
00462     g_object_get( thiz,
00463                   PROPNAME_FONT, &font_default,
00464                   NULL );
00465 
00466     // gtkcellrenderertext renderer omits the foreground 
00467     // color for selected lines so they default to black
00468     // to avoid this behaviour, we clear the selected bit
00469     flags &= ~GTK_CELL_RENDERER_SELECTED;
00470 
00471     // render each line of text
00472     for ( line = 0 ; line < priv->n_lines ; line++ )
00473     {
00474         // set properties for this line
00475         font = priv->details[line].font;
00476         if (   font    == NULL
00477             || font[0] == '\0' )
00478         {
00479             font = font_default;
00480         }
00481         text = priv->details[line].text;
00482         if ( text == NULL )
00483         {
00484             text = "";
00485         }
00486         color = priv->details[line].color;
00487         if (color == NULL) color = "black";
00488         g_object_set( thiz,
00489                       PROPNAME_FONT, font,
00490                       PROPNAME_TEXT, text,
00491                       PROPNAME_COLOR, color,
00492                       NULL );
00493         LOGPRINTF("line [%d] font [%s] text [%s] color [%s] flags [%d]", line, font, text, color, flags);
00494         
00495         // determine line height
00496         //TODO gtk_cell_renderer_text_set_fixed_height_from_font( GTK_CELL_RENDERER_TEXT(thiz), 1 );
00497         //TODO gtk_cell_renderer_get_fixed_size( GTK_CELL_RENDERER(thiz), NULL, &height );
00498         height = priv->details[line].height;
00499 
00500         // render current line
00501         sub_cell_area.y      = MIN( sub_cell_area.y,  max_y                    );
00502         sub_cell_area.height = MIN( height,          (max_y - sub_cell_area.y) );
00503         if ( sub_cell_area.height > 0 )
00504         {
00505             sub_expose_area = *expose_area;
00506             ok = gdk_rectangle_intersect( &sub_cell_area, &sub_expose_area, &sub_expose_area );
00507             if (ok)
00508             {
00509                 g_parent_class->parent_class.render( cell,
00510                                                      window,
00511                                                      widget,
00512                                                      background_area,
00513                                                      &sub_cell_area,
00514                                                      &sub_expose_area,
00515                                                      flags );
00516             }
00517         }
00518 
00519         // advance to next line's vertical offset
00520         sub_cell_area.y += sub_cell_area.height;
00521     }
00522 
00523     // restore default font
00524     g_object_set( thiz,
00525                   PROPNAME_FONT, font_default,
00526                   NULL );
00527 
00528     // clean up
00529     g_free(font_default);
00530 
00531 }

Here is the caller graph for this function:

static void set_property_impl ( GObject *  object,
guint  param_id,
const GValue *  value,
GParamSpec *  pspec 
) [static]

Definition at line 348 of file ergtkcellrenderertext.c.

References erGtkCellRendererTextPrivate::color, erGtkCellRendererTextPrivate::details, ERGTK_CELL_RENDERER_TEXT_GET_PRIVATE, ERGTK_CELL_RENDERER_TEXT_MAX_LINES, erGtkCellRendererTextPrivate::font, erGtkCellRendererTextPrivate::height, IS_ERGTK_CELL_RENDERER_TEXT, LOGPRINTF, NUM_PROPS, PROP_COLOR, PROP_FONT, PROP_HEIGHT, PROP_NOT_USED, PROP_TEXT, and erGtkCellRendererTextPrivate::text.

Referenced by ergtk_cell_renderer_text_class_init().

00352 {
00353     g_return_if_fail( IS_ERGTK_CELL_RENDERER_TEXT(object) );
00354 
00355     erGtkCellRendererTextPrivate *priv = ERGTK_CELL_RENDERER_TEXT_GET_PRIVATE(object);
00356 
00357     guint        u;
00358     gchar        **cpp;
00359     const gint   line = param_id / NUM_PROPS;
00360     const prop_t prop = param_id % NUM_PROPS;
00361 
00362     if (   prop == PROP_NOT_USED
00363         || line >= ERGTK_CELL_RENDERER_TEXT_MAX_LINES )
00364     {
00365         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
00366         return;
00367     }
00368 
00369     switch (prop)
00370     {
00371         case PROP_FONT:
00372             cpp = &(priv->details[line].font);
00373             g_free(*cpp);
00374             *cpp = g_strdup(g_value_get_string(value));
00375             LOGPRINTF("font[%d] set to [%s]", line, *cpp);
00376             break; 
00377 
00378         case PROP_HEIGHT:
00379             u = g_value_get_uint(value);
00380             priv->details[line].height = u;
00381             LOGPRINTF("height[%d] set to [%u]", line, u);
00382             break;
00383 
00384         case PROP_TEXT:
00385             cpp = &(priv->details[line].text);
00386             g_free(*cpp);
00387             *cpp = g_strdup(g_value_get_string(value));
00388             LOGPRINTF("text[%d] set to [%s]", line, *cpp);
00389             break;
00390 
00391         case PROP_COLOR:
00392             g_free(priv->details[line].color);
00393             priv->details[line].color = g_strdup(g_value_get_string(value));
00394             break;
00395 
00396         default:
00397             ; // ignore
00398     }
00399 }

Here is the caller graph for this function:


Variable Documentation

GtkCellRendererTextClass* g_parent_class = NULL [static]
const gchar* PROPNAME_COLOR = "foreground" [static]

Definition at line 80 of file ergtkcellrenderertext.c.

Referenced by ergtk_cell_renderer_text_class_init(), and render_impl().

const gchar* PROPNAME_FONT = "font" [static]

Definition at line 77 of file ergtkcellrenderertext.c.

Referenced by ergtk_cell_renderer_text_class_init(), and render_impl().

const gchar* PROPNAME_HEIGHT = "height" [static]

Definition at line 78 of file ergtkcellrenderertext.c.

Referenced by ergtk_cell_renderer_text_class_init().

const gchar* PROPNAME_TEXT = "text" [static]

Definition at line 79 of file ergtkcellrenderertext.c.

Referenced by ergtk_cell_renderer_text_class_init(), and render_impl().

Generated by  doxygen 1.6.2-20100208