Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/yabause/src/gtk/yuicheckbutton.c
2 views
1
/* Copyright 2006 Guillaume Duhamel
2
Copyright 2005-2006 Fabien Coulon
3
Copyright 2009 Andrew Church
4
5
This file is part of Yabause.
6
7
Yabause is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
11
12
Yabause is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
16
17
You should have received a copy of the GNU General Public License
18
along with Yabause; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
*/
21
22
#include <gtk/gtk.h>
23
24
#include "yuicheckbutton.h"
25
26
static void yui_check_button_class_init(YuiCheckButtonClass * klass);
27
static void yui_check_button_init (YuiCheckButton * ycb);
28
static void yui_check_button_toggled (GtkToggleButton * button, YuiCheckButton * ycb);
29
30
GType yui_check_button_get_type (void) {
31
static GType ycb_type = 0;
32
33
if (!ycb_type)
34
{
35
static const GTypeInfo ycb_info =
36
{
37
sizeof (YuiCheckButtonClass),
38
NULL, /* base_init */
39
NULL, /* base_finalize */
40
(GClassInitFunc) yui_check_button_class_init,
41
NULL, /* class_finalize */
42
NULL, /* class_data */
43
sizeof (YuiCheckButton),
44
0,
45
(GInstanceInitFunc) yui_check_button_init,
46
NULL,
47
};
48
49
ycb_type = g_type_register_static(GTK_TYPE_CHECK_BUTTON, "YuiCheckButton", &ycb_info, 0);
50
}
51
52
return ycb_type;
53
}
54
55
#define PROP_KEYFILE 1
56
#define PROP_GROUP 2
57
#define PROP_KEY 3
58
59
static void yui_check_button_set_property(GObject * object, guint property_id,
60
const GValue * value, GParamSpec * pspec) {
61
switch(property_id) {
62
case PROP_KEYFILE:
63
YUI_CHECK_BUTTON(object)->keyfile = g_value_get_pointer(value);
64
break;
65
case PROP_GROUP:
66
YUI_CHECK_BUTTON(object)->group = g_value_get_pointer(value);
67
break;
68
case PROP_KEY:
69
YUI_CHECK_BUTTON(object)->key = g_value_get_pointer(value);
70
break;
71
}
72
}
73
74
static void yui_check_button_get_property(GObject * object, guint property_id,
75
GValue * value, GParamSpec * pspec) {
76
}
77
78
enum { YUI_CHECK_BUTTON_CHANGED_SIGNAL, LAST_SIGNAL };
79
80
static guint yui_check_button_signals[LAST_SIGNAL] = { 0 };
81
82
static void yui_check_button_class_init (YuiCheckButtonClass * klass) {
83
GParamSpec * param;
84
85
G_OBJECT_CLASS(klass)->set_property = yui_check_button_set_property;
86
G_OBJECT_CLASS(klass)->get_property = yui_check_button_get_property;
87
88
param = g_param_spec_pointer("key-file", 0, 0, G_PARAM_READABLE | G_PARAM_WRITABLE);
89
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_KEYFILE, param);
90
91
param = g_param_spec_pointer("group", 0, 0, G_PARAM_READABLE | G_PARAM_WRITABLE);
92
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_GROUP, param);
93
94
param = g_param_spec_pointer("key", 0, 0, G_PARAM_READABLE | G_PARAM_WRITABLE);
95
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_KEY, param);
96
97
yui_check_button_signals[YUI_CHECK_BUTTON_CHANGED_SIGNAL] = g_signal_new ("changed", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
98
G_STRUCT_OFFSET(YuiCheckButtonClass, yui_check_button_change), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
99
}
100
101
static void yui_check_button_init (YuiCheckButton * ycb) {
102
}
103
104
GtkWidget * yui_check_button_new(const gchar * label, GKeyFile * keyfile, const gchar * group, const gchar * key) {
105
GtkWidget * button;
106
YuiCheckButton * ycb;
107
gboolean current;
108
109
button = GTK_WIDGET(g_object_new(yui_check_button_get_type(),
110
"label", label,
111
"key-file", keyfile, "group", group, "key", key, NULL));
112
ycb = YUI_CHECK_BUTTON(button);
113
114
gtk_toggle_button_set_mode(GTK_TOGGLE_BUTTON(ycb), TRUE);
115
116
current = g_key_file_get_boolean(ycb->keyfile, ycb->group, ycb->key, NULL);
117
gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(ycb), current);
118
119
g_signal_connect(GTK_TOGGLE_BUTTON(ycb), "toggled", G_CALLBACK(yui_check_button_toggled), ycb);
120
121
return button;
122
}
123
124
static void yui_check_button_toggled(GtkToggleButton * button, YuiCheckButton * ycb) {
125
g_key_file_set_boolean(ycb->keyfile, ycb->group, ycb->key,
126
gtk_toggle_button_get_active(button));
127
g_signal_emit(G_OBJECT(ycb), yui_check_button_signals[YUI_CHECK_BUTTON_CHANGED_SIGNAL], 0);
128
}
129
130
gboolean yui_check_button_get_active(YuiCheckButton * ycb) {
131
return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(ycb));
132
}
133
134