src/widgets/dropdown.cpp
author terom@frrb.lan
Fri, 19 Dec 2008 01:32:07 +0200
changeset 10438 51bff16a04c9
parent 10009 41d822dd3350
permissions -rw-r--r--
initial mini-map stuff
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
     1
/* $Id$ */
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9082
diff changeset
     3
/** @file dropdown.cpp Implementation of the dropdown widget. */
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9082
diff changeset
     4
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
     5
#include "../stdafx.h"
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
     6
#include "../openttd.h"
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
     7
#include "../strings_type.h"
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
     8
#include "../window_gui.h"
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
     9
#include "../strings_func.h"
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    10
#include "../strings_type.h"
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    11
#include "../gfx_func.h"
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    12
#include "../window_func.h"
8301
9f8d82ea6667 (svn r11865) -Feature(tte): Support scrolling of drop down lists when in drag mode by moving the pointer above or below the list.
peter1138
parents: 8299
diff changeset
    13
#include "../core/math_func.hpp"
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    14
#include "dropdown_type.h"
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    15
#include "dropdown_func.h"
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    16
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    17
#include "../table/sprites.h"
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    18
#include "table/strings.h"
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    19
9859
28606a486c52 (svn r14004) -Codechange: Clean of drop down lists.
peter1138
parents: 9827
diff changeset
    20
void DropDownListItem::Draw(int x, int y, uint width, uint height, bool sel, int bg_colour) const
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    21
{
9859
28606a486c52 (svn r14004) -Codechange: Clean of drop down lists.
peter1138
parents: 9827
diff changeset
    22
	int c1 = _colour_gradient[bg_colour][3];
28606a486c52 (svn r14004) -Codechange: Clean of drop down lists.
peter1138
parents: 9827
diff changeset
    23
	int c2 = _colour_gradient[bg_colour][7];
28606a486c52 (svn r14004) -Codechange: Clean of drop down lists.
peter1138
parents: 9827
diff changeset
    24
28606a486c52 (svn r14004) -Codechange: Clean of drop down lists.
peter1138
parents: 9827
diff changeset
    25
	GfxFillRect(x + 1, y + 3, x + width - 2, y + 3, c1);
28606a486c52 (svn r14004) -Codechange: Clean of drop down lists.
peter1138
parents: 9827
diff changeset
    26
	GfxFillRect(x + 1, y + 4, x + width - 2, y + 4, c2);
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    27
}
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    28
9868
c529be2a15c5 (svn r14014) -Codechange: Add support for automatically sizing drop down lists to the widest list item.
peter1138
parents: 9859
diff changeset
    29
uint DropDownListStringItem::Width() const
c529be2a15c5 (svn r14014) -Codechange: Add support for automatically sizing drop down lists to the widest list item.
peter1138
parents: 9859
diff changeset
    30
{
c529be2a15c5 (svn r14014) -Codechange: Add support for automatically sizing drop down lists to the widest list item.
peter1138
parents: 9859
diff changeset
    31
	char buffer[512];
c529be2a15c5 (svn r14014) -Codechange: Add support for automatically sizing drop down lists to the widest list item.
peter1138
parents: 9859
diff changeset
    32
	GetString(buffer, this->String(), lastof(buffer));
c529be2a15c5 (svn r14014) -Codechange: Add support for automatically sizing drop down lists to the widest list item.
peter1138
parents: 9859
diff changeset
    33
	return GetStringBoundingBox(buffer).width;
c529be2a15c5 (svn r14014) -Codechange: Add support for automatically sizing drop down lists to the widest list item.
peter1138
parents: 9859
diff changeset
    34
}
c529be2a15c5 (svn r14014) -Codechange: Add support for automatically sizing drop down lists to the widest list item.
peter1138
parents: 9859
diff changeset
    35
9859
28606a486c52 (svn r14004) -Codechange: Clean of drop down lists.
peter1138
parents: 9827
diff changeset
    36
void DropDownListStringItem::Draw(int x, int y, uint width, uint height, bool sel, int bg_colour) const
8905
609b1121b3b3 (svn r12672) -Codechange: Add support for variably-sized drop down list items.
peter1138
parents: 8884
diff changeset
    37
{
9859
28606a486c52 (svn r14004) -Codechange: Clean of drop down lists.
peter1138
parents: 9827
diff changeset
    38
	DrawStringTruncated(x + 2, y, this->String(), sel ? TC_WHITE : TC_BLACK, width);
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    39
}
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    40
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    41
StringID DropDownListParamStringItem::String() const
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    42
{
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    43
	for (uint i = 0; i < lengthof(this->decode_params); i++) SetDParam(i, this->decode_params[i]);
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    44
	return this->string;
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    45
}
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    46
8299
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
    47
/**
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
    48
 * Delete all items of a drop down list and the list itself
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
    49
 * @param list List to delete.
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
    50
 */
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
    51
static void DeleteDropDownList(DropDownList *list)
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
    52
{
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
    53
	for (DropDownList::iterator it = list->begin(); it != list->end(); ++it) {
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
    54
		DropDownListItem *item = *it;
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
    55
		delete item;
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
    56
	}
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
    57
	delete list;
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
    58
}
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
    59
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
    60
static const Widget _dropdown_menu_widgets[] = {
9827
338aac16d11b (svn r13970) -Codechange: Replace numbers with Colours enum on network, toolbar and dropdown guis.
belugas
parents: 9607
diff changeset
    61
{      WWT_PANEL,   RESIZE_NONE,  COLOUR_END,     0, 0,     0, 0, 0x0, STR_NULL},
338aac16d11b (svn r13970) -Codechange: Replace numbers with Colours enum on network, toolbar and dropdown guis.
belugas
parents: 9607
diff changeset
    62
{  WWT_SCROLLBAR,   RESIZE_NONE,  COLOUR_END,     0, 0,     0, 0, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST},
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
    63
{   WIDGETS_END},
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
    64
};
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
    65
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
    66
struct DropdownWindow : Window {
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    67
	WindowClass parent_wnd_class;
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    68
	WindowNumber parent_wnd_num;
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    69
	byte parent_button;
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    70
	DropDownList *list;
8543
87899423775d (svn r12121) -Fix [FS#1764]: Drop down item indexes are now an int instead of a byte (Yexo)
peter1138
parents: 8358
diff changeset
    71
	int selected_index;
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    72
	byte click_delay;
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    73
	bool drag_mode;
9869
548d99e11ad7 (svn r14015) -Codechange: Add facility for a drop down list to always close (if requested) when the mouse button is released.
peter1138
parents: 9868
diff changeset
    74
	bool instant_close;
8301
9f8d82ea6667 (svn r11865) -Feature(tte): Support scrolling of drop down lists when in drag mode by moving the pointer above or below the list.
peter1138
parents: 8299
diff changeset
    75
	int scrolling;
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    76
9301
3b20dfb6c4e8 (svn r13169) -Codechange: remove a (now) unneeded parameter of one of the Window constructors.
rubidium
parents: 9273
diff changeset
    77
	DropdownWindow(int x, int y, int width, int height, const Widget *widget) : Window(x, y, width, height, WC_DROPDOWN_MENU, widget)
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
    78
	{
9374
4e9c2b65768e (svn r13278) -Fix: Missing call to FindWindowPlacementAndResize() for drop down lists
peter1138
parents: 9301
diff changeset
    79
		this->FindWindowPlacementAndResize(width, height);
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    80
	}
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    81
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
    82
	~DropdownWindow()
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
    83
	{
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
    84
		Window *w2 = FindWindowById(this->parent_wnd_class, this->parent_wnd_num);
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
    85
		if (w2 != NULL) {
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
    86
			w2->RaiseWidget(this->parent_button);
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
    87
			w2->InvalidateWidget(this->parent_button);
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
    88
		}
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    89
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
    90
		DeleteDropDownList(this->list);
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
    91
	}
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    92
9209
2987efebe01d (svn r13075) -Codechange: Allow any value for a dropdown item instead of just positive.
peter1138
parents: 9189
diff changeset
    93
	bool GetDropDownItem(int &value)
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
    94
	{
9209
2987efebe01d (svn r13075) -Codechange: Allow any value for a dropdown item instead of just positive.
peter1138
parents: 9189
diff changeset
    95
		if (GetWidgetFromPos(this, _cursor.pos.x - this->left, _cursor.pos.y - this->top) < 0) return false;
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
    96
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
    97
		int y     = _cursor.pos.y - this->top - 2;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
    98
		int width = this->widget[0].right - 3;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
    99
		int pos   = this->vscroll.pos;
8301
9f8d82ea6667 (svn r11865) -Feature(tte): Support scrolling of drop down lists when in drag mode by moving the pointer above or below the list.
peter1138
parents: 8299
diff changeset
   100
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   101
		const DropDownList *list = this->list;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   102
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   103
		for (DropDownList::const_iterator it = list->begin(); it != list->end(); ++it) {
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   104
			/* Skip items that are scrolled up */
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   105
			if (--pos >= 0) continue;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   106
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   107
			const DropDownListItem *item = *it;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   108
			int item_height = item->Height(width);
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   109
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   110
			if (y < item_height) {
9859
28606a486c52 (svn r14004) -Codechange: Clean of drop down lists.
peter1138
parents: 9827
diff changeset
   111
				if (item->masked || !item->Selectable()) return false;
9209
2987efebe01d (svn r13075) -Codechange: Allow any value for a dropdown item instead of just positive.
peter1138
parents: 9189
diff changeset
   112
				value = item->result;
2987efebe01d (svn r13075) -Codechange: Allow any value for a dropdown item instead of just positive.
peter1138
parents: 9189
diff changeset
   113
				return true;
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   114
			}
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   115
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   116
			y -= item_height;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   117
		}
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   118
9209
2987efebe01d (svn r13075) -Codechange: Allow any value for a dropdown item instead of just positive.
peter1138
parents: 9189
diff changeset
   119
		return false;
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   120
	}
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   121
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   122
	virtual void OnPaint()
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   123
	{
9273
35e0224ea8f1 (svn r13139) -Codechange: move DrawWindowWidgets and DrawWindowViewport to the Window class and remove Window from their naming.
rubidium
parents: 9209
diff changeset
   124
		this->DrawWidgets();
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   125
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   126
		int x = 1;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   127
		int y = 2;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   128
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   129
		int sel    = this->selected_index;
9859
28606a486c52 (svn r14004) -Codechange: Clean of drop down lists.
peter1138
parents: 9827
diff changeset
   130
		int width  = this->widget[0].right - 2;
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   131
		int height = this->widget[0].bottom;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   132
		int pos    = this->vscroll.pos;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   133
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   134
		DropDownList *list = this->list;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   135
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   136
		for (DropDownList::const_iterator it = list->begin(); it != list->end(); ++it) {
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   137
			const DropDownListItem *item = *it;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   138
			int item_height = item->Height(width);
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   139
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   140
			/* Skip items that are scrolled up */
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   141
			if (--pos >= 0) continue;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   142
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   143
			if (y + item_height < height) {
9859
28606a486c52 (svn r14004) -Codechange: Clean of drop down lists.
peter1138
parents: 9827
diff changeset
   144
				if (sel == item->result) GfxFillRect(x + 1, y, x + width - 1, y + item_height - 1, 0);
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   145
9859
28606a486c52 (svn r14004) -Codechange: Clean of drop down lists.
peter1138
parents: 9827
diff changeset
   146
				item->Draw(x, y, width, height, sel == item->result, (TextColour)this->widget[0].color);
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   147
9859
28606a486c52 (svn r14004) -Codechange: Clean of drop down lists.
peter1138
parents: 9827
diff changeset
   148
				if (item->masked) {
28606a486c52 (svn r14004) -Codechange: Clean of drop down lists.
peter1138
parents: 9827
diff changeset
   149
					GfxFillRect(x, y, x + width - 1, y + item_height - 1,
28606a486c52 (svn r14004) -Codechange: Clean of drop down lists.
peter1138
parents: 9827
diff changeset
   150
						_colour_gradient[this->widget[0].color][5], FILLRECT_CHECKER
28606a486c52 (svn r14004) -Codechange: Clean of drop down lists.
peter1138
parents: 9827
diff changeset
   151
					);
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   152
				}
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   153
			}
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   154
			y += item_height;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   155
		}
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   156
	};
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   157
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   158
	virtual void OnClick(Point pt, int widget)
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   159
	{
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   160
		if (widget != 0) return;
9209
2987efebe01d (svn r13075) -Codechange: Allow any value for a dropdown item instead of just positive.
peter1138
parents: 9189
diff changeset
   161
		int item;
2987efebe01d (svn r13075) -Codechange: Allow any value for a dropdown item instead of just positive.
peter1138
parents: 9189
diff changeset
   162
		if (this->GetDropDownItem(item)) {
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   163
			this->click_delay = 4;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   164
			this->selected_index = item;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   165
			this->SetDirty();
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   166
		}
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   167
	}
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   168
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   169
	virtual void OnTick()
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   170
	{
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   171
		if (this->scrolling == -1) {
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   172
			this->vscroll.pos = max(0, this->vscroll.pos - 1);
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   173
			this->SetDirty();
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   174
		} else if (this->scrolling == 1) {
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   175
			this->vscroll.pos = min(this->vscroll.count - this->vscroll.cap, this->vscroll.pos + 1);
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   176
			this->SetDirty();
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   177
		}
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   178
		this->scrolling = 0;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   179
	}
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   180
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   181
	virtual void OnMouseLoop()
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   182
	{
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   183
		Window *w2 = FindWindowById(this->parent_wnd_class, this->parent_wnd_num);
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   184
		if (w2 == NULL) {
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   185
			delete this;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   186
			return;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   187
		}
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   188
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   189
		if (this->click_delay != 0 && --this->click_delay == 0) {
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   190
			w2->OnDropdownSelect(this->parent_button, this->selected_index);
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   191
			delete this;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   192
			return;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   193
		}
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   194
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   195
		if (this->drag_mode) {
9209
2987efebe01d (svn r13075) -Codechange: Allow any value for a dropdown item instead of just positive.
peter1138
parents: 9189
diff changeset
   196
			int item;
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   197
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   198
			if (!_left_button_clicked) {
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   199
				this->drag_mode = false;
9869
548d99e11ad7 (svn r14015) -Codechange: Add facility for a drop down list to always close (if requested) when the mouse button is released.
peter1138
parents: 9868
diff changeset
   200
				if (!this->GetDropDownItem(item)) {
548d99e11ad7 (svn r14015) -Codechange: Add facility for a drop down list to always close (if requested) when the mouse button is released.
peter1138
parents: 9868
diff changeset
   201
					if (this->instant_close) {
548d99e11ad7 (svn r14015) -Codechange: Add facility for a drop down list to always close (if requested) when the mouse button is released.
peter1138
parents: 9868
diff changeset
   202
						if (GetWidgetFromPos(w2, _cursor.pos.x - w2->left, _cursor.pos.y - w2->top) == this->parent_button) {
548d99e11ad7 (svn r14015) -Codechange: Add facility for a drop down list to always close (if requested) when the mouse button is released.
peter1138
parents: 9868
diff changeset
   203
							/* Send event for selected option if we're still
548d99e11ad7 (svn r14015) -Codechange: Add facility for a drop down list to always close (if requested) when the mouse button is released.
peter1138
parents: 9868
diff changeset
   204
							 * on the parent button of the list. */
548d99e11ad7 (svn r14015) -Codechange: Add facility for a drop down list to always close (if requested) when the mouse button is released.
peter1138
parents: 9868
diff changeset
   205
							w2->OnDropdownSelect(this->parent_button, this->selected_index);
548d99e11ad7 (svn r14015) -Codechange: Add facility for a drop down list to always close (if requested) when the mouse button is released.
peter1138
parents: 9868
diff changeset
   206
						}
548d99e11ad7 (svn r14015) -Codechange: Add facility for a drop down list to always close (if requested) when the mouse button is released.
peter1138
parents: 9868
diff changeset
   207
						delete this;
548d99e11ad7 (svn r14015) -Codechange: Add facility for a drop down list to always close (if requested) when the mouse button is released.
peter1138
parents: 9868
diff changeset
   208
					}
548d99e11ad7 (svn r14015) -Codechange: Add facility for a drop down list to always close (if requested) when the mouse button is released.
peter1138
parents: 9868
diff changeset
   209
					return;
548d99e11ad7 (svn r14015) -Codechange: Add facility for a drop down list to always close (if requested) when the mouse button is released.
peter1138
parents: 9868
diff changeset
   210
				}
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   211
				this->click_delay = 2;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   212
			} else {
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   213
				if (_cursor.pos.y <= this->top + 2) {
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   214
					/* Cursor is above the list, set scroll up */
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   215
					this->scrolling = -1;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   216
					return;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   217
				} else if (_cursor.pos.y >= this->top + this->height - 2) {
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   218
					/* Cursor is below list, set scroll down */
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   219
					this->scrolling = 1;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   220
					return;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   221
				}
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   222
9209
2987efebe01d (svn r13075) -Codechange: Allow any value for a dropdown item instead of just positive.
peter1138
parents: 9189
diff changeset
   223
				if (!this->GetDropDownItem(item)) return;
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   224
			}
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   225
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   226
			this->selected_index = item;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   227
			this->SetDirty();
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   228
		}
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   229
	}
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   230
};
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   231
10009
41d822dd3350 (svn r14168) -Codechange: Make dropdown 'auto_width' a separate parameter, so that a minimum width can be specified.
peter1138
parents: 9869
diff changeset
   232
void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width, bool auto_width, bool instant_close)
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   233
{
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   234
	bool is_dropdown_menu_shown = w->IsWidgetLowered(button);
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   235
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   236
	DeleteWindowById(WC_DROPDOWN_MENU, 0);
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   237
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   238
	if (is_dropdown_menu_shown) {
8299
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
   239
		DeleteDropDownList(list);
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   240
		return;
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   241
	}
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   242
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   243
	w->LowerWidget(button);
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   244
	w->InvalidateWidget(button);
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   245
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   246
	/* Our parent's button widget is used to determine where to place the drop
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   247
	 * down list window. */
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   248
	const Widget *wi = &w->widget[button];
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   249
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   250
	/* The preferred position is just below the dropdown calling widget */
8335
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8301
diff changeset
   251
	int top = w->top + wi->bottom + 1;
8905
609b1121b3b3 (svn r12672) -Codechange: Add support for variably-sized drop down list items.
peter1138
parents: 8884
diff changeset
   252
10009
41d822dd3350 (svn r14168) -Codechange: Make dropdown 'auto_width' a separate parameter, so that a minimum width can be specified.
peter1138
parents: 9869
diff changeset
   253
	if (width == 0) width = wi->right - wi->left + 1;
41d822dd3350 (svn r14168) -Codechange: Make dropdown 'auto_width' a separate parameter, so that a minimum width can be specified.
peter1138
parents: 9869
diff changeset
   254
41d822dd3350 (svn r14168) -Codechange: Make dropdown 'auto_width' a separate parameter, so that a minimum width can be specified.
peter1138
parents: 9869
diff changeset
   255
	uint max_item_width = 0;
9868
c529be2a15c5 (svn r14014) -Codechange: Add support for automatically sizing drop down lists to the widest list item.
peter1138
parents: 9859
diff changeset
   256
c529be2a15c5 (svn r14014) -Codechange: Add support for automatically sizing drop down lists to the widest list item.
peter1138
parents: 9859
diff changeset
   257
	if (auto_width) {
c529be2a15c5 (svn r14014) -Codechange: Add support for automatically sizing drop down lists to the widest list item.
peter1138
parents: 9859
diff changeset
   258
		/* Find the longest item in the list */
c529be2a15c5 (svn r14014) -Codechange: Add support for automatically sizing drop down lists to the widest list item.
peter1138
parents: 9859
diff changeset
   259
		for (DropDownList::const_iterator it = list->begin(); it != list->end(); ++it) {
c529be2a15c5 (svn r14014) -Codechange: Add support for automatically sizing drop down lists to the widest list item.
peter1138
parents: 9859
diff changeset
   260
			const DropDownListItem *item = *it;
10009
41d822dd3350 (svn r14168) -Codechange: Make dropdown 'auto_width' a separate parameter, so that a minimum width can be specified.
peter1138
parents: 9869
diff changeset
   261
			max_item_width = max(max_item_width, item->Width() + 5);
9868
c529be2a15c5 (svn r14014) -Codechange: Add support for automatically sizing drop down lists to the widest list item.
peter1138
parents: 9859
diff changeset
   262
		}
c529be2a15c5 (svn r14014) -Codechange: Add support for automatically sizing drop down lists to the widest list item.
peter1138
parents: 9859
diff changeset
   263
	}
c529be2a15c5 (svn r14014) -Codechange: Add support for automatically sizing drop down lists to the widest list item.
peter1138
parents: 9859
diff changeset
   264
8905
609b1121b3b3 (svn r12672) -Codechange: Add support for variably-sized drop down list items.
peter1138
parents: 8884
diff changeset
   265
	/* Total length of list */
609b1121b3b3 (svn r12672) -Codechange: Add support for variably-sized drop down list items.
peter1138
parents: 8884
diff changeset
   266
	int list_height = 0;
609b1121b3b3 (svn r12672) -Codechange: Add support for variably-sized drop down list items.
peter1138
parents: 8884
diff changeset
   267
609b1121b3b3 (svn r12672) -Codechange: Add support for variably-sized drop down list items.
peter1138
parents: 8884
diff changeset
   268
	for (DropDownList::const_iterator it = list->begin(); it != list->end(); ++it) {
609b1121b3b3 (svn r12672) -Codechange: Add support for variably-sized drop down list items.
peter1138
parents: 8884
diff changeset
   269
		DropDownListItem *item = *it;
609b1121b3b3 (svn r12672) -Codechange: Add support for variably-sized drop down list items.
peter1138
parents: 8884
diff changeset
   270
		list_height += item->Height(width);
609b1121b3b3 (svn r12672) -Codechange: Add support for variably-sized drop down list items.
peter1138
parents: 8884
diff changeset
   271
	}
609b1121b3b3 (svn r12672) -Codechange: Add support for variably-sized drop down list items.
peter1138
parents: 8884
diff changeset
   272
609b1121b3b3 (svn r12672) -Codechange: Add support for variably-sized drop down list items.
peter1138
parents: 8884
diff changeset
   273
	/* Height of window visible */
609b1121b3b3 (svn r12672) -Codechange: Add support for variably-sized drop down list items.
peter1138
parents: 8884
diff changeset
   274
	int height = list_height;
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   275
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   276
	/* Check if the status bar is visible, as we don't want to draw over it */
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   277
	Window *w3 = FindWindowById(WC_STATUS_BAR, 0);
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   278
	int screen_bottom = w3 == NULL ? _screen.height : w3->top;
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   279
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   280
	bool scroll = false;
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   281
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   282
	/* Check if the dropdown will fully fit below the widget */
8905
609b1121b3b3 (svn r12672) -Codechange: Add support for variably-sized drop down list items.
peter1138
parents: 8884
diff changeset
   283
	if (top + height + 4 >= screen_bottom) {
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   284
		w3 = FindWindowById(WC_MAIN_TOOLBAR, 0);
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   285
		int screen_top = w3 == NULL ? 0 : w3->top + w3->height;
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   286
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   287
		/* If not, check if it will fit above the widget */
8335
09a2e049b3a8 (svn r11901) -Add: add two widgets for dropdowns, one raised and one inset, to eventually replace use of two widgets for each dropdown control.
peter1138
parents: 8301
diff changeset
   288
		if (w->top + wi->top - height > screen_top) {
8905
609b1121b3b3 (svn r12672) -Codechange: Add support for variably-sized drop down list items.
peter1138
parents: 8884
diff changeset
   289
			top = w->top + wi->top - height - 4;
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   290
		} else {
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   291
			/* ... and lastly if it won't, enable the scroll bar and fit the
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   292
			 * list in below the widget */
9390
88d36f907e96 (svn r13301) -Fix [FS#1997]: resolve more MSVC 9 x64 warnings.
rubidium
parents: 9374
diff changeset
   293
			int avg_height = list_height / (int)list->size();
8905
609b1121b3b3 (svn r12672) -Codechange: Add support for variably-sized drop down list items.
peter1138
parents: 8884
diff changeset
   294
			int rows = (screen_bottom - 4 - top) / avg_height;
609b1121b3b3 (svn r12672) -Codechange: Add support for variably-sized drop down list items.
peter1138
parents: 8884
diff changeset
   295
			height = rows * avg_height;
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   296
			scroll = true;
9868
c529be2a15c5 (svn r14014) -Codechange: Add support for automatically sizing drop down lists to the widest list item.
peter1138
parents: 9859
diff changeset
   297
			/* Add space for the scroll bar if we automatically determined
c529be2a15c5 (svn r14014) -Codechange: Add support for automatically sizing drop down lists to the widest list item.
peter1138
parents: 9859
diff changeset
   298
			 * the width of the list. */
10009
41d822dd3350 (svn r14168) -Codechange: Make dropdown 'auto_width' a separate parameter, so that a minimum width can be specified.
peter1138
parents: 9869
diff changeset
   299
			max_item_width += 12;
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   300
		}
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   301
	}
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   302
10009
41d822dd3350 (svn r14168) -Codechange: Make dropdown 'auto_width' a separate parameter, so that a minimum width can be specified.
peter1138
parents: 9869
diff changeset
   303
	if (auto_width) width = max(width, max_item_width);
41d822dd3350 (svn r14168) -Codechange: Make dropdown 'auto_width' a separate parameter, so that a minimum width can be specified.
peter1138
parents: 9869
diff changeset
   304
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   305
	DropdownWindow *dw = new DropdownWindow(
8358
cbd1a077e375 (svn r11924) -Codechange: All dropdowns now use the dropdown widget, so compatibility code can be removed
peter1138
parents: 8335
diff changeset
   306
		w->left + wi->left,
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   307
		top,
8877
f09f03b0dc64 (svn r12644) -Codechange: rework the order gui a little to prepare it for some future changes.
rubidium
parents: 8857
diff changeset
   308
		width,
8905
609b1121b3b3 (svn r12672) -Codechange: Add support for variably-sized drop down list items.
peter1138
parents: 8884
diff changeset
   309
		height + 4,
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   310
		_dropdown_menu_widgets);
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   311
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   312
	dw->widget[0].color = wi->color;
8884
cebc13b06266 (svn r12651) -Fix (r12644) [FS#1915]: Dropdown widget width should be one pixel less than window width, not one more.
peter1138
parents: 8877
diff changeset
   313
	dw->widget[0].right = width - 1;
8905
609b1121b3b3 (svn r12672) -Codechange: Add support for variably-sized drop down list items.
peter1138
parents: 8884
diff changeset
   314
	dw->widget[0].bottom = height + 3;
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   315
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   316
	dw->SetWidgetHiddenState(1, !scroll);
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   317
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   318
	if (scroll) {
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   319
		/* We're scrolling, so enable the scroll bar and shrink the list by
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   320
		 * the scrollbar's width */
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   321
		dw->widget[1].color  = wi->color;
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   322
		dw->widget[1].right  = dw->widget[0].right;
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   323
		dw->widget[1].left   = dw->widget[1].right - 11;
8905
609b1121b3b3 (svn r12672) -Codechange: Add support for variably-sized drop down list items.
peter1138
parents: 8884
diff changeset
   324
		dw->widget[1].bottom = dw->widget[0].bottom;
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   325
		dw->widget[0].right -= 12;
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   326
8905
609b1121b3b3 (svn r12672) -Codechange: Add support for variably-sized drop down list items.
peter1138
parents: 8884
diff changeset
   327
		/* Capacity is the average number of items visible */
9390
88d36f907e96 (svn r13301) -Fix [FS#1997]: resolve more MSVC 9 x64 warnings.
rubidium
parents: 9374
diff changeset
   328
		dw->vscroll.cap   = height * (uint16)list->size() / list_height;
88d36f907e96 (svn r13301) -Fix [FS#1997]: resolve more MSVC 9 x64 warnings.
rubidium
parents: 9374
diff changeset
   329
		dw->vscroll.count = (uint16)list->size();
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   330
	}
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   331
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   332
	dw->desc_flags = WDF_DEF_WIDGET;
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   333
	dw->flags4 &= ~WF_WHITE_BORDER_MASK;
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   334
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   335
	dw->parent_wnd_class = w->window_class;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   336
	dw->parent_wnd_num   = w->window_number;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   337
	dw->parent_button    = button;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   338
	dw->list             = list;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   339
	dw->selected_index   = selected;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   340
	dw->click_delay      = 0;
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   341
	dw->drag_mode        = true;
9869
548d99e11ad7 (svn r14015) -Codechange: Add facility for a drop down list to always close (if requested) when the mouse button is released.
peter1138
parents: 9868
diff changeset
   342
	dw->instant_close    = instant_close;
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   343
}
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   344
8877
f09f03b0dc64 (svn r12644) -Codechange: rework the order gui a little to prepare it for some future changes.
rubidium
parents: 8857
diff changeset
   345
void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   346
{
8299
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
   347
	/* Don't create a new list if we're just closing an existing menu */
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
   348
	if (w->IsWidgetLowered(button)) {
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
   349
		DeleteWindowById(WC_DROPDOWN_MENU, 0);
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
   350
		return;
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
   351
	}
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
   352
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   353
	uint result = 0;
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   354
	DropDownList *list = new DropDownList();
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   355
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   356
	for (uint i = 0; strings[i] != INVALID_STRING_ID; i++) {
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   357
		if (!HasBit(hidden_mask, i)) {
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   358
			list->push_back(new DropDownListStringItem(strings[i], result, HasBit(disabled_mask, i)));
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   359
		}
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   360
		result++;
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   361
	}
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   362
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   363
	/* No entries in the list? */
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   364
	if (list->size() == 0) {
8299
e8b5a9aef71a (svn r11863) -Fix (r11848): One day I'll learn C++... Delete all items in a drop down list before deleting the list.
peter1138
parents: 8294
diff changeset
   365
		DeleteDropDownList(list);
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   366
		return;
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   367
	}
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   368
8877
f09f03b0dc64 (svn r12644) -Codechange: rework the order gui a little to prepare it for some future changes.
rubidium
parents: 8857
diff changeset
   369
	ShowDropDownList(w, list, selected, button, width);
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   370
}
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   371
8857
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8543
diff changeset
   372
/**
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8543
diff changeset
   373
 * Delete the drop-down menu from window \a pw
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8543
diff changeset
   374
 * @param pw Parent window of the drop-down menu window
7593af4962e6 (svn r12619) -Codechange: lots of documentation about window related stuff. Patch by Alberth.
rubidium
parents: 8543
diff changeset
   375
 */
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   376
void HideDropDownMenu(Window *pw)
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   377
{
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   378
	Window **wz;
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   379
	FOR_ALL_WINDOWS(wz) {
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   380
		if ((*wz)->window_class != WC_DROPDOWN_MENU) continue;
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   381
9189
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   382
		DropdownWindow *dw = dynamic_cast<DropdownWindow*>(*wz);
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   383
		if (pw->window_class == dw->parent_wnd_class &&
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   384
				pw->window_number == dw->parent_wnd_num) {
128a1809a977 (svn r13052) -Codechange: make a class of the DropdownWindow.
rubidium
parents: 9166
diff changeset
   385
			delete dw;
8284
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   386
			break;
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   387
		}
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   388
	}
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   389
}
ebdc5ba08874 (svn r11848) -Codechange: New class-based drop down list functionality. Lists are now dynamically generated, and can include parameters, or be extended however needed.
peter1138
parents:
diff changeset
   390