Commit fd9441462dea9b2687876c10dd718999aaf10100
1 parent
716a7aa6
Exists in
master
and in
1 other branch
Updating color selection dialog.
Showing
3 changed files
with
300 additions
and
3 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,246 @@ |
| 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., 51 Franklin | |
| 19 | + * St, Fifth Floor, Boston, MA 02110-1301 USA | |
| 20 | + * | |
| 21 | + * Este programa está nomeado como - e possui - linhas de código. | |
| 22 | + * | |
| 23 | + * Contatos: | |
| 24 | + * | |
| 25 | + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) | |
| 26 | + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) | |
| 27 | + * | |
| 28 | + */ | |
| 29 | + | |
| 30 | + #include "private.h" | |
| 31 | + #include <v3270/colorscheme.h> | |
| 32 | + #include <lib3270/log.h> | |
| 33 | + | |
| 34 | +/*--[ Widget definition ]----------------------------------------------------------------------------*/ | |
| 35 | + | |
| 36 | + struct _V3270ColorSelectionClass | |
| 37 | + { | |
| 38 | + GtkGridClass parent_class; | |
| 39 | + | |
| 40 | + }; | |
| 41 | + | |
| 42 | + struct _V3270ColorSelection | |
| 43 | + { | |
| 44 | + GtkGrid parent; | |
| 45 | + | |
| 46 | + GtkWidget * terminal; | |
| 47 | + | |
| 48 | + struct { | |
| 49 | + GtkWidget * view; | |
| 50 | + GtkTreeModel * list; | |
| 51 | +#if USE_GTK_COLOR_CHOOSER | |
| 52 | + GtkWidget * chooser; | |
| 53 | +#else | |
| 54 | + GtkWidget * editor; | |
| 55 | +#endif // USE_GTK_COLOR_CHOOSER | |
| 56 | + GtkWidget * scheme; | |
| 57 | + } colors; | |
| 58 | + | |
| 59 | + /// @brief Saved colors. | |
| 60 | + GdkRGBA saved[V3270_COLOR_COUNT]; | |
| 61 | + | |
| 62 | + }; | |
| 63 | + | |
| 64 | + G_DEFINE_TYPE(V3270ColorSelection, V3270ColorSelection, GTK_TYPE_GRID); | |
| 65 | + | |
| 66 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 67 | + | |
| 68 | + static void V3270ColorSelection_class_init(G_GNUC_UNUSED V3270ColorSelectionClass *klass) | |
| 69 | + { | |
| 70 | + | |
| 71 | + | |
| 72 | + } | |
| 73 | + | |
| 74 | +static void color_scheme_changed(GtkWidget G_GNUC_UNUSED(*dunno), const GdkRGBA *colors, V3270ColorSelection *widget) { | |
| 75 | + | |
| 76 | + debug("%s=%p",__FUNCTION__,colors); | |
| 77 | + | |
| 78 | + int f; | |
| 79 | + for(f=0;f<V3270_COLOR_COUNT;f++) | |
| 80 | + v3270_set_color(widget->terminal,f,colors+f); | |
| 81 | + | |
| 82 | + v3270_reload(widget->terminal); | |
| 83 | + gtk_widget_queue_draw(widget->terminal); | |
| 84 | + | |
| 85 | +} | |
| 86 | + | |
| 87 | + static void V3270ColorSelection_init(V3270ColorSelection *widget) | |
| 88 | + { | |
| 89 | + gtk_grid_set_row_spacing(GTK_GRID(widget),5); | |
| 90 | + gtk_grid_set_column_spacing(GTK_GRID(widget),5); | |
| 91 | + | |
| 92 | + { | |
| 93 | + // Create colors list view. | |
| 94 | + widget->colors.list = (GtkTreeModel *) gtk_tree_store_new(2,G_TYPE_STRING,G_TYPE_INT); | |
| 95 | + widget->colors.view = gtk_tree_view_new_with_model(widget->colors.list); | |
| 96 | + | |
| 97 | + gtk_widget_set_tooltip_markup(widget->colors.view,_("Terminal colors")); | |
| 98 | + | |
| 99 | + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(widget->colors.view),FALSE); | |
| 100 | + gtk_tree_view_insert_column_with_attributes( GTK_TREE_VIEW(widget->colors.view), | |
| 101 | + -1, | |
| 102 | + "color",gtk_cell_renderer_text_new(),"text", | |
| 103 | + 0, NULL ); | |
| 104 | + | |
| 105 | + // Setup selection mode. | |
| 106 | + GtkTreeSelection * select = gtk_tree_view_get_selection(GTK_TREE_VIEW(widget->colors.view)); | |
| 107 | + gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE); | |
| 108 | + // g_signal_connect(G_OBJECT(select),"changed",G_CALLBACK(color_selected),widget); | |
| 109 | + | |
| 110 | + // Put the view inside a scrolled window. | |
| 111 | + GtkWidget * box = gtk_scrolled_window_new(NULL,NULL); | |
| 112 | + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(box),GTK_POLICY_NEVER,GTK_POLICY_ALWAYS); | |
| 113 | + gtk_container_add(GTK_CONTAINER(box),widget->colors.view); | |
| 114 | + | |
| 115 | + gtk_widget_set_vexpand(box,TRUE); | |
| 116 | + gtk_widget_set_hexpand(box,TRUE); | |
| 117 | + | |
| 118 | + gtk_grid_attach(GTK_GRID(widget),box,0,0,1,5); | |
| 119 | + | |
| 120 | + } | |
| 121 | + | |
| 122 | +#ifdef USE_GTK_COLOR_CHOOSER | |
| 123 | + { | |
| 124 | + // Create color chooser widget | |
| 125 | + widget->colors.chooser = gtk_color_chooser_widget_new(); | |
| 126 | + // gtk_widget_set_sensitive(widget->colors.chooser,0); | |
| 127 | + // g_signal_connect(G_OBJECT(widget->colors.chooser),"color-activated",G_CALLBACK(color_activated),widget); | |
| 128 | + | |
| 129 | + gtk_grid_attach(GTK_GRID(widget),widget->colors.chooser,1,0,5,5); | |
| 130 | + } | |
| 131 | +#else | |
| 132 | + { | |
| 133 | + widget->colors.editor = gtk_color_selection_new(); | |
| 134 | + gtk_widget_set_sensitive(widget->colors.editor,0); | |
| 135 | + gtk_color_selection_set_has_opacity_control(GTK_COLOR_SELECTION(widget->colors.editor),FALSE); | |
| 136 | + gtk_color_selection_set_has_palette(GTK_COLOR_SELECTION(widget->colors.editor),TRUE); | |
| 137 | + // g_signal_connect(G_OBJECT(widget->colors.editor),"color-changed",G_CALLBACK(color_changed),widget); | |
| 138 | + | |
| 139 | + gtk_grid_attach(GTK_GRID(widget),widget->colors.editor,1,0,5,5); | |
| 140 | + } | |
| 141 | +#endif // USE_GTK_COLOR_CHOOSER | |
| 142 | + | |
| 143 | + { | |
| 144 | + // Create scheme selector | |
| 145 | + widget->colors.scheme = v3270_color_scheme_new(); | |
| 146 | + gtk_widget_set_tooltip_markup(widget->colors.scheme,_("Predefined color schemes")); | |
| 147 | + gtk_grid_attach(GTK_GRID(widget),widget->colors.scheme,0,6,6,1); | |
| 148 | + | |
| 149 | + g_signal_connect(G_OBJECT(widget->colors.scheme),"update-colors",G_CALLBACK(color_scheme_changed),widget); | |
| 150 | + | |
| 151 | + } | |
| 152 | + | |
| 153 | + | |
| 154 | + } | |
| 155 | + | |
| 156 | + LIB3270_EXPORT GtkWidget * v3270_color_selection_new(GtkWidget *terminal) | |
| 157 | + { | |
| 158 | + g_return_val_if_fail(GTK_IS_V3270(terminal),NULL); | |
| 159 | + | |
| 160 | + V3270ColorSelection * widget = GTK_V3270_COLOR_SELECTION(g_object_new(GTK_TYPE_V3270_COLOR_SELECTION, NULL)); | |
| 161 | + | |
| 162 | + widget->terminal = terminal; | |
| 163 | + | |
| 164 | + // Load colors | |
| 165 | + { | |
| 166 | + static const struct _node | |
| 167 | + { | |
| 168 | + int id; | |
| 169 | + const char *text; | |
| 170 | + } node[] = | |
| 171 | + { | |
| 172 | + { V3270_COLOR_BACKGROUND, N_( "Terminal colors" ) }, | |
| 173 | + { V3270_COLOR_FIELD, N_( "Field colors" ) }, | |
| 174 | + { V3270_COLOR_SELECTED_BG, N_( "Misc colors" ) }, | |
| 175 | + }; | |
| 176 | + | |
| 177 | + static const gchar *color_name[V3270_COLOR_COUNT] = | |
| 178 | + { | |
| 179 | + N_( "Background" ), // V3270_COLOR_BACKGROUND | |
| 180 | + N_( "Blue" ), // V3270_COLOR_BLUE | |
| 181 | + N_( "Red" ), // V3270_COLOR_RED | |
| 182 | + N_( "Pink" ), // V3270_COLOR_PINK | |
| 183 | + N_( "Green" ), // V3270_COLOR_GREEN | |
| 184 | + N_( "Turquoise" ), // V3270_COLOR_TURQUOISE | |
| 185 | + N_( "Yellow" ), // V3270_COLOR_YELLOW | |
| 186 | + N_( "White" ), // V3270_COLOR_WHITE | |
| 187 | + N_( "Black" ), // V3270_COLOR_BLACK | |
| 188 | + N_( "Dark Blue" ), // V3270_COLOR_DARK_BLUE | |
| 189 | + N_( "Orange" ), // V3270_COLOR_ORANGE | |
| 190 | + N_( "Purple" ), // V3270_COLOR_PURPLE | |
| 191 | + N_( "Dark Green" ), // V3270_COLOR_DARK_GREEN | |
| 192 | + N_( "Dark Turquoise" ), // V3270_COLOR_DARK_TURQUOISE | |
| 193 | + N_( "Mustard" ), // V3270_COLOR_MUSTARD | |
| 194 | + N_( "Gray" ), // V3270_COLOR_GRAY | |
| 195 | + | |
| 196 | + N_( "Normal/Unprotected" ), // V3270_COLOR_FIELD | |
| 197 | + N_( "Intensified/Unprotected" ), // V3270_COLOR_FIELD_INTENSIFIED | |
| 198 | + N_( "Normal/Protected" ), // V3270_COLOR_FIELD_PROTECTED | |
| 199 | + N_( "Intensified/Protected" ), // V3270_COLOR_FIELD_PROTECTED_INTENSIFIED | |
| 200 | + | |
| 201 | + N_( "Selection background" ), // TERMINAL_COLOR_SELECTED_BG | |
| 202 | + N_( "Selection foreground" ), // TERMINAL_COLOR_SELECTED_FG | |
| 203 | + | |
| 204 | + N_( "Cross hair cursor" ), // TERMINAL_COLOR_CROSS_HAIR | |
| 205 | + | |
| 206 | + // Oia Colors | |
| 207 | + N_( "OIA background" ), // TERMINAL_COLOR_OIA_BACKGROUND | |
| 208 | + N_( "OIA foreground" ), // TERMINAL_COLOR_OIA_FOREGROUND | |
| 209 | + N_( "OIA separator" ), // TERMINAL_COLOR_OIA_SEPARATOR | |
| 210 | + N_( "OIA status ok" ), // TERMINAL_COLOR_OIA_STATUS_OK | |
| 211 | + N_( "OIA Warning" ), // V3270_COLOR_OIA_STATUS_WARNING | |
| 212 | + N_( "OIA status invalid" ), // TERMINAL_COLOR_OIA_STATUS_INVALID | |
| 213 | + | |
| 214 | + }; | |
| 215 | + | |
| 216 | + GtkTreeIter iter; | |
| 217 | + GtkTreeIter parent; | |
| 218 | + int title = 0; | |
| 219 | + int f; | |
| 220 | + | |
| 221 | + gtk_tree_store_append(GTK_TREE_STORE(widget->colors.list),&parent,NULL); | |
| 222 | + gtk_tree_store_set(GTK_TREE_STORE(widget->colors.list), &parent, 0, gettext(node[title++].text), 1, V3270_COLOR_COUNT, -1); | |
| 223 | + | |
| 224 | + for(f=0;f<V3270_COLOR_COUNT;f++) | |
| 225 | + { | |
| 226 | + widget->saved[f] = *(v3270_get_color(terminal,f)); | |
| 227 | + | |
| 228 | + if(f == node[title].id) | |
| 229 | + { | |
| 230 | + gtk_tree_store_append(GTK_TREE_STORE(widget->colors.list),&parent,NULL); | |
| 231 | + gtk_tree_store_set(GTK_TREE_STORE(widget->colors.list), &parent, 0, gettext(node[title++].text), 1, V3270_COLOR_COUNT, -1); | |
| 232 | + } | |
| 233 | + gtk_tree_store_append(GTK_TREE_STORE(widget->colors.list),&iter,&parent); | |
| 234 | + gtk_tree_store_set(GTK_TREE_STORE(widget->colors.list), &iter, 0, gettext(color_name[f]), 1, f, -1); | |
| 235 | + } | |
| 236 | + | |
| 237 | + gtk_tree_view_expand_all(GTK_TREE_VIEW(widget->colors.view)); | |
| 238 | + | |
| 239 | + } | |
| 240 | + | |
| 241 | + v3270_color_scheme_set_rgba(widget->colors.scheme,v3270_get_color_table(terminal)); | |
| 242 | + | |
| 243 | + gtk_widget_show_all(GTK_WIDGET(widget)); | |
| 244 | + return GTK_WIDGET(widget); | |
| 245 | + } | |
| 246 | + | ... | ... |
src/include/v3270/colorscheme.h
| ... | ... | @@ -33,7 +33,7 @@ |
| 33 | 33 | |
| 34 | 34 | G_BEGIN_DECLS |
| 35 | 35 | |
| 36 | -/*--[ Progress widget ]------------------------------------------------------------------------------*/ | |
| 36 | +/*--[ Color Scheme Widget ]--------------------------------------------------------------------------*/ | |
| 37 | 37 | |
| 38 | 38 | #define GTK_TYPE_V3270_COLOR_SCHEME (V3270ColorScheme_get_type()) |
| 39 | 39 | #define GTK_V3270_COLOR_SCHEME(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_V3270_COLOR_SCHEME, V3270ColorScheme)) |
| ... | ... | @@ -45,6 +45,18 @@ |
| 45 | 45 | typedef struct _V3270ColorScheme V3270ColorScheme; |
| 46 | 46 | typedef struct _V3270ColorSchemeClass V3270ColorSchemeClass; |
| 47 | 47 | |
| 48 | +/*--[ Color Selection Widget ]-----------------------------------------------------------------------*/ | |
| 49 | + | |
| 50 | + #define GTK_TYPE_V3270_COLOR_SELECTION (V3270ColorSelection_get_type()) | |
| 51 | + #define GTK_V3270_COLOR_SELECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_V3270_COLOR_SELECTION, V3270ColorSelection)) | |
| 52 | + #define GTK_V3270_COLOR_SELECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_V3270_COLOR_SELECTION, V3270ColorSelectionClass)) | |
| 53 | + #define GTK_IS_V3270_COLOR_SELECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_V3270_COLOR_SELECTION)) | |
| 54 | + #define GTK_IS_V3270_COLOR_SELECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_V3270_COLOR_SELECTION)) | |
| 55 | + #define GTK_V3270_COLOR_SELECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_V3270_COLOR_SELECTION, V3270ColorSelectionClass)) | |
| 56 | + | |
| 57 | + typedef struct _V3270ColorSelection V3270ColorSelection; | |
| 58 | + typedef struct _V3270ColorSelectionClass V3270ColorSelectionClass; | |
| 59 | + | |
| 48 | 60 | /*--[ Prototipes ]-----------------------------------------------------------------------------------*/ |
| 49 | 61 | |
| 50 | 62 | LIB3270_EXPORT GtkWidget * v3270_color_scheme_new(); |
| ... | ... | @@ -52,6 +64,8 @@ |
| 52 | 64 | LIB3270_EXPORT gchar * v3270_color_scheme_get_text(GtkWidget *widget); |
| 53 | 65 | LIB3270_EXPORT void v3270_color_scheme_set_text(GtkWidget *widget, const gchar *colors); |
| 54 | 66 | |
| 67 | + LIB3270_EXPORT GtkWidget * v3270_color_selection_new(GtkWidget *widget); | |
| 68 | + | |
| 55 | 69 | G_END_DECLS |
| 56 | 70 | |
| 57 | 71 | #endif // V3270_COLOR_SCHEME_H_INCLUDED | ... | ... |
src/testprogram/testprogram.c
| ... | ... | @@ -110,6 +110,7 @@ static void trace_window_destroy(G_GNUC_UNUSED GtkWidget *widget, H3270 *hSessio |
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | |
| 113 | +/* | |
| 113 | 114 | static void color_scheme_changed(GtkWidget G_GNUC_UNUSED(*widget), const GdkRGBA *colors, GtkWidget *terminal) { |
| 114 | 115 | |
| 115 | 116 | debug("%s=%p",__FUNCTION__,colors); |
| ... | ... | @@ -122,6 +123,7 @@ static void color_scheme_changed(GtkWidget G_GNUC_UNUSED(*widget), const GdkRGBA |
| 122 | 123 | gtk_widget_queue_draw(terminal); |
| 123 | 124 | |
| 124 | 125 | } |
| 126 | +*/ | |
| 125 | 127 | |
| 126 | 128 | static void print_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal) |
| 127 | 129 | { |
| ... | ... | @@ -133,6 +135,38 @@ static void host_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal) |
| 133 | 135 | v3270_select_host(terminal); |
| 134 | 136 | } |
| 135 | 137 | |
| 138 | +static void color_clicked(GtkButton G_GNUC_UNUSED(*button), GtkWidget *terminal) | |
| 139 | +{ | |
| 140 | + GtkWidget * dialog = gtk_dialog_new_with_buttons ( | |
| 141 | + _( "Color Setup" ), | |
| 142 | + NULL, // GTK_WINDOW(gtk_widget_get_toplevel(terminal)), | |
| 143 | + GTK_DIALOG_DESTROY_WITH_PARENT, | |
| 144 | + _( "Cancel" ), GTK_RESPONSE_REJECT, | |
| 145 | + _( "Save" ), GTK_RESPONSE_ACCEPT, | |
| 146 | + NULL ); | |
| 147 | + | |
| 148 | + | |
| 149 | + GtkWidget * colors = v3270_color_selection_new(terminal); | |
| 150 | + | |
| 151 | + gtk_container_set_border_width(GTK_CONTAINER(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),10); | |
| 152 | + | |
| 153 | + gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),colors,TRUE,TRUE,2); | |
| 154 | + | |
| 155 | + gtk_widget_show_all(dialog); | |
| 156 | + | |
| 157 | + if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) | |
| 158 | + { | |
| 159 | + g_message("Accepted"); | |
| 160 | + } | |
| 161 | + else | |
| 162 | + { | |
| 163 | + g_message("Cancel"); | |
| 164 | + } | |
| 165 | + | |
| 166 | + gtk_widget_destroy(dialog); | |
| 167 | + | |
| 168 | + | |
| 169 | +} | |
| 136 | 170 | |
| 137 | 171 | static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { |
| 138 | 172 | |
| ... | ... | @@ -192,7 +226,7 @@ static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { |
| 192 | 226 | // Create box |
| 193 | 227 | GtkWidget *box = gtk_box_new(GTK_ORIENTATION_VERTICAL,2); |
| 194 | 228 | GtkWidget *grid = gtk_grid_new(); |
| 195 | - GtkWidget *color = v3270_color_scheme_new(); | |
| 229 | + GtkWidget *color = gtk_button_new_with_label("Colors"); | |
| 196 | 230 | GtkWidget *print = gtk_button_new_with_label("Print"); |
| 197 | 231 | GtkWidget *host = gtk_button_new_with_label("Host"); |
| 198 | 232 | |
| ... | ... | @@ -202,10 +236,13 @@ static void activate(GtkApplication* app, G_GNUC_UNUSED gpointer user_data) { |
| 202 | 236 | gtk_widget_set_focus_on_click(host,FALSE); |
| 203 | 237 | g_signal_connect(G_OBJECT(host),"clicked",G_CALLBACK(host_clicked),terminal); |
| 204 | 238 | |
| 205 | - gtk_widget_set_can_focus(color,FALSE); | |
| 206 | 239 | gtk_widget_set_focus_on_click(color,FALSE); |
| 240 | + g_signal_connect(G_OBJECT(color),"clicked",G_CALLBACK(color_clicked),terminal); | |
| 241 | + | |
| 242 | + /* | |
| 207 | 243 | v3270_color_scheme_set_rgba(color,v3270_get_color_table(terminal)); |
| 208 | 244 | g_signal_connect(G_OBJECT(color),"update-colors",G_CALLBACK(color_scheme_changed),terminal); |
| 245 | + */ | |
| 209 | 246 | |
| 210 | 247 | gtk_grid_attach(GTK_GRID(grid),color,0,0,1,1); |
| 211 | 248 | gtk_grid_attach(GTK_GRID(grid),print,1,0,1,1); | ... | ... |