~DropdownWindow() { /* Make the dropdown "invisible", so it doesn't affect new window placement. * Also mark it dirty in case the callback deals with the screen. (e.g. screenshots). */ this->window_class = WC_INVALID; this->SetDirty(); Window *w2 = FindWindowById(this->parent_wnd_class, this->parent_wnd_num); if (w2 != NULL) { Point pt = _cursor.pos; pt.x -= w2->left; pt.y -= w2->top; w2->OnDropdownClose(pt, this->parent_button, this->selected_index, this->instant_close); } DeleteDropDownList(this->list); }
/** * Show a dropdown menu window near a widget of the parent window. * The result code of the items is their index in the #strings list. * @param w Parent window that wants the dropdown menu. * @param strings Menu list, end with #INVALID_STRING_ID * @param selected Index of initial selected item. * @param button Button widget number of the parent window #w that wants the dropdown menu. * @param disabled_mask Bitmask for diabled items (items with their bit set are not copied to the dropdown list). * @param hidden_mask Bitmask for hidden items (items with their bit set are displayed, but not selectable in the dropdown list). * @param width Width of the dropdown menu. If \c 0, use the width of parent widget #button. */ void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width) { DropDownList *list = new DropDownList(); for (uint i = 0; strings[i] != INVALID_STRING_ID; i++) { if (!HasBit(hidden_mask, i)) { list->push_back(new DropDownListStringItem(strings[i], i, HasBit(disabled_mask, i))); } } /* No entries in the list? */ if (list->size() == 0) { DeleteDropDownList(list); return; } ShowDropDownList(w, list, selected, button, width); }
~DropdownWindow() { Window *w2 = FindWindowById(this->parent_wnd_class, this->parent_wnd_num); if (w2 != NULL) { if (w2->nested_array != NULL) { NWidgetCore *nwi2 = w2->GetWidget<NWidgetCore>(this->parent_button); if (nwi2->type == NWID_BUTTON_DROPDOWN) { nwi2->disp_flags &= ~ND_DROPDOWN_ACTIVE; } else { w2->RaiseWidget(this->parent_button); } } else { w2->RaiseWidget(this->parent_button); } w2->SetWidgetDirty(this->parent_button); } DeleteDropDownList(this->list); }