Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/yabause/src/gtk/yuirange.c
2 views
1
/* Copyright 2006 Guillaume Duhamel
2
Copyright 2005-2006 Fabien Coulon
3
4
This file is part of Yabause.
5
6
Yabause is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
11
Yabause is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
15
16
You should have received a copy of the GNU General Public License
17
along with Yabause; if not, write to the Free Software
18
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
*/
20
21
#include <gtk/gtk.h>
22
#include <string.h>
23
24
#include "yuirange.h"
25
26
static void yui_range_class_init (YuiRangeClass * klass);
27
static void yui_range_init (YuiRange * yfe);
28
static void yui_range_changed (GtkWidget * widget, YuiRange * yfe);
29
30
GType yui_range_get_type (void) {
31
static GType yfe_type = 0;
32
33
if (!yfe_type)
34
{
35
static const GTypeInfo yfe_info =
36
{
37
sizeof (YuiRangeClass),
38
NULL, /* base_init */
39
NULL, /* base_finalize */
40
(GClassInitFunc) yui_range_class_init,
41
NULL, /* class_finalize */
42
NULL, /* class_data */
43
sizeof (YuiRange),
44
0,
45
(GInstanceInitFunc) yui_range_init,
46
NULL,
47
};
48
49
yfe_type = g_type_register_static(GTK_TYPE_HBOX, "YuiRange", &yfe_info, 0);
50
}
51
52
return yfe_type;
53
}
54
55
#define PROP_KEYFILE 1
56
#define PROP_GROUP 2
57
#define PROP_KEY 3
58
#define PROP_ITEMS 4
59
60
static void yui_range_set_property(GObject * object, guint property_id,
61
const GValue * value, GParamSpec * pspec) {
62
switch(property_id) {
63
case PROP_KEYFILE:
64
YUI_RANGE(object)->keyfile = g_value_get_pointer(value);
65
break;
66
case PROP_GROUP:
67
YUI_RANGE(object)->group = g_value_get_pointer(value);
68
break;
69
case PROP_KEY:
70
YUI_RANGE(object)->key = g_value_get_pointer(value);
71
break;
72
case PROP_ITEMS:
73
YUI_RANGE(object)->items = g_value_get_pointer(value);
74
break;
75
}
76
}
77
78
static void yui_range_get_property(GObject * object, guint property_id,
79
GValue * value, GParamSpec * pspec) {
80
}
81
82
enum { YUI_RANGE_CHANGED_SIGNAL, LAST_SIGNAL };
83
84
static guint yui_range_signals[LAST_SIGNAL] = { 0 };
85
86
static void yui_range_class_init (YuiRangeClass * klass) {
87
GParamSpec * param;
88
89
G_OBJECT_CLASS(klass)->set_property = yui_range_set_property;
90
G_OBJECT_CLASS(klass)->get_property = yui_range_get_property;
91
92
param = g_param_spec_pointer("key-file", 0, 0, G_PARAM_READABLE | G_PARAM_WRITABLE);
93
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_KEYFILE, param);
94
95
param = g_param_spec_pointer("group", 0, 0, G_PARAM_READABLE | G_PARAM_WRITABLE);
96
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_GROUP, param);
97
98
param = g_param_spec_pointer("key", 0, 0, G_PARAM_READABLE | G_PARAM_WRITABLE);
99
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_KEY, param);
100
101
param = g_param_spec_pointer("items", 0, 0, G_PARAM_READABLE | G_PARAM_WRITABLE);
102
g_object_class_install_property(G_OBJECT_CLASS(klass), PROP_ITEMS, param);
103
104
yui_range_signals[YUI_RANGE_CHANGED_SIGNAL] = g_signal_new ("changed", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
105
G_STRUCT_OFFSET(YuiRangeClass, yui_range_change), NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0);
106
}
107
108
static void yui_range_init (YuiRange * yfe) {
109
gtk_container_set_border_width(GTK_CONTAINER(yfe), 10);
110
111
yfe->combo = gtk_combo_box_new_text();
112
113
gtk_box_pack_start(GTK_BOX(yfe), yfe->combo, TRUE, TRUE, 0);
114
}
115
116
GtkWidget * yui_range_new(GKeyFile * keyfile, const gchar * group, const gchar * key, YuiRangeItem * items) {
117
GtkWidget * entry;
118
YuiRange * yfe;
119
gchar * current;
120
guint i;
121
122
entry = GTK_WIDGET(g_object_new(yui_range_get_type(), "spacing", 10,
123
"key-file", keyfile, "group", group, "key", key, "items", items, NULL));
124
yfe = YUI_RANGE(entry);
125
126
current = g_key_file_get_value(yfe->keyfile, yfe->group, yfe->key, 0);
127
i = 0;
128
while(yfe->items[i].name) {
129
gtk_combo_box_append_text(GTK_COMBO_BOX(yfe->combo), yfe->items[i].name);
130
if (current && !strcmp(yfe->items[i].value, current))
131
gtk_combo_box_set_active(GTK_COMBO_BOX(yfe->combo), i);
132
i++;
133
}
134
if ( !current ) {
135
gtk_combo_box_set_active(GTK_COMBO_BOX(yfe->combo), 0);
136
g_key_file_set_value(yfe->keyfile, yfe->group, yfe->key, items[0].value);
137
}
138
139
g_signal_connect(GTK_COMBO_BOX(yfe->combo), "changed", G_CALLBACK(yui_range_changed), yfe);
140
141
return entry;
142
}
143
144
static void yui_range_changed(GtkWidget * entry, YuiRange * yfe) {
145
g_key_file_set_value(yfe->keyfile, yfe->group, yfe->key,
146
yfe->items[gtk_combo_box_get_active(GTK_COMBO_BOX(yfe->combo))].value);
147
g_signal_emit(G_OBJECT(yfe), yui_range_signals[YUI_RANGE_CHANGED_SIGNAL], 0);
148
}
149
150
gint yui_range_get_active(YuiRange * range) {
151
return gtk_combo_box_get_active(GTK_COMBO_BOX(range->combo));
152
}
153
154