2016-05-27 22:42:05 -05:00
|
|
|
// 27 may 2016
|
|
|
|
#include "uipriv_darwin.h"
|
|
|
|
|
2016-06-22 21:58:51 -05:00
|
|
|
// 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-05-28 16:04:28 -05:00
|
|
|
|
2016-05-27 22:42:05 -05:00
|
|
|
struct scrollViewData {
|
|
|
|
BOOL hscroll;
|
|
|
|
BOOL vscroll;
|
|
|
|
};
|
|
|
|
|
|
|
|
NSScrollView *mkScrollView(struct scrollViewCreateParams *p, struct scrollViewData **dout)
|
|
|
|
{
|
|
|
|
NSScrollView *sv;
|
|
|
|
NSBorderType border;
|
|
|
|
struct scrollViewData *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
|
2016-05-27 22:42:05 -05:00
|
|
|
[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
|
2016-05-27 22:56:44 -05:00
|
|
|
[sv setScrollsDynamically:YES];
|
2016-05-27 22:42:05 -05:00
|
|
|
[sv setFindBarPosition:NSScrollViewFindBarPositionAboveContent];
|
|
|
|
[sv setUsesPredominantAxisScrolling:NO];
|
2016-05-27 22:56:44 -05:00
|
|
|
[sv setHorizontalScrollElasticity:NSScrollElasticityAutomatic];
|
|
|
|
[sv setVerticalScrollElasticity:NSScrollElasticityAutomatic];
|
2016-05-27 22:42:05 -05:00
|
|
|
[sv setAllowsMagnification:NO];
|
|
|
|
|
|
|
|
[sv setDocumentView:p->DocumentView];
|
|
|
|
d = uiNew(struct scrollViewData);
|
|
|
|
scrollViewSetScrolling(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)
|
|
|
|
{
|
|
|
|
d->hscroll = hscroll;
|
|
|
|
[sv setHasHorizontalScroller:d->hscroll];
|
|
|
|
d->vscroll = vscroll;
|
|
|
|
[sv setHasVerticalScroller:d->vscroll];
|
|
|
|
}
|
|
|
|
|
|
|
|
void scrollViewFreeData(NSScrollView *sv, struct scrollViewData *d)
|
|
|
|
{
|
|
|
|
uiFree(d);
|
|
|
|
}
|