* Boston, MA 02111-1307, USA.
*/
+#include <config.h>
#include <stdlib.h>
#include "gtkcellrenderertext.h"
#include "gtkeditable.h"
#include "gtkentry.h"
#include "gtkmarshalers.h"
#include "gtkintl.h"
+#include "gtkprivate.h"
#include "gtktreeprivate.h"
+#include "gtkalias.h"
static void gtk_cell_renderer_text_init (GtkCellRendererText *celltext);
static void gtk_cell_renderer_text_class_init (GtkCellRendererTextClass *class);
PROP_MARKUP,
PROP_ATTRIBUTES,
PROP_SINGLE_PARAGRAPH_MODE,
+ PROP_WIDTH_CHARS,
+ PROP_WRAP_WIDTH,
/* Style args */
PROP_BACKGROUND,
PROP_UNDERLINE,
PROP_RISE,
PROP_LANGUAGE,
+ PROP_ELLIPSIZE,
+ PROP_WRAP_MODE,
/* Whether-a-style-arg-is-set args */
PROP_BACKGROUND_SET,
PROP_STRIKETHROUGH_SET,
PROP_UNDERLINE_SET,
PROP_RISE_SET,
- PROP_LANGUAGE_SET
+ PROP_LANGUAGE_SET,
+ PROP_ELLIPSIZE_SET
};
static gpointer parent_class;
guint single_paragraph : 1;
guint language_set : 1;
guint markup_set : 1;
-
+ guint ellipsize_set : 1;
+
gulong focus_out_id;
PangoLanguage *language;
+ PangoEllipsizeMode ellipsize;
+ PangoWrapMode wrap_mode;
+
+ gulong populate_popup_id;
+ gulong entry_menu_popdown_timeout;
+ gboolean in_entry_menu;
+
+ gint width_chars;
+ gint wrap_width;
+
+ GtkWidget *entry;
};
static void
gtk_cell_renderer_text_init (GtkCellRendererText *celltext)
{
+ GtkCellRendererTextPrivate *priv;
+
+ priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (celltext);
+
GTK_CELL_RENDERER (celltext)->xalign = 0.0;
GTK_CELL_RENDERER (celltext)->yalign = 0.5;
GTK_CELL_RENDERER (celltext)->xpad = 2;
GTK_CELL_RENDERER (celltext)->ypad = 2;
celltext->fixed_height_rows = -1;
celltext->font = pango_font_description_new ();
+
+ priv->width_chars = -1;
+ priv->wrap_width = -1;
}
static void
cell_class->get_size = gtk_cell_renderer_text_get_size;
cell_class->render = gtk_cell_renderer_text_render;
cell_class->start_editing = gtk_cell_renderer_text_start_editing;
-
+
g_object_class_install_property (object_class,
PROP_TEXT,
g_param_spec_string ("text",
- _("Text"),
- _("Text to render"),
+ P_("Text"),
+ P_("Text to render"),
NULL,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_MARKUP,
g_param_spec_string ("markup",
- _("Markup"),
- _("Marked up text to render"),
+ P_("Markup"),
+ P_("Marked up text to render"),
NULL,
- G_PARAM_WRITABLE));
+ GTK_PARAM_WRITABLE));
g_object_class_install_property (object_class,
PROP_ATTRIBUTES,
g_param_spec_boxed ("attributes",
- _("Attributes"),
- _("A list of style attributes to apply to the text of the renderer"),
+ P_("Attributes"),
+ P_("A list of style attributes to apply to the text of the renderer"),
PANGO_TYPE_ATTR_LIST,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_SINGLE_PARAGRAPH_MODE,
- g_param_spec_boolean ("single_paragraph_mode",
- _("Single Paragraph Mode"),
- _("Whether or not to keep all text in a single paragraph"),
+ g_param_spec_boolean ("single-paragraph-mode",
+ P_("Single Paragraph Mode"),
+ P_("Whether or not to keep all text in a single paragraph"),
FALSE,
- G_PARAM_READWRITE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_BACKGROUND,
g_param_spec_string ("background",
- _("Background color name"),
- _("Background color as a string"),
+ P_("Background color name"),
+ P_("Background color as a string"),
NULL,
- G_PARAM_WRITABLE));
+ GTK_PARAM_WRITABLE));
g_object_class_install_property (object_class,
PROP_BACKGROUND_GDK,
- g_param_spec_boxed ("background_gdk",
- _("Background color"),
- _("Background color as a GdkColor"),
+ g_param_spec_boxed ("background-gdk",
+ P_("Background color"),
+ P_("Background color as a GdkColor"),
GDK_TYPE_COLOR,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_FOREGROUND,
g_param_spec_string ("foreground",
- _("Foreground color name"),
- _("Foreground color as a string"),
+ P_("Foreground color name"),
+ P_("Foreground color as a string"),
NULL,
- G_PARAM_WRITABLE));
+ GTK_PARAM_WRITABLE));
g_object_class_install_property (object_class,
PROP_FOREGROUND_GDK,
- g_param_spec_boxed ("foreground_gdk",
- _("Foreground color"),
- _("Foreground color as a GdkColor"),
+ g_param_spec_boxed ("foreground-gdk",
+ P_("Foreground color"),
+ P_("Foreground color as a GdkColor"),
GDK_TYPE_COLOR,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_EDITABLE,
g_param_spec_boolean ("editable",
- _("Editable"),
- _("Whether the text can be modified by the user"),
+ P_("Editable"),
+ P_("Whether the text can be modified by the user"),
FALSE,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_FONT,
g_param_spec_string ("font",
- _("Font"),
- _("Font description as a string"),
+ P_("Font"),
+ P_("Font description as a string"),
NULL,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_FONT_DESC,
- g_param_spec_boxed ("font_desc",
- _("Font"),
- _("Font description as a PangoFontDescription struct"),
+ g_param_spec_boxed ("font-desc",
+ P_("Font"),
+ P_("Font description as a PangoFontDescription struct"),
PANGO_TYPE_FONT_DESCRIPTION,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_FAMILY,
g_param_spec_string ("family",
- _("Font family"),
- _("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
+ P_("Font family"),
+ P_("Name of the font family, e.g. Sans, Helvetica, Times, Monospace"),
NULL,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_STYLE,
g_param_spec_enum ("style",
- _("Font style"),
- _("Font style"),
+ P_("Font style"),
+ P_("Font style"),
PANGO_TYPE_STYLE,
PANGO_STYLE_NORMAL,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_VARIANT,
g_param_spec_enum ("variant",
- _("Font variant"),
- _("Font variant"),
+ P_("Font variant"),
+ P_("Font variant"),
PANGO_TYPE_VARIANT,
PANGO_VARIANT_NORMAL,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_WEIGHT,
g_param_spec_int ("weight",
- _("Font weight"),
- _("Font weight"),
+ P_("Font weight"),
+ P_("Font weight"),
0,
G_MAXINT,
PANGO_WEIGHT_NORMAL,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_STRETCH,
g_param_spec_enum ("stretch",
- _("Font stretch"),
- _("Font stretch"),
+ P_("Font stretch"),
+ P_("Font stretch"),
PANGO_TYPE_STRETCH,
PANGO_STRETCH_NORMAL,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_SIZE,
g_param_spec_int ("size",
- _("Font size"),
- _("Font size"),
+ P_("Font size"),
+ P_("Font size"),
0,
G_MAXINT,
0,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_SIZE_POINTS,
- g_param_spec_double ("size_points",
- _("Font points"),
- _("Font size in points"),
+ g_param_spec_double ("size-points",
+ P_("Font points"),
+ P_("Font size in points"),
0.0,
G_MAXDOUBLE,
0.0,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_SCALE,
g_param_spec_double ("scale",
- _("Font scale"),
- _("Font scaling factor"),
+ P_("Font scale"),
+ P_("Font scaling factor"),
0.0,
G_MAXDOUBLE,
1.0,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_RISE,
g_param_spec_int ("rise",
- _("Rise"),
- _("Offset of text above the baseline (below the baseline if rise is negative)"),
+ P_("Rise"),
+ P_("Offset of text above the baseline "
+ "(below the baseline if rise is negative)"),
-G_MAXINT,
G_MAXINT,
0,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_STRIKETHROUGH,
g_param_spec_boolean ("strikethrough",
- _("Strikethrough"),
- _("Whether to strike through the text"),
+ P_("Strikethrough"),
+ P_("Whether to strike through the text"),
FALSE,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_UNDERLINE,
g_param_spec_enum ("underline",
- _("Underline"),
- _("Style of underline for this text"),
+ P_("Underline"),
+ P_("Style of underline for this text"),
PANGO_TYPE_UNDERLINE,
PANGO_UNDERLINE_NONE,
- G_PARAM_READABLE | G_PARAM_WRITABLE));
+ GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_LANGUAGE,
g_param_spec_string ("language",
- _("Language"),
- _("The language this text is in, as an ISO code. Pango can use this as a hint when rendering the text. If you don't understand this parameter, you probably don't need it"),
+ P_("Language"),
+ P_("The language this text is in, as an ISO code. "
+ "Pango can use this as a hint when rendering the text. "
+ "If you don't understand this parameter, you probably don't need it"),
NULL,
- G_PARAM_READWRITE));
-
+ GTK_PARAM_READWRITE));
+
+
+ /**
+ * GtkCellRendererText:ellipsize:
+ *
+ * Specifies the preferred place to ellipsize the string, if the cell renderer
+ * does not have enough room to display the entire string. Setting it to
+ * %PANGO_ELLIPSIZE_NONE turns off ellipsizing. See the wrap-width property
+ * for another way of making the text fit into a given width.
+ *
+ * Since: 2.6
+ */
+ g_object_class_install_property (object_class,
+ PROP_ELLIPSIZE,
+ g_param_spec_enum ("ellipsize",
+ P_("Ellipsize"),
+ P_("The preferred place to ellipsize the string, "
+ "if the cell renderer does not have enough room "
+ "to display the entire string, if at all"),
+ PANGO_TYPE_ELLIPSIZE_MODE,
+ PANGO_ELLIPSIZE_NONE,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkCellRendererText:width-chars:
+ *
+ * The desired width of the cell, in characters. If this property is set to
+ * -1, the width will be calculated automatically, otherwise the cell will
+ * request either 3 characters or the property value, whichever is greater.
+ *
+ * Since: 2.6
+ **/
+ g_object_class_install_property (object_class,
+ PROP_WIDTH_CHARS,
+ g_param_spec_int ("width-chars",
+ P_("Width In Characters"),
+ P_("The desired width of the label, in characters"),
+ -1,
+ G_MAXINT,
+ -1,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkCellRendererText:wrap-mode:
+ *
+ * Specifies how to break the string into multiple lines, if the cell
+ * renderer does not have enough room to display the entire string.
+ * This property has no effect unless the wrap-width property is set.
+ *
+ * Since: 2.8
+ */
+ g_object_class_install_property (object_class,
+ PROP_WRAP_MODE,
+ g_param_spec_enum ("wrap-mode",
+ P_("Wrap mode"),
+ P_("How to break the string into multiple lines, "
+ "if the cell renderer does not have enough room "
+ "to display the entire string"),
+ PANGO_TYPE_WRAP_MODE,
+ PANGO_WRAP_CHAR,
+ GTK_PARAM_READWRITE));
+
+ /**
+ * GtkCellRendererText:wrap-width:
+ *
+ * Specifies the width at which the text is wrapped. The wrap-mode property can
+ * be used to influence at what character positions the line breaks can be placed.
+ * Setting wrap-width to -1 turns wrapping off.
+ *
+ * Since: 2.8
+ */
+ g_object_class_install_property (object_class,
+ PROP_WRAP_WIDTH,
+ g_param_spec_int ("wrap-width",
+ P_("Wrap width"),
+ P_("The width at which the text is wrapped"),
+ -1,
+ G_MAXINT,
+ -1,
+ GTK_PARAM_READWRITE));
+
/* Style props are set or not */
-#define ADD_SET_PROP(propname, propval, nick, blurb) g_object_class_install_property (object_class, propval, g_param_spec_boolean (propname, nick, blurb, FALSE, G_PARAM_READABLE | G_PARAM_WRITABLE))
+#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))
- ADD_SET_PROP ("background_set", PROP_BACKGROUND_SET,
- _("Background set"),
- _("Whether this tag affects the background color"));
+ ADD_SET_PROP ("background-set", PROP_BACKGROUND_SET,
+ P_("Background set"),
+ P_("Whether this tag affects the background color"));
- ADD_SET_PROP ("foreground_set", PROP_FOREGROUND_SET,
- _("Foreground set"),
- _("Whether this tag affects the foreground color"));
+ ADD_SET_PROP ("foreground-set", PROP_FOREGROUND_SET,
+ P_("Foreground set"),
+ P_("Whether this tag affects the foreground color"));
- ADD_SET_PROP ("editable_set", PROP_EDITABLE_SET,
- _("Editability set"),
- _("Whether this tag affects text editability"));
+ ADD_SET_PROP ("editable-set", PROP_EDITABLE_SET,
+ P_("Editability set"),
+ P_("Whether this tag affects text editability"));
- ADD_SET_PROP ("family_set", PROP_FAMILY_SET,
- _("Font family set"),
- _("Whether this tag affects the font family"));
+ ADD_SET_PROP ("family-set", PROP_FAMILY_SET,
+ P_("Font family set"),
+ P_("Whether this tag affects the font family"));
- ADD_SET_PROP ("style_set", PROP_STYLE_SET,
- _("Font style set"),
- _("Whether this tag affects the font style"));
+ ADD_SET_PROP ("style-set", PROP_STYLE_SET,
+ P_("Font style set"),
+ P_("Whether this tag affects the font style"));
- ADD_SET_PROP ("variant_set", PROP_VARIANT_SET,
- _("Font variant set"),
- _("Whether this tag affects the font variant"));
+ ADD_SET_PROP ("variant-set", PROP_VARIANT_SET,
+ P_("Font variant set"),
+ P_("Whether this tag affects the font variant"));
- ADD_SET_PROP ("weight_set", PROP_WEIGHT_SET,
- _("Font weight set"),
- _("Whether this tag affects the font weight"));
+ ADD_SET_PROP ("weight-set", PROP_WEIGHT_SET,
+ P_("Font weight set"),
+ P_("Whether this tag affects the font weight"));
- ADD_SET_PROP ("stretch_set", PROP_STRETCH_SET,
- _("Font stretch set"),
- _("Whether this tag affects the font stretch"));
+ ADD_SET_PROP ("stretch-set", PROP_STRETCH_SET,
+ P_("Font stretch set"),
+ P_("Whether this tag affects the font stretch"));
- ADD_SET_PROP ("size_set", PROP_SIZE_SET,
- _("Font size set"),
- _("Whether this tag affects the font size"));
+ ADD_SET_PROP ("size-set", PROP_SIZE_SET,
+ P_("Font size set"),
+ P_("Whether this tag affects the font size"));
- ADD_SET_PROP ("scale_set", PROP_SCALE_SET,
- _("Font scale set"),
- _("Whether this tag scales the font size by a factor"));
+ ADD_SET_PROP ("scale-set", PROP_SCALE_SET,
+ P_("Font scale set"),
+ P_("Whether this tag scales the font size by a factor"));
- ADD_SET_PROP ("rise_set", PROP_RISE_SET,
- _("Rise set"),
- _("Whether this tag affects the rise"));
+ ADD_SET_PROP ("rise-set", PROP_RISE_SET,
+ P_("Rise set"),
+ P_("Whether this tag affects the rise"));
- ADD_SET_PROP ("strikethrough_set", PROP_STRIKETHROUGH_SET,
- _("Strikethrough set"),
- _("Whether this tag affects strikethrough"));
+ ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
+ P_("Strikethrough set"),
+ P_("Whether this tag affects strikethrough"));
- ADD_SET_PROP ("underline_set", PROP_UNDERLINE_SET,
- _("Underline set"),
- _("Whether this tag affects underlining"));
+ ADD_SET_PROP ("underline-set", PROP_UNDERLINE_SET,
+ P_("Underline set"),
+ P_("Whether this tag affects underlining"));
- ADD_SET_PROP ("language_set", PROP_LANGUAGE_SET,
- _("Language set"),
- _("Whether this tag affects the language the text is renderer as"));
+ ADD_SET_PROP ("language-set", PROP_LANGUAGE_SET,
+ P_("Language set"),
+ P_("Whether this tag affects the language the text is rendered as"));
+
+ ADD_SET_PROP ("ellipsize-set", PROP_ELLIPSIZE_SET,
+ P_("Ellipsize set"),
+ P_("Whether this tag affects the ellipsize mode"));
text_cell_renderer_signals [EDITED] =
g_signal_new ("edited",
g_value_set_string (value, pango_language_to_string (priv->language));
break;
+ case PROP_ELLIPSIZE:
+ g_value_set_enum (value, priv->ellipsize);
+ break;
+
+ case PROP_WRAP_MODE:
+ g_value_set_enum (value, priv->wrap_mode);
+ break;
+
+ case PROP_WRAP_WIDTH:
+ g_value_set_int (value, priv->wrap_width);
+ break;
+
case PROP_BACKGROUND_SET:
g_value_set_boolean (value, celltext->background_set);
break;
case PROP_LANGUAGE_SET:
g_value_set_boolean (value, priv->language_set);
break;
+
+ case PROP_ELLIPSIZE_SET:
+ g_value_set_boolean (value, priv->ellipsize_set);
+ break;
+ case PROP_WIDTH_CHARS:
+ g_value_set_int (value, priv->width_chars);
+ break;
+
case PROP_BACKGROUND:
case PROP_FOREGROUND:
case PROP_MARKUP:
if (!celltext->background_set)
{
celltext->background_set = TRUE;
- g_object_notify (G_OBJECT (celltext), "background_set");
+ g_object_notify (G_OBJECT (celltext), "background-set");
}
celltext->background.red = color->red;
if (celltext->background_set)
{
celltext->background_set = FALSE;
- g_object_notify (G_OBJECT (celltext), "background_set");
+ g_object_notify (G_OBJECT (celltext), "background-set");
}
}
}
if (!celltext->foreground_set)
{
celltext->foreground_set = TRUE;
- g_object_notify (G_OBJECT (celltext), "foreground_set");
+ g_object_notify (G_OBJECT (celltext), "foreground-set");
}
celltext->foreground.red = color->red;
if (celltext->foreground_set)
{
celltext->foreground_set = FALSE;
- g_object_notify (G_OBJECT (celltext), "foreground_set");
+ g_object_notify (G_OBJECT (celltext), "foreground-set");
}
}
}
PangoFontMask changed_mask)
{
if (changed_mask & PANGO_FONT_MASK_FAMILY)
- g_object_notify (object, "family_set");
+ g_object_notify (object, "family-set");
if (changed_mask & PANGO_FONT_MASK_STYLE)
- g_object_notify (object, "style_set");
+ g_object_notify (object, "style-set");
if (changed_mask & PANGO_FONT_MASK_VARIANT)
- g_object_notify (object, "variant_set");
+ g_object_notify (object, "variant-set");
if (changed_mask & PANGO_FONT_MASK_WEIGHT)
- g_object_notify (object, "weight_set");
+ g_object_notify (object, "weight-set");
if (changed_mask & PANGO_FONT_MASK_STRETCH)
- g_object_notify (object, "stretch_set");
+ g_object_notify (object, "stretch-set");
if (changed_mask & PANGO_FONT_MASK_SIZE)
- g_object_notify (object, "size_set");
+ g_object_notify (object, "size-set");
}
static void
g_object_freeze_notify (object);
- g_object_notify (object, "font_desc");
+ g_object_notify (object, "font-desc");
g_object_notify (object, "font");
if (changed_mask & PANGO_FONT_MASK_FAMILY)
if (changed_mask & PANGO_FONT_MASK_SIZE)
{
g_object_notify (object, "size");
- g_object_notify (object, "size_points");
+ g_object_notify (object, "size-points");
}
notify_set_changed (object, set_changed_mask);
else
g_warning ("Don't know color `%s'", g_value_get_string (value));
- g_object_notify (object, "background_gdk");
+ g_object_notify (object, "background-gdk");
}
break;
else
g_warning ("Don't know color `%s'", g_value_get_string (value));
- g_object_notify (object, "foreground_gdk");
+ g_object_notify (object, "foreground-gdk");
}
break;
font_desc = pango_font_description_from_string (name);
set_font_description (celltext, font_desc);
+
+ pango_font_description_free (font_desc);
if (celltext->fixed_height_rows != -1)
celltext->calc_fixed_height = TRUE;
case PROP_SIZE:
pango_font_description_set_size (celltext->font,
g_value_get_int (value));
- g_object_notify (object, "size_points");
+ g_object_notify (object, "size-points");
break;
case PROP_SIZE_POINTS:
pango_font_description_set_size (celltext->font,
celltext->calc_fixed_height = TRUE;
notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (celltext->font));
- g_object_notify (object, "font_desc");
+ g_object_notify (object, "font-desc");
g_object_notify (object, "font");
break;
celltext->scale_set = TRUE;
if (celltext->fixed_height_rows != -1)
celltext->calc_fixed_height = TRUE;
- g_object_notify (object, "scale_set");
+ g_object_notify (object, "scale-set");
break;
case PROP_EDITABLE:
GTK_CELL_RENDERER (celltext)->mode = GTK_CELL_RENDERER_MODE_EDITABLE;
else
GTK_CELL_RENDERER (celltext)->mode = GTK_CELL_RENDERER_MODE_INERT;
- g_object_notify (object, "editable_set");
+ g_object_notify (object, "editable-set");
break;
case PROP_STRIKETHROUGH:
celltext->strikethrough = g_value_get_boolean (value);
celltext->strikethrough_set = TRUE;
- g_object_notify (object, "strikethrough_set");
+ g_object_notify (object, "strikethrough-set");
break;
case PROP_UNDERLINE:
celltext->underline_style = g_value_get_enum (value);
celltext->underline_set = TRUE;
- g_object_notify (object, "underline_set");
+ g_object_notify (object, "underline-set");
break;
case PROP_RISE:
celltext->rise = g_value_get_int (value);
celltext->rise_set = TRUE;
- g_object_notify (object, "rise_set");
+ g_object_notify (object, "rise-set");
if (celltext->fixed_height_rows != -1)
celltext->calc_fixed_height = TRUE;
break;
if (priv->language)
g_object_unref (priv->language);
priv->language = pango_language_from_string (g_value_get_string (value));
- g_object_notify (object, "language_set");
+ g_object_notify (object, "language-set");
+ break;
+
+ case PROP_ELLIPSIZE:
+ priv->ellipsize = g_value_get_enum (value);
+ priv->ellipsize_set = TRUE;
+ g_object_notify (object, "ellipsize-set");
+ break;
+
+ case PROP_WRAP_MODE:
+ priv->wrap_mode = g_value_get_enum (value);
break;
+
+ case PROP_WRAP_WIDTH:
+ priv->wrap_width = g_value_get_int (value);
+ break;
+
+ case PROP_WIDTH_CHARS:
+ priv->width_chars = g_value_get_int (value);
+ break;
case PROP_BACKGROUND_SET:
celltext->background_set = g_value_get_boolean (value);
priv->language_set = g_value_get_boolean (value);
break;
+ case PROP_ELLIPSIZE_SET:
+ priv->ellipsize_set = g_value_get_boolean (value);
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
break;
* background_area not the PangoLayout area
*/
- if (celltext->foreground_set)
+ if (celltext->foreground_set
+ && (flags & GTK_CELL_RENDERER_SELECTED) == 0)
{
PangoColor color;
if (celltext->rise_set)
add_attr (attr_list, pango_attr_rise_new (celltext->rise));
-
+
+ if (priv->ellipsize_set)
+ pango_layout_set_ellipsize (layout, priv->ellipsize);
+ else
+ pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_NONE);
+
+ if (priv->wrap_width != -1)
+ {
+ pango_layout_set_width (layout, priv->wrap_width * PANGO_SCALE);
+ pango_layout_set_wrap (layout, priv->wrap_mode);
+
+ if (pango_layout_get_line_count (layout) == 1)
+ {
+ pango_layout_set_width (layout, -1);
+ pango_layout_set_wrap (layout, PANGO_WRAP_CHAR);
+ }
+ }
+ else
+ {
+ pango_layout_set_width (layout, -1);
+ pango_layout_set_wrap (layout, PANGO_WRAP_CHAR);
+ }
+
pango_layout_set_attributes (layout, attr_list);
- pango_layout_set_width (layout, -1);
pango_attr_list_unref (attr_list);
}
static void
-gtk_cell_renderer_text_get_size (GtkCellRenderer *cell,
- GtkWidget *widget,
- GdkRectangle *cell_area,
- gint *x_offset,
- gint *y_offset,
- gint *width,
- gint *height)
+get_size (GtkCellRenderer *cell,
+ GtkWidget *widget,
+ GdkRectangle *cell_area,
+ PangoLayout *layout,
+ gint *x_offset,
+ gint *y_offset,
+ gint *width,
+ gint *height)
{
GtkCellRendererText *celltext = (GtkCellRendererText *) cell;
PangoRectangle rect;
- PangoLayout *layout;
+ GtkCellRendererTextPrivate *priv;
+
+ priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
if (celltext->calc_fixed_height)
{
row_height = (pango_font_metrics_get_ascent (metrics) +
pango_font_metrics_get_descent (metrics));
pango_font_metrics_unref (metrics);
-
+
+ pango_font_description_free (font_desc);
+
gtk_cell_renderer_set_fixed_size (cell,
cell->width, 2*cell->ypad +
celltext->fixed_height_rows * PANGO_PIXELS (row_height));
if (width == NULL)
return;
}
- layout = get_layout (celltext, widget, FALSE, 0);
+
+ if (layout)
+ g_object_ref (layout);
+ else
+ layout = get_layout (celltext, widget, FALSE, 0);
+
pango_layout_get_pixel_extents (layout, NULL, &rect);
+ if (height)
+ *height = cell->ypad * 2 + rect.height;
+
+ /* The minimum size for ellipsized labels is ~ 3 chars */
if (width)
- *width = GTK_CELL_RENDERER (celltext)->xpad * 2 + rect.width;
+ {
+ if (priv->ellipsize || priv->width_chars > 0)
+ {
+ PangoContext *context;
+ PangoFontMetrics *metrics;
+ gint char_width;
- if (height)
- *height = GTK_CELL_RENDERER (celltext)->ypad * 2 + rect.height;
+ context = pango_layout_get_context (layout);
+ metrics = pango_context_get_metrics (context, widget->style->font_desc, pango_context_get_language (context));
+
+ char_width = pango_font_metrics_get_approximate_char_width (metrics);
+ pango_font_metrics_unref (metrics);
+
+ *width = cell->xpad * 2 + (PANGO_PIXELS (char_width) * MAX (priv->width_chars, 3));
+ }
+ else
+ {
+ *width = cell->xpad * 2 + rect.x + rect.width;
+ }
+ }
if (cell_area)
{
if (x_offset)
{
- *x_offset = ((gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL) ?
- (1.0 - cell->xalign) : cell->xalign) * (cell_area->width - rect.width - (2 * cell->xpad));
- *x_offset = MAX (*x_offset, 0);
+ if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+ *x_offset = (1.0 - cell->xalign) * (cell_area->width - (rect.x + rect.width + 2 * cell->xpad));
+ else
+ *x_offset = cell->xalign * (cell_area->width - (rect.x + rect.width + 2 * cell->xpad));
+
+ if (priv->ellipsize_set || priv->wrap_width != -1)
+ *x_offset = MAX(*x_offset, 0);
}
if (y_offset)
{
- *y_offset = cell->yalign * (cell_area->height - rect.height - (2 * cell->ypad));
+ *y_offset = cell->yalign * (cell_area->height - (rect.height + 2 * cell->ypad));
*y_offset = MAX (*y_offset, 0);
}
}
g_object_unref (layout);
}
+
+static void
+gtk_cell_renderer_text_get_size (GtkCellRenderer *cell,
+ GtkWidget *widget,
+ GdkRectangle *cell_area,
+ gint *x_offset,
+ gint *y_offset,
+ gint *width,
+ gint *height)
+{
+ get_size (cell, widget, cell_area, NULL,
+ x_offset, y_offset, width, height);
+}
+
static void
gtk_cell_renderer_text_render (GtkCellRenderer *cell,
GdkDrawable *window,
GtkStateType state;
gint x_offset;
gint y_offset;
+ GtkCellRendererTextPrivate *priv;
- layout = get_layout (celltext, widget, TRUE, flags);
+ priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (cell);
- gtk_cell_renderer_text_get_size (cell, widget, cell_area, &x_offset, &y_offset, NULL, NULL);
+ layout = get_layout (celltext, widget, TRUE, flags);
+ get_size (cell, widget, cell_area, layout, &x_offset, &y_offset, NULL, NULL);
- if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
+ if (!cell->sensitive)
+ {
+ state = GTK_STATE_INSENSITIVE;
+ }
+ else if ((flags & GTK_CELL_RENDERER_SELECTED) == GTK_CELL_RENDERER_SELECTED)
{
if (GTK_WIDGET_HAS_FOCUS (widget))
state = GTK_STATE_SELECTED;
else
state = GTK_STATE_ACTIVE;
}
+ else if ((flags & GTK_CELL_RENDERER_PRELIT) == GTK_CELL_RENDERER_PRELIT &&
+ GTK_WIDGET_STATE (widget) == GTK_STATE_PRELIGHT)
+ {
+ state = GTK_STATE_PRELIGHT;
+ }
else
{
if (GTK_WIDGET_STATE (widget) == GTK_STATE_INSENSITIVE)
state = GTK_STATE_NORMAL;
}
- if (celltext->background_set && state != GTK_STATE_SELECTED)
+ if (celltext->background_set &&
+ (flags & GTK_CELL_RENDERER_SELECTED) == 0)
{
GdkColor color;
GdkGC *gc;
gc = gdk_gc_new (window);
gdk_gc_set_rgb_fg_color (gc, &color);
-
+
+ if (expose_area)
+ gdk_gc_set_clip_rectangle (gc, expose_area);
gdk_draw_rectangle (window,
gc,
TRUE,
background_area->y,
background_area->width,
background_area->height);
-
+ if (expose_area)
+ gdk_gc_set_clip_rectangle (gc, NULL);
g_object_unref (gc);
}
+ if (priv->ellipsize_set)
+ pango_layout_set_width (layout,
+ (cell_area->width - x_offset - 2 * cell->xpad) * PANGO_SCALE);
+ else if (priv->wrap_width == -1)
+ pango_layout_set_width (layout, -1);
+
gtk_paint_layout (widget->style,
window,
state,
TRUE,
- cell_area,
+ expose_area,
widget,
"cellrenderertext",
cell_area->x + x_offset + cell->xpad,
priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
+ priv->entry = NULL;
+
if (priv->focus_out_id > 0)
{
g_signal_handler_disconnect (entry, priv->focus_out_id);
priv->focus_out_id = 0;
}
+ if (priv->populate_popup_id > 0)
+ {
+ g_signal_handler_disconnect (entry, priv->populate_popup_id);
+ priv->populate_popup_id = 0;
+ }
+
+ if (priv->entry_menu_popdown_timeout)
+ {
+ g_source_remove (priv->entry_menu_popdown_timeout);
+ priv->entry_menu_popdown_timeout = 0;
+ }
+
+ gtk_cell_renderer_stop_editing (GTK_CELL_RENDERER (data),
+ GTK_ENTRY (entry)->editing_canceled);
if (GTK_ENTRY (entry)->editing_canceled)
return;
g_signal_emit (data, text_cell_renderer_signals[EDITED], 0, path, new_text);
}
+static gboolean
+popdown_timeout (gpointer data)
+{
+ GtkCellRendererTextPrivate *priv;
+
+ GDK_THREADS_ENTER ();
+
+ priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
+
+ priv->entry_menu_popdown_timeout = 0;
+
+ if (!GTK_WIDGET_HAS_FOCUS (priv->entry))
+ gtk_cell_renderer_text_editing_done (GTK_CELL_EDITABLE (priv->entry), data);
+
+ GDK_THREADS_LEAVE ();
+
+ return FALSE;
+}
+
+static void
+gtk_cell_renderer_text_popup_unmap (GtkMenu *menu,
+ gpointer data)
+{
+ GtkCellRendererTextPrivate *priv;
+
+ priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
+
+ priv->in_entry_menu = FALSE;
+
+ if (priv->entry_menu_popdown_timeout)
+ return;
+
+ priv->entry_menu_popdown_timeout = g_timeout_add (500, popdown_timeout,
+ data);
+}
+
+static void
+gtk_cell_renderer_text_populate_popup (GtkEntry *entry,
+ GtkMenu *menu,
+ gpointer data)
+{
+ GtkCellRendererTextPrivate *priv;
+
+ priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
+
+ if (priv->entry_menu_popdown_timeout)
+ {
+ g_source_remove (priv->entry_menu_popdown_timeout);
+ priv->entry_menu_popdown_timeout = 0;
+ }
+
+ priv->in_entry_menu = TRUE;
+
+ g_signal_connect (menu, "unmap",
+ G_CALLBACK (gtk_cell_renderer_text_popup_unmap), data);
+}
+
static gboolean
gtk_cell_renderer_text_focus_out_event (GtkWidget *entry,
GdkEvent *event,
gpointer data)
{
+ GtkCellRendererTextPrivate *priv;
+
+ priv = GTK_CELL_RENDERER_TEXT_GET_PRIVATE (data);
+
+ if (priv->in_entry_menu)
+ return FALSE;
+
gtk_cell_renderer_text_editing_done (GTK_CELL_EDITABLE (entry), data);
/* entry needs focus-out-event */
GdkRectangle *cell_area,
GtkCellRendererState flags)
{
- GtkWidget *entry;
GtkCellRendererText *celltext;
GtkCellRendererTextPrivate *priv;
if (celltext->editable == FALSE)
return NULL;
- entry = g_object_new (GTK_TYPE_ENTRY,
- "has_frame", FALSE,
- NULL);
+ priv->entry = g_object_new (GTK_TYPE_ENTRY,
+ "has-frame", FALSE,
+ "xalign", cell->xalign,
+ NULL);
if (celltext->text)
- gtk_entry_set_text (GTK_ENTRY (entry), celltext->text);
- g_object_set_data_full (G_OBJECT (entry), GTK_CELL_RENDERER_TEXT_PATH, g_strdup (path), g_free);
+ gtk_entry_set_text (GTK_ENTRY (priv->entry), celltext->text);
+ g_object_set_data_full (G_OBJECT (priv->entry), GTK_CELL_RENDERER_TEXT_PATH, g_strdup (path), g_free);
- gtk_editable_select_region (GTK_EDITABLE (entry), 0, -1);
+ gtk_editable_select_region (GTK_EDITABLE (priv->entry), 0, -1);
- gtk_widget_show (entry);
- g_signal_connect (entry,
+
+ priv->in_entry_menu = FALSE;
+ if (priv->entry_menu_popdown_timeout)
+ {
+ g_source_remove (priv->entry_menu_popdown_timeout);
+ priv->entry_menu_popdown_timeout = 0;
+ }
+
+ g_signal_connect (priv->entry,
"editing_done",
G_CALLBACK (gtk_cell_renderer_text_editing_done),
celltext);
- priv->focus_out_id = g_signal_connect (entry, "focus_out_event",
+ priv->focus_out_id = g_signal_connect (priv->entry, "focus_out_event",
G_CALLBACK (gtk_cell_renderer_text_focus_out_event),
celltext);
-
- return GTK_CELL_EDITABLE (entry);
-
+ priv->populate_popup_id =
+ g_signal_connect (priv->entry, "populate_popup",
+ G_CALLBACK (gtk_cell_renderer_text_populate_popup),
+ celltext);
+
+ gtk_widget_show (priv->entry);
+
+ return GTK_CELL_EDITABLE (priv->entry);
}
/**
renderer->calc_fixed_height = TRUE;
}
}
+
+#define __GTK_CELL_RENDERER_TEXT_C__
+#include "gtkaliasdef.c"