diff --git a/src/include/terminal.h b/src/include/terminal.h index c2594ea..d6b4534 100644 --- a/src/include/terminal.h +++ b/src/include/terminal.h @@ -29,6 +29,7 @@ #include #include +#include G_BEGIN_DECLS @@ -166,6 +167,7 @@ G_BEGIN_DECLS V3270_COPY_MODE format; ///< @brief Copy mode. GList * blocks; ///< @brief Selection blocks. V3270SelectionOption options; ///< @brief Selection options. + gchar * font_family; ///< @brief Font family for HTML paste. } selection; diff --git a/src/include/v3270.h b/src/include/v3270.h index 8a267da..53337c5 100644 --- a/src/include/v3270.h +++ b/src/include/v3270.h @@ -201,45 +201,6 @@ LIB3270_EXPORT void v3270_set_lunames(GtkWidget *widget, const gchar *lunames); LIB3270_EXPORT gchar * v3270_get_lunames(GtkWidget *widget); - // Clipboard - typedef enum _v3270_copy_mode - { - - V3270_COPY_DEFAULT, ///< @brief Detect format based on lib3270's smart past toggle. - V3270_COPY_FORMATTED, ///< @brief Copy formatted data; keep attributes. - V3270_COPY_TEXT, ///< @brief Single text format, ignore attributes. - V3270_COPY_TABLE, ///< @brief Copy as table. - V3270_COPY_APPEND ///< @brief Append to current contents keeping the stored format. - - } V3270_COPY_MODE; - - LIB3270_EXPORT void v3270_clipboard_set(GtkWidget *widget, V3270_COPY_MODE mode, gboolean cut); - LIB3270_EXPORT void v3270_clipboard_get_from_url(GtkWidget *widget, const gchar *url); - - /// @brief Check if the widget has saved text. - LIB3270_EXPORT gboolean v3270_has_copy(GtkWidget *widget); - - LIB3270_EXPORT void v3270_paste(GtkWidget *widget) G_GNUC_DEPRECATED; - LIB3270_EXPORT void v3270_paste_text(GtkWidget *widget) G_GNUC_DEPRECATED; - LIB3270_EXPORT void v3270_paste_from_file(GtkWidget *widget) G_GNUC_DEPRECATED; - LIB3270_EXPORT void v3270_copy_selection(GtkWidget *widget, V3270_COPY_MODE mode, gboolean cut) G_GNUC_DEPRECATED; - LIB3270_EXPORT void v3270_append_selection(GtkWidget *widget, gboolean cut) G_GNUC_DEPRECATED; - - // Selections - - LIB3270_EXPORT gchar * v3270_get_selected(GtkWidget *widget, gboolean cut); - LIB3270_EXPORT gchar * v3270_get_copy(GtkWidget *widget); - - LIB3270_EXPORT gchar * v3270_get_text(GtkWidget *widget,int offset, int len); - LIB3270_EXPORT gchar * v3270_get_region(GtkWidget *widget, gint start_pos, gint end_pos, gboolean all); - - LIB3270_EXPORT void v3270_set_string(GtkWidget *widget, const gchar *str); - - LIB3270_EXPORT gboolean v3270_get_selection_bounds(GtkWidget *widget, gint *start, gint *end); - LIB3270_EXPORT void v3270_unselect(GtkWidget *widget); - LIB3270_EXPORT void v3270_select_all(GtkWidget *widget); - LIB3270_EXPORT void v3270_select_region(GtkWidget *widget, gint start, gint end); - LIB3270_EXPORT void v3270_input_text(GtkWidget *widget, const gchar *text, const gchar *encoding); // Colors diff --git a/src/include/v3270/selection.h b/src/include/v3270/selection.h new file mode 100644 index 0000000..4c22b64 --- /dev/null +++ b/src/include/v3270/selection.h @@ -0,0 +1,82 @@ +/* + * "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., 51 Franklin + * St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Este programa está nomeado como - e possui - linhas de código. + * + * Contatos: + * + * perry.werneck@gmail.com (Alexandre Perry de Souza Werneck) + * erico.mendonca@gmail.com (Erico Mascarenhas Mendonça) + * + */ + +#ifndef V3270_SELECTION_H_INCLUDED + + #define V3270_SELECTION_H_INCLUDED 1 + + #include + + G_BEGIN_DECLS + + // Clipboard + typedef enum _v3270_copy_mode + { + + V3270_COPY_DEFAULT, ///< @brief Detect format based on lib3270's smart past toggle. + V3270_COPY_FORMATTED, ///< @brief Copy formatted data; keep attributes. + V3270_COPY_TEXT, ///< @brief Single text format, ignore attributes. + V3270_COPY_TABLE, ///< @brief Copy as table. + V3270_COPY_APPEND ///< @brief Append to current contents keeping the stored format. + + } V3270_COPY_MODE; + + void v3270_clipboard_set(GtkWidget *widget, V3270_COPY_MODE mode, gboolean cut); + void v3270_clipboard_get_from_url(GtkWidget *widget, const gchar *url); + + /// @brief Check if the widget has saved text. + gboolean v3270_has_copy(GtkWidget *widget); + + void v3270_paste(GtkWidget *widget) G_GNUC_DEPRECATED; + void v3270_paste_text(GtkWidget *widget) G_GNUC_DEPRECATED; + void v3270_paste_from_file(GtkWidget *widget) G_GNUC_DEPRECATED; + void v3270_copy_selection(GtkWidget *widget, V3270_COPY_MODE mode, gboolean cut) G_GNUC_DEPRECATED; + void v3270_append_selection(GtkWidget *widget, gboolean cut) G_GNUC_DEPRECATED; + + // Selections + + gchar * v3270_get_selected(GtkWidget *widget, gboolean cut); + gchar * v3270_get_copy(GtkWidget *widget); + + gchar * v3270_get_text(GtkWidget *widget,int offset, int len); + gchar * v3270_get_region(GtkWidget *widget, gint start_pos, gint end_pos, gboolean all); + + void v3270_set_string(GtkWidget *widget, const gchar *str); + + gboolean v3270_get_selection_bounds(GtkWidget *widget, gint *start, gint *end); + void v3270_unselect(GtkWidget *widget); + void v3270_select_all(GtkWidget *widget); + void v3270_select_region(GtkWidget *widget, gint start, gint end); + + void v3270_selection_set_font_family(GtkWidget *widget, const gchar *name); + const gchar * v3270_selection_get_font_family(GtkWidget *widget); + + G_END_DECLS + +#endif // V3270_ACTIONS_H_INCLUDED diff --git a/src/selection/html.c b/src/selection/html.c index 836800d..d5b1eda 100644 --- a/src/selection/html.c +++ b/src/selection/html.c @@ -49,8 +49,8 @@ static void get_element_colors(v3270 * terminal, unsigned short attr, gchar **fg } /// @brief Get formatted contents as HTML DIV. -static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all, const V3270SelectionOption options) -{ +static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all, const V3270SelectionOption options) { + const GList * element = selection; GString * string = g_string_new(""); gchar * bgColor; @@ -58,13 +58,11 @@ static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all g_string_append(string,"
font.family); + if(options & V3270_SELECTION_FONT_FAMILY) { + g_string_append_printf(string,";font-family:%s,monospace",(terminal->selection.font_family ? terminal->selection.font_family : terminal->font.family)); } - if(options & V3270_SELECTION_COLORS) - { + if(options & V3270_SELECTION_COLORS) { bgColor = gdk_rgba_to_string(terminal->color+V3270_COLOR_BACKGROUND); g_string_append_printf(string,";background-color:%s",bgColor); g_free(bgColor); @@ -72,14 +70,13 @@ static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all g_string_append(string,"\">"); - while(element) - { + while(element) { const lib3270_selection * block = ((const lib3270_selection *) element->data); unsigned int row, col, src = 0; unsigned short flags = block->contents[0].attribute.visual; - if(options & V3270_SELECTION_COLORS) - { + if(options & V3270_SELECTION_COLORS) { + get_element_colors(terminal,flags,&fgColor,&bgColor); g_string_append_printf( @@ -97,16 +94,16 @@ static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all g_string_append_c(string,'\n'); #endif // DEBUG - for(row=0; row < block->bounds.height; row++) - { - for(col=0; colbounds.width; col++) - { - if(flags != block->contents[src].attribute.visual) - { + for(row=0; row < block->bounds.height; row++) { + + for(col=0; colbounds.width; col++) { + + if(flags != block->contents[src].attribute.visual) { + flags = block->contents[src].attribute.visual; - if(options & V3270_SELECTION_COLORS) - { + if(options & V3270_SELECTION_COLORS) { + get_element_colors(terminal,flags,&fgColor,&bgColor); g_string_append_printf( @@ -122,13 +119,14 @@ static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all } - if( (block->contents[src].attribute.visual & LIB3270_ATTR_SELECTED || all) && !isspace(block->contents[src].chr)) - { + if( (block->contents[src].attribute.visual & LIB3270_ATTR_SELECTED || all) && !isspace(block->contents[src].chr)) { + g_string_append_c(string,block->contents[src].chr); - } - else - { + + } else { + g_string_append(string,((options & V3270_SELECTION_NON_BREAKABLE_SPACE) ? " " : " ")); + } src++; @@ -140,9 +138,10 @@ static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all #endif // DEBUG } - if(options & V3270_SELECTION_COLORS) - { + if(options & V3270_SELECTION_COLORS) { + g_string_append(string,""); + } element = g_list_next(element); @@ -162,13 +161,21 @@ static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all static gchar * get_as_table(v3270 * terminal, const GList *selection, gboolean all, const V3270SelectionOption G_GNUC_UNUSED(options)) // TODO: Use options to set colors & font. { const GList * element = selection; - GString * string = g_string_new(""); + GString * string = g_string_new(""); unsigned int width = lib3270_get_width(terminal->host); g_autofree gchar * line = g_malloc0(width+1); GList * column; + g_string_append(string,"selection.font_family ? terminal->selection.font_family : terminal->font.family)); + } + + g_string_append(string,">"); + // Get contents GList * columns = v3270_getColumns_from_selection(terminal, selection, all); diff --git a/src/selection/selection.c b/src/selection/selection.c index 698592e..1cc4113 100644 --- a/src/selection/selection.c +++ b/src/selection/selection.c @@ -132,4 +132,28 @@ LIB3270_EXPORT void v3270_select_all(GtkWidget *widget) v3270_enable_updates(widget); } +void v3270_selection_set_font_family(GtkWidget *widget, const gchar *name) { + + g_return_if_fail(GTK_IS_V3270(widget)); + + v3270 * terminal = GTK_V3270(widget); + + if(terminal->selection.font_family) { + g_free(terminal->selection.font_family); + terminal->selection.font_family = NULL; + } + + if(name) { + terminal->selection.font_family = g_strdup(name); + } + + v3270_emit_save_settings(widget); + +} + +const gchar * v3270_selection_get_font_family(GtkWidget *widget) { + + g_return_val_if_fail(GTK_IS_V3270(widget),NULL); + return GTK_V3270(widget)->selection.font_family; +} diff --git a/src/terminal/keyfile.c b/src/terminal/keyfile.c index 94c2080..e1aa7e4 100644 --- a/src/terminal/keyfile.c +++ b/src/terminal/keyfile.c @@ -37,10 +37,47 @@ /*--[ Implement ]------------------------------------------------------------------------------------*/ - static void save_by_pspec(GtkWidget *widget, GParamSpec *pspec, GKeyFile *key_file, const gchar *group_name) - { - if(!pspec) - { + static void save_string(GKeyFile *key_file, const gchar *group_name, const gchar *key, const gchar *value) { + + if(value) { + + g_key_file_set_string( + key_file, + group_name, + key, + value + ); + + } else { + + g_key_file_remove_key( + key_file, + group_name, + key, + NULL + ); + + + } + + } + + static void load_string(GKeyFile *key_file, const gchar *group_name, const gchar *key, gchar **value) { + + if(*value) { + g_free(*value); + *value = NULL; + } + + if(g_key_file_has_key(key_file,group_name,key,NULL)) { + *value = g_key_file_get_string(key_file,group_name,key,NULL); + } + + } + + static void save_by_pspec(GtkWidget *widget, GParamSpec *pspec, GKeyFile *key_file, const gchar *group_name) { + + if(!pspec) { g_warning("Invalid property"); return; } @@ -51,8 +88,7 @@ g_value_init(&value, pspec->value_type); g_object_get_property(G_OBJECT(widget),name,&value); - switch(pspec->value_type) - { + switch(pspec->value_type) { case G_TYPE_STRING: { const gchar * current = g_value_get_string(&value); @@ -264,6 +300,9 @@ } + // Save internal properties + save_string(key_file, group_name, "selection-font-family", terminal->selection.font_family); + // Save Toggles for(ix = 0; ix < G_N_ELEMENTS(klass->properties.toggle); ix++) save_by_pspec(widget,klass->properties.toggle[ix],key_file,group_name); @@ -294,6 +333,9 @@ g_object_freeze_notify(G_OBJECT(widget)); terminal->freeze = 1; + // Load internal properties. + load_string(key_file, group_name, "selection-font-family", &terminal->selection.font_family); + // Load session_name if(g_key_file_has_key(key_file,group_name,"session-name",NULL)) { diff --git a/src/terminal/widget.c b/src/terminal/widget.c index a4d191c..d11c001 100644 --- a/src/terminal/widget.c +++ b/src/terminal/widget.c @@ -161,31 +161,33 @@ static void v3270_toggle_changed(G_GNUC_UNUSED v3270 *widget, G_GNUC_UNUSED LIB3 { } -static void finalize(GObject *object) - { +static void finalize(GObject *object) { + debug("V3270::%s",__FUNCTION__); v3270 * terminal = GTK_V3270(object); - if(terminal->remap_filename) - { + if(terminal->remap_filename) { g_free(terminal->remap_filename); terminal->remap_filename = NULL; } - if(terminal->host) - { + if(terminal->host) { // Release session lib3270_session_free(terminal->host); terminal->host = NULL; } - if(terminal->accelerators) - { + if(terminal->accelerators) { g_slist_free_full(terminal->accelerators,g_free); terminal->accelerators = NULL; } + if(terminal->selection.font_family) { + g_free(terminal->selection.font_family); + terminal->selection.font_family = NULL; + } + G_OBJECT_CLASS(v3270_parent_class)->finalize(object); } diff --git a/src/terminal/windows/registry.c b/src/terminal/windows/registry.c index 8dd9937..1f4d024 100644 --- a/src/terminal/windows/registry.c +++ b/src/terminal/windows/registry.c @@ -42,6 +42,10 @@ /*--[ Implement ]------------------------------------------------------------------------------------*/ + static void save_string(HKEY hKey, const gchar *key, const gchar *value) { + RegSetValueEx(hKey,key,0,REG_SZ,(const BYTE *) value,strlen(value)+1); + } + static void save_by_pspec(GtkWidget *widget, GParamSpec *pspec, HKEY hKey) { if(!pspec) @@ -134,6 +138,24 @@ } + static void load_string(HKEY hKey, const gchar *key, gchar **value) { + + if(*value) { + g_free(*value); + *value = NULL; + } + + BYTE data[4097]; + unsigned long datatype; + unsigned long datalen = 4096; + + if(RegQueryValueExA(hKey,key,NULL,&datatype,data,&datalen) != ERROR_SUCCESS) + return; + + *value = g_strdup((const gchar *) data); + + } + static void load_by_pspec(GtkWidget *widget, GParamSpec *pspec, HKEY hKey) { if(!pspec) @@ -228,6 +250,9 @@ } + // Save internal properties + save_string(hKey, "selection-font-family", terminal->selection.font_family); + // Save Toggles for(ix = 0; ix < G_N_ELEMENTS(klass->properties.toggle); ix++) save_by_pspec(widget,klass->properties.toggle[ix],hKey); @@ -283,6 +308,9 @@ } + // Load internal properties. + load_string(hKey, "selection-font-family", &terminal->selection.font_family); + // Load Toggles for(ix = 0; ix < G_N_ELEMENTS(klass->properties.toggle); ix++) load_by_pspec(widget,klass->properties.toggle[ix],hKey); diff --git a/src/testprogram/testprogram.c b/src/testprogram/testprogram.c index 0d6a9ff..ccebda0 100644 --- a/src/testprogram/testprogram.c +++ b/src/testprogram/testprogram.c @@ -45,7 +45,7 @@ #include #include #include - + #include /*---[ Implement ]----------------------------------------------------------------------------------*/ @@ -147,6 +147,8 @@ v3270_set_font_family(terminal,"Lucida Console"); #endif // _WIN32 + v3270_selection_set_font_family(terminal,"monospace"); + // Load settings before connecting the signals. #ifdef _WIN32 { diff --git a/src/testprogram/toolbar.c b/src/testprogram/toolbar.c index d946178..71cb045 100644 --- a/src/testprogram/toolbar.c +++ b/src/testprogram/toolbar.c @@ -34,6 +34,7 @@ #include #include #include + #include #include #include #include diff --git a/src/trace/exec.c b/src/trace/exec.c index 9330bdc..990cdf6 100644 --- a/src/trace/exec.c +++ b/src/trace/exec.c @@ -33,6 +33,7 @@ #include #include #include + #include static const gchar * get_word(gchar **ptr) { diff --git a/v3270.cbp b/v3270.cbp index 6227711..de0cfdd 100644 --- a/v3270.cbp +++ b/v3270.cbp @@ -185,6 +185,7 @@ + -- libgit2 0.21.2