# dropdown.cpp File Reference

Implementation of the dropdown widget. More...

`#include "../stdafx.h"`
`#include "../window_gui.h"`
`#include "../strings_func.h"`
`#include "../window_func.h"`
`#include "dropdown_type.h"`

Go to the source code of this file.

## Data Structures
struct | DropdownWindow
| Drop-down menu window. More...
## Enumerations
enum | DropdownMenuWidgets { DDM_ITEMS, DDM_SCROLL }
| Widget numbers of the dropdown menu. More...
## Functions
static void | DeleteDropDownList (DropDownList *list)
| Delete all items of a drop down list and the list itself.
void | ShowDropDownList (Window *w, DropDownList *list, int selected, int button, uint width, bool auto_width, bool instant_close)
| Show a drop down list.
void | ShowDropDownMenu (Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
| Show a dropdown menu window near a widget of the parent window.
int | HideDropDownMenu (Window *pw)
| Delete the drop-down menu from window pw.
## Variables
static const NWidgetPart | _nested_dropdown_menu_widgets []
const WindowDesc | _dropdown_desc (WDP_MANUAL, 0, 0, WC_DROPDOWN_MENU, WC_NONE, 0, _nested_dropdown_menu_widgets, lengthof(_nested_dropdown_menu_widgets))

## Detailed Description

Implementation of the dropdown widget.

Definition in file dropdown.cpp.

## Enumeration Type Documentation

enum DropdownMenuWidgets

Widget numbers of the dropdown menu.

Enumerator:

  DDM_ITEMS | Panel showing the dropdown items.
  DDM_SCROLL | Scrollbar.

Definition at line 71 of file dropdown.cpp.

## Function Documentation

static void DeleteDropDownList | ( | DropDownList * | list | ) | `[static]`

Delete all items of a drop down list and the list itself.

Parameters:

  | list | List to delete.

Definition at line 61 of file dropdown.cpp.

Referenced by ShowDropDownMenu().

int HideDropDownMenu | ( | Window * | pw | ) |

Delete the drop-down menu from window pw.

Parameters:

  | pw | Parent window of the drop-down menu window

Returns:
  Parent widget number if the drop-down was found and closed, `-1` if the window was not found.

Definition at line 449 of file dropdown.cpp.

References DropdownWindow::parent_button, DropdownWindow::parent_wnd_class, DropdownWindow::parent_wnd_num, Window::window_class, and Window::window_number.

Referenced by DispatchLeftClickEvent(), OrdersWindow::OnClick(), OrdersWindow::OnInvalidateData(), VehicleGroupWindow::OnInvalidateData(), VehicleListWindow::OnPaint(), and VehicleGroupWindow::OnPaint().

void ShowDropDownList | ( | Window * | w,
|  | DropDownList * | list,
|  | int | selected,
|  | int | button,
|  | uint | width = `0`,
|  | bool | auto_width = `false`,
|  | bool | instant_close = `false` |
| ) |  |  |

Show a drop down list.

Parameters:

  | w | Parent window for the list.
  | list | Prepopulated DropDownList. Will be deleted when the list is closed.
  | selected | The initially selected list item.
  | button | The widget within the parent window that is used to determine the list's location.
  | width | Override the width determined by the selected widget.
  | auto_width | Maximum width is determined by the widest item in the list.
  | instant_close | Set to true if releasing mouse button should close the list regardless of where the cursor is.

Definition at line 338 of file dropdown.cpp.

References _dynlang, NWidgetCore::colour, NWidgetBase::current_x, NWidgetBase::current_y, DeleteWindowById(), NWidgetCore::disp_flags, GetMainViewBottom(), GetMainViewTop(), Window::GetWidget(), Window::left, Window::LowerWidget(), max(), ND_DROPDOWN_ACTIVE, NWID_BUTTON_DROPDOWN, NWidgetBase::pos_x, NWidgetBase::pos_y, Window::SetWidgetDirty(), TD_RTL, DynamicLanguages::text_dir, Window::top, NWidgetBase::type, and WD_VSCROLLBAR_WIDTH.

Referenced by GameOptionsWindow::OnClick(), BuildRailStationWindow::OnClick(), NewGRFWindow::OnClick(), CreateScenarioWindow::OnClick(), GenerateLandscapeWindow::OnClick(), ReplaceVehicleWindow::OnClick(), PopupMainCompanyToolbMenu(), PopupMainToolbMenu(), SetDateWindow::ShowDateDropDown(), ShowDropDownMenu(), ShowGroupActionDropdown(), and ShowTownnameDropdown().

void ShowDropDownMenu | ( | Window * | w,
|  | const StringID * | strings,
|  | int | selected,
|  | int | button,
|  | uint32 | disabled_mask,
|  | uint32 | hidden_mask,
|  | uint | width |
| ) |  |  |

Show a dropdown menu window near a widget of the parent window.

The result code of the items is their index in the strings list.

Parameters:

  | w | Parent window that wants the dropdown menu.
  | strings | Menu list, end with INVALID_STRING_ID
  | selected | Index of initial selected item.
  | button | Button widget number of the parent window w that wants the dropdown menu.
  | disabled_mask | Bitmask for diabled items (items with their bit set are not copied to the dropdown list).
  | hidden_mask | Bitmask for hidden items (items with their bit set are displayed, but not selectable in the dropdown list).
  | width | Width of the dropdown menu. If `0`, use the width of parent widget button.

Definition at line 425 of file dropdown.cpp.

References DeleteDropDownList(), HasBit(), INVALID_STRING_ID, and ShowDropDownList().

Referenced by VehicleListWindow::OnClick(), CompanyStationsWindow::OnClick(), GameOptionsWindow::OnClick(), OrdersWindow::OnClick(), MessageOptionsWindow::OnClick(), NetworkStartServerWindow::OnClick(), NetworkGameWindow::OnClick(), IndustryDirectoryWindow::OnClick(), VehicleGroupWindow::OnClick(), GenerateLandscapeWindow::OnClick(), BuildVehicleWindow::OnClick(), and BuildBridgeWindow::OnClick().

## Variable Documentation

const NWidgetPart _nested_dropdown_menu_widgets[]`[static]`

Initial value:

     {
      NWidget(NWID_HORIZONTAL),
        NWidget(WWT_PANEL, COLOUR_END, DDM_ITEMS), SetMinimalSize(1, 1), EndContainer(),
        NWidget(WWT_SCROLLBAR, COLOUR_END, DDM_SCROLL),
      EndContainer(),
    }

Definition at line 76 of file dropdown.cpp.