Changeset c9722c1 in mainline
- Timestamp:
- 2021-07-20T00:18:59Z (4 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 282c86d
- Parents:
- 9eb8d12
- Location:
- uspace/lib/ui
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/include/ui/entry.h
r9eb8d12 rc9722c1 55 55 extern void ui_entry_backspace(ui_entry_t *); 56 56 extern void ui_entry_delete(ui_entry_t *); 57 extern void ui_entry_copy(ui_entry_t *); 58 extern void ui_entry_cut(ui_entry_t *); 59 extern void ui_entry_paste(ui_entry_t *); 57 60 extern void ui_entry_seek_start(ui_entry_t *, bool); 58 61 extern void ui_entry_seek_end(ui_entry_t *, bool); -
uspace/lib/ui/private/entry.h
r9eb8d12 rc9722c1 80 80 81 81 extern errno_t ui_entry_insert_str(ui_entry_t *, const char *); 82 extern ui_evclaim_t ui_entry_key_press_ctrl(ui_entry_t *, kbd_event_t *); 82 83 extern ui_evclaim_t ui_entry_key_press_shift(ui_entry_t *, kbd_event_t *); 83 84 extern ui_evclaim_t ui_entry_key_press_unmod(ui_entry_t *, kbd_event_t *); -
uspace/lib/ui/src/entry.c
r9eb8d12 rc9722c1 37 37 */ 38 38 39 #include <clipboard.h> 39 40 #include <errno.h> 40 41 #include <gfx/context.h> … … 553 554 } 554 555 556 /** Copy selected text to clipboard. 557 * 558 * @param entry Text entry 559 */ 560 void ui_entry_copy(ui_entry_t *entry) 561 { 562 unsigned off1; 563 unsigned off2; 564 char c; 565 566 off1 = min(entry->pos, entry->sel_start); 567 off2 = max(entry->pos, entry->sel_start); 568 569 c = entry->text[off2]; 570 entry->text[off2] = '\0'; 571 572 (void) clipboard_put_str(entry->text + off1); 573 574 entry->text[off2] = c; 575 } 576 577 /** Cut selected text to clipboard. 578 * 579 * @param entry Text entry 580 */ 581 void ui_entry_cut(ui_entry_t *entry) 582 { 583 ui_entry_copy(entry); 584 ui_entry_delete_sel(entry); 585 } 586 587 /** Paste text from clipboard. 588 * 589 * @param entry Text entry 590 */ 591 void ui_entry_paste(ui_entry_t *entry) 592 { 593 char *str; 594 errno_t rc; 595 596 rc = clipboard_get_str(&str); 597 if (rc != EOK) 598 return; 599 600 ui_entry_insert_str(entry, str); 601 free(str); 602 } 603 555 604 /** Handle text entry key press without modifiers. 556 605 * … … 626 675 break; 627 676 677 default: 678 break; 679 } 680 681 return ui_claimed; 682 } 683 684 /** Handle text entry key press with control modifier. 685 * 686 * @param entry Text entry 687 * @param kbd_event Keyboard event 688 * @return @c ui_claimed iff the event is claimed 689 */ 690 ui_evclaim_t ui_entry_key_press_ctrl(ui_entry_t *entry, kbd_event_t *event) 691 { 692 assert(event->type == KEY_PRESS); 693 694 switch (event->key) { 695 case KC_C: 696 ui_entry_copy(entry); 697 break; 698 case KC_V: 699 ui_entry_paste(entry); 700 break; 701 case KC_X: 702 ui_entry_cut(entry); 703 break; 628 704 default: 629 705 break; … … 665 741 (event->mods & (KM_CTRL | KM_ALT)) == 0) 666 742 return ui_entry_key_press_shift(entry, event); 743 744 if (event->type == KEY_PRESS && 745 (event->mods & KM_CTRL) != 0 && 746 (event->mods & (KM_ALT | KM_SHIFT)) == 0) 747 return ui_entry_key_press_ctrl(entry, event); 667 748 668 749 return ui_claimed; -
uspace/lib/ui/test/entry.c
r9eb8d12 rc9722c1 27 27 */ 28 28 29 #include <clipboard.h> 29 30 #include <gfx/context.h> 30 31 #include <gfx/coord.h> … … 487 488 } 488 489 490 /** ui_entry_copy() copies selected text to clipboard. */ 491 PCUT_TEST(copy) 492 { 493 errno_t rc; 494 ui_t *ui = NULL; 495 ui_window_t *window = NULL; 496 ui_wnd_params_t params; 497 ui_entry_t *entry; 498 char *str; 499 500 rc = ui_create_disp(NULL, &ui); 501 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 502 503 ui_wnd_params_init(¶ms); 504 params.caption = "Hello"; 505 506 rc = ui_window_create(ui, ¶ms, &window); 507 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 508 PCUT_ASSERT_NOT_NULL(window); 509 510 rc = ui_entry_create(window, "ABCDEF", &entry); 511 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 512 513 ui_entry_activate(entry); 514 ui_entry_seek_start(entry, false); 515 ui_entry_seek_next_char(entry, false); 516 ui_entry_seek_end(entry, true); 517 ui_entry_seek_prev_char(entry, true); 518 519 // FIXME: This is not safe unless we could create a private 520 // test clipboard 521 522 ui_entry_copy(entry); 523 rc = clipboard_get_str(&str); 524 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 525 PCUT_ASSERT_STR_EQUALS("BCDE", str); 526 PCUT_ASSERT_STR_EQUALS("ABCDEF", entry->text); 527 free(str); 528 529 ui_entry_destroy(entry); 530 ui_window_destroy(window); 531 ui_destroy(ui); 532 } 533 534 /** ui_entry_cut() cuts selected text to clipboard. */ 535 PCUT_TEST(cut) 536 { 537 errno_t rc; 538 ui_t *ui = NULL; 539 ui_window_t *window = NULL; 540 ui_wnd_params_t params; 541 ui_entry_t *entry; 542 char *str; 543 544 rc = ui_create_disp(NULL, &ui); 545 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 546 547 ui_wnd_params_init(¶ms); 548 params.caption = "Hello"; 549 550 rc = ui_window_create(ui, ¶ms, &window); 551 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 552 PCUT_ASSERT_NOT_NULL(window); 553 554 rc = ui_entry_create(window, "ABCDEF", &entry); 555 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 556 557 ui_entry_activate(entry); 558 ui_entry_seek_start(entry, false); 559 ui_entry_seek_next_char(entry, false); 560 ui_entry_seek_end(entry, true); 561 ui_entry_seek_prev_char(entry, true); 562 563 // FIXME: This is not safe unless we could create a private 564 // test clipboard 565 566 ui_entry_cut(entry); 567 rc = clipboard_get_str(&str); 568 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 569 PCUT_ASSERT_STR_EQUALS("BCDE", str); 570 PCUT_ASSERT_STR_EQUALS("AF", entry->text); 571 free(str); 572 573 ui_entry_destroy(entry); 574 ui_window_destroy(window); 575 ui_destroy(ui); 576 } 577 578 /** ui_entry_paste() pastes text from clipboard. */ 579 PCUT_TEST(paste) 580 { 581 errno_t rc; 582 ui_t *ui = NULL; 583 ui_window_t *window = NULL; 584 ui_wnd_params_t params; 585 ui_entry_t *entry; 586 587 rc = ui_create_disp(NULL, &ui); 588 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 589 590 ui_wnd_params_init(¶ms); 591 params.caption = "Hello"; 592 593 rc = ui_window_create(ui, ¶ms, &window); 594 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 595 PCUT_ASSERT_NOT_NULL(window); 596 597 rc = ui_entry_create(window, "AB", &entry); 598 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 599 600 ui_entry_activate(entry); 601 ui_entry_seek_start(entry, false); 602 ui_entry_seek_next_char(entry, false); 603 604 // FIXME: This is not safe unless we could create a private 605 // test clipboard 606 607 rc = clipboard_put_str("123"); 608 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 609 610 ui_entry_paste(entry); 611 PCUT_ASSERT_STR_EQUALS("A123B", entry->text); 612 613 ui_entry_destroy(entry); 614 ui_window_destroy(window); 615 ui_destroy(ui); 616 } 617 489 618 /** ui_entry_seek_start() moves cursor to beginning of text */ 490 619 PCUT_TEST(seek_start) … … 506 635 PCUT_ASSERT_NOT_NULL(window); 507 636 508 rc = ui_entry_create(window, "ABCD", &entry); 509 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 510 511 PCUT_ASSERT_STR_EQUALS("ABCD", entry->text); 637 rc = ui_entry_create(window, "ABCDEF", &entry); 638 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 639 640 ui_entry_activate(entry); 641 512 642 entry->pos = 2; 513 643 entry->sel_start = 2;
Note:
See TracChangeset
for help on using the changeset viewer.