summaryrefslogtreecommitdiffstats
path: root/tdegtk/tdegtk-engine.c
blob: 9619b9e2ad0f519073a8ec9080d2f9fe6bf23aef (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
/* 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;
}

static void
tdegtk_engine_class_finalize (TdeGtkEngineClass *klass)
{
}