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,
122 static guint text_cell_renderer_signals [LAST_SIGNAL];
124 #define GTK_CELL_RENDERER_TEXT_PATH "gtk-cell-renderer-text-path"
126 #define GTK_CELL_RENDERER_TEXT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CELL_RENDERER_TEXT, GtkCellRendererTextPrivate))
128 typedef struct _GtkCellRendererTextPrivate GtkCellRendererTextPrivate;
129 struct _GtkCellRendererTextPrivate
131 guint single_paragraph : 1;
132 guint language_set : 1;
133 guint markup_set : 1;
134 guint ellipsize_set : 1;
138 PangoLanguage *language;
139 PangoEllipsizeMode ellipsize;
140 PangoWrapMode wrap_mode;
141 PangoAlignment align;
143 gulong populate_popup_id;
144 gulong entry_menu_popdown_timeout;
145 gboolean in_entry_menu;
153 G_DEFINE_TYPE (GtkCellRendererText, gtk_cell_renderer_text, GTK_TYPE_CELL_RENDERER)
156 gtk_cell_renderer_text_init (GtkCellRendererText *celltext)
158 GtkCellRendererTextPrivate *priv;
160 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (celltext);
162 GTK_CELL_RENDERER (celltext)->xalign = 0.0;
163 GTK_CELL_RENDERER (celltext)->yalign = 0.5;
164 GTK_CELL_RENDERER (celltext)->xpad = 2;
165 GTK_CELL_RENDERER (celltext)->ypad = 2;
166 celltext->font_scale = 1.0;
167 celltext->fixed_height_rows = -1;
168 celltext->font = pango_font_description_new ();
170 priv->width_chars = -1;
171 priv->wrap_width = -1;
172 priv->wrap_mode = PANGO_WRAP_CHAR;
173 priv->align = PANGO_ALIGN_LEFT;
174 priv->align_set = FALSE;
178 gtk_cell_renderer_text_class_init (GtkCellRendererTextClass *class)
180 GObjectClass *object_class = G_OBJECT_CLASS (class);
181 GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);
183 object_class->finalize = gtk_cell_renderer_text_finalize;
185 object_class->get_property = gtk_cell_renderer_text_get_property;
186 object_class->set_property = gtk_cell_renderer_text_set_property;
188 cell_class->get_size = gtk_cell_renderer_text_get_size;
189 cell_class->render = gtk_cell_renderer_text_render;
190 cell_class->start_editing = gtk_cell_renderer_text_start_editing;
192 g_object_class_install_property (object_class,
194 g_param_spec_string ("text",
196 P_("Text to render"),
198 GTK_PARAM_READWRITE));
200 g_object_class_install_property (object_class,
202 g_param_spec_string ("markup",
204 P_("Marked up text to render"),
206 GTK_PARAM_WRITABLE));
208 g_object_class_install_property (object_class,
210 g_param_spec_boxed ("attributes",
212 P_("A list of style attributes to apply to the text of the renderer"),
213 PANGO_TYPE_ATTR_LIST,
214 GTK_PARAM_READWRITE));
216 g_object_class_install_property (object_class,
217 PROP_SINGLE_PARAGRAPH_MODE,
218 g_param_spec_boolean ("single-paragraph-mode",
219 P_("Single Paragraph Mode"),
220 P_("Whether or not to keep all text in a single paragraph"),
222 GTK_PARAM_READWRITE));
225 g_object_class_install_property (object_class,
227 g_param_spec_string ("background",
228 P_("Background color name"),
229 P_("Background color as a string"),
231 GTK_PARAM_WRITABLE));
233 g_object_class_install_property (object_class,
235 g_param_spec_boxed ("background-gdk",
236 P_("Background color"),
237 P_("Background color as a GdkColor"),
239 GTK_PARAM_READWRITE));
241 g_object_class_install_property (object_class,
243 g_param_spec_string ("foreground",
244 P_("Foreground color name"),
245 P_("Foreground color as a string"),
247 GTK_PARAM_WRITABLE));
249 g_object_class_install_property (object_class,
251 g_param_spec_boxed ("foreground-gdk",
252 P_("Foreground color"),
253 P_("Foreground color as a GdkColor"),
255 GTK_PARAM_READWRITE));
258 g_object_class_install_property (object_class,
260 g_param_spec_boolean ("editable",
262 P_("Whether the text can be modified by the user"),
264 GTK_PARAM_READWRITE));
266 g_object_class_install_property (object_class,
268 g_param_spec_string ("font",
270 P_("Font description as a string, e.g. \"Sans Italic 12\""),
272 GTK_PARAM_READWRITE));
274 g_object_class_install_property (object_class,
276 g_param_spec_boxed ("font-desc",
278 P_("Font description as a PangoFontDescription struct"),
279 PANGO_TYPE_FONT_DESCRIPTION,
280 GTK_PARAM_READWRITE));
283 g_object_class_install_property (object_class,
285 g_param_spec_string ("family",
287 P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
289 GTK_PARAM_READWRITE));
291 g_object_class_install_property (object_class,
293 g_param_spec_enum ("style",
298 GTK_PARAM_READWRITE));
300 g_object_class_install_property (object_class,
302 g_param_spec_enum ("variant",
306 PANGO_VARIANT_NORMAL,
307 GTK_PARAM_READWRITE));
309 g_object_class_install_property (object_class,
311 g_param_spec_int ("weight",
317 GTK_PARAM_READWRITE));
319 g_object_class_install_property (object_class,
321 g_param_spec_enum ("stretch",
325 PANGO_STRETCH_NORMAL,
326 GTK_PARAM_READWRITE));
328 g_object_class_install_property (object_class,
330 g_param_spec_int ("size",
336 GTK_PARAM_READWRITE));
338 g_object_class_install_property (object_class,
340 g_param_spec_double ("size-points",
342 P_("Font size in points"),
346 GTK_PARAM_READWRITE));
348 g_object_class_install_property (object_class,
350 g_param_spec_double ("scale",
352 P_("Font scaling factor"),
356 GTK_PARAM_READWRITE));
358 g_object_class_install_property (object_class,
360 g_param_spec_int ("rise",
362 P_("Offset of text above the baseline "
363 "(below the baseline if rise is negative)"),
367 GTK_PARAM_READWRITE));
370 g_object_class_install_property (object_class,
372 g_param_spec_boolean ("strikethrough",
374 P_("Whether to strike through the text"),
376 GTK_PARAM_READWRITE));
378 g_object_class_install_property (object_class,
380 g_param_spec_enum ("underline",
382 P_("Style of underline for this text"),
383 PANGO_TYPE_UNDERLINE,
384 PANGO_UNDERLINE_NONE,
385 GTK_PARAM_READWRITE));
387 g_object_class_install_property (object_class,
389 g_param_spec_string ("language",
391 P_("The language this text is in, as an ISO code. "
392 "Pango can use this as a hint when rendering the text. "
393 "If you don't understand this parameter, you probably don't need it"),
395 GTK_PARAM_READWRITE));
399 * GtkCellRendererText:ellipsize:
401 * Specifies the preferred place to ellipsize the string, if the cell renderer
402 * does not have enough room to display the entire string. Setting it to
403 * %PANGO_ELLIPSIZE_NONE turns off ellipsizing. See the wrap-width property
404 * for another way of making the text fit into a given width.
408 g_object_class_install_property (object_class,
410 g_param_spec_enum ("ellipsize",
412 P_("The preferred place to ellipsize the string, "
413 "if the cell renderer does not have enough room "
414 "to display the entire string"),
415 PANGO_TYPE_ELLIPSIZE_MODE,
416 PANGO_ELLIPSIZE_NONE,
417 GTK_PARAM_READWRITE));
420 * GtkCellRendererText:width-chars:
422 * The desired width of the cell, in characters. If this property is set to
423 * -1, the width will be calculated automatically, otherwise the cell will
424 * request either 3 characters or the property value, whichever is greater.
428 g_object_class_install_property (object_class,
430 g_param_spec_int ("width-chars",
431 P_("Width In Characters"),
432 P_("The desired width of the label, in characters"),
436 GTK_PARAM_READWRITE));
439 * GtkCellRendererText:wrap-mode:
441 * Specifies how to break the string into multiple lines, if the cell
442 * renderer does not have enough room to display the entire string.
443 * This property has no effect unless the wrap-width property is set.
447 g_object_class_install_property (object_class,
449 g_param_spec_enum ("wrap-mode",
451 P_("How to break the string into multiple lines, "
452 "if the cell renderer does not have enough room "
453 "to display the entire string"),
454 PANGO_TYPE_WRAP_MODE,
456 GTK_PARAM_READWRITE));
459 * GtkCellRendererText:wrap-width:
461 * Specifies the width at which the text is wrapped. The wrap-mode property can
462 * be used to influence at what character positions the line breaks can be placed.
463 * Setting wrap-width to -1 turns wrapping off.
467 g_object_class_install_property (object_class,
469 g_param_spec_int ("wrap-width",
471 P_("The width at which the text is wrapped"),
475 GTK_PARAM_READWRITE));
478 * GtkCellRendererText:alignment:
480 * Specifies how to align the lines of text with respect to each other.
482 * Note that this property describes how to align the lines of text in
483 * case there are several of them. The "xalign" property of #GtkCellRenderer,
484 * on the other hand, sets the horizontal alignment of the whole text.
488 g_object_class_install_property (object_class,
490 g_param_spec_enum ("alignment",
492 P_("How to align the lines"),
493 PANGO_TYPE_ALIGNMENT,
495 GTK_PARAM_READWRITE));
497 /* Style props are set or not */
499 #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))
501 ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
502 P_("Background set"),
503 P_("Whether this tag affects the background color"));
505 ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
506 P_("Foreground set"),
507 P_("Whether this tag affects the foreground color"));
509 ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
510 P_("Editability set"),
511 P_("Whether this tag affects text editability"));
513 ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
514 P_("Font family set"),
515 P_("Whether this tag affects the font family"));
517 ADD_SET_PROP ("style-set", PROP_STYLE_SET,
518 P_("Font style set"),
519 P_("Whether this tag affects the font style"));
521 ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
522 P_("Font variant set"),
523 P_("Whether this tag affects the font variant"));
525 ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
526 P_("Font weight set"),
527 P_("Whether this tag affects the font weight"));
529 ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
530 P_("Font stretch set"),
531 P_("Whether this tag affects the font stretch"));
533 ADD_SET_PROP ("size-set", PROP_SIZE_SET,
535 P_("Whether this tag affects the font size"));
537 ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
538 P_("Font scale set"),
539 P_("Whether this tag scales the font size by a factor"));
541 ADD_SET_PROP ("rise-set", PROP_RISE_SET,
543 P_("Whether this tag affects the rise"));
545 ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
546 P_("Strikethrough set"),
547 P_("Whether this tag affects strikethrough"));
549 ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
551 P_("Whether this tag affects underlining"));
553 ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
555 P_("Whether this tag affects the language the text is rendered as"));
557 ADD_SET_PROP ("ellipsize-set", PROP_ELLIPSIZE_SET,
559 P_("Whether this tag affects the ellipsize mode"));
561 ADD_SET_PROP ("align-set", PROP_ALIGN_SET,
563 P_("Whether this tag affects the alignment mode"));
566 * GtkCellRendererText::edited
567 * @renderer: the object which received the signal
568 * @path: the path identifying the edited cell
569 * @new_text: the new text
571 * This signal is emitted after @renderer has been edited.
573 * It is the responsibility of the application to update the model
574 * and store @new_text at the position indicated by @path.
576 text_cell_renderer_signals [EDITED] =
577 g_signal_new (I_("edited"),
578 G_OBJECT_CLASS_TYPE (object_class),
580 G_STRUCT_OFFSET (GtkCellRendererTextClass, edited),
582 _gtk_marshal_VOID__STRING_STRING,
587 g_type_class_add_private (object_class, sizeof (GtkCellRendererTextPrivate));
591 gtk_cell_renderer_text_finalize (GObject *object)
593 GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
594 GtkCellRendererTextPrivate *priv;
596 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (object);
598 pango_font_description_free (celltext->font);
600 g_free (celltext->text);
602 if (celltext->extra_attrs)
603 pango_attr_list_unref (celltext->extra_attrs);
606 g_object_unref (priv->language);
608 G_OBJECT_CLASS (gtk_cell_renderer_text_parent_class)->finalize (object);
612 get_property_font_set_mask (guint prop_id)
616 case PROP_FAMILY_SET:
617 return PANGO_FONT_MASK_FAMILY;
619 return PANGO_FONT_MASK_STYLE;
620 case PROP_VARIANT_SET:
621 return PANGO_FONT_MASK_VARIANT;
622 case PROP_WEIGHT_SET:
623 return PANGO_FONT_MASK_WEIGHT;
624 case PROP_STRETCH_SET:
625 return PANGO_FONT_MASK_STRETCH;
627 return PANGO_FONT_MASK_SIZE;
634 gtk_cell_renderer_text_get_property (GObject *object,
639 GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
640 GtkCellRendererTextPrivate *priv;
642 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (object);
647 g_value_set_string (value, celltext->text);
650 case PROP_ATTRIBUTES:
651 g_value_set_boxed (value, celltext->extra_attrs);
654 case PROP_SINGLE_PARAGRAPH_MODE:
655 g_value_set_boolean (value, priv->single_paragraph);
658 case PROP_BACKGROUND_GDK:
662 color.red = celltext->background.red;
663 color.green = celltext->background.green;
664 color.blue = celltext->background.blue;
666 g_value_set_boxed (value, &color);
670 case PROP_FOREGROUND_GDK:
674 color.red = celltext->foreground.red;
675 color.green = celltext->foreground.green;
676 color.blue = celltext->foreground.blue;
678 g_value_set_boxed (value, &color);
683 g_value_take_string (value, pango_font_description_to_string (celltext->font));
687 g_value_set_boxed (value, celltext->font);
691 g_value_set_string (value, pango_font_description_get_family (celltext->font));
695 g_value_set_enum (value, pango_font_description_get_style (celltext->font));
699 g_value_set_enum (value, pango_font_description_get_variant (celltext->font));
703 g_value_set_int (value, pango_font_description_get_weight (celltext->font));
707 g_value_set_enum (value, pango_font_description_get_stretch (celltext->font));
711 g_value_set_int (value, pango_font_description_get_size (celltext->font));
714 case PROP_SIZE_POINTS:
715 g_value_set_double (value, ((double)pango_font_description_get_size (celltext->font)) / (double)PANGO_SCALE);
719 g_value_set_double (value, celltext->font_scale);
723 g_value_set_boolean (value, celltext->editable);
726 case PROP_STRIKETHROUGH:
727 g_value_set_boolean (value, celltext->strikethrough);
731 g_value_set_enum (value, celltext->underline_style);
735 g_value_set_int (value, celltext->rise);
739 g_value_set_static_string (value, pango_language_to_string (priv->language));
743 g_value_set_enum (value, priv->ellipsize);
747 g_value_set_enum (value, priv->wrap_mode);
750 case PROP_WRAP_WIDTH:
751 g_value_set_int (value, priv->wrap_width);
755 g_value_set_enum (value, priv->align);
758 case PROP_BACKGROUND_SET:
759 g_value_set_boolean (value, celltext->background_set);
762 case PROP_FOREGROUND_SET:
763 g_value_set_boolean (value, celltext->foreground_set);
766 case PROP_FAMILY_SET:
768 case PROP_VARIANT_SET:
769 case PROP_WEIGHT_SET:
770 case PROP_STRETCH_SET:
773 PangoFontMask mask = get_property_font_set_mask (param_id);
774 g_value_set_boolean (value, (pango_font_description_get_set_fields (celltext->font) & mask) != 0);
780 g_value_set_boolean (value, celltext->scale_set);
783 case PROP_EDITABLE_SET:
784 g_value_set_boolean (value, celltext->editable_set);
787 case PROP_STRIKETHROUGH_SET:
788 g_value_set_boolean (value, celltext->strikethrough_set);
791 case PROP_UNDERLINE_SET:
792 g_value_set_boolean (value, celltext->underline_set);
796 g_value_set_boolean (value, celltext->rise_set);
799 case PROP_LANGUAGE_SET:
800 g_value_set_boolean (value, priv->language_set);
803 case PROP_ELLIPSIZE_SET:
804 g_value_set_boolean (value, priv->ellipsize_set);
808 g_value_set_boolean (value, priv->align_set);
811 case PROP_WIDTH_CHARS:
812 g_value_set_int (value, priv->width_chars);
815 case PROP_BACKGROUND:
816 case PROP_FOREGROUND:
819 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
826 set_bg_color (GtkCellRendererText *celltext,
831 if (!celltext->background_set)
833 celltext->background_set = TRUE;
834 g_object_notify (G_OBJECT (celltext), "background-set");
837 celltext->background.red = color->red;
838 celltext->background.green = color->green;
839 celltext->background.blue = color->blue;
843 if (celltext->background_set)
845 celltext->background_set = FALSE;
846 g_object_notify (G_OBJECT (celltext), "background-set");
853 set_fg_color (GtkCellRendererText *celltext,
858 if (!celltext->foreground_set)
860 celltext->foreground_set = TRUE;
861 g_object_notify (G_OBJECT (celltext), "foreground-set");
864 celltext->foreground.red = color->red;
865 celltext->foreground.green = color->green;
866 celltext->foreground.blue = color->blue;
870 if (celltext->foreground_set)
872 celltext->foreground_set = FALSE;
873 g_object_notify (G_OBJECT (celltext), "foreground-set");
879 set_font_desc_fields (PangoFontDescription *desc,
880 PangoFontMask to_set)
882 PangoFontMask changed_mask = 0;
884 if (to_set & PANGO_FONT_MASK_FAMILY)
886 const char *family = pango_font_description_get_family (desc);
890 changed_mask |= PANGO_FONT_MASK_FAMILY;
893 pango_font_description_set_family (desc, family);
895 if (to_set & PANGO_FONT_MASK_STYLE)
896 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
897 if (to_set & PANGO_FONT_MASK_VARIANT)
898 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
899 if (to_set & PANGO_FONT_MASK_WEIGHT)
900 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
901 if (to_set & PANGO_FONT_MASK_STRETCH)
902 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
903 if (to_set & PANGO_FONT_MASK_SIZE)
905 gint size = pango_font_description_get_size (desc);
908 size = 10 * PANGO_SCALE;
909 changed_mask |= PANGO_FONT_MASK_SIZE;
912 pango_font_description_set_size (desc, size);
919 notify_set_changed (GObject *object,
920 PangoFontMask changed_mask)
922 if (changed_mask & PANGO_FONT_MASK_FAMILY)
923 g_object_notify (object, "family-set");
924 if (changed_mask & PANGO_FONT_MASK_STYLE)
925 g_object_notify (object, "style-set");
926 if (changed_mask & PANGO_FONT_MASK_VARIANT)
927 g_object_notify (object, "variant-set");
928 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
929 g_object_notify (object, "weight-set");
930 if (changed_mask & PANGO_FONT_MASK_STRETCH)
931 g_object_notify (object, "stretch-set");
932 if (changed_mask & PANGO_FONT_MASK_SIZE)
933 g_object_notify (object, "size-set");
937 notify_fields_changed (GObject *object,
938 PangoFontMask changed_mask)
940 if (changed_mask & PANGO_FONT_MASK_FAMILY)
941 g_object_notify (object, "family");
942 if (changed_mask & PANGO_FONT_MASK_STYLE)
943 g_object_notify (object, "style");
944 if (changed_mask & PANGO_FONT_MASK_VARIANT)
945 g_object_notify (object, "variant");
946 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
947 g_object_notify (object, "weight");
948 if (changed_mask & PANGO_FONT_MASK_STRETCH)
949 g_object_notify (object, "stretch");
950 if (changed_mask & PANGO_FONT_MASK_SIZE)
951 g_object_notify (object, "size");
955 set_font_description (GtkCellRendererText *celltext,
956 PangoFontDescription *font_desc)
958 GObject *object = G_OBJECT (celltext);
959 PangoFontDescription *new_font_desc;
960 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
963 new_font_desc = pango_font_description_copy (font_desc);
965 new_font_desc = pango_font_description_new ();
967 old_mask = pango_font_description_get_set_fields (celltext->font);
968 new_mask = pango_font_description_get_set_fields (new_font_desc);
970 changed_mask = old_mask | new_mask;
971 set_changed_mask = old_mask ^ new_mask;
973 pango_font_description_free (celltext->font);
974 celltext->font = new_font_desc;
976 g_object_freeze_notify (object);
978 g_object_notify (object, "font-desc");
979 g_object_notify (object, "font");
981 if (changed_mask & PANGO_FONT_MASK_FAMILY)
982 g_object_notify (object, "family");
983 if (changed_mask & PANGO_FONT_MASK_STYLE)
984 g_object_notify (object, "style");
985 if (changed_mask & PANGO_FONT_MASK_VARIANT)
986 g_object_notify (object, "variant");
987 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
988 g_object_notify (object, "weight");
989 if (changed_mask & PANGO_FONT_MASK_STRETCH)
990 g_object_notify (object, "stretch");
991 if (changed_mask & PANGO_FONT_MASK_SIZE)
993 g_object_notify (object, "size");
994 g_object_notify (object, "size-points");
997 notify_set_changed (object, set_changed_mask);
999 g_object_thaw_notify (object);
1003 gtk_cell_renderer_text_set_property (GObject *object,
1005 const GValue *value,
1008 GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
1009 GtkCellRendererTextPrivate *priv;
1011 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (object);
1016 g_free (celltext->text);
1018 if (priv->markup_set)
1020 if (celltext->extra_attrs)
1021 pango_attr_list_unref (celltext->extra_attrs);
1022 celltext->extra_attrs = NULL;
1023 priv->markup_set = FALSE;
1026 celltext->text = g_value_dup_string (value);
1027 g_object_notify (object, "text");
1030 case PROP_ATTRIBUTES:
1031 if (celltext->extra_attrs)
1032 pango_attr_list_unref (celltext->extra_attrs);
1034 celltext->extra_attrs = g_value_get_boxed (value);
1035 if (celltext->extra_attrs)
1036 pango_attr_list_ref (celltext->extra_attrs);
1042 GError *error = NULL;
1043 PangoAttrList *attrs = NULL;
1045 str = g_value_get_string (value);
1046 if (str && !pango_parse_markup (str,
1054 g_warning ("Failed to set text from markup due to error parsing markup: %s",
1056 g_error_free (error);
1060 g_free (celltext->text);
1062 if (celltext->extra_attrs)
1063 pango_attr_list_unref (celltext->extra_attrs);
1065 celltext->text = text;
1066 celltext->extra_attrs = attrs;
1067 priv->markup_set = TRUE;
1071 case PROP_SINGLE_PARAGRAPH_MODE:
1072 priv->single_paragraph = g_value_get_boolean (value);
1075 case PROP_BACKGROUND:
1079 if (!g_value_get_string (value))
1080 set_bg_color (celltext, NULL); /* reset to background_set to FALSE */
1081 else if (gdk_color_parse (g_value_get_string (value), &color))
1082 set_bg_color (celltext, &color);
1084 g_warning ("Don't know color `%s'", g_value_get_string (value));
1086 g_object_notify (object, "background-gdk");
1090 case PROP_FOREGROUND:
1094 if (!g_value_get_string (value))
1095 set_fg_color (celltext, NULL); /* reset to foreground_set to FALSE */
1096 else if (gdk_color_parse (g_value_get_string (value), &color))
1097 set_fg_color (celltext, &color);
1099 g_warning ("Don't know color `%s'", g_value_get_string (value));
1101 g_object_notify (object, "foreground-gdk");
1105 case PROP_BACKGROUND_GDK:
1106 /* This notifies the GObject itself. */
1107 set_bg_color (celltext, g_value_get_boxed (value));
1110 case PROP_FOREGROUND_GDK:
1111 /* This notifies the GObject itself. */
1112 set_fg_color (celltext, g_value_get_boxed (value));
1117 PangoFontDescription *font_desc = NULL;
1120 name = g_value_get_string (value);
1123 font_desc = pango_font_description_from_string (name);
1125 set_font_description (celltext, font_desc);
1127 pango_font_description_free (font_desc);
1129 if (celltext->fixed_height_rows != -1)
1130 celltext->calc_fixed_height = TRUE;
1134 case PROP_FONT_DESC:
1135 set_font_description (celltext, g_value_get_boxed (value));
1137 if (celltext->fixed_height_rows != -1)
1138 celltext->calc_fixed_height = TRUE;
1147 case PROP_SIZE_POINTS:
1149 PangoFontMask old_set_mask = pango_font_description_get_set_fields (celltext->font);
1154 pango_font_description_set_family (celltext->font,
1155 g_value_get_string (value));
1158 pango_font_description_set_style (celltext->font,
1159 g_value_get_enum (value));
1162 pango_font_description_set_variant (celltext->font,
1163 g_value_get_enum (value));
1166 pango_font_description_set_weight (celltext->font,
1167 g_value_get_int (value));
1170 pango_font_description_set_stretch (celltext->font,
1171 g_value_get_enum (value));
1174 pango_font_description_set_size (celltext->font,
1175 g_value_get_int (value));
1176 g_object_notify (object, "size-points");
1178 case PROP_SIZE_POINTS:
1179 pango_font_description_set_size (celltext->font,
1180 g_value_get_double (value) * PANGO_SCALE);
1181 g_object_notify (object, "size");
1185 if (celltext->fixed_height_rows != -1)
1186 celltext->calc_fixed_height = TRUE;
1188 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (celltext->font));
1189 g_object_notify (object, "font-desc");
1190 g_object_notify (object, "font");
1196 celltext->font_scale = g_value_get_double (value);
1197 celltext->scale_set = TRUE;
1198 if (celltext->fixed_height_rows != -1)
1199 celltext->calc_fixed_height = TRUE;
1200 g_object_notify (object, "scale-set");
1204 celltext->editable = g_value_get_boolean (value);
1205 celltext->editable_set = TRUE;
1206 if (celltext->editable)
1207 GTK_CELL_RENDERER (celltext)->mode = GTK_CELL_RENDERER_MODE_EDITABLE;
1209 GTK_CELL_RENDERER (celltext)->mode = GTK_CELL_RENDERER_MODE_INERT;
1210 g_object_notify (object, "editable-set");
1213 case PROP_STRIKETHROUGH:
1214 celltext->strikethrough = g_value_get_boolean (value);
1215 celltext->strikethrough_set = TRUE;
1216 g_object_notify (object, "strikethrough-set");
1219 case PROP_UNDERLINE:
1220 celltext->underline_style = g_value_get_enum (value);
1221 celltext->underline_set = TRUE;
1222 g_object_notify (object, "underline-set");
1227 celltext->rise = g_value_get_int (value);
1228 celltext->rise_set = TRUE;
1229 g_object_notify (object, "rise-set");
1230 if (celltext->fixed_height_rows != -1)
1231 celltext->calc_fixed_height = TRUE;
1235 priv->language_set = TRUE;
1237 g_object_unref (priv->language);
1238 priv->language = pango_language_from_string (g_value_get_string (value));
1239 g_object_notify (object, "language-set");
1242 case PROP_ELLIPSIZE:
1243 priv->ellipsize = g_value_get_enum (value);
1244 priv->ellipsize_set = TRUE;
1245 g_object_notify (object, "ellipsize-set");
1248 case PROP_WRAP_MODE:
1249 priv->wrap_mode = g_value_get_enum (value);
1252 case PROP_WRAP_WIDTH:
1253 priv->wrap_width = g_value_get_int (value);
1256 case PROP_WIDTH_CHARS:
1257 priv->width_chars = g_value_get_int (value);
1261 priv->align = g_value_get_enum (value);
1262 priv->align_set = TRUE;
1263 g_object_notify (object, "align-set");
1266 case PROP_BACKGROUND_SET:
1267 celltext->background_set = g_value_get_boolean (value);
1270 case PROP_FOREGROUND_SET:
1271 celltext->foreground_set = g_value_get_boolean (value);
1274 case PROP_FAMILY_SET:
1275 case PROP_STYLE_SET:
1276 case PROP_VARIANT_SET:
1277 case PROP_WEIGHT_SET:
1278 case PROP_STRETCH_SET:
1280 if (!g_value_get_boolean (value))
1282 pango_font_description_unset_fields (celltext->font,
1283 get_property_font_set_mask (param_id));
1287 PangoFontMask changed_mask;
1289 changed_mask = set_font_desc_fields (celltext->font,
1290 get_property_font_set_mask (param_id));
1291 notify_fields_changed (G_OBJECT (celltext), changed_mask);
1295 case PROP_SCALE_SET:
1296 celltext->scale_set = g_value_get_boolean (value);
1299 case PROP_EDITABLE_SET:
1300 celltext->editable_set = g_value_get_boolean (value);
1303 case PROP_STRIKETHROUGH_SET:
1304 celltext->strikethrough_set = g_value_get_boolean (value);
1307 case PROP_UNDERLINE_SET:
1308 celltext->underline_set = g_value_get_boolean (value);
1312 celltext->rise_set = g_value_get_boolean (value);
1315 case PROP_LANGUAGE_SET:
1316 priv->language_set = g_value_get_boolean (value);
1319 case PROP_ELLIPSIZE_SET:
1320 priv->ellipsize_set = g_value_get_boolean (value);
1323 case PROP_ALIGN_SET:
1324 priv->align_set = g_value_get_boolean (value);
1328 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1334 * gtk_cell_renderer_text_new:
1336 * Creates a new #GtkCellRendererText. Adjust how text is drawn using
1337 * object properties. Object properties can be
1338 * set globally (with g_object_set()). Also, with #GtkTreeViewColumn,
1339 * you can bind a property to a value in a #GtkTreeModel. For example,
1340 * you can bind the "text" property on the cell renderer to a string
1341 * value in the model, thus rendering a different string in each row
1342 * of the #GtkTreeView
1344 * Return value: the new cell renderer
1347 gtk_cell_renderer_text_new (void)
1349 return g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, NULL);
1353 add_attr (PangoAttrList *attr_list,
1354 PangoAttribute *attr)
1356 attr->start_index = 0;
1357 attr->end_index = G_MAXINT;
1359 pango_attr_list_insert (attr_list, attr);
1363 get_layout (GtkCellRendererText *celltext,
1365 gboolean will_render,
1366 GtkCellRendererState flags)
1368 PangoAttrList *attr_list;
1369 PangoLayout *layout;
1370 PangoUnderline uline;
1371 GtkCellRendererTextPrivate *priv;
1373 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (celltext);
1375 layout = gtk_widget_create_pango_layout (widget, celltext->text);
1377 if (celltext->extra_attrs)
1378 attr_list = pango_attr_list_copy (celltext->extra_attrs);
1380 attr_list = pango_attr_list_new ();
1382 pango_layout_set_single_paragraph_mode (layout, priv->single_paragraph);
1386 /* Add options that affect appearance but not size */
1388 /* note that background doesn't go here, since it affects
1389 * background_area not the PangoLayout area
1392 if (celltext->foreground_set
1393 && (flags & GTK_CELL_RENDERER_SELECTED) == 0)
1397 color = celltext->foreground;
1399 add_attr (attr_list,
1400 pango_attr_foreground_new (color.red, color.green, color.blue));
1403 if (celltext->strikethrough_set)
1404 add_attr (attr_list,
1405 pango_attr_strikethrough_new (celltext->strikethrough));
1408 add_attr (attr_list, pango_attr_font_desc_new (celltext->font));
1410 if (celltext->scale_set &&
1411 celltext->font_scale != 1.0)
1412 add_attr (attr_list, pango_attr_scale_new (celltext->font_scale));
1414 if (celltext->underline_set)
1415 uline = celltext->underline_style;
1417 uline = PANGO_UNDERLINE_NONE;
1419 if (priv->language_set)
1420 add_attr (attr_list, pango_attr_language_new (priv->language));
1422 if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT)
1426 case PANGO_UNDERLINE_NONE:
1427 uline = PANGO_UNDERLINE_SINGLE;
1430 case PANGO_UNDERLINE_SINGLE:
1431 uline = PANGO_UNDERLINE_DOUBLE;
1439 if (uline != PANGO_UNDERLINE_NONE)
1440 add_attr (attr_list, pango_attr_underline_new (celltext->underline_style));
1442 if (celltext->rise_set)
1443 add_attr (attr_list, pango_attr_rise_new (celltext->rise));
1445 if (priv->ellipsize_set)
1446 pango_layout_set_ellipsize (layout, priv->ellipsize);
1448 pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_NONE);
1450 if (priv->wrap_width != -1)
1452 pango_layout_set_width (layout, priv->wrap_width * PANGO_SCALE);
1453 pango_layout_set_wrap (layout, priv->wrap_mode);
1457 pango_layout_set_width (layout, -1);
1458 pango_layout_set_wrap (layout, PANGO_WRAP_CHAR);
1461 if (priv->align_set)
1462 pango_layout_set_alignment (layout, priv->align);
1465 PangoAlignment align;
1467 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1468 align = PANGO_ALIGN_RIGHT;
1470 align = PANGO_ALIGN_LEFT;
1472 pango_layout_set_alignment (layout, align);
1475 pango_layout_set_attributes (layout, attr_list);
1477 pango_attr_list_unref (attr_list);
1483 get_size (GtkCellRenderer *cell,
1485 GdkRectangle *cell_area,
1486 PangoLayout *layout,
1492 GtkCellRendererText *celltext = (GtkCellRendererText *) cell;
1493 PangoRectangle rect;
1494 GtkCellRendererTextPrivate *priv;
1496 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
1498 if (celltext->calc_fixed_height)
1500 PangoContext *context;
1501 PangoFontMetrics *metrics;
1502 PangoFontDescription *font_desc;
1505 font_desc = pango_font_description_copy_static (widget->style->font_desc);
1506 pango_font_description_merge_static (font_desc, celltext->font, TRUE);
1508 if (celltext->scale_set)
1509 pango_font_description_set_size (font_desc,
1510 celltext->font_scale * pango_font_description_get_size (font_desc));
1512 context = gtk_widget_get_pango_context (widget);
1514 metrics = pango_context_get_metrics (context,
1516 pango_context_get_language (context));
1517 row_height = (pango_font_metrics_get_ascent (metrics) +
1518 pango_font_metrics_get_descent (metrics));
1519 pango_font_metrics_unref (metrics);
1521 pango_font_description_free (font_desc);
1523 gtk_cell_renderer_set_fixed_size (cell,
1524 cell->width, 2*cell->ypad +
1525 celltext->fixed_height_rows * PANGO_PIXELS (row_height));
1529 *height = cell->height;
1532 celltext->calc_fixed_height = FALSE;
1538 g_object_ref (layout);
1540 layout = get_layout (celltext, widget, FALSE, 0);
1542 pango_layout_get_pixel_extents (layout, NULL, &rect);
1545 *height = cell->ypad * 2 + rect.height;
1547 /* The minimum size for ellipsized labels is ~ 3 chars */
1550 if (priv->ellipsize || priv->width_chars > 0)
1552 PangoContext *context;
1553 PangoFontMetrics *metrics;
1556 context = pango_layout_get_context (layout);
1557 metrics = pango_context_get_metrics (context, widget->style->font_desc, pango_context_get_language (context));
1559 char_width = pango_font_metrics_get_approximate_char_width (metrics);
1560 pango_font_metrics_unref (metrics);
1562 *width = cell->xpad * 2 + (PANGO_PIXELS (char_width) * MAX (priv->width_chars, 3));
1566 *width = cell->xpad * 2 + rect.x + rect.width;
1574 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1575 *x_offset = (1.0 - cell->xalign) * (cell_area->width - (rect.x + rect.width + (2 * cell->xpad)));
1577 *x_offset = cell->xalign * (cell_area->width - (rect.x + rect.width + (2 * cell->xpad)));
1579 if ((priv->ellipsize_set && priv->ellipsize != PANGO_ELLIPSIZE_NONE) || priv->wrap_width != -1)
1580 *x_offset = MAX(*x_offset, 0);
1584 *y_offset = cell->yalign * (cell_area->height - (rect.height + (2 * cell->ypad)));
1585 *y_offset = MAX (*y_offset, 0);
1590 if (x_offset) *x_offset = 0;
1591 if (y_offset) *y_offset = 0;
1594 g_object_unref (layout);
1599 gtk_cell_renderer_text_get_size (GtkCellRenderer *cell,
1601 GdkRectangle *cell_area,
1607 get_size (cell, widget, cell_area, NULL,
1608 x_offset, y_offset, width, height);
1612 gtk_cell_renderer_text_render (GtkCellRenderer *cell,
1613 GdkDrawable *window,
1615 GdkRectangle *background_area,
1616 GdkRectangle *cell_area,
1617 GdkRectangle *expose_area,
1618 GtkCellRendererState flags)
1621 GtkCellRendererText *celltext = (GtkCellRendererText *) cell;
1622 PangoLayout *layout;
1626 GtkCellRendererTextPrivate *priv;
1628 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
1630 layout = get_layout (celltext, widget, TRUE, flags);
1631 get_size (cell, widget, cell_area, layout, &x_offset, &y_offset, NULL, NULL);
1633 if (!cell->sensitive)
1635 state = GTK_STATE_INSENSITIVE;
1637 else if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
1639 if (gtk_widget_has_focus (widget))
1640 state = GTK_STATE_SELECTED;
1642 state = GTK_STATE_ACTIVE;
1644 else if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT &&
1645 gtk_widget_get_state (widget) == GTK_STATE_PRELIGHT)
1647 state = GTK_STATE_PRELIGHT;
1651 if (gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE)
1652 state = GTK_STATE_INSENSITIVE;
1654 state = GTK_STATE_NORMAL;
1657 if (celltext->background_set &&
1658 (flags & GTK_CELL_RENDERER_SELECTED) == 0)
1660 cairo_t *cr = gdk_cairo_create (window);
1664 gdk_cairo_rectangle (cr, expose_area);
1668 gdk_cairo_rectangle (cr, background_area);
1669 cairo_set_source_rgb (cr,
1670 celltext->background.red / 65535.,
1671 celltext->background.green / 65535.,
1672 celltext->background.blue / 65535.);
1678 if (priv->ellipsize_set && priv->ellipsize != PANGO_ELLIPSIZE_NONE)
1679 pango_layout_set_width (layout,
1680 (cell_area->width - x_offset - 2 * cell->xpad) * PANGO_SCALE);
1681 else if (priv->wrap_width == -1)
1682 pango_layout_set_width (layout, -1);
1684 gtk_paint_layout (widget->style,
1691 cell_area->x + x_offset + cell->xpad,
1692 cell_area->y + y_offset + cell->ypad,
1695 g_object_unref (layout);
1699 gtk_cell_renderer_text_editing_done (GtkCellEditable *entry,
1703 const gchar *new_text;
1705 GtkCellRendererTextPrivate *priv;
1707 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1711 if (priv->focus_out_id > 0)
1713 g_signal_handler_disconnect (entry, priv->focus_out_id);
1714 priv->focus_out_id = 0;
1717 if (priv->populate_popup_id > 0)
1719 g_signal_handler_disconnect (entry, priv->populate_popup_id);
1720 priv->populate_popup_id = 0;
1723 if (priv->entry_menu_popdown_timeout)
1725 g_source_remove (priv->entry_menu_popdown_timeout);
1726 priv->entry_menu_popdown_timeout = 0;
1729 g_object_get (entry,
1730 "editing-canceled", &canceled,
1732 gtk_cell_renderer_stop_editing (GTK_CELL_RENDERER (data), canceled);
1737 path = g_object_get_data (G_OBJECT (entry), GTK_CELL_RENDERER_TEXT_PATH);
1738 new_text = gtk_entry_get_text (GTK_ENTRY (entry));
1740 g_signal_emit (data, text_cell_renderer_signals[EDITED], 0, path, new_text);
1744 popdown_timeout (gpointer data)
1746 GtkCellRendererTextPrivate *priv;
1748 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1750 priv->entry_menu_popdown_timeout = 0;
1752 if (!gtk_widget_has_focus (priv->entry))
1753 gtk_cell_renderer_text_editing_done (GTK_CELL_EDITABLE (priv->entry), data);
1759 gtk_cell_renderer_text_popup_unmap (GtkMenu *menu,
1762 GtkCellRendererTextPrivate *priv;
1764 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1766 priv->in_entry_menu = FALSE;
1768 if (priv->entry_menu_popdown_timeout)
1771 priv->entry_menu_popdown_timeout = gdk_threads_add_timeout (500, popdown_timeout,
1776 gtk_cell_renderer_text_populate_popup (GtkEntry *entry,
1780 GtkCellRendererTextPrivate *priv;
1782 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1784 if (priv->entry_menu_popdown_timeout)
1786 g_source_remove (priv->entry_menu_popdown_timeout);
1787 priv->entry_menu_popdown_timeout = 0;
1790 priv->in_entry_menu = TRUE;
1792 g_signal_connect (menu, "unmap",
1793 G_CALLBACK (gtk_cell_renderer_text_popup_unmap), data);
1797 gtk_cell_renderer_text_focus_out_event (GtkWidget *entry,
1801 GtkCellRendererTextPrivate *priv;
1803 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1805 if (priv->in_entry_menu)
1808 g_object_set (entry,
1809 "editing-canceled", TRUE,
1811 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
1812 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
1814 /* entry needs focus-out-event */
1818 static GtkCellEditable *
1819 gtk_cell_renderer_text_start_editing (GtkCellRenderer *cell,
1823 GdkRectangle *background_area,
1824 GdkRectangle *cell_area,
1825 GtkCellRendererState flags)
1827 GtkRequisition requisition;
1828 GtkCellRendererText *celltext;
1829 GtkCellRendererTextPrivate *priv;
1831 celltext = GTK_CELL_RENDERER_TEXT (cell);
1832 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
1834 /* If the cell isn't editable we return NULL. */
1835 if (celltext->editable == FALSE)
1838 priv->entry = g_object_new (GTK_TYPE_ENTRY,
1840 "xalign", cell->xalign,
1844 gtk_entry_set_text (GTK_ENTRY (priv->entry), celltext->text);
1845 g_object_set_data_full (G_OBJECT (priv->entry), I_(GTK_CELL_RENDERER_TEXT_PATH), g_strdup (path), g_free);
1847 gtk_editable_select_region (GTK_EDITABLE (priv->entry), 0, -1);
1849 gtk_widget_size_request (priv->entry, &requisition);
1850 if (requisition.height < cell_area->height)
1852 GtkBorder *style_border;
1855 gtk_widget_style_get (priv->entry,
1856 "inner-border", &style_border,
1861 border = *style_border;
1862 g_boxed_free (GTK_TYPE_BORDER, style_border);
1866 /* Since boxed style properties can't have default values ... */
1871 border.top = (cell_area->height - requisition.height) / 2;
1872 border.bottom = (cell_area->height - requisition.height) / 2;
1873 gtk_entry_set_inner_border (GTK_ENTRY (priv->entry), &border);
1876 priv->in_entry_menu = FALSE;
1877 if (priv->entry_menu_popdown_timeout)
1879 g_source_remove (priv->entry_menu_popdown_timeout);
1880 priv->entry_menu_popdown_timeout = 0;
1883 g_signal_connect (priv->entry,
1885 G_CALLBACK (gtk_cell_renderer_text_editing_done),
1887 priv->focus_out_id = g_signal_connect_after (priv->entry, "focus-out-event",
1888 G_CALLBACK (gtk_cell_renderer_text_focus_out_event),
1890 priv->populate_popup_id =
1891 g_signal_connect (priv->entry, "populate-popup",
1892 G_CALLBACK (gtk_cell_renderer_text_populate_popup),
1895 gtk_widget_show (priv->entry);
1897 return GTK_CELL_EDITABLE (priv->entry);
1901 * gtk_cell_renderer_text_set_fixed_height_from_font:
1902 * @renderer: A #GtkCellRendererText
1903 * @number_of_rows: Number of rows of text each cell renderer is allocated, or -1
1905 * Sets the height of a renderer to explicitly be determined by the "font" and
1906 * "y_pad" property set on it. Further changes in these properties do not
1907 * affect the height, so they must be accompanied by a subsequent call to this
1908 * function. Using this function is unflexible, and should really only be used
1909 * if calculating the size of a cell is too slow (ie, a massive number of cells
1910 * displayed). If @number_of_rows is -1, then the fixed height is unset, and
1911 * the height is determined by the properties again.
1914 gtk_cell_renderer_text_set_fixed_height_from_font (GtkCellRendererText *renderer,
1915 gint number_of_rows)
1917 g_return_if_fail (GTK_IS_CELL_RENDERER_TEXT (renderer));
1918 g_return_if_fail (number_of_rows == -1 || number_of_rows > 0);
1920 if (number_of_rows == -1)
1922 gtk_cell_renderer_set_fixed_size (GTK_CELL_RENDERER (renderer),
1923 GTK_CELL_RENDERER (renderer)->width,
1928 renderer->fixed_height_rows = number_of_rows;
1929 renderer->calc_fixed_height = TRUE;
1933 #define __GTK_CELL_RENDERER_TEXT_C__
1934 #include "gtkaliasdef.c"