From 33b7e9c1424ce10952e64e8c64b7210104555d10 Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Wed, 22 Jan 2020 08:46:55 -0300 Subject: [PATCH] Creating tools for setting dialogs. --- src/dialogs/settings/host.c | 55 +++++++++---------------------------------------------- src/dialogs/settings/private.h | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/dialogs/settings/tools.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ v3270.cbp | 4 ++++ 4 files changed, 154 insertions(+), 46 deletions(-) create mode 100644 src/dialogs/settings/private.h create mode 100644 src/dialogs/settings/tools.c diff --git a/src/dialogs/settings/host.c b/src/dialogs/settings/host.c index 9fa934e..e1043a3 100644 --- a/src/dialogs/settings/host.c +++ b/src/dialogs/settings/host.c @@ -32,10 +32,9 @@ * */ - #include + #include "private.h" #include #include - #include #include #include #include @@ -49,16 +48,7 @@ GRID_COUNT }; - static const struct ToggleList - { - gint left; - gint top; - gint width; - unsigned short grid; - - LIB3270_TOGGLE_ID id; - } - toggleList[] = + static const struct ToggleButtonDefinition toggleList[] = { { .left = 2, @@ -96,7 +86,7 @@ .width = 1, .grid = EMULATION, .id = LIB3270_TOGGLE_MONOCASE, - } + }, }; @@ -212,15 +202,7 @@ } }; - static const struct Entry - { - ENTRY_FIELD_HEAD - - unsigned short grid; - gint max_length; - gint width_chars; - - } entryfields[] = { + static const struct EntryFieldDefinition entryfields[] = { { .left = 0, .top = 0, @@ -471,6 +453,9 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) // Entry fields { + v3270_settings_create_entry_fields(entryfields, G_N_ELEMENTS(entryfields), grids, widget->input.entry); + + /* size_t entry; for(entry = 0; entry < G_N_ELEMENTS(entryfields); entry++) @@ -486,6 +471,7 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) ); } + */ // Custom settings gtk_entry_set_placeholder_text(widget->input.entry[ENTRY_SRVCNAME],"telnet"); @@ -548,30 +534,7 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) } // Toggle checkboxes - { - size_t toggle; - - for(toggle = 0; toggle < G_N_ELEMENTS(toggleList); toggle++) - { - const LIB3270_TOGGLE * descriptor = lib3270_toggle_get_from_id(toggleList[toggle].id); - - if(descriptor) - { - widget->input.toggles[toggle] = GTK_TOGGLE_BUTTON(gtk_check_button_new_with_label(lib3270_toggle_get_label(descriptor))); - - const gchar *tooltip = lib3270_property_get_tooltip((const LIB3270_PROPERTY *) descriptor); - - if(tooltip && *tooltip) - gtk_widget_set_tooltip_text(GTK_WIDGET(widget->input.toggles[toggle]),tooltip); - - gtk_widget_set_halign(GTK_WIDGET(widget->input.toggles[toggle]),GTK_ALIGN_START); - gtk_grid_attach(GTK_GRID(grids[toggleList[toggle].grid]),GTK_WIDGET(widget->input.toggles[toggle]),toggleList[toggle].left,toggleList[toggle].top,toggleList[toggle].width,1); - - } - - } - - } + v3270_settings_create_toggle_buttons(toggleList, G_N_ELEMENTS(toggleList), grids, widget->input.toggles); // Create combo boxes { diff --git a/src/dialogs/settings/private.h b/src/dialogs/settings/private.h new file mode 100644 index 0000000..099f0e9 --- /dev/null +++ b/src/dialogs/settings/private.h @@ -0,0 +1,61 @@ +/* + * "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 private.h 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 PRIVATE_H_INCLUDED + + #include + #include + #include + #include + + /// @brief Toggle button factory. + struct ToggleButtonDefinition { + gint left; + gint top; + gint width; + unsigned short grid; + LIB3270_TOGGLE_ID id; + }; + + G_GNUC_INTERNAL void v3270_settings_create_toggle_buttons(const struct ToggleButtonDefinition * definitions, size_t length, GtkWidget **grids, GtkToggleButton **toggles); + + /// @brief Entry field factory. + struct EntryFieldDefinition { + + ENTRY_FIELD_HEAD + + unsigned short grid; + gint max_length; + gint width_chars; + + }; + + G_GNUC_INTERNAL void v3270_settings_create_entry_fields(const struct EntryFieldDefinition * definitions, size_t length, GtkWidget **grids, GtkEntry **entries); + +#endif // PRIVATE_H_INCLUDED diff --git a/src/dialogs/settings/tools.c b/src/dialogs/settings/tools.c new file mode 100644 index 0000000..ac08b38 --- /dev/null +++ b/src/dialogs/settings/tools.c @@ -0,0 +1,80 @@ +/* + * "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 "private.h" + #include + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + + void v3270_settings_create_toggle_buttons(const struct ToggleButtonDefinition * definitions, size_t length, GtkWidget **grids, GtkToggleButton **toggles) { + + size_t toggle; + + for(toggle = 0; toggle < length; toggle++) { + + const LIB3270_TOGGLE * descriptor = lib3270_toggle_get_from_id(definitions[toggle].id); + + if(descriptor) { + + toggles[toggle] = GTK_TOGGLE_BUTTON(gtk_check_button_new_with_label(lib3270_toggle_get_label(descriptor))); + + const gchar *tooltip = lib3270_property_get_tooltip((const LIB3270_PROPERTY *) descriptor); + + if(tooltip && *tooltip) + gtk_widget_set_tooltip_text(GTK_WIDGET(toggles[toggle]),tooltip); + + gtk_widget_set_halign(GTK_WIDGET(toggles[toggle]),GTK_ALIGN_START); + gtk_grid_attach(GTK_GRID(grids[definitions[toggle].grid]),GTK_WIDGET(toggles[toggle]),definitions[toggle].left,definitions[toggle].top,definitions[toggle].width,1); + + } + + } + + } + + void v3270_settings_create_entry_fields(const struct EntryFieldDefinition * definitions, size_t length, GtkWidget **grids, GtkEntry **entries) { + + size_t entry; + + for(entry = 0; entry < length; entry++) { + + entries[entry] = GTK_ENTRY(gtk_entry_new()); + gtk_entry_set_max_length(entries[entry],definitions[entry].max_length); + gtk_entry_set_width_chars(entries[entry],definitions[entry].width_chars); + + v3270_grid_attach( + GTK_GRID(grids[definitions[entry].grid]), + (struct v3270_entry_field *) & definitions[entry], + GTK_WIDGET(entries[entry]) + ); + + } + + } + diff --git a/v3270.cbp b/v3270.cbp index 21a18e2..58ecdbd 100644 --- a/v3270.cbp +++ b/v3270.cbp @@ -114,6 +114,10 @@ + + + -- libgit2 0.21.2