TabView: Add TabViewPrivate class, actually fix non-layout SetView.

Thanks to Axel and Stephan for reviewing!
This commit is contained in:
Augustin Cavalier
2015-07-14 11:04:39 -04:00
parent ce7470f8bf
commit c432a83bf3
3 changed files with 41 additions and 7 deletions
+4 -2
View File
@@ -52,7 +52,11 @@ public:
virtual void DrawTab(BView* owner, BRect frame,
tab_position position, bool full = true);
class Private;
private:
friend class Private;
// FBC padding and forbidden methods
virtual void _ReservedTab1();
virtual void _ReservedTab2();
@@ -70,8 +74,6 @@ private:
BTab& operator=(const BTab&);
private:
friend class BTabView;
bool fEnabled;
bool fSelected;
bool fFocus;
@@ -0,0 +1,31 @@
/*
* Copyright 2015, Haiku Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Augustin Cavalier <waddlesplash>
*/
#ifndef TABVIEW_PRIVATE_H
#define TABVIEW_PRIVATE_H
#include <TabView.h>
class BTab::Private {
public:
Private(BTab* tab)
:
fTab(tab)
{
}
void SetTabView(BTabView* tabView)
{ fTab->fTabView = tabView; }
private:
BTab* fTab;
};
#endif /* TABVIEW_PRIVATE_H */
+6 -5
View File
@@ -12,6 +12,7 @@
#include <TabView.h>
#include <TabViewPrivate.h>
#include <new>
#include <string.h>
@@ -153,12 +154,12 @@ BTab::Select(BView* owner)
{
fSelected = true;
if (!owner || !View() || !owner->Window())
if (!owner || !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)
if (!owner->GetLayout() && View()->Parent() == NULL)
owner->AddChild(fView);
}
@@ -223,7 +224,7 @@ BTab::SetView(BView* view)
fView = view;
if (fTabView != NULL && fSelected) {
Select(NULL);
Select(fTabView->ContainerView());
fTabView->Invalidate();
}
}
@@ -1151,7 +1152,7 @@ BTabView::AddTab(BView* target, BTab* tab)
fContainerView->GetLayout()->AddView(CountTabs(), target);
fTabList->AddItem(tab);
tab->fTabView = this;
BTab::Private(tab).SetTabView(this);
// When we haven't had a any tabs before, but are already attached to the
// window, select this one.
@@ -1171,7 +1172,7 @@ BTabView::RemoveTab(int32 index)
return NULL;
tab->Deselect();
tab->fTabView = NULL;
BTab::Private(tab).SetTabView(NULL);
if (fContainerView->GetLayout())
fContainerView->GetLayout()->RemoveItem(index);