Skip to content

Commit

Permalink
BTabView: Lots of fixes & cleanup.
Browse files Browse the repository at this point in the history
 * Address TODO about setting fSelected when nothing is done.
 * Pass a pointer to the tab view to the BTab so that it can call Invalidate().
  (Checked against BeOS).
 * Call Invalidate() from the BTab after SetView() & SetName().

Fixes #12108 & #12196.
  • Loading branch information
waddlesplash committed Jul 14, 2015
1 parent fb6c8a0 commit 6031dea
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 14 deletions.
8 changes: 7 additions & 1 deletion headers/os/interface/TabView.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
#include <View.h>


class BTabView;


enum tab_position {
B_TAB_FIRST = 999,
B_TAB_FRONT,
Expand Down Expand Up @@ -67,12 +70,15 @@ class BTab : public BArchivable {
BTab& operator=(const BTab&);

private:
friend class BTabView;

bool fEnabled;
bool fSelected;
bool fFocus;
BView* fView;
BTabView* fTabView;

uint32 _reserved[12];
uint32 _reserved[11];
};


Expand Down
37 changes: 24 additions & 13 deletions src/kits/interface/TabView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ BTab::BTab(BView* tabView)
fEnabled(true),
fSelected(false),
fFocus(false),
fView(tabView)
fView(tabView),
fTabView(NULL)
{
}

Expand All @@ -62,7 +63,8 @@ BTab::BTab(BMessage* archive)
BArchivable(archive),
fSelected(false),
fFocus(false),
fView(NULL)
fView(NULL),
fTabView(NULL)
{
bool disable;

Expand Down Expand Up @@ -133,6 +135,9 @@ BTab::SetLabel(const char* label)
return;

fView->SetName(label);

if (fTabView != NULL)
fTabView->Invalidate();
}


Expand All @@ -144,29 +149,28 @@ BTab::IsSelected() const


void
BTab::Select(BView* owner)
BTab::Select(BView*)
{
// TODO: Shouldn't we still maintain fSelected like in Deselect()?
if (!owner || !View() || !owner->Window())
fSelected = true;

if (!fTabView || !View())
return;

// NOTE: Views are not added/removed, if there is layout,
// they are made visible/invisible in that case.
if (!owner->GetLayout() && View()->Parent() == NULL)
owner->AddChild(fView);

fSelected = true;
if (!fTabView->ContainerView()->GetLayout() && View()->Parent() == NULL)
fTabView->AddChild(fView);
}


void
BTab::Deselect()
{
if (View()) {
if (View() && fTabView) {
// 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();
BView* container = fTabView->ContainerView();
if (container)
removeView =
dynamic_cast<BCardLayout*>(container->GetLayout()) == NULL;
Expand Down Expand Up @@ -217,6 +221,11 @@ BTab::SetView(BView* view)
delete fView;
}
fView = view;

if (fTabView != NULL && fSelected) {
Select(NULL);
fTabView->Invalidate();
}
}


Expand Down Expand Up @@ -491,7 +500,7 @@ BTabView::AttachedToWindow()
{
BView::AttachedToWindow();

if (fSelection < 0)
if (fSelection < 0 && CountTabs() > 0)
Select(0);
}

Expand Down Expand Up @@ -682,10 +691,10 @@ BTabView::Select(int32 index)
tab->Deselect();

tab = TabAt(index);
tab->Select(NULL);
if (tab && ContainerView()) {
if (index == 0)
fTabOffset = 0.0f;
tab->Select(ContainerView());
fSelection = index;

// make the view visible through the layout if there is one
Expand Down Expand Up @@ -1142,6 +1151,7 @@ BTabView::AddTab(BView* target, BTab* tab)
fContainerView->GetLayout()->AddView(CountTabs(), target);

fTabList->AddItem(tab);
tab->fTabView = this;

// When we haven't had a any tabs before, but are already attached to the
// window, select this one.
Expand All @@ -1161,6 +1171,7 @@ BTabView::RemoveTab(int32 index)
return NULL;

tab->Deselect();
tab->fTabView = NULL;

if (fContainerView->GetLayout())
fContainerView->GetLayout()->RemoveItem(index);
Expand Down

0 comments on commit 6031dea

Please sign in to comment.