From b079db7b57c80140086d9b319e6cb0463f95f8d7 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Thu, 7 Feb 2019 17:52:04 -0200 Subject: [PATCH] Moving customized "pack" methods to global methods to avoid code repetition. --- src/dialogs/tools.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/include/internals.h | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/testprogram/testprogram.c | 2 +- src/v3270ft/private.h | 12 +----------- src/v3270ft/settings.c | 53 ++++++++++++++++++++++++++++++++++++++--------------- 5 files changed, 173 insertions(+), 27 deletions(-) create mode 100644 src/dialogs/tools.c create mode 100644 src/include/internals.h diff --git a/src/dialogs/tools.c b/src/dialogs/tools.c new file mode 100644 index 0000000..7aca839 --- /dev/null +++ b/src/dialogs/tools.c @@ -0,0 +1,66 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + + GtkWidget * v3270_dialog_create_grid(GtkAlign align) + { + GtkWidget * grid = gtk_grid_new(); + + gtk_grid_set_row_spacing(GTK_GRID(grid),6); + gtk_grid_set_column_spacing(GTK_GRID(grid),12); + + g_object_set(G_OBJECT(grid),"margin-top",6,NULL); + gtk_widget_set_halign(GTK_WIDGET(grid),align); + + return grid; + } + + GtkWidget * v3270_box_pack_frame(GtkWidget *box, GtkWidget *child, const gchar *title, GtkAlign align, gboolean expand, gboolean fill, guint padding) + { + GtkFrame * frame = GTK_FRAME(gtk_frame_new("")); + g_autofree gchar * markup = g_strdup_printf("%s",title); + GtkWidget * label = gtk_label_new(NULL); + + gtk_frame_set_shadow_type(GTK_FRAME(frame),GTK_SHADOW_NONE); + gtk_label_set_markup(GTK_LABEL(label),markup); + gtk_frame_set_label_widget(GTK_FRAME(frame),label); + + gtk_container_add(GTK_CONTAINER(frame),GTK_WIDGET(child)); + gtk_widget_set_halign(GTK_WIDGET(frame),align); + + g_object_set(G_OBJECT(frame),"margin-top",6,NULL); + + gtk_box_pack_start(GTK_BOX(box),GTK_WIDGET(frame),expand,fill,padding); + + return child; + } + diff --git a/src/include/internals.h b/src/include/internals.h new file mode 100644 index 0000000..5724fe8 --- /dev/null +++ b/src/include/internals.h @@ -0,0 +1,67 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + +#ifndef V3270_INTERNALS_H_INCLUDED + + #define V3270_INTERNALS_H_INCLUDED 1 + + #include + #include + #include + #include + #include + + #if ! GLIB_CHECK_VERSION(2,44,0) + + // Reference: https://github.com/ImageMagick/glib/blob/master/glib/glib-autocleanups.h + static inline void v3270_autoptr_cleanup_generic_gfree(void *p) + { + void **pp = (void**)p; + g_free (*pp); + } + + #define g_autofree __attribute__((cleanup(v3270_autoptr_cleanup_generic_gfree))) + + #endif // ! GLIB(2,44,0) + + G_BEGIN_DECLS + + inline GtkWidget * v3270_box_pack_start(GtkWidget *box, GtkWidget *child, gboolean expand, gboolean fill, guint padding) + { + gtk_box_pack_start(GTK_BOX(box),child,expand,fill,padding); + return child; + } + + G_GNUC_INTERNAL GtkWidget * v3270_box_pack_frame(GtkWidget *box, GtkWidget *child, const gchar *title, GtkAlign align, gboolean expand, gboolean fill, guint padding); + G_GNUC_INTERNAL GtkWidget * v3270_dialog_create_grid(GtkAlign align); + + + G_END_DECLS + +#endif // V3270_INTERNALS_H_INCLUDED diff --git a/src/testprogram/testprogram.c b/src/testprogram/testprogram.c index a28500e..2198e98 100644 --- a/src/testprogram/testprogram.c +++ b/src/testprogram/testprogram.c @@ -260,7 +260,7 @@ static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { GtkWidget * toolbar = gtk_toolbar_new(); for(f = 0; f < G_N_ELEMENTS(buttons); f++) { - GtkWidget * button = gtk_tool_button_new_from_stock(buttons[f].icon); + GtkWidget * button = GTK_WIDGET(gtk_tool_button_new_from_stock(buttons[f].icon)); gtk_widget_set_tooltip_markup(button,buttons[f].tooltip); g_signal_connect(G_OBJECT(button),"clicked",buttons[f].callback,terminal); gtk_toolbar_insert(GTK_TOOLBAR(toolbar),GTK_TOOL_ITEM(button),-1); diff --git a/src/v3270ft/private.h b/src/v3270ft/private.h index 68960df..fefd609 100644 --- a/src/v3270ft/private.h +++ b/src/v3270ft/private.h @@ -43,6 +43,7 @@ #include #include #include + #include #include #define NUM_OPTIONS_WIDGETS 12 @@ -179,17 +180,6 @@ }; - #ifdef DEBUG - - #define debug(fmt, ...) g_message( "%s(%d) " fmt , __FILE__, (int) __LINE__, __VA_ARGS__ ) - - #else - - #define debug(fmt, ...) /* */ - - #endif // DEBUG - - G_GNUC_INTERNAL guint v3270ftprogress_signal[V3270FTPROGRESS_SIGNAL_COUNT]; diff --git a/src/v3270ft/settings.c b/src/v3270ft/settings.c index cd244c5..13a3c19 100644 --- a/src/v3270ft/settings.c +++ b/src/v3270ft/settings.c @@ -28,9 +28,9 @@ */ #include - #include - #include + #include #include "private.h" + #include /*--[ Widget definition ]----------------------------------------------------------------------------*/ @@ -83,8 +83,11 @@ return entry; } + /* static GtkWidget * create_frame(GtkWidget *container, const gchar *title, GtkWidget *box, GtkAlign align) { + gtk_box_pack_start(GTK_BOX(container),v3270_dialog_create_frame(title,box,align),TRUE,TRUE,0); + GtkFrame * frame = GTK_FRAME(gtk_frame_new("")); g_autofree gchar * markup = g_strdup_printf("%s",title); GtkWidget * label = gtk_label_new(NULL); @@ -102,19 +105,11 @@ return box; } + */ static GtkWidget * create_grid(GtkWidget *container, GtkAlign align) { - GtkWidget * grid = gtk_grid_new(); - - gtk_grid_set_row_spacing(GTK_GRID(grid),6); - gtk_grid_set_column_spacing(GTK_GRID(grid),12); - - g_object_set(G_OBJECT(grid),"margin-top",6,NULL); - gtk_widget_set_halign(GTK_WIDGET(grid),align); - gtk_box_pack_start(GTK_BOX(container),GTK_WIDGET(grid),TRUE,TRUE,0); - - return grid; + return v3270_box_pack_start(container,v3270_dialog_create_grid(align),TRUE,TRUE,0); } GtkWidget * create_spin_button(V3270FTSettings *widget, GtkWidget *grid, size_t row, LIB3270_FT_VALUE id) @@ -277,7 +272,16 @@ static void open_select_file_dialog(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconP // Transfer options { - GtkWidget * box = create_frame(options, _("Transfer options"), gtk_box_new(GTK_ORIENTATION_VERTICAL,6),GTK_ALIGN_START); + GtkWidget * box = + v3270_box_pack_frame( + options, + gtk_box_new(GTK_ORIENTATION_VERTICAL,6), + _("Transfer options"), + GTK_ALIGN_START, + FALSE, + FALSE, + 0 + ); for(ix=0;ix<4;ix++) { @@ -293,7 +297,17 @@ static void open_select_file_dialog(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconP // Record format { GSList * group = NULL; - widget->recordFormatBox = create_frame(options, _("Record format"), gtk_box_new(GTK_ORIENTATION_VERTICAL,6),GTK_ALIGN_CENTER); + + widget->recordFormatBox = + v3270_box_pack_frame( + options, + gtk_box_new(GTK_ORIENTATION_VERTICAL,6), + _("Record format"), + GTK_ALIGN_CENTER, + FALSE, + FALSE, + 0 + ); for(ix=4;ix<8;ix++) { @@ -309,7 +323,16 @@ static void open_select_file_dialog(GtkEntry *entry, G_GNUC_UNUSED GtkEntryIconP // Space allocation units { GSList * group = NULL; - widget->spaceAllocationBox = create_frame(options, _("Space allocation units"), gtk_box_new(GTK_ORIENTATION_VERTICAL,6),GTK_ALIGN_END); + widget->spaceAllocationBox = + v3270_box_pack_frame( + options, + gtk_box_new(GTK_ORIENTATION_VERTICAL,6), + _("Space allocation units"), + GTK_ALIGN_END, + FALSE, + FALSE, + 0 + ); for(ix=8;ix<12;ix++) { -- libgit2 0.21.2