-/*
- * Attributes
- */
-
-/**
- * gtk_text_attributes_new:
- *
- * Creates a #GtkTextAttributes, which describes
- * a set of properties on some text.
- *
- * Return value: a new #GtkTextAttributes
- **/
-GtkTextAttributes*
-gtk_text_attributes_new (void)
-{
- GtkTextAttributes *values;
-
- values = g_new0 (GtkTextAttributes, 1);
-
- /* 0 is a valid value for most of the struct */
-
- values->refcount = 1;
-
- 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)
-{
- GtkTextAttributes *dest;
-
- dest = gtk_text_attributes_new ();
- gtk_text_attributes_copy_values (src, dest);
-
- return dest;
-}
-
-/**
- * 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. Frees existing values in @dest.
- **/
-void
-gtk_text_attributes_copy_values (GtkTextAttributes *src,
- GtkTextAttributes *dest)
-{
- guint orig_refcount;
-
- g_return_if_fail (!dest->realized);
-
- if (src == dest)
- return;
-
- /* Add refs */
-
- if (src->appearance.bg_stipple)
- gdk_bitmap_ref (src->appearance.bg_stipple);
-
- if (src->appearance.fg_stipple)
- gdk_bitmap_ref (src->appearance.fg_stipple);
-
- /* Remove refs */
-
- if (dest->appearance.bg_stipple)
- gdk_bitmap_unref (dest->appearance.bg_stipple);
-
- if (dest->appearance.fg_stipple)
- gdk_bitmap_unref (dest->appearance.fg_stipple);
-
- if (dest->font)
- pango_font_description_free (dest->font);
-
- /* Copy */
- orig_refcount = dest->refcount;
-
- *dest = *src;
-
- if (src->tabs)
- dest->tabs = pango_tab_array_copy (src->tabs);
-
- dest->language = src->language;
-
- 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)
-{
- g_return_if_fail (values != NULL);
-
- 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_return_if_fail (values != NULL);
- g_return_if_fail (values->refcount > 0);
-
- values->refcount -= 1;
-
- if (values->refcount == 0)
- {
- g_assert (!values->realized);
-
- if (values->appearance.bg_stipple)
- gdk_bitmap_unref (values->appearance.bg_stipple);
-
- if (values->appearance.fg_stipple)
- gdk_bitmap_unref (values->appearance.fg_stipple);
-
- if (values->tabs)
- pango_tab_array_free (values->tabs);
-
- if (values->font)
- pango_font_description_free (values->font);
-
- g_free (values);
- }
-}
-
-void
-_gtk_text_attributes_realize (GtkTextAttributes *values,
- GdkColormap *cmap,
- GdkVisual *visual)
-{
- g_return_if_fail (values != NULL);
- g_return_if_fail (values->refcount > 0);
- g_return_if_fail (!values->realized);
-
- /* It is wrong to use this colormap, FIXME */
- gdk_colormap_alloc_color (cmap,
- &values->appearance.fg_color,
- FALSE, TRUE);
-
- gdk_colormap_alloc_color (cmap,
- &values->appearance.bg_color,
- FALSE, TRUE);
-
- values->realized = TRUE;
-}
-
-void
-_gtk_text_attributes_unrealize (GtkTextAttributes *values,
- GdkColormap *cmap,
- GdkVisual *visual)
-{
- g_return_if_fail (values != NULL);
- g_return_if_fail (values->refcount > 0);
- g_return_if_fail (values->realized);
-
- gdk_colormap_free_colors (cmap,
- &values->appearance.fg_color, 1);
-
-
- gdk_colormap_free_colors (cmap,
- &values->appearance.bg_color, 1);
-
- values->appearance.fg_color.pixel = 0;
- values->appearance.bg_color.pixel = 0;
-
- values->realized = FALSE;
-}
-
-void
-_gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
- GtkTextTag** tags,
- guint n_tags)
-{
- guint n = 0;
-
- g_return_if_fail (!dest->realized);
-
- while (n < n_tags)
- {
- 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_color_set)
- {
- dest->appearance.bg_color = vals->appearance.bg_color;
-
- dest->appearance.draw_bg = TRUE;
- }
- if (tag->fg_color_set)
- dest->appearance.fg_color = vals->appearance.fg_color;
-
- if (tag->bg_stipple_set)
- {
- gdk_bitmap_ref (vals->appearance.bg_stipple);
- if (dest->appearance.bg_stipple)
- gdk_bitmap_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);
- if (dest->appearance.fg_stipple)
- gdk_bitmap_unref (dest->appearance.fg_stipple);
- dest->appearance.fg_stipple = vals->appearance.fg_stipple;
- }
-
- 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;
-
- if (vals->direction != GTK_TEXT_DIR_NONE)
- dest->direction = vals->direction;
-
- if (tag->left_margin_set)
- dest->left_margin = vals->left_margin;
-
- if (tag->indent_set)
- dest->indent = vals->indent;
-
- if (tag->rise_set)
- dest->appearance.rise = vals->appearance.rise;
-
- if (tag->right_margin_set)
- dest->right_margin = vals->right_margin;
-
- if (tag->pixels_above_lines_set)
- dest->pixels_above_lines = vals->pixels_above_lines;
-
- if (tag->pixels_below_lines_set)
- dest->pixels_below_lines = vals->pixels_below_lines;
-
- if (tag->pixels_inside_wrap_set)
- dest->pixels_inside_wrap = vals->pixels_inside_wrap;
-
- if (tag->tabs_set)
- {
- if (dest->tabs)
- pango_tab_array_free (dest->tabs);
- dest->tabs = pango_tab_array_copy (vals->tabs);
- }
-
- if (tag->wrap_mode_set)
- dest->wrap_mode = vals->wrap_mode;
-
- if (tag->underline_set)
- dest->appearance.underline = vals->appearance.underline;
-
- if (tag->strikethrough_set)
- dest->appearance.strikethrough = vals->appearance.strikethrough;
-
- if (tag->invisible_set)
- dest->invisible = vals->invisible;
-
- if (tag->editable_set)
- dest->editable = vals->editable;
-
- if (tag->bg_full_height_set)
- dest->bg_full_height = vals->bg_full_height;
-
- if (tag->language_set)
- dest->language = vals->language;
-
- ++n;
- }
-}
-
-gboolean
-_gtk_text_tag_affects_size (GtkTextTag *tag)
-{
- g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
-
- return
- (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 ||
- tag->rise_set ||
- tag->right_margin_set ||
- tag->pixels_above_lines_set ||
- tag->pixels_below_lines_set ||
- tag->pixels_inside_wrap_set ||
- tag->tabs_set ||
- tag->underline_set ||
- tag->wrap_mode_set ||
- tag->invisible_set;
-}
-
-gboolean
-_gtk_text_tag_affects_nonsize_appearance (GtkTextTag *tag)
-{
- g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
-
- return
- tag->bg_color_set ||
- tag->bg_stipple_set ||
- tag->fg_color_set ||
- tag->fg_stipple_set ||
- tag->strikethrough_set ||
- tag->bg_full_height_set;
-}