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:
Stefano Ceccherini
2007-08-02 06:44:34 +00:00
parent 6b7bedcbee
commit bba01ef7c1
2 changed files with 108 additions and 26 deletions
+93 -22
View File
@@ -8,10 +8,15 @@
#include "SmartTabView.h" #include "SmartTabView.h"
#include <TabView.h>
SmartTabView::SmartTabView(BRect frame, const char *name, button_width width, SmartTabView::SmartTabView(BRect frame, const char *name, button_width width,
uint32 resizingMode, uint32 flags) uint32 resizingMode, uint32 flags)
: :
BTabView(frame, name, width, resizingMode, flags) BView(frame, name, resizingMode, flags),
fTabView(NULL),
fView(NULL)
{ {
} }
@@ -21,50 +26,116 @@ SmartTabView::~SmartTabView()
} }
BView *
SmartTabView::ContainerView()
{
return fTabView != NULL ? fTabView->ContainerView() : this;
}
BView *
SmartTabView::ViewForTab(int32 tab)
{
return fTabView != NULL ? fTabView->ViewForTab(tab) : fView;
}
void void
SmartTabView::Select(int32 index) SmartTabView::Select(int32 index)
{ {
BTabView::Select(index); if (fView != NULL) {
BTab *tab = TabAt(Selection()); fView->ResizeTo(Bounds().Width(), Bounds().Height());
if (tab != NULL) { } else if (fTabView != NULL) {
BView *view = tab->View(); fTabView->Select(index);
if (view != NULL) BTab *tab = fTabView->TabAt(fTabView->Selection());
view->ResizeTo(Bounds().Width(), Bounds().Height()); 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 void
SmartTabView::AddTab(BView *target, BTab *tab) SmartTabView::AddTab(BView *target, BTab *tab)
{ {
if (target == NULL) if (target == NULL)
return; return;
if (CountTabs() == 1) { if (fView == NULL && fTabView == NULL) {
fView = target;
} AddChild(target);
AddTab(target, tab); } 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);
}
} }
BTab * BTab *
SmartTabView::RemoveTab(int32 index) SmartTabView::RemoveTab(int32 index)
{ {
BTab *oldTab = RemoveTab(index); BTab *returnTab = NULL;
if (CountTabs() == 1) { 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 int32
SmartTabView::DrawTabs() SmartTabView::CountTabs() const
{ {
//if (CountTabs() > 1) if (fTabView != NULL)
return BTabView::DrawTabs(); return fTabView->CountTabs();
//return BRect(0, 0, -1, -1);
return fView != NULL ? 1 : 0;
}
/*
void
SmartTabView::Draw(BRect updateRect)
{
if (fView != NULL) {
}
} }
*/ */
+15 -4
View File
@@ -9,9 +9,10 @@
#ifndef __SMARTTABVIEW_H #ifndef __SMARTTABVIEW_H
#define __SMARTTABVIEW_H #define __SMARTTABVIEW_H
#include <TabView.h> #include <View.h>
class SmartTabView : public BTabView { class BTabView;
class SmartTabView : public BView {
public: public:
SmartTabView(BRect frame, const char *name, SmartTabView(BRect frame, const char *name,
button_width width = B_WIDTH_AS_USUAL, button_width width = B_WIDTH_AS_USUAL,
@@ -20,12 +21,22 @@ public:
B_WILL_DRAW | B_NAVIGABLE_JUMP | B_WILL_DRAW | B_NAVIGABLE_JUMP |
B_FRAME_EVENTS | B_NAVIGABLE); B_FRAME_EVENTS | B_NAVIGABLE);
virtual ~SmartTabView(); virtual ~SmartTabView();
virtual BView *ContainerView();
virtual BView *ViewForTab(int32);
virtual void Select(int32 tab); virtual void Select(int32 tab);
/* virtual int32 Selection() const;
virtual void AddTab(BView *target, BTab *tab = NULL); virtual void AddTab(BView *target, BTab *tab = NULL);
virtual BTab* RemoveTab(int32 index); 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 #endif // __SMARTTABVIEW_H