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

Method SetFocusedWidget

src/window.cpp:487–504  ·  view source on GitHub ↗

* Set focus within this window to the given widget. The function however doesn't change which window has focus. * @param widget_index Index of the widget in the window to set the focus to. * @return Focus has changed. */

Source from the content-addressed store, hash-verified

485 * @return Focus has changed.
486 */
487bool Window::SetFocusedWidget(WidgetID widget_index)
488{
489 NWidgetCore *widget = this->GetWidget<NWidgetCore>(widget_index);
490 assert(widget != nullptr); /* Setting focus to a non-existing widget is a bad idea. */
491
492 if (this->nested_focus != nullptr) {
493 /* Do nothing if widget_index is already focused. */
494 if (widget == this->nested_focus) return false;
495
496 /* Repaint the widget that lost focus. A focused edit box may else leave the caret on the screen. */
497 this->nested_focus->SetDirty(this);
498 if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxLostFocus();
499 }
500
501 this->nested_focus = widget;
502 if (this->nested_focus->type == WWT_EDITBOX) VideoDriver::GetInstance()->EditBoxGainedFocus();
503 return true;
504}
505
506std::string Window::GetWidgetString([[maybe_unused]] WidgetID widget, StringID stringid) const
507{

Callers 15

OnHotkeyMethod · 0.95
SignWindowMethod · 0.80
UpdateSignEditWindowMethod · 0.80
SaveLoadWindowMethod · 0.80
NewGRFWindowMethod · 0.80
SavePresetWindowMethod · 0.80
OskWindowMethod · 0.80
DispatchLeftClickEventFunction · 0.80
OnClickMethod · 0.80
QueryStringWindowMethod · 0.80
OnHotkeyMethod · 0.80
SetTabMethod · 0.80

Calls 3

SetDirtyMethod · 0.45
EditBoxLostFocusMethod · 0.45
EditBoxGainedFocusMethod · 0.45

Tested by

no test coverage detected