Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/gtk-engine/src/olpc-rc-style.c
blob: a71b087f1e91c4bf3999af41ce0a52f66288cd60 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
/* olpc - cairo based gtk+ theme
 *
 * Copyright © 2005 Red Hat, Inc.
 * Based on CGE by Julien Boulnois.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */

#include "olpc-style.h"
#include "olpc-rc-style.h"

#include <gtk/gtk.h>
#include <string.h>

static void	olpc_rc_style_init		(OlpcRcStyle *style);
static void	olpc_rc_style_class_init	(OlpcRcStyleClass *klass);
static void	olpc_rc_style_finalize		(GObject *object);

enum
{
    TOKEN_WINDOW_TOP_COLOR = G_TOKEN_LAST + 1,
    TOKEN_WINDOW_BOTTOM_COLOR
};

static struct
{
    gchar *name;
    guint token;
}
theme_symbols[] =
{
    { "window-top-color",	TOKEN_WINDOW_TOP_COLOR },
    { "window-bottom-color",	TOKEN_WINDOW_BOTTOM_COLOR }
};

static GtkRcStyleClass *parent_class;

GType olpc_type_rc_style = 0;

void
olpc_rc_style_register_type (GTypeModule *module)
{
    static const GTypeInfo object_info = {
	sizeof (OlpcRcStyleClass),
	(GBaseInitFunc) NULL,
	(GBaseFinalizeFunc) NULL,
	(GClassInitFunc) olpc_rc_style_class_init,
	NULL,           /* class_finalize */
	NULL,           /* class_data */
	sizeof (OlpcRcStyle),
	0,              /* n_preallocs */
	(GInstanceInitFunc) olpc_rc_style_init,
    };
  
    olpc_type_rc_style = g_type_module_register_type (module,
						      GTK_TYPE_RC_STYLE,
						      "OlpcRcStyle",
						      &object_info, 0);
}

static GtkStyle *
olpc_rc_style_create_style (GtkRcStyle *style)
{
    return g_object_new (OLPC_TYPE_STYLE, NULL);
}

static GTokenType
olpc_rc_style_parse_window_top_color (OlpcRcStyle	*rc_style,
				      GtkSettings	*settings,
				      GScanner		*scanner)
{
    GTokenType token;

    token = g_scanner_get_next_token (scanner);
    if (token != TOKEN_WINDOW_TOP_COLOR)
	return TOKEN_WINDOW_TOP_COLOR;

    token = g_scanner_get_next_token (scanner);
    if (token != G_TOKEN_EQUAL_SIGN)
	return G_TOKEN_EQUAL_SIGN;

    token = gtk_rc_parse_color (scanner,
				&rc_style->window_top_color);
    if (token != G_TOKEN_NONE)
	return token;

    rc_style->window_top_color.pixel = TRUE;

    return G_TOKEN_NONE;
}

static GTokenType
olpc_rc_style_parse_window_bottom_color (OlpcRcStyle	*rc_style,
					 GtkSettings	*settings,
					 GScanner	*scanner)
{
    GTokenType token;

    token = g_scanner_get_next_token (scanner);
    if (token != TOKEN_WINDOW_BOTTOM_COLOR)
	return TOKEN_WINDOW_BOTTOM_COLOR;

    token = g_scanner_get_next_token (scanner);
    if (token != G_TOKEN_EQUAL_SIGN)
	return G_TOKEN_EQUAL_SIGN;

    token = gtk_rc_parse_color (scanner,
				&rc_style->window_bottom_color);
    if (token != G_TOKEN_NONE)
	return token;

    rc_style->window_bottom_color.pixel = TRUE;

    return G_TOKEN_NONE;
}

static GTokenType
olpc_rc_style_parse (GtkRcStyle  *rc_style,
			 GtkSettings *settings,
			 GScanner    *scanner)
{
  static GQuark scope_id = 0;
  OlpcRcStyle *olpc_style = OLPC_RC_STYLE (rc_style);

  guint old_scope;
  GTokenType token, expected;
  gint i;

  /* Set up a new scope in this scanner. */
  if (!scope_id)
      scope_id = g_quark_from_string ("olpc_theme_engine");

  old_scope = g_scanner_set_scope (scanner, scope_id);

  /* Add symbols for this scope, (if not present already) */
  if (!g_scanner_lookup_symbol(scanner, theme_symbols[0].name)) {
      for (i = 0; i < G_N_ELEMENTS (theme_symbols); i++)
	  g_scanner_scope_add_symbol(scanner, scope_id,
				     theme_symbols[i].name,
				     GINT_TO_POINTER(theme_symbols[i].token));
  }

  /* Begin parsing top-level. Apparently a left curly brace has
   * already been consumed for use, but we're expected to consume the
   * final right closing brace. Weird. */
  while (1) {
      token = g_scanner_peek_next_token(scanner);
      if (token == G_TOKEN_RIGHT_CURLY) {
	  g_scanner_get_next_token (scanner);
	  expected = G_TOKEN_NONE;
	  break;
      }

      switch (token)
      {
      case TOKEN_WINDOW_TOP_COLOR:
	  expected = olpc_rc_style_parse_window_top_color (olpc_style, settings, scanner);
	  break;
      case TOKEN_WINDOW_BOTTOM_COLOR:
	  expected = olpc_rc_style_parse_window_bottom_color (olpc_style, settings, scanner);
	  break;
      default:
	  g_scanner_get_next_token (scanner);
	  expected = G_TOKEN_RIGHT_CURLY;
	  break;
      }

      if (expected != G_TOKEN_NONE)
	  break;
  }

  /* On success, restore the previous scope. (For errors, we need the
   * current scope to format a proper error message.) */
  if (expected == G_TOKEN_NONE)
      g_scanner_set_scope(scanner, old_scope);

  return expected;
}

static void
olpc_rc_style_merge (GtkRcStyle *dest,
		     GtkRcStyle *src)
{
    if (OLPC_IS_RC_STYLE (src)) {

	OlpcRcStyle *olpc_dest = OLPC_RC_STYLE (dest);
	OlpcRcStyle *olpc_src = OLPC_RC_STYLE (src);

	if (olpc_src->window_top_color.pixel)
	    olpc_dest->window_top_color = olpc_src->window_top_color;

	if (olpc_src->window_bottom_color.pixel)
	    olpc_dest->window_bottom_color = olpc_src->window_bottom_color;
    }

    parent_class->merge (dest, src);
}

static void
olpc_rc_style_init (OlpcRcStyle *rc_style)
{
}

static void
olpc_rc_style_class_init (OlpcRcStyleClass *klass)
{
    GtkRcStyleClass *rc_style_class = GTK_RC_STYLE_CLASS (klass);
    GObjectClass *object_class = G_OBJECT_CLASS (klass);

    parent_class = g_type_class_peek_parent (klass);

    rc_style_class->parse = olpc_rc_style_parse;
    rc_style_class->merge = olpc_rc_style_merge;
    rc_style_class->create_style = olpc_rc_style_create_style;

    object_class->finalize = olpc_rc_style_finalize;
}

static void
olpc_rc_style_finalize (GObject *object)
{
    /* OlpcRcStyle *rc_style = OLPC_RC_STYLE (object);
       We would free anything necessary in rc_style here. */
 
    G_OBJECT_CLASS (parent_class)->finalize (object);
}