# window_func.h File Reference

Window functions not directly related to making/drawing windows. More...

`#include "window_type.h"`
`#include "company_type.h"`

Go to the source code of this file.

## Functions
Window * | FindWindowById (WindowClass cls, WindowNumber number)
| Find a window by its class and window number.
Window * | FindWindowByClass (WindowClass cls)
| Find any window by its class.
void | ChangeWindowOwner (Owner old_owner, Owner new_owner)
| Change the owner of all the windows one company can take over from another company in the case of a company merger.
void | ResizeWindow (Window *w, int x, int y)
| Resize the window.
int | PositionMainToolbar (Window *w)
| (Re)position main toolbar window at the screen
int | GetMainViewTop ()
| Return the top of the main view available for general use.
int | GetMainViewBottom ()
| Return the bottom of the main view available for general use.
void | InitWindowSystem ()
| (re)initialize the windowing system
void | UnInitWindowSystem ()
| Close down the windowing system.
void | ResetWindowSystem ()
| Reset the windowing system, by means of shutting it down followed by re-initialization.
void | SetupColoursAndInitialWindow ()
void | InputLoop ()
| Regular call from the global game loop.
void | InvalidateWindowData (WindowClass cls, WindowNumber number, int data=0)
| Mark window data of the window of a given class and specific window number as invalid (in need of re-computing).
void | InvalidateWindowClassesData (WindowClass cls, int data=0)
| Mark window data of all windows of a given class as invalid (in need of re-computing).
void | DeleteNonVitalWindows ()
| Try to delete a non-vital window.
void | DeleteAllNonVitalWindows ()
| It is possible that a stickied window gets to a position where the 'close' button is outside the gaming area.
void | DeleteConstructionWindows ()
| Delete all windows that are used for construction of vehicle etc.
void | HideVitalWindows ()
| Delete all always on-top windows to get an empty screen.
void | ShowVitalWindows ()
void | ReInitAllWindows ()
| Re-initialize all windows.
void | SetWindowWidgetDirty (WindowClass cls, WindowNumber number, byte widget_index)
| Mark a particular widget in a particular window as dirty (in need of repainting).
void | SetWindowDirty (WindowClass cls, WindowNumber number)
| Mark window as dirty (in need of repainting).
void | SetWindowClassesDirty (WindowClass cls)
| Mark all windows of a particular class as dirty (in need of repainting).
void | DeleteWindowById (WindowClass cls, WindowNumber number, bool force=true)
| Delete a window by its class and window number (if it is open).
void | DeleteWindowByClass (WindowClass cls)
| Delete all windows of a given class.

## Detailed Description

Window functions not directly related to making/drawing windows.

Definition in file window_func.h.

## Function Documentation

void ChangeWindowOwner | ( | Owner | old_owner,
|  | Owner | new_owner |
| ) |  |  |

Change the owner of all the windows one company can take over from another company in the case of a company merger.

Do not change ownership of windows that need to be deleted once takeover is complete

Parameters:

  | old_owner | original owner of the window
  | new_owner | the new owner of the window

Definition at line 731 of file window.cpp.

References Window::owner, and Window::window_class.

void DeleteAllNonVitalWindows | ( |  | ) |

It is possible that a stickied window gets to a position where the 'close' button is outside the gaming area.

You cannot close it then; except with this function. It closes all windows calling the standard function, then, does a little hacked loop of closing all stickied windows. Note that standard windows (status bar, etc.) are not stickied, so these aren't affected

Definition at line 2422 of file window.cpp.

References DeleteNonVitalWindows(), Window::flags4, and WF_STICKY.

Referenced by GenerateWorld().

void DeleteConstructionWindows | ( |  | ) |

Delete all windows that are used for construction of vehicle etc.

Once done with that invalidate the others to ensure they get refreshed too.

Definition at line 2445 of file window.cpp.

References Window::desc_flags, Window::SetDirty(), and WDF_CONSTRUCTION.

Referenced by SetLocalCompany().

void DeleteNonVitalWindows | ( |  | ) |

Try to delete a non-vital window.

Non-vital windows are windows other than the game selection, main toolbar, status bar, toolbar menu, and tooltip windows. Stickied windows are also considered vital.

Definition at line 2394 of file window.cpp.

References Window::flags4, WF_STICKY, and Window::window_class.

Referenced by DeleteAllNonVitalWindows().

void DeleteWindowByClass | ( | WindowClass | cls | ) |

Delete all windows of a given class.

Parameters:

  | cls | Window class of windows to delete

Definition at line 687 of file window.cpp.

References Window::window_class.

Referenced by NewGRFWindow::OnClick(), NewGRFAddWindow::OnClick(), BuildRailToolbarWindow::OnPlaceObjectAbort(), ShowBuildBridgeWindow(), ShowBuildRailToolbar(), ShowEndGameChart(), ShowHighscoreTable(), ShowNewGRFSettings(), and ShowSetDateWindow().

void DeleteWindowById | ( | WindowClass | cls,
|  | WindowNumber | number,
|  | bool | force |
| ) |  |  |

Delete a window by its class and window number (if it is open).

Parameters:

  | cls | Window class
  | number | Number of the window within the window class
  | force | force deletion; if false don't delete when stickied

Definition at line 674 of file window.cpp.

References FindWindowById(), Window::flags4, and WF_STICKY.

Referenced by CleanupGeneration(), CmdCompanyCtrl(), CmdDeleteGroup(), CmdMoveRailVehicle(), DeleteCompanyWindows(), DispatchLeftClickEvent(), EnginesDailyLoop(), GuiShowTooltips(), HideVitalWindows(), MoveToNextItem(), SelectStationWindow< T >::OnClick(), BuildRailToolbarWindow::OnPlaceObjectAbort(), RemoveAirport(), ShowDropDownList(), ShowErrorMessage(), ShowMessageHistory(), ShowNewsMessage(), ShowOnScreenKeyboard(), ShowQueryString(), ShowVehicleDetailsWindow(), ShowVehicleRefitWindow(), StartWindowDrag(), StartWindowSizing(), ToggleRailButton_Remove(), and Station::~Station().

Window* FindWindowByClass | ( | WindowClass | cls | ) |

Find any window by its class.

Useful when searching for a window that uses the window number as a WindowType, like WC_SEND_NETWORK_MSG.

Parameters:

  | cls | Window class

Returns:
  Pointer to the found window, or `NULL` if not available

Definition at line 658 of file window.cpp.

References Window::window_class.

Referenced by Window::InitializeData().

Window* FindWindowById | ( | WindowClass | cls,
|  | WindowNumber | number |
| ) |  |  |

Find a window by its class and window number.

Parameters:

  | cls | Window class
  | number | Number of the window within the window class

Returns:
  Pointer to the found window, or `NULL` if not available

Definition at line 642 of file window.cpp.

References Window::window_class, and Window::window_number.

Referenced by BringWindowToFrontById(), ChangeVehicleWindow(), DeleteDepotHighlightOfVehicle(), DeleteWindowById(), SmallMapWindow::DrawMapIndicators(), FindVehicleGroupWindow(), Window::FindWindowPlacementAndResize(), GenerateWorld(), GenericPlaceSignals(), GetMainViewBottom(), GetMainViewTop(), GetToolbarAlignedWindowPosition(), HandleAutoSignalPlacement(), HandleKeypress(), Window::InitializeData(), IsNewsTickerShown(), LocalGetWindowPlacement(), VehicleViewWindow::OnClick(), SmallMapWindow::OnClick(), ErrmsgWindow::OnInitialPosition(), QueryStringWindow::OnKeyPress(), DropdownWindow::OnMouseLoop(), BuildRailToolbarWindow::OnPlaceDrag(), PositionMainToolbar(), ReadyForNextItem(), ReinitGuiAfterToggleElrail(), RelocateAllWindows(), ResetSignalVariant(), ScrollMainWindowTo(), SetDefaultRailGui(), ShowBuildRailToolbar(), ShowLastNewsMessage(), StationJoinerNeeded(), UpdateOSKOriginalText(), and VpHandlePlaceSizingDrag().

int GetMainViewBottom | ( |  | ) |

Return the bottom of the main view available for general use.

Returns:
  The vertical coordinate of the first unusable row, so 'top + height <= bottom' gives the correct result.

Note:
  At and below the bottom y coordinate is often the status bar.

Definition at line 1445 of file window.cpp.

References FindWindowById(), DrawPixelInfo::height, and Window::top.

Referenced by TooltipsWindow::OnInitialPosition(), ErrmsgWindow::OnInitialPosition(), and ShowDropDownList().

int GetMainViewTop | ( |  | ) |

Return the top of the main view available for general use.

Returns:
  Uppermost vertical coordinate available.

Note:
  Above the upper y coordinate is often the main toolbar.

Definition at line 1435 of file window.cpp.

References FindWindowById(), Window::height, and Window::top.

Referenced by TooltipsWindow::OnInitialPosition(), ErrmsgWindow::OnInitialPosition(), and ShowDropDownList().

void InvalidateWindowClassesData | ( | WindowClass | cls,
|  | int | data |
| ) |  |  |

Mark window data of all windows of a given class as invalid (in need of re-computing).

Parameters:

  | cls | Window class
  | data | The data to invalidate with

Definition at line 2362 of file window.cpp.

References Window::InvalidateData(), and Window::window_class.

Referenced by AddRemoveEngineFromAutoreplaceAndBuildWindows(), ClickChangeDateCheat(), CmdBuildAircraft(), CmdBuildRailVehicle(), CmdBuildRoadVeh(), CmdBuildShip(), CmdCloneOrder(), CmdDeleteOrder(), CmdInsertOrder(), CmdMoveOrder(), CmdMoveRailVehicle(), CmdRefitAircraft(), CmdRefitRailVehicle(), CmdRefitRoadVeh(), CmdRefitShip(), CmdRenameVehicle(), CmdSellRailWagon(), DecloneOrder(), and OnNewYear().

void InvalidateWindowData | ( | WindowClass | cls,
|  | WindowNumber | number,
|  | int | data |
| ) |  |  |

Mark window data of the window of a given class and specific window number as invalid (in need of re-computing).

Parameters:

  | cls | Window class
  | number | Window number within the class
  | data | The data to invalidate with

Definition at line 2349 of file window.cpp.

References Window::InvalidateData(), Window::window_class, and Window::window_number.

Referenced by AddRemoveEngineFromAutoreplaceAndBuildWindows(), Subsidy::AwardTo(), ChangePopulation(), CmdAddSharedVehicleGroup(), CmdAddVehicleGroup(), CmdBuildAircraft(), CmdBuildAirport(), CmdBuildBuoy(), CmdBuildDock(), CmdBuildRailStation(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRoadStop(), CmdBuildRoadVeh(), CmdBuildShip(), CmdCompanyCtrl(), CmdConvertRail(), CmdCreateGroup(), CmdDeleteGroup(), CmdMoveRailVehicle(), CmdPlaceSign(), CmdRemoveAllVehiclesGroup(), CmdRenameGroup(), CmdRenameSign(), CmdRenameStation(), CmdRenameTown(), CmdSellRailWagon(), CmdSetGroupReplaceProtection(), DeleteStationIfEmpty(), DoCreateTown(), IndustryDailyLoop(), InvalidateAutoreplaceWindow(), InvalidateVehicleOrder(), AILog::Log(), MoveToNextItem(), NewGRFAddWindow::OnClick(), BaseStation::PostDestructor(), Industry::PostDestructor(), ReloadNewGRFData(), RemoveBuoy(), SaveFileDone(), SaveFileStart(), SetLocalCompany(), ShowTicker(), VehicleEnter_Track(), and Station::~Station().

int PositionMainToolbar | ( | Window * | w | ) |

(Re)position main toolbar window at the screen

Parameters:

  | w | Window structure of the main toolbar window, may also be `NULL`

Returns:
  X coordinate of left edge of the repositioned toolbar window

Definition at line 2491 of file window.cpp.

References _settings_client, FindWindowById(), ClientSettings::gui, Window::height, Window::left, SetDirtyBlocks(), GUISettings::toolbar_pos, Window::width, DrawPixelInfo::width, and Window::window_class.

Referenced by RelocateAllWindows().

void ReInitAllWindows | ( |  | ) |

Re-initialize all windows.

Definition at line 2472 of file window.cpp.

References Dimension::height, NWidgetLeaf::InvalidateDimensionCache(), MarkWholeScreenDirty(), Window::ReInit(), RelocateAllWindows(), and Dimension::width.

Referenced by LoadStringWidthTable().

void ResizeWindow | ( | Window * | w,
|  | int | delta_x,
|  | int | delta_y |
| ) |  |  |

Resize the window.

Update all the widgets of a window based on their resize flags Both the areas of the old window and the new sized window are set dirty ensuring proper redrawal.

Parameters:

  | w | Window to resize
  | delta_x | Delta x-size of changed window (positive if larger, etc.)
  | delta_y | Delta y-size of changed window

Definition at line 1414 of file window.cpp.

References _dynlang, NWidgetBase::AssignSizePosition(), NWidgetBase::current_x, NWidgetBase::current_y, Window::height, max(), Window::nested_root, NWidgetBase::resize_x, NWidgetBase::resize_y, Window::SetDirty(), NWidgetBase::smallest_x, NWidgetBase::smallest_y, ST_RESIZE, TD_RTL, DynamicLanguages::text_dir, and Window::width.

Referenced by TownAuthorityWindow::DrawRatings(), Window::FindWindowPlacementAndResize(), Window::ReInit(), and RelocateAllWindows().

void SetWindowClassesDirty | ( | WindowClass | cls | ) |

Mark all windows of a particular class as dirty (in need of repainting).

Parameters:

  | cls | Window class

Definition at line 2335 of file window.cpp.

References Window::SetDirty(), and Window::window_class.

Referenced by ClickSetProdCheat(), CmdSkipToOrder(), CmdStartStopVehicle(), OnNewDay(), OnNewMonth(), ProcessOrders(), RecomputePrices(), and SetNewLandscapeType().

void SetWindowDirty | ( | WindowClass | cls,
|  | WindowNumber | number |
| ) |  |  |

Mark window as dirty (in need of repainting).

Parameters:

  | cls | Window class
  | number | Window number in that class

Definition at line 2307 of file window.cpp.

References Window::SetDirty(), Window::window_class, and Window::window_number.

Referenced by AddNewsItem(), AircraftEventHandler_AtTerminal(), ChangePopulation(), ChangeTownRating(), ClickChangeDateCheat(), CmdAddVehicleGroup(), CmdAutofillTimetable(), CmdBuildAircraft(), CmdBuildAirport(), CmdBuildCompanyHQ(), CmdBuildRailVehicle(), CmdBuildRailWagon(), CmdBuildRoadVeh(), CmdBuildShip(), CmdBuyShareInCompany(), CmdChangeCompanySetting(), CmdChangeServiceInt(), CmdChangeSetting(), CmdDoTownAction(), CmdForceTrainProceed(), CmdPause(), CmdRefitAircraft(), CmdRefitRailVehicle(), CmdRefitRoadVeh(), CmdRefitShip(), CmdReverseTrainDirection(), CmdSellShareInCompany(), CmdSetTimetableStart(), CmdSetVehicleOnTime(), CmdStartStopVehicle(), Train::ConsistChanged(), DeleteLastWagon(), DeleteNewsItem(), DestroyCompanyHQ(), DoStartupNewCompany(), IConsoleGUIPrint(), IndustryProductionCallback(), InvalidateVehicleOrder(), LoadUnloadVehicle(), NormaliseTrainHead(), Train::PowerChanged(), RecomputePrices(), RemoveAirport(), RemoveOrderFromAllVehicles(), SetSettingValue(), SetTrainGroupID(), TriggerIndustryProduction(), UpdateCompanyRatingAndValue(), UpdateTownGrowRate(), UpdateTrainGroupID(), and Station::UpdateVirtCoord().

void SetWindowWidgetDirty | ( | WindowClass | cls,
|  | WindowNumber | number,
|  | byte | widget_index |
| ) |  |  |

Mark a particular widget in a particular window as dirty (in need of repainting).

Parameters:

  | cls | Window class
  | number | Window number in that class
  | widget_index | Index number of the widget that needs repainting

Definition at line 2321 of file window.cpp.

References Window::SetWidgetDirty(), Window::window_class, and Window::window_number.

Referenced by CmdBuildAirport(), CmdBuildDock(), CmdBuildRailStation(), CmdBuildRoadStop(), CmdRemoveFromRailStation(), CmdStartStopVehicle(), MarkTrainAsStuck(), NormaliseTrainHead(), OnNewDay(), Train::PowerChanged(), RemoveAirport(), RemoveDock(), RemoveFromRailBaseStation(), RemoveRailStation(), RemoveRoadStop(), TryPathReserve(), UpdateAircraftSpeed(), and UpdateStationAcceptance().