From f2ab9a417aa20cdc169bc6356a2a359a8e67e9e3 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Fri, 14 Feb 2020 15:22:40 -0300 Subject: [PATCH] Refactoring actions. --- src/terminal/actions/pakey.c | 2 +- src/terminal/actions/pfkey.c | 3 +-- src/terminal/actions/table.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------- src/terminal/actions/toggle.c | 2 +- src/terminal/drawing/surface.c | 17 +++++++++++------ 5 files changed, 71 insertions(+), 24 deletions(-) diff --git a/src/terminal/actions/pakey.c b/src/terminal/actions/pakey.c index d816544..1592175 100644 --- a/src/terminal/actions/pakey.c +++ b/src/terminal/actions/pakey.c @@ -88,7 +88,7 @@ } static gboolean get_enabled(GAction *action, GtkWidget *terminal) { - return V3270_ACTION_GET_CLASS(action)->get_enabled(action,terminal); + return TRUE; } void Lib3270PaAction_class_init(Lib3270PaActionClass *klass) { diff --git a/src/terminal/actions/pfkey.c b/src/terminal/actions/pfkey.c index d44b5b7..6b0c11b 100644 --- a/src/terminal/actions/pfkey.c +++ b/src/terminal/actions/pfkey.c @@ -88,14 +88,13 @@ } static gboolean get_enabled(GAction *action, GtkWidget *terminal) { - return V3270_ACTION_GET_CLASS(action)->get_enabled(action,terminal); + return TRUE; } void Lib3270PfAction_class_init(Lib3270PfActionClass *klass) { klass->parent_class.parent_class.get_parameter_type = get_parameter_type; klass->parent_class.parent_class.activate = activate; klass->parent_class.parent_class.get_enabled = get_enabled; - } void Lib3270PfAction_init(Lib3270PfAction *action) { diff --git a/src/terminal/actions/table.c b/src/terminal/actions/table.c index 5c264c0..1cadd94 100644 --- a/src/terminal/actions/table.c +++ b/src/terminal/actions/table.c @@ -42,6 +42,25 @@ #define GDK_ALT_MASK GDK_MOD1_MASK #endif + #define LIB3270_TYPE_V3270_INTERNAL_ACTION (V270InternalAction_get_type()) + #define V3270_INTERNAL_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), LIB3270_TYPE_V3270_INTERNAL_ACTION, V270InternalAction)) + + #define GET_DESCRIPTOR(obj) ((const V3270_ACTION *) V3270_INTERNAL_ACTION(obj)->definition) + + typedef struct _V270InternalActionClass { + V3270ActionClass parent_class; + } V270InternalActionClass; + + typedef struct _V270InternalAction { + V3270Action parent; + const V3270_ACTION * definition; + } V270InternalAction; + + static void V270InternalAction_class_init(V270InternalActionClass *klass); + static void V270InternalAction_init(V270InternalAction *action); + + G_DEFINE_TYPE(V270InternalAction, V270InternalAction, V3270_TYPE_ACTION); + /*--[ Globals ]--------------------------------------------------------------------------------------*/ static const V3270_ACTION actions[] = @@ -344,31 +363,56 @@ return actions; } - static void activate_v3270(GAction *action, GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) - { + static const gchar * get_icon_name(GAction *action) { + return GET_DESCRIPTOR(action)->icon; + } + + static const gchar * get_label(GAction *action) { + return GET_DESCRIPTOR(action)->label; + } + + static const gchar * get_tooltip(GAction *action) { + return GET_DESCRIPTOR(action)->summary; + } + + static const gchar * get_name(GAction *action) { + return GET_DESCRIPTOR(action)->name; + } + + static void activate(GAction *action, GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) { + debug("Activating action \"%s\"",g_action_get_name(action)); - /* - V3270_ACTION * descriptor = (V3270_ACTION *) ((V3270Action *) action)->info; - descriptor->activate(terminal,descriptor); - */ + const V3270_ACTION *descriptor = GET_DESCRIPTOR(action); + + descriptor->activate(terminal,descriptor); } - void g_action_map_add_v3270_actions(GActionMap *action_map) - { + static void V270InternalAction_class_init(V270InternalActionClass *klass) { + + klass->parent_class.get_name = get_name; + klass->parent_class.get_icon_name = get_icon_name; + klass->parent_class.get_label = get_label; + klass->parent_class.get_tooltip = get_tooltip; + klass->parent_class.activate = activate; + + } + + static void V270InternalAction_init(V270InternalAction G_GNUC_UNUSED(*action)) { + } + + void g_action_map_add_v3270_actions(GActionMap *action_map) { const V3270_ACTION * actions = v3270_get_actions(); size_t ix; - /* for(ix = 0; actions[ix].name; ix++) { - V3270Action * action = V3270_ACTION(g_object_new(V3270_TYPE_ACTION, NULL)); + V270InternalAction * action = V3270_INTERNAL_ACTION(g_object_new(LIB3270_TYPE_V3270_INTERNAL_ACTION, NULL)); - action->info = (const LIB3270_PROPERTY *) &actions[ix]; - action->activate = activate_v3270; - action->translation_domain = GETTEXT_PACKAGE; + action->definition = &actions[ix]; + action->parent.translation_domain = GETTEXT_PACKAGE; if(!g_action_get_name(G_ACTION(action))) { g_warning("Action \"%s\" is invalid",actions[ix].name); @@ -377,7 +421,6 @@ } } - */ } diff --git a/src/terminal/actions/toggle.c b/src/terminal/actions/toggle.c index 3ce5994..d8c5631 100644 --- a/src/terminal/actions/toggle.c +++ b/src/terminal/actions/toggle.c @@ -113,7 +113,7 @@ } static gboolean get_enabled(GAction *action, GtkWidget *terminal) { - return V3270_ACTION_GET_CLASS(action)->get_enabled(action,terminal); + return TRUE; } void Lib3270ToggleAction_class_init(Lib3270ToggleActionClass *klass) { diff --git a/src/terminal/drawing/surface.c b/src/terminal/drawing/surface.c index 7a6b9f2..5dad9ce 100644 --- a/src/terminal/drawing/surface.c +++ b/src/terminal/drawing/surface.c @@ -45,15 +45,18 @@ */ void v3270_reconfigure(v3270 * terminal) { - GtkAllocation allocation; - GtkWidget *widget; - GdkEvent *event = gdk_event_new(GDK_CONFIGURE); + GtkWidget * widget = GTK_WIDGET(terminal); + GdkWindow * window = gtk_widget_get_window(widget); - widget = GTK_WIDGET(terminal); + // If the widget isn't realized just return. + if(!window) + return; + GtkAllocation allocation; gtk_widget_get_allocation(widget, &allocation); - event->configure.window = g_object_ref(gtk_widget_get_window(widget)); + GdkEvent *event = gdk_event_new(GDK_CONFIGURE); + event->configure.window = g_object_ref(window); event->configure.send_event = TRUE; event->configure.x = allocation.x; event->configure.y = allocation.y; @@ -63,7 +66,7 @@ void v3270_reconfigure(v3270 * terminal) if(terminal->surface) cairo_surface_destroy(terminal->surface); - terminal->surface = (cairo_surface_t *) gdk_window_create_similar_surface(gtk_widget_get_window(widget),CAIRO_CONTENT_COLOR,allocation.width,allocation.height); + terminal->surface = (cairo_surface_t *) gdk_window_create_similar_surface(window,CAIRO_CONTENT_COLOR,allocation.width,allocation.height); // Update the created image cairo_t * cr = cairo_create(terminal->surface); @@ -80,7 +83,9 @@ void v3270_reconfigure(v3270 * terminal) #endif gtk_widget_event(widget, event); + gdk_event_free(event); } + -- libgit2 0.21.2