Commit 3b55c2c79e12a79d0e9c6e16ebac62179edcde0c

Authored by Perry Werneck
1 parent bfef8307

Adding font selection menu.

@@ -50,6 +50,9 @@ @@ -50,6 +50,9 @@
50 <Unit filename="src/main/main.c"> 50 <Unit filename="src/main/main.c">
51 <Option compilerVar="CC" /> 51 <Option compilerVar="CC" />
52 </Unit> 52 </Unit>
  53 + <Unit filename="src/main/placeholders.c">
  54 + <Option compilerVar="CC" />
  55 + </Unit>
53 <Unit filename="src/main/private.h" /> 56 <Unit filename="src/main/private.h" />
54 <Unit filename="src/main/tools.c"> 57 <Unit filename="src/main/tools.c">
55 <Option compilerVar="CC" /> 58 <Option compilerVar="CC" />
src/include/pw3270.h
@@ -52,6 +52,9 @@ @@ -52,6 +52,9 @@
52 #define I_(string) g_intern_static_string (string) 52 #define I_(string) g_intern_static_string (string)
53 53
54 54
  55 + void pw3270_load_placeholders(GtkBuilder * builder);
  56 +
  57 +
55 G_END_DECLS 58 G_END_DECLS
56 59
57 #endif // PW3270_H_INCLUDED 60 #endif // PW3270_H_INCLUDED
src/include/pw3270/actions.h
@@ -169,6 +169,8 @@ @@ -169,6 +169,8 @@
169 /// @brief New simple action from LIB3270's action name. 169 /// @brief New simple action from LIB3270's action name.
170 pw3270SimpleAction * pw3270_simple_action_new_from_name(const gchar *source_name, const gchar *name); 170 pw3270SimpleAction * pw3270_simple_action_new_from_name(const gchar *source_name, const gchar *name);
171 171
  172 + /// @brief Update simple action from LIB3270's property description.
  173 + void pw3270_simple_action_set_lib3270_property(pw3270SimpleAction *action, const LIB3270_PROPERTY * property);
172 174
173 // 175 //
174 // Dialog action 176 // Dialog action
@@ -197,7 +199,7 @@ @@ -197,7 +199,7 @@
197 199
198 typedef struct _v3270PropertyAction { 200 typedef struct _v3270PropertyAction {
199 201
200 - pw3270Action parent; 202 + pw3270SimpleAction parent;
201 203
202 GParamSpec *pspec; 204 GParamSpec *pspec;
203 205
@@ -205,7 +207,7 @@ @@ -205,7 +207,7 @@
205 207
206 typedef struct _v3270PropertyActionClass { 208 typedef struct _v3270PropertyActionClass {
207 209
208 - pw3270ActionClass parent_class; 210 + pw3270SimpleActionClass parent_class;
209 211
210 } v3270PropertyActionClass; 212 } v3270PropertyActionClass;
211 213
src/main/placeholders.c 0 → 100644
@@ -0,0 +1,70 @@ @@ -0,0 +1,70 @@
  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. Registro no INPI sob
  5 + * o nome G3270.
  6 + *
  7 + * Copyright (C) <2008> <Banco do Brasil S.A.>
  8 + *
  9 + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob
  10 + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela
  11 + * Free Software Foundation.
  12 + *
  13 + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER
  14 + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO
  15 + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para
  16 + * obter mais detalhes.
  17 + *
  18 + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este
  19 + * programa; se não, escreva para a Free Software Foundation, Inc., 51 Franklin
  20 + * St, Fifth Floor, Boston, MA 02110-1301 USA
  21 + *
  22 + * Este programa está nomeado como main.c e possui - linhas de código.
  23 + *
  24 + * Contatos:
  25 + *
  26 + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck)
  27 + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça)
  28 + *
  29 + */
  30 +
  31 + /**
  32 + * @brief PW3270 Placeholders management.
  33 + *
  34 + */
  35 +
  36 + #include "private.h"
  37 + #include <pw3270/application.h>
  38 + #include <lib3270.h>
  39 + #include <lib3270/log.h>
  40 +
  41 +/*---[ Implement ]----------------------------------------------------------------------------------*/
  42 +
  43 + void pw3270_load_placeholders(GtkBuilder * builder) {
  44 +
  45 + GObject * placeholder = gtk_builder_get_object(builder, "font-select-placeholder");
  46 +
  47 + if(placeholder && G_IS_MENU(placeholder)) {
  48 +
  49 + GMenu * font_menu = G_MENU(placeholder);
  50 +
  51 + gint n_families;
  52 + PangoFontFamily **families;
  53 + pango_context_list_families(gdk_pango_context_get_for_screen(gdk_screen_get_default()),&families, &n_families);
  54 +
  55 + size_t ix;
  56 + for(ix=0; ix < (size_t) n_families; ix++)
  57 + {
  58 + if(!pango_font_family_is_monospace(families[ix]))
  59 + continue;
  60 +
  61 + const gchar * family = pango_font_family_get_name(families[ix]);
  62 + g_autofree gchar * detailed_action = g_strconcat("win.font-family::",family,NULL);
  63 + g_menu_append(font_menu,family,detailed_action);
  64 +
  65 + }
  66 +
  67 + }
  68 +
  69 +
  70 + }
src/objects/actions/simple.c
@@ -101,6 +101,16 @@ @@ -101,6 +101,16 @@
101 101
102 } 102 }
103 103
  104 + void pw3270_simple_action_set_lib3270_property(pw3270SimpleAction *action, const LIB3270_PROPERTY * property) {
  105 +
  106 + if(property) {
  107 + action->parent.name = property->name;
  108 + action->tooltip = property->summary ? property->summary : property->description;
  109 + action->group.id = property->group;
  110 + }
  111 +
  112 + }
  113 +
104 pw3270SimpleAction * pw3270_simple_action_new_from_lib3270(const LIB3270_ACTION * definition, const gchar *name) { 114 pw3270SimpleAction * pw3270_simple_action_new_from_lib3270(const LIB3270_ACTION * definition, const gchar *name) {
105 115
106 if(!definition) 116 if(!definition)
@@ -110,10 +120,11 @@ @@ -110,10 +120,11 @@
110 120
111 pw3270SimpleAction * action = (pw3270SimpleAction *) g_object_new(PW3270_TYPE_SIMPLE_ACTION, NULL); 121 pw3270SimpleAction * action = (pw3270SimpleAction *) g_object_new(PW3270_TYPE_SIMPLE_ACTION, NULL);
112 122
  123 + pw3270_simple_action_set_lib3270_property(action, (const LIB3270_PROPERTY *) definition);
  124 +
113 action->parent.name = name ? name : definition->name; 125 action->parent.name = name ? name : definition->name;
114 action->icon_name = definition->icon; 126 action->icon_name = definition->icon;
115 action->label = definition->label; 127 action->label = definition->label;
116 - action->tooltip = definition->summary;  
117 action->activate = activate; 128 action->activate = activate;
118 129
119 return action; 130 return action;
src/objects/actions/v3270/property.c
@@ -40,21 +40,22 @@ @@ -40,21 +40,22 @@
40 #include <stdlib.h> 40 #include <stdlib.h>
41 #include <pw3270/window.h> 41 #include <pw3270/window.h>
42 #include <v3270.h> 42 #include <v3270.h>
  43 + #include <lib3270/properties.h>
43 44
44 static void v3270PropertyAction_class_init(v3270PropertyActionClass *klass); 45 static void v3270PropertyAction_class_init(v3270PropertyActionClass *klass);
45 static void v3270PropertyAction_init(v3270PropertyAction *action); 46 static void v3270PropertyAction_init(v3270PropertyAction *action);
46 static GVariant * get_state(GAction *action, GtkWidget *terminal); 47 static GVariant * get_state(GAction *action, GtkWidget *terminal);
47 static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to); 48 static void change_widget(GAction *object, GtkWidget *from, GtkWidget *to);
48 49
49 - G_DEFINE_TYPE(v3270PropertyAction, v3270PropertyAction, PW3270_TYPE_ACTION); 50 + G_DEFINE_TYPE(v3270PropertyAction, v3270PropertyAction, PW3270_TYPE_SIMPLE_ACTION);
50 51
51 void v3270PropertyAction_class_init(v3270PropertyActionClass *klass) { 52 void v3270PropertyAction_class_init(v3270PropertyActionClass *klass) {
52 - klass->parent_class.change_widget = change_widget; 53 + klass->parent_class.parent_class.change_widget = change_widget;
53 } 54 }
54 55
55 static void v3270PropertyAction_init(v3270PropertyAction *action) { 56 static void v3270PropertyAction_init(v3270PropertyAction *action) {
56 57
57 - action->parent.get_state_property = get_state; 58 + action->parent.parent.get_state_property = get_state;
58 59
59 } 60 }
60 61
@@ -76,10 +77,11 @@ @@ -76,10 +77,11 @@
76 case G_TYPE_STRING: 77 case G_TYPE_STRING:
77 result = g_variant_new_string(g_value_get_string(&value)); 78 result = g_variant_new_string(g_value_get_string(&value));
78 break; 79 break;
79 - /* 80 +
80 case G_TYPE_BOOLEAN: 81 case G_TYPE_BOOLEAN:
81 result = g_variant_new_boolean(g_value_get_boolean(&value)); 82 result = g_variant_new_boolean(g_value_get_boolean(&value));
82 break; 83 break;
  84 + /*
83 85
84 case G_TYPE_INT: 86 case G_TYPE_INT:
85 result = g_variant_new_int32(g_value_get_int(&value)); 87 result = g_variant_new_int32(g_value_get_int(&value));
@@ -100,17 +102,6 @@ @@ -100,17 +102,6 @@
100 102
101 g_value_unset (&value); 103 g_value_unset (&value);
102 104
103 -#ifdef DEBUG  
104 - if(result)  
105 - {  
106 - debug("Action %s set to \"%s\"",g_action_get_name(object),g_variant_get_string(result,NULL));  
107 - }  
108 - else  
109 - {  
110 - debug("Action %s set to \"%s\"",g_action_get_name(object),"NULL");  
111 - }  
112 -#endif // DEBUG  
113 -  
114 return result; 105 return result;
115 106
116 } 107 }
@@ -128,12 +119,27 @@ @@ -128,12 +119,27 @@
128 { 119 {
129 case G_TYPE_UINT: 120 case G_TYPE_UINT:
130 g_value_set_uint(&value,atoi(g_variant_get_string(parameter,NULL))); 121 g_value_set_uint(&value,atoi(g_variant_get_string(parameter,NULL)));
  122 +
131 break; 123 break;
132 124
133 - /*  
134 case G_TYPE_BOOLEAN: 125 case G_TYPE_BOOLEAN:
  126 +
  127 + if(parameter) {
  128 +
  129 + if(g_variant_is_of_type(parameter,G_VARIANT_TYPE_BOOLEAN))
  130 + g_value_set_boolean(&value,g_variant_get_boolean(parameter));
  131 + else
  132 + g_value_set_boolean(&value,atoi(g_variant_get_string(parameter,NULL)) != 0);
  133 +
  134 + } else {
  135 +
  136 + debug("%s: TODO: Toggle property",__FUNCTION__);
  137 +
  138 + }
  139 +
135 break; 140 break;
136 141
  142 + /*
137 case G_TYPE_INT: 143 case G_TYPE_INT:
138 break; 144 break;
139 145
@@ -170,6 +176,20 @@ @@ -170,6 +176,20 @@
170 176
171 GParamSpec *pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(widget), property_name); 177 GParamSpec *pspec = g_object_class_find_property(G_OBJECT_GET_CLASS(widget), property_name);
172 178
  179 + if(!pspec) {
  180 +
  181 + g_warning(
  182 + "Can't find property '%s::%s'",
  183 + G_OBJECT_TYPE_NAME(G_OBJECT(widget)),
  184 + property_name
  185 + );
  186 +
  187 + return NULL;
  188 +
  189 + }
  190 +
  191 + debug("%s: pspec(%s)=%p",__FUNCTION__,property_name,pspec);
  192 +
173 if(~pspec->flags & G_PARAM_READABLE || ~pspec->flags & G_PARAM_WRITABLE || pspec->flags & G_PARAM_CONSTRUCT_ONLY) { 193 if(~pspec->flags & G_PARAM_READABLE || ~pspec->flags & G_PARAM_WRITABLE || pspec->flags & G_PARAM_CONSTRUCT_ONLY) {
174 194
175 g_warning( 195 g_warning(
@@ -183,11 +203,20 @@ @@ -183,11 +203,20 @@
183 203
184 v3270PropertyAction * action = (v3270PropertyAction *) g_object_new(V3270_TYPE_PROPERTY_ACTION, NULL); 204 v3270PropertyAction * action = (v3270PropertyAction *) g_object_new(V3270_TYPE_PROPERTY_ACTION, NULL);
185 205
186 - action->parent.name = pspec->name;  
187 - action->parent.types.state = G_VARIANT_TYPE_STRING;  
188 - action->parent.types.parameter = G_VARIANT_TYPE_STRING;  
189 - action->parent.activate = activate;  
190 - action->pspec = pspec; 206 + pw3270_simple_action_set_lib3270_property(PW3270_SIMPLE_ACTION(action), lib3270_property_get_by_name(pspec->name));
  207 +
  208 + action->parent.parent.name = g_param_spec_get_name(pspec);
  209 + action->parent.tooltip = g_param_spec_get_blurb(pspec);
  210 +
  211 + if(pspec->value_type == G_TYPE_BOOLEAN) {
  212 + action->parent.parent.types.state = G_VARIANT_TYPE_BOOLEAN;
  213 + } else {
  214 + action->parent.parent.types.state = G_VARIANT_TYPE_STRING;
  215 + action->parent.parent.types.parameter = G_VARIANT_TYPE_STRING;
  216 + }
  217 +
  218 + action->parent.parent.activate = activate;
  219 + action->pspec = pspec;
191 220
192 pw3270_action_set_terminal_widget(G_ACTION(action), widget); 221 pw3270_action_set_terminal_widget(G_ACTION(action), widget);
193 222
src/objects/application/application.c
@@ -32,6 +32,7 @@ @@ -32,6 +32,7 @@
32 */ 32 */
33 33
34 #include "private.h" 34 #include "private.h"
  35 + #include <pw3270.h>
35 #include <pw3270/application.h> 36 #include <pw3270/application.h>
36 #include <pw3270/actions.h> 37 #include <pw3270/actions.h>
37 38
@@ -246,14 +247,6 @@ @@ -246,14 +247,6 @@
246 .activate = pw3270_application_generic_activated, 247 .activate = pw3270_application_generic_activated,
247 }, 248 },
248 249
249 - /*  
250 - {  
251 - .name = "model-number",  
252 - .activate = model_cb,  
253 - .parameter_type = "s"  
254 - }  
255 - */  
256 -  
257 }; 250 };
258 251
259 g_action_map_add_action_entries( 252 g_action_map_add_action_entries(
@@ -274,46 +267,36 @@ @@ -274,46 +267,36 @@
274 if(pw3270_application_get_ui_style(application) == PW3270_UI_STYLE_CLASSICAL) 267 if(pw3270_application_get_ui_style(application) == PW3270_UI_STYLE_CLASSICAL)
275 gtk_application_set_menubar(GTK_APPLICATION (application), G_MENU_MODEL(gtk_builder_get_object (builder, "menubar"))); 268 gtk_application_set_menubar(GTK_APPLICATION (application), G_MENU_MODEL(gtk_builder_get_object (builder, "menubar")));
276 269
  270 + pw3270_load_placeholders(builder);
  271 +
277 g_object_unref(builder); 272 g_object_unref(builder);
278 273
279 } 274 }
280 275
281 void activate(GApplication *application) { 276 void activate(GApplication *application) {
282 277
  278 + size_t ix;
  279 +
283 GtkWidget * window = pw3270_application_window_new(GTK_APPLICATION(application)); 280 GtkWidget * window = pw3270_application_window_new(GTK_APPLICATION(application));
284 281
285 // Create terminal widget & associated widget 282 // Create terminal widget & associated widget
286 GtkWidget * terminal = pw3270_terminal_new(window); 283 GtkWidget * terminal = pw3270_terminal_new(window);
287 284
288 - /*  
289 - GAction * action = G_ACTION(v3270_property_action_new(terminal,"model_number"));  
290 - if(action) {  
291 - debug("Adding window action \"%s\"",g_action_get_name(action));  
292 - g_action_map_add_action(G_ACTION_MAP(window),action);  
293 - }  
294 - */  
295 -  
296 - // https://developer.gnome.org/gnome-devel-demos/stable/menubar.vala.html.en  
297 -  
298 - /*  
299 - static const GActionEntry actions[] = {  
300 -  
301 - {  
302 - .name = "model-number",  
303 - .activate = model_cb,  
304 - .parameter_type = "s",  
305 - .state = "2"  
306 - }  
307 - 285 + // Create property actions
  286 + static const gchar * properties[] = {
  287 + "model-number",
  288 + "font-family",
  289 + "dynamic-font-spacing"
308 }; 290 };
309 291
310 - g_action_map_add_action_entries(G_ACTION_MAP(window),actions,G_N_ELEMENTS(actions),NULL);  
311 - */ 292 + for(ix = 0; ix < G_N_ELEMENTS(properties); ix++) {
312 293
313 - g_action_map_add_action(  
314 - G_ACTION_MAP(window),  
315 - v3270_property_action_new(terminal,"model-number")  
316 - ); 294 + g_action_map_add_action(
  295 + G_ACTION_MAP(window),
  296 + v3270_property_action_new(terminal,properties[ix])
  297 + );
  298 +
  299 + }
317 300
318 // Present the new window 301 // Present the new window
319 pw3270_window_set_current_page(window,0); 302 pw3270_window_set_current_page(window,0);
src/objects/window/window.c
@@ -170,6 +170,8 @@ @@ -170,6 +170,8 @@
170 170
171 GtkWidget * pw3270_application_window_new(GtkApplication * application) { 171 GtkWidget * pw3270_application_window_new(GtkApplication * application) {
172 172
  173 + size_t ix;
  174 +
173 const gchar * title = _( "IBM 3270 Terminal emulator" ); 175 const gchar * title = _( "IBM 3270 Terminal emulator" );
174 176
175 g_autoptr(GSettings) settings = pw3270_application_get_settings(G_APPLICATION(application)); 177 g_autoptr(GSettings) settings = pw3270_application_get_settings(G_APPLICATION(application));
@@ -226,7 +228,6 @@ @@ -226,7 +228,6 @@
226 g_warning("Unexpected UI"); 228 g_warning("Unexpected UI");
227 229
228 } 230 }
229 -  
230 g_object_unref(builder); 231 g_object_unref(builder);
231 232
232 } 233 }
ui/application.xml
@@ -245,8 +245,6 @@ @@ -245,8 +245,6 @@
245 245
246 <attribute name="label" translatable="yes">Screen size</attribute> 246 <attribute name="label" translatable="yes">Screen size</attribute>
247 247
248 - <!-- https://developer.gnome.org/gnome-devel-demos/stable/menubar.vala.html.en -->  
249 -  
250 <item> 248 <item>
251 <attribute name="label" translatable="yes">Model 2 - 80x24</attribute> 249 <attribute name="label" translatable="yes">Model 2 - 80x24</attribute>
252 <attribute name="action">win.model-number</attribute> 250 <attribute name="action">win.model-number</attribute>