diff --git a/headers/os/interface/TabView.h b/headers/os/interface/TabView.h index 86fe2d528d..7604d5b06d 100644 --- a/headers/os/interface/TabView.h +++ b/headers/os/interface/TabView.h @@ -106,6 +106,11 @@ virtual void _ReservedTab12(); class BTabView : public BView { public: + BTabView(const char *name, + button_width width = B_WIDTH_AS_USUAL, + uint32 flags = B_FULL_UPDATE_ON_RESIZE | + B_WILL_DRAW | B_NAVIGABLE_JUMP | + B_FRAME_EVENTS | B_NAVIGABLE); BTabView(BRect frame, const char *name, button_width width = B_WIDTH_AS_USUAL, uint32 resizingMode = B_FOLLOW_ALL, @@ -150,8 +155,12 @@ virtual BRect TabFrame(int32 tab_index) const; virtual void SetFlags(uint32 flags); virtual void SetResizingMode(uint32 mode); -virtual void GetPreferredSize(float *width, float *height); -virtual void ResizeToPreferred(); +virtual void ResizeToPreferred(); +virtual void GetPreferredSize(float* _width, float* _height); + +virtual BSize MinSize(); +virtual BSize MaxSize(); +virtual BSize PreferredSize(); virtual BHandler *ResolveSpecifier(BMessage *message, int32 index, BMessage *specifier, int32 what, const char *property); @@ -174,7 +183,7 @@ virtual void SetTabHeight(float height); BView *ViewForTab(int32 tabIndex) const; private: - void _InitObject(); + void _InitObject(bool layouted = false); virtual void _ReservedTabView1(); virtual void _ReservedTabView2(); diff --git a/src/kits/interface/TabView.cpp b/src/kits/interface/TabView.cpp index 56247d05f1..e0b08ac03a 100644 --- a/src/kits/interface/TabView.cpp +++ b/src/kits/interface/TabView.cpp @@ -8,8 +8,11 @@ */ #include +#include #include +#include +#include #include #include #include @@ -127,12 +130,15 @@ BTab::IsSelected() const void BTab::Select(BView *owner) -{ +{ + // TODO: Shouldn't we still maintain fSelected like in Deselect()? if (!owner || !View() || !owner->Window()) return; - owner->AddChild(fView); - //fView->Show(); + // NOTE: Views are not added/removed, if there is layout, + // they are made visible/invisible in that case. + if (!owner->GetLayout()) + owner->AddChild(fView); fSelected = true; } @@ -141,9 +147,18 @@ BTab::Select(BView *owner) void BTab::Deselect() { - if (View()) - View()->RemoveSelf(); - + if (View()) { + // NOTE: Views are not added/removed, if there is layout, + // they are made visible/invisible in that case. + bool removeView = false; + BView* container = View()->Parent(); + if (container) + removeView = + dynamic_cast(container->GetLayout()) == NULL; + if (removeView) + View()->RemoveSelf(); + } + fSelected = false; } @@ -329,6 +344,16 @@ BTab &BTab::operator=(const BTab &) // #pragma mark - +BTabView::BTabView(const char *name, button_width width, uint32 flags) + : BView(name, flags) +{ + SetFont(be_bold_font); + + _InitObject(true); + + fTabWidthSetting = width; +} + BTabView::BTabView(BRect frame, const char *name, button_width width, uint32 resizingMode, uint32 flags) @@ -669,6 +694,7 @@ BTabView::Select(int32 index) index = Selection(); BTab *tab = TabAt(Selection()); + if (tab) tab->Deselect(); @@ -678,6 +704,12 @@ BTabView::Select(int32 index) fTabOffset = 0.0f; tab->Select(ContainerView()); fSelection = index; + + // make the view visible through the layout if there is one + BCardLayout* layout + = dynamic_cast(fContainerView->GetLayout()); + if (layout) + layout->SetVisibleItem(index); } Invalidate(); @@ -917,6 +949,36 @@ BTabView::GetPreferredSize(float *width, float *height) } +BSize +BTabView::MinSize() +{ + BSize size = fContainerView->MinSize(); + size.height += TabHeight() + 6.0f; + size.width += 6.0f; + return BLayoutUtils::ComposeSize(ExplicitMinSize(), size); +} + + +BSize +BTabView::MaxSize() +{ + BSize size = fContainerView->MaxSize(); + size.height += TabHeight() + 6.0f; + size.width += 6.0f; + return BLayoutUtils::ComposeSize(ExplicitMaxSize(), size); +} + + +BSize +BTabView::PreferredSize() +{ + BSize size = fContainerView->PreferredSize(); + size.height += TabHeight() + 6.0f; + size.width += 6.0f; + return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), size); +} + + void BTabView::ResizeToPreferred() { @@ -957,6 +1019,9 @@ BTabView::AddTab(BView *target, BTab *tab) tab = new BTab(target); else tab->SetView(target); + + if (fContainerView->GetLayout()) + fContainerView->GetLayout()->AddView(CountTabs(), target); fTabList->AddItem(tab); } @@ -987,6 +1052,9 @@ BTabView::RemoveTab(int32 index) else SetFocusTab(fFocus, true); + if (fContainerView->GetLayout()) + fContainerView->GetLayout()->RemoveItem(index); + return tab; } @@ -1062,7 +1130,7 @@ BTabView::ViewForTab(int32 tabIndex) const void -BTabView::_InitObject() +BTabView::_InitObject(bool layouted) { fTabList = new BList; @@ -1088,6 +1156,9 @@ BTabView::_InitObject() fContainerView = new BView(bounds, "view container", B_FOLLOW_ALL, B_WILL_DRAW); + if (layouted) + fContainerView->SetLayout(new(std::nothrow) BCardLayout()); + fContainerView->SetViewColor(color); fContainerView->SetLowColor(color);