TabView: Assume be_control_look is not NULL.

This commit is contained in:
Augustin Cavalier
2015-07-14 11:25:46 -04:00
parent 6fd2553690
commit fe47b32f75
+73 -141
View File
@@ -787,11 +787,8 @@ BTabView::FocusTab() const
void void
BTabView::Draw(BRect updateRect) BTabView::Draw(BRect updateRect)
{ {
if (be_control_look != NULL) { DrawBox(TabFrame(fSelection));
DrawBox(TabFrame(fSelection)); DrawTabs();
DrawTabs();
} else
DrawBox(DrawTabs());
if (IsFocus() && fFocus != -1) if (IsFocus() && fFocus != -1)
TabAt(fFocus)->DrawFocusMark(this, TabFrame(fFocus)); TabAt(fFocus)->DrawFocusMark(this, TabFrame(fFocus));
@@ -811,35 +808,33 @@ BTabView::DrawTabs()
left = tabFrame.right; left = tabFrame.right;
} }
if (be_control_look != NULL) { BRect frame(Bounds());
BRect frame(Bounds()); if (fBorderStyle == B_PLAIN_BORDER)
if (fBorderStyle == B_PLAIN_BORDER) frame.right += 1;
frame.right += 1; else if (fBorderStyle == B_NO_BORDER)
else if (fBorderStyle == B_NO_BORDER) frame.right += 2;
frame.right += 2; if (left < frame.right) {
if (left < frame.right) { frame.left = left;
frame.left = left; frame.bottom = fTabHeight;
frame.bottom = fTabHeight; rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); uint32 borders = BControlLook::B_TOP_BORDER
uint32 borders = BControlLook::B_TOP_BORDER | BControlLook::B_BOTTOM_BORDER | BControlLook::B_RIGHT_BORDER;
| BControlLook::B_BOTTOM_BORDER | BControlLook::B_RIGHT_BORDER; if (left == 0)
if (left == 0) borders |= BControlLook::B_LEFT_BORDER;
borders |= BControlLook::B_LEFT_BORDER; be_control_look->DrawInactiveTab(this, frame, frame, base, 0,
be_control_look->DrawInactiveTab(this, frame, frame, base, 0, borders);
borders); }
} if (fBorderStyle == B_NO_BORDER) {
if (fBorderStyle == B_NO_BORDER) { // Draw a small inactive area before first tab.
// Draw a small inactive area before first tab. frame = Bounds();
frame = Bounds(); frame.right = 0.0f;
frame.right = 0.0f; // one pixel wide
// one pixel wide frame.bottom = fTabHeight;
frame.bottom = fTabHeight; rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); uint32 borders = BControlLook::B_TOP_BORDER
uint32 borders = BControlLook::B_TOP_BORDER | BControlLook::B_BOTTOM_BORDER;
| BControlLook::B_BOTTOM_BORDER; be_control_look->DrawInactiveTab(this, frame, frame, base, 0,
be_control_look->DrawInactiveTab(this, frame, frame, base, 0, borders);
borders);
}
} }
if (fSelection < CountTabs()) if (fSelection < CountTabs())
@@ -852,79 +847,21 @@ BTabView::DrawTabs()
void void
BTabView::DrawBox(BRect selTabRect) BTabView::DrawBox(BRect selTabRect)
{ {
if (be_control_look != NULL) { BRect rect(Bounds());
BRect rect(Bounds()); rect.top = selTabRect.bottom;
rect.top = selTabRect.bottom; if (fBorderStyle != B_FANCY_BORDER)
if (fBorderStyle != B_FANCY_BORDER) rect.top += 1.0f;
rect.top += 1.0f;
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR); rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
if (fBorderStyle == B_FANCY_BORDER)
be_control_look->DrawGroupFrame(this, rect, rect, base); if (fBorderStyle == B_FANCY_BORDER)
else { be_control_look->DrawGroupFrame(this, rect, rect, base);
uint32 borders = BControlLook::B_TOP_BORDER; else {
if (fBorderStyle == B_PLAIN_BORDER) uint32 borders = BControlLook::B_TOP_BORDER;
borders = BControlLook::B_ALL_BORDERS; if (fBorderStyle == B_PLAIN_BORDER)
be_control_look->DrawBorder(this, rect, rect, base, B_PLAIN_BORDER, borders = BControlLook::B_ALL_BORDERS;
0, 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();
} }
@@ -934,42 +871,40 @@ BTabView::TabFrame(int32 index) const
if (index >= CountTabs() || index < 0) if (index >= CountTabs() || index < 0)
return BRect(); return BRect();
if (be_control_look != NULL) { float width = 100.0f;
float width = 100.0f; float height = fTabHeight;
float height = fTabHeight; float borderOffset = 0.0f;
float borderOffset = 0.0f; // Do not use 2.0f for B_NO_BORDER, that will look yet different
// Do not use 2.0f for B_NO_BORDER, that will look yet different // again (handled in DrawTabs()).
// again (handled in DrawTabs()). if (fBorderStyle == B_PLAIN_BORDER)
if (fBorderStyle == B_PLAIN_BORDER) borderOffset = 1.0f;
borderOffset = 1.0f; switch (fTabWidthSetting) {
switch (fTabWidthSetting) { case B_WIDTH_FROM_LABEL:
case B_WIDTH_FROM_LABEL: {
{ float x = 0.0f;
float x = 0.0f; for (int32 i = 0; i < index; i++){
for (int32 i = 0; i < index; i++){ x += StringWidth(TabAt(i)->Label()) + 20.0f;
x += StringWidth(TabAt(i)->Label()) + 20.0f;
}
return BRect(x - borderOffset, 0.0f,
x + StringWidth(TabAt(index)->Label()) + 20.0f
- borderOffset,
height);
} }
case B_WIDTH_FROM_WIDEST: return BRect(x - borderOffset, 0.0f,
width = 0.0; x + StringWidth(TabAt(index)->Label()) + 20.0f
for (int32 i = 0; i < CountTabs(); i++) { - borderOffset,
float tabWidth = StringWidth(TabAt(i)->Label()) + 20.0f; height);
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);
} }
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 ... // TODO: fix to remove "offset" in DrawTab and DrawLabel ...
@@ -1281,9 +1216,6 @@ BTabView::ViewForTab(int32 tabIndex) const
void void
BTabView::_InitObject(bool layouted, button_width width) BTabView::_InitObject(bool layouted, button_width width)
{ {
if (be_control_look == NULL)
SetFont(be_bold_font);
fTabList = new BList; fTabList = new BList;
fTabWidthSetting = width; fTabWidthSetting = width;