File: thinice_theme_main.c

package info (click to toggle)
gtk-engines-thinice 1.0.3-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 620 kB
  • ctags: 87
  • sloc: sh: 7,275; ansic: 2,225; makefile: 73
file content (357 lines) | stat: -rw-r--r-- 9,099 bytes parent folder | download
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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#include "thinice_theme.h"
#include <gmodule.h>

/* Theme functions to export */
void                theme_init(GtkThemeEngine * engine);
void                theme_exit(void);

/* Exported vtable from th_draw */

extern GtkStyleClass thinice_default_class;

/* internals */

/* external theme functions called */

static struct
  {
    gchar       *name;
    guint        token;
  }
theme_symbols[] =
{
  { "rect_scrollbar",      TOKEN_RECTSCROLLBAR },
  { "scrollbar_marks",     TOKEN_SCROLLBARMARKS },
  { "scroll_button_marks", TOKEN_SCROLLBUTTONMARKS },
  { "handlebox_marks",     TOKEN_HANDLEBOXMARKS },
  
  { "TRUE",                TOKEN_TRUE },
  { "FALSE",               TOKEN_FALSE },
};

static guint n_theme_symbols = sizeof(theme_symbols) / sizeof(theme_symbols[0]);

static guint
theme_parse_scrollmarks(GScanner *scanner,
                        ThemeRcData *theme_data)
{
  guint               token, which_token;
  guint               set_to;
  
  which_token = g_scanner_get_next_token(scanner);
  if (!((which_token == TOKEN_SCROLLBARMARKS) ||
        (which_token == TOKEN_SCROLLBUTTONMARKS)))
    return TOKEN_SCROLLBARMARKS;
  
  token = g_scanner_get_next_token(scanner);
  if (token != G_TOKEN_EQUAL_SIGN)
    return G_TOKEN_EQUAL_SIGN;
  
  token = g_scanner_get_next_token(scanner);
  if (token == TOKEN_TRUE)
    set_to = MARKS_ON;
  else if (token == TOKEN_FALSE)
    set_to = MARKS_OFF;
  else
    return TOKEN_TRUE;

  switch (which_token) {
    case TOKEN_SCROLLBARMARKS:
      theme_data->scrollbar_marks = set_to;
      break;
    case TOKEN_SCROLLBUTTONMARKS:
    default:
      theme_data->scroll_button_marks = set_to;
      break;
  }

  return G_TOKEN_NONE;
}

static guint
theme_parse_scrollbar(GScanner *scanner,
                      ThemeRcData *theme_data)
{
  guint               token;
  
  token = g_scanner_get_next_token(scanner);
  if (token != TOKEN_RECTSCROLLBAR)
    return TOKEN_RECTSCROLLBAR;
  
  token = g_scanner_get_next_token(scanner);
  if (token != G_TOKEN_EQUAL_SIGN)
    return G_TOKEN_EQUAL_SIGN;
  
  token = g_scanner_get_next_token(scanner);
  if (token == TOKEN_TRUE)
    theme_data->scrollbar_type = SCROLL_RECT;
  else if (token == TOKEN_FALSE)
    theme_data->scrollbar_type = SCROLL_SHAPED;
  else
    return TOKEN_TRUE;

  return G_TOKEN_NONE;
}

static guint
theme_parse_handleboxmarks(GScanner *scanner,
                           ThemeRcData *theme_data)
{
  guint               token;
  
  token = g_scanner_get_next_token(scanner);
  if (token != TOKEN_HANDLEBOXMARKS)
    return TOKEN_HANDLEBOXMARKS;
  
  token = g_scanner_get_next_token(scanner);
  if (token != G_TOKEN_EQUAL_SIGN)
    return G_TOKEN_EQUAL_SIGN;
  
  token = g_scanner_get_next_token(scanner);
  if (token == TOKEN_TRUE)
    theme_data->handlebox_marks = MARKS_ON;
  else if (token == TOKEN_FALSE)
    theme_data->handlebox_marks = MARKS_OFF;
  else
    return TOKEN_TRUE;

  return G_TOKEN_NONE;
}

guint
theme_parse_rc_style(GScanner * scanner,
		     GtkRcStyle * rc_style)
{
  static GQuark       scope_id = 0;
  ThemeRcData        *theme_data;
  guint               old_scope;
  guint               token;
  guint               i;

  /* Set up a new scope in this scanner. */

  if (!scope_id)
    scope_id = g_quark_from_string("theme_engine");

  /* If we bail out due to errors, we *don't* reset the scope, so the
   * error messaging code can make sense of our tokens.
   */
  old_scope = g_scanner_set_scope(scanner, scope_id);
  
  /* Now check if we already added our symbols to this scope
   * (in some previous call to theme_parse_rc_style for the
   * same scanner.
   */

  if (!g_scanner_lookup_symbol(scanner, theme_symbols[0].name))
    {
      g_scanner_freeze_symbol_table(scanner);
      for (i = 0; i < n_theme_symbols; i++)
        {
          g_scanner_scope_add_symbol(scanner, scope_id,
              theme_symbols[i].name,
              GINT_TO_POINTER(theme_symbols[i].token));
        }
      g_scanner_thaw_symbol_table(scanner);
    }

  /* We're ready to go, now parse the top level */

  theme_data = g_new(ThemeRcData, 1);
  theme_data->scrollbar_type = DEFAULT_SCROLLSHAPE;
  theme_data->scrollbar_marks = DEFAULT_SCROLLBARMARKS;
  theme_data->scroll_button_marks = DEFAULT_SCROLLBUTTONMARKS;
  theme_data->handlebox_marks = DEFAULT_HANDLEBOXMARKS;

  token = g_scanner_peek_next_token(scanner);
  while (token != G_TOKEN_RIGHT_CURLY)
    {
      switch (token)
	{
        case TOKEN_RECTSCROLLBAR:
          token = theme_parse_scrollbar(scanner, theme_data);
          break;
        case TOKEN_SCROLLBUTTONMARKS:
        case TOKEN_SCROLLBARMARKS:
          token = theme_parse_scrollmarks(scanner, theme_data);
          break;
        case TOKEN_HANDLEBOXMARKS:
          token = theme_parse_handleboxmarks(scanner, theme_data);
          break;
	default:
	  g_scanner_get_next_token(scanner);
	  token = G_TOKEN_RIGHT_CURLY;
	  break;
	}

      if (token != G_TOKEN_NONE)
	{
	  g_free(theme_data);
	  return token;
	}
      token = g_scanner_peek_next_token(scanner);
    }

  g_scanner_get_next_token(scanner);

  rc_style->engine_data = theme_data;
  g_scanner_set_scope(scanner, old_scope);

  return G_TOKEN_NONE;
}

void
theme_merge_rc_style(GtkRcStyle * dest,
		     GtkRcStyle * src)
{
  ThemeRcData        *src_data = src->engine_data;
  ThemeRcData        *dest_data = dest->engine_data;

  if (!dest_data)
    {
      dest_data = g_new(ThemeRcData, 1);
      dest->engine_data = dest_data;
    }

  dest_data->scrollbar_type = src_data->scrollbar_type;
  dest_data->scrollbar_marks = src_data->scrollbar_marks;
  dest_data->scroll_button_marks = src_data->scroll_button_marks;
  dest_data->handlebox_marks = src_data->handlebox_marks;
}

void
theme_rc_style_to_style(GtkStyle * style,
			GtkRcStyle * rc_style)
{
  ThemeRcData        *data = rc_style->engine_data;
  ThemeStyleData     *style_data;

  style_data = g_new(ThemeStyleData, 1);
  style_data->scrollbar_type = data->scrollbar_type;
  style_data->scrollbar_marks = data->scrollbar_marks;
  style_data->scroll_button_marks = data->scroll_button_marks;
  style_data->handlebox_marks = data->handlebox_marks;

  style->klass = &thinice_default_class;
  style->engine_data = style_data;
}

void
theme_duplicate_style(GtkStyle * dest,
		      GtkStyle * src)
{
  ThemeStyleData     *dest_data;
  ThemeStyleData     *src_data = src->engine_data;

  dest_data = g_new(ThemeStyleData, 1);
  dest_data->scrollbar_type = src_data->scrollbar_type;
  dest_data->scrollbar_marks = src_data->scrollbar_marks;
  dest_data->scroll_button_marks = src_data->scroll_button_marks;
  dest_data->handlebox_marks = src_data->handlebox_marks;

  dest->klass = &thinice_default_class;
  dest->engine_data = dest_data;
}

void
theme_realize_style(GtkStyle * style)
{
}

void
theme_unrealize_style(GtkStyle * style)
{
}

void
theme_destroy_rc_style(GtkRcStyle * rc_style)
{
  ThemeRcData        *data = rc_style->engine_data;

  if (data)
    {
      g_free(data);
    }
}

void
theme_destroy_style(GtkStyle * style)
{
  ThemeStyleData     *data = style->engine_data;

  if (data)
    {
      g_free(data);
    }
}

void
theme_set_background(GtkStyle * style,
		     GdkWindow * window,
		     GtkStateType state_type)
{
  GdkPixmap          *pixmap;
  gint                parent_relative;

  g_return_if_fail(style != NULL);
  g_return_if_fail(window != NULL);

  if (style->bg_pixmap[state_type])
    {
      if (style->bg_pixmap[state_type] == (GdkPixmap *) GDK_PARENT_RELATIVE)
	{
	  pixmap = NULL;
	  parent_relative = TRUE;
	}
      else
	{
	  pixmap = style->bg_pixmap[state_type];
	  parent_relative = FALSE;
	}

      gdk_window_set_back_pixmap(window, pixmap, parent_relative);
    }
  else
    gdk_window_set_background(window, &style->bg[state_type]);
}

void
theme_init(GtkThemeEngine * engine)
{
    GtkRangeClass *rangeclass;

    engine->parse_rc_style = theme_parse_rc_style;
    engine->merge_rc_style = theme_merge_rc_style;
    engine->rc_style_to_style = theme_rc_style_to_style;
    engine->duplicate_style = theme_duplicate_style;
    engine->realize_style = theme_realize_style;
    engine->unrealize_style = theme_unrealize_style;
    engine->destroy_rc_style = theme_destroy_rc_style;
    engine->destroy_style = theme_destroy_style;
    engine->set_background = theme_set_background;
    
    rangeclass = (GtkRangeClass *)gtk_type_class(gtk_range_get_type());
    rangeclass->slider_width = DEFAULT_SLIDER_WIDTH;
    rangeclass->stepper_size = DEFAULT_SLIDER_WIDTH;
    rangeclass->min_slider_size = DEFAULT_MIN_SLIDER_SIZE;
}

void
theme_exit(void)
{
  printf("ThinIce Theme Exit\n* Need to add memory deallocation code here *\n");
}

/* The following function will be called by GTK+ when the module
 * is loaded and checks to see if we are compatible with the
 * version of GTK+ that loads us.
*/
G_MODULE_EXPORT const gchar* g_module_check_init (GModule *module);

const gchar*
g_module_check_init (GModule *module)
{
	return gtk_check_version(GTK_MAJOR_VERSION,
				 GTK_MINOR_VERSION,
				 GTK_MICRO_VERSION - GTK_INTERFACE_AGE);
}