From e4c05f8d789b8a83159313d3ce745745038a7b67 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Mon, 14 Jan 2008 16:10:58 +0000 Subject: (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed. --- src/widgets/dropdown_type.h | 65 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 src/widgets/dropdown_type.h (limited to 'src/widgets/dropdown_type.h') diff --git a/src/widgets/dropdown_type.h b/src/widgets/dropdown_type.h new file mode 100644 index 000000000..650edc5b1 --- /dev/null +++ b/src/widgets/dropdown_type.h @@ -0,0 +1,65 @@ +/* $Id$ */ + +#ifndef WIDGETS_DROPDOWN_TYPE_H +#define WIDGETS_DROPDOWN_TYPE_H + +#include "../window_type.h" +#include + +/** + * Base list item class from which others are derived. If placed in a list it + * will appear as a horizontal line in the menu. + */ +class DropDownListItem { +public: + int result; ///< Result code to return to window on selection + bool masked; ///< Masked and unselectable item + + virtual StringID String() const; +}; + +/** + * Common string list item. + */ +class DropDownListStringItem : public DropDownListItem { +public: + StringID string; ///< String ID of item + + DropDownListStringItem(StringID string, uint result, bool masked) + { + this->string = string; + this->result = result; + this->masked = masked; + } + + StringID String() const; +}; + +/** + * String list item with parameters. + */ +class DropDownListParamStringItem : public DropDownListStringItem { +public: + uint64 decode_params[10]; ///< Parameters of the string + + StringID String() const; + void SetParam(uint index, uint64 value) { decode_params[index] = value; } +}; + +/** + * A drop down list is a collection of drop down list items. + */ +typedef std::list DropDownList; + +/** + * Show a drop down list. + * @param w Parent window for the list. + * @param list Prepopulated DropDownList. Will be deleted when the list is + * closed. + * @param selected The initially selected list item. + * @param button The widget within the parent window that is used to determine + * the list's location. + */ +void ShowDropDownList(Window *w, DropDownList *list, int selected, int button); + +#endif /* WIDGETS_DROPDOWN_TYPE_H */ -- cgit v1.2.3-70-g09d2