Commit 2439885252edee98bdc1f02cf2450c416ac70f45
1 parent
e60b57c4
Exists in
master
and in
4 other branches
Implementing "color.set" action.
Showing
7 changed files
with
177 additions
and
6 deletions
Show diff stats
pw3270.cbp
| @@ -76,6 +76,9 @@ | @@ -76,6 +76,9 @@ | ||
| 76 | <Option compilerVar="CC" /> | 76 | <Option compilerVar="CC" /> |
| 77 | </Unit> | 77 | </Unit> |
| 78 | <Unit filename="src/objects/actions/private.h" /> | 78 | <Unit filename="src/objects/actions/private.h" /> |
| 79 | + <Unit filename="src/objects/actions/simple.c"> | ||
| 80 | + <Option compilerVar="CC" /> | ||
| 81 | + </Unit> | ||
| 79 | <Unit filename="src/objects/actions/window.c"> | 82 | <Unit filename="src/objects/actions/window.c"> |
| 80 | <Option compilerVar="CC" /> | 83 | <Option compilerVar="CC" /> |
| 81 | </Unit> | 84 | </Unit> |
src/include/pw3270/actions.h
| @@ -42,6 +42,9 @@ | @@ -42,6 +42,9 @@ | ||
| 42 | 42 | ||
| 43 | G_BEGIN_DECLS | 43 | G_BEGIN_DECLS |
| 44 | 44 | ||
| 45 | + // | ||
| 46 | + // Abstract action | ||
| 47 | + // | ||
| 45 | #define PW3270_TYPE_ACTION (pw3270Action_get_type()) | 48 | #define PW3270_TYPE_ACTION (pw3270Action_get_type()) |
| 46 | #define PW3270_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), PW3270_TYPE_ACTION, pw3270Action)) | 49 | #define PW3270_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), PW3270_TYPE_ACTION, pw3270Action)) |
| 47 | #define PW3270_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PW3270_TYPE_ACTION, pw3270ActionClass)) | 50 | #define PW3270_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PW3270_TYPE_ACTION, pw3270ActionClass)) |
| @@ -110,6 +113,47 @@ | @@ -110,6 +113,47 @@ | ||
| 110 | /// @brief Add lib3270 actions to an application window. | 113 | /// @brief Add lib3270 actions to an application window. |
| 111 | void pw3270_window_add_actions(GtkWidget * appwindow); | 114 | void pw3270_window_add_actions(GtkWidget * appwindow); |
| 112 | 115 | ||
| 116 | + // | ||
| 117 | + // "Simple" action | ||
| 118 | + // | ||
| 119 | + #define PW3270_TYPE_SIMPLE_ACTION (pw3270SimpleAction_get_type()) | ||
| 120 | + #define PW3270_SIMPLE_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), PW3270_TYPE_SIMPLE_ACTION, pw3270SimpleAction)) | ||
| 121 | + #define PW3270_SIMPLE_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), PW3270_TYPE_SIMPLE_ACTION, pw3270SimpleActionClass)) | ||
| 122 | + #define PW3270_IS_SIMPLE_ACTION(inst) (G_TYPE_CHECK_INSTANCE_TYPE ((inst), PW3270_TYPE_SIMPLE_ACTION)) | ||
| 123 | + #define PW3270_IS_SIMPLE_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), PW3270_TYPE_SIMPLE_ACTION)) | ||
| 124 | + #define PW3270_SIMPLE_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), PW3270_TYPE_SIMPLE_ACTION, pw3270SimpleActionClass)) | ||
| 125 | + | ||
| 126 | + typedef struct _pw3270SimpleAction { | ||
| 127 | + | ||
| 128 | + pw3270Action parent; | ||
| 129 | + | ||
| 130 | + // Fixed data | ||
| 131 | + const gchar * icon_name; | ||
| 132 | + const gchar * label; | ||
| 133 | + const gchar * tooltip; | ||
| 134 | + | ||
| 135 | + /// @brief Activation method. | ||
| 136 | + void (*activate)(GAction *action, GVariant *parameter, GtkWidget *terminal); | ||
| 137 | + | ||
| 138 | + } pw3270SimpleAction; | ||
| 139 | + | ||
| 140 | + typedef struct _pw3270SimpleActionClass { | ||
| 141 | + | ||
| 142 | + pw3270ActionClass parent_class; | ||
| 143 | + | ||
| 144 | + } pw3270SimpleActionClass; | ||
| 145 | + | ||
| 146 | + GType pw3270SimpleAction_get_type(void) G_GNUC_CONST; | ||
| 147 | + | ||
| 148 | + /// @brief Create an empty simple action. | ||
| 149 | + pw3270SimpleAction * pw3270_simple_action_new(); | ||
| 150 | + | ||
| 151 | + /// @brief New simple action from LIB3270's control data. | ||
| 152 | + pw3270SimpleAction * pw3270_simple_action_new_from_lib3270(const LIB3270_ACTION * definition, const gchar *name); | ||
| 153 | + | ||
| 154 | + /// @brief New simple action from LIB3270's action name. | ||
| 155 | + pw3270SimpleAction * pw3270_simple_action_new_from_name(const gchar *source_name, const gchar *name); | ||
| 156 | + | ||
| 113 | G_END_DECLS | 157 | G_END_DECLS |
| 114 | 158 | ||
| 115 | #endif // PW3270_ACTIONS_H_INCLUDED | 159 | #endif // PW3270_ACTIONS_H_INCLUDED |
src/objects/actions/abstract.c
| @@ -354,8 +354,13 @@ | @@ -354,8 +354,13 @@ | ||
| 354 | 354 | ||
| 355 | } | 355 | } |
| 356 | 356 | ||
| 357 | - static void change_widget(GAction *action, GtkWidget G_GNUC_UNUSED(*from), GtkWidget *to) { | ||
| 358 | - PW3270_ACTION(action)->terminal = to; | 357 | + static void change_widget(GAction *action, GtkWidget *from, GtkWidget *to) { |
| 358 | + | ||
| 359 | + if(from != to) { | ||
| 360 | + PW3270_ACTION(action)->terminal = to; | ||
| 361 | + pw3270_action_notify_enabled(action); | ||
| 362 | + } | ||
| 363 | + | ||
| 359 | } | 364 | } |
| 360 | 365 | ||
| 361 | void pw3270_action_set_terminal_widget(GAction *object, GtkWidget *widget) { | 366 | void pw3270_action_set_terminal_widget(GAction *object, GtkWidget *widget) { |
| @@ -383,6 +388,7 @@ | @@ -383,6 +388,7 @@ | ||
| 383 | 388 | ||
| 384 | if(action && action->terminal) { | 389 | if(action && action->terminal) { |
| 385 | enabled = PW3270_ACTION_GET_CLASS(object)->get_enabled(object,action->terminal); | 390 | enabled = PW3270_ACTION_GET_CLASS(object)->get_enabled(object,action->terminal); |
| 391 | + debug("Action %s is %s",g_action_get_name(object),enabled ? "enabled" : "disabled"); | ||
| 386 | } | 392 | } |
| 387 | 393 | ||
| 388 | return enabled; | 394 | return enabled; |
| @@ -402,7 +408,6 @@ | @@ -402,7 +408,6 @@ | ||
| 402 | } | 408 | } |
| 403 | 409 | ||
| 404 | gboolean get_enabled(GAction G_GNUC_UNUSED(*object), GtkWidget *terminal) { | 410 | gboolean get_enabled(GAction G_GNUC_UNUSED(*object), GtkWidget *terminal) { |
| 405 | - debug("Action %s is %s",pw3270_action_get_name(object),terminal == NULL ? "disabled" : "enabled"); | ||
| 406 | return terminal != NULL; | 411 | return terminal != NULL; |
| 407 | } | 412 | } |
| 408 | 413 | ||
| @@ -415,6 +420,8 @@ | @@ -415,6 +420,8 @@ | ||
| 415 | } | 420 | } |
| 416 | 421 | ||
| 417 | const gchar * pw3270_action_get_icon_name(GAction *action) { | 422 | const gchar * pw3270_action_get_icon_name(GAction *action) { |
| 423 | + debug("***********%s(%p)=%p",__FUNCTION__,action,PW3270_ACTION_GET_CLASS(action)->get_icon_name); | ||
| 424 | + debug("*************** %s",g_action_get_name(action)); | ||
| 418 | return PW3270_ACTION_GET_CLASS(action)->get_icon_name(action); | 425 | return PW3270_ACTION_GET_CLASS(action)->get_icon_name(action); |
| 419 | } | 426 | } |
| 420 | 427 |
| @@ -0,0 +1,109 @@ | @@ -0,0 +1,109 @@ | ||
| 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 PW3270 Simple Action. | ||
| 32 | + * | ||
| 33 | + */ | ||
| 34 | + | ||
| 35 | + #include "private.h" | ||
| 36 | + | ||
| 37 | + static void pw3270SimpleAction_class_init(pw3270SimpleActionClass *klass); | ||
| 38 | + static void pw3270SimpleAction_init(pw3270SimpleAction *action); | ||
| 39 | + | ||
| 40 | + G_DEFINE_TYPE(pw3270SimpleAction, pw3270SimpleAction, PW3270_TYPE_ACTION); | ||
| 41 | + | ||
| 42 | + static void activate(GAction G_GNUC_UNUSED(*action), GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) { | ||
| 43 | + | ||
| 44 | + debug("%s",__FUNCTION__); | ||
| 45 | + | ||
| 46 | + } | ||
| 47 | + | ||
| 48 | + static gboolean get_enabled(GAction *action, GtkWidget *terminal) { | ||
| 49 | + return TRUE; | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + static const gchar * get_icon_name(GAction *action) { | ||
| 53 | + return PW3270_SIMPLE_ACTION(action)->icon_name; | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + static const gchar * get_label(GAction *action) { | ||
| 57 | + return PW3270_SIMPLE_ACTION(action)->label; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + static const gchar * get_tooltip(GAction *action) { | ||
| 61 | + return PW3270_SIMPLE_ACTION(action)->tooltip; | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + static void pw3270SimpleAction_class_init(pw3270SimpleActionClass *klass) { | ||
| 65 | + | ||
| 66 | + klass->parent_class.get_icon_name = get_icon_name; | ||
| 67 | + klass->parent_class.get_label = get_label; | ||
| 68 | + klass->parent_class.get_tooltip = get_tooltip; | ||
| 69 | + klass->parent_class.get_enabled = get_enabled; | ||
| 70 | + | ||
| 71 | + debug("%s:%p",__FUNCTION__,klass->parent_class.get_icon_name); | ||
| 72 | + | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + static void pw3270SimpleAction_init(pw3270SimpleAction *action) { | ||
| 76 | + | ||
| 77 | + action->icon_name = NULL; | ||
| 78 | + action->label = N_( "No label" ); | ||
| 79 | + action->tooltip = NULL; | ||
| 80 | + | ||
| 81 | + } | ||
| 82 | + | ||
| 83 | + pw3270SimpleAction * pw3270_simple_action_new_from_lib3270(const LIB3270_ACTION * definition, const gchar *name) { | ||
| 84 | + | ||
| 85 | + if(!definition) | ||
| 86 | + return NULL; | ||
| 87 | + | ||
| 88 | + debug("%s(%s,%s)",__FUNCTION__,definition->name,name); | ||
| 89 | + | ||
| 90 | + pw3270SimpleAction * action = (pw3270SimpleAction *) g_object_new(PW3270_TYPE_SIMPLE_ACTION, NULL); | ||
| 91 | + | ||
| 92 | + action->parent.name = name ? name : definition->name; | ||
| 93 | + action->icon_name = definition->icon; | ||
| 94 | + action->label = definition->label; | ||
| 95 | + action->tooltip = definition->summary; | ||
| 96 | + action->activate = activate; | ||
| 97 | + | ||
| 98 | + return action; | ||
| 99 | + | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + pw3270SimpleAction * pw3270_simple_action_new_from_name(const gchar *source_name, const gchar *name) { | ||
| 103 | + return pw3270_simple_action_new_from_lib3270(lib3270_action_get_by_name(source_name),name); | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + pw3270SimpleAction * pw3270_simple_action_new() { | ||
| 107 | + return (pw3270SimpleAction *) g_object_new(PW3270_TYPE_SIMPLE_ACTION, NULL); | ||
| 108 | + } | ||
| 109 | + |
src/objects/window/actions/preferences.c
| @@ -41,6 +41,9 @@ | @@ -41,6 +41,9 @@ | ||
| 41 | action->activate = activate; | 41 | action->activate = activate; |
| 42 | action->name = "preferences"; | 42 | action->name = "preferences"; |
| 43 | 43 | ||
| 44 | + debug("action=%p",__FUNCTION__); | ||
| 45 | + debug("\n\n%s\n\n",pw3270_action_get_icon_name(G_ACTION(action))); | ||
| 46 | + | ||
| 44 | return G_ACTION(action); | 47 | return G_ACTION(action); |
| 45 | 48 | ||
| 46 | } | 49 | } |
src/objects/window/actions/setcolors.c
| @@ -38,10 +38,12 @@ | @@ -38,10 +38,12 @@ | ||
| 38 | 38 | ||
| 39 | GAction * pw3270_set_color_action_new(void) { | 39 | GAction * pw3270_set_color_action_new(void) { |
| 40 | 40 | ||
| 41 | - pw3270Action * action = PW3270_ACTION(pw3270_action_new()); | 41 | + pw3270SimpleAction * action = pw3270_simple_action_new(); |
| 42 | 42 | ||
| 43 | - action->activate = activate; | ||
| 44 | - action->name = "setcolors"; | 43 | + action->parent.activate = activate; |
| 44 | + action->parent.name = "set.colors"; | ||
| 45 | + action->icon_name = "gtk-select-color"; | ||
| 46 | + action->label = N_("Colors"); | ||
| 45 | 47 | ||
| 46 | return G_ACTION(action); | 48 | return G_ACTION(action); |
| 47 | 49 | ||
| @@ -58,5 +60,7 @@ | @@ -58,5 +60,7 @@ | ||
| 58 | g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); | 60 | g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); |
| 59 | g_signal_connect(dialog,"response",G_CALLBACK(gtk_widget_destroy),NULL); | 61 | g_signal_connect(dialog,"response",G_CALLBACK(gtk_widget_destroy),NULL); |
| 60 | 62 | ||
| 63 | + gtk_widget_show_all(dialog); | ||
| 64 | + | ||
| 61 | } | 65 | } |
| 62 | 66 |
src/objects/window/window.c