4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 /** @file dropdown_type.h Types related to the drop down widget. */
12 #ifndef WIDGETS_DROPDOWN_TYPE_H
13 #define WIDGETS_DROPDOWN_TYPE_H
15 #include "../window_type.h"
16 #include "../gfx_func.h"
17 #include "../core/smallvec_type.hpp"
18 #include "table/strings.h"
20 enum DropDownSyncFocus
{
24 DDSF_ALL
= DDSF_RECV_FOCUS
| DDSF_LOST_FOCUS
,
28 * Base list item class from which others are derived. If placed in a list it
29 * will appear as a horizontal line in the menu.
31 class DropDownListItem
{
33 int result
; ///< Result code to return to window on selection
34 bool masked
; ///< Masked and unselectable item
36 DropDownListItem(int result
, bool masked
) : result(result
), masked(masked
) {}
37 virtual ~DropDownListItem() {}
39 virtual bool Selectable() const { return false; }
40 virtual uint
Height(uint width
) const { return FONT_HEIGHT_NORMAL
; }
41 virtual uint
Width() const { return 0; }
42 virtual void Draw(int left
, int right
, int top
, int bottom
, bool sel
, int bg_colour
) const;
46 * Common string list item.
48 class DropDownListStringItem
: public DropDownListItem
{
50 StringID string
; ///< String ID of item
52 DropDownListStringItem(StringID string
, int result
, bool masked
) : DropDownListItem(result
, masked
), string(string
) {}
53 virtual ~DropDownListStringItem() {}
55 virtual bool Selectable() const { return true; }
56 virtual uint
Width() const;
57 virtual void Draw(int left
, int right
, int top
, int bottom
, bool sel
, int bg_colour
) const;
58 virtual StringID
String() const { return this->string
; }
60 static int CDECL
NatSortFunc(const DropDownListItem
* const *first
, const DropDownListItem
* const *second
);
64 * String list item with parameters.
66 class DropDownListParamStringItem
: public DropDownListStringItem
{
68 uint64 decode_params
[10]; ///< Parameters of the string
70 DropDownListParamStringItem(StringID string
, int result
, bool masked
) : DropDownListStringItem(string
, result
, masked
) {}
71 virtual ~DropDownListParamStringItem() {}
73 virtual StringID
String() const;
74 virtual void SetParam(uint index
, uint64 value
) { decode_params
[index
] = value
; }
78 * List item containing a C char string.
80 class DropDownListCharStringItem
: public DropDownListStringItem
{
82 const char *raw_string
;
84 DropDownListCharStringItem(const char *raw_string
, int result
, bool masked
) : DropDownListStringItem(STR_JUST_RAW_STRING
, result
, masked
), raw_string(raw_string
) {}
85 virtual ~DropDownListCharStringItem() {}
87 virtual StringID
String() const;
91 * A drop down list is a collection of drop down list items.
93 typedef AutoDeleteSmallVector
<const DropDownListItem
*, 4> DropDownList
;
95 void ShowDropDownListAt(Window
*w
, const DropDownList
*list
, int selected
, int button
, Rect wi_rect
, Colours wi_colour
, bool auto_width
= false, bool instant_close
= false, DropDownSyncFocus sync_parent_focus
= DDSF_NONE
);
97 void ShowDropDownList(Window
*w
, const DropDownList
*list
, int selected
, int button
, uint width
= 0, bool auto_width
= false, bool instant_close
= false, DropDownSyncFocus sync_parent_focus
= DDSF_NONE
);
99 #endif /* WIDGETS_DROPDOWN_TYPE_H */