libui/darwin/scrollview.m

62 lines
2.0 KiB
Mathematica
Raw Normal View History

// 27 may 2016
#include "uipriv_darwin.h"
// 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
2016-06-23 13:57:40 -05:00
// TODO do the same with uiGroup and uiTab?
2016-05-28 16:04:28 -05:00
struct uiprivScrollViewData {
BOOL hscroll;
BOOL vscroll;
};
NSScrollView *uiprivMkScrollView(uiprivScrollViewCreateParams *p, uiprivScrollViewData **dout)
{
NSScrollView *sv;
NSBorderType border;
uiprivScrollViewData *d;
sv = [[NSScrollView alloc] initWithFrame:NSZeroRect];
if (p->BackgroundColor != nil)
[sv setBackgroundColor:p->BackgroundColor];
[sv setDrawsBackground:p->DrawsBackground];
border = NSNoBorder;
if (p->Bordered)
border = NSBezelBorder;
2016-05-27 23:35:56 -05:00
// document view seems to set the cursor properly
[sv setBorderType:border];
[sv setAutohidesScrollers:YES];
[sv setHasHorizontalRuler:NO];
[sv setHasVerticalRuler:NO];
[sv setRulersVisible:NO];
[sv setScrollerKnobStyle:NSScrollerKnobStyleDefault];
// the scroller style is documented as being set by default for us
2016-05-27 23:35:56 -05:00
// LONGTERM verify line and page for programmatically created NSTableView
[sv setScrollsDynamically:YES];
[sv setFindBarPosition:NSScrollViewFindBarPositionAboveContent];
[sv setUsesPredominantAxisScrolling:NO];
[sv setHorizontalScrollElasticity:NSScrollElasticityAutomatic];
[sv setVerticalScrollElasticity:NSScrollElasticityAutomatic];
[sv setAllowsMagnification:NO];
[sv setDocumentView:p->DocumentView];
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 uiprivScrollViewSetScrolling(NSScrollView *sv, uiprivScrollViewData *d, BOOL hscroll, BOOL vscroll)
{
d->hscroll = hscroll;
[sv setHasHorizontalScroller:d->hscroll];
d->vscroll = vscroll;
[sv setHasVerticalScroller:d->vscroll];
}
void uiprivScrollViewFreeData(NSScrollView *sv, uiprivScrollViewData *d)
{
uiprivFree(d);
}