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
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
NSScrollView *sv;
areaView *area;
struct scrollViewData *d;
uiprivScrollViewData *d;
uiAreaHandler *ah;
BOOL scrolling;
NSEvent *dragevent;
@ -350,7 +350,7 @@ static void uiAreaDestroy(uiControl *c)
uiArea *a = uiArea(c);
if (a->scrolling)
scrollViewFreeData(a->sv, a->d);
uiprivScrollViewFreeData(a->sv, a->d);
[a->area release];
if (a->scrolling)
[a->sv release];
@ -450,7 +450,7 @@ uiArea *uiNewArea(uiAreaHandler *ah)
uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height)
{
uiArea *a;
struct scrollViewCreateParams p;
uiprivScrollViewCreateParams p;
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)
area:a];
memset(&p, 0, sizeof (struct scrollViewCreateParams));
memset(&p, 0, sizeof (uiprivScrollViewCreateParams));
p.DocumentView = a->area;
p.BackgroundColor = [NSColor controlColor];
p.DrawsBackground = 1;
p.Bordered = NO;
p.HScroll = YES;
p.VScroll = YES;
a->sv = mkScrollView(&p, &(a->d));
a->sv = uiprivMkScrollView(&p, &(a->d));
a->view = a->sv;

View File

@ -14,7 +14,7 @@ struct uiMultilineEntry {
uiDarwinControl c;
NSScrollView *sv;
intrinsicSizeTextView *tv;
struct scrollViewData *d;
uiprivScrollViewData *d;
void (*onChanged)(uiMultilineEntry *, void *);
void *onChangedData;
BOOL changing;
@ -59,7 +59,7 @@ static void uiMultilineEntryDestroy(uiControl *c)
{
uiMultilineEntry *e = uiMultilineEntry(c);
scrollViewFreeData(e->sv, e->d);
uiprivScrollViewFreeData(e->sv, e->d);
[e->tv release];
[e->sv release];
uiFreeControl(uiControl(e));
@ -120,7 +120,7 @@ static uiMultilineEntry *finishMultilineEntry(BOOL hscroll)
{
uiMultilineEntry *e;
NSFont *font;
struct scrollViewCreateParams p;
uiprivScrollViewCreateParams p;
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
[e->tv setFont:font];
memset(&p, 0, sizeof (struct scrollViewCreateParams));
memset(&p, 0, sizeof (uiprivScrollViewCreateParams));
p.DocumentView = e->tv;
// this is what Interface Builder sets it to
p.BackgroundColor = [NSColor colorWithCalibratedWhite:1.0 alpha:1.0];
@ -215,7 +215,7 @@ static uiMultilineEntry *finishMultilineEntry(BOOL hscroll)
p.Bordered = YES;
p.HScroll = hscroll;
p.VScroll = YES;
e->sv = mkScrollView(&p, &(e->d));
e->sv = uiprivMkScrollView(&p, &(e->d));
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
// TODO do the same with uiGroup and uiTab?
struct scrollViewData {
struct uiprivScrollViewData {
BOOL hscroll;
BOOL vscroll;
};
NSScrollView *mkScrollView(struct scrollViewCreateParams *p, struct scrollViewData **dout)
NSScrollView *uiprivMkScrollView(uiprivScrollViewCreateParams *p, uiprivScrollViewData **dout)
{
NSScrollView *sv;
NSBorderType border;
struct scrollViewData *d;
uiprivScrollViewData *d;
sv = [[NSScrollView alloc] initWithFrame:NSZeroRect];
if (p->BackgroundColor != nil)
@ -39,15 +39,15 @@ NSScrollView *mkScrollView(struct scrollViewCreateParams *p, struct scrollViewDa
[sv setAllowsMagnification:NO];
[sv setDocumentView:p->DocumentView];
d = uiprivNew(struct scrollViewData);
scrollViewSetScrolling(sv, d, p->HScroll, p->VScroll);
d = uiprivNew(uiprivScrollViewData);
uiprivScrollViewSetScrolling(sv, d, p->HScroll, p->VScroll);
*dout = d;
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
void scrollViewSetScrolling(NSScrollView *sv, struct scrollViewData *d, BOOL hscroll, BOOL vscroll)
void uiprivScrollViewSetScrolling(NSScrollView *sv, uiprivScrollViewData *d, BOOL hscroll, BOOL vscroll)
{
d->hscroll = hscroll;
[sv setHasHorizontalScroller:d->hscroll];
@ -55,7 +55,7 @@ void scrollViewSetScrolling(NSScrollView *sv, struct scrollViewData *d, BOOL hsc
[sv setHasVerticalScroller:d->vscroll];
}
void scrollViewFreeData(NSScrollView *sv, struct scrollViewData *d)
void uiprivScrollViewFreeData(NSScrollView *sv, uiprivScrollViewData *d)
{
uiprivFree(d);
}

View File

@ -122,4 +122,20 @@ extern void uiprivSetupFontPanel(void);
// colorbutton.m
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"