More uiCombobox work and TODOs.
This commit is contained in:
parent
b7db41d7e8
commit
db05b745f5
|
@ -1,26 +1,42 @@
|
||||||
// 14 august 2015
|
// 14 august 2015
|
||||||
#include "uipriv_darwin.h"
|
#include "uipriv_darwin.h"
|
||||||
|
|
||||||
|
// TODOs:
|
||||||
|
// - 10.8: edges of NSPopUpButton clipped
|
||||||
|
|
||||||
struct uiCombobox {
|
struct uiCombobox {
|
||||||
uiDarwinControl c;
|
uiDarwinControl c;
|
||||||
BOOL editable;
|
BOOL editable;
|
||||||
NSPopUpButton *pb;
|
NSPopUpButton *pb;
|
||||||
|
NSArrayController *pbac;
|
||||||
NSComboBox *cb;
|
NSComboBox *cb;
|
||||||
NSObject *handle; // for uiControlHandle()
|
NSObject *handle; // for uiControlHandle()
|
||||||
};
|
};
|
||||||
|
|
||||||
uiDarwinDefineControl(
|
static void onDestroy(uiCombobox *);
|
||||||
|
|
||||||
|
uiDarwinDefineControlWithOnDestroy(
|
||||||
uiCombobox, // type name
|
uiCombobox, // type name
|
||||||
uiComboboxType, // type function
|
uiComboboxType, // type function
|
||||||
handle // handle
|
handle, // handle
|
||||||
|
onDestroy(this); // on destroy
|
||||||
)
|
)
|
||||||
|
|
||||||
|
static void onDestroy(uiCombobox *c)
|
||||||
|
{
|
||||||
|
if (!c->editable) {
|
||||||
|
[c->pb unbind:@"contentObjects"];
|
||||||
|
[c->pb unbind:@"selectedIndex"];
|
||||||
|
[c->pbac release];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void uiComboboxAppend(uiCombobox *c, const char *text)
|
void uiComboboxAppend(uiCombobox *c, const char *text)
|
||||||
{
|
{
|
||||||
if (c->editable)
|
if (c->editable)
|
||||||
[c->cb addItemWithObjectValue:toNSString(text)];
|
[c->cb addItemWithObjectValue:toNSString(text)];
|
||||||
else
|
else
|
||||||
[c->pb addItemWithTitle:toNSString(text)];
|
[c->pbac addObject:toNSString(text)];
|
||||||
}
|
}
|
||||||
|
|
||||||
static uiCombobox *finishNewCombobox(BOOL editable)
|
static uiCombobox *finishNewCombobox(BOOL editable)
|
||||||
|
@ -46,6 +62,23 @@ static uiCombobox *finishNewCombobox(BOOL editable)
|
||||||
[pbcell setArrowPosition:NSPopUpArrowAtBottom];
|
[pbcell setArrowPosition:NSPopUpArrowAtBottom];
|
||||||
// TODO font
|
// TODO font
|
||||||
c->handle = c->pb;
|
c->handle = c->pb;
|
||||||
|
|
||||||
|
// NSPopUpButton doesn't work like a combobox
|
||||||
|
// - it automatically selects the first item
|
||||||
|
// - it doesn't support duplicates
|
||||||
|
// but we can use a NSArrayController and Cocoa bindings to bypass these restrictions
|
||||||
|
c->pbac = [NSArrayController new];
|
||||||
|
[c->pbac setAvoidsEmptySelection:NO];
|
||||||
|
[c->pbac setSelectsInsertedObjects:NO];
|
||||||
|
[c->pbac setAutomaticallyRearrangesObjects:NO];
|
||||||
|
[c->pb bind:@"contentValues"
|
||||||
|
toObject:c->pbac
|
||||||
|
withKeyPath:@"arrangedObjects"
|
||||||
|
options:nil];
|
||||||
|
[c->pb bind:@"selectedIndex"
|
||||||
|
toObject:c->pbac
|
||||||
|
withKeyPath:@"selectionIndex"
|
||||||
|
options:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
uiDarwinFinishNewControl(c, uiCombobox);
|
uiDarwinFinishNewControl(c, uiCombobox);
|
||||||
|
|
Loading…
Reference in New Issue