diff --git a/redo/reredo/darwin/button.m b/redo/reredo/darwin/button.m index 38139e8d..3981699e 100644 --- a/redo/reredo/darwin/button.m +++ b/redo/reredo/darwin/button.m @@ -104,7 +104,7 @@ uiButton *uiNewButton(const char *text) [b->button setButtonType:NSMomentaryPushInButton]; [b->button setBordered:YES]; [b->button setBezelStyle:NSRoundedBezelStyle]; - uiDarwinSetControlFont(b->button, NSControlSizeRegular); + uiDarwinSetControlFont(b->button, NSRegularControlSize); if (buttonDelegate == nil) buttonDelegate = [buttonDelegateClass new]; diff --git a/redo/reredo/darwin/checkbox.m b/redo/reredo/darwin/checkbox.m index b40155e9..1533d9be 100644 --- a/redo/reredo/darwin/checkbox.m +++ b/redo/reredo/darwin/checkbox.m @@ -118,7 +118,7 @@ uiCheckbox *uiNewCheckbox(const char *text) [c->button setTitle:toNSString(text)]; [c->button setButtonType:NSSwitchButton]; [c->button setBordered:NO]; - uiDarwinSetControlFont(c->button, NSControlSizeRegular); + uiDarwinSetControlFont(c->button, NSRegularControlSize); if (checkboxDelegate == nil) checkboxDelegate = [checkboxDelegateClass new]; diff --git a/redo/reredo/darwin/combobox.m b/redo/reredo/darwin/combobox.m index 794d584d..926a64ea 100644 --- a/redo/reredo/darwin/combobox.m +++ b/redo/reredo/darwin/combobox.m @@ -32,7 +32,7 @@ static uiCombobox *finishNewCombobox(BOOL editable) [c->cb setUsesDataSource:NO]; [c->cb setButtonBordered:YES]; [c->cb setCompletes:NO]; - uiDarwinSetControlFont(c->cb, NSControlSizeRegular); + uiDarwinSetControlFont(c->cb, NSRegularControlSize); c->handle = (uintptr_t) (c->cb); } else { c->pb = [[NSPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:NO]; diff --git a/redo/reredo/darwin/entry.m b/redo/reredo/darwin/entry.m new file mode 100644 index 00000000..b7d5868a --- /dev/null +++ b/redo/reredo/darwin/entry.m @@ -0,0 +1,140 @@ +// 14 august 2015 +#import "uipriv_darwin.h" + +// TODO set a text field minimum width + +struct uiEntry { + uiDarwinControl c; + NSTextField *textfield; + void (*onChanged)(uiEntry *, void *); + void *onChangedData; +}; + +@interface entryDelegateClass : NSObject { + NSMutableDictionary *entries; +} +- (void)controlTextDidChange:(NSNotification *)note; +- (void)registerEntry:(uiEntry *)e; +- (void)unregisterEntry:(uiEntry *)e; +@end + +@implementation entryDelegateClass + +- (id)init +{ + self = [super init]; + if (self) + self->entries = [NSMutableDictionary new]; + return self; +} + +// TODO have this called +- (void)dealloc +{ + if ([self->entries count] != 0) + complain("attempt to destroy shared entry delegate but entries are still registered to it"); + [self->entries release]; + [super dealloc]; +} + +- (void)controlTextDidChange:(NSNotification *)note +{ + NSValue *v; + uiEntry *e; + + v = (NSValue *) [self->entries objectForKey:[note object]]; + e = (uiEntry *) [v pointerValue]; + (*(e->onChanged))(e, e->onChangedData); +} + +- (void)registerEntry:(uiEntry *)e +{ + [self->entries setObject:[NSValue valueWithPointer:e] + forKey:e->textfield]; + [e->entry setDelegate:self]; +} + +- (void)unregisterEntry:(uiEntry *)e +{ + [e->textfield setDelegate:nil]; + [self->entries removeObjectForKey:e->textfield]; +} + +@end + +static entryDelegateClass *entryDelegate = nil; + +uiDarwinDefineControlWithOnDestroy( + uiEntry, // type name + uiEntryType, // type function + textfield, // handle + [entryDelegate unregisterEntry:this]; // on destroy +) + +char *uiEntryText(uiEntry *e) +{ + return uiDarwinNSStringToText([e->textfield stringValue]); +} + +void uiEntrySetText(uiEntry *e, const char *text) +{ + [e->textfield setStringValue:toNSString(text)]; + // don't queue the control for resize; entry sizes are independent of their contents +} + +void uiEntryOnChanged(uiEntry *e, void (*f)(uiEntry *, void *), void *data) +{ + e->onChanged = f; + e->onChangedData = data; +} + +int uiEntryReadOnly(uiEntry *e) +{ + return [e->textfield isEditable] == NO; +} + +void uiEntrySetReadOnly(uiEntry *e, int readonly) +{ + BOOL editable; + + editable = YES; + if (readonly) + editable = NO; + [e->textfield setEditable:editable]; +} + +// these are based on interface builder defaults; my comments in the old code weren't very good so I don't really know what talked about what, sorry :/ +void finishNewTextField(NSTextField *t, BOOL isEntry) +{ + uiDarwinSetControlFont(t, NSRegularControlSize); + + // THE ORDER OF THESE CALLS IS IMPORTANT; CHANGE IT AND THE BORDERS WILL DISAPPEAR + [t setBordered:NO]; + [t setBezelStyle:NSTextFieldSquareBezel]; + [t setBezeled:isEntry]; + + // we don't need to worry about substitutions/autocorrect here; see window_darwin.m for details + + [[t cell] setLineBreakMode:NSLineBreakByClipping]; + [[t cell] setScrollable:YES]; +} + +uiEntry *uiNewEntry(void) +{ + uiEntry *e; + + e = (uiEntry *) uiNewControl(uiEntryType()); + + e->textfield = [[NSTextField alloc] initWithFrame:NSZeroRect]; + [e->textfield setSelectable:YES]; // otherwise the setting is masked by the editable default of YES + finishNewTextField(e->textfield, YES); + + if (entryDelegate == nil) + entryDelegate = [entryDelegateClass new]; + [entryDelegate registerEntry:e]; + uiEntryOnChanged(e, defaultOnChanged, NULL); + + uiDarwinFinishNewControl(e, uiEntry); + + return e; +} diff --git a/redo/reredo/darwin/group.m b/redo/reredo/darwin/group.m new file mode 100644 index 00000000..c37718fb --- /dev/null +++ b/redo/reredo/darwin/group.m @@ -0,0 +1,74 @@ +// 14 august 2015 +#import "uipriv_darwin.h" + +struct uiGroup { + uiDarwinControl c; + NSBox *box; + uiControl *child; + int margined; +}; + +uiDarwinDefineControlWithOnDestroy( + uiGroup, // type name + uiGroupType, // type function + box, // handle + /* TODO */; // on destroy +) + +// TODO group container update + +char *uiGroupTitle(uiGroup *g) +{ + return PUT_CODE_HERE; +} + +void uiGroupSetTitle(uiGroup *g, const char *text) +{ + // TODO + // changing the text might necessitate a change in the groupbox's size + uiControlQueueResize(uiControl(g)); +} + +void uiGroupSetChild(uiGroup *g, uiControl *child) +{ +/* TODO + if (g->child != NULL) + uiControlSetParent(g->child, NULL); + g->child = child; + if (g->child != NULL) { + uiControlSetParent(g->child, uiControl(g)); + uiControlQueueResize(g->child); + } +*/ +} + +int uiGroupMargined(uiGroup *g) +{ + return g->margined; +} + +void uiGroupSetMargined(uiGroup *g, int margined) +{ + g->margined = margined; + // TODO + uiControlQueueResize(uiControl(g)); +} + +uiGroup *uiNewGroup(const char *title) +{ + uiGroup *g; + + g = (uiGroup *) uiNewControl(uiGroupType()); + + g->box = [[NSBox alloc] initWithFrame:NSZeroRect]; + // TODO title + [g->box setBoxType:NSBoxPrimary]; +//TODO [g->box setBorderType:TODO]; + [g->box setTransparent:NO]; + [g->box setTitlePosition:NSAtTop]; + uiDarwinSetControlFont(g->box, NSSmallControlSize); + + uiDarwinFinishNewControl(g, uiGroup); + + return g; +} diff --git a/redo/reredo/darwin/label.m b/redo/reredo/darwin/label.m new file mode 100644 index 00000000..dc5e8302 --- /dev/null +++ b/redo/reredo/darwin/label.m @@ -0,0 +1,43 @@ +// 14 august 2015 +#import "uipriv_darwin.h" + +struct uiLabel { + uiDarwinControl c; + NSTextField *textfield; // TODO rename to label? +}; + +uiDarwinDefineControl( + uiLabel, // type name + uiLabelType, // type function + textfield // handle +) + +char *uiLabelText(uiLabel *ll) +{ + return uiDarwinNSStringToText([l->textfield stringValue]); +} + +void uiLabelSetText(uiLabel *l, const char *text) +{ + [l->textfield setStringValue:toNSString(text)]; + // changing the text might necessitate a change in the label's size + uiControlQueueResize(uiControl(l)); +} + +uiLabel *uiNewLabel(const char *text) +{ + uiLabel *l; + + l = (uiLabel *) uiNewControl(uiLabelType()); + + l->textfield = [[NSTextField alloc] initWithFrame:NSZeroRect]; + [l->textfield setStringValue:toNSString(text)]; + [l->textfield setEditable:NO]; + [l->textfield setSelectable:NO]; + [l->textfield setDrawsBackground:NO]; + finishNewTextField(l->textfield, NO); + + uiDarwinFinishNewControl(l, uiLabel); + + return l; +}