Try to have a really smart tab view... It won't show any tabs when
there's only one view attached. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21785 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
6b7bedcbee
commit
bba01ef7c1
@ -8,10 +8,15 @@
|
||||
|
||||
#include "SmartTabView.h"
|
||||
|
||||
#include <TabView.h>
|
||||
|
||||
|
||||
SmartTabView::SmartTabView(BRect frame, const char *name, button_width width,
|
||||
uint32 resizingMode, uint32 flags)
|
||||
:
|
||||
BTabView(frame, name, width, resizingMode, flags)
|
||||
BView(frame, name, resizingMode, flags),
|
||||
fTabView(NULL),
|
||||
fView(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
@ -21,49 +26,115 @@ SmartTabView::~SmartTabView()
|
||||
}
|
||||
|
||||
|
||||
BView *
|
||||
SmartTabView::ContainerView()
|
||||
{
|
||||
return fTabView != NULL ? fTabView->ContainerView() : this;
|
||||
}
|
||||
|
||||
|
||||
BView *
|
||||
SmartTabView::ViewForTab(int32 tab)
|
||||
{
|
||||
return fTabView != NULL ? fTabView->ViewForTab(tab) : fView;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SmartTabView::Select(int32 index)
|
||||
{
|
||||
BTabView::Select(index);
|
||||
BTab *tab = TabAt(Selection());
|
||||
if (tab != NULL) {
|
||||
BView *view = tab->View();
|
||||
if (view != NULL)
|
||||
view->ResizeTo(Bounds().Width(), Bounds().Height());
|
||||
if (fView != NULL) {
|
||||
fView->ResizeTo(Bounds().Width(), Bounds().Height());
|
||||
} else if (fTabView != NULL) {
|
||||
fTabView->Select(index);
|
||||
BTab *tab = fTabView->TabAt(fTabView->Selection());
|
||||
if (tab != NULL) {
|
||||
BView *view = tab->View();
|
||||
if (view != NULL)
|
||||
view->ResizeTo(fTabView->Bounds().Width(), fTabView->Bounds().Height());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
int32
|
||||
SmartTabView::Selection() const
|
||||
{
|
||||
return fTabView != NULL ? fTabView->Selection() : 0;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SmartTabView::AddTab(BView *target, BTab *tab)
|
||||
{
|
||||
if (target == NULL)
|
||||
return;
|
||||
|
||||
if (CountTabs() == 1) {
|
||||
|
||||
if (fView == NULL && fTabView == NULL) {
|
||||
fView = target;
|
||||
AddChild(target);
|
||||
} else {
|
||||
if (fTabView == NULL) {
|
||||
RemoveChild(fView);
|
||||
fTabView = new BTabView(Bounds(), "tabview");
|
||||
AddChild(fTabView);
|
||||
fTabView->MoveTo(B_ORIGIN);
|
||||
fTabView->ResizeTo(Bounds().Width(), Bounds().Height());
|
||||
fTabView->AddTab(fView);
|
||||
fTabView->Select(0);
|
||||
fView = NULL;
|
||||
}
|
||||
fTabView->AddTab(target, tab);
|
||||
}
|
||||
AddTab(target, tab);
|
||||
}
|
||||
|
||||
|
||||
BTab *
|
||||
SmartTabView::RemoveTab(int32 index)
|
||||
{
|
||||
BTab *oldTab = RemoveTab(index);
|
||||
if (CountTabs() == 1) {
|
||||
|
||||
BTab *returnTab = NULL;
|
||||
if (fTabView != NULL) {
|
||||
returnTab = fTabView->RemoveTab(index);
|
||||
if (fTabView->CountTabs() == 1) {
|
||||
BTab *tab = fTabView->RemoveTab(0);
|
||||
RemoveChild(fTabView);
|
||||
delete fTabView;
|
||||
fTabView = NULL;
|
||||
fView = tab->View();
|
||||
tab->SetView(NULL);
|
||||
AddChild(fView);
|
||||
fView->MoveTo(B_ORIGIN);
|
||||
fView->ResizeTo(Bounds().Width(), Bounds().Height());
|
||||
delete tab;
|
||||
}
|
||||
} else if (fView != NULL) {
|
||||
RemoveChild(fView);
|
||||
returnTab = new BTab();
|
||||
returnTab->SetView(fView);
|
||||
fView = NULL;
|
||||
}
|
||||
return oldTab;
|
||||
|
||||
return returnTab;
|
||||
}
|
||||
|
||||
|
||||
BRect
|
||||
SmartTabView::DrawTabs()
|
||||
int32
|
||||
SmartTabView::CountTabs() const
|
||||
{
|
||||
//if (CountTabs() > 1)
|
||||
return BTabView::DrawTabs();
|
||||
//return BRect(0, 0, -1, -1);
|
||||
if (fTabView != NULL)
|
||||
return fTabView->CountTabs();
|
||||
|
||||
return fView != NULL ? 1 : 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
void
|
||||
SmartTabView::Draw(BRect updateRect)
|
||||
{
|
||||
if (fView != NULL) {
|
||||
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
|
@ -9,9 +9,10 @@
|
||||
#ifndef __SMARTTABVIEW_H
|
||||
#define __SMARTTABVIEW_H
|
||||
|
||||
#include <TabView.h>
|
||||
#include <View.h>
|
||||
|
||||
class SmartTabView : public BTabView {
|
||||
class BTabView;
|
||||
class SmartTabView : public BView {
|
||||
public:
|
||||
SmartTabView(BRect frame, const char *name,
|
||||
button_width width = B_WIDTH_AS_USUAL,
|
||||
@ -20,12 +21,22 @@ public:
|
||||
B_WILL_DRAW | B_NAVIGABLE_JUMP |
|
||||
B_FRAME_EVENTS | B_NAVIGABLE);
|
||||
virtual ~SmartTabView();
|
||||
|
||||
virtual BView *ContainerView();
|
||||
virtual BView *ViewForTab(int32);
|
||||
|
||||
virtual void Select(int32 tab);
|
||||
/*
|
||||
virtual int32 Selection() const;
|
||||
|
||||
virtual void AddTab(BView *target, BTab *tab = NULL);
|
||||
virtual BTab* RemoveTab(int32 index);
|
||||
virtual BRect DrawTabs();*/
|
||||
virtual int32 CountTabs() const;
|
||||
|
||||
//virtual void Draw(BRect rect);
|
||||
|
||||
private:
|
||||
BTabView *fTabView;
|
||||
BView *fView;
|
||||
};
|
||||
|
||||
#endif // __SMARTTABVIEW_H
|
||||
|
Loading…
Reference in New Issue
Block a user