2 * Copyright (C) 2010 Rene Gollent <rene@gollent.com>
3 * Copyright (C) 2010 Stephan Aßmus <superstippi@gmx.de>
5 * All rights reserved. Distributed under the terms of the MIT License.
12 #include <Application.h>
15 #include <CardLayout.h>
16 #include <ControlLook.h>
17 #include <GroupView.h>
18 #include <SpaceLayoutItem.h>
21 #include "TabContainerView.h"
24 // #pragma mark - TabView
30 fLayoutItem(new TabLayoutItem(this)),
38 // The layout item is deleted for us by the layout which contains it.
47 BSize
size(MaxSize());
54 TabView::PreferredSize()
63 float extra
= be_control_look
->DefaultLabelSpacing();
64 float labelWidth
= 300.0f
;
65 return BSize(labelWidth
, _LabelHeight() + extra
);
70 TabView::Draw(BRect updateRect
)
72 BRect
frame(fLayoutItem
->Frame());
74 // Extend the front tab outward left/right in order to merge
75 // the frames of adjacent tabs.
83 DrawBackground(fContainerView
, frame
, updateRect
, fIsFirst
, fIsLast
,
95 float spacing
= be_control_look
->DefaultLabelSpacing();
96 frame
.InsetBy(spacing
, spacing
/ 2);
97 DrawContents(fContainerView
, frame
, updateRect
, fIsFirst
, fIsLast
,
103 TabView::DrawBackground(BView
* owner
, BRect frame
, const BRect
& updateRect
,
104 bool isFirst
, bool isLast
, bool isFront
)
106 rgb_color base
= ui_color(B_PANEL_BACKGROUND_COLOR
);
107 uint32 borders
= BControlLook::B_TOP_BORDER
108 | BControlLook::B_BOTTOM_BORDER
;
111 borders
|= BControlLook::B_LEFT_BORDER
;
113 borders
|= BControlLook::B_RIGHT_BORDER
;
115 be_control_look
->DrawActiveTab(owner
, frame
, updateRect
, base
,
118 be_control_look
->DrawInactiveTab(owner
, frame
, updateRect
, base
,
125 TabView::DrawContents(BView
* owner
, BRect frame
, const BRect
& updateRect
,
126 bool isFirst
, bool isLast
, bool isFront
)
128 rgb_color base
= ui_color(B_PANEL_BACKGROUND_COLOR
);
129 be_control_look
->DrawLabel(owner
, fLabel
.String(), frame
, updateRect
,
130 base
, 0, BAlignment(B_ALIGN_LEFT
, B_ALIGN_MIDDLE
));
135 TabView::MouseDown(BPoint where
, uint32 buttons
)
137 fContainerView
->SelectTab(this);
142 TabView::MouseUp(BPoint where
)
148 TabView::MouseMoved(BPoint where
, uint32 transit
, const BMessage
* dragMessage
)
154 TabView::SetIsFront(bool isFront
)
156 Update(fIsFirst
, fIsLast
, isFront
);
161 TabView::IsFront() const
168 TabView::SetIsLast(bool isLast
)
170 Update(fIsFirst
, isLast
, fIsFront
);
175 TabView::Update(bool isFirst
, bool isLast
, bool isFront
)
177 if (fIsFirst
== isFirst
&& fIsLast
== isLast
&& fIsFront
== isFront
)
183 fLayoutItem
->InvalidateContainer();
188 TabView::SetContainerView(TabContainerView
* containerView
)
190 fContainerView
= containerView
;
195 TabView::ContainerView() const
197 return fContainerView
;
202 TabView::LayoutItem() const
209 TabView::SetLabel(const char* label
)
214 fLayoutItem
->InvalidateLayout();
219 TabView::Label() const
226 TabView::Frame() const
228 return fLayoutItem
->Frame();
233 TabView::_LabelHeight() const
235 font_height fontHeight
;
236 fContainerView
->GetFontHeight(&fontHeight
);
237 return ceilf(fontHeight
.ascent
) + ceilf(fontHeight
.descent
);
241 // #pragma mark - TabLayoutItem
244 TabLayoutItem::TabLayoutItem(TabView
* parent
)
253 TabLayoutItem::IsVisible()
260 TabLayoutItem::SetVisible(bool visible
)
262 if (fVisible
== visible
)
267 InvalidateContainer();
268 fParent
->ContainerView()->InvalidateLayout();
273 TabLayoutItem::Frame()
280 TabLayoutItem::SetFrame(BRect frame
)
282 BRect dirty
= fFrame
;
284 dirty
= dirty
| fFrame
;
285 InvalidateContainer(dirty
);
290 TabLayoutItem::View()
297 TabLayoutItem::BaseMinSize()
299 return fParent
->MinSize();
304 TabLayoutItem::BaseMaxSize()
306 return fParent
->MaxSize();
311 TabLayoutItem::BasePreferredSize()
313 return fParent
->PreferredSize();
318 TabLayoutItem::BaseAlignment()
320 return BAlignment(B_ALIGN_USE_FULL_WIDTH
, B_ALIGN_USE_FULL_HEIGHT
);
325 TabLayoutItem::Parent() const
332 TabLayoutItem::InvalidateContainer()
334 InvalidateContainer(Frame());
339 TabLayoutItem::InvalidateContainer(BRect frame
)
341 // Invalidate more than necessary, to help the TabContainerView
342 // redraw the parts outside any tabs...
345 fParent
->ContainerView()->Invalidate(frame
);