This commit is contained in:
Trond Arne Bråthen 2021-01-02 10:21:30 -05:00 committed by GitHub
commit 57d413284d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 89 additions and 0 deletions

View File

@ -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];

View File

@ -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);

3
ui.h
View File

@ -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);

View File

@ -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);

View File

@ -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;