Commit 69f76c9cfd587fd5765b027fe28cc4af161f920c
1 parent
b3d7d133
Exists in
master
and in
5 other branches
Implementando combo para selecao do esquema de cores
Showing
6 changed files
with
175 additions
and
2 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,133 @@ |
| 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 | + * Este programa está nomeado como colors.c 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 <gtk/gtk.h> | |
| 31 | + #include "globals.h" | |
| 32 | + | |
| 33 | +/*--[ Implement ]------------------------------------------------------------------------------------*/ | |
| 34 | + | |
| 35 | + void load_color_schemes(GtkWidget *widget, gchar **target) | |
| 36 | + { | |
| 37 | + gchar *filename = build_data_filename("colors.conf",NULL); | |
| 38 | + | |
| 39 | + if(!g_file_test(filename,G_FILE_TEST_IS_REGULAR)) | |
| 40 | + { | |
| 41 | + gtk_widget_set_sensitive(widget,FALSE); | |
| 42 | + g_warning("Unable to load color schemes in \"%s\"",filename); | |
| 43 | + } | |
| 44 | + else | |
| 45 | + { | |
| 46 | + gchar ** group; | |
| 47 | + GKeyFile * conf = g_key_file_new(); | |
| 48 | + int f; | |
| 49 | + gboolean found = FALSE; | |
| 50 | + | |
| 51 | +#if !GTK_CHECK_VERSION(3,0,0) | |
| 52 | + GtkTreeModel * model = (GtkTreeModel *) gtk_list_store_new(2,G_TYPE_STRING,G_TYPE_STRING); | |
| 53 | + GtkCellRenderer * renderer = gtk_cell_renderer_text_new(); | |
| 54 | + GtkTreeIter iter; | |
| 55 | + | |
| 56 | + gtk_combo_box_set_model(GTK_COMBO_BOX(widget),model); | |
| 57 | + | |
| 58 | + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), renderer, TRUE); | |
| 59 | + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget), renderer, "text", 0, NULL); | |
| 60 | + | |
| 61 | +#endif // !GTK(3,0,0) | |
| 62 | + | |
| 63 | + g_key_file_load_from_file(conf,filename,G_KEY_FILE_NONE,NULL); | |
| 64 | + | |
| 65 | + group = g_key_file_get_groups(conf,NULL); | |
| 66 | + | |
| 67 | + for(f=0;group[f];f++) | |
| 68 | + { | |
| 69 | + gchar *str = g_strjoin( ",", g_key_file_get_string(conf,group[f],"Terminal",NULL), | |
| 70 | + g_key_file_get_string(conf,group[f],"BaseAttributes",NULL), | |
| 71 | + g_key_file_get_string(conf,group[f],"SelectedText",NULL), | |
| 72 | + g_key_file_get_string(conf,group[f],"Cursor",NULL), | |
| 73 | + g_key_file_get_string(conf,group[f],"OIA",NULL), | |
| 74 | + NULL | |
| 75 | + ); | |
| 76 | +#if GTK_CHECK_VERSION(3,0,0) | |
| 77 | + | |
| 78 | + gtk_combo_box_text_insert( GTK_COMBO_BOX_TEXT(widget), | |
| 79 | + 0, | |
| 80 | + str, | |
| 81 | + g_key_file_get_locale_string(conf,group[f],"Label",NULL,NULL)); | |
| 82 | + | |
| 83 | +#else | |
| 84 | + | |
| 85 | + gtk_list_store_append((GtkListStore *) model,&iter); | |
| 86 | + gtk_list_store_set((GtkListStore *) model, &iter, | |
| 87 | + 0, g_key_file_get_locale_string(conf,group[f],"Label",NULL,NULL), | |
| 88 | + 1, str, | |
| 89 | + -1); | |
| 90 | + | |
| 91 | + if(*target && !g_strcasecmp(*target,str)) | |
| 92 | + { | |
| 93 | + found = TRUE; | |
| 94 | + gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget),&iter); | |
| 95 | + } | |
| 96 | + | |
| 97 | +#endif // GTK(3,0,0) | |
| 98 | + | |
| 99 | + g_free(str); | |
| 100 | + } | |
| 101 | + | |
| 102 | + g_strfreev(group); | |
| 103 | + g_key_file_free(conf); | |
| 104 | + | |
| 105 | + if(!found) | |
| 106 | + { | |
| 107 | +#if GTK_CHECK_VERSION(3,0,0) | |
| 108 | + | |
| 109 | + gtk_combo_box_text_insert( GTK_COMBO_BOX_TEXT(widget), | |
| 110 | + 0, | |
| 111 | + *target, | |
| 112 | + _( "Custom colors") ); | |
| 113 | + | |
| 114 | +#else | |
| 115 | + | |
| 116 | + gtk_list_store_append((GtkListStore *) model,&iter); | |
| 117 | + gtk_list_store_set((GtkListStore *) model, &iter, | |
| 118 | + 0, _( "Custom colors" ), | |
| 119 | + 1, *target, | |
| 120 | + -1); | |
| 121 | + | |
| 122 | + gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget),&iter); | |
| 123 | +#endif | |
| 124 | + } | |
| 125 | + | |
| 126 | + gtk_widget_set_sensitive(widget,TRUE); | |
| 127 | + | |
| 128 | + } | |
| 129 | + | |
| 130 | + g_free(filename); | |
| 131 | + } | |
| 132 | + | |
| 133 | + | ... | ... |
src/gtk/dialog.c
src/gtk/globals.h
| ... | ... | @@ -55,6 +55,7 @@ |
| 55 | 55 | |
| 56 | 56 | GtkWidget * create_main_window(void); |
| 57 | 57 | void setup_font_list(GtkWidget *widget, GtkWidget *obj); |
| 58 | + void load_color_schemes(GtkWidget *widget, gchar **target); | |
| 58 | 59 | |
| 59 | 60 | // actions |
| 60 | 61 | void paste_file_action(GtkAction *action, GtkWidget *widget); | ... | ... |
src/gtk/print.c
| ... | ... | @@ -39,6 +39,7 @@ |
| 39 | 39 | GdkColor color[V3270_COLOR_COUNT]; |
| 40 | 40 | H3270 * session; |
| 41 | 41 | gchar * font; |
| 42 | + gchar * colorname; | |
| 42 | 43 | int rows; |
| 43 | 44 | int cols; |
| 44 | 45 | int pages; |
| ... | ... | @@ -91,6 +92,9 @@ |
| 91 | 92 | if(info->font) |
| 92 | 93 | g_free(info->font); |
| 93 | 94 | |
| 95 | + if(info->colorname) | |
| 96 | + g_free(info->colorname); | |
| 97 | + | |
| 94 | 98 | g_free(info); |
| 95 | 99 | } |
| 96 | 100 | |
| ... | ... | @@ -128,7 +132,7 @@ |
| 128 | 132 | // Font selection button |
| 129 | 133 | widget = gtk_font_button_new(); |
| 130 | 134 | #if GTK_CHECK_VERSION(3,2,0) |
| 131 | - gtk_font_chooser_set_filter_func(widget,filter_monospaced,0); | |
| 135 | + gtk_font_chooser_set_filter_func((GtkFontChooser *) widget,filter_monospaced,NULL,NULL); | |
| 132 | 136 | #endif // GTK(3,2,0) |
| 133 | 137 | gtk_table_attach(GTK_TABLE(container),widget,1,2,0,1,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0); |
| 134 | 138 | |
| ... | ... | @@ -137,6 +141,14 @@ |
| 137 | 141 | g_signal_connect(G_OBJECT(widget),"font-set",G_CALLBACK(font_set),info); |
| 138 | 142 | |
| 139 | 143 | // Color scheme dropdown |
| 144 | +#if GTK_CHECK_VERSION(3,0,0) | |
| 145 | + widget = gtk_combo_box_text_new(); | |
| 146 | +#else | |
| 147 | + widget = gtk_combo_box_new(); | |
| 148 | +#endif // GTK(3,0,0) | |
| 149 | + | |
| 150 | + load_color_schemes(widget,&info->colorname); | |
| 151 | + gtk_table_attach(GTK_TABLE(container),widget,1,2,1,2,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0); | |
| 140 | 152 | |
| 141 | 153 | // Show and return |
| 142 | 154 | gtk_widget_show_all(container); | ... | ... |
src/include/lib3270.h
| ... | ... | @@ -647,8 +647,21 @@ |
| 647 | 647 | */ |
| 648 | 648 | LIB3270_EXPORT char * lib3270_get_text(H3270 *h); |
| 649 | 649 | |
| 650 | + /** | |
| 651 | + * Get a terminal character and attribute. | |
| 652 | + * | |
| 653 | + * @param h Session Handle. | |
| 654 | + * @param baddr Element address ((element_row*cols)+element_col) | |
| 655 | + * @param c Pointer to character. | |
| 656 | + * @param attr Pointer to attribute. | |
| 657 | + * | |
| 658 | + * @return 0 if ok or error code. | |
| 659 | + * | |
| 660 | + */ | |
| 661 | + LIB3270_EXPORT int lib3270_get_element(H3270 *h, int baddr, unsigned char *c, unsigned short *attr); | |
| 662 | + | |
| 650 | 663 | LIB3270_EXPORT int lib3270_set_model(H3270 *session, int model); |
| 651 | - LIB3270_EXPORT int lib3270_get_model(H3270 *session); | |
| 664 | + LIB3270_EXPORT int lib3270_get_model(H3270 *session); | |
| 652 | 665 | |
| 653 | 666 | #ifdef __cplusplus |
| 654 | 667 | } | ... | ... |
src/lib3270/screen.c
| ... | ... | @@ -99,6 +99,19 @@ static void addch(H3270 *session, int baddr, unsigned char c, unsigned short att |
| 99 | 99 | session->update(session,baddr,c,attr,baddr == session->cursor_addr); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | +LIB3270_EXPORT int lib3270_get_element(H3270 *h, int baddr, unsigned char *c, unsigned short *attr) | |
| 103 | +{ | |
| 104 | + CHECK_SESSION_HANDLE(h); | |
| 105 | + | |
| 106 | + if(!h->text || baddr < 0 || baddr > (h->rows*h->cols)) | |
| 107 | + return EINVAL; | |
| 108 | + | |
| 109 | + *c = h->text[baddr].chr; | |
| 110 | + *attr = h->text[baddr].attr; | |
| 111 | + | |
| 112 | + return 0; | |
| 113 | +} | |
| 114 | + | |
| 102 | 115 | /** |
| 103 | 116 | * Initialize the screen. |
| 104 | 117 | * | ... | ... |