1 /* gtkcellrenderertext.c
2 * Copyright (C) 2000 Red Hat, Inc., Jonathan Blandford <jrb@redhat.com>
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.
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.
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.
23 #include <glib/gi18n-lib.h>
24 #include <gtk/gtkmarshal.h>
25 //#include <gtk/gtkeditable.h>
26 //#include <gtk/gtkentry.h>
27 //#include <gtk/gtkintl.h>
28 //#include <gtk/gtkprivate.h>
29 //#include <gtk/gtktreeprivate.h>
30 //#include <gtk/gtkalias.h>
32 #include "marshalers.h"
33 #include "ghbcellrenderertext.h"
36 #define P_(String) dgettext(GETTEXT_PACKAGE "-properties",String)
38 #define P_(String) (String)
41 #define I_(string) g_intern_static_string (string)
43 #define GTK_PARAM_READABLE G_PARAM_READABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
44 #define GTK_PARAM_WRITABLE G_PARAM_WRITABLE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
45 #define GTK_PARAM_READWRITE G_PARAM_READWRITE|G_PARAM_STATIC_NAME|G_PARAM_STATIC_NICK|G_PARAM_STATIC_BLURB
49 static void ghb_cell_renderer_text_finalize (GObject *object);
51 static void ghb_cell_renderer_text_get_property (GObject *object,
55 static void ghb_cell_renderer_text_set_property (GObject *object,
59 static void ghb_cell_renderer_text_get_size (GtkCellRenderer *cell,
61 GdkRectangle *cell_area,
66 static void ghb_cell_renderer_text_render (GtkCellRenderer *cell,
69 GdkRectangle *background_area,
70 GdkRectangle *cell_area,
71 GdkRectangle *expose_area,
72 GtkCellRendererState flags);
74 static GtkCellEditable *ghb_cell_renderer_text_start_editing (GtkCellRenderer *cell,
78 GdkRectangle *background_area,
79 GdkRectangle *cell_area,
80 GtkCellRendererState flags);
94 PROP_SINGLE_PARAGRAPH_MODE,
122 /* Whether-a-style-arg-is-set args */
133 PROP_STRIKETHROUGH_SET,
141 static guint text_cell_renderer_signals [LAST_SIGNAL];
143 #define GHB_CELL_RENDERER_TEXT_PATH "gtk-cell-renderer-text-path"
145 #define GHB_CELL_RENDERER_TEXT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GHB_TYPE_CELL_RENDERER_TEXT, GhbCellRendererTextPrivate))
147 typedef struct _GhbCellRendererTextPrivate GhbCellRendererTextPrivate;
148 struct _GhbCellRendererTextPrivate
150 guint single_paragraph : 1;
151 guint language_set : 1;
152 guint markup_set : 1;
153 guint ellipsize_set : 1;
157 PangoLanguage *language;
158 PangoEllipsizeMode ellipsize;
159 PangoWrapMode wrap_mode;
160 PangoAlignment align;
162 gulong populate_popup_id;
163 gulong entry_menu_popdown_timeout;
164 gboolean in_entry_menu;
172 G_DEFINE_TYPE (GhbCellRendererText, ghb_cell_renderer_text, GTK_TYPE_CELL_RENDERER)
175 ghb_cell_renderer_text_init (GhbCellRendererText *celltext)
177 GhbCellRendererTextPrivate *priv;
179 priv = GHB_CELL_RENDERER_TEXT_GET_PRIVATE (celltext);
181 GTK_CELL_RENDERER (celltext)->xalign = 0.0;
182 GTK_CELL_RENDERER (celltext)->yalign = 0.5;
183 GTK_CELL_RENDERER (celltext)->xpad = 2;
184 GTK_CELL_RENDERER (celltext)->ypad = 2;
185 celltext->font_scale = 1.0;
186 celltext->fixed_height_rows = -1;
187 celltext->font = pango_font_description_new ();
189 priv->width_chars = -1;
190 priv->wrap_width = -1;
191 priv->wrap_mode = PANGO_WRAP_CHAR;
192 priv->align = PANGO_ALIGN_LEFT;
193 priv->align_set = FALSE;
197 ghb_cell_renderer_text_class_init (GhbCellRendererTextClass *class)
199 GObjectClass *object_class = G_OBJECT_CLASS (class);
200 GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);
202 object_class->finalize = ghb_cell_renderer_text_finalize;
204 object_class->get_property = ghb_cell_renderer_text_get_property;
205 object_class->set_property = ghb_cell_renderer_text_set_property;
207 cell_class->get_size = ghb_cell_renderer_text_get_size;
208 cell_class->render = ghb_cell_renderer_text_render;
209 cell_class->start_editing = ghb_cell_renderer_text_start_editing;
211 g_object_class_install_property (object_class,
213 g_param_spec_string ("text",
215 P_("Text to render"),
217 GTK_PARAM_READWRITE));
219 g_object_class_install_property (object_class,
221 g_param_spec_string ("markup",
223 P_("Marked up text to render"),
225 GTK_PARAM_WRITABLE));
227 g_object_class_install_property (object_class,
229 g_param_spec_boxed ("attributes",
231 P_("A list of style attributes to apply to the text of the renderer"),
232 PANGO_TYPE_ATTR_LIST,
233 GTK_PARAM_READWRITE));
235 g_object_class_install_property (object_class,
236 PROP_SINGLE_PARAGRAPH_MODE,
237 g_param_spec_boolean ("single-paragraph-mode",
238 P_("Single Paragraph Mode"),
239 P_("Whether or not to keep all text in a single paragraph"),
241 GTK_PARAM_READWRITE));
244 g_object_class_install_property (object_class,
246 g_param_spec_string ("background",
247 P_("Background color name"),
248 P_("Background color as a string"),
250 GTK_PARAM_WRITABLE));
252 g_object_class_install_property (object_class,
254 g_param_spec_boxed ("background-gdk",
255 P_("Background color"),
256 P_("Background color as a GdkColor"),
258 GTK_PARAM_READWRITE));
260 g_object_class_install_property (object_class,
262 g_param_spec_string ("foreground",
263 P_("Foreground color name"),
264 P_("Foreground color as a string"),
266 GTK_PARAM_WRITABLE));
268 g_object_class_install_property (object_class,
270 g_param_spec_boxed ("foreground-gdk",
271 P_("Foreground color"),
272 P_("Foreground color as a GdkColor"),
274 GTK_PARAM_READWRITE));
277 g_object_class_install_property (object_class,
279 g_param_spec_boolean ("editable",
281 P_("Whether the text can be modified by the user"),
283 GTK_PARAM_READWRITE));
285 g_object_class_install_property (object_class,
287 g_param_spec_string ("font",
289 P_("Font description as a string, e.g. \"Sans Italic 12\""),
291 GTK_PARAM_READWRITE));
293 g_object_class_install_property (object_class,
295 g_param_spec_boxed ("font-desc",
297 P_("Font description as a PangoFontDescription struct"),
298 PANGO_TYPE_FONT_DESCRIPTION,
299 GTK_PARAM_READWRITE));
302 g_object_class_install_property (object_class,
304 g_param_spec_string ("family",
306 P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
308 GTK_PARAM_READWRITE));
310 g_object_class_install_property (object_class,
312 g_param_spec_enum ("style",
317 GTK_PARAM_READWRITE));
319 g_object_class_install_property (object_class,
321 g_param_spec_enum ("variant",
325 PANGO_VARIANT_NORMAL,
326 GTK_PARAM_READWRITE));
328 g_object_class_install_property (object_class,
330 g_param_spec_int ("weight",
336 GTK_PARAM_READWRITE));
338 g_object_class_install_property (object_class,
340 g_param_spec_enum ("stretch",
344 PANGO_STRETCH_NORMAL,
345 GTK_PARAM_READWRITE));
347 g_object_class_install_property (object_class,
349 g_param_spec_int ("size",
355 GTK_PARAM_READWRITE));
357 g_object_class_install_property (object_class,
359 g_param_spec_double ("size-points",
361 P_("Font size in points"),
365 GTK_PARAM_READWRITE));
367 g_object_class_install_property (object_class,
369 g_param_spec_double ("scale",
371 P_("Font scaling factor"),
375 GTK_PARAM_READWRITE));
377 g_object_class_install_property (object_class,
379 g_param_spec_int ("rise",
381 P_("Offset of text above the baseline "
382 "(below the baseline if rise is negative)"),
386 GTK_PARAM_READWRITE));
389 g_object_class_install_property (object_class,
391 g_param_spec_boolean ("strikethrough",
393 P_("Whether to strike through the text"),
395 GTK_PARAM_READWRITE));
397 g_object_class_install_property (object_class,
399 g_param_spec_enum ("underline",
401 P_("Style of underline for this text"),
402 PANGO_TYPE_UNDERLINE,
403 PANGO_UNDERLINE_NONE,
404 GTK_PARAM_READWRITE));
406 g_object_class_install_property (object_class,
408 g_param_spec_string ("language",
410 P_("The language this text is in, as an ISO code. "
411 "Pango can use this as a hint when rendering the text. "
412 "If you don't understand this parameter, you probably don't need it"),
414 GTK_PARAM_READWRITE));
418 * GhbCellRendererText:ellipsize:
420 * Specifies the preferred place to ellipsize the string, if the cell renderer
421 * does not have enough room to display the entire string. Setting it to
422 * %PANGO_ELLIPSIZE_NONE turns off ellipsizing. See the wrap-width property
423 * for another way of making the text fit into a given width.
427 g_object_class_install_property (object_class,
429 g_param_spec_enum ("ellipsize",
431 P_("The preferred place to ellipsize the string, "
432 "if the cell renderer does not have enough room "
433 "to display the entire string"),
434 PANGO_TYPE_ELLIPSIZE_MODE,
435 PANGO_ELLIPSIZE_NONE,
436 GTK_PARAM_READWRITE));
439 * GhbCellRendererText:width-chars:
441 * The desired width of the cell, in characters. If this property is set to
442 * -1, the width will be calculated automatically, otherwise the cell will
443 * request either 3 characters or the property value, whichever is greater.
447 g_object_class_install_property (object_class,
449 g_param_spec_int ("width-chars",
450 P_("Width In Characters"),
451 P_("The desired width of the label, in characters"),
455 GTK_PARAM_READWRITE));
458 * GhbCellRendererText:wrap-mode:
460 * Specifies how to break the string into multiple lines, if the cell
461 * renderer does not have enough room to display the entire string.
462 * This property has no effect unless the wrap-width property is set.
466 g_object_class_install_property (object_class,
468 g_param_spec_enum ("wrap-mode",
470 P_("How to break the string into multiple lines, "
471 "if the cell renderer does not have enough room "
472 "to display the entire string"),
473 PANGO_TYPE_WRAP_MODE,
475 GTK_PARAM_READWRITE));
478 * GhbCellRendererText:wrap-width:
480 * Specifies the width at which the text is wrapped. The wrap-mode property can
481 * be used to influence at what character positions the line breaks can be placed.
482 * Setting wrap-width to -1 turns wrapping off.
486 g_object_class_install_property (object_class,
488 g_param_spec_int ("wrap-width",
490 P_("The width at which the text is wrapped"),
494 GTK_PARAM_READWRITE));
497 * GhbCellRendererText:alignment:
499 * Specifies how to align the lines of text with respect to each other.
501 * Note that this property describes how to align the lines of text in
502 * case there are several of them. The "xalign" property of #GtkCellRenderer,
503 * on the other hand, sets the horizontal alignment of the whole text.
507 g_object_class_install_property (object_class,
509 g_param_spec_enum ("alignment",
511 P_("How to align the lines"),
512 PANGO_TYPE_ALIGNMENT,
514 GTK_PARAM_READWRITE));
516 /* Style props are set or not */
518 #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))
520 ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
521 P_("Background set"),
522 P_("Whether this tag affects the background color"));
524 ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
525 P_("Foreground set"),
526 P_("Whether this tag affects the foreground color"));
528 ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
529 P_("Editability set"),
530 P_("Whether this tag affects text editability"));
532 ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
533 P_("Font family set"),
534 P_("Whether this tag affects the font family"));
536 ADD_SET_PROP ("style-set", PROP_STYLE_SET,
537 P_("Font style set"),
538 P_("Whether this tag affects the font style"));
540 ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
541 P_("Font variant set"),
542 P_("Whether this tag affects the font variant"));
544 ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
545 P_("Font weight set"),
546 P_("Whether this tag affects the font weight"));
548 ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
549 P_("Font stretch set"),
550 P_("Whether this tag affects the font stretch"));
552 ADD_SET_PROP ("size-set", PROP_SIZE_SET,
554 P_("Whether this tag affects the font size"));
556 ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
557 P_("Font scale set"),
558 P_("Whether this tag scales the font size by a factor"));
560 ADD_SET_PROP ("rise-set", PROP_RISE_SET,
562 P_("Whether this tag affects the rise"));
564 ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
565 P_("Strikethrough set"),
566 P_("Whether this tag affects strikethrough"));
568 ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
570 P_("Whether this tag affects underlining"));
572 ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
574 P_("Whether this tag affects the language the text is rendered as"));
576 ADD_SET_PROP ("ellipsize-set", PROP_ELLIPSIZE_SET,
578 P_("Whether this tag affects the ellipsize mode"));
580 ADD_SET_PROP ("align-set", PROP_ALIGN_SET,
582 P_("Whether this tag affects the alignment mode"));
585 * GhbCellRendererText::edited
586 * @renderer: the object which received the signal
587 * @path: the path identifying the edited cell
588 * @new_text: the new text
590 * This signal is emitted after @renderer has been edited.
592 * It is the responsibility of the application to update the model
593 * and store @new_text at the position indicated by @path.
595 text_cell_renderer_signals [EDITED] =
596 g_signal_new (I_("edited"),
597 G_OBJECT_CLASS_TYPE (object_class),
599 G_STRUCT_OFFSET (GhbCellRendererTextClass, edited),
601 ghb_marshal_VOID__STRING_STRING,
606 text_cell_renderer_signals [KEYPRESS] =
607 g_signal_new (I_("key-press-event"),
608 G_OBJECT_CLASS_TYPE (object_class),
610 G_STRUCT_OFFSET (GhbCellRendererTextClass, keypress),
612 ghb_marshal_BOOLEAN__BOXED,
614 GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
616 g_type_class_add_private (object_class, sizeof (GhbCellRendererTextPrivate));
620 ghb_cell_renderer_text_finalize (GObject *object)
622 GhbCellRendererText *celltext = GHB_CELL_RENDERER_TEXT (object);
623 GhbCellRendererTextPrivate *priv;
625 priv = GHB_CELL_RENDERER_TEXT_GET_PRIVATE (object);
627 pango_font_description_free (celltext->font);
629 g_free (celltext->text);
631 if (celltext->extra_attrs)
632 pango_attr_list_unref (celltext->extra_attrs);
635 g_object_unref (priv->language);
637 (* G_OBJECT_CLASS (ghb_cell_renderer_text_parent_class)->finalize) (object);
641 get_property_font_set_mask (guint prop_id)
645 case PROP_FAMILY_SET:
646 return PANGO_FONT_MASK_FAMILY;
648 return PANGO_FONT_MASK_STYLE;
649 case PROP_VARIANT_SET:
650 return PANGO_FONT_MASK_VARIANT;
651 case PROP_WEIGHT_SET:
652 return PANGO_FONT_MASK_WEIGHT;
653 case PROP_STRETCH_SET:
654 return PANGO_FONT_MASK_STRETCH;
656 return PANGO_FONT_MASK_SIZE;
663 ghb_cell_renderer_text_get_property (GObject *object,
668 GhbCellRendererText *celltext = GHB_CELL_RENDERER_TEXT (object);
669 GhbCellRendererTextPrivate *priv;
671 priv = GHB_CELL_RENDERER_TEXT_GET_PRIVATE (object);
676 g_value_set_string (value, celltext->text);
679 case PROP_ATTRIBUTES:
680 g_value_set_boxed (value, celltext->extra_attrs);
683 case PROP_SINGLE_PARAGRAPH_MODE:
684 g_value_set_boolean (value, priv->single_paragraph);
687 case PROP_BACKGROUND_GDK:
691 color.red = celltext->background.red;
692 color.green = celltext->background.green;
693 color.blue = celltext->background.blue;
695 g_value_set_boxed (value, &color);
699 case PROP_FOREGROUND_GDK:
703 color.red = celltext->foreground.red;
704 color.green = celltext->foreground.green;
705 color.blue = celltext->foreground.blue;
707 g_value_set_boxed (value, &color);
712 g_value_take_string (value, pango_font_description_to_string (celltext->font));
716 g_value_set_boxed (value, celltext->font);
720 g_value_set_string (value, pango_font_description_get_family (celltext->font));
724 g_value_set_enum (value, pango_font_description_get_style (celltext->font));
728 g_value_set_enum (value, pango_font_description_get_variant (celltext->font));
732 g_value_set_int (value, pango_font_description_get_weight (celltext->font));
736 g_value_set_enum (value, pango_font_description_get_stretch (celltext->font));
740 g_value_set_int (value, pango_font_description_get_size (celltext->font));
743 case PROP_SIZE_POINTS:
744 g_value_set_double (value, ((double)pango_font_description_get_size (celltext->font)) / (double)PANGO_SCALE);
748 g_value_set_double (value, celltext->font_scale);
752 g_value_set_boolean (value, celltext->editable);
755 case PROP_STRIKETHROUGH:
756 g_value_set_boolean (value, celltext->strikethrough);
760 g_value_set_enum (value, celltext->underline_style);
764 g_value_set_int (value, celltext->rise);
768 g_value_set_static_string (value, pango_language_to_string (priv->language));
772 g_value_set_enum (value, priv->ellipsize);
776 g_value_set_enum (value, priv->wrap_mode);
779 case PROP_WRAP_WIDTH:
780 g_value_set_int (value, priv->wrap_width);
784 g_value_set_enum (value, priv->align);
787 case PROP_BACKGROUND_SET:
788 g_value_set_boolean (value, celltext->background_set);
791 case PROP_FOREGROUND_SET:
792 g_value_set_boolean (value, celltext->foreground_set);
795 case PROP_FAMILY_SET:
797 case PROP_VARIANT_SET:
798 case PROP_WEIGHT_SET:
799 case PROP_STRETCH_SET:
802 PangoFontMask mask = get_property_font_set_mask (param_id);
803 g_value_set_boolean (value, (pango_font_description_get_set_fields (celltext->font) & mask) != 0);
809 g_value_set_boolean (value, celltext->scale_set);
812 case PROP_EDITABLE_SET:
813 g_value_set_boolean (value, celltext->editable_set);
816 case PROP_STRIKETHROUGH_SET:
817 g_value_set_boolean (value, celltext->strikethrough_set);
820 case PROP_UNDERLINE_SET:
821 g_value_set_boolean (value, celltext->underline_set);
825 g_value_set_boolean (value, celltext->rise_set);
828 case PROP_LANGUAGE_SET:
829 g_value_set_boolean (value, priv->language_set);
832 case PROP_ELLIPSIZE_SET:
833 g_value_set_boolean (value, priv->ellipsize_set);
837 g_value_set_boolean (value, priv->align_set);
840 case PROP_WIDTH_CHARS:
841 g_value_set_int (value, priv->width_chars);
844 case PROP_BACKGROUND:
845 case PROP_FOREGROUND:
848 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
855 set_bg_color (GhbCellRendererText *celltext,
860 if (!celltext->background_set)
862 celltext->background_set = TRUE;
863 g_object_notify (G_OBJECT (celltext), "background-set");
866 celltext->background.red = color->red;
867 celltext->background.green = color->green;
868 celltext->background.blue = color->blue;
872 if (celltext->background_set)
874 celltext->background_set = FALSE;
875 g_object_notify (G_OBJECT (celltext), "background-set");
882 set_fg_color (GhbCellRendererText *celltext,
887 if (!celltext->foreground_set)
889 celltext->foreground_set = TRUE;
890 g_object_notify (G_OBJECT (celltext), "foreground-set");
893 celltext->foreground.red = color->red;
894 celltext->foreground.green = color->green;
895 celltext->foreground.blue = color->blue;
899 if (celltext->foreground_set)
901 celltext->foreground_set = FALSE;
902 g_object_notify (G_OBJECT (celltext), "foreground-set");
908 set_font_desc_fields (PangoFontDescription *desc,
909 PangoFontMask to_set)
911 PangoFontMask changed_mask = 0;
913 if (to_set & PANGO_FONT_MASK_FAMILY)
915 const char *family = pango_font_description_get_family (desc);
919 changed_mask |= PANGO_FONT_MASK_FAMILY;
922 pango_font_description_set_family (desc, family);
924 if (to_set & PANGO_FONT_MASK_STYLE)
925 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
926 if (to_set & PANGO_FONT_MASK_VARIANT)
927 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
928 if (to_set & PANGO_FONT_MASK_WEIGHT)
929 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
930 if (to_set & PANGO_FONT_MASK_STRETCH)
931 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
932 if (to_set & PANGO_FONT_MASK_SIZE)
934 gint size = pango_font_description_get_size (desc);
937 size = 10 * PANGO_SCALE;
938 changed_mask |= PANGO_FONT_MASK_SIZE;
941 pango_font_description_set_size (desc, size);
948 notify_set_changed (GObject *object,
949 PangoFontMask changed_mask)
951 if (changed_mask & PANGO_FONT_MASK_FAMILY)
952 g_object_notify (object, "family-set");
953 if (changed_mask & PANGO_FONT_MASK_STYLE)
954 g_object_notify (object, "style-set");
955 if (changed_mask & PANGO_FONT_MASK_VARIANT)
956 g_object_notify (object, "variant-set");
957 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
958 g_object_notify (object, "weight-set");
959 if (changed_mask & PANGO_FONT_MASK_STRETCH)
960 g_object_notify (object, "stretch-set");
961 if (changed_mask & PANGO_FONT_MASK_SIZE)
962 g_object_notify (object, "size-set");
966 notify_fields_changed (GObject *object,
967 PangoFontMask changed_mask)
969 if (changed_mask & PANGO_FONT_MASK_FAMILY)
970 g_object_notify (object, "family");
971 if (changed_mask & PANGO_FONT_MASK_STYLE)
972 g_object_notify (object, "style");
973 if (changed_mask & PANGO_FONT_MASK_VARIANT)
974 g_object_notify (object, "variant");
975 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
976 g_object_notify (object, "weight");
977 if (changed_mask & PANGO_FONT_MASK_STRETCH)
978 g_object_notify (object, "stretch");
979 if (changed_mask & PANGO_FONT_MASK_SIZE)
980 g_object_notify (object, "size");
984 set_font_description (GhbCellRendererText *celltext,
985 PangoFontDescription *font_desc)
987 GObject *object = G_OBJECT (celltext);
988 PangoFontDescription *new_font_desc;
989 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
992 new_font_desc = pango_font_description_copy (font_desc);
994 new_font_desc = pango_font_description_new ();
996 old_mask = pango_font_description_get_set_fields (celltext->font);
997 new_mask = pango_font_description_get_set_fields (new_font_desc);
999 changed_mask = old_mask | new_mask;
1000 set_changed_mask = old_mask ^ new_mask;
1002 pango_font_description_free (celltext->font);
1003 celltext->font = new_font_desc;
1005 g_object_freeze_notify (object);
1007 g_object_notify (object, "font-desc");
1008 g_object_notify (object, "font");
1010 if (changed_mask & PANGO_FONT_MASK_FAMILY)
1011 g_object_notify (object, "family");
1012 if (changed_mask & PANGO_FONT_MASK_STYLE)
1013 g_object_notify (object, "style");
1014 if (changed_mask & PANGO_FONT_MASK_VARIANT)
1015 g_object_notify (object, "variant");
1016 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1017 g_object_notify (object, "weight");
1018 if (changed_mask & PANGO_FONT_MASK_STRETCH)
1019 g_object_notify (object, "stretch");
1020 if (changed_mask & PANGO_FONT_MASK_SIZE)
1022 g_object_notify (object, "size");
1023 g_object_notify (object, "size-points");
1026 notify_set_changed (object, set_changed_mask);
1028 g_object_thaw_notify (object);
1032 ghb_cell_renderer_text_set_property (GObject *object,
1034 const GValue *value,
1037 GhbCellRendererText *celltext = GHB_CELL_RENDERER_TEXT (object);
1038 GhbCellRendererTextPrivate *priv;
1040 priv = GHB_CELL_RENDERER_TEXT_GET_PRIVATE (object);
1045 g_free (celltext->text);
1047 if (priv->markup_set)
1049 if (celltext->extra_attrs)
1050 pango_attr_list_unref (celltext->extra_attrs);
1051 celltext->extra_attrs = NULL;
1052 priv->markup_set = FALSE;
1055 celltext->text = g_strdup (g_value_get_string (value));
1056 g_object_notify (object, "text");
1059 case PROP_ATTRIBUTES:
1060 if (celltext->extra_attrs)
1061 pango_attr_list_unref (celltext->extra_attrs);
1063 celltext->extra_attrs = g_value_get_boxed (value);
1064 if (celltext->extra_attrs)
1065 pango_attr_list_ref (celltext->extra_attrs);
1071 GError *error = NULL;
1072 PangoAttrList *attrs = NULL;
1074 str = g_value_get_string (value);
1075 if (str && !pango_parse_markup (str,
1083 g_warning ("Failed to set text from markup due to error parsing markup: %s",
1085 g_error_free (error);
1089 g_free (celltext->text);
1091 if (celltext->extra_attrs)
1092 pango_attr_list_unref (celltext->extra_attrs);
1094 celltext->text = text;
1095 celltext->extra_attrs = attrs;
1096 priv->markup_set = TRUE;
1100 case PROP_SINGLE_PARAGRAPH_MODE:
1101 priv->single_paragraph = g_value_get_boolean (value);
1104 case PROP_BACKGROUND:
1108 if (!g_value_get_string (value))
1109 set_bg_color (celltext, NULL); /* reset to background_set to FALSE */
1110 else if (gdk_color_parse (g_value_get_string (value), &color))
1111 set_bg_color (celltext, &color);
1113 g_warning ("Don't know color `%s'", g_value_get_string (value));
1115 g_object_notify (object, "background-gdk");
1119 case PROP_FOREGROUND:
1123 if (!g_value_get_string (value))
1124 set_fg_color (celltext, NULL); /* reset to foreground_set to FALSE */
1125 else if (gdk_color_parse (g_value_get_string (value), &color))
1126 set_fg_color (celltext, &color);
1128 g_warning ("Don't know color `%s'", g_value_get_string (value));
1130 g_object_notify (object, "foreground-gdk");
1134 case PROP_BACKGROUND_GDK:
1135 /* This notifies the GObject itself. */
1136 set_bg_color (celltext, g_value_get_boxed (value));
1139 case PROP_FOREGROUND_GDK:
1140 /* This notifies the GObject itself. */
1141 set_fg_color (celltext, g_value_get_boxed (value));
1146 PangoFontDescription *font_desc = NULL;
1149 name = g_value_get_string (value);
1152 font_desc = pango_font_description_from_string (name);
1154 set_font_description (celltext, font_desc);
1156 pango_font_description_free (font_desc);
1158 if (celltext->fixed_height_rows != -1)
1159 celltext->calc_fixed_height = TRUE;
1163 case PROP_FONT_DESC:
1164 set_font_description (celltext, g_value_get_boxed (value));
1166 if (celltext->fixed_height_rows != -1)
1167 celltext->calc_fixed_height = TRUE;
1176 case PROP_SIZE_POINTS:
1178 PangoFontMask old_set_mask = pango_font_description_get_set_fields (celltext->font);
1183 pango_font_description_set_family (celltext->font,
1184 g_value_get_string (value));
1187 pango_font_description_set_style (celltext->font,
1188 g_value_get_enum (value));
1191 pango_font_description_set_variant (celltext->font,
1192 g_value_get_enum (value));
1195 pango_font_description_set_weight (celltext->font,
1196 g_value_get_int (value));
1199 pango_font_description_set_stretch (celltext->font,
1200 g_value_get_enum (value));
1203 pango_font_description_set_size (celltext->font,
1204 g_value_get_int (value));
1205 g_object_notify (object, "size-points");
1207 case PROP_SIZE_POINTS:
1208 pango_font_description_set_size (celltext->font,
1209 g_value_get_double (value) * PANGO_SCALE);
1210 g_object_notify (object, "size");
1214 if (celltext->fixed_height_rows != -1)
1215 celltext->calc_fixed_height = TRUE;
1217 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (celltext->font));
1218 g_object_notify (object, "font-desc");
1219 g_object_notify (object, "font");
1225 celltext->font_scale = g_value_get_double (value);
1226 celltext->scale_set = TRUE;
1227 if (celltext->fixed_height_rows != -1)
1228 celltext->calc_fixed_height = TRUE;
1229 g_object_notify (object, "scale-set");
1233 celltext->editable = g_value_get_boolean (value);
1234 celltext->editable_set = TRUE;
1235 if (celltext->editable)
1236 GTK_CELL_RENDERER (celltext)->mode = GTK_CELL_RENDERER_MODE_EDITABLE;
1238 GTK_CELL_RENDERER (celltext)->mode = GTK_CELL_RENDERER_MODE_INERT;
1239 g_object_notify (object, "editable-set");
1242 case PROP_STRIKETHROUGH:
1243 celltext->strikethrough = g_value_get_boolean (value);
1244 celltext->strikethrough_set = TRUE;
1245 g_object_notify (object, "strikethrough-set");
1248 case PROP_UNDERLINE:
1249 celltext->underline_style = g_value_get_enum (value);
1250 celltext->underline_set = TRUE;
1251 g_object_notify (object, "underline-set");
1256 celltext->rise = g_value_get_int (value);
1257 celltext->rise_set = TRUE;
1258 g_object_notify (object, "rise-set");
1259 if (celltext->fixed_height_rows != -1)
1260 celltext->calc_fixed_height = TRUE;
1264 priv->language_set = TRUE;
1266 g_object_unref (priv->language);
1267 priv->language = pango_language_from_string (g_value_get_string (value));
1268 g_object_notify (object, "language-set");
1271 case PROP_ELLIPSIZE:
1272 priv->ellipsize = g_value_get_enum (value);
1273 priv->ellipsize_set = TRUE;
1274 g_object_notify (object, "ellipsize-set");
1277 case PROP_WRAP_MODE:
1278 priv->wrap_mode = g_value_get_enum (value);
1281 case PROP_WRAP_WIDTH:
1282 priv->wrap_width = g_value_get_int (value);
1285 case PROP_WIDTH_CHARS:
1286 priv->width_chars = g_value_get_int (value);
1290 priv->align = g_value_get_enum (value);
1291 priv->align_set = TRUE;
1292 g_object_notify (object, "align-set");
1295 case PROP_BACKGROUND_SET:
1296 celltext->background_set = g_value_get_boolean (value);
1299 case PROP_FOREGROUND_SET:
1300 celltext->foreground_set = g_value_get_boolean (value);
1303 case PROP_FAMILY_SET:
1304 case PROP_STYLE_SET:
1305 case PROP_VARIANT_SET:
1306 case PROP_WEIGHT_SET:
1307 case PROP_STRETCH_SET:
1309 if (!g_value_get_boolean (value))
1311 pango_font_description_unset_fields (celltext->font,
1312 get_property_font_set_mask (param_id));
1316 PangoFontMask changed_mask;
1318 changed_mask = set_font_desc_fields (celltext->font,
1319 get_property_font_set_mask (param_id));
1320 notify_fields_changed (G_OBJECT (celltext), changed_mask);
1324 case PROP_SCALE_SET:
1325 celltext->scale_set = g_value_get_boolean (value);
1328 case PROP_EDITABLE_SET:
1329 celltext->editable_set = g_value_get_boolean (value);
1332 case PROP_STRIKETHROUGH_SET:
1333 celltext->strikethrough_set = g_value_get_boolean (value);
1336 case PROP_UNDERLINE_SET:
1337 celltext->underline_set = g_value_get_boolean (value);
1341 celltext->rise_set = g_value_get_boolean (value);
1344 case PROP_LANGUAGE_SET:
1345 priv->language_set = g_value_get_boolean (value);
1348 case PROP_ELLIPSIZE_SET:
1349 priv->ellipsize_set = g_value_get_boolean (value);
1352 case PROP_ALIGN_SET:
1353 priv->align_set = g_value_get_boolean (value);
1357 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1363 * ghb_cell_renderer_text_new:
1365 * Creates a new #GhbCellRendererText. Adjust how text is drawn using
1366 * object properties. Object properties can be
1367 * set globally (with g_object_set()). Also, with #GtkTreeViewColumn,
1368 * you can bind a property to a value in a #GtkTreeModel. For example,
1369 * you can bind the "text" property on the cell renderer to a string
1370 * value in the model, thus rendering a different string in each row
1371 * of the #GtkTreeView
1373 * Return value: the new cell renderer
1376 ghb_cell_renderer_text_new (void)
1378 return g_object_new (GHB_TYPE_CELL_RENDERER_TEXT, NULL);
1382 add_attr (PangoAttrList *attr_list,
1383 PangoAttribute *attr)
1385 attr->start_index = 0;
1386 attr->end_index = G_MAXINT;
1388 pango_attr_list_insert (attr_list, attr);
1392 get_layout (GhbCellRendererText *celltext,
1394 gboolean will_render,
1395 GtkCellRendererState flags)
1397 PangoAttrList *attr_list;
1398 PangoLayout *layout;
1399 PangoUnderline uline;
1400 GhbCellRendererTextPrivate *priv;
1402 priv = GHB_CELL_RENDERER_TEXT_GET_PRIVATE (celltext);
1404 layout = gtk_widget_create_pango_layout (widget, celltext->text);
1406 if (celltext->extra_attrs)
1407 attr_list = pango_attr_list_copy (celltext->extra_attrs);
1409 attr_list = pango_attr_list_new ();
1411 pango_layout_set_single_paragraph_mode (layout, priv->single_paragraph);
1415 /* Add options that affect appearance but not size */
1417 /* note that background doesn't go here, since it affects
1418 * background_area not the PangoLayout area
1421 if (celltext->foreground_set
1422 && (flags & GTK_CELL_RENDERER_SELECTED) == 0)
1426 color = celltext->foreground;
1428 add_attr (attr_list,
1429 pango_attr_foreground_new (color.red, color.green, color.blue));
1432 if (celltext->strikethrough_set)
1433 add_attr (attr_list,
1434 pango_attr_strikethrough_new (celltext->strikethrough));
1437 add_attr (attr_list, pango_attr_font_desc_new (celltext->font));
1439 if (celltext->scale_set &&
1440 celltext->font_scale != 1.0)
1441 add_attr (attr_list, pango_attr_scale_new (celltext->font_scale));
1443 if (celltext->underline_set)
1444 uline = celltext->underline_style;
1446 uline = PANGO_UNDERLINE_NONE;
1448 if (priv->language_set)
1449 add_attr (attr_list, pango_attr_language_new (priv->language));
1451 if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT)
1455 case PANGO_UNDERLINE_NONE:
1456 uline = PANGO_UNDERLINE_SINGLE;
1459 case PANGO_UNDERLINE_SINGLE:
1460 uline = PANGO_UNDERLINE_DOUBLE;
1468 if (uline != PANGO_UNDERLINE_NONE)
1469 add_attr (attr_list, pango_attr_underline_new (celltext->underline_style));
1471 if (celltext->rise_set)
1472 add_attr (attr_list, pango_attr_rise_new (celltext->rise));
1474 if (priv->ellipsize_set)
1475 pango_layout_set_ellipsize (layout, priv->ellipsize);
1477 pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_NONE);
1479 if (priv->wrap_width != -1)
1481 pango_layout_set_width (layout, priv->wrap_width * PANGO_SCALE);
1482 pango_layout_set_wrap (layout, priv->wrap_mode);
1486 pango_layout_set_width (layout, -1);
1487 pango_layout_set_wrap (layout, PANGO_WRAP_CHAR);
1490 if (priv->align_set)
1491 pango_layout_set_alignment (layout, priv->align);
1494 PangoAlignment align;
1496 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1497 align = PANGO_ALIGN_RIGHT;
1499 align = PANGO_ALIGN_LEFT;
1501 pango_layout_set_alignment (layout, align);
1504 pango_layout_set_attributes (layout, attr_list);
1506 pango_attr_list_unref (attr_list);
1512 get_size (GtkCellRenderer *cell,
1514 GdkRectangle *cell_area,
1515 PangoLayout *layout,
1521 GhbCellRendererText *celltext = (GhbCellRendererText *) cell;
1522 PangoRectangle rect;
1523 GhbCellRendererTextPrivate *priv;
1525 priv = GHB_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
1527 if (celltext->calc_fixed_height)
1529 PangoContext *context;
1530 PangoFontMetrics *metrics;
1531 PangoFontDescription *font_desc;
1534 font_desc = pango_font_description_copy_static (widget->style->font_desc);
1535 pango_font_description_merge_static (font_desc, celltext->font, TRUE);
1537 if (celltext->scale_set)
1538 pango_font_description_set_size (font_desc,
1539 celltext->font_scale * pango_font_description_get_size (font_desc));
1541 context = gtk_widget_get_pango_context (widget);
1543 metrics = pango_context_get_metrics (context,
1545 pango_context_get_language (context));
1546 row_height = (pango_font_metrics_get_ascent (metrics) +
1547 pango_font_metrics_get_descent (metrics));
1548 pango_font_metrics_unref (metrics);
1550 pango_font_description_free (font_desc);
1552 gtk_cell_renderer_set_fixed_size (cell,
1553 cell->width, 2*cell->ypad +
1554 celltext->fixed_height_rows * PANGO_PIXELS (row_height));
1558 *height = cell->height;
1561 celltext->calc_fixed_height = FALSE;
1567 g_object_ref (layout);
1569 layout = get_layout (celltext, widget, FALSE, 0);
1571 pango_layout_get_extents (layout, NULL, &rect);
1572 pango_extents_to_pixels (&rect, NULL);
1575 *height = cell->ypad * 2 + rect.height;
1577 /* The minimum size for ellipsized labels is ~ 3 chars */
1580 if (priv->ellipsize || priv->width_chars > 0)
1582 PangoContext *context;
1583 PangoFontMetrics *metrics;
1586 context = pango_layout_get_context (layout);
1587 metrics = pango_context_get_metrics (context, widget->style->font_desc, pango_context_get_language (context));
1589 char_width = pango_font_metrics_get_approximate_char_width (metrics);
1590 pango_font_metrics_unref (metrics);
1592 *width = cell->xpad * 2 + (PANGO_PIXELS (char_width) * MAX (priv->width_chars, 3));
1596 *width = cell->xpad * 2 + rect.x + rect.width;
1604 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1605 *x_offset = (1.0 - cell->xalign) * (cell_area->width - (rect.x + rect.width + (2 * cell->xpad)));
1607 *x_offset = cell->xalign * (cell_area->width - (rect.x + rect.width + (2 * cell->xpad)));
1609 if ((priv->ellipsize_set && priv->ellipsize != PANGO_ELLIPSIZE_NONE) || priv->wrap_width != -1)
1610 *x_offset = MAX(*x_offset, 0);
1614 *y_offset = cell->yalign * (cell_area->height - (rect.height + (2 * cell->ypad)));
1615 *y_offset = MAX (*y_offset, 0);
1620 if (x_offset) *x_offset = 0;
1621 if (y_offset) *y_offset = 0;
1624 g_object_unref (layout);
1629 ghb_cell_renderer_text_get_size (GtkCellRenderer *cell,
1631 GdkRectangle *cell_area,
1637 get_size (cell, widget, cell_area, NULL,
1638 x_offset, y_offset, width, height);
1642 ghb_cell_renderer_text_render (GtkCellRenderer *cell,
1643 GdkDrawable *window,
1645 GdkRectangle *background_area,
1646 GdkRectangle *cell_area,
1647 GdkRectangle *expose_area,
1648 GtkCellRendererState flags)
1651 GhbCellRendererText *celltext = (GhbCellRendererText *) cell;
1652 PangoLayout *layout;
1656 GhbCellRendererTextPrivate *priv;
1658 priv = GHB_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
1660 layout = get_layout (celltext, widget, TRUE, flags);
1661 get_size (cell, widget, cell_area, layout, &x_offset, &y_offset, NULL, NULL);
1663 if (!cell->sensitive)
1665 state = GTK_STATE_INSENSITIVE;
1667 else if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
1669 if (GTK_WIDGET_HAS_FOCUS (widget))
1670 state = GTK_STATE_SELECTED;
1672 state = GTK_STATE_ACTIVE;
1674 else if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT &&
1675 GTK_WIDGET_STATE (widget) == GTK_STATE_PRELIGHT)
1677 state = GTK_STATE_PRELIGHT;
1681 if (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE)
1682 state = GTK_STATE_INSENSITIVE;
1684 state = GTK_STATE_NORMAL;
1687 if (celltext->background_set &&
1688 (flags & GTK_CELL_RENDERER_SELECTED) == 0)
1690 cairo_t *cr = gdk_cairo_create (window);
1694 gdk_cairo_rectangle (cr, expose_area);
1698 gdk_cairo_rectangle (cr, background_area);
1699 cairo_set_source_rgb (cr,
1700 celltext->background.red / 65535.,
1701 celltext->background.green / 65535.,
1702 celltext->background.blue / 65535.);
1708 if (priv->ellipsize_set && priv->ellipsize != PANGO_ELLIPSIZE_NONE)
1709 pango_layout_set_width (layout,
1710 (cell_area->width - x_offset - 2 * cell->xpad) * PANGO_SCALE);
1711 else if (priv->wrap_width == -1)
1712 pango_layout_set_width (layout, -1);
1714 gtk_paint_layout (widget->style,
1721 cell_area->x + x_offset + cell->xpad,
1722 cell_area->y + y_offset + cell->ypad,
1725 g_object_unref (layout);
1729 ghb_cell_renderer_text_keypress(
1730 GtkCellEditable *entry,
1736 data, text_cell_renderer_signals[KEYPRESS], 0, event, &result);
1741 ghb_cell_renderer_text_editing_done (GtkCellEditable *entry,
1745 const gchar *new_text;
1746 GhbCellRendererTextPrivate *priv;
1748 priv = GHB_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1752 if (priv->focus_out_id > 0)
1754 g_signal_handler_disconnect (entry, priv->focus_out_id);
1755 priv->focus_out_id = 0;
1758 if (priv->populate_popup_id > 0)
1760 g_signal_handler_disconnect (entry, priv->populate_popup_id);
1761 priv->populate_popup_id = 0;
1764 if (priv->entry_menu_popdown_timeout)
1766 g_source_remove (priv->entry_menu_popdown_timeout);
1767 priv->entry_menu_popdown_timeout = 0;
1770 gtk_cell_renderer_stop_editing (GTK_CELL_RENDERER (data),
1771 GTK_ENTRY (entry)->editing_canceled);
1772 if (GTK_ENTRY (entry)->editing_canceled)
1775 path = g_object_get_data (G_OBJECT (entry), GHB_CELL_RENDERER_TEXT_PATH);
1776 new_text = gtk_entry_get_text (GTK_ENTRY (entry));
1778 g_signal_emit (data, text_cell_renderer_signals[EDITED], 0, path, new_text);
1782 popdown_timeout (gpointer data)
1784 GhbCellRendererTextPrivate *priv;
1786 priv = GHB_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1788 priv->entry_menu_popdown_timeout = 0;
1790 if (!GTK_WIDGET_HAS_FOCUS (priv->entry))
1791 ghb_cell_renderer_text_editing_done (GTK_CELL_EDITABLE (priv->entry), data);
1797 ghb_cell_renderer_text_popup_unmap (GtkMenu *menu,
1800 GhbCellRendererTextPrivate *priv;
1802 priv = GHB_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1804 priv->in_entry_menu = FALSE;
1806 if (priv->entry_menu_popdown_timeout)
1809 priv->entry_menu_popdown_timeout = gdk_threads_add_timeout (500, popdown_timeout,
1814 ghb_cell_renderer_text_populate_popup (GtkEntry *entry,
1818 GhbCellRendererTextPrivate *priv;
1820 priv = GHB_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1822 if (priv->entry_menu_popdown_timeout)
1824 g_source_remove (priv->entry_menu_popdown_timeout);
1825 priv->entry_menu_popdown_timeout = 0;
1828 priv->in_entry_menu = TRUE;
1830 g_signal_connect (menu, "unmap",
1831 G_CALLBACK (ghb_cell_renderer_text_popup_unmap), data);
1835 ghb_cell_renderer_text_focus_out_event (GtkWidget *entry,
1839 GhbCellRendererTextPrivate *priv;
1841 priv = GHB_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1843 if (priv->in_entry_menu)
1846 GTK_ENTRY (entry)->editing_canceled = TRUE;
1847 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
1848 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
1850 /* entry needs focus-out-event */
1854 static GtkCellEditable *
1855 ghb_cell_renderer_text_start_editing (GtkCellRenderer *cell,
1859 GdkRectangle *background_area,
1860 GdkRectangle *cell_area,
1861 GtkCellRendererState flags)
1863 GtkRequisition requisition;
1864 GhbCellRendererText *celltext;
1865 GhbCellRendererTextPrivate *priv;
1867 celltext = GHB_CELL_RENDERER_TEXT (cell);
1868 priv = GHB_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
1870 /* If the cell isn't editable we return NULL. */
1871 if (celltext->editable == FALSE)
1874 priv->entry = g_object_new (GTK_TYPE_ENTRY,
1876 "xalign", cell->xalign,
1880 gtk_entry_set_text (GTK_ENTRY (priv->entry), celltext->text);
1881 g_object_set_data_full (G_OBJECT (priv->entry), I_(GHB_CELL_RENDERER_TEXT_PATH), g_strdup (path), g_free);
1883 gtk_editable_select_region (GTK_EDITABLE (priv->entry), 0, -1);
1885 gtk_widget_size_request (priv->entry, &requisition);
1886 if (requisition.height < cell_area->height)
1888 GtkBorder *style_border;
1891 gtk_widget_style_get (priv->entry,
1892 "inner-border", &style_border,
1897 border = *style_border;
1898 g_boxed_free (GTK_TYPE_BORDER, style_border);
1902 /* Since boxed style properties can't have default values ... */
1907 border.top = (cell_area->height - requisition.height) / 2;
1908 border.bottom = (cell_area->height - requisition.height) / 2;
1909 gtk_entry_set_inner_border (GTK_ENTRY (priv->entry), &border);
1912 priv->in_entry_menu = FALSE;
1913 if (priv->entry_menu_popdown_timeout)
1915 g_source_remove (priv->entry_menu_popdown_timeout);
1916 priv->entry_menu_popdown_timeout = 0;
1919 g_signal_connect (priv->entry,
1921 G_CALLBACK (ghb_cell_renderer_text_keypress),
1923 g_signal_connect (priv->entry,
1925 G_CALLBACK (ghb_cell_renderer_text_editing_done),
1927 priv->focus_out_id = g_signal_connect_after (priv->entry, "focus_out_event",
1928 G_CALLBACK (ghb_cell_renderer_text_focus_out_event),
1930 priv->populate_popup_id =
1931 g_signal_connect (priv->entry, "populate_popup",
1932 G_CALLBACK (ghb_cell_renderer_text_populate_popup),
1935 gtk_widget_show (priv->entry);
1937 return GTK_CELL_EDITABLE (priv->entry);
1941 * ghb_cell_renderer_text_set_fixed_height_from_font:
1942 * @renderer: A #GhbCellRendererText
1943 * @number_of_rows: Number of rows of text each cell renderer is allocated, or -1
1945 * Sets the height of a renderer to explicitly be determined by the "font" and
1946 * "y_pad" property set on it. Further changes in these properties do not
1947 * affect the height, so they must be accompanied by a subsequent call to this
1948 * function. Using this function is unflexible, and should really only be used
1949 * if calculating the size of a cell is too slow (ie, a massive number of cells
1950 * displayed). If @number_of_rows is -1, then the fixed height is unset, and
1951 * the height is determined by the properties again.
1954 ghb_cell_renderer_text_set_fixed_height_from_font (GhbCellRendererText *renderer,
1955 gint number_of_rows)
1957 g_return_if_fail (GHB_IS_CELL_RENDERER_TEXT (renderer));
1958 g_return_if_fail (number_of_rows == -1 || number_of_rows > 0);
1960 if (number_of_rows == -1)
1962 gtk_cell_renderer_set_fixed_size (GTK_CELL_RENDERER (renderer),
1963 GTK_CELL_RENDERER (renderer)->width,
1968 renderer->fixed_height_rows = number_of_rows;
1969 renderer->calc_fixed_height = TRUE;