Commit f4129bbd4860d9c608ffc9302cc95e1def8005f4

Authored by perry.werneck@gmail.com
1 parent 26ff334a

Iniciando migração para GtkColorChooser

Showing 1 changed file with 60 additions and 12 deletions   Show diff stats
src/pw3270/colors.c
... ... @@ -30,6 +30,10 @@
30 30 #include <gtk/gtk.h>
31 31 #include "globals.h"
32 32  
  33 +//#if GTK_CHECK_VERSION(3,4,0)
  34 +// #define USE_GTK_COLOR_CHOOSER 1
  35 +//#endif // GTK_CHECK_VERSION
  36 +
33 37 /*--[ Implement ]------------------------------------------------------------------------------------*/
34 38  
35 39 static void load_color_scheme(GKeyFile *conf, const gchar *group, GdkRGBA *clr)
... ... @@ -196,7 +200,13 @@ static void load_color_scheme(GKeyFile *conf, const gchar *group, GdkRGBA *clr)
196 200 // Update color selection widget
197 201 int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(colorsel),"colorid"));
198 202 if(id >= 0 && id < V3270_COLOR_COUNT)
  203 + {
  204 +#if USE_GTK_COLOR_CHOOSER
  205 + gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(colorsel),clr+id);
  206 +#else
199 207 gtk_color_selection_set_current_rgba(GTK_COLOR_SELECTION(colorsel),clr+id);
  208 +#endif // GTK_CHECK_VERSION
  209 + }
200 210 }
201 211  
202 212 }
... ... @@ -328,24 +338,45 @@ static void load_color_scheme(GKeyFile *conf, const gchar *group, GdkRGBA *clr)
328 338 return widget;
329 339 }
330 340  
331   - static void color_changed(GtkColorSelection *colorselection, GtkWidget *widget)
  341 +#if USE_GTK_COLOR_CHOOSER
  342 + static void color_activated(GtkColorChooser *chooser, GdkRGBA *clr, GtkWidget *widget)
  343 + {
  344 + int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(chooser),"colorid"));
  345 +
  346 + if(id < 0 || id >= V3270_COLOR_COUNT)
  347 + return;
  348 +
  349 + trace("Updating color %d",id);
  350 +
  351 + v3270_set_color(widget,id,clr);
  352 + v3270_reload(widget);
  353 + gtk_widget_queue_draw(widget);
  354 +
  355 + }
  356 +
  357 +#else
  358 + static void color_changed(GtkWidget *colorselection, GtkWidget *widget)
332 359 {
333 360 GdkRGBA clr;
334   - int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(colorselection),"colorid"));
  361 + int id = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(colorselection),"colorid"));
335 362  
336 363 if(id < 0 || id >= V3270_COLOR_COUNT)
337 364 return;
338 365  
339   - gtk_color_selection_get_current_rgba(colorselection,&clr);
  366 + gtk_color_selection_get_current_rgba(GTK_COLOR_SELECTION(colorselection),&clr);
  367 +
340 368 v3270_set_color(widget,id,&clr);
341 369 v3270_reload(widget);
342 370 gtk_widget_queue_draw(widget);
343 371 }
  372 +#endif // GTK_CHECK_VERSION
344 373  
345 374 static void color_selected(GtkTreeSelection *selection, GtkWidget *color)
346 375 {
347 376 GtkWidget * widget = g_object_get_data(G_OBJECT(selection),"v3270");
  377 +#if ! USE_GTK_COLOR_CHOOSER
348 378 GdkRGBA * saved = g_object_get_data(G_OBJECT(selection),"lastcolors");
  379 +#endif // !GTK(3,4,0)
349 380 GValue value = { 0, };
350 381 GtkTreeModel * model;
351 382 GtkTreeIter iter;
... ... @@ -367,8 +398,20 @@ static void load_color_scheme(GKeyFile *conf, const gchar *group, GdkRGBA *clr)
367 398 g_object_set_data(G_OBJECT(color),"colorid",GINT_TO_POINTER(id));
368 399 clr = v3270_get_color(widget,id);
369 400  
  401 +#if USE_GTK_COLOR_CHOOSER
  402 + {
  403 + GValue value;
  404 +
  405 + gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(color),clr);
  406 +
  407 + g_value_init(&value, G_TYPE_BOOLEAN);
  408 + g_value_set_boolean(&value,FALSE);
  409 + g_object_set_property(G_OBJECT(color),"show-editor",&value);
  410 + }
  411 +#else
370 412 gtk_color_selection_set_previous_rgba(GTK_COLOR_SELECTION(color),saved+id);
371 413 gtk_color_selection_set_current_rgba(GTK_COLOR_SELECTION(color),clr);
  414 +#endif // GTK_CHECK_VERSION
372 415  
373 416 gtk_widget_set_sensitive(color,TRUE);
374 417 }
... ... @@ -445,15 +488,20 @@ static void load_color_scheme(GKeyFile *conf, const gchar *group, GdkRGBA *clr)
445 488 GdkRGBA saved[V3270_COLOR_COUNT];
446 489  
447 490 // Color dialog setup
448   - {
449   - color = gtk_color_selection_new();
450   - gtk_widget_set_sensitive(color,0);
451   - gtk_color_selection_set_has_opacity_control(GTK_COLOR_SELECTION(color),FALSE);
452   - gtk_color_selection_set_has_palette(GTK_COLOR_SELECTION(color),TRUE);
453   - gtk_box_pack_end(GTK_BOX(panned),color,TRUE,TRUE,0);
454   - g_object_set_data(G_OBJECT(color),"colorid",(gpointer) -1);
455   - g_signal_connect(G_OBJECT(color),"color-changed",G_CALLBACK(color_changed),widget);
456   - }
  491 +#if USE_GTK_COLOR_CHOOSER
  492 + color = gtk_color_chooser_widget_new();
  493 + gtk_widget_set_sensitive(color,0);
  494 + g_signal_connect(G_OBJECT(color),"color-activated",G_CALLBACK(color_activated),widget);
  495 +#else
  496 + color = gtk_color_selection_new();
  497 + gtk_widget_set_sensitive(color,0);
  498 + gtk_color_selection_set_has_opacity_control(GTK_COLOR_SELECTION(color),FALSE);
  499 + gtk_color_selection_set_has_palette(GTK_COLOR_SELECTION(color),TRUE);
  500 + g_signal_connect(G_OBJECT(color),"color-changed",G_CALLBACK(color_changed),widget);
  501 +#endif // GTK_CHECK_VERSION
  502 +
  503 + gtk_box_pack_end(GTK_BOX(panned),color,TRUE,TRUE,0);
  504 + g_object_set_data(G_OBJECT(color),"colorid",(gpointer) -1);
457 505  
458 506 // Tree view with all available colors
459 507 {
... ...