2 * Copyright 2010-2012 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT license.
6 * DarkWyrm <bpmagic@columbus.rr.com>
7 * John Scipione <jscipione@gmail.com>
11 #include "FakeScrollBar.h"
14 #include <ControlLook.h>
16 #include <ScrollBar.h>
31 FakeScrollBar::FakeScrollBar(bool drawArrows
, bool doubleArrows
,
34 BControl("FakeScrollBar", NULL
, message
, B_WILL_DRAW
| B_NAVIGABLE
),
35 fDrawArrows(drawArrows
),
36 fDoubleArrows(doubleArrows
)
38 SetExplicitMinSize(BSize(160, 20));
39 SetExplicitMaxSize(BSize(B_SIZE_UNLIMITED
, 20));
43 FakeScrollBar::~FakeScrollBar(void)
49 FakeScrollBar::Draw(BRect updateRect
)
51 BRect bounds
= Bounds();
53 rgb_color normal
= ui_color(B_PANEL_BACKGROUND_COLOR
);
56 // draw the focus indicator
57 SetHighColor(ui_color(B_NAVIGATION_BASE_COLOR
));
59 bounds
.InsetBy(1.0, 1.0);
61 // Draw the selected border (1px)
62 if (Value() == B_CONTROL_ON
)
63 SetHighColor(ui_color(B_CONTROL_MARK_COLOR
));
68 bounds
.InsetBy(1.0, 1.0);
70 // Draw the selected border (2px)
71 if (Value() == B_CONTROL_ON
)
72 SetHighColor(ui_color(B_CONTROL_MARK_COLOR
));
77 bounds
.InsetBy(1.0, 1.0);
79 bounds
.InsetBy(1.0, 1.0);
85 bounds
.InsetBy(1.0, 1.0);
87 // draw a border around control (1px)
88 SetHighColor(tint_color(normal
, B_DARKEN_1_TINT
));
90 bounds
.InsetBy(1.0, 1.0);
92 BRect thumbBG
= bounds
;
93 BRect bgRect
= bounds
;
97 SetDrawingMode(B_OP_OVER
);
99 BRect
buttonFrame(bounds
.left
, bounds
.top
,
100 bounds
.left
+ bounds
.Height(), bounds
.bottom
);
102 _DrawArrowButton(ARROW_LEFT
, buttonFrame
, updateRect
);
105 buttonFrame
.OffsetBy(bounds
.Height() + 1, 0.0);
106 _DrawArrowButton(ARROW_RIGHT
, buttonFrame
,
109 buttonFrame
.OffsetTo(bounds
.right
- ((bounds
.Height() * 2) + 1),
111 _DrawArrowButton(ARROW_LEFT
, buttonFrame
,
114 thumbBG
.left
+= bounds
.Height() * 2 + 2;
115 thumbBG
.right
-= bounds
.Height() * 2 + 2;
117 thumbBG
.left
+= bounds
.Height() + 1;
118 thumbBG
.right
-= bounds
.Height() + 1;
121 buttonFrame
.OffsetTo(bounds
.right
- bounds
.Height(), bounds
.top
);
122 _DrawArrowButton(ARROW_RIGHT
, buttonFrame
, updateRect
);
124 SetDrawingMode(B_OP_COPY
);
126 bgRect
= bounds
.InsetByCopy(48, 0);
128 bgRect
= bounds
.InsetByCopy(16, 0);
130 // fill background besides the thumb
131 BRect
leftOfThumb(thumbBG
.left
, thumbBG
.top
, bgRect
.left
- 1,
133 BRect
rightOfThumb(bgRect
.right
+ 1, thumbBG
.top
, thumbBG
.right
,
136 be_control_look
->DrawScrollBarBackground(this, leftOfThumb
,
137 rightOfThumb
, updateRect
, normal
, 0, B_HORIZONTAL
);
141 // fill the clickable surface of the thumb
142 be_control_look
->DrawButtonBackground(this, bgRect
, updateRect
,
143 normal
, 0, BControlLook::B_ALL_BORDERS
, B_HORIZONTAL
);
148 FakeScrollBar::MouseDown(BPoint point
)
150 BControl::MouseDown(point
);
155 FakeScrollBar::MouseMoved(BPoint point
, uint32 transit
,
156 const BMessage
* message
)
158 BControl::MouseMoved(point
, transit
, message
);
163 FakeScrollBar::MouseUp(BPoint point
)
165 SetValue(B_CONTROL_ON
);
170 BControl::MouseUp(point
);
175 FakeScrollBar::SetValue(int32 value
)
177 if (value
!= Value()) {
178 BControl::SetValueNoUpdate(value
);
185 BView
* parent
= Parent();
188 if (parent
!= NULL
) {
189 // If the parent is a BBox, the group parent is the parent of the BBox
190 BBox
* box
= dynamic_cast<BBox
*>(parent
);
192 if (box
&& box
->LabelView() == this)
193 parent
= box
->Parent();
195 if (parent
!= NULL
) {
196 BBox
* box
= dynamic_cast<BBox
*>(parent
);
198 // If the parent is a BBox, skip the label if there is one
199 if (box
&& box
->LabelView())
200 child
= parent
->ChildAt(1);
202 child
= parent
->ChildAt(0);
204 child
= Window()->ChildAt(0);
206 child
= Window()->ChildAt(0);
209 FakeScrollBar
* scrollbar
= dynamic_cast<FakeScrollBar
*>(child
);
211 if (scrollbar
!= NULL
&& (scrollbar
!= this))
212 scrollbar
->SetValue(B_CONTROL_OFF
);
214 // If the child is a BBox, check if the label is a scrollbarbutton
215 BBox
* box
= dynamic_cast<BBox
*>(child
);
217 if (box
&& box
->LabelView()) {
218 scrollbar
= dynamic_cast<FakeScrollBar
*>(box
->LabelView());
220 if (scrollbar
!= NULL
&& (scrollbar
!= this))
221 scrollbar
->SetValue(B_CONTROL_OFF
);
225 child
= child
->NextSibling();
228 //ASSERT(Value() == B_CONTROL_ON);
236 FakeScrollBar::SetDoubleArrows(bool doubleArrows
)
238 fDoubleArrows
= doubleArrows
;
244 FakeScrollBar::SetKnobStyle(uint32 knobStyle
)
246 fKnobStyle
= knobStyle
;
252 FakeScrollBar::SetFromScrollBarInfo(const scroll_bar_info
&info
)
254 fDoubleArrows
= info
.double_arrows
;
255 fKnobStyle
= info
.knob
;
264 FakeScrollBar::_DrawArrowButton(int32 direction
, BRect rect
,
265 const BRect
& updateRect
)
267 if (!updateRect
.Intersects(rect
))
272 rgb_color baseColor
= tint_color(ui_color(B_PANEL_BACKGROUND_COLOR
),
275 be_control_look
->DrawButtonBackground(this, rect
, updateRect
, baseColor
,
276 flags
, BControlLook::B_ALL_BORDERS
, B_HORIZONTAL
);
278 rect
.InsetBy(-1, -1);
279 be_control_look
->DrawArrowShape(this, rect
, updateRect
,
280 baseColor
, direction
, flags
, B_DARKEN_MAX_TINT
);