Changeset c9722c1 in mainline for uspace/lib/ui/src/entry.c
- Timestamp:
- 2021-07-20T00:18:59Z (3 years ago)
- Branches:
- master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 282c86d
- Parents:
- 9eb8d12
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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;
Note:
See TracChangeset
for help on using the changeset viewer.