Commit 007c44c5c43d90d04c1b6e4e22fb56d74a5bbda2
1 parent
27a0ca65
Exists in
master
and in
1 other branch
Updating font-chooser widget.
Showing
1 changed file
with
81 additions
and
25 deletions
Show diff stats
src/dialogs/font/chooser.c
| ... | ... | @@ -37,6 +37,7 @@ |
| 37 | 37 | #include "../private.h" |
| 38 | 38 | #include <v3270/dialogs.h> |
| 39 | 39 | #include <v3270/settings.h> |
| 40 | + #include <v3270/toggle.h> | |
| 40 | 41 | #include <lib3270/log.h> |
| 41 | 42 | #include <terminal.h> |
| 42 | 43 | |
| ... | ... | @@ -55,11 +56,18 @@ |
| 55 | 56 | |
| 56 | 57 | GtkWidget * font_list; |
| 57 | 58 | GtkWidget * preview; |
| 59 | + GtkToggleButton * bold; | |
| 58 | 60 | |
| 59 | 61 | struct { |
| 60 | - cairo_font_face_t * face; | |
| 62 | + cairo_font_face_t * face; | |
| 63 | + cairo_font_weight_t weight; | |
| 61 | 64 | } font; |
| 62 | 65 | |
| 66 | + struct { | |
| 67 | + gchar * family; | |
| 68 | + gboolean bold; | |
| 69 | + } saved; | |
| 70 | + | |
| 63 | 71 | } V3270FontChooserWidget; |
| 64 | 72 | |
| 65 | 73 | typedef struct _V3270HostSelectWidgetClass |
| ... | ... | @@ -72,25 +80,37 @@ |
| 72 | 80 | |
| 73 | 81 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 74 | 82 | |
| 75 | -static void apply(GtkWidget *widget, GtkWidget *terminal) | |
| 76 | -{ | |
| 77 | - | |
| 83 | + static void cancel(GtkWidget *widget, GtkWidget *terminal) | |
| 84 | + { | |
| 78 | 85 | debug("V3270FontChooserWidget::%s",__FUNCTION__); |
| 79 | 86 | |
| 80 | -} | |
| 87 | + V3270FontChooserWidget *chooser = GTK_V3270_FONT_CHOOSER(widget); | |
| 81 | 88 | |
| 82 | -static void load(GtkWidget *widget, GtkWidget *terminal) | |
| 83 | -{ | |
| 89 | + if(chooser->saved.family) | |
| 90 | + v3270_set_font_family(terminal,chooser->saved.family); | |
| 91 | + | |
| 92 | + v3270_set_toggle(terminal,LIB3270_TOGGLE_BOLD,chooser->saved.bold); | |
| 93 | + } | |
| 94 | + | |
| 95 | + static void load(GtkWidget *widget, GtkWidget *terminal) | |
| 96 | + { | |
| 84 | 97 | V3270FontChooserWidget *chooser = GTK_V3270_FONT_CHOOSER(widget); |
| 85 | 98 | |
| 86 | 99 | debug("V3270FontChooserWidget::%s",__FUNCTION__); |
| 87 | 100 | |
| 101 | + if(chooser->saved.family) { | |
| 102 | + g_free(chooser->saved.family); | |
| 103 | + } | |
| 104 | + | |
| 105 | + chooser->saved.family = g_strdup(v3270_get_font_family(terminal)); | |
| 106 | + chooser->saved.bold = v3270_get_toggle(terminal,LIB3270_TOGGLE_BOLD); | |
| 107 | + | |
| 88 | 108 | GtkTreeIter active; |
| 89 | 109 | gtk_tree_view_set_model( |
| 90 | 110 | GTK_TREE_VIEW(chooser->font_list), |
| 91 | 111 | v3270_font_family_model_new( |
| 92 | 112 | chooser->font_list, |
| 93 | - v3270_get_font_family(terminal), | |
| 113 | + chooser->saved.family, | |
| 94 | 114 | &active |
| 95 | 115 | ) |
| 96 | 116 | ); |
| ... | ... | @@ -100,10 +120,13 @@ static void load(GtkWidget *widget, GtkWidget *terminal) |
| 100 | 120 | &active |
| 101 | 121 | ); |
| 102 | 122 | |
| 103 | -} | |
| 123 | + gtk_toggle_button_set_active(chooser->bold,chooser->saved.bold); | |
| 104 | 124 | |
| 105 | -static void dispose(GObject *object) | |
| 106 | -{ | |
| 125 | + gtk_widget_queue_draw(chooser->preview); | |
| 126 | + } | |
| 127 | + | |
| 128 | + static void dispose(GObject *object) | |
| 129 | + { | |
| 107 | 130 | V3270FontChooserWidget * widget = GTK_V3270_FONT_CHOOSER(object); |
| 108 | 131 | |
| 109 | 132 | if(widget->font.face) { |
| ... | ... | @@ -111,19 +134,38 @@ static void dispose(GObject *object) |
| 111 | 134 | widget->font.face = NULL; |
| 112 | 135 | } |
| 113 | 136 | |
| 137 | + if(widget->saved.family) { | |
| 138 | + g_free(widget->saved.family); | |
| 139 | + widget->saved.family = NULL; | |
| 140 | + } | |
| 141 | + | |
| 114 | 142 | G_OBJECT_CLASS(V3270FontChooserWidget_parent_class)->dispose(object); |
| 115 | -} | |
| 143 | + } | |
| 116 | 144 | |
| 117 | -static void V3270FontChooserWidget_class_init(V3270FontChooserWidgetClass *klass) | |
| 118 | -{ | |
| 145 | + static void V3270FontChooserWidget_class_init(V3270FontChooserWidgetClass *klass) | |
| 146 | + { | |
| 119 | 147 | V3270SettingsClass * widget = GTK_V3270_SETTINGS_CLASS(klass); |
| 120 | 148 | |
| 121 | 149 | G_OBJECT_CLASS(klass)->dispose = dispose; |
| 122 | 150 | |
| 123 | - widget->apply = apply; | |
| 151 | + widget->cancel = cancel; | |
| 124 | 152 | widget->load = load; |
| 125 | 153 | |
| 126 | -} | |
| 154 | + } | |
| 155 | + | |
| 156 | + static void set_font_family(V3270FontChooserWidget *widget, const gchar * font_family) | |
| 157 | + { | |
| 158 | + | |
| 159 | + // Update font | |
| 160 | + if(widget->font.face) { | |
| 161 | + cairo_font_face_destroy(widget->font.face); | |
| 162 | + widget->font.face = NULL; | |
| 163 | + } | |
| 164 | + | |
| 165 | + widget->font.face = cairo_toy_font_face_create(font_family, CAIRO_FONT_SLANT_NORMAL, widget->font.weight); | |
| 166 | + gtk_widget_queue_draw(widget->preview); | |
| 167 | + | |
| 168 | + } | |
| 127 | 169 | |
| 128 | 170 | static void font_selected(GtkTreeSelection *selection, V3270FontChooserWidget *widget) |
| 129 | 171 | { |
| ... | ... | @@ -139,16 +181,10 @@ static void V3270FontChooserWidget_class_init(V3270FontChooserWidgetClass *klass |
| 139 | 181 | debug("Font-family: %s",g_value_get_string(&value)); |
| 140 | 182 | |
| 141 | 183 | // Update terminal widget |
| 142 | - GtkWidget * terminal = v3270_settings_get_terminal_widget(GTK_WIDGET(widget)); | |
| 143 | - if(terminal) | |
| 144 | - { | |
| 145 | - v3270_set_font_family(terminal,g_value_get_string(&value)); | |
| 146 | - gtk_widget_queue_draw(widget->preview); | |
| 147 | - } | |
| 148 | - | |
| 149 | - // Update font | |
| 184 | + if(widget->parent.terminal) | |
| 185 | + v3270_set_font_family(widget->parent.terminal,g_value_get_string(&value)); | |
| 150 | 186 | |
| 151 | - widget->font.face = cairo_toy_font_face_create(g_value_get_string(&value), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); | |
| 187 | + set_font_family(widget,g_value_get_string(&value)); | |
| 152 | 188 | |
| 153 | 189 | g_value_unset(&value); |
| 154 | 190 | } |
| ... | ... | @@ -206,8 +242,21 @@ static void V3270FontChooserWidget_class_init(V3270FontChooserWidgetClass *klass |
| 206 | 242 | return FALSE; |
| 207 | 243 | } |
| 208 | 244 | |
| 245 | +static void bold_toggled(GtkToggleButton *togglebutton, V3270FontChooserWidget *widget) | |
| 246 | +{ | |
| 247 | + gboolean active = gtk_toggle_button_get_active(togglebutton); | |
| 248 | + | |
| 249 | + widget->font.weight = (active ? CAIRO_FONT_WEIGHT_BOLD : CAIRO_FONT_WEIGHT_NORMAL); | |
| 250 | + | |
| 251 | + v3270_set_toggle(widget->parent.terminal,LIB3270_TOGGLE_BOLD,active); | |
| 252 | + set_font_family(widget,v3270_get_font_family(widget->parent.terminal)); | |
| 253 | + | |
| 254 | +} | |
| 255 | + | |
| 209 | 256 | static void V3270FontChooserWidget_init(V3270FontChooserWidget *widget) |
| 210 | 257 | { |
| 258 | + widget->font.weight = CAIRO_FONT_WEIGHT_NORMAL; | |
| 259 | + | |
| 211 | 260 | gtk_widget_set_size_request(GTK_WIDGET(widget),-1,136); |
| 212 | 261 | gtk_grid_set_row_homogeneous(GTK_GRID(widget),FALSE); |
| 213 | 262 | |
| ... | ... | @@ -260,6 +309,13 @@ static void V3270FontChooserWidget_init(V3270FontChooserWidget *widget) |
| 260 | 309 | gtk_grid_attach(GTK_GRID(widget),frame,1,0,5,3); |
| 261 | 310 | } |
| 262 | 311 | |
| 312 | + // Add font-weight button | |
| 313 | + { | |
| 314 | + widget->bold = GTK_TOGGLE_BUTTON(gtk_check_button_new_with_label(_("Bold"))); | |
| 315 | + gtk_grid_attach(GTK_GRID(widget),GTK_WIDGET(widget->bold),1,3,1,1); | |
| 316 | + g_signal_connect(G_OBJECT(widget->bold),"toggled",G_CALLBACK(bold_toggled),widget); | |
| 317 | + } | |
| 318 | + | |
| 263 | 319 | } |
| 264 | 320 | |
| 265 | 321 | GtkWidget * v3270_font_chooser_widget_new() | ... | ... |