Commit 33b7e9c1424ce10952e64e8c64b7210104555d10

Authored by Perry Werneck
1 parent 7fbca4eb
Exists in master and in 1 other branch develop

Creating tools for setting dialogs.

src/dialogs/settings/host.c
@@ -32,10 +32,9 @@ @@ -32,10 +32,9 @@
32 * 32 *
33 */ 33 */
34 34
35 - #include <internals.h> 35 + #include "private.h"
36 #include <hostselect.h> 36 #include <hostselect.h>
37 #include <v3270/dialogs.h> 37 #include <v3270/dialogs.h>
38 - #include <v3270/settings.h>  
39 #include <lib3270/log.h> 38 #include <lib3270/log.h>
40 #include <lib3270/toggle.h> 39 #include <lib3270/toggle.h>
41 #include <lib3270/properties.h> 40 #include <lib3270/properties.h>
@@ -49,16 +48,7 @@ @@ -49,16 +48,7 @@
49 GRID_COUNT 48 GRID_COUNT
50 }; 49 };
51 50
52 - static const struct ToggleList  
53 - {  
54 - gint left;  
55 - gint top;  
56 - gint width;  
57 - unsigned short grid;  
58 -  
59 - LIB3270_TOGGLE_ID id;  
60 - }  
61 - toggleList[] = 51 + static const struct ToggleButtonDefinition toggleList[] =
62 { 52 {
63 { 53 {
64 .left = 2, 54 .left = 2,
@@ -96,7 +86,7 @@ @@ -96,7 +86,7 @@
96 .width = 1, 86 .width = 1,
97 .grid = EMULATION, 87 .grid = EMULATION,
98 .id = LIB3270_TOGGLE_MONOCASE, 88 .id = LIB3270_TOGGLE_MONOCASE,
99 - } 89 + },
100 90
101 }; 91 };
102 92
@@ -212,15 +202,7 @@ @@ -212,15 +202,7 @@
212 } 202 }
213 }; 203 };
214 204
215 - static const struct Entry  
216 - {  
217 - ENTRY_FIELD_HEAD  
218 -  
219 - unsigned short grid;  
220 - gint max_length;  
221 - gint width_chars;  
222 -  
223 - } entryfields[] = { 205 + static const struct EntryFieldDefinition entryfields[] = {
224 { 206 {
225 .left = 0, 207 .left = 0,
226 .top = 0, 208 .top = 0,
@@ -471,6 +453,9 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) @@ -471,6 +453,9 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget)
471 453
472 // Entry fields 454 // Entry fields
473 { 455 {
  456 + v3270_settings_create_entry_fields(entryfields, G_N_ELEMENTS(entryfields), grids, widget->input.entry);
  457 +
  458 + /*
474 size_t entry; 459 size_t entry;
475 460
476 for(entry = 0; entry < G_N_ELEMENTS(entryfields); entry++) 461 for(entry = 0; entry < G_N_ELEMENTS(entryfields); entry++)
@@ -486,6 +471,7 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) @@ -486,6 +471,7 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget)
486 ); 471 );
487 472
488 } 473 }
  474 + */
489 475
490 // Custom settings 476 // Custom settings
491 gtk_entry_set_placeholder_text(widget->input.entry[ENTRY_SRVCNAME],"telnet"); 477 gtk_entry_set_placeholder_text(widget->input.entry[ENTRY_SRVCNAME],"telnet");
@@ -548,30 +534,7 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget) @@ -548,30 +534,7 @@ static void V3270HostSelectWidget_init(V3270HostSelectWidget *widget)
548 } 534 }
549 535
550 // Toggle checkboxes 536 // Toggle checkboxes
551 - {  
552 - size_t toggle;  
553 -  
554 - for(toggle = 0; toggle < G_N_ELEMENTS(toggleList); toggle++)  
555 - {  
556 - const LIB3270_TOGGLE * descriptor = lib3270_toggle_get_from_id(toggleList[toggle].id);  
557 -  
558 - if(descriptor)  
559 - {  
560 - widget->input.toggles[toggle] = GTK_TOGGLE_BUTTON(gtk_check_button_new_with_label(lib3270_toggle_get_label(descriptor)));  
561 -  
562 - const gchar *tooltip = lib3270_property_get_tooltip((const LIB3270_PROPERTY *) descriptor);  
563 -  
564 - if(tooltip && *tooltip)  
565 - gtk_widget_set_tooltip_text(GTK_WIDGET(widget->input.toggles[toggle]),tooltip);  
566 -  
567 - gtk_widget_set_halign(GTK_WIDGET(widget->input.toggles[toggle]),GTK_ALIGN_START);  
568 - 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);  
569 -  
570 - }  
571 -  
572 - }  
573 -  
574 - } 537 + v3270_settings_create_toggle_buttons(toggleList, G_N_ELEMENTS(toggleList), grids, widget->input.toggles);
575 538
576 // Create combo boxes 539 // Create combo boxes
577 { 540 {
src/dialogs/settings/private.h 0 → 100644
@@ -0,0 +1,61 @@ @@ -0,0 +1,61 @@
  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 private.h 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 +#ifndef PRIVATE_H_INCLUDED
  31 +
  32 + #include <internals.h>
  33 + #include <lib3270/log.h>
  34 + #include <lib3270/toggle.h>
  35 + #include <v3270/settings.h>
  36 +
  37 + /// @brief Toggle button factory.
  38 + struct ToggleButtonDefinition {
  39 + gint left;
  40 + gint top;
  41 + gint width;
  42 + unsigned short grid;
  43 + LIB3270_TOGGLE_ID id;
  44 + };
  45 +
  46 + G_GNUC_INTERNAL void v3270_settings_create_toggle_buttons(const struct ToggleButtonDefinition * definitions, size_t length, GtkWidget **grids, GtkToggleButton **toggles);
  47 +
  48 + /// @brief Entry field factory.
  49 + struct EntryFieldDefinition {
  50 +
  51 + ENTRY_FIELD_HEAD
  52 +
  53 + unsigned short grid;
  54 + gint max_length;
  55 + gint width_chars;
  56 +
  57 + };
  58 +
  59 + G_GNUC_INTERNAL void v3270_settings_create_entry_fields(const struct EntryFieldDefinition * definitions, size_t length, GtkWidget **grids, GtkEntry **entries);
  60 +
  61 +#endif // PRIVATE_H_INCLUDED
src/dialogs/settings/tools.c 0 → 100644
@@ -0,0 +1,80 @@ @@ -0,0 +1,80 @@
  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 <lib3270/properties.h>
  32 +
  33 +/*--[ Implement ]------------------------------------------------------------------------------------*/
  34 +
  35 + void v3270_settings_create_toggle_buttons(const struct ToggleButtonDefinition * definitions, size_t length, GtkWidget **grids, GtkToggleButton **toggles) {
  36 +
  37 + size_t toggle;
  38 +
  39 + for(toggle = 0; toggle < length; toggle++) {
  40 +
  41 + const LIB3270_TOGGLE * descriptor = lib3270_toggle_get_from_id(definitions[toggle].id);
  42 +
  43 + if(descriptor) {
  44 +
  45 + toggles[toggle] = GTK_TOGGLE_BUTTON(gtk_check_button_new_with_label(lib3270_toggle_get_label(descriptor)));
  46 +
  47 + const gchar *tooltip = lib3270_property_get_tooltip((const LIB3270_PROPERTY *) descriptor);
  48 +
  49 + if(tooltip && *tooltip)
  50 + gtk_widget_set_tooltip_text(GTK_WIDGET(toggles[toggle]),tooltip);
  51 +
  52 + gtk_widget_set_halign(GTK_WIDGET(toggles[toggle]),GTK_ALIGN_START);
  53 + gtk_grid_attach(GTK_GRID(grids[definitions[toggle].grid]),GTK_WIDGET(toggles[toggle]),definitions[toggle].left,definitions[toggle].top,definitions[toggle].width,1);
  54 +
  55 + }
  56 +
  57 + }
  58 +
  59 + }
  60 +
  61 + void v3270_settings_create_entry_fields(const struct EntryFieldDefinition * definitions, size_t length, GtkWidget **grids, GtkEntry **entries) {
  62 +
  63 + size_t entry;
  64 +
  65 + for(entry = 0; entry < length; entry++) {
  66 +
  67 + entries[entry] = GTK_ENTRY(gtk_entry_new());
  68 + gtk_entry_set_max_length(entries[entry],definitions[entry].max_length);
  69 + gtk_entry_set_width_chars(entries[entry],definitions[entry].width_chars);
  70 +
  71 + v3270_grid_attach(
  72 + GTK_GRID(grids[definitions[entry].grid]),
  73 + (struct v3270_entry_field *) & definitions[entry],
  74 + GTK_WIDGET(entries[entry])
  75 + );
  76 +
  77 + }
  78 +
  79 + }
  80 +
@@ -114,6 +114,10 @@ @@ -114,6 +114,10 @@
114 <Unit filename="src/dialogs/settings/host.c"> 114 <Unit filename="src/dialogs/settings/host.c">
115 <Option compilerVar="CC" /> 115 <Option compilerVar="CC" />
116 </Unit> 116 </Unit>
  117 + <Unit filename="src/dialogs/settings/private.h" />
  118 + <Unit filename="src/dialogs/settings/tools.c">
  119 + <Option compilerVar="CC" />
  120 + </Unit>
117 <Unit filename="src/dialogs/settings/widget.c"> 121 <Unit filename="src/dialogs/settings/widget.c">
118 <Option compilerVar="CC" /> 122 <Option compilerVar="CC" />
119 </Unit> 123 </Unit>