Commit fe9d26d215742b3c2f0db64063bf28aec368804a

Authored by Perry Werneck
1 parent 93290192
Exists in master and in 1 other branch develop

Color scheme selector widget is now in the widget library.

src/dialogs/colorscheme.c
... ... @@ -336,6 +336,33 @@
336 336 return TRUE;
337 337 }
338 338  
  339 + gchar * v3270_color_scheme_get_text(GtkWidget *widget)
  340 + {
  341 + GdkRGBA * clr = NULL;
  342 + GValue value = { 0, };
  343 + GtkTreeIter iter;
  344 + int f;
  345 +
  346 + if(!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(widget),&iter))
  347 + return NULL;
  348 +
  349 + gtk_tree_model_get_value(gtk_combo_box_get_model(GTK_COMBO_BOX(widget)),&iter,1,&value);
  350 + clr = g_value_get_pointer(&value);
  351 +
  352 + GString *str = g_string_new("");
  353 + for(f=0;f<V3270_COLOR_COUNT;f++)
  354 + {
  355 + if(f)
  356 + g_string_append_c(str,';');
  357 +
  358 + g_autofree gchar * color = gdk_rgba_to_string(clr+f);
  359 + g_string_append_printf(str,"%s",color);
  360 + }
  361 +
  362 + return g_string_free(str,FALSE);
  363 +
  364 + }
  365 +
339 366 void v3270_color_scheme_set_rgba(GtkWidget *widget, const GdkRGBA *colors)
340 367 {
341 368 GtkTreeModel * model = gtk_combo_box_get_model(GTK_COMBO_BOX(widget));
... ... @@ -364,3 +391,42 @@
364 391  
365 392  
366 393 }
  394 +
  395 + void v3270_color_scheme_set_text(GtkWidget *widget, const gchar *colors)
  396 + {
  397 + GdkRGBA clr[V3270_COLOR_COUNT];
  398 + gchar **str = g_strsplit(colors,";",V3270_COLOR_BASE);
  399 + size_t f;
  400 +
  401 + switch(g_strv_length(str))
  402 + {
  403 + case 2: // Only 2 colors, create monocromatic table
  404 + v3270_set_mono_color_table(clr,str[1],str[0]);
  405 + break;
  406 +
  407 + case V3270_COLOR_BASE: // All colors, update it
  408 + for(f=0;f<V3270_COLOR_BASE;f++)
  409 + gdk_rgba_parse(clr+f,str[f]);
  410 + break;
  411 +
  412 + default:
  413 +
  414 + // Unexpected size, load new colors over the defaults
  415 + gdk_rgba_parse(clr,str[0]);
  416 + gdk_rgba_parse(clr+1,str[1]);
  417 +
  418 + for(f=2;f<V3270_COLOR_BASE;f++)
  419 + clr[f] = clr[1];
  420 +
  421 + clr[V3270_COLOR_BLACK] = *clr;
  422 +
  423 + for(f=2;f<MIN(g_strv_length(str),V3270_COLOR_BASE-1);f++)
  424 + gdk_rgba_parse(clr+f,str[f]);
  425 +
  426 + }
  427 +
  428 + g_strfreev(str);
  429 +
  430 + v3270_color_scheme_set_rgba(widget,clr);
  431 +
  432 + }
... ...
src/include/v3270/colorscheme.h
... ... @@ -49,6 +49,8 @@
49 49  
50 50 LIB3270_EXPORT GtkWidget * v3270_color_scheme_new();
51 51 LIB3270_EXPORT void v3270_color_scheme_set_rgba(GtkWidget *widget, const GdkRGBA *colors);
  52 + LIB3270_EXPORT gchar * v3270_color_scheme_get_text(GtkWidget *widget);
  53 + LIB3270_EXPORT void v3270_color_scheme_set_text(GtkWidget *widget, const gchar *colors);
52 54  
53 55 G_END_DECLS
54 56  
... ...