Migrated shared scrollview.m types and functions.

This commit is contained in:
Pietro Gagliardi 2018-05-05 21:21:44 -04:00
parent cc271ccc37
commit 69922a0fb3
5 changed files with 33 additions and 30 deletions

View File

@ -1,16 +1,3 @@
// scrollview.m
struct scrollViewCreateParams {
NSView *DocumentView;
NSColor *BackgroundColor;
BOOL DrawsBackground;
BOOL Bordered;
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);
// label.m // label.m
extern NSTextField *newLabel(NSString *str); extern NSTextField *newLabel(NSString *str);

View File

@ -29,7 +29,7 @@ struct uiArea {
NSView *view; // either sv or area depending on whether it is scrolling NSView *view; // either sv or area depending on whether it is scrolling
NSScrollView *sv; NSScrollView *sv;
areaView *area; areaView *area;
struct scrollViewData *d; uiprivScrollViewData *d;
uiAreaHandler *ah; uiAreaHandler *ah;
BOOL scrolling; BOOL scrolling;
NSEvent *dragevent; NSEvent *dragevent;
@ -350,7 +350,7 @@ static void uiAreaDestroy(uiControl *c)
uiArea *a = uiArea(c); uiArea *a = uiArea(c);
if (a->scrolling) if (a->scrolling)
scrollViewFreeData(a->sv, a->d); uiprivScrollViewFreeData(a->sv, a->d);
[a->area release]; [a->area release];
if (a->scrolling) if (a->scrolling)
[a->sv release]; [a->sv release];
@ -450,7 +450,7 @@ uiArea *uiNewArea(uiAreaHandler *ah)
uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height) uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height)
{ {
uiArea *a; uiArea *a;
struct scrollViewCreateParams p; uiprivScrollViewCreateParams p;
uiDarwinNewControl(uiArea, a); uiDarwinNewControl(uiArea, a);
@ -460,14 +460,14 @@ uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height)
a->area = [[areaView alloc] initWithFrame:NSMakeRect(0, 0, width, height) a->area = [[areaView alloc] initWithFrame:NSMakeRect(0, 0, width, height)
area:a]; area:a];
memset(&p, 0, sizeof (struct scrollViewCreateParams)); memset(&p, 0, sizeof (uiprivScrollViewCreateParams));
p.DocumentView = a->area; p.DocumentView = a->area;
p.BackgroundColor = [NSColor controlColor]; p.BackgroundColor = [NSColor controlColor];
p.DrawsBackground = 1; p.DrawsBackground = 1;
p.Bordered = NO; p.Bordered = NO;
p.HScroll = YES; p.HScroll = YES;
p.VScroll = YES; p.VScroll = YES;
a->sv = mkScrollView(&p, &(a->d)); a->sv = uiprivMkScrollView(&p, &(a->d));
a->view = a->sv; a->view = a->sv;

View File

@ -14,7 +14,7 @@ struct uiMultilineEntry {
uiDarwinControl c; uiDarwinControl c;
NSScrollView *sv; NSScrollView *sv;
intrinsicSizeTextView *tv; intrinsicSizeTextView *tv;
struct scrollViewData *d; uiprivScrollViewData *d;
void (*onChanged)(uiMultilineEntry *, void *); void (*onChanged)(uiMultilineEntry *, void *);
void *onChangedData; void *onChangedData;
BOOL changing; BOOL changing;
@ -59,7 +59,7 @@ static void uiMultilineEntryDestroy(uiControl *c)
{ {
uiMultilineEntry *e = uiMultilineEntry(c); uiMultilineEntry *e = uiMultilineEntry(c);
scrollViewFreeData(e->sv, e->d); uiprivScrollViewFreeData(e->sv, e->d);
[e->tv release]; [e->tv release];
[e->sv release]; [e->sv release];
uiFreeControl(uiControl(e)); uiFreeControl(uiControl(e));
@ -120,7 +120,7 @@ static uiMultilineEntry *finishMultilineEntry(BOOL hscroll)
{ {
uiMultilineEntry *e; uiMultilineEntry *e;
NSFont *font; NSFont *font;
struct scrollViewCreateParams p; uiprivScrollViewCreateParams p;
uiDarwinNewControl(uiMultilineEntry, e); uiDarwinNewControl(uiMultilineEntry, e);
@ -207,7 +207,7 @@ static uiMultilineEntry *finishMultilineEntry(BOOL hscroll)
// let's just set it to the standard control font anyway, just to be safe // let's just set it to the standard control font anyway, just to be safe
[e->tv setFont:font]; [e->tv setFont:font];
memset(&p, 0, sizeof (struct scrollViewCreateParams)); memset(&p, 0, sizeof (uiprivScrollViewCreateParams));
p.DocumentView = e->tv; p.DocumentView = e->tv;
// this is what Interface Builder sets it to // this is what Interface Builder sets it to
p.BackgroundColor = [NSColor colorWithCalibratedWhite:1.0 alpha:1.0]; p.BackgroundColor = [NSColor colorWithCalibratedWhite:1.0 alpha:1.0];
@ -215,7 +215,7 @@ static uiMultilineEntry *finishMultilineEntry(BOOL hscroll)
p.Bordered = YES; p.Bordered = YES;
p.HScroll = hscroll; p.HScroll = hscroll;
p.VScroll = YES; p.VScroll = YES;
e->sv = mkScrollView(&p, &(e->d)); e->sv = uiprivMkScrollView(&p, &(e->d));
uiMultilineEntryOnChanged(e, defaultOnChanged, NULL); uiMultilineEntryOnChanged(e, defaultOnChanged, NULL);

View File

@ -4,16 +4,16 @@
// see http://stackoverflow.com/questions/37979445/how-do-i-properly-set-up-a-scrolling-nstableview-using-auto-layout-what-ive-tr for why we don't use auto layout // see http://stackoverflow.com/questions/37979445/how-do-i-properly-set-up-a-scrolling-nstableview-using-auto-layout-what-ive-tr for why we don't use auto layout
// TODO do the same with uiGroup and uiTab? // TODO do the same with uiGroup and uiTab?
struct scrollViewData { struct uiprivScrollViewData {
BOOL hscroll; BOOL hscroll;
BOOL vscroll; BOOL vscroll;
}; };
NSScrollView *mkScrollView(struct scrollViewCreateParams *p, struct scrollViewData **dout) NSScrollView *uiprivMkScrollView(uiprivScrollViewCreateParams *p, uiprivScrollViewData **dout)
{ {
NSScrollView *sv; NSScrollView *sv;
NSBorderType border; NSBorderType border;
struct scrollViewData *d; uiprivScrollViewData *d;
sv = [[NSScrollView alloc] initWithFrame:NSZeroRect]; sv = [[NSScrollView alloc] initWithFrame:NSZeroRect];
if (p->BackgroundColor != nil) if (p->BackgroundColor != nil)
@ -39,15 +39,15 @@ NSScrollView *mkScrollView(struct scrollViewCreateParams *p, struct scrollViewDa
[sv setAllowsMagnification:NO]; [sv setAllowsMagnification:NO];
[sv setDocumentView:p->DocumentView]; [sv setDocumentView:p->DocumentView];
d = uiprivNew(struct scrollViewData); d = uiprivNew(uiprivScrollViewData);
scrollViewSetScrolling(sv, d, p->HScroll, p->VScroll); uiprivScrollViewSetScrolling(sv, d, p->HScroll, p->VScroll);
*dout = d; *dout = d;
return sv; return sv;
} }
// based on http://blog.bjhomer.com/2014/08/nsscrollview-and-autolayout.html because (as pointed out there) Apple's official guide is really only for iOS // based on http://blog.bjhomer.com/2014/08/nsscrollview-and-autolayout.html because (as pointed out there) Apple's official guide is really only for iOS
void scrollViewSetScrolling(NSScrollView *sv, struct scrollViewData *d, BOOL hscroll, BOOL vscroll) void uiprivScrollViewSetScrolling(NSScrollView *sv, uiprivScrollViewData *d, BOOL hscroll, BOOL vscroll)
{ {
d->hscroll = hscroll; d->hscroll = hscroll;
[sv setHasHorizontalScroller:d->hscroll]; [sv setHasHorizontalScroller:d->hscroll];
@ -55,7 +55,7 @@ void scrollViewSetScrolling(NSScrollView *sv, struct scrollViewData *d, BOOL hsc
[sv setHasVerticalScroller:d->vscroll]; [sv setHasVerticalScroller:d->vscroll];
} }
void scrollViewFreeData(NSScrollView *sv, struct scrollViewData *d) void uiprivScrollViewFreeData(NSScrollView *sv, uiprivScrollViewData *d)
{ {
uiprivFree(d); uiprivFree(d);
} }

View File

@ -122,4 +122,20 @@ extern void uiprivSetupFontPanel(void);
// colorbutton.m // colorbutton.m
extern BOOL uiprivColorButtonInhibitSendAction(SEL sel, id from, id to); extern BOOL uiprivColorButtonInhibitSendAction(SEL sel, id from, id to);
// scrollview.m
typedef struct uiprivScrollViewCreateParams uiprivScrollViewCreateParams;
struct uiprivScrollViewCreateParams {
// TODO MAYBE fix these identifiers
NSView *DocumentView;
NSColor *BackgroundColor;
BOOL DrawsBackground;
BOOL Bordered;
BOOL HScroll;
BOOL VScroll;
};
typedef struct uiprivScrollViewData uiprivScrollViewData;
extern NSScrollView *uiprivMkScrollView(uiprivScrollViewCreateParams *p, uiprivScrollViewData **dout);
extern void uiprivScrollViewSetScrolling(NSScrollView *sv, uiprivScrollViewData *d, BOOL hscroll, BOOL vscroll);
extern void uiprivScrollViewFreeData(NSScrollView *sv, uiprivScrollViewData *d);
#import "OLD_uipriv_darwin.h" #import "OLD_uipriv_darwin.h"