libui/redo/darwin/combobox.m

68 lines
1.5 KiB
Mathematica
Raw Normal View History

// 11 june 2015
2015-07-11 16:02:01 -05:00
#include "uipriv_darwin.h"
struct combobox {
uiCombobox c;
2015-07-27 22:38:44 -05:00
BOOL editable;
NSPopUpButton *pb;
NSComboBox *cb;
};
uiDefineControlType(uiCombobox, uiTypeCombobox, struct combobox)
static uintptr_t comboboxHandle(uiControl *cc)
{
struct combobox *c = (struct combobox *) cc;
2015-07-27 22:38:44 -05:00
if (c->editable)
return (uintptr_t) (c->cb);
return (uintptr_t) (c->pb);
}
static void comboboxAppend(uiCombobox *cc, const char *text)
{
struct combobox *c = (struct combobox *) cc;
PUT_CODE_HERE;
}
2015-07-27 22:38:44 -05:00
static uiCombobox *finishNewCombobox(BOOL editable)
{
struct combobox *c;
2015-07-27 22:38:44 -05:00
c = (struct combobox *) uiNewControl(uiTypeCombobox());
2015-07-27 22:38:44 -05:00
c->editable = editable;
if (c->editable) {
c->cb = [[NSComboBox alloc] initWithFrame:NSZeroRect];
[c->cb setUsesDataSource:NO];
[c->cb setButtonBordered:YES];
NSLog(@"TEST intercellSpacing %@", NSStringFromSize([c->cb intercellSpacing]);
[c->cb setCompletes:NO];
uiDarwinMakeSingleViewControl(uiControl(c), c->cb, YES);
NSLog(@"TEST intercellSpacing %@", NSStringFromSize([c->cb intercellSpacing]);
} else {
c->pb = [[NSPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:NO];
// TODO preferred edge
// TODO arrow position
// TODO font
uiDarwinMakeSingleViewControl(uiControl(c), c->cb, YES);
}
uiControl(c)->Handle = comboboxHandle;
uiCombobox(c)->Append = comboboxAppend;
return uiCombobox(c);
}
uiCombobox *uiNewCombobox(void)
{
2015-07-27 22:38:44 -05:00
return finishNewCombobox(NO);
}
uiCombobox *uiNewEditableCombobox(void)
{
2015-07-27 22:38:44 -05:00
return finishNewCombobox(YES);
}