BTab: decouple display label from view name.
In BeOS, the tab label was synchronized with the view name. This means BTab::SetLabel would change the view name. This behavior is unexpected, and also annoying, for example it prevents using localized tab labels but fixed view names for scripting. * Document this divergence from BeOS in the Haiku book * Detect if we're running in a BeOS app to preserve the old behavior then Change-Id: I5b758a035fe8752cee2ea7789a30ea47a01467b9 Reviewed-on: https://review.haiku-os.org/c/haiku/+/122 Tested-by: Commit checker robot <[email protected]> Reviewed-by: Jérôme Duval <[email protected]>
This commit is contained in:
committed by
Adrien Destugues
parent
0200659132
commit
ccf8b1e96f
@@ -140,6 +140,8 @@
|
||||
/*!
|
||||
\fn const char* BTab::Label() const
|
||||
\brief Returns the tab's label (the target view's name).
|
||||
\warning In BeOS, the tab label is determined from the view name. In Haiku, they can be
|
||||
different if SetLabel() was used.
|
||||
|
||||
\since BeOS R3
|
||||
*/
|
||||
@@ -147,7 +149,9 @@
|
||||
|
||||
/*!
|
||||
\fn void BTab::SetLabel(const char* label)
|
||||
\brief Sets the target view's name, and updates the BTab accordingly.
|
||||
\brief Sets the tab label.
|
||||
\warning In BeOS, setting the tab label also renamed the view attached to the tab. In Haiku,
|
||||
this is not the case anymore, the label and view name are independant.
|
||||
|
||||
\since BeOS R3
|
||||
*/
|
||||
@@ -220,6 +224,9 @@
|
||||
/*!
|
||||
\fn void BTab::SetView(BView* view)
|
||||
\brief Sets the view to be displayed for this tab.
|
||||
|
||||
This also resets the tab label to match the view name (to preserve BeOS behavior).
|
||||
If you need to use a different label, SetLabel must be called after SetView.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
@@ -82,8 +82,13 @@ private:
|
||||
bool fFocus;
|
||||
BView* fView;
|
||||
BTabView* fTabView;
|
||||
BString fLabel;
|
||||
|
||||
uint32 _reserved[11];
|
||||
#ifdef B_HAIKU_64_BIT
|
||||
uint32 _reserved[9];
|
||||
#else
|
||||
uint32 _reserved[10];
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
#include <Window.h>
|
||||
|
||||
#include <binary_compatibility/Support.h>
|
||||
#include <private/libroot/libroot_private.h>
|
||||
|
||||
|
||||
static property_info sPropertyList[] = {
|
||||
@@ -47,14 +48,26 @@ static property_info sPropertyList[] = {
|
||||
};
|
||||
|
||||
|
||||
static bool
|
||||
IsLayouted(BView* childView)
|
||||
{
|
||||
BView* container = childView->Parent();
|
||||
if (container != NULL)
|
||||
return dynamic_cast<BCardLayout*>(container->GetLayout()) != NULL;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
BTab::BTab(BView* contentsView)
|
||||
:
|
||||
fEnabled(true),
|
||||
fSelected(false),
|
||||
fFocus(false),
|
||||
fView(contentsView),
|
||||
fTabView(NULL)
|
||||
fView(contentsView)
|
||||
{
|
||||
fTabView = NULL;
|
||||
if (fView != NULL)
|
||||
fLabel = fView->Name();
|
||||
}
|
||||
|
||||
|
||||
@@ -63,9 +76,10 @@ BTab::BTab(BMessage* archive)
|
||||
BArchivable(archive),
|
||||
fSelected(false),
|
||||
fFocus(false),
|
||||
fView(NULL),
|
||||
fTabView(NULL)
|
||||
fView(NULL)
|
||||
{
|
||||
fTabView = NULL;
|
||||
|
||||
bool disable;
|
||||
|
||||
if (archive->FindBool("_disable", &disable) != B_OK)
|
||||
@@ -121,10 +135,17 @@ BTab::Perform(uint32 d, void* arg)
|
||||
const char*
|
||||
BTab::Label() const
|
||||
{
|
||||
#ifdef __HAIKU_BEOS_COMPATIBLE
|
||||
if (__gABIVersion >= B_HAIKU_ABI_GCC_2_HAIKU)
|
||||
return fLabel;
|
||||
|
||||
if (fView != NULL)
|
||||
return fView->Name();
|
||||
else
|
||||
return NULL;
|
||||
|
||||
return NULL;
|
||||
#else
|
||||
return fLabel;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +155,11 @@ BTab::SetLabel(const char* label)
|
||||
if (label == NULL || fView == NULL)
|
||||
return;
|
||||
|
||||
fView->SetName(label);
|
||||
#ifdef __HAIKU_BEOS_COMPATIBLE
|
||||
if (__gABIVersion < B_HAIKU_ABI_GCC_2_HAIKU)
|
||||
fView->SetName(label);
|
||||
#endif
|
||||
fLabel = label;
|
||||
|
||||
if (fTabView != NULL)
|
||||
fTabView->Invalidate();
|
||||
@@ -169,12 +194,7 @@ BTab::Deselect()
|
||||
if (fView != NULL) {
|
||||
// NOTE: Views are not added/removed, if there is layout,
|
||||
// they are made visible/invisible in that case.
|
||||
bool removeView = false;
|
||||
BView* container = fView->Parent();
|
||||
if (container != NULL)
|
||||
removeView =
|
||||
dynamic_cast<BCardLayout*>(container->GetLayout()) == NULL;
|
||||
if (removeView)
|
||||
if (!IsLayouted(fView))
|
||||
fView->RemoveSelf();
|
||||
}
|
||||
|
||||
@@ -221,6 +241,7 @@ BTab::SetView(BView* view)
|
||||
delete fView;
|
||||
}
|
||||
fView = view;
|
||||
fLabel = fView->Name();
|
||||
|
||||
if (fTabView != NULL && fSelected) {
|
||||
Select(fTabView->ContainerView());
|
||||
|
||||
Reference in New Issue
Block a user