Fix crash when selecting the selected item from a dropdown menu

This commit is contained in:
Celtic Minstrel 2016-09-27 19:17:50 -04:00
parent 296902d426
commit 6c2e2e9bf7

View file

@ -33,6 +33,14 @@ REGISTER_DIALOG(drop_down_list)
namespace {
void click_callback(twindow& window, bool&, bool&, tpoint coordinate)
{
// By deselecting any selected row here, we remove the possibility that the click actually deselects the row
// and results in selected_item_ being set to -1.
// It works because this handler is called *before* the listbox's click handler.
tlistbox& list = find_widget<tlistbox>(&window, "list", true);
int sel = list.get_selected_row();
if(sel >= 0) {
list.select_row(sel, false);
}
SDL_Rect rect = window.get_rectangle();
if(coordinate.x < rect.x || coordinate.x > rect.x + rect.w || coordinate.y < rect.y || coordinate.y > rect.y + rect.h ) {
window.set_retval(twindow::CANCEL);