Skip to content

Commit

Permalink
Close dropdown list popup windows when clicking outside the window.
Browse files Browse the repository at this point in the history
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 2323
  • Loading branch information
fragglet committed Apr 4, 2011
1 parent eac4192 commit 954eeae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@
panes.
* Clicking on scroll bars now moves the scroll handle to a
matching location.
* Clicking outside a dropdown list popup window now dismisses the
window.

1.5.0 (2011-01-02):

Expand Down
17 changes: 17 additions & 0 deletions textscreen/txt_dropdown.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ static int SelectorWindowListener(txt_window_t *window, int key, void *user_data
return 0;
}

static int SelectorMouseListener(txt_window_t *window, int x, int y, int b,
void *unused)
{
txt_widget_t *win;

win = (txt_widget_t *) window;

if (x < win->x || x > win->x + win->w || y < win->y || y > win->y + win->h)
{
TXT_CloseWindow(window);
return 1;
}

return 0;
}

// Open the dropdown list window to select an item

static void OpenSelectorWindow(txt_dropdown_list_t *list)
Expand Down Expand Up @@ -158,6 +174,7 @@ static void OpenSelectorWindow(txt_dropdown_list_t *list)
// Catch presses of escape in this window and close it.

TXT_SetKeyListener(window, SelectorWindowListener, NULL);
TXT_SetMouseListener(window, SelectorMouseListener, NULL);
}

static int DropdownListWidth(txt_dropdown_list_t *list)
Expand Down

0 comments on commit 954eeae

Please sign in to comment.