# NewGRFAddWindow Struct Reference

Window for adding NewGRF files. More...

Inheritance diagram for NewGRFAddWindow:

## Public Member Functions
| NewGRFAddWindow (const WindowDesc *desc, Window *parent, GRFConfig **list)
virtual void | OnInvalidateData (int data)
| Some data on this window has become invalid.
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 | OnResize ()
| Called after the window got resized.
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 | OnClick (Point pt, int widget, int click_count)
| A click with the left mouse button has been made on the window.
virtual void | OnMouseLoop ()
| Called for every mouse loop run, which is at least once per (game) tick.
virtual EventState | OnKeyPress (uint16 key, uint16 keycode)
| A key has been pressed.
virtual void | OnOSKInput (int wid)
## Private Types
enum | { EDITBOX_MAX_SIZE = 50, EDITBOX_MAX_LENGTH = 300 }
typedef GUIList< const GRFConfig * > | GUIGRFConfigList
## Private Member Functions
void | BuildGrfList ()
| (Re)build the grf as its amount has changed because an item has been added or deleted for example
void | SortGrfList ()
| Sort the grf list.
void | UpdateListPosition ()
| Update selection position.
void | FilterGrfList ()
| Filter the grf list.
void | ScrollToSelected ()
| Make sure that the currently selected grf is within the visible part of the list.
## Static Private Member Functions
static int CDECL | NameSorter (const GRFConfig *const *a, const GRFConfig *const *b)
| Sort grfs by name.
static bool CDECL | TagNameFilter (const GRFConfig *const *a, const char *filter_string)
| Filter grfs by tags/name.
## Private Attributes
GRFConfig ** | list
GUIGRFConfigList | grfs
const GRFConfig * | sel
int | sel_pos
## Static Private Attributes
static Listing | last_sorting = {false, 0}
| Runtime saved values.
static Filtering | last_filtering = {false, 0}
static GUIGRFConfigList::SortFunction *const | sorter_funcs []
static GUIGRFConfigList::FilterFunction *const | filter_funcs []

## Detailed Description

Window for adding NewGRF files.

Definition at line 157 of file newgrf_gui.cpp.

## Member Function Documentation

static int CDECL NewGRFAddWindow::NameSorter | ( | const GRFConfig *const * | a,
|  | const GRFConfig *const * | b |
| ) |  |  | `[inline, static, private]`

Sort grfs by name.

Definition at line 204 of file newgrf_gui.cpp.

void NewGRFAddWindow::UpdateListPosition | ( |  | ) | `[inline, private]`

Update selection position.

Definition at line 223 of file newgrf_gui.cpp.

References SmallVector< T, S >::FindIndex().

Referenced by FilterGrfList(), and SortGrfList().

virtual void NewGRFAddWindow::OnInvalidateData | ( | int | data | ) | `[inline, virtual]`

Some data on this window has become invalid.

Parameters:

  | data | information about the changed data.

Reimplemented from Window.

Definition at line 276 of file newgrf_gui.cpp.

References BuildGrfList(), GUIList< T, F >::ForceRebuild(), GRFConfig::IsOpenTTDBaseGRF(), and Window::SetWidgetDisabledState().

virtual void NewGRFAddWindow::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 from Window.

Definition at line 290 of file newgrf_gui.cpp.

References FONT_HEIGHT_NORMAL, Dimension::height, max(), WD_FRAMERECT_BOTTOM, and WD_FRAMERECT_TOP.

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

Called after the window got resized.

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

Reimplemented from Window.

Definition at line 304 of file newgrf_gui.cpp.

References Scrollbar::SetCapacityFromWidget(), and Window::vscroll.

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

The window must be repainted.

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

Reimplemented from Window.

Definition at line 309 of file newgrf_gui.cpp.

References Window::DrawWidgets().

virtual void NewGRFAddWindow::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 from Window.

Definition at line 315 of file newgrf_gui.cpp.

References Rect::bottom, DrawString(), GRFConfig::filename, Scrollbar::GetCapacity(), Scrollbar::GetPosition(), GfxFillRect(), Rect::left, SmallVector< T, S >::Length(), min(), GRFConfig::name, Window::resize, Rect::right, ResizeInfo::step_height, StrEmpty(), Rect::top, Window::vscroll, WD_FRAMERECT_BOTTOM, WD_FRAMERECT_LEFT, WD_FRAMERECT_RIGHT, and WD_FRAMERECT_TOP.

virtual void NewGRFAddWindow::OnClick | ( | Point | pt,
|  | int | widget,
|  | int | click_count |
| ) |  |  | `[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.
  | click_count | Number of fast consecutive clicks at same position

Reimplemented from Window.

Definition at line 347 of file newgrf_gui.cpp.

References DeleteWindowByClass(), DuplicateGRFConfig(), Scrollbar::GetPosition(), GRFIdentifier::grfid, INVALID_STRING_ID, Window::InvalidateData(), InvalidateWindowData(), SmallVector< T, S >::Length(), GRFConfig::next, Window::resize, ShowErrorMessage(), ResizeInfo::step_height, Window::vscroll, WD_FRAMERECT_TOP, and Point::y.

virtual EventState NewGRFAddWindow::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 from Window.

Definition at line 402 of file newgrf_gui.cpp.

References Window::ES_HANDLED, Window::ES_NOT_HANDLED, Scrollbar::GetCapacity(), Window::InvalidateData(), SmallVector< T, S >::Length(), min(), ScrollToSelected(), and Window::vscroll.

## Field Documentation

NewGRFAddWindow::GUIGRFConfigList::SortFunction *const NewGRFAddWindow::sorter_funcs`[static, private]`

Initial value:

     {
      &NameSorter,
    }

Definition at line 167 of file newgrf_gui.cpp.

NewGRFAddWindow::GUIGRFConfigList::FilterFunction *const NewGRFAddWindow::filter_funcs`[static, private]`

Initial value:

     {
      &TagNameFilter,
    }

Definition at line 168 of file newgrf_gui.cpp.

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

- src/newgrf_gui.cpp