diff --git a/darwin/multilineentry.m b/darwin/multilineentry.m index 34611071..afcb1fec 100644 --- a/darwin/multilineentry.m +++ b/darwin/multilineentry.m @@ -44,15 +44,24 @@ struct uiMultilineEntry { uiDarwinControl c; NSScrollView *sv; intrinsicSizeTextView *tv; + struct scrollViewData *d; void (*onChanged)(uiMultilineEntry *, void *); void *onChangedData; - struct scrollViewConstraints constraints; }; // TODO events -// TODO destroy -uiDarwinControlAllDefaults(uiMultilineEntry, sv) +uiDarwinControlAllDefaultsExceptDestroy(uiMultilineEntry, sv) + +static void uiMultilineEntryDestroy(uiControl *c) +{ + uiMultilineEntry *e = uiMultilineEntry(c); + + scrollViewFreeData(e->sv, e->d); + [e->tv release]; + [e->sv release]; + uiFreeControl(uiControl(e)); +} static void defaultOnChanged(uiMultilineEntry *e, void *data) { @@ -107,16 +116,10 @@ static uiMultilineEntry *finishMultilineEntry(BOOL hscroll) { uiMultilineEntry *e; NSFont *font; + struct scrollViewCreateParams p; uiDarwinNewControl(uiMultilineEntry, e); - e->sv = [[NSScrollView alloc] initWithFrame:NSZeroRect]; - // TODO verify against Interface Builder - [e->sv setHasHorizontalScroller:hscroll]; - [e->sv setHasVerticalScroller:YES]; - [e->sv setAutohidesScrollers:YES]; - [e->sv setBorderType:NSBezelBorder]; - e->tv = [[intrinsicSizeTextView alloc] initWithFrame:NSZeroRect]; // verified against Interface Builder, except for rich text options [e->tv setAllowsDocumentBackgroundColorChange:NO]; @@ -166,15 +169,14 @@ static uiMultilineEntry *finishMultilineEntry(BOOL hscroll) // let's just set it to the standard control font anyway, just to be safe [e->tv setFont:font]; - [e->sv setDocumentView:e->tv]; - [e->tv setTranslatesAutoresizingMaskIntoConstraints:NO]; - scrollViewConstraintsEstablish(&(e->constraints), e->sv, hscroll, YES, @"uiMultilineEntry"); - // needed to allow horizontal shrinking - // TODO what about vertical text? - [e->tv setContentCompressionResistancePriority:NSLayoutPriorityDefaultLow forOrientation:NSLayoutConstraintOrientationHorizontal]; - -//TODO:void printinfo(NSScrollView *sv, NSTextView *tv); -//printinfo(e->sv, e->tv); + memset(&p, 0, sizeof (struct scrollViewCreateParams)); + p.DocumentView = e->tv; + p.BackgroundColor = nil; + p.DrawsBackground = YES; + p.Bordered = YES; + p.HScroll = hscroll; + p.VScroll = YES; + e->sv = mkScrollView(&p, &(e->d)); uiMultilineEntryOnChanged(e, defaultOnChanged, NULL); @@ -227,47 +229,7 @@ NSTextView *tv; } _s; _s.sv = sv; _s.tv = tv; - - add("NSScrollView"); - add(" backgroundColor %@", [self.sv backgroundColor]); - add(" drawsBackground %d", [self.sv drawsBackground]); - add(" borderType %d", [self.sv borderType]); - add(" documentCursor %@", [self.sv documentCursor]); - add(" hasHorizontalScroller %d", [self.sv hasHorizontalScroller]); - add(" hasVerticalScroller %d", [self.sv hasVerticalScroller]); - add(" autohidesScrollers %d", [self.sv autohidesScrollers]); - add(" hasHorizontalRuler %d", [self.sv hasHorizontalRuler]); - add(" hasVerticalRuler %d", [self.sv hasVerticalRuler]); - add(" rulersVisible %d", [self.sv rulersVisible]); - add(" automaticallyAdjustsContentInsets %d", - [self.sv automaticallyAdjustsContentInsets]); - add(" contentInsets %@", - edgeInsetsStr([self.sv contentInsets])); - add(" scrollerInsets %@", - edgeInsetsStr([self.sv scrollerInsets])); - add(" scrollerKnobStyle %d", [self.sv scrollerKnobStyle]); - add(" scrollerStyle %d", [self.sv scrollerStyle]); - add(" lineScroll %g", [self.sv lineScroll]); - add(" horizontalLineScroll %g", [self.sv horizontalLineScroll]); - add(" verticalLineScroll %g", [self.sv verticalLineScroll]); - add(" pageScroll %g", [self.sv pageScroll]); - add(" horizontalPageScroll %g", [self.sv horizontalPageScroll]); - add(" verticalPageScroll %g", [self.sv verticalPageScroll]); - add(" scrollsDynamically %d", [self.sv scrollsDynamically]); - add(" findBarPosition %d", [self.sv findBarPosition]); - add(" usesPredominantAxisScrolling %d", - [self.sv usesPredominantAxisScrolling]); - add(" horizontalScrollElasticity %d", - [self.sv horizontalScrollElasticity]); - add(" verticalScrollElasticity %d", - [self.sv verticalScrollElasticity]); - add(" allowsMagnification %d", [self.sv allowsMagnification]); - add(" magnification %g", [self.sv magnification]); - add(" maxMagnification %g", [self.sv maxMagnification]); - add(" minMagnification %g", [self.sv minMagnification]); - add(""); - add("NSTextView"); add(" textContainerInset %@", NSStringFromSize([self.tv textContainerInset])); diff --git a/darwin/scrollview.m b/darwin/scrollview.m index f02d5acf..90ef504f 100644 --- a/darwin/scrollview.m +++ b/darwin/scrollview.m @@ -33,11 +33,11 @@ NSScrollView *mkScrollView(struct scrollViewCreateParams *p, struct scrollViewDa [sv setScrollerKnobStyle:NSScrollerKnobStyleDefault]; // the scroller style is documented as being set by default for us // TODO verify line and page for programmatically created NSTextView - [sv scrollsDynamically:YES]; + [sv setScrollsDynamically:YES]; [sv setFindBarPosition:NSScrollViewFindBarPositionAboveContent]; [sv setUsesPredominantAxisScrolling:NO]; - [sv setHorizontalElasticity:NSScrollElasticityAutomatic]; - [sv setVerticalElasticity:NSScrollElasticityAutomatic]; + [sv setHorizontalScrollElasticity:NSScrollElasticityAutomatic]; + [sv setVerticalScrollElasticity:NSScrollElasticityAutomatic]; [sv setAllowsMagnification:NO]; [p->DocumentView setTranslatesAutoresizingMaskIntoConstraints:NO]; diff --git a/darwin/uipriv_darwin.h b/darwin/uipriv_darwin.h index e016bf3e..0bc79f37 100644 --- a/darwin/uipriv_darwin.h +++ b/darwin/uipriv_darwin.h @@ -115,6 +115,7 @@ struct scrollViewCreateParams { BOOL HScroll; BOOL VScroll; }; +struct scrollViewData; extern NSScrollView *mkScrollView(struct scrollViewCreateParams *p, struct scrollViewData **dout); extern void scrollViewSetScrolling(NSScrollView *sv, struct scrollViewData *d, BOOL hscroll, BOOL vscroll); extern void scrollViewFreeData(NSScrollView *sv, struct scrollViewData *d);