Commit 67471cd984cebc743d1634a4d6d9d2246c6a2fc2
1 parent
73dcb9dd
Exists in
master
and in
5 other branches
Implementando controle de cores
Showing
3 changed files
with
31 additions
and
102 deletions
Show diff stats
src/gtk/colors.c
@@ -32,106 +32,6 @@ | @@ -32,106 +32,6 @@ | ||
32 | 32 | ||
33 | /*--[ Implement ]------------------------------------------------------------------------------------*/ | 33 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
34 | 34 | ||
35 | -/* | ||
36 | - void load_color_schemes(GtkWidget *widget, gchar *active) | ||
37 | - { | ||
38 | - | ||
39 | - else | ||
40 | - { | ||
41 | - gchar ** group; | ||
42 | - GKeyFile * conf = g_key_file_new(); | ||
43 | - int f = 0; | ||
44 | - gboolean found = FALSE; | ||
45 | - | ||
46 | -#if !GTK_CHECK_VERSION(3,0,0) | ||
47 | - GtkTreeModel * model = (GtkTreeModel *) gtk_list_store_new(2,G_TYPE_STRING,G_TYPE_STRING); | ||
48 | - GtkCellRenderer * renderer = gtk_cell_renderer_text_new(); | ||
49 | - GtkTreeIter iter; | ||
50 | - | ||
51 | - gtk_combo_box_set_model(GTK_COMBO_BOX(widget),model); | ||
52 | - | ||
53 | - gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), renderer, TRUE); | ||
54 | - gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget), renderer, "text", 0, NULL); | ||
55 | - | ||
56 | -#endif // !GTK(3,0,0) | ||
57 | - | ||
58 | - g_key_file_load_from_file(conf,filename,G_KEY_FILE_NONE,NULL); | ||
59 | - | ||
60 | - group = g_key_file_get_groups(conf,NULL); | ||
61 | - | ||
62 | - for(f=0;group[f];f++) | ||
63 | - { | ||
64 | - gchar *str = g_strjoin( ",", g_key_file_get_string(conf,group[f],"Terminal",NULL), | ||
65 | - g_key_file_get_string(conf,group[f],"BaseAttributes",NULL), | ||
66 | - g_key_file_get_string(conf,group[f],"SelectedText",NULL), | ||
67 | - g_key_file_get_string(conf,group[f],"Cursor",NULL), | ||
68 | - g_key_file_get_string(conf,group[f],"OIA",NULL), | ||
69 | - NULL | ||
70 | - ); | ||
71 | -#if GTK_CHECK_VERSION(3,0,0) | ||
72 | - | ||
73 | - gtk_combo_box_text_insert( GTK_COMBO_BOX_TEXT(widget), | ||
74 | - f, | ||
75 | - str, | ||
76 | - g_key_file_get_locale_string(conf,group[f],"Label",NULL,NULL)); | ||
77 | - | ||
78 | - | ||
79 | - if(active && !g_strcasecmp(active,str)) | ||
80 | - { | ||
81 | - found = TRUE; | ||
82 | - gtk_combo_box_set_active(GTK_COMBO_BOX(widget),f); | ||
83 | - } | ||
84 | -#else | ||
85 | - | ||
86 | - gtk_list_store_append((GtkListStore *) model,&iter); | ||
87 | - gtk_list_store_set((GtkListStore *) model, &iter, | ||
88 | - 0, g_key_file_get_locale_string(conf,group[f],"Label",NULL,NULL), | ||
89 | - 1, str, | ||
90 | - -1); | ||
91 | - | ||
92 | - if(active && !g_strcasecmp(active,str)) | ||
93 | - { | ||
94 | - found = TRUE; | ||
95 | - gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget),&iter); | ||
96 | - } | ||
97 | - | ||
98 | -#endif // GTK(3,0,0) | ||
99 | - | ||
100 | - g_free(str); | ||
101 | - } | ||
102 | - | ||
103 | - g_strfreev(group); | ||
104 | - g_key_file_free(conf); | ||
105 | - | ||
106 | - if(active && !found) | ||
107 | - { | ||
108 | -#if GTK_CHECK_VERSION(3,0,0) | ||
109 | - | ||
110 | - gtk_combo_box_text_insert( GTK_COMBO_BOX_TEXT(widget), | ||
111 | - 0, | ||
112 | - active, | ||
113 | - _( "Custom colors") ); | ||
114 | - gtk_combo_box_set_active(GTK_COMBO_BOX(widget),0); | ||
115 | - | ||
116 | -#else | ||
117 | - | ||
118 | - gtk_list_store_append((GtkListStore *) model,&iter); | ||
119 | - gtk_list_store_set((GtkListStore *) model, &iter, | ||
120 | - 0, _( "Custom colors" ), | ||
121 | - 1, active, | ||
122 | - -1); | ||
123 | - | ||
124 | - gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget),&iter); | ||
125 | -#endif | ||
126 | - } | ||
127 | - | ||
128 | - gtk_widget_set_sensitive(widget,TRUE); | ||
129 | - | ||
130 | - } | ||
131 | - | ||
132 | - g_free(filename); | ||
133 | - } | ||
134 | -*/ | ||
135 | 35 | ||
136 | static void load_color_scheme(GKeyFile *conf, const gchar *group, GdkColor *clr) | 36 | static void load_color_scheme(GKeyFile *conf, const gchar *group, GdkColor *clr) |
137 | { | 37 | { |
@@ -294,13 +194,28 @@ static void load_color_scheme(GKeyFile *conf, const gchar *group, GdkColor *clr) | @@ -294,13 +194,28 @@ static void load_color_scheme(GKeyFile *conf, const gchar *group, GdkColor *clr) | ||
294 | 194 | ||
295 | } | 195 | } |
296 | 196 | ||
197 | + static gboolean compare_colors(const GdkColor *colora, const GdkColor *colorb) | ||
198 | + { | ||
199 | + int f; | ||
200 | + | ||
201 | + for(f=0;f<V3270_COLOR_COUNT;f++) | ||
202 | + { | ||
203 | + if(!gdk_color_equal(colora+f,colorb+f)) | ||
204 | + return FALSE; | ||
205 | + } | ||
206 | + | ||
207 | + return TRUE; | ||
208 | + } | ||
209 | + | ||
297 | /** | 210 | /** |
298 | * Create a color scheme dropdown button | 211 | * Create a color scheme dropdown button |
299 | * | 212 | * |
300 | * @param clr Pointer to current color table | 213 | * @param clr Pointer to current color table |
301 | * | 214 | * |
215 | + * @return Combobox widget with colors.conf loaded and set | ||
216 | + * | ||
302 | */ | 217 | */ |
303 | - GtkWidget * color_scheme_new(GdkColor *clr) | 218 | + GtkWidget * color_scheme_new(const GdkColor *current) |
304 | { | 219 | { |
305 | gchar * filename = build_data_filename("colors.conf",NULL); | 220 | gchar * filename = build_data_filename("colors.conf",NULL); |
306 | GtkTreeModel * model = (GtkTreeModel *) gtk_list_store_new(2,G_TYPE_STRING,G_TYPE_POINTER); | 221 | GtkTreeModel * model = (GtkTreeModel *) gtk_list_store_new(2,G_TYPE_STRING,G_TYPE_POINTER); |
@@ -355,6 +270,13 @@ static void load_color_scheme(GKeyFile *conf, const gchar *group, GdkColor *clr) | @@ -355,6 +270,13 @@ static void load_color_scheme(GKeyFile *conf, const gchar *group, GdkColor *clr) | ||
355 | 1, clr, | 270 | 1, clr, |
356 | -1); | 271 | -1); |
357 | 272 | ||
273 | + if(compare_colors(clr,current) && current) | ||
274 | + { | ||
275 | + // It's the same color, select iter | ||
276 | + trace("Current color scheme is \"%s\"",group[g]); | ||
277 | + gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget),&iter); | ||
278 | + } | ||
279 | + | ||
358 | // move to next color list | 280 | // move to next color list |
359 | pos += V3270_COLOR_COUNT; | 281 | pos += V3270_COLOR_COUNT; |
360 | } | 282 | } |
@@ -558,7 +480,7 @@ static void load_color_scheme(GKeyFile *conf, const gchar *group, GdkColor *clr) | @@ -558,7 +480,7 @@ static void load_color_scheme(GKeyFile *conf, const gchar *group, GdkColor *clr) | ||
558 | // Color scheme combo | 480 | // Color scheme combo |
559 | { | 481 | { |
560 | GtkWidget * box = gtk_hbox_new(FALSE,2); | 482 | GtkWidget * box = gtk_hbox_new(FALSE,2); |
561 | - GtkWidget * button = color_scheme_new(NULL); | 483 | + GtkWidget * button = color_scheme_new(v3270_get_color_table(widget)); |
562 | 484 | ||
563 | g_object_set_data(G_OBJECT(button),"terminal_widget",widget); | 485 | g_object_set_data(G_OBJECT(button),"terminal_widget",widget); |
564 | g_object_set_data(G_OBJECT(button),"color_selection_widget",color); | 486 | g_object_set_data(G_OBJECT(button),"color_selection_widget",color); |
src/gtk/v3270/v3270.h
@@ -218,6 +218,7 @@ | @@ -218,6 +218,7 @@ | ||
218 | // Colors | 218 | // Colors |
219 | void v3270_set_colors(GtkWidget *widget, const gchar *); | 219 | void v3270_set_colors(GtkWidget *widget, const gchar *); |
220 | void v3270_set_color_table(GdkColor *table, const gchar *colors); | 220 | void v3270_set_color_table(GdkColor *table, const gchar *colors); |
221 | + const GdkColor * v3270_get_color_table(GtkWidget *widget); | ||
221 | void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, guint height, GdkRectangle *rect, GdkColor *color); | 222 | void v3270_draw_element(cairo_t *cr, unsigned char chr, unsigned short attr, H3270 *session, guint height, GdkRectangle *rect, GdkColor *color); |
222 | void v3270_set_color(GtkWidget *widget, enum V3270_COLOR id, GdkColor *color); | 223 | void v3270_set_color(GtkWidget *widget, enum V3270_COLOR id, GdkColor *color); |
223 | GdkColor * v3270_get_color(GtkWidget *widget, enum V3270_COLOR id); | 224 | GdkColor * v3270_get_color(GtkWidget *widget, enum V3270_COLOR id); |
src/gtk/v3270/widget.c
@@ -868,6 +868,12 @@ GdkColor * v3270_get_color(GtkWidget *widget, enum V3270_COLOR id) | @@ -868,6 +868,12 @@ GdkColor * v3270_get_color(GtkWidget *widget, enum V3270_COLOR id) | ||
868 | return GTK_V3270(widget)->color+id; | 868 | return GTK_V3270(widget)->color+id; |
869 | } | 869 | } |
870 | 870 | ||
871 | +const GdkColor * v3270_get_color_table(GtkWidget *widget) | ||
872 | +{ | ||
873 | + g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | ||
874 | + return GTK_V3270(widget)->color; | ||
875 | +} | ||
876 | + | ||
871 | void v3270_set_color_table(GdkColor *table, const gchar *colors) | 877 | void v3270_set_color_table(GdkColor *table, const gchar *colors) |
872 | { | 878 | { |
873 | gchar **clr; | 879 | gchar **clr; |