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"
24 #include "gtkextendedlayout.h"
26 #include "gtkmarshalers.h"
28 #include "gtkprivate.h"
29 #include "gtktreeprivate.h"
32 static void gtk_cell_renderer_text_finalize (GObject *object);
34 static void gtk_cell_renderer_text_get_property (GObject *object,
38 static void gtk_cell_renderer_text_set_property (GObject *object,
42 static void gtk_cell_renderer_text_get_size (GtkCellRenderer *cell,
44 GdkRectangle *cell_area,
49 static void gtk_cell_renderer_text_render (GtkCellRenderer *cell,
52 GdkRectangle *background_area,
53 GdkRectangle *cell_area,
54 GdkRectangle *expose_area,
55 GtkCellRendererState flags);
57 static GtkCellEditable *gtk_cell_renderer_text_start_editing (GtkCellRenderer *cell,
61 GdkRectangle *background_area,
62 GdkRectangle *cell_area,
63 GtkCellRendererState flags);
65 static void gtk_cell_renderer_text_extended_layout_init (GtkExtendedLayoutIface *iface);
78 PROP_SINGLE_PARAGRAPH_MODE,
106 /* Whether-a-style-arg-is-set args */
117 PROP_STRIKETHROUGH_SET,
125 static guint text_cell_renderer_signals [LAST_SIGNAL];
127 #define GTK_CELL_RENDERER_TEXT_PATH "gtk-cell-renderer-text-path"
129 #define GTK_CELL_RENDERER_TEXT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), GTK_TYPE_CELL_RENDERER_TEXT, GtkCellRendererTextPrivate))
131 typedef struct _GtkCellRendererTextPrivate GtkCellRendererTextPrivate;
132 struct _GtkCellRendererTextPrivate
134 guint single_paragraph : 1;
135 guint language_set : 1;
136 guint markup_set : 1;
137 guint ellipsize_set : 1;
141 PangoLanguage *language;
142 PangoEllipsizeMode ellipsize;
143 PangoWrapMode wrap_mode;
144 PangoAlignment align;
146 gulong populate_popup_id;
147 gulong entry_menu_popdown_timeout;
148 gboolean in_entry_menu;
157 G_DEFINE_TYPE_WITH_CODE (GtkCellRendererText, gtk_cell_renderer_text, GTK_TYPE_CELL_RENDERER,
158 G_IMPLEMENT_INTERFACE (GTK_TYPE_EXTENDED_LAYOUT,
159 gtk_cell_renderer_text_extended_layout_init))
162 gtk_cell_renderer_text_init (GtkCellRendererText *celltext)
164 GtkCellRendererTextPrivate *priv;
166 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (celltext);
168 GTK_CELL_RENDERER (celltext)->xalign = 0.0;
169 GTK_CELL_RENDERER (celltext)->yalign = 0.5;
170 GTK_CELL_RENDERER (celltext)->xpad = 2;
171 GTK_CELL_RENDERER (celltext)->ypad = 2;
172 celltext->font_scale = 1.0;
173 celltext->fixed_height_rows = -1;
174 celltext->font = pango_font_description_new ();
176 priv->width_chars = -1;
177 priv->wrap_width = -1;
178 priv->wrap_mode = PANGO_WRAP_CHAR;
179 priv->align = PANGO_ALIGN_LEFT;
180 priv->align_set = FALSE;
184 gtk_cell_renderer_text_class_init (GtkCellRendererTextClass *class)
186 GObjectClass *object_class = G_OBJECT_CLASS (class);
187 GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);
189 object_class->finalize = gtk_cell_renderer_text_finalize;
191 object_class->get_property = gtk_cell_renderer_text_get_property;
192 object_class->set_property = gtk_cell_renderer_text_set_property;
194 cell_class->get_size = gtk_cell_renderer_text_get_size;
195 cell_class->render = gtk_cell_renderer_text_render;
196 cell_class->start_editing = gtk_cell_renderer_text_start_editing;
198 g_object_class_install_property (object_class,
200 g_param_spec_string ("text",
202 P_("Text to render"),
204 GTK_PARAM_READWRITE));
206 g_object_class_install_property (object_class,
208 g_param_spec_string ("markup",
210 P_("Marked up text to render"),
212 GTK_PARAM_WRITABLE));
214 g_object_class_install_property (object_class,
216 g_param_spec_boxed ("attributes",
218 P_("A list of style attributes to apply to the text of the renderer"),
219 PANGO_TYPE_ATTR_LIST,
220 GTK_PARAM_READWRITE));
222 g_object_class_install_property (object_class,
223 PROP_SINGLE_PARAGRAPH_MODE,
224 g_param_spec_boolean ("single-paragraph-mode",
225 P_("Single Paragraph Mode"),
226 P_("Whether or not to keep all text in a single paragraph"),
228 GTK_PARAM_READWRITE));
231 g_object_class_install_property (object_class,
233 g_param_spec_string ("background",
234 P_("Background color name"),
235 P_("Background color as a string"),
237 GTK_PARAM_WRITABLE));
239 g_object_class_install_property (object_class,
241 g_param_spec_boxed ("background-gdk",
242 P_("Background color"),
243 P_("Background color as a GdkColor"),
245 GTK_PARAM_READWRITE));
247 g_object_class_install_property (object_class,
249 g_param_spec_string ("foreground",
250 P_("Foreground color name"),
251 P_("Foreground color as a string"),
253 GTK_PARAM_WRITABLE));
255 g_object_class_install_property (object_class,
257 g_param_spec_boxed ("foreground-gdk",
258 P_("Foreground color"),
259 P_("Foreground color as a GdkColor"),
261 GTK_PARAM_READWRITE));
264 g_object_class_install_property (object_class,
266 g_param_spec_boolean ("editable",
268 P_("Whether the text can be modified by the user"),
270 GTK_PARAM_READWRITE));
272 g_object_class_install_property (object_class,
274 g_param_spec_string ("font",
276 P_("Font description as a string, e.g. \"Sans Italic 12\""),
278 GTK_PARAM_READWRITE));
280 g_object_class_install_property (object_class,
282 g_param_spec_boxed ("font-desc",
284 P_("Font description as a PangoFontDescription struct"),
285 PANGO_TYPE_FONT_DESCRIPTION,
286 GTK_PARAM_READWRITE));
289 g_object_class_install_property (object_class,
291 g_param_spec_string ("family",
293 P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
295 GTK_PARAM_READWRITE));
297 g_object_class_install_property (object_class,
299 g_param_spec_enum ("style",
304 GTK_PARAM_READWRITE));
306 g_object_class_install_property (object_class,
308 g_param_spec_enum ("variant",
312 PANGO_VARIANT_NORMAL,
313 GTK_PARAM_READWRITE));
315 g_object_class_install_property (object_class,
317 g_param_spec_int ("weight",
323 GTK_PARAM_READWRITE));
325 g_object_class_install_property (object_class,
327 g_param_spec_enum ("stretch",
331 PANGO_STRETCH_NORMAL,
332 GTK_PARAM_READWRITE));
334 g_object_class_install_property (object_class,
336 g_param_spec_int ("size",
342 GTK_PARAM_READWRITE));
344 g_object_class_install_property (object_class,
346 g_param_spec_double ("size-points",
348 P_("Font size in points"),
352 GTK_PARAM_READWRITE));
354 g_object_class_install_property (object_class,
356 g_param_spec_double ("scale",
358 P_("Font scaling factor"),
362 GTK_PARAM_READWRITE));
364 g_object_class_install_property (object_class,
366 g_param_spec_int ("rise",
368 P_("Offset of text above the baseline "
369 "(below the baseline if rise is negative)"),
373 GTK_PARAM_READWRITE));
376 g_object_class_install_property (object_class,
378 g_param_spec_boolean ("strikethrough",
380 P_("Whether to strike through the text"),
382 GTK_PARAM_READWRITE));
384 g_object_class_install_property (object_class,
386 g_param_spec_enum ("underline",
388 P_("Style of underline for this text"),
389 PANGO_TYPE_UNDERLINE,
390 PANGO_UNDERLINE_NONE,
391 GTK_PARAM_READWRITE));
393 g_object_class_install_property (object_class,
395 g_param_spec_string ("language",
397 P_("The language this text is in, as an ISO code. "
398 "Pango can use this as a hint when rendering the text. "
399 "If you don't understand this parameter, you probably don't need it"),
401 GTK_PARAM_READWRITE));
405 * GtkCellRendererText:ellipsize:
407 * Specifies the preferred place to ellipsize the string, if the cell renderer
408 * does not have enough room to display the entire string. Setting it to
409 * %PANGO_ELLIPSIZE_NONE turns off ellipsizing. See the wrap-width property
410 * for another way of making the text fit into a given width.
414 g_object_class_install_property (object_class,
416 g_param_spec_enum ("ellipsize",
418 P_("The preferred place to ellipsize the string, "
419 "if the cell renderer does not have enough room "
420 "to display the entire string"),
421 PANGO_TYPE_ELLIPSIZE_MODE,
422 PANGO_ELLIPSIZE_NONE,
423 GTK_PARAM_READWRITE));
426 * GtkCellRendererText:width-chars:
428 * The desired width of the cell, in characters. If this property is set to
429 * -1, the width will be calculated automatically, otherwise the cell will
430 * request either 3 characters or the property value, whichever is greater.
434 g_object_class_install_property (object_class,
436 g_param_spec_int ("width-chars",
437 P_("Width In Characters"),
438 P_("The desired width of the label, in characters"),
442 GTK_PARAM_READWRITE));
445 * GtkCellRendererText:wrap-mode:
447 * Specifies how to break the string into multiple lines, if the cell
448 * renderer does not have enough room to display the entire string.
449 * This property has no effect unless the wrap-width property is set.
453 g_object_class_install_property (object_class,
455 g_param_spec_enum ("wrap-mode",
457 P_("How to break the string into multiple lines, "
458 "if the cell renderer does not have enough room "
459 "to display the entire string"),
460 PANGO_TYPE_WRAP_MODE,
462 GTK_PARAM_READWRITE));
465 * GtkCellRendererText:wrap-width:
467 * Specifies the width at which the text is wrapped. The wrap-mode property can
468 * be used to influence at what character positions the line breaks can be placed.
469 * Setting wrap-width to -1 turns wrapping off.
473 g_object_class_install_property (object_class,
475 g_param_spec_int ("wrap-width",
477 P_("The width at which the text is wrapped"),
481 GTK_PARAM_READWRITE));
484 * GtkCellRendererText:alignment:
486 * Specifies how to align the lines of text with respect to each other.
488 * Note that this property describes how to align the lines of text in
489 * case there are several of them. The "xalign" property of #GtkCellRenderer,
490 * on the other hand, sets the horizontal alignment of the whole text.
494 g_object_class_install_property (object_class,
496 g_param_spec_enum ("alignment",
498 P_("How to align the lines"),
499 PANGO_TYPE_ALIGNMENT,
501 GTK_PARAM_READWRITE));
503 /* Style props are set or not */
505 #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))
507 ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
508 P_("Background set"),
509 P_("Whether this tag affects the background color"));
511 ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
512 P_("Foreground set"),
513 P_("Whether this tag affects the foreground color"));
515 ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
516 P_("Editability set"),
517 P_("Whether this tag affects text editability"));
519 ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
520 P_("Font family set"),
521 P_("Whether this tag affects the font family"));
523 ADD_SET_PROP ("style-set", PROP_STYLE_SET,
524 P_("Font style set"),
525 P_("Whether this tag affects the font style"));
527 ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
528 P_("Font variant set"),
529 P_("Whether this tag affects the font variant"));
531 ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
532 P_("Font weight set"),
533 P_("Whether this tag affects the font weight"));
535 ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
536 P_("Font stretch set"),
537 P_("Whether this tag affects the font stretch"));
539 ADD_SET_PROP ("size-set", PROP_SIZE_SET,
541 P_("Whether this tag affects the font size"));
543 ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
544 P_("Font scale set"),
545 P_("Whether this tag scales the font size by a factor"));
547 ADD_SET_PROP ("rise-set", PROP_RISE_SET,
549 P_("Whether this tag affects the rise"));
551 ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
552 P_("Strikethrough set"),
553 P_("Whether this tag affects strikethrough"));
555 ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
557 P_("Whether this tag affects underlining"));
559 ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
561 P_("Whether this tag affects the language the text is rendered as"));
563 ADD_SET_PROP ("ellipsize-set", PROP_ELLIPSIZE_SET,
565 P_("Whether this tag affects the ellipsize mode"));
567 ADD_SET_PROP ("align-set", PROP_ALIGN_SET,
569 P_("Whether this tag affects the alignment mode"));
572 * GtkCellRendererText::edited
573 * @renderer: the object which received the signal
574 * @path: the path identifying the edited cell
575 * @new_text: the new text
577 * This signal is emitted after @renderer has been edited.
579 * It is the responsibility of the application to update the model
580 * and store @new_text at the position indicated by @path.
582 text_cell_renderer_signals [EDITED] =
583 g_signal_new (I_("edited"),
584 G_OBJECT_CLASS_TYPE (object_class),
586 G_STRUCT_OFFSET (GtkCellRendererTextClass, edited),
588 _gtk_marshal_VOID__STRING_STRING,
593 g_type_class_add_private (object_class, sizeof (GtkCellRendererTextPrivate));
597 gtk_cell_renderer_text_finalize (GObject *object)
599 GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
600 GtkCellRendererTextPrivate *priv;
602 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (object);
604 pango_font_description_free (celltext->font);
606 g_free (celltext->text);
608 if (celltext->extra_attrs)
609 pango_attr_list_unref (celltext->extra_attrs);
612 g_object_unref (priv->language);
614 G_OBJECT_CLASS (gtk_cell_renderer_text_parent_class)->finalize (object);
618 get_property_font_set_mask (guint prop_id)
622 case PROP_FAMILY_SET:
623 return PANGO_FONT_MASK_FAMILY;
625 return PANGO_FONT_MASK_STYLE;
626 case PROP_VARIANT_SET:
627 return PANGO_FONT_MASK_VARIANT;
628 case PROP_WEIGHT_SET:
629 return PANGO_FONT_MASK_WEIGHT;
630 case PROP_STRETCH_SET:
631 return PANGO_FONT_MASK_STRETCH;
633 return PANGO_FONT_MASK_SIZE;
640 gtk_cell_renderer_text_get_property (GObject *object,
645 GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
646 GtkCellRendererTextPrivate *priv;
648 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (object);
653 g_value_set_string (value, celltext->text);
656 case PROP_ATTRIBUTES:
657 g_value_set_boxed (value, celltext->extra_attrs);
660 case PROP_SINGLE_PARAGRAPH_MODE:
661 g_value_set_boolean (value, priv->single_paragraph);
664 case PROP_BACKGROUND_GDK:
668 color.red = celltext->background.red;
669 color.green = celltext->background.green;
670 color.blue = celltext->background.blue;
672 g_value_set_boxed (value, &color);
676 case PROP_FOREGROUND_GDK:
680 color.red = celltext->foreground.red;
681 color.green = celltext->foreground.green;
682 color.blue = celltext->foreground.blue;
684 g_value_set_boxed (value, &color);
689 g_value_take_string (value, pango_font_description_to_string (celltext->font));
693 g_value_set_boxed (value, celltext->font);
697 g_value_set_string (value, pango_font_description_get_family (celltext->font));
701 g_value_set_enum (value, pango_font_description_get_style (celltext->font));
705 g_value_set_enum (value, pango_font_description_get_variant (celltext->font));
709 g_value_set_int (value, pango_font_description_get_weight (celltext->font));
713 g_value_set_enum (value, pango_font_description_get_stretch (celltext->font));
717 g_value_set_int (value, pango_font_description_get_size (celltext->font));
720 case PROP_SIZE_POINTS:
721 g_value_set_double (value, ((double)pango_font_description_get_size (celltext->font)) / (double)PANGO_SCALE);
725 g_value_set_double (value, celltext->font_scale);
729 g_value_set_boolean (value, celltext->editable);
732 case PROP_STRIKETHROUGH:
733 g_value_set_boolean (value, celltext->strikethrough);
737 g_value_set_enum (value, celltext->underline_style);
741 g_value_set_int (value, celltext->rise);
745 g_value_set_static_string (value, pango_language_to_string (priv->language));
749 g_value_set_enum (value, priv->ellipsize);
753 g_value_set_enum (value, priv->wrap_mode);
756 case PROP_WRAP_WIDTH:
757 g_value_set_int (value, priv->wrap_width);
761 g_value_set_enum (value, priv->align);
764 case PROP_BACKGROUND_SET:
765 g_value_set_boolean (value, celltext->background_set);
768 case PROP_FOREGROUND_SET:
769 g_value_set_boolean (value, celltext->foreground_set);
772 case PROP_FAMILY_SET:
774 case PROP_VARIANT_SET:
775 case PROP_WEIGHT_SET:
776 case PROP_STRETCH_SET:
779 PangoFontMask mask = get_property_font_set_mask (param_id);
780 g_value_set_boolean (value, (pango_font_description_get_set_fields (celltext->font) & mask) != 0);
786 g_value_set_boolean (value, celltext->scale_set);
789 case PROP_EDITABLE_SET:
790 g_value_set_boolean (value, celltext->editable_set);
793 case PROP_STRIKETHROUGH_SET:
794 g_value_set_boolean (value, celltext->strikethrough_set);
797 case PROP_UNDERLINE_SET:
798 g_value_set_boolean (value, celltext->underline_set);
802 g_value_set_boolean (value, celltext->rise_set);
805 case PROP_LANGUAGE_SET:
806 g_value_set_boolean (value, priv->language_set);
809 case PROP_ELLIPSIZE_SET:
810 g_value_set_boolean (value, priv->ellipsize_set);
814 g_value_set_boolean (value, priv->align_set);
817 case PROP_WIDTH_CHARS:
818 g_value_set_int (value, priv->width_chars);
821 case PROP_BACKGROUND:
822 case PROP_FOREGROUND:
825 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
832 set_bg_color (GtkCellRendererText *celltext,
837 if (!celltext->background_set)
839 celltext->background_set = TRUE;
840 g_object_notify (G_OBJECT (celltext), "background-set");
843 celltext->background.red = color->red;
844 celltext->background.green = color->green;
845 celltext->background.blue = color->blue;
849 if (celltext->background_set)
851 celltext->background_set = FALSE;
852 g_object_notify (G_OBJECT (celltext), "background-set");
859 set_fg_color (GtkCellRendererText *celltext,
864 if (!celltext->foreground_set)
866 celltext->foreground_set = TRUE;
867 g_object_notify (G_OBJECT (celltext), "foreground-set");
870 celltext->foreground.red = color->red;
871 celltext->foreground.green = color->green;
872 celltext->foreground.blue = color->blue;
876 if (celltext->foreground_set)
878 celltext->foreground_set = FALSE;
879 g_object_notify (G_OBJECT (celltext), "foreground-set");
885 set_font_desc_fields (PangoFontDescription *desc,
886 PangoFontMask to_set)
888 PangoFontMask changed_mask = 0;
890 if (to_set & PANGO_FONT_MASK_FAMILY)
892 const char *family = pango_font_description_get_family (desc);
896 changed_mask |= PANGO_FONT_MASK_FAMILY;
899 pango_font_description_set_family (desc, family);
901 if (to_set & PANGO_FONT_MASK_STYLE)
902 pango_font_description_set_style (desc, pango_font_description_get_style (desc));
903 if (to_set & PANGO_FONT_MASK_VARIANT)
904 pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
905 if (to_set & PANGO_FONT_MASK_WEIGHT)
906 pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
907 if (to_set & PANGO_FONT_MASK_STRETCH)
908 pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
909 if (to_set & PANGO_FONT_MASK_SIZE)
911 gint size = pango_font_description_get_size (desc);
914 size = 10 * PANGO_SCALE;
915 changed_mask |= PANGO_FONT_MASK_SIZE;
918 pango_font_description_set_size (desc, size);
925 notify_set_changed (GObject *object,
926 PangoFontMask changed_mask)
928 if (changed_mask & PANGO_FONT_MASK_FAMILY)
929 g_object_notify (object, "family-set");
930 if (changed_mask & PANGO_FONT_MASK_STYLE)
931 g_object_notify (object, "style-set");
932 if (changed_mask & PANGO_FONT_MASK_VARIANT)
933 g_object_notify (object, "variant-set");
934 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
935 g_object_notify (object, "weight-set");
936 if (changed_mask & PANGO_FONT_MASK_STRETCH)
937 g_object_notify (object, "stretch-set");
938 if (changed_mask & PANGO_FONT_MASK_SIZE)
939 g_object_notify (object, "size-set");
943 notify_fields_changed (GObject *object,
944 PangoFontMask changed_mask)
946 if (changed_mask & PANGO_FONT_MASK_FAMILY)
947 g_object_notify (object, "family");
948 if (changed_mask & PANGO_FONT_MASK_STYLE)
949 g_object_notify (object, "style");
950 if (changed_mask & PANGO_FONT_MASK_VARIANT)
951 g_object_notify (object, "variant");
952 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
953 g_object_notify (object, "weight");
954 if (changed_mask & PANGO_FONT_MASK_STRETCH)
955 g_object_notify (object, "stretch");
956 if (changed_mask & PANGO_FONT_MASK_SIZE)
957 g_object_notify (object, "size");
961 set_font_description (GtkCellRendererText *celltext,
962 PangoFontDescription *font_desc)
964 GObject *object = G_OBJECT (celltext);
965 PangoFontDescription *new_font_desc;
966 PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
969 new_font_desc = pango_font_description_copy (font_desc);
971 new_font_desc = pango_font_description_new ();
973 old_mask = pango_font_description_get_set_fields (celltext->font);
974 new_mask = pango_font_description_get_set_fields (new_font_desc);
976 changed_mask = old_mask | new_mask;
977 set_changed_mask = old_mask ^ new_mask;
979 pango_font_description_free (celltext->font);
980 celltext->font = new_font_desc;
982 g_object_freeze_notify (object);
984 g_object_notify (object, "font-desc");
985 g_object_notify (object, "font");
987 if (changed_mask & PANGO_FONT_MASK_FAMILY)
988 g_object_notify (object, "family");
989 if (changed_mask & PANGO_FONT_MASK_STYLE)
990 g_object_notify (object, "style");
991 if (changed_mask & PANGO_FONT_MASK_VARIANT)
992 g_object_notify (object, "variant");
993 if (changed_mask & PANGO_FONT_MASK_WEIGHT)
994 g_object_notify (object, "weight");
995 if (changed_mask & PANGO_FONT_MASK_STRETCH)
996 g_object_notify (object, "stretch");
997 if (changed_mask & PANGO_FONT_MASK_SIZE)
999 g_object_notify (object, "size");
1000 g_object_notify (object, "size-points");
1003 notify_set_changed (object, set_changed_mask);
1005 g_object_thaw_notify (object);
1009 gtk_cell_renderer_text_set_property (GObject *object,
1011 const GValue *value,
1014 GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
1015 GtkCellRendererTextPrivate *priv;
1017 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (object);
1022 g_free (celltext->text);
1024 if (priv->markup_set)
1026 if (celltext->extra_attrs)
1027 pango_attr_list_unref (celltext->extra_attrs);
1028 celltext->extra_attrs = NULL;
1029 priv->markup_set = FALSE;
1032 celltext->text = g_value_dup_string (value);
1033 g_object_notify (object, "text");
1036 case PROP_ATTRIBUTES:
1037 if (celltext->extra_attrs)
1038 pango_attr_list_unref (celltext->extra_attrs);
1040 celltext->extra_attrs = g_value_get_boxed (value);
1041 if (celltext->extra_attrs)
1042 pango_attr_list_ref (celltext->extra_attrs);
1048 GError *error = NULL;
1049 PangoAttrList *attrs = NULL;
1051 str = g_value_get_string (value);
1052 if (str && !pango_parse_markup (str,
1060 g_warning ("Failed to set text from markup due to error parsing markup: %s",
1062 g_error_free (error);
1066 g_free (celltext->text);
1068 if (celltext->extra_attrs)
1069 pango_attr_list_unref (celltext->extra_attrs);
1071 celltext->text = text;
1072 celltext->extra_attrs = attrs;
1073 priv->markup_set = TRUE;
1077 case PROP_SINGLE_PARAGRAPH_MODE:
1078 priv->single_paragraph = g_value_get_boolean (value);
1081 case PROP_BACKGROUND:
1085 if (!g_value_get_string (value))
1086 set_bg_color (celltext, NULL); /* reset to background_set to FALSE */
1087 else if (gdk_color_parse (g_value_get_string (value), &color))
1088 set_bg_color (celltext, &color);
1090 g_warning ("Don't know color `%s'", g_value_get_string (value));
1092 g_object_notify (object, "background-gdk");
1096 case PROP_FOREGROUND:
1100 if (!g_value_get_string (value))
1101 set_fg_color (celltext, NULL); /* reset to foreground_set to FALSE */
1102 else if (gdk_color_parse (g_value_get_string (value), &color))
1103 set_fg_color (celltext, &color);
1105 g_warning ("Don't know color `%s'", g_value_get_string (value));
1107 g_object_notify (object, "foreground-gdk");
1111 case PROP_BACKGROUND_GDK:
1112 /* This notifies the GObject itself. */
1113 set_bg_color (celltext, g_value_get_boxed (value));
1116 case PROP_FOREGROUND_GDK:
1117 /* This notifies the GObject itself. */
1118 set_fg_color (celltext, g_value_get_boxed (value));
1123 PangoFontDescription *font_desc = NULL;
1126 name = g_value_get_string (value);
1129 font_desc = pango_font_description_from_string (name);
1131 set_font_description (celltext, font_desc);
1133 pango_font_description_free (font_desc);
1135 if (celltext->fixed_height_rows != -1)
1136 celltext->calc_fixed_height = TRUE;
1140 case PROP_FONT_DESC:
1141 set_font_description (celltext, g_value_get_boxed (value));
1143 if (celltext->fixed_height_rows != -1)
1144 celltext->calc_fixed_height = TRUE;
1153 case PROP_SIZE_POINTS:
1155 PangoFontMask old_set_mask = pango_font_description_get_set_fields (celltext->font);
1160 pango_font_description_set_family (celltext->font,
1161 g_value_get_string (value));
1164 pango_font_description_set_style (celltext->font,
1165 g_value_get_enum (value));
1168 pango_font_description_set_variant (celltext->font,
1169 g_value_get_enum (value));
1172 pango_font_description_set_weight (celltext->font,
1173 g_value_get_int (value));
1176 pango_font_description_set_stretch (celltext->font,
1177 g_value_get_enum (value));
1180 pango_font_description_set_size (celltext->font,
1181 g_value_get_int (value));
1182 g_object_notify (object, "size-points");
1184 case PROP_SIZE_POINTS:
1185 pango_font_description_set_size (celltext->font,
1186 g_value_get_double (value) * PANGO_SCALE);
1187 g_object_notify (object, "size");
1191 if (celltext->fixed_height_rows != -1)
1192 celltext->calc_fixed_height = TRUE;
1194 notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (celltext->font));
1195 g_object_notify (object, "font-desc");
1196 g_object_notify (object, "font");
1202 celltext->font_scale = g_value_get_double (value);
1203 celltext->scale_set = TRUE;
1204 if (celltext->fixed_height_rows != -1)
1205 celltext->calc_fixed_height = TRUE;
1206 g_object_notify (object, "scale-set");
1210 celltext->editable = g_value_get_boolean (value);
1211 celltext->editable_set = TRUE;
1212 if (celltext->editable)
1213 GTK_CELL_RENDERER (celltext)->mode = GTK_CELL_RENDERER_MODE_EDITABLE;
1215 GTK_CELL_RENDERER (celltext)->mode = GTK_CELL_RENDERER_MODE_INERT;
1216 g_object_notify (object, "editable-set");
1219 case PROP_STRIKETHROUGH:
1220 celltext->strikethrough = g_value_get_boolean (value);
1221 celltext->strikethrough_set = TRUE;
1222 g_object_notify (object, "strikethrough-set");
1225 case PROP_UNDERLINE:
1226 celltext->underline_style = g_value_get_enum (value);
1227 celltext->underline_set = TRUE;
1228 g_object_notify (object, "underline-set");
1233 celltext->rise = g_value_get_int (value);
1234 celltext->rise_set = TRUE;
1235 g_object_notify (object, "rise-set");
1236 if (celltext->fixed_height_rows != -1)
1237 celltext->calc_fixed_height = TRUE;
1241 priv->language_set = TRUE;
1243 g_object_unref (priv->language);
1244 priv->language = pango_language_from_string (g_value_get_string (value));
1245 g_object_notify (object, "language-set");
1248 case PROP_ELLIPSIZE:
1249 priv->ellipsize = g_value_get_enum (value);
1250 priv->ellipsize_set = TRUE;
1251 g_object_notify (object, "ellipsize-set");
1254 case PROP_WRAP_MODE:
1255 priv->wrap_mode = g_value_get_enum (value);
1258 case PROP_WRAP_WIDTH:
1259 priv->wrap_width = g_value_get_int (value);
1262 case PROP_WIDTH_CHARS:
1263 priv->width_chars = g_value_get_int (value);
1267 priv->align = g_value_get_enum (value);
1268 priv->align_set = TRUE;
1269 g_object_notify (object, "align-set");
1272 case PROP_BACKGROUND_SET:
1273 celltext->background_set = g_value_get_boolean (value);
1276 case PROP_FOREGROUND_SET:
1277 celltext->foreground_set = g_value_get_boolean (value);
1280 case PROP_FAMILY_SET:
1281 case PROP_STYLE_SET:
1282 case PROP_VARIANT_SET:
1283 case PROP_WEIGHT_SET:
1284 case PROP_STRETCH_SET:
1286 if (!g_value_get_boolean (value))
1288 pango_font_description_unset_fields (celltext->font,
1289 get_property_font_set_mask (param_id));
1293 PangoFontMask changed_mask;
1295 changed_mask = set_font_desc_fields (celltext->font,
1296 get_property_font_set_mask (param_id));
1297 notify_fields_changed (G_OBJECT (celltext), changed_mask);
1301 case PROP_SCALE_SET:
1302 celltext->scale_set = g_value_get_boolean (value);
1305 case PROP_EDITABLE_SET:
1306 celltext->editable_set = g_value_get_boolean (value);
1309 case PROP_STRIKETHROUGH_SET:
1310 celltext->strikethrough_set = g_value_get_boolean (value);
1313 case PROP_UNDERLINE_SET:
1314 celltext->underline_set = g_value_get_boolean (value);
1318 celltext->rise_set = g_value_get_boolean (value);
1321 case PROP_LANGUAGE_SET:
1322 priv->language_set = g_value_get_boolean (value);
1325 case PROP_ELLIPSIZE_SET:
1326 priv->ellipsize_set = g_value_get_boolean (value);
1329 case PROP_ALIGN_SET:
1330 priv->align_set = g_value_get_boolean (value);
1334 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
1340 * gtk_cell_renderer_text_new:
1342 * Creates a new #GtkCellRendererText. Adjust how text is drawn using
1343 * object properties. Object properties can be
1344 * set globally (with g_object_set()). Also, with #GtkTreeViewColumn,
1345 * you can bind a property to a value in a #GtkTreeModel. For example,
1346 * you can bind the "text" property on the cell renderer to a string
1347 * value in the model, thus rendering a different string in each row
1348 * of the #GtkTreeView
1350 * Return value: the new cell renderer
1353 gtk_cell_renderer_text_new (void)
1355 return g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, NULL);
1359 add_attr (PangoAttrList *attr_list,
1360 PangoAttribute *attr)
1362 attr->start_index = 0;
1363 attr->end_index = G_MAXINT;
1365 pango_attr_list_insert (attr_list, attr);
1369 get_layout (GtkCellRendererText *celltext,
1371 gboolean will_render,
1372 GtkCellRendererState flags)
1374 PangoAttrList *attr_list;
1375 PangoLayout *layout;
1376 PangoUnderline uline;
1377 GtkCellRendererTextPrivate *priv;
1379 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (celltext);
1381 layout = gtk_widget_create_pango_layout (widget, celltext->text);
1383 if (celltext->extra_attrs)
1384 attr_list = pango_attr_list_copy (celltext->extra_attrs);
1386 attr_list = pango_attr_list_new ();
1388 pango_layout_set_single_paragraph_mode (layout, priv->single_paragraph);
1392 /* Add options that affect appearance but not size */
1394 /* note that background doesn't go here, since it affects
1395 * background_area not the PangoLayout area
1398 if (celltext->foreground_set
1399 && (flags & GTK_CELL_RENDERER_SELECTED) == 0)
1403 color = celltext->foreground;
1405 add_attr (attr_list,
1406 pango_attr_foreground_new (color.red, color.green, color.blue));
1409 if (celltext->strikethrough_set)
1410 add_attr (attr_list,
1411 pango_attr_strikethrough_new (celltext->strikethrough));
1414 add_attr (attr_list, pango_attr_font_desc_new (celltext->font));
1416 if (celltext->scale_set &&
1417 celltext->font_scale != 1.0)
1418 add_attr (attr_list, pango_attr_scale_new (celltext->font_scale));
1420 if (celltext->underline_set)
1421 uline = celltext->underline_style;
1423 uline = PANGO_UNDERLINE_NONE;
1425 if (priv->language_set)
1426 add_attr (attr_list, pango_attr_language_new (priv->language));
1428 if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT)
1432 case PANGO_UNDERLINE_NONE:
1433 uline = PANGO_UNDERLINE_SINGLE;
1436 case PANGO_UNDERLINE_SINGLE:
1437 uline = PANGO_UNDERLINE_DOUBLE;
1445 if (uline != PANGO_UNDERLINE_NONE)
1446 add_attr (attr_list, pango_attr_underline_new (celltext->underline_style));
1448 if (celltext->rise_set)
1449 add_attr (attr_list, pango_attr_rise_new (celltext->rise));
1451 if (priv->ellipsize_set)
1452 pango_layout_set_ellipsize (layout, priv->ellipsize);
1454 pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_NONE);
1456 if (priv->wrap_width != -1)
1458 pango_layout_set_width (layout, priv->wrap_width * PANGO_SCALE);
1459 pango_layout_set_wrap (layout, priv->wrap_mode);
1463 pango_layout_set_width (layout, -1);
1464 pango_layout_set_wrap (layout, PANGO_WRAP_CHAR);
1467 if (priv->align_set)
1468 pango_layout_set_alignment (layout, priv->align);
1471 PangoAlignment align;
1473 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1474 align = PANGO_ALIGN_RIGHT;
1476 align = PANGO_ALIGN_LEFT;
1478 pango_layout_set_alignment (layout, align);
1481 pango_layout_set_attributes (layout, attr_list);
1483 pango_attr_list_unref (attr_list);
1489 get_size (GtkCellRenderer *cell,
1491 GdkRectangle *cell_area,
1492 PangoLayout *layout,
1498 GtkCellRendererText *celltext = (GtkCellRendererText *) cell;
1499 PangoRectangle rect;
1500 GtkCellRendererTextPrivate *priv;
1502 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
1503 priv->owner = widget;
1505 if (celltext->calc_fixed_height)
1507 PangoContext *context;
1508 PangoFontMetrics *metrics;
1509 PangoFontDescription *font_desc;
1512 font_desc = pango_font_description_copy_static (widget->style->font_desc);
1513 pango_font_description_merge_static (font_desc, celltext->font, TRUE);
1515 if (celltext->scale_set)
1516 pango_font_description_set_size (font_desc,
1517 celltext->font_scale * pango_font_description_get_size (font_desc));
1519 context = gtk_widget_get_pango_context (widget);
1521 metrics = pango_context_get_metrics (context,
1523 pango_context_get_language (context));
1524 row_height = (pango_font_metrics_get_ascent (metrics) +
1525 pango_font_metrics_get_descent (metrics));
1526 pango_font_metrics_unref (metrics);
1528 pango_font_description_free (font_desc);
1530 gtk_cell_renderer_set_fixed_size (cell,
1531 cell->width, 2*cell->ypad +
1532 celltext->fixed_height_rows * PANGO_PIXELS (row_height));
1536 *height = cell->height;
1539 celltext->calc_fixed_height = FALSE;
1545 g_object_ref (layout);
1547 layout = get_layout (celltext, widget, FALSE, 0);
1549 pango_layout_get_pixel_extents (layout, NULL, &rect);
1552 *height = cell->ypad * 2 + rect.height;
1554 /* The minimum size for ellipsized labels is ~ 3 chars */
1557 if (priv->ellipsize || priv->width_chars > 0)
1559 PangoContext *context;
1560 PangoFontMetrics *metrics;
1563 context = pango_layout_get_context (layout);
1564 metrics = pango_context_get_metrics (context, widget->style->font_desc, pango_context_get_language (context));
1566 char_width = pango_font_metrics_get_approximate_char_width (metrics);
1567 pango_font_metrics_unref (metrics);
1569 *width = cell->xpad * 2 + (PANGO_PIXELS (char_width) * MAX (priv->width_chars, 3));
1573 *width = cell->xpad * 2 + rect.x + rect.width;
1581 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
1582 *x_offset = (1.0 - cell->xalign) * (cell_area->width - (rect.x + rect.width + (2 * cell->xpad)));
1584 *x_offset = cell->xalign * (cell_area->width - (rect.x + rect.width + (2 * cell->xpad)));
1586 if ((priv->ellipsize_set && priv->ellipsize != PANGO_ELLIPSIZE_NONE) || priv->wrap_width != -1)
1587 *x_offset = MAX(*x_offset, 0);
1591 *y_offset = cell->yalign * (cell_area->height - (rect.height + (2 * cell->ypad)));
1592 *y_offset = MAX (*y_offset, 0);
1597 if (x_offset) *x_offset = 0;
1598 if (y_offset) *y_offset = 0;
1601 g_object_unref (layout);
1606 gtk_cell_renderer_text_get_size (GtkCellRenderer *cell,
1608 GdkRectangle *cell_area,
1614 get_size (cell, widget, cell_area, NULL,
1615 x_offset, y_offset, width, height);
1619 gtk_cell_renderer_text_render (GtkCellRenderer *cell,
1620 GdkDrawable *window,
1622 GdkRectangle *background_area,
1623 GdkRectangle *cell_area,
1624 GdkRectangle *expose_area,
1625 GtkCellRendererState flags)
1628 GtkCellRendererText *celltext = (GtkCellRendererText *) cell;
1629 PangoLayout *layout;
1633 GtkCellRendererTextPrivate *priv;
1635 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
1637 layout = get_layout (celltext, widget, TRUE, flags);
1638 get_size (cell, widget, cell_area, layout, &x_offset, &y_offset, NULL, NULL);
1640 if (!cell->sensitive)
1642 state = GTK_STATE_INSENSITIVE;
1644 else if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
1646 if (GTK_WIDGET_HAS_FOCUS (widget))
1647 state = GTK_STATE_SELECTED;
1649 state = GTK_STATE_ACTIVE;
1651 else if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT &&
1652 GTK_WIDGET_STATE (widget) == GTK_STATE_PRELIGHT)
1654 state = GTK_STATE_PRELIGHT;
1658 if (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE)
1659 state = GTK_STATE_INSENSITIVE;
1661 state = GTK_STATE_NORMAL;
1664 if (celltext->background_set &&
1665 (flags & GTK_CELL_RENDERER_SELECTED) == 0)
1667 cairo_t *cr = gdk_cairo_create (window);
1671 gdk_cairo_rectangle (cr, expose_area);
1675 gdk_cairo_rectangle (cr, background_area);
1676 cairo_set_source_rgb (cr,
1677 celltext->background.red / 65535.,
1678 celltext->background.green / 65535.,
1679 celltext->background.blue / 65535.);
1685 if (priv->ellipsize_set && priv->ellipsize != PANGO_ELLIPSIZE_NONE)
1686 pango_layout_set_width (layout,
1687 (cell_area->width - x_offset - 2 * cell->xpad) * PANGO_SCALE);
1688 else if (priv->wrap_width == -1)
1689 pango_layout_set_width (layout, -1);
1691 gtk_paint_layout (widget->style,
1698 cell_area->x + x_offset + cell->xpad,
1699 cell_area->y + y_offset + cell->ypad,
1702 g_object_unref (layout);
1706 gtk_cell_renderer_text_editing_done (GtkCellEditable *entry,
1710 const gchar *new_text;
1712 GtkCellRendererTextPrivate *priv;
1714 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1718 if (priv->focus_out_id > 0)
1720 g_signal_handler_disconnect (entry, priv->focus_out_id);
1721 priv->focus_out_id = 0;
1724 if (priv->populate_popup_id > 0)
1726 g_signal_handler_disconnect (entry, priv->populate_popup_id);
1727 priv->populate_popup_id = 0;
1730 if (priv->entry_menu_popdown_timeout)
1732 g_source_remove (priv->entry_menu_popdown_timeout);
1733 priv->entry_menu_popdown_timeout = 0;
1736 g_object_get (entry,
1737 "editing-canceled", &canceled,
1739 gtk_cell_renderer_stop_editing (GTK_CELL_RENDERER (data), canceled);
1744 path = g_object_get_data (G_OBJECT (entry), GTK_CELL_RENDERER_TEXT_PATH);
1745 new_text = gtk_entry_get_text (GTK_ENTRY (entry));
1747 g_signal_emit (data, text_cell_renderer_signals[EDITED], 0, path, new_text);
1751 popdown_timeout (gpointer data)
1753 GtkCellRendererTextPrivate *priv;
1755 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1757 priv->entry_menu_popdown_timeout = 0;
1759 if (!GTK_WIDGET_HAS_FOCUS (priv->entry))
1760 gtk_cell_renderer_text_editing_done (GTK_CELL_EDITABLE (priv->entry), data);
1766 gtk_cell_renderer_text_popup_unmap (GtkMenu *menu,
1769 GtkCellRendererTextPrivate *priv;
1771 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1773 priv->in_entry_menu = FALSE;
1775 if (priv->entry_menu_popdown_timeout)
1778 priv->entry_menu_popdown_timeout = gdk_threads_add_timeout (500, popdown_timeout,
1783 gtk_cell_renderer_text_populate_popup (GtkEntry *entry,
1787 GtkCellRendererTextPrivate *priv;
1789 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1791 if (priv->entry_menu_popdown_timeout)
1793 g_source_remove (priv->entry_menu_popdown_timeout);
1794 priv->entry_menu_popdown_timeout = 0;
1797 priv->in_entry_menu = TRUE;
1799 g_signal_connect (menu, "unmap",
1800 G_CALLBACK (gtk_cell_renderer_text_popup_unmap), data);
1804 gtk_cell_renderer_text_focus_out_event (GtkWidget *entry,
1808 GtkCellRendererTextPrivate *priv;
1810 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
1812 if (priv->in_entry_menu)
1815 g_object_set (entry,
1816 "editing-canceled", TRUE,
1818 gtk_cell_editable_editing_done (GTK_CELL_EDITABLE (entry));
1819 gtk_cell_editable_remove_widget (GTK_CELL_EDITABLE (entry));
1821 /* entry needs focus-out-event */
1825 static GtkCellEditable *
1826 gtk_cell_renderer_text_start_editing (GtkCellRenderer *cell,
1830 GdkRectangle *background_area,
1831 GdkRectangle *cell_area,
1832 GtkCellRendererState flags)
1834 GtkRequisition requisition;
1835 GtkCellRendererText *celltext;
1836 GtkCellRendererTextPrivate *priv;
1838 celltext = GTK_CELL_RENDERER_TEXT (cell);
1839 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
1841 /* If the cell isn't editable we return NULL. */
1842 if (celltext->editable == FALSE)
1845 priv->entry = g_object_new (GTK_TYPE_ENTRY,
1847 "xalign", cell->xalign,
1851 gtk_entry_set_text (GTK_ENTRY (priv->entry), celltext->text);
1852 g_object_set_data_full (G_OBJECT (priv->entry), I_(GTK_CELL_RENDERER_TEXT_PATH), g_strdup (path), g_free);
1854 gtk_editable_select_region (GTK_EDITABLE (priv->entry), 0, -1);
1856 gtk_widget_size_request (priv->entry, &requisition);
1857 if (requisition.height < cell_area->height)
1859 GtkBorder *style_border;
1862 gtk_widget_style_get (priv->entry,
1863 "inner-border", &style_border,
1868 border = *style_border;
1869 g_boxed_free (GTK_TYPE_BORDER, style_border);
1873 /* Since boxed style properties can't have default values ... */
1878 border.top = (cell_area->height - requisition.height) / 2;
1879 border.bottom = (cell_area->height - requisition.height) / 2;
1880 gtk_entry_set_inner_border (GTK_ENTRY (priv->entry), &border);
1883 priv->in_entry_menu = FALSE;
1884 if (priv->entry_menu_popdown_timeout)
1886 g_source_remove (priv->entry_menu_popdown_timeout);
1887 priv->entry_menu_popdown_timeout = 0;
1890 g_signal_connect (priv->entry,
1892 G_CALLBACK (gtk_cell_renderer_text_editing_done),
1894 priv->focus_out_id = g_signal_connect_after (priv->entry, "focus-out-event",
1895 G_CALLBACK (gtk_cell_renderer_text_focus_out_event),
1897 priv->populate_popup_id =
1898 g_signal_connect (priv->entry, "populate-popup",
1899 G_CALLBACK (gtk_cell_renderer_text_populate_popup),
1902 gtk_widget_show (priv->entry);
1904 return GTK_CELL_EDITABLE (priv->entry);
1908 * gtk_cell_renderer_text_set_fixed_height_from_font:
1909 * @renderer: A #GtkCellRendererText
1910 * @number_of_rows: Number of rows of text each cell renderer is allocated, or -1
1912 * Sets the height of a renderer to explicitly be determined by the "font" and
1913 * "y_pad" property set on it. Further changes in these properties do not
1914 * affect the height, so they must be accompanied by a subsequent call to this
1915 * function. Using this function is unflexible, and should really only be used
1916 * if calculating the size of a cell is too slow (ie, a massive number of cells
1917 * displayed). If @number_of_rows is -1, then the fixed height is unset, and
1918 * the height is determined by the properties again.
1921 gtk_cell_renderer_text_set_fixed_height_from_font (GtkCellRendererText *renderer,
1922 gint number_of_rows)
1924 g_return_if_fail (GTK_IS_CELL_RENDERER_TEXT (renderer));
1925 g_return_if_fail (number_of_rows == -1 || number_of_rows > 0);
1927 if (number_of_rows == -1)
1929 gtk_cell_renderer_set_fixed_size (GTK_CELL_RENDERER (renderer),
1930 GTK_CELL_RENDERER (renderer)->width,
1935 renderer->fixed_height_rows = number_of_rows;
1936 renderer->calc_fixed_height = TRUE;
1941 gtk_cell_renderer_text_extended_layout_get_desired_size (GtkExtendedLayout *layout,
1942 GtkRequisition *minimal_size,
1943 GtkRequisition *desired_size)
1945 GtkCellRendererTextPrivate *priv;
1947 priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (layout);
1951 get_size (GTK_CELL_RENDERER (layout),
1952 priv->owner, NULL, NULL, NULL, NULL,
1953 &minimal_size->width, &minimal_size->height);
1958 PangoEllipsizeMode ellipsize;
1960 ellipsize = priv->ellipsize;
1961 priv->ellipsize = PANGO_ELLIPSIZE_NONE;
1963 get_size (GTK_CELL_RENDERER (layout),
1964 priv->owner, NULL, NULL, NULL, NULL,
1965 &desired_size->width, &desired_size->height);
1967 priv->ellipsize = ellipsize;
1972 gtk_cell_renderer_text_extended_layout_init (GtkExtendedLayoutIface *iface)
1974 iface->get_desired_size = gtk_cell_renderer_text_extended_layout_get_desired_size;
1977 #define __GTK_CELL_RENDERER_TEXT_C__
1978 #include "gtkaliasdef.c"