Commit 600d45c413eacefb2908652736fc654b5c69700d

Authored by perry.werneck@gmail.com
1 parent 983dcc99

Conteúdo do clipboard passa a ficar guardado no widget no formato original da li…

…b3270 para permitir a futura implementação de cópia com formatação
src/pw3270/v3270/private.h
... ... @@ -152,7 +152,11 @@ G_BEGIN_DECLS
152 152 GSource * timer;
153 153 GtkIMContext * input_method;
154 154 unsigned short keyflags;
155   - gchar * clipboard; /**< Clipboard contents (text only) */
  155 +
  156 + struct
  157 + {
  158 + char * text; /**< Clipboard contents (lib3270 charset) */
  159 + } selection;
156 160  
157 161 LIB3270_CURSOR pointer_id;
158 162 unsigned char pointer; /**< Mouse pointer ID */
... ...
src/pw3270/v3270/selection.c
... ... @@ -63,11 +63,17 @@ static void clipboard_get(GtkClipboard *clipboard, GtkSelectionData *selection,
63 63  
64 64 switch(target)
65 65 {
66   - case CLIPBOARD_TYPE_TEXT:
67   - if(!widget->clipboard)
  66 + case CLIPBOARD_TYPE_TEXT: /* Get clipboard contents as text */
  67 + if(!widget->selection.text)
  68 + {
68 69 lib3270_ring_bell(widget->host);
  70 + }
69 71 else
70   - gtk_selection_data_set_text(selection,widget->clipboard,-1);
  72 + {
  73 + gchar * text = g_convert(widget->selection.text, -1, "UTF-8", lib3270_get_charset(widget->host), NULL, NULL, NULL);
  74 + gtk_selection_data_set_text(selection,text,-1);
  75 + g_free(text);
  76 + }
71 77 break;
72 78  
73 79 default:
... ... @@ -96,46 +102,11 @@ gchar * v3270_get_text(GtkWidget *widget, int offset, int len)
96 102 return text;
97 103 }
98 104  
99   -/**
100   - * Get lib3270 selection as a g_malloc buffer.
101   - *
102   - * @param widget Widget containing the desired section.
103   - *
104   - * @return NULL if error, otherwise the selected buffer contents (release with g_free).
105   - *
106   - */ /*
107   -static gchar * v3270_get_selected(v3270 *widget)
108   -{
109   - gchar *text = lib3270_get_selected(widget->host);
110   - if(text)
111   - {
112   - gchar *str = g_strdup(text);
113   - lib3270_free(text);
114   - return str;
115   - }
116   - return NULL;
117   -}
118   -
119   -static gchar * v3270_cut_selected(v3270 *widget)
120   -{
121   - gchar *text = lib3270_cut_selected(widget->host);
122   - if(text)
123   - {
124   - gchar *str = g_strdup(text);
125   - lib3270_free(text);
126   - return str;
127   - }
128   - return NULL;
129   -}
130   -*/
131   -
132   -gchar * v3270_get_selected(GtkWidget *widget, gboolean cut)
  105 +static const char * update_selected_text(GtkWidget *widget, gboolean cut)
133 106 {
134 107 v3270 * terminal;
135 108 char * text;
136 109  
137   - g_return_val_if_fail(GTK_IS_V3270(widget),NULL);
138   -
139 110 terminal = GTK_V3270(widget);
140 111  
141 112 v3270_clear_clipboard(terminal);
... ... @@ -227,32 +198,77 @@ gchar * v3270_get_selected(GtkWidget *widget, gboolean cut)
227 198 text = g_string_free(buffer,FALSE);
228 199 }
229 200  
230   - terminal->clipboard = g_convert(text, -1, "UTF-8", lib3270_get_charset(terminal->host), NULL, NULL, NULL);
  201 + return terminal->selection.text = text;
231 202  
232   - lib3270_free(text);
  203 +}
233 204  
  205 +/**
  206 + * Get lib3270 selection as a g_malloc buffer.
  207 + *
  208 + * @param widget Widget containing the desired section.
  209 + *
  210 + * @return NULL if error, otherwise the selected buffer contents (release with g_free).
  211 + *
  212 + */
  213 +gchar * v3270_get_selected(GtkWidget *widget, gboolean cut)
  214 +{
  215 + const char *text;
  216 +
  217 + g_return_val_if_fail(GTK_IS_V3270(widget),NULL);
234 218  
235   - return g_strdup(terminal->clipboard);
  219 + text = update_selected_text(widget,cut);
  220 +
  221 + if(text)
  222 + return g_convert(text, -1, "UTF-8", lib3270_get_charset(GTK_V3270(widget)->host), NULL, NULL, NULL);
  223 +
  224 + return NULL;
236 225 }
237 226  
238 227 gchar * v3270_get_copy(GtkWidget *widget)
239 228 {
  229 + const char *text;
240 230 g_return_val_if_fail(GTK_IS_V3270(widget),NULL);
241   - return g_strdup(GTK_V3270(widget)->clipboard);
  231 +
  232 + text = update_selected_text(widget,FALSE);
  233 +
  234 + if(text)
  235 + return g_convert(text, -1, "UTF-8", lib3270_get_charset(GTK_V3270(widget)->host), NULL, NULL, NULL);
  236 +
  237 + return NULL;
  238 +}
  239 +
  240 +static void update_system_clipboard(GtkWidget *widget)
  241 +{
  242 + if(GTK_V3270(widget)->selection.text)
  243 + {
  244 + GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,GDK_SELECTION_CLIPBOARD);
  245 +
  246 + if(gtk_clipboard_set_with_owner( clipboard,
  247 + targets,
  248 + G_N_ELEMENTS(targets),
  249 + (GtkClipboardGetFunc) clipboard_get,
  250 + (GtkClipboardClearFunc) clipboard_clear,
  251 + G_OBJECT(widget)
  252 + ))
  253 + {
  254 + gtk_clipboard_set_can_store(clipboard,targets,1);
  255 + }
  256 +
  257 + g_signal_emit(widget,v3270_widget_signal[SIGNAL_CLIPBOARD], 0, TRUE);
  258 + }
242 259 }
243 260  
  261 +
244 262 void v3270_copy_append(GtkWidget *widget)
245 263 {
246 264 v3270 * terminal;
247 265 char * str;
248   - gchar * text;
249   - gchar * clip;
250 266  
251 267 g_return_if_fail(GTK_IS_V3270(widget));
252 268  
253 269 terminal = GTK_V3270(widget);
254 270  
255   - if(!terminal->clipboard)
  271 + if(!terminal->selection.text)
256 272 {
257 273 // Clipboard is empty, do a single copy
258 274 v3270_copy(widget, V3270_SELECT_TEXT, FALSE);
... ... @@ -261,54 +277,36 @@ void v3270_copy_append(GtkWidget *widget)
261 277  
262 278 str = lib3270_get_selected(terminal->host);
263 279  
264   - if(!str)
265   - return;
266   -
267   - text = g_convert(str, -1, "UTF-8", lib3270_get_charset(terminal->host), NULL, NULL, NULL);
268   -
269   - lib3270_free(str);
  280 + if(str)
  281 + {
  282 + size_t len = strlen(terminal->selection.text)+strlen(str)+2;
270 283  
271   - clip = g_strconcat(terminal->clipboard,"\n",text,NULL);
  284 + terminal->selection.text = lib3270_realloc(terminal->selection.text,len);
272 285  
273   - g_free(text);
274   - v3270_clear_clipboard(terminal);
  286 + strncat(terminal->selection.text,"\n",len);
  287 + strncat(terminal->selection.text,str,len);
275 288  
276   - terminal->clipboard = clip;
  289 + lib3270_free(str);
  290 + }
277 291  
278   - gtk_clipboard_set_text(gtk_widget_get_clipboard(widget,GDK_SELECTION_CLIPBOARD),terminal->clipboard,-1);
  292 +/*
  293 + text = g_convert(terminal->selection.text, -1, "UTF-8", lib3270_get_charset(terminal->host), NULL, NULL, NULL);
  294 + gtk_clipboard_set_text(gtk_widget_get_clipboard(widget,GDK_SELECTION_CLIPBOARD),text,-1);
  295 + g_free(text);
279 296  
280 297 g_signal_emit(widget,v3270_widget_signal[SIGNAL_CLIPBOARD], 0, TRUE);
  298 +*/
  299 +
  300 + update_system_clipboard(widget);
281 301  
282 302 }
283 303  
284 304 void v3270_copy(GtkWidget *widget, V3270_SELECT_FORMAT mode, gboolean cut)
285 305 {
286   - gchar * text;
287   - GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,GDK_SELECTION_CLIPBOARD);
288   -
289 306 g_return_if_fail(GTK_IS_V3270(widget));
290   -
291 307 GTK_V3270(widget)->table = (mode == V3270_SELECT_TABLE ? 1 : 0);
292   -
293   - text = v3270_get_selected(widget,cut);
294   -
295   - if(text)
296   - {
297   - if(gtk_clipboard_set_with_owner( clipboard,
298   - targets,
299   - G_N_ELEMENTS(targets),
300   - (GtkClipboardGetFunc) clipboard_get,
301   - (GtkClipboardClearFunc) clipboard_clear,
302   - G_OBJECT(widget)
303   - ))
304   - {
305   - gtk_clipboard_set_can_store(clipboard,targets,1);
306   - }
307   -
308   - g_signal_emit(widget,v3270_widget_signal[SIGNAL_CLIPBOARD], 0, TRUE);
309   - g_free(text);
310   - }
311   -
  308 + update_selected_text(widget,cut);
  309 + update_system_clipboard(widget);
312 310 }
313 311  
314 312 void v3270_paste_string(GtkWidget *widget, const gchar *text, const gchar *encoding)
... ...
src/pw3270/v3270/widget.c
... ... @@ -897,11 +897,7 @@ GtkWidget * v3270_new(void)
897 897  
898 898 void v3270_clear_clipboard(v3270 *terminal)
899 899 {
900   - if(terminal->clipboard)
901   - {
902   - g_free(terminal->clipboard);
903   - terminal->clipboard = NULL;
904   - }
  900 + terminal->selection.text = lib3270_free(terminal->selection.text);
905 901 }
906 902  
907 903 #if GTK_CHECK_VERSION(3,0,0)
... ...