Commit 858b95b6c7710155a6ab7b4a0484319f70f6f257
1 parent
847739b8
Exists in
master
and in
4 other branches
Implementing toolbar actions.
Showing
9 changed files
with
134 additions
and
3 deletions
Show diff stats
pw3270.cbp
| ... | ... | @@ -73,6 +73,9 @@ |
| 73 | 73 | <Unit filename="src/objects/actions/window.c"> |
| 74 | 74 | <Option compilerVar="CC" /> |
| 75 | 75 | </Unit> |
| 76 | + <Unit filename="src/objects/toolbar/actions.c"> | |
| 77 | + <Option compilerVar="CC" /> | |
| 78 | + </Unit> | |
| 76 | 79 | <Unit filename="src/objects/toolbar/private.h" /> |
| 77 | 80 | <Unit filename="src/objects/toolbar/toolbar.c"> |
| 78 | 81 | <Option compilerVar="CC" /> | ... | ... |
src/include/pw3270/actions.h
| ... | ... | @@ -56,6 +56,15 @@ |
| 56 | 56 | const gchar * pw3270_action_get_name(GAction *action); |
| 57 | 57 | void pw3270_action_set_name(GAction *action, const gchar *name); |
| 58 | 58 | |
| 59 | + /// @brief Get the action icon name. | |
| 60 | + const gchar * pw3270_action_get_icon_name(GAction *action); | |
| 61 | + | |
| 62 | + /// @brief Get the action label. | |
| 63 | + const gchar * pw3270_action_get_label(GAction *action); | |
| 64 | + | |
| 65 | + /// @brief Get the action tooltip. | |
| 66 | + const gchar * pw3270_action_get_tooltip(GAction *action); | |
| 67 | + | |
| 59 | 68 | /// @brief Associate action with the terminal widget. |
| 60 | 69 | void pw3270_action_set_terminal_widget(GAction *action, GtkWidget *terminal); |
| 61 | 70 | ... | ... |
src/include/pw3270/toolbar.h
| ... | ... | @@ -52,8 +52,12 @@ |
| 52 | 52 | typedef struct _pw3270ToolBar pw3270ToolBar; |
| 53 | 53 | typedef struct _pw3270ToolBarClass pw3270ToolBarClass; |
| 54 | 54 | |
| 55 | + GType pw3270ToolBar_get_type(void) G_GNUC_CONST; | |
| 56 | + | |
| 55 | 57 | GtkWidget * pw3270_toolbar_new(void); |
| 58 | + | |
| 56 | 59 | GtkWidget * pw3270_toolbar_insert_lib3270_action(GtkWidget *toolbar, const LIB3270_ACTION *action, gint pos); |
| 60 | + GtkWidget * pw3270_toolbar_insert_action(GtkWidget *toolbar, GAction *action, gint pos); | |
| 57 | 61 | |
| 58 | 62 | G_END_DECLS |
| 59 | 63 | ... | ... |
src/objects/actions/abstract.c
| ... | ... | @@ -42,6 +42,7 @@ |
| 42 | 42 | static gboolean get_enabled(GAction *action, GtkWidget *terminal); |
| 43 | 43 | static void activate(GAction *action, GVariant *parameter, GtkWidget *terminal); |
| 44 | 44 | static void change_widget(GAction *action, GtkWidget *from, GtkWidget *to); |
| 45 | + static const gchar *get_null(GAction *action); | |
| 45 | 46 | |
| 46 | 47 | static void finalize(GObject *object); |
| 47 | 48 | |
| ... | ... | @@ -95,6 +96,9 @@ |
| 95 | 96 | klass->get_enabled = get_enabled; |
| 96 | 97 | klass->activate = activate; |
| 97 | 98 | klass->get_parameter_type = get_parameter_type; |
| 99 | + klass->get_icon_name = get_null; | |
| 100 | + klass->get_label = get_null; | |
| 101 | + klass->get_tooltip = get_null; | |
| 98 | 102 | |
| 99 | 103 | object_class->finalize = finalize; |
| 100 | 104 | object_class->set_property = pw3270_action_set_property; |
| ... | ... | @@ -409,3 +413,30 @@ |
| 409 | 413 | void activate(GAction *action, GVariant G_GNUC_UNUSED(*parameter), GtkWidget G_GNUC_UNUSED(*terminal)) { |
| 410 | 414 | g_message("Action %s can't be activated",pw3270_action_get_name(action)); |
| 411 | 415 | } |
| 416 | + | |
| 417 | + const gchar * get_null(GAction G_GNUC_UNUSED(*action)) { | |
| 418 | + return NULL; | |
| 419 | + } | |
| 420 | + | |
| 421 | + const gchar * pw3270_action_get_icon_name(GAction *action) { | |
| 422 | + return PW3270_ACTION_GET_CLASS(action)->get_icon_name(action); | |
| 423 | + } | |
| 424 | + | |
| 425 | + const gchar * pw3270_action_get_label(GAction *action) { | |
| 426 | + const gchar * label = PW3270_ACTION_GET_CLASS(action)->get_label(action); | |
| 427 | + | |
| 428 | + if(label) | |
| 429 | + return gettext(label); | |
| 430 | + | |
| 431 | + return NULL; | |
| 432 | + } | |
| 433 | + | |
| 434 | + const gchar * pw3270_action_get_tooltip(GAction *action) { | |
| 435 | + const gchar * tooltip = PW3270_ACTION_GET_CLASS(action)->get_tooltip(action); | |
| 436 | + | |
| 437 | + if(tooltip) | |
| 438 | + return gettext(tooltip); | |
| 439 | + | |
| 440 | + return NULL; | |
| 441 | + } | |
| 442 | + | ... | ... |
src/objects/actions/lib3270/action.c
| ... | ... | @@ -66,10 +66,22 @@ |
| 66 | 66 | |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - static void activate(GAction *action, GVariant *parameter, GtkWidget *terminal) { | |
| 69 | + static void activate(GAction *action, GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) { | |
| 70 | 70 | PW3270_LIB3270_ACTION(action)->definition->activate(v3270_get_session(terminal)); |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | + static const gchar * get_icon_name(GAction *action) { | |
| 74 | + return PW3270_LIB3270_ACTION(action)->definition->icon; | |
| 75 | + } | |
| 76 | + | |
| 77 | + const gchar * get_label(GAction *action) { | |
| 78 | + return PW3270_LIB3270_ACTION(action)->definition->label; | |
| 79 | + } | |
| 80 | + | |
| 81 | + const gchar * get_tooltip(GAction *action) { | |
| 82 | + return PW3270_LIB3270_ACTION(action)->definition->summary; | |
| 83 | + } | |
| 84 | + | |
| 73 | 85 | void Lib3270Action_class_init(Lib3270ActionClass *klass) { |
| 74 | 86 | |
| 75 | 87 | pw3270ActionClass * action = PW3270_ACTION_CLASS(klass); |
| ... | ... | @@ -77,10 +89,13 @@ |
| 77 | 89 | action->activate = activate; |
| 78 | 90 | action->get_enabled = get_enabled; |
| 79 | 91 | action->change_widget = change_widget; |
| 92 | + action->get_icon_name = get_icon_name; | |
| 93 | + action->get_label = get_label; | |
| 94 | + action->get_tooltip = get_tooltip; | |
| 80 | 95 | |
| 81 | 96 | } |
| 82 | 97 | |
| 83 | - void Lib3270Action_init(Lib3270Action *action) { | |
| 98 | + void Lib3270Action_init(Lib3270Action G_GNUC_UNUSED(*action)) { | |
| 84 | 99 | } |
| 85 | 100 | |
| 86 | 101 | GAction * pw3270_action_new_from_lib3270(const LIB3270_ACTION * definition) { | ... | ... |
src/objects/actions/private.h
| ... | ... | @@ -73,6 +73,9 @@ |
| 73 | 73 | gboolean (*get_enabled)(GAction *action, GtkWidget *terminal); |
| 74 | 74 | void (*activate)(GAction *action, GVariant *parameter, GtkWidget *terminal); |
| 75 | 75 | const GVariantType * (*get_parameter_type)(GAction *action); |
| 76 | + const gchar * (*get_icon_name)(GAction *action); | |
| 77 | + const gchar * (*get_label)(GAction *action); | |
| 78 | + const gchar * (*get_tooltip)(GAction *action); | |
| 76 | 79 | |
| 77 | 80 | }; |
| 78 | 81 | ... | ... |
| ... | ... | @@ -0,0 +1,62 @@ |
| 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 <pw3270/actions.h> | |
| 32 | + | |
| 33 | + GtkWidget * pw3270_toolbar_insert_action(GtkWidget *toolbar, GAction *action, gint pos) { | |
| 34 | + | |
| 35 | + debug("toolbar=%p action=%p",toolbar,action); | |
| 36 | + | |
| 37 | + g_return_val_if_fail(PW3270_IS_ACTION(action) && PW3270_IS_TOOLBAR(toolbar),NULL); | |
| 38 | + | |
| 39 | + const gchar * icon_name = pw3270_action_get_icon_name(action); | |
| 40 | + if(!icon_name) { | |
| 41 | + g_message("Action doesn't have an icon"); | |
| 42 | + return NULL; | |
| 43 | + } | |
| 44 | + | |
| 45 | + debug("%s - %s",icon_name,pw3270_action_get_label(action)); | |
| 46 | + | |
| 47 | + GtkToolItem * item = gtk_tool_button_new( | |
| 48 | + gtk_image_new_from_icon_name(icon_name,GTK_ICON_SIZE_LARGE_TOOLBAR), | |
| 49 | + pw3270_action_get_label(action) | |
| 50 | + ); | |
| 51 | + | |
| 52 | + gtk_tool_button_set_use_underline(GTK_TOOL_BUTTON(item),TRUE); | |
| 53 | + | |
| 54 | + gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, pos); | |
| 55 | + gtk_widget_show_all(GTK_WIDGET(item)); | |
| 56 | + | |
| 57 | + const gchar * tooltip = pw3270_action_get_tooltip(action); | |
| 58 | + if(tooltip) | |
| 59 | + gtk_widget_set_tooltip_markup(GTK_WIDGET(item),tooltip); | |
| 60 | + | |
| 61 | + return GTK_WIDGET(item); | |
| 62 | + } | ... | ... |
src/objects/toolbar/toolbar.c
src/objects/window/window.c
| ... | ... | @@ -57,7 +57,6 @@ |
| 57 | 57 | |
| 58 | 58 | widget->toolbar = GTK_TOOLBAR(pw3270_toolbar_new()); |
| 59 | 59 | |
| 60 | - | |
| 61 | 60 | gtk_box_pack_start(vBox,GTK_WIDGET(widget->toolbar),FALSE,TRUE,0); |
| 62 | 61 | gtk_box_pack_start(vBox,GTK_WIDGET(widget->notebook),TRUE,TRUE,0); |
| 63 | 62 | |
| ... | ... | @@ -69,6 +68,10 @@ |
| 69 | 68 | // |
| 70 | 69 | pw3270_window_add_actions(GTK_WIDGET(widget)); |
| 71 | 70 | |
| 71 | + pw3270_toolbar_insert_action(GTK_WIDGET(widget->toolbar), g_action_map_lookup_action(G_ACTION_MAP(widget), "win.reconnect"), -1); | |
| 72 | + | |
| 73 | + //gtk_widget_show_all(GTK_WIDGET(widget->toolbar)); | |
| 74 | + | |
| 72 | 75 | // |
| 73 | 76 | // Setup Window actions. |
| 74 | 77 | // | ... | ... |