Commit 48e3b3488d58eb47514c16d94578ec083047e942

Authored by perry.werneck@gmail.com
1 parent 05681efe

Implementando propriedades no widget 3270

src/include/lib3270.h
@@ -636,6 +636,14 @@ @@ -636,6 +636,14 @@
636 LIB3270_EXPORT const char * lib3270_get_toggle_name(LIB3270_TOGGLE ix); 636 LIB3270_EXPORT const char * lib3270_get_toggle_name(LIB3270_TOGGLE ix);
637 637
638 /** 638 /**
  639 + * Get a small text description of the toggle.
  640 + *
  641 + * @return Constant string with the toggle name.
  642 + *
  643 + */
  644 + LIB3270_EXPORT const char * lib3270_get_toggle_description(LIB3270_TOGGLE_ID ix);
  645 +
  646 + /**
639 * Revert toggle status. 647 * Revert toggle status.
640 * 648 *
641 * @param h Session handle. 649 * @param h Session handle.
src/lib3270/toggles.c
@@ -55,35 +55,39 @@ @@ -55,35 +55,39 @@
55 #include "togglesc.h" 55 #include "togglesc.h"
56 #include "api.h" 56 #include "api.h"
57 57
58 -static const char *toggle_names[LIB3270_TOGGLE_COUNT] = 58 +static const struct _toggle
59 { 59 {
60 - "monocase",  
61 - "cursorblink",  
62 - "showtiming",  
63 - "cursorpos",  
64 - "dstrace",  
65 - "linewrap",  
66 - "blankfill",  
67 - "screentrace",  
68 - "eventtrace",  
69 - "marginedpaste",  
70 - "rectselect",  
71 - "crosshair",  
72 - "fullscreen",  
73 - "reconnect",  
74 - "insert",  
75 - "smartpaste",  
76 - "bold",  
77 - "keepselected",  
78 - "underline",  
79 - "autoconnect",  
80 - "kpalternative", /**< Keypad +/- move to next/previous field */  
81 - "beep", /**< Beep on errors */  
82 - "fieldattr", /**< View Field attribute */  
83 - "altscreen", /**< auto resize on altscreen */  
84 - "keepalive", /**< Enable network keep-alive with SO_KEEPALIVE */  
85 - "nettrace", /**< Enable network in/out trace */  
86 - 60 + const char *name;
  61 + const char *descr;
  62 +}
  63 +toggle_info[LIB3270_TOGGLE_COUNT] =
  64 +{
  65 + { "monocase", "" },
  66 + { "cursorblink", "" },
  67 + { "showtiming", "" },
  68 + { "cursorpos", "" },
  69 + { "dstrace", "" },
  70 + { "linewrap", "" },
  71 + { "blankfill", "" },
  72 + { "screentrace", "" },
  73 + { "eventtrace", "" },
  74 + { "marginedpaste", "" },
  75 + { "rectselect", "" },
  76 + { "crosshair", "" },
  77 + { "fullscreen", "" },
  78 + { "reconnect", "" },
  79 + { "insert", "" },
  80 + { "smartpaste", "" },
  81 + { "bold", "" },
  82 + { "keepselected", "" },
  83 + { "underline", "" },
  84 + { "autoconnect", "" },
  85 + { "kpalternative", "" }, /**< Keypad +/- move to next/previous field */
  86 + { "beep", "" }, /**< Beep on errors */
  87 + { "fieldattr", "" }, /**< View Field attribute */
  88 + { "altscreen", "" }, /**< auto resize on altscreen */
  89 + { "keepalive", "" }, /**< Enable network keep-alive with SO_KEEPALIVE */
  90 + { "nettrace", "" }, /**< Enable network in/out trace */
87 }; 91 };
88 92
89 LIB3270_EXPORT unsigned char lib3270_get_toggle(H3270 *session, LIB3270_TOGGLE ix) 93 LIB3270_EXPORT unsigned char lib3270_get_toggle(H3270 *session, LIB3270_TOGGLE ix)
@@ -237,6 +241,13 @@ void shutdown_toggles(H3270 *session) @@ -237,6 +241,13 @@ void shutdown_toggles(H3270 *session)
237 #endif 241 #endif
238 } 242 }
239 243
  244 +LIB3270_EXPORT const char * lib3270_get_toggle_description(LIB3270_TOGGLE_ID ix)
  245 +{
  246 + if(ix < N_TOGGLES)
  247 + return toggle_names[ix];
  248 + return "";
  249 +}
  250 +
240 LIB3270_EXPORT const char * lib3270_get_toggle_name(LIB3270_TOGGLE_ID ix) 251 LIB3270_EXPORT const char * lib3270_get_toggle_name(LIB3270_TOGGLE_ID ix)
241 { 252 {
242 if(ix < N_TOGGLES) 253 if(ix < N_TOGGLES)
src/pw3270/v3270/widget.c
@@ -68,6 +68,21 @@ @@ -68,6 +68,21 @@
68 68
69 /*--[ Widget definition ]----------------------------------------------------------------------------*/ 69 /*--[ Widget definition ]----------------------------------------------------------------------------*/
70 70
  71 + enum
  72 + {
  73 + PROP_0,
  74 +
  75 + /* Construct */
  76 + PROP_TYPE,
  77 +
  78 + /* Normal Props */
  79 + PROP_FULLSCREEN,
  80 +
  81 +
  82 + /* Toggle - always the last one, the real values are PROP_TOGGLE+LIB3270_TOGGLE */
  83 + PROP_TOGGLE
  84 + };
  85 +
71 G_DEFINE_TYPE(v3270, v3270, GTK_TYPE_WIDGET); 86 G_DEFINE_TYPE(v3270, v3270, GTK_TYPE_WIDGET);
72 87
73 /*--[ Globals ]--------------------------------------------------------------------------------------*/ 88 /*--[ Globals ]--------------------------------------------------------------------------------------*/
@@ -296,6 +311,25 @@ gboolean v3270_query_tooltip(GtkWidget *widget, gint x, gint y, gboolean keyboa @@ -296,6 +311,25 @@ gboolean v3270_query_tooltip(GtkWidget *widget, gint x, gint y, gboolean keyboa
296 return FALSE; 311 return FALSE;
297 } 312 }
298 313
  314 +static void v3270_set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
  315 +{
  316 + v3270 *window = GTK_V3270(object);
  317 +
  318 + switch (prop_id)
  319 + {
  320 + case PROP_FULLSCREEN:
  321 + if(g_value_get_boolean (value))
  322 + gtk_window_fullscreen(GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(object))));
  323 + else
  324 + gtk_window_unfullscreen(GTK_WINDOW(gtk_widget_get_toplevel(GTK_WIDGET(object))));
  325 + break;
  326 +
  327 + default:
  328 + G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
  329 + }
  330 +
  331 +}
  332 +
299 static void v3270_class_init(v3270Class *klass) 333 static void v3270_class_init(v3270Class *klass)
300 { 334 {
301 GObjectClass * gobject_class = G_OBJECT_CLASS(klass); 335 GObjectClass * gobject_class = G_OBJECT_CLASS(klass);
@@ -561,6 +595,36 @@ static void v3270_class_init(v3270Class *klass) @@ -561,6 +595,36 @@ static void v3270_class_init(v3270Class *klass)
561 v3270_VOID__VOID, 595 v3270_VOID__VOID,
562 G_TYPE_NONE, 0); 596 G_TYPE_NONE, 0);
563 597
  598 +
  599 + // Properties
  600 + gobject_class->set_property = v3270_set_property;
  601 +
  602 + g_object_class_install_property(
  603 + gobject_class,
  604 + PROP_FULLSCREEN,
  605 + g_param_spec_boolean("fullscreen",
  606 + "Fullscreen","If TRUE, the toplevel window was set to fullscreen",
  607 + FALSE,
  608 + G_PARAM_WRITABLE|G_PARAM_READABLE));
  609 +
  610 +
  611 + // Toggle properties
  612 + int f;
  613 +
  614 + for(f=0;f<LIB3270_TOGGLE_COUNT;f++)
  615 + {
  616 + g_object_class_install_property(
  617 + gobject_class,
  618 + PROP_TOGGLE+f,
  619 + g_param_spec_boolean(
  620 + lib3270_get_toggle_name(f),
  621 + lib3270_get_toggle_name(f),
  622 + lib3270_get_toggle_description(f),
  623 + FALSE,
  624 + G_PARAM_WRITABLE|G_PARAM_READABLE));
  625 + }
  626 +
  627 +
564 } 628 }
565 629
566 void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int height) 630 void v3270_update_font_metrics(v3270 *terminal, cairo_t *cr, int width, int height)