Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing ComboBox features #468

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions darwin/combobox.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
24 changes: 24 additions & 0 deletions test/page4.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions unix/combobox.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
32 changes: 32 additions & 0 deletions windows/combobox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down