blob: b0b4040c3abddf8280fd53d582675c503940e489 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
// 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
// TODO do the same with uiGroup and uiTab?
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;
// 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
// 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 = 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);
}
|