GtkTexTag utility functions
- From: Gustavo Joćo Alves Marques Carneiro <ee96090 fe up pt>
- To: gtk-devel-list gnome org
- Subject: GtkTexTag utility functions
- Date: Thu, 3 May 2001 15:23:00 +0100 (WEST)
I find these functions useful, so maybe others will too. Can they be
included in GTK?
/* -*- Mode: C; c-file-style: "gnu"; -*- */
#include "misc.h"
/**
* gtk_text_tag_copy_values: -copy attributes from one tag to another
* @dest: a #GtkTextTag
* @src: another #GtkTextTag
*
* Copy the contents of tag @src into tag @dest. The destination tag's
* name and table are not changed, only text attributes.
**/
void gtk_text_tag_copy_values (GtkTextTag *dest, GtkTextTag *src)
{
g_return_if_fail (dest);
g_return_if_fail (src);
g_return_if_fail (GTK_IS_TEXT_TAG (dest));
g_return_if_fail (GTK_IS_TEXT_TAG (src));
gtk_text_attributes_copy_values (src->values, dest->values);
#define _COPY_FLAG(flag) dest->flag = src->flag
_COPY_FLAG (bg_color_set);
_COPY_FLAG (bg_color_set);
_COPY_FLAG (bg_stipple_set);
_COPY_FLAG (fg_color_set);
_COPY_FLAG (family_set);
_COPY_FLAG (style_set);
_COPY_FLAG (variant_set);
_COPY_FLAG (weight_set);
_COPY_FLAG (stretch_set);
_COPY_FLAG (size_set);
_COPY_FLAG (fg_stipple_set);
_COPY_FLAG (justification_set);
_COPY_FLAG (left_margin_set);
_COPY_FLAG (indent_set);
_COPY_FLAG (rise_set);
_COPY_FLAG (strikethrough_set);
_COPY_FLAG (right_margin_set);
_COPY_FLAG (pixels_above_lines_set);
_COPY_FLAG (pixels_below_lines_set);
_COPY_FLAG (pixels_inside_wrap_set);
_COPY_FLAG (tabs_set);
_COPY_FLAG (underline_set);
_COPY_FLAG (wrap_mode_set);
_COPY_FLAG (bg_full_height_set);
_COPY_FLAG (invisible_set);
_COPY_FLAG (editable_set);
_COPY_FLAG (language_set);
#undef _COPY_FLAG
}
/**
* gtk_text_tag_copy: -duplicate a tag
* @tag: the #GtkTextTag to duplicate
*
* Create a new #GtkTextTag with same values as @tag. The returned
* #GtkTextTag doesn't belong to any $GtkTextTagTable.
*
* Return value: the newly created #GtkTextTag
**/
GtkTextTag* gtk_text_tag_copy (GtkTextTag *tag)
{
GtkTextTag *ntag;
g_return_val_if_fail (tag, NULL);
g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), NULL);
ntag = gtk_text_tag_new (tag->name);
gtk_text_tag_copy_values (ntag, tag);
return ntag;
}
/**
* gtk_text_tag_table_install:
* @table: a #GtkTextTagTable
* @tag: a #GtkTextTag
*
* Add @tag to the tag table @table or, if a tag with the same name
* already exists in @table, update the existing tag in the table with
* the values in @tag. If the tag is anonymous, it is simply added to
* the table.
**/
void gtk_text_tag_table_install (GtkTextTagTable *table, GtkTextTag *tag)
{
GtkTextTag *existing_tag;
g_return_if_fail (table);
g_return_if_fail (GTK_IS_TEXT_TAG_TABLE (table));
g_return_if_fail (tag);
g_return_if_fail (GTK_IS_TEXT_TAG (tag));
if (!tag->name)
gtk_text_tag_table_add(table, tag);
else {
existing_tag = gtk_text_tag_table_lookup(table, tag->name);
if (existing_tag)
gtk_text_tag_copy_values(existing_tag, tag);
else
gtk_text_tag_table_add(table, tag);
}
}
--
Gustavo J. A. M. Carneiro
[http://linuxdeec.fe.up.pt/~ee96090]
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]