More Darwin control migration.
This commit is contained in:
parent
e0963f8030
commit
521da6c598
|
@ -85,7 +85,7 @@ void uiButtonSetText(uiButton *b, const char *text)
|
||||||
void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data)
|
void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data)
|
||||||
{
|
{
|
||||||
b->onClicked = f;
|
b->onClicked = f;
|
||||||
b->onClickedData = NULL;
|
b->onClickedData = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void defaultOnClicked(uiButton *b, void *data)
|
static void defaultOnClicked(uiButton *b, void *data)
|
||||||
|
|
|
@ -0,0 +1,131 @@
|
||||||
|
// 14 august 2015
|
||||||
|
#import "uipriv_darwin.h"
|
||||||
|
|
||||||
|
struct uiCheckbox {
|
||||||
|
uiDarwinControl c;
|
||||||
|
NSButton *button; // TODO rename to checkbox?
|
||||||
|
void (*onToggled)(uiCheckbox *, void *);
|
||||||
|
void *onToggledData;
|
||||||
|
};
|
||||||
|
|
||||||
|
@interface checkboxDelegateClass : NSObject {
|
||||||
|
NSMutableDictionary *buttons; // TODO rename to checkboxes?
|
||||||
|
}
|
||||||
|
- (IBAction)onToggled:(id)sender;
|
||||||
|
- (void)registerCheckbox:(uiCheckbox *)c;
|
||||||
|
- (void)unregisterCheckbox:(uiCheckbox *)c;
|
||||||
|
@end
|
||||||
|
|
||||||
|
@implementation checkboxDelegateClass
|
||||||
|
|
||||||
|
- (id)init
|
||||||
|
{
|
||||||
|
self = [super init];
|
||||||
|
if (self)
|
||||||
|
self->buttons = [NSMutableDictionary new];
|
||||||
|
return self;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO have this called
|
||||||
|
- (void)dealloc
|
||||||
|
{
|
||||||
|
if ([self->buttons count] != 0)
|
||||||
|
complain("attempt to destroy shared checkbox delegate but checkboxes are still registered to it");
|
||||||
|
[self->buttons release];
|
||||||
|
[super dealloc];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (IBAction)onToggled:(id)sender
|
||||||
|
{
|
||||||
|
NSValue *v;
|
||||||
|
uiCheckbox *c;
|
||||||
|
|
||||||
|
v = (NSValue *) [self->buttons objectForKey:sender];
|
||||||
|
c = (uiCheckbox *) [v pointerValue];
|
||||||
|
(*(c->onToggled))(c, c->onToggledData);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)registerCheckbox:(uiCheckbox *)c
|
||||||
|
{
|
||||||
|
[self->buttons setObject:[NSValue valueWithPointer:c]
|
||||||
|
forKey:c->button];
|
||||||
|
[c->button setTarget:self];
|
||||||
|
[c->button setAction:@selector(onToggled:)];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)unregisterCheckbox:(uiCheckbox *)c
|
||||||
|
{
|
||||||
|
[c->button setTarget:nil];
|
||||||
|
[self->buttons removeObjectForKey:c->button];
|
||||||
|
}
|
||||||
|
|
||||||
|
@end
|
||||||
|
|
||||||
|
static checkboxDelegateClass *checkboxDelegate = nil;
|
||||||
|
|
||||||
|
uiDarwinDefineControlWithOnDestroy(
|
||||||
|
uiCheckbox, // type name
|
||||||
|
uiCheckboxType, // type function
|
||||||
|
button, // handle
|
||||||
|
[checkboxDelegate unregisterCheckbox:this]; // on destroy
|
||||||
|
)
|
||||||
|
|
||||||
|
char *uiCheckboxText(uiCheckbox *c)
|
||||||
|
{
|
||||||
|
return uiDarwinNSStringToText([c->button title]);
|
||||||
|
}
|
||||||
|
|
||||||
|
void uiCheckboxSetText(uiCheckbox *c, const char *text)
|
||||||
|
{
|
||||||
|
[c->button setTitle:toNSString(text)];
|
||||||
|
// this may result in the size of the checkbox changing
|
||||||
|
uiControlQueueResize(uiControl(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
void uiCheckboxOnToggled(uiCheckbox *c, void (*f)(uiCheckbox *, void *), void *data)
|
||||||
|
{
|
||||||
|
c->onToggled = f;
|
||||||
|
c->onToggledData = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void defaultOnToggled(uiCheckbox *c, void *data)
|
||||||
|
{
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
static int uiCheckboxChecked(uiCheckbox *c)
|
||||||
|
{
|
||||||
|
return [c->button state] == NSOnState;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void uiCheckboxSetChecked(uiCheckbox *c, int checked)
|
||||||
|
{
|
||||||
|
NSInteger state;
|
||||||
|
|
||||||
|
state = NSOnState;
|
||||||
|
if (!checked)
|
||||||
|
state = NSOffState;
|
||||||
|
[c->button setState:state];
|
||||||
|
}
|
||||||
|
|
||||||
|
uiCheckbox *uiNewCheckbox(const char *text)
|
||||||
|
{
|
||||||
|
uiCheckbox *c;
|
||||||
|
|
||||||
|
c = (uiCheckbox *) uiNewControl(uiCheckboxType());
|
||||||
|
|
||||||
|
c->button = [[NSButton alloc] initWithFrame:NSZeroRect];
|
||||||
|
[c->button setTitle:toNSString(text)];
|
||||||
|
[c->button setButtonType:NSSwitchButton];
|
||||||
|
[c->button setBordered:NO];
|
||||||
|
uiDarwinSetControlFont(c->button, NSControlSizeRegular);
|
||||||
|
|
||||||
|
if (checkboxDelegate == nil)
|
||||||
|
checkboxDelegate = [checkboxDelegateClass new];
|
||||||
|
[checkboxDelegate registerCheckbox:c];
|
||||||
|
uiCheckboxOnToggled(c, defaultOnToggled, NULL);
|
||||||
|
|
||||||
|
uiDarwinFinishNewControl(c, uiCheckbox);
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
|
@ -0,0 +1,58 @@
|
||||||
|
// 14 august 2015
|
||||||
|
#include "uipriv_darwin.h"
|
||||||
|
|
||||||
|
struct uiCombobox {
|
||||||
|
uiDarwinControl c;
|
||||||
|
BOOL editable;
|
||||||
|
NSPopUpButton *pb;
|
||||||
|
NSComboBox *cb;
|
||||||
|
uintptr_t handle; // for uiControlHandle()
|
||||||
|
};
|
||||||
|
|
||||||
|
uiDarwinDefineControl(
|
||||||
|
uiCombobox, // type name
|
||||||
|
uiComboboxType, // type function
|
||||||
|
handle // handle
|
||||||
|
)
|
||||||
|
|
||||||
|
void uiComboboxAppend(uiCombobox *c, const char *text)
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
|
||||||
|
static uiCombobox *finishNewCombobox(BOOL editable)
|
||||||
|
{
|
||||||
|
uiCombobox *c;
|
||||||
|
|
||||||
|
c = (uiCombobox *) uiNewControl(uiComboboxType());
|
||||||
|
|
||||||
|
c->editable = editable;
|
||||||
|
if (c->editable) {
|
||||||
|
c->cb = [[NSComboBox alloc] initWithFrame:NSZeroRect];
|
||||||
|
[c->cb setUsesDataSource:NO];
|
||||||
|
[c->cb setButtonBordered:YES];
|
||||||
|
[c->cb setCompletes:NO];
|
||||||
|
uiDarwinSetControlFont(c->cb, NSControlSizeRegular);
|
||||||
|
c->handle = (uintptr_t) (c->cb);
|
||||||
|
} else {
|
||||||
|
c->pb = [[NSPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:NO];
|
||||||
|
// TODO preferred edge
|
||||||
|
// TODO arrow position
|
||||||
|
// TODO font
|
||||||
|
c->handle = (uintptr_t) (c->pb);
|
||||||
|
}
|
||||||
|
|
||||||
|
uiDarwinFinishNewControl(c, uiCombobox);
|
||||||
|
|
||||||
|
return c;
|
||||||
|
}
|
||||||
|
|
||||||
|
uiCombobox *uiNewCombobox(void)
|
||||||
|
{
|
||||||
|
return finishNewCombobox(NO);
|
||||||
|
}
|
||||||
|
|
||||||
|
uiCombobox *uiNewEditableCombobox(void)
|
||||||
|
{
|
||||||
|
return finishNewCombobox(YES);
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
// 14 august 2015
|
||||||
|
#import "uipriv_darwin.h"
|
||||||
|
|
||||||
|
struct uiDateTimePicker {
|
||||||
|
uiDarwinControl c;
|
||||||
|
NSDatePicker *dp;
|
||||||
|
};
|
||||||
|
|
||||||
|
uiDarwinDefineControl(
|
||||||
|
uiDateTimePicker, // type name
|
||||||
|
uiDaateTimePickerType, // type function
|
||||||
|
dp // handle
|
||||||
|
)
|
||||||
|
|
||||||
|
static uiDateTimePicker *finishNewDateTimePicker(NSDatePickerElementFlags elements)
|
||||||
|
{
|
||||||
|
uiDateTimePicker *d;
|
||||||
|
|
||||||
|
d = (uiDateTimePicker *) uiNewControl(uiDateTimePickerType());
|
||||||
|
|
||||||
|
d->dp = [[NSDatePicker alloc] initWithFrame:NSZeroRect];
|
||||||
|
// TODO text field stuff
|
||||||
|
[d->dp setDatePickerStyle:NSTextFieldAndStepperDatePickerStyle];
|
||||||
|
[d->dp setDatePickerElements:elements];
|
||||||
|
[d->dp setDatePickerMode:NSSingleDateMode];
|
||||||
|
// TODO get date picker font
|
||||||
|
|
||||||
|
uiDarwinFinishNewControl(d, uiDateTimePicker);
|
||||||
|
|
||||||
|
return d;
|
||||||
|
}
|
||||||
|
|
||||||
|
uiDateTimePicker *uiNewDateTimePicker(void)
|
||||||
|
{
|
||||||
|
return finishNewDateTimePicker(NSYearMonthDayDatePickerElementFlag | NSHourMinuteSecondDatePickerElementFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
uiDateTimePicker *uiNewDatePicker(void)
|
||||||
|
{
|
||||||
|
return finishNewDateTimePicker(NSYearMonthDayDatePickerElementFlag);
|
||||||
|
}
|
||||||
|
|
||||||
|
uiDateTimePicker *uiNewTimePicker(void)
|
||||||
|
{
|
||||||
|
return finishNewDateTimePicker(NSHourMinuteSecondDatePickerElementFlag);
|
||||||
|
}
|
Loading…
Reference in New Issue