Commit f19db94c6e61ed3094b4448f15e93514e5236eb8
1 parent
8751ec68
Exists in
master
and in
4 other branches
Working on keypad show/hide actions.
Showing
8 changed files
with
391 additions
and
356 deletions
Show diff stats
keypad/00-right.xml
... | ... | @@ -29,7 +29,7 @@ |
29 | 29 | --> |
30 | 30 | <interface> |
31 | 31 | |
32 | - <keypad name="lateral_keypad" position="right" width='6'> | |
32 | + <keypad name="keypad_right" position="right" width='6'> | |
33 | 33 | |
34 | 34 | <attribute name='label' translatable='yes'>Right keypad</attribute> |
35 | 35 | |
... | ... | @@ -93,7 +93,7 @@ |
93 | 93 | <attribute name="action">win.pfkey(12)</attribute> |
94 | 94 | </button> |
95 | 95 | |
96 | -\ <button column='2' width='2'> | |
96 | + <button column='2' width='2'> | |
97 | 97 | <attribute name="icon-name" translatable="no">gtk-go-up</attribute> |
98 | 98 | <attribute name="action">win.up</attribute> |
99 | 99 | </button> | ... | ... |
keypad/10-bottom.xml
pw3270.cbp
... | ... | @@ -116,10 +116,10 @@ |
116 | 116 | <Unit filename="src/objects/keypad/element.c"> |
117 | 117 | <Option compilerVar="CC" /> |
118 | 118 | </Unit> |
119 | - <Unit filename="src/objects/keypad/keypad.c"> | |
119 | + <Unit filename="src/objects/keypad/load.c"> | |
120 | 120 | <Option compilerVar="CC" /> |
121 | 121 | </Unit> |
122 | - <Unit filename="src/objects/keypad/load.c"> | |
122 | + <Unit filename="src/objects/keypad/model.c"> | |
123 | 123 | <Option compilerVar="CC" /> |
124 | 124 | </Unit> |
125 | 125 | <Unit filename="src/objects/keypad/private.h" /> | ... | ... |
src/include/pw3270/keypad.h
... | ... | @@ -54,6 +54,8 @@ |
54 | 54 | |
55 | 55 | GList * pw3270_keypad_model_new_from_xml(GList *keypads, const gchar *filename); |
56 | 56 | GtkWidget * pw3270_keypad_get_from_model(GObject *model); |
57 | + const gchar * pw3270_keypad_model_get_action_name(GObject *model); | |
58 | + const gchar * pw3270_keypad_model_get_label(GObject *model); | |
57 | 59 | |
58 | 60 | typedef enum _keypad_position { |
59 | 61 | KEYPAD_POSITION_TOP, | ... | ... |
src/objects/keypad/keypad.c
... | ... | @@ -1,350 +0,0 @@ |
1 | -/* | |
2 | - * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
3 | - * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
4 | - * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
5 | - * | |
6 | - * Copyright (C) <2008> <Banco do Brasil S.A.> | |
7 | - * | |
8 | - * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
9 | - * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
10 | - * Free Software Foundation. | |
11 | - * | |
12 | - * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
13 | - * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
14 | - * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
15 | - * obter mais detalhes. | |
16 | - * | |
17 | - * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
18 | - * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
19 | - * St, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | - * | |
21 | - * Este programa está nomeado como - e possui - linhas de código. | |
22 | - * | |
23 | - * Contatos: | |
24 | - * | |
25 | - * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
26 | - * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
27 | - * | |
28 | - */ | |
29 | - | |
30 | - #include "private.h" | |
31 | - #include <stdlib.h> | |
32 | - | |
33 | -/*---[ Globals & Object definition ]----------------------------------------------------------------*/ | |
34 | - | |
35 | - enum { | |
36 | - PROP_NONE, | |
37 | - PROP_NAME, | |
38 | - PROP_LABEL, | |
39 | - PROP_POSITION, | |
40 | - PROP_WIDTH, | |
41 | - PROP_HEIGHT, | |
42 | - }; | |
43 | - | |
44 | - static const char * positions[] = { | |
45 | - "top", | |
46 | - "left", | |
47 | - "bottom", | |
48 | - "right" | |
49 | - }; | |
50 | - | |
51 | - static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); | |
52 | - static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); | |
53 | - | |
54 | - G_DEFINE_TYPE(KeypadModel, KeypadModel, G_TYPE_OBJECT) | |
55 | - | |
56 | -/*---[ Implement ]----------------------------------------------------------------------------------*/ | |
57 | - | |
58 | - static void finalize(GObject *object) { | |
59 | - | |
60 | - KeypadModel * model = PW_KEYPAD_MODEL(object); | |
61 | - | |
62 | - if(model->elements) { | |
63 | - g_list_free_full(model->elements,g_object_unref); | |
64 | - model->elements = NULL; | |
65 | - } | |
66 | - | |
67 | - if(model->name) { | |
68 | - g_free(model->name); | |
69 | - model->name = NULL; | |
70 | - } | |
71 | - | |
72 | - if(model->label) { | |
73 | - g_free(model->label); | |
74 | - model->label = NULL; | |
75 | - } | |
76 | - | |
77 | - } | |
78 | - | |
79 | - static void KeypadModel_class_init(KeypadModelClass *klass) { | |
80 | - | |
81 | - GObjectClass *object_class = G_OBJECT_CLASS(klass); | |
82 | - | |
83 | - klass->domain = g_quark_from_static_string("keypad"); | |
84 | - | |
85 | - object_class->finalize = finalize; | |
86 | - object_class->get_property = get_property; | |
87 | - object_class->set_property = set_property; | |
88 | - | |
89 | - // Install properties | |
90 | - g_object_class_install_property(object_class, PROP_NAME, | |
91 | - g_param_spec_string ( | |
92 | - I_("name"), | |
93 | - N_("Keypad Name"), | |
94 | - N_("The name used to identify the keypad"), | |
95 | - NULL, | |
96 | - G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | |
97 | - ) | |
98 | - ); | |
99 | - | |
100 | - g_object_class_install_property(object_class, PROP_LABEL, | |
101 | - g_param_spec_string ( | |
102 | - _("label"), | |
103 | - N_("Keypad Label"), | |
104 | - N_("The Label of the keypad"), | |
105 | - NULL, | |
106 | - G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | |
107 | - ) | |
108 | - ); | |
109 | - | |
110 | - g_object_class_install_property(object_class, PROP_POSITION, | |
111 | - g_param_spec_string ( | |
112 | - I_("position"), | |
113 | - I_("position"), | |
114 | - N_("The position of the keypad"), | |
115 | - NULL, | |
116 | - G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | |
117 | - ) | |
118 | - ); | |
119 | - | |
120 | - g_object_class_install_property(object_class, PROP_WIDTH, | |
121 | - g_param_spec_uint( | |
122 | - I_("width"), | |
123 | - I_("width"), | |
124 | - _("Keypad width in columns"), | |
125 | - 1, | |
126 | - 10, | |
127 | - 3, | |
128 | - G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | |
129 | - ) | |
130 | - ); | |
131 | - | |
132 | - g_object_class_install_property(object_class, PROP_WIDTH, | |
133 | - g_param_spec_uint( | |
134 | - I_("height"), | |
135 | - I_("height"), | |
136 | - _("Keypad height in rows"), | |
137 | - 0, | |
138 | - 100, | |
139 | - 0, | |
140 | - G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | |
141 | - ) | |
142 | - ); | |
143 | - } | |
144 | - | |
145 | - static void KeypadModel_init(KeypadModel *object) { | |
146 | - | |
147 | - object->position = (unsigned short) KEYPAD_POSITION_BOTTOM; | |
148 | - | |
149 | - } | |
150 | - | |
151 | - static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec G_GNUC_UNUSED(*pspec)) { | |
152 | - | |
153 | - KeypadModel * model = PW_KEYPAD_MODEL(object); | |
154 | - | |
155 | - switch (prop_id) { | |
156 | - case PROP_NAME: | |
157 | - g_value_set_string(value, model->name); | |
158 | - break; | |
159 | - | |
160 | - case PROP_LABEL: | |
161 | - g_value_set_string(value, model->label); | |
162 | - break; | |
163 | - | |
164 | - case PROP_POSITION: | |
165 | - g_value_set_static_string(value,keypad_model_get_position(object)); | |
166 | - break; | |
167 | - | |
168 | - case PROP_HEIGHT: | |
169 | - g_value_set_uint(value, model->height); | |
170 | - break; | |
171 | - | |
172 | - case PROP_WIDTH: | |
173 | - g_value_set_uint(value, model->width); | |
174 | - break; | |
175 | - | |
176 | - default: | |
177 | - g_assert_not_reached (); | |
178 | - } | |
179 | - | |
180 | - } | |
181 | - | |
182 | - static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec G_GNUC_UNUSED(*pspec)) { | |
183 | - | |
184 | - KeypadModel * model = PW_KEYPAD_MODEL(object); | |
185 | - | |
186 | - switch (prop_id) { | |
187 | - case PROP_NAME: | |
188 | - | |
189 | - if(model->name) { | |
190 | - g_free(model->name); | |
191 | - model->name = g_value_dup_string(value); | |
192 | - } | |
193 | - break; | |
194 | - | |
195 | - case PROP_LABEL: | |
196 | - | |
197 | - if(model->label) { | |
198 | - g_free(model->label); | |
199 | - model->label = g_value_dup_string(value); | |
200 | - } | |
201 | - break; | |
202 | - | |
203 | - case PROP_POSITION: | |
204 | - keypad_model_set_position(object,g_value_get_string(value)); | |
205 | - break; | |
206 | - | |
207 | - case PROP_HEIGHT: | |
208 | - model->height = (unsigned short) g_value_get_uint(value); | |
209 | - break; | |
210 | - | |
211 | - case PROP_WIDTH: | |
212 | - model->width = (unsigned short) g_value_get_uint(value); | |
213 | - break; | |
214 | - | |
215 | - default: | |
216 | - g_assert_not_reached(); | |
217 | - } | |
218 | - } | |
219 | - | |
220 | - void keypad_model_set_position(GObject *model, const gchar *position) { | |
221 | - | |
222 | - if(position) { | |
223 | - size_t ix; | |
224 | - for(ix = 0; ix < G_N_ELEMENTS(positions); ix++) { | |
225 | - if(!g_ascii_strcasecmp(positions[ix],position)) { | |
226 | - PW_KEYPAD_MODEL(model)->position = (unsigned short) ix; | |
227 | - break; | |
228 | - } | |
229 | - } | |
230 | - } | |
231 | - | |
232 | - } | |
233 | - | |
234 | - const gchar * keypad_model_get_position(GObject *model) { | |
235 | - | |
236 | - size_t ix = (size_t) PW_KEYPAD_MODEL(model)->position; | |
237 | - | |
238 | - if(ix < G_N_ELEMENTS(positions)) | |
239 | - return positions[ix]; | |
240 | - | |
241 | - return "undefined"; | |
242 | - } | |
243 | - | |
244 | - static void element_start(GMarkupParseContext *context, const gchar *element_name, const gchar **names,const gchar **values, KeypadModel *keypad, GError **error) { | |
245 | - | |
246 | - debug("%s(%s)",__FUNCTION__,element_name); | |
247 | - | |
248 | - if(!g_ascii_strcasecmp(element_name,"button")) { | |
249 | - | |
250 | - const gchar *row, *col, *width, *height; | |
251 | - KeypadElement * element = PW_KEYPAD_ELEMENT(g_object_new(PW_TYPE_KEYPAD_ELEMENT,NULL)); | |
252 | - | |
253 | - if(!g_markup_collect_attributes( | |
254 | - element_name,names,values,error, | |
255 | - G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "row", &row, | |
256 | - G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "column", &col, | |
257 | - G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "width", &width, | |
258 | - G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "height", &height, | |
259 | - G_MARKUP_COLLECT_INVALID | |
260 | - )) { | |
261 | - | |
262 | - return; | |
263 | - | |
264 | - } | |
265 | - | |
266 | - if(col) { | |
267 | - element->col = (unsigned short) atoi(col); | |
268 | - | |
269 | - if(element->col < keypad->current.col) { | |
270 | - keypad->current.row++; | |
271 | - } | |
272 | - | |
273 | - } else { | |
274 | - element->col = keypad->current.col; | |
275 | - } | |
276 | - | |
277 | - if(row) { | |
278 | - element->row = (unsigned short) atoi(row); | |
279 | - } else { | |
280 | - element->row = keypad->current.row; | |
281 | - } | |
282 | - | |
283 | - | |
284 | - if(width) { | |
285 | - element->width = (unsigned short) atoi(width); | |
286 | - } else { | |
287 | - element->width = 1; | |
288 | - } | |
289 | - | |
290 | - if(height) { | |
291 | - element->height = (unsigned short) atoi(height); | |
292 | - } else { | |
293 | - element->height = 1; | |
294 | - } | |
295 | - | |
296 | - keypad->elements = g_list_prepend(keypad->elements,element); | |
297 | - keypad_model_element_parse_context(G_OBJECT(element),context); | |
298 | - | |
299 | - } | |
300 | - | |
301 | - | |
302 | - } | |
303 | - | |
304 | - static void element_end(GMarkupParseContext *context, const gchar *element_name, KeypadModel *keypad, GError G_GNUC_UNUSED(**error)) { | |
305 | - | |
306 | - debug("%s(%s)",__FUNCTION__,element_name); | |
307 | - | |
308 | - if(!g_ascii_strcasecmp(element_name,"button")) { | |
309 | - g_markup_parse_context_pop(context); | |
310 | - | |
311 | - KeypadElement * element = PW_KEYPAD_ELEMENT(g_list_first(keypad->elements)->data); | |
312 | - | |
313 | - keypad->current.row = element->row; | |
314 | - keypad->current.col = element->col + element->width; | |
315 | - | |
316 | - if(keypad->width && keypad->current.col >= keypad->width) { | |
317 | - keypad->current.col = 0; | |
318 | - keypad->current.row++; | |
319 | - } | |
320 | - | |
321 | - } | |
322 | - | |
323 | - } | |
324 | - | |
325 | - void keypad_model_parse_context(GObject *object, GMarkupParseContext *context) { | |
326 | - | |
327 | - static const GMarkupParser parser = { | |
328 | - (void (*)(GMarkupParseContext *, const gchar *, const gchar **, const gchar **, gpointer, GError **)) | |
329 | - element_start, | |
330 | - | |
331 | - (void (*)(GMarkupParseContext *, const gchar *, gpointer, GError **)) | |
332 | - element_end, | |
333 | - NULL, | |
334 | - NULL, | |
335 | - NULL | |
336 | - }; | |
337 | - | |
338 | - KeypadModel * model = PW_KEYPAD_MODEL(object); | |
339 | - | |
340 | - model->elements = g_list_reverse(model->elements); | |
341 | - g_markup_parse_context_push(context, &parser, model); | |
342 | - model->elements = g_list_reverse(model->elements); | |
343 | - | |
344 | - } | |
345 | - | |
346 | - KEYPAD_POSITION pw3270_keypad_get_position(GObject *model) { | |
347 | - g_return_val_if_fail(PW_IS_KEYPAD_MODEL(model), (KEYPAD_POSITION) -1); | |
348 | - return (KEYPAD_POSITION) PW_KEYPAD_MODEL(model)->position; | |
349 | - } | |
350 | - |
src/objects/keypad/load.c
... | ... | @@ -36,12 +36,13 @@ |
36 | 36 | |
37 | 37 | if(!g_ascii_strcasecmp(element_name,"keypad")) { |
38 | 38 | |
39 | - const gchar *name, *position, *width, *height; | |
39 | + const gchar *name, *label, *position, *width, *height; | |
40 | 40 | GObject * keypad = g_object_new(PW_TYPE_KEYPAD_MODEL,NULL); |
41 | 41 | |
42 | 42 | if(!g_markup_collect_attributes( |
43 | 43 | element_name,names,values,error, |
44 | 44 | G_MARKUP_COLLECT_STRING, "name", &name, |
45 | + G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "label", &label, | |
45 | 46 | G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "position", &position, |
46 | 47 | G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "width", &width, |
47 | 48 | G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "height", &height, |
... | ... | @@ -57,6 +58,14 @@ |
57 | 58 | |
58 | 59 | keypad_model_set_position(keypad,position); |
59 | 60 | |
61 | + if(name) { | |
62 | + PW_KEYPAD_MODEL(keypad)->name = g_strdup(name); | |
63 | + } | |
64 | + | |
65 | + if(label) { | |
66 | + PW_KEYPAD_MODEL(keypad)->label = g_strdup(label); | |
67 | + } | |
68 | + | |
60 | 69 | if(width) { |
61 | 70 | PW_KEYPAD_MODEL(keypad)->width = (unsigned short) atoi(width); |
62 | 71 | } | ... | ... |
... | ... | @@ -0,0 +1,363 @@ |
1 | +/* | |
2 | + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 | |
3 | + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a | |
4 | + * aplicativos mainframe. Registro no INPI sob o nome G3270. | |
5 | + * | |
6 | + * Copyright (C) <2008> <Banco do Brasil S.A.> | |
7 | + * | |
8 | + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob | |
9 | + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela | |
10 | + * Free Software Foundation. | |
11 | + * | |
12 | + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER | |
13 | + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO | |
14 | + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para | |
15 | + * obter mais detalhes. | |
16 | + * | |
17 | + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este | |
18 | + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin | |
19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | + * | |
21 | + * Este programa está nomeado como - e possui - linhas de código. | |
22 | + * | |
23 | + * Contatos: | |
24 | + * | |
25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
27 | + * | |
28 | + */ | |
29 | + | |
30 | + #include "private.h" | |
31 | + #include <stdlib.h> | |
32 | + | |
33 | +/*---[ Globals & Object definition ]----------------------------------------------------------------*/ | |
34 | + | |
35 | + enum { | |
36 | + PROP_NONE, | |
37 | + PROP_NAME, | |
38 | + PROP_LABEL, | |
39 | + PROP_POSITION, | |
40 | + PROP_WIDTH, | |
41 | + PROP_HEIGHT, | |
42 | + }; | |
43 | + | |
44 | + static const char * positions[] = { | |
45 | + "top", | |
46 | + "left", | |
47 | + "bottom", | |
48 | + "right" | |
49 | + }; | |
50 | + | |
51 | + static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); | |
52 | + static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); | |
53 | + | |
54 | + G_DEFINE_TYPE(KeypadModel, KeypadModel, G_TYPE_OBJECT) | |
55 | + | |
56 | +/*---[ Implement ]----------------------------------------------------------------------------------*/ | |
57 | + | |
58 | + static void finalize(GObject *object) { | |
59 | + | |
60 | + KeypadModel * model = PW_KEYPAD_MODEL(object); | |
61 | + | |
62 | + if(model->elements) { | |
63 | + g_list_free_full(model->elements,g_object_unref); | |
64 | + model->elements = NULL; | |
65 | + } | |
66 | + | |
67 | + if(model->name) { | |
68 | + g_free(model->name); | |
69 | + model->name = NULL; | |
70 | + } | |
71 | + | |
72 | + if(model->label) { | |
73 | + g_free(model->label); | |
74 | + model->label = NULL; | |
75 | + } | |
76 | + | |
77 | + } | |
78 | + | |
79 | + static void KeypadModel_class_init(KeypadModelClass *klass) { | |
80 | + | |
81 | + GObjectClass *object_class = G_OBJECT_CLASS(klass); | |
82 | + | |
83 | + klass->domain = g_quark_from_static_string("keypad"); | |
84 | + | |
85 | + object_class->finalize = finalize; | |
86 | + object_class->get_property = get_property; | |
87 | + object_class->set_property = set_property; | |
88 | + | |
89 | + // Install properties | |
90 | + g_object_class_install_property(object_class, PROP_NAME, | |
91 | + g_param_spec_string ( | |
92 | + I_("name"), | |
93 | + N_("Keypad Name"), | |
94 | + N_("The name used to identify the keypad"), | |
95 | + NULL, | |
96 | + G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | |
97 | + ) | |
98 | + ); | |
99 | + | |
100 | + g_object_class_install_property(object_class, PROP_LABEL, | |
101 | + g_param_spec_string ( | |
102 | + _("label"), | |
103 | + N_("Keypad Label"), | |
104 | + N_("The Label of the keypad"), | |
105 | + NULL, | |
106 | + G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | |
107 | + ) | |
108 | + ); | |
109 | + | |
110 | + g_object_class_install_property(object_class, PROP_POSITION, | |
111 | + g_param_spec_string ( | |
112 | + I_("position"), | |
113 | + I_("position"), | |
114 | + N_("The position of the keypad"), | |
115 | + NULL, | |
116 | + G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | |
117 | + ) | |
118 | + ); | |
119 | + | |
120 | + g_object_class_install_property(object_class, PROP_WIDTH, | |
121 | + g_param_spec_uint( | |
122 | + I_("width"), | |
123 | + I_("width"), | |
124 | + _("Keypad width in columns"), | |
125 | + 1, | |
126 | + 10, | |
127 | + 3, | |
128 | + G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | |
129 | + ) | |
130 | + ); | |
131 | + | |
132 | + g_object_class_install_property(object_class, PROP_WIDTH, | |
133 | + g_param_spec_uint( | |
134 | + I_("height"), | |
135 | + I_("height"), | |
136 | + _("Keypad height in rows"), | |
137 | + 0, | |
138 | + 100, | |
139 | + 0, | |
140 | + G_PARAM_STATIC_STRINGS | G_PARAM_READABLE | G_PARAM_WRITABLE | |
141 | + ) | |
142 | + ); | |
143 | + } | |
144 | + | |
145 | + static void KeypadModel_init(KeypadModel *object) { | |
146 | + | |
147 | + object->position = (unsigned short) KEYPAD_POSITION_BOTTOM; | |
148 | + | |
149 | + } | |
150 | + | |
151 | + static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec G_GNUC_UNUSED(*pspec)) { | |
152 | + | |
153 | + KeypadModel * model = PW_KEYPAD_MODEL(object); | |
154 | + | |
155 | + switch (prop_id) { | |
156 | + case PROP_NAME: | |
157 | + g_value_set_string(value, model->name); | |
158 | + break; | |
159 | + | |
160 | + case PROP_LABEL: | |
161 | + g_value_set_string(value, model->label); | |
162 | + break; | |
163 | + | |
164 | + case PROP_POSITION: | |
165 | + g_value_set_static_string(value,keypad_model_get_position(object)); | |
166 | + break; | |
167 | + | |
168 | + case PROP_HEIGHT: | |
169 | + g_value_set_uint(value, model->height); | |
170 | + break; | |
171 | + | |
172 | + case PROP_WIDTH: | |
173 | + g_value_set_uint(value, model->width); | |
174 | + break; | |
175 | + | |
176 | + default: | |
177 | + g_assert_not_reached (); | |
178 | + } | |
179 | + | |
180 | + } | |
181 | + | |
182 | + static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec G_GNUC_UNUSED(*pspec)) { | |
183 | + | |
184 | + KeypadModel * model = PW_KEYPAD_MODEL(object); | |
185 | + | |
186 | + switch (prop_id) { | |
187 | + case PROP_NAME: | |
188 | + | |
189 | + if(model->name) { | |
190 | + g_free(model->name); | |
191 | + } | |
192 | + model->name = g_value_dup_string(value); | |
193 | + break; | |
194 | + | |
195 | + case PROP_LABEL: | |
196 | + | |
197 | + if(model->label) { | |
198 | + g_free(model->label); | |
199 | + } | |
200 | + model->label = g_value_dup_string(value); | |
201 | + break; | |
202 | + | |
203 | + case PROP_POSITION: | |
204 | + keypad_model_set_position(object,g_value_get_string(value)); | |
205 | + break; | |
206 | + | |
207 | + case PROP_HEIGHT: | |
208 | + model->height = (unsigned short) g_value_get_uint(value); | |
209 | + break; | |
210 | + | |
211 | + case PROP_WIDTH: | |
212 | + model->width = (unsigned short) g_value_get_uint(value); | |
213 | + break; | |
214 | + | |
215 | + default: | |
216 | + g_assert_not_reached(); | |
217 | + } | |
218 | + } | |
219 | + | |
220 | + void keypad_model_set_position(GObject *model, const gchar *position) { | |
221 | + | |
222 | + if(position) { | |
223 | + size_t ix; | |
224 | + for(ix = 0; ix < G_N_ELEMENTS(positions); ix++) { | |
225 | + if(!g_ascii_strcasecmp(positions[ix],position)) { | |
226 | + PW_KEYPAD_MODEL(model)->position = (unsigned short) ix; | |
227 | + break; | |
228 | + } | |
229 | + } | |
230 | + } | |
231 | + | |
232 | + } | |
233 | + | |
234 | + const gchar * keypad_model_get_position(GObject *model) { | |
235 | + | |
236 | + size_t ix = (size_t) PW_KEYPAD_MODEL(model)->position; | |
237 | + | |
238 | + if(ix < G_N_ELEMENTS(positions)) | |
239 | + return positions[ix]; | |
240 | + | |
241 | + return "undefined"; | |
242 | + } | |
243 | + | |
244 | + static void element_start(GMarkupParseContext *context, const gchar *element_name, const gchar **names,const gchar **values, KeypadModel *keypad, GError **error) { | |
245 | + | |
246 | + debug("%s(%s)",__FUNCTION__,element_name); | |
247 | + | |
248 | + if(!g_ascii_strcasecmp(element_name,"button")) { | |
249 | + | |
250 | + const gchar *row, *col, *width, *height; | |
251 | + KeypadElement * element = PW_KEYPAD_ELEMENT(g_object_new(PW_TYPE_KEYPAD_ELEMENT,NULL)); | |
252 | + | |
253 | + if(!g_markup_collect_attributes( | |
254 | + element_name,names,values,error, | |
255 | + G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "row", &row, | |
256 | + G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "column", &col, | |
257 | + G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "width", &width, | |
258 | + G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "height", &height, | |
259 | + G_MARKUP_COLLECT_INVALID | |
260 | + )) { | |
261 | + | |
262 | + return; | |
263 | + | |
264 | + } | |
265 | + | |
266 | + if(col) { | |
267 | + element->col = (unsigned short) atoi(col); | |
268 | + | |
269 | + if(element->col < keypad->current.col) { | |
270 | + keypad->current.row++; | |
271 | + } | |
272 | + | |
273 | + } else { | |
274 | + element->col = keypad->current.col; | |
275 | + } | |
276 | + | |
277 | + if(row) { | |
278 | + element->row = (unsigned short) atoi(row); | |
279 | + } else { | |
280 | + element->row = keypad->current.row; | |
281 | + } | |
282 | + | |
283 | + | |
284 | + if(width) { | |
285 | + element->width = (unsigned short) atoi(width); | |
286 | + } else { | |
287 | + element->width = 1; | |
288 | + } | |
289 | + | |
290 | + if(height) { | |
291 | + element->height = (unsigned short) atoi(height); | |
292 | + } else { | |
293 | + element->height = 1; | |
294 | + } | |
295 | + | |
296 | + keypad->elements = g_list_prepend(keypad->elements,element); | |
297 | + keypad_model_element_parse_context(G_OBJECT(element),context); | |
298 | + | |
299 | + } else if(!g_ascii_strcasecmp(element_name,"attribute")) { | |
300 | + attribute_element_start(context,names,values,G_OBJECT(keypad),error); | |
301 | + } | |
302 | + | |
303 | + } | |
304 | + | |
305 | + static void element_end(GMarkupParseContext *context, const gchar *element_name, KeypadModel *keypad, GError G_GNUC_UNUSED(**error)) { | |
306 | + | |
307 | + debug("%s(%s)",__FUNCTION__,element_name); | |
308 | + | |
309 | + if(!g_ascii_strcasecmp(element_name,"button")) { | |
310 | + g_markup_parse_context_pop(context); | |
311 | + | |
312 | + KeypadElement * element = PW_KEYPAD_ELEMENT(g_list_first(keypad->elements)->data); | |
313 | + | |
314 | + keypad->current.row = element->row; | |
315 | + keypad->current.col = element->col + element->width; | |
316 | + | |
317 | + if(keypad->width && keypad->current.col >= keypad->width) { | |
318 | + keypad->current.col = 0; | |
319 | + keypad->current.row++; | |
320 | + } | |
321 | + | |
322 | + } else if(!g_ascii_strcasecmp(element_name,"attribute")) { | |
323 | + attribute_element_end(context,G_OBJECT(keypad),error); | |
324 | + } | |
325 | + | |
326 | + } | |
327 | + | |
328 | + void keypad_model_parse_context(GObject *object, GMarkupParseContext *context) { | |
329 | + | |
330 | + static const GMarkupParser parser = { | |
331 | + (void (*)(GMarkupParseContext *, const gchar *, const gchar **, const gchar **, gpointer, GError **)) | |
332 | + element_start, | |
333 | + | |
334 | + (void (*)(GMarkupParseContext *, const gchar *, gpointer, GError **)) | |
335 | + element_end, | |
336 | + NULL, | |
337 | + NULL, | |
338 | + NULL | |
339 | + }; | |
340 | + | |
341 | + KeypadModel * model = PW_KEYPAD_MODEL(object); | |
342 | + | |
343 | + model->elements = g_list_reverse(model->elements); | |
344 | + g_markup_parse_context_push(context, &parser, model); | |
345 | + model->elements = g_list_reverse(model->elements); | |
346 | + | |
347 | + } | |
348 | + | |
349 | + KEYPAD_POSITION pw3270_keypad_get_position(GObject *model) { | |
350 | + g_return_val_if_fail(PW_IS_KEYPAD_MODEL(model), (KEYPAD_POSITION) -1); | |
351 | + return (KEYPAD_POSITION) PW_KEYPAD_MODEL(model)->position; | |
352 | + } | |
353 | + | |
354 | + const gchar * pw3270_keypad_model_get_action_name(GObject *model) { | |
355 | + g_return_val_if_fail(PW_IS_KEYPAD_MODEL(model), NULL); | |
356 | + return PW_KEYPAD_MODEL(model)->name; | |
357 | + } | |
358 | + | |
359 | + const gchar * pw3270_keypad_model_get_label(GObject *model) { | |
360 | + g_return_val_if_fail(PW_IS_KEYPAD_MODEL(model), NULL); | |
361 | + return PW_KEYPAD_MODEL(model)->label; | |
362 | + } | |
363 | + | ... | ... |
src/objects/window/window.c
... | ... | @@ -183,6 +183,17 @@ |
183 | 183 | |
184 | 184 | GtkWidget * widget = pw3270_keypad_get_from_model(model); |
185 | 185 | |
186 | + V3270SimpleAction * action = v3270_property_action_new(widget,"visible",LIB3270_ACTION_GROUP_NONE); | |
187 | + | |
188 | + action->name = pw3270_keypad_model_get_action_name(model); | |
189 | + debug("*********** name=%s",action->name); | |
190 | + action->label = pw3270_keypad_model_get_label(model); | |
191 | + debug("*********** label=%s",action->label); | |
192 | + | |
193 | + g_action_map_add_action( | |
194 | + G_ACTION_MAP(window), | |
195 | + G_ACTION(action) | |
196 | + ); | |
186 | 197 | |
187 | 198 | return widget; |
188 | 199 | ... | ... |