Commit 8f15131ca40fc8fd142cdbcd9fe23bdc5f51e2bc
1 parent
e647dd0d
Exists in
master
and in
1 other branch
Adjustments on color settings dialog.
Showing
6 changed files
with
402 additions
and
391 deletions
Show diff stats
src/dialogs/colors.c
| ... | ... | @@ -1,387 +0,0 @@ |
| 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 | - /** | |
| 31 | - * @brief Implements the V3270 Color selection widget. | |
| 32 | - * | |
| 33 | - */ | |
| 34 | - | |
| 35 | - #include "private.h" | |
| 36 | - #include <v3270/colorscheme.h> | |
| 37 | - #include <v3270/settings.h> | |
| 38 | - #include <v3270/dialogs.h> | |
| 39 | - #include <lib3270/log.h> | |
| 40 | - | |
| 41 | - #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
| 42 | - | |
| 43 | -/*--[ Widget definition ]----------------------------------------------------------------------------*/ | |
| 44 | - | |
| 45 | - struct _V3270ColorSelectionClass | |
| 46 | - { | |
| 47 | - V3270SettingsClass parent_class; | |
| 48 | - | |
| 49 | - }; | |
| 50 | - | |
| 51 | - struct _V3270ColorSelection | |
| 52 | - { | |
| 53 | - V3270Settings parent; | |
| 54 | - | |
| 55 | - int selected; | |
| 56 | - | |
| 57 | - struct { | |
| 58 | - GtkWidget * view; | |
| 59 | - GtkTreeModel * list; | |
| 60 | -#if USE_GTK_COLOR_CHOOSER | |
| 61 | - GtkWidget * chooser; | |
| 62 | -#else | |
| 63 | - GtkWidget * editor; | |
| 64 | -#endif // USE_GTK_COLOR_CHOOSER | |
| 65 | - GtkWidget * scheme; | |
| 66 | - } colors; | |
| 67 | - | |
| 68 | - /// @brief Saved colors. | |
| 69 | - GdkRGBA saved[V3270_COLOR_COUNT]; | |
| 70 | - | |
| 71 | - }; | |
| 72 | - | |
| 73 | - G_DEFINE_TYPE(V3270ColorSelection, V3270ColorSelection, GTK_TYPE_V3270_SETTINGS); | |
| 74 | - | |
| 75 | -/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 76 | - | |
| 77 | - static void update_color_chooser(V3270ColorSelection *widget, int id) | |
| 78 | - { | |
| 79 | - widget->selected = id; | |
| 80 | - | |
| 81 | - if(id < 0 || id >= V3270_COLOR_COUNT) | |
| 82 | - { | |
| 83 | -#if USE_GTK_COLOR_CHOOSER | |
| 84 | - gtk_widget_set_sensitive(widget->colors.chooser,FALSE); | |
| 85 | -#else | |
| 86 | - gtk_widget_set_sensitive(widget->colors.editor,FALSE); | |
| 87 | -#endif // USE_GTK_COLOR_CHOOSER | |
| 88 | - return; | |
| 89 | - } | |
| 90 | - | |
| 91 | - GdkRGBA * clr = v3270_get_color(GTK_V3270_SETTINGS(widget)->terminal,id); | |
| 92 | - | |
| 93 | -#if USE_GTK_COLOR_CHOOSER | |
| 94 | - { | |
| 95 | - GValue value; | |
| 96 | - | |
| 97 | - gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(widget->colors.chooser),clr); | |
| 98 | - | |
| 99 | - g_value_init(&value, G_TYPE_BOOLEAN); | |
| 100 | - g_value_set_boolean(&value,FALSE); | |
| 101 | - g_object_set_property(G_OBJECT(widget->colors.chooser),"show-editor",&value); | |
| 102 | - | |
| 103 | - gtk_widget_set_sensitive(widget->colors.chooser,TRUE); | |
| 104 | - | |
| 105 | - } | |
| 106 | -#else | |
| 107 | - | |
| 108 | - gtk_color_selection_set_previous_rgba(GTK_COLOR_SELECTION(widget->colors.editor),widget->saved+id); | |
| 109 | - gtk_color_selection_set_current_rgba(GTK_COLOR_SELECTION(widget->colors.editor),clr); | |
| 110 | - | |
| 111 | - gtk_widget_set_sensitive(widget->colors.editor,TRUE); | |
| 112 | -#endif // GTK_CHECK_VERSION | |
| 113 | - | |
| 114 | -} | |
| 115 | - | |
| 116 | -static void cancel(GtkWidget *widget, GtkWidget *terminal) | |
| 117 | -{ | |
| 118 | - debug("V3270ColorSelection::%s",__FUNCTION__); | |
| 119 | - | |
| 120 | - V3270ColorSelection * sel = GTK_V3270_COLOR_SELECTION(widget); | |
| 121 | - | |
| 122 | - int f; | |
| 123 | - for(f=0;f<V3270_COLOR_COUNT;f++) | |
| 124 | - v3270_set_color(terminal,f,sel->saved+f); | |
| 125 | - | |
| 126 | - update_color_chooser(sel,sel->selected); | |
| 127 | - | |
| 128 | - v3270_reload(terminal); | |
| 129 | - gtk_widget_queue_draw(terminal); | |
| 130 | - | |
| 131 | -} | |
| 132 | - | |
| 133 | -static void load(GtkWidget G_GNUC_UNUSED(*w), GtkWidget *terminal) | |
| 134 | -{ | |
| 135 | - debug("V3270ColorSelection::%s",__FUNCTION__); | |
| 136 | - | |
| 137 | - V3270ColorSelection * widget = GTK_V3270_COLOR_SELECTION(w); | |
| 138 | - | |
| 139 | - // Load colors | |
| 140 | - { | |
| 141 | - static const struct _node | |
| 142 | - { | |
| 143 | - int id; | |
| 144 | - const char *text; | |
| 145 | - } node[] = | |
| 146 | - { | |
| 147 | - { V3270_COLOR_BACKGROUND, N_( "Terminal colors" ) }, | |
| 148 | - { V3270_COLOR_FIELD, N_( "Field colors" ) }, | |
| 149 | - { V3270_COLOR_SELECTED_BG, N_( "Misc colors" ) }, | |
| 150 | - }; | |
| 151 | - | |
| 152 | - static const gchar *color_name[V3270_COLOR_COUNT] = | |
| 153 | - { | |
| 154 | - N_( "Background" ), // V3270_COLOR_BACKGROUND | |
| 155 | - N_( "Blue" ), // V3270_COLOR_BLUE | |
| 156 | - N_( "Red" ), // V3270_COLOR_RED | |
| 157 | - N_( "Pink" ), // V3270_COLOR_PINK | |
| 158 | - N_( "Green" ), // V3270_COLOR_GREEN | |
| 159 | - N_( "Turquoise" ), // V3270_COLOR_TURQUOISE | |
| 160 | - N_( "Yellow" ), // V3270_COLOR_YELLOW | |
| 161 | - N_( "White" ), // V3270_COLOR_WHITE | |
| 162 | - N_( "Black" ), // V3270_COLOR_BLACK | |
| 163 | - N_( "Dark Blue" ), // V3270_COLOR_DARK_BLUE | |
| 164 | - N_( "Orange" ), // V3270_COLOR_ORANGE | |
| 165 | - N_( "Purple" ), // V3270_COLOR_PURPLE | |
| 166 | - N_( "Dark Green" ), // V3270_COLOR_DARK_GREEN | |
| 167 | - N_( "Dark Turquoise" ), // V3270_COLOR_DARK_TURQUOISE | |
| 168 | - N_( "Mustard" ), // V3270_COLOR_MUSTARD | |
| 169 | - N_( "Gray" ), // V3270_COLOR_GRAY | |
| 170 | - | |
| 171 | - N_( "Normal/Unprotected" ), // V3270_COLOR_FIELD | |
| 172 | - N_( "Intensified/Unprotected" ), // V3270_COLOR_FIELD_INTENSIFIED | |
| 173 | - N_( "Normal/Protected" ), // V3270_COLOR_FIELD_PROTECTED | |
| 174 | - N_( "Intensified/Protected" ), // V3270_COLOR_FIELD_PROTECTED_INTENSIFIED | |
| 175 | - | |
| 176 | - N_( "Selection background" ), // TERMINAL_COLOR_SELECTED_BG | |
| 177 | - N_( "Selection foreground" ), // TERMINAL_COLOR_SELECTED_FG | |
| 178 | - | |
| 179 | - N_( "Cross hair cursor" ), // TERMINAL_COLOR_CROSS_HAIR | |
| 180 | - | |
| 181 | - // Oia Colors | |
| 182 | - N_( "OIA background" ), // TERMINAL_COLOR_OIA_BACKGROUND | |
| 183 | - N_( "OIA foreground" ), // TERMINAL_COLOR_OIA_FOREGROUND | |
| 184 | - N_( "OIA separator" ), // TERMINAL_COLOR_OIA_SEPARATOR | |
| 185 | - N_( "OIA status ok" ), // TERMINAL_COLOR_OIA_STATUS_OK | |
| 186 | - N_( "OIA Warning" ), // V3270_COLOR_OIA_STATUS_WARNING | |
| 187 | - N_( "OIA status invalid" ), // TERMINAL_COLOR_OIA_STATUS_INVALID | |
| 188 | - | |
| 189 | - }; | |
| 190 | - | |
| 191 | - GtkTreeIter iter; | |
| 192 | - GtkTreeIter parent; | |
| 193 | - int title = 0; | |
| 194 | - int f; | |
| 195 | - | |
| 196 | - gtk_tree_store_append(GTK_TREE_STORE(widget->colors.list),&parent,NULL); | |
| 197 | - gtk_tree_store_set(GTK_TREE_STORE(widget->colors.list), &parent, 0, gettext(node[title++].text), 1, V3270_COLOR_COUNT, -1); | |
| 198 | - | |
| 199 | - for(f=0;f<V3270_COLOR_COUNT;f++) | |
| 200 | - { | |
| 201 | - widget->saved[f] = *(v3270_get_color(terminal,f)); | |
| 202 | - | |
| 203 | - if(f == node[title].id) | |
| 204 | - { | |
| 205 | - gtk_tree_store_append(GTK_TREE_STORE(widget->colors.list),&parent,NULL); | |
| 206 | - gtk_tree_store_set(GTK_TREE_STORE(widget->colors.list), &parent, 0, gettext(node[title++].text), 1, V3270_COLOR_COUNT, -1); | |
| 207 | - } | |
| 208 | - gtk_tree_store_append(GTK_TREE_STORE(widget->colors.list),&iter,&parent); | |
| 209 | - gtk_tree_store_set(GTK_TREE_STORE(widget->colors.list), &iter, 0, gettext(color_name[f]), 1, f, -1); | |
| 210 | - } | |
| 211 | - | |
| 212 | - gtk_tree_view_expand_all(GTK_TREE_VIEW(widget->colors.view)); | |
| 213 | - | |
| 214 | - } | |
| 215 | - | |
| 216 | - v3270_color_scheme_set_rgba(widget->colors.scheme,v3270_get_color_table(terminal)); | |
| 217 | - | |
| 218 | -} | |
| 219 | - | |
| 220 | - static void V3270ColorSelection_class_init(G_GNUC_UNUSED V3270ColorSelectionClass *klass) | |
| 221 | - { | |
| 222 | - GTK_V3270_SETTINGS_CLASS(klass)->load = load; | |
| 223 | - GTK_V3270_SETTINGS_CLASS(klass)->revert = cancel; | |
| 224 | - } | |
| 225 | - | |
| 226 | - static void color_scheme_changed(GtkWidget G_GNUC_UNUSED(*dunno), const GdkRGBA *colors, V3270ColorSelection *widget) { | |
| 227 | - | |
| 228 | - GtkWidget * terminal = GTK_V3270_SETTINGS(widget)->terminal; | |
| 229 | - | |
| 230 | - int f; | |
| 231 | - for(f=0;f<V3270_COLOR_COUNT;f++) | |
| 232 | - v3270_set_color(terminal,f,colors+f); | |
| 233 | - | |
| 234 | - update_color_chooser(widget,widget->selected); | |
| 235 | - | |
| 236 | - v3270_reload(terminal); | |
| 237 | - gtk_widget_queue_draw(terminal); | |
| 238 | - | |
| 239 | - } | |
| 240 | - | |
| 241 | - | |
| 242 | - | |
| 243 | -#if USE_GTK_COLOR_CHOOSER | |
| 244 | - static void color_activated(GtkColorChooser *chooser, GdkRGBA *clr, V3270ColorSelection *widget) | |
| 245 | - { | |
| 246 | - if(widget->selected < 0 || widget->selected >= V3270_COLOR_COUNT) | |
| 247 | - return; | |
| 248 | - | |
| 249 | - trace("Updating color %d",widget->selected); | |
| 250 | - | |
| 251 | - v3270_set_color(widget->terminal,widget->selected,clr); | |
| 252 | - v3270_reload(widget->terminal); | |
| 253 | - v3270_color_scheme_set_rgba(widget->colors.scheme,v3270_get_color_table(widget->terminal)); | |
| 254 | - gtk_widget_queue_draw(widget->terminal); | |
| 255 | - | |
| 256 | - } | |
| 257 | -#else | |
| 258 | - static void color_changed(GtkWidget *colorselection, V3270ColorSelection *widget) | |
| 259 | - { | |
| 260 | - GdkRGBA clr; | |
| 261 | - GtkWidget * terminal = GTK_V3270_SETTINGS(widget)->terminal; | |
| 262 | - | |
| 263 | - if(widget->selected < 0 || widget->selected >= V3270_COLOR_COUNT) | |
| 264 | - return; | |
| 265 | - | |
| 266 | - gtk_color_selection_get_current_rgba(GTK_COLOR_SELECTION(colorselection),&clr); | |
| 267 | - | |
| 268 | - v3270_set_color(terminal,widget->selected,&clr); | |
| 269 | - v3270_reload(terminal); | |
| 270 | - v3270_color_scheme_set_rgba(widget->colors.scheme,v3270_get_color_table(terminal)); | |
| 271 | - gtk_widget_queue_draw(terminal); | |
| 272 | - | |
| 273 | - } | |
| 274 | -#endif // GTK_CHECK_VERSION | |
| 275 | - | |
| 276 | - static void color_selected(GtkTreeSelection *selection, V3270ColorSelection *widget) | |
| 277 | - { | |
| 278 | - GValue value = { 0, }; | |
| 279 | - GtkTreeModel * model; | |
| 280 | - GtkTreeIter iter; | |
| 281 | - | |
| 282 | - if(!gtk_tree_selection_get_selected(selection,&model,&iter)) | |
| 283 | - return; | |
| 284 | - | |
| 285 | - gtk_tree_model_get_value(model,&iter,1,&value); | |
| 286 | - | |
| 287 | - update_color_chooser(widget,g_value_get_int(&value)); | |
| 288 | - | |
| 289 | - g_value_unset(&value); | |
| 290 | - } | |
| 291 | - | |
| 292 | - static void V3270ColorSelection_init(V3270ColorSelection *widget) | |
| 293 | - { | |
| 294 | - { | |
| 295 | - // Create colors list view. | |
| 296 | - widget->colors.list = (GtkTreeModel *) gtk_tree_store_new(2,G_TYPE_STRING,G_TYPE_INT); | |
| 297 | - widget->colors.view = gtk_tree_view_new_with_model(widget->colors.list); | |
| 298 | - | |
| 299 | - gtk_widget_set_tooltip_markup(widget->colors.view,_("Terminal colors")); | |
| 300 | - | |
| 301 | - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(widget->colors.view),FALSE); | |
| 302 | - gtk_tree_view_insert_column_with_attributes( GTK_TREE_VIEW(widget->colors.view), | |
| 303 | - -1, | |
| 304 | - "color",gtk_cell_renderer_text_new(),"text", | |
| 305 | - 0, NULL ); | |
| 306 | - | |
| 307 | - // Setup selection mode. | |
| 308 | - GtkTreeSelection * select = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget->colors.view)); | |
| 309 | - gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE); | |
| 310 | - g_signal_connect(G_OBJECT(select),"changed",G_CALLBACK(color_selected),widget); | |
| 311 | - | |
| 312 | - // Put the view inside a scrolled window. | |
| 313 | - GtkWidget * box = gtk_scrolled_window_new(NULL,NULL); | |
| 314 | - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(box),GTK_POLICY_NEVER,GTK_POLICY_ALWAYS); | |
| 315 | - gtk_container_add(GTK_CONTAINER(box),widget->colors.view); | |
| 316 | - | |
| 317 | - gtk_widget_set_vexpand(box,TRUE); | |
| 318 | - gtk_widget_set_hexpand(box,TRUE); | |
| 319 | - | |
| 320 | - gtk_grid_attach(GTK_GRID(widget),box,0,0,3,5); | |
| 321 | - | |
| 322 | - } | |
| 323 | - | |
| 324 | -#ifdef USE_GTK_COLOR_CHOOSER | |
| 325 | - { | |
| 326 | - // Create color chooser widget | |
| 327 | - widget->colors.chooser = gtk_color_chooser_widget_new(); | |
| 328 | - | |
| 329 | - gtk_widget_set_sensitive(widget->colors.chooser,0); | |
| 330 | - g_signal_connect(G_OBJECT(widget->colors.chooser),"color-activated",G_CALLBACK(color_activated),widget); | |
| 331 | - | |
| 332 | - gtk_grid_attach(GTK_GRID(widget),widget->colors.chooser,3,0,5,5); | |
| 333 | - } | |
| 334 | -#else | |
| 335 | - { | |
| 336 | - widget->colors.editor = gtk_color_selection_new(); | |
| 337 | - gtk_color_selection_set_has_opacity_control(GTK_COLOR_SELECTION(widget->colors.editor),FALSE); | |
| 338 | - gtk_color_selection_set_has_palette(GTK_COLOR_SELECTION(widget->colors.editor),TRUE); | |
| 339 | - | |
| 340 | - gtk_widget_set_sensitive(widget->colors.editor,0); | |
| 341 | - g_signal_connect(G_OBJECT(widget->colors.editor),"color-changed",G_CALLBACK(color_changed),widget); | |
| 342 | - | |
| 343 | - gtk_grid_attach(GTK_GRID(widget),widget->colors.editor,3,0,5,5); | |
| 344 | - } | |
| 345 | -#endif // USE_GTK_COLOR_CHOOSER | |
| 346 | - | |
| 347 | - { | |
| 348 | - // Create scheme selector | |
| 349 | - GtkWidget * label = gtk_label_new_with_mnemonic(_("Color _theme")); | |
| 350 | - gtk_widget_set_halign(label,GTK_ALIGN_END); | |
| 351 | - | |
| 352 | - widget->colors.scheme = v3270_color_scheme_new(); | |
| 353 | - gtk_widget_set_tooltip_markup(widget->colors.scheme,_("Predefined color theme")); | |
| 354 | - | |
| 355 | - gtk_label_set_mnemonic_widget(GTK_LABEL(label),widget->colors.scheme); | |
| 356 | - | |
| 357 | - gtk_widget_set_margin_top(label,6); | |
| 358 | - gtk_widget_set_margin_top(widget->colors.scheme,6); | |
| 359 | - | |
| 360 | - gtk_grid_attach(GTK_GRID(widget),label,0,6,1,1); | |
| 361 | - gtk_grid_attach(GTK_GRID(widget),widget->colors.scheme,1,6,8,1); | |
| 362 | - g_signal_connect(G_OBJECT(widget->colors.scheme),"update-colors",G_CALLBACK(color_scheme_changed),widget); | |
| 363 | - | |
| 364 | - } | |
| 365 | - | |
| 366 | - | |
| 367 | - } | |
| 368 | - | |
| 369 | - LIB3270_EXPORT GtkWidget * v3270_color_selection_new() | |
| 370 | - { | |
| 371 | - V3270Settings * settings = GTK_V3270_SETTINGS(g_object_new(GTK_TYPE_V3270_COLOR_SELECTION, NULL)); | |
| 372 | - | |
| 373 | - settings->title = _("Terminal colors"); | |
| 374 | - settings->label = _("Colors"); | |
| 375 | - | |
| 376 | - return GTK_WIDGET(settings); | |
| 377 | - } | |
| 378 | - | |
| 379 | - LIB3270_EXPORT void v3270_edit_color_table(GtkWidget *terminal) | |
| 380 | - { | |
| 381 | - v3270_settings_popup_dialog( | |
| 382 | - v3270_color_selection_new(), | |
| 383 | - terminal, | |
| 384 | - FALSE | |
| 385 | - ); | |
| 386 | - | |
| 387 | - } |
| ... | ... | @@ -0,0 +1,394 @@ |
| 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 | + /** | |
| 31 | + * @brief Implements the V3270 Color selection widget. | |
| 32 | + * | |
| 33 | + */ | |
| 34 | + | |
| 35 | +// #include "private.h" | |
| 36 | + #include <internals.h> | |
| 37 | + #include <lib3270.h> | |
| 38 | + #include <v3270/colorscheme.h> | |
| 39 | + #include <v3270/settings.h> | |
| 40 | + #include <v3270/dialogs.h> | |
| 41 | + #include <lib3270/log.h> | |
| 42 | + | |
| 43 | + #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
| 44 | + | |
| 45 | +/*--[ Widget definition ]----------------------------------------------------------------------------*/ | |
| 46 | + | |
| 47 | + struct _V3270ColorSelectionClass | |
| 48 | + { | |
| 49 | + V3270SettingsClass parent_class; | |
| 50 | + | |
| 51 | + }; | |
| 52 | + | |
| 53 | + struct _V3270ColorSelection | |
| 54 | + { | |
| 55 | + V3270Settings parent; | |
| 56 | + | |
| 57 | + int selected; | |
| 58 | + | |
| 59 | + struct { | |
| 60 | + GtkWidget * view; | |
| 61 | + GtkTreeModel * list; | |
| 62 | +#if USE_GTK_COLOR_CHOOSER | |
| 63 | + GtkWidget * chooser; | |
| 64 | +#else | |
| 65 | + GtkWidget * editor; | |
| 66 | +#endif // USE_GTK_COLOR_CHOOSER | |
| 67 | + GtkWidget * scheme; | |
| 68 | + } colors; | |
| 69 | + | |
| 70 | + /// @brief Saved colors. | |
| 71 | + GdkRGBA saved[V3270_COLOR_COUNT]; | |
| 72 | + | |
| 73 | + }; | |
| 74 | + | |
| 75 | + G_DEFINE_TYPE(V3270ColorSelection, V3270ColorSelection, GTK_TYPE_V3270_SETTINGS); | |
| 76 | + | |
| 77 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 78 | + | |
| 79 | + static void update_color_chooser(V3270ColorSelection *widget, int id) | |
| 80 | + { | |
| 81 | + widget->selected = id; | |
| 82 | + | |
| 83 | + if(id < 0 || id >= V3270_COLOR_COUNT) | |
| 84 | + { | |
| 85 | +#if USE_GTK_COLOR_CHOOSER | |
| 86 | + gtk_widget_set_sensitive(widget->colors.chooser,FALSE); | |
| 87 | +#else | |
| 88 | + gtk_widget_set_sensitive(widget->colors.editor,FALSE); | |
| 89 | +#endif // USE_GTK_COLOR_CHOOSER | |
| 90 | + return; | |
| 91 | + } | |
| 92 | + | |
| 93 | + GdkRGBA * clr = v3270_get_color(GTK_V3270_SETTINGS(widget)->terminal,id); | |
| 94 | + | |
| 95 | +#if USE_GTK_COLOR_CHOOSER | |
| 96 | + { | |
| 97 | + GValue value; | |
| 98 | + | |
| 99 | + gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(widget->colors.chooser),clr); | |
| 100 | + | |
| 101 | + g_value_init(&value, G_TYPE_BOOLEAN); | |
| 102 | + g_value_set_boolean(&value,FALSE); | |
| 103 | + g_object_set_property(G_OBJECT(widget->colors.chooser),"show-editor",&value); | |
| 104 | + | |
| 105 | + gtk_widget_set_sensitive(widget->colors.chooser,TRUE); | |
| 106 | + | |
| 107 | + } | |
| 108 | +#else | |
| 109 | + | |
| 110 | + gtk_color_selection_set_previous_rgba(GTK_COLOR_SELECTION(widget->colors.editor),widget->saved+id); | |
| 111 | + gtk_color_selection_set_current_rgba(GTK_COLOR_SELECTION(widget->colors.editor),clr); | |
| 112 | + | |
| 113 | + gtk_widget_set_sensitive(widget->colors.editor,TRUE); | |
| 114 | +#endif // GTK_CHECK_VERSION | |
| 115 | + | |
| 116 | +} | |
| 117 | + | |
| 118 | +static void cancel(GtkWidget *widget, GtkWidget *terminal) | |
| 119 | +{ | |
| 120 | + debug("V3270ColorSelection::%s",__FUNCTION__); | |
| 121 | + | |
| 122 | + V3270ColorSelection * sel = GTK_V3270_COLOR_SELECTION(widget); | |
| 123 | + | |
| 124 | + int f; | |
| 125 | + for(f=0;f<V3270_COLOR_COUNT;f++) | |
| 126 | + v3270_set_color(terminal,f,sel->saved+f); | |
| 127 | + | |
| 128 | + update_color_chooser(sel,sel->selected); | |
| 129 | + | |
| 130 | + v3270_reload(terminal); | |
| 131 | + gtk_widget_queue_draw(terminal); | |
| 132 | + | |
| 133 | +} | |
| 134 | + | |
| 135 | +static void load(GtkWidget G_GNUC_UNUSED(*w), GtkWidget *terminal) | |
| 136 | +{ | |
| 137 | + debug("V3270ColorSelection::%s",__FUNCTION__); | |
| 138 | + | |
| 139 | + V3270ColorSelection * widget = GTK_V3270_COLOR_SELECTION(w); | |
| 140 | + | |
| 141 | + // Load colors | |
| 142 | + { | |
| 143 | + static const struct _node | |
| 144 | + { | |
| 145 | + int id; | |
| 146 | + const char *text; | |
| 147 | + } node[] = | |
| 148 | + { | |
| 149 | + { V3270_COLOR_BACKGROUND, N_( "Terminal colors" ) }, | |
| 150 | + { V3270_COLOR_FIELD, N_( "Field colors" ) }, | |
| 151 | + { V3270_COLOR_SELECTED_BG, N_( "Misc colors" ) }, | |
| 152 | + }; | |
| 153 | + | |
| 154 | + static const gchar *color_name[V3270_COLOR_COUNT] = | |
| 155 | + { | |
| 156 | + N_( "Background" ), // V3270_COLOR_BACKGROUND | |
| 157 | + N_( "Blue" ), // V3270_COLOR_BLUE | |
| 158 | + N_( "Red" ), // V3270_COLOR_RED | |
| 159 | + N_( "Pink" ), // V3270_COLOR_PINK | |
| 160 | + N_( "Green" ), // V3270_COLOR_GREEN | |
| 161 | + N_( "Turquoise" ), // V3270_COLOR_TURQUOISE | |
| 162 | + N_( "Yellow" ), // V3270_COLOR_YELLOW | |
| 163 | + N_( "White" ), // V3270_COLOR_WHITE | |
| 164 | + N_( "Black" ), // V3270_COLOR_BLACK | |
| 165 | + N_( "Dark Blue" ), // V3270_COLOR_DARK_BLUE | |
| 166 | + N_( "Orange" ), // V3270_COLOR_ORANGE | |
| 167 | + N_( "Purple" ), // V3270_COLOR_PURPLE | |
| 168 | + N_( "Dark Green" ), // V3270_COLOR_DARK_GREEN | |
| 169 | + N_( "Dark Turquoise" ), // V3270_COLOR_DARK_TURQUOISE | |
| 170 | + N_( "Mustard" ), // V3270_COLOR_MUSTARD | |
| 171 | + N_( "Gray" ), // V3270_COLOR_GRAY | |
| 172 | + | |
| 173 | + N_( "Normal/Unprotected" ), // V3270_COLOR_FIELD | |
| 174 | + N_( "Intensified/Unprotected" ), // V3270_COLOR_FIELD_INTENSIFIED | |
| 175 | + N_( "Normal/Protected" ), // V3270_COLOR_FIELD_PROTECTED | |
| 176 | + N_( "Intensified/Protected" ), // V3270_COLOR_FIELD_PROTECTED_INTENSIFIED | |
| 177 | + | |
| 178 | + N_( "Selection background" ), // TERMINAL_COLOR_SELECTED_BG | |
| 179 | + N_( "Selection foreground" ), // TERMINAL_COLOR_SELECTED_FG | |
| 180 | + | |
| 181 | + N_( "Cross hair cursor" ), // TERMINAL_COLOR_CROSS_HAIR | |
| 182 | + | |
| 183 | + // Oia Colors | |
| 184 | + N_( "OIA background" ), // TERMINAL_COLOR_OIA_BACKGROUND | |
| 185 | + N_( "OIA foreground" ), // TERMINAL_COLOR_OIA_FOREGROUND | |
| 186 | + N_( "OIA separator" ), // TERMINAL_COLOR_OIA_SEPARATOR | |
| 187 | + N_( "OIA status ok" ), // TERMINAL_COLOR_OIA_STATUS_OK | |
| 188 | + N_( "OIA Warning" ), // V3270_COLOR_OIA_STATUS_WARNING | |
| 189 | + N_( "OIA status invalid" ), // TERMINAL_COLOR_OIA_STATUS_INVALID | |
| 190 | + | |
| 191 | + }; | |
| 192 | + | |
| 193 | + GtkTreeIter iter; | |
| 194 | + GtkTreeIter parent; | |
| 195 | + int title = 0; | |
| 196 | + int f; | |
| 197 | + | |
| 198 | + gtk_tree_store_append(GTK_TREE_STORE(widget->colors.list),&parent,NULL); | |
| 199 | + gtk_tree_store_set(GTK_TREE_STORE(widget->colors.list), &parent, 0, gettext(node[title++].text), 1, V3270_COLOR_COUNT, -1); | |
| 200 | + | |
| 201 | + for(f=0;f<V3270_COLOR_COUNT;f++) | |
| 202 | + { | |
| 203 | + widget->saved[f] = *(v3270_get_color(terminal,f)); | |
| 204 | + | |
| 205 | + if(f == node[title].id) | |
| 206 | + { | |
| 207 | + gtk_tree_store_append(GTK_TREE_STORE(widget->colors.list),&parent,NULL); | |
| 208 | + gtk_tree_store_set(GTK_TREE_STORE(widget->colors.list), &parent, 0, gettext(node[title++].text), 1, V3270_COLOR_COUNT, -1); | |
| 209 | + } | |
| 210 | + gtk_tree_store_append(GTK_TREE_STORE(widget->colors.list),&iter,&parent); | |
| 211 | + gtk_tree_store_set(GTK_TREE_STORE(widget->colors.list), &iter, 0, gettext(color_name[f]), 1, f, -1); | |
| 212 | + } | |
| 213 | + | |
| 214 | + gtk_tree_view_expand_all(GTK_TREE_VIEW(widget->colors.view)); | |
| 215 | + | |
| 216 | + } | |
| 217 | + | |
| 218 | + v3270_color_scheme_set_rgba(widget->colors.scheme,v3270_get_color_table(terminal)); | |
| 219 | + | |
| 220 | +} | |
| 221 | + | |
| 222 | + static void V3270ColorSelection_class_init(G_GNUC_UNUSED V3270ColorSelectionClass *klass) | |
| 223 | + { | |
| 224 | + GTK_V3270_SETTINGS_CLASS(klass)->load = load; | |
| 225 | + GTK_V3270_SETTINGS_CLASS(klass)->revert = cancel; | |
| 226 | + } | |
| 227 | + | |
| 228 | + static void color_scheme_changed(GtkWidget G_GNUC_UNUSED(*dunno), const GdkRGBA *colors, V3270ColorSelection *widget) { | |
| 229 | + | |
| 230 | + GtkWidget * terminal = GTK_V3270_SETTINGS(widget)->terminal; | |
| 231 | + | |
| 232 | + int f; | |
| 233 | + for(f=0;f<V3270_COLOR_COUNT;f++) | |
| 234 | + v3270_set_color(terminal,f,colors+f); | |
| 235 | + | |
| 236 | + update_color_chooser(widget,widget->selected); | |
| 237 | + | |
| 238 | + v3270_reload(terminal); | |
| 239 | + gtk_widget_queue_draw(terminal); | |
| 240 | + | |
| 241 | + } | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | +#if USE_GTK_COLOR_CHOOSER | |
| 246 | + static void color_activated(GtkColorChooser *chooser, GdkRGBA *clr, V3270ColorSelection *widget) | |
| 247 | + { | |
| 248 | + if(widget->selected < 0 || widget->selected >= V3270_COLOR_COUNT) | |
| 249 | + return; | |
| 250 | + | |
| 251 | + trace("Updating color %d",widget->selected); | |
| 252 | + | |
| 253 | + v3270_set_color(widget->terminal,widget->selected,clr); | |
| 254 | + v3270_reload(widget->terminal); | |
| 255 | + v3270_color_scheme_set_rgba(widget->colors.scheme,v3270_get_color_table(widget->terminal)); | |
| 256 | + gtk_widget_queue_draw(widget->terminal); | |
| 257 | + | |
| 258 | + } | |
| 259 | +#else | |
| 260 | + static void color_changed(GtkWidget *colorselection, V3270ColorSelection *widget) | |
| 261 | + { | |
| 262 | + GdkRGBA clr; | |
| 263 | + GtkWidget * terminal = GTK_V3270_SETTINGS(widget)->terminal; | |
| 264 | + | |
| 265 | + if(widget->selected < 0 || widget->selected >= V3270_COLOR_COUNT) | |
| 266 | + return; | |
| 267 | + | |
| 268 | + gtk_color_selection_get_current_rgba(GTK_COLOR_SELECTION(colorselection),&clr); | |
| 269 | + | |
| 270 | + v3270_set_color(terminal,widget->selected,&clr); | |
| 271 | + v3270_reload(terminal); | |
| 272 | + v3270_color_scheme_set_rgba(widget->colors.scheme,v3270_get_color_table(terminal)); | |
| 273 | + gtk_widget_queue_draw(terminal); | |
| 274 | + | |
| 275 | + } | |
| 276 | +#endif // GTK_CHECK_VERSION | |
| 277 | + | |
| 278 | + static void color_selected(GtkTreeSelection *selection, V3270ColorSelection *widget) | |
| 279 | + { | |
| 280 | + GValue value = { 0, }; | |
| 281 | + GtkTreeModel * model; | |
| 282 | + GtkTreeIter iter; | |
| 283 | + | |
| 284 | + if(!gtk_tree_selection_get_selected(selection,&model,&iter)) | |
| 285 | + return; | |
| 286 | + | |
| 287 | + gtk_tree_model_get_value(model,&iter,1,&value); | |
| 288 | + | |
| 289 | + update_color_chooser(widget,g_value_get_int(&value)); | |
| 290 | + | |
| 291 | + g_value_unset(&value); | |
| 292 | + } | |
| 293 | + | |
| 294 | + static void V3270ColorSelection_init(V3270ColorSelection *widget) | |
| 295 | + { | |
| 296 | + { | |
| 297 | + // Create colors list view. | |
| 298 | + widget->colors.list = (GtkTreeModel *) gtk_tree_store_new(2,G_TYPE_STRING,G_TYPE_INT); | |
| 299 | + widget->colors.view = gtk_tree_view_new_with_model(widget->colors.list); | |
| 300 | + | |
| 301 | + gtk_widget_set_tooltip_markup(widget->colors.view,_("Terminal colors")); | |
| 302 | + | |
| 303 | + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(widget->colors.view),FALSE); | |
| 304 | + gtk_tree_view_insert_column_with_attributes( GTK_TREE_VIEW(widget->colors.view), | |
| 305 | + -1, | |
| 306 | + "color",gtk_cell_renderer_text_new(),"text", | |
| 307 | + 0, NULL ); | |
| 308 | + | |
| 309 | + // Setup selection mode. | |
| 310 | + GtkTreeSelection * select = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget->colors.view)); | |
| 311 | + gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE); | |
| 312 | + g_signal_connect(G_OBJECT(select),"changed",G_CALLBACK(color_selected),widget); | |
| 313 | + | |
| 314 | + // Put the view inside a scrolled window. | |
| 315 | + GtkWidget * box = gtk_scrolled_window_new(NULL,NULL); | |
| 316 | + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(box),GTK_POLICY_NEVER,GTK_POLICY_ALWAYS); | |
| 317 | + gtk_container_add(GTK_CONTAINER(box),widget->colors.view); | |
| 318 | + | |
| 319 | + gtk_widget_set_vexpand(box,TRUE); | |
| 320 | + gtk_widget_set_hexpand(box,TRUE); | |
| 321 | + | |
| 322 | + gtk_grid_attach(GTK_GRID(widget),box,0,0,3,5); | |
| 323 | + | |
| 324 | + } | |
| 325 | + | |
| 326 | +#ifdef USE_GTK_COLOR_CHOOSER | |
| 327 | + { | |
| 328 | + // Create color chooser widget | |
| 329 | + widget->colors.chooser = gtk_color_chooser_widget_new(); | |
| 330 | + | |
| 331 | + gtk_widget_set_sensitive(widget->colors.chooser,0); | |
| 332 | + g_signal_connect(G_OBJECT(widget->colors.chooser),"color-activated",G_CALLBACK(color_activated),widget); | |
| 333 | + | |
| 334 | + gtk_grid_attach(GTK_GRID(widget),widget->colors.chooser,3,0,5,5); | |
| 335 | + } | |
| 336 | +#else | |
| 337 | + { | |
| 338 | + widget->colors.editor = gtk_color_selection_new(); | |
| 339 | + gtk_color_selection_set_has_opacity_control(GTK_COLOR_SELECTION(widget->colors.editor),FALSE); | |
| 340 | + gtk_color_selection_set_has_palette(GTK_COLOR_SELECTION(widget->colors.editor),TRUE); | |
| 341 | + | |
| 342 | + gtk_widget_set_sensitive(widget->colors.editor,0); | |
| 343 | + g_signal_connect(G_OBJECT(widget->colors.editor),"color-changed",G_CALLBACK(color_changed),widget); | |
| 344 | + | |
| 345 | + gtk_grid_attach(GTK_GRID(widget),widget->colors.editor,3,0,5,5); | |
| 346 | + } | |
| 347 | +#endif // USE_GTK_COLOR_CHOOSER | |
| 348 | + | |
| 349 | + { | |
| 350 | + // Create scheme selector | |
| 351 | + GtkWidget * label = gtk_label_new_with_mnemonic(_("Color _theme")); | |
| 352 | + gtk_widget_set_halign(label,GTK_ALIGN_END); | |
| 353 | + | |
| 354 | + widget->colors.scheme = v3270_color_scheme_new(); | |
| 355 | + gtk_widget_set_tooltip_markup(widget->colors.scheme,_("Predefined color theme")); | |
| 356 | + | |
| 357 | + gtk_label_set_mnemonic_widget(GTK_LABEL(label),widget->colors.scheme); | |
| 358 | + | |
| 359 | + gtk_widget_set_margin_top(label,6); | |
| 360 | + gtk_widget_set_margin_top(widget->colors.scheme,6); | |
| 361 | + | |
| 362 | + gtk_grid_attach(GTK_GRID(widget),label,0,6,1,1); | |
| 363 | + gtk_grid_attach(GTK_GRID(widget),widget->colors.scheme,1,6,8,1); | |
| 364 | + g_signal_connect(G_OBJECT(widget->colors.scheme),"update-colors",G_CALLBACK(color_scheme_changed),widget); | |
| 365 | + | |
| 366 | + } | |
| 367 | + | |
| 368 | + | |
| 369 | + } | |
| 370 | + | |
| 371 | + LIB3270_EXPORT GtkWidget * v3270_color_selection_new() | |
| 372 | + { | |
| 373 | + return v3270_color_settings_new(); | |
| 374 | + } | |
| 375 | + | |
| 376 | + LIB3270_EXPORT GtkWidget * v3270_color_settings_new() | |
| 377 | + { | |
| 378 | + V3270Settings * settings = GTK_V3270_SETTINGS(g_object_new(GTK_TYPE_V3270_COLOR_SELECTION, NULL)); | |
| 379 | + | |
| 380 | + settings->title = _("Terminal colors"); | |
| 381 | + settings->label = _("Colors"); | |
| 382 | + | |
| 383 | + return GTK_WIDGET(settings); | |
| 384 | + } | |
| 385 | + | |
| 386 | + LIB3270_EXPORT void v3270_edit_color_table(GtkWidget *terminal) | |
| 387 | + { | |
| 388 | + v3270_settings_popup_dialog( | |
| 389 | + v3270_color_settings_new(), | |
| 390 | + terminal, | |
| 391 | + FALSE | |
| 392 | + ); | |
| 393 | + | |
| 394 | + } | ... | ... |
src/dialogs/settings/dialog.c
| ... | ... | @@ -320,6 +320,8 @@ void v3270_settings_popup_dialog(GtkWidget *widget, GtkWidget *terminal, gboolea |
| 320 | 320 | GtkWidget * dialog = v3270_settings_dialog_new(); |
| 321 | 321 | V3270Settings * settings = GTK_V3270_SETTINGS(widget); |
| 322 | 322 | |
| 323 | + v3270_settings_dialog_set_has_subtitle(dialog,FALSE); | |
| 324 | + | |
| 323 | 325 | if(settings->title) |
| 324 | 326 | gtk_window_set_title(GTK_WINDOW(dialog),settings->title); |
| 325 | 327 | ... | ... |
src/include/v3270/colorscheme.h
| ... | ... | @@ -65,7 +65,7 @@ |
| 65 | 65 | LIB3270_EXPORT gchar * v3270_color_scheme_get_text(GtkWidget *widget); |
| 66 | 66 | LIB3270_EXPORT void v3270_color_scheme_set_text(GtkWidget *widget, const gchar *colors); |
| 67 | 67 | |
| 68 | - LIB3270_EXPORT GtkWidget * v3270_color_selection_new(); | |
| 68 | + LIB3270_EXPORT GtkWidget * v3270_color_selection_new() G_GNUC_DEPRECATED; | |
| 69 | 69 | LIB3270_EXPORT void v3270_edit_color_table(GtkWidget *terminal); |
| 70 | 70 | |
| 71 | 71 | G_END_DECLS | ... | ... |
src/include/v3270/settings.h
v3270.cbp
| ... | ... | @@ -42,9 +42,6 @@ |
| 42 | 42 | <Add option="-fPIC" /> |
| 43 | 43 | </Linker> |
| 44 | 44 | <Unit filename="configure.ac" /> |
| 45 | - <Unit filename="src/dialogs/colors.c"> | |
| 46 | - <Option compilerVar="CC" /> | |
| 47 | - </Unit> | |
| 48 | 45 | <Unit filename="src/dialogs/colorscheme.c"> |
| 49 | 46 | <Option compilerVar="CC" /> |
| 50 | 47 | </Unit> |
| ... | ... | @@ -102,6 +99,9 @@ |
| 102 | 99 | <Unit filename="src/dialogs/settings/accelerator.c"> |
| 103 | 100 | <Option compilerVar="CC" /> |
| 104 | 101 | </Unit> |
| 102 | + <Unit filename="src/dialogs/settings/colors.c"> | |
| 103 | + <Option compilerVar="CC" /> | |
| 104 | + </Unit> | |
| 105 | 105 | <Unit filename="src/dialogs/settings/dialog.c"> |
| 106 | 106 | <Option compilerVar="CC" /> |
| 107 | 107 | </Unit> | ... | ... |