-
Notifications
You must be signed in to change notification settings - Fork 97
/
rb-gtk3-spin-button.c
85 lines (74 loc) · 2.59 KB
/
rb-gtk3-spin-button.c
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
/* -*- c-file-style: "ruby"; indent-tabs-mode: nil -*- */
/*
* Copyright (C) 2016 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 "rb-gtk3-private.h"
typedef struct {
RGClosureCallData *data;
VALUE args;
double *new_value;
} InputData;
static VALUE
rb_gtk3_spin_button_input_body(VALUE user_data)
{
InputData *input_data = (InputData *)user_data;
VALUE new_value;
new_value = rb_apply(input_data->data->callback,
rb_intern("call"),
input_data->args);
if (NIL_P(new_value)) {
g_value_set_int(input_data->data->return_value, FALSE);
} else {
g_value_set_int(input_data->data->return_value, TRUE);
*(input_data->new_value) = NUM2DBL(new_value);
}
return Qnil;
}
static VALUE
rb_gtk3_spin_button_input_rescue(VALUE user_data, VALUE error)
{
InputData *input_data = (InputData *)user_data;
g_value_set_int(input_data->data->return_value, GTK_INPUT_ERROR);
return Qnil;
}
static void
rb_gtk3_spin_button_input(RGClosureCallData *data)
{
InputData input_data;
VALUE args;
args = rb_ary_new_from_args(1, GVAL2RVAL(&(data->param_values[0])));
if (!NIL_P(data->extra_args)) {
rb_ary_concat(args, data->extra_args);
}
input_data.data = data;
input_data.args = args;
input_data.new_value = g_value_get_pointer(&(data->param_values[1]));
rb_rescue(rb_gtk3_spin_button_input_body, (VALUE)&input_data,
rb_gtk3_spin_button_input_rescue, (VALUE)&input_data);
}
void
rbgtk3_spin_button_init(void)
{
VALUE mGtk;
VALUE RG_TARGET_NAMESPACE;
mGtk = rb_const_get(rb_cObject, rb_intern("Gtk"));
RG_TARGET_NAMESPACE = rb_const_get(mGtk, rb_intern("SpinButton"));
rbgobj_set_signal_call_func(RG_TARGET_NAMESPACE,
"input",
rb_gtk3_spin_button_input);
}