changeset 9869 | 548d99e11ad7 |
parent 9868 | c529be2a15c5 |
child 10009 | 41d822dd3350 |
9868:c529be2a15c5 | 9869:548d99e11ad7 |
---|---|
69 byte parent_button; |
69 byte parent_button; |
70 DropDownList *list; |
70 DropDownList *list; |
71 int selected_index; |
71 int selected_index; |
72 byte click_delay; |
72 byte click_delay; |
73 bool drag_mode; |
73 bool drag_mode; |
74 bool instant_close; |
|
74 int scrolling; |
75 int scrolling; |
75 |
76 |
76 DropdownWindow(int x, int y, int width, int height, const Widget *widget) : Window(x, y, width, height, WC_DROPDOWN_MENU, widget) |
77 DropdownWindow(int x, int y, int width, int height, const Widget *widget) : Window(x, y, width, height, WC_DROPDOWN_MENU, widget) |
77 { |
78 { |
78 this->FindWindowPlacementAndResize(width, height); |
79 this->FindWindowPlacementAndResize(width, height); |
194 if (this->drag_mode) { |
195 if (this->drag_mode) { |
195 int item; |
196 int item; |
196 |
197 |
197 if (!_left_button_clicked) { |
198 if (!_left_button_clicked) { |
198 this->drag_mode = false; |
199 this->drag_mode = false; |
199 if (!this->GetDropDownItem(item)) return; |
200 if (!this->GetDropDownItem(item)) { |
201 if (this->instant_close) { |
|
202 if (GetWidgetFromPos(w2, _cursor.pos.x - w2->left, _cursor.pos.y - w2->top) == this->parent_button) { |
|
203 /* Send event for selected option if we're still |
|
204 * on the parent button of the list. */ |
|
205 w2->OnDropdownSelect(this->parent_button, this->selected_index); |
|
206 } |
|
207 delete this; |
|
208 } |
|
209 return; |
|
210 } |
|
200 this->click_delay = 2; |
211 this->click_delay = 2; |
201 } else { |
212 } else { |
202 if (_cursor.pos.y <= this->top + 2) { |
213 if (_cursor.pos.y <= this->top + 2) { |
203 /* Cursor is above the list, set scroll up */ |
214 /* Cursor is above the list, set scroll up */ |
204 this->scrolling = -1; |
215 this->scrolling = -1; |
216 this->SetDirty(); |
227 this->SetDirty(); |
217 } |
228 } |
218 } |
229 } |
219 }; |
230 }; |
220 |
231 |
221 void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width) |
232 void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width, bool instant_close) |
222 { |
233 { |
223 bool is_dropdown_menu_shown = w->IsWidgetLowered(button); |
234 bool is_dropdown_menu_shown = w->IsWidgetLowered(button); |
224 |
235 |
225 DeleteWindowById(WC_DROPDOWN_MENU, 0); |
236 DeleteWindowById(WC_DROPDOWN_MENU, 0); |
226 |
237 |
325 dw->parent_button = button; |
336 dw->parent_button = button; |
326 dw->list = list; |
337 dw->list = list; |
327 dw->selected_index = selected; |
338 dw->selected_index = selected; |
328 dw->click_delay = 0; |
339 dw->click_delay = 0; |
329 dw->drag_mode = true; |
340 dw->drag_mode = true; |
341 dw->instant_close = instant_close; |
|
330 } |
342 } |
331 |
343 |
332 void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width) |
344 void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width) |
333 { |
345 { |
334 /* Don't create a new list if we're just closing an existing menu */ |
346 /* Don't create a new list if we're just closing an existing menu */ |