From 581cbaecc9483f57442b21634457df66549baa3e Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 9 Oct 2015 13:47:02 -0400 Subject: [PATCH] Added uiComboboxSetSelected(), which we need for the uiArea drawing tests. Will implement next. --- test/drawtests.c | 9 +++++++++ test/page6.c | 15 +++++++++++++++ test/test.h | 1 + ui.h | 2 +- 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/test/drawtests.c b/test/drawtests.c index dec8baa4..5e105b10 100644 --- a/test/drawtests.c +++ b/test/drawtests.c @@ -223,9 +223,18 @@ static void drawOriginal(uiAreaDrawParams *p) static const struct drawtest tests[] = { { "Original uiArea test", drawOriginal }, + { NULL, NULL }, }; void runDrawTest(intmax_t n, uiAreaDrawParams *p) { (*(tests[n].draw))(p); } + +void populateComboboxWithTests(uiCombobox *c) +{ + size_t i; + + for (i = 0; test[i].name != NULL; i++) + uiComboboxAppend(c, tests[i].name); +} diff --git a/test/page6.c b/test/page6.c index f62776c7..41a45d6e 100644 --- a/test/page6.c +++ b/test/page6.c @@ -78,6 +78,16 @@ static void onAmountChanged(uiSpinbox *s, void *data) uiAreaUpdateScroll(area); } +static void shouldntHappen(uiCombobox *c, void *data) +{ + fprintf(stderr, "YOU SHOULD NOT SEE THIS. If you do, uiComboboxSetSelected() is triggering uiComboboxOnSelected(), which it should not."); +} + +static void redraw(uiCombobox *c, void *data) +{ + // TODO +} + uiBox *makePage6(void) { uiBox *page6; @@ -97,6 +107,11 @@ uiBox *makePage6(void) uiBoxAppend(page6, uiControl(hbox), 0); which = uiNewCombobox(); + populateComboboxWithTests(which); + // this is to make sure that uiComboboxOnSelected() doesn't trigger with uiComboboxSetSelected() + uiComboboxOnSelected(which, shouldntHappen, NULL); + uiComboboxSetSelected(which, 0); + uiComboboxOnSelected(which, redraw, NULL); uiBoxAppend(hbox, uiControl(which), 0); // make these first in case the area handler calls the information as part of the constructor diff --git a/test/test.h b/test/test.h index 2f6b64f7..59436603 100644 --- a/test/test.h +++ b/test/test.h @@ -52,3 +52,4 @@ extern uiBox *makePage6(void); // drawtests.c extern void runDrawTest(intmax_t, uiAreaDrawParams *); +extern void populateComboboxWithTests(uiCombobox *); diff --git a/ui.h b/ui.h index ff4c9274..e5efca3b 100644 --- a/ui.h +++ b/ui.h @@ -203,7 +203,7 @@ _UI_EXTERN uintmax_t uiComboboxType(void); #define uiCombobox(this) ((uiCombobox *) uiIsA((this), uiComboboxType(), 1)) _UI_EXTERN void uiComboboxAppend(uiCombobox *c, const char *text); _UI_EXTERN intmax_t uiComboboxSelected(uiCombobox *c); -// TODO SetSelected +_UI_EXTERN void uiComboboxSetSelected(uiCombobox *c, intmax_t n); _UI_EXTERN void uiComboboxOnSelected(uiCombobox *c, void (*f)(uiCombobox *c, void *data), void *data); _UI_EXTERN uiCombobox *uiNewCombobox(void); _UI_EXTERN uiCombobox *uiNewEditableCombobox(void);