Commit 050f6abaccb7b23a3912eba1b37f88f4c360e611
1 parent
f0203846
Exists in
master
and in
1 other branch
Fixing 'copy-as-html' action.
Showing
4 changed files
with
67 additions
and
124 deletions
Show diff stats
src/include/clipboard.h
... | ... | @@ -104,6 +104,9 @@ |
104 | 104 | G_GNUC_INTERNAL gchar * v3270_get_copy_as_table(v3270 * terminal, const gchar *delimiter, const gchar *encoding); |
105 | 105 | G_GNUC_INTERNAL gchar * v3270_get_copy_as_data_block(v3270 * terminal); |
106 | 106 | |
107 | + G_GNUC_INTERNAL void v3270_clipboard_clear(GtkClipboard *clipboard, GObject *obj); | |
108 | + G_GNUC_INTERNAL void v3270_clipboard_get(GtkClipboard *clipboard, GtkSelectionData *selection, guint target, GObject *obj); | |
109 | + | |
107 | 110 | /// @brief Set contents. |
108 | 111 | G_GNUC_INTERNAL gboolean v3270_set_from_data_block(v3270 * terminal, const struct SelectionHeader *selection); |
109 | 112 | ... | ... |
src/selection/copy.c
... | ... | @@ -30,7 +30,17 @@ |
30 | 30 | #include <clipboard.h> |
31 | 31 | #include <lib3270/selection.h> |
32 | 32 | |
33 | - static void do_copy(v3270 *terminal, gboolean cut) { | |
33 | + static void do_copy(v3270 *terminal, V3270_COPY_MODE mode, gboolean cut) { | |
34 | + | |
35 | + if(mode == V3270_COPY_SMART) { | |
36 | + mode = (terminal->append ? V3270_COPY_APPEND : V3270_COPY_FORMATTED); | |
37 | + } | |
38 | + | |
39 | + if(mode != V3270_COPY_APPEND) { | |
40 | + // It's not append, clear current contents ... | |
41 | + v3270_clear_selection(terminal); | |
42 | + terminal->selection.format = mode; | |
43 | + } | |
34 | 44 | |
35 | 45 | lib3270_selection * selection = lib3270_selection_new(terminal->host,cut,0); |
36 | 46 | |
... | ... | @@ -44,32 +54,60 @@ |
44 | 54 | LIB3270_EXPORT void v3270_clipboard_set(GtkWidget *widget, V3270_COPY_MODE mode, gboolean cut) { |
45 | 55 | |
46 | 56 | g_return_if_fail(GTK_IS_V3270(widget)); |
57 | + do_copy(GTK_V3270(widget),mode,cut); | |
58 | + v3270_update_system_clipboard(widget); | |
59 | + | |
60 | + } | |
61 | + | |
62 | + LIB3270_EXPORT void v3270_copy_selection(GtkWidget *widget, V3270_COPY_MODE mode, gboolean cut) { | |
63 | + v3270_clipboard_set(widget,mode,cut); | |
64 | + } | |
65 | + | |
66 | + LIB3270_EXPORT void v3270_append_selection(GtkWidget *widget, gboolean cut) { | |
67 | + v3270_clipboard_set(widget,V3270_COPY_APPEND,cut); | |
68 | + } | |
47 | 69 | |
70 | + LIB3270_EXPORT void v3270_copy_as_html(GtkWidget *widget) { | |
71 | + | |
72 | + g_return_if_fail(GTK_IS_V3270(widget)); | |
48 | 73 | v3270 * terminal = GTK_V3270(widget); |
49 | 74 | |
50 | - if(mode == V3270_COPY_SMART) { | |
51 | - mode = (terminal->append ? V3270_COPY_APPEND : V3270_COPY_FORMATTED); | |
52 | - } | |
75 | + debug("%s",__FUNCTION__); | |
53 | 76 | |
54 | - if(mode != V3270_COPY_APPEND) { | |
77 | + do_copy(terminal,V3270_COPY_FORMATTED,0); | |
55 | 78 | |
56 | - // It's not append, clear current contents ... | |
57 | - v3270_clear_selection(terminal); | |
79 | + // | |
80 | + // Export only in HTML format | |
81 | + // | |
82 | + GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,terminal->selection.target); | |
58 | 83 | |
59 | - terminal->selection.format = mode; | |
84 | + GtkTargetList * list = gtk_target_list_new(NULL,0); | |
60 | 85 | |
61 | - } | |
86 | + static const GtkTargetEntry entry = { | |
87 | + .target = "text/html", | |
88 | + .flags = 0, | |
89 | + .info = CLIPBOARD_TYPE_HTML | |
90 | + }; | |
62 | 91 | |
63 | - do_copy(terminal,cut); | |
92 | + gtk_target_list_add_table(list, &entry, 1); | |
64 | 93 | |
65 | - v3270_update_system_clipboard(widget); | |
66 | - } | |
94 | + int n_targets; | |
95 | + GtkTargetEntry * targets = gtk_target_table_new_from_list(list, &n_targets); | |
67 | 96 | |
68 | - LIB3270_EXPORT void v3270_copy_selection(GtkWidget *widget, V3270_COPY_MODE format, gboolean cut) { | |
69 | - v3270_clipboard_set(widget,format,cut); | |
70 | - } | |
97 | + if(gtk_clipboard_set_with_owner( | |
98 | + clipboard, | |
99 | + targets, | |
100 | + n_targets, | |
101 | + (GtkClipboardGetFunc) v3270_clipboard_get, | |
102 | + (GtkClipboardClearFunc) v3270_clipboard_clear, | |
103 | + G_OBJECT(widget) | |
104 | + )) | |
105 | + { | |
106 | + gtk_clipboard_set_can_store(clipboard,targets,1); | |
107 | + } | |
71 | 108 | |
72 | - LIB3270_EXPORT void v3270_append_selection(GtkWidget *widget, gboolean cut) { | |
73 | - v3270_clipboard_set(widget,V3270_COPY_APPEND,cut); | |
74 | - } | |
109 | + gtk_target_table_free(targets, n_targets); | |
110 | + gtk_target_list_unref(list); | |
75 | 111 | |
112 | + v3270_emit_copy_state(widget); | |
113 | + } | ... | ... |
src/selection/linux/copy.c
... | ... | @@ -33,7 +33,7 @@ |
33 | 33 | |
34 | 34 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
35 | 35 | |
36 | -static void clipboard_clear(G_GNUC_UNUSED GtkClipboard *clipboard, G_GNUC_UNUSED GObject *obj) | |
36 | +void v3270_clipboard_clear(G_GNUC_UNUSED GtkClipboard *clipboard, G_GNUC_UNUSED GObject *obj) | |
37 | 37 | { |
38 | 38 | v3270 * terminal = GTK_V3270(obj); |
39 | 39 | |
... | ... | @@ -45,7 +45,7 @@ static void clipboard_clear(G_GNUC_UNUSED GtkClipboard *clipboard, G_GNUC_UNUSED |
45 | 45 | |
46 | 46 | } |
47 | 47 | |
48 | -static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionData *selection, guint target, GObject *obj) | |
48 | +void v3270_clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionData *selection, guint target, GObject *obj) | |
49 | 49 | { |
50 | 50 | v3270 * terminal = GTK_V3270(obj); |
51 | 51 | |
... | ... | @@ -178,8 +178,8 @@ void v3270_update_system_clipboard(GtkWidget *widget) |
178 | 178 | clipboard, |
179 | 179 | targets, |
180 | 180 | n_targets, |
181 | - (GtkClipboardGetFunc) clipboard_get, | |
182 | - (GtkClipboardClearFunc) clipboard_clear, | |
181 | + (GtkClipboardGetFunc) v3270_clipboard_get, | |
182 | + (GtkClipboardClearFunc) v3270_clipboard_clear, | |
183 | 183 | G_OBJECT(widget) |
184 | 184 | )) |
185 | 185 | { |
... | ... | @@ -193,52 +193,4 @@ void v3270_update_system_clipboard(GtkWidget *widget) |
193 | 193 | |
194 | 194 | } |
195 | 195 | |
196 | -void v3270_set_copy_target(GtkWidget *widget, const gchar *target, guint flags, guint info) { | |
197 | - | |
198 | - v3270 * terminal = GTK_V3270(widget); | |
199 | - | |
200 | - if(!terminal->selection.blocks) | |
201 | - { | |
202 | - // No clipboard data, return. | |
203 | - v3270_emit_copy_state(widget); | |
204 | - return; | |
205 | - } | |
206 | - | |
207 | - // Has clipboard data, inform system. | |
208 | - GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,terminal->selection.target); | |
209 | - | |
210 | - GtkTargetList * list = gtk_target_list_new(NULL,0); | |
211 | - | |
212 | - GtkTargetEntry entry = { | |
213 | - .target = (char *) target, | |
214 | - .flags = flags, | |
215 | - .info = info | |
216 | - }; | |
217 | - | |
218 | - gtk_target_list_add_table(list, &entry, 1); | |
219 | - | |
220 | - int n_targets; | |
221 | - GtkTargetEntry * targets = gtk_target_table_new_from_list(list, &n_targets); | |
222 | - | |
223 | - if(gtk_clipboard_set_with_owner( | |
224 | - clipboard, | |
225 | - targets, | |
226 | - n_targets, | |
227 | - (GtkClipboardGetFunc) clipboard_get, | |
228 | - (GtkClipboardClearFunc) clipboard_clear, | |
229 | - G_OBJECT(widget) | |
230 | - )) | |
231 | - { | |
232 | - gtk_clipboard_set_can_store(clipboard,targets,1); | |
233 | - } | |
234 | - | |
235 | - gtk_target_table_free(targets, n_targets); | |
236 | - gtk_target_list_unref(list); | |
237 | - v3270_emit_copy_state(widget); | |
238 | -} | |
239 | - | |
240 | -LIB3270_EXPORT void v3270_copy_as_html(GtkWidget *widget) { | |
241 | - debug("%s(%p)",__FUNCTION__,widget); | |
242 | - v3270_set_copy_target(widget,"text/html", 0, CLIPBOARD_TYPE_HTML); | |
243 | -} | |
244 | 196 | ... | ... |
src/selection/windows/copy.c
... | ... | @@ -33,7 +33,7 @@ |
33 | 33 | |
34 | 34 | /*--[ Implement ]------------------------------------------------------------------------------------*/ |
35 | 35 | |
36 | -static void clipboard_clear(G_GNUC_UNUSED GtkClipboard *clipboard, G_GNUC_UNUSED GObject *obj) | |
36 | +void v3270_clipboard_clear(G_GNUC_UNUSED GtkClipboard *clipboard, G_GNUC_UNUSED GObject *obj) | |
37 | 37 | { |
38 | 38 | v3270 * terminal = GTK_V3270(obj); |
39 | 39 | |
... | ... | @@ -45,7 +45,7 @@ static void clipboard_clear(G_GNUC_UNUSED GtkClipboard *clipboard, G_GNUC_UNUSED |
45 | 45 | |
46 | 46 | } |
47 | 47 | |
48 | -static void clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionData *selection, guint target, GObject *obj) | |
48 | +void v3270_clipboard_get(G_GNUC_UNUSED GtkClipboard *clipboard, GtkSelectionData *selection, guint target, GObject *obj) | |
49 | 49 | { |
50 | 50 | v3270 * terminal = GTK_V3270(obj); |
51 | 51 | |
... | ... | @@ -178,8 +178,8 @@ void v3270_update_system_clipboard(GtkWidget *widget) |
178 | 178 | clipboard, |
179 | 179 | targets, |
180 | 180 | n_targets, |
181 | - (GtkClipboardGetFunc) clipboard_get, | |
182 | - (GtkClipboardClearFunc) clipboard_clear, | |
181 | + (GtkClipboardGetFunc) v3270_clipboard_get, | |
182 | + (GtkClipboardClearFunc) v3270_clipboard_clear, | |
183 | 183 | G_OBJECT(widget) |
184 | 184 | )) |
185 | 185 | { |
... | ... | @@ -192,53 +192,3 @@ void v3270_update_system_clipboard(GtkWidget *widget) |
192 | 192 | v3270_emit_copy_state(widget); |
193 | 193 | |
194 | 194 | } |
195 | - | |
196 | -void v3270_set_copy_target(GtkWidget *widget, const gchar *target, guint flags, guint info) { | |
197 | - | |
198 | - v3270 * terminal = GTK_V3270(widget); | |
199 | - | |
200 | - if(!terminal->selection.blocks) | |
201 | - { | |
202 | - // No clipboard data, return. | |
203 | - v3270_emit_copy_state(widget); | |
204 | - return; | |
205 | - } | |
206 | - | |
207 | - // Has clipboard data, inform system. | |
208 | - GtkClipboard * clipboard = gtk_widget_get_clipboard(widget,terminal->selection.target); | |
209 | - | |
210 | - GtkTargetList * list = gtk_target_list_new(NULL,0); | |
211 | - | |
212 | - GtkTargetEntry entry = { | |
213 | - .target = (char *) target, | |
214 | - .flags = flags, | |
215 | - .info = info | |
216 | - }; | |
217 | - | |
218 | - gtk_target_list_add_table(list, &entry, 1); | |
219 | - | |
220 | - int n_targets; | |
221 | - GtkTargetEntry * targets = gtk_target_table_new_from_list(list, &n_targets); | |
222 | - | |
223 | - if(gtk_clipboard_set_with_owner( | |
224 | - clipboard, | |
225 | - targets, | |
226 | - n_targets, | |
227 | - (GtkClipboardGetFunc) clipboard_get, | |
228 | - (GtkClipboardClearFunc) clipboard_clear, | |
229 | - G_OBJECT(widget) | |
230 | - )) | |
231 | - { | |
232 | - gtk_clipboard_set_can_store(clipboard,targets,1); | |
233 | - } | |
234 | - | |
235 | - gtk_target_table_free(targets, n_targets); | |
236 | - gtk_target_list_unref(list); | |
237 | - v3270_emit_copy_state(widget); | |
238 | -} | |
239 | - | |
240 | -LIB3270_EXPORT void v3270_copy_as_html(GtkWidget *widget) { | |
241 | - debug("%s(%p)",__FUNCTION__,widget); | |
242 | - v3270_set_copy_target(widget,"text/html", 0, CLIPBOARD_TYPE_HTML); | |
243 | -} | |
244 | - | ... | ... |