forked from phoudoin/sanity
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathStackView.cpp
128 lines (100 loc) · 2.39 KB
/
StackView.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#include <stdlib.h>
#include "StackView.h"
#ifdef CODEWARRIOR
#pragma mark [Constructor & destructor]
#endif
// --------------------------------------------------------------
StackView::StackView
(
BRect frame,
const char * name,
uint32 resizeMask,
uint32 flags
)
: BView(frame, name, resizeMask, flags | B_WILL_DRAW | B_FRAME_EVENTS | B_NAVIGABLE_JUMP)
{
rgb_color bg = ui_color(B_PANEL_BACKGROUND_COLOR);
SetViewColor(tint_color(bg, B_LIGHTEN_1_TINT));
m_height = 0;
m_width = frame.Width();
m_scroller = NULL;
}
// #pragma mark -
// --------------------------------------------------------------
void StackView::TargetedByScrollView
(
BScrollView * scrollview
)
{
m_scroller = scrollview;
SetupScroller();
}
// --------------------------------------------------------------
void StackView::FrameResized
(
float width,
float height
)
{
inherited::FrameResized(width, height);
SetupScroller();
}
// --------------------------------------------------------------
void StackView::AddChild
(
BView * view
)
{
view->MoveTo(Bounds().left, m_height - Bounds().top);
m_height += view->Bounds().Height() + 1.0;
inherited::AddChild(view);
SetupScroller();
}
// --------------------------------------------------------------
void StackView::MessageReceived(BMessage *msg)
{
switch(msg->what) {
case RESTACK_MSG: {
BView *child;
BRect r = Bounds();
m_height = 0;
child = ChildAt(0);
while (child) {
child->MoveTo(r.left, m_height - r.top);
m_height += child->Bounds().Height() + 1.0;
child = child->NextSibling();
};
SetupScroller();
break;
}
default:
inherited::MessageReceived(msg);
}
}
// #pragma mark -
// --------------------------------------------------------------
void StackView::SetupScroller()
{
BScrollBar *sb;
float visible_height;
if ( ! m_scroller )
return;
visible_height = m_scroller->Bounds().Height();
// Hacky: Scrollview's Bounds() don't account of (inner) border style!
// Compensate by hand...
float h = visible_height;
if (m_scroller->Border() == B_FANCY_BORDER)
h -= 4;
else if (m_scroller->Border() == B_PLAIN_BORDER)
h -= 2;
if ( (m_height-1) < h )
ResizeTo(Bounds().Width(), h);
sb = m_scroller->ScrollBar(B_VERTICAL);
if ( ! sb )
return;
sb->SetProportion(h / (m_height-1));
if ( (m_height-1) <= h )
sb->SetRange(0, 0);
else
sb->SetRange(0, m_height - h - 1); // 0 to + (m_height-1) - h
}