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 struct _GtkCellRendererTextPriv
130 PangoAlignment align;
131 PangoAttrList *extra_attrs;
132 PangoColor foreground;
133 PangoColor background;
134 PangoEllipsizeMode ellipsize;
135 PangoFontDescription *font;
136 PangoLanguage *language;
137 PangoUnderline underline_style;
138 PangoWrapMode wrap_mode;
140 gboolean in_entry_menu;
147 gint fixed_height_rows;
151 guint strikethrough : 1;
154 guint foreground_set : 1;
155 guint background_set : 1;
156 guint underline_set : 1;
158 guint strikethrough_set : 1;
159 guint editable_set : 1;
160 guint calc_fixed_height : 1;
161 guint single_paragraph : 1;
162 guint language_set : 1;
163 guint markup_set : 1;
164 guint ellipsize_set : 1;
168 gulong populate_popup_id;
169 gulong entry_menu_popdown_timeout;
172 G_DEFINE_TYPE (GtkCellRendererText, gtk_cell_renderer_text, GTK_TYPE_CELL_RENDERER)
175 gtk_cell_renderer_text_init (GtkCellRendererText *celltext)
177 GtkCellRendererTextPriv *priv;
178 GtkCellRenderer *cell = GTK_CELL_RENDERER (celltext);
180 celltext->priv = G_TYPE_INSTANCE_GET_PRIVATE (celltext,
181 GTK_TYPE_CELL_RENDERER_TEXT,
182 GtkCellRendererTextPriv);
183 priv = celltext->priv;
185 gtk_cell_renderer_set_alignment (cell, 0.0, 0.5);
186 gtk_cell_renderer_set_padding (cell, 2, 2);
187 priv->font_scale = 1.0;
188 priv->fixed_height_rows = -1;
189 priv->font = pango_font_description_new ();
191 priv->width_chars = -1;
192 priv->wrap_width = -1;
193 priv->wrap_mode = PANGO_WRAP_CHAR;
194 priv->align = PANGO_ALIGN_LEFT;
195 priv->align_set = FALSE;
199 gtk_cell_renderer_text_class_init (GtkCellRendererTextClass *class)
201 GObjectClass *object_class = G_OBJECT_CLASS (class);
202 GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);
204 object_class->finalize = gtk_cell_renderer_text_finalize;
206 object_class->get_property = gtk_cell_renderer_text_get_property;
207 object_class->set_property = gtk_cell_renderer_text_set_property;
209 cell_class->get_size = gtk_cell_renderer_text_get_size;
210 cell_class->render = gtk_cell_renderer_text_render;
211 cell_class->start_editing = gtk_cell_renderer_text_start_editing;
213 g_object_class_install_property (object_class,
215 g_param_spec_string ("text",
217 P_("Text to render"),
219 GTK_PARAM_READWRITE));
221 g_object_class_install_property (object_class,
223 g_param_spec_string ("markup",
225 P_("Marked up text to render"),
227 GTK_PARAM_WRITABLE));
229 g_object_class_install_property (object_class,
231 g_param_spec_boxed ("attributes",
233 P_("A list of style attributes to apply to the text of the renderer"),
234 PANGO_TYPE_ATTR_LIST,
235 GTK_PARAM_READWRITE));
237 g_object_class_install_property (object_class,
238 PROP_SINGLE_PARAGRAPH_MODE,
239 g_param_spec_boolean ("single-paragraph-mode",
240 P_("Single Paragraph Mode"),
241 P_("Whether or not to keep all text in a single paragraph"),
243 GTK_PARAM_READWRITE));
246 g_object_class_install_property (object_class,
248 g_param_spec_string ("background",
249 P_("Background color name"),
250 P_("Background color as a string"),
252 GTK_PARAM_WRITABLE));
254 g_object_class_install_property (object_class,
256 g_param_spec_boxed ("background-gdk",
257 P_("Background color"),
258 P_("Background color as a GdkColor"),
260 GTK_PARAM_READWRITE));
262 g_object_class_install_property (object_class,
264 g_param_spec_string ("foreground",
265 P_("Foreground color name"),
266 P_("Foreground color as a string"),
268 GTK_PARAM_WRITABLE));
270 g_object_class_install_property (object_class,
272 g_param_spec_boxed ("foreground-gdk",
273 P_("Foreground color"),
274 P_("Foreground color as a GdkColor"),
276 GTK_PARAM_READWRITE));
279 g_object_class_install_property (object_class,
281 g_param_spec_boolean ("editable",
283 P_("Whether the text can be modified by the user"),
285 GTK_PARAM_READWRITE));
287 g_object_class_install_property (object_class,
289 g_param_spec_string ("font",
291 P_("Font description as a string, e.g. \"Sans Italic 12\""),
293 GTK_PARAM_READWRITE));
295 g_object_class_install_property (object_class,
297 g_param_spec_boxed ("font-desc",
299 P_("Font description as a PangoFontDescription struct"),
300 PANGO_TYPE_FONT_DESCRIPTION,
301 GTK_PARAM_READWRITE));
304 g_object_class_install_property (object_class,
306 g_param_spec_string ("family",
308 P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
310 GTK_PARAM_READWRITE));
312 g_object_class_install_property (object_class,
314 g_param_spec_enum ("style",
319 GTK_PARAM_READWRITE));
321 g_object_class_install_property (object_class,
323 g_param_spec_enum ("variant",
327 PANGO_VARIANT_NORMAL,
328 GTK_PARAM_READWRITE));
330 g_object_class_install_property (object_class,
332 g_param_spec_int ("weight",
338 GTK_PARAM_READWRITE));
340 g_object_class_install_property (object_class,
342 g_param_spec_enum ("stretch",
346 PANGO_STRETCH_NORMAL,
347 GTK_PARAM_READWRITE));
349 g_object_class_install_property (object_class,
351 g_param_spec_int ("size",
357 GTK_PARAM_READWRITE));
359 g_object_class_install_property (object_class,
361 g_param_spec_double ("size-points",
363 P_("Font size in points"),
367 GTK_PARAM_READWRITE));
369 g_object_class_install_property (object_class,
371 g_param_spec_double ("scale",
373 P_("Font scaling factor"),
377 GTK_PARAM_READWRITE));
379 g_object_class_install_property (object_class,
381 g_param_spec_int ("rise",
383 P_("Offset of text above the baseline "
384 "(below the baseline if rise is negative)"),
388 GTK_PARAM_READWRITE));
391 g_object_class_install_property (object_class,
393 g_param_spec_boolean ("strikethrough",
395 P_("Whether to strike through the text"),
397 GTK_PARAM_READWRITE));
399 g_object_class_install_property (object_class,
401 g_param_spec_enum ("underline",
403 P_("Style of underline for this text"),
404 PANGO_TYPE_UNDERLINE,
405 PANGO_UNDERLINE_NONE,
406 GTK_PARAM_READWRITE));
408 g_object_class_install_property (object_class,
410 g_param_spec_string ("language",
412 P_("The language this text is in, as an ISO code. "
413 "Pango can use this as a hint when rendering the text. "
414 "If you don't understand this parameter, you probably don't need it"),
416 GTK_PARAM_READWRITE));
420 * GtkCellRendererText:ellipsize:
422 * Specifies the preferred place to ellipsize the string, if the cell renderer
423 * does not have enough room to display the entire string. Setting it to
424 * %PANGO_ELLIPSIZE_NONE turns off ellipsizing. See the wrap-width property
425 * for another way of making the text fit into a given width.
429 g_object_class_install_property (object_class,
431 g_param_spec_enum ("ellipsize",
433 P_("The preferred place to ellipsize the string, "
434 "if the cell renderer does not have enough room "
435 "to display the entire string"),
436 PANGO_TYPE_ELLIPSIZE_MODE,
437 PANGO_ELLIPSIZE_NONE,
438 GTK_PARAM_READWRITE));
441 * GtkCellRendererText:width-chars:
443 * The desired width of the cell, in characters. If this property is set to
444 * -1, the width will be calculated automatically, otherwise the cell will
445 * request either 3 characters or the property value, whichever is greater.
449 g_object_class_install_property (object_class,
451 g_param_spec_int ("width-chars",
452 P_("Width In Characters"),
453 P_("The desired width of the label, in characters"),
457 GTK_PARAM_READWRITE));
460 * GtkCellRendererText:wrap-mode:
462 * Specifies how to break the string into multiple lines, if the cell
463 * renderer does not have enough room to display the entire string.
464 * This property has no effect unless the wrap-width property is set.
468 g_object_class_install_property (object_class,
470 g_param_spec_enum ("wrap-mode",
472 P_("How to break the string into multiple lines, "
473 "if the cell renderer does not have enough room "
474 "to display the entire string"),
475 PANGO_TYPE_WRAP_MODE,
477 GTK_PARAM_READWRITE));
480 * GtkCellRendererText:wrap-width:
482 * Specifies the width at which the text is wrapped. The wrap-mode property can
483 * be used to influence at what character positions the line breaks can be placed.
484 * Setting wrap-width to -1 turns wrapping off.
488 g_object_class_install_property (object_class,
490 g_param_spec_int ("wrap-width",
492 P_("The width at which the text is wrapped"),
496 GTK_PARAM_READWRITE));
499 * GtkCellRendererText:alignment:
501 * Specifies how to align the lines of text with respect to each other.
503 * Note that this property describes how to align the lines of text in
504 * case there are several of them. The "xalign" property of #GtkCellRenderer,
505 * on the other hand, sets the horizontal alignment of the whole text.
509 g_object_class_install_property (object_class,
511 g_param_spec_enum ("alignment",
513 P_("How to align the lines"),
514 PANGO_TYPE_ALIGNMENT,
516 GTK_PARAM_READWRITE));
518 /* Style props are set or not */
520 #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))
522 ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
523 P_("Background set"),
524 P_("Whether this tag affects the background color"));
526 ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
527 P_("Foreground set"),
528 P_("Whether this tag affects the foreground color"));
530 ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
531 P_("Editability set"),
532 P_("Whether this tag affects text editability"));
534 ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
535 P_("Font family set"),
536 P_("Whether this tag affects the font family"));
538 ADD_SET_PROP ("style-set", PROP_STYLE_SET,
539 P_("Font style set"),
540 P_("Whether this tag affects the font style"));
542 ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
543 P_("Font variant set"),
544 P_("Whether this tag affects the font variant"));
546 ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
547 P_("Font weight set"),
548 P_("Whether this tag affects the font weight"));
550 ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
551 P_("Font stretch set"),
552 P_("Whether this tag affects the font stretch"));
554 ADD_SET_PROP ("size-set", PROP_SIZE_SET,
556 P_("Whether this tag affects the font size"));
558 ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
559 P_("Font scale set"),
560 P_("Whether this tag scales the font size by a factor"));
562 ADD_SET_PROP ("rise-set", PROP_RISE_SET,
564 P_("Whether this tag affects the rise"));
566 ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
567 P_("Strikethrough set"),
568 P_("Whether this tag affects strikethrough"));
570 ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
572 P_("Whether this tag affects underlining"));
574 ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
576 P_("Whether this tag affects the language the text is rendered as"));
578 ADD_SET_PROP ("ellipsize-set", PROP_ELLIPSIZE_SET,
580 P_("Whether this tag affects the ellipsize mode"));
582 ADD_SET_PROP ("align-set", PROP_ALIGN_SET,
584 P_("Whether this tag affects the alignment mode"));
587 * GtkCellRendererText::edited
588 * @renderer: the object which received the signal
589 * @path: the path identifying the edited cell
590 * @new_text: the new text
592 * This signal is emitted after @renderer has been edited.
594 * It is the responsibility of the application to update the model
595 * and store @new_text at the position indicated by @path.
597 text_cell_renderer_signals [EDITED] =
598 g_signal_new (I_("edited"),
599 G_OBJECT_CLASS_TYPE (object_class),
601 G_STRUCT_OFFSET (GtkCellRendererTextClass, edited),
603 _gtk_marshal_VOID__STRING_STRING,
608 g_type_class_add_private (object_class, sizeof (GtkCellRendererTextPriv));
612 gtk_cell_renderer_text_finalize (GObject *object)
614 GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
615 GtkCellRendererTextPriv *priv = celltext->priv;
617 pango_font_description_free (priv->font);
621 if (priv->extra_attrs)
622 pango_attr_list_unref (priv->extra_attrs);
625 g_object_unref (priv->language);
627 G_OBJECT_CLASS (gtk_cell_renderer_text_parent_class)->finalize (object);
631 get_property_font_set_mask (guint prop_id)
635 case PROP_FAMILY_SET:
636 return PANGO_FONT_MASK_FAMILY;
638 return PANGO_FONT_MASK_STYLE;
639 case PROP_VARIANT_SET:
640 return PANGO_FONT_MASK_VARIANT;
641 case PROP_WEIGHT_SET:
642 return PANGO_FONT_MASK_WEIGHT;
643 case PROP_STRETCH_SET:
644 return PANGO_FONT_MASK_STRETCH;
646 return PANGO_FONT_MASK_SIZE;
653 gtk_cell_renderer_text_get_property (GObject *object,
658 GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
659 GtkCellRendererTextPriv *priv = celltext->priv;
664 g_value_set_string (value, priv->text);
667 case PROP_ATTRIBUTES:
668 g_value_set_boxed (value, priv->extra_attrs);
671 case PROP_SINGLE_PARAGRAPH_MODE:
672 g_value_set_boolean (value, priv->single_paragraph);
675 case PROP_BACKGROUND_GDK:
679 color.red = priv->background.red;
680 color.green = priv->background.green;
681 color.blue = priv->background.blue;
683 g_value_set_boxed (value, &color);
687 case PROP_FOREGROUND_GDK:
691 color.red = priv->foreground.red;
692 color.green = priv->foreground.green;
693 color.blue = priv->foreground.blue;
695 g_value_set_boxed (value, &color);
700 g_value_take_string (value, pango_font_description_to_string (priv->font));
704 g_value_set_boxed (value, priv->font);
708 g_value_set_string (value, pango_font_description_get_family (priv->font));
712 g_value_set_enum (value, pango_font_description_get_style (priv->font));
716 g_value_set_enum (value, pango_font_description_get_variant (priv->font));
720 g_value_set_int (value, pango_font_description_get_weight (priv->font));
724 g_value_set_enum (value, pango_font_description_get_stretch (priv->font));
728 g_value_set_int (value, pango_font_description_get_size (priv->font));
731 case PROP_SIZE_POINTS:
732 g_value_set_double (value, ((double)pango_font_description_get_size (priv->font)) / (double)PANGO_SCALE);
736 g_value_set_double (value, priv->font_scale);
740 g_value_set_boolean (value, priv->editable);
743 case PROP_STRIKETHROUGH:
744 g_value_set_boolean (value, priv->strikethrough);
748 g_value_set_enum (value, priv->underline_style);
752 g_value_set_int (value, priv->rise);
756 g_value_set_static_string (value, pango_language_to_string (priv->language));
760 g_value_set_enum (value, priv->ellipsize);
764 g_value_set_enum (value, priv->wrap_mode);
767 case PROP_WRAP_WIDTH:
768 g_value_set_int (value, priv->wrap_width);
772 g_value_set_enum (value, priv->align);
775 case PROP_BACKGROUND_SET:
776 g_value_set_boolean (value, priv->background_set);
779 case PROP_FOREGROUND_SET:
780 g_value_set_boolean (value, priv->foreground_set);
783 case PROP_FAMILY_SET:
785 case PROP_VARIANT_SET:
786 case PROP_WEIGHT_SET:
787 case PROP_STRETCH_SET:
790 PangoFontMask mask = get_property_font_set_mask (param_id);
791 g_value_set_boolean (value, (pango_font_description_get_set_fields (priv->font) & mask) != 0);
797 g_value_set_boolean (value, priv->scale_set);
800 case PROP_EDITABLE_SET:
801 g_value_set_boolean (value, priv->editable_set);
804 case PROP_STRIKETHROUGH_SET:
805 g_value_set_boolean (value, priv->strikethrough_set);
808 case PROP_UNDERLINE_SET:
809 g_value_set_boolean (value, priv->underline_set);
813 g_value_set_boolean (value, priv->rise_set);
816 case PROP_LANGUAGE_SET:
817 g_value_set_boolean (value, priv->language_set);
820 case PROP_ELLIPSIZE_SET:
821 g_value_set_boolean (value, priv->ellipsize_set);
825 g_value_set_boolean (value, priv->align_set);
828 case PROP_WIDTH_CHARS:
829 g_value_set_int (value, priv->width_chars);
832 case PROP_BACKGROUND:
833 case PROP_FOREGROUND:
836 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
843 set_bg_color (GtkCellRendererText *celltext,
846 GtkCellRendererTextPriv *priv = celltext->priv;
850 if (!priv->background_set)
852 priv->background_set = TRUE;
853 g_object_notify (G_OBJECT (celltext), "background-set");
856 priv->background.red = color->red;
857 priv->background.green = color->green;
858 priv->background.blue = color->blue;
862 if (priv->background_set)
864 priv->background_set = FALSE;
865 g_object_notify (G_OBJECT (celltext), "background-set");
872 set_fg_color (GtkCellRendererText *celltext,
875 GtkCellRendererTextPriv *priv = celltext->priv;
879 if (!priv->foreground_set)
881 priv->foreground_set = TRUE;
882 g_object_notify (G_OBJECT (celltext), "foreground-set");
885 priv->foreground.red = color->red;
886 priv->foreground.green = color->green;
887 priv->foreground.blue = color->blue;
891 if (priv->foreground_set)
893 priv->foreground_set = FALSE;
894 g_object_notify (G_OBJECT (celltext), "foreground-set");
900 set_font_desc_fields (PangoFontDescription *desc,
901 PangoFontMask to_set)
903 PangoFontMask changed_mask = 0;
905 if (to_set & PANGO_FONT_MASK_FAMILY)
907 const char *family = pango_font_description_get_family (desc);
911 changed_mask |= PANGO_FONT_MASK_FAMILY;
914 pango_font_description_set_family (desc, family);
916 if (to_set & PANGO_FONT_MASK_STYLE)
917 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
918 if (to_set & PANGO_FONT_MASK_VARIANT)
919 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
920 if (to_set & PANGO_FONT_MASK_WEIGHT)
921 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
922 if (to_set & PANGO_FONT_MASK_STRETCH)
923 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
924 if (to_set & PANGO_FONT_MASK_SIZE)
926 gint size = pango_font_description_get_size (desc);
929 size = 10 * PANGO_SCALE;
930 changed_mask |= PANGO_FONT_MASK_SIZE;
933 pango_font_description_set_size (desc, size);
940 notify_set_changed (GObject *object,
941 PangoFontMask changed_mask)
943 if (changed_mask & PANGO_FONT_MASK_FAMILY)
944 g_object_notify (object, "family-set");
945 if (changed_mask & PANGO_FONT_MASK_STYLE)
946 g_object_notify (object, "style-set");
947 if (changed_mask & PANGO_FONT_MASK_VARIANT)
948 g_object_notify (object, "variant-set");
949 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
950 g_object_notify (object, "weight-set");
951 if (changed_mask & PANGO_FONT_MASK_STRETCH)
952 g_object_notify (object, "stretch-set");
953 if (changed_mask & PANGO_FONT_MASK_SIZE)
954 g_object_notify (object, "size-set");
958 notify_fields_changed (GObject *object,
959 PangoFontMask changed_mask)
961 if (changed_mask & PANGO_FONT_MASK_FAMILY)
962 g_object_notify (object, "family");
963 if (changed_mask & PANGO_FONT_MASK_STYLE)
964 g_object_notify (object, "style");
965 if (changed_mask & PANGO_FONT_MASK_VARIANT)
966 g_object_notify (object, "variant");
967 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
968 g_object_notify (object, "weight");
969 if (changed_mask & PANGO_FONT_MASK_STRETCH)
970 g_object_notify (object, "stretch");
971 if (changed_mask & PANGO_FONT_MASK_SIZE)
972 g_object_notify (object, "size");
976 set_font_description (GtkCellRendererText *celltext,
977 PangoFontDescription *font_desc)
979 GtkCellRendererTextPriv *priv = celltext->priv;
980 GObject *object = G_OBJECT (celltext);
981 PangoFontDescription *new_font_desc;
982 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
985 new_font_desc = pango_font_description_copy (font_desc);
987 new_font_desc = pango_font_description_new ();
989 old_mask = pango_font_description_get_set_fields (priv->font);
990 new_mask = pango_font_description_get_set_fields (new_font_desc);
992 changed_mask = old_mask | new_mask;
993 set_changed_mask = old_mask ^ new_mask;
995 pango_font_description_free (priv->font);
996 priv->font = new_font_desc;
998 g_object_freeze_notify (object);
1000 g_object_notify (object, "font-desc");
1001 g_object_notify (object, "font");
1003 if (changed_mask & PANGO_FONT_MASK_FAMILY)
1004 g_object_notify (object, "family");
1005 if (changed_mask & PANGO_FONT_MASK_STYLE)
1006 g_object_notify (object, "style");
1007 if (changed_mask & PANGO_FONT_MASK_VARIANT)
1008 g_object_notify (object, "variant");
1009 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
1010 g_object_notify (object, "weight");
1011 if (changed_mask & PANGO_FONT_MASK_STRETCH)
1012 g_object_notify (object, "stretch");
1013 if (changed_mask & PANGO_FONT_MASK_SIZE)
1015 g_object_notify (object, "size");
1016 g_object_notify (object, "size-points");
1019 notify_set_changed (object, set_changed_mask);
1021 g_object_thaw_notify (object);
1025 gtk_cell_renderer_text_set_property (GObject *object,
1027 const GValue *value,
1030 GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
1031 GtkCellRendererTextPriv *priv = celltext->priv;
1036 g_free (priv->text);
1038 if (priv->markup_set)
1040 if (priv->extra_attrs)
1041 pango_attr_list_unref (priv->extra_attrs);
1042 priv->extra_attrs = NULL;
1043 priv->markup_set = FALSE;
1046 priv->text = g_value_dup_string (value);
1047 g_object_notify (object, "text");
1050 case PROP_ATTRIBUTES:
1051 if (priv->extra_attrs)
1052 pango_attr_list_unref (priv->extra_attrs);
1054 priv->extra_attrs = g_value_get_boxed (value);
1055 if (priv->extra_attrs)
1056 pango_attr_list_ref (priv->extra_attrs);
1062 GError *error = NULL;
1063 PangoAttrList *attrs = NULL;
1065 str = g_value_get_string (value);
1066 if (str && !pango_parse_markup (str,
1074 g_warning ("Failed to set text from markup due to error parsing markup: %s",
1076 g_error_free (error);
1080 g_free (priv->text);
1082 if (priv->extra_attrs)
1083 pango_attr_list_unref (priv->extra_attrs);
1086 priv->extra_attrs = attrs;
1087 priv->markup_set = TRUE;
1091 case PROP_SINGLE_PARAGRAPH_MODE:
1092 priv->single_paragraph = g_value_get_boolean (value);
1095 case PROP_BACKGROUND:
1099 if (!g_value_get_string (value))
1100 set_bg_color (celltext, NULL); /* reset to background_set to FALSE */
1101 else if (gdk_color_parse (g_value_get_string (value), &color))
1102 set_bg_color (celltext, &color);
1104 g_warning ("Don't know color `%s'", g_value_get_string (value));
1106 g_object_notify (object, "background-gdk");
1110 case PROP_FOREGROUND:
1114 if (!g_value_get_string (value))
1115 set_fg_color (celltext, NULL); /* reset to foreground_set to FALSE */
1116 else if (gdk_color_parse (g_value_get_string (value), &color))
1117 set_fg_color (celltext, &color);
1119 g_warning ("Don't know color `%s'", g_value_get_string (value));
1121 g_object_notify (object, "foreground-gdk");
1125 case PROP_BACKGROUND_GDK:
1126 /* This notifies the GObject itself. */
1127 set_bg_color (celltext, g_value_get_boxed (value));
1130 case PROP_FOREGROUND_GDK:
1131 /* This notifies the GObject itself. */
1132 set_fg_color (celltext, g_value_get_boxed (value));
1137 PangoFontDescription *font_desc = NULL;
1140 name = g_value_get_string (value);
1143 font_desc = pango_font_description_from_string (name);
1145 set_font_description (celltext, font_desc);
1147 pango_font_description_free (font_desc);
1149 if (priv->fixed_height_rows != -1)
1150 priv->calc_fixed_height = TRUE;
1154 case PROP_FONT_DESC:
1155 set_font_description (celltext, g_value_get_boxed (value));
1157 if (priv->fixed_height_rows != -1)
1158 priv->calc_fixed_height = TRUE;
1167 case PROP_SIZE_POINTS:
1169 PangoFontMask old_set_mask = pango_font_description_get_set_fields (priv->font);
1174 pango_font_description_set_family (priv->font,
1175 g_value_get_string (value));
1178 pango_font_description_set_style (priv->font,
1179 g_value_get_enum (value));
1182 pango_font_description_set_variant (priv->font,
1183 g_value_get_enum (value));
1186 pango_font_description_set_weight (priv->font,
1187 g_value_get_int (value));
1190 pango_font_description_set_stretch (priv->font,
1191 g_value_get_enum (value));
1194 pango_font_description_set_size (priv->font,
1195 g_value_get_int (value));
1196 g_object_notify (object, "size-points");
1198 case PROP_SIZE_POINTS:
1199 pango_font_description_set_size (priv->font,
1200 g_value_get_double (value) * PANGO_SCALE);
1201 g_object_notify (object, "size");
1205 if (priv->fixed_height_rows != -1)
1206 priv->calc_fixed_height = TRUE;
1208 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (priv->font));
1209 g_object_notify (object, "font-desc");
1210 g_object_notify (object, "font");
1216 priv->font_scale = g_value_get_double (value);
1217 priv->scale_set = TRUE;
1218 if (priv->fixed_height_rows != -1)
1219 priv->calc_fixed_height = TRUE;
1220 g_object_notify (object, "scale-set");
1224 priv->editable = g_value_get_boolean (value);
1225 priv->editable_set = TRUE;
1227 g_object_set (celltext, "mode", GTK_CELL_RENDERER_MODE_EDITABLE, NULL);
1229 g_object_set (celltext, "mode", GTK_CELL_RENDERER_MODE_INERT, NULL);
1230 g_object_notify (object, "editable-set");
1233 case PROP_STRIKETHROUGH:
1234 priv->strikethrough = g_value_get_boolean (value);
1235 priv->strikethrough_set = TRUE;
1236 g_object_notify (object, "strikethrough-set");
1239 case PROP_UNDERLINE:
1240 priv->underline_style = g_value_get_enum (value);
1241 priv->underline_set = TRUE;
1242 g_object_notify (object, "underline-set");
1247 priv->rise = g_value_get_int (value);
1248 priv->rise_set = TRUE;
1249 g_object_notify (object, "rise-set");
1250 if (priv->fixed_height_rows != -1)
1251 priv->calc_fixed_height = TRUE;
1255 priv->language_set = TRUE;
1257 g_object_unref (priv->language);
1258 priv->language = pango_language_from_string (g_value_get_string (value));
1259 g_object_notify (object, "language-set");
1262 case PROP_ELLIPSIZE:
1263 priv->ellipsize = g_value_get_enum (value);
1264 priv->ellipsize_set = TRUE;
1265 g_object_notify (object, "ellipsize-set");
1268 case PROP_WRAP_MODE:
1269 priv->wrap_mode = g_value_get_enum (value);
1272 case PROP_WRAP_WIDTH:
1273 priv->wrap_width = g_value_get_int (value);
1276 case PROP_WIDTH_CHARS:
1277 priv->width_chars = g_value_get_int (value);
1281 priv->align = g_value_get_enum (value);
1282 priv->align_set = TRUE;
1283 g_object_notify (object, "align-set");
1286 case PROP_BACKGROUND_SET:
1287 priv->background_set = g_value_get_boolean (value);
1290 case PROP_FOREGROUND_SET:
1291 priv->foreground_set = g_value_get_boolean (value);
1294 case PROP_FAMILY_SET:
1295 case PROP_STYLE_SET:
1296 case PROP_VARIANT_SET:
1297 case PROP_WEIGHT_SET:
1298 case PROP_STRETCH_SET:
1300 if (!g_value_get_boolean (value))
1302 pango_font_description_unset_fields (priv->font,
1303 get_property_font_set_mask (param_id));
1307 PangoFontMask changed_mask;
1309 changed_mask = set_font_desc_fields (priv->font,
1310 get_property_font_set_mask (param_id));
1311 notify_fields_changed (G_OBJECT (celltext), changed_mask);
1315 case PROP_SCALE_SET:
1316 priv->scale_set = g_value_get_boolean (value);
1319 case PROP_EDITABLE_SET:
1320 priv->editable_set = g_value_get_boolean (value);
1323 case PROP_STRIKETHROUGH_SET:
1324 priv->strikethrough_set = g_value_get_boolean (value);
1327 case PROP_UNDERLINE_SET:
1328 priv->underline_set = g_value_get_boolean (value);
1332 priv->rise_set = g_value_get_boolean (value);
1335 case PROP_LANGUAGE_SET:
1336 priv->language_set = g_value_get_boolean (value);
1339 case PROP_ELLIPSIZE_SET:
1340 priv->ellipsize_set = g_value_get_boolean (value);
1343 case PROP_ALIGN_SET:
1344 priv->align_set = g_value_get_boolean (value);
1348 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1354 * gtk_cell_renderer_text_new:
1356 * Creates a new #GtkCellRendererText. Adjust how text is drawn using
1357 * object properties. Object properties can be
1358 * set globally (with g_object_set()). Also, with #GtkTreeViewColumn,
1359 * you can bind a property to a value in a #GtkTreeModel. For example,
1360 * you can bind the "text" property on the cell renderer to a string
1361 * value in the model, thus rendering a different string in each row
1362 * of the #GtkTreeView
1364 * Return value: the new cell renderer
1367 gtk_cell_renderer_text_new (void)
1369 return g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, NULL);
1373 add_attr (PangoAttrList *attr_list,
1374 PangoAttribute *attr)
1376 attr->start_index = 0;
1377 attr->end_index = G_MAXINT;
1379 pango_attr_list_insert (attr_list, attr);
1383 get_layout (GtkCellRendererText *celltext,
1385 gboolean will_render,
1386 GtkCellRendererState flags)
1388 GtkCellRendererTextPriv *priv = celltext->priv;
1389 PangoAttrList *attr_list;
1390 PangoLayout *layout;
1391 PangoUnderline uline;
1393 layout = gtk_widget_create_pango_layout (widget, priv->text);
1395 if (priv->extra_attrs)
1396 attr_list = pango_attr_list_copy (priv->extra_attrs);
1398 attr_list = pango_attr_list_new ();
1400 pango_layout_set_single_paragraph_mode (layout, priv->single_paragraph);
1404 /* Add options that affect appearance but not size */
1406 /* note that background doesn't go here, since it affects
1407 * background_area not the PangoLayout area
1410 if (priv->foreground_set
1411 && (flags & GTK_CELL_RENDERER_SELECTED) == 0)
1415 color = priv->foreground;
1417 add_attr (attr_list,
1418 pango_attr_foreground_new (color.red, color.green, color.blue));
1421 if (priv->strikethrough_set)
1422 add_attr (attr_list,
1423 pango_attr_strikethrough_new (priv->strikethrough));
1426 add_attr (attr_list, pango_attr_font_desc_new (priv->font));
1428 if (priv->scale_set &&
1429 priv->font_scale != 1.0)
1430 add_attr (attr_list, pango_attr_scale_new (priv->font_scale));
1432 if (priv->underline_set)
1433 uline = priv->underline_style;
1435 uline = PANGO_UNDERLINE_NONE;
1437 if (priv->language_set)
1438 add_attr (attr_list, pango_attr_language_new (priv->language));
1440 if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT)
1444 case PANGO_UNDERLINE_NONE:
1445 uline = PANGO_UNDERLINE_SINGLE;
1448 case PANGO_UNDERLINE_SINGLE:
1449 uline = PANGO_UNDERLINE_DOUBLE;
1457 if (uline != PANGO_UNDERLINE_NONE)
1458 add_attr (attr_list, pango_attr_underline_new (priv->underline_style));
1461 add_attr (attr_list, pango_attr_rise_new (priv->rise));
1463 if (priv->ellipsize_set)
1464 pango_layout_set_ellipsize (layout, priv->ellipsize);
1466 pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_NONE);
1468 if (priv->wrap_width != -1)
1470 pango_layout_set_width (layout, priv->wrap_width * PANGO_SCALE);
1471 pango_layout_set_wrap (layout, priv->wrap_mode);
1475 pango_layout_set_width (layout, -1);
1476 pango_layout_set_wrap (layout, PANGO_WRAP_CHAR);
1479 if (priv->align_set)
1480 pango_layout_set_alignment (layout, priv->align);
1483 PangoAlignment align;
1485 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1486 align = PANGO_ALIGN_RIGHT;
1488 align = PANGO_ALIGN_LEFT;
1490 pango_layout_set_alignment (layout, align);
1493 pango_layout_set_attributes (layout, attr_list);
1495 pango_attr_list_unref (attr_list);
1501 get_size (GtkCellRenderer *cell,
1503 GdkRectangle *cell_area,
1504 PangoLayout *layout,
1510 GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (cell);
1511 GtkCellRendererTextPriv *priv = celltext->priv;
1512 PangoRectangle rect;
1514 gint cell_width, cell_height;
1516 gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
1518 if (priv->calc_fixed_height)
1520 PangoContext *context;
1521 PangoFontMetrics *metrics;
1522 PangoFontDescription *font_desc;
1525 font_desc = pango_font_description_copy_static (widget->style->font_desc);
1526 pango_font_description_merge_static (font_desc, priv->font, TRUE);
1528 if (priv->scale_set)
1529 pango_font_description_set_size (font_desc,
1530 priv->font_scale * pango_font_description_get_size (font_desc));
1532 context = gtk_widget_get_pango_context (widget);
1534 metrics = pango_context_get_metrics (context,
1536 pango_context_get_language (context));
1537 row_height = (pango_font_metrics_get_ascent (metrics) +
1538 pango_font_metrics_get_descent (metrics));
1539 pango_font_metrics_unref (metrics);
1541 pango_font_description_free (font_desc);
1543 gtk_cell_renderer_get_fixed_size (cell, &cell_width, &cell_height);
1545 gtk_cell_renderer_set_fixed_size (cell,
1546 cell_width, 2 * ypad +
1547 priv->fixed_height_rows * PANGO_PIXELS (row_height));
1551 *height = cell_height;
1554 priv->calc_fixed_height = FALSE;
1560 g_object_ref (layout);
1562 layout = get_layout (celltext, widget, FALSE, 0);
1564 pango_layout_get_pixel_extents (layout, NULL, &rect);
1567 *height = ypad * 2 + rect.height;
1569 /* The minimum size for ellipsized labels is ~ 3 chars */
1572 if (priv->ellipsize || priv->width_chars > 0)
1574 PangoContext *context;
1575 PangoFontMetrics *metrics;
1578 context = pango_layout_get_context (layout);
1579 metrics = pango_context_get_metrics (context, widget->style->font_desc, pango_context_get_language (context));
1581 char_width = pango_font_metrics_get_approximate_char_width (metrics);
1582 pango_font_metrics_unref (metrics);
1584 *width = xpad * 2 + (PANGO_PIXELS (char_width) * MAX (priv->width_chars, 3));
1588 *width = xpad * 2 + rect.x + rect.width;
1594 gfloat xalign, yalign;
1596 gtk_cell_renderer_get_alignment (cell, &xalign, &yalign);
1600 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1601 *x_offset = (1.0 - xalign) * (cell_area->width - (rect.x + rect.width + (2 * xpad)));
1603 *x_offset = xalign * (cell_area->width - (rect.x + rect.width + (2 * xpad)));
1605 if ((priv->ellipsize_set && priv->ellipsize != PANGO_ELLIPSIZE_NONE) || priv->wrap_width != -1)
1606 *x_offset = MAX(*x_offset, 0);
1610 *y_offset = yalign * (cell_area->height - (rect.height + (2 * ypad)));
1611 *y_offset = MAX (*y_offset, 0);
1616 if (x_offset) *x_offset = 0;
1617 if (y_offset) *y_offset = 0;
1620 g_object_unref (layout);
1625 gtk_cell_renderer_text_get_size (GtkCellRenderer *cell,
1627 GdkRectangle *cell_area,
1633 get_size (cell, widget, cell_area, NULL,
1634 x_offset, y_offset, width, height);
1638 gtk_cell_renderer_text_render (GtkCellRenderer *cell,
1639 GdkDrawable *window,
1641 GdkRectangle *background_area,
1642 GdkRectangle *cell_area,
1643 GdkRectangle *expose_area,
1644 GtkCellRendererState flags)
1647 GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (cell);
1648 GtkCellRendererTextPriv *priv = celltext->priv;
1649 PangoLayout *layout;
1655 layout = get_layout (celltext, widget, TRUE, flags);
1656 get_size (cell, widget, cell_area, layout, &x_offset, &y_offset, NULL, NULL);
1658 if (!gtk_cell_renderer_get_sensitive (cell))
1660 state = GTK_STATE_INSENSITIVE;
1662 else if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
1664 if (gtk_widget_has_focus (widget))
1665 state = GTK_STATE_SELECTED;
1667 state = GTK_STATE_ACTIVE;
1669 else if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT &&
1670 gtk_widget_get_state (widget) == GTK_STATE_PRELIGHT)
1672 state = GTK_STATE_PRELIGHT;
1676 if (gtk_widget_get_state (widget) == GTK_STATE_INSENSITIVE)
1677 state = GTK_STATE_INSENSITIVE;
1679 state = GTK_STATE_NORMAL;
1682 if (priv->background_set &&
1683 (flags & GTK_CELL_RENDERER_SELECTED) == 0)
1685 cairo_t *cr = gdk_cairo_create (window);
1689 gdk_cairo_rectangle (cr, expose_area);
1693 gdk_cairo_rectangle (cr, background_area);
1694 cairo_set_source_rgb (cr,
1695 priv->background.red / 65535.,
1696 priv->background.green / 65535.,
1697 priv->background.blue / 65535.);
1703 gtk_cell_renderer_get_padding (cell, &xpad, &ypad);
1705 if (priv->ellipsize_set && priv->ellipsize != PANGO_ELLIPSIZE_NONE)
1706 pango_layout_set_width (layout,
1707 (cell_area->width - x_offset - 2 * xpad) * PANGO_SCALE);
1708 else if (priv->wrap_width == -1)
1709 pango_layout_set_width (layout, -1);
1711 gtk_paint_layout (widget->style,
1718 cell_area->x + x_offset + xpad,
1719 cell_area->y + y_offset + ypad,
1722 g_object_unref (layout);
1726 gtk_cell_renderer_text_editing_done (GtkCellEditable *entry,
1729 GtkCellRendererTextPriv *priv;
1731 const gchar *new_text;
1734 priv = GTK_CELL_RENDERER_TEXT (data)->priv;
1738 if (priv->focus_out_id > 0)
1740 g_signal_handler_disconnect (entry, priv->focus_out_id);
1741 priv->focus_out_id = 0;
1744 if (priv->populate_popup_id > 0)
1746 g_signal_handler_disconnect (entry, priv->populate_popup_id);
1747 priv->populate_popup_id = 0;
1750 if (priv->entry_menu_popdown_timeout)
1752 g_source_remove (priv->entry_menu_popdown_timeout);
1753 priv->entry_menu_popdown_timeout = 0;
1756 g_object_get (entry,
1757 "editing-canceled", &canceled,
1759 gtk_cell_renderer_stop_editing (GTK_CELL_RENDERER (data), canceled);
1764 path = g_object_get_data (G_OBJECT (entry), GTK_CELL_RENDERER_TEXT_PATH);
1765 new_text = gtk_entry_get_text (GTK_ENTRY (entry));
1767 g_signal_emit (data, text_cell_renderer_signals[EDITED], 0, path, new_text);
1771 popdown_timeout (gpointer data)
1773 GtkCellRendererTextPriv *priv;
1775 priv = GTK_CELL_RENDERER_TEXT (data)->priv;
1777 priv->entry_menu_popdown_timeout = 0;
1779 if (!gtk_widget_has_focus (priv->entry))
1780 gtk_cell_renderer_text_editing_done (GTK_CELL_EDITABLE (priv->entry), data);
1786 gtk_cell_renderer_text_popup_unmap (GtkMenu *menu,
1789 GtkCellRendererTextPriv *priv;
1791 priv = GTK_CELL_RENDERER_TEXT (data)->priv;
1793 priv->in_entry_menu = FALSE;
1795 if (priv->entry_menu_popdown_timeout)
1798 priv->entry_menu_popdown_timeout = gdk_threads_add_timeout (500, popdown_timeout,
1803 gtk_cell_renderer_text_populate_popup (GtkEntry *entry,
1807 GtkCellRendererTextPriv *priv;
1809 priv = GTK_CELL_RENDERER_TEXT (data)->priv;
1811 if (priv->entry_menu_popdown_timeout)
1813 g_source_remove (priv->entry_menu_popdown_timeout);
1814 priv->entry_menu_popdown_timeout = 0;
1817 priv->in_entry_menu = TRUE;
1819 g_signal_connect (menu, "unmap",
1820 G_CALLBACK (gtk_cell_renderer_text_popup_unmap), data);
1824 gtk_cell_renderer_text_focus_out_event (GtkWidget *entry,
1828 GtkCellRendererTextPriv *priv;
1830 priv = GTK_CELL_RENDERER_TEXT (data)->priv;
1832 if (priv->in_entry_menu)
1835 g_object_set (entry,
1836 "editing-canceled", TRUE,
1838 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
1839 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
1841 /* entry needs focus-out-event */
1845 static GtkCellEditable *
1846 gtk_cell_renderer_text_start_editing (GtkCellRenderer *cell,
1850 GdkRectangle *background_area,
1851 GdkRectangle *cell_area,
1852 GtkCellRendererState flags)
1854 GtkRequisition requisition;
1855 GtkCellRendererText *celltext;
1856 GtkCellRendererTextPriv *priv;
1857 gfloat xalign, yalign;
1859 celltext = GTK_CELL_RENDERER_TEXT (cell);
1860 priv = celltext->priv;
1862 /* If the cell isn't editable we return NULL. */
1863 if (priv->editable == FALSE)
1866 gtk_cell_renderer_get_alignment (cell, &xalign, &yalign);
1868 priv->entry = gtk_entry_new ();
1869 gtk_entry_set_has_frame (GTK_ENTRY (priv->entry), FALSE);
1870 gtk_entry_set_alignment (GTK_ENTRY (priv->entry), xalign);
1873 gtk_entry_set_text (GTK_ENTRY (priv->entry), priv->text);
1874 g_object_set_data_full (G_OBJECT (priv->entry), I_(GTK_CELL_RENDERER_TEXT_PATH), g_strdup (path), g_free);
1876 gtk_editable_select_region (GTK_EDITABLE (priv->entry), 0, -1);
1878 gtk_widget_size_request (priv->entry, &requisition);
1879 if (requisition.height < cell_area->height)
1881 GtkBorder *style_border;
1884 gtk_widget_style_get (priv->entry,
1885 "inner-border", &style_border,
1890 border = *style_border;
1891 g_boxed_free (GTK_TYPE_BORDER, style_border);
1895 /* Since boxed style properties can't have default values ... */
1900 border.top = (cell_area->height - requisition.height) / 2;
1901 border.bottom = (cell_area->height - requisition.height) / 2;
1902 gtk_entry_set_inner_border (GTK_ENTRY (priv->entry), &border);
1905 priv->in_entry_menu = FALSE;
1906 if (priv->entry_menu_popdown_timeout)
1908 g_source_remove (priv->entry_menu_popdown_timeout);
1909 priv->entry_menu_popdown_timeout = 0;
1912 g_signal_connect (priv->entry,
1914 G_CALLBACK (gtk_cell_renderer_text_editing_done),
1916 priv->focus_out_id = g_signal_connect_after (priv->entry, "focus-out-event",
1917 G_CALLBACK (gtk_cell_renderer_text_focus_out_event),
1919 priv->populate_popup_id =
1920 g_signal_connect (priv->entry, "populate-popup",
1921 G_CALLBACK (gtk_cell_renderer_text_populate_popup),
1924 gtk_widget_show (priv->entry);
1926 return GTK_CELL_EDITABLE (priv->entry);
1930 * gtk_cell_renderer_text_set_fixed_height_from_font:
1931 * @renderer: A #GtkCellRendererText
1932 * @number_of_rows: Number of rows of text each cell renderer is allocated, or -1
1934 * Sets the height of a renderer to explicitly be determined by the "font" and
1935 * "y_pad" property set on it. Further changes in these properties do not
1936 * affect the height, so they must be accompanied by a subsequent call to this
1937 * function. Using this function is unflexible, and should really only be used
1938 * if calculating the size of a cell is too slow (ie, a massive number of cells
1939 * displayed). If @number_of_rows is -1, then the fixed height is unset, and
1940 * the height is determined by the properties again.
1943 gtk_cell_renderer_text_set_fixed_height_from_font (GtkCellRendererText *renderer,
1944 gint number_of_rows)
1946 GtkCellRendererTextPriv *priv;
1947 GtkCellRenderer *cell;
1949 g_return_if_fail (GTK_IS_CELL_RENDERER_TEXT (renderer));
1950 g_return_if_fail (number_of_rows == -1 || number_of_rows > 0);
1952 cell = GTK_CELL_RENDERER (renderer);
1953 priv = renderer->priv;
1955 if (number_of_rows == -1)
1959 gtk_cell_renderer_get_fixed_size (cell, &width, &height);
1960 gtk_cell_renderer_set_fixed_size (cell, width, -1);
1964 priv->fixed_height_rows = number_of_rows;
1965 priv->calc_fixed_height = TRUE;