Commit a4e0ef9b2f3c76edde28ae22e3b6ff78e6e6a497
1 parent
228b06a6
Exists in
master
and in
5 other branches
Iniciando implementação de seleção acessível
Showing
7 changed files
with
165 additions
and
24 deletions
Show diff stats
src/gtk/actions.c
| ... | ... | @@ -307,7 +307,7 @@ static void action_select_field(GtkAction *action, GtkWidget *widget) |
| 307 | 307 | |
| 308 | 308 | static void action_select_none(GtkAction *action, GtkWidget *widget) |
| 309 | 309 | { |
| 310 | - lib3270_unselect(v3270_get_session(widget)); | |
| 310 | + v3270_unselect(widget); | |
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | static void action_select_last(GtkAction *action, GtkWidget *widget) | ... | ... |
src/gtk/print.c
| ... | ... | @@ -501,7 +501,7 @@ static gchar * enum_to_string(GType type, guint enum_value) |
| 501 | 501 | |
| 502 | 502 | trace("Action %s activated on widget %p",gtk_action_get_name(action),widget); |
| 503 | 503 | |
| 504 | - if(lib3270_get_selected_addr(info->session,&start,&end)) | |
| 504 | + if(!lib3270_get_selection_bounds(info->session,&start,&end)) | |
| 505 | 505 | { |
| 506 | 506 | g_warning("Can't get selected addresses for action %s",gtk_action_get_name(action)); |
| 507 | 507 | g_object_unref(print); | ... | ... |
src/gtk/v3270/accessible.c
| ... | ... | @@ -431,6 +431,40 @@ static gboolean v3270_set_caret_offset(AtkText *text, gint offset) |
| 431 | 431 | return TRUE; |
| 432 | 432 | } |
| 433 | 433 | |
| 434 | +static gboolean v3270_accessible_remove_selection(AtkText *text, gint selection_num) | |
| 435 | +{ | |
| 436 | + GtkWidget * widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text)); | |
| 437 | + | |
| 438 | + if (widget == NULL || selection_num != 0) | |
| 439 | + return FALSE; | |
| 440 | + | |
| 441 | + v3270_unselect(widget); | |
| 442 | + | |
| 443 | + return TRUE; | |
| 444 | +} | |
| 445 | + | |
| 446 | +static gint v3270_accessible_get_n_selections (AtkText *text) | |
| 447 | +{ | |
| 448 | + GtkWidget *widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text)); | |
| 449 | + | |
| 450 | + if(!widget) | |
| 451 | + return 0; | |
| 452 | + | |
| 453 | + return v3270_get_selection_bounds(widget, NULL, NULL) ? 1 : 0; | |
| 454 | +} | |
| 455 | + | |
| 456 | +static gchar * v3270_accessible_get_selection (AtkText *atk_text, gint selection_num, gint *start_pos, gint *end_pos) | |
| 457 | +{ | |
| 458 | + GtkWidget *widget = gtk_accessible_get_widget(GTK_ACCESSIBLE (atk_text)); | |
| 459 | + | |
| 460 | + if (widget == NULL ||selection_num != 0) | |
| 461 | + return NULL; | |
| 462 | + | |
| 463 | + if(v3270_get_selection_bounds(widget, start_pos, end_pos)) | |
| 464 | + return v3270_get_region(widget, *start_pos, *end_pos, FALSE); | |
| 465 | + | |
| 466 | + return NULL; | |
| 467 | +} | |
| 434 | 468 | static void atk_text_interface_init(AtkTextIface *iface) |
| 435 | 469 | { |
| 436 | 470 | iface->get_text = v3270_accessible_get_text; |
| ... | ... | @@ -444,14 +478,18 @@ static void atk_text_interface_init(AtkTextIface *iface) |
| 444 | 478 | |
| 445 | 479 | iface->get_character_extents = v3270_accessible_get_character_extents; |
| 446 | 480 | iface->get_offset_at_point = v3270_accessible_get_offset_at_point; |
| 481 | + iface->remove_selection = v3270_accessible_remove_selection; | |
| 482 | + | |
| 483 | + iface->get_n_selections = v3270_accessible_get_n_selections; | |
| 484 | + iface->get_selection = v3270_accessible_get_selection; | |
| 447 | 485 | |
| 448 | 486 | /* |
| 487 | +http://git.gnome.org/browse/gtk+/tree/gtk/a11y/gtklabelaccessible.c | |
| 488 | + | |
| 449 | 489 | iface->get_text_before_offset = gtk_label_accessible_get_text_before_offset; |
| 450 | 490 | |
| 451 | 491 | iface->get_text_after_offset = gtk_label_accessible_get_text_after_offset; |
| 452 | 492 | |
| 453 | - iface->get_n_selections = gtk_label_accessible_get_n_selections; | |
| 454 | - iface->get_selection = gtk_label_accessible_get_selection; | |
| 455 | 493 | iface->add_selection = gtk_label_accessible_add_selection; |
| 456 | 494 | iface->remove_selection = gtk_label_accessible_remove_selection; |
| 457 | 495 | iface->set_selection = gtk_label_accessible_set_selection; |
| ... | ... | @@ -461,14 +499,12 @@ static void atk_text_interface_init(AtkTextIface *iface) |
| 461 | 499 | */ |
| 462 | 500 | } |
| 463 | 501 | |
| 464 | - | |
| 465 | 502 | static void v3270_accessible_init(v3270Accessible *widget) |
| 466 | 503 | { |
| 467 | - AtkObject *obj = ATK_OBJECT(widget); | |
| 468 | - obj->role = ATK_ROLE_TEXT; | |
| 504 | + AtkObject *obj = ATK_OBJECT(widget); | |
| 505 | + obj->role = ATK_ROLE_TEXT; | |
| 469 | 506 | } |
| 470 | 507 | |
| 471 | - | |
| 472 | 508 | void v3270_accessible_get_extents(AtkComponent *component, gint *x, gint *y,gint *width,gint *height, AtkCoordType coord_type) |
| 473 | 509 | { |
| 474 | 510 | GtkWidget *widget = gtk_accessible_get_widget(GTK_ACCESSIBLE (component)); |
| ... | ... | @@ -546,18 +582,33 @@ static gboolean v3270_accessible_grab_focus(AtkComponent *component) |
| 546 | 582 | return TRUE; |
| 547 | 583 | } |
| 548 | 584 | |
| 585 | +static AtkLayer v3270_accessible_get_layer (AtkComponent *component) | |
| 586 | +{ | |
| 587 | + return ATK_LAYER_WIDGET; | |
| 588 | +} | |
| 589 | + | |
| 590 | +static gboolean v3270_accessible_set_size(AtkComponent *component, gint width, gint height) | |
| 591 | +{ | |
| 592 | + GtkWidget *widget = gtk_accessible_get_widget(GTK_ACCESSIBLE (component)); | |
| 593 | + | |
| 594 | + if (widget == NULL) | |
| 595 | + return FALSE; | |
| 596 | + | |
| 597 | + gtk_widget_set_size_request(widget, width, height); | |
| 598 | + return TRUE; | |
| 599 | +} | |
| 549 | 600 | |
| 550 | 601 | static void atk_component_interface_init(AtkComponentIface *iface) |
| 551 | 602 | { |
| 552 | 603 | iface->get_extents = v3270_accessible_get_extents; |
| 553 | 604 | iface->get_size = v3270_accessible_get_size; |
| 554 | 605 | iface->grab_focus = v3270_accessible_grab_focus; |
| 606 | + iface->get_layer = v3270_accessible_get_layer; | |
| 607 | + iface->set_size = v3270_accessible_set_size; | |
| 555 | 608 | |
| 556 | 609 | /* |
| 557 | - iface->get_layer = gtk_widget_accessible_get_layer; | |
| 558 | 610 | iface->set_extents = gtk_widget_accessible_set_extents; |
| 559 | 611 | iface->set_position = gtk_widget_accessible_set_position; |
| 560 | - iface->set_size = gtk_widget_accessible_set_size; | |
| 561 | 612 | */ |
| 562 | 613 | } |
| 563 | 614 | ... | ... |
src/gtk/v3270/clipboard.c
| ... | ... | @@ -438,3 +438,33 @@ void v3270_paste(GtkWidget *widget) |
| 438 | 438 | gtk_clipboard_request_text(gtk_widget_get_clipboard(widget,GDK_SELECTION_CLIPBOARD),(GtkClipboardTextReceivedFunc) text_received,(gpointer) widget); |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | +void v3270_unselect(GtkWidget *widget) | |
| 442 | +{ | |
| 443 | + lib3270_unselect(v3270_get_session(widget)); | |
| 444 | +} | |
| 445 | + | |
| 446 | +gboolean v3270_get_selection_bounds(GtkWidget *widget, gint *start, gint *end) | |
| 447 | +{ | |
| 448 | + g_return_val_if_fail(GTK_IS_V3270(widget),FALSE); | |
| 449 | + return lib3270_get_selection_bounds(GTK_V3270(widget)->host,start,end) == 0 ? FALSE : TRUE; | |
| 450 | +} | |
| 451 | + | |
| 452 | +gchar * v3270_get_region(GtkWidget *widget, gint start_pos, gint end_pos, gboolean all) | |
| 453 | +{ | |
| 454 | + char * str; | |
| 455 | + gchar * utftext; | |
| 456 | + | |
| 457 | + g_return_val_if_fail(GTK_IS_V3270(widget),NULL); | |
| 458 | + | |
| 459 | + str = lib3270_get_region(GTK_V3270(widget)->host,start_pos,end_pos,all); | |
| 460 | + if(!str) | |
| 461 | + return NULL; | |
| 462 | + | |
| 463 | + utftext = g_convert(str, -1, "UTF-8", lib3270_get_charset(GTK_V3270(widget)->host), NULL, NULL, NULL); | |
| 464 | + | |
| 465 | + free(str); | |
| 466 | + | |
| 467 | + return utftext; | |
| 468 | +} | |
| 469 | + | |
| 470 | + | ... | ... |
src/gtk/v3270/v3270.h
| ... | ... | @@ -156,7 +156,11 @@ |
| 156 | 156 | const gchar * v3270_get_selected_text(GtkWidget *widget); |
| 157 | 157 | const gchar * v3270_get_copy(GtkWidget *widget); |
| 158 | 158 | gchar * v3270_get_text(GtkWidget *widget,int offset, int len); |
| 159 | + gchar * v3270_get_region(GtkWidget *widget, gint start_pos, gint end_pos, gboolean all); | |
| 159 | 160 | |
| 161 | + // Cut & Paste | |
| 162 | + gboolean v3270_get_selection_bounds(GtkWidget *widget, gint *start, gint *end); | |
| 163 | + void v3270_unselect(GtkWidget *widget); | |
| 160 | 164 | void v3270_paste(GtkWidget *widget); |
| 161 | 165 | void v3270_paste_string(GtkWidget *widget, const gchar *text, const gchar *encoding); |
| 162 | 166 | ... | ... |
src/include/lib3270/selection.h
| ... | ... | @@ -101,16 +101,16 @@ |
| 101 | 101 | LIB3270_EXPORT int lib3270_drag_selection(H3270 *h, unsigned char flag, int origin, int baddr); |
| 102 | 102 | |
| 103 | 103 | /** |
| 104 | - * Get addresses of selected area. | |
| 104 | + * Gets the selected range of characters in the screen | |
| 105 | 105 | * |
| 106 | 106 | * @param h Session handle. |
| 107 | - * @param begin Pointer to the begin value. | |
| 108 | - * @param end Pointer to the end value. | |
| 107 | + * @param start return location for start of selection, as a character offset. | |
| 108 | + * @param end return location for end of selection, as a character offset. | |
| 109 | 109 | * |
| 110 | - * @return 0 if the selected area was get, non zero if unselected or unavailable. | |
| 110 | + * @return Non 0 if selection is non-empty | |
| 111 | 111 | * |
| 112 | 112 | */ |
| 113 | - LIB3270_EXPORT int lib3270_get_selected_addr(H3270 *hSession, int *begin, int *end); | |
| 113 | + LIB3270_EXPORT int lib3270_get_selection_bounds(H3270 *hSession, int *start, int *end); | |
| 114 | 114 | |
| 115 | 115 | /** |
| 116 | 116 | * Get bitmasked flag for the current selection. |
| ... | ... | @@ -124,4 +124,17 @@ |
| 124 | 124 | */ |
| 125 | 125 | LIB3270_EXPORT unsigned char lib3270_get_selection_flags(H3270 *h, int baddr); |
| 126 | 126 | |
| 127 | + /** | |
| 128 | + * Get a string from required region. | |
| 129 | + * | |
| 130 | + * @param h Session handle. | |
| 131 | + * @param start_pos First char to get. | |
| 132 | + * @param end_pos Last char to get. | |
| 133 | + * @param all zero to get only selected chars. | |
| 134 | + * | |
| 135 | + * @return String with selected region (release it with free() | |
| 136 | + * | |
| 137 | + */ | |
| 138 | + LIB3270_EXPORT char * lib3270_get_region(H3270 *h, int start_pos, int end_pos, unsigned char all); | |
| 139 | + | |
| 127 | 140 | #endif // LIB3270_SELECTION_H_INCLUDED | ... | ... |
src/lib3270/selection.c
| ... | ... | @@ -407,6 +407,41 @@ static char * get_text(H3270 *hSession,unsigned char all) |
| 407 | 407 | return ret; |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | +LIB3270_EXPORT char * lib3270_get_region(H3270 *h, int start_pos, int end_pos, unsigned char all) | |
| 411 | +{ | |
| 412 | + char * text; | |
| 413 | + int maxlen; | |
| 414 | + int sz = 0; | |
| 415 | + int baddr; | |
| 416 | + | |
| 417 | + CHECK_SESSION_HANDLE(h); | |
| 418 | + | |
| 419 | + if(!lib3270_connected(h)) | |
| 420 | + return NULL; | |
| 421 | + | |
| 422 | + maxlen = h->rows * (h->cols+1); | |
| 423 | + | |
| 424 | + if(start_pos < 0 || start_pos > maxlen || end_pos < 0 || end_pos > maxlen || end_pos < start_pos) | |
| 425 | + return NULL; | |
| 426 | + | |
| 427 | + text = malloc(maxlen); | |
| 428 | + | |
| 429 | + for(baddr=start_pos;baddr<end_pos;baddr++) | |
| 430 | + { | |
| 431 | + if(all || h->text[baddr].attr & LIB3270_ATTR_SELECTED) | |
| 432 | + text[sz++] = (h->text[baddr].attr & LIB3270_ATTR_CG) ? ' ' : h->text[baddr].chr; | |
| 433 | + | |
| 434 | + if((baddr%h->cols) == 0 && sz > 0) | |
| 435 | + text[sz++] = '\n'; | |
| 436 | + } | |
| 437 | + text[sz++] = 0; | |
| 438 | + | |
| 439 | + return realloc(text,sz); | |
| 440 | +} | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 410 | 445 | LIB3270_EXPORT char * lib3270_get_text(H3270 *h, int offset, int len) |
| 411 | 446 | { |
| 412 | 447 | char * buffer; |
| ... | ... | @@ -468,25 +503,33 @@ LIB3270_EXPORT char * lib3270_get_selected(H3270 *hSession) |
| 468 | 503 | return get_text(hSession,0); |
| 469 | 504 | } |
| 470 | 505 | |
| 471 | -LIB3270_EXPORT int lib3270_get_selected_addr(H3270 *hSession, int *begin, int *end) | |
| 506 | +LIB3270_EXPORT int lib3270_get_selection_bounds(H3270 *hSession, int *start, int *end) | |
| 472 | 507 | { |
| 508 | + int first, last; | |
| 509 | + | |
| 473 | 510 | CHECK_SESSION_HANDLE(hSession); |
| 474 | 511 | |
| 475 | 512 | if(!hSession->selected || hSession->select.begin == hSession->select.end) |
| 476 | - return -1; | |
| 513 | + return 0; | |
| 477 | 514 | |
| 478 | 515 | if(hSession->select.end > hSession->select.begin) |
| 479 | 516 | { |
| 480 | - *begin = hSession->select.begin; | |
| 481 | - *end = hSession->select.end; | |
| 517 | + first = hSession->select.begin; | |
| 518 | + last = hSession->select.end; | |
| 482 | 519 | } |
| 483 | 520 | else |
| 484 | 521 | { |
| 485 | - *begin = hSession->select.end; | |
| 486 | - *end = hSession->select.begin; | |
| 522 | + first = hSession->select.end; | |
| 523 | + last = hSession->select.begin; | |
| 487 | 524 | } |
| 488 | 525 | |
| 489 | - return 0; | |
| 526 | + if(start) | |
| 527 | + *start = first; | |
| 528 | + | |
| 529 | + if(end) | |
| 530 | + *end = last; | |
| 531 | + | |
| 532 | + return 1; | |
| 490 | 533 | } |
| 491 | 534 | |
| 492 | 535 | LIB3270_EXPORT int lib3270_move_selected_area(H3270 *hSession, int from, int to) |
| ... | ... | @@ -494,7 +537,7 @@ LIB3270_EXPORT int lib3270_move_selected_area(H3270 *hSession, int from, int to) |
| 494 | 537 | int pos[2]; |
| 495 | 538 | int rows, cols, f, step; |
| 496 | 539 | |
| 497 | - if(lib3270_get_selected_addr(hSession,&pos[0],&pos[1])) | |
| 540 | + if(!lib3270_get_selection_bounds(hSession,&pos[0],&pos[1])) | |
| 498 | 541 | return from; |
| 499 | 542 | |
| 500 | 543 | rows = (to / hSession->cols) - (from / hSession->cols); |
| ... | ... | @@ -533,7 +576,7 @@ LIB3270_EXPORT int lib3270_drag_selection(H3270 *h, unsigned char flag, int orig |
| 533 | 576 | { |
| 534 | 577 | int first, last, row, col; |
| 535 | 578 | |
| 536 | - if(lib3270_get_selected_addr(h,&first,&last)) | |
| 579 | + if(!lib3270_get_selection_bounds(h,&first,&last)) | |
| 537 | 580 | return origin; |
| 538 | 581 | |
| 539 | 582 | flag &= 0x1f; | ... | ... |