Commit 97eb40b97ba58b074e39c73fec386450e43ebeda

Authored by Perry Werneck
1 parent bf54c0d5
Exists in master and in 1 other branch develop

Adjustments in the cut & paste methods.

src/include/terminal.h
... ... @@ -29,6 +29,7 @@
29 29  
30 30 #include <config.h>
31 31 #include <internals.h>
  32 +#include <v3270/selection.h>
32 33  
33 34 G_BEGIN_DECLS
34 35  
... ... @@ -166,6 +167,7 @@ G_BEGIN_DECLS
166 167 V3270_COPY_MODE format; ///< @brief Copy mode.
167 168 GList * blocks; ///< @brief Selection blocks.
168 169 V3270SelectionOption options; ///< @brief Selection options.
  170 + gchar * font_family; ///< @brief Font family for HTML paste.
169 171  
170 172 } selection;
171 173  
... ...
src/include/v3270.h
... ... @@ -201,45 +201,6 @@
201 201 LIB3270_EXPORT void v3270_set_lunames(GtkWidget *widget, const gchar *lunames);
202 202 LIB3270_EXPORT gchar * v3270_get_lunames(GtkWidget *widget);
203 203  
204   - // Clipboard
205   - typedef enum _v3270_copy_mode
206   - {
207   -
208   - V3270_COPY_DEFAULT, ///< @brief Detect format based on lib3270's smart past toggle.
209   - V3270_COPY_FORMATTED, ///< @brief Copy formatted data; keep attributes.
210   - V3270_COPY_TEXT, ///< @brief Single text format, ignore attributes.
211   - V3270_COPY_TABLE, ///< @brief Copy as table.
212   - V3270_COPY_APPEND ///< @brief Append to current contents keeping the stored format.
213   -
214   - } V3270_COPY_MODE;
215   -
216   - LIB3270_EXPORT void v3270_clipboard_set(GtkWidget *widget, V3270_COPY_MODE mode, gboolean cut);
217   - LIB3270_EXPORT void v3270_clipboard_get_from_url(GtkWidget *widget, const gchar *url);
218   -
219   - /// @brief Check if the widget has saved text.
220   - LIB3270_EXPORT gboolean v3270_has_copy(GtkWidget *widget);
221   -
222   - LIB3270_EXPORT void v3270_paste(GtkWidget *widget) G_GNUC_DEPRECATED;
223   - LIB3270_EXPORT void v3270_paste_text(GtkWidget *widget) G_GNUC_DEPRECATED;
224   - LIB3270_EXPORT void v3270_paste_from_file(GtkWidget *widget) G_GNUC_DEPRECATED;
225   - LIB3270_EXPORT void v3270_copy_selection(GtkWidget *widget, V3270_COPY_MODE mode, gboolean cut) G_GNUC_DEPRECATED;
226   - LIB3270_EXPORT void v3270_append_selection(GtkWidget *widget, gboolean cut) G_GNUC_DEPRECATED;
227   -
228   - // Selections
229   -
230   - LIB3270_EXPORT gchar * v3270_get_selected(GtkWidget *widget, gboolean cut);
231   - LIB3270_EXPORT gchar * v3270_get_copy(GtkWidget *widget);
232   -
233   - LIB3270_EXPORT gchar * v3270_get_text(GtkWidget *widget,int offset, int len);
234   - LIB3270_EXPORT gchar * v3270_get_region(GtkWidget *widget, gint start_pos, gint end_pos, gboolean all);
235   -
236   - LIB3270_EXPORT void v3270_set_string(GtkWidget *widget, const gchar *str);
237   -
238   - LIB3270_EXPORT gboolean v3270_get_selection_bounds(GtkWidget *widget, gint *start, gint *end);
239   - LIB3270_EXPORT void v3270_unselect(GtkWidget *widget);
240   - LIB3270_EXPORT void v3270_select_all(GtkWidget *widget);
241   - LIB3270_EXPORT void v3270_select_region(GtkWidget *widget, gint start, gint end);
242   -
243 204 LIB3270_EXPORT void v3270_input_text(GtkWidget *widget, const gchar *text, const gchar *encoding);
244 205  
245 206 // Colors
... ...
src/include/v3270/selection.h 0 → 100644
... ... @@ -0,0 +1,82 @@
  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 +#ifndef V3270_SELECTION_H_INCLUDED
  31 +
  32 + #define V3270_SELECTION_H_INCLUDED 1
  33 +
  34 + #include <gtk/gtk.h>
  35 +
  36 + G_BEGIN_DECLS
  37 +
  38 + // Clipboard
  39 + typedef enum _v3270_copy_mode
  40 + {
  41 +
  42 + V3270_COPY_DEFAULT, ///< @brief Detect format based on lib3270's smart past toggle.
  43 + V3270_COPY_FORMATTED, ///< @brief Copy formatted data; keep attributes.
  44 + V3270_COPY_TEXT, ///< @brief Single text format, ignore attributes.
  45 + V3270_COPY_TABLE, ///< @brief Copy as table.
  46 + V3270_COPY_APPEND ///< @brief Append to current contents keeping the stored format.
  47 +
  48 + } V3270_COPY_MODE;
  49 +
  50 + void v3270_clipboard_set(GtkWidget *widget, V3270_COPY_MODE mode, gboolean cut);
  51 + void v3270_clipboard_get_from_url(GtkWidget *widget, const gchar *url);
  52 +
  53 + /// @brief Check if the widget has saved text.
  54 + gboolean v3270_has_copy(GtkWidget *widget);
  55 +
  56 + void v3270_paste(GtkWidget *widget) G_GNUC_DEPRECATED;
  57 + void v3270_paste_text(GtkWidget *widget) G_GNUC_DEPRECATED;
  58 + void v3270_paste_from_file(GtkWidget *widget) G_GNUC_DEPRECATED;
  59 + void v3270_copy_selection(GtkWidget *widget, V3270_COPY_MODE mode, gboolean cut) G_GNUC_DEPRECATED;
  60 + void v3270_append_selection(GtkWidget *widget, gboolean cut) G_GNUC_DEPRECATED;
  61 +
  62 + // Selections
  63 +
  64 + gchar * v3270_get_selected(GtkWidget *widget, gboolean cut);
  65 + gchar * v3270_get_copy(GtkWidget *widget);
  66 +
  67 + gchar * v3270_get_text(GtkWidget *widget,int offset, int len);
  68 + gchar * v3270_get_region(GtkWidget *widget, gint start_pos, gint end_pos, gboolean all);
  69 +
  70 + void v3270_set_string(GtkWidget *widget, const gchar *str);
  71 +
  72 + gboolean v3270_get_selection_bounds(GtkWidget *widget, gint *start, gint *end);
  73 + void v3270_unselect(GtkWidget *widget);
  74 + void v3270_select_all(GtkWidget *widget);
  75 + void v3270_select_region(GtkWidget *widget, gint start, gint end);
  76 +
  77 + void v3270_selection_set_font_family(GtkWidget *widget, const gchar *name);
  78 + const gchar * v3270_selection_get_font_family(GtkWidget *widget);
  79 +
  80 + G_END_DECLS
  81 +
  82 +#endif // V3270_ACTIONS_H_INCLUDED
... ...
src/selection/html.c
... ... @@ -49,8 +49,8 @@ static void get_element_colors(v3270 * terminal, unsigned short attr, gchar **fg
49 49 }
50 50  
51 51 /// @brief Get formatted contents as HTML DIV.
52   -static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all, const V3270SelectionOption options)
53   -{
  52 +static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all, const V3270SelectionOption options) {
  53 +
54 54 const GList * element = selection;
55 55 GString * string = g_string_new("");
56 56 gchar * bgColor;
... ... @@ -58,13 +58,11 @@ static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all
58 58  
59 59 g_string_append(string,"<div style=\"padding:1em;display:inline-block");
60 60  
61   - if(options & V3270_SELECTION_FONT_FAMILY)
62   - {
63   - g_string_append_printf(string,";font-family:%s,monospace",terminal->font.family);
  61 + if(options & V3270_SELECTION_FONT_FAMILY) {
  62 + g_string_append_printf(string,";font-family:%s,monospace",(terminal->selection.font_family ? terminal->selection.font_family : terminal->font.family));
64 63 }
65 64  
66   - if(options & V3270_SELECTION_COLORS)
67   - {
  65 + if(options & V3270_SELECTION_COLORS) {
68 66 bgColor = gdk_rgba_to_string(terminal->color+V3270_COLOR_BACKGROUND);
69 67 g_string_append_printf(string,";background-color:%s",bgColor);
70 68 g_free(bgColor);
... ... @@ -72,14 +70,13 @@ static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all
72 70  
73 71 g_string_append(string,"\">");
74 72  
75   - while(element)
76   - {
  73 + while(element) {
77 74 const lib3270_selection * block = ((const lib3270_selection *) element->data);
78 75 unsigned int row, col, src = 0;
79 76 unsigned short flags = block->contents[0].attribute.visual;
80 77  
81   - if(options & V3270_SELECTION_COLORS)
82   - {
  78 + if(options & V3270_SELECTION_COLORS) {
  79 +
83 80 get_element_colors(terminal,flags,&fgColor,&bgColor);
84 81  
85 82 g_string_append_printf(
... ... @@ -97,16 +94,16 @@ static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all
97 94 g_string_append_c(string,'\n');
98 95 #endif // DEBUG
99 96  
100   - for(row=0; row < block->bounds.height; row++)
101   - {
102   - for(col=0; col<block->bounds.width; col++)
103   - {
104   - if(flags != block->contents[src].attribute.visual)
105   - {
  97 + for(row=0; row < block->bounds.height; row++) {
  98 +
  99 + for(col=0; col<block->bounds.width; col++) {
  100 +
  101 + if(flags != block->contents[src].attribute.visual) {
  102 +
106 103 flags = block->contents[src].attribute.visual;
107 104  
108   - if(options & V3270_SELECTION_COLORS)
109   - {
  105 + if(options & V3270_SELECTION_COLORS) {
  106 +
110 107 get_element_colors(terminal,flags,&fgColor,&bgColor);
111 108  
112 109 g_string_append_printf(
... ... @@ -122,13 +119,14 @@ static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all
122 119  
123 120 }
124 121  
125   - if( (block->contents[src].attribute.visual & LIB3270_ATTR_SELECTED || all) && !isspace(block->contents[src].chr))
126   - {
  122 + if( (block->contents[src].attribute.visual & LIB3270_ATTR_SELECTED || all) && !isspace(block->contents[src].chr)) {
  123 +
127 124 g_string_append_c(string,block->contents[src].chr);
128   - }
129   - else
130   - {
  125 +
  126 + } else {
  127 +
131 128 g_string_append(string,((options & V3270_SELECTION_NON_BREAKABLE_SPACE) ? "&nbsp;" : " "));
  129 +
132 130 }
133 131  
134 132 src++;
... ... @@ -140,9 +138,10 @@ static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all
140 138 #endif // DEBUG
141 139 }
142 140  
143   - if(options & V3270_SELECTION_COLORS)
144   - {
  141 + if(options & V3270_SELECTION_COLORS) {
  142 +
145 143 g_string_append(string,"</span>");
  144 +
146 145 }
147 146  
148 147 element = g_list_next(element);
... ... @@ -162,13 +161,21 @@ static gchar * get_as_div(v3270 * terminal, const GList *selection, gboolean all
162 161 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.
163 162 {
164 163 const GList * element = selection;
165   - GString * string = g_string_new("<table><tbody>");
  164 + GString * string = g_string_new("");
166 165  
167 166 unsigned int width = lib3270_get_width(terminal->host);
168 167 g_autofree gchar * line = g_malloc0(width+1);
169 168  
170 169 GList * column;
171 170  
  171 + g_string_append(string,"<table");
  172 +
  173 + if(options & V3270_SELECTION_FONT_FAMILY) {
  174 + g_string_append_printf(string," style=\"font-family:%s,monospace\"",(terminal->selection.font_family ? terminal->selection.font_family : terminal->font.family));
  175 + }
  176 +
  177 + g_string_append(string,"><tbody>");
  178 +
172 179 // Get contents
173 180 GList * columns = v3270_getColumns_from_selection(terminal, selection, all);
174 181  
... ...
src/selection/selection.c
... ... @@ -132,4 +132,28 @@ LIB3270_EXPORT void v3270_select_all(GtkWidget *widget)
132 132 v3270_enable_updates(widget);
133 133 }
134 134  
  135 +void v3270_selection_set_font_family(GtkWidget *widget, const gchar *name) {
  136 +
  137 + g_return_if_fail(GTK_IS_V3270(widget));
  138 +
  139 + v3270 * terminal = GTK_V3270(widget);
  140 +
  141 + if(terminal->selection.font_family) {
  142 + g_free(terminal->selection.font_family);
  143 + terminal->selection.font_family = NULL;
  144 + }
  145 +
  146 + if(name) {
  147 + terminal->selection.font_family = g_strdup(name);
  148 + }
  149 +
  150 + v3270_emit_save_settings(widget);
  151 +
  152 +}
  153 +
  154 +const gchar * v3270_selection_get_font_family(GtkWidget *widget) {
  155 +
  156 + g_return_val_if_fail(GTK_IS_V3270(widget),NULL);
  157 + return GTK_V3270(widget)->selection.font_family;
  158 +}
135 159  
... ...
src/terminal/keyfile.c
... ... @@ -37,10 +37,47 @@
37 37  
38 38 /*--[ Implement ]------------------------------------------------------------------------------------*/
39 39  
40   - static void save_by_pspec(GtkWidget *widget, GParamSpec *pspec, GKeyFile *key_file, const gchar *group_name)
41   - {
42   - if(!pspec)
43   - {
  40 + static void save_string(GKeyFile *key_file, const gchar *group_name, const gchar *key, const gchar *value) {
  41 +
  42 + if(value) {
  43 +
  44 + g_key_file_set_string(
  45 + key_file,
  46 + group_name,
  47 + key,
  48 + value
  49 + );
  50 +
  51 + } else {
  52 +
  53 + g_key_file_remove_key(
  54 + key_file,
  55 + group_name,
  56 + key,
  57 + NULL
  58 + );
  59 +
  60 +
  61 + }
  62 +
  63 + }
  64 +
  65 + static void load_string(GKeyFile *key_file, const gchar *group_name, const gchar *key, gchar **value) {
  66 +
  67 + if(*value) {
  68 + g_free(*value);
  69 + *value = NULL;
  70 + }
  71 +
  72 + if(g_key_file_has_key(key_file,group_name,key,NULL)) {
  73 + *value = g_key_file_get_string(key_file,group_name,key,NULL);
  74 + }
  75 +
  76 + }
  77 +
  78 + static void save_by_pspec(GtkWidget *widget, GParamSpec *pspec, GKeyFile *key_file, const gchar *group_name) {
  79 +
  80 + if(!pspec) {
44 81 g_warning("Invalid property");
45 82 return;
46 83 }
... ... @@ -51,8 +88,7 @@
51 88 g_value_init(&value, pspec->value_type);
52 89 g_object_get_property(G_OBJECT(widget),name,&value);
53 90  
54   - switch(pspec->value_type)
55   - {
  91 + switch(pspec->value_type) {
56 92 case G_TYPE_STRING:
57 93 {
58 94 const gchar * current = g_value_get_string(&value);
... ... @@ -264,6 +300,9 @@
264 300  
265 301 }
266 302  
  303 + // Save internal properties
  304 + save_string(key_file, group_name, "selection-font-family", terminal->selection.font_family);
  305 +
267 306 // Save Toggles
268 307 for(ix = 0; ix < G_N_ELEMENTS(klass->properties.toggle); ix++)
269 308 save_by_pspec(widget,klass->properties.toggle[ix],key_file,group_name);
... ... @@ -294,6 +333,9 @@
294 333 g_object_freeze_notify(G_OBJECT(widget));
295 334 terminal->freeze = 1;
296 335  
  336 + // Load internal properties.
  337 + load_string(key_file, group_name, "selection-font-family", &terminal->selection.font_family);
  338 +
297 339 // Load session_name
298 340 if(g_key_file_has_key(key_file,group_name,"session-name",NULL)) {
299 341  
... ...
src/terminal/widget.c
... ... @@ -161,31 +161,33 @@ static void v3270_toggle_changed(G_GNUC_UNUSED v3270 *widget, G_GNUC_UNUSED LIB3
161 161 {
162 162 }
163 163  
164   -static void finalize(GObject *object)
165   - {
  164 +static void finalize(GObject *object) {
  165 +
166 166 debug("V3270::%s",__FUNCTION__);
167 167  
168 168 v3270 * terminal = GTK_V3270(object);
169 169  
170   - if(terminal->remap_filename)
171   - {
  170 + if(terminal->remap_filename) {
172 171 g_free(terminal->remap_filename);
173 172 terminal->remap_filename = NULL;
174 173 }
175 174  
176   - if(terminal->host)
177   - {
  175 + if(terminal->host) {
178 176 // Release session
179 177 lib3270_session_free(terminal->host);
180 178 terminal->host = NULL;
181 179 }
182 180  
183   - if(terminal->accelerators)
184   - {
  181 + if(terminal->accelerators) {
185 182 g_slist_free_full(terminal->accelerators,g_free);
186 183 terminal->accelerators = NULL;
187 184 }
188 185  
  186 + if(terminal->selection.font_family) {
  187 + g_free(terminal->selection.font_family);
  188 + terminal->selection.font_family = NULL;
  189 + }
  190 +
189 191 G_OBJECT_CLASS(v3270_parent_class)->finalize(object);
190 192 }
191 193  
... ...
src/terminal/windows/registry.c
... ... @@ -42,6 +42,10 @@
42 42  
43 43 /*--[ Implement ]------------------------------------------------------------------------------------*/
44 44  
  45 + static void save_string(HKEY hKey, const gchar *key, const gchar *value) {
  46 + RegSetValueEx(hKey,key,0,REG_SZ,(const BYTE *) value,strlen(value)+1);
  47 + }
  48 +
45 49 static void save_by_pspec(GtkWidget *widget, GParamSpec *pspec, HKEY hKey)
46 50 {
47 51 if(!pspec)
... ... @@ -134,6 +138,24 @@
134 138  
135 139 }
136 140  
  141 + static void load_string(HKEY hKey, const gchar *key, gchar **value) {
  142 +
  143 + if(*value) {
  144 + g_free(*value);
  145 + *value = NULL;
  146 + }
  147 +
  148 + BYTE data[4097];
  149 + unsigned long datatype;
  150 + unsigned long datalen = 4096;
  151 +
  152 + if(RegQueryValueExA(hKey,key,NULL,&datatype,data,&datalen) != ERROR_SUCCESS)
  153 + return;
  154 +
  155 + *value = g_strdup((const gchar *) data);
  156 +
  157 + }
  158 +
137 159 static void load_by_pspec(GtkWidget *widget, GParamSpec *pspec, HKEY hKey)
138 160 {
139 161 if(!pspec)
... ... @@ -228,6 +250,9 @@
228 250  
229 251 }
230 252  
  253 + // Save internal properties
  254 + save_string(hKey, "selection-font-family", terminal->selection.font_family);
  255 +
231 256 // Save Toggles
232 257 for(ix = 0; ix < G_N_ELEMENTS(klass->properties.toggle); ix++)
233 258 save_by_pspec(widget,klass->properties.toggle[ix],hKey);
... ... @@ -283,6 +308,9 @@
283 308  
284 309 }
285 310  
  311 + // Load internal properties.
  312 + load_string(hKey, "selection-font-family", &terminal->selection.font_family);
  313 +
286 314 // Load Toggles
287 315 for(ix = 0; ix < G_N_ELEMENTS(klass->properties.toggle); ix++)
288 316 load_by_pspec(widget,klass->properties.toggle[ix],hKey);
... ...
src/testprogram/testprogram.c
... ... @@ -45,7 +45,7 @@
45 45 #include <gdk/gdkkeysyms-compat.h>
46 46 #include <locale.h>
47 47 #include <libintl.h>
48   -
  48 + #include <v3270/selection.h>
49 49  
50 50 /*---[ Implement ]----------------------------------------------------------------------------------*/
51 51  
... ... @@ -147,6 +147,8 @@
147 147 v3270_set_font_family(terminal,"Lucida Console");
148 148 #endif // _WIN32
149 149  
  150 + v3270_selection_set_font_family(terminal,"monospace");
  151 +
150 152 // Load settings before connecting the signals.
151 153 #ifdef _WIN32
152 154 {
... ...
src/testprogram/toolbar.c
... ... @@ -34,6 +34,7 @@
34 34 #include <v3270/colorscheme.h>
35 35 #include <v3270/dialogs.h>
36 36 #include <v3270/settings.h>
  37 + #include <v3270/selection.h>
37 38 #include <v3270/trace.h>
38 39 #include <lib3270/log.h>
39 40 #include <stdlib.h>
... ...
src/trace/exec.c
... ... @@ -33,6 +33,7 @@
33 33 #include <lib3270/properties.h>
34 34 #include <lib3270/actions.h>
35 35 #include <internals.h>
  36 + #include <v3270/selection.h>
36 37  
37 38 static const gchar * get_word(gchar **ptr)
38 39 {
... ...
v3270.cbp
... ... @@ -185,6 +185,7 @@
185 185 <Unit filename="src/include/v3270/ftprogress.h" />
186 186 <Unit filename="src/include/v3270/print.h" />
187 187 <Unit filename="src/include/v3270/security.h" />
  188 + <Unit filename="src/include/v3270/selection.h" />
188 189 <Unit filename="src/include/v3270/settings.h" />
189 190 <Unit filename="src/include/v3270/toggle.h" />
190 191 <Unit filename="src/include/v3270/trace.h" />
... ...