File: rbgtk-style-context.c

package info (click to toggle)
ruby-gnome 3.4.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 29,112 kB
  • sloc: ansic: 97,029; ruby: 70,747; xml: 350; sh: 142; cpp: 45; makefile: 29
file content (411 lines) | stat: -rw-r--r-- 9,970 bytes parent folder | download | duplicates (6)
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
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
/*
 *  Copyright (C) 2011  Ruby-GNOME2 Project Team
 *
 *  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.1 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 Street, Fifth Floor, Boston,
 *  MA  02110-1301  USA
 */

#include "rbgtk3private.h"

#define RG_TARGET_NAMESPACE cStyleContext
#define _SELF(self) (RVAL2GTKSTYLECONTEXT(self))

static VALUE
rg_initialize(VALUE self)
{
    G_INITIALIZE(self, gtk_style_context_new());

    return Qnil;
}

static VALUE
rg_add_class(VALUE self, VALUE class_name)
{
    gtk_style_context_add_class(_SELF(self), RVAL2CSTR(class_name));

    return self;
}

static VALUE
rg_add_provider(VALUE self, VALUE provider, VALUE priority)
{
    gtk_style_context_add_provider(_SELF(self),
                                   RVAL2GTKSTYLEPROVIDER(provider),
                                   NUM2UINT(priority));

    return self;
}

static VALUE
rg_add_region(VALUE self, VALUE region_name, VALUE flags)
{
    gtk_style_context_add_region(_SELF(self),
                                 RVAL2CSTR(region_name),
                                 RVAL2GTKREGIONFLAGS(flags));

    return self;
}

static VALUE
rg_get_background_color(VALUE self, VALUE state)
{
    GdkRGBA color;

    gtk_style_context_get_background_color(_SELF(self),
                                           RVAL2GTKSTATEFLAGS(state),
                                           &color);

    return GDKRGBA2RVAL(&color);
}

static VALUE
rg_get_border(VALUE self, VALUE state)
{
    GtkBorder border;

    gtk_style_context_get_border(_SELF(self),
                                 RVAL2GTKSTATEFLAGS(state),
                                 &border);

    return GTKBORDER2RVAL(&border);
}

static VALUE
rg_get_border_color(VALUE self, VALUE state)
{
    GdkRGBA color;

    gtk_style_context_get_border_color(_SELF(self),
                                       RVAL2GTKSTATEFLAGS(state),
                                       &color);

    return GDKRGBA2RVAL(&color);
}

static VALUE
rg_get_color(VALUE self, VALUE state)
{
    GdkRGBA color;

    gtk_style_context_get_color(_SELF(self),
                                RVAL2GTKSTATEFLAGS(state),
                                &color);

    return GDKRGBA2RVAL(&color);
}

static VALUE
rg_get_font(VALUE self, VALUE state)
{
    PangoFontDescription *desc;

    desc = gtk_style_context_get_font(_SELF(self),
                                      RVAL2GTKSTATEFLAGS(state));

    return PANGOFONTDESCRIPTION2RVAL(desc);
}

static VALUE
rg_junction_sides(VALUE self)
{
    GtkJunctionSides sides;

    sides = gtk_style_context_get_junction_sides(_SELF(self));

    return GTKJUNCTIONSIDES2RVAL(sides);
}

static VALUE
rg_get_margin(VALUE self, VALUE state)
{
    GtkBorder margin;

    gtk_style_context_get_margin(_SELF(self),
                                 RVAL2GTKSTATEFLAGS(state),
                                 &margin);

    return GTKBORDER2RVAL(&margin);
}

static VALUE
rg_get_padding(VALUE self, VALUE state)
{
    GtkBorder padding;

    gtk_style_context_get_padding(_SELF(self),
                                  RVAL2GTKSTATEFLAGS(state),
                                  &padding);

    return GTKBORDER2RVAL(&padding);
}

static VALUE
rg_path(VALUE self)
{
    return GTKWIDGETPATH2RVAL(gtk_style_context_get_path(_SELF(self)));
}

static VALUE
rg_get_property(VALUE self, VALUE property, VALUE state)
{
    GValue value = G_VALUE_INIT;
    VALUE ret = Qnil;

    gtk_style_context_get_property(_SELF(self),
                                   RVAL2CSTR(property),
                                   RVAL2GTKSTATEFLAGS(state),
                                   &value);
    if (G_VALUE_TYPE(&value) != G_TYPE_INVALID){
        ret = GVAL2RVAL(&value);
        g_value_unset(&value);
    } 

    return ret;
}

static VALUE
rg_state(VALUE self)
{
    GtkStateFlags state;

    state = gtk_style_context_get_state(_SELF(self));

    return GTKSTATEFLAGS2RVAL(state);
}

static VALUE
rg_get_style_property(VALUE self, VALUE property_name)
{
    GValue value = G_VALUE_INIT;
    VALUE ret = Qnil;

    gtk_style_context_get_style_property(_SELF(self),
                                         RVAL2CSTR(property_name),
                                         &value);
    if (G_VALUE_TYPE(&value) != G_TYPE_INVALID){
        ret = GVAL2RVAL(&value);
        g_value_unset(&value);
    } 

    return ret;
}

static VALUE
rg_has_class_p(VALUE self, VALUE class_name)
{
    return CBOOL2RVAL(gtk_style_context_has_class(_SELF(self), RVAL2CSTR(class_name)));
}

static VALUE
rg_has_region(VALUE self, VALUE region_name)
{
    GtkRegionFlags flags;
    gboolean result;

    result = gtk_style_context_has_region(_SELF(self),
                                          RVAL2CSTR(region_name),
                                          &flags);

    return result ? GTKREGIONFLAGS2RVAL(flags) : Qnil;
}

static VALUE
rg_invalidate(VALUE self)
{
    gtk_style_context_invalidate(_SELF(self));

    return self;
}

static VALUE
rg_classes(VALUE self)
{
    return CSTRGLIST2RVAL_FREE(gtk_style_context_list_classes(_SELF(self)),
                               g_list_free, NULL);
}

static VALUE
rg_regions(VALUE self)
{
    return CSTRGLIST2RVAL_FREE(gtk_style_context_list_regions(_SELF(self)),
                               g_list_free, NULL);
}

static VALUE
rg_lookup_color(VALUE self, VALUE color_name)
{
    GdkRGBA color;
    gboolean result;

    result = gtk_style_context_lookup_color(_SELF(self), RVAL2CSTR(color_name), &color);

    return result ? GDKRGBA2RVAL(&color) : Qnil;
}

static VALUE
rg_lookup_icon_set(VALUE self, VALUE stock_id)
{
    VALUE buffer;
    return GTKICONSET2RVAL(gtk_style_context_lookup_icon_set(_SELF(self),
                                                             RVAL2GLIBID(stock_id, buffer)));
}

static VALUE
rg_pop_animatable_region(VALUE self)
{
    gtk_style_context_pop_animatable_region(_SELF(self));

    return self;
}

static VALUE
rg_push_animatable_region(VALUE self, VALUE region_id)
{
    gtk_style_context_push_animatable_region(_SELF(self), (gpointer)region_id);
    if (rb_block_given_p())
        rb_ensure(rb_yield, self, rg_pop_animatable_region, self);

    return self;
}

static VALUE
rg_remove_class(VALUE self, VALUE class_name)
{
    gtk_style_context_remove_class(_SELF(self), RVAL2CSTR(class_name));

    return self;
}

static VALUE
rg_remove_provider(VALUE self, VALUE provider)
{
    gtk_style_context_remove_provider(_SELF(self),
                                      RVAL2GTKSTYLEPROVIDER(provider));

    return self;
}

static VALUE
rg_remove_region(VALUE self, VALUE region_name)
{
    gtk_style_context_remove_region(_SELF(self), RVAL2CSTR(region_name));

    return self;
}

static VALUE
rg_restore(VALUE self)
{
    gtk_style_context_restore(_SELF(self));

    return self;
}

static VALUE
rg_save(VALUE self)
{
    gtk_style_context_save(_SELF(self));

    return self;
}

static VALUE
rg_set_background(VALUE self, VALUE window)
{
    gtk_style_context_set_background(_SELF(self), RVAL2GDKWINDOW(window));

    return self;
}

static VALUE
rg_set_junction_sides(VALUE self, VALUE sides)
{
    gtk_style_context_set_junction_sides(_SELF(self),
                                         RVAL2GTKJUNCTIONSIDES(sides));

    return self;
}

static VALUE
rg_set_path(VALUE self, VALUE path)
{
    gtk_style_context_set_path(_SELF(self), RVAL2GTKWIDGETPATH(path));

    return self;
}

static VALUE
rg_set_state(VALUE self, VALUE state)
{
    gtk_style_context_set_state(_SELF(self), RVAL2GTKSTATEFLAGS(state));

    return self;
}

static VALUE
rg_state_is_running(VALUE self, VALUE state)
{
    gdouble progress;
    gboolean result;

    result = gtk_style_context_state_is_running(_SELF(self),
                                                RVAL2GTKSTATEFLAGS(state),
                                                &progress);

    return result ? DBL2NUM(progress) : Qnil;
}

void
Init_gtk_stylecontext(VALUE mGtk)
{
    VALUE RG_TARGET_NAMESPACE = G_DEF_CLASS(GTK_TYPE_STYLE_CONTEXT, "StyleContext", mGtk);

    RG_DEF_METHOD(initialize, 0);
    RG_DEF_METHOD(add_class, 1);
    RG_DEF_METHOD(add_provider, 2);
    RG_DEF_METHOD(add_region, 2);
    RG_DEF_METHOD(classes, 0);
    RG_DEF_METHOD(get_background_color, 1);
    RG_DEF_METHOD(get_border, 1);
    RG_DEF_METHOD(get_border_color, 1);
    RG_DEF_METHOD(get_color, 1);
    RG_DEF_METHOD(get_font, 1);
    RG_DEF_METHOD(get_margin, 1);
    RG_DEF_METHOD(get_padding, 1);
    RG_DEF_METHOD(get_property, 2);
    RG_DEF_METHOD(get_style_property, 1);
    RG_DEF_METHOD_P(has_class, 1);
    RG_DEF_METHOD(has_region, 1);
    RG_DEF_METHOD(invalidate, 0);
    RG_DEF_METHOD(junction_sides, 0);
    RG_DEF_METHOD(lookup_color, 1);
    RG_DEF_METHOD(lookup_icon_set, 1);
    RG_DEF_METHOD(path, 0);
    RG_DEF_METHOD(pop_animatable_region, 0);
    RG_DEF_METHOD(push_animatable_region, 1);
    RG_DEF_METHOD(regions, 0);
    RG_DEF_METHOD(remove_class, 1);
    RG_DEF_METHOD(remove_provider, 1);
    RG_DEF_METHOD(remove_region, 1);
    RG_DEF_METHOD(restore, 0);
    RG_DEF_METHOD(save, 0);
    RG_DEF_METHOD(set_background, 1);
    RG_DEF_METHOD(set_junction_sides, 1);
    RG_DEF_METHOD(set_path, 1);
    RG_DEF_METHOD(set_state, 1);
    RG_DEF_METHOD(state, 0);
    RG_DEF_METHOD(state_is_running, 1);
}