[haiku-commits] haiku: hrev49405 - src/kits/interface headers/private/interface docs/user/interface

  • From: waddlesplash@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Tue, 14 Jul 2015 17:32:08 +0200 (CEST)

hrev49405 adds 4 changesets to branch 'master'
old head: ce7470f8bf2b8d7680f66a0dba482226d18b2d97
new head: 8868ca02edb85145772dfceff2f9504d67b05f70
overview:
http://cgit.haiku-os.org/haiku/log/?qt=range&q=8868ca02edb8+%5Ece7470f8bf2b

----------------------------------------------------------------------------

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

Thanks to Axel and Stephan for reviewing!

6fd2553690c7: TabView: Lots of style fixes.

fe47b32f75e4: TabView: Assume be_control_look is not NULL.

8868ca02edb8: docs/user: TabView: Fix erroneous descriptions of Select() and
Deselect().

[ Augustin Cavalier <waddlesplash@xxxxxxxxx> ]

----------------------------------------------------------------------------

4 files changed, 140 insertions(+), 173 deletions(-)
docs/user/interface/TabView.dox | 11 +-
headers/os/interface/TabView.h | 8 +-
headers/private/interface/TabViewPrivate.h | 31 +++
src/kits/interface/TabView.cpp | 263 +++++++++----------------

############################################################################

Commit: c432a83bf3855f2a291d97b269bdcdee606149f5
URL: http://cgit.haiku-os.org/haiku/commit/?id=c432a83bf385
Author: Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date: Tue Jul 14 15:04:39 2015 UTC

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

Thanks to Axel and Stephan for reviewing!

----------------------------------------------------------------------------

diff --git a/headers/os/interface/TabView.h b/headers/os/interface/TabView.h
index 90f193b..9a8830a 100644
--- a/headers/os/interface/TabView.h
+++ b/headers/os/interface/TabView.h
@@ -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;
diff --git a/headers/private/interface/TabViewPrivate.h
b/headers/private/interface/TabViewPrivate.h
new file mode 100644
index 0000000..8b6c9c4
--- /dev/null
+++ b/headers/private/interface/TabViewPrivate.h
@@ -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 */
diff --git a/src/kits/interface/TabView.cpp b/src/kits/interface/TabView.cpp
index 1c09b96..1dbc59f 100644
--- a/src/kits/interface/TabView.cpp
+++ b/src/kits/interface/TabView.cpp
@@ -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);

############################################################################

Commit: 6fd2553690c71824d7a6d80e2c6228c804eda3e8
URL: http://cgit.haiku-os.org/haiku/commit/?id=6fd2553690c7
Author: Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date: Tue Jul 14 15:15:36 2015 UTC

TabView: Lots of style fixes.

----------------------------------------------------------------------------

diff --git a/headers/os/interface/TabView.h b/headers/os/interface/TabView.h
index 9a8830a..845893a 100644
--- a/headers/os/interface/TabView.h
+++ b/headers/os/interface/TabView.h
@@ -21,7 +21,7 @@ enum tab_position {

class BTab : public BArchivable {
public:
- BTab(BView*
tabView = NULL);
+ BTab(BView*
contentsView = NULL);
virtual ~BTab();

BTab(BMessage*
archive);
diff --git a/src/kits/interface/TabView.cpp b/src/kits/interface/TabView.cpp
index 1dbc59f..60d5d1b 100644
--- a/src/kits/interface/TabView.cpp
+++ b/src/kits/interface/TabView.cpp
@@ -48,12 +48,12 @@ static property_info sPropertyList[] = {



-BTab::BTab(BView* tabView)
+BTab::BTab(BView* contentsView)
:
fEnabled(true),
fSelected(false),
fFocus(false),
- fView(tabView),
+ fView(contentsView),
fTabView(NULL)
{
}
@@ -78,7 +78,7 @@ BTab::BTab(BMessage* archive)

BTab::~BTab()
{
- if (!fView)
+ if (fView == NULL)
return;

if (fSelected)
@@ -122,7 +122,7 @@ BTab::Perform(uint32 d, void* arg)
const char*
BTab::Label() const
{
- if (fView)
+ if (fView != NULL)
return fView->Name();
else
return NULL;
@@ -132,7 +132,7 @@ BTab::Label() const
void
BTab::SetLabel(const char* label)
{
- if (!label || !fView)
+ if (label == NULL || fView == NULL)
return;

fView->SetName(label);
@@ -154,12 +154,12 @@ BTab::Select(BView* owner)
{
fSelected = true;

- if (!owner || !View())
+ if (owner == NULL || fView == NULL)
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() == NULL && fView->Parent() == NULL)
owner->AddChild(fView);
}

@@ -167,16 +167,16 @@ BTab::Select(BView* owner)
void
BTab::Deselect()
{
- if (View()) {
+ 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 = View()->Parent();
- if (container)
+ BView* container = fView->Parent();
+ if (container != NULL)
removeView =

dynamic_cast<BCardLayout*>(container->GetLayout()) == NULL;
if (removeView)
- View()->RemoveSelf();
+ fView->RemoveSelf();
}

fSelected = false;
@@ -214,7 +214,7 @@ BTab::IsFocus() const
void
BTab::SetView(BView* view)
{
- if (!view || fView == view)
+ if (view == NULL || fView == view)
return;

if (fView != NULL) {
@@ -692,16 +692,16 @@ BTabView::Select(int32 index)
tab->Deselect();

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

// make the view visible through the layout if there is one
BCardLayout* layout
=
dynamic_cast<BCardLayout*>(fContainerView->GetLayout());
- if (layout)
+ if (layout != NULL)
layout->SetVisibleItem(index);
}

@@ -1080,7 +1080,7 @@ BSize
BTabView::PreferredSize()
{
BSize size;
- if (GetLayout())
+ if (GetLayout() != NULL)
size = GetLayout()->PreferredSize();
else {
size = _TabsMinSize();
@@ -1271,7 +1271,7 @@ BView*
BTabView::ViewForTab(int32 tabIndex) const
{
BTab* tab = TabAt(tabIndex);
- if (tab)
+ if (tab != NULL)
return tab->View();

return NULL;
@@ -1281,7 +1281,7 @@ BTabView::ViewForTab(int32 tabIndex) const
void
BTabView::_InitObject(bool layouted, button_width width)
{
- if (!be_control_look)
+ if (be_control_look == NULL)
SetFont(be_bold_font);

fTabList = new BList;
@@ -1312,17 +1312,17 @@ BTabView::_InitContainerView(bool layouted)
bool needsLayout = false;
bool createdContainer = false;
if (layouted) {
- if (!GetLayout()) {
+ if (GetLayout() == NULL) {
SetLayout(new(nothrow) BGroupLayout(B_HORIZONTAL));
needsLayout = true;
}

- if (!fContainerView) {
+ if (fContainerView == NULL) {
fContainerView = new BView("view container",
B_WILL_DRAW);
fContainerView->SetLayout(new(std::nothrow)
BCardLayout());
createdContainer = true;
}
- } else if (!fContainerView) {
+ } else if (fContainerView == NULL) {
fContainerView = new BView(Bounds(), "view container",
B_FOLLOW_ALL,
B_WILL_DRAW);
createdContainer = true;
@@ -1392,7 +1392,7 @@ BTabView::_LayoutContainerView(bool layouted)
break;
}
BGroupLayout* layout = dynamic_cast<BGroupLayout*>(GetLayout());
- if (layout) {
+ if (layout != NULL) {
layout->SetInsets(borderWidth, borderWidth + TabHeight()
- topBorderOffset, borderWidth, borderWidth);
}

############################################################################

Commit: fe47b32f75e4f5acf80dd4693877cc8ed9a23fbc
URL: http://cgit.haiku-os.org/haiku/commit/?id=fe47b32f75e4
Author: Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date: Tue Jul 14 15:25:46 2015 UTC

TabView: Assume be_control_look is not NULL.

----------------------------------------------------------------------------

diff --git a/src/kits/interface/TabView.cpp b/src/kits/interface/TabView.cpp
index 60d5d1b..28c93c6 100644
--- a/src/kits/interface/TabView.cpp
+++ b/src/kits/interface/TabView.cpp
@@ -787,11 +787,8 @@ BTabView::FocusTab() const
void
BTabView::Draw(BRect updateRect)
{
- if (be_control_look != NULL) {
- DrawBox(TabFrame(fSelection));
- DrawTabs();
- } else
- DrawBox(DrawTabs());
+ DrawBox(TabFrame(fSelection));
+ DrawTabs();

if (IsFocus() && fFocus != -1)
TabAt(fFocus)->DrawFocusMark(this, TabFrame(fFocus));
@@ -811,35 +808,33 @@ BTabView::DrawTabs()
left = tabFrame.right;
}

- if (be_control_look != NULL) {
- BRect frame(Bounds());
- if (fBorderStyle == B_PLAIN_BORDER)
- frame.right += 1;
- else if (fBorderStyle == B_NO_BORDER)
- frame.right += 2;
- if (left < frame.right) {
- frame.left = left;
- frame.bottom = fTabHeight;
- rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
- uint32 borders = BControlLook::B_TOP_BORDER
- | BControlLook::B_BOTTOM_BORDER |
BControlLook::B_RIGHT_BORDER;
- if (left == 0)
- borders |= BControlLook::B_LEFT_BORDER;
- be_control_look->DrawInactiveTab(this, frame, frame,
base, 0,
- borders);
- }
- if (fBorderStyle == B_NO_BORDER) {
- // Draw a small inactive area before first tab.
- frame = Bounds();
- frame.right = 0.0f;
- // one pixel wide
- frame.bottom = fTabHeight;
- rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
- uint32 borders = BControlLook::B_TOP_BORDER
- | BControlLook::B_BOTTOM_BORDER;
- be_control_look->DrawInactiveTab(this, frame, frame,
base, 0,
- borders);
- }
+ BRect frame(Bounds());
+ if (fBorderStyle == B_PLAIN_BORDER)
+ frame.right += 1;
+ else if (fBorderStyle == B_NO_BORDER)
+ frame.right += 2;
+ if (left < frame.right) {
+ frame.left = left;
+ frame.bottom = fTabHeight;
+ rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
+ uint32 borders = BControlLook::B_TOP_BORDER
+ | BControlLook::B_BOTTOM_BORDER |
BControlLook::B_RIGHT_BORDER;
+ if (left == 0)
+ borders |= BControlLook::B_LEFT_BORDER;
+ be_control_look->DrawInactiveTab(this, frame, frame, base, 0,
+ borders);
+ }
+ if (fBorderStyle == B_NO_BORDER) {
+ // Draw a small inactive area before first tab.
+ frame = Bounds();
+ frame.right = 0.0f;
+ // one pixel wide
+ frame.bottom = fTabHeight;
+ rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
+ uint32 borders = BControlLook::B_TOP_BORDER
+ | BControlLook::B_BOTTOM_BORDER;
+ be_control_look->DrawInactiveTab(this, frame, frame, base, 0,
+ borders);
}

if (fSelection < CountTabs())
@@ -852,79 +847,21 @@ BTabView::DrawTabs()
void
BTabView::DrawBox(BRect selTabRect)
{
- if (be_control_look != NULL) {
- BRect rect(Bounds());
- rect.top = selTabRect.bottom;
- if (fBorderStyle != B_FANCY_BORDER)
- rect.top += 1.0f;
-
+ BRect rect(Bounds());
+ rect.top = selTabRect.bottom;
+ if (fBorderStyle != B_FANCY_BORDER)
+ rect.top += 1.0f;
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
- if (fBorderStyle == B_FANCY_BORDER)
- be_control_look->DrawGroupFrame(this, rect, rect, base);
- else {
- uint32 borders = BControlLook::B_TOP_BORDER;
- if (fBorderStyle == B_PLAIN_BORDER)
- borders = BControlLook::B_ALL_BORDERS;
- be_control_look->DrawBorder(this, rect, rect, base,
B_PLAIN_BORDER,
- 0, borders);
- }
- return;
- }

- BRect rect = Bounds();
- BRect lastTabRect = TabFrame(CountTabs() - 1);
-
- rgb_color noTint = ui_color(B_PANEL_BACKGROUND_COLOR);
- rgb_color lightenMax = tint_color(noTint, B_LIGHTEN_MAX_TINT);
- rgb_color darken1 = tint_color(noTint, B_DARKEN_1_TINT);
- rgb_color darken2 = tint_color(noTint, B_DARKEN_2_TINT);
- rgb_color darken4 = tint_color(noTint, B_DARKEN_4_TINT);
-
- BeginLineArray(12);
-
- int32 offset = (int32)ceilf(selTabRect.Height() / 2.0);
-
- // outer lines
- AddLine(BPoint(rect.left, rect.bottom - 1),
- BPoint(rect.left, selTabRect.bottom), darken2);
- if (selTabRect.left >= rect.left + 1)
- AddLine(BPoint(rect.left + 1, selTabRect.bottom),
- BPoint(selTabRect.left, selTabRect.bottom),
darken2);
- if (lastTabRect.right + offset + 1 <= rect.right - 1)
- AddLine(BPoint(lastTabRect.right + offset + 1,
selTabRect.bottom),
- BPoint(rect.right - 1, selTabRect.bottom),
darken2);
- AddLine(BPoint(rect.right, selTabRect.bottom + 2),
- BPoint(rect.right, rect.bottom), darken2);
- AddLine(BPoint(rect.right - 1, rect.bottom),
- BPoint(rect.left + 2, rect.bottom), darken2);
-
- // inner lines
- rect.InsetBy(1, 1);
- selTabRect.bottom += 1;
-
- AddLine(BPoint(rect.left, rect.bottom - 2),
- BPoint(rect.left, selTabRect.bottom), lightenMax);
- if (selTabRect.left >= rect.left + 1)
- AddLine(BPoint(rect.left + 1, selTabRect.bottom),
- BPoint(selTabRect.left, selTabRect.bottom),
lightenMax);
- if (selTabRect.right + offset + 1 <= rect.right - 2)
- AddLine(BPoint(selTabRect.right + offset + 1,
selTabRect.bottom),
- BPoint(rect.right - 2, selTabRect.bottom),
lightenMax);
- AddLine(BPoint(rect.right, selTabRect.bottom),
- BPoint(rect.right, rect.bottom), darken4);
- AddLine(BPoint(rect.right - 1, rect.bottom),
- BPoint(rect.left, rect.bottom), darken4);
-
- // soft inner bevel at right/bottom
- rect.right--;
- rect.bottom--;
-
- AddLine(BPoint(rect.right, selTabRect.bottom + 1),
- BPoint(rect.right, rect.bottom), darken1);
- AddLine(BPoint(rect.right - 1, rect.bottom),
- BPoint(rect.left + 1, rect.bottom), darken1);
-
- EndLineArray();
+ if (fBorderStyle == B_FANCY_BORDER)
+ be_control_look->DrawGroupFrame(this, rect, rect, base);
+ else {
+ uint32 borders = BControlLook::B_TOP_BORDER;
+ if (fBorderStyle == B_PLAIN_BORDER)
+ borders = BControlLook::B_ALL_BORDERS;
+ be_control_look->DrawBorder(this, rect, rect, base,
B_PLAIN_BORDER,
+ 0, borders);
+ }
}


@@ -934,42 +871,40 @@ BTabView::TabFrame(int32 index) const
if (index >= CountTabs() || index < 0)
return BRect();

- if (be_control_look != NULL) {
- float width = 100.0f;
- float height = fTabHeight;
- float borderOffset = 0.0f;
- // Do not use 2.0f for B_NO_BORDER, that will look yet different
- // again (handled in DrawTabs()).
- if (fBorderStyle == B_PLAIN_BORDER)
- borderOffset = 1.0f;
- switch (fTabWidthSetting) {
- case B_WIDTH_FROM_LABEL:
- {
- float x = 0.0f;
- for (int32 i = 0; i < index; i++){
- x += StringWidth(TabAt(i)->Label()) +
20.0f;
- }
-
- return BRect(x - borderOffset, 0.0f,
- x + StringWidth(TabAt(index)->Label())
+ 20.0f
- - borderOffset,
- height);
+ float width = 100.0f;
+ float height = fTabHeight;
+ float borderOffset = 0.0f;
+ // Do not use 2.0f for B_NO_BORDER, that will look yet different
+ // again (handled in DrawTabs()).
+ if (fBorderStyle == B_PLAIN_BORDER)
+ borderOffset = 1.0f;
+ switch (fTabWidthSetting) {
+ case B_WIDTH_FROM_LABEL:
+ {
+ float x = 0.0f;
+ for (int32 i = 0; i < index; i++){
+ x += StringWidth(TabAt(i)->Label()) + 20.0f;
}

- case B_WIDTH_FROM_WIDEST:
- width = 0.0;
- for (int32 i = 0; i < CountTabs(); i++) {
- float tabWidth =
StringWidth(TabAt(i)->Label()) + 20.0f;
- if (tabWidth > width)
- width = tabWidth;
- }
- // fall through
-
- case B_WIDTH_AS_USUAL:
- default:
- return BRect(index * width - borderOffset, 0.0f,
- index * width + width - borderOffset,
height);
+ return BRect(x - borderOffset, 0.0f,
+ x + StringWidth(TabAt(index)->Label()) + 20.0f
+ - borderOffset,
+ height);
}
+
+ case B_WIDTH_FROM_WIDEST:
+ width = 0.0;
+ for (int32 i = 0; i < CountTabs(); i++) {
+ float tabWidth = StringWidth(TabAt(i)->Label())
+ 20.0f;
+ if (tabWidth > width)
+ width = tabWidth;
+ }
+ // fall through
+
+ case B_WIDTH_AS_USUAL:
+ default:
+ return BRect(index * width - borderOffset, 0.0f,
+ index * width + width - borderOffset, height);
}

// TODO: fix to remove "offset" in DrawTab and DrawLabel ...
@@ -1281,9 +1216,6 @@ BTabView::ViewForTab(int32 tabIndex) const
void
BTabView::_InitObject(bool layouted, button_width width)
{
- if (be_control_look == NULL)
- SetFont(be_bold_font);
-
fTabList = new BList;

fTabWidthSetting = width;

############################################################################

Revision: hrev49405
Commit: 8868ca02edb85145772dfceff2f9504d67b05f70
URL: http://cgit.haiku-os.org/haiku/commit/?id=8868ca02edb8
Author: Augustin Cavalier <waddlesplash@xxxxxxxxx>
Date: Tue Jul 14 15:26:39 2015 UTC

docs/user: TabView: Fix erroneous descriptions of Select() and Deselect().

----------------------------------------------------------------------------

diff --git a/docs/user/interface/TabView.dox b/docs/user/interface/TabView.dox
index 15b9ce5..e582540 100644
--- a/docs/user/interface/TabView.dox
+++ b/docs/user/interface/TabView.dox
@@ -3,6 +3,7 @@
* Distributed under the terms of the MIT License.
*
* Authors:
+ * Augustin Cavalier <waddlesplash>
* John Scipione, jscipione@xxxxxxxxx
*
* Corresponds to:
@@ -67,10 +68,10 @@


/*!
- \fn BTab::BTab(BView* tabView)
+ \fn BTab::BTab(BView* contentsView)
\brief Initializes a new BTab object as part of a \a tabView.

- The BTab is enabled, but not selected nor the current focus. \a tabView
+ The BTab is enabled, but not selected nor the current focus. \a
contentsView
is set as the tab's target view -- when the tab is selected, its target
view is activated.

@@ -160,9 +161,9 @@

/*!
\fn void BTab::Select(BView* owner)
- \brief Selects the tab.
+ \brief Called by the BTabView when the tab is selected.

- This also adds the tab's target view to the \a owner view.
+ \param owner The view that the tab's view should be owned by.

\since BeOS R3
*/
@@ -170,7 +171,7 @@

/*!
\fn void BTab::Deselect()
- \brief Delects the tab.
+ \brief Called by the BTabView when the tab is de-selected.

\since BeOS R3
*/


Other related posts:

  • » [haiku-commits] haiku: hrev49405 - src/kits/interface headers/private/interface docs/user/interface - waddlesplash