summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Fleischer <calcurse@cryptocrack.de>2014-07-18 08:19:12 +0200
committerLukas Fleischer <calcurse@cryptocrack.de>2014-07-18 08:30:09 +0200
commit80a7267f8c03a1c307b4f6b9bee1a906f53a0a01 (patch)
tree36281a483e856ece21a70efac2504f7d5d58cce4
parent0ad6ff74df54c58afeca5b755054667728c53c1e (diff)
downloadcalcurse-80a7267f8c03a1c307b4f6b9bee1a906f53a0a01.tar.gz
calcurse-80a7267f8c03a1c307b4f6b9bee1a906f53a0a01.zip
Fix selection in listbox_load_items()
Call listbox_fix_sel() after setting an initial selection in listbox_load_items() to make sure we do not pick a caption row. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
-rw-r--r--src/listbox.c20
1 files changed, 13 insertions, 7 deletions
diff --git a/src/listbox.c b/src/listbox.c
index 853dc03..c886dce 100644
--- a/src/listbox.c
+++ b/src/listbox.c
@@ -82,20 +82,18 @@ void listbox_set_cb_data(struct listbox *lb, void *cb_data)
lb->cb_data = cb_data;
}
+static void listbox_fix_sel(struct listbox *, int);
+
void listbox_load_items(struct listbox *lb, int item_count)
{
int i, ch;
lb->item_count = item_count;
- if (item_count > 0 && lb->item_sel < 0)
- lb->item_sel = 0;
-
- if (lb->item_sel >= item_count)
- lb->item_sel = item_count - 1;
-
- if (item_count == 0)
+ if (item_count == 0) {
+ lb->item_sel = -1;
return;
+ }
free(lb->type);
free(lb->ch);
@@ -109,6 +107,14 @@ void listbox_load_items(struct listbox *lb, int item_count)
lb->ch[item_count] = ch;
wins_scrollwin_set_linecount(&(lb->sw), ch);
+
+ if (item_count > 0 && lb->item_sel < 0) {
+ lb->item_sel = 0;
+ listbox_fix_sel(lb, 1);
+ } else if (lb->item_sel >= item_count) {
+ lb->item_sel = item_count - 1;
+ listbox_fix_sel(lb, -1);
+ }
}
void listbox_draw_deco(struct listbox *lb, int hilt)