# Window Struct Reference

Data structure for an opened window. More...

`#include <window_gui.h>`

Inheritance diagram for Window:

## Public Types
enum | EventState { ES_HANDLED, ES_NOT_HANDLED }
| State whether an event is handled or not. More...
## Public Member Functions
| Window ()
| Empty constructor, initialization has been moved to InitNested() called from the constructor of the derived class.
virtual | ~Window ()
| Remove window and all its child windows from the window stack.
FORCEINLINE void * | operator new[] (size_t size)
| Helper allocation function to disallow something.
FORCEINLINE void | operator delete (void *ptr)
| Helper allocation function to disallow something.
template<class NWID>
const NWID * | GetWidget (uint widnum) const
| Specialized case of Window::GetWidget for the nested widget base class.
template<class NWID>
NWID * | GetWidget (uint widnum)
| Get the nested widget with number widnum from the nested widget tree.
void | InitNested (const WindowDesc *desc, WindowNumber number=0)
| Perform complete initialization of the Window with nested widgets, to allow use.
void | CreateNestedTree (const WindowDesc *desc, bool fill_nested=true)
| Perform the first part of the initialization of a nested widget tree.
void | FinishInitNested (const WindowDesc *desc, WindowNumber window_number)
| Perform the second part of the initialization of a nested widget tree.
void | SetWidgetDisabledState (byte widget_index, bool disab_stat)
| Sets the enabled/disabled status of a widget.
void | DisableWidget (byte widget_index)
| Sets a widget to disabled.
void | EnableWidget (byte widget_index)
| Sets a widget to Enabled.
bool | IsWidgetDisabled (byte widget_index) const
| Gets the enabled/disabled status of a widget.
bool | IsWidgetFocused (byte widget_index) const
| Check if given widget is focused within this window.
bool | IsWidgetGloballyFocused (byte widget_index) const
| Check if given widget has user input focus.
void | SetWidgetLoweredState (byte widget_index, bool lowered_stat)
| Sets the lowered/raised status of a widget.
void | ToggleWidgetLoweredState (byte widget_index)
| Invert the lowered/raised status of a widget.
void | LowerWidget (byte widget_index)
| Marks a widget as lowered.
void | RaiseWidget (byte widget_index)
| Marks a widget as raised.
bool | IsWidgetLowered (byte widget_index) const
| Gets the lowered state of a widget.
void | UnfocusFocusedWidget ()
| Makes no widget on this window have focus.
bool | SetFocusedWidget (byte widget_index)
| Set focus within this window to the given widget.
void | HandleButtonClick (byte widget)
| Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
void | RaiseButtons (bool autoraise=false)
| Raise the buttons of the window.
void CDECL | SetWidgetsDisabledState (bool disab_stat, int widgets,...)
| Sets the enabled/disabled status of a list of widgets.
void CDECL | SetWidgetsLoweredState (bool lowered_stat, int widgets,...)
| Sets the lowered/raised status of a list of widgets.
void | SetWidgetDirty (byte widget_index) const
| Invalidate a widget, i.e.
void | DrawWidgets () const
| Paint all widgets of a window.
void | DrawViewport () const
| Draw the viewport of this window.
void | DrawSortButtonState (int widget, SortButtonState state) const
| Draw a sort button's up or down arrow symbol.
void | DeleteChildWindows (WindowClass wc=WC_INVALID) const
| Delete all children a window might have in a head-recursive manner.
void | SetDirty () const
| Mark entire window as dirty (in need of re-paint).
void | ReInit (int rx=0, int ry=0)
| Re-initialize a window, and optionally change its size.
bool | IsShaded () const
| Is window shaded currently?
void | SetShaded (bool make_shaded)
| Set the shaded state of the window to make_shaded.
void | InvalidateData (int data=0)
| Mark this window's data as invalid (in need of re-computing).
virtual void | OnInit ()
| Notification that the nested widget tree gets initialized.
virtual Point | OnInitialPosition (const WindowDesc *desc, int16 sm_width, int16 sm_height, int window_number)
| Compute the initial position of the window.
virtual void | OnPaint ()
| The window must be repainted.
virtual void | DrawWidget (const Rect &r, int widget) const
| Draw the contents of a nested widget.
virtual void | UpdateWidgetSize (int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
| Update size and resize step of a widget in the window.
virtual void | SetStringParameters (int widget) const
| Initialize string parameters for a widget.
virtual void | OnFocus ()
| Called when window gains focus.
virtual void | OnFocusLost ()
| Called when window looses focus.
virtual EventState | OnKeyPress (uint16 key, uint16 keycode)
| A key has been pressed.
virtual EventState | OnCTRLStateChange ()
| The state of the control key has changed.
virtual void | OnClick (Point pt, int widget)
| A click with the left mouse button has been made on the window.
virtual void | OnDoubleClick (Point pt, int widget)
| A double click with the left mouse button has been made on the window.
virtual void | OnRightClick (Point pt, int widget)
| A click with the right mouse button has been made on the window.
virtual void | OnDragDrop (Point pt, int widget)
| A dragged 'object' has been released.
virtual void | OnScroll (Point delta)
| Handle the request for (viewport) scrolling.
virtual void | OnMouseOver (Point pt, int widget)
| The mouse is currently moving over the window or has just moved outside of the window.
virtual void | OnMouseWheel (int wheel)
| The mouse wheel has been turned.
virtual void | OnMouseLoop ()
| Called for every mouse loop run, which is at least once per (game) tick.
virtual void | OnTick ()
| Called once per (game) tick.
virtual void | OnHundredthTick ()
| Called once every 100 (game) ticks.
virtual void | OnTimeout ()
| Called when this window's timeout has been reached.
virtual void | OnResize ()
| Called after the window got resized.
virtual void | OnDropdownSelect (int widget, int index)
| A dropdown option associated to this window has been selected.
virtual void | OnQueryTextFinished (char *str)
| The query window opened from this window has closed.
virtual void | OnInvalidateData (int data=0)
| Some data on this window has become invalid.
virtual void | OnPlaceObject (Point pt, TileIndex tile)
| The user clicked some place on the map when a tile highlight mode has been set.
virtual void | OnPlaceObjectAbort ()
| The user cancelled a tile highlight mode that has been set.
virtual void | OnPlaceDrag (ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt)
| The user is dragging over the map when the tile highlight mode has been set.
virtual void | OnPlaceMouseUp (ViewportPlaceMethod select_method, ViewportDragDropSelectionProcess select_proc, Point pt, TileIndex start_tile, TileIndex end_tile)
| The user has dragged over the map when the tile highlight mode has been set.
virtual void | OnPlacePresize (Point pt, TileIndex tile)
| The user moves over the map when a tile highlight mode has been set when the special mouse mode has been set to 'PRESIZE' mode.
## Data Fields
uint16 | flags4
| Window flags,.
WindowClass | window_class
| Window class.
WindowNumber | window_number
| Window number within the window class.
int | left
| x position of left edge of the window
int | top
| y position of top edge of the window
int | width
| width of the window (number of pixels to the right in x direction)
int | height
| Height of the window (number of pixels down in y direction).
Scrollbar | hscroll
| Horizontal scroll bar.
Scrollbar | vscroll
| First vertical scroll bar.
Scrollbar | vscroll2
| Second vertical scroll bar.
ResizeInfo | resize
| Resize information.
Owner | owner
| The owner of the content shown in this window. Company colour is acquired from this variable.
ViewportData * | viewport
| Pointer to viewport data, if present.
uint32 | desc_flags
| Window/widgets default flags setting.
const NWidgetCore * | nested_focus
| Currently focused nested widget, or `NULL` if no nested widget has focus.
NWidgetBase * | nested_root
| Root of the nested tree.
NWidgetBase ** | nested_array
| Array of pointers into the tree. Do not access directly, use Window::GetWidget() instead.
uint | nested_array_size
| Size of the nested array.
NWidgetStacked * | shade_select
| Selection widget (NWID_SELECTION) to use for shading the window. If `NULL`, window cannot shade.
Dimension | unshaded_size
| Last known unshaded size (only valid while shaded).
Window * | parent
| Parent window.
Window * | z_front
| The window in front of us in z-order.
Window * | z_back
| The window behind us in z-order.
## Protected Member Functions
void | InitializeData (WindowClass cls, int window_number, uint32 desc_flags)
| Initializes the data (except the position and initial size) of a new Window.
void | InitializePositionSize (int x, int y, int min_width, int min_height)
| Set the position and smallest size of the window.
void | FindWindowPlacementAndResize (int def_width, int def_height)
| Resize window towards the default size.

## Detailed Description

Data structure for an opened window.

Definition at line 332 of file window_gui.h.

## Member Enumeration Documentation

enum Window::EventState

State whether an event is handled or not.

Enumerator:

  ES_HANDLED | The passed event is handled.
  ES_NOT_HANDLED | The passed event is not handled.

Definition at line 334 of file window_gui.h.

## Constructor & Destructor Documentation

Window::Window | ( |  | ) |

Empty constructor, initialization has been moved to InitNested() called from the constructor of the derived class.

Definition at line 1255 of file window.cpp.

## Member Function Documentation

void Window::InitializeData | ( | WindowClass | cls,
|  | int | window_number,
|  | uint32 | desc_flags |
| ) |  |  | `[protected]`

Initializes the data (except the position and initial size) of a new Window.

Parameters:

  | cls | Class of the window, used for identification and grouping.

See also:
  WindowClass

Parameters:

  | window_number | Number being assigned to the new window
  | desc_flags | Window flags.

See also:
  WindowDefaultFlag

Returns:
  Window pointer of the newly created window

Precondition:
  If nested widgets are used (widget is `NULL`), nested_root and nested_array_size must be initialized. In addition, nested_array is either `NULL`, or already initialized.

Definition at line 845 of file window.cpp.

References _dynlang, NWidgetBase::AssignSizePosition(), EditBoxInGlobalFocus(), FindWindowByClass(), FindWindowById(), flags4, NWidgetBase::GetWidgetOfType(), INVALID_OWNER, nested_array, nested_array_size, nested_focus, nested_root, OnInit(), owner, resize, NWidgetBase::resize_x, NWidgetBase::resize_y, SetFocusedWindow(), NWidgetBase::SetupSmallestSize(), NWidgetBase::smallest_x, ST_SMALLEST, ResizeInfo::step_height, ResizeInfo::step_width, TD_RTL, DynamicLanguages::text_dir, window_class, WWT_EDITBOX, z_back, and z_front.

Referenced by FinishInitNested().

void Window::InitializePositionSize | ( | int | x,
|  | int | y,
|  | int | sm_width,
|  | int | sm_height |
| ) |  |  | `[protected]`

Set the position and smallest size of the window.

Parameters:

  | x | Offset in pixels from the left of the screen of the new window.
  | y | Offset in pixels from the top of the screen of the new window.
  | sm_width | Smallest width in pixels of the window.
  | sm_height | Smallest height in pixels of the window.

Definition at line 924 of file window.cpp.

References height, left, top, and width.

Referenced by FinishInitNested().

void Window::FindWindowPlacementAndResize | ( | int | def_width,
|  | int | def_height |
| ) |  |  | `[protected]`

Resize window towards the default size.

Prior to construction, a position for the new window (for its default size) has been found with LocalGetWindowPlacement(). Initially, the window is constructed with minimal size. Resizing the window to its default size is done here.

Parameters:

  | def_width | default width in pixels of the window
  | def_height | default height in pixels of the window

See also:
  Window::Window(), Window::InitializeData(), Window::InitializePositionSize()

Definition at line 942 of file window.cpp.

References FindWindowById(), DrawPixelInfo::height, height, ViewPort::left, left, max(), min(), OnResize(), resize, ResizeWindow(), SetDirty(), ResizeInfo::step_height, ResizeInfo::step_width, ViewPort::top, top, viewport, DrawPixelInfo::width, and width.

Referenced by FinishInitNested().

FORCEINLINE void* Window::operator new[] | ( | size_t | size | ) | `[inline]`

Helper allocation function to disallow something.

Don't allow arrays; arrays of Windows are pointless as you need to destruct them all at the same time too, which is kinda hard.

Parameters:

  | size | the amount of space not to allocate

Reimplemented from ZeroedMemoryAllocator.

Definition at line 355 of file window_gui.h.

FORCEINLINE void Window::operator delete | ( | void * | ptr | ) | `[inline]`

Helper allocation function to disallow something.

Don't free the window directly; it corrupts the linked list when iterating

Parameters:

  | ptr | the pointer not to free

Reimplemented from ZeroedMemoryAllocator.

Definition at line 365 of file window_gui.h.

template<class NWID>

const NWID * Window::GetWidget | ( | uint | widnum | ) | const`[inline]`

Specialized case of Window::GetWidget for the nested widget base class.

Get the nested widget with number widnum from the nested widget tree.

Template Parameters:

  | NWID | Type of the nested widget.

Parameters:

  | widnum | Widget number of the widget to retrieve.

Returns:
  The requested widget if it is instantiated, `NULL` otherwise.

Definition at line 811 of file window_gui.h.

Referenced by NWidgetLeaf::FindScrollbar(), NWidgetBackground::FindScrollbar(), Scrollbar::SetCapacityFromWidget(), and ShowDropDownList().

template<class NWID>

NWID * Window::GetWidget | ( | uint | widnum | ) | `[inline]`

Get the nested widget with number widnum from the nested widget tree.

Template Parameters:

  | NWID | Type of the nested widget.

Parameters:

  | widnum | Widget number of the widget to retrieve.

Returns:
  The requested widget if it is instantiated, `NULL` otherwise.

Definition at line 789 of file window_gui.h.

References nested_array, and nested_array_size.

void Window::InitNested | ( | const WindowDesc * | desc,
|  | WindowNumber | window_number = `0` |
| ) |  |  |

Perform complete initialization of the Window with nested widgets, to allow use.

Parameters:

  | desc | Window description.
  | window_number | Number of the new window.

Definition at line 1248 of file window.cpp.

References CreateNestedTree(), and FinishInitNested().

Referenced by SetDateWindow::SetDateWindow(), and VehicleDetailsWindow::VehicleDetailsWindow().

void Window::CreateNestedTree | ( | const WindowDesc * | desc,
|  | bool | fill_nested = `true` |
| ) |  |  |

Perform the first part of the initialization of a nested widget tree.

Construct a nested widget tree in nested_root, and optionally fill the nested_array array to provide quick access to the uninitialized widgets. This is mainly useful for setting very basic properties.

Parameters:

  | desc | Window description.
  | fill_nested | Fill the nested_array (enabling is expensive!).

Note:
  Filling the nested array requires an additional traversal through the nested widget tree, and is best performed by FinishInitNested rather than here.

Definition at line 1218 of file window.cpp.

References NWidgetBase::FillNestedArray(), MakeWindowNWidgetTree(), nested_array, nested_array_size, nested_root, WindowDesc::nwid_length, and WindowDesc::nwid_parts.

Referenced by InitNested().

void Window::FinishInitNested | ( | const WindowDesc * | desc,
|  | WindowNumber | window_number |
| ) |  |  |

Perform the second part of the initialization of a nested widget tree.

Parameters:

  | desc | Window description.
  | window_number | Number of the new window.

Definition at line 1235 of file window.cpp.

References WindowDesc::cls, WindowDesc::default_height, WindowDesc::default_width, FindWindowPlacementAndResize(), WindowDesc::flags, InitializeData(), InitializePositionSize(), nested_root, OnInitialPosition(), NWidgetBase::smallest_x, Point::x, and Point::y.

Referenced by InitNested().

void Window::SetWidgetDisabledState | ( | byte | widget_index,
|  | bool | disab_stat |
| ) |  |  | `[inline]`

Sets the enabled/disabled status of a widget.

By default, widgets are enabled. On certain conditions, they have to be disabled.

Parameters:

  | widget_index | index of this widget in the window
  | disab_stat | status to use ie: disabled = true, enabled = false

Definition at line 415 of file window_gui.h.

References nested_array, and nested_array_size.

Referenced by DisableWidget(), EnableWidget(), HandleZoomMessage(), BuildIndustryWindow::OnClick(), NewGRFWindow::OnInvalidateData(), NewGRFAddWindow::OnInvalidateData(), BuildIndustryWindow::OnInvalidateData(), AIConfigWindow::OnInvalidateData(), VehicleDetailsWindow::OnPaint(), VehicleListWindow::OnPaint(), TownAuthorityWindow::OnPaint(), StationViewWindow::OnPaint(), CompanyWindow::OnPaint(), SelectCompanyLiveryWindow::OnPaint(), CompanyFinancesWindow::OnPaint(), AIDebugWindow::OnPaint(), BuildIndustryWindow::OnTick(), and SetWidgetsDisabledState().

void Window::DisableWidget | ( | byte | widget_index | ) | `[inline]`

Sets a widget to disabled.

Parameters:

  | widget_index | index of this widget in the window

Definition at line 425 of file window_gui.h.

References SetWidgetDisabledState().

Referenced by NewGRFWindow::OnInvalidateData(), VehicleDetailsWindow::OnPaint(), CompanyWindow::OnPaint(), and AIDebugWindow::OnPaint().

void Window::EnableWidget | ( | byte | widget_index | ) | `[inline]`

Sets a widget to Enabled.

Parameters:

  | widget_index | index of this widget in the window

Definition at line 434 of file window_gui.h.

References SetWidgetDisabledState().

bool Window::IsWidgetDisabled | ( | byte | widget_index | ) | const`[inline]`

Gets the enabled/disabled status of a widget.

Parameters:

  | widget_index | index of this widget in the window

Returns:
  status of the widget ie: disabled = true, enabled = false

Definition at line 444 of file window_gui.h.

References nested_array_size.

Referenced by BuildRailClick_Remove(), BuildRoadClick_OneWay(), HandlePlacePushButton(), AIDebugWindow::OnClick(), RailToolbar_CtrlChanged(), and RoadToolbar_CtrlChanged().

bool Window::IsWidgetFocused | ( | byte | widget_index | ) | const`[inline]`

Check if given widget is focused within this window.

Parameters:

  | widget_index | : index of the widget in the window to check

Returns:
  true if given widget is the focused window in this window

Definition at line 455 of file window_gui.h.

References NWidgetCore::index, and nested_focus.

Referenced by IsWidgetGloballyFocused().

bool Window::IsWidgetGloballyFocused | ( | byte | widget_index | ) | const`[inline]`

Check if given widget has user input focus.

This means that both the window has focus and that the given widget has focus within the window.

Parameters:

  | widget_index | : index of the widget in the window to check

Returns:
  true if given widget is the focused window in this window and this window has focus

Definition at line 466 of file window_gui.h.

References IsWidgetFocused().

void Window::SetWidgetLoweredState | ( | byte | widget_index,
|  | bool | lowered_stat |
| ) |  |  | `[inline]`

Sets the lowered/raised status of a widget.

Parameters:

  | widget_index | index of this widget in the window
  | lowered_stat | status to use ie: lowered = true, raised = false

Definition at line 476 of file window_gui.h.

References nested_array_size.

Referenced by LowerWidget(), FoundTownWindow::OnClick(), SmallMapWindow::OnClick(), SelectCompanyManagerFaceWindow::OnPaint(), RaiseWidget(), and SetWidgetsLoweredState().

void Window::ToggleWidgetLoweredState | ( | byte | widget_index | ) | `[inline]`

Invert the lowered/raised status of a widget.

Parameters:

  | widget_index | index of this widget in the window

Definition at line 486 of file window_gui.h.

References nested_array_size.

Referenced by BuildRoadClick_OneWay(), OrdersWindow::OrderClick_Goto(), ToggleRailButton_Remove(), and ToggleRoadButton_Remove().

void Window::LowerWidget | ( | byte | widget_index | ) | `[inline]`

Marks a widget as lowered.

Parameters:

  | widget_index | index of this widget in the window

Definition at line 497 of file window_gui.h.

References SetWidgetLoweredState().

Referenced by HandleButtonClick(), HandlePlacePushButton(), BuildTreesWindow::OnClick(), SmallMapWindow::OnClick(), CompanyWindow::OnClick(), SelectCompanyLiveryWindow::OnClick(), AIDebugWindow::OnPaint(), OrdersWindow::OrderClick_Conditional(), and ShowDropDownList().

void Window::RaiseWidget | ( | byte | widget_index | ) | `[inline]`

Marks a widget as raised.

Parameters:

  | widget_index | index of this widget in the window

Definition at line 506 of file window_gui.h.

References SetWidgetLoweredState().

Referenced by SmallMapWindow::OnClick(), SelectCompanyLiveryWindow::OnClick(), AIDebugWindow::OnPaint(), OrdersWindow::OnPlaceObjectAbort(), BuildTreesWindow::OnTimeout(), FoundTownWindow::OnTimeout(), OrdersWindow::OnTimeout(), AIDebugWindow::OnTimeout(), RaiseButtons(), and ResetSignalVariant().

bool Window::IsWidgetLowered | ( | byte | widget_index | ) | const`[inline]`

Gets the lowered state of a widget.

Parameters:

  | widget_index | index of this widget in the window

Returns:
  status of the widget ie: lowered = true, raised= false

Definition at line 516 of file window_gui.h.

References nested_array_size.

Referenced by BuildRailClick_Remove(), DrawSortButtonState(), HandlePlacePushButton(), OrdersWindow::OnMouseLoop(), BuildRailToolbarWindow::OnPlaceDrag(), BuildRailToolbarWindow::OnPlaceMouseUp(), OrdersWindow::OnTimeout(), OrdersWindow::OrderClick_Goto(), RailToolbar_CtrlChanged(), RaiseButtons(), RoadToolbar_CtrlChanged(), ToggleRailButton_Remove(), and ToggleRoadButton_Remove().

void Window::UnfocusFocusedWidget | ( |  | ) |

Makes no widget on this window have focus.

The function however doesn't change which window has focus.

Definition at line 138 of file window.cpp.

References nested_focus, and NWidgetBase::SetDirty().

Referenced by FoundTownWindow::OnKeyPress().

bool Window::SetFocusedWidget | ( | byte | widget_index | ) |

Set focus within this window to the given widget.

The function however doesn't change which window has focus.

Parameters:

  | widget_index | Index of the widget in the window to set the focus to.

Returns:
  Focus has changed.

Definition at line 152 of file window.cpp.

References nested_array, nested_array_size, nested_focus, and NWidgetBase::SetDirty().

Referenced by DispatchLeftClickEvent(), and FoundTownWindow::OnClick().

void Window::HandleButtonClick | ( | byte | widget | ) |

Do all things to make a button look clicked and mark it to be unclicked in a few ticks.

Parameters:

  | widget | the widget to "click"

Definition at line 240 of file window.cpp.

References flags4, LowerWidget(), SetWidgetDirty(), and WF_TIMEOUT_BEGIN.

Referenced by DispatchLeftClickEvent(), FoundTownWindow::OnClick(), SmallMapWindow::OnClick(), and BuildIndustryWindow::OnClick().

void Window::RaiseButtons | ( | bool | autoraise = `false` | ) |

Raise the buttons of the window.

Parameters:

  | autoraise | Raise only the push buttons of the window.

Definition at line 212 of file window.cpp.

References IsWidgetLowered(), nested_array, nested_array_size, RaiseWidget(), SetWidgetDirty(), and WWT_LAST.

Referenced by BuildIndustryWindow::OnClick(), CompanyWindow::OnPlaceObject(), BuildTreesWindow::OnPlaceObjectAbort(), FoundTownWindow::OnPlaceObjectAbort(), BuildIndustryWindow::OnPlaceObjectAbort(), CompanyWindow::OnPlaceObjectAbort(), and BuildIndustryWindow::OnTimeout().

void CDECL Window::SetWidgetsDisabledState | ( | bool | disab_stat,
|  | int | widgets,
|  |  | ... |
| ) |  |  |

Sets the enabled/disabled status of a list of widgets.

By default, widgets are enabled. On certain conditions, they have to be disabled.

Parameters:

  | disab_stat | status to use ie: disabled = true, enabled = false
  | widgets | list of widgets ended by WIDGET_LIST_END

Definition at line 175 of file window.cpp.

References SetWidgetDisabledState(), and WIDGET_LIST_END.

Referenced by VehicleDetailsWindow::OnClick(), NewGRFWindow::OnInvalidateData(), VehicleDetailsWindow::OnPaint(), VehicleListWindow::OnPaint(), and SelectCompanyManagerFaceWindow::OnPaint().

void CDECL Window::SetWidgetsLoweredState | ( | bool | lowered_stat,
|  | int | widgets,
|  |  | ... |
| ) |  |  |

Sets the lowered/raised status of a list of widgets.

Parameters:

  | lowered_stat | status to use ie: lowered = true, raised = false
  | widgets | list of widgets ended by WIDGET_LIST_END

Definition at line 194 of file window.cpp.

References SetWidgetLoweredState(), and WIDGET_LIST_END.

Referenced by SelectCompanyManagerFaceWindow::OnPaint().

void Window::SetWidgetDirty | ( | byte | widget_index | ) | const

Invalidate a widget, i.e.

mark it as being changed and in need of redraw.

Parameters:

  | widget_index | the widget to redraw.

Definition at line 227 of file window.cpp.

References nested_array, and NWidgetBase::SetDirty().

Referenced by IndustryDirectoryWindow::BuildSortIndustriesList(), HandleButtonClick(), HandleZoomMessage(), CompanyWindow::OnClick(), AIDebugWindow::OnPaint(), OrdersWindow::OnPlaceObjectAbort(), BuildTreesWindow::OnTimeout(), OrdersWindow::OnTimeout(), OrdersWindow::OrderClick_Conditional(), OrdersWindow::OrderClick_Goto(), OrdersWindow::OrderClick_Nonstop(), RaiseButtons(), SetWindowWidgetDirty(), ShowDropDownList(), CompanyStationsWindow::SortStationsList(), ToggleRailButton_Remove(), and ToggleRoadButton_Remove().

void Window::DrawSortButtonState | ( | int | widget,
|  | SortButtonState | state |
| ) |  |  | const

Draw a sort button's up or down arrow symbol.

Parameters:

  | widget | Sort button widget
  | state | State of sort button

Definition at line 582 of file widget.cpp.

References _dynlang, NWidgetBase::current_x, DOWNARROW, DrawString(), IsWidgetLowered(), nested_array, NWidgetBase::pos_x, NWidgetBase::pos_y, SA_CENTER, SBS_DOWN, SBS_OFF, TD_LTR, DynamicLanguages::text_dir, top, UPARROW, and WD_SORTBUTTON_ARROW_WIDTH.

Referenced by VehicleListWindow::DrawWidget(), TownDirectoryWindow::DrawWidget(), and IndustryDirectoryWindow::DrawWidget().

void Window::DeleteChildWindows | ( | WindowClass | wc = `WC_INVALID` | ) | const

Delete all children a window might have in a head-recursive manner.

Parameters:

  | wc | Window class of the window to remove; WC_INVALID if class does not matter

Definition at line 602 of file window.cpp.

References FindChildWindow().

Referenced by OrdersWindow::OnClick(), NewGRFWindow::OnClick(), OrdersWindow::OnInvalidateData(), and ~Window().

void Window::ReInit | ( | int | rx = `0`,
|  | int | ry = `0` |
| ) |  |  |

Re-initialize a window, and optionally change its size.

Parameters:

  | rx | Horizontal resize of the window.
  | ry | Vertical resize of the window.

Note:
  For just resizing the window, use ResizeWindow instead.

Definition at line 527 of file window.cpp.

References _dynlang, NWidgetBase::AssignSizePosition(), height, max(), nested_root, OnInit(), OnResize(), resize, NWidgetBase::resize_x, NWidgetBase::resize_y, ResizeWindow(), SetDirty(), NWidgetBase::SetupSmallestSize(), NWidgetBase::smallest_x, NWidgetBase::smallest_y, ST_SMALLEST, ResizeInfo::step_height, ResizeInfo::step_width, TD_RTL, DynamicLanguages::text_dir, and width.

Referenced by BuildRailToolbarWindow::ModifyRailType(), StationViewWindow::OnClick(), SelectCompanyManagerFaceWindow::OnClick(), SelectCompanyLiveryWindow::OnClick(), CompanyFinancesWindow::OnClick(), CompanyFinancesWindow::OnHundredthTick(), SelectCompanyLiveryWindow::OnInvalidateData(), CompanyFinancesWindow::OnPaint(), ReInitAllWindows(), and SetShaded().

void Window::SetShaded | ( | bool | make_shaded | ) |

Set the shaded state of the window to make_shaded.

Parameters:

  | make_shaded | If `true`, shade the window (roll up until just the title bar is visible), else unshade/unroll the window to its original size.

Note:
  The method uses Window::ReInit(), thus after the call, the whole window should be considered changed.

Definition at line 563 of file window.cpp.

References height, Dimension::height, ReInit(), NWidgetStacked::SetDisplayedPlane(), shade_select, NWidgetStacked::shown_plane, SZSP_HORIZONTAL, unshaded_size, width, and Dimension::width.

Referenced by BringWindowToFrontById(), DispatchLeftClickEvent(), DispatchMouseWheelEvent(), and CompanyFinancesWindow::OnClick().

void Window::InvalidateData | ( | int | data = `0` | ) | `[inline]`

Mark this window's data as invalid (in need of re-computing).

Parameters:

  | data | The data to invalidate with

Definition at line 553 of file window_gui.h.

References OnInvalidateData(), and SetDirty().

Referenced by ChangeVehicleWindow(), InvalidateWindowClassesData(), InvalidateWindowData(), NewGRFWindow::OnClick(), NewGRFAddWindow::OnClick(), AIConfigWindow::OnClick(), NewGRFWindow::OnDropdownSelect(), NewGRFAddWindow::OnKeyPress(), QueryStringWindow::OnKeyPress(), and NewGRFWindow::OnQueryTextFinished().

virtual void Window::OnInit | ( |  | ) | `[inline, virtual]`

Notification that the nested widget tree gets initialized.

The event can be used to perform general computations.

Note:
  nested_root and/or nested_array (normally accessed via GetWidget()) may not exist during this call.

Reimplemented in SelectCompanyManagerFaceWindow, and SmallMapWindow.

Definition at line 565 of file window_gui.h.

Referenced by InitializeData(), and ReInit().

Point Window::OnInitialPosition | ( | const WindowDesc * | desc,
|  | int16 | sm_width,
|  | int16 | sm_height,
|  | int | window_number |
| ) |  |  | `[virtual]`

Compute the initial position of the window.

Parameters:

  | *desc | The pointer to the WindowDesc of the window to create.
  | sm_width | Smallest width of the window.
  | sm_height | Smallest height of the window.
  | window_number | The window number of the new window.

Returns:
  Initial position of the top-left corner of the window.

Reimplemented in SetDateWindow, ErrmsgWindow, TooltipsWindow, NewsWindow, and DropdownWindow.

Definition at line 1205 of file window.cpp.

References LocalGetWindowPlacement().

Referenced by FinishInitNested().

virtual void Window::OnPaint | ( |  | ) | `[inline, virtual]`

The window must be repainted.

Note:
  This method should not change any state, it should only use drawing functions.

Reimplemented in AIListWindow, AISettingsWindow, AIConfigWindow, AIDebugWindow, ReplaceVehicleWindow, CompanyFinancesWindow, SelectCompanyLiveryWindow, SelectCompanyManagerFaceWindow, CompanyWindow, SetDateWindow, EndGameWindow, BuildIndustryWindow, IndustryDirectoryWindow, ErrmsgWindow, TooltipsWindow, QueryStringWindow, QueryWindow, NewGRFAddWindow, NewGRFWindow, NewsWindow, OrdersWindow, BuildRailToolbarWindow, SmallMapWindow, CompanyStationsWindow, StationViewWindow, SelectStationWindow< T >, TownAuthorityWindow, TownDirectoryWindow, FoundTownWindow, BuildTreesWindow, RefitWindow, VehicleListWindow, VehicleDetailsWindow, VehicleViewWindow, and DropdownWindow.

Definition at line 581 of file window_gui.h.

Referenced by DrawOverlappedWindow().

virtual void Window::DrawWidget | ( | const Rect & | r,
|  | int | widget |
| ) |  |  | const`[inline, virtual]`

Draw the contents of a nested widget.

Parameters:

  | r | Rectangle occupied by the widget.
  | widget | Number of the widget to draw.

Note:
  This method may not change any state, it may only use drawing functions.

Reimplemented in AIListWindow, AISettingsWindow, AIConfigWindow, AIDebugWindow, ReplaceVehicleWindow, CompanyFinancesWindow, SelectCompanyLiveryWindow, SelectCompanyManagerFaceWindow, CompanyWindow, BuildIndustryWindow, IndustryDirectoryWindow, ErrmsgWindow, TooltipsWindow, QueryWindow, NewGRFAddWindow, NewGRFWindow, NewsWindow, OrdersWindow, SmallMapWindow, CompanyStationsWindow, StationViewWindow, SelectStationWindow< T >, TownAuthorityWindow, TownDirectoryWindow, BuildTreesWindow, RefitWindow, VehicleListWindow, VehicleDetailsWindow, VehicleViewWindow, and DropdownWindow.

Definition at line 589 of file window_gui.h.

Referenced by NWidgetLeaf::Draw(), and NWidgetBackground::Draw().

virtual void Window::UpdateWidgetSize | ( | int | widget,
|  | Dimension * | size,
|  | const Dimension & | padding,
|  | Dimension * | fill,
|  | Dimension * | resize |
| ) |  |  | `[inline, virtual]`

Update size and resize step of a widget in the window.

After retrieval of the minimal size and the resize-steps of a widget, this function is called to allow further refinement, typically by computing the real maximal size of the content. Afterwards, size is taken to be the minimal size of the widget and resize is taken to contain the resize steps. For the convenience of the callee, padding contains the amount of padding between the content and the edge of the widget. This should be added to the returned size.

Parameters:

  | widget | Widget number.
  | size | Size of the widget.
  | padding | Recommended amount of space between the widget content and the widget edge.
  | fill | Fill step of the widget.
  | resize | Resize step of the widget.

Reimplemented in AIListWindow, AISettingsWindow, AIConfigWindow, AIDebugWindow, ReplaceVehicleWindow, CompanyFinancesWindow, SelectCompanyLiveryWindow, SelectCompanyManagerFaceWindow, CompanyWindow, SetDateWindow, BuildIndustryWindow, IndustryDirectoryWindow, ErrmsgWindow, TooltipsWindow, QueryStringWindow, QueryWindow, NewGRFAddWindow, NewGRFWindow, NewsWindow, OrdersWindow, CompanyStationsWindow, StationViewWindow, SelectStationWindow< T >, TownAuthorityWindow, TownDirectoryWindow, BuildTreesWindow, RefitWindow, VehicleListWindow, VehicleDetailsWindow, and VehicleViewWindow.

Definition at line 603 of file window_gui.h.

Referenced by NWidgetLeaf::SetupSmallestSize(), NWidgetBackground::SetupSmallestSize(), and NWidgetStacked::SetupSmallestSize().

virtual void Window::SetStringParameters | ( | int | widget | ) | const`[inline, virtual]`

Initialize string parameters for a widget.

Calls to this function are made during initialization to measure the size (that is as part of InitNested()), during drawing, and while re-initializing the window. Only for widgets that render text initializing is requested.

Parameters:

  | widget | Widget number.

Reimplemented in AIConfigWindow, ReplaceVehicleWindow, CompanyFinancesWindow, SelectCompanyLiveryWindow, CompanyWindow, SetDateWindow, BuildIndustryWindow, IndustryDirectoryWindow, ErrmsgWindow, QueryStringWindow, QueryWindow, NewGRFWindow, NewsWindow, OrdersWindow, SmallMapWindow, CompanyStationsWindow, StationViewWindow, TownAuthorityWindow, TownDirectoryWindow, RefitWindow, VehicleListWindow, VehicleDetailsWindow, and VehicleViewWindow.

Definition at line 611 of file window_gui.h.

Referenced by NWidgetLeaf::Draw(), NWidgetBackground::Draw(), NWidgetLeaf::SetupSmallestSize(), and NWidgetBackground::SetupSmallestSize().

virtual EventState Window::OnKeyPress | ( | uint16 | key,
|  | uint16 | keycode |
| ) |  |  | `[inline, virtual]`

A key has been pressed.

Parameters:

  | key | the Unicode value of the key.
  | keycode | the untranslated key code including shift state.

Returns:
  ES_HANDLED if the key press has been handled and no other window should receive the event.

Reimplemented in ErrmsgWindow, QueryStringWindow, QueryWindow, NewGRFAddWindow, NewsWindow, OrdersWindow, BuildRailToolbarWindow, and FoundTownWindow.

Definition at line 630 of file window_gui.h.

References ES_NOT_HANDLED.

Referenced by HandleKeypress().

virtual EventState Window::OnCTRLStateChange | ( |  | ) | `[inline, virtual]`

The state of the control key has changed.

Returns:
  ES_HANDLED if the change has been handled and no other window should receive the event.

Reimplemented in BuildRailToolbarWindow.

Definition at line 637 of file window_gui.h.

References ES_NOT_HANDLED.

Referenced by HandleCtrlChanged().

virtual void Window::OnClick | ( | Point | pt,
|  | int | widget |
| ) |  |  | `[inline, virtual]`

A click with the left mouse button has been made on the window.

Parameters:

  | pt | the point inside the window that has been clicked.
  | widget | the clicked widget.

Reimplemented in AIListWindow, AISettingsWindow, AIConfigWindow, AIDebugWindow, ReplaceVehicleWindow, CompanyFinancesWindow, SelectCompanyLiveryWindow, SelectCompanyManagerFaceWindow, CompanyWindow, SetDateWindow, BuildIndustryWindow, IndustryDirectoryWindow, QueryStringWindow, QueryWindow, NewGRFAddWindow, NewGRFWindow, NewsWindow, OrdersWindow, BuildRailToolbarWindow, SmallMapWindow, CompanyStationsWindow, StationViewWindow, SelectStationWindow< T >, TownAuthorityWindow, TownDirectoryWindow, FoundTownWindow, BuildTreesWindow, RefitWindow, VehicleListWindow, VehicleDetailsWindow, VehicleViewWindow, and DropdownWindow.

Definition at line 645 of file window_gui.h.

Referenced by DispatchLeftClickEvent().

virtual void Window::OnDoubleClick | ( | Point | pt,
|  | int | widget |
| ) |  |  | `[inline, virtual]`

A double click with the left mouse button has been made on the window.

Parameters:

  | pt | the point inside the window that has been clicked.
  | widget | the clicked widget.

Reimplemented in AIListWindow, AIConfigWindow, BuildIndustryWindow, NewGRFAddWindow, NewGRFWindow, TownAuthorityWindow, and RefitWindow.

Definition at line 652 of file window_gui.h.

Referenced by DispatchLeftClickEvent().

virtual void Window::OnRightClick | ( | Point | pt,
|  | int | widget |
| ) |  |  | `[inline, virtual]`

A click with the right mouse button has been made on the window.

Parameters:

  | pt | the point inside the window that has been clicked.
  | widget | the clicked widget.

Reimplemented in SmallMapWindow.

Definition at line 659 of file window_gui.h.

Referenced by DispatchRightClickEvent().

virtual void Window::OnDragDrop | ( | Point | pt,
|  | int | widget |
| ) |  |  | `[inline, virtual]`

A dragged 'object' has been released.

Parameters:

  | pt | the point inside the window where the release took place.
  | widget | the widget where the release took place.

Reimplemented in OrdersWindow.

Definition at line 666 of file window_gui.h.

virtual void Window::OnScroll | ( | Point | delta | ) | `[inline, virtual]`

Handle the request for (viewport) scrolling.

Parameters:

  | delta | the amount the viewport must be scrolled.

Reimplemented in SmallMapWindow.

Definition at line 672 of file window_gui.h.

virtual void Window::OnMouseOver | ( | Point | pt,
|  | int | widget |
| ) |  |  | `[inline, virtual]`

The mouse is currently moving over the window or has just moved outside of the window.

In the latter case pt is (-1, -1).

Parameters:

  | pt | the point inside the window that the mouse hovers over.
  | widget | the widget the mouse hovers over.

Definition at line 680 of file window_gui.h.

virtual void Window::OnMouseWheel | ( | int | wheel | ) | `[inline, virtual]`

The mouse wheel has been turned.

Parameters:

  | wheel | the amount of movement of the mouse wheel.

Definition at line 686 of file window_gui.h.

virtual void Window::OnResize | ( |  | ) | `[inline, virtual]`

Called after the window got resized.

For nested windows with a viewport, call NWidgetViewport::UpdateViewportCoordinates.

Reimplemented in AIListWindow, AISettingsWindow, AIDebugWindow, ReplaceVehicleWindow, BuildIndustryWindow, IndustryDirectoryWindow, NewGRFAddWindow, NewGRFWindow, OrdersWindow, CompanyStationsWindow, StationViewWindow, SelectStationWindow< T >, TownDirectoryWindow, RefitWindow, VehicleListWindow, VehicleDetailsWindow, and VehicleViewWindow.

Definition at line 714 of file window_gui.h.

Referenced by FindWindowPlacementAndResize(), ReInit(), and RelocateAllWindows().

virtual void Window::OnDropdownSelect | ( | int | widget,
|  | int | index |
| ) |  |  | `[inline, virtual]`

A dropdown option associated to this window has been selected.

Parameters:

  | widget | the widget (button) that the dropdown is associated with.
  | index | the element in the dropdown that is selected.

Reimplemented in ReplaceVehicleWindow, SelectCompanyLiveryWindow, SetDateWindow, IndustryDirectoryWindow, NewGRFWindow, OrdersWindow, CompanyStationsWindow, and VehicleListWindow.

Definition at line 721 of file window_gui.h.

Referenced by DropdownWindow::OnMouseLoop().

virtual void Window::OnQueryTextFinished | ( | char * | str | ) | `[inline, virtual]`

The query window opened from this window has closed.

Parameters:

  | str | the new value of the string or NULL if the window was cancelled.

Reimplemented in AISettingsWindow, SelectCompanyManagerFaceWindow, CompanyWindow, NewGRFWindow, OrdersWindow, StationViewWindow, and VehicleDetailsWindow.

Definition at line 728 of file window_gui.h.

virtual void Window::OnInvalidateData | ( | int | data = `0` | ) | `[inline, virtual]`

Some data on this window has become invalid.

Parameters:

  | data | information about the changed data.

Reimplemented in AIConfigWindow, AIDebugWindow, ReplaceVehicleWindow, SelectCompanyLiveryWindow, BuildIndustryWindow, IndustryDirectoryWindow, NewGRFAddWindow, NewGRFWindow, NewsWindow, OrdersWindow, CompanyStationsWindow, SelectStationWindow< T >, TownDirectoryWindow, FoundTownWindow, BuildTreesWindow, and VehicleListWindow.

Definition at line 734 of file window_gui.h.

Referenced by InvalidateData().

virtual void Window::OnPlaceObject | ( | Point | pt,
|  | TileIndex | tile |
| ) |  |  | `[inline, virtual]`

The user clicked some place on the map when a tile highlight mode has been set.

Parameters:

  | pt | the exact point on the map that has been clicked.
  | tile | the tile on the map that has been clicked.

Reimplemented in CompanyWindow, BuildIndustryWindow, OrdersWindow, BuildRailToolbarWindow, FoundTownWindow, and BuildTreesWindow.

Definition at line 743 of file window_gui.h.

virtual void Window::OnPlaceDrag | ( | ViewportPlaceMethod | select_method,
|  | ViewportDragDropSelectionProcess | select_proc,
|  | Point | pt |
| ) |  |  | `[inline, virtual]`

The user is dragging over the map when the tile highlight mode has been set.

Parameters:

  | select_method | the method of selection (allowed directions)
  | select_proc | what will be created when the drag is over.
  | pt | the exact point on the map where the mouse is.

Reimplemented in BuildRailToolbarWindow, and BuildTreesWindow.

Definition at line 758 of file window_gui.h.

Referenced by VpHandlePlaceSizingDrag().

virtual void Window::OnPlaceMouseUp | ( | ViewportPlaceMethod | select_method,
|  | ViewportDragDropSelectionProcess | select_proc,
|  | Point | pt,
|  | TileIndex | start_tile,
|  | TileIndex | end_tile |
| ) |  |  | `[inline, virtual]`

The user has dragged over the map when the tile highlight mode has been set.

Parameters:

  | select_method | the method of selection (allowed directions)
  | select_proc | what should be created.
  | pt | the exact point on the map where the mouse was released.
  | start_tile | the begin tile of the drag.
  | end_tile | the end tile of the drag.

Reimplemented in BuildRailToolbarWindow, and BuildTreesWindow.

Definition at line 769 of file window_gui.h.

Referenced by VpHandlePlaceSizingDrag().

virtual void Window::OnPlacePresize | ( | Point | pt,
|  | TileIndex | tile |
| ) |  |  | `[inline, virtual]`

The user moves over the map when a tile highlight mode has been set when the special mouse mode has been set to 'PRESIZE' mode.

An example of this is the tile highlight for dock building.

Parameters:

  | pt | the exact point on the map where the mouse is.
  | tile | the tile on the map where the mouse is.

Reimplemented in BuildRailToolbarWindow.

Definition at line 778 of file window_gui.h.

## Field Documentation

uint16 Window::flags4

Window flags,.

See also:
  WindowFlags

Definition at line 369 of file window_gui.h.

Referenced by BringWindowToFrontById(), CheckSoftLimit(), DeleteAllNonVitalWindows(), DeleteNonVitalWindows(), DeleteWindowById(), DispatchLeftClickEvent(), NWidgetLeaf::Draw(), DrawWidgets(), HandleAutoscroll(), HandleButtonClick(), InitializeData(), MaybeBringWindowToFront(), BuildTreesWindow::OnClick(), ScrollbarClickPositioning(), StartWindowDrag(), StartWindowSizing(), and UpdateWindows().

uint32 Window::desc_flags

Window/widgets default flags setting.

See also:
  WindowDefaultFlag

Definition at line 386 of file window_gui.h.

Referenced by DeleteConstructionWindows(), DispatchLeftClickEvent(), and MaybeBringWindowToFront().

The documentation for this struct was generated from the following files:

- src/window_gui.h
- src/viewport.cpp
- src/widget.cpp
- src/window.cpp