]> git.0d.be Git - empathy.git/blob - libempathy-gtk/empathy-theme-utils.c
56b758e2a8ec4c6c17774289ff289283b02f4834
[empathy.git] / libempathy-gtk / empathy-theme-utils.c
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2 /*
3  * Copyright (C) 2007 Imendio AB
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the
17  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18  * Boston, MA 02111-1307, USA.
19  */
20
21 #include <config.h>
22
23 #include <gtk/gtktexttag.h>
24
25 #include "empathy-theme-utils.h"
26
27 void
28 empathy_theme_utils_ensure_tag_by_name (GtkTextBuffer *buffer, const gchar *name)
29 {
30         GtkTextTagTable *table;
31         GtkTextTag      *tag;
32
33         table = gtk_text_buffer_get_tag_table (buffer);
34         tag = gtk_text_tag_table_lookup (table, name);
35
36         if (!tag) {
37                 gtk_text_buffer_create_tag (buffer,
38                                             name,
39                                             NULL);
40         }
41 }
42
43 GtkTextTag *
44 empathy_theme_utils_init_tag_by_name (GtkTextTagTable *table, const gchar *name)
45 {
46         GtkTextTag *tag;
47
48         tag = gtk_text_tag_table_lookup (table, name);
49
50         if (!tag) {
51                 return gtk_text_tag_new (name);
52         }
53
54         /* Clear the old values so that we don't affect the new theme. */
55         g_object_set (tag,
56                       "background-set", FALSE,
57                       "foreground-set", FALSE,
58                       "invisible-set", FALSE,
59                       "justification-set", FALSE,
60                       "paragraph-background-set", FALSE,
61                       "pixels-above-lines-set", FALSE,
62                       "pixels-below-lines-set", FALSE,
63                       "rise-set", FALSE,
64                       "scale-set", FALSE,
65                       "size-set", FALSE,
66                       "style-set", FALSE,
67                       "weight-set", FALSE,
68                       NULL);
69
70         return tag;
71 }
72
73 void
74 empathy_theme_utils_add_tag (GtkTextTagTable *table, GtkTextTag *tag)
75 {
76         gchar      *name;
77         GtkTextTag *check_tag;
78
79         g_object_get (tag, "name", &name, NULL);
80         check_tag = gtk_text_tag_table_lookup (table, name);
81         g_free (name);
82         if (check_tag) {
83                 return;
84         }
85
86         gtk_text_tag_table_add (table, tag);
87
88         g_object_unref (tag);
89 }
90