Patch by Artur Wyszynski:
* The BTabView can now be used with layout management. In this setup, children views are managed by a BCardLayout and are hidden/shown instead of removed/ added when (de)activated. Thanks a lot! git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28701 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
5ebeee561a
commit
e401039efa
@ -106,6 +106,11 @@ virtual void _ReservedTab12();
|
|||||||
class BTabView : public BView
|
class BTabView : public BView
|
||||||
{
|
{
|
||||||
public:
|
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,
|
BTabView(BRect frame, const char *name,
|
||||||
button_width width = B_WIDTH_AS_USUAL,
|
button_width width = B_WIDTH_AS_USUAL,
|
||||||
uint32 resizingMode = B_FOLLOW_ALL,
|
uint32 resizingMode = B_FOLLOW_ALL,
|
||||||
@ -150,8 +155,12 @@ virtual BRect TabFrame(int32 tab_index) const;
|
|||||||
virtual void SetFlags(uint32 flags);
|
virtual void SetFlags(uint32 flags);
|
||||||
virtual void SetResizingMode(uint32 mode);
|
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,
|
virtual BHandler *ResolveSpecifier(BMessage *message, int32 index,
|
||||||
BMessage *specifier, int32 what, const char *property);
|
BMessage *specifier, int32 what, const char *property);
|
||||||
@ -174,7 +183,7 @@ virtual void SetTabHeight(float height);
|
|||||||
BView *ViewForTab(int32 tabIndex) const;
|
BView *ViewForTab(int32 tabIndex) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _InitObject();
|
void _InitObject(bool layouted = false);
|
||||||
|
|
||||||
virtual void _ReservedTabView1();
|
virtual void _ReservedTabView1();
|
||||||
virtual void _ReservedTabView2();
|
virtual void _ReservedTabView2();
|
||||||
|
@ -8,8 +8,11 @@
|
|||||||
*/
|
*/
|
||||||
#include <TabView.h>
|
#include <TabView.h>
|
||||||
|
|
||||||
|
#include <new>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include <CardLayout.h>
|
||||||
|
#include <LayoutUtils.h>
|
||||||
#include <List.h>
|
#include <List.h>
|
||||||
#include <Message.h>
|
#include <Message.h>
|
||||||
#include <PropertyInfo.h>
|
#include <PropertyInfo.h>
|
||||||
@ -128,11 +131,14 @@ BTab::IsSelected() const
|
|||||||
void
|
void
|
||||||
BTab::Select(BView *owner)
|
BTab::Select(BView *owner)
|
||||||
{
|
{
|
||||||
|
// TODO: Shouldn't we still maintain fSelected like in Deselect()?
|
||||||
if (!owner || !View() || !owner->Window())
|
if (!owner || !View() || !owner->Window())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
owner->AddChild(fView);
|
// NOTE: Views are not added/removed, if there is layout,
|
||||||
//fView->Show();
|
// they are made visible/invisible in that case.
|
||||||
|
if (!owner->GetLayout())
|
||||||
|
owner->AddChild(fView);
|
||||||
|
|
||||||
fSelected = true;
|
fSelected = true;
|
||||||
}
|
}
|
||||||
@ -141,8 +147,17 @@ BTab::Select(BView *owner)
|
|||||||
void
|
void
|
||||||
BTab::Deselect()
|
BTab::Deselect()
|
||||||
{
|
{
|
||||||
if (View())
|
if (View()) {
|
||||||
View()->RemoveSelf();
|
// 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<BCardLayout*>(container->GetLayout()) == NULL;
|
||||||
|
if (removeView)
|
||||||
|
View()->RemoveSelf();
|
||||||
|
}
|
||||||
|
|
||||||
fSelected = false;
|
fSelected = false;
|
||||||
}
|
}
|
||||||
@ -329,6 +344,16 @@ BTab &BTab::operator=(const BTab &)
|
|||||||
|
|
||||||
// #pragma mark -
|
// #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,
|
BTabView::BTabView(BRect frame, const char *name, button_width width,
|
||||||
uint32 resizingMode, uint32 flags)
|
uint32 resizingMode, uint32 flags)
|
||||||
@ -669,6 +694,7 @@ BTabView::Select(int32 index)
|
|||||||
index = Selection();
|
index = Selection();
|
||||||
|
|
||||||
BTab *tab = TabAt(Selection());
|
BTab *tab = TabAt(Selection());
|
||||||
|
|
||||||
if (tab)
|
if (tab)
|
||||||
tab->Deselect();
|
tab->Deselect();
|
||||||
|
|
||||||
@ -678,6 +704,12 @@ BTabView::Select(int32 index)
|
|||||||
fTabOffset = 0.0f;
|
fTabOffset = 0.0f;
|
||||||
tab->Select(ContainerView());
|
tab->Select(ContainerView());
|
||||||
fSelection = index;
|
fSelection = index;
|
||||||
|
|
||||||
|
// make the view visible through the layout if there is one
|
||||||
|
BCardLayout* layout
|
||||||
|
= dynamic_cast<BCardLayout*>(fContainerView->GetLayout());
|
||||||
|
if (layout)
|
||||||
|
layout->SetVisibleItem(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
Invalidate();
|
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
|
void
|
||||||
BTabView::ResizeToPreferred()
|
BTabView::ResizeToPreferred()
|
||||||
{
|
{
|
||||||
@ -958,6 +1020,9 @@ BTabView::AddTab(BView *target, BTab *tab)
|
|||||||
else
|
else
|
||||||
tab->SetView(target);
|
tab->SetView(target);
|
||||||
|
|
||||||
|
if (fContainerView->GetLayout())
|
||||||
|
fContainerView->GetLayout()->AddView(CountTabs(), target);
|
||||||
|
|
||||||
fTabList->AddItem(tab);
|
fTabList->AddItem(tab);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -987,6 +1052,9 @@ BTabView::RemoveTab(int32 index)
|
|||||||
else
|
else
|
||||||
SetFocusTab(fFocus, true);
|
SetFocusTab(fFocus, true);
|
||||||
|
|
||||||
|
if (fContainerView->GetLayout())
|
||||||
|
fContainerView->GetLayout()->RemoveItem(index);
|
||||||
|
|
||||||
return tab;
|
return tab;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1062,7 +1130,7 @@ BTabView::ViewForTab(int32 tabIndex) const
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
BTabView::_InitObject()
|
BTabView::_InitObject(bool layouted)
|
||||||
{
|
{
|
||||||
fTabList = new BList;
|
fTabList = new BList;
|
||||||
|
|
||||||
@ -1088,6 +1156,9 @@ BTabView::_InitObject()
|
|||||||
fContainerView = new BView(bounds, "view container", B_FOLLOW_ALL,
|
fContainerView = new BView(bounds, "view container", B_FOLLOW_ALL,
|
||||||
B_WILL_DRAW);
|
B_WILL_DRAW);
|
||||||
|
|
||||||
|
if (layouted)
|
||||||
|
fContainerView->SetLayout(new(std::nothrow) BCardLayout());
|
||||||
|
|
||||||
fContainerView->SetViewColor(color);
|
fContainerView->SetViewColor(color);
|
||||||
fContainerView->SetLowColor(color);
|
fContainerView->SetLowColor(color);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user