HaikuDepot: notify work status from main window
[haiku.git] / src / apps / webpositive / tabview / TabView.cpp
blob350bed59b975772488059c1fdbb8e37073654fa4
1 /*
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.
6 */
8 #include "TabView.h"
10 #include <stdio.h>
12 #include <Application.h>
13 #include <Bitmap.h>
14 #include <Button.h>
15 #include <CardLayout.h>
16 #include <ControlLook.h>
17 #include <GroupView.h>
18 #include <SpaceLayoutItem.h>
19 #include <Window.h>
21 #include "TabContainerView.h"
24 // #pragma mark - TabView
27 TabView::TabView()
29 fContainerView(NULL),
30 fLayoutItem(new TabLayoutItem(this)),
31 fLabel()
36 TabView::~TabView()
38 // The layout item is deleted for us by the layout which contains it.
39 if (!fContainerView)
40 delete fLayoutItem;
44 BSize
45 TabView::MinSize()
47 BSize size(MaxSize());
48 size.width = 60.0f;
49 return size;
53 BSize
54 TabView::PreferredSize()
56 return MaxSize();
60 BSize
61 TabView::MaxSize()
63 float extra = be_control_look->DefaultLabelSpacing();
64 float labelWidth = 300.0f;
65 return BSize(labelWidth, _LabelHeight() + extra);
69 void
70 TabView::Draw(BRect updateRect)
72 BRect frame(fLayoutItem->Frame());
73 if (fIsFront) {
74 // Extend the front tab outward left/right in order to merge
75 // the frames of adjacent tabs.
76 if (!fIsFirst)
77 frame.left--;
78 if (!fIsLast)
79 frame.right++;
81 frame.bottom++;
83 DrawBackground(fContainerView, frame, updateRect, fIsFirst, fIsLast,
84 fIsFront);
86 if (fIsFront) {
87 frame.top += 3.0f;
88 if (!fIsFirst)
89 frame.left++;
90 if (!fIsLast)
91 frame.right--;
92 } else
93 frame.top += 6.0f;
95 float spacing = be_control_look->DefaultLabelSpacing();
96 frame.InsetBy(spacing, spacing / 2);
97 DrawContents(fContainerView, frame, updateRect, fIsFirst, fIsLast,
98 fIsFront);
102 void
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;
110 if (isFirst)
111 borders |= BControlLook::B_LEFT_BORDER;
112 if (isLast)
113 borders |= BControlLook::B_RIGHT_BORDER;
114 if (isFront) {
115 be_control_look->DrawActiveTab(owner, frame, updateRect, base,
116 0, borders);
117 } else {
118 be_control_look->DrawInactiveTab(owner, frame, updateRect, base,
119 0, borders);
124 void
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));
134 void
135 TabView::MouseDown(BPoint where, uint32 buttons)
137 fContainerView->SelectTab(this);
141 void
142 TabView::MouseUp(BPoint where)
147 void
148 TabView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
153 void
154 TabView::SetIsFront(bool isFront)
156 Update(fIsFirst, fIsLast, isFront);
160 bool
161 TabView::IsFront() const
163 return fIsFront;
167 void
168 TabView::SetIsLast(bool isLast)
170 Update(fIsFirst, isLast, fIsFront);
174 void
175 TabView::Update(bool isFirst, bool isLast, bool isFront)
177 if (fIsFirst == isFirst && fIsLast == isLast && fIsFront == isFront)
178 return;
179 fIsFirst = isFirst;
180 fIsLast = isLast;
181 fIsFront = isFront;
183 fLayoutItem->InvalidateContainer();
187 void
188 TabView::SetContainerView(TabContainerView* containerView)
190 fContainerView = containerView;
194 TabContainerView*
195 TabView::ContainerView() const
197 return fContainerView;
201 BLayoutItem*
202 TabView::LayoutItem() const
204 return fLayoutItem;
208 void
209 TabView::SetLabel(const char* label)
211 if (fLabel == label)
212 return;
213 fLabel = label;
214 fLayoutItem->InvalidateLayout();
218 const BString&
219 TabView::Label() const
221 return fLabel;
225 BRect
226 TabView::Frame() const
228 return fLayoutItem->Frame();
232 float
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)
246 fParent(parent),
247 fVisible(true)
252 bool
253 TabLayoutItem::IsVisible()
255 return fVisible;
259 void
260 TabLayoutItem::SetVisible(bool visible)
262 if (fVisible == visible)
263 return;
265 fVisible = visible;
267 InvalidateContainer();
268 fParent->ContainerView()->InvalidateLayout();
272 BRect
273 TabLayoutItem::Frame()
275 return fFrame;
279 void
280 TabLayoutItem::SetFrame(BRect frame)
282 BRect dirty = fFrame;
283 fFrame = frame;
284 dirty = dirty | fFrame;
285 InvalidateContainer(dirty);
289 BView*
290 TabLayoutItem::View()
292 return NULL;
296 BSize
297 TabLayoutItem::BaseMinSize()
299 return fParent->MinSize();
303 BSize
304 TabLayoutItem::BaseMaxSize()
306 return fParent->MaxSize();
310 BSize
311 TabLayoutItem::BasePreferredSize()
313 return fParent->PreferredSize();
317 BAlignment
318 TabLayoutItem::BaseAlignment()
320 return BAlignment(B_ALIGN_USE_FULL_WIDTH, B_ALIGN_USE_FULL_HEIGHT);
324 TabView*
325 TabLayoutItem::Parent() const
327 return fParent;
331 void
332 TabLayoutItem::InvalidateContainer()
334 InvalidateContainer(Frame());
338 void
339 TabLayoutItem::InvalidateContainer(BRect frame)
341 // Invalidate more than necessary, to help the TabContainerView
342 // redraw the parts outside any tabs...
343 frame.bottom++;
344 frame.right++;
345 fParent->ContainerView()->Invalidate(frame);