~canonical-dx-team/ubuntu/maverick/gtk+2.0/menuproxy

« back to all changes in this revision

Viewing changes to gtk/gtkcellrenderer.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-05-04 12:24:25 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20070504122425-0m8midgzrp40y8w2
Tags: 2.10.12-1ubuntu1
* Sync with Debian
* New upstream version:
  Fixed bugs:
  - 379414 file chooser warnings when changing path in the entry
  - 418585 GtkFileChooserDefault sizing code is not DPI independent
  - 419568 Crash in search if start with special letter
  - 435062 build dies with icon cache validation
  - 379399 Segfault to call gtk_print_operation_run twice.
  - 387889 cups backend has problems when there are too many printers
  - 418531 invalid read to gtkicontheme.c gtk_icon_theme_lookup_icon...
  - 423916 crash in color scheme code
  - 424042 Segmentation fault while quickly pressing Alt+arrows
  - 415260 Protect against negative indices when setting values in G...
  - 419171 XGetVisualInfo() may not set nxvisuals
  - 128852 Gdk cursors don't look good on win32
  - 344657 Ctrl-H doesn't toggle "Show Hidden Files" setting
  - 345345 PrintOperation::paginate is not emitted for class handler
  - 347567 GtkPrintOperation::end-print is not emitted if it's cance...
  - 369112 gtk_ui_manager_add_ui should accept unnamed separator
  - 392015 Selected menu item invisible on Windows Vista
  - 399253 MS-Windows Theme Bottom Tab placement rendering glitches
  - 399425 gtk_input_dialog_fill_axes() adds child to gtkscrolledwin...
  - 403251 [patch] little memory leak in GtkPrintJob
  - 403267 [patch] memory leak in GtkPageSetupUnixDialog
  - 403470 MS-Windows Theme tab placement other than on top leaks a ...
  - 404506 Windows system fonts that have multi-byte font names cann...
  - 405089 Incorrect window placement for GtkEventBox private window
  - 405515 Minor leak in gtkfilesystemmodel.c
  - 405539 gdk_pixbuf_save() for PNG saver can return FALSE without ...
  - 415681 gdk_window_clear_area includes an extra line and column o...
  - 418219 GtkRecentChooser should apply filter before sorting and c...
  - 418403 Scroll to printer after selecting it from settings
  - 421985 _gtk_print_operation_platform_backend_launch_preview
  - 421990 gtk_print_job_get_surface
  - 421993 gtk_print_operation_init
  - 423064 Conditional jump or move depends on uninitialised value(s...
  - 423722 Fix printing header in gtk-demo
  - 424168 gtk_print_operation_run on async preview
  - 425655 Don't install gtk+-unix-print-2.0.pc on non-UNIX platforms
  - 425786 GDK segfaults if XineramaQueryScreens fails
  - 428665 Lpr Backend gets stuck in infinite loop during gtk_enumer...
  - 429902 GtkPrintOperation leaks cairo contextes
  - 431997 First delay of GdkPixbufAnimationIter is wrong
  - 433242 Inconsistent scroll arrow position calculations
  - 433972 Placing gtk.Expander inside a gtk.TextView() changes gtk....
  - 434261 _gtk_toolbar_elide_underscores incorrectly handles some s...
  - 383354 ctrl-L should make 'Location' entry disappear
  - 418673 gtk_recent_manager_add_item
  - 429732 gtk_accel_group_finalize accesses invalid memory
  - 435028 WM_CLIENT_LEADER is wrong on the leader_window
  - 431067 Background of the header window is not updated
  - 338843 add recent files support inside the ui manager
  - 148535 add drop shadow to menus, tooltips, etc. under Windows XP
* debian/control.in:
  - Conflicts on ubuntulooks (<= 0.9.11-1)
* debian/patches/15_default-fallback-icon-theme.patch:
  - patch from Debian, fallback on gnome icon theme

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* gtkcellrenderer.c
 
2
 * Copyright (C) 2000  Red Hat, Inc. Jonathan Blandford
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Library General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Library General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Library General Public
 
15
 * License along with this library; if not, write to the
 
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 * Boston, MA 02111-1307, USA.
 
18
 */
 
19
 
 
20
#include <config.h>
 
21
#include "gtkcellrenderer.h"
 
22
#include "gtkintl.h"
 
23
#include "gtkmarshalers.h"
 
24
#include "gtkprivate.h"
 
25
#include "gtktreeprivate.h"
 
26
#include "gtkalias.h"
 
27
 
 
28
static void gtk_cell_renderer_get_property  (GObject              *object,
 
29
                                             guint                 param_id,
 
30
                                             GValue               *value,
 
31
                                             GParamSpec           *pspec);
 
32
static void gtk_cell_renderer_set_property  (GObject              *object,
 
33
                                             guint                 param_id,
 
34
                                             const GValue         *value,
 
35
                                             GParamSpec           *pspec);
 
36
static void set_cell_bg_color               (GtkCellRenderer      *cell,
 
37
                                             GdkColor             *color);
 
38
 
 
39
 
 
40
#define GTK_CELL_RENDERER_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CELL_RENDERER, GtkCellRendererPrivate))
 
41
 
 
42
typedef struct _GtkCellRendererPrivate GtkCellRendererPrivate;
 
43
struct _GtkCellRendererPrivate
 
44
{
 
45
  GdkColor cell_background;
 
46
};
 
47
 
 
48
 
 
49
enum {
 
50
  PROP_ZERO,
 
51
  PROP_MODE,
 
52
  PROP_VISIBLE,
 
53
  PROP_SENSITIVE,
 
54
  PROP_XALIGN,
 
55
  PROP_YALIGN,
 
56
  PROP_XPAD,
 
57
  PROP_YPAD,
 
58
  PROP_WIDTH,
 
59
  PROP_HEIGHT,
 
60
  PROP_IS_EXPANDER,
 
61
  PROP_IS_EXPANDED,
 
62
  PROP_CELL_BACKGROUND,
 
63
  PROP_CELL_BACKGROUND_GDK,
 
64
  PROP_CELL_BACKGROUND_SET
 
65
};
 
66
 
 
67
/* Signal IDs */
 
68
enum {
 
69
  EDITING_CANCELED,
 
70
  EDITING_STARTED,
 
71
  LAST_SIGNAL
 
72
};
 
73
 
 
74
static guint cell_renderer_signals[LAST_SIGNAL] = { 0 };
 
75
 
 
76
G_DEFINE_ABSTRACT_TYPE (GtkCellRenderer, gtk_cell_renderer, GTK_TYPE_OBJECT)
 
77
 
 
78
static void
 
79
gtk_cell_renderer_init (GtkCellRenderer *cell)
 
80
{
 
81
  cell->mode = GTK_CELL_RENDERER_MODE_INERT;
 
82
  cell->visible = TRUE;
 
83
  cell->width = -1;
 
84
  cell->height = -1;
 
85
  cell->xalign = 0.5;
 
86
  cell->yalign = 0.5;
 
87
  cell->xpad = 0;
 
88
  cell->ypad = 0;
 
89
  cell->sensitive = TRUE;
 
90
  cell->is_expander = FALSE;
 
91
  cell->is_expanded = FALSE;
 
92
  cell->editing = FALSE;
 
93
}
 
94
 
 
95
static void
 
96
gtk_cell_renderer_class_init (GtkCellRendererClass *class)
 
97
{
 
98
  GObjectClass *object_class = G_OBJECT_CLASS (class);
 
99
 
 
100
  object_class->get_property = gtk_cell_renderer_get_property;
 
101
  object_class->set_property = gtk_cell_renderer_set_property;
 
102
 
 
103
  class->render = NULL;
 
104
  class->get_size = NULL;
 
105
 
 
106
  /**
 
107
   * GtkCellRenderer::editing-canceled:
 
108
   * @renderer: the object which received the signal
 
109
   *
 
110
   * This signal gets emitted when the user cancels the process of editing a
 
111
   * cell.  For example, an editable cell renderer could be written to cancel
 
112
   * editing when the user presses Escape. 
 
113
   *
 
114
   * See also: gtk_cell_renderer_editing_canceled()
 
115
   *
 
116
   * Since: 2.4
 
117
   */
 
118
  cell_renderer_signals[EDITING_CANCELED] =
 
119
    g_signal_new (I_("editing-canceled"),
 
120
                  G_OBJECT_CLASS_TYPE (object_class),
 
121
                  G_SIGNAL_RUN_FIRST,
 
122
                  G_STRUCT_OFFSET (GtkCellRendererClass, editing_canceled),
 
123
                  NULL, NULL,
 
124
                  _gtk_marshal_VOID__VOID,
 
125
                  G_TYPE_NONE, 0);
 
126
 
 
127
  /**
 
128
   * GtkCellRenderer::editing-started:
 
129
   * @renderer: the object which received the signal
 
130
   * @editable: the #GtkCellEditable
 
131
   * @path: the path identifying the edited cell
 
132
   *
 
133
   * This signal gets emitted when a cell starts to be edited.
 
134
   * The indended use of this signal is to do special setup
 
135
   * on @editable, e.g. adding a #GtkEntryCompletion or setting
 
136
   * up additional columns in a #GtkComboBox.
 
137
   *
 
138
   * Note that GTK+ doesn't guarantee that cell renderers will
 
139
   * continue to use the same kind of widget for editing in future
 
140
   * releases, therefore you should check the type of @editable
 
141
   * before doing any specific setup, as in the following example:
 
142
   *
 
143
   * <informalexample><programlisting>
 
144
   * static void
 
145
   * text_editing_started (GtkCellRenderer *cell,
 
146
   *                       GtkCellEditable *editable,
 
147
   *                       const gchar     *path,
 
148
   *                       gpointer         data)
 
149
   * {
 
150
   *   if (GTK_IS_ENTRY (editable)) 
 
151
   *     {
 
152
   *       GtkEntry *entry = GTK_ENTRY (editable);
 
153
   *       <!-- -->
 
154
   *       /<!-- -->* ... create a GtkEntryCompletion *<!-- -->/
 
155
   *       <!-- -->
 
156
   *       gtk_entry_set_completion (entry, completion);
 
157
   *     }
 
158
   * }
 
159
   * </programlisting></informalexample>
 
160
   *
 
161
   * Since: 2.6
 
162
   */
 
163
  cell_renderer_signals[EDITING_STARTED] =
 
164
    g_signal_new (I_("editing-started"),
 
165
                  G_OBJECT_CLASS_TYPE (object_class),
 
166
                  G_SIGNAL_RUN_FIRST,
 
167
                  G_STRUCT_OFFSET (GtkCellRendererClass, editing_started),
 
168
                  NULL, NULL,
 
169
                  _gtk_marshal_VOID__OBJECT_STRING,
 
170
                  G_TYPE_NONE, 2,
 
171
                  GTK_TYPE_CELL_EDITABLE,
 
172
                  G_TYPE_STRING);
 
173
 
 
174
  g_object_class_install_property (object_class,
 
175
                                   PROP_MODE,
 
176
                                   g_param_spec_enum ("mode",
 
177
                                                      P_("mode"),
 
178
                                                      P_("Editable mode of the CellRenderer"),
 
179
                                                      GTK_TYPE_CELL_RENDERER_MODE,
 
180
                                                      GTK_CELL_RENDERER_MODE_INERT,
 
181
                                                      GTK_PARAM_READWRITE));
 
182
 
 
183
  g_object_class_install_property (object_class,
 
184
                                   PROP_VISIBLE,
 
185
                                   g_param_spec_boolean ("visible",
 
186
                                                         P_("visible"),
 
187
                                                         P_("Display the cell"),
 
188
                                                         TRUE,
 
189
                                                         GTK_PARAM_READWRITE));
 
190
  g_object_class_install_property (object_class,
 
191
                                   PROP_SENSITIVE,
 
192
                                   g_param_spec_boolean ("sensitive",
 
193
                                                         P_("Sensitive"),
 
194
                                                         P_("Display the cell sensitive"),
 
195
                                                         TRUE,
 
196
                                                         GTK_PARAM_READWRITE));
 
197
 
 
198
  g_object_class_install_property (object_class,
 
199
                                   PROP_XALIGN,
 
200
                                   g_param_spec_float ("xalign",
 
201
                                                       P_("xalign"),
 
202
                                                       P_("The x-align"),
 
203
                                                       0.0,
 
204
                                                       1.0,
 
205
                                                       0.5,
 
206
                                                       GTK_PARAM_READWRITE));
 
207
 
 
208
  g_object_class_install_property (object_class,
 
209
                                   PROP_YALIGN,
 
210
                                   g_param_spec_float ("yalign",
 
211
                                                       P_("yalign"),
 
212
                                                       P_("The y-align"),
 
213
                                                       0.0,
 
214
                                                       1.0,
 
215
                                                       0.5,
 
216
                                                       GTK_PARAM_READWRITE));
 
217
 
 
218
  g_object_class_install_property (object_class,
 
219
                                   PROP_XPAD,
 
220
                                   g_param_spec_uint ("xpad",
 
221
                                                      P_("xpad"),
 
222
                                                      P_("The xpad"),
 
223
                                                      0,
 
224
                                                      G_MAXUINT,
 
225
                                                      0,
 
226
                                                      GTK_PARAM_READWRITE));
 
227
 
 
228
  g_object_class_install_property (object_class,
 
229
                                   PROP_YPAD,
 
230
                                   g_param_spec_uint ("ypad",
 
231
                                                      P_("ypad"),
 
232
                                                      P_("The ypad"),
 
233
                                                      0,
 
234
                                                      G_MAXUINT,
 
235
                                                      0,
 
236
                                                      GTK_PARAM_READWRITE));
 
237
 
 
238
  g_object_class_install_property (object_class,
 
239
                                   PROP_WIDTH,
 
240
                                   g_param_spec_int ("width",
 
241
                                                     P_("width"),
 
242
                                                     P_("The fixed width"),
 
243
                                                     -1,
 
244
                                                     G_MAXINT,
 
245
                                                     -1,
 
246
                                                     GTK_PARAM_READWRITE));
 
247
 
 
248
  g_object_class_install_property (object_class,
 
249
                                   PROP_HEIGHT,
 
250
                                   g_param_spec_int ("height",
 
251
                                                     P_("height"),
 
252
                                                     P_("The fixed height"),
 
253
                                                     -1,
 
254
                                                     G_MAXINT,
 
255
                                                     -1,
 
256
                                                     GTK_PARAM_READWRITE));
 
257
 
 
258
  g_object_class_install_property (object_class,
 
259
                                   PROP_IS_EXPANDER,
 
260
                                   g_param_spec_boolean ("is-expander",
 
261
                                                         P_("Is Expander"),
 
262
                                                         P_("Row has children"),
 
263
                                                         FALSE,
 
264
                                                         GTK_PARAM_READWRITE));
 
265
 
 
266
 
 
267
  g_object_class_install_property (object_class,
 
268
                                   PROP_IS_EXPANDED,
 
269
                                   g_param_spec_boolean ("is-expanded",
 
270
                                                         P_("Is Expanded"),
 
271
                                                         P_("Row is an expander row, and is expanded"),
 
272
                                                         FALSE,
 
273
                                                         GTK_PARAM_READWRITE));
 
274
 
 
275
  g_object_class_install_property (object_class,
 
276
                                   PROP_CELL_BACKGROUND,
 
277
                                   g_param_spec_string ("cell-background",
 
278
                                                        P_("Cell background color name"),
 
279
                                                        P_("Cell background color as a string"),
 
280
                                                        NULL,
 
281
                                                        GTK_PARAM_WRITABLE));
 
282
 
 
283
  g_object_class_install_property (object_class,
 
284
                                   PROP_CELL_BACKGROUND_GDK,
 
285
                                   g_param_spec_boxed ("cell-background-gdk",
 
286
                                                       P_("Cell background color"),
 
287
                                                       P_("Cell background color as a GdkColor"),
 
288
                                                       GDK_TYPE_COLOR,
 
289
                                                       GTK_PARAM_READWRITE));
 
290
 
 
291
 
 
292
#define ADD_SET_PROP(propname, propval, nick, blurb) g_object_class_install_property (object_class, propval, g_param_spec_boolean (propname, nick, blurb, FALSE, GTK_PARAM_READWRITE))
 
293
 
 
294
  ADD_SET_PROP ("cell-background-set", PROP_CELL_BACKGROUND_SET,
 
295
                P_("Cell background set"),
 
296
                P_("Whether this tag affects the cell background color"));
 
297
 
 
298
  g_type_class_add_private (object_class, sizeof (GtkCellRendererPrivate));
 
299
}
 
300
 
 
301
static void
 
302
gtk_cell_renderer_get_property (GObject     *object,
 
303
                                guint        param_id,
 
304
                                GValue      *value,
 
305
                                GParamSpec  *pspec)
 
306
{
 
307
  GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
 
308
  GtkCellRendererPrivate *priv = GTK_CELL_RENDERER_GET_PRIVATE (object);
 
309
 
 
310
  switch (param_id)
 
311
    {
 
312
    case PROP_MODE:
 
313
      g_value_set_enum (value, cell->mode);
 
314
      break;
 
315
    case PROP_VISIBLE:
 
316
      g_value_set_boolean (value, cell->visible);
 
317
      break;
 
318
    case PROP_SENSITIVE:
 
319
      g_value_set_boolean (value, cell->sensitive);
 
320
      break;
 
321
    case PROP_XALIGN:
 
322
      g_value_set_float (value, cell->xalign);
 
323
      break;
 
324
    case PROP_YALIGN:
 
325
      g_value_set_float (value, cell->yalign);
 
326
      break;
 
327
    case PROP_XPAD:
 
328
      g_value_set_uint (value, cell->xpad);
 
329
      break;
 
330
    case PROP_YPAD:
 
331
      g_value_set_uint (value, cell->ypad);
 
332
      break;
 
333
    case PROP_WIDTH:
 
334
      g_value_set_int (value, cell->width);
 
335
      break;
 
336
    case PROP_HEIGHT:
 
337
      g_value_set_int (value, cell->height);
 
338
      break;
 
339
    case PROP_IS_EXPANDER:
 
340
      g_value_set_boolean (value, cell->is_expander);
 
341
      break;
 
342
    case PROP_IS_EXPANDED:
 
343
      g_value_set_boolean (value, cell->is_expanded);
 
344
      break;
 
345
    case PROP_CELL_BACKGROUND_GDK:
 
346
      {
 
347
        GdkColor color;
 
348
 
 
349
        color.red = priv->cell_background.red;
 
350
        color.green = priv->cell_background.green;
 
351
        color.blue = priv->cell_background.blue;
 
352
 
 
353
        g_value_set_boxed (value, &color);
 
354
      }
 
355
      break;
 
356
    case PROP_CELL_BACKGROUND_SET:
 
357
      g_value_set_boolean (value, cell->cell_background_set);
 
358
      break;
 
359
    case PROP_CELL_BACKGROUND:
 
360
    default:
 
361
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
 
362
      break;
 
363
    }
 
364
 
 
365
}
 
366
 
 
367
static void
 
368
gtk_cell_renderer_set_property (GObject      *object,
 
369
                                guint         param_id,
 
370
                                const GValue *value,
 
371
                                GParamSpec   *pspec)
 
372
{
 
373
  GtkCellRenderer *cell = GTK_CELL_RENDERER (object);
 
374
 
 
375
  switch (param_id)
 
376
    {
 
377
    case PROP_MODE:
 
378
      cell->mode = g_value_get_enum (value);
 
379
      break;
 
380
    case PROP_VISIBLE:
 
381
      cell->visible = g_value_get_boolean (value);
 
382
      break;
 
383
    case PROP_SENSITIVE:
 
384
      cell->sensitive = g_value_get_boolean (value);
 
385
      break;
 
386
    case PROP_XALIGN:
 
387
      cell->xalign = g_value_get_float (value);
 
388
      break;
 
389
    case PROP_YALIGN:
 
390
      cell->yalign = g_value_get_float (value);
 
391
      break;
 
392
    case PROP_XPAD:
 
393
      cell->xpad = g_value_get_uint (value);
 
394
      break;
 
395
    case PROP_YPAD:
 
396
      cell->ypad = g_value_get_uint (value);
 
397
      break;
 
398
    case PROP_WIDTH:
 
399
      cell->width = g_value_get_int (value);
 
400
      break;
 
401
    case PROP_HEIGHT:
 
402
      cell->height = g_value_get_int (value);
 
403
      break;
 
404
    case PROP_IS_EXPANDER:
 
405
      cell->is_expander = g_value_get_boolean (value);
 
406
      break;
 
407
    case PROP_IS_EXPANDED:
 
408
      cell->is_expanded = g_value_get_boolean (value);
 
409
      break;
 
410
    case PROP_CELL_BACKGROUND:
 
411
      {
 
412
        GdkColor color;
 
413
 
 
414
        if (!g_value_get_string (value))
 
415
          set_cell_bg_color (cell, NULL);
 
416
        else if (gdk_color_parse (g_value_get_string (value), &color))
 
417
          set_cell_bg_color (cell, &color);
 
418
        else
 
419
          g_warning ("Don't know color `%s'", g_value_get_string (value));
 
420
 
 
421
        g_object_notify (object, "cell-background-gdk");
 
422
      }
 
423
      break;
 
424
    case PROP_CELL_BACKGROUND_GDK:
 
425
      set_cell_bg_color (cell, g_value_get_boxed (value));
 
426
      break;
 
427
    case PROP_CELL_BACKGROUND_SET:
 
428
      cell->cell_background_set = g_value_get_boolean (value);
 
429
      break;
 
430
    default:
 
431
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
 
432
      break;
 
433
    }
 
434
}
 
435
 
 
436
static void
 
437
set_cell_bg_color (GtkCellRenderer *cell,
 
438
                   GdkColor        *color)
 
439
{
 
440
  GtkCellRendererPrivate *priv = GTK_CELL_RENDERER_GET_PRIVATE (cell);
 
441
 
 
442
  if (color)
 
443
    {
 
444
      if (!cell->cell_background_set)
 
445
        {
 
446
          cell->cell_background_set = TRUE;
 
447
          g_object_notify (G_OBJECT (cell), "cell-background-set");
 
448
        }
 
449
 
 
450
      priv->cell_background.red = color->red;
 
451
      priv->cell_background.green = color->green;
 
452
      priv->cell_background.blue = color->blue;
 
453
    }
 
454
  else
 
455
    {
 
456
      if (cell->cell_background_set)
 
457
        {
 
458
          cell->cell_background_set = FALSE;
 
459
          g_object_notify (G_OBJECT (cell), "cell-background-set");
 
460
        }
 
461
    }
 
462
}
 
463
 
 
464
/**
 
465
 * gtk_cell_renderer_get_size:
 
466
 * @cell: a #GtkCellRenderer
 
467
 * @widget: the widget the renderer is rendering to
 
468
 * @cell_area: The area a cell will be allocated, or %NULL
 
469
 * @x_offset: location to return x offset of cell relative to @cell_area, or %NULL
 
470
 * @y_offset: location to return y offset of cell relative to @cell_area, or %NULL
 
471
 * @width: location to return width needed to render a cell, or %NULL
 
472
 * @height: location to return height needed to render a cell, or %NULL
 
473
 *
 
474
 * Obtains the width and height needed to render the cell. Used by view widgets
 
475
 * to determine the appropriate size for the cell_area passed to
 
476
 * gtk_cell_renderer_render().  If @cell_area is not %NULL, fills in the x and y
 
477
 * offsets (if set) of the cell relative to this location.  Please note that the
 
478
 * values set in @width and @height, as well as those in @x_offset and @y_offset
 
479
 * are inclusive of the xpad and ypad properties.
 
480
 **/
 
481
void
 
482
gtk_cell_renderer_get_size (GtkCellRenderer *cell,
 
483
                            GtkWidget       *widget,
 
484
                            GdkRectangle    *cell_area,
 
485
                            gint            *x_offset,
 
486
                            gint            *y_offset,
 
487
                            gint            *width,
 
488
                            gint            *height)
 
489
{
 
490
  gint *real_width = width;
 
491
  gint *real_height = height;
 
492
 
 
493
  g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
 
494
  g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->get_size != NULL);
 
495
 
 
496
  if (width && cell->width != -1)
 
497
    {
 
498
      real_width = NULL;
 
499
      *width = cell->width;
 
500
    }
 
501
  if (height && cell->height != -1)
 
502
    {
 
503
      real_height = NULL;
 
504
      *height = cell->height;
 
505
    }
 
506
 
 
507
  GTK_CELL_RENDERER_GET_CLASS (cell)->get_size (cell,
 
508
                                                widget,
 
509
                                                cell_area,
 
510
                                                x_offset,
 
511
                                                y_offset,
 
512
                                                real_width,
 
513
                                                real_height);
 
514
}
 
515
 
 
516
/**
 
517
 * gtk_cell_renderer_render:
 
518
 * @cell: a #GtkCellRenderer
 
519
 * @window: a #GdkDrawable to draw to
 
520
 * @widget: the widget owning @window
 
521
 * @background_area: entire cell area (including tree expanders and maybe padding on the sides)
 
522
 * @cell_area: area normally rendered by a cell renderer
 
523
 * @expose_area: area that actually needs updating
 
524
 * @flags: flags that affect rendering
 
525
 *
 
526
 * Invokes the virtual render function of the #GtkCellRenderer. The three
 
527
 * passed-in rectangles are areas of @window. Most renderers will draw within
 
528
 * @cell_area; the xalign, yalign, xpad, and ypad fields of the #GtkCellRenderer
 
529
 * should be honored with respect to @cell_area. @background_area includes the
 
530
 * blank space around the cell, and also the area containing the tree expander;
 
531
 * so the @background_area rectangles for all cells tile to cover the entire
 
532
 * @window.  @expose_area is a clip rectangle.
 
533
 *
 
534
 **/
 
535
void
 
536
gtk_cell_renderer_render (GtkCellRenderer     *cell,
 
537
                          GdkWindow           *window,
 
538
                          GtkWidget           *widget,
 
539
                          GdkRectangle        *background_area,
 
540
                          GdkRectangle        *cell_area,
 
541
                          GdkRectangle        *expose_area,
 
542
                          GtkCellRendererState flags)
 
543
{
 
544
  gboolean selected = FALSE;
 
545
  GtkCellRendererPrivate *priv = GTK_CELL_RENDERER_GET_PRIVATE (cell);
 
546
 
 
547
  g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
 
548
  g_return_if_fail (GTK_CELL_RENDERER_GET_CLASS (cell)->render != NULL);
 
549
 
 
550
  selected = (flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED;
 
551
 
 
552
  if (cell->cell_background_set && !selected)
 
553
    {
 
554
      cairo_t *cr = gdk_cairo_create (window);
 
555
 
 
556
      gdk_cairo_rectangle (cr, background_area);
 
557
      gdk_cairo_set_source_color (cr, &priv->cell_background);
 
558
      cairo_fill (cr);
 
559
      
 
560
      cairo_destroy (cr);
 
561
    }
 
562
 
 
563
  GTK_CELL_RENDERER_GET_CLASS (cell)->render (cell,
 
564
                                              window,
 
565
                                              widget,
 
566
                                              background_area,
 
567
                                              cell_area,
 
568
                                              expose_area,
 
569
                                              flags);
 
570
}
 
571
 
 
572
/**
 
573
 * gtk_cell_renderer_activate:
 
574
 * @cell: a #GtkCellRenderer
 
575
 * @event: a #GdkEvent
 
576
 * @widget: widget that received the event
 
577
 * @path: widget-dependent string representation of the event location; e.g. for #GtkTreeView, a string representation of #GtkTreePath
 
578
 * @background_area: background area as passed to @gtk_cell_renderer_render
 
579
 * @cell_area: cell area as passed to @gtk_cell_renderer_render
 
580
 * @flags: render flags
 
581
 *
 
582
 * Passes an activate event to the cell renderer for possible processing.  Some
 
583
 * cell renderers may use events; for example, #GtkCellRendererToggle toggles
 
584
 * when it gets a mouse click.
 
585
 *
 
586
 * Return value: %TRUE if the event was consumed/handled
 
587
 **/
 
588
gboolean
 
589
gtk_cell_renderer_activate (GtkCellRenderer      *cell,
 
590
                            GdkEvent             *event,
 
591
                            GtkWidget            *widget,
 
592
                            const gchar          *path,
 
593
                            GdkRectangle         *background_area,
 
594
                            GdkRectangle         *cell_area,
 
595
                            GtkCellRendererState  flags)
 
596
{
 
597
  g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), FALSE);
 
598
 
 
599
  if (cell->mode != GTK_CELL_RENDERER_MODE_ACTIVATABLE)
 
600
    return FALSE;
 
601
 
 
602
  if (GTK_CELL_RENDERER_GET_CLASS (cell)->activate == NULL)
 
603
    return FALSE;
 
604
 
 
605
  return GTK_CELL_RENDERER_GET_CLASS (cell)->activate (cell,
 
606
                                                       event,
 
607
                                                       widget,
 
608
                                                       path,
 
609
                                                       background_area,
 
610
                                                       cell_area,
 
611
                                                       flags);
 
612
}
 
613
 
 
614
/**
 
615
 * gtk_cell_renderer_start_editing:
 
616
 * @cell: a #GtkCellRenderer
 
617
 * @event: a #GdkEvent
 
618
 * @widget: widget that received the event
 
619
 * @path: widget-dependent string representation of the event location; e.g. for #GtkTreeView, a string representation of #GtkTreePath
 
620
 * @background_area: background area as passed to @gtk_cell_renderer_render
 
621
 * @cell_area: cell area as passed to @gtk_cell_renderer_render
 
622
 * @flags: render flags
 
623
 * 
 
624
 * Passes an activate event to the cell renderer for possible processing.
 
625
 * 
 
626
 * Return value: A new #GtkCellEditable, or %NULL
 
627
 **/
 
628
GtkCellEditable *
 
629
gtk_cell_renderer_start_editing (GtkCellRenderer      *cell,
 
630
                                 GdkEvent             *event,
 
631
                                 GtkWidget            *widget,
 
632
                                 const gchar          *path,
 
633
                                 GdkRectangle         *background_area,
 
634
                                 GdkRectangle         *cell_area,
 
635
                                 GtkCellRendererState  flags)
 
636
 
 
637
{
 
638
  GtkCellEditable *editable;
 
639
 
 
640
  g_return_val_if_fail (GTK_IS_CELL_RENDERER (cell), NULL);
 
641
 
 
642
  if (cell->mode != GTK_CELL_RENDERER_MODE_EDITABLE)
 
643
    return NULL;
 
644
 
 
645
  if (GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing == NULL)
 
646
    return NULL;
 
647
 
 
648
  editable = GTK_CELL_RENDERER_GET_CLASS (cell)->start_editing (cell,
 
649
                                                                event,
 
650
                                                                widget,
 
651
                                                                path,
 
652
                                                                background_area,
 
653
                                                                cell_area,
 
654
                                                                flags);
 
655
 
 
656
  g_signal_emit (cell, 
 
657
                 cell_renderer_signals[EDITING_STARTED], 0,
 
658
                 editable, path);
 
659
 
 
660
  cell->editing = TRUE;
 
661
 
 
662
  return editable;
 
663
}
 
664
 
 
665
/**
 
666
 * gtk_cell_renderer_set_fixed_size:
 
667
 * @cell: A #GtkCellRenderer
 
668
 * @width: the width of the cell renderer, or -1
 
669
 * @height: the height of the cell renderer, or -1
 
670
 * 
 
671
 * Sets the renderer size to be explicit, independent of the properties set.
 
672
 **/
 
673
void
 
674
gtk_cell_renderer_set_fixed_size (GtkCellRenderer *cell,
 
675
                                  gint             width,
 
676
                                  gint             height)
 
677
{
 
678
  g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
 
679
  g_return_if_fail (width >= -1 && height >= -1);
 
680
 
 
681
  if ((width != cell->width) || (height != cell->height))
 
682
    {
 
683
      g_object_freeze_notify (G_OBJECT (cell));
 
684
 
 
685
      if (width != cell->width)
 
686
        {
 
687
          cell->width = width;
 
688
          g_object_notify (G_OBJECT (cell), "width");
 
689
        }
 
690
 
 
691
      if (height != cell->height)
 
692
        {
 
693
          cell->height = height;
 
694
          g_object_notify (G_OBJECT (cell), "height");
 
695
        }
 
696
 
 
697
      g_object_thaw_notify (G_OBJECT (cell));
 
698
    }
 
699
}
 
700
 
 
701
/**
 
702
 * gtk_cell_renderer_get_fixed_size:
 
703
 * @cell: A #GtkCellRenderer
 
704
 * @width: location to fill in with the fixed width of the widget, or %NULL
 
705
 * @height: location to fill in with the fixed height of the widget, or %NULL
 
706
 * 
 
707
 * Fills in @width and @height with the appropriate size of @cell.
 
708
 **/
 
709
void
 
710
gtk_cell_renderer_get_fixed_size (GtkCellRenderer *cell,
 
711
                                  gint            *width,
 
712
                                  gint            *height)
 
713
{
 
714
  g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
 
715
 
 
716
  if (width)
 
717
    (* width) = cell->width;
 
718
  if (height)
 
719
    (* height) = cell->height;
 
720
}
 
721
 
 
722
/**
 
723
 * gtk_cell_renderer_editing_canceled:
 
724
 * @cell: A #GtkCellRenderer
 
725
 * 
 
726
 * Causes the cell renderer to emit the "editing-canceled" signal.  This
 
727
 * function is for use only by implementations of cell renderers that need to
 
728
 * notify the client program that an editing process was canceled and the
 
729
 * changes were not committed.
 
730
 *
 
731
 * Since: 2.4
 
732
 * Deprecated: 2.6: Use gtk_cell_renderer_stop_editing() instead
 
733
 **/
 
734
void
 
735
gtk_cell_renderer_editing_canceled (GtkCellRenderer *cell)
 
736
{
 
737
  g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
 
738
 
 
739
  gtk_cell_renderer_stop_editing (cell, TRUE);
 
740
}
 
741
 
 
742
/**
 
743
 * gtk_cell_renderer_stop_editing:
 
744
 * @cell: A #GtkCellRenderer
 
745
 * @canceled: %TRUE if the editing has been canceled
 
746
 * 
 
747
 * Informs the cell renderer that the editing is stopped.
 
748
 * If @canceled is %TRUE, the cell renderer will emit the "editing-canceled" 
 
749
 * signal. This function should be called by cell renderer implementations 
 
750
 * in response to the "editing-done" signal of #GtkCellEditable.
 
751
 *
 
752
 * Since: 2.6
 
753
 **/
 
754
void
 
755
gtk_cell_renderer_stop_editing (GtkCellRenderer *cell,
 
756
                                gboolean         canceled)
 
757
{
 
758
  g_return_if_fail (GTK_IS_CELL_RENDERER (cell));
 
759
 
 
760
  if (cell->editing)
 
761
    {
 
762
      cell->editing = FALSE;
 
763
      if (canceled)
 
764
        g_signal_emit (cell, cell_renderer_signals[EDITING_CANCELED], 0);
 
765
    }
 
766
}
 
767
 
 
768
#define __GTK_CELL_RENDERER_C__
 
769
#include "gtkaliasdef.c"