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->fixed_height_rows = -1;
167 celltext->font = pango_font_description_new ();
169 priv->width_chars = -1;
170 priv->wrap_width = -1;
171 priv->align = PANGO_ALIGN_LEFT;
172 priv->align_set = FALSE;
176 gtk_cell_renderer_text_class_init (GtkCellRendererTextClass *class)
178 GObjectClass *object_class = G_OBJECT_CLASS (class);
179 GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);
181 object_class->finalize = gtk_cell_renderer_text_finalize;
183 object_class->get_property = gtk_cell_renderer_text_get_property;
184 object_class->set_property = gtk_cell_renderer_text_set_property;
186 cell_class->get_size = gtk_cell_renderer_text_get_size;
187 cell_class->render = gtk_cell_renderer_text_render;
188 cell_class->start_editing = gtk_cell_renderer_text_start_editing;
190 g_object_class_install_property (object_class,
192 g_param_spec_string ("text",
194 P_("Text to render"),
196 GTK_PARAM_READWRITE));
198 g_object_class_install_property (object_class,
200 g_param_spec_string ("markup",
202 P_("Marked up text to render"),
204 GTK_PARAM_WRITABLE));
206 g_object_class_install_property (object_class,
208 g_param_spec_boxed ("attributes",
210 P_("A list of style attributes to apply to the text of the renderer"),
211 PANGO_TYPE_ATTR_LIST,
212 GTK_PARAM_READWRITE));
214 g_object_class_install_property (object_class,
215 PROP_SINGLE_PARAGRAPH_MODE,
216 g_param_spec_boolean ("single-paragraph-mode",
217 P_("Single Paragraph Mode"),
218 P_("Whether or not to keep all text in a single paragraph"),
220 GTK_PARAM_READWRITE));
223 g_object_class_install_property (object_class,
225 g_param_spec_string ("background",
226 P_("Background color name"),
227 P_("Background color as a string"),
229 GTK_PARAM_WRITABLE));
231 g_object_class_install_property (object_class,
233 g_param_spec_boxed ("background-gdk",
234 P_("Background color"),
235 P_("Background color as a GdkColor"),
237 GTK_PARAM_READWRITE));
239 g_object_class_install_property (object_class,
241 g_param_spec_string ("foreground",
242 P_("Foreground color name"),
243 P_("Foreground color as a string"),
245 GTK_PARAM_WRITABLE));
247 g_object_class_install_property (object_class,
249 g_param_spec_boxed ("foreground-gdk",
250 P_("Foreground color"),
251 P_("Foreground color as a GdkColor"),
253 GTK_PARAM_READWRITE));
256 g_object_class_install_property (object_class,
258 g_param_spec_boolean ("editable",
260 P_("Whether the text can be modified by the user"),
262 GTK_PARAM_READWRITE));
264 g_object_class_install_property (object_class,
266 g_param_spec_string ("font",
268 P_("Font description as a string, e.g. \"Sans Italic 12\""),
270 GTK_PARAM_READWRITE));
272 g_object_class_install_property (object_class,
274 g_param_spec_boxed ("font-desc",
276 P_("Font description as a PangoFontDescription struct"),
277 PANGO_TYPE_FONT_DESCRIPTION,
278 GTK_PARAM_READWRITE));
281 g_object_class_install_property (object_class,
283 g_param_spec_string ("family",
285 P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
287 GTK_PARAM_READWRITE));
289 g_object_class_install_property (object_class,
291 g_param_spec_enum ("style",
296 GTK_PARAM_READWRITE));
298 g_object_class_install_property (object_class,
300 g_param_spec_enum ("variant",
304 PANGO_VARIANT_NORMAL,
305 GTK_PARAM_READWRITE));
307 g_object_class_install_property (object_class,
309 g_param_spec_int ("weight",
315 GTK_PARAM_READWRITE));
317 g_object_class_install_property (object_class,
319 g_param_spec_enum ("stretch",
323 PANGO_STRETCH_NORMAL,
324 GTK_PARAM_READWRITE));
326 g_object_class_install_property (object_class,
328 g_param_spec_int ("size",
334 GTK_PARAM_READWRITE));
336 g_object_class_install_property (object_class,
338 g_param_spec_double ("size-points",
340 P_("Font size in points"),
344 GTK_PARAM_READWRITE));
346 g_object_class_install_property (object_class,
348 g_param_spec_double ("scale",
350 P_("Font scaling factor"),
354 GTK_PARAM_READWRITE));
356 g_object_class_install_property (object_class,
358 g_param_spec_int ("rise",
360 P_("Offset of text above the baseline "
361 "(below the baseline if rise is negative)"),
365 GTK_PARAM_READWRITE));
368 g_object_class_install_property (object_class,
370 g_param_spec_boolean ("strikethrough",
372 P_("Whether to strike through the text"),
374 GTK_PARAM_READWRITE));
376 g_object_class_install_property (object_class,
378 g_param_spec_enum ("underline",
380 P_("Style of underline for this text"),
381 PANGO_TYPE_UNDERLINE,
382 PANGO_UNDERLINE_NONE,
383 GTK_PARAM_READWRITE));
385 g_object_class_install_property (object_class,
387 g_param_spec_string ("language",
389 P_("The language this text is in, as an ISO code. "
390 "Pango can use this as a hint when rendering the text. "
391 "If you don't understand this parameter, you probably don't need it"),
393 GTK_PARAM_READWRITE));
397 * GtkCellRendererText:ellipsize:
399 * Specifies the preferred place to ellipsize the string, if the cell renderer
400 * does not have enough room to display the entire string. Setting it to
401 * %PANGO_ELLIPSIZE_NONE turns off ellipsizing. See the wrap-width property
402 * for another way of making the text fit into a given width.
406 g_object_class_install_property (object_class,
408 g_param_spec_enum ("ellipsize",
410 P_("The preferred place to ellipsize the string, "
411 "if the cell renderer does not have enough room "
412 "to display the entire string"),
413 PANGO_TYPE_ELLIPSIZE_MODE,
414 PANGO_ELLIPSIZE_NONE,
415 GTK_PARAM_READWRITE));
418 * GtkCellRendererText:width-chars:
420 * The desired width of the cell, in characters. If this property is set to
421 * -1, the width will be calculated automatically, otherwise the cell will
422 * request either 3 characters or the property value, whichever is greater.
426 g_object_class_install_property (object_class,
428 g_param_spec_int ("width-chars",
429 P_("Width In Characters"),
430 P_("The desired width of the label, in characters"),
434 GTK_PARAM_READWRITE));
437 * GtkCellRendererText:wrap-mode:
439 * Specifies how to break the string into multiple lines, if the cell
440 * renderer does not have enough room to display the entire string.
441 * This property has no effect unless the wrap-width property is set.
445 g_object_class_install_property (object_class,
447 g_param_spec_enum ("wrap-mode",
449 P_("How to break the string into multiple lines, "
450 "if the cell renderer does not have enough room "
451 "to display the entire string"),
452 PANGO_TYPE_WRAP_MODE,
454 GTK_PARAM_READWRITE));
457 * GtkCellRendererText:wrap-width:
459 * Specifies the width at which the text is wrapped. The wrap-mode property can
460 * be used to influence at what character positions the line breaks can be placed.
461 * Setting wrap-width to -1 turns wrapping off.
465 g_object_class_install_property (object_class,
467 g_param_spec_int ("wrap-width",
469 P_("The width at which the text is wrapped"),
473 GTK_PARAM_READWRITE));
476 * GtkCellRendererText:alignment:
478 * Specifies how to align the lines of text with respect to each other.
480 * Note that this property describes how to align the lines of text in
481 * case there are several of them. The "xalign" property of #GtkCellRenderer,
482 * on the other hand, sets the horizontal alignment of the whole text.
486 g_object_class_install_property (object_class,
488 g_param_spec_enum ("alignment",
490 P_("How to align the lines"),
491 PANGO_TYPE_ALIGNMENT,
493 GTK_PARAM_READWRITE));
495 /* Style props are set or not */
497 #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))
499 ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
500 P_("Background set"),
501 P_("Whether this tag affects the background color"));
503 ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
504 P_("Foreground set"),
505 P_("Whether this tag affects the foreground color"));
507 ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
508 P_("Editability set"),
509 P_("Whether this tag affects text editability"));
511 ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
512 P_("Font family set"),
513 P_("Whether this tag affects the font family"));
515 ADD_SET_PROP ("style-set", PROP_STYLE_SET,
516 P_("Font style set"),
517 P_("Whether this tag affects the font style"));
519 ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
520 P_("Font variant set"),
521 P_("Whether this tag affects the font variant"));
523 ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
524 P_("Font weight set"),
525 P_("Whether this tag affects the font weight"));
527 ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
528 P_("Font stretch set"),
529 P_("Whether this tag affects the font stretch"));
531 ADD_SET_PROP ("size-set", PROP_SIZE_SET,
533 P_("Whether this tag affects the font size"));
535 ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
536 P_("Font scale set"),
537 P_("Whether this tag scales the font size by a factor"));
539 ADD_SET_PROP ("rise-set", PROP_RISE_SET,
541 P_("Whether this tag affects the rise"));
543 ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
544 P_("Strikethrough set"),
545 P_("Whether this tag affects strikethrough"));
547 ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
549 P_("Whether this tag affects underlining"));
551 ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
553 P_("Whether this tag affects the language the text is rendered as"));
555 ADD_SET_PROP ("ellipsize-set", PROP_ELLIPSIZE_SET,
557 P_("Whether this tag affects the ellipsize mode"));
559 ADD_SET_PROP ("align-set", PROP_ALIGN_SET,
561 P_("Whether this tag affects the alignment mode"));
564 * GtkCellRendererText::edited
565 * @renderer: the object which received the signal.
566 * @path: the path identifying the edited cell.
567 * @new_text: the new text.
569 * This signal is emitted after @renderer has been edited.
571 text_cell_renderer_signals [EDITED] =
572 g_signal_new (I_("edited"),
573 G_OBJECT_CLASS_TYPE (object_class),
575 G_STRUCT_OFFSET (GtkCellRendererTextClass, edited),
577 _gtk_marshal_VOID__STRING_STRING,
582 g_type_class_add_private (object_class, sizeof (GtkCellRendererTextPrivate));
586 gtk_cell_renderer_text_finalize (GObject *object)
588 GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
589 GtkCellRendererTextPrivate *priv;
591 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (object);
593 pango_font_description_free (celltext->font);
595 g_free (celltext->text);
597 if (celltext->extra_attrs)
598 pango_attr_list_unref (celltext->extra_attrs);
601 g_object_unref (priv->language);
603 (* G_OBJECT_CLASS (gtk_cell_renderer_text_parent_class)->finalize) (object);
607 get_property_font_set_mask (guint prop_id)
611 case PROP_FAMILY_SET:
612 return PANGO_FONT_MASK_FAMILY;
614 return PANGO_FONT_MASK_STYLE;
615 case PROP_VARIANT_SET:
616 return PANGO_FONT_MASK_VARIANT;
617 case PROP_WEIGHT_SET:
618 return PANGO_FONT_MASK_WEIGHT;
619 case PROP_STRETCH_SET:
620 return PANGO_FONT_MASK_STRETCH;
622 return PANGO_FONT_MASK_SIZE;
629 gtk_cell_renderer_text_get_property (GObject *object,
634 GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
635 GtkCellRendererTextPrivate *priv;
637 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (object);
642 g_value_set_string (value, celltext->text);
645 case PROP_ATTRIBUTES:
646 g_value_set_boxed (value, celltext->extra_attrs);
649 case PROP_SINGLE_PARAGRAPH_MODE:
650 g_value_set_boolean (value, priv->single_paragraph);
653 case PROP_BACKGROUND_GDK:
657 color.red = celltext->background.red;
658 color.green = celltext->background.green;
659 color.blue = celltext->background.blue;
661 g_value_set_boxed (value, &color);
665 case PROP_FOREGROUND_GDK:
669 color.red = celltext->foreground.red;
670 color.green = celltext->foreground.green;
671 color.blue = celltext->foreground.blue;
673 g_value_set_boxed (value, &color);
678 g_value_take_string (value, pango_font_description_to_string (celltext->font));
682 g_value_set_boxed (value, celltext->font);
686 g_value_set_string (value, pango_font_description_get_family (celltext->font));
690 g_value_set_enum (value, pango_font_description_get_style (celltext->font));
694 g_value_set_enum (value, pango_font_description_get_variant (celltext->font));
698 g_value_set_int (value, pango_font_description_get_weight (celltext->font));
702 g_value_set_enum (value, pango_font_description_get_stretch (celltext->font));
706 g_value_set_int (value, pango_font_description_get_size (celltext->font));
709 case PROP_SIZE_POINTS:
710 g_value_set_double (value, ((double)pango_font_description_get_size (celltext->font)) / (double)PANGO_SCALE);
714 g_value_set_double (value, celltext->font_scale);
718 g_value_set_boolean (value, celltext->editable);
721 case PROP_STRIKETHROUGH:
722 g_value_set_boolean (value, celltext->strikethrough);
726 g_value_set_enum (value, celltext->underline_style);
730 g_value_set_int (value, celltext->rise);
734 g_value_set_static_string (value, pango_language_to_string (priv->language));
738 g_value_set_enum (value, priv->ellipsize);
742 g_value_set_enum (value, priv->wrap_mode);
745 case PROP_WRAP_WIDTH:
746 g_value_set_int (value, priv->wrap_width);
750 g_value_set_enum (value, priv->align);
753 case PROP_BACKGROUND_SET:
754 g_value_set_boolean (value, celltext->background_set);
757 case PROP_FOREGROUND_SET:
758 g_value_set_boolean (value, celltext->foreground_set);
761 case PROP_FAMILY_SET:
763 case PROP_VARIANT_SET:
764 case PROP_WEIGHT_SET:
765 case PROP_STRETCH_SET:
768 PangoFontMask mask = get_property_font_set_mask (param_id);
769 g_value_set_boolean (value, (pango_font_description_get_set_fields (celltext->font) & mask) != 0);
775 g_value_set_boolean (value, celltext->scale_set);
778 case PROP_EDITABLE_SET:
779 g_value_set_boolean (value, celltext->editable_set);
782 case PROP_STRIKETHROUGH_SET:
783 g_value_set_boolean (value, celltext->strikethrough_set);
786 case PROP_UNDERLINE_SET:
787 g_value_set_boolean (value, celltext->underline_set);
791 g_value_set_boolean (value, celltext->rise_set);
794 case PROP_LANGUAGE_SET:
795 g_value_set_boolean (value, priv->language_set);
798 case PROP_ELLIPSIZE_SET:
799 g_value_set_boolean (value, priv->ellipsize_set);
803 g_value_set_boolean (value, priv->align_set);
806 case PROP_WIDTH_CHARS:
807 g_value_set_int (value, priv->width_chars);
810 case PROP_BACKGROUND:
811 case PROP_FOREGROUND:
814 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
821 set_bg_color (GtkCellRendererText *celltext,
826 if (!celltext->background_set)
828 celltext->background_set = TRUE;
829 g_object_notify (G_OBJECT (celltext), "background-set");
832 celltext->background.red = color->red;
833 celltext->background.green = color->green;
834 celltext->background.blue = color->blue;
838 if (celltext->background_set)
840 celltext->background_set = FALSE;
841 g_object_notify (G_OBJECT (celltext), "background-set");
848 set_fg_color (GtkCellRendererText *celltext,
853 if (!celltext->foreground_set)
855 celltext->foreground_set = TRUE;
856 g_object_notify (G_OBJECT (celltext), "foreground-set");
859 celltext->foreground.red = color->red;
860 celltext->foreground.green = color->green;
861 celltext->foreground.blue = color->blue;
865 if (celltext->foreground_set)
867 celltext->foreground_set = FALSE;
868 g_object_notify (G_OBJECT (celltext), "foreground-set");
874 set_font_desc_fields (PangoFontDescription *desc,
875 PangoFontMask to_set)
877 PangoFontMask changed_mask = 0;
879 if (to_set & PANGO_FONT_MASK_FAMILY)
881 const char *family = pango_font_description_get_family (desc);
885 changed_mask |= PANGO_FONT_MASK_FAMILY;
888 pango_font_description_set_family (desc, family);
890 if (to_set & PANGO_FONT_MASK_STYLE)
891 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
892 if (to_set & PANGO_FONT_MASK_VARIANT)
893 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
894 if (to_set & PANGO_FONT_MASK_WEIGHT)
895 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
896 if (to_set & PANGO_FONT_MASK_STRETCH)
897 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
898 if (to_set & PANGO_FONT_MASK_SIZE)
900 gint size = pango_font_description_get_size (desc);
903 size = 10 * PANGO_SCALE;
904 changed_mask |= PANGO_FONT_MASK_SIZE;
907 pango_font_description_set_size (desc, size);
914 notify_set_changed (GObject *object,
915 PangoFontMask changed_mask)
917 if (changed_mask & PANGO_FONT_MASK_FAMILY)
918 g_object_notify (object, "family-set");
919 if (changed_mask & PANGO_FONT_MASK_STYLE)
920 g_object_notify (object, "style-set");
921 if (changed_mask & PANGO_FONT_MASK_VARIANT)
922 g_object_notify (object, "variant-set");
923 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
924 g_object_notify (object, "weight-set");
925 if (changed_mask & PANGO_FONT_MASK_STRETCH)
926 g_object_notify (object, "stretch-set");
927 if (changed_mask & PANGO_FONT_MASK_SIZE)
928 g_object_notify (object, "size-set");
932 notify_fields_changed (GObject *object,
933 PangoFontMask changed_mask)
935 if (changed_mask & PANGO_FONT_MASK_FAMILY)
936 g_object_notify (object, "family");
937 if (changed_mask & PANGO_FONT_MASK_STYLE)
938 g_object_notify (object, "style");
939 if (changed_mask & PANGO_FONT_MASK_VARIANT)
940 g_object_notify (object, "variant");
941 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
942 g_object_notify (object, "weight");
943 if (changed_mask & PANGO_FONT_MASK_STRETCH)
944 g_object_notify (object, "stretch");
945 if (changed_mask & PANGO_FONT_MASK_SIZE)
946 g_object_notify (object, "size");
950 set_font_description (GtkCellRendererText *celltext,
951 PangoFontDescription *font_desc)
953 GObject *object = G_OBJECT (celltext);
954 PangoFontDescription *new_font_desc;
955 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
958 new_font_desc = pango_font_description_copy (font_desc);
960 new_font_desc = pango_font_description_new ();
962 old_mask = pango_font_description_get_set_fields (celltext->font);
963 new_mask = pango_font_description_get_set_fields (new_font_desc);
965 changed_mask = old_mask | new_mask;
966 set_changed_mask = old_mask ^ new_mask;
968 pango_font_description_free (celltext->font);
969 celltext->font = new_font_desc;
971 g_object_freeze_notify (object);
973 g_object_notify (object, "font-desc");
974 g_object_notify (object, "font");
976 if (changed_mask & PANGO_FONT_MASK_FAMILY)
977 g_object_notify (object, "family");
978 if (changed_mask & PANGO_FONT_MASK_STYLE)
979 g_object_notify (object, "style");
980 if (changed_mask & PANGO_FONT_MASK_VARIANT)
981 g_object_notify (object, "variant");
982 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
983 g_object_notify (object, "weight");
984 if (changed_mask & PANGO_FONT_MASK_STRETCH)
985 g_object_notify (object, "stretch");
986 if (changed_mask & PANGO_FONT_MASK_SIZE)
988 g_object_notify (object, "size");
989 g_object_notify (object, "size-points");
992 notify_set_changed (object, set_changed_mask);
994 g_object_thaw_notify (object);
998 gtk_cell_renderer_text_set_property (GObject *object,
1000 const GValue *value,
1003 GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
1004 GtkCellRendererTextPrivate *priv;
1006 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (object);
1011 g_free (celltext->text);
1013 if (priv->markup_set)
1015 if (celltext->extra_attrs)
1016 pango_attr_list_unref (celltext->extra_attrs);
1017 celltext->extra_attrs = NULL;
1018 priv->markup_set = FALSE;
1021 celltext->text = g_strdup (g_value_get_string (value));
1022 g_object_notify (object, "text");
1025 case PROP_ATTRIBUTES:
1026 if (celltext->extra_attrs)
1027 pango_attr_list_unref (celltext->extra_attrs);
1029 celltext->extra_attrs = g_value_get_boxed (value);
1030 if (celltext->extra_attrs)
1031 pango_attr_list_ref (celltext->extra_attrs);
1037 GError *error = NULL;
1038 PangoAttrList *attrs = NULL;
1040 str = g_value_get_string (value);
1041 if (str && !pango_parse_markup (str,
1049 g_warning ("Failed to set text from markup due to error parsing markup: %s",
1051 g_error_free (error);
1055 g_free (celltext->text);
1057 if (celltext->extra_attrs)
1058 pango_attr_list_unref (celltext->extra_attrs);
1060 celltext->text = text;
1061 celltext->extra_attrs = attrs;
1062 priv->markup_set = TRUE;
1066 case PROP_SINGLE_PARAGRAPH_MODE:
1067 priv->single_paragraph = g_value_get_boolean (value);
1070 case PROP_BACKGROUND:
1074 if (!g_value_get_string (value))
1075 set_bg_color (celltext, NULL); /* reset to backgrounmd_set to FALSE */
1076 else if (gdk_color_parse (g_value_get_string (value), &color))
1077 set_bg_color (celltext, &color);
1079 g_warning ("Don't know color `%s'", g_value_get_string (value));
1081 g_object_notify (object, "background-gdk");
1085 case PROP_FOREGROUND:
1089 if (!g_value_get_string (value))
1090 set_fg_color (celltext, NULL); /* reset to foreground_set to FALSE */
1091 else if (gdk_color_parse (g_value_get_string (value), &color))
1092 set_fg_color (celltext, &color);
1094 g_warning ("Don't know color `%s'", g_value_get_string (value));
1096 g_object_notify (object, "foreground-gdk");
1100 case PROP_BACKGROUND_GDK:
1101 /* This notifies the GObject itself. */
1102 set_bg_color (celltext, g_value_get_boxed (value));
1105 case PROP_FOREGROUND_GDK:
1106 /* This notifies the GObject itself. */
1107 set_fg_color (celltext, g_value_get_boxed (value));
1112 PangoFontDescription *font_desc = NULL;
1115 name = g_value_get_string (value);
1118 font_desc = pango_font_description_from_string (name);
1120 set_font_description (celltext, font_desc);
1122 pango_font_description_free (font_desc);
1124 if (celltext->fixed_height_rows != -1)
1125 celltext->calc_fixed_height = TRUE;
1129 case PROP_FONT_DESC:
1130 set_font_description (celltext, g_value_get_boxed (value));
1132 if (celltext->fixed_height_rows != -1)
1133 celltext->calc_fixed_height = TRUE;
1142 case PROP_SIZE_POINTS:
1144 PangoFontMask old_set_mask = pango_font_description_get_set_fields (celltext->font);
1149 pango_font_description_set_family (celltext->font,
1150 g_value_get_string (value));
1153 pango_font_description_set_style (celltext->font,
1154 g_value_get_enum (value));
1157 pango_font_description_set_variant (celltext->font,
1158 g_value_get_enum (value));
1161 pango_font_description_set_weight (celltext->font,
1162 g_value_get_int (value));
1165 pango_font_description_set_stretch (celltext->font,
1166 g_value_get_enum (value));
1169 pango_font_description_set_size (celltext->font,
1170 g_value_get_int (value));
1171 g_object_notify (object, "size-points");
1173 case PROP_SIZE_POINTS:
1174 pango_font_description_set_size (celltext->font,
1175 g_value_get_double (value) * PANGO_SCALE);
1176 g_object_notify (object, "size");
1180 if (celltext->fixed_height_rows != -1)
1181 celltext->calc_fixed_height = TRUE;
1183 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (celltext->font));
1184 g_object_notify (object, "font-desc");
1185 g_object_notify (object, "font");
1191 celltext->font_scale = g_value_get_double (value);
1192 celltext->scale_set = TRUE;
1193 if (celltext->fixed_height_rows != -1)
1194 celltext->calc_fixed_height = TRUE;
1195 g_object_notify (object, "scale-set");
1199 celltext->editable = g_value_get_boolean (value);
1200 celltext->editable_set = TRUE;
1201 if (celltext->editable)
1202 GTK_CELL_RENDERER (celltext)->mode = GTK_CELL_RENDERER_MODE_EDITABLE;
1204 GTK_CELL_RENDERER (celltext)->mode = GTK_CELL_RENDERER_MODE_INERT;
1205 g_object_notify (object, "editable-set");
1208 case PROP_STRIKETHROUGH:
1209 celltext->strikethrough = g_value_get_boolean (value);
1210 celltext->strikethrough_set = TRUE;
1211 g_object_notify (object, "strikethrough-set");
1214 case PROP_UNDERLINE:
1215 celltext->underline_style = g_value_get_enum (value);
1216 celltext->underline_set = TRUE;
1217 g_object_notify (object, "underline-set");
1222 celltext->rise = g_value_get_int (value);
1223 celltext->rise_set = TRUE;
1224 g_object_notify (object, "rise-set");
1225 if (celltext->fixed_height_rows != -1)
1226 celltext->calc_fixed_height = TRUE;
1230 priv->language_set = TRUE;
1232 g_object_unref (priv->language);
1233 priv->language = pango_language_from_string (g_value_get_string (value));
1234 g_object_notify (object, "language-set");
1237 case PROP_ELLIPSIZE:
1238 priv->ellipsize = g_value_get_enum (value);
1239 priv->ellipsize_set = TRUE;
1240 g_object_notify (object, "ellipsize-set");
1243 case PROP_WRAP_MODE:
1244 priv->wrap_mode = g_value_get_enum (value);
1247 case PROP_WRAP_WIDTH:
1248 priv->wrap_width = g_value_get_int (value);
1251 case PROP_WIDTH_CHARS:
1252 priv->width_chars = g_value_get_int (value);
1256 priv->align = g_value_get_enum (value);
1257 priv->align_set = TRUE;
1258 g_object_notify (object, "align-set");
1261 case PROP_BACKGROUND_SET:
1262 celltext->background_set = g_value_get_boolean (value);
1265 case PROP_FOREGROUND_SET:
1266 celltext->foreground_set = g_value_get_boolean (value);
1269 case PROP_FAMILY_SET:
1270 case PROP_STYLE_SET:
1271 case PROP_VARIANT_SET:
1272 case PROP_WEIGHT_SET:
1273 case PROP_STRETCH_SET:
1275 if (!g_value_get_boolean (value))
1277 pango_font_description_unset_fields (celltext->font,
1278 get_property_font_set_mask (param_id));
1282 PangoFontMask changed_mask;
1284 changed_mask = set_font_desc_fields (celltext->font,
1285 get_property_font_set_mask (param_id));
1286 notify_fields_changed (G_OBJECT (celltext), changed_mask);
1290 case PROP_SCALE_SET:
1291 celltext->scale_set = g_value_get_boolean (value);
1294 case PROP_EDITABLE_SET:
1295 celltext->editable_set = g_value_get_boolean (value);
1298 case PROP_STRIKETHROUGH_SET:
1299 celltext->strikethrough_set = g_value_get_boolean (value);
1302 case PROP_UNDERLINE_SET:
1303 celltext->underline_set = g_value_get_boolean (value);
1307 celltext->rise_set = g_value_get_boolean (value);
1310 case PROP_LANGUAGE_SET:
1311 priv->language_set = g_value_get_boolean (value);
1314 case PROP_ELLIPSIZE_SET:
1315 priv->ellipsize_set = g_value_get_boolean (value);
1318 case PROP_ALIGN_SET:
1319 priv->align_set = g_value_get_boolean (value);
1323 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1329 * gtk_cell_renderer_text_new:
1331 * Creates a new #GtkCellRendererText. Adjust how text is drawn using
1332 * object properties. Object properties can be
1333 * set globally (with g_object_set()). Also, with #GtkTreeViewColumn,
1334 * you can bind a property to a value in a #GtkTreeModel. For example,
1335 * you can bind the "text" property on the cell renderer to a string
1336 * value in the model, thus rendering a different string in each row
1337 * of the #GtkTreeView
1339 * Return value: the new cell renderer
1342 gtk_cell_renderer_text_new (void)
1344 return g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, NULL);
1348 add_attr (PangoAttrList *attr_list,
1349 PangoAttribute *attr)
1351 attr->start_index = 0;
1352 attr->end_index = G_MAXINT;
1354 pango_attr_list_insert (attr_list, attr);
1358 get_layout (GtkCellRendererText *celltext,
1360 gboolean will_render,
1361 GtkCellRendererState flags)
1363 PangoAttrList *attr_list;
1364 PangoLayout *layout;
1365 PangoUnderline uline;
1366 GtkCellRendererTextPrivate *priv;
1368 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (celltext);
1370 layout = gtk_widget_create_pango_layout (widget, celltext->text);
1372 if (celltext->extra_attrs)
1373 attr_list = pango_attr_list_copy (celltext->extra_attrs);
1375 attr_list = pango_attr_list_new ();
1377 pango_layout_set_single_paragraph_mode (layout, priv->single_paragraph);
1381 /* Add options that affect appearance but not size */
1383 /* note that background doesn't go here, since it affects
1384 * background_area not the PangoLayout area
1387 if (celltext->foreground_set
1388 && (flags & GTK_CELL_RENDERER_SELECTED) == 0)
1392 color = celltext->foreground;
1394 add_attr (attr_list,
1395 pango_attr_foreground_new (color.red, color.green, color.blue));
1398 if (celltext->strikethrough_set)
1399 add_attr (attr_list,
1400 pango_attr_strikethrough_new (celltext->strikethrough));
1403 add_attr (attr_list, pango_attr_font_desc_new (celltext->font));
1405 if (celltext->scale_set &&
1406 celltext->font_scale != 1.0)
1407 add_attr (attr_list, pango_attr_scale_new (celltext->font_scale));
1409 if (celltext->underline_set)
1410 uline = celltext->underline_style;
1412 uline = PANGO_UNDERLINE_NONE;
1414 if (priv->language_set)
1415 add_attr (attr_list, pango_attr_language_new (priv->language));
1417 if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT)
1421 case PANGO_UNDERLINE_NONE:
1422 uline = PANGO_UNDERLINE_SINGLE;
1425 case PANGO_UNDERLINE_SINGLE:
1426 uline = PANGO_UNDERLINE_DOUBLE;
1434 if (uline != PANGO_UNDERLINE_NONE)
1435 add_attr (attr_list, pango_attr_underline_new (celltext->underline_style));
1437 if (celltext->rise_set)
1438 add_attr (attr_list, pango_attr_rise_new (celltext->rise));
1440 if (priv->ellipsize_set)
1441 pango_layout_set_ellipsize (layout, priv->ellipsize);
1443 pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_NONE);
1445 if (priv->wrap_width != -1)
1447 pango_layout_set_width (layout, priv->wrap_width * PANGO_SCALE);
1448 pango_layout_set_wrap (layout, priv->wrap_mode);
1452 pango_layout_set_width (layout, -1);
1453 pango_layout_set_wrap (layout, PANGO_WRAP_CHAR);
1456 if (priv->align_set)
1457 pango_layout_set_alignment (layout, priv->align);
1460 PangoAlignment align;
1462 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1463 align = PANGO_ALIGN_RIGHT;
1465 align = PANGO_ALIGN_LEFT;
1467 pango_layout_set_alignment (layout, align);
1470 pango_layout_set_attributes (layout, attr_list);
1472 pango_attr_list_unref (attr_list);
1478 get_size (GtkCellRenderer *cell,
1480 GdkRectangle *cell_area,
1481 PangoLayout *layout,
1487 GtkCellRendererText *celltext = (GtkCellRendererText *) cell;
1488 PangoRectangle rect;
1489 GtkCellRendererTextPrivate *priv;
1491 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
1493 if (celltext->calc_fixed_height)
1495 PangoContext *context;
1496 PangoFontMetrics *metrics;
1497 PangoFontDescription *font_desc;
1500 font_desc = pango_font_description_copy_static (widget->style->font_desc);
1501 pango_font_description_merge_static (font_desc, celltext->font, TRUE);
1503 if (celltext->scale_set)
1504 pango_font_description_set_size (font_desc,
1505 celltext->font_scale * pango_font_description_get_size (font_desc));
1507 context = gtk_widget_get_pango_context (widget);
1509 metrics = pango_context_get_metrics (context,
1511 pango_context_get_language (context));
1512 row_height = (pango_font_metrics_get_ascent (metrics) +
1513 pango_font_metrics_get_descent (metrics));
1514 pango_font_metrics_unref (metrics);
1516 pango_font_description_free (font_desc);
1518 gtk_cell_renderer_set_fixed_size (cell,
1519 cell->width, 2*cell->ypad +
1520 celltext->fixed_height_rows * PANGO_PIXELS (row_height));
1524 *height = cell->height;
1527 celltext->calc_fixed_height = FALSE;
1533 g_object_ref (layout);
1535 layout = get_layout (celltext, widget, FALSE, 0);
1537 pango_layout_get_pixel_extents (layout, NULL, &rect);
1540 *height = cell->ypad * 2 + rect.height;
1542 /* The minimum size for ellipsized labels is ~ 3 chars */
1545 if (priv->ellipsize || priv->width_chars > 0)
1547 PangoContext *context;
1548 PangoFontMetrics *metrics;
1551 context = pango_layout_get_context (layout);
1552 metrics = pango_context_get_metrics (context, widget->style->font_desc, pango_context_get_language (context));
1554 char_width = pango_font_metrics_get_approximate_char_width (metrics);
1555 pango_font_metrics_unref (metrics);
1557 *width = cell->xpad * 2 + (PANGO_PIXELS (char_width) * MAX (priv->width_chars, 3));
1561 *width = cell->xpad * 2 + rect.x + rect.width;
1569 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1570 *x_offset = (1.0 - cell->xalign) * (cell_area->width - (rect.x + rect.width + (2 * cell->xpad)));
1572 *x_offset = cell->xalign * (cell_area->width - (rect.x + rect.width + (2 * cell->xpad)));
1574 if ((priv->ellipsize_set && priv->ellipsize != PANGO_ELLIPSIZE_NONE) || priv->wrap_width != -1)
1575 *x_offset = MAX(*x_offset, 0);
1579 *y_offset = cell->yalign * (cell_area->height - (rect.height + (2 * cell->ypad)));
1580 *y_offset = MAX (*y_offset, 0);
1585 if (x_offset) *x_offset = 0;
1586 if (y_offset) *y_offset = 0;
1589 g_object_unref (layout);
1594 gtk_cell_renderer_text_get_size (GtkCellRenderer *cell,
1596 GdkRectangle *cell_area,
1602 get_size (cell, widget, cell_area, NULL,
1603 x_offset, y_offset, width, height);
1607 gtk_cell_renderer_text_render (GtkCellRenderer *cell,
1608 GdkDrawable *window,
1610 GdkRectangle *background_area,
1611 GdkRectangle *cell_area,
1612 GdkRectangle *expose_area,
1613 GtkCellRendererState flags)
1616 GtkCellRendererText *celltext = (GtkCellRendererText *) cell;
1617 PangoLayout *layout;
1621 GtkCellRendererTextPrivate *priv;
1623 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
1625 layout = get_layout (celltext, widget, TRUE, flags);
1626 get_size (cell, widget, cell_area, layout, &x_offset, &y_offset, NULL, NULL);
1628 if (!cell->sensitive)
1630 state = GTK_STATE_INSENSITIVE;
1632 else if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
1634 if (GTK_WIDGET_HAS_FOCUS (widget))
1635 state = GTK_STATE_SELECTED;
1637 state = GTK_STATE_ACTIVE;
1639 else if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT &&
1640 GTK_WIDGET_STATE (widget) == GTK_STATE_PRELIGHT)
1642 state = GTK_STATE_PRELIGHT;
1646 if (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE)
1647 state = GTK_STATE_INSENSITIVE;
1649 state = GTK_STATE_NORMAL;
1652 if (celltext->background_set &&
1653 (flags & GTK_CELL_RENDERER_SELECTED) == 0)
1655 cairo_t *cr = gdk_cairo_create (window);
1659 gdk_cairo_rectangle (cr, expose_area);
1663 gdk_cairo_rectangle (cr, background_area);
1664 cairo_set_source_rgb (cr,
1665 celltext->background.red / 65535.,
1666 celltext->background.green / 65535.,
1667 celltext->background.blue / 65535.);
1673 if (priv->ellipsize_set && priv->ellipsize != PANGO_ELLIPSIZE_NONE)
1674 pango_layout_set_width (layout,
1675 (cell_area->width - x_offset - 2 * cell->xpad) * PANGO_SCALE);
1676 else if (priv->wrap_width == -1)
1677 pango_layout_set_width (layout, -1);
1679 gtk_paint_layout (widget->style,
1686 cell_area->x + x_offset + cell->xpad,
1687 cell_area->y + y_offset + cell->ypad,
1690 g_object_unref (layout);
1694 gtk_cell_renderer_text_editing_done (GtkCellEditable *entry,
1698 const gchar *new_text;
1699 GtkCellRendererTextPrivate *priv;
1701 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1705 if (priv->focus_out_id > 0)
1707 g_signal_handler_disconnect (entry, priv->focus_out_id);
1708 priv->focus_out_id = 0;
1711 if (priv->populate_popup_id > 0)
1713 g_signal_handler_disconnect (entry, priv->populate_popup_id);
1714 priv->populate_popup_id = 0;
1717 if (priv->entry_menu_popdown_timeout)
1719 g_source_remove (priv->entry_menu_popdown_timeout);
1720 priv->entry_menu_popdown_timeout = 0;
1723 gtk_cell_renderer_stop_editing (GTK_CELL_RENDERER (data),
1724 GTK_ENTRY (entry)->editing_canceled);
1725 if (GTK_ENTRY (entry)->editing_canceled)
1728 path = g_object_get_data (G_OBJECT (entry), GTK_CELL_RENDERER_TEXT_PATH);
1729 new_text = gtk_entry_get_text (GTK_ENTRY (entry));
1731 g_signal_emit (data, text_cell_renderer_signals[EDITED], 0, path, new_text);
1735 popdown_timeout (gpointer data)
1737 GtkCellRendererTextPrivate *priv;
1739 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1741 priv->entry_menu_popdown_timeout = 0;
1743 if (!GTK_WIDGET_HAS_FOCUS (priv->entry))
1744 gtk_cell_renderer_text_editing_done (GTK_CELL_EDITABLE (priv->entry), data);
1750 gtk_cell_renderer_text_popup_unmap (GtkMenu *menu,
1753 GtkCellRendererTextPrivate *priv;
1755 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1757 priv->in_entry_menu = FALSE;
1759 if (priv->entry_menu_popdown_timeout)
1762 priv->entry_menu_popdown_timeout = gdk_threads_add_timeout (500, popdown_timeout,
1767 gtk_cell_renderer_text_populate_popup (GtkEntry *entry,
1771 GtkCellRendererTextPrivate *priv;
1773 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1775 if (priv->entry_menu_popdown_timeout)
1777 g_source_remove (priv->entry_menu_popdown_timeout);
1778 priv->entry_menu_popdown_timeout = 0;
1781 priv->in_entry_menu = TRUE;
1783 g_signal_connect (menu, "unmap",
1784 G_CALLBACK (gtk_cell_renderer_text_popup_unmap), data);
1788 gtk_cell_renderer_text_focus_out_event (GtkWidget *entry,
1792 GtkCellRendererTextPrivate *priv;
1794 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1796 if (priv->in_entry_menu)
1799 GTK_ENTRY (entry)->editing_canceled = TRUE;
1800 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
1801 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
1803 /* entry needs focus-out-event */
1807 static GtkCellEditable *
1808 gtk_cell_renderer_text_start_editing (GtkCellRenderer *cell,
1812 GdkRectangle *background_area,
1813 GdkRectangle *cell_area,
1814 GtkCellRendererState flags)
1816 GtkRequisition requisition;
1817 GtkCellRendererText *celltext;
1818 GtkCellRendererTextPrivate *priv;
1820 celltext = GTK_CELL_RENDERER_TEXT (cell);
1821 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
1823 /* If the cell isn't editable we return NULL. */
1824 if (celltext->editable == FALSE)
1827 priv->entry = g_object_new (GTK_TYPE_ENTRY,
1829 "xalign", cell->xalign,
1833 gtk_entry_set_text (GTK_ENTRY (priv->entry), celltext->text);
1834 g_object_set_data_full (G_OBJECT (priv->entry), I_(GTK_CELL_RENDERER_TEXT_PATH), g_strdup (path), g_free);
1836 gtk_editable_select_region (GTK_EDITABLE (priv->entry), 0, -1);
1838 gtk_widget_size_request (priv->entry, &requisition);
1839 if (requisition.height < cell_area->height)
1841 GtkBorder *style_border;
1844 gtk_widget_style_get (priv->entry,
1845 "inner-border", &style_border,
1850 border = *style_border;
1851 g_boxed_free (GTK_TYPE_BORDER, style_border);
1855 /* Since boxed style properties can't have default values ... */
1860 border.top = (cell_area->height - requisition.height) / 2;
1861 border.bottom = (cell_area->height - requisition.height) / 2;
1862 gtk_entry_set_inner_border (GTK_ENTRY (priv->entry), &border);
1865 priv->in_entry_menu = FALSE;
1866 if (priv->entry_menu_popdown_timeout)
1868 g_source_remove (priv->entry_menu_popdown_timeout);
1869 priv->entry_menu_popdown_timeout = 0;
1872 g_signal_connect (priv->entry,
1874 G_CALLBACK (gtk_cell_renderer_text_editing_done),
1876 priv->focus_out_id = g_signal_connect_after (priv->entry, "focus_out_event",
1877 G_CALLBACK (gtk_cell_renderer_text_focus_out_event),
1879 priv->populate_popup_id =
1880 g_signal_connect (priv->entry, "populate_popup",
1881 G_CALLBACK (gtk_cell_renderer_text_populate_popup),
1884 gtk_widget_show (priv->entry);
1886 return GTK_CELL_EDITABLE (priv->entry);
1890 * gtk_cell_renderer_text_set_fixed_height_from_font:
1891 * @renderer: A #GtkCellRendererText
1892 * @number_of_rows: Number of rows of text each cell renderer is allocated, or -1
1894 * Sets the height of a renderer to explicitly be determined by the "font" and
1895 * "y_pad" property set on it. Further changes in these properties do not
1896 * affect the height, so they must be accompanied by a subsequent call to this
1897 * function. Using this function is unflexible, and should really only be used
1898 * if calculating the size of a cell is too slow (ie, a massive number of cells
1899 * displayed). If @number_of_rows is -1, then the fixed height is unset, and
1900 * the height is determined by the properties again.
1903 gtk_cell_renderer_text_set_fixed_height_from_font (GtkCellRendererText *renderer,
1904 gint number_of_rows)
1906 g_return_if_fail (GTK_IS_CELL_RENDERER_TEXT (renderer));
1907 g_return_if_fail (number_of_rows == -1 || number_of_rows > 0);
1909 if (number_of_rows == -1)
1911 gtk_cell_renderer_set_fixed_size (GTK_CELL_RENDERER (renderer),
1912 GTK_CELL_RENDERER (renderer)->width,
1917 renderer->fixed_height_rows = number_of_rows;
1918 renderer->calc_fixed_height = TRUE;
1922 #define __GTK_CELL_RENDERER_TEXT_C__
1923 #include "gtkaliasdef.c"