equal
deleted
inserted
replaced
227 this->SetDirty(); |
227 this->SetDirty(); |
228 } |
228 } |
229 } |
229 } |
230 }; |
230 }; |
231 |
231 |
232 void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width, bool instant_close) |
232 void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width, bool auto_width, bool instant_close) |
233 { |
233 { |
234 bool is_dropdown_menu_shown = w->IsWidgetLowered(button); |
234 bool is_dropdown_menu_shown = w->IsWidgetLowered(button); |
235 |
235 |
236 DeleteWindowById(WC_DROPDOWN_MENU, 0); |
236 DeleteWindowById(WC_DROPDOWN_MENU, 0); |
237 |
237 |
248 const Widget *wi = &w->widget[button]; |
248 const Widget *wi = &w->widget[button]; |
249 |
249 |
250 /* The preferred position is just below the dropdown calling widget */ |
250 /* The preferred position is just below the dropdown calling widget */ |
251 int top = w->top + wi->bottom + 1; |
251 int top = w->top + wi->bottom + 1; |
252 |
252 |
253 bool auto_width = (width == UINT_MAX); |
253 if (width == 0) width = wi->right - wi->left + 1; |
|
254 |
|
255 uint max_item_width = 0; |
254 |
256 |
255 if (auto_width) { |
257 if (auto_width) { |
256 /* Find the longest item in the list */ |
258 /* Find the longest item in the list */ |
257 width = 0; |
|
258 for (DropDownList::const_iterator it = list->begin(); it != list->end(); ++it) { |
259 for (DropDownList::const_iterator it = list->begin(); it != list->end(); ++it) { |
259 const DropDownListItem *item = *it; |
260 const DropDownListItem *item = *it; |
260 width = max(width, item->Width() + 5); |
261 max_item_width = max(max_item_width, item->Width() + 5); |
261 } |
262 } |
262 } else if (width == 0) { |
|
263 width = wi->right - wi->left + 1; |
|
264 } |
263 } |
265 |
264 |
266 /* Total length of list */ |
265 /* Total length of list */ |
267 int list_height = 0; |
266 int list_height = 0; |
268 |
267 |
295 int rows = (screen_bottom - 4 - top) / avg_height; |
294 int rows = (screen_bottom - 4 - top) / avg_height; |
296 height = rows * avg_height; |
295 height = rows * avg_height; |
297 scroll = true; |
296 scroll = true; |
298 /* Add space for the scroll bar if we automatically determined |
297 /* Add space for the scroll bar if we automatically determined |
299 * the width of the list. */ |
298 * the width of the list. */ |
300 if (auto_width) width += 12; |
299 max_item_width += 12; |
301 } |
300 } |
302 } |
301 } |
|
302 |
|
303 if (auto_width) width = max(width, max_item_width); |
303 |
304 |
304 DropdownWindow *dw = new DropdownWindow( |
305 DropdownWindow *dw = new DropdownWindow( |
305 w->left + wi->left, |
306 w->left + wi->left, |
306 top, |
307 top, |
307 width, |
308 width, |