Commit 73dcb9ddcfb7906f65f7fb1622706df3cbdc1ba3
1 parent
a4dea2fc
Exists in
master
and in
5 other branches
Implementando suporte à esquemas de cor
Showing
2 changed files
with
305 additions
and
60 deletions
Show diff stats
colors.conf
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., 59 Temple | |
19 | +# Place, Suite 330, Boston, MA, 02111-1307, USA | |
20 | +# | |
21 | +# Contatos: | |
22 | +# | |
23 | +# perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
24 | +# erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
25 | +# | |
26 | + | |
1 | 27 | [X3270] |
2 | -Label=X3270 | |
3 | -Terminal=black,deepSkyBlue,red,pink,green,turquoise,yellow,white,black,blue3,orange,purple,paleGreen,paleTurquoise2,grey,white | |
4 | -BaseAttributes=green,red,deepSkyBlue,white | |
5 | -SelectedText=dimGrey,black,dimGrey | |
6 | -Cursor=white,white | |
7 | -OIA=black,white,white,white,white | |
28 | +label=X3270 | |
29 | + | |
30 | +base=black,deepSkyBlue,red,pink,green,turquoise,yellow,white,black,blue3,orange,purple,paleGreen,paleTurquoise2,grey,white | |
31 | +field=green,red,deepSkyBlue,white | |
32 | +selection=dimGrey,black | |
33 | +OIA=black,turquoise,turquoise,white,red | |
34 | + | |
35 | +cross-hair=white | |
8 | 36 | |
9 | 37 | [Reverse] |
10 | -Label=Reverse | |
11 | -Label[pt_BR]=Invertido | |
12 | -Terminal=white,blue,firebrick,pink,green4,cadetBlue,goldenrod,black,black,blue3,orange,purple,paleGreen,darkTurquoise,grey,black | |
13 | -BaseAttributes=green4,firebrick,blue,black | |
14 | -SelectedText=dimGrey,black,dimGrey | |
15 | -Cursor=black,black | |
16 | -OIA=white,black,black,black,black | |
38 | +label=Reverse | |
39 | +label[pt_BR]=Invertido | |
40 | + | |
41 | +base=white,blue,firebrick,pink,green4,cadetBlue,goldenrod,black,white,blue3,orange,purple,paleGreen,darkTurquoise,grey,black | |
42 | +selection=dimGrey,black | |
43 | +OIA=white,blue,blue,black,black | |
44 | + | |
45 | +cross-hair=black | |
17 | 46 | |
18 | 47 | [Bright] |
19 | -Label=Bright | |
20 | -Label[pt_BR]=Cores fortes | |
21 | -Terminal=black,blue,red,magenta,green,turquoise,yellow,white,black,blue3,orange,purple,paleGreen,cyan,grey,white | |
22 | -BaseAttributes=green,red,blue,white | |
23 | -SelectedText=dimGrey,black,dimGrey | |
24 | -Cursor=white,white | |
25 | -OIA=black,white,white,white,white | |
48 | +label=Bright | |
49 | +label[pt_BR]=Cores fortes | |
50 | + | |
51 | +base=black,blue,red,magenta,green,turquoise,yellow,white,black,blue3,orange,purple,paleGreen,cyan,grey,white | |
52 | +selection=dimGrey,black | |
53 | +OIA=black,blue,blue,white,red | |
54 | + | |
55 | +cross-hair=white | |
26 | 56 | |
27 | 57 | [CPE] |
28 | -Label=CPE | |
29 | -Terminal=black,LightBlue1,PaleVioletRed1,pink,green,turquoise,yellow,white,black,LightBlue3,orange,MediumPurple1,paleGreen,paleTurquoise2,grey80,white | |
30 | -BaseAttributes=green,PaleVioletRed1,LightBlue1,white | |
31 | -SelectedText=dimGrey,black,dimGrey | |
32 | -Cursor=white,white | |
33 | -OIA=black,white,white,white,white | |
58 | +label=CPE | |
59 | +base=black,LightBlue1,PaleVioletRed1,pink,green,turquoise,yellow,white,black,LightBlue3,orange,MediumPurple1,paleGreen,paleTurquoise2,grey80,white | |
60 | +selection=dimGrey,black | |
61 | +OIA=black,turquoise,turquoise,white,red | |
62 | + | |
63 | +cross-hair=white | |
34 | 64 | |
35 | 65 | [Green] |
36 | -Label=Green | |
37 | -Label[pt_BR]=Verde | |
38 | -Terminal=black,green,green,green,green,green,green,green,green,green,green,green,green,green,green,green | |
39 | -BaseAttributes=green,green,green,green | |
40 | -SelectedText=dimGrey,green,dimGrey | |
41 | -Cursor=green,green | |
42 | -OIA=black,green,green,green,green | |
66 | +label=Green | |
67 | +label[pt_BR]=Verde | |
68 | + | |
69 | +base=black,green | |
43 | 70 | |
44 | 71 | [WB] |
45 | -Label=White on Black | |
46 | -Label[pt_BR]=Branco com fundo preto | |
47 | -Terminal=black,white,white,white,white,white,white,white,white,white,white,white,white,white,white,white | |
48 | -BaseAttributes=white,white,white,white | |
49 | -SelectedText=white,black,white | |
50 | -Cursor=white,white | |
51 | -OIA=black,white,white,white,white | |
72 | +label=White on Black | |
73 | +label[pt_BR]=Branco com fundo preto | |
74 | + | |
75 | +base=black,white | |
52 | 76 | |
53 | 77 | [BW] |
54 | -Label=Black on White | |
55 | -Label[pt_BR]=Preto com fundo branco | |
56 | -Terminal=white,black,black,black,black,black,black,black,black,black,black,black,black,black,black,black | |
57 | -BaseAttributes=black,black,black,black | |
58 | -SelectedText=black,white,black | |
59 | -Cursor=black,black | |
60 | -OIA=white,black,black,black,black | |
78 | +label=Black on White | |
79 | +label[pt_BR]=Preto com fundo branco | |
80 | + | |
81 | +base=white,black | |
61 | 82 | ... | ... |
src/gtk/colors.c
... | ... | @@ -35,13 +35,7 @@ |
35 | 35 | /* |
36 | 36 | void load_color_schemes(GtkWidget *widget, gchar *active) |
37 | 37 | { |
38 | - gchar *filename = build_data_filename("colors.conf",NULL); | |
39 | 38 | |
40 | - if(!g_file_test(filename,G_FILE_TEST_IS_REGULAR)) | |
41 | - { | |
42 | - gtk_widget_set_sensitive(widget,FALSE); | |
43 | - g_warning("Unable to load color schemes in \"%s\"",filename); | |
44 | - } | |
45 | 39 | else |
46 | 40 | { |
47 | 41 | gchar ** group; |
... | ... | @@ -139,6 +133,167 @@ |
139 | 133 | } |
140 | 134 | */ |
141 | 135 | |
136 | +static void load_color_scheme(GKeyFile *conf, const gchar *group, GdkColor *clr) | |
137 | +{ | |
138 | + #define V3270_COLOR_BASE V3270_COLOR_GRAY+1 | |
139 | + | |
140 | + const gchar * val; | |
141 | + int f; | |
142 | + | |
143 | + // Load base colors | |
144 | + val = g_key_file_get_string(conf,group,"base",NULL); | |
145 | + if(val) | |
146 | + { | |
147 | + // Process base colors | |
148 | + gchar **str = g_strsplit(val,",",V3270_COLOR_BASE); | |
149 | + | |
150 | + switch(g_strv_length(str)) | |
151 | + { | |
152 | + case 2: // Only 2 colors, create monocromatic table | |
153 | + gdk_color_parse(str[0],clr); | |
154 | + gdk_color_parse(str[1],clr+1); | |
155 | + | |
156 | + trace("%s color table is: monocromatic",group); | |
157 | + | |
158 | + for(f=2;f<V3270_COLOR_BASE;f++) | |
159 | + clr[f] = clr[1]; | |
160 | + clr[V3270_COLOR_BLACK] = *clr; | |
161 | + break; | |
162 | + | |
163 | + case V3270_COLOR_BASE: // All colors, update it | |
164 | + trace("%s color table is: complete",group); | |
165 | + for(f=0;f<V3270_COLOR_BASE;f++) | |
166 | + gdk_color_parse(str[f],clr+f); | |
167 | + break; | |
168 | + | |
169 | + default: | |
170 | + | |
171 | + // Unexpected size, load new colors over the defaults | |
172 | + g_warning("base color list in %s has %d elements, should have %d",group,g_strv_length(str),V3270_COLOR_GRAY); | |
173 | + | |
174 | + gdk_color_parse(str[0],clr); | |
175 | + gdk_color_parse(str[1],clr+1); | |
176 | + | |
177 | + for(f=2;f<V3270_COLOR_BASE;f++) | |
178 | + clr[f] = clr[1]; | |
179 | + | |
180 | + clr[V3270_COLOR_BLACK] = *clr; | |
181 | + | |
182 | + for(f=2;f<MIN(g_strv_length(str),V3270_COLOR_BASE-1);f++) | |
183 | + gdk_color_parse(str[f],clr+f); | |
184 | + | |
185 | + } | |
186 | + g_strfreev(str); | |
187 | + | |
188 | + } | |
189 | + else | |
190 | + { | |
191 | + g_warning("Color scheme [%d] has no \"base\" entry, using green on black",group); | |
192 | + | |
193 | + gdk_color_parse("black",clr); | |
194 | + gdk_color_parse("green",clr+1); | |
195 | + | |
196 | + for(f=2;f<V3270_COLOR_BASE;f++) | |
197 | + clr[f] = clr[1]; | |
198 | + clr[V3270_COLOR_BLACK] = *clr; | |
199 | + } | |
200 | + | |
201 | + // Load field colors | |
202 | + clr[V3270_COLOR_FIELD] = clr[V3270_COLOR_GREEN]; | |
203 | + clr[V3270_COLOR_FIELD_INTENSIFIED] = clr[V3270_COLOR_RED]; | |
204 | + clr[V3270_COLOR_FIELD_PROTECTED] = clr[V3270_COLOR_BLUE]; | |
205 | + clr[V3270_COLOR_FIELD_PROTECTED_INTENSIFIED] = clr[V3270_COLOR_WHITE]; | |
206 | + | |
207 | + val = g_key_file_get_string(conf,group,"field",NULL); | |
208 | + if(val) | |
209 | + { | |
210 | + gchar **str = g_strsplit(val,",",5); | |
211 | + | |
212 | + for(f=0;f< MIN(g_strv_length(str),4); f++) | |
213 | + gdk_color_parse(str[f],clr+V3270_COLOR_FIELD+f); | |
214 | + | |
215 | + g_strfreev(str); | |
216 | + } | |
217 | + | |
218 | + // Load selection colors | |
219 | + clr[V3270_COLOR_SELECTED_BG] = clr[V3270_COLOR_WHITE]; | |
220 | + clr[V3270_COLOR_SELECTED_FG] = clr[V3270_COLOR_BLACK]; | |
221 | + val = g_key_file_get_string(conf,group,"selection",NULL); | |
222 | + if(val) | |
223 | + { | |
224 | + gchar **str = g_strsplit(val,",",3); | |
225 | + | |
226 | + for(f=0;f< MIN(g_strv_length(str),2); f++) | |
227 | + gdk_color_parse(str[f],clr+V3270_COLOR_SELECTED_BG+f); | |
228 | + | |
229 | + g_strfreev(str); | |
230 | + } | |
231 | + | |
232 | + // Load OIA colors | |
233 | + clr[V3270_COLOR_OIA_BACKGROUND] = clr[V3270_COLOR_BACKGROUND]; | |
234 | + clr[V3270_COLOR_OIA_FOREGROUND] = clr[V3270_COLOR_GREEN]; | |
235 | + clr[V3270_COLOR_OIA_SEPARATOR] = clr[V3270_COLOR_GREEN]; | |
236 | + clr[V3270_COLOR_OIA_STATUS_OK] = clr[V3270_COLOR_GREEN]; | |
237 | + clr[V3270_COLOR_OIA_STATUS_INVALID] = clr[V3270_COLOR_RED]; | |
238 | + | |
239 | + val = g_key_file_get_string(conf,group,"OIA",NULL); | |
240 | + if(val) | |
241 | + { | |
242 | + gchar **str = g_strsplit(val,",",5); | |
243 | + | |
244 | + for(f=0;f< MIN(g_strv_length(str),4); f++) | |
245 | + gdk_color_parse(str[f],clr+V3270_COLOR_OIA_BACKGROUND+f); | |
246 | + | |
247 | + g_strfreev(str); | |
248 | + } | |
249 | + | |
250 | + // Setup extended elements | |
251 | + clr[V3270_COLOR_CROSS_HAIR] = clr[V3270_COLOR_GREEN]; | |
252 | + | |
253 | + val = g_key_file_get_string(conf,group,"cross-hair",NULL); | |
254 | + if(val) | |
255 | + gdk_color_parse(val,clr+V3270_COLOR_CROSS_HAIR); | |
256 | + | |
257 | +} | |
258 | + | |
259 | + static void color_scheme_changed(GtkComboBox *combo,gpointer dunno) | |
260 | + { | |
261 | + GtkWidget * terminal = (GtkWidget *) g_object_get_data(G_OBJECT(combo),"terminal_widget"); | |
262 | + GtkWidget * colorsel = (GtkWidget *) g_object_get_data(G_OBJECT(combo),"color_selection_widget"); | |
263 | + GdkColor * clr = NULL; | |
264 | + GValue value = { 0, }; | |
265 | + GtkTreeIter iter; | |
266 | + | |
267 | + if(!gtk_combo_box_get_active_iter(combo,&iter)) | |
268 | + return; | |
269 | + | |
270 | + gtk_tree_model_get_value(gtk_combo_box_get_model(combo),&iter,1,&value); | |
271 | + | |
272 | + clr = g_value_get_pointer(&value); | |
273 | + g_object_set_data(G_OBJECT(combo),"selected",clr); | |
274 | + | |
275 | + if(terminal) | |
276 | + { | |
277 | + // Update terminal colors | |
278 | + int f; | |
279 | + for(f=0;f<V3270_COLOR_COUNT;f++) | |
280 | + v3270_set_color(terminal,f,clr+f); | |
281 | + | |
282 | + v3270_reload(terminal); | |
283 | + gtk_widget_queue_draw(terminal); | |
284 | + | |
285 | + } | |
286 | + | |
287 | + if(colorsel) | |
288 | + { | |
289 | + // Update color selection widget | |
290 | + int id = (int) g_object_get_data(G_OBJECT(colorsel),"colorid"); | |
291 | + if(id >= 0 && id < V3270_COLOR_COUNT) | |
292 | + gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel),clr+id); | |
293 | + } | |
294 | + | |
295 | + } | |
296 | + | |
142 | 297 | /** |
143 | 298 | * Create a color scheme dropdown button |
144 | 299 | * |
... | ... | @@ -147,13 +302,75 @@ |
147 | 302 | */ |
148 | 303 | GtkWidget * color_scheme_new(GdkColor *clr) |
149 | 304 | { |
150 | -#if GTK_CHECK_VERSION(3,0,0) | |
151 | - GtkWidget *widget = gtk_combo_box_text_new(); | |
152 | -#else | |
153 | - GtkWidget *widget = gtk_combo_box_new(); | |
154 | -#endif // GTK(3,0,0) | |
305 | + gchar * filename = build_data_filename("colors.conf",NULL); | |
306 | + GtkTreeModel * model = (GtkTreeModel *) gtk_list_store_new(2,G_TYPE_STRING,G_TYPE_POINTER); | |
307 | + GtkCellRenderer * renderer = gtk_cell_renderer_text_new(); | |
308 | + GtkWidget * widget = gtk_combo_box_new_with_model(model); | |
309 | + GtkTreeIter iter; | |
310 | + | |
311 | + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), renderer, TRUE); | |
312 | + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget), renderer, "text", 0, NULL); | |
313 | + | |
314 | + gtk_widget_set_sensitive(widget,FALSE); | |
315 | + | |
316 | + if(!g_file_test(filename,G_FILE_TEST_IS_REGULAR)) | |
317 | + { | |
318 | + g_warning("Unable to load color schemes in \"%s\"",filename); | |
319 | + } | |
320 | + else | |
321 | + { | |
322 | + GKeyFile * conf = g_key_file_new(); | |
323 | + GError * err = NULL; | |
324 | + | |
325 | + g_key_file_load_from_file(conf,filename,G_KEY_FILE_NONE,&err); | |
326 | + if(err) | |
327 | + { | |
328 | + g_warning("Error \"%s\" loading %s",err->message,filename); | |
329 | + g_error_free(err); | |
330 | + } | |
331 | + else | |
332 | + { | |
333 | + gsize len = 0; | |
334 | + gchar **group = g_key_file_get_groups(conf,&len); | |
335 | + GdkColor * table = g_new0(GdkColor,(len*V3270_COLOR_COUNT)); | |
336 | + int pos = 0; | |
337 | + int g; | |
338 | + | |
339 | + g_signal_connect(G_OBJECT(widget),"changed",G_CALLBACK(color_scheme_changed),table); | |
340 | + | |
341 | + g_object_set_data_full(G_OBJECT(widget),"colortable",table,g_free); | |
342 | + | |
343 | + for(g=0;g<len;g++) | |
344 | + { | |
345 | + // Setup colors for current entry | |
346 | + GdkColor * clr = table+pos; | |
347 | + const gchar * label = g_key_file_get_locale_string(conf,group[g],"label",NULL,NULL); | |
348 | + | |
349 | + load_color_scheme(conf,group[g],clr); | |
350 | + | |
351 | + // Set it in the combobox | |
352 | + gtk_list_store_append((GtkListStore *) model,&iter); | |
353 | + gtk_list_store_set((GtkListStore *) model, &iter, | |
354 | + 0, label ? label : group[g], | |
355 | + 1, clr, | |
356 | + -1); | |
357 | + | |
358 | + // move to next color list | |
359 | + pos += V3270_COLOR_COUNT; | |
360 | + } | |
155 | 361 | |
156 | 362 | |
363 | + g_strfreev(group); | |
364 | + | |
365 | + gtk_widget_set_sensitive(widget,TRUE); | |
366 | + } | |
367 | + | |
368 | + | |
369 | + g_key_file_free(conf); | |
370 | + | |
371 | + } | |
372 | + g_free(filename); | |
373 | + | |
157 | 374 | return widget; |
158 | 375 | } |
159 | 376 | |
... | ... | @@ -258,8 +475,12 @@ |
258 | 475 | |
259 | 476 | const gchar * title = g_object_get_data(G_OBJECT(action),"title"); |
260 | 477 | GtkWidget * dialog = gtk_dialog_new_with_buttons ( gettext(title ? title : N_( "Color setup") ), |
478 | +#if GTK_CHECK_VERSION(3,0,0) | |
479 | + NULL, | |
480 | +#else | |
261 | 481 | GTK_WINDOW(gtk_widget_get_toplevel(widget)), |
262 | - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
482 | +#endif // GTK(3,0,0) | |
483 | + GTK_DIALOG_DESTROY_WITH_PARENT, | |
263 | 484 | GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, |
264 | 485 | GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, |
265 | 486 | NULL ); |
... | ... | @@ -339,10 +560,13 @@ |
339 | 560 | GtkWidget * box = gtk_hbox_new(FALSE,2); |
340 | 561 | GtkWidget * button = color_scheme_new(NULL); |
341 | 562 | |
563 | + g_object_set_data(G_OBJECT(button),"terminal_widget",widget); | |
564 | + g_object_set_data(G_OBJECT(button),"color_selection_widget",color); | |
565 | + | |
342 | 566 | gtk_box_pack_start(GTK_BOX(box),gtk_label_new(_("Color scheme:")),FALSE,FALSE,2); |
343 | 567 | gtk_box_pack_start(GTK_BOX(box),button,TRUE,TRUE,2); |
344 | 568 | gtk_widget_show_all(box); |
345 | - gtk_box_pack_end(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),box,TRUE,TRUE,2); | |
569 | + gtk_box_pack_end(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),box,FALSE,FALSE,2); | |
346 | 570 | } |
347 | 571 | |
348 | 572 | // Run dialog | ... | ... |