From 15a3d151cd0f96b760d1d2e7e2a044c5c1947ede Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 27 Jul 2015 23:38:44 -0400 Subject: [PATCH] More OS X control work. --- redo/darwin/combobox.m | 33 ++++++++++++++++++++++++++------- redo/darwin/group.m | 15 ++++++++++++--- redo/darwin/separator.m | 14 +++++++++++--- redo/darwin/slider.m | 6 +++++- 4 files changed, 54 insertions(+), 14 deletions(-) diff --git a/redo/darwin/combobox.m b/redo/darwin/combobox.m index d8eb07f0..3e2d2f71 100644 --- a/redo/darwin/combobox.m +++ b/redo/darwin/combobox.m @@ -3,7 +3,9 @@ struct combobox { uiCombobox c; - OSTYPE *OSHANDLE; + BOOL editable; + NSPopUpButton *pb; + NSComboBox *cb; }; uiDefineControlType(uiCombobox, uiTypeCombobox, struct combobox) @@ -12,7 +14,9 @@ static uintptr_t comboboxHandle(uiControl *cc) { struct combobox *c = (struct combobox *) cc; - return (uintptr_t) (c->OSHANDLE); + if (c->editable) + return (uintptr_t) (c->cb); + return (uintptr_t) (c->pb); } static void comboboxAppend(uiCombobox *cc, const char *text) @@ -22,13 +26,28 @@ static void comboboxAppend(uiCombobox *cc, const char *text) PUT_CODE_HERE; } -static uiCombobox *finishNewCombobox(OSTHING OSARG) +static uiCombobox *finishNewCombobox(BOOL editable) { struct combobox *c; - c = (struct combobox *) MAKE_CONTROL_INSTANCE(uiTypeCombobox()); + c = (struct combobox *) uiNewControl(uiTypeCombobox()); - PUT_CODE_HERE; + 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; @@ -39,10 +58,10 @@ static uiCombobox *finishNewCombobox(OSTHING OSARG) uiCombobox *uiNewCombobox(void) { - return finishNewCombobox(OSARGNONEDITABLE); + return finishNewCombobox(NO); } uiCombobox *uiNewEditableCombobox(void) { - return finishNewCombobox(OSARGEDITABLE); + return finishNewCombobox(YES); } diff --git a/redo/darwin/group.m b/redo/darwin/group.m index af318b12..4f369342 100644 --- a/redo/darwin/group.m +++ b/redo/darwin/group.m @@ -3,7 +3,7 @@ struct group { uiGroup g; - OSTYPE *OSHANDLE; + NSBox *box; uiControl *child; int margined; }; @@ -14,7 +14,7 @@ static uintptr_t groupHandle(uiControl *c) { struct group *g = (struct group *) c; - return (uintptr_t) (g->OSHANDLE); + return (uintptr_t) (g->box); } static void groupContainerUpdateState(uiControl *c) @@ -75,7 +75,16 @@ uiGroup *uiNewGroup(const char *text) g = (struct group *) MAKE_CONTROL_INSTANCE(uiTypeGroup()); - PUT_CODE_HERE; + g->box = [[NSBox alloc] initWithFrame:NSZeroRect]; + [g->box setBoxType:NSBoxPrimary]; + [g->box setBorderType:TODO]; + [g->box setTransparent:NO]; + [g->box setTitlePosition:NSAtTop]; + + // can't set title font the way the function does; plus we need to use a different size + uiDarwinMakeSingleViewControl(uiControl(g), g->box, NO); + // TODO verify if Small in Xcode is this small + [g->box setTitleFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]]; uiControl(g)->Handle = groupHandle; uiControl(g)->ContainerUpdateState = groupContainerUpdateState; diff --git a/redo/darwin/separator.m b/redo/darwin/separator.m index c99dcaf0..5ae46872 100644 --- a/redo/darwin/separator.m +++ b/redo/darwin/separator.m @@ -1,9 +1,11 @@ // 11 june 2015 #include "uipriv_darwin.h" +// TODO sizing + struct separator { uiSeparator s; - OSTYPE *OSHANDLE; + NSBox *box; }; uiDefineControlType(uiSeparator, uiTypeSeparator, struct separator) @@ -12,7 +14,7 @@ static uintptr_t separatorHandle(uiControl *c) { struct separator *s = (struct separator *) c; - return (uintptr_t) (s->OSHANDLE); + return (uintptr_t) (s->box); } uiSeparator *uiNewHorizontalSeparator(void) @@ -21,7 +23,13 @@ uiSeparator *uiNewHorizontalSeparator(void) s = (struct separator *) MAKE_CONTROL_INSTANCE(uiTypeSeparator()); - PUT_CODE_HERE; + s->box = [[NSBox alloc] initWithFrame:NSZeroRect]; + [s->box setBoxType:NSBoxSeparator]; + [s->box setBorderType:TODO]; + [s->box setTransparent:NO]; + [s->box setTitlePosition:NSNoTitle]; + + uiDarwinMakeSingleViewControl(uiControl(s), s->box, NO); uiControl(s)->Handle = separatorHandle; diff --git a/redo/darwin/slider.m b/redo/darwin/slider.m index 3bc47aac..b95768f4 100644 --- a/redo/darwin/slider.m +++ b/redo/darwin/slider.m @@ -54,13 +54,17 @@ uiSlider *uiNewSlider(intmax_t min, intmax_t max) s = (struct slider *) uiNewControl(uiTypeSlider()); s->slider = [[NSSlider alloc] initWithFrame:NSZeroRect]; +NSLog(@"NOTE thickness %f\n", [s->slider knobThickness]); // TODO vertical is defined by wider than tall [s->slider setMinValue:min]; [s->slider setMaxValue:max]; - // TODO NSTickMarkAbove? + [s->slider setAllowsTickMarkValuesOnly:NO]; + [s->slider setNumberOfTicks:0]; + [s->slider setTickMarkPosition:NSTickMarkAbove]; cell = (NSSliderCell *) [s->slider cell]; [cell setSliderType:NSLinearSlider]; +NSLog(@"NOTE thickness %f\n", [s->slider knobThickness]); uiDarwinMakeSingleViewControl(uiControl(s), s->slider, NO);