diff --git a/darwin/combobox.m b/darwin/combobox.m index cc2f330a..9cf7f925 100644 --- a/darwin/combobox.m +++ b/darwin/combobox.m @@ -81,6 +81,21 @@ void uiComboboxAppend(uiCombobox *c, const char *text) [c->pbac addObject:uiprivToNSString(text)]; } +void uiComboboxInsertAt(uiCombobox *c, int n, const char *text) +{ + [c->pbac insert:uiprivToNSString(text) atArrangedObjectIndex:n]; +} + +void uiComboboxDelete(uiCombobox *c, int n) +{ + [c->pb removeItemAtIndex:n]; +} + +void uiComboboxClear(uiCombobox *c) +{ + [c->pb removeAllItems]; +} + int uiComboboxSelected(uiCombobox *c) { return [c->pb indexOfSelectedItem]; diff --git a/test/page4.c b/test/page4.c index ce4a6afb..4c683574 100644 --- a/test/page4.c +++ b/test/page4.c @@ -39,6 +39,21 @@ static void appendCBRB(uiButton *b, void *data) uiRadioButtonsAppend(rb, "New Item"); } +static void insertCB(uiButton *b, void *data) +{ + uiComboboxInsertAt(cbox, 0, "Inserted item"); +} + +static void deleteCB(uiButton *b, void *data) +{ + uiComboboxDelete(cbox, 0); +} + +static void clearCB(uiButton *b, void *data) +{ + uiComboboxClear(cbox); +} + static void onCBChanged(uiCombobox *c, void *data) { printf("%s combobox changed to %d\n", @@ -147,6 +162,15 @@ uiBox *makePage4(void) b = uiNewButton("Append"); uiButtonOnClicked(b, appendCBRB, NULL); uiBoxAppend(hbox, uiControl(b), 0); + b = uiNewButton("Insert"); + uiButtonOnClicked(b, insertCB, NULL); + uiBoxAppend(hbox, uiControl(b), 0); + b = uiNewButton("Delete"); + uiButtonOnClicked(b, deleteCB, NULL); + uiBoxAppend(hbox, uiControl(b), 0); + b = uiNewButton("Clear"); + uiButtonOnClicked(b, clearCB, NULL); + uiBoxAppend(hbox, uiControl(b), 0); b = uiNewButton("Second"); uiButtonOnClicked(b, selectSecond, NULL); uiBoxAppend(hbox, uiControl(b), 0); diff --git a/ui.h b/ui.h index 40aea949..c9c225cb 100644 --- a/ui.h +++ b/ui.h @@ -226,6 +226,9 @@ _UI_EXTERN uiSeparator *uiNewVerticalSeparator(void); typedef struct uiCombobox uiCombobox; #define uiCombobox(this) ((uiCombobox *) (this)) _UI_EXTERN void uiComboboxAppend(uiCombobox *c, const char *text); +_UI_EXTERN void uiComboboxInsertAt(uiCombobox *c, int n, const char *text); +_UI_EXTERN void uiComboboxDelete(uiCombobox *c, int n); +_UI_EXTERN void uiComboboxClear(uiCombobox *c); _UI_EXTERN int uiComboboxSelected(uiCombobox *c); _UI_EXTERN void uiComboboxSetSelected(uiCombobox *c, int n); _UI_EXTERN void uiComboboxOnSelected(uiCombobox *c, void (*f)(uiCombobox *c, void *data), void *data); diff --git a/unix/combobox.c b/unix/combobox.c index 6fed804b..5dfeb6f1 100644 --- a/unix/combobox.c +++ b/unix/combobox.c @@ -30,6 +30,21 @@ void uiComboboxAppend(uiCombobox *c, const char *text) gtk_combo_box_text_append(c->comboboxText, NULL, text); } +void uiComboboxInsertAt(uiCombobox *c, int n, const char *text) +{ + gtk_combo_box_text_insert(c->comboboxText, n, NULL, text); +} + +void uiComboboxDelete(uiCombobox *c, int n) +{ + gtk_combo_box_text_remove(c->comboboxText, n); +} + +void uiComboboxClear(uiCombobox *c) +{ + gtk_combo_box_text_remove_all(c->comboboxText); +} + int uiComboboxSelected(uiCombobox *c) { return gtk_combo_box_get_active(c->combobox); diff --git a/windows/combobox.cpp b/windows/combobox.cpp index 50f49dd7..bee0e1c2 100644 --- a/windows/combobox.cpp +++ b/windows/combobox.cpp @@ -69,6 +69,38 @@ void uiComboboxAppend(uiCombobox *c, const char *text) uiprivFree(wtext); } +void uiComboboxInsertAt(uiCombobox *c, int n, const char *text) +{ + WCHAR *wtext; + LRESULT res; + + wtext = toUTF16(text); + res = SendMessageW(c->hwnd, CB_INSERTSTRING, (WPARAM)n, (LPARAM) wtext); + if (res == (LRESULT) CB_ERR) + logLastError(L"error inserting item to uiCombobox"); + else if (res == (LRESULT) CB_ERRSPACE) + logLastError(L"memory exhausted inserting item to uiCombobox"); + uiprivFree(wtext); +} + +void uiComboboxDelete(uiCombobox *c, int n) +{ + LRESULT res; + + res = SendMessage(c->hwnd, CB_DELETESTRING, (WPARAM)n, 0); + if (res == (LRESULT) CB_ERR) + logLastError(L"error removing item from uiCombobox"); +} + +void uiComboboxClear(uiCombobox *c) +{ + LRESULT res; + + res = SendMessage(c->hwnd, CB_RESETCONTENT, 0, 0); + if (res == (LRESULT) CB_ERR) + logLastError(L"error clearing items from uiCombobox"); +} + int uiComboboxSelected(uiCombobox *c) { LRESULT n;