Commit 9d289f73759f8666f5d9d7558ca500a7cd52c257
1 parent
877b74f9
Exists in
master
and in
3 other branches
Implementando "paste"
Showing
3 changed files
with
96 additions
and
38 deletions
Show diff stats
paste.c
@@ -32,14 +32,17 @@ | @@ -32,14 +32,17 @@ | ||
32 | 32 | ||
33 | #include "globals.h" | 33 | #include "globals.h" |
34 | 34 | ||
35 | -#if defined(X3270_DISPLAY) /*[*/ | ||
36 | -#include <X11/Xatom.h> | 35 | +/* |
36 | +#if defined(X3270_DISPLAY) | ||
37 | + #include <X11/Xatom.h> | ||
37 | #endif | 38 | #endif |
39 | +*/ | ||
40 | + | ||
38 | #define XK_3270 | 41 | #define XK_3270 |
39 | -#if defined(X3270_APL) /*[*/ | ||
40 | -#define XK_APL | ||
41 | -#endif /*]*/ | ||
42 | -//#include <X11/keysym.h> | 42 | + |
43 | +#if defined(X3270_APL) | ||
44 | + #define XK_APL | ||
45 | +#endif | ||
43 | 46 | ||
44 | #include <fcntl.h> | 47 | #include <fcntl.h> |
45 | #include "3270ds.h" | 48 | #include "3270ds.h" |
@@ -53,17 +56,18 @@ | @@ -53,17 +56,18 @@ | ||
53 | #include "ctlrc.h" | 56 | #include "ctlrc.h" |
54 | #include "ftc.h" | 57 | #include "ftc.h" |
55 | #include "hostc.h" | 58 | #include "hostc.h" |
56 | -// #include "idlec.h" | ||
57 | -// #include "keymapc.h" | ||
58 | #include "keypadc.h" | 59 | #include "keypadc.h" |
59 | #include "kybdc.h" | 60 | #include "kybdc.h" |
60 | -// #include "macrosc.h" | ||
61 | #include "popupsc.h" | 61 | #include "popupsc.h" |
62 | #include "printc.h" | 62 | #include "printc.h" |
63 | #include "screenc.h" | 63 | #include "screenc.h" |
64 | -// #if defined(X3270_DISPLAY) /*[*/ | ||
65 | -// #include "selectc.h" | ||
66 | -// #endif /*]*/ | 64 | + |
65 | +/* | ||
66 | +#if defined(X3270_DISPLAY) | ||
67 | + #include "selectc.h" | ||
68 | +#endif | ||
69 | +*/ | ||
70 | + | ||
67 | #include "statusc.h" | 71 | #include "statusc.h" |
68 | #include "tablesc.h" | 72 | #include "tablesc.h" |
69 | #include "telnetc.h" | 73 | #include "telnetc.h" |
@@ -76,6 +80,8 @@ | @@ -76,6 +80,8 @@ | ||
76 | #endif /*]*/ | 80 | #endif /*]*/ |
77 | #include "api.h" | 81 | #include "api.h" |
78 | 82 | ||
83 | +#include <lib3270/popup.h> | ||
84 | + | ||
79 | /*---[ Struct ]-------------------------------------------------------------------------------------------------*/ | 85 | /*---[ Struct ]-------------------------------------------------------------------------------------------------*/ |
80 | 86 | ||
81 | typedef struct _paste_data | 87 | typedef struct _paste_data |
@@ -157,6 +163,15 @@ | @@ -157,6 +163,15 @@ | ||
157 | return c; | 163 | return c; |
158 | } | 164 | } |
159 | 165 | ||
166 | +/** | ||
167 | + * Set string at cursor position. | ||
168 | + * | ||
169 | + * @param h Session handle. | ||
170 | + * @param str String to set | ||
171 | + * | ||
172 | + * @return Number of characters inserted; <0 in case of error. | ||
173 | + * | ||
174 | + */ | ||
160 | LIB3270_EXPORT int lib3270_set_string(H3270 *h, const unsigned char *str) | 175 | LIB3270_EXPORT int lib3270_set_string(H3270 *h, const unsigned char *str) |
161 | { | 176 | { |
162 | PASTE_DATA data; | 177 | PASTE_DATA data; |
@@ -218,3 +233,62 @@ LIB3270_EXPORT int lib3270_set_string(H3270 *h, const unsigned char *str) | @@ -218,3 +233,62 @@ LIB3270_EXPORT int lib3270_set_string(H3270 *h, const unsigned char *str) | ||
218 | screen_resume(h); | 233 | screen_resume(h); |
219 | return data.qtd; | 234 | return data.qtd; |
220 | } | 235 | } |
236 | + | ||
237 | +LIB3270_EXPORT int lib3270_paste(H3270 *h, const char *str) | ||
238 | +{ | ||
239 | + int sz; | ||
240 | + CHECK_SESSION_HANDLE(h); | ||
241 | + | ||
242 | + if(!lib3270_connected(h)) | ||
243 | + { | ||
244 | + lib3270_ring_bell(h); | ||
245 | + return 0; | ||
246 | + } | ||
247 | + | ||
248 | + if(h->paste_buffer) | ||
249 | + { | ||
250 | + free(h->paste_buffer); | ||
251 | + h->paste_buffer = NULL; | ||
252 | + } | ||
253 | + | ||
254 | + sz = lib3270_set_string(h,str); | ||
255 | + if(sz < 0) | ||
256 | + { | ||
257 | + // Can´t paste | ||
258 | + lib3270_popup_dialog(h,LIB3270_NOTIFY_WARNING, | ||
259 | + _( "Action failed" ), | ||
260 | + _( "Unable to paste text" ), | ||
261 | + "%s", sz == -EINVAL ? _( "Keyboard is locked" ) : _( "Unexpected error" ) ); | ||
262 | + return 0; | ||
263 | + } | ||
264 | + | ||
265 | + if(strlen(str) > sz) | ||
266 | + { | ||
267 | + h->paste_buffer = strdup(str+sz); | ||
268 | + return 1; | ||
269 | + } | ||
270 | + | ||
271 | + return 0; | ||
272 | +} | ||
273 | + | ||
274 | +LIB3270_EXPORT int lib3270_pastenext(H3270 *h) | ||
275 | +{ | ||
276 | + char * ptr; | ||
277 | + int rc; | ||
278 | + | ||
279 | + CHECK_SESSION_HANDLE(h); | ||
280 | + | ||
281 | + if(!(lib3270_connected(h) && h->paste_buffer)) | ||
282 | + { | ||
283 | + lib3270_ring_bell(h); | ||
284 | + return 0; | ||
285 | + } | ||
286 | + | ||
287 | + ptr = h->paste_buffer; | ||
288 | + h->paste_buffer = NULL; | ||
289 | + | ||
290 | + rc = lib3270_paste(h,ptr); | ||
291 | + | ||
292 | + free(ptr); | ||
293 | + return rc; | ||
294 | +} |
screen.c
@@ -787,3 +787,13 @@ LIB3270_EXPORT void lib3270_set_popup_handler(int (*handler)(H3270 *, LIB3270_NO | @@ -787,3 +787,13 @@ LIB3270_EXPORT void lib3270_set_popup_handler(int (*handler)(H3270 *, LIB3270_NO | ||
787 | popup_handler = handler ? handler : logpopup; | 787 | popup_handler = handler ? handler : logpopup; |
788 | } | 788 | } |
789 | 789 | ||
790 | +LIB3270_EXPORT lib3270_popup_dialog(H3270 *session, LIB3270_NOTIFY id , const char *title, const char *message, const char *fmt, ...) | ||
791 | +{ | ||
792 | + va_list args; | ||
793 | + | ||
794 | + CHECK_SESSION_HANDLE(session); | ||
795 | + | ||
796 | + va_start(args, fmt); | ||
797 | + popup_handler(session,id,title ? title : _( "3270 Error" ), message,fmt,args); | ||
798 | + va_end(args); | ||
799 | +} |
selection.c
@@ -345,29 +345,3 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) | @@ -345,29 +345,3 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) | ||
345 | return realloc(ret,sz+1); | 345 | return realloc(ret,sz+1); |
346 | } | 346 | } |
347 | 347 | ||
348 | -LIB3270_EXPORT int lib3270_paste(H3270 *h, const char *str) | ||
349 | -{ | ||
350 | - CHECK_SESSION_HANDLE(h); | ||
351 | - | ||
352 | - if(!lib3270_connected(h)) | ||
353 | - { | ||
354 | - lib3270_ring_bell(h); | ||
355 | - return 0; | ||
356 | - } | ||
357 | - | ||
358 | - return 0; | ||
359 | -} | ||
360 | - | ||
361 | -LIB3270_EXPORT int lib3270_pastenext(H3270 *h) | ||
362 | -{ | ||
363 | - CHECK_SESSION_HANDLE(h); | ||
364 | - | ||
365 | - if(!(lib3270_connected(h) && h->paste_buffer)) | ||
366 | - { | ||
367 | - lib3270_ring_bell(h); | ||
368 | - return 0; | ||
369 | - } | ||
370 | - | ||
371 | - | ||
372 | - return 0; | ||
373 | -} |