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.
22 #include "gtkcellrenderertext.h"
23 #include "gtkeditable.h"
25 #include "gtkmarshalers.h"
27 #include "gtkprivate.h"
28 #include "gtktreeprivate.h"
31 static void gtk_cell_renderer_text_finalize (GObject *object);
33 static void gtk_cell_renderer_text_get_property (GObject *object,
37 static void gtk_cell_renderer_text_set_property (GObject *object,
41 static void gtk_cell_renderer_text_get_size (GtkCellRenderer *cell,
43 GdkRectangle *cell_area,
48 static void gtk_cell_renderer_text_render (GtkCellRenderer *cell,
51 GdkRectangle *background_area,
52 GdkRectangle *cell_area,
53 GdkRectangle *expose_area,
54 GtkCellRendererState flags);
56 static GtkCellEditable *gtk_cell_renderer_text_start_editing (GtkCellRenderer *cell,
60 GdkRectangle *background_area,
61 GdkRectangle *cell_area,
62 GtkCellRendererState flags);
75 PROP_SINGLE_PARAGRAPH_MODE,
103 /* Whether-a-style-arg-is-set args */
114 PROP_STRIKETHROUGH_SET,
121 static guint text_cell_renderer_signals [LAST_SIGNAL];
123 #define GTK_CELL_RENDERER_TEXT_PATH "gtk-cell-renderer-text-path"
125 #define GTK_CELL_RENDERER_TEXT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CELL_RENDERER_TEXT, GtkCellRendererTextPrivate))
127 typedef struct _GtkCellRendererTextPrivate GtkCellRendererTextPrivate;
128 struct _GtkCellRendererTextPrivate
130 guint single_paragraph : 1;
131 guint language_set : 1;
132 guint markup_set : 1;
133 guint ellipsize_set : 1;
137 PangoLanguage *language;
138 PangoEllipsizeMode ellipsize;
139 PangoWrapMode wrap_mode;
140 PangoAlignment align;
142 gulong populate_popup_id;
143 gulong entry_menu_popdown_timeout;
144 gboolean in_entry_menu;
152 G_DEFINE_TYPE (GtkCellRendererText, gtk_cell_renderer_text, GTK_TYPE_CELL_RENDERER)
155 gtk_cell_renderer_text_init (GtkCellRendererText *celltext)
157 GtkCellRendererTextPrivate *priv;
159 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (celltext);
161 GTK_CELL_RENDERER (celltext)->xalign = 0.0;
162 GTK_CELL_RENDERER (celltext)->yalign = 0.5;
163 GTK_CELL_RENDERER (celltext)->xpad = 2;
164 GTK_CELL_RENDERER (celltext)->ypad = 2;
165 celltext->fixed_height_rows = -1;
166 celltext->font = pango_font_description_new ();
168 priv->width_chars = -1;
169 priv->wrap_width = -1;
170 priv->align = PANGO_ALIGN_LEFT;
171 priv->align_set = FALSE;
175 gtk_cell_renderer_text_class_init (GtkCellRendererTextClass *class)
177 GObjectClass *object_class = G_OBJECT_CLASS (class);
178 GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);
180 object_class->finalize = gtk_cell_renderer_text_finalize;
182 object_class->get_property = gtk_cell_renderer_text_get_property;
183 object_class->set_property = gtk_cell_renderer_text_set_property;
185 cell_class->get_size = gtk_cell_renderer_text_get_size;
186 cell_class->render = gtk_cell_renderer_text_render;
187 cell_class->start_editing = gtk_cell_renderer_text_start_editing;
189 g_object_class_install_property (object_class,
191 g_param_spec_string ("text",
193 P_("Text to render"),
195 GTK_PARAM_READWRITE));
197 g_object_class_install_property (object_class,
199 g_param_spec_string ("markup",
201 P_("Marked up text to render"),
203 GTK_PARAM_WRITABLE));
205 g_object_class_install_property (object_class,
207 g_param_spec_boxed ("attributes",
209 P_("A list of style attributes to apply to the text of the renderer"),
210 PANGO_TYPE_ATTR_LIST,
211 GTK_PARAM_READWRITE));
213 g_object_class_install_property (object_class,
214 PROP_SINGLE_PARAGRAPH_MODE,
215 g_param_spec_boolean ("single-paragraph-mode",
216 P_("Single Paragraph Mode"),
217 P_("Whether or not to keep all text in a single paragraph"),
219 GTK_PARAM_READWRITE));
222 g_object_class_install_property (object_class,
224 g_param_spec_string ("background",
225 P_("Background color name"),
226 P_("Background color as a string"),
228 GTK_PARAM_WRITABLE));
230 g_object_class_install_property (object_class,
232 g_param_spec_boxed ("background-gdk",
233 P_("Background color"),
234 P_("Background color as a GdkColor"),
236 GTK_PARAM_READWRITE));
238 g_object_class_install_property (object_class,
240 g_param_spec_string ("foreground",
241 P_("Foreground color name"),
242 P_("Foreground color as a string"),
244 GTK_PARAM_WRITABLE));
246 g_object_class_install_property (object_class,
248 g_param_spec_boxed ("foreground-gdk",
249 P_("Foreground color"),
250 P_("Foreground color as a GdkColor"),
252 GTK_PARAM_READWRITE));
255 g_object_class_install_property (object_class,
257 g_param_spec_boolean ("editable",
259 P_("Whether the text can be modified by the user"),
261 GTK_PARAM_READWRITE));
263 g_object_class_install_property (object_class,
265 g_param_spec_string ("font",
267 P_("Font description as a string, e.g. \"Sans Italic 12\""),
269 GTK_PARAM_READWRITE));
271 g_object_class_install_property (object_class,
273 g_param_spec_boxed ("font-desc",
275 P_("Font description as a PangoFontDescription struct"),
276 PANGO_TYPE_FONT_DESCRIPTION,
277 GTK_PARAM_READWRITE));
280 g_object_class_install_property (object_class,
282 g_param_spec_string ("family",
284 P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
286 GTK_PARAM_READWRITE));
288 g_object_class_install_property (object_class,
290 g_param_spec_enum ("style",
295 GTK_PARAM_READWRITE));
297 g_object_class_install_property (object_class,
299 g_param_spec_enum ("variant",
303 PANGO_VARIANT_NORMAL,
304 GTK_PARAM_READWRITE));
306 g_object_class_install_property (object_class,
308 g_param_spec_int ("weight",
314 GTK_PARAM_READWRITE));
316 g_object_class_install_property (object_class,
318 g_param_spec_enum ("stretch",
322 PANGO_STRETCH_NORMAL,
323 GTK_PARAM_READWRITE));
325 g_object_class_install_property (object_class,
327 g_param_spec_int ("size",
333 GTK_PARAM_READWRITE));
335 g_object_class_install_property (object_class,
337 g_param_spec_double ("size-points",
339 P_("Font size in points"),
343 GTK_PARAM_READWRITE));
345 g_object_class_install_property (object_class,
347 g_param_spec_double ("scale",
349 P_("Font scaling factor"),
353 GTK_PARAM_READWRITE));
355 g_object_class_install_property (object_class,
357 g_param_spec_int ("rise",
359 P_("Offset of text above the baseline "
360 "(below the baseline if rise is negative)"),
364 GTK_PARAM_READWRITE));
367 g_object_class_install_property (object_class,
369 g_param_spec_boolean ("strikethrough",
371 P_("Whether to strike through the text"),
373 GTK_PARAM_READWRITE));
375 g_object_class_install_property (object_class,
377 g_param_spec_enum ("underline",
379 P_("Style of underline for this text"),
380 PANGO_TYPE_UNDERLINE,
381 PANGO_UNDERLINE_NONE,
382 GTK_PARAM_READWRITE));
384 g_object_class_install_property (object_class,
386 g_param_spec_string ("language",
388 P_("The language this text is in, as an ISO code. "
389 "Pango can use this as a hint when rendering the text. "
390 "If you don't understand this parameter, you probably don't need it"),
392 GTK_PARAM_READWRITE));
396 * GtkCellRendererText:ellipsize:
398 * Specifies the preferred place to ellipsize the string, if the cell renderer
399 * does not have enough room to display the entire string. Setting it to
400 * %PANGO_ELLIPSIZE_NONE turns off ellipsizing. See the wrap-width property
401 * for another way of making the text fit into a given width.
405 g_object_class_install_property (object_class,
407 g_param_spec_enum ("ellipsize",
409 P_("The preferred place to ellipsize the string, "
410 "if the cell renderer does not have enough room "
411 "to display the entire string"),
412 PANGO_TYPE_ELLIPSIZE_MODE,
413 PANGO_ELLIPSIZE_NONE,
414 GTK_PARAM_READWRITE));
417 * GtkCellRendererText:width-chars:
419 * The desired width of the cell, in characters. If this property is set to
420 * -1, the width will be calculated automatically, otherwise the cell will
421 * request either 3 characters or the property value, whichever is greater.
425 g_object_class_install_property (object_class,
427 g_param_spec_int ("width-chars",
428 P_("Width In Characters"),
429 P_("The desired width of the label, in characters"),
433 GTK_PARAM_READWRITE));
436 * GtkCellRendererText:wrap-mode:
438 * Specifies how to break the string into multiple lines, if the cell
439 * renderer does not have enough room to display the entire string.
440 * This property has no effect unless the wrap-width property is set.
444 g_object_class_install_property (object_class,
446 g_param_spec_enum ("wrap-mode",
448 P_("How to break the string into multiple lines, "
449 "if the cell renderer does not have enough room "
450 "to display the entire string"),
451 PANGO_TYPE_WRAP_MODE,
453 GTK_PARAM_READWRITE));
456 * GtkCellRendererText:wrap-width:
458 * Specifies the width at which the text is wrapped. The wrap-mode property can
459 * be used to influence at what character positions the line breaks can be placed.
460 * Setting wrap-width to -1 turns wrapping off.
464 g_object_class_install_property (object_class,
466 g_param_spec_int ("wrap-width",
468 P_("The width at which the text is wrapped"),
472 GTK_PARAM_READWRITE));
475 * GtkCellRendererText:alignment:
477 * Specifies how to align the lines of text.
481 g_object_class_install_property (object_class,
483 g_param_spec_enum ("alignment",
485 P_("How to align the lines"),
486 PANGO_TYPE_ALIGNMENT,
488 GTK_PARAM_READWRITE));
490 /* Style props are set or not */
492 #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))
494 ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
495 P_("Background set"),
496 P_("Whether this tag affects the background color"));
498 ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
499 P_("Foreground set"),
500 P_("Whether this tag affects the foreground color"));
502 ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
503 P_("Editability set"),
504 P_("Whether this tag affects text editability"));
506 ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
507 P_("Font family set"),
508 P_("Whether this tag affects the font family"));
510 ADD_SET_PROP ("style-set", PROP_STYLE_SET,
511 P_("Font style set"),
512 P_("Whether this tag affects the font style"));
514 ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
515 P_("Font variant set"),
516 P_("Whether this tag affects the font variant"));
518 ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
519 P_("Font weight set"),
520 P_("Whether this tag affects the font weight"));
522 ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
523 P_("Font stretch set"),
524 P_("Whether this tag affects the font stretch"));
526 ADD_SET_PROP ("size-set", PROP_SIZE_SET,
528 P_("Whether this tag affects the font size"));
530 ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
531 P_("Font scale set"),
532 P_("Whether this tag scales the font size by a factor"));
534 ADD_SET_PROP ("rise-set", PROP_RISE_SET,
536 P_("Whether this tag affects the rise"));
538 ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
539 P_("Strikethrough set"),
540 P_("Whether this tag affects strikethrough"));
542 ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
544 P_("Whether this tag affects underlining"));
546 ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
548 P_("Whether this tag affects the language the text is rendered as"));
550 ADD_SET_PROP ("ellipsize-set", PROP_ELLIPSIZE_SET,
552 P_("Whether this tag affects the ellipsize mode"));
554 text_cell_renderer_signals [EDITED] =
555 g_signal_new (I_("edited"),
556 G_OBJECT_CLASS_TYPE (object_class),
558 G_STRUCT_OFFSET (GtkCellRendererTextClass, edited),
560 _gtk_marshal_VOID__STRING_STRING,
565 g_type_class_add_private (object_class, sizeof (GtkCellRendererTextPrivate));
569 gtk_cell_renderer_text_finalize (GObject *object)
571 GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
572 GtkCellRendererTextPrivate *priv;
574 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (object);
576 pango_font_description_free (celltext->font);
579 g_free (celltext->text);
581 if (celltext->extra_attrs)
582 pango_attr_list_unref (celltext->extra_attrs);
585 g_object_unref (priv->language);
587 (* G_OBJECT_CLASS (gtk_cell_renderer_text_parent_class)->finalize) (object);
591 get_property_font_set_mask (guint prop_id)
595 case PROP_FAMILY_SET:
596 return PANGO_FONT_MASK_FAMILY;
598 return PANGO_FONT_MASK_STYLE;
599 case PROP_VARIANT_SET:
600 return PANGO_FONT_MASK_VARIANT;
601 case PROP_WEIGHT_SET:
602 return PANGO_FONT_MASK_WEIGHT;
603 case PROP_STRETCH_SET:
604 return PANGO_FONT_MASK_STRETCH;
606 return PANGO_FONT_MASK_SIZE;
613 gtk_cell_renderer_text_get_property (GObject *object,
618 GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
619 GtkCellRendererTextPrivate *priv;
621 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (object);
626 g_value_set_string (value, celltext->text);
629 case PROP_ATTRIBUTES:
630 g_value_set_boxed (value, celltext->extra_attrs);
633 case PROP_SINGLE_PARAGRAPH_MODE:
634 g_value_set_boolean (value, priv->single_paragraph);
637 case PROP_BACKGROUND_GDK:
641 color.red = celltext->background.red;
642 color.green = celltext->background.green;
643 color.blue = celltext->background.blue;
645 g_value_set_boxed (value, &color);
649 case PROP_FOREGROUND_GDK:
653 color.red = celltext->foreground.red;
654 color.green = celltext->foreground.green;
655 color.blue = celltext->foreground.blue;
657 g_value_set_boxed (value, &color);
662 g_value_take_string (value, pango_font_description_to_string (celltext->font));
666 g_value_set_boxed (value, celltext->font);
670 g_value_set_string (value, pango_font_description_get_family (celltext->font));
674 g_value_set_enum (value, pango_font_description_get_style (celltext->font));
678 g_value_set_enum (value, pango_font_description_get_variant (celltext->font));
682 g_value_set_int (value, pango_font_description_get_weight (celltext->font));
686 g_value_set_enum (value, pango_font_description_get_stretch (celltext->font));
690 g_value_set_int (value, pango_font_description_get_size (celltext->font));
693 case PROP_SIZE_POINTS:
694 g_value_set_double (value, ((double)pango_font_description_get_size (celltext->font)) / (double)PANGO_SCALE);
698 g_value_set_double (value, celltext->font_scale);
702 g_value_set_boolean (value, celltext->editable);
705 case PROP_STRIKETHROUGH:
706 g_value_set_boolean (value, celltext->strikethrough);
710 g_value_set_enum (value, celltext->underline_style);
714 g_value_set_int (value, celltext->rise);
718 g_value_set_string (value, pango_language_to_string (priv->language));
722 g_value_set_enum (value, priv->ellipsize);
726 g_value_set_enum (value, priv->wrap_mode);
729 case PROP_WRAP_WIDTH:
730 g_value_set_int (value, priv->wrap_width);
734 g_value_set_enum (value, priv->align);
737 case PROP_BACKGROUND_SET:
738 g_value_set_boolean (value, celltext->background_set);
741 case PROP_FOREGROUND_SET:
742 g_value_set_boolean (value, celltext->foreground_set);
745 case PROP_FAMILY_SET:
747 case PROP_VARIANT_SET:
748 case PROP_WEIGHT_SET:
749 case PROP_STRETCH_SET:
752 PangoFontMask mask = get_property_font_set_mask (param_id);
753 g_value_set_boolean (value, (pango_font_description_get_set_fields (celltext->font) & mask) != 0);
759 g_value_set_boolean (value, celltext->scale_set);
762 case PROP_EDITABLE_SET:
763 g_value_set_boolean (value, celltext->editable_set);
766 case PROP_STRIKETHROUGH_SET:
767 g_value_set_boolean (value, celltext->strikethrough_set);
770 case PROP_UNDERLINE_SET:
771 g_value_set_boolean (value, celltext->underline_set);
775 g_value_set_boolean (value, celltext->rise_set);
778 case PROP_LANGUAGE_SET:
779 g_value_set_boolean (value, priv->language_set);
782 case PROP_ELLIPSIZE_SET:
783 g_value_set_boolean (value, priv->ellipsize_set);
786 case PROP_WIDTH_CHARS:
787 g_value_set_int (value, priv->width_chars);
790 case PROP_BACKGROUND:
791 case PROP_FOREGROUND:
794 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
801 set_bg_color (GtkCellRendererText *celltext,
806 if (!celltext->background_set)
808 celltext->background_set = TRUE;
809 g_object_notify (G_OBJECT (celltext), "background-set");
812 celltext->background.red = color->red;
813 celltext->background.green = color->green;
814 celltext->background.blue = color->blue;
818 if (celltext->background_set)
820 celltext->background_set = FALSE;
821 g_object_notify (G_OBJECT (celltext), "background-set");
828 set_fg_color (GtkCellRendererText *celltext,
833 if (!celltext->foreground_set)
835 celltext->foreground_set = TRUE;
836 g_object_notify (G_OBJECT (celltext), "foreground-set");
839 celltext->foreground.red = color->red;
840 celltext->foreground.green = color->green;
841 celltext->foreground.blue = color->blue;
845 if (celltext->foreground_set)
847 celltext->foreground_set = FALSE;
848 g_object_notify (G_OBJECT (celltext), "foreground-set");
854 set_font_desc_fields (PangoFontDescription *desc,
855 PangoFontMask to_set)
857 PangoFontMask changed_mask = 0;
859 if (to_set & PANGO_FONT_MASK_FAMILY)
861 const char *family = pango_font_description_get_family (desc);
865 changed_mask |= PANGO_FONT_MASK_FAMILY;
868 pango_font_description_set_family (desc, family);
870 if (to_set & PANGO_FONT_MASK_STYLE)
871 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
872 if (to_set & PANGO_FONT_MASK_VARIANT)
873 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
874 if (to_set & PANGO_FONT_MASK_WEIGHT)
875 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
876 if (to_set & PANGO_FONT_MASK_STRETCH)
877 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
878 if (to_set & PANGO_FONT_MASK_SIZE)
880 gint size = pango_font_description_get_size (desc);
883 size = 10 * PANGO_SCALE;
884 changed_mask |= PANGO_FONT_MASK_SIZE;
887 pango_font_description_set_size (desc, size);
894 notify_set_changed (GObject *object,
895 PangoFontMask changed_mask)
897 if (changed_mask & PANGO_FONT_MASK_FAMILY)
898 g_object_notify (object, "family-set");
899 if (changed_mask & PANGO_FONT_MASK_STYLE)
900 g_object_notify (object, "style-set");
901 if (changed_mask & PANGO_FONT_MASK_VARIANT)
902 g_object_notify (object, "variant-set");
903 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
904 g_object_notify (object, "weight-set");
905 if (changed_mask & PANGO_FONT_MASK_STRETCH)
906 g_object_notify (object, "stretch-set");
907 if (changed_mask & PANGO_FONT_MASK_SIZE)
908 g_object_notify (object, "size-set");
912 notify_fields_changed (GObject *object,
913 PangoFontMask changed_mask)
915 if (changed_mask & PANGO_FONT_MASK_FAMILY)
916 g_object_notify (object, "family");
917 if (changed_mask & PANGO_FONT_MASK_STYLE)
918 g_object_notify (object, "style");
919 if (changed_mask & PANGO_FONT_MASK_VARIANT)
920 g_object_notify (object, "variant");
921 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
922 g_object_notify (object, "weight");
923 if (changed_mask & PANGO_FONT_MASK_STRETCH)
924 g_object_notify (object, "stretch");
925 if (changed_mask & PANGO_FONT_MASK_SIZE)
926 g_object_notify (object, "size");
930 set_font_description (GtkCellRendererText *celltext,
931 PangoFontDescription *font_desc)
933 GObject *object = G_OBJECT (celltext);
934 PangoFontDescription *new_font_desc;
935 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
938 new_font_desc = pango_font_description_copy (font_desc);
940 new_font_desc = pango_font_description_new ();
942 old_mask = pango_font_description_get_set_fields (celltext->font);
943 new_mask = pango_font_description_get_set_fields (new_font_desc);
945 changed_mask = old_mask | new_mask;
946 set_changed_mask = old_mask ^ new_mask;
948 pango_font_description_free (celltext->font);
949 celltext->font = new_font_desc;
951 g_object_freeze_notify (object);
953 g_object_notify (object, "font-desc");
954 g_object_notify (object, "font");
956 if (changed_mask & PANGO_FONT_MASK_FAMILY)
957 g_object_notify (object, "family");
958 if (changed_mask & PANGO_FONT_MASK_STYLE)
959 g_object_notify (object, "style");
960 if (changed_mask & PANGO_FONT_MASK_VARIANT)
961 g_object_notify (object, "variant");
962 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
963 g_object_notify (object, "weight");
964 if (changed_mask & PANGO_FONT_MASK_STRETCH)
965 g_object_notify (object, "stretch");
966 if (changed_mask & PANGO_FONT_MASK_SIZE)
968 g_object_notify (object, "size");
969 g_object_notify (object, "size-points");
972 notify_set_changed (object, set_changed_mask);
974 g_object_thaw_notify (object);
978 gtk_cell_renderer_text_set_property (GObject *object,
983 GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
984 GtkCellRendererTextPrivate *priv;
986 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (object);
992 g_free (celltext->text);
994 if (priv->markup_set)
996 if (celltext->extra_attrs)
997 pango_attr_list_unref (celltext->extra_attrs);
998 celltext->extra_attrs = NULL;
999 priv->markup_set = FALSE;
1002 celltext->text = g_strdup (g_value_get_string (value));
1003 g_object_notify (object, "text");
1006 case PROP_ATTRIBUTES:
1007 if (celltext->extra_attrs)
1008 pango_attr_list_unref (celltext->extra_attrs);
1010 celltext->extra_attrs = g_value_get_boxed (value);
1011 if (celltext->extra_attrs)
1012 pango_attr_list_ref (celltext->extra_attrs);
1018 GError *error = NULL;
1019 PangoAttrList *attrs = NULL;
1021 str = g_value_get_string (value);
1022 if (str && !pango_parse_markup (str,
1030 g_warning ("Failed to set text from markup due to error parsing markup: %s",
1032 g_error_free (error);
1037 g_free (celltext->text);
1039 if (celltext->extra_attrs)
1040 pango_attr_list_unref (celltext->extra_attrs);
1042 celltext->text = text;
1043 celltext->extra_attrs = attrs;
1044 priv->markup_set = TRUE;
1048 case PROP_SINGLE_PARAGRAPH_MODE:
1049 priv->single_paragraph = g_value_get_boolean (value);
1052 case PROP_BACKGROUND:
1056 if (!g_value_get_string (value))
1057 set_bg_color (celltext, NULL); /* reset to backgrounmd_set to FALSE */
1058 else if (gdk_color_parse (g_value_get_string (value), &color))
1059 set_bg_color (celltext, &color);
1061 g_warning ("Don't know color `%s'", g_value_get_string (value));
1063 g_object_notify (object, "background-gdk");
1067 case PROP_FOREGROUND:
1071 if (!g_value_get_string (value))
1072 set_fg_color (celltext, NULL); /* reset to foreground_set to FALSE */
1073 else if (gdk_color_parse (g_value_get_string (value), &color))
1074 set_fg_color (celltext, &color);
1076 g_warning ("Don't know color `%s'", g_value_get_string (value));
1078 g_object_notify (object, "foreground-gdk");
1082 case PROP_BACKGROUND_GDK:
1083 /* This notifies the GObject itself. */
1084 set_bg_color (celltext, g_value_get_boxed (value));
1087 case PROP_FOREGROUND_GDK:
1088 /* This notifies the GObject itself. */
1089 set_fg_color (celltext, g_value_get_boxed (value));
1094 PangoFontDescription *font_desc = NULL;
1097 name = g_value_get_string (value);
1100 font_desc = pango_font_description_from_string (name);
1102 set_font_description (celltext, font_desc);
1104 pango_font_description_free (font_desc);
1106 if (celltext->fixed_height_rows != -1)
1107 celltext->calc_fixed_height = TRUE;
1111 case PROP_FONT_DESC:
1112 set_font_description (celltext, g_value_get_boxed (value));
1114 if (celltext->fixed_height_rows != -1)
1115 celltext->calc_fixed_height = TRUE;
1124 case PROP_SIZE_POINTS:
1126 PangoFontMask old_set_mask = pango_font_description_get_set_fields (celltext->font);
1131 pango_font_description_set_family (celltext->font,
1132 g_value_get_string (value));
1135 pango_font_description_set_style (celltext->font,
1136 g_value_get_enum (value));
1139 pango_font_description_set_variant (celltext->font,
1140 g_value_get_enum (value));
1143 pango_font_description_set_weight (celltext->font,
1144 g_value_get_int (value));
1147 pango_font_description_set_stretch (celltext->font,
1148 g_value_get_enum (value));
1151 pango_font_description_set_size (celltext->font,
1152 g_value_get_int (value));
1153 g_object_notify (object, "size-points");
1155 case PROP_SIZE_POINTS:
1156 pango_font_description_set_size (celltext->font,
1157 g_value_get_double (value) * PANGO_SCALE);
1158 g_object_notify (object, "size");
1162 if (celltext->fixed_height_rows != -1)
1163 celltext->calc_fixed_height = TRUE;
1165 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (celltext->font));
1166 g_object_notify (object, "font-desc");
1167 g_object_notify (object, "font");
1173 celltext->font_scale = g_value_get_double (value);
1174 celltext->scale_set = TRUE;
1175 if (celltext->fixed_height_rows != -1)
1176 celltext->calc_fixed_height = TRUE;
1177 g_object_notify (object, "scale-set");
1181 celltext->editable = g_value_get_boolean (value);
1182 celltext->editable_set = TRUE;
1183 if (celltext->editable)
1184 GTK_CELL_RENDERER (celltext)->mode = GTK_CELL_RENDERER_MODE_EDITABLE;
1186 GTK_CELL_RENDERER (celltext)->mode = GTK_CELL_RENDERER_MODE_INERT;
1187 g_object_notify (object, "editable-set");
1190 case PROP_STRIKETHROUGH:
1191 celltext->strikethrough = g_value_get_boolean (value);
1192 celltext->strikethrough_set = TRUE;
1193 g_object_notify (object, "strikethrough-set");
1196 case PROP_UNDERLINE:
1197 celltext->underline_style = g_value_get_enum (value);
1198 celltext->underline_set = TRUE;
1199 g_object_notify (object, "underline-set");
1204 celltext->rise = g_value_get_int (value);
1205 celltext->rise_set = TRUE;
1206 g_object_notify (object, "rise-set");
1207 if (celltext->fixed_height_rows != -1)
1208 celltext->calc_fixed_height = TRUE;
1212 priv->language_set = TRUE;
1214 g_object_unref (priv->language);
1215 priv->language = pango_language_from_string (g_value_get_string (value));
1216 g_object_notify (object, "language-set");
1219 case PROP_ELLIPSIZE:
1220 priv->ellipsize = g_value_get_enum (value);
1221 priv->ellipsize_set = TRUE;
1222 g_object_notify (object, "ellipsize-set");
1225 case PROP_WRAP_MODE:
1226 priv->wrap_mode = g_value_get_enum (value);
1229 case PROP_WRAP_WIDTH:
1230 priv->wrap_width = g_value_get_int (value);
1233 case PROP_WIDTH_CHARS:
1234 priv->width_chars = g_value_get_int (value);
1238 priv->align = g_value_get_enum (value);
1239 priv->align_set = TRUE;
1242 case PROP_BACKGROUND_SET:
1243 celltext->background_set = g_value_get_boolean (value);
1246 case PROP_FOREGROUND_SET:
1247 celltext->foreground_set = g_value_get_boolean (value);
1250 case PROP_FAMILY_SET:
1251 case PROP_STYLE_SET:
1252 case PROP_VARIANT_SET:
1253 case PROP_WEIGHT_SET:
1254 case PROP_STRETCH_SET:
1256 if (!g_value_get_boolean (value))
1258 pango_font_description_unset_fields (celltext->font,
1259 get_property_font_set_mask (param_id));
1263 PangoFontMask changed_mask;
1265 changed_mask = set_font_desc_fields (celltext->font,
1266 get_property_font_set_mask (param_id));
1267 notify_fields_changed (G_OBJECT (celltext), changed_mask);
1271 case PROP_SCALE_SET:
1272 celltext->scale_set = g_value_get_boolean (value);
1275 case PROP_EDITABLE_SET:
1276 celltext->editable_set = g_value_get_boolean (value);
1279 case PROP_STRIKETHROUGH_SET:
1280 celltext->strikethrough_set = g_value_get_boolean (value);
1283 case PROP_UNDERLINE_SET:
1284 celltext->underline_set = g_value_get_boolean (value);
1288 celltext->rise_set = g_value_get_boolean (value);
1291 case PROP_LANGUAGE_SET:
1292 priv->language_set = g_value_get_boolean (value);
1295 case PROP_ELLIPSIZE_SET:
1296 priv->ellipsize_set = g_value_get_boolean (value);
1300 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1306 * gtk_cell_renderer_text_new:
1308 * Creates a new #GtkCellRendererText. Adjust how text is drawn using
1309 * object properties. Object properties can be
1310 * set globally (with g_object_set()). Also, with #GtkTreeViewColumn,
1311 * you can bind a property to a value in a #GtkTreeModel. For example,
1312 * you can bind the "text" property on the cell renderer to a string
1313 * value in the model, thus rendering a different string in each row
1314 * of the #GtkTreeView
1316 * Return value: the new cell renderer
1319 gtk_cell_renderer_text_new (void)
1321 return g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, NULL);
1325 add_attr (PangoAttrList *attr_list,
1326 PangoAttribute *attr)
1328 attr->start_index = 0;
1329 attr->end_index = G_MAXINT;
1331 pango_attr_list_insert (attr_list, attr);
1335 get_layout (GtkCellRendererText *celltext,
1337 gboolean will_render,
1338 GtkCellRendererState flags)
1340 PangoAttrList *attr_list;
1341 PangoLayout *layout;
1342 PangoUnderline uline;
1343 GtkCellRendererTextPrivate *priv;
1345 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (celltext);
1347 layout = gtk_widget_create_pango_layout (widget, celltext->text);
1349 if (celltext->extra_attrs)
1350 attr_list = pango_attr_list_copy (celltext->extra_attrs);
1352 attr_list = pango_attr_list_new ();
1354 pango_layout_set_single_paragraph_mode (layout, priv->single_paragraph);
1358 /* Add options that affect appearance but not size */
1360 /* note that background doesn't go here, since it affects
1361 * background_area not the PangoLayout area
1364 if (celltext->foreground_set
1365 && (flags & GTK_CELL_RENDERER_SELECTED) == 0)
1369 color = celltext->foreground;
1371 add_attr (attr_list,
1372 pango_attr_foreground_new (color.red, color.green, color.blue));
1375 if (celltext->strikethrough_set)
1376 add_attr (attr_list,
1377 pango_attr_strikethrough_new (celltext->strikethrough));
1380 add_attr (attr_list, pango_attr_font_desc_new (celltext->font));
1382 if (celltext->scale_set &&
1383 celltext->font_scale != 1.0)
1384 add_attr (attr_list, pango_attr_scale_new (celltext->font_scale));
1386 if (celltext->underline_set)
1387 uline = celltext->underline_style;
1389 uline = PANGO_UNDERLINE_NONE;
1391 if (priv->language_set)
1392 add_attr (attr_list, pango_attr_language_new (priv->language));
1394 if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT)
1398 case PANGO_UNDERLINE_NONE:
1399 uline = PANGO_UNDERLINE_SINGLE;
1402 case PANGO_UNDERLINE_SINGLE:
1403 uline = PANGO_UNDERLINE_DOUBLE;
1411 if (uline != PANGO_UNDERLINE_NONE)
1412 add_attr (attr_list, pango_attr_underline_new (celltext->underline_style));
1414 if (celltext->rise_set)
1415 add_attr (attr_list, pango_attr_rise_new (celltext->rise));
1417 if (priv->ellipsize_set)
1418 pango_layout_set_ellipsize (layout, priv->ellipsize);
1420 pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_NONE);
1422 if (priv->wrap_width != -1)
1424 pango_layout_set_width (layout, priv->wrap_width * PANGO_SCALE);
1425 pango_layout_set_wrap (layout, priv->wrap_mode);
1427 if (pango_layout_get_line_count (layout) == 1)
1429 pango_layout_set_width (layout, -1);
1430 pango_layout_set_wrap (layout, PANGO_WRAP_CHAR);
1435 pango_layout_set_width (layout, -1);
1436 pango_layout_set_wrap (layout, PANGO_WRAP_CHAR);
1439 if (priv->align_set)
1440 pango_layout_set_alignment (layout, priv->align);
1443 PangoAlignment align;
1445 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1446 align = PANGO_ALIGN_RIGHT;
1448 align = PANGO_ALIGN_LEFT;
1450 pango_layout_set_alignment (layout, align);
1453 pango_layout_set_attributes (layout, attr_list);
1455 pango_attr_list_unref (attr_list);
1461 get_size (GtkCellRenderer *cell,
1463 GdkRectangle *cell_area,
1464 PangoLayout *layout,
1470 GtkCellRendererText *celltext = (GtkCellRendererText *) cell;
1471 PangoRectangle rect;
1472 GtkCellRendererTextPrivate *priv;
1474 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
1476 if (celltext->calc_fixed_height)
1478 PangoContext *context;
1479 PangoFontMetrics *metrics;
1480 PangoFontDescription *font_desc;
1483 font_desc = pango_font_description_copy_static (widget->style->font_desc);
1484 pango_font_description_merge_static (font_desc, celltext->font, TRUE);
1486 if (celltext->scale_set)
1487 pango_font_description_set_size (font_desc,
1488 celltext->font_scale * pango_font_description_get_size (font_desc));
1490 context = gtk_widget_get_pango_context (widget);
1492 metrics = pango_context_get_metrics (context,
1494 pango_context_get_language (context));
1495 row_height = (pango_font_metrics_get_ascent (metrics) +
1496 pango_font_metrics_get_descent (metrics));
1497 pango_font_metrics_unref (metrics);
1499 pango_font_description_free (font_desc);
1501 gtk_cell_renderer_set_fixed_size (cell,
1502 cell->width, 2*cell->ypad +
1503 celltext->fixed_height_rows * PANGO_PIXELS (row_height));
1507 *height = cell->height;
1510 celltext->calc_fixed_height = FALSE;
1516 g_object_ref (layout);
1518 layout = get_layout (celltext, widget, FALSE, 0);
1520 pango_layout_get_pixel_extents (layout, NULL, &rect);
1523 *height = cell->ypad * 2 + rect.height;
1525 /* The minimum size for ellipsized labels is ~ 3 chars */
1528 if (priv->ellipsize || priv->width_chars > 0)
1530 PangoContext *context;
1531 PangoFontMetrics *metrics;
1534 context = pango_layout_get_context (layout);
1535 metrics = pango_context_get_metrics (context, widget->style->font_desc, pango_context_get_language (context));
1537 char_width = pango_font_metrics_get_approximate_char_width (metrics);
1538 pango_font_metrics_unref (metrics);
1540 *width = cell->xpad * 2 + (PANGO_PIXELS (char_width) * MAX (priv->width_chars, 3));
1544 *width = cell->xpad * 2 + rect.x + rect.width;
1552 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1553 *x_offset = (1.0 - cell->xalign) * (cell_area->width - (rect.x + rect.width + (2 * cell->xpad)));
1555 *x_offset = cell->xalign * (cell_area->width - (rect.x + rect.width + (2 * cell->xpad)));
1557 if ((priv->ellipsize_set && priv->ellipsize != PANGO_ELLIPSIZE_NONE) || priv->wrap_width != -1)
1558 *x_offset = MAX(*x_offset, 0);
1562 *y_offset = cell->yalign * (cell_area->height - (rect.height + (2 * cell->ypad)));
1563 *y_offset = MAX (*y_offset, 0);
1567 g_object_unref (layout);
1572 gtk_cell_renderer_text_get_size (GtkCellRenderer *cell,
1574 GdkRectangle *cell_area,
1580 get_size (cell, widget, cell_area, NULL,
1581 x_offset, y_offset, width, height);
1585 gtk_cell_renderer_text_render (GtkCellRenderer *cell,
1586 GdkDrawable *window,
1588 GdkRectangle *background_area,
1589 GdkRectangle *cell_area,
1590 GdkRectangle *expose_area,
1591 GtkCellRendererState flags)
1594 GtkCellRendererText *celltext = (GtkCellRendererText *) cell;
1595 PangoLayout *layout;
1599 GtkCellRendererTextPrivate *priv;
1601 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
1603 layout = get_layout (celltext, widget, TRUE, flags);
1604 get_size (cell, widget, cell_area, layout, &x_offset, &y_offset, NULL, NULL);
1606 if (!cell->sensitive)
1608 state = GTK_STATE_INSENSITIVE;
1610 else if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
1612 if (GTK_WIDGET_HAS_FOCUS (widget))
1613 state = GTK_STATE_SELECTED;
1615 state = GTK_STATE_ACTIVE;
1617 else if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT &&
1618 GTK_WIDGET_STATE (widget) == GTK_STATE_PRELIGHT)
1620 state = GTK_STATE_PRELIGHT;
1624 if (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE)
1625 state = GTK_STATE_INSENSITIVE;
1627 state = GTK_STATE_NORMAL;
1630 if (celltext->background_set &&
1631 (flags & GTK_CELL_RENDERER_SELECTED) == 0)
1633 cairo_t *cr = gdk_cairo_create (window);
1637 gdk_cairo_rectangle (cr, expose_area);
1641 gdk_cairo_rectangle (cr, background_area);
1642 cairo_set_source_rgb (cr,
1643 celltext->background.red / 65535.,
1644 celltext->background.green / 65535.,
1645 celltext->background.blue / 65535.);
1651 if (priv->ellipsize_set && priv->ellipsize != PANGO_ELLIPSIZE_NONE)
1652 pango_layout_set_width (layout,
1653 (cell_area->width - x_offset - 2 * cell->xpad) * PANGO_SCALE);
1654 else if (priv->wrap_width == -1)
1655 pango_layout_set_width (layout, -1);
1657 gtk_paint_layout (widget->style,
1664 cell_area->x + x_offset + cell->xpad,
1665 cell_area->y + y_offset + cell->ypad,
1668 g_object_unref (layout);
1672 gtk_cell_renderer_text_editing_done (GtkCellEditable *entry,
1676 const gchar *new_text;
1677 GtkCellRendererTextPrivate *priv;
1679 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1683 if (priv->focus_out_id > 0)
1685 g_signal_handler_disconnect (entry, priv->focus_out_id);
1686 priv->focus_out_id = 0;
1689 if (priv->populate_popup_id > 0)
1691 g_signal_handler_disconnect (entry, priv->populate_popup_id);
1692 priv->populate_popup_id = 0;
1695 if (priv->entry_menu_popdown_timeout)
1697 g_source_remove (priv->entry_menu_popdown_timeout);
1698 priv->entry_menu_popdown_timeout = 0;
1701 gtk_cell_renderer_stop_editing (GTK_CELL_RENDERER (data),
1702 GTK_ENTRY (entry)->editing_canceled);
1703 if (GTK_ENTRY (entry)->editing_canceled)
1706 path = g_object_get_data (G_OBJECT (entry), GTK_CELL_RENDERER_TEXT_PATH);
1707 new_text = gtk_entry_get_text (GTK_ENTRY (entry));
1709 g_signal_emit (data, text_cell_renderer_signals[EDITED], 0, path, new_text);
1713 popdown_timeout (gpointer data)
1715 GtkCellRendererTextPrivate *priv;
1717 GDK_THREADS_ENTER ();
1719 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1721 priv->entry_menu_popdown_timeout = 0;
1723 if (!GTK_WIDGET_HAS_FOCUS (priv->entry))
1724 gtk_cell_renderer_text_editing_done (GTK_CELL_EDITABLE (priv->entry), data);
1726 GDK_THREADS_LEAVE ();
1732 gtk_cell_renderer_text_popup_unmap (GtkMenu *menu,
1735 GtkCellRendererTextPrivate *priv;
1737 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1739 priv->in_entry_menu = FALSE;
1741 if (priv->entry_menu_popdown_timeout)
1744 priv->entry_menu_popdown_timeout = g_timeout_add (500, popdown_timeout,
1749 gtk_cell_renderer_text_populate_popup (GtkEntry *entry,
1753 GtkCellRendererTextPrivate *priv;
1755 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1757 if (priv->entry_menu_popdown_timeout)
1759 g_source_remove (priv->entry_menu_popdown_timeout);
1760 priv->entry_menu_popdown_timeout = 0;
1763 priv->in_entry_menu = TRUE;
1765 g_signal_connect (menu, "unmap",
1766 G_CALLBACK (gtk_cell_renderer_text_popup_unmap), data);
1770 gtk_cell_renderer_text_focus_out_event (GtkWidget *entry,
1774 GtkCellRendererTextPrivate *priv;
1776 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1778 if (priv->in_entry_menu)
1781 gtk_cell_renderer_text_editing_done (GTK_CELL_EDITABLE (entry), data);
1783 /* entry needs focus-out-event */
1787 static GtkCellEditable *
1788 gtk_cell_renderer_text_start_editing (GtkCellRenderer *cell,
1792 GdkRectangle *background_area,
1793 GdkRectangle *cell_area,
1794 GtkCellRendererState flags)
1796 GtkRequisition requisition;
1797 GtkCellRendererText *celltext;
1798 GtkCellRendererTextPrivate *priv;
1800 celltext = GTK_CELL_RENDERER_TEXT (cell);
1801 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
1803 /* If the cell isn't editable we return NULL. */
1804 if (celltext->editable == FALSE)
1807 priv->entry = g_object_new (GTK_TYPE_ENTRY,
1809 "xalign", cell->xalign,
1813 gtk_entry_set_text (GTK_ENTRY (priv->entry), celltext->text);
1814 g_object_set_data_full (G_OBJECT (priv->entry), I_(GTK_CELL_RENDERER_TEXT_PATH), g_strdup (path), g_free);
1816 gtk_editable_select_region (GTK_EDITABLE (priv->entry), 0, -1);
1818 gtk_widget_size_request (priv->entry, &requisition);
1819 if (requisition.height < cell_area->height)
1821 GtkBorder *style_border;
1824 gtk_widget_style_get (priv->entry,
1825 "inner-border", &style_border,
1830 border = *style_border;
1831 g_boxed_free (GTK_TYPE_BORDER, style_border);
1835 /* Since boxed style properties can't have default values ... */
1840 border.top = (cell_area->height - requisition.height) / 2;
1841 border.bottom = (cell_area->height - requisition.height) / 2;
1842 gtk_entry_set_inner_border (GTK_ENTRY (priv->entry), &border);
1845 priv->in_entry_menu = FALSE;
1846 if (priv->entry_menu_popdown_timeout)
1848 g_source_remove (priv->entry_menu_popdown_timeout);
1849 priv->entry_menu_popdown_timeout = 0;
1852 g_signal_connect (priv->entry,
1854 G_CALLBACK (gtk_cell_renderer_text_editing_done),
1856 priv->focus_out_id = g_signal_connect_after (priv->entry, "focus_out_event",
1857 G_CALLBACK (gtk_cell_renderer_text_focus_out_event),
1859 priv->populate_popup_id =
1860 g_signal_connect (priv->entry, "populate_popup",
1861 G_CALLBACK (gtk_cell_renderer_text_populate_popup),
1864 gtk_widget_show (priv->entry);
1866 return GTK_CELL_EDITABLE (priv->entry);
1870 * gtk_cell_renderer_text_set_fixed_height_from_font:
1871 * @renderer: A #GtkCellRendererText
1872 * @number_of_rows: Number of rows of text each cell renderer is allocated, or -1
1874 * Sets the height of a renderer to explicitly be determined by the "font" and
1875 * "y_pad" property set on it. Further changes in these properties do not
1876 * affect the height, so they must be accompanied by a subsequent call to this
1877 * function. Using this function is unflexible, and should really only be used
1878 * if calculating the size of a cell is too slow (ie, a massive number of cells
1879 * displayed). If @number_of_rows is -1, then the fixed height is unset, and
1880 * the height is determined by the properties again.
1883 gtk_cell_renderer_text_set_fixed_height_from_font (GtkCellRendererText *renderer,
1884 gint number_of_rows)
1886 g_return_if_fail (GTK_IS_CELL_RENDERER_TEXT (renderer));
1887 g_return_if_fail (number_of_rows == -1 || number_of_rows > 0);
1889 if (number_of_rows == -1)
1891 gtk_cell_renderer_set_fixed_size (GTK_CELL_RENDERER (renderer),
1892 GTK_CELL_RENDERER (renderer)->width,
1897 renderer->fixed_height_rows = number_of_rows;
1898 renderer->calc_fixed_height = TRUE;
1902 #define __GTK_CELL_RENDERER_TEXT_C__
1903 #include "gtkaliasdef.c"