MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / HandleEditBoxKey

Method HandleEditBoxKey

src/window.cpp:2564–2630  ·  view source on GitHub ↗

* 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. */

Source from the content-addressed store, hash-verified

2562 * window should receive the event.
2563 */
2564EventState 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);

Callers 1

HandleKeypressFunction · 0.80

Calls 10

GetQueryStringMethod · 0.95
SetWidgetDirtyMethod · 0.95
OnEditboxChangedMethod · 0.95
InvalidateDataMethod · 0.95
OnClickMethod · 0.95
UnfocusFocusedWidgetMethod · 0.95
HandleKeyPressMethod · 0.80
DeleteAllMethod · 0.80
emptyMethod · 0.45
GetTextMethod · 0.45

Tested by

no test coverage detected