#include "gtktexttag.h"
#include "gtktexttypes.h"
#include "gtktexttagtable.h"
-#include "gtksignal.h"
#include "gtkmain.h"
#include "gtkintl.h"
-#include "gtktypebuiltins.h"
+#include "gtkmarshalers.h"
#include <stdlib.h>
#include <string.h>
PROP_STRETCH,
PROP_SIZE,
PROP_SIZE_POINTS,
+ PROP_SCALE,
PROP_PIXELS_ABOVE_LINES,
PROP_PIXELS_BELOW_LINES,
PROP_PIXELS_INSIDE_WRAP,
/* Whether-a-style-arg-is-set args */
PROP_BACKGROUND_SET,
PROP_FOREGROUND_SET,
- PROP_BACKGROUND_GDK_SET,
- PROP_FOREGROUND_GDK_SET,
PROP_BACKGROUND_STIPPLE_SET,
PROP_FOREGROUND_STIPPLE_SET,
PROP_FAMILY_SET,
PROP_WEIGHT_SET,
PROP_STRETCH_SET,
PROP_SIZE_SET,
+ PROP_SCALE_SET,
PROP_PIXELS_ABOVE_LINES_SET,
PROP_PIXELS_BELOW_LINES_SET,
PROP_PIXELS_INSIDE_WRAP_SET,
static void gtk_text_tag_set_property (GObject *object,
guint prop_id,
const GValue *value,
- GParamSpec *pspec,
- const gchar *trailer);
+ GParamSpec *pspec);
static void gtk_text_tag_get_property (GObject *object,
guint prop_id,
GValue *value,
- GParamSpec *pspec,
- const gchar *trailer);
+ GParamSpec *pspec);
static GObjectClass *parent_class = NULL;
static guint signals[LAST_SIGNAL] = { 0 };
(GInstanceInitFunc) gtk_text_tag_init
};
- our_type = g_type_register_static (G_TYPE_OBJECT,
- "GtkTextTag",
- &our_info,
- 0);
+ our_type = g_type_register_static (G_TYPE_OBJECT, "GtkTextTag",
+ &our_info, 0);
}
return our_type;
PROP_NAME,
g_param_spec_string ("name",
_("Tag name"),
- _("Name used to refer to the text tag"),
+ _("Name used to refer to the text tag. NULL for anonymous tags"),
NULL,
G_PARAM_READABLE | G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
PROP_BACKGROUND_GDK,
g_param_spec_boxed ("background_gdk",
_("Background color"),
- _("Background color as a GdkColor"),
- GTK_TYPE_GDK_COLOR,
+ _("Background color as a (possibly unallocated) GdkColor"),
+ GDK_TYPE_COLOR,
G_PARAM_READABLE | G_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"),
- GTK_TYPE_GDK_COLOR,
+ _("Foreground color as a (possibly unallocated) GdkColor"),
+ GDK_TYPE_COLOR,
G_PARAM_READABLE | G_PARAM_WRITABLE));
PROP_FONT,
g_param_spec_string ("font",
_("Font"),
- _("Font description as a string"),
+ _("Font description as a string, e.g. \"Sans Italic 12\""),
NULL,
G_PARAM_READABLE | G_PARAM_WRITABLE));
g_param_spec_boxed ("font_desc",
_("Font"),
_("Font description as a PangoFontDescription struct"),
- GTK_TYPE_PANGO_FONT_DESCRIPTION,
+ PANGO_TYPE_FONT_DESCRIPTION,
G_PARAM_READABLE | G_PARAM_WRITABLE));
PROP_STYLE,
g_param_spec_enum ("style",
_("Font style"),
- _("Font style"),
+ _("Font style as a PangoStyle, e.g. PANGO_STYLE_ITALIC"),
PANGO_TYPE_STYLE,
PANGO_STYLE_NORMAL,
G_PARAM_READABLE | G_PARAM_WRITABLE));
PROP_VARIANT,
g_param_spec_enum ("variant",
_("Font variant"),
- _("Font variant"),
+ _("Font variant as a PangoVariant, e.g. PANGO_VARIANT_SMALL_CAPS"),
PANGO_TYPE_VARIANT,
PANGO_VARIANT_NORMAL,
G_PARAM_READABLE | G_PARAM_WRITABLE));
PROP_WEIGHT,
g_param_spec_int ("weight",
_("Font weight"),
- _("Font weight"),
+ _("Font weight as an integer, see predefined values in PangoWeight; for example, PANGO_WEIGHT_BOLD"),
0,
G_MAXINT,
PANGO_WEIGHT_NORMAL,
PROP_STRETCH,
g_param_spec_enum ("stretch",
_("Font stretch"),
- _("Font stretch"),
+ _("Font stretch as a PangoStretch, e.g. PANGO_STRETCH_CONDENSED"),
PANGO_TYPE_STRETCH,
PANGO_STRETCH_NORMAL,
G_PARAM_READABLE | G_PARAM_WRITABLE));
PROP_SIZE,
g_param_spec_int ("size",
_("Font size"),
- _("Font size"),
+ _("Font size in Pango units"),
0,
G_MAXINT,
0,
G_PARAM_READABLE | G_PARAM_WRITABLE));
+ g_object_class_install_property (object_class,
+ PROP_SCALE,
+ g_param_spec_double ("scale",
+ _("Font scale"),
+ _("Font size as a scale factor relative to the default font size. This properly adapts to theme changes etc. so is recommended. Pango predefines some scales such as PANGO_SCALE_X_LARGE"),
+ 0.0,
+ G_MAXDOUBLE,
+ 1.0,
+ G_PARAM_READABLE | G_PARAM_WRITABLE));
+
g_object_class_install_property (object_class,
PROP_SIZE_POINTS,
g_param_spec_double ("size_points",
PROP_LANGUAGE,
g_param_spec_string ("language",
_("Language"),
- _("Language engine code to use for rendering the text"),
+ _("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_READABLE | G_PARAM_WRITABLE));
g_param_spec_int ("indent",
_("Indent"),
_("Amount to indent the paragraph, in pixels"),
- 0,
+ G_MININT,
G_MAXINT,
0,
G_PARAM_READABLE | G_PARAM_WRITABLE));
PROP_RISE,
g_param_spec_int ("rise",
_("Rise"),
- _("Offset of text above the baseline (below the baseline if rise is negative)"),
- -G_MAXINT,
+ _("Offset of text above the baseline (below the baseline if rise is negative) in pixels"),
+ G_MININT,
G_MAXINT,
0,
G_PARAM_READABLE | G_PARAM_WRITABLE));
_("Wrap mode"),
_("Whether to wrap lines never, at word boundaries, or at character boundaries"),
GTK_TYPE_WRAP_MODE,
- GTK_WRAPMODE_NONE,
+ GTK_WRAP_NONE,
G_PARAM_READABLE | G_PARAM_WRITABLE));
g_param_spec_boxed ("tabs",
_("Tabs"),
_("Custom tabs for this text"),
- GTK_TYPE_PANGO_TAB_ARRAY,
+ PANGO_TYPE_TAB_ARRAY,
G_PARAM_READABLE | G_PARAM_WRITABLE));
g_object_class_install_property (object_class,
PROP_INVISIBLE,
g_param_spec_boolean ("invisible",
_("Invisible"),
- _("Whether this text is hidden"),
+ _("Whether this text is hidden. Not implemented in GTK 2.0"),
FALSE,
G_PARAM_READABLE | G_PARAM_WRITABLE));
_("Background full height set"),
_("Whether this tag affects background height"));
- ADD_SET_PROP ("background_gdk_set", PROP_BACKGROUND_GDK_SET,
- _("Background set"),
- _("Whether this tag affects the background color"));
-
ADD_SET_PROP ("background_stipple_set", PROP_BACKGROUND_STIPPLE_SET,
_("Background stipple set"),
_("Whether this tag affects the background stipple"));
_("Foreground set"),
_("Whether this tag affects the foreground color"));
- ADD_SET_PROP ("foreground_gdk_set", PROP_FOREGROUND_GDK_SET,
- _("Foreground set"),
- _("Whether this tag affects the foreground color"));
-
ADD_SET_PROP ("foreground_stipple_set", PROP_FOREGROUND_STIPPLE_SET,
_("Foreground stipple set"),
_("Whether this tag affects the foreground stipple"));
_("Font size set"),
_("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 ("justification_set", PROP_JUSTIFICATION_SET,
_("Justification set"),
_("Whether this tag affects paragraph justification"));
_("Whether this tag affects text visibility"));
signals[EVENT] =
- g_signal_newc ("event",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_LAST,
- GTK_SIGNAL_OFFSET (GtkTextTagClass, event),
- NULL,
- gtk_marshal_INT__OBJECT_BOXED_BOXED,
- GTK_TYPE_INT,
- 3,
- G_TYPE_OBJECT,
- GTK_TYPE_GDK_EVENT,
- GTK_TYPE_TEXT_ITER);
+ g_signal_new ("event",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (GtkTextTagClass, event),
+ _gtk_boolean_handled_accumulator, NULL,
+ _gtk_marshal_BOOLEAN__OBJECT_BOXED_BOXED,
+ G_TYPE_BOOLEAN,
+ 3,
+ G_TYPE_OBJECT,
+ GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
+ GTK_TYPE_TEXT_ITER);
}
-void
+static void
gtk_text_tag_init (GtkTextTag *text_tag)
{
/* 0 is basically a fine way to initialize everything in the
{
GtkTextTag *tag;
- tag = GTK_TEXT_TAG (g_object_new (gtk_text_tag_get_type (),
- "name", name,
- NULL));
+ tag = g_object_new (GTK_TYPE_TEXT_TAG, "name", name, NULL);
return tag;
}
}
}
-static void
-set_font_description (GtkTextTag *text_tag,
- PangoFontDescription *font_desc)
+static PangoFontMask
+get_property_font_set_mask (guint prop_id)
{
- if (font_desc != NULL)
+ switch (prop_id)
{
- /* pango_font_description_from_string() will sometimes return
- * a NULL family or -1 size, so handle those cases.
- */
-
- if (font_desc->family_name)
- g_object_set (G_OBJECT (text_tag),
- "family", font_desc->family_name,
- NULL);
+ case PROP_FAMILY_SET:
+ return PANGO_FONT_MASK_FAMILY;
+ case PROP_STYLE_SET:
+ return PANGO_FONT_MASK_STYLE;
+ case PROP_VARIANT_SET:
+ return PANGO_FONT_MASK_VARIANT;
+ case PROP_WEIGHT_SET:
+ return PANGO_FONT_MASK_WEIGHT;
+ case PROP_STRETCH_SET:
+ return PANGO_FONT_MASK_STRETCH;
+ case PROP_SIZE_SET:
+ return PANGO_FONT_MASK_SIZE;
+ }
+
+ return 0;
+}
+
+static PangoFontMask
+set_font_desc_fields (PangoFontDescription *desc,
+ PangoFontMask to_set)
+{
+ PangoFontMask changed_mask = 0;
+
+ if (to_set & PANGO_FONT_MASK_FAMILY)
+ {
+ const char *family = pango_font_description_get_family (desc);
+ if (!family)
+ {
+ family = "sans";
+ changed_mask |= PANGO_FONT_MASK_FAMILY;
+ }
+
+ pango_font_description_set_family (desc, family);
+ }
+ if (to_set & PANGO_FONT_MASK_STYLE)
+ pango_font_description_set_style (desc, pango_font_description_get_style (desc));
+ if (to_set & PANGO_FONT_MASK_VARIANT)
+ pango_font_description_set_variant (desc, pango_font_description_get_variant (desc));
+ if (to_set & PANGO_FONT_MASK_WEIGHT)
+ pango_font_description_set_weight (desc, pango_font_description_get_weight (desc));
+ if (to_set & PANGO_FONT_MASK_STRETCH)
+ pango_font_description_set_stretch (desc, pango_font_description_get_stretch (desc));
+ if (to_set & PANGO_FONT_MASK_SIZE)
+ {
+ gint size = pango_font_description_get_size (desc);
+ if (size <= 0)
+ {
+ size = 10 * PANGO_SCALE;
+ changed_mask |= PANGO_FONT_MASK_SIZE;
+ }
- if (font_desc->size >= 0)
- g_object_set (G_OBJECT (text_tag),
- "size", font_desc->size,
- NULL);
-
- g_object_set (G_OBJECT (text_tag),
- "style", font_desc->style,
- "variant", font_desc->variant,
- "weight", font_desc->weight,
- "stretch", font_desc->stretch,
- NULL);
+ pango_font_description_set_size (desc, size);
}
+
+ return changed_mask;
+}
+
+static void
+notify_set_changed (GObject *object,
+ PangoFontMask changed_mask)
+{
+ if (changed_mask & PANGO_FONT_MASK_FAMILY)
+ g_object_notify (object, "family_set");
+ if (changed_mask & PANGO_FONT_MASK_STYLE)
+ g_object_notify (object, "style_set");
+ if (changed_mask & PANGO_FONT_MASK_VARIANT)
+ g_object_notify (object, "variant_set");
+ if (changed_mask & PANGO_FONT_MASK_WEIGHT)
+ g_object_notify (object, "weight_set");
+ if (changed_mask & PANGO_FONT_MASK_STRETCH)
+ g_object_notify (object, "stretch_set");
+ if (changed_mask & PANGO_FONT_MASK_SIZE)
+ g_object_notify (object, "size_set");
+}
+
+static void
+notify_fields_changed (GObject *object,
+ PangoFontMask changed_mask)
+{
+ if (changed_mask & PANGO_FONT_MASK_FAMILY)
+ g_object_notify (object, "family");
+ if (changed_mask & PANGO_FONT_MASK_STYLE)
+ g_object_notify (object, "style");
+ if (changed_mask & PANGO_FONT_MASK_VARIANT)
+ g_object_notify (object, "variant");
+ if (changed_mask & PANGO_FONT_MASK_WEIGHT)
+ g_object_notify (object, "weight");
+ if (changed_mask & PANGO_FONT_MASK_STRETCH)
+ g_object_notify (object, "stretch");
+ if (changed_mask & PANGO_FONT_MASK_SIZE)
+ g_object_notify (object, "size");
+}
+
+static void
+set_font_description (GtkTextTag *text_tag,
+ PangoFontDescription *font_desc)
+{
+ GObject *object = G_OBJECT (text_tag);
+ PangoFontDescription *new_font_desc;
+ PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
+
+ if (font_desc)
+ new_font_desc = pango_font_description_copy (font_desc);
+ else
+ new_font_desc = pango_font_description_new ();
+
+ if (text_tag->values->font)
+ old_mask = pango_font_description_get_set_fields (text_tag->values->font);
else
+ old_mask = 0;
+
+ new_mask = pango_font_description_get_set_fields (new_font_desc);
+
+ changed_mask = old_mask | new_mask;
+ set_changed_mask = old_mask ^ new_mask;
+
+ if (text_tag->values->font)
+ pango_font_description_free (text_tag->values->font);
+ text_tag->values->font = new_font_desc;
+
+ g_object_freeze_notify (object);
+
+ g_object_notify (object, "font_desc");
+ g_object_notify (object, "font");
+
+ if (changed_mask & PANGO_FONT_MASK_FAMILY)
+ g_object_notify (object, "family");
+ if (changed_mask & PANGO_FONT_MASK_STYLE)
+ g_object_notify (object, "style");
+ if (changed_mask & PANGO_FONT_MASK_VARIANT)
+ g_object_notify (object, "variant");
+ if (changed_mask & PANGO_FONT_MASK_WEIGHT)
+ g_object_notify (object, "weight");
+ if (changed_mask & PANGO_FONT_MASK_STRETCH)
+ g_object_notify (object, "stretch");
+ if (changed_mask & PANGO_FONT_MASK_SIZE)
{
- if (text_tag->family_set)
- {
- text_tag->family_set = FALSE;
- g_object_notify (G_OBJECT (text_tag), "family_set");
- }
- if (text_tag->style_set)
- {
- text_tag->style_set = FALSE;
- g_object_notify (G_OBJECT (text_tag), "style_set");
- }
- if (text_tag->variant_set)
- {
- text_tag->variant_set = FALSE;
- g_object_notify (G_OBJECT (text_tag), "variant_set");
- }
- if (text_tag->weight_set)
- {
- text_tag->weight_set = FALSE;
- g_object_notify (G_OBJECT (text_tag), "weight_set");
- }
- if (text_tag->stretch_set)
- {
- text_tag->stretch_set = FALSE;
- g_object_notify (G_OBJECT (text_tag), "stretch_set");
- }
- if (text_tag->size_set)
- {
- text_tag->size_set = FALSE;
- g_object_notify (G_OBJECT (text_tag), "size_set");
- }
+ g_object_notify (object, "size");
+ g_object_notify (object, "size_points");
}
+
+ notify_set_changed (object, set_changed_mask);
+
+ g_object_thaw_notify (object);
+}
+
+static void
+gtk_text_tag_ensure_font (GtkTextTag *text_tag)
+{
+ if (!text_tag->values->font)
+ text_tag->values->font = pango_font_description_new ();
}
static void
gtk_text_tag_set_property (GObject *object,
guint prop_id,
const GValue *value,
- GParamSpec *pspec,
- const gchar *trailer)
+ GParamSpec *pspec)
{
GtkTextTag *text_tag;
gboolean size_changed = FALSE;
set_bg_color (text_tag, &color);
else
g_warning ("Don't know color `%s'", g_value_get_string (value));
+
+ g_object_notify (object, "background_gdk");
}
break;
set_fg_color (text_tag, &color);
else
g_warning ("Don't know color `%s'", g_value_get_string (value));
+
+ g_object_notify (object, "foreground_gdk");
}
break;
case PROP_BACKGROUND_GDK:
{
- GdkColor *color = g_value_get_as_pointer (value);
+ GdkColor *color = g_value_get_boxed (value);
+
set_bg_color (text_tag, color);
}
break;
case PROP_FOREGROUND_GDK:
{
- GdkColor *color = g_value_get_as_pointer (value);
+ GdkColor *color = g_value_get_boxed (value);
+
set_fg_color (text_tag, color);
}
break;
case PROP_BACKGROUND_STIPPLE:
{
- GdkBitmap *bitmap = g_value_get_as_pointer (value);
+ GdkBitmap *bitmap = g_value_get_object (value);
text_tag->bg_stipple_set = TRUE;
- g_object_notify (G_OBJECT (text_tag), "bg_stipple_set");
+ g_object_notify (object, "background_stipple_set");
if (text_tag->values->appearance.bg_stipple != bitmap)
{
if (bitmap != NULL)
- gdk_bitmap_ref (bitmap);
+ g_object_ref (bitmap);
if (text_tag->values->appearance.bg_stipple)
- gdk_bitmap_unref (text_tag->values->appearance.bg_stipple);
+ g_object_unref (text_tag->values->appearance.bg_stipple);
text_tag->values->appearance.bg_stipple = bitmap;
}
case PROP_FOREGROUND_STIPPLE:
{
- GdkBitmap *bitmap = g_value_get_as_pointer (value);
+ GdkBitmap *bitmap = g_value_get_object (value);
text_tag->fg_stipple_set = TRUE;
- g_object_notify (G_OBJECT (text_tag), "fg_stipple_set");
+ g_object_notify (object, "foreground_stipple_set");
if (text_tag->values->appearance.fg_stipple != bitmap)
{
if (bitmap != NULL)
- gdk_bitmap_ref (bitmap);
+ g_object_ref (bitmap);
if (text_tag->values->appearance.fg_stipple)
- gdk_bitmap_unref (text_tag->values->appearance.fg_stipple);
+ g_object_unref (text_tag->values->appearance.fg_stipple);
text_tag->values->appearance.fg_stipple = bitmap;
}
font_desc = pango_font_description_from_string (name);
set_font_description (text_tag, font_desc);
+ if (font_desc)
+ pango_font_description_free (font_desc);
- if (font_desc)
- pango_font_description_free (font_desc);
-
size_changed = TRUE;
}
break;
{
PangoFontDescription *font_desc;
- font_desc = g_value_get_as_pointer (value);
+ font_desc = g_value_get_boxed (value);
set_font_description (text_tag, font_desc);
break;
case PROP_FAMILY:
- if (text_tag->values->font.family_name)
- g_free (text_tag->values->font.family_name);
- text_tag->values->font.family_name = g_strdup (g_value_get_string (value));
- text_tag->family_set = TRUE;
- g_object_notify (G_OBJECT (text_tag), "family_set");
- size_changed = TRUE;
- break;
-
case PROP_STYLE:
- text_tag->values->font.style = g_value_get_enum (value);
- text_tag->style_set = TRUE;
- g_object_notify (G_OBJECT (text_tag), "style_set");
- size_changed = TRUE;
- break;
-
case PROP_VARIANT:
- text_tag->values->font.variant = g_value_get_enum (value);
- text_tag->variant_set = TRUE;
- g_object_notify (G_OBJECT (text_tag), "variant_set");
- size_changed = TRUE;
- break;
-
case PROP_WEIGHT:
- text_tag->values->font.weight = g_value_get_int (value);
- text_tag->weight_set = TRUE;
- g_object_notify (G_OBJECT (text_tag), "weight_set");
- size_changed = TRUE;
- break;
-
case PROP_STRETCH:
- text_tag->values->font.stretch = g_value_get_enum (value);
- text_tag->stretch_set = TRUE;
- g_object_notify (G_OBJECT (text_tag), "stretch_set");
- size_changed = TRUE;
- break;
-
case PROP_SIZE:
- text_tag->values->font.size = g_value_get_int (value);
- text_tag->size_set = TRUE;
- g_object_notify (G_OBJECT (text_tag), "size_set");
- size_changed = TRUE;
- break;
-
case PROP_SIZE_POINTS:
- text_tag->values->font.size = g_value_get_double (value) * PANGO_SCALE;
- text_tag->size_set = TRUE;
- g_object_notify (G_OBJECT (text_tag), "size_set");
+ {
+ PangoFontMask old_set_mask;
+
+ gtk_text_tag_ensure_font (text_tag);
+ old_set_mask = pango_font_description_get_set_fields (text_tag->values->font);
+
+ switch (prop_id)
+ {
+ case PROP_FAMILY:
+ pango_font_description_set_family (text_tag->values->font,
+ g_value_get_string (value));
+ break;
+ case PROP_STYLE:
+ pango_font_description_set_style (text_tag->values->font,
+ g_value_get_enum (value));
+ break;
+ case PROP_VARIANT:
+ pango_font_description_set_variant (text_tag->values->font,
+ g_value_get_enum (value));
+ break;
+ case PROP_WEIGHT:
+ pango_font_description_set_weight (text_tag->values->font,
+ g_value_get_int (value));
+ break;
+ case PROP_STRETCH:
+ pango_font_description_set_stretch (text_tag->values->font,
+ g_value_get_enum (value));
+ break;
+ case PROP_SIZE:
+ pango_font_description_set_size (text_tag->values->font,
+ g_value_get_int (value));
+ g_object_notify (object, "size_points");
+ break;
+ case PROP_SIZE_POINTS:
+ pango_font_description_set_size (text_tag->values->font,
+ g_value_get_double (value) * PANGO_SCALE);
+ g_object_notify (object, "size");
+ break;
+ }
+
+ size_changed = TRUE;
+ notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (text_tag->values->font));
+ g_object_notify (object, "font_desc");
+ g_object_notify (object, "font");
+
+ break;
+ }
+
+ case PROP_SCALE:
+ text_tag->values->font_scale = g_value_get_double (value);
+ text_tag->scale_set = TRUE;
+ g_object_notify (object, "scale_set");
size_changed = TRUE;
break;
case PROP_PIXELS_ABOVE_LINES:
text_tag->pixels_above_lines_set = TRUE;
text_tag->values->pixels_above_lines = g_value_get_int (value);
- g_object_notify (G_OBJECT (text_tag), "pixels_above_lines_set");
+ g_object_notify (object, "pixels_above_lines_set");
size_changed = TRUE;
break;
case PROP_PIXELS_BELOW_LINES:
text_tag->pixels_below_lines_set = TRUE;
text_tag->values->pixels_below_lines = g_value_get_int (value);
- g_object_notify (G_OBJECT (text_tag), "pixels_below_lines_set");
+ g_object_notify (object, "pixels_below_lines_set");
size_changed = TRUE;
break;
case PROP_PIXELS_INSIDE_WRAP:
text_tag->pixels_inside_wrap_set = TRUE;
text_tag->values->pixels_inside_wrap = g_value_get_int (value);
- g_object_notify (G_OBJECT (text_tag), "pixels_inside_wrap_set");
+ g_object_notify (object, "pixels_inside_wrap_set");
size_changed = TRUE;
break;
case PROP_EDITABLE:
text_tag->editable_set = TRUE;
text_tag->values->editable = g_value_get_boolean (value);
- g_object_notify (G_OBJECT (text_tag), "editable_set");
+ g_object_notify (object, "editable_set");
break;
case PROP_WRAP_MODE:
text_tag->wrap_mode_set = TRUE;
text_tag->values->wrap_mode = g_value_get_enum (value);
- g_object_notify (G_OBJECT (text_tag), "wrap_mode_set");
+ g_object_notify (object, "wrap_mode_set");
size_changed = TRUE;
break;
case PROP_JUSTIFICATION:
text_tag->justification_set = TRUE;
text_tag->values->justification = g_value_get_enum (value);
- g_object_notify (G_OBJECT (text_tag), "justification_set");
+ g_object_notify (object, "justification_set");
size_changed = TRUE;
break;
case PROP_LEFT_MARGIN:
text_tag->left_margin_set = TRUE;
text_tag->values->left_margin = g_value_get_int (value);
- g_object_notify (G_OBJECT (text_tag), "left_margin_set");
+ g_object_notify (object, "left_margin_set");
size_changed = TRUE;
break;
case PROP_INDENT:
text_tag->indent_set = TRUE;
text_tag->values->indent = g_value_get_int (value);
- g_object_notify (G_OBJECT (text_tag), "indent_set");
+ g_object_notify (object, "indent_set");
size_changed = TRUE;
break;
case PROP_STRIKETHROUGH:
text_tag->strikethrough_set = TRUE;
text_tag->values->appearance.strikethrough = g_value_get_boolean (value);
- g_object_notify (G_OBJECT (text_tag), "strikethrough_set");
+ g_object_notify (object, "strikethrough_set");
break;
case PROP_RIGHT_MARGIN:
text_tag->right_margin_set = TRUE;
text_tag->values->right_margin = g_value_get_int (value);
- g_object_notify (G_OBJECT (text_tag), "right_margin_set");
+ g_object_notify (object, "right_margin_set");
size_changed = TRUE;
break;
case PROP_UNDERLINE:
text_tag->underline_set = TRUE;
text_tag->values->appearance.underline = g_value_get_enum (value);
- g_object_notify (G_OBJECT (text_tag), "underline_set");
+ g_object_notify (object, "underline_set");
break;
case PROP_RISE:
text_tag->rise_set = TRUE;
text_tag->values->appearance.rise = g_value_get_int (value);
- g_object_notify (G_OBJECT (text_tag), "rise_set");
+ g_object_notify (object, "rise_set");
size_changed = TRUE;
break;
case PROP_BG_FULL_HEIGHT:
text_tag->bg_full_height_set = TRUE;
text_tag->values->bg_full_height = g_value_get_boolean (value);
- g_object_notify (G_OBJECT (text_tag), "bg_full_height_set");
+ g_object_notify (object, "background_full_height_set");
break;
case PROP_LANGUAGE:
text_tag->language_set = TRUE;
- text_tag->values->language = g_strdup (g_value_get_string (value));
- g_object_notify (G_OBJECT (text_tag), "language_set");
+ text_tag->values->language = pango_language_from_string (g_value_get_string (value));
+ g_object_notify (object, "language_set");
break;
case PROP_TABS:
/* FIXME I'm not sure if this is a memleak or not */
text_tag->values->tabs =
- pango_tab_array_copy (g_value_get_as_pointer (value));
+ pango_tab_array_copy (g_value_get_boxed (value));
- g_object_notify (G_OBJECT (text_tag), "tabs_set");
+ g_object_notify (object, "tabs_set");
size_changed = TRUE;
break;
case PROP_INVISIBLE:
+ g_warning ("The \"invisible\" property on GtkTextTag is not supported for GTK 2.0, it will be added in a future release. see http://bugzilla.gnome.org bug #66194 for status.");
text_tag->invisible_set = TRUE;
text_tag->values->invisible = g_value_get_boolean (value);
- g_object_notify (G_OBJECT (text_tag), "invisible_set");
+ g_object_notify (object, "invisible_set");
size_changed = TRUE;
break;
/* Whether the value should be used... */
case PROP_BACKGROUND_SET:
- case PROP_BACKGROUND_GDK_SET:
text_tag->bg_color_set = g_value_get_boolean (value);
break;
case PROP_FOREGROUND_SET:
- case PROP_FOREGROUND_GDK_SET:
text_tag->fg_color_set = g_value_get_boolean (value);
break;
if (!text_tag->bg_stipple_set &&
text_tag->values->appearance.bg_stipple)
{
- g_object_unref (G_OBJECT (text_tag->values->appearance.bg_stipple));
+ g_object_unref (text_tag->values->appearance.bg_stipple);
text_tag->values->appearance.bg_stipple = NULL;
}
break;
if (!text_tag->fg_stipple_set &&
text_tag->values->appearance.fg_stipple)
{
- g_object_unref (G_OBJECT (text_tag->values->appearance.fg_stipple));
+ g_object_unref (text_tag->values->appearance.fg_stipple);
text_tag->values->appearance.fg_stipple = NULL;
}
break;
case PROP_FAMILY_SET:
- text_tag->family_set = g_value_get_boolean (value);
- size_changed = TRUE;
- break;
-
case PROP_STYLE_SET:
- text_tag->style_set = g_value_get_boolean (value);
- size_changed = TRUE;
- break;
-
case PROP_VARIANT_SET:
- text_tag->variant_set = g_value_get_boolean (value);
- size_changed = TRUE;
- break;
-
case PROP_WEIGHT_SET:
- text_tag->weight_set = g_value_get_boolean (value);
- size_changed = TRUE;
- break;
-
case PROP_STRETCH_SET:
- text_tag->stretch_set = g_value_get_boolean (value);
- size_changed = TRUE;
- break;
-
case PROP_SIZE_SET:
- text_tag->size_set = g_value_get_boolean (value);
+ if (!g_value_get_boolean (value))
+ {
+ if (text_tag->values->font)
+ pango_font_description_unset_fields (text_tag->values->font,
+ get_property_font_set_mask (prop_id));
+ }
+ else
+ {
+ PangoFontMask changed_mask;
+
+ gtk_text_tag_ensure_font (text_tag);
+ changed_mask = set_font_desc_fields (text_tag->values->font,
+ get_property_font_set_mask (prop_id));
+ notify_fields_changed (G_OBJECT (text_tag), changed_mask);
+ }
+ break;
+
+ case PROP_SCALE_SET:
+ text_tag->scale_set = g_value_get_boolean (value);
size_changed = TRUE;
break;
*/
if (text_tag->table)
- g_signal_emit_by_name (G_OBJECT (text_tag->table),
+ g_signal_emit_by_name (text_tag->table,
"tag_changed",
text_tag, size_changed);
}
-static void
-get_color_arg (GValue *value, GdkColor *orig)
-{
- GdkColor *color;
-
- color = g_new (GdkColor, 1);
- *color = *orig;
- g_value_init (value, GTK_TYPE_GDK_COLOR);
- g_value_set_boxed (value, color);
-}
-
static void
gtk_text_tag_get_property (GObject *object,
guint prop_id,
GValue *value,
- GParamSpec *pspec,
- const gchar *trailer)
+ GParamSpec *pspec)
{
GtkTextTag *tag;
break;
case PROP_BACKGROUND_GDK:
- get_color_arg (value, &tag->values->appearance.bg_color);
+ g_value_set_boxed (value, &tag->values->appearance.bg_color);
break;
case PROP_FOREGROUND_GDK:
- get_color_arg (value, &tag->values->appearance.fg_color);
+ g_value_set_boxed (value, &tag->values->appearance.fg_color);
break;
case PROP_BACKGROUND_STIPPLE:
break;
case PROP_FONT:
- if (tag->family_set &&
- tag->style_set &&
- tag->variant_set &&
- tag->size_set &&
- tag->stretch_set &&
- tag->weight_set)
{
/* FIXME GValue imposes a totally gratuitous string copy
* here, we could just hand off string ownership
*/
- gchar *str = pango_font_description_to_string (&tag->values->font);
+ gchar *str;
+
+ gtk_text_tag_ensure_font (tag);
+
+ str = pango_font_description_to_string (tag->values->font);
g_value_set_string (value, str);
g_free (str);
}
break;
case PROP_FONT_DESC:
- if (tag->family_set &&
- tag->style_set &&
- tag->variant_set &&
- tag->size_set &&
- tag->stretch_set &&
- tag->weight_set)
- g_value_set_boxed (value, &tag->values->font);
+ gtk_text_tag_ensure_font (tag);
+ g_value_set_boxed (value, tag->values->font);
break;
case PROP_FAMILY:
- g_value_set_string (value, tag->values->font.family_name);
- break;
-
case PROP_STYLE:
- g_value_set_enum (value, tag->values->font.style);
- break;
-
case PROP_VARIANT:
- g_value_set_enum (value, tag->values->font.variant);
- break;
-
case PROP_WEIGHT:
- g_value_set_int (value, tag->values->font.weight);
- break;
-
case PROP_STRETCH:
- g_value_set_enum (value, tag->values->font.stretch);
- break;
-
case PROP_SIZE:
- g_value_set_int (value, tag->values->font.size);
- break;
-
case PROP_SIZE_POINTS:
- g_value_set_double (value, ((double)tag->values->font.size) / (double)PANGO_SCALE);
+ gtk_text_tag_ensure_font (tag);
+ switch (prop_id)
+ {
+ case PROP_FAMILY:
+ g_value_set_string (value, pango_font_description_get_family (tag->values->font));
+ break;
+
+ case PROP_STYLE:
+ g_value_set_enum (value, pango_font_description_get_style (tag->values->font));
+ break;
+
+ case PROP_VARIANT:
+ g_value_set_enum (value, pango_font_description_get_variant (tag->values->font));
+ break;
+
+ case PROP_WEIGHT:
+ g_value_set_int (value, pango_font_description_get_weight (tag->values->font));
+ break;
+
+ case PROP_STRETCH:
+ g_value_set_enum (value, pango_font_description_get_stretch (tag->values->font));
+ break;
+
+ case PROP_SIZE:
+ g_value_set_int (value, pango_font_description_get_size (tag->values->font));
+ break;
+
+ case PROP_SIZE_POINTS:
+ g_value_set_double (value, ((double)pango_font_description_get_size (tag->values->font)) / (double)PANGO_SCALE);
+ break;
+ }
+ break;
+
+ case PROP_SCALE:
+ g_value_set_double (value, tag->values->font_scale);
break;
case PROP_PIXELS_ABOVE_LINES:
break;
case PROP_LANGUAGE:
- g_value_set_string (value, tag->values->language);
+ g_value_set_string (value, pango_language_to_string (tag->values->language));
break;
case PROP_TABS:
break;
case PROP_BACKGROUND_SET:
- case PROP_BACKGROUND_GDK_SET:
g_value_set_boolean (value, tag->bg_color_set);
break;
case PROP_FOREGROUND_SET:
- case PROP_FOREGROUND_GDK_SET:
g_value_set_boolean (value, tag->fg_color_set);
break;
break;
case PROP_FAMILY_SET:
- g_value_set_boolean (value, tag->family_set);
- break;
-
case PROP_STYLE_SET:
- g_value_set_boolean (value, tag->style_set);
- break;
-
case PROP_VARIANT_SET:
- g_value_set_boolean (value, tag->variant_set);
- break;
-
case PROP_WEIGHT_SET:
- g_value_set_boolean (value, tag->weight_set);
- break;
-
case PROP_STRETCH_SET:
- g_value_set_boolean (value, tag->stretch_set);
- break;
-
case PROP_SIZE_SET:
- g_value_set_boolean (value, tag->size_set);
+ {
+ PangoFontMask set_mask = tag->values->font ? pango_font_description_get_set_fields (tag->values->font) : 0;
+ PangoFontMask test_mask = get_property_font_set_mask (prop_id);
+ g_value_set_boolean (value, (set_mask & test_mask) != 0);
+
+ break;
+ }
+
+ case PROP_SCALE_SET:
+ g_value_set_boolean (value, tag->scale_set);
break;
case PROP_PIXELS_ABOVE_LINES_SET:
* @priority: the new priority
*
* Sets the priority of a #GtkTextTag. Valid priorities are
- * start at 0 and go to one less than gtk_text_tag_table_size().
+ * start at 0 and go to one less than gtk_text_tag_table_get_size().
* Each tag in a table has a unique priority; setting the priority
* of one tag shifts the priorities of all the other tags in the
* table to maintain a unique priority for each tag. Higher priority
g_return_if_fail (GTK_IS_TEXT_TAG (tag));
g_return_if_fail (tag->table != NULL);
g_return_if_fail (priority >= 0);
- g_return_if_fail (priority < gtk_text_tag_table_size (tag->table));
+ g_return_if_fail (priority < gtk_text_tag_table_get_size (tag->table));
if (priority == tag->priority)
return;
*
* Return value: result of signal emission (whether the event was handled)
**/
-gint
+gboolean
gtk_text_tag_event (GtkTextTag *tag,
GObject *event_object,
GdkEvent *event,
const GtkTextIter *iter)
{
- gint retval = FALSE;
+ gboolean retval = FALSE;
g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
- g_return_val_if_fail (GTK_IS_OBJECT (event_object), FALSE);
+ g_return_val_if_fail (G_IS_OBJECT (event_object), FALSE);
g_return_val_if_fail (event != NULL, FALSE);
- g_signal_emit (G_OBJECT (tag),
+ g_signal_emit (tag,
signals[EVENT],
0,
event_object,
values->language = gtk_get_default_language ();
+ values->font_scale = 1.0;
+
return values;
}
+/**
+ * gtk_text_attributes_copy:
+ * @src: a #GtkTextAttributes to be copied
+ *
+ * Copies @src and returns a new #GtkTextAttributes.
+ *
+ * Return value: a copy of @src
+ **/
GtkTextAttributes*
gtk_text_attributes_copy (GtkTextAttributes *src)
{
return dest;
}
+GType
+gtk_text_attributes_get_type (void)
+{
+ static GType our_type = 0;
+
+ if (our_type == 0)
+ our_type = g_boxed_type_register_static ("GtkTextAttributes",
+ (GBoxedCopyFunc) gtk_text_attributes_ref,
+ (GBoxedFreeFunc) gtk_text_attributes_unref);
+
+ return our_type;
+}
+
/**
* gtk_text_attributes_copy_values:
* @src: a #GtkTextAttributes
* @dest: another #GtkTextAttributes
*
* Copies the values from @src to @dest so that @dest has the same values
- * as @src.
+ * as @src. Frees existing values in @dest.
**/
void
gtk_text_attributes_copy_values (GtkTextAttributes *src,
/* Add refs */
if (src->appearance.bg_stipple)
- gdk_bitmap_ref (src->appearance.bg_stipple);
+ g_object_ref (src->appearance.bg_stipple);
if (src->appearance.fg_stipple)
- gdk_bitmap_ref (src->appearance.fg_stipple);
+ g_object_ref (src->appearance.fg_stipple);
/* Remove refs */
if (dest->appearance.bg_stipple)
- gdk_bitmap_unref (dest->appearance.bg_stipple);
+ g_object_unref (dest->appearance.bg_stipple);
if (dest->appearance.fg_stipple)
- gdk_bitmap_unref (dest->appearance.fg_stipple);
-
- if (dest->language)
- g_free (dest->language);
+ g_object_unref (dest->appearance.fg_stipple);
- if (dest->font.family_name)
- g_free (dest->font.family_name);
+ if (dest->font)
+ pango_font_description_free (dest->font);
/* Copy */
orig_refcount = dest->refcount;
if (src->tabs)
dest->tabs = pango_tab_array_copy (src->tabs);
- dest->language = g_strdup (src->language);
+ dest->language = src->language;
- dest->font.family_name = g_strdup (src->font.family_name);
+ if (dest->font)
+ dest->font = pango_font_description_copy (src->font);
dest->refcount = orig_refcount;
dest->realized = FALSE;
}
+/**
+ * gtk_text_attributes_ref:
+ * @values: a #GtkTextAttributes
+ *
+ * Increments the reference count on @values.
+ **/
void
gtk_text_attributes_ref (GtkTextAttributes *values)
{
values->refcount += 1;
}
+/**
+ * gtk_text_attributes_unref:
+ * @values: a #GtkTextAttributes
+ *
+ * Decrements the reference count on @values, freeing the structure
+ * if the reference count reaches 0.
+ **/
void
gtk_text_attributes_unref (GtkTextAttributes *values)
{
g_assert (!values->realized);
if (values->appearance.bg_stipple)
- gdk_bitmap_unref (values->appearance.bg_stipple);
+ g_object_unref (values->appearance.bg_stipple);
if (values->appearance.fg_stipple)
- gdk_bitmap_unref (values->appearance.fg_stipple);
+ g_object_unref (values->appearance.fg_stipple);
if (values->tabs)
pango_tab_array_free (values->tabs);
- if (values->language)
- g_free (values->language);
-
- if (values->font.family_name)
- g_free (values->font.family_name);
+ if (values->font)
+ pango_font_description_free (values->font);
g_free (values);
}
GtkTextTag *tag = tags[n];
GtkTextAttributes *vals = tag->values;
+ g_assert (tag->table != NULL);
if (n > 0)
g_assert (tags[n]->priority > tags[n-1]->priority);
if (tag->bg_stipple_set)
{
- gdk_bitmap_ref (vals->appearance.bg_stipple);
+ g_object_ref (vals->appearance.bg_stipple);
if (dest->appearance.bg_stipple)
- gdk_bitmap_unref (dest->appearance.bg_stipple);
+ g_object_unref (dest->appearance.bg_stipple);
dest->appearance.bg_stipple = vals->appearance.bg_stipple;
dest->appearance.draw_bg = TRUE;
if (tag->fg_stipple_set)
{
- gdk_bitmap_ref (vals->appearance.fg_stipple);
+ g_object_ref (vals->appearance.fg_stipple);
if (dest->appearance.fg_stipple)
- gdk_bitmap_unref (dest->appearance.fg_stipple);
+ g_object_unref (dest->appearance.fg_stipple);
dest->appearance.fg_stipple = vals->appearance.fg_stipple;
}
- if (tag->family_set)
- {
- if (dest->font.family_name)
- g_free (dest->font.family_name);
-
- dest->font.family_name = g_strdup (vals->font.family_name);
- }
-
- if (tag->style_set)
- dest->font.style = vals->font.style;
-
- if (tag->variant_set)
- dest->font.variant = vals->font.variant;
-
- if (tag->weight_set)
- dest->font.weight = vals->font.weight;
-
- if (tag->stretch_set)
- dest->font.stretch = vals->font.stretch;
-
- if (tag->size_set)
- dest->font.size = vals->font.size;
-
+ if (vals->font)
+ {
+ if (dest->font)
+ pango_font_description_merge (dest->font, vals->font, TRUE);
+ else
+ dest->font = pango_font_description_copy (vals->font);
+ }
+
+ /* multiply all the scales together to get a composite */
+ if (tag->scale_set)
+ dest->font_scale *= vals->font_scale;
+
if (tag->justification_set)
dest->justification = vals->justification;
dest->bg_full_height = vals->bg_full_height;
if (tag->language_set)
- {
- g_free (dest->language);
- dest->language = g_strdup (vals->language);
- }
+ dest->language = vals->language;
++n;
}
g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
return
- tag->family_set ||
- tag->style_set ||
- tag->variant_set ||
- tag->weight_set ||
- tag->size_set ||
- tag->stretch_set ||
+ (tag->values->font && pango_font_description_get_set_fields (tag->values->font) != 0) ||
+ tag->scale_set ||
tag->justification_set ||
tag->left_margin_set ||
tag->indent_set ||