* Process keypress for editbox widget. * @param wid Editbox widget. * @param key the Unicode value of the key. * @param keycode the untranslated key code including shift state. * @return #ES_HANDLED if the key press has been handled and no other * window should receive the event. */
| 2562 | * window should receive the event. |
| 2563 | */ |
| 2564 | EventState Window::HandleEditBoxKey(WidgetID wid, char32_t key, uint16_t keycode) |
| 2565 | { |
| 2566 | QueryString *query = this->GetQueryString(wid); |
| 2567 | if (query == nullptr) return ES_NOT_HANDLED; |
| 2568 | |
| 2569 | int action = QueryString::ACTION_NOTHING; |
| 2570 | |
| 2571 | switch (query->text.HandleKeyPress(key, keycode)) { |
| 2572 | case HKPR_EDITING: |
| 2573 | this->SetWidgetDirty(wid); |
| 2574 | this->OnEditboxChanged(wid); |
| 2575 | break; |
| 2576 | |
| 2577 | case HKPR_CURSOR: |
| 2578 | this->SetWidgetDirty(wid); |
| 2579 | /* For the OSK also invalidate the parent window */ |
| 2580 | if (this->window_class == WC_OSK) this->InvalidateData(); |
| 2581 | break; |
| 2582 | |
| 2583 | case HKPR_CONFIRM: |
| 2584 | if (this->window_class == WC_OSK) { |
| 2585 | this->OnClick(Point(), WID_OSK_OK, 1); |
| 2586 | } else if (query->ok_button >= 0) { |
| 2587 | this->OnClick(Point(), query->ok_button, 1); |
| 2588 | } else { |
| 2589 | action = query->ok_button; |
| 2590 | } |
| 2591 | break; |
| 2592 | |
| 2593 | case HKPR_CANCEL: |
| 2594 | if (this->window_class == WC_OSK) { |
| 2595 | this->OnClick(Point(), WID_OSK_CANCEL, 1); |
| 2596 | } else if (query->cancel_button >= 0) { |
| 2597 | this->OnClick(Point(), query->cancel_button, 1); |
| 2598 | } else { |
| 2599 | action = query->cancel_button; |
| 2600 | } |
| 2601 | break; |
| 2602 | |
| 2603 | case HKPR_NOT_HANDLED: |
| 2604 | return ES_NOT_HANDLED; |
| 2605 | |
| 2606 | default: break; |
| 2607 | } |
| 2608 | |
| 2609 | switch (action) { |
| 2610 | case QueryString::ACTION_DESELECT: |
| 2611 | this->UnfocusFocusedWidget(); |
| 2612 | break; |
| 2613 | |
| 2614 | case QueryString::ACTION_CLEAR: |
| 2615 | if (query->text.GetText().empty()) { |
| 2616 | /* If already empty, unfocus instead */ |
| 2617 | this->UnfocusFocusedWidget(); |
| 2618 | } else { |
| 2619 | query->text.DeleteAll(); |
| 2620 | this->SetWidgetDirty(wid); |
| 2621 | this->OnEditboxChanged(wid); |
no test coverage detected