1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /* This file is part of the GtkHTML library. |
---|
3 | |
---|
4 | Copyright (C) 2000 Helix Code, Inc. |
---|
5 | |
---|
6 | This library is free software; you can redistribute it and/or |
---|
7 | modify it under the terms of the GNU Library General Public |
---|
8 | License as published by the Free Software Foundation; either |
---|
9 | version 2 of the License, or (at your option) any later version. |
---|
10 | |
---|
11 | This library is distributed in the hope that it will be useful, |
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | Library General Public License for more details. |
---|
15 | |
---|
16 | You should have received a copy of the GNU Library General Public License |
---|
17 | along with this library; see the file COPYING.LIB. If not, write to |
---|
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
19 | Boston, MA 02111-1307, USA. |
---|
20 | */ |
---|
21 | |
---|
22 | #include <config.h> |
---|
23 | #include "htmlcolor.h" |
---|
24 | #include "htmlcolorset.h" |
---|
25 | #include "htmlpainter.h" |
---|
26 | |
---|
27 | |
---|
28 | |
---|
29 | HTMLColorSet * |
---|
30 | html_colorset_new (GtkWidget *w) |
---|
31 | { |
---|
32 | HTMLColorSet *s; |
---|
33 | |
---|
34 | s = g_new0 (HTMLColorSet, 1); |
---|
35 | |
---|
36 | /* these are default color settings */ |
---|
37 | s->color [HTMLLinkColor] = html_color_new_from_rgb (0, 0, 0xffff); |
---|
38 | s->color [HTMLALinkColor] = html_color_new_from_rgb (0, 0, 0xffff); |
---|
39 | s->color [HTMLVLinkColor] = html_color_new_from_rgb (0, 0, 0xffff); |
---|
40 | s->color [HTMLSpellErrorColor] = html_color_new_from_rgb (0xffff, 0, 0); |
---|
41 | |
---|
42 | if (w) { |
---|
43 | GtkStyle *style = gtk_widget_get_style (w); |
---|
44 | html_colorset_set_style (s, style); |
---|
45 | } else { |
---|
46 | s->color [HTMLBgColor] = html_color_new_from_rgb (0xffff, 0xffff, 0xffff); |
---|
47 | s->color [HTMLHighlightColor] = html_color_new_from_rgb (0x7fff, 0x7fff, 0xffff); |
---|
48 | s->color [HTMLHighlightTextColor] = html_color_new (); |
---|
49 | s->color [HTMLHighlightNFColor] = html_color_new (); |
---|
50 | s->color [HTMLHighlightTextNFColor] = html_color_new (); |
---|
51 | s->color [HTMLTextColor] = html_color_new (); |
---|
52 | } |
---|
53 | |
---|
54 | return s; |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | void |
---|
59 | html_colorset_destroy (HTMLColorSet *set) |
---|
60 | { |
---|
61 | int i; |
---|
62 | |
---|
63 | g_return_if_fail (set != NULL); |
---|
64 | |
---|
65 | for (i = 0; i < HTMLColors; i++) { |
---|
66 | if (set->color[i] != NULL) |
---|
67 | html_color_unref (set->color[i]); |
---|
68 | } |
---|
69 | |
---|
70 | if (set->slaves) |
---|
71 | g_slist_free (set->slaves); |
---|
72 | |
---|
73 | g_free (set); |
---|
74 | } |
---|
75 | |
---|
76 | void |
---|
77 | html_colorset_add_slave (HTMLColorSet *set, HTMLColorSet *slave) |
---|
78 | { |
---|
79 | set->slaves = g_slist_prepend (set->slaves, slave); |
---|
80 | } |
---|
81 | |
---|
82 | void |
---|
83 | html_colorset_set_color (HTMLColorSet *s, GdkColor *color, HTMLColorId idx) |
---|
84 | { |
---|
85 | GSList *cur; |
---|
86 | HTMLColorSet *cs; |
---|
87 | |
---|
88 | html_color_set (s->color [idx], color); |
---|
89 | s->changed [idx] = TRUE; |
---|
90 | |
---|
91 | /* forward change to slaves */ |
---|
92 | cur = s->slaves; |
---|
93 | while (cur) { |
---|
94 | cs = (HTMLColorSet *) cur->data; |
---|
95 | html_colorset_set_color (cs, color, idx); |
---|
96 | cur = cur->next; |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | HTMLColor * |
---|
101 | html_colorset_get_color (HTMLColorSet *s, HTMLColorId idx) |
---|
102 | { |
---|
103 | return s->color [idx]; |
---|
104 | } |
---|
105 | |
---|
106 | HTMLColor * |
---|
107 | html_colorset_get_color_allocated (HTMLPainter *painter, HTMLColorId idx) |
---|
108 | { |
---|
109 | HTMLColorSet *s = painter->color_set; |
---|
110 | |
---|
111 | html_color_alloc (s->color [idx], painter); |
---|
112 | return s->color [idx]; |
---|
113 | } |
---|
114 | |
---|
115 | void |
---|
116 | html_colorset_set_by (HTMLColorSet *s, HTMLColorSet *o) |
---|
117 | { |
---|
118 | HTMLColorId i; |
---|
119 | |
---|
120 | for (i=0; i < HTMLColors; i++) { |
---|
121 | html_colorset_set_color (s, &o->color [i]->color, i); |
---|
122 | /* unset the changed flag */ |
---|
123 | s->changed [i] = FALSE; |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | void |
---|
128 | html_colorset_set_unchanged (HTMLColorSet *s, HTMLColorSet *o) |
---|
129 | { |
---|
130 | HTMLColorId i; |
---|
131 | |
---|
132 | for (i=0; i < HTMLColors; i++) { |
---|
133 | if (!s->changed[i]) { |
---|
134 | html_colorset_set_color (s, &o->color [i]->color, i); |
---|
135 | s->changed [i] = FALSE; |
---|
136 | } |
---|
137 | } |
---|
138 | } |
---|
139 | |
---|
140 | #define SET_GCOLOR(t,c) \ |
---|
141 | if (!s->changed [HTML ## t ## Color]) { \ |
---|
142 | if (s->color [HTML ## t ## Color]) html_color_unref (s->color [HTML ## t ## Color]); \ |
---|
143 | s->color [HTML ## t ## Color] = html_color_new_from_gdk_color (&c); \ |
---|
144 | } |
---|
145 | |
---|
146 | void |
---|
147 | html_colorset_set_style (HTMLColorSet *s, GtkStyle *style) |
---|
148 | { |
---|
149 | SET_GCOLOR (Bg, style->base [GTK_STATE_NORMAL]); |
---|
150 | SET_GCOLOR (Text, style->text [GTK_STATE_NORMAL]); |
---|
151 | SET_GCOLOR (Highlight, style->bg [GTK_STATE_SELECTED]); |
---|
152 | SET_GCOLOR (HighlightText, style->fg [GTK_STATE_SELECTED]); |
---|
153 | SET_GCOLOR (HighlightNF, style->bg [GTK_STATE_ACTIVE]); |
---|
154 | SET_GCOLOR (HighlightTextNF, style->fg [GTK_STATE_ACTIVE]); |
---|
155 | } |
---|