Commit f2ab9a417aa20cdc169bc6356a2a359a8e67e9e3
1 parent
ee3269db
Exists in
master
and in
1 other branch
Refactoring actions.
Showing
5 changed files
with
71 additions
and
24 deletions
Show diff stats
src/terminal/actions/pakey.c
| @@ -88,7 +88,7 @@ | @@ -88,7 +88,7 @@ | ||
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | static gboolean get_enabled(GAction *action, GtkWidget *terminal) { | 90 | static gboolean get_enabled(GAction *action, GtkWidget *terminal) { |
| 91 | - return V3270_ACTION_GET_CLASS(action)->get_enabled(action,terminal); | 91 | + return TRUE; |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | void Lib3270PaAction_class_init(Lib3270PaActionClass *klass) { | 94 | void Lib3270PaAction_class_init(Lib3270PaActionClass *klass) { |
src/terminal/actions/pfkey.c
| @@ -88,14 +88,13 @@ | @@ -88,14 +88,13 @@ | ||
| 88 | } | 88 | } |
| 89 | 89 | ||
| 90 | static gboolean get_enabled(GAction *action, GtkWidget *terminal) { | 90 | static gboolean get_enabled(GAction *action, GtkWidget *terminal) { |
| 91 | - return V3270_ACTION_GET_CLASS(action)->get_enabled(action,terminal); | 91 | + return TRUE; |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | void Lib3270PfAction_class_init(Lib3270PfActionClass *klass) { | 94 | void Lib3270PfAction_class_init(Lib3270PfActionClass *klass) { |
| 95 | klass->parent_class.parent_class.get_parameter_type = get_parameter_type; | 95 | klass->parent_class.parent_class.get_parameter_type = get_parameter_type; |
| 96 | klass->parent_class.parent_class.activate = activate; | 96 | klass->parent_class.parent_class.activate = activate; |
| 97 | klass->parent_class.parent_class.get_enabled = get_enabled; | 97 | klass->parent_class.parent_class.get_enabled = get_enabled; |
| 98 | - | ||
| 99 | } | 98 | } |
| 100 | 99 | ||
| 101 | void Lib3270PfAction_init(Lib3270PfAction *action) { | 100 | void Lib3270PfAction_init(Lib3270PfAction *action) { |
src/terminal/actions/table.c
| @@ -42,6 +42,25 @@ | @@ -42,6 +42,25 @@ | ||
| 42 | #define GDK_ALT_MASK GDK_MOD1_MASK | 42 | #define GDK_ALT_MASK GDK_MOD1_MASK |
| 43 | #endif | 43 | #endif |
| 44 | 44 | ||
| 45 | + #define LIB3270_TYPE_V3270_INTERNAL_ACTION (V270InternalAction_get_type()) | ||
| 46 | + #define V3270_INTERNAL_ACTION(inst) (G_TYPE_CHECK_INSTANCE_CAST ((inst), LIB3270_TYPE_V3270_INTERNAL_ACTION, V270InternalAction)) | ||
| 47 | + | ||
| 48 | + #define GET_DESCRIPTOR(obj) ((const V3270_ACTION *) V3270_INTERNAL_ACTION(obj)->definition) | ||
| 49 | + | ||
| 50 | + typedef struct _V270InternalActionClass { | ||
| 51 | + V3270ActionClass parent_class; | ||
| 52 | + } V270InternalActionClass; | ||
| 53 | + | ||
| 54 | + typedef struct _V270InternalAction { | ||
| 55 | + V3270Action parent; | ||
| 56 | + const V3270_ACTION * definition; | ||
| 57 | + } V270InternalAction; | ||
| 58 | + | ||
| 59 | + static void V270InternalAction_class_init(V270InternalActionClass *klass); | ||
| 60 | + static void V270InternalAction_init(V270InternalAction *action); | ||
| 61 | + | ||
| 62 | + G_DEFINE_TYPE(V270InternalAction, V270InternalAction, V3270_TYPE_ACTION); | ||
| 63 | + | ||
| 45 | /*--[ Globals ]--------------------------------------------------------------------------------------*/ | 64 | /*--[ Globals ]--------------------------------------------------------------------------------------*/ |
| 46 | 65 | ||
| 47 | static const V3270_ACTION actions[] = | 66 | static const V3270_ACTION actions[] = |
| @@ -344,31 +363,56 @@ | @@ -344,31 +363,56 @@ | ||
| 344 | return actions; | 363 | return actions; |
| 345 | } | 364 | } |
| 346 | 365 | ||
| 347 | - static void activate_v3270(GAction *action, GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) | ||
| 348 | - { | 366 | + static const gchar * get_icon_name(GAction *action) { |
| 367 | + return GET_DESCRIPTOR(action)->icon; | ||
| 368 | + } | ||
| 369 | + | ||
| 370 | + static const gchar * get_label(GAction *action) { | ||
| 371 | + return GET_DESCRIPTOR(action)->label; | ||
| 372 | + } | ||
| 373 | + | ||
| 374 | + static const gchar * get_tooltip(GAction *action) { | ||
| 375 | + return GET_DESCRIPTOR(action)->summary; | ||
| 376 | + } | ||
| 377 | + | ||
| 378 | + static const gchar * get_name(GAction *action) { | ||
| 379 | + return GET_DESCRIPTOR(action)->name; | ||
| 380 | + } | ||
| 381 | + | ||
| 382 | + static void activate(GAction *action, GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) { | ||
| 383 | + | ||
| 349 | debug("Activating action \"%s\"",g_action_get_name(action)); | 384 | debug("Activating action \"%s\"",g_action_get_name(action)); |
| 350 | 385 | ||
| 351 | - /* | ||
| 352 | - V3270_ACTION * descriptor = (V3270_ACTION *) ((V3270Action *) action)->info; | ||
| 353 | - descriptor->activate(terminal,descriptor); | ||
| 354 | - */ | 386 | + const V3270_ACTION *descriptor = GET_DESCRIPTOR(action); |
| 387 | + | ||
| 388 | + descriptor->activate(terminal,descriptor); | ||
| 355 | 389 | ||
| 356 | } | 390 | } |
| 357 | 391 | ||
| 358 | - void g_action_map_add_v3270_actions(GActionMap *action_map) | ||
| 359 | - { | 392 | + static void V270InternalAction_class_init(V270InternalActionClass *klass) { |
| 393 | + | ||
| 394 | + klass->parent_class.get_name = get_name; | ||
| 395 | + klass->parent_class.get_icon_name = get_icon_name; | ||
| 396 | + klass->parent_class.get_label = get_label; | ||
| 397 | + klass->parent_class.get_tooltip = get_tooltip; | ||
| 398 | + klass->parent_class.activate = activate; | ||
| 399 | + | ||
| 400 | + } | ||
| 401 | + | ||
| 402 | + static void V270InternalAction_init(V270InternalAction G_GNUC_UNUSED(*action)) { | ||
| 403 | + } | ||
| 404 | + | ||
| 405 | + void g_action_map_add_v3270_actions(GActionMap *action_map) { | ||
| 360 | 406 | ||
| 361 | const V3270_ACTION * actions = v3270_get_actions(); | 407 | const V3270_ACTION * actions = v3270_get_actions(); |
| 362 | size_t ix; | 408 | size_t ix; |
| 363 | 409 | ||
| 364 | - /* | ||
| 365 | for(ix = 0; actions[ix].name; ix++) { | 410 | for(ix = 0; actions[ix].name; ix++) { |
| 366 | 411 | ||
| 367 | - V3270Action * action = V3270_ACTION(g_object_new(V3270_TYPE_ACTION, NULL)); | 412 | + V270InternalAction * action = V3270_INTERNAL_ACTION(g_object_new(LIB3270_TYPE_V3270_INTERNAL_ACTION, NULL)); |
| 368 | 413 | ||
| 369 | - action->info = (const LIB3270_PROPERTY *) &actions[ix]; | ||
| 370 | - action->activate = activate_v3270; | ||
| 371 | - action->translation_domain = GETTEXT_PACKAGE; | 414 | + action->definition = &actions[ix]; |
| 415 | + action->parent.translation_domain = GETTEXT_PACKAGE; | ||
| 372 | 416 | ||
| 373 | if(!g_action_get_name(G_ACTION(action))) { | 417 | if(!g_action_get_name(G_ACTION(action))) { |
| 374 | g_warning("Action \"%s\" is invalid",actions[ix].name); | 418 | g_warning("Action \"%s\" is invalid",actions[ix].name); |
| @@ -377,7 +421,6 @@ | @@ -377,7 +421,6 @@ | ||
| 377 | } | 421 | } |
| 378 | 422 | ||
| 379 | } | 423 | } |
| 380 | - */ | ||
| 381 | 424 | ||
| 382 | } | 425 | } |
| 383 | 426 |
src/terminal/actions/toggle.c
| @@ -113,7 +113,7 @@ | @@ -113,7 +113,7 @@ | ||
| 113 | } | 113 | } |
| 114 | 114 | ||
| 115 | static gboolean get_enabled(GAction *action, GtkWidget *terminal) { | 115 | static gboolean get_enabled(GAction *action, GtkWidget *terminal) { |
| 116 | - return V3270_ACTION_GET_CLASS(action)->get_enabled(action,terminal); | 116 | + return TRUE; |
| 117 | } | 117 | } |
| 118 | 118 | ||
| 119 | void Lib3270ToggleAction_class_init(Lib3270ToggleActionClass *klass) { | 119 | void Lib3270ToggleAction_class_init(Lib3270ToggleActionClass *klass) { |
src/terminal/drawing/surface.c
| @@ -45,15 +45,18 @@ | @@ -45,15 +45,18 @@ | ||
| 45 | */ | 45 | */ |
| 46 | void v3270_reconfigure(v3270 * terminal) | 46 | void v3270_reconfigure(v3270 * terminal) |
| 47 | { | 47 | { |
| 48 | - GtkAllocation allocation; | ||
| 49 | - GtkWidget *widget; | ||
| 50 | - GdkEvent *event = gdk_event_new(GDK_CONFIGURE); | 48 | + GtkWidget * widget = GTK_WIDGET(terminal); |
| 49 | + GdkWindow * window = gtk_widget_get_window(widget); | ||
| 51 | 50 | ||
| 52 | - widget = GTK_WIDGET(terminal); | 51 | + // If the widget isn't realized just return. |
| 52 | + if(!window) | ||
| 53 | + return; | ||
| 53 | 54 | ||
| 55 | + GtkAllocation allocation; | ||
| 54 | gtk_widget_get_allocation(widget, &allocation); | 56 | gtk_widget_get_allocation(widget, &allocation); |
| 55 | 57 | ||
| 56 | - event->configure.window = g_object_ref(gtk_widget_get_window(widget)); | 58 | + GdkEvent *event = gdk_event_new(GDK_CONFIGURE); |
| 59 | + event->configure.window = g_object_ref(window); | ||
| 57 | event->configure.send_event = TRUE; | 60 | event->configure.send_event = TRUE; |
| 58 | event->configure.x = allocation.x; | 61 | event->configure.x = allocation.x; |
| 59 | event->configure.y = allocation.y; | 62 | event->configure.y = allocation.y; |
| @@ -63,7 +66,7 @@ void v3270_reconfigure(v3270 * terminal) | @@ -63,7 +66,7 @@ void v3270_reconfigure(v3270 * terminal) | ||
| 63 | if(terminal->surface) | 66 | if(terminal->surface) |
| 64 | cairo_surface_destroy(terminal->surface); | 67 | cairo_surface_destroy(terminal->surface); |
| 65 | 68 | ||
| 66 | - terminal->surface = (cairo_surface_t *) gdk_window_create_similar_surface(gtk_widget_get_window(widget),CAIRO_CONTENT_COLOR,allocation.width,allocation.height); | 69 | + terminal->surface = (cairo_surface_t *) gdk_window_create_similar_surface(window,CAIRO_CONTENT_COLOR,allocation.width,allocation.height); |
| 67 | 70 | ||
| 68 | // Update the created image | 71 | // Update the created image |
| 69 | cairo_t * cr = cairo_create(terminal->surface); | 72 | cairo_t * cr = cairo_create(terminal->surface); |
| @@ -80,7 +83,9 @@ void v3270_reconfigure(v3270 * terminal) | @@ -80,7 +83,9 @@ void v3270_reconfigure(v3270 * terminal) | ||
| 80 | #endif | 83 | #endif |
| 81 | 84 | ||
| 82 | gtk_widget_event(widget, event); | 85 | gtk_widget_event(widget, event); |
| 86 | + | ||
| 83 | gdk_event_free(event); | 87 | gdk_event_free(event); |
| 84 | } | 88 | } |
| 85 | 89 | ||
| 86 | 90 | ||
| 91 | + |