Commit b8b2fc1900a4a04954cc270685b74685c8b24b36
1 parent
96c566b7
Exists in
master
and in
5 other branches
Implementando dialogo de configuracao de cores
Showing
3 changed files
with
76 additions
and
41 deletions
Show diff stats
src/gtk/colors.c
| ... | ... | @@ -137,14 +137,31 @@ |
| 137 | 137 | g_free(filename); |
| 138 | 138 | } |
| 139 | 139 | |
| 140 | - static void color_selected(GtkTreeSelection *selection, GtkWidget *widget) | |
| 140 | + static void color_changed(GtkColorSelection *colorselection, GtkWidget *widget) | |
| 141 | 141 | { |
| 142 | + GdkColor clr; | |
| 143 | + int id = (int) g_object_get_data(G_OBJECT(colorselection),"colorid"); | |
| 144 | + | |
| 145 | + if(id < 0 || id >= V3270_COLOR_COUNT) | |
| 146 | + return; | |
| 147 | + | |
| 148 | + gtk_color_selection_get_current_color(colorselection,&clr); | |
| 149 | + v3270_set_color(widget,id,&clr); | |
| 150 | + v3270_reload(widget); | |
| 151 | + gtk_widget_queue_draw(widget); | |
| 152 | + } | |
| 153 | + | |
| 154 | + static void color_selected(GtkTreeSelection *selection, GtkWidget *color) | |
| 155 | + { | |
| 156 | + GtkWidget * widget = g_object_get_data(G_OBJECT(selection),"v3270"); | |
| 157 | + GdkColor * saved = g_object_get_data(G_OBJECT(selection),"lastcolors"); | |
| 158 | + GValue value = { 0, }; | |
| 142 | 159 | GtkTreeModel * model; |
| 143 | 160 | GtkTreeIter iter; |
| 144 | - GValue value = { 0, }; | |
| 161 | + GdkColor * clr; | |
| 145 | 162 | int id; |
| 146 | 163 | |
| 147 | - gtk_widget_set_sensitive(widget,FALSE); | |
| 164 | + gtk_widget_set_sensitive(color,FALSE); | |
| 148 | 165 | |
| 149 | 166 | if(!gtk_tree_selection_get_selected(selection,&model,&iter)) |
| 150 | 167 | return; |
| ... | ... | @@ -156,8 +173,13 @@ |
| 156 | 173 | if(id < 0 || id >= V3270_COLOR_COUNT) |
| 157 | 174 | return; |
| 158 | 175 | |
| 176 | + g_object_set_data(G_OBJECT(color),"colorid",(gpointer) id); | |
| 177 | + clr = v3270_get_color(widget,id); | |
| 178 | + | |
| 179 | + gtk_color_selection_set_previous_color(GTK_COLOR_SELECTION(color),saved+id); | |
| 180 | + gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(color),clr); | |
| 159 | 181 | |
| 160 | - gtk_widget_set_sensitive(widget,TRUE); | |
| 182 | + gtk_widget_set_sensitive(color,TRUE); | |
| 161 | 183 | } |
| 162 | 184 | |
| 163 | 185 | void editcolors_action(GtkAction *action, GtkWidget *widget) |
| ... | ... | @@ -224,6 +246,7 @@ |
| 224 | 246 | GtkWidget * panned = gtk_hbox_new(FALSE,2); |
| 225 | 247 | GtkWidget * tree; |
| 226 | 248 | GtkWidget * color; |
| 249 | + GdkColor saved[V3270_COLOR_COUNT]; | |
| 227 | 250 | |
| 228 | 251 | { |
| 229 | 252 | // Color dialog setup |
| ... | ... | @@ -232,6 +255,8 @@ |
| 232 | 255 | gtk_color_selection_set_has_opacity_control(GTK_COLOR_SELECTION(color),FALSE); |
| 233 | 256 | gtk_color_selection_set_has_palette(GTK_COLOR_SELECTION(color),TRUE); |
| 234 | 257 | gtk_box_pack_end(GTK_BOX(panned),color,TRUE,TRUE,0); |
| 258 | + g_object_set_data(G_OBJECT(color),"colorid",(gpointer) -1); | |
| 259 | + g_signal_connect(G_OBJECT(color),"color-changed",G_CALLBACK(color_changed),widget); | |
| 235 | 260 | } |
| 236 | 261 | |
| 237 | 262 | // Tree view with all available colors |
| ... | ... | @@ -255,13 +280,18 @@ |
| 255 | 280 | gtk_tree_store_append((GtkTreeStore *) model,&parent,NULL); |
| 256 | 281 | gtk_tree_store_set((GtkTreeStore *) model, &parent, 0, gettext(node[title++].text), 1, V3270_COLOR_COUNT, -1); |
| 257 | 282 | |
| 258 | - | |
| 259 | 283 | select = gtk_tree_view_get_selection(GTK_TREE_VIEW (tree)); |
| 284 | + | |
| 285 | + g_object_set_data(G_OBJECT(select),"v3270",widget); | |
| 286 | + g_object_set_data(G_OBJECT(select),"lastcolors",saved); | |
| 287 | + | |
| 260 | 288 | gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE); |
| 261 | - g_signal_connect(G_OBJECT (select),"changed",G_CALLBACK(color_selected),color); | |
| 289 | + g_signal_connect(G_OBJECT(select),"changed",G_CALLBACK(color_selected),color); | |
| 262 | 290 | |
| 263 | 291 | for(f=0;f<V3270_COLOR_COUNT;f++) |
| 264 | 292 | { |
| 293 | + saved[f] = *(v3270_get_color(widget,f)); | |
| 294 | + | |
| 265 | 295 | if(f == node[title].id) |
| 266 | 296 | { |
| 267 | 297 | gtk_tree_store_append((GtkTreeStore *) model,&parent,NULL); |
| ... | ... | @@ -285,11 +315,25 @@ |
| 285 | 315 | gtk_widget_show_all(panned); |
| 286 | 316 | gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),GTK_WIDGET(panned),TRUE,TRUE,2); |
| 287 | 317 | |
| 288 | - gtk_dialog_run(GTK_DIALOG(dialog)); | |
| 318 | + if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) | |
| 319 | + { | |
| 320 | + // Acepted, save in configuration file | |
| 321 | + } | |
| 322 | + else | |
| 323 | + { | |
| 324 | + // Rejected, restore original colors | |
| 325 | + int f; | |
| 289 | 326 | |
| 327 | + for(f=0;f<V3270_COLOR_COUNT;f++) | |
| 328 | + v3270_set_color(widget,f,saved+f); | |
| 329 | + } | |
| 290 | 330 | |
| 291 | 331 | gtk_widget_destroy(dialog); |
| 292 | 332 | |
| 333 | + // Redraw widget | |
| 334 | + v3270_reload(widget); | |
| 335 | + gtk_widget_queue_draw(widget); | |
| 336 | + | |
| 293 | 337 | } |
| 294 | 338 | |
| 295 | 339 | ... | ... |
src/gtk/v3270/v3270.h
| ... | ... | @@ -217,10 +217,10 @@ |
| 217 | 217 | |
| 218 | 218 | // Colors |
| 219 | 219 | void v3270_set_colors(GtkWidget *widget, const gchar *); |
| 220 | - void v3270_set_color(GtkWidget *widget, enum V3270_COLOR id, const gchar *name); | |
| 221 | - int v3270_set_color_entry(GdkColor *clr, enum V3270_COLOR id, const gchar *name); | |
| 222 | 220 | void v3270_set_color_table(GdkColor *table, const gchar *colors); |
| 223 | 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_set_color(GtkWidget *widget, enum V3270_COLOR id, GdkColor *color); | |
| 223 | + GdkColor * v3270_get_color(GtkWidget *widget, enum V3270_COLOR id); | |
| 224 | 224 | |
| 225 | 225 | G_END_DECLS |
| 226 | 226 | ... | ... |
src/gtk/v3270/widget.c
| ... | ... | @@ -846,12 +846,28 @@ void v3270_set_colors(GtkWidget *widget, const gchar *colors) |
| 846 | 846 | } |
| 847 | 847 | |
| 848 | 848 | v3270_set_color_table(GTK_V3270(widget)->color,colors); |
| 849 | - | |
| 850 | 849 | g_signal_emit(widget,v3270_widget_signal[SIGNAL_UPDATE_CONFIG], 0, "colors", colors); |
| 851 | 850 | v3270_reload(widget); |
| 852 | 851 | |
| 853 | 852 | } |
| 854 | 853 | |
| 854 | +void v3270_set_color(GtkWidget *widget, enum V3270_COLOR id, GdkColor *color) | |
| 855 | +{ | |
| 856 | + g_return_if_fail(GTK_IS_V3270(widget)); | |
| 857 | + | |
| 858 | + GTK_V3270(widget)->color[id] = *color; | |
| 859 | + | |
| 860 | +#if !GTK_CHECK_VERSION(3,0,0) | |
| 861 | + gdk_colormap_alloc_color(gtk_widget_get_default_colormap(),color,TRUE,TRUE); | |
| 862 | +#endif // !GTK(3,0,0) | |
| 863 | + | |
| 864 | +} | |
| 865 | +GdkColor * v3270_get_color(GtkWidget *widget, enum V3270_COLOR id) | |
| 866 | +{ | |
| 867 | + g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | |
| 868 | + return GTK_V3270(widget)->color+id; | |
| 869 | +} | |
| 870 | + | |
| 855 | 871 | void v3270_set_color_table(GdkColor *table, const gchar *colors) |
| 856 | 872 | { |
| 857 | 873 | gchar **clr; |
| ... | ... | @@ -864,7 +880,7 @@ void v3270_set_color_table(GdkColor *table, const gchar *colors) |
| 864 | 880 | { |
| 865 | 881 | case V3270_COLOR_COUNT: // Complete string |
| 866 | 882 | for(f=0;f < V3270_COLOR_COUNT;f++) |
| 867 | - v3270_set_color_entry(table,f,clr[f]); | |
| 883 | + gdk_color_parse(clr[f],table+f); | |
| 868 | 884 | break; |
| 869 | 885 | |
| 870 | 886 | default: |
| ... | ... | @@ -872,12 +888,13 @@ void v3270_set_color_table(GdkColor *table, const gchar *colors) |
| 872 | 888 | g_warning("Color table has %d elements; should be %d.",cnt,V3270_COLOR_COUNT); |
| 873 | 889 | |
| 874 | 890 | for(f=0;f < cnt;f++) |
| 875 | - v3270_set_color_entry(table,f,clr[f]); | |
| 891 | + gdk_color_parse(clr[f],table+f); | |
| 892 | + | |
| 876 | 893 | for(f=cnt; f < V3270_COLOR_COUNT;f++) |
| 877 | - v3270_set_color_entry(table,f,clr[cnt-1]); | |
| 894 | + gdk_color_parse(clr[cnt-1],table+f); | |
| 878 | 895 | |
| 879 | - v3270_set_color_entry(table,V3270_COLOR_OIA_BACKGROUND,clr[0]); | |
| 880 | - v3270_set_color_entry(table,V3270_COLOR_SELECTED_BG,clr[0]); | |
| 896 | + clr[V3270_COLOR_OIA_BACKGROUND] = clr[0]; | |
| 897 | + clr[V3270_COLOR_SELECTED_BG] = clr[0]; | |
| 881 | 898 | |
| 882 | 899 | } |
| 883 | 900 | |
| ... | ... | @@ -885,32 +902,6 @@ void v3270_set_color_table(GdkColor *table, const gchar *colors) |
| 885 | 902 | |
| 886 | 903 | } |
| 887 | 904 | |
| 888 | -int v3270_set_color_entry(GdkColor *clr, enum V3270_COLOR id, const gchar *name) | |
| 889 | -{ | |
| 890 | - if(id >= V3270_COLOR_COUNT) | |
| 891 | - return -1; | |
| 892 | - | |
| 893 | - gdk_color_parse(name,clr+id); | |
| 894 | - | |
| 895 | - return 0; | |
| 896 | -} | |
| 897 | - | |
| 898 | -void v3270_set_color(GtkWidget *widget, enum V3270_COLOR id, const gchar *name) | |
| 899 | -{ | |
| 900 | - v3270 * terminal = GTK_V3270(widget); | |
| 901 | - | |
| 902 | - if(v3270_set_color_entry(terminal->color,id,name)) | |
| 903 | - return; | |
| 904 | - | |
| 905 | -#if(GTK_CHECK_VERSION(3,0,0)) | |
| 906 | - | |
| 907 | -#else | |
| 908 | - gdk_colormap_alloc_color(gtk_widget_get_default_colormap(),terminal->color+id,TRUE,TRUE); | |
| 909 | -#endif | |
| 910 | - | |
| 911 | - | |
| 912 | -} | |
| 913 | - | |
| 914 | 905 | void v3270_set_font_family(GtkWidget *widget, const gchar *name) |
| 915 | 906 | { |
| 916 | 907 | v3270 * terminal; | ... | ... |