Commit a1bc9024b04c9dabe10cb2c295798659eece921c
1 parent
c22a68ec
Exists in
master
and in
1 other branch
Adding simple & dialog actions.
Showing
5 changed files
with
333 additions
and
28 deletions
Show diff stats
src/include/v3270/actions.h
... | ... | @@ -149,6 +149,10 @@ |
149 | 149 | GVariant * (*get_state)(GAction *action, GtkWidget *terminal); |
150 | 150 | const gchar * (*translate)(GAction *action, const gchar *text); |
151 | 151 | |
152 | + const gchar * (*get_icon_name)(GAction *action); | |
153 | + const gchar * (*get_label)(GAction *action); | |
154 | + const gchar * (*get_tooltip)(GAction *action); | |
155 | + | |
152 | 156 | } V3270ActionClass; |
153 | 157 | |
154 | 158 | LIB3270_EXPORT GType V3270Action_get_type(void) G_GNUC_CONST; |
... | ... | @@ -179,6 +183,49 @@ |
179 | 183 | LIB3270_EXPORT void g_action_map_add_lib3270_actions(GActionMap *action_map); |
180 | 184 | LIB3270_EXPORT void g_action_map_add_lib3270_toggles(GActionMap *action_map); |
181 | 185 | |
186 | + // | |
187 | + // "Simple" action | |
188 | + // | |
189 | + #define V3270_TYPE_SIMPLE_ACTION (V3270SimpleAction_get_type()) | |
190 | + #define V3270_SIMPLE_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), V3270_TYPE_SIMPLE_ACTION, V3270SimpleAction)) | |
191 | + #define V3270_SIMPLE_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), V3270_TYPE_SIMPLE_ACTION, V3270SimpleActionClass)) | |
192 | + #define V3270_IS_SIMPLE_ACTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), V3270_TYPE_SIMPLE_ACTION)) | |
193 | + #define V3270_IS_SIMPLE_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), V3270_TYPE_SIMPLE_ACTION)) | |
194 | + #define V3270_SIMPLE_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), V3270_TYPE_SIMPLE_ACTION, V3270SimpleActionClass)) | |
195 | + | |
196 | + typedef struct _V3270SimpleAction { | |
197 | + | |
198 | + V3270Action parent; | |
199 | + | |
200 | + // Fixed data | |
201 | + const gchar * icon_name; | |
202 | + const gchar * label; | |
203 | + const gchar * tooltip; | |
204 | + | |
205 | + // Lib3270 Action group | |
206 | + struct { | |
207 | + LIB3270_ACTION_GROUP id; | |
208 | + const void * listener; | |
209 | + } group; | |
210 | + | |
211 | + /// @brief Activation method. | |
212 | + void (*activate)(GAction *action, GVariant *parameter, GtkWidget *terminal); | |
213 | + | |
214 | + } V3270SimpleAction; | |
215 | + | |
216 | + typedef struct _V3270SimpleActionClass { | |
217 | + | |
218 | + V3270ActionClass parent_class; | |
219 | + | |
220 | + } V3270SimpleActionClass; | |
221 | + | |
222 | + GType V3270SimpleAction_get_type(void) G_GNUC_CONST; | |
223 | + | |
224 | + /// @brief Create an empty simple action. | |
225 | + V3270SimpleAction * v3270_simple_action_new(); | |
226 | + | |
227 | + /// @brief Create a dialog action. | |
228 | + V3270SimpleAction * v3270_dialog_action_new(GtkWidget * (*factory)(V3270SimpleAction *, GtkWidget *)); | |
182 | 229 | |
183 | 230 | G_END_DECLS |
184 | 231 | ... | ... |
src/terminal/actions/action.c
... | ... | @@ -43,6 +43,10 @@ |
43 | 43 | static void get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec); |
44 | 44 | static void set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec); |
45 | 45 | |
46 | + static const gchar * get_icon_name(GAction *action); | |
47 | + static const gchar * get_label(GAction *action); | |
48 | + static const gchar * get_tooltip(GAction *action); | |
49 | + | |
46 | 50 | static void change_widget(GAction *action, GtkWidget *from, GtkWidget *to); |
47 | 51 | static void finalize(GObject *object); |
48 | 52 | |
... | ... | @@ -86,6 +90,10 @@ |
86 | 90 | klass->get_state = get_state; |
87 | 91 | klass->translate = translate; |
88 | 92 | |
93 | + klass->get_icon_name = get_icon_name; | |
94 | + klass->get_label = get_label; | |
95 | + klass->get_tooltip = get_tooltip; | |
96 | + | |
89 | 97 | klass->type.state = NULL; |
90 | 98 | klass->type.parameter = NULL; |
91 | 99 | |
... | ... | @@ -321,38 +329,10 @@ |
321 | 329 | g_message("Action %s can't be activated",g_action_get_name(action)); |
322 | 330 | } |
323 | 331 | |
324 | - const gchar * v3270_action_get_icon_name(GAction *action) { | |
325 | - return V3270_ACTION_GET_DESCRIPTOR(action)->icon; | |
326 | - } | |
327 | - | |
328 | 332 | const gchar * v3270_action_translate(GAction *action, const gchar *text) { |
329 | 333 | return V3270_ACTION_GET_CLASS(action)->translate(action,text); |
330 | 334 | } |
331 | 335 | |
332 | - const gchar * v3270_action_get_label(GAction *action) { | |
333 | - const gchar * label = V3270_ACTION_GET_DESCRIPTOR(action)->label; | |
334 | - | |
335 | - debug("%s(%s): [%s] [%s]",__FUNCTION__,g_action_get_name(action),label,v3270_action_translate(action,label)); | |
336 | - | |
337 | - if(label && *label) | |
338 | - return v3270_action_translate(action,label); | |
339 | - | |
340 | - return NULL; | |
341 | - } | |
342 | - | |
343 | - const gchar * v3270_action_get_tooltip(GAction *action) { | |
344 | - | |
345 | - const gchar * tooltip = V3270_ACTION_GET_DESCRIPTOR(action)->description; | |
346 | - | |
347 | - if(!tooltip) | |
348 | - tooltip = V3270_ACTION_GET_DESCRIPTOR(action)->summary; | |
349 | - | |
350 | - if(tooltip) | |
351 | - return v3270_action_translate(action,tooltip); | |
352 | - | |
353 | - return NULL; | |
354 | - } | |
355 | - | |
356 | 336 | // |
357 | 337 | // Action methods. |
358 | 338 | // |
... | ... | @@ -488,3 +468,44 @@ |
488 | 468 | |
489 | 469 | } |
490 | 470 | |
471 | + const gchar * get_icon_name(GAction *action) { | |
472 | + return V3270_ACTION_GET_DESCRIPTOR(action)->icon; | |
473 | + } | |
474 | + | |
475 | + const gchar * get_label(GAction *action) { | |
476 | + const gchar * label = V3270_ACTION_GET_DESCRIPTOR(action)->label; | |
477 | + | |
478 | + debug("%s(%s): [%s] [%s]",__FUNCTION__,g_action_get_name(action),label,v3270_action_translate(action,label)); | |
479 | + | |
480 | + if(label && *label) | |
481 | + return v3270_action_translate(action,label); | |
482 | + | |
483 | + return NULL; | |
484 | + } | |
485 | + | |
486 | + const gchar * get_tooltip(GAction *action) { | |
487 | + | |
488 | + const gchar * tooltip = V3270_ACTION_GET_DESCRIPTOR(action)->description; | |
489 | + | |
490 | + if(!tooltip) | |
491 | + tooltip = V3270_ACTION_GET_DESCRIPTOR(action)->summary; | |
492 | + | |
493 | + if(tooltip) | |
494 | + return v3270_action_translate(action,tooltip); | |
495 | + | |
496 | + return NULL; | |
497 | + | |
498 | + } | |
499 | + | |
500 | + const gchar * v3270_action_get_icon_name(GAction *action) { | |
501 | + return V3270_ACTION_GET_CLASS(action)->get_icon_name(action); | |
502 | + } | |
503 | + | |
504 | + const gchar * v3270_action_get_label(GAction *action) { | |
505 | + return V3270_ACTION_GET_CLASS(action)->get_label(action); | |
506 | + } | |
507 | + | |
508 | + const gchar * v3270_action_get_tooltip(GAction *action) { | |
509 | + return V3270_ACTION_GET_CLASS(action)->get_tooltip(action); | |
510 | + } | |
511 | + | ... | ... |
... | ... | @@ -0,0 +1,133 @@ |
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 | + /** | |
31 | + * @brief Implements V3270 Dialog Action. | |
32 | + * | |
33 | + */ | |
34 | + | |
35 | + #include "private.h" | |
36 | + #include <v3270.h> | |
37 | + #include <v3270/settings.h> | |
38 | + #include <v3270/actions.h> | |
39 | + | |
40 | + #define V3270_TYPE_DIALOG_ACTION (V3270DialogAction_get_type()) | |
41 | + #define V3270_DIALOG_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), V3270_TYPE_DIALOG_ACTION, V3270DialogAction)) | |
42 | + #define V3270_DIALOG_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), V3270_TYPE_DIALOG_ACTION, V3270DialogActionClass)) | |
43 | + #define V3270_IS_DIALOG_ACTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), V3270_TYPE_DIALOG_ACTION)) | |
44 | + #define V3270_IS_DIALOG_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), V3270_TYPE_DIALOG_ACTION)) | |
45 | + #define V3270_DIALOG_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), V3270_TYPE_DIALOG_ACTION, V3270DialogActionClass)) | |
46 | + | |
47 | + typedef struct _V3270DialogAction { | |
48 | + | |
49 | + V3270SimpleAction parent; | |
50 | + | |
51 | + GtkWidget * dialog; | |
52 | + GtkWidget * (*factory)(V3270SimpleAction *, GtkWidget *); | |
53 | + | |
54 | + } V3270DialogAction; | |
55 | + | |
56 | + typedef struct _V3270DialogActionClass { | |
57 | + | |
58 | + V3270SimpleActionClass parent_class; | |
59 | + | |
60 | + } V3270DialogActionClass; | |
61 | + | |
62 | + | |
63 | + static void V3270DialogAction_class_init(V3270DialogActionClass *klass); | |
64 | + static void V3270DialogAction_init(V3270DialogAction *action); | |
65 | + static void activate(GAction G_GNUC_UNUSED(*action), GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal); | |
66 | + | |
67 | + G_DEFINE_TYPE(V3270DialogAction, V3270DialogAction, V3270_TYPE_SIMPLE_ACTION); | |
68 | + | |
69 | + static gboolean get_enabled(GAction *action, GtkWidget *terminal) { | |
70 | + | |
71 | + if((V3270_DIALOG_ACTION(action)->dialog)) { | |
72 | + return FALSE; | |
73 | + } | |
74 | + | |
75 | + return V3270_ACTION_CLASS(V3270DialogAction_parent_class)->get_enabled(action,terminal); | |
76 | + | |
77 | + } | |
78 | + | |
79 | + static void V3270DialogAction_class_init(V3270DialogActionClass *klass) { | |
80 | + klass->parent_class.parent_class.get_enabled = get_enabled; | |
81 | + } | |
82 | + | |
83 | + static void V3270DialogAction_init(V3270DialogAction *action) { | |
84 | + | |
85 | + action->dialog = NULL; | |
86 | + action->parent.parent.activate = activate; | |
87 | + | |
88 | + } | |
89 | + | |
90 | + V3270SimpleAction * v3270_dialog_action_new(GtkWidget * (*factory)(V3270SimpleAction *, GtkWidget *)) { | |
91 | + | |
92 | + V3270DialogAction * action = (V3270DialogAction *) g_object_new(V3270_TYPE_DIALOG_ACTION, NULL); | |
93 | + action->factory = factory; | |
94 | + return V3270_SIMPLE_ACTION(action); | |
95 | + | |
96 | + } | |
97 | + | |
98 | + static void on_destroy(GtkWidget *dialog, V3270DialogAction *action) { | |
99 | + | |
100 | + if(action->dialog == dialog) { | |
101 | + action->dialog = NULL; | |
102 | + v3270_action_notify_enabled(G_ACTION(action)); | |
103 | + } | |
104 | + } | |
105 | + | |
106 | + void activate(GAction *object, GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) { | |
107 | + | |
108 | + if(!GTK_IS_V3270(terminal)) | |
109 | + return; | |
110 | + | |
111 | + V3270DialogAction * action = V3270_DIALOG_ACTION(object); | |
112 | + | |
113 | + if(!action->factory) { | |
114 | + g_warning("Action %s is invalid (no factory method)",g_action_get_name(G_ACTION(action))); | |
115 | + return; | |
116 | + } | |
117 | + | |
118 | + if(action->dialog) | |
119 | + return; | |
120 | + | |
121 | + action->dialog = action->factory((V3270SimpleAction *) object, terminal); | |
122 | + v3270_action_notify_enabled(G_ACTION(action)); | |
123 | + | |
124 | + if(action->dialog) { | |
125 | + | |
126 | + g_signal_connect(action->dialog,"destroy",G_CALLBACK(on_destroy),action); | |
127 | + g_signal_connect(action->dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); | |
128 | + gtk_widget_show(GTK_WIDGET(action->dialog)); | |
129 | + | |
130 | + } | |
131 | + | |
132 | + } | |
133 | + | ... | ... |
... | ... | @@ -0,0 +1,98 @@ |
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 | + /** | |
31 | + * @brief Implement V3270 Simple Action. | |
32 | + * | |
33 | + */ | |
34 | + | |
35 | + #include "private.h" | |
36 | + #include <v3270.h> | |
37 | + #include <v3270/actions.h> | |
38 | + | |
39 | + static void V3270SimpleAction_class_init(V3270SimpleActionClass *klass); | |
40 | + static void V3270SimpleAction_init(V3270SimpleAction *action); | |
41 | + | |
42 | + G_DEFINE_TYPE(V3270SimpleAction, V3270SimpleAction, V3270_TYPE_ACTION); | |
43 | + | |
44 | + static void activate(GAction *action, GVariant G_GNUC_UNUSED(*parameter), GtkWidget G_GNUC_UNUSED(*terminal)) { | |
45 | + g_warning("Action %s activation method is invalid",g_action_get_name(action)); | |
46 | + } | |
47 | + | |
48 | + static const gchar * get_icon_name(GAction *action) { | |
49 | + return V3270_SIMPLE_ACTION(action)->icon_name; | |
50 | + } | |
51 | + | |
52 | + static const gchar * get_label(GAction *action) { | |
53 | + return V3270_SIMPLE_ACTION(action)->label; | |
54 | + } | |
55 | + | |
56 | + static const gchar * get_tooltip(GAction *action) { | |
57 | + return V3270_SIMPLE_ACTION(action)->tooltip; | |
58 | + } | |
59 | + | |
60 | + static void dispose(GObject *object) { | |
61 | + | |
62 | + V3270SimpleAction *action = V3270_SIMPLE_ACTION(object); | |
63 | + | |
64 | + if(action->group.listener) { | |
65 | + lib3270_unregister_action_group_listener(v3270_action_get_session(G_ACTION(object)),action->group.id,action->group.listener); | |
66 | + action->group.listener = NULL; | |
67 | + } | |
68 | + | |
69 | + G_OBJECT_CLASS(V3270SimpleAction_parent_class)->dispose(object); | |
70 | + } | |
71 | + | |
72 | + static void V3270SimpleAction_class_init(V3270SimpleActionClass *klass) { | |
73 | + | |
74 | + klass->parent_class.get_icon_name = get_icon_name; | |
75 | + klass->parent_class.get_label = get_label; | |
76 | + klass->parent_class.get_tooltip = get_tooltip; | |
77 | + | |
78 | + G_OBJECT_CLASS(klass)->dispose = dispose; | |
79 | + | |
80 | + } | |
81 | + | |
82 | + static void V3270SimpleAction_init(V3270SimpleAction *action) { | |
83 | + | |
84 | + action->icon_name = NULL; | |
85 | + action->label = _( "No label" ); | |
86 | + action->tooltip = NULL; | |
87 | + action->activate = activate; | |
88 | + action->group.id = LIB3270_ACTION_GROUP_NONE; | |
89 | + action->group.listener = NULL; | |
90 | + | |
91 | + } | |
92 | + | |
93 | + V3270SimpleAction * v3270_simple_action_new() { | |
94 | + return (V3270SimpleAction *) g_object_new(V3270_TYPE_SIMPLE_ACTION, NULL); | |
95 | + } | |
96 | + | |
97 | + | |
98 | + | ... | ... |
v3270.cbp
... | ... | @@ -233,6 +233,9 @@ |
233 | 233 | <Unit filename="src/terminal/actions/clipboard.c"> |
234 | 234 | <Option compilerVar="CC" /> |
235 | 235 | </Unit> |
236 | + <Unit filename="src/terminal/actions/dialog.c"> | |
237 | + <Option compilerVar="CC" /> | |
238 | + </Unit> | |
236 | 239 | <Unit filename="src/terminal/actions/lib3270.c"> |
237 | 240 | <Option compilerVar="CC" /> |
238 | 241 | </Unit> |
... | ... | @@ -252,6 +255,9 @@ |
252 | 255 | <Unit filename="src/terminal/actions/scroll.c"> |
253 | 256 | <Option compilerVar="CC" /> |
254 | 257 | </Unit> |
258 | + <Unit filename="src/terminal/actions/simple.c"> | |
259 | + <Option compilerVar="CC" /> | |
260 | + </Unit> | |
255 | 261 | <Unit filename="src/terminal/actions/table.c"> |
256 | 262 | <Option compilerVar="CC" /> |
257 | 263 | </Unit> | ... | ... |