Commit a008763afb6d08b24515d069c92cf45163ec5687
1 parent
b9333f4a
Exists in
v5.2
Updating settings manager.
Showing
2 changed files
with
15 additions
and
631 deletions
Show diff stats
src/pw3270/colors.c
| @@ -41,637 +41,6 @@ | @@ -41,637 +41,6 @@ | ||
| 41 | 41 | ||
| 42 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 42 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
| 43 | 43 | ||
| 44 | -/* | ||
| 45 | -static void store_color_scheme(GtkWidget *widget) | ||
| 46 | -{ | ||
| 47 | - int f; | ||
| 48 | - | ||
| 49 | - GString *text = g_string_new(""); | ||
| 50 | - // Base colors | ||
| 51 | - // base=#000000,#7890F0,#FF0000,#FF00FF,#00FF00,#00FFFF,#FFFF00,#FFFFFF,#000000,#000080,#FFA200,#800080,#008000,#008080,#A0A000,#C0C0C0 | ||
| 52 | - for(f=0;f<V3270_COLOR_BASE;f++) | ||
| 53 | - { | ||
| 54 | - if(f) | ||
| 55 | - g_string_append_c(text,';'); | ||
| 56 | - g_string_append_printf(text,"%s",gdk_rgba_to_string(v3270_get_color(widget,f))); | ||
| 57 | - } | ||
| 58 | - set_string_to_config("color-scheme","base","%s",text->str); | ||
| 59 | - g_string_truncate(text,0); | ||
| 60 | - | ||
| 61 | - // Field colors. | ||
| 62 | - // field=#00FF00,#FF0000,#00FFFF,#FFFFFF | ||
| 63 | - for(f=0;f<4;f++) | ||
| 64 | - { | ||
| 65 | - if(f) | ||
| 66 | - g_string_append_c(text,';'); | ||
| 67 | - g_string_append_printf(text,"%s",gdk_rgba_to_string(v3270_get_color(widget,V3270_COLOR_FIELD+f))); | ||
| 68 | - } | ||
| 69 | - set_string_to_config("color-scheme","field","%s",text->str); | ||
| 70 | - g_string_truncate(text,0); | ||
| 71 | - | ||
| 72 | - // Selection colors | ||
| 73 | - // selection=#404040,#ffffff | ||
| 74 | - for(f=0;f<2;f++) | ||
| 75 | - { | ||
| 76 | - if(f) | ||
| 77 | - g_string_append_c(text,';'); | ||
| 78 | - g_string_append_printf(text,"%s",gdk_rgba_to_string(v3270_get_color(widget,V3270_COLOR_SELECTED_BG+f))); | ||
| 79 | - } | ||
| 80 | - set_string_to_config("color-scheme","selection","%s",text->str); | ||
| 81 | - g_string_truncate(text,0); | ||
| 82 | - | ||
| 83 | - // OIA colors | ||
| 84 | - // OIA=#000000,#00FF00,#7890F0,#FFFFFF,#FF0000 | ||
| 85 | - for(f=0;f<5;f++) | ||
| 86 | - { | ||
| 87 | - if(f) | ||
| 88 | - g_string_append_c(text,';'); | ||
| 89 | - g_string_append_printf(text,"%s",gdk_rgba_to_string(v3270_get_color(widget,V3270_COLOR_OIA_BACKGROUND+f))); | ||
| 90 | - } | ||
| 91 | - set_string_to_config("color-scheme","OIA","%s",text->str); | ||
| 92 | - g_string_truncate(text,0); | ||
| 93 | - | ||
| 94 | - // Cross-hair | ||
| 95 | - g_string_append_printf(text,"%s",gdk_rgba_to_string(v3270_get_color(widget,V3270_COLOR_CROSS_HAIR))); | ||
| 96 | - | ||
| 97 | - set_string_to_config("color-scheme","cross-hair","%s",text->str); | ||
| 98 | - g_string_free(text,TRUE); | ||
| 99 | - | ||
| 100 | -} | ||
| 101 | - | ||
| 102 | -static void load_color_scheme(GKeyFile *conf, const gchar *group, GdkRGBA *clr) | ||
| 103 | -{ | ||
| 104 | - const gchar * val; | ||
| 105 | - int f; | ||
| 106 | - | ||
| 107 | - // Load base colors | ||
| 108 | - val = g_key_file_get_string(conf,group,"base",NULL); | ||
| 109 | - if(val) | ||
| 110 | - { | ||
| 111 | - // Process base colors | ||
| 112 | - gchar **str = g_strsplit(val,";",V3270_COLOR_BASE); | ||
| 113 | - | ||
| 114 | - switch(g_strv_length(str)) | ||
| 115 | - { | ||
| 116 | - case 2: // Only 2 colors, create monocromatic table | ||
| 117 | - v3270_set_mono_color_table(clr,str[1],str[0]); | ||
| 118 | - break; | ||
| 119 | - | ||
| 120 | - case V3270_COLOR_BASE: // All colors, update it | ||
| 121 | - for(f=0;f<V3270_COLOR_BASE;f++) | ||
| 122 | - gdk_rgba_parse(clr+f,str[f]); | ||
| 123 | - break; | ||
| 124 | - | ||
| 125 | - default: | ||
| 126 | - | ||
| 127 | - // Unexpected size, load new colors over the defaults | ||
| 128 | - g_warning("base color list in %s has %d elements, should have %d",group,g_strv_length(str),V3270_COLOR_GRAY); | ||
| 129 | - | ||
| 130 | - gdk_rgba_parse(clr,str[0]); | ||
| 131 | - gdk_rgba_parse(clr+1,str[1]); | ||
| 132 | - | ||
| 133 | - for(f=2;f<V3270_COLOR_BASE;f++) | ||
| 134 | - clr[f] = clr[1]; | ||
| 135 | - | ||
| 136 | - clr[V3270_COLOR_BLACK] = *clr; | ||
| 137 | - | ||
| 138 | - for(f=2;f<MIN(g_strv_length(str),V3270_COLOR_BASE-1);f++) | ||
| 139 | - gdk_rgba_parse(clr+f,str[f]); | ||
| 140 | - | ||
| 141 | - } | ||
| 142 | - g_strfreev(str); | ||
| 143 | - | ||
| 144 | - } | ||
| 145 | - else | ||
| 146 | - { | ||
| 147 | - g_warning("Color scheme [%s] has no \"base\" entry, using green on black",group); | ||
| 148 | - | ||
| 149 | - gdk_rgba_parse(clr,"black"); | ||
| 150 | - gdk_rgba_parse(clr+1,"green"); | ||
| 151 | - | ||
| 152 | - for(f=2;f<V3270_COLOR_BASE;f++) | ||
| 153 | - clr[f] = clr[1]; | ||
| 154 | - clr[V3270_COLOR_BLACK] = *clr; | ||
| 155 | - } | ||
| 156 | - | ||
| 157 | - // Load field colors | ||
| 158 | - clr[V3270_COLOR_FIELD] = clr[V3270_COLOR_GREEN]; | ||
| 159 | - clr[V3270_COLOR_FIELD_INTENSIFIED] = clr[V3270_COLOR_RED]; | ||
| 160 | - clr[V3270_COLOR_FIELD_PROTECTED] = clr[V3270_COLOR_BLUE]; | ||
| 161 | - clr[V3270_COLOR_FIELD_PROTECTED_INTENSIFIED] = clr[V3270_COLOR_WHITE]; | ||
| 162 | - | ||
| 163 | - val = g_key_file_get_string(conf,group,"field",NULL); | ||
| 164 | - if(val) | ||
| 165 | - { | ||
| 166 | - gchar **str = g_strsplit(val,";",5); | ||
| 167 | - | ||
| 168 | - for(f=0;f< MIN(g_strv_length(str),4); f++) | ||
| 169 | - gdk_rgba_parse(clr+V3270_COLOR_FIELD+f,str[f]); | ||
| 170 | - | ||
| 171 | - g_strfreev(str); | ||
| 172 | - } | ||
| 173 | - | ||
| 174 | - // Load selection colors | ||
| 175 | - clr[V3270_COLOR_SELECTED_BG] = clr[V3270_COLOR_WHITE]; | ||
| 176 | - clr[V3270_COLOR_SELECTED_FG] = clr[V3270_COLOR_BLACK]; | ||
| 177 | - val = g_key_file_get_string(conf,group,"selection",NULL); | ||
| 178 | - if(val) | ||
| 179 | - { | ||
| 180 | - gchar **str = g_strsplit(val,";",3); | ||
| 181 | - | ||
| 182 | - for(f=0;f< MIN(g_strv_length(str),2); f++) | ||
| 183 | - gdk_rgba_parse(clr+V3270_COLOR_SELECTED_BG+f,str[f]); | ||
| 184 | - | ||
| 185 | - g_strfreev(str); | ||
| 186 | - } | ||
| 187 | - | ||
| 188 | - // Load OIA colors | ||
| 189 | - clr[V3270_COLOR_OIA_BACKGROUND] = clr[V3270_COLOR_BACKGROUND]; | ||
| 190 | - clr[V3270_COLOR_OIA_FOREGROUND] = clr[V3270_COLOR_GREEN]; | ||
| 191 | - clr[V3270_COLOR_OIA_SEPARATOR] = clr[V3270_COLOR_GREEN]; | ||
| 192 | - clr[V3270_COLOR_OIA_STATUS_OK] = clr[V3270_COLOR_GREEN]; | ||
| 193 | - clr[V3270_COLOR_OIA_STATUS_INVALID] = clr[V3270_COLOR_RED]; | ||
| 194 | - clr[V3270_COLOR_OIA_STATUS_WARNING] = clr[V3270_COLOR_YELLOW]; | ||
| 195 | - | ||
| 196 | - val = g_key_file_get_string(conf,group,"OIA",NULL); | ||
| 197 | - if(val) | ||
| 198 | - { | ||
| 199 | - gchar **str = g_strsplit(val,";",6); | ||
| 200 | - | ||
| 201 | - // 0 = V3270_COLOR_OIA_BACKGROUND, | ||
| 202 | - // 1 = V3270_COLOR_OIA_FOREGROUND, | ||
| 203 | - // 2 = V3270_COLOR_OIA_SEPARATOR, | ||
| 204 | - // 3 = V3270_COLOR_OIA_STATUS_OK, | ||
| 205 | - // 4 = V3270_COLOR_OIA_STATUS_WARNING, | ||
| 206 | - // 5 = V3270_COLOR_OIA_STATUS_INVALID, | ||
| 207 | - | ||
| 208 | - if(g_strv_length(str) == 5) | ||
| 209 | - { | ||
| 210 | - for(f=0;f < 5; f++) | ||
| 211 | - gdk_rgba_parse(clr+V3270_COLOR_OIA_BACKGROUND+f,str[f]); | ||
| 212 | - clr[V3270_COLOR_OIA_STATUS_INVALID] = clr[V3270_COLOR_OIA_STATUS_WARNING]; | ||
| 213 | - } | ||
| 214 | - else | ||
| 215 | - { | ||
| 216 | - for(f=0;f< MIN(g_strv_length(str),6); f++) | ||
| 217 | - gdk_rgba_parse(clr+V3270_COLOR_OIA_BACKGROUND+f,str[f]); | ||
| 218 | - } | ||
| 219 | - | ||
| 220 | - g_strfreev(str); | ||
| 221 | - } | ||
| 222 | - | ||
| 223 | - // Setup extended elements | ||
| 224 | - clr[V3270_COLOR_CROSS_HAIR] = clr[V3270_COLOR_GREEN]; | ||
| 225 | - | ||
| 226 | - val = g_key_file_get_string(conf,group,"cross-hair",NULL); | ||
| 227 | - if(val) | ||
| 228 | - gdk_rgba_parse(clr+V3270_COLOR_CROSS_HAIR,val); | ||
| 229 | - | ||
| 230 | -} | ||
| 231 | - | ||
| 232 | - static void color_scheme_changed(GtkComboBox *combo) | ||
| 233 | - { | ||
| 234 | - GtkWidget * terminal = (GtkWidget *) g_object_get_data(G_OBJECT(combo),"terminal_widget"); | ||
| 235 | - GtkWidget * colorsel = (GtkWidget *) g_object_get_data(G_OBJECT(combo),"color_selection_widget"); | ||
| 236 | - GdkRGBA * clr = NULL; | ||
| 237 | - GValue value = { 0, }; | ||
| 238 | - GtkTreeIter iter; | ||
| 239 | - | ||
| 240 | - if(!gtk_combo_box_get_active_iter(combo,&iter)) | ||
| 241 | - return; | ||
| 242 | - | ||
| 243 | - gtk_tree_model_get_value(gtk_combo_box_get_model(combo),&iter,1,&value); | ||
| 244 | - | ||
| 245 | - clr = g_value_get_pointer(&value); | ||
| 246 | - g_object_set_data(G_OBJECT(combo),"selected",clr); | ||
| 247 | - | ||
| 248 | - if(terminal) | ||
| 249 | - { | ||
| 250 | - // Update terminal colors | ||
| 251 | - int f; | ||
| 252 | - for(f=0;f<V3270_COLOR_COUNT;f++) | ||
| 253 | - v3270_set_color(terminal,f,clr+f); | ||
| 254 | - | ||
| 255 | - v3270_reload(terminal); | ||
| 256 | - gtk_widget_queue_draw(terminal); | ||
| 257 | - } | ||
| 258 | - | ||
| 259 | - if(colorsel) | ||
| 260 | - { | ||
| 261 | - // Update color selection widget | ||
| 262 | - int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(colorsel),"colorid")); | ||
| 263 | - if(id >= 0 && id < V3270_COLOR_COUNT) | ||
| 264 | - { | ||
| 265 | -#if USE_GTK_COLOR_CHOOSER | ||
| 266 | - gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(colorsel),clr+id); | ||
| 267 | -#else | ||
| 268 | - gtk_color_selection_set_current_rgba(GTK_COLOR_SELECTION(colorsel),clr+id); | ||
| 269 | -#endif // GTK_CHECK_VERSION | ||
| 270 | - } | ||
| 271 | - } | ||
| 272 | - | ||
| 273 | - } | ||
| 274 | - | ||
| 275 | - static gboolean compare_colors(const GdkRGBA *colora, const GdkRGBA *colorb) | ||
| 276 | - { | ||
| 277 | - int f; | ||
| 278 | - | ||
| 279 | - for(f=0;f<V3270_COLOR_COUNT;f++) | ||
| 280 | - { | ||
| 281 | - if(!gdk_rgba_equal(colora+f,colorb+f)) | ||
| 282 | - return FALSE; | ||
| 283 | - } | ||
| 284 | - | ||
| 285 | - return TRUE; | ||
| 286 | - } | ||
| 287 | - | ||
| 288 | - /// | ||
| 289 | - /// @brief Create a color scheme dropdown button | ||
| 290 | - /// | ||
| 291 | - /// @param clr Pointer to current color table | ||
| 292 | - /// | ||
| 293 | - /// @return Combobox widget with colors.conf loaded and set | ||
| 294 | - /// | ||
| 295 | - /// | ||
| 296 | - GtkWidget * color_scheme_new(const GdkRGBA *current) | ||
| 297 | - { | ||
| 298 | - gchar * filename = build_data_filename("colors.conf",NULL); | ||
| 299 | - GtkTreeModel * model = (GtkTreeModel *) gtk_list_store_new(2,G_TYPE_STRING,G_TYPE_POINTER); | ||
| 300 | - GtkCellRenderer * renderer = gtk_cell_renderer_text_new(); | ||
| 301 | - GtkWidget * widget = gtk_combo_box_new_with_model(model); | ||
| 302 | - GtkTreeIter iter; | ||
| 303 | - | ||
| 304 | - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), renderer, TRUE); | ||
| 305 | - gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget), renderer, "text", 0, NULL); | ||
| 306 | - | ||
| 307 | - gtk_widget_set_sensitive(widget,FALSE); | ||
| 308 | - | ||
| 309 | - if(!g_file_test(filename,G_FILE_TEST_IS_REGULAR)) | ||
| 310 | - { | ||
| 311 | - g_warning("Unable to load color schemes in \"%s\"",filename); | ||
| 312 | - } | ||
| 313 | - else | ||
| 314 | - { | ||
| 315 | - GKeyFile * conf = g_key_file_new(); | ||
| 316 | - GError * err = NULL; | ||
| 317 | - | ||
| 318 | - g_key_file_load_from_file(conf,filename,G_KEY_FILE_NONE,&err); | ||
| 319 | - if(err) | ||
| 320 | - { | ||
| 321 | - g_warning("Error \"%s\" loading %s",err->message,filename); | ||
| 322 | - g_error_free(err); | ||
| 323 | - } | ||
| 324 | - else | ||
| 325 | - { | ||
| 326 | - gsize len = 0; | ||
| 327 | - gchar **group = g_key_file_get_groups(conf,&len); | ||
| 328 | - GdkRGBA * table = g_new0(GdkRGBA,(len*V3270_COLOR_COUNT)); | ||
| 329 | - int pos = 0; | ||
| 330 | - int g; | ||
| 331 | - gboolean found = FALSE; | ||
| 332 | - | ||
| 333 | - g_signal_connect(G_OBJECT(widget),"changed",G_CALLBACK(color_scheme_changed),0); | ||
| 334 | - | ||
| 335 | - g_object_set_data_full(G_OBJECT(widget),"colortable",table,g_free); | ||
| 336 | - | ||
| 337 | - for(g=0;g<len;g++) | ||
| 338 | - { | ||
| 339 | - // Setup colors for current entry | ||
| 340 | - GdkRGBA * clr = table+pos; | ||
| 341 | - const gchar * label = g_key_file_get_locale_string(conf,group[g],"label",NULL,NULL); | ||
| 342 | - | ||
| 343 | - load_color_scheme(conf,group[g],clr); | ||
| 344 | - | ||
| 345 | - // Set it in the combobox | ||
| 346 | - gtk_list_store_append((GtkListStore *) model,&iter); | ||
| 347 | - gtk_list_store_set((GtkListStore *) model, &iter, | ||
| 348 | - 0, label ? label : group[g], | ||
| 349 | - 1, clr, | ||
| 350 | - -1); | ||
| 351 | - | ||
| 352 | - if(compare_colors(clr,current) && current) | ||
| 353 | - { | ||
| 354 | - // It's the same color, select iter | ||
| 355 | - trace("Current color scheme is \"%s\"",group[g]); | ||
| 356 | - gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget),&iter); | ||
| 357 | - found = TRUE; | ||
| 358 | - } | ||
| 359 | - | ||
| 360 | - // move to next color list | ||
| 361 | - pos += V3270_COLOR_COUNT; | ||
| 362 | - } | ||
| 363 | - | ||
| 364 | - g_strfreev(group); | ||
| 365 | - | ||
| 366 | - if(!found) | ||
| 367 | - { | ||
| 368 | - // Custom color table, save it as a new dropdown entry. | ||
| 369 | - | ||
| 370 | - GdkRGBA * clr = g_new0(GdkRGBA,V3270_COLOR_COUNT); | ||
| 371 | - int f; | ||
| 372 | - | ||
| 373 | - for(f=0;f<V3270_COLOR_COUNT;f++) | ||
| 374 | - clr[f] = current[f]; | ||
| 375 | - | ||
| 376 | - trace("Current color scheme is \"%s\"","custom"); | ||
| 377 | - | ||
| 378 | - g_object_set_data_full(G_OBJECT(widget),"customcolortable",clr,g_free); | ||
| 379 | - | ||
| 380 | - gtk_list_store_append((GtkListStore *) model,&iter); | ||
| 381 | - gtk_list_store_set((GtkListStore *) model, &iter, | ||
| 382 | - 0, _( "Custom colors" ), | ||
| 383 | - 1, clr, | ||
| 384 | - -1); | ||
| 385 | - | ||
| 386 | - gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget),&iter); | ||
| 387 | - | ||
| 388 | - } | ||
| 389 | - | ||
| 390 | - | ||
| 391 | - gtk_widget_set_sensitive(widget,TRUE); | ||
| 392 | - } | ||
| 393 | - | ||
| 394 | - g_key_file_free(conf); | ||
| 395 | - | ||
| 396 | - } | ||
| 397 | - g_free(filename); | ||
| 398 | - | ||
| 399 | - return widget; | ||
| 400 | - } | ||
| 401 | - | ||
| 402 | -#if USE_GTK_COLOR_CHOOSER | ||
| 403 | - static void color_activated(GtkColorChooser *chooser, GdkRGBA *clr, GtkWidget *widget) | ||
| 404 | - { | ||
| 405 | - int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(chooser),"colorid")); | ||
| 406 | - | ||
| 407 | - if(id < 0 || id >= V3270_COLOR_COUNT) | ||
| 408 | - return; | ||
| 409 | - | ||
| 410 | - trace("Updating color %d",id); | ||
| 411 | - | ||
| 412 | - v3270_set_color(widget,id,clr); | ||
| 413 | - v3270_reload(widget); | ||
| 414 | - gtk_widget_queue_draw(widget); | ||
| 415 | - | ||
| 416 | - } | ||
| 417 | -#else | ||
| 418 | - static void color_changed(GtkWidget *colorselection, GtkWidget *widget) | ||
| 419 | - { | ||
| 420 | - GdkRGBA clr; | ||
| 421 | - int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(colorselection),"colorid")); | ||
| 422 | - | ||
| 423 | - if(id < 0 || id >= V3270_COLOR_COUNT) | ||
| 424 | - return; | ||
| 425 | - | ||
| 426 | - gtk_color_selection_get_current_rgba(GTK_COLOR_SELECTION(colorselection),&clr); | ||
| 427 | - | ||
| 428 | - v3270_set_color(widget,id,&clr); | ||
| 429 | - v3270_reload(widget); | ||
| 430 | - gtk_widget_queue_draw(widget); | ||
| 431 | - } | ||
| 432 | -#endif // GTK_CHECK_VERSION | ||
| 433 | - | ||
| 434 | - static void color_selected(GtkTreeSelection *selection, GtkWidget *color) | ||
| 435 | - { | ||
| 436 | - GtkWidget * widget = g_object_get_data(G_OBJECT(selection),"v3270"); | ||
| 437 | -#if ! USE_GTK_COLOR_CHOOSER | ||
| 438 | - GdkRGBA * saved = g_object_get_data(G_OBJECT(selection),"lastcolors"); | ||
| 439 | -#endif // !GTK(3,4,0) | ||
| 440 | - GValue value = { 0, }; | ||
| 441 | - GtkTreeModel * model; | ||
| 442 | - GtkTreeIter iter; | ||
| 443 | - GdkRGBA * clr; | ||
| 444 | - int id; | ||
| 445 | - | ||
| 446 | - gtk_widget_set_sensitive(color,FALSE); | ||
| 447 | - | ||
| 448 | - if(!gtk_tree_selection_get_selected(selection,&model,&iter)) | ||
| 449 | - return; | ||
| 450 | - | ||
| 451 | - gtk_tree_model_get_value(model,&iter,1,&value); | ||
| 452 | - | ||
| 453 | - id = g_value_get_int(&value); | ||
| 454 | - | ||
| 455 | - if(id < 0 || id >= V3270_COLOR_COUNT) | ||
| 456 | - return; | ||
| 457 | - | ||
| 458 | - g_object_set_data(G_OBJECT(color),"colorid",GINT_TO_POINTER(id)); | ||
| 459 | - clr = v3270_get_color(widget,id); | ||
| 460 | - | ||
| 461 | -#if USE_GTK_COLOR_CHOOSER | ||
| 462 | - { | ||
| 463 | - GValue value; | ||
| 464 | - | ||
| 465 | - gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(color),clr); | ||
| 466 | - | ||
| 467 | - g_value_init(&value, G_TYPE_BOOLEAN); | ||
| 468 | - g_value_set_boolean(&value,FALSE); | ||
| 469 | - g_object_set_property(G_OBJECT(color),"show-editor",&value); | ||
| 470 | - } | ||
| 471 | -#else | ||
| 472 | - gtk_color_selection_set_previous_rgba(GTK_COLOR_SELECTION(color),saved+id); | ||
| 473 | - gtk_color_selection_set_current_rgba(GTK_COLOR_SELECTION(color),clr); | ||
| 474 | -#endif // GTK_CHECK_VERSION | ||
| 475 | - | ||
| 476 | - gtk_widget_set_sensitive(color,TRUE); | ||
| 477 | - } | ||
| 478 | - | ||
| 479 | - void editcolors_action(GtkAction *action, GtkWidget *widget) | ||
| 480 | - { | ||
| 481 | -// static const gchar *custom = N_( "Custom colors" ); | ||
| 482 | - | ||
| 483 | - static const struct _node | ||
| 484 | - { | ||
| 485 | - int id; | ||
| 486 | - const char *text; | ||
| 487 | - } node[] = | ||
| 488 | - { | ||
| 489 | - { V3270_COLOR_BACKGROUND, N_( "Terminal colors" ) }, | ||
| 490 | - { V3270_COLOR_FIELD, N_( "Field colors" ) }, | ||
| 491 | - { V3270_COLOR_SELECTED_BG, N_( "Misc colors" ) }, | ||
| 492 | - }; | ||
| 493 | - | ||
| 494 | - static const gchar *color_name[V3270_COLOR_COUNT] = | ||
| 495 | - { | ||
| 496 | - N_( "Background" ), // V3270_COLOR_BACKGROUND | ||
| 497 | - N_( "Blue" ), // V3270_COLOR_BLUE | ||
| 498 | - N_( "Red" ), // V3270_COLOR_RED | ||
| 499 | - N_( "Pink" ), // V3270_COLOR_PINK | ||
| 500 | - N_( "Green" ), // V3270_COLOR_GREEN | ||
| 501 | - N_( "Turquoise" ), // V3270_COLOR_TURQUOISE | ||
| 502 | - N_( "Yellow" ), // V3270_COLOR_YELLOW | ||
| 503 | - N_( "White" ), // V3270_COLOR_WHITE | ||
| 504 | - N_( "Black" ), // V3270_COLOR_BLACK | ||
| 505 | - N_( "Dark Blue" ), // V3270_COLOR_DARK_BLUE | ||
| 506 | - N_( "Orange" ), // V3270_COLOR_ORANGE | ||
| 507 | - N_( "Purple" ), // V3270_COLOR_PURPLE | ||
| 508 | - N_( "Dark Green" ), // V3270_COLOR_DARK_GREEN | ||
| 509 | - N_( "Dark Turquoise" ), // V3270_COLOR_DARK_TURQUOISE | ||
| 510 | - N_( "Mustard" ), // V3270_COLOR_MUSTARD | ||
| 511 | - N_( "Gray" ), // V3270_COLOR_GRAY | ||
| 512 | - | ||
| 513 | - N_( "Normal/Unprotected" ), // V3270_COLOR_FIELD | ||
| 514 | - N_( "Intensified/Unprotected" ), // V3270_COLOR_FIELD_INTENSIFIED | ||
| 515 | - N_( "Normal/Protected" ), // V3270_COLOR_FIELD_PROTECTED | ||
| 516 | - N_( "Intensified/Protected" ), // V3270_COLOR_FIELD_PROTECTED_INTENSIFIED | ||
| 517 | - | ||
| 518 | - N_( "Selection background" ), // TERMINAL_COLOR_SELECTED_BG | ||
| 519 | - N_( "Selection foreground" ), // TERMINAL_COLOR_SELECTED_FG | ||
| 520 | - | ||
| 521 | - N_( "Cross hair cursor" ), // TERMINAL_COLOR_CROSS_HAIR | ||
| 522 | - | ||
| 523 | - // Oia Colors | ||
| 524 | - N_( "OIA background" ), // TERMINAL_COLOR_OIA_BACKGROUND | ||
| 525 | - N_( "OIA foreground" ), // TERMINAL_COLOR_OIA_FOREGROUND | ||
| 526 | - N_( "OIA separator" ), // TERMINAL_COLOR_OIA_SEPARATOR | ||
| 527 | - N_( "OIA status ok" ), // TERMINAL_COLOR_OIA_STATUS_OK | ||
| 528 | - N_( "OIA Warning" ), // V3270_COLOR_OIA_STATUS_WARNING | ||
| 529 | - N_( "OIA status invalid" ), // TERMINAL_COLOR_OIA_STATUS_INVALID | ||
| 530 | - | ||
| 531 | - }; | ||
| 532 | - | ||
| 533 | - const gchar * title = g_object_get_data(G_OBJECT(action),"title"); | ||
| 534 | - GtkWidget * dialog = gtk_dialog_new_with_buttons ( gettext(title ? title : N_( "Color setup") ), | ||
| 535 | - GTK_WINDOW(gtk_widget_get_toplevel(widget)), | ||
| 536 | - GTK_DIALOG_DESTROY_WITH_PARENT, | ||
| 537 | - GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, | ||
| 538 | - GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, | ||
| 539 | - NULL ); | ||
| 540 | -#if GTK_CHECK_VERSION(3,0,0) | ||
| 541 | - GtkWidget * panned = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,2); | ||
| 542 | -#else | ||
| 543 | - GtkWidget * panned = gtk_hbox_new(FALSE,2); | ||
| 544 | -#endif // GTK(3,0,0) | ||
| 545 | - | ||
| 546 | - GtkWidget * tree; | ||
| 547 | - GtkWidget * color; | ||
| 548 | - GdkRGBA saved[V3270_COLOR_COUNT]; | ||
| 549 | - | ||
| 550 | - // Color dialog setup | ||
| 551 | -#if USE_GTK_COLOR_CHOOSER | ||
| 552 | - color = gtk_color_chooser_widget_new(); | ||
| 553 | - gtk_widget_set_sensitive(color,0); | ||
| 554 | - g_signal_connect(G_OBJECT(color),"color-activated",G_CALLBACK(color_activated),widget); | ||
| 555 | -#else | ||
| 556 | - color = gtk_color_selection_new(); | ||
| 557 | - gtk_widget_set_sensitive(color,0); | ||
| 558 | - gtk_color_selection_set_has_opacity_control(GTK_COLOR_SELECTION(color),FALSE); | ||
| 559 | - gtk_color_selection_set_has_palette(GTK_COLOR_SELECTION(color),TRUE); | ||
| 560 | - g_signal_connect(G_OBJECT(color),"color-changed",G_CALLBACK(color_changed),widget); | ||
| 561 | -#endif // GTK_CHECK_VERSION | ||
| 562 | - | ||
| 563 | - gtk_box_pack_end(GTK_BOX(panned),color,TRUE,TRUE,0); | ||
| 564 | - g_object_set_data(G_OBJECT(color),"colorid",(gpointer) -1); | ||
| 565 | - | ||
| 566 | - // Tree view with all available colors | ||
| 567 | - { | ||
| 568 | - GtkTreeModel * model = (GtkTreeModel *) gtk_tree_store_new(2,G_TYPE_STRING,G_TYPE_INT); | ||
| 569 | - GtkWidget * box; | ||
| 570 | - GtkTreeIter iter; | ||
| 571 | - GtkTreeIter parent; | ||
| 572 | - GtkTreeSelection * select; | ||
| 573 | - int f; | ||
| 574 | - int title = 0; | ||
| 575 | - | ||
| 576 | - tree = gtk_tree_view_new_with_model(model); | ||
| 577 | - | ||
| 578 | - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(tree),FALSE); | ||
| 579 | - gtk_tree_view_insert_column_with_attributes( GTK_TREE_VIEW(tree), | ||
| 580 | - -1, | ||
| 581 | - "color",gtk_cell_renderer_text_new(),"text", | ||
| 582 | - 0, NULL ); | ||
| 583 | - | ||
| 584 | - gtk_tree_store_append((GtkTreeStore *) model,&parent,NULL); | ||
| 585 | - gtk_tree_store_set((GtkTreeStore *) model, &parent, 0, gettext(node[title++].text), 1, V3270_COLOR_COUNT, -1); | ||
| 586 | - | ||
| 587 | - select = gtk_tree_view_get_selection(GTK_TREE_VIEW (tree)); | ||
| 588 | - | ||
| 589 | - g_object_set_data(G_OBJECT(select),"v3270",widget); | ||
| 590 | - g_object_set_data(G_OBJECT(select),"lastcolors",saved); | ||
| 591 | - | ||
| 592 | - gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE); | ||
| 593 | - g_signal_connect(G_OBJECT(select),"changed",G_CALLBACK(color_selected),color); | ||
| 594 | - | ||
| 595 | - for(f=0;f<V3270_COLOR_COUNT;f++) | ||
| 596 | - { | ||
| 597 | - saved[f] = *(v3270_get_color(widget,f)); | ||
| 598 | - | ||
| 599 | - if(f == node[title].id) | ||
| 600 | - { | ||
| 601 | - gtk_tree_store_append((GtkTreeStore *) model,&parent,NULL); | ||
| 602 | - gtk_tree_store_set((GtkTreeStore *) model, &parent, 0, gettext(node[title++].text), 1, V3270_COLOR_COUNT, -1); | ||
| 603 | - } | ||
| 604 | - gtk_tree_store_append((GtkTreeStore *) model,&iter,&parent); | ||
| 605 | - gtk_tree_store_set((GtkTreeStore *) model, &iter, 0, gettext(color_name[f]), 1, f, -1); | ||
| 606 | - } | ||
| 607 | - | ||
| 608 | - gtk_tree_view_expand_all(GTK_TREE_VIEW(tree)); | ||
| 609 | - | ||
| 610 | - box = gtk_scrolled_window_new(NULL,NULL); | ||
| 611 | - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(box),GTK_POLICY_NEVER,GTK_POLICY_ALWAYS); | ||
| 612 | - gtk_container_add(GTK_CONTAINER(box),tree); | ||
| 613 | - gtk_box_pack_start(GTK_BOX(panned),box,TRUE,TRUE,0); | ||
| 614 | - | ||
| 615 | - | ||
| 616 | - } | ||
| 617 | - | ||
| 618 | - gtk_widget_show_all(panned); | ||
| 619 | - gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),GTK_WIDGET(panned),TRUE,TRUE,2); | ||
| 620 | - | ||
| 621 | - // Color scheme combo | ||
| 622 | - { | ||
| 623 | -#if GTK_CHECK_VERSION(3,0,0) | ||
| 624 | - GtkWidget * box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,2); | ||
| 625 | -#else | ||
| 626 | - GtkWidget * box = gtk_hbox_new(FALSE,2); | ||
| 627 | -#endif // GTK(3,0,0) | ||
| 628 | - GtkWidget * button = color_scheme_new(v3270_get_color_table(widget)); | ||
| 629 | - | ||
| 630 | - g_object_set_data(G_OBJECT(button),"terminal_widget",widget); | ||
| 631 | - g_object_set_data(G_OBJECT(button),"color_selection_widget",color); | ||
| 632 | - | ||
| 633 | - gtk_box_pack_start(GTK_BOX(box),gtk_label_new(_("Color scheme:")),FALSE,FALSE,2); | ||
| 634 | - gtk_box_pack_start(GTK_BOX(box),button,TRUE,TRUE,2); | ||
| 635 | - gtk_widget_show_all(box); | ||
| 636 | - gtk_box_pack_end(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),box,FALSE,FALSE,2); | ||
| 637 | - } | ||
| 638 | - | ||
| 639 | - // Run dialog | ||
| 640 | - | ||
| 641 | - if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) | ||
| 642 | - { | ||
| 643 | - // Accepted, save in configuration file | ||
| 644 | - int f; | ||
| 645 | - GString *str = g_string_new(""); | ||
| 646 | - for(f=0;f<V3270_COLOR_COUNT;f++) | ||
| 647 | - { | ||
| 648 | - if(f) | ||
| 649 | - g_string_append_c(str,';'); | ||
| 650 | - g_string_append_printf(str,"%s",gdk_rgba_to_string(v3270_get_color(widget,f))); | ||
| 651 | - } | ||
| 652 | - set_string_to_config("terminal","colors","%s",str->str); | ||
| 653 | - g_string_free(str,TRUE); | ||
| 654 | - | ||
| 655 | - store_color_scheme(widget); | ||
| 656 | - } | ||
| 657 | - else | ||
| 658 | - { | ||
| 659 | - // Rejected, restore original colors | ||
| 660 | - int f; | ||
| 661 | - | ||
| 662 | - for(f=0;f<V3270_COLOR_COUNT;f++) | ||
| 663 | - v3270_set_color(widget,f,saved+f); | ||
| 664 | - } | ||
| 665 | - | ||
| 666 | - gtk_widget_destroy(dialog); | ||
| 667 | - | ||
| 668 | - // Redraw widget | ||
| 669 | - v3270_reload(widget); | ||
| 670 | - gtk_widget_queue_draw(widget); | ||
| 671 | - | ||
| 672 | - } | ||
| 673 | - | ||
| 674 | -*/ | ||
| 675 | 44 | ||
| 676 | void editcolors_action(GtkAction *action, GtkWidget *terminal) | 45 | void editcolors_action(GtkAction *action, GtkWidget *terminal) |
| 677 | { | 46 | { |
src/pw3270/window.c
| @@ -34,10 +34,12 @@ | @@ -34,10 +34,12 @@ | ||
| 34 | #include <lib3270/popup.h> | 34 | #include <lib3270/popup.h> |
| 35 | #include <lib3270/actions.h> | 35 | #include <lib3270/actions.h> |
| 36 | #include <lib3270/trace.h> | 36 | #include <lib3270/trace.h> |
| 37 | +#include <lib3270/log.h> | ||
| 37 | #include <lib3270/toggle.h> | 38 | #include <lib3270/toggle.h> |
| 38 | #include <lib3270/properties.h> | 39 | #include <lib3270/properties.h> |
| 39 | #include <v3270/trace.h> | 40 | #include <v3270/trace.h> |
| 40 | #include <v3270/toggle.h> | 41 | #include <v3270/toggle.h> |
| 42 | +#include <v3270/settings.h> | ||
| 41 | 43 | ||
| 42 | /*--[ Widget definition ]----------------------------------------------------------------------------*/ | 44 | /*--[ Widget definition ]----------------------------------------------------------------------------*/ |
| 43 | 45 | ||
| @@ -401,6 +403,18 @@ static GtkWidget * trace_window = NULL; | @@ -401,6 +403,18 @@ static GtkWidget * trace_window = NULL; | ||
| 401 | update_window_title(window); | 403 | update_window_title(window); |
| 402 | } | 404 | } |
| 403 | 405 | ||
| 406 | + static void save_terminal_settings(GtkWidget *widget, GtkWidget *window) | ||
| 407 | + { | ||
| 408 | + debug("%s",__FUNCTION__); | ||
| 409 | + | ||
| 410 | +#ifdef ENABLE_WINDOWS_REGISTRY | ||
| 411 | + | ||
| 412 | +#else | ||
| 413 | + v3270_to_key_file(widget, get_application_keyfile(), "terminal"); | ||
| 414 | +#endif // _WIN32 | ||
| 415 | + | ||
| 416 | + } | ||
| 417 | + | ||
| 404 | LIB3270_EXPORT void pw3270_set_session_name(GtkWidget *widget, const gchar *name) | 418 | LIB3270_EXPORT void pw3270_set_session_name(GtkWidget *widget, const gchar *name) |
| 405 | { | 419 | { |
| 406 | g_return_if_fail(GTK_IS_PW3270(widget)); | 420 | g_return_if_fail(GTK_IS_PW3270(widget)); |
| @@ -840,6 +854,7 @@ static GtkWidget * trace_window = NULL; | @@ -840,6 +854,7 @@ static GtkWidget * trace_window = NULL; | ||
| 840 | g_signal_connect(widget->terminal,"field_clicked",G_CALLBACK(field_clicked),widget); | 854 | g_signal_connect(widget->terminal,"field_clicked",G_CALLBACK(field_clicked),widget); |
| 841 | g_signal_connect(widget->terminal,"toggle_changed",G_CALLBACK(toggle_changed),widget); | 855 | g_signal_connect(widget->terminal,"toggle_changed",G_CALLBACK(toggle_changed),widget); |
| 842 | g_signal_connect(widget->terminal,"session_changed",G_CALLBACK(session_changed),widget); | 856 | g_signal_connect(widget->terminal,"session_changed",G_CALLBACK(session_changed),widget); |
| 857 | + g_signal_connect(widget->terminal,"save_settings",G_CALLBACK(save_terminal_settings),widget); | ||
| 843 | 858 | ||
| 844 | //g_signal_connect(widget->terminal,"print",G_CALLBACK(print_all),widget); | 859 | //g_signal_connect(widget->terminal,"print",G_CALLBACK(print_all),widget); |
| 845 | 860 |