src/widgets/dropdown.cpp
branchNewGRF_ports
changeset 10184 fcf5fb2548eb
parent 6878 7d1ff2f621c7
child 10192 195d7f6dcf71
equal deleted inserted replaced
10179:eec5a7dcbf61 10184:fcf5fb2548eb
   199 			DeleteDropDownList(WP(w, dropdown_d).list);
   199 			DeleteDropDownList(WP(w, dropdown_d).list);
   200 		} break;
   200 		} break;
   201 	}
   201 	}
   202 }
   202 }
   203 
   203 
   204 void ShowDropDownList(Window *w, DropDownList *list, int selected, int button)
   204 void ShowDropDownList(Window *w, DropDownList *list, int selected, int button, uint width)
   205 {
   205 {
   206 	bool is_dropdown_menu_shown = w->IsWidgetLowered(button);
   206 	bool is_dropdown_menu_shown = w->IsWidgetLowered(button);
   207 
   207 
   208 	DeleteWindowById(WC_DROPDOWN_MENU, 0);
   208 	DeleteWindowById(WC_DROPDOWN_MENU, 0);
   209 
   209 
   244 			height = rows * 10 + 4;
   244 			height = rows * 10 + 4;
   245 			scroll = true;
   245 			scroll = true;
   246 		}
   246 		}
   247 	}
   247 	}
   248 
   248 
       
   249 	if (width == 0) width = wi->right - wi->left + 1;
       
   250 
   249 	Window *dw = AllocateWindow(
   251 	Window *dw = AllocateWindow(
   250 		w->left + wi->left,
   252 		w->left + wi->left,
   251 		top,
   253 		top,
   252 		wi->right - wi->left + 1,
   254 		width,
   253 		height,
   255 		height,
   254 		DropDownMenuWndProc,
   256 		DropDownMenuWndProc,
   255 		WC_DROPDOWN_MENU,
   257 		WC_DROPDOWN_MENU,
   256 		_dropdown_menu_widgets);
   258 		_dropdown_menu_widgets);
   257 
   259 
   258 	dw->widget[0].color = wi->color;
   260 	dw->widget[0].color = wi->color;
   259 	dw->widget[0].right = wi->right - wi->left;
   261 	dw->widget[0].right = width + 1;
   260 	dw->widget[0].bottom = height - 1;
   262 	dw->widget[0].bottom = height - 1;
   261 
   263 
   262 	dw->SetWidgetHiddenState(1, !scroll);
   264 	dw->SetWidgetHiddenState(1, !scroll);
   263 
   265 
   264 	if (scroll) {
   266 	if (scroll) {
   284 	WP(dw, dropdown_d).selected_index   = selected;
   286 	WP(dw, dropdown_d).selected_index   = selected;
   285 	WP(dw, dropdown_d).click_delay      = 0;
   287 	WP(dw, dropdown_d).click_delay      = 0;
   286 	WP(dw, dropdown_d).drag_mode        = true;
   288 	WP(dw, dropdown_d).drag_mode        = true;
   287 }
   289 }
   288 
   290 
   289 void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask)
   291 void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width)
   290 {
   292 {
   291 	/* Don't create a new list if we're just closing an existing menu */
   293 	/* Don't create a new list if we're just closing an existing menu */
   292 	if (w->IsWidgetLowered(button)) {
   294 	if (w->IsWidgetLowered(button)) {
   293 		DeleteWindowById(WC_DROPDOWN_MENU, 0);
   295 		DeleteWindowById(WC_DROPDOWN_MENU, 0);
   294 		return;
   296 		return;
   308 	if (list->size() == 0) {
   310 	if (list->size() == 0) {
   309 		DeleteDropDownList(list);
   311 		DeleteDropDownList(list);
   310 		return;
   312 		return;
   311 	}
   313 	}
   312 
   314 
   313 	ShowDropDownList(w, list, selected, button);
   315 	ShowDropDownList(w, list, selected, button, width);
   314 }
   316 }
   315 
   317 
       
   318 /**
       
   319  * Delete the drop-down menu from window \a pw
       
   320  * @param pw Parent window of the drop-down menu window
       
   321  */
   316 void HideDropDownMenu(Window *pw)
   322 void HideDropDownMenu(Window *pw)
   317 {
   323 {
   318 	Window **wz;
   324 	Window **wz;
   319 	FOR_ALL_WINDOWS(wz) {
   325 	FOR_ALL_WINDOWS(wz) {
   320 		if ((*wz)->window_class != WC_DROPDOWN_MENU) continue;
   326 		if ((*wz)->window_class != WC_DROPDOWN_MENU) continue;