Commit 0a3c790091447478c0e1d7fa953d23950a648107
1 parent
e9fcb006
Exists in
master
and in
5 other branches
Separando funcoes de configuração da tabela de cores para permitir o uso nas funções de impressão
Showing
3 changed files
with
104 additions
and
49 deletions
Show diff stats
src/gtk/print.c
@@ -115,38 +115,70 @@ | @@ -115,38 +115,70 @@ | ||
115 | trace("Font set to \"%s\"",info->font); | 115 | trace("Font set to \"%s\"",info->font); |
116 | } | 116 | } |
117 | 117 | ||
118 | + static void color_scheme_changed(GtkComboBox *widget,PRINT_INFO *info) | ||
119 | + { | ||
120 | + gchar *new_colors = NULL; | ||
121 | + | ||
122 | +#if GTK_CHECK_VERSION(3,0,0) | ||
123 | + | ||
124 | + new_colors = g_strdup(gtk_combo_box_get_active_id(GTK_COMBO_BOX(widget))); | ||
125 | + | ||
126 | +#else | ||
127 | + | ||
128 | + GValue value = { 0, }; | ||
129 | + GtkTreeIter iter; | ||
130 | + | ||
131 | + if(!gtk_combo_box_get_active_iter(widget,&iter)) | ||
132 | + return; | ||
133 | + | ||
134 | + gtk_tree_model_get_value(gtk_combo_box_get_model(widget),&iter,1,&value); | ||
135 | + new_colors = g_strdup(g_value_get_string(&value)); | ||
136 | + | ||
137 | +#endif | ||
138 | + | ||
139 | + if(!info->colorname) | ||
140 | + return; | ||
141 | + | ||
142 | + trace("%s: %s->%s",__FUNCTION__,info->colorname,new_colors); | ||
143 | + | ||
144 | + if(*info->colorname) | ||
145 | + g_free(info->colorname); | ||
146 | + | ||
147 | + info->colorname = new_colors; | ||
148 | + } | ||
149 | + | ||
118 | static GObject * create_custom_widget(GtkPrintOperation *prt, PRINT_INFO *info) | 150 | static GObject * create_custom_widget(GtkPrintOperation *prt, PRINT_INFO *info) |
119 | { | 151 | { |
120 | - static const gchar *def_colors = "white," | ||
121 | - "black," | ||
122 | - "black," | ||
123 | - "black," | ||
124 | - "black," | ||
125 | - "black," | ||
126 | - "black," | ||
127 | - "black," | ||
128 | - "black," | ||
129 | - "black," | ||
130 | - "black," | ||
131 | - "black," | ||
132 | - "black," | ||
133 | - "black," | ||
134 | - "black," | ||
135 | - "black," | ||
136 | - "black," | ||
137 | - "black," | ||
138 | - "black," | ||
139 | - "black," | ||
140 | - "black," | ||
141 | - "white," | ||
142 | - "black," | ||
143 | - "black," | ||
144 | - "black," | ||
145 | - "white," | ||
146 | - "black," | ||
147 | - "black," | ||
148 | - "black," | ||
149 | - "black"; | 152 | + static const gchar *def_colors = "white," // V3270_COLOR_BACKGROUND |
153 | + "black," // V3270_COLOR_BLUE | ||
154 | + "black," // V3270_COLOR_RED | ||
155 | + "black," // V3270_COLOR_PINK | ||
156 | + "black," // V3270_COLOR_GREEN | ||
157 | + "black," // V3270_COLOR_TURQUOISE | ||
158 | + "black," // V3270_COLOR_YELLOW | ||
159 | + "black," // V3270_COLOR_WHITE | ||
160 | + "black," // V3270_COLOR_BLACK | ||
161 | + "black," // V3270_COLOR_DARK_BLUE | ||
162 | + "black," // V3270_COLOR_ORANGE | ||
163 | + "black," // V3270_COLOR_PURPLE | ||
164 | + "black," // V3270_COLOR_DARK_GREEN | ||
165 | + "black," // V3270_COLOR_DARK_TURQUOISE | ||
166 | + "black," // V3270_COLOR_MUSTARD | ||
167 | + "black," // V3270_COLOR_GRAY | ||
168 | + "black," // V3270_COLOR_FIELD_DEFAULT | ||
169 | + "black," // V3270_COLOR_FIELD_INTENSIFIED | ||
170 | + "black," // V3270_COLOR_FIELD_PROTECTED | ||
171 | + "black," // V3270_COLOR_FIELD_PROTECTED_INTENSIFIED | ||
172 | + "black," // V3270_COLOR_SELECTED_BG | ||
173 | + "white," // V3270_COLOR_SELECTED_FG | ||
174 | + "black," // V3270_COLOR_SELECTED_BORDER | ||
175 | + "black," // V3270_COLOR_CURSOR | ||
176 | + "black," // V3270_COLOR_CROSS_HAIR | ||
177 | + "white," // V3270_COLOR_OIA_BACKGROUND | ||
178 | + "black," // V3270_COLOR_OIA | ||
179 | + "black," // V3270_COLOR_OIA_SEPARATOR | ||
180 | + "black," // V3270_COLOR_OIA_STATUS_OK | ||
181 | + "black"; // V3270_COLOR_OIA_STATUS_INVALID | ||
150 | 182 | ||
151 | static const gchar * label[] = { N_( "Font:" ), N_( "Color scheme:" ) }; | 183 | static const gchar * label[] = { N_( "Font:" ), N_( "Color scheme:" ) }; |
152 | GtkWidget * container = gtk_table_new(2,2,FALSE); | 184 | GtkWidget * container = gtk_table_new(2,2,FALSE); |
@@ -180,6 +212,9 @@ | @@ -180,6 +212,9 @@ | ||
180 | 212 | ||
181 | info->colorname = get_string_from_config("print","colors",def_colors); | 213 | info->colorname = get_string_from_config("print","colors",def_colors); |
182 | load_color_schemes(widget,info->colorname); | 214 | load_color_schemes(widget,info->colorname); |
215 | + | ||
216 | + g_signal_connect(G_OBJECT(widget),"changed",G_CALLBACK(color_scheme_changed),info); | ||
217 | + | ||
183 | gtk_table_attach(GTK_TABLE(container),widget,1,2,1,2,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0); | 218 | gtk_table_attach(GTK_TABLE(container),widget,1,2,1,2,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0); |
184 | 219 | ||
185 | // Show and return | 220 | // Show and return |
src/gtk/v3270/v3270.h
@@ -191,9 +191,6 @@ | @@ -191,9 +191,6 @@ | ||
191 | 191 | ||
192 | void v3270_reload(GtkWidget * widget); | 192 | void v3270_reload(GtkWidget * widget); |
193 | 193 | ||
194 | - void v3270_set_colors(GtkWidget *widget, const gchar *); | ||
195 | - void v3270_set_color(GtkWidget *widget, enum V3270_COLOR id, const gchar *name); | ||
196 | - | ||
197 | void v3270_set_font_family(GtkWidget *widget, const gchar *name); | 194 | void v3270_set_font_family(GtkWidget *widget, const gchar *name); |
198 | const gchar * v3270_get_font_family(GtkWidget *widget); | 195 | const gchar * v3270_get_font_family(GtkWidget *widget); |
199 | 196 | ||
@@ -212,6 +209,12 @@ | @@ -212,6 +209,12 @@ | ||
212 | void v3270_paste(GtkWidget *widget); | 209 | void v3270_paste(GtkWidget *widget); |
213 | void v3270_paste_string(GtkWidget *widget, const gchar *text, const gchar *encoding); | 210 | void v3270_paste_string(GtkWidget *widget, const gchar *text, const gchar *encoding); |
214 | 211 | ||
212 | + // Colors | ||
213 | + void v3270_set_colors(GtkWidget *widget, const gchar *); | ||
214 | + void v3270_set_color(GtkWidget *widget, enum V3270_COLOR id, const gchar *name); | ||
215 | + int v3270_set_color_entry(GdkColor *clr, enum V3270_COLOR id, const gchar *name); | ||
216 | + void v3270_set_color_table(GdkColor *table, const gchar *colors); | ||
217 | + | ||
215 | G_END_DECLS | 218 | G_END_DECLS |
216 | 219 | ||
217 | #endif // V3270_H_INCLUDED | 220 | #endif // V3270_H_INCLUDED |
src/gtk/v3270/widget.c
@@ -721,9 +721,7 @@ static void v3270_send_configure(v3270 * terminal) | @@ -721,9 +721,7 @@ static void v3270_send_configure(v3270 * terminal) | ||
721 | 721 | ||
722 | void v3270_set_colors(GtkWidget *widget, const gchar *colors) | 722 | void v3270_set_colors(GtkWidget *widget, const gchar *colors) |
723 | { | 723 | { |
724 | - gchar **clr; | ||
725 | - guint cnt; | ||
726 | - int f; | 724 | + g_return_if_fail(GTK_IS_V3270(widget)); |
727 | 725 | ||
728 | if(!colors) | 726 | if(!colors) |
729 | { | 727 | { |
@@ -764,6 +762,19 @@ void v3270_set_colors(GtkWidget *widget, const gchar *colors) | @@ -764,6 +762,19 @@ void v3270_set_colors(GtkWidget *widget, const gchar *colors) | ||
764 | 762 | ||
765 | } | 763 | } |
766 | 764 | ||
765 | + v3270_set_color_table(GTK_V3270(widget)->color,colors); | ||
766 | + | ||
767 | + g_signal_emit(widget,v3270_widget_signal[SIGNAL_UPDATE_CONFIG], 0, "colors", colors); | ||
768 | + v3270_reload(widget); | ||
769 | + | ||
770 | +} | ||
771 | + | ||
772 | +void v3270_set_color_table(GdkColor *table, const gchar *colors) | ||
773 | +{ | ||
774 | + gchar **clr; | ||
775 | + guint cnt; | ||
776 | + int f; | ||
777 | + | ||
767 | clr = g_strsplit(colors,",",V3270_COLOR_COUNT+1); | 778 | clr = g_strsplit(colors,",",V3270_COLOR_COUNT+1); |
768 | cnt = g_strv_length(clr); | 779 | cnt = g_strv_length(clr); |
769 | switch(cnt) | 780 | switch(cnt) |
@@ -774,53 +785,59 @@ void v3270_set_colors(GtkWidget *widget, const gchar *colors) | @@ -774,53 +785,59 @@ void v3270_set_colors(GtkWidget *widget, const gchar *colors) | ||
774 | 785 | ||
775 | case 29: | 786 | case 29: |
776 | for(f=0;f < V3270_COLOR_SELECTED_BORDER;f++) | 787 | for(f=0;f < V3270_COLOR_SELECTED_BORDER;f++) |
777 | - v3270_set_color(widget,f,clr[f]); | 788 | + v3270_set_color_entry(table,f,clr[f]); |
778 | 789 | ||
779 | - v3270_set_color(widget,V3270_COLOR_SELECTED_BORDER,clr[V3270_COLOR_SELECTED_BG]); | 790 | + v3270_set_color_entry(table,V3270_COLOR_SELECTED_BORDER,clr[V3270_COLOR_SELECTED_BG]); |
780 | 791 | ||
781 | for(f=V3270_COLOR_SELECTED_BORDER+1;f < V3270_COLOR_COUNT;f++) | 792 | for(f=V3270_COLOR_SELECTED_BORDER+1;f < V3270_COLOR_COUNT;f++) |
782 | - v3270_set_color(widget,f,clr[f-1]); | 793 | + v3270_set_color_entry(table,f,clr[f-1]); |
783 | 794 | ||
784 | break; | 795 | break; |
785 | 796 | ||
786 | case V3270_COLOR_COUNT: // Complete string | 797 | case V3270_COLOR_COUNT: // Complete string |
787 | for(f=0;f < V3270_COLOR_COUNT;f++) | 798 | for(f=0;f < V3270_COLOR_COUNT;f++) |
788 | - v3270_set_color(widget,f,clr[f]); | 799 | + v3270_set_color_entry(table,f,clr[f]); |
789 | break; | 800 | break; |
790 | 801 | ||
791 | default: | 802 | default: |
792 | for(f=0;f < cnt;f++) | 803 | for(f=0;f < cnt;f++) |
793 | - v3270_set_color(widget,f,clr[f]); | 804 | + v3270_set_color_entry(table,f,clr[f]); |
794 | for(f=cnt; f < V3270_COLOR_COUNT;f++) | 805 | for(f=cnt; f < V3270_COLOR_COUNT;f++) |
795 | - v3270_set_color(widget,f,clr[cnt-1]); | 806 | + v3270_set_color_entry(table,f,clr[cnt-1]); |
796 | 807 | ||
797 | - v3270_set_color(widget,V3270_COLOR_OIA_BACKGROUND,clr[0]); | ||
798 | - v3270_set_color(widget,V3270_COLOR_SELECTED_BG,clr[0]); | 808 | + v3270_set_color_entry(table,V3270_COLOR_OIA_BACKGROUND,clr[0]); |
809 | + v3270_set_color_entry(table,V3270_COLOR_SELECTED_BG,clr[0]); | ||
799 | 810 | ||
800 | } | 811 | } |
801 | 812 | ||
802 | g_strfreev(clr); | 813 | g_strfreev(clr); |
803 | 814 | ||
804 | - g_signal_emit(widget,v3270_widget_signal[SIGNAL_UPDATE_CONFIG], 0, "colors", colors); | 815 | +} |
805 | 816 | ||
806 | - v3270_reload(widget); | 817 | +int v3270_set_color_entry(GdkColor *clr, enum V3270_COLOR id, const gchar *name) |
818 | +{ | ||
819 | + if(id >= V3270_COLOR_COUNT) | ||
820 | + return -1; | ||
821 | + | ||
822 | + gdk_color_parse(name,clr+id); | ||
823 | + | ||
824 | + return 0; | ||
807 | } | 825 | } |
808 | 826 | ||
809 | void v3270_set_color(GtkWidget *widget, enum V3270_COLOR id, const gchar *name) | 827 | void v3270_set_color(GtkWidget *widget, enum V3270_COLOR id, const gchar *name) |
810 | { | 828 | { |
811 | v3270 * terminal = GTK_V3270(widget); | 829 | v3270 * terminal = GTK_V3270(widget); |
812 | 830 | ||
813 | - if(id >= V3270_COLOR_COUNT) | 831 | + if(v3270_set_color_entry(terminal->color,id,name)) |
814 | return; | 832 | return; |
815 | 833 | ||
816 | - gdk_color_parse(name,terminal->color+id); | ||
817 | - | ||
818 | #if(GTK_CHECK_VERSION(3,0,0)) | 834 | #if(GTK_CHECK_VERSION(3,0,0)) |
819 | 835 | ||
820 | #else | 836 | #else |
821 | gdk_colormap_alloc_color(gtk_widget_get_default_colormap(),terminal->color+id,TRUE,TRUE); | 837 | gdk_colormap_alloc_color(gtk_widget_get_default_colormap(),terminal->color+id,TRUE,TRUE); |
822 | #endif | 838 | #endif |
823 | 839 | ||
840 | + | ||
824 | } | 841 | } |
825 | 842 | ||
826 | void v3270_set_font_family(GtkWidget *widget, const gchar *name) | 843 | void v3270_set_font_family(GtkWidget *widget, const gchar *name) |