diff --git a/src/gtk/colors.c b/src/gtk/colors.c new file mode 100644 index 0000000..b3cdd46 --- /dev/null +++ b/src/gtk/colors.c @@ -0,0 +1,133 @@ +/* + * "Software pw3270, desenvolvido com base nos códigos fontes do WC3270 e X3270 + * (Paul Mattes Paul.Mattes@usa.net), de emulação de terminal 3270 para acesso a + * aplicativos mainframe. Registro no INPI sob o nome G3270. + * + * Copyright (C) <2008> + * + * Este programa é software livre. Você pode redistribuí-lo e/ou modificá-lo sob + * os termos da GPL v.2 - Licença Pública Geral GNU, conforme publicado pela + * Free Software Foundation. + * + * Este programa é distribuído na expectativa de ser útil, mas SEM QUALQUER + * GARANTIA; sem mesmo a garantia implícita de COMERCIALIZAÇÃO ou de ADEQUAÇÃO + * A QUALQUER PROPÓSITO EM PARTICULAR. Consulte a Licença Pública Geral GNU para + * obter mais detalhes. + * + * Você deve ter recebido uma cópia da Licença Pública Geral GNU junto com este + * programa; se não, escreva para a Free Software Foundation, Inc., 59 Temple + * Place, Suite 330, Boston, MA, 02111-1307, USA + * + * Este programa está nomeado como colors.c e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + + #include + #include "globals.h" + +/*--[ Implement ]------------------------------------------------------------------------------------*/ + + void load_color_schemes(GtkWidget *widget, gchar **target) + { + gchar *filename = build_data_filename("colors.conf",NULL); + + if(!g_file_test(filename,G_FILE_TEST_IS_REGULAR)) + { + gtk_widget_set_sensitive(widget,FALSE); + g_warning("Unable to load color schemes in \"%s\"",filename); + } + else + { + gchar ** group; + GKeyFile * conf = g_key_file_new(); + int f; + gboolean found = FALSE; + +#if !GTK_CHECK_VERSION(3,0,0) + GtkTreeModel * model = (GtkTreeModel *) gtk_list_store_new(2,G_TYPE_STRING,G_TYPE_STRING); + GtkCellRenderer * renderer = gtk_cell_renderer_text_new(); + GtkTreeIter iter; + + gtk_combo_box_set_model(GTK_COMBO_BOX(widget),model); + + gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(widget), renderer, TRUE); + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(widget), renderer, "text", 0, NULL); + +#endif // !GTK(3,0,0) + + g_key_file_load_from_file(conf,filename,G_KEY_FILE_NONE,NULL); + + group = g_key_file_get_groups(conf,NULL); + + for(f=0;group[f];f++) + { + gchar *str = g_strjoin( ",", g_key_file_get_string(conf,group[f],"Terminal",NULL), + g_key_file_get_string(conf,group[f],"BaseAttributes",NULL), + g_key_file_get_string(conf,group[f],"SelectedText",NULL), + g_key_file_get_string(conf,group[f],"Cursor",NULL), + g_key_file_get_string(conf,group[f],"OIA",NULL), + NULL + ); +#if GTK_CHECK_VERSION(3,0,0) + + gtk_combo_box_text_insert( GTK_COMBO_BOX_TEXT(widget), + 0, + str, + g_key_file_get_locale_string(conf,group[f],"Label",NULL,NULL)); + +#else + + gtk_list_store_append((GtkListStore *) model,&iter); + gtk_list_store_set((GtkListStore *) model, &iter, + 0, g_key_file_get_locale_string(conf,group[f],"Label",NULL,NULL), + 1, str, + -1); + + if(*target && !g_strcasecmp(*target,str)) + { + found = TRUE; + gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget),&iter); + } + +#endif // GTK(3,0,0) + + g_free(str); + } + + g_strfreev(group); + g_key_file_free(conf); + + if(!found) + { +#if GTK_CHECK_VERSION(3,0,0) + + gtk_combo_box_text_insert( GTK_COMBO_BOX_TEXT(widget), + 0, + *target, + _( "Custom colors") ); + +#else + + gtk_list_store_append((GtkListStore *) model,&iter); + gtk_list_store_set((GtkListStore *) model, &iter, + 0, _( "Custom colors" ), + 1, *target, + -1); + + gtk_combo_box_set_active_iter(GTK_COMBO_BOX(widget),&iter); +#endif + } + + gtk_widget_set_sensitive(widget,TRUE); + + } + + g_free(filename); + } + + diff --git a/src/gtk/dialog.c b/src/gtk/dialog.c index f9893f0..b63caf9 100644 --- a/src/gtk/dialog.c +++ b/src/gtk/dialog.c @@ -84,6 +84,7 @@ } list[] = { // http://en.wikipedia.org/wiki/Character_encoding + { "UTF-8", N_( "UTF-8" ) }, { "ISO-8859-1", N_( "Western Europe (ISO 8859-1)" ) }, { "CP1252", N_( "Windows Western languages (CP1252)" ) }, diff --git a/src/gtk/globals.h b/src/gtk/globals.h index 9edf68b..303908f 100644 --- a/src/gtk/globals.h +++ b/src/gtk/globals.h @@ -55,6 +55,7 @@ GtkWidget * create_main_window(void); void setup_font_list(GtkWidget *widget, GtkWidget *obj); + void load_color_schemes(GtkWidget *widget, gchar **target); // actions void paste_file_action(GtkAction *action, GtkWidget *widget); diff --git a/src/gtk/print.c b/src/gtk/print.c index 4fea777..b4f6e54 100644 --- a/src/gtk/print.c +++ b/src/gtk/print.c @@ -39,6 +39,7 @@ GdkColor color[V3270_COLOR_COUNT]; H3270 * session; gchar * font; + gchar * colorname; int rows; int cols; int pages; @@ -91,6 +92,9 @@ if(info->font) g_free(info->font); + if(info->colorname) + g_free(info->colorname); + g_free(info); } @@ -128,7 +132,7 @@ // Font selection button widget = gtk_font_button_new(); #if GTK_CHECK_VERSION(3,2,0) - gtk_font_chooser_set_filter_func(widget,filter_monospaced,0); + gtk_font_chooser_set_filter_func((GtkFontChooser *) widget,filter_monospaced,NULL,NULL); #endif // GTK(3,2,0) gtk_table_attach(GTK_TABLE(container),widget,1,2,0,1,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0); @@ -137,6 +141,14 @@ g_signal_connect(G_OBJECT(widget),"font-set",G_CALLBACK(font_set),info); // Color scheme dropdown +#if GTK_CHECK_VERSION(3,0,0) + widget = gtk_combo_box_text_new(); +#else + widget = gtk_combo_box_new(); +#endif // GTK(3,0,0) + + load_color_schemes(widget,&info->colorname); + gtk_table_attach(GTK_TABLE(container),widget,1,2,1,2,GTK_EXPAND|GTK_FILL,GTK_FILL,5,0); // Show and return gtk_widget_show_all(container); diff --git a/src/include/lib3270.h b/src/include/lib3270.h index e96ca02..2b09dbe 100644 --- a/src/include/lib3270.h +++ b/src/include/lib3270.h @@ -647,8 +647,21 @@ */ LIB3270_EXPORT char * lib3270_get_text(H3270 *h); + /** + * Get a terminal character and attribute. + * + * @param h Session Handle. + * @param baddr Element address ((element_row*cols)+element_col) + * @param c Pointer to character. + * @param attr Pointer to attribute. + * + * @return 0 if ok or error code. + * + */ + LIB3270_EXPORT int lib3270_get_element(H3270 *h, int baddr, unsigned char *c, unsigned short *attr); + LIB3270_EXPORT int lib3270_set_model(H3270 *session, int model); - LIB3270_EXPORT int lib3270_get_model(H3270 *session); + LIB3270_EXPORT int lib3270_get_model(H3270 *session); #ifdef __cplusplus } diff --git a/src/lib3270/screen.c b/src/lib3270/screen.c index 5530784..7ad09b6 100644 --- a/src/lib3270/screen.c +++ b/src/lib3270/screen.c @@ -99,6 +99,19 @@ static void addch(H3270 *session, int baddr, unsigned char c, unsigned short att session->update(session,baddr,c,attr,baddr == session->cursor_addr); } +LIB3270_EXPORT int lib3270_get_element(H3270 *h, int baddr, unsigned char *c, unsigned short *attr) +{ + CHECK_SESSION_HANDLE(h); + + if(!h->text || baddr < 0 || baddr > (h->rows*h->cols)) + return EINVAL; + + *c = h->text[baddr].chr; + *attr = h->text[baddr].attr; + + return 0; +} + /** * Initialize the screen. * -- libgit2 0.21.2