summaryrefslogtreecommitdiffstats
path: root/tdegtk/tdegtk-engine.c
blob: fbf07a8ed105d1357bd2f89042b1c684da89624f (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
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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
/* The TdeGtk Theming Engine for Gtk+.
 * Copyright (C) 2011 Canonical Ltd
 *
 * This  library is free  software; you can  redistribute it and/or
 * modify it  under  the terms  of the  GNU Lesser  General  Public
 * License  as published  by the Free  Software  Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License  along  with  this library;  if not,  write to  the Free
 * Software Foundation, Inc., 51  Franklin St, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 *
 * Authored by Andrea Cimitan <andrea.cimitan@canonical.com>
 *
 */

#include <cairo.h>
#include <cairo-gobject.h>
#include <gtk/gtk.h>

#include "tdegtk.h"
#include "tdegtk-cairo-support.h"
#include "tdegtk-draw.h"
#include "tdegtk-engine.h"
#include "tdegtk-support.h"
#include "tdegtk-types.h"

#define TDEGTK_NAMESPACE "tdegtk"

#define TDEGTK_CAIRO_INIT \
        cairo_set_line_width (cr, 1.0); \
        cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE); \
        cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);

G_DEFINE_DYNAMIC_TYPE (TdeGtkEngine, tdegtk_engine, GTK_TYPE_THEMING_ENGINE)

static void
tdegtk_engine_render_activity (GtkThemingEngine *engine,
                              cairo_t          *cr,
                              gdouble           x,
                              gdouble           y,
                              gdouble           width,
                              gdouble           height)
{
	TdeGtkStyleFunctions *style_functions;
	const GtkWidgetPath *path;
	
	TDEGTK_CAIRO_INIT
	
	tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
	path = gtk_theming_engine_get_path (engine);
	
	if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINNER)) {
		GTK_THEMING_ENGINE_CLASS (tdegtk_engine_parent_class)->render_activity (engine, cr, x, y, width, height);
	}
	else {
		style_functions->draw_activity (engine, cr, x, y, width, height);
	}
}

static void
tdegtk_engine_render_arrow (GtkThemingEngine *engine,
                           cairo_t          *cr,
                           gdouble           angle,
                           gdouble           x,
                           gdouble           y,
                           gdouble           size)
{
	TdeGtkStyleFunctions *style_functions;
	
	TDEGTK_CAIRO_INIT
	
	tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
	
	style_functions->draw_arrow (engine, cr, angle, x, y, size);
}

static void
tdegtk_engine_render_background (GtkThemingEngine *engine,
                                cairo_t          *cr,
                                gdouble           x,
                                gdouble           y,
                                gdouble           width,
                                gdouble           height)
{
	TdeGtkStyleFunctions *style_functions;
	const GtkWidgetPath *path;
	GtkRegionFlags flags;
	
	TDEGTK_CAIRO_INIT
	
	tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
	path = gtk_theming_engine_get_path (engine);
	
	if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_BUTTON) &&
		gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINBUTTON)
		) {
		style_functions->draw_spinbutton_background (engine, cr, x, y, width, height);
	}
	else if (!gtk_widget_path_is_type (path, GTK_TYPE_ICON_VIEW) &&
		gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_VIEW) &&
		gtk_theming_engine_has_region (engine, GTK_STYLE_REGION_COLUMN, &flags)
		) {
		style_functions->draw_cell_background (engine, cr, x, y, width, height, flags);
	}
	else {
		style_functions->draw_common_background (engine, cr, x, y, width, height);
	}
}

static void
tdegtk_engine_render_check (GtkThemingEngine *engine,
                           cairo_t          *cr,
                           gdouble           x,
                           gdouble           y,
                           gdouble           width,
                           gdouble           height)
{
	TdeGtkStyleFunctions *style_functions;
	
	TDEGTK_CAIRO_INIT
	
	tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
	
	style_functions->draw_check (engine, cr, x, y, width, height);
}

static void
tdegtk_engine_render_expander (GtkThemingEngine *engine,
                              cairo_t          *cr,
                              gdouble           x,
                              gdouble           y,
                              gdouble           width,
                              gdouble           height)
{
	TdeGtkStyleFunctions *style_functions;
	
	TDEGTK_CAIRO_INIT
	
	tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
	
	style_functions->draw_expander (engine, cr, x, y, width, height);
}

static void
tdegtk_engine_render_extension (GtkThemingEngine *engine,
                               cairo_t          *cr,
                               gdouble           x,
                               gdouble           y,
                               gdouble           width,
                               gdouble           height,
                               GtkPositionType   gap_side)
{
	TdeGtkStyleFunctions *style_functions;
	
	TDEGTK_CAIRO_INIT
	
	tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
	
	style_functions->draw_extension (engine, cr, x, y, width, height, gap_side);
}

static void
tdegtk_engine_render_focus (GtkThemingEngine *engine,
                           cairo_t          *cr,
                           gdouble           x,
                           gdouble           y,
                           gdouble           width,
                           gdouble           height)
{
	TdeGtkStyleFunctions *style_functions;
	
	TDEGTK_CAIRO_INIT
	
	tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
	
	style_functions->draw_focus (engine, cr, x, y, width, height);
}

static void
tdegtk_engine_render_frame (GtkThemingEngine *engine,
                           cairo_t          *cr,
                           gdouble           x,
                           gdouble           y,
                           gdouble           width,
                           gdouble           height)
{
	TdeGtkStyleFunctions *style_functions;
	const GtkWidgetPath *path;
	GtkRegionFlags flags;
	
	TDEGTK_CAIRO_INIT
	
	tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
	path = gtk_theming_engine_get_path (engine);
	
	if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SEPARATOR)) {
		style_functions->draw_separator (engine, cr, x, y, width, height);
	}
	else if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_BUTTON) &&
		gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_SPINBUTTON)
		) {
		style_functions->draw_spinbutton_frame (engine, cr, x, y, width, height);
	}
	else if (!gtk_widget_path_is_type (path, GTK_TYPE_ICON_VIEW) &&
		gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_VIEW) &&
		gtk_theming_engine_has_region (engine, GTK_STYLE_REGION_COLUMN, &flags)
		) {
		style_functions->draw_cell_frame (engine, cr, x, y, width, height, flags);
	}
	else {
		style_functions->draw_common_frame (engine, cr, x, y, width, height);
	}
}

static void
tdegtk_engine_render_frame_gap (GtkThemingEngine *engine,
                               cairo_t          *cr,
                               gdouble           x,
                               gdouble           y,
                               gdouble           width,
                               gdouble           height,
                               GtkPositionType   gap_side,
                               gdouble           xy0_gap,
                               gdouble           xy1_gap)
{
	TdeGtkStyleFunctions *style_functions;
	
	TDEGTK_CAIRO_INIT
	
	tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
	
	if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_NOTEBOOK)) {
		style_functions->draw_notebook (engine, cr, x, y, width, height, gap_side, xy0_gap, xy1_gap);
	}
	else {
		style_functions->draw_frame_gap (engine, cr, x, y, width, height, gap_side, xy0_gap, xy1_gap);
	}
}

static void
tdegtk_engine_render_handle (GtkThemingEngine *engine,
                            cairo_t          *cr,
                            gdouble           x,
                            gdouble           y,
                            gdouble           width,
                            gdouble           height)
{
	TdeGtkStyleFunctions *style_functions;
	
	TDEGTK_CAIRO_INIT
	
	tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
	
	if (gtk_theming_engine_has_class (engine, GTK_STYLE_CLASS_GRIP)) {
		style_functions->draw_grip (engine, cr, x, y, width, height);
	}
	else {
		style_functions->draw_handle (engine, cr, x, y, width, height);
	}
}

static void
tdegtk_engine_render_line (GtkThemingEngine *engine,
                          cairo_t          *cr,
                          gdouble           x0,
                          gdouble           y0,
                          gdouble           x1,
                          gdouble           y1)
{
	TdeGtkStyleFunctions *style_functions;
	
	TDEGTK_CAIRO_INIT
	
	tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
	
	style_functions->draw_line (engine, cr, x0, y0, x1, y1);
}

static void
tdegtk_engine_render_option (GtkThemingEngine *engine,
                            cairo_t          *cr,
                            gdouble           x,
                            gdouble           y,
                            gdouble           width,
                            gdouble           height)
{
	TdeGtkStyleFunctions *style_functions;
	
	TDEGTK_CAIRO_INIT
	
	tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
	
	style_functions->draw_radio (engine, cr, x, y, width, height);
}

static void
tdegtk_engine_render_slider (GtkThemingEngine *engine,
                            cairo_t          *cr,
                            gdouble           x,
                            gdouble           y,
                            gdouble           width,
                            gdouble           height,
                            GtkOrientation    orientation)
{
	TdeGtkStyleFunctions *style_functions;
	
	TDEGTK_CAIRO_INIT
	
	tdegtk_lookup_functions (TDEGTK_ENGINE (engine), &style_functions);
	
	style_functions->draw_slider (engine, cr, x, y, width, height, orientation);
}

void
tdegtk_engine_register_types (GTypeModule *module)
{
	tdegtk_engine_register_type (module);
}

static void
tdegtk_engine_init (TdeGtkEngine *engine)
{
	tdegtk_register_style_default (&engine->style_functions[TDEGTK_STYLE_DEFAULT]);
}

static void
tdegtk_engine_class_init (TdeGtkEngineClass *klass)
{
	GtkThemingEngineClass *engine_class = GTK_THEMING_ENGINE_CLASS (klass);
	
	engine_class->render_activity    = tdegtk_engine_render_activity;
	engine_class->render_arrow       = tdegtk_engine_render_arrow;
	engine_class->render_background  = tdegtk_engine_render_background;
	engine_class->render_check       = tdegtk_engine_render_check;
	engine_class->render_expander    = tdegtk_engine_render_expander;
	engine_class->render_extension   = tdegtk_engine_render_extension;
	engine_class->render_focus       = tdegtk_engine_render_focus;
	engine_class->render_frame       = tdegtk_engine_render_frame;
	engine_class->render_frame_gap   = tdegtk_engine_render_frame_gap;
	engine_class->render_handle      = tdegtk_engine_render_handle;
	engine_class->render_line        = tdegtk_engine_render_line;
	engine_class->render_option      = tdegtk_engine_render_option;
	engine_class->render_slider      = tdegtk_engine_render_slider;

	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("background-texture",
								"Background texture",
								"Background texture",
								CAIRO_GOBJECT_TYPE_PATTERN, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("border-gradient",
								"Border gradient",
								"Border gradient",
								CAIRO_GOBJECT_TYPE_PATTERN, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("bullet-color",
								"Bullet color",
								"Bullet color",
								GDK_TYPE_RGBA, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("bullet-outline-color",
								"Bullet outline color",
								"Bullet outline color",
								GDK_TYPE_RGBA, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("centroid-texture",
								"Centroid texture",
								"Centroid texture",
								CAIRO_GOBJECT_TYPE_PATTERN, 0));
	
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("focus-border-color",
								"Focus border color",
								"Focus border color",
								GDK_TYPE_RGBA, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_int ("focus-border-radius",
								"Focus border radius",
								"Focus border radius",
								0, G_MAXINT, 0, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("focus-fill-color",
								"Focus fill color",
								"Focus fill color",
								GDK_TYPE_RGBA, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("focus-outer-stroke-color",
								"Focus outer stroke color",
								"Focus outer stroke color",
								GDK_TYPE_RGBA, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_int ("glow-radius",
								"Glow radius",
								"Glow radius",
								0, G_MAXINT, 0, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("glow-color",
								"Glow color",
								"Glow color",
								GDK_TYPE_RGBA, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("inner-stroke-color",
								"Inner stroke color",
								"Inner stroke color",
								GDK_TYPE_RGBA, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("inner-stroke-top-color",
								"Inner stroke top color",
								"Inner stroke top color",
								GDK_TYPE_RGBA, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("inner-stroke-right-color",
								"Inner stroke right color",
								"Inner stroke right color",
								GDK_TYPE_RGBA, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("inner-stroke-bottom-color",
								"Inner stroke bottom color",
								"Inner stroke bottom color",
								GDK_TYPE_RGBA, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("inner-stroke-left-color",
								"Inner stroke left color",
								"Inner stroke left color",
								GDK_TYPE_RGBA, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("inner-stroke-gradient",
								"Inner stroke gradient",
								"Inner stroke gradient",
								CAIRO_GOBJECT_TYPE_PATTERN, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("inner-stroke-width",
								"Inner stroke width",
								"Inner stroke width",
								GTK_TYPE_BORDER, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("outer-stroke-color",
								"Outer stroke color",
								"Outer stroke color",
								GDK_TYPE_RGBA, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("outer-stroke-top-color",
								"Outer stroke top color",
								"Outer stroke top color",
								GDK_TYPE_RGBA, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("outer-stroke-right-color",
								"Outer stroke right color",
								"Outer stroke right color",
								GDK_TYPE_RGBA, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("outer-stroke-bottom-color",
								"Outer stroke bottom color",
								"Outer stroke bottom color",
								GDK_TYPE_RGBA, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("outer-stroke-left-color",
								"Outer stroke left color",
								"Outer stroke left color",
								GDK_TYPE_RGBA, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("outer-stroke-gradient",
								"Outer stroke gradient",
								"Outer stroke gradient",
								CAIRO_GOBJECT_TYPE_PATTERN, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("outer-stroke-width",
								"Outer stroke width",
								"Outer stroke width",
								GTK_TYPE_BORDER, 0));
	
	gtk_theming_engine_register_property (TDEGTK_NAMESPACE, NULL,
					g_param_spec_boxed ("text-shadow-color",
								"Text shadow color",
								"Text shadow color",
								GDK_TYPE_RGBA, 0));
}

static void
tdegtk_engine_class_finalize (TdeGtkEngineClass *klass)
{
}