Commit d1a0641a9194fabb76593e39ade1365f11473acf
1 parent
52166de6
Exists in
master
and in
5 other branches
Implementando seleção por campo/palavra direto na biblioteca.
Showing
6 changed files
with
76 additions
and
24 deletions
Show diff stats
src/include/lib3270/selection.h
| ... | ... | @@ -33,8 +33,9 @@ |
| 33 | 33 | |
| 34 | 34 | #define LIB3270_SELECTION_H_INCLUDED 1 |
| 35 | 35 | |
| 36 | - LIB3270_EXPORT void lib3270_clear_selection(H3270 *session); | |
| 37 | - LIB3270_EXPORT void lib3270_select_to(H3270 *session, int baddr); | |
| 38 | - | |
| 36 | + LIB3270_EXPORT void lib3270_clear_selection(H3270 *session); | |
| 37 | + LIB3270_EXPORT void lib3270_select_to(H3270 *session, int baddr); | |
| 38 | + LIB3270_EXPORT void lib3270_select_word(H3270 *session, int baddr); | |
| 39 | + LIB3270_EXPORT int lib3270_select_field(H3270 *session, int baddr); | |
| 39 | 40 | |
| 40 | 41 | #endif // LIB3270_SELECTION_H_INCLUDED | ... | ... |
src/lib3270/api.h
| ... | ... | @@ -383,7 +383,8 @@ |
| 383 | 383 | const char *description; |
| 384 | 384 | }; |
| 385 | 385 | |
| 386 | - LOCAL_EXTERN int Register3270ScreenCallbacks(const struct lib3270_screen_callbacks *cbk); | |
| 386 | + // LOCAL_EXTERN int Register3270ScreenCallbacks(const struct lib3270_screen_callbacks *cbk); | |
| 387 | + LOCAL_EXTERN void ring_bell(void); | |
| 387 | 388 | |
| 388 | 389 | #define new_3270_session(m) lib3270_session_new(m) |
| 389 | 390 | |
| ... | ... | @@ -395,8 +396,23 @@ |
| 395 | 396 | LOCAL_EXTERN void show_3270_popup_dialog(H3270 *session, PW3270_DIALOG type, const char *title, const char *msg, const char *fmt, ...); |
| 396 | 397 | |
| 397 | 398 | /* Set/Get screen contents */ |
| 398 | - LOCAL_EXTERN int find_field_attribute(H3270 *session, int baddr); | |
| 399 | - LOCAL_EXTERN int find_field_length(H3270 *session, int baddr); | |
| 399 | + #define find_field_attribute(s,a) lib3270_field_addr(s,a) | |
| 400 | + #define find_field_length(s,a) find_field_length(s,a) | |
| 401 | + | |
| 402 | + /** | |
| 403 | + * Find the buffer address of the field attribute for a given buffer address. | |
| 404 | + * | |
| 405 | + * @param h Session handle. | |
| 406 | + * @param addr Buffer address of the field. | |
| 407 | + * | |
| 408 | + * @return field address or -1 if the screen isn't formatted. | |
| 409 | + * | |
| 410 | + */ | |
| 411 | + LIB3270_EXPORT int lib3270_field_addr(H3270 *h, int baddr); | |
| 412 | + | |
| 413 | + LIB3270_EXPORT int lib3270_field_length(H3270 *session, int baddr); | |
| 414 | + | |
| 415 | + | |
| 400 | 416 | LOCAL_EXTERN unsigned char get_field_attribute(H3270 *session, int baddr); |
| 401 | 417 | LOCAL_EXTERN int screen_read(char *dest, int baddr, int count); |
| 402 | 418 | LOCAL_EXTERN void Input_String(const unsigned char *str); | ... | ... |
src/lib3270/ctlr.c
| ... | ... | @@ -320,11 +320,7 @@ static void ctlr_connect(H3270 *session, int ignored unused, void *dunno) |
| 320 | 320 | |
| 321 | 321 | |
| 322 | 322 | |
| 323 | -/* | |
| 324 | - * Find the buffer address of the field attribute for a given buffer address. | |
| 325 | - * Returns -1 if the screen isn't formatted. | |
| 326 | - */ | |
| 327 | -int find_field_attribute(H3270 *h, int baddr) | |
| 323 | +LIB3270_EXPORT int lib3270_field_addr(H3270 *h, int baddr) | |
| 328 | 324 | { |
| 329 | 325 | int sbaddr; |
| 330 | 326 | |
| ... | ... | @@ -334,18 +330,20 @@ int find_field_attribute(H3270 *h, int baddr) |
| 334 | 330 | return -1; |
| 335 | 331 | |
| 336 | 332 | sbaddr = baddr; |
| 337 | - do { | |
| 333 | + do | |
| 334 | + { | |
| 338 | 335 | if (ea_buf[baddr].fa) |
| 339 | 336 | return baddr; |
| 340 | 337 | DEC_BA(baddr); |
| 341 | 338 | } while (baddr != sbaddr); |
| 339 | + | |
| 342 | 340 | return -1; |
| 343 | 341 | } |
| 344 | 342 | |
| 345 | 343 | /* |
| 346 | 344 | * Get Field width |
| 347 | 345 | */ |
| 348 | -int find_field_length(H3270 *h, int baddr) | |
| 346 | +int lib3270_field_length(H3270 *h, int baddr) | |
| 349 | 347 | { |
| 350 | 348 | int saddr; |
| 351 | 349 | int addr; | ... | ... |
src/lib3270/lib3270.cbp
| ... | ... | @@ -7,8 +7,8 @@ |
| 7 | 7 | <Option compiler="gcc" /> |
| 8 | 8 | <Build> |
| 9 | 9 | <Target title="Debug"> |
| 10 | - <Option output=".bin/Debug/lib3270" prefix_auto="1" extension_auto="1" /> | |
| 11 | - <Option object_output=".obj/Debug/" /> | |
| 10 | + <Option output=".bin\Debug\lib3270" prefix_auto="1" extension_auto="1" /> | |
| 11 | + <Option object_output=".obj\Debug\" /> | |
| 12 | 12 | <Option type="1" /> |
| 13 | 13 | <Option compiler="gcc" /> |
| 14 | 14 | <Option use_console_runner="0" /> |
| ... | ... | @@ -21,8 +21,8 @@ |
| 21 | 21 | </Linker> |
| 22 | 22 | </Target> |
| 23 | 23 | <Target title="Release"> |
| 24 | - <Option output=".bin/Release/lib3270" prefix_auto="1" extension_auto="1" /> | |
| 25 | - <Option object_output=".obj/Release/" /> | |
| 24 | + <Option output=".bin\Release\lib3270" prefix_auto="1" extension_auto="1" /> | |
| 25 | + <Option object_output=".obj\Release\" /> | |
| 26 | 26 | <Option type="3" /> |
| 27 | 27 | <Option compiler="gcc" /> |
| 28 | 28 | <Option createDefFile="1" /> |
| ... | ... | @@ -35,8 +35,8 @@ |
| 35 | 35 | </Linker> |
| 36 | 36 | </Target> |
| 37 | 37 | <Target title="testprogram"> |
| 38 | - <Option output=".bin/Debug/lib3270" prefix_auto="1" extension_auto="1" /> | |
| 39 | - <Option object_output=".obj/testprogram/" /> | |
| 38 | + <Option output=".bin\Debug\lib3270" prefix_auto="1" extension_auto="1" /> | |
| 39 | + <Option object_output=".obj\testprogram\" /> | |
| 40 | 40 | <Option type="1" /> |
| 41 | 41 | <Option compiler="gcc" /> |
| 42 | 42 | <Option use_console_runner="0" /> |
| ... | ... | @@ -53,10 +53,12 @@ |
| 53 | 53 | <Add option="-Wmissing-declarations" /> |
| 54 | 54 | <Add option="-Wall" /> |
| 55 | 55 | <Add option="-DLIB3270=1" /> |
| 56 | - <Add directory="../include" /> | |
| 57 | - <Add directory="../include/lib3270" /> | |
| 56 | + <Add directory="..\include" /> | |
| 57 | + <Add directory="..\include\lib3270" /> | |
| 58 | 58 | </Compiler> |
| 59 | - <Unit filename="../include/lib3270/config.h.in" /> | |
| 59 | + <Unit filename="..\include\lib3270.h" /> | |
| 60 | + <Unit filename="..\include\lib3270\config.h.in" /> | |
| 61 | + <Unit filename="..\include\lib3270\selection.h" /> | |
| 60 | 62 | <Unit filename="3270ds.h" /> |
| 61 | 63 | <Unit filename="Makefile.in" /> |
| 62 | 64 | <Unit filename="X11keysym.h" /> | ... | ... |
src/lib3270/screenc.h
| ... | ... | @@ -27,7 +27,6 @@ |
| 27 | 27 | #define screen_80() /* */ |
| 28 | 28 | |
| 29 | 29 | |
| 30 | -LIB3270_INTERNAL void ring_bell(void); | |
| 31 | 30 | LIB3270_INTERNAL void screen_erase(H3270 *session); |
| 32 | 31 | LIB3270_INTERNAL void screen_changed(H3270 *session, int bstart, int bend); |
| 33 | 32 | LIB3270_INTERNAL int screen_init(H3270 *session); | ... | ... |
src/lib3270/selection.c
| ... | ... | @@ -178,7 +178,6 @@ LIB3270_EXPORT void lib3270_clear_selection(H3270 *session) |
| 178 | 178 | |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | - | |
| 182 | 181 | LIB3270_EXPORT void lib3270_select_to(H3270 *session, int baddr) |
| 183 | 182 | { |
| 184 | 183 | CHECK_SESSION_HANDLE(session); |
| ... | ... | @@ -195,3 +194,40 @@ LIB3270_EXPORT void lib3270_select_to(H3270 *session, int baddr) |
| 195 | 194 | |
| 196 | 195 | } |
| 197 | 196 | |
| 197 | +LIB3270_EXPORT void lib3270_select_word(H3270 *session, int baddr) | |
| 198 | +{ | |
| 199 | + int pos, len; | |
| 200 | + | |
| 201 | + CHECK_SESSION_HANDLE(session); | |
| 202 | + | |
| 203 | + for(pos = baddr; pos > 0 && !isspace(ea_buf[pos].chr);pos--); | |
| 204 | + session->selected.begin = pos; | |
| 205 | + | |
| 206 | + len = session->rows * session->cols; | |
| 207 | + for(pos = baddr; pos < len && !isspace(ea_buf[pos].chr);pos++); | |
| 208 | + session->selected.end = pos; | |
| 209 | + | |
| 210 | + update_selected_region(session); | |
| 211 | +} | |
| 212 | + | |
| 213 | +LIB3270_EXPORT int lib3270_select_field(H3270 *session, int baddr) | |
| 214 | +{ | |
| 215 | + int start; | |
| 216 | + | |
| 217 | + CHECK_SESSION_HANDLE(session); | |
| 218 | + | |
| 219 | + start = lib3270_field_addr(session,baddr); | |
| 220 | + | |
| 221 | + if(start < 0) | |
| 222 | + { | |
| 223 | + ring_bell(); | |
| 224 | + return -1; | |
| 225 | + } | |
| 226 | + | |
| 227 | + session->selected.begin = start; | |
| 228 | + session->selected.end = start + lib3270_field_length(session,start); | |
| 229 | + | |
| 230 | + update_selected_region(session); | |
| 231 | + | |
| 232 | + return 0; | |
| 233 | +} | ... | ... |