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
|
/*
* (GLABELS) Label and Business Card Creation program for GNOME
*
* prop_bc_data.c: barcode data widget module
*
* Copyright (C) 2001-2002 Jim Evins <evins@snaught.com>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <config.h>
#include "prop_bc_data.h"
#include "merge.h"
#include "debug.h"
/*===========================================*/
/* Private types */
/*===========================================*/
enum {
CHANGED,
LAST_SIGNAL
};
typedef void (*glPropBCDataSignal) (GtkObject * object, gpointer data);
/*===========================================*/
/* Private globals */
/*===========================================*/
static GtkContainerClass *parent_class;
static gint prop_bc_data_signals[LAST_SIGNAL] = { 0 };
/*===========================================*/
/* Local function prototypes */
/*===========================================*/
static void gl_prop_bc_data_class_init (glPropBCDataClass * class);
static void gl_prop_bc_data_init (glPropBCData * bc_data);
static void gl_prop_bc_data_destroy (GtkObject * object);
static void gl_prop_bc_data_construct (glPropBCData * bc_data,
gchar * label, GList * field_defs);
static void changed_cb (glPropBCData * bc_data);
static void radio_toggled_cb (GtkToggleButton * togglebutton,
glPropBCData * bc_data);
/*================================================================*/
/* Boilerplate Object stuff. */
/*================================================================*/
guint
gl_prop_bc_data_get_type (void)
{
static guint prop_bc_data_type = 0;
if (!prop_bc_data_type) {
GtkTypeInfo prop_bc_data_info = {
"glPropBCData",
sizeof (glPropBCData),
sizeof (glPropBCDataClass),
(GtkClassInitFunc) gl_prop_bc_data_class_init,
(GtkObjectInitFunc) gl_prop_bc_data_init,
(GtkArgSetFunc) NULL,
(GtkArgGetFunc) NULL,
};
prop_bc_data_type = gtk_type_unique (gtk_vbox_get_type (),
&prop_bc_data_info);
}
return prop_bc_data_type;
}
static void
gl_prop_bc_data_class_init (glPropBCDataClass * class)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = (GtkObjectClass *) class;
widget_class = (GtkWidgetClass *) class;
parent_class = gtk_type_class (gtk_vbox_get_type ());
object_class->destroy = gl_prop_bc_data_destroy;
prop_bc_data_signals[CHANGED] =
gtk_signal_new ("changed", GTK_RUN_LAST, object_class->type,
GTK_SIGNAL_OFFSET (glPropBCDataClass, changed),
gtk_signal_default_marshaller, GTK_TYPE_NONE, 0);
gtk_object_class_add_signals (object_class,
prop_bc_data_signals, LAST_SIGNAL);
class->changed = NULL;
}
static void
gl_prop_bc_data_init (glPropBCData * bc_data)
{
bc_data->literal_radio = NULL;
bc_data->literal_entry = NULL;
bc_data->key_radio = NULL;
bc_data->key_entry = NULL;
}
static void
gl_prop_bc_data_destroy (GtkObject * object)
{
glPropBCData *bc_data;
glPropBCDataClass *class;
g_return_if_fail (object != NULL);
g_return_if_fail (GL_IS_PROP_BC_DATA (object));
bc_data = GL_PROP_BC_DATA (object);
class = GL_PROP_BC_DATA_CLASS (GTK_OBJECT (bc_data)->klass);
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
GtkWidget *
gl_prop_bc_data_new (gchar * label,
GList * field_defs)
{
glPropBCData *bc_data;
bc_data = gtk_type_new (gl_prop_bc_data_get_type ());
gl_prop_bc_data_construct (bc_data, label, field_defs);
return GTK_WIDGET (bc_data);
}
/*============================================================*/
/* Construct composite widget. */
/*============================================================*/
static void
gl_prop_bc_data_construct (glPropBCData * bc_data,
gchar * label,
GList * field_defs)
{
GtkWidget *wvbox, *wframe, *wtable, *wcombo;
GSList *radio_group = NULL;
GList *keys;
wvbox = GTK_WIDGET (bc_data);
wframe = gtk_frame_new (label);
gtk_box_pack_start (GTK_BOX (wvbox), wframe, FALSE, FALSE, 0);
wtable = gtk_table_new (2, 2, FALSE);
gtk_container_set_border_width (GTK_CONTAINER (wtable), 10);
gtk_table_set_row_spacings (GTK_TABLE (wtable), 5);
gtk_table_set_col_spacings (GTK_TABLE (wtable), 5);
gtk_container_add (GTK_CONTAINER (wframe), wtable);
/* Literal radio */
bc_data->literal_radio = gtk_radio_button_new_with_label (radio_group,
_
("Literal:"));
radio_group =
gtk_radio_button_group (GTK_RADIO_BUTTON (bc_data->literal_radio));
gtk_signal_connect (GTK_OBJECT (bc_data->literal_radio), "toggled",
GTK_SIGNAL_FUNC (radio_toggled_cb),
GTK_OBJECT (bc_data));
gtk_table_attach_defaults (GTK_TABLE (wtable), bc_data->literal_radio,
0, 1, 0, 1);
/* Literal entry widget */
bc_data->literal_entry = gtk_entry_new ();
gtk_widget_set_usize (bc_data->literal_entry, 200, 0);
gtk_signal_connect_object (GTK_OBJECT (bc_data->literal_entry),
"changed", GTK_SIGNAL_FUNC (changed_cb),
GTK_OBJECT (bc_data));
gtk_table_attach_defaults (GTK_TABLE (wtable), bc_data->literal_entry,
1, 2, 0, 1);
/* Key radio */
bc_data->key_radio = gtk_radio_button_new_with_label (radio_group,
_("Key:"));
gtk_signal_connect (GTK_OBJECT (bc_data->key_radio), "toggled",
GTK_SIGNAL_FUNC (radio_toggled_cb),
GTK_OBJECT (bc_data));
gtk_table_attach_defaults (GTK_TABLE (wtable), bc_data->key_radio,
0, 1, 1, 2);
/* Key entry widget */
wcombo = gtk_combo_new ();
keys = gl_merge_get_key_list (field_defs);
if (keys != NULL)
gtk_combo_set_popdown_strings (GTK_COMBO (wcombo), keys);
gl_merge_free_key_list (&keys);
bc_data->key_entry = GTK_COMBO (wcombo)->entry;
gtk_entry_set_editable (GTK_ENTRY (bc_data->key_entry), FALSE);
gtk_widget_set_usize (wcombo, 200, 0);
gtk_signal_connect_object (GTK_OBJECT (bc_data->key_entry), "changed",
GTK_SIGNAL_FUNC (changed_cb),
GTK_OBJECT (bc_data));
gtk_table_attach_defaults (GTK_TABLE (wtable), wcombo, 1, 2, 1, 2);
}
/*--------------------------------------------------------------------------*/
/* PRIVATE. Callback for when any control in the widget has changed. */
/*--------------------------------------------------------------------------*/
static void
changed_cb (glPropBCData * bc_data)
{
/* Emit our "changed" signal */
gtk_signal_emit (GTK_OBJECT (bc_data), prop_bc_data_signals[CHANGED]);
}
/*--------------------------------------------------------------------------*/
/* PRIVATE. Callback to handle toggling of radio buttons */
/*--------------------------------------------------------------------------*/
static void
radio_toggled_cb (GtkToggleButton * togglebutton,
glPropBCData * bc_data)
{
if (gtk_toggle_button_get_active
(GTK_TOGGLE_BUTTON (bc_data->literal_radio))) {
gtk_widget_set_sensitive (bc_data->literal_entry, TRUE);
gtk_widget_set_sensitive (bc_data->key_entry, FALSE);
} else {
gtk_widget_set_sensitive (bc_data->literal_entry, FALSE);
gtk_widget_set_sensitive (bc_data->key_entry, TRUE);
}
/* Emit our "changed" signal */
gtk_signal_emit (GTK_OBJECT (bc_data), prop_bc_data_signals[CHANGED]);
}
/*--------------------------------------------------------------------------*/
/* Get widget data. */
/*--------------------------------------------------------------------------*/
void
gl_prop_bc_data_get_data (glPropBCData * bc_data,
gboolean * field_flag,
gchar ** data,
gchar ** key)
{
if (gtk_toggle_button_get_active
(GTK_TOGGLE_BUTTON (bc_data->literal_radio))) {
*field_flag = FALSE;
*data =
gtk_editable_get_chars (GTK_EDITABLE
(bc_data->literal_entry), 0, -1);
*key = NULL;
} else {
*field_flag = TRUE;
*data = NULL;
*key =
gtk_editable_get_chars (GTK_EDITABLE (bc_data->key_entry),
0, -1);
}
}
/*--------------------------------------------------------------------------*/
/* Set widget data. */
/*--------------------------------------------------------------------------*/
void
gl_prop_bc_data_set_data (glPropBCData * bc_data,
gboolean merge_flag,
gboolean field_flag,
gchar * data,
gchar * key)
{
gint pos;
gtk_widget_set_sensitive (bc_data->key_radio, merge_flag);
if (!field_flag) {
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
(bc_data->literal_radio), TRUE);
gtk_widget_set_sensitive (bc_data->literal_entry, TRUE);
gtk_widget_set_sensitive (bc_data->key_entry, FALSE);
gtk_signal_handler_block_by_func (GTK_OBJECT
(bc_data->literal_entry),
GTK_SIGNAL_FUNC (changed_cb),
bc_data);
gtk_editable_delete_text (GTK_EDITABLE (bc_data->literal_entry),
0, -1);
gtk_signal_handler_unblock_by_func (GTK_OBJECT
(bc_data->literal_entry),
GTK_SIGNAL_FUNC
(changed_cb), bc_data);
pos = 0;
gtk_editable_insert_text (GTK_EDITABLE (bc_data->literal_entry),
data, strlen (data), &pos);
} else {
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON
(bc_data->key_radio), TRUE);
gtk_widget_set_sensitive (bc_data->literal_entry, FALSE);
gtk_widget_set_sensitive (bc_data->key_entry, TRUE);
gtk_signal_handler_block_by_func (GTK_OBJECT
(bc_data->key_entry),
GTK_SIGNAL_FUNC (changed_cb),
bc_data);
gtk_editable_delete_text (GTK_EDITABLE (bc_data->key_entry), 0,
-1);
gtk_signal_handler_unblock_by_func (GTK_OBJECT
(bc_data->key_entry),
GTK_SIGNAL_FUNC
(changed_cb), bc_data);
pos = 0;
gtk_editable_insert_text (GTK_EDITABLE (bc_data->key_entry),
data, strlen (data), &pos);
}
}
|