BTabView: Lots of fixes & cleanup.

* 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.
This commit is contained in:
Augustin Cavalier 2015-07-13 21:28:20 -04:00
parent fb6c8a0479
commit 6031dea0cb
2 changed files with 31 additions and 14 deletions

View File

@ -9,6 +9,9 @@
#include <View.h> #include <View.h>
class BTabView;
enum tab_position { enum tab_position {
B_TAB_FIRST = 999, B_TAB_FIRST = 999,
B_TAB_FRONT, B_TAB_FRONT,
@ -67,12 +70,15 @@ private:
BTab& operator=(const BTab&); BTab& operator=(const BTab&);
private: private:
friend class BTabView;
bool fEnabled; bool fEnabled;
bool fSelected; bool fSelected;
bool fFocus; bool fFocus;
BView* fView; BView* fView;
BTabView* fTabView;
uint32 _reserved[12]; uint32 _reserved[11];
}; };

View File

@ -52,7 +52,8 @@ BTab::BTab(BView* tabView)
fEnabled(true), fEnabled(true),
fSelected(false), fSelected(false),
fFocus(false), fFocus(false),
fView(tabView) fView(tabView),
fTabView(NULL)
{ {
} }
@ -62,7 +63,8 @@ BTab::BTab(BMessage* archive)
BArchivable(archive), BArchivable(archive),
fSelected(false), fSelected(false),
fFocus(false), fFocus(false),
fView(NULL) fView(NULL),
fTabView(NULL)
{ {
bool disable; bool disable;
@ -133,6 +135,9 @@ BTab::SetLabel(const char* label)
return; return;
fView->SetName(label); fView->SetName(label);
if (fTabView != NULL)
fTabView->Invalidate();
} }
@ -144,29 +149,28 @@ BTab::IsSelected() const
void void
BTab::Select(BView* owner) BTab::Select(BView*)
{ {
// TODO: Shouldn't we still maintain fSelected like in Deselect()? fSelected = true;
if (!owner || !View() || !owner->Window())
if (!fTabView || !View())
return; return;
// NOTE: Views are not added/removed, if there is layout, // NOTE: Views are not added/removed, if there is layout,
// they are made visible/invisible in that case. // they are made visible/invisible in that case.
if (!owner->GetLayout() && View()->Parent() == NULL) if (!fTabView->ContainerView()->GetLayout() && View()->Parent() == NULL)
owner->AddChild(fView); fTabView->AddChild(fView);
fSelected = true;
} }
void void
BTab::Deselect() BTab::Deselect()
{ {
if (View()) { if (View() && fTabView) {
// NOTE: Views are not added/removed, if there is layout, // NOTE: Views are not added/removed, if there is layout,
// they are made visible/invisible in that case. // they are made visible/invisible in that case.
bool removeView = false; bool removeView = false;
BView* container = View()->Parent(); BView* container = fTabView->ContainerView();
if (container) if (container)
removeView = removeView =
dynamic_cast<BCardLayout*>(container->GetLayout()) == NULL; dynamic_cast<BCardLayout*>(container->GetLayout()) == NULL;
@ -217,6 +221,11 @@ BTab::SetView(BView* view)
delete fView; delete fView;
} }
fView = view; fView = view;
if (fTabView != NULL && fSelected) {
Select(NULL);
fTabView->Invalidate();
}
} }
@ -491,7 +500,7 @@ BTabView::AttachedToWindow()
{ {
BView::AttachedToWindow(); BView::AttachedToWindow();
if (fSelection < 0) if (fSelection < 0 && CountTabs() > 0)
Select(0); Select(0);
} }
@ -682,10 +691,10 @@ BTabView::Select(int32 index)
tab->Deselect(); tab->Deselect();
tab = TabAt(index); tab = TabAt(index);
tab->Select(NULL);
if (tab && ContainerView()) { if (tab && ContainerView()) {
if (index == 0) if (index == 0)
fTabOffset = 0.0f; fTabOffset = 0.0f;
tab->Select(ContainerView());
fSelection = index; fSelection = index;
// make the view visible through the layout if there is one // make the view visible through the layout if there is one
@ -1142,6 +1151,7 @@ BTabView::AddTab(BView* target, BTab* tab)
fContainerView->GetLayout()->AddView(CountTabs(), target); fContainerView->GetLayout()->AddView(CountTabs(), target);
fTabList->AddItem(tab); fTabList->AddItem(tab);
tab->fTabView = this;
// When we haven't had a any tabs before, but are already attached to the // When we haven't had a any tabs before, but are already attached to the
// window, select this one. // window, select this one.
@ -1161,6 +1171,7 @@ BTabView::RemoveTab(int32 index)
return NULL; return NULL;
tab->Deselect(); tab->Deselect();
tab->fTabView = NULL;
if (fContainerView->GetLayout()) if (fContainerView->GetLayout())
fContainerView->GetLayout()->RemoveItem(index); fContainerView->GetLayout()->RemoveItem(index);