Commit 3b55c2c79e12a79d0e9c6e16ebac62179edcde0c
1 parent
bfef8307
Exists in
master
and in
4 other branches
Adding font selection menu.
Showing
9 changed files
with
161 additions
and
61 deletions
Show diff stats
pw3270.cbp
| ... | ... | @@ -50,6 +50,9 @@ |
| 50 | 50 | <Unit filename="src/main/main.c"> |
| 51 | 51 | <Option compilerVar="CC" /> |
| 52 | 52 | </Unit> |
| 53 | + <Unit filename="src/main/placeholders.c"> | |
| 54 | + <Option compilerVar="CC" /> | |
| 55 | + </Unit> | |
| 53 | 56 | <Unit filename="src/main/private.h" /> |
| 54 | 57 | <Unit filename="src/main/tools.c"> |
| 55 | 58 | <Option compilerVar="CC" /> | ... | ... |
src/include/pw3270.h
src/include/pw3270/actions.h
| ... | ... | @@ -169,6 +169,8 @@ |
| 169 | 169 | /// @brief New simple action from LIB3270's action name. |
| 170 | 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 | 176 | // Dialog action |
| ... | ... | @@ -197,7 +199,7 @@ |
| 197 | 199 | |
| 198 | 200 | typedef struct _v3270PropertyAction { |
| 199 | 201 | |
| 200 | - pw3270Action parent; | |
| 202 | + pw3270SimpleAction parent; | |
| 201 | 203 | |
| 202 | 204 | GParamSpec *pspec; |
| 203 | 205 | |
| ... | ... | @@ -205,7 +207,7 @@ |
| 205 | 207 | |
| 206 | 208 | typedef struct _v3270PropertyActionClass { |
| 207 | 209 | |
| 208 | - pw3270ActionClass parent_class; | |
| 210 | + pw3270SimpleActionClass parent_class; | |
| 209 | 211 | |
| 210 | 212 | } v3270PropertyActionClass; |
| 211 | 213 | ... | ... |
| ... | ... | @@ -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 | 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 | 114 | pw3270SimpleAction * pw3270_simple_action_new_from_lib3270(const LIB3270_ACTION * definition, const gchar *name) { |
| 105 | 115 | |
| 106 | 116 | if(!definition) |
| ... | ... | @@ -110,10 +120,11 @@ |
| 110 | 120 | |
| 111 | 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 | 125 | action->parent.name = name ? name : definition->name; |
| 114 | 126 | action->icon_name = definition->icon; |
| 115 | 127 | action->label = definition->label; |
| 116 | - action->tooltip = definition->summary; | |
| 117 | 128 | action->activate = activate; |
| 118 | 129 | |
| 119 | 130 | return action; | ... | ... |
src/objects/actions/v3270/property.c
| ... | ... | @@ -40,21 +40,22 @@ |
| 40 | 40 | #include <stdlib.h> |
| 41 | 41 | #include <pw3270/window.h> |
| 42 | 42 | #include <v3270.h> |
| 43 | + #include <lib3270/properties.h> | |
| 43 | 44 | |
| 44 | 45 | static void v3270PropertyAction_class_init(v3270PropertyActionClass *klass); |
| 45 | 46 | static void v3270PropertyAction_init(v3270PropertyAction *action); |
| 46 | 47 | static GVariant * get_state(GAction *action, GtkWidget *terminal); |
| 47 | 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 | 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 | 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 | 77 | case G_TYPE_STRING: |
| 77 | 78 | result = g_variant_new_string(g_value_get_string(&value)); |
| 78 | 79 | break; |
| 79 | - /* | |
| 80 | + | |
| 80 | 81 | case G_TYPE_BOOLEAN: |
| 81 | 82 | result = g_variant_new_boolean(g_value_get_boolean(&value)); |
| 82 | 83 | break; |
| 84 | + /* | |
| 83 | 85 | |
| 84 | 86 | case G_TYPE_INT: |
| 85 | 87 | result = g_variant_new_int32(g_value_get_int(&value)); |
| ... | ... | @@ -100,17 +102,6 @@ |
| 100 | 102 | |
| 101 | 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 | 105 | return result; |
| 115 | 106 | |
| 116 | 107 | } |
| ... | ... | @@ -128,12 +119,27 @@ |
| 128 | 119 | { |
| 129 | 120 | case G_TYPE_UINT: |
| 130 | 121 | g_value_set_uint(&value,atoi(g_variant_get_string(parameter,NULL))); |
| 122 | + | |
| 131 | 123 | break; |
| 132 | 124 | |
| 133 | - /* | |
| 134 | 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 | 140 | break; |
| 136 | 141 | |
| 142 | + /* | |
| 137 | 143 | case G_TYPE_INT: |
| 138 | 144 | break; |
| 139 | 145 | |
| ... | ... | @@ -170,6 +176,20 @@ |
| 170 | 176 | |
| 171 | 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 | 193 | if(~pspec->flags & G_PARAM_READABLE || ~pspec->flags & G_PARAM_WRITABLE || pspec->flags & G_PARAM_CONSTRUCT_ONLY) { |
| 174 | 194 | |
| 175 | 195 | g_warning( |
| ... | ... | @@ -183,11 +203,20 @@ |
| 183 | 203 | |
| 184 | 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 | 221 | pw3270_action_set_terminal_widget(G_ACTION(action), widget); |
| 193 | 222 | ... | ... |
src/objects/application/application.c
| ... | ... | @@ -32,6 +32,7 @@ |
| 32 | 32 | */ |
| 33 | 33 | |
| 34 | 34 | #include "private.h" |
| 35 | + #include <pw3270.h> | |
| 35 | 36 | #include <pw3270/application.h> |
| 36 | 37 | #include <pw3270/actions.h> |
| 37 | 38 | |
| ... | ... | @@ -246,14 +247,6 @@ |
| 246 | 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 | 252 | g_action_map_add_action_entries( |
| ... | ... | @@ -274,46 +267,36 @@ |
| 274 | 267 | if(pw3270_application_get_ui_style(application) == PW3270_UI_STYLE_CLASSICAL) |
| 275 | 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 | 272 | g_object_unref(builder); |
| 278 | 273 | |
| 279 | 274 | } |
| 280 | 275 | |
| 281 | 276 | void activate(GApplication *application) { |
| 282 | 277 | |
| 278 | + size_t ix; | |
| 279 | + | |
| 283 | 280 | GtkWidget * window = pw3270_application_window_new(GTK_APPLICATION(application)); |
| 284 | 281 | |
| 285 | 282 | // Create terminal widget & associated widget |
| 286 | 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 | 301 | // Present the new window |
| 319 | 302 | pw3270_window_set_current_page(window,0); | ... | ... |
src/objects/window/window.c
| ... | ... | @@ -170,6 +170,8 @@ |
| 170 | 170 | |
| 171 | 171 | GtkWidget * pw3270_application_window_new(GtkApplication * application) { |
| 172 | 172 | |
| 173 | + size_t ix; | |
| 174 | + | |
| 173 | 175 | const gchar * title = _( "IBM 3270 Terminal emulator" ); |
| 174 | 176 | |
| 175 | 177 | g_autoptr(GSettings) settings = pw3270_application_get_settings(G_APPLICATION(application)); |
| ... | ... | @@ -226,7 +228,6 @@ |
| 226 | 228 | g_warning("Unexpected UI"); |
| 227 | 229 | |
| 228 | 230 | } |
| 229 | - | |
| 230 | 231 | g_object_unref(builder); |
| 231 | 232 | |
| 232 | 233 | } | ... | ... |
ui/application.xml
| ... | ... | @@ -245,8 +245,6 @@ |
| 245 | 245 | |
| 246 | 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 | 248 | <item> |
| 251 | 249 | <attribute name="label" translatable="yes">Model 2 - 80x24</attribute> |
| 252 | 250 | <attribute name="action">win.model-number</attribute> | ... | ... |