BeControlLook: Fix app integration drawing issues

Update BTab::DrawTab() to pass the current index, the index of the
selected tab, and the index of the first and last tabs into
BControlLook::DrawActiveTab() and BControlLook::DrawInactiveTab().
This allows you to draw tabs differently in your BTab or BControlLook
subclass in many different circumstances.

Modify BControlLook API to add indexes to DrawActiveTab() and
DrawInactiveTab() like so:

void DrawActiveTab(..., int32 index = 0, int32 selected = -1,
	int32 first = 0, int32 last = 0);
void DrawInactiveTab(..., int32 index = 0, int32 selected = -1,
	int32 first = 0, int32 last = 0);

These extra indexes are not used by HaikuControlLook which relies only
on if the tab is active or inactive to draw.

Add IndexOf(BTab* tab) method to BTabView and document it to get the
index of the current tab in BTab::DrawTab(). Also add a warning in the
BTabView::DrawTab() method not to use the position and full parameters
anymore, use BTabView::IndexOf(), BTabView::Selection(), and
BTabView::TabCount() to get the info you need.

Using a dynamic_cast to a BTabView in BeControlLook to determine if the
view is derived from a BTabView didn't work in the case of WebPositive.
Furthermore, WebPositive does custom tab drawing which needed to be
updated for alternative control look. These index parameters passed from
BTab to BeControlLook allow us to draw the tab like BeOS without relying
on a dynamic_cast to BTabView to get the info.

Reproduce the functionality described above for BTab in WebPositive's
custom tabs. Eliminate no longer needed code in favor of using indexes.
Update WebPositive custom tabs to use BControlLook::DrawTabFrame()
instead of BControlLook::DrawInactiveTab() matching the update made in
BTabView.

In BeControlLook::DrawTabFrame() fill rect with base color, WebPositive
doesn't draw any tab background, so it expects this work to be done for
it.

Eliminate hasFrames variable from WebPositive.

Rename TabSelected(index) to UpdateSelection(index) in WebPositive to
better reflect its purpose.

Adjusted HaikuControlLook::DrawInactiveTab() to draw the tab borders more
selectively. Only draw border if left border is set for top and bottom tabs
or top border is set for left and right tabs. Undo no longer needed frame
manipulation border drawing workaround in HaikuControlLook::DrawTabFrame().

Draw scroll bar triangle without using DrawArrowShape().

Unlike in HaikuControlLook, DrawArrowShape() is used to draw arrows in
BOutlineListView and menus distinctly from how it draws arrows in scroll
bars. Draw our distinct arrows in DrawSrollBarButtons() instead.

This fixes overflow of time edit up-down arrows in Clock prefs and the
collapse-expand arrow in Deskbar not being vertically centered.

In DrawBorders() only inset if we actually draw the border.

Fix alignment issues with DrawSliderThumb dots for example in
MediaPlayer volume knobs.

Draw using line arrays calling AddLine instead of StrokeLine in
several places.

DrawMenuBar() extends to draw final pixel which eliminates an extra
lines at the end of menu bars.

Truncate button labels better fixing a few issues for example keymap
keyboard layout button labels. Button insets has been updated a bit
to fix drawing issues with buttons missing a border.

Using a dynamic_cast to a BButton to determine if a view is a button
in BeControlLook didn't work in the case of the keymap label. Look for
B_FLAT, B_HOVER, or B_DEFAULT_BUTTON flag in BeControlLook::DrawLabel()
to draw the label inverted on click. Pass the B_FLAT flag from Keymap
keys when drawing using BControlLook so that the label is inverted.

Change-Id: I07631f4b006bdb9aeca2adc9cbdf2da54dae8e92
Reviewed-on: https://review.haiku-os.org/c/haiku/+/2866
Reviewed-by: Adrien Destugues <pulkomandy@gmail.com>
This commit is contained in:
John Scipione 2020-06-01 17:15:29 -04:00 committed by waddlesplash
parent 186dc96ef6
commit 7c095f4709
14 changed files with 639 additions and 464 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2014 Haiku, Inc. All rights reserved.
* Copyright 2014-2020 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
@ -7,8 +7,8 @@
* John Scipione, jscipione@gmail.com
*
* Corresponds to:
* headers/os/interface/TabView.h hrev45377
* src/kits/interface/TabView.cpp hrev45377
* headers/os/interface/TabView.h hrev54500
* src/kits/interface/TabView.cpp hrev54500
*/
@ -27,33 +27,45 @@
Tab position flags
\since BeOS R3
\deprecated This should not be used anymore.
\sa BTab::DrawTab()
*/
/*!
\var tab_position B_TAB_FIRST
First tab in the tab view.
The first tab in the tab view.
\since BeOS R3
\deprecated This should not be used anymore.
\sa BTab::DrawTab()
*/
/*!
\var tab_position B_TAB_FRONT
Front most tab in the tab view.
The selected tab in the tab view.
\since BeOS R3
\deprecated This should not be used anymore.
\sa BTab::DrawTab()
*/
/*!
\var tab_position B_TAB_ANY
Any tab in the tab view.
Any tab in the tab view that is not the first or selected tab.
\since BeOS R3
\deprecated This should not be used anymore.
\sa BTab::DrawTab()
*/
@ -239,20 +251,27 @@
/*!
\fn void BTab::DrawTab(BView* owner, BRect frame, tab_position position,
bool full)
\brief Draws the tab.
\brief Draws the tab and label according to \a position and \a full.
This method draws the tab's title by calling DrawLabel(), then draws the
tab itself. The \a position of the tab may affect how the tab is rendered
-- for example the frontmost tab may have a different appearance than the
other tabs.
This method draws the tab, then draws the tab's title by calling
DrawLabel(). The \a position of the tab may affect how the tab is
rendered -- for example the first tab may have a differene appearance
than the other tabs. You may override this method to draw tabs
differently in your BTab subclass.
\param owner The view that owns the tab.
\param frame The frame rectangle to draw in.
\param position May affect how the tab is rendered. Choices include:
- \c B_TAB_FIRST
- \c B_TAB_FRONT
- \c B_TAB_ANY
\param full Whether or not to completely draw the tab, no longer used.
- \c B_TAB_FIRST The first tab
- \c B_TAB_FRONT The selected or active tab
- \c B_TAB_ANY Tab that is not first or front
\param full Whether or not to completely draw the tab. All tabs were full
except for the tab before the selected tab on BeOS R5.
\warning The \a position and \a full parameters should no longer be used.
This information can be gathered from BTabView by calling the
BTabView::IndexOf(), BTabView::Selection(), and
BTabView::CountTabs() methods.
\since BeOS R3
*/
@ -484,7 +503,7 @@
/*!
\fn int32 BTabView::Selection() const
\brief Returns the currently selected tab's index.
\brief Returns the index of the selected tab or -1 if not found.
\since BeOS R3
*/
@ -727,3 +746,11 @@
\since Haiku R1
*/
/*!
\fn int32 BTabView::IndexOf(Tab* tab) const
\brief Returns the index of \a tab or -1 if not found.
\since Haiku R1
*/

View File

@ -294,12 +294,16 @@ public:
const BRect& updateRect,
const rgb_color& base, uint32 flags = 0,
uint32 borders = B_ALL_BORDERS,
uint32 side = B_TOP_BORDER) = 0;
uint32 side = B_TOP_BORDER,
int32 index = 0, int32 selected = -1,
int32 first = 0, int32 last = 0) = 0;
virtual void DrawInactiveTab(BView* view, BRect& rect,
const BRect& updateRect,
const rgb_color& base, uint32 flags = 0,
uint32 borders = B_ALL_BORDERS,
uint32 side = B_TOP_BORDER) = 0;
uint32 side = B_TOP_BORDER,
int32 index = 0, int32 selected = -1,
int32 first = 0, int32 last = 0) = 0;
virtual void DrawSplitter(BView* view, BRect& rect,
const BRect& updateRect,

View File

@ -73,6 +73,9 @@ private:
BTab& operator=(const BTab&);
private:
uint32 _Borders(BView* owner, BRect frame);
private:
bool fEnabled;
bool fSelected;
@ -180,6 +183,8 @@ public:
int32 CountTabs() const;
BView* ViewForTab(int32 tabIndex) const;
int32 IndexOf(BTab* tab) const;
private:
// FBC padding and forbidden methods
virtual void _ReservedTabView3();

View File

@ -241,12 +241,16 @@ public:
const BRect& updateRect,
const rgb_color& base, uint32 flags = 0,
uint32 borders = B_ALL_BORDERS,
uint32 side = B_TOP_BORDER);
uint32 side = B_TOP_BORDER,
int32 index = 0, int32 selected = -1,
int32 first = 0, int32 last = 0);
virtual void DrawInactiveTab(BView* view, BRect& rect,
const BRect& updateRect,
const rgb_color& base, uint32 flags = 0,
uint32 borders = B_ALL_BORDERS,
uint32 side = B_TOP_BORDER);
uint32 side = B_TOP_BORDER,
int32 index = 0, int32 selected = -1,
int32 first = 0, int32 last = 0);
virtual void DrawSplitter(BView* view, BRect& rect,
const BRect& updateRect,

View File

@ -466,9 +466,83 @@ BeControlLook::DrawScrollBarButton(BView* view, BRect rect,
rect.InsetBy(1, 1);
view->FillRect(rect);
// draw button triangle
// don't use DrawArrowShape because we use that to draw arrows differently
// in menus and outline list view
rect.InsetBy(1, 1);
rect.OffsetBy(-3, -3);
DrawArrowShape(view, rect, updateRect, base, direction, flags, B_NO_TINT);
BPoint tri1, tri2, tri3;
BPoint off1, off2, off3;
BRect r(rect.left, rect.top, rect.left + 14, rect.top + 14);
rgb_color lightenmax = tint_color(base, B_LIGHTEN_MAX_TINT);
rgb_color light, dark, arrow, arrow2;
switch(direction) {
case B_LEFT_ARROW:
tri1.Set(r.left + 3, floorf((r.top + r.bottom) / 2));
tri2.Set(r.right - 4, r.top + 4);
tri3.Set(r.right - 4, r.bottom - 4);
break;
default:
case B_RIGHT_ARROW:
tri1.Set(r.left + 4, r.bottom - 4);
tri2.Set(r.left + 4, r.top + 4);
tri3.Set(r.right - 3, floorf((r.top + r.bottom) / 2));
break;
case B_UP_ARROW:
tri1.Set(r.left + 4, r.bottom - 4);
tri2.Set(floorf((r.left + r.right) / 2), r.top + 3);
tri3.Set(r.right - 4, r.bottom - 4);
break;
case B_DOWN_ARROW:
tri1.Set(r.left + 4, r.top + 4);
tri2.Set(r.right - 4, r.top + 4);
tri3.Set(floorf((r.left + r.right) / 2), r.bottom - 3);
break;
}
r.InsetBy(1, 1);
float tint = B_NO_TINT;
if (!isEnabled)
tint = (tint + B_NO_TINT + B_NO_TINT) / 3;
view->SetHighColor(tint_color(base, tint));
view->MovePenTo(B_ORIGIN);
view->SetDrawingMode(B_OP_OVER);
view->SetHighColor(tint_color(base, tint));
if (isEnabled) {
arrow2 = light = tint_color(base, B_DARKEN_2_TINT);
dark = tint_color(base, B_DARKEN_3_TINT);
arrow = tint_color(base, B_DARKEN_MAX_TINT);
} else
arrow = arrow2 = light = dark = tint_color(base, B_DARKEN_1_TINT);
// white triangle offset by 1px
off1.Set(tri1.x + 1, tri1.y + 1);
off2.Set(tri2.x + 1, tri2.y + 1);
off3.Set(tri3.x + 1, tri3.y + 1);
// draw white triangle
view->BeginLineArray(3);
view->AddLine(off2, off3, lightenmax);
view->AddLine(off1, off3, lightenmax);
view->AddLine(off1, off2, lightenmax);
view->EndLineArray();
// draw triangle on top
view->BeginLineArray(3);
view->AddLine(tri2, tri3, dark);
view->AddLine(tri1, tri3, dark);
view->AddLine(tri1, tri2, arrow2);
view->EndLineArray();
view->PopState();
}
@ -673,80 +747,61 @@ void
BeControlLook::DrawArrowShape(BView* view, BRect& rect, const BRect& updateRect,
const rgb_color& base, uint32 direction, uint32 flags, float tint)
{
if (!rect.IsValid() || !rect.Intersects(updateRect))
return;
view->PushState();
bool isEnabled = (flags & B_DISABLED) == 0;
BPoint tri1, tri2, tri3;
BPoint off1, off2, off3;
BRect r(rect.left, rect.top, rect.left + 14, rect.top + 14);
rgb_color lightenmax = tint_color(base, B_LIGHTEN_MAX_TINT);
rgb_color light, dark, arrow, arrow2;
rgb_color fill = tint_color(base, 1.074); // 200
rgb_color stroke = tint_color(base, 1.629); // 80
switch(direction) {
case B_LEFT_ARROW:
tri1.Set(r.left + 3, floorf((r.top + r.bottom) / 2));
tri2.Set(r.right - 4, r.top + 4);
tri3.Set(r.right - 4, r.bottom - 4);
view->SetHighColor(fill);
view->FillTriangle(rect.LeftTop() + BPoint(4, 6),
rect.LeftTop() + BPoint(8, 2),
rect.LeftTop() + BPoint(8, 10));
view->SetHighColor(stroke);
view->StrokeTriangle(rect.LeftTop() + BPoint(4, 6),
rect.LeftTop() + BPoint(8, 2),
rect.LeftTop() + BPoint(8, 10));
break;
default:
case B_RIGHT_ARROW:
tri1.Set(r.left + 4, r.bottom - 4);
tri2.Set(r.left + 4, r.top + 4);
tri3.Set(r.right - 3, floorf((r.top + r.bottom) / 2));
view->SetHighColor(fill);
view->FillTriangle(rect.LeftTop() + BPoint(4, 2),
rect.LeftTop() + BPoint(4, 10),
rect.LeftTop() + BPoint(8, 6));
view->SetHighColor(stroke);
view->StrokeTriangle(rect.LeftTop() + BPoint(4, 2),
rect.LeftTop() + BPoint(4, 10),
rect.LeftTop() + BPoint(8, 6));
break;
case B_UP_ARROW:
tri1.Set(r.left + 4, r.bottom - 4);
tri2.Set(floorf((r.left + r.right) / 2), r.top + 3);
tri3.Set(r.right - 4, r.bottom - 4);
view->SetHighColor(fill);
view->FillTriangle(rect.LeftTop() + BPoint(6, 4),
rect.LeftTop() + BPoint(2, 8),
rect.LeftTop() + BPoint(10, 8));
view->SetHighColor(stroke);
view->StrokeTriangle(rect.LeftTop() + BPoint(6, 4),
rect.LeftTop() + BPoint(2, 8),
rect.LeftTop() + BPoint(10, 8));
break;
case B_DOWN_ARROW:
tri1.Set(r.left + 4, r.top + 4);
tri2.Set(r.right - 4, r.top + 4);
tri3.Set(floorf((r.left + r.right) / 2), r.bottom - 3);
view->SetHighColor(fill);
view->FillTriangle(rect.LeftTop() + BPoint(2, 4),
rect.LeftTop() + BPoint(10, 4),
rect.LeftTop() + BPoint(6, 8));
view->SetHighColor(stroke);
view->StrokeTriangle(rect.LeftTop() + BPoint(2, 4),
rect.LeftTop() + BPoint(10, 4),
rect.LeftTop() + BPoint(6, 8));
break;
}
r.InsetBy(1, 1);
if (!isEnabled)
tint = (tint + B_NO_TINT + B_NO_TINT) / 3;
view->SetHighColor(tint_color(base, tint));
view->MovePenTo(B_ORIGIN);
view->SetDrawingMode(B_OP_OVER);
view->SetHighColor(tint_color(base, tint));
if (isEnabled) {
arrow2 = light = tint_color(base, B_DARKEN_2_TINT);
dark = tint_color(base, B_DARKEN_3_TINT);
arrow = tint_color(base, B_DARKEN_MAX_TINT);
} else
arrow = arrow2 = light = dark = tint_color(base, B_DARKEN_1_TINT);
// white triangle offset by 1px
off1.Set(tri1.x + 1, tri1.y + 1);
off2.Set(tri2.x + 1, tri2.y + 1);
off3.Set(tri3.x + 1, tri3.y + 1);
// draw white triangle
view->BeginLineArray(3);
view->AddLine(off2, off3, lightenmax);
view->AddLine(off1, off3, lightenmax);
view->AddLine(off1, off2, lightenmax);
view->EndLineArray();
// draw triangle on top
view->BeginLineArray(3);
view->AddLine(tri2, tri3, dark);
view->AddLine(tri1, tri3, dark);
view->AddLine(tri1, tri2, arrow2);
view->EndLineArray();
view->PopState();
}
@ -768,7 +823,7 @@ BeControlLook::DrawMenuBarBackground(BView* view, BRect& rect,
rgb_color lighten2 = tint_color(base, B_LIGHTEN_2_TINT);
rgb_color darken1 = tint_color(base, B_DARKEN_1_TINT);
view->BeginLineArray(5);
view->BeginLineArray(3);
view->AddLine(rect.LeftTop(), rect.RightTop(), lighten2);
// left bottom pixel is base color
view->AddLine(rect.LeftTop(), rect.LeftBottom() - BPoint(0, 1),
@ -818,7 +873,6 @@ BeControlLook::DrawMenuFieldFrame(BView* view, BRect& rect,
rect.InsetBy(2, 2);
rgb_color darken2 = tint_color(base, B_DARKEN_2_TINT);
rgb_color darken4 = tint_color(base, B_DARKEN_4_TINT);
// draw left and top side and top right corner
view->BeginLineArray(3);
@ -1009,31 +1063,33 @@ BeControlLook::DrawSliderBar(BView* view, BRect rect, const BRect& updateRect,
rgb_color darken2 = tint_color(base, B_DARKEN_2_TINT);
rgb_color darkenmax = tint_color(base, B_DARKEN_MAX_TINT);
view->SetHighColor(darken1);
view->StrokeLine(BPoint(rect.left, rect.top),
BPoint(rect.left + 1, rect.top));
view->StrokeLine(BPoint(rect.left, rect.bottom),
BPoint(rect.left + 1, rect.bottom));
view->StrokeLine(BPoint(rect.right - 1, rect.top),
BPoint(rect.right, rect.top));
view->BeginLineArray(9);
view->SetHighColor(darken2);
view->StrokeLine(BPoint(rect.left + 1, rect.top),
BPoint(rect.right - 1, rect.top));
view->StrokeLine(BPoint(rect.left, rect.bottom - 1),
BPoint(rect.left, rect.top + 1));
view->AddLine(BPoint(rect.left, rect.top),
BPoint(rect.left + 1, rect.top), darken1);
view->AddLine(BPoint(rect.left, rect.bottom),
BPoint(rect.left + 1, rect.bottom), darken1);
view->AddLine(BPoint(rect.right - 1, rect.top),
BPoint(rect.right, rect.top), darken1);
view->SetHighColor(lightenmax);
view->StrokeLine(BPoint(rect.left + 1, rect.bottom),
BPoint(rect.right, rect.bottom));
view->StrokeLine(BPoint(rect.right, rect.top + 1));
view->AddLine(BPoint(rect.left + 1, rect.top),
BPoint(rect.right - 1, rect.top), darken2);
view->AddLine(BPoint(rect.left, rect.bottom - 1),
BPoint(rect.left, rect.top + 1), darken2);
view->AddLine(BPoint(rect.left + 1, rect.bottom),
BPoint(rect.right, rect.bottom), lightenmax);
view->AddLine(BPoint(rect.right, rect.top + 1),
BPoint(rect.right, rect.bottom), lightenmax);
rect.InsetBy(1, 1);
view->SetHighColor(darkenmax);
view->StrokeLine(BPoint(rect.left, rect.bottom),
BPoint(rect.left, rect.top));
view->StrokeLine(BPoint(rect.right, rect.top));
view->AddLine(BPoint(rect.left, rect.top),
BPoint(rect.left, rect.bottom), darkenmax);
view->AddLine(BPoint(rect.left, rect.top),
BPoint(rect.right, rect.top), darkenmax);
view->EndLineArray();
}
@ -1045,20 +1101,21 @@ BeControlLook::DrawSliderThumb(BView* view, BRect& rect, const BRect& updateRect
return;
rgb_color lighten2 = tint_color(base, B_LIGHTEN_2_TINT);
rgb_color darken2 = tint_color(base, B_DARKEN_2_TINT);
rgb_color darken3 = tint_color(base, B_DARKEN_3_TINT);
rgb_color dark = tint_color(base, 1.333); // 144
rgb_color darker = tint_color(base, 1.444); // 120
rgb_color darkenmax = tint_color(base, B_DARKEN_MAX_TINT);
view->BeginLineArray(14);
// outline
view->SetHighColor(darken3);
view->StrokeLine(BPoint(rect.left, rect.bottom - 2),
BPoint(rect.left, rect.top + 1));
view->StrokeLine(BPoint(rect.left + 1, rect.top),
BPoint(rect.right - 2, rect.top));
view->StrokeLine(BPoint(rect.right, rect.top + 2),
BPoint(rect.right, rect.bottom - 1));
view->StrokeLine(BPoint(rect.left + 2, rect.bottom),
BPoint(rect.right - 1, rect.bottom));
view->AddLine(BPoint(rect.left, rect.bottom - 2),
BPoint(rect.left, rect.top + 1), darker);
view->AddLine(BPoint(rect.left + 1, rect.top),
BPoint(rect.right - 2, rect.top), darker);
view->AddLine(BPoint(rect.right, rect.top + 2),
BPoint(rect.right, rect.bottom - 1), darker);
view->AddLine(BPoint(rect.left + 2, rect.bottom),
BPoint(rect.right - 1, rect.bottom), darker);
// first bevel
rect.InsetBy(1, 1);
@ -1066,46 +1123,51 @@ BeControlLook::DrawSliderThumb(BView* view, BRect& rect, const BRect& updateRect
view->SetHighColor(lighten2);
view->FillRect(rect);
view->SetHighColor(darkenmax);
view->StrokeLine(BPoint(rect.left, rect.bottom),
BPoint(rect.right - 1, rect.bottom));
view->StrokeLine(BPoint(rect.right, rect.bottom - 1),
BPoint(rect.right, rect.top));
view->AddLine(BPoint(rect.left, rect.bottom),
BPoint(rect.right - 1, rect.bottom), darkenmax);
view->AddLine(BPoint(rect.right, rect.bottom - 1),
BPoint(rect.right, rect.top), darkenmax);
rect.InsetBy(1, 1);
// second bevel and center dots
view->SetHighColor(darken2);
view->StrokeLine(BPoint(rect.left, rect.bottom),
BPoint(rect.right, rect.bottom));
view->StrokeLine(BPoint(rect.right, rect.top));
view->SetHighColor(dark);
view->AddLine(BPoint(rect.left, rect.bottom),
BPoint(rect.right, rect.bottom), dark);
view->AddLine(BPoint(rect.right, rect.top),
BPoint(rect.right, rect.bottom), dark);
// center dots
float hCenter = rect.Width() / 2;
float vMiddle = rect.Height() / 2;
if (orientation == B_HORIZONTAL) {
view->StrokeLine(BPoint(rect.left + 6, rect.top + 2),
BPoint(rect.left + 6, rect.top + 2));
view->StrokeLine(BPoint(rect.left + 6, rect.top + 4),
BPoint(rect.left + 6, rect.top + 4));
view->StrokeLine(BPoint(rect.left + 6, rect.top + 6),
BPoint(rect.left + 6, rect.top + 6));
view->AddLine(BPoint(rect.left + hCenter, rect.top + 1),
BPoint(rect.left + hCenter, rect.top + 1), dark);
view->AddLine(BPoint(rect.left + hCenter, rect.top + 3),
BPoint(rect.left + hCenter, rect.top + 3), dark);
view->AddLine(BPoint(rect.left + hCenter, rect.top + 5),
BPoint(rect.left + hCenter, rect.top + 5), dark);
} else {
view->StrokeLine(BPoint(rect.left + 2, rect.top + 6),
BPoint(rect.left + 2, rect.top + 6));
view->StrokeLine(BPoint(rect.left + 4, rect.top + 6),
BPoint(rect.left + 4, rect.top + 6));
view->StrokeLine(BPoint(rect.left + 6, rect.top + 6),
BPoint(rect.left + 6, rect.top + 6));
view->AddLine(BPoint(rect.left + 1, rect.top + vMiddle),
BPoint(rect.left + 1, rect.top + vMiddle), dark);
view->AddLine(BPoint(rect.left + 3, rect.top + vMiddle),
BPoint(rect.left + 3, rect.top + vMiddle), dark);
view->AddLine(BPoint(rect.left + 5, rect.top + vMiddle - 1),
BPoint(rect.left + 5, rect.top + vMiddle), dark);
}
view->StrokeLine(BPoint(rect.right + 1, rect.bottom + 1),
BPoint(rect.right + 1, rect.bottom + 1));
view->AddLine(BPoint(rect.right + 1, rect.bottom + 1),
BPoint(rect.right + 1, rect.bottom + 1), dark);
rect.InsetBy(1, 1);
// third bevel
view->SetHighColor(base);
view->StrokeLine(BPoint(rect.left, rect.bottom),
BPoint(rect.right, rect.bottom));
view->StrokeLine(BPoint(rect.right, rect.top));
view->AddLine(BPoint(rect.left, rect.bottom),
BPoint(rect.right, rect.bottom), base);
view->AddLine(BPoint(rect.right, rect.top),
BPoint(rect.right, rect.bottom), base);
view->EndLineArray();
}
@ -1275,6 +1337,9 @@ BeControlLook::DrawTabFrame(BView* view, BRect& rect, const BRect& updateRect,
const rgb_color& base, uint32 flags, uint32 borders,
border_style borderStyle, uint32 side)
{
view->SetHighColor(base);
view->FillRect(rect);
rgb_color lightenmax = tint_color(base, B_LIGHTEN_MAX_TINT);
view->BeginLineArray(1);
@ -1309,7 +1374,7 @@ BeControlLook::DrawTabFrame(BView* view, BRect& rect, const BRect& updateRect,
void
BeControlLook::DrawActiveTab(BView* view, BRect& rect,
const BRect& updateRect, const rgb_color& base, uint32 flags,
uint32 borders, uint32 side)
uint32 borders, uint32 side, int32, int32, int32, int32)
{
if (!rect.IsValid() || !rect.Intersects(updateRect))
return;
@ -1531,11 +1596,15 @@ BeControlLook::DrawActiveTab(BView* view, BRect& rect,
void
BeControlLook::DrawInactiveTab(BView* view, BRect& rect,
const BRect& updateRect, const rgb_color& base, uint32 flags,
uint32 borders, uint32 side)
uint32 borders, uint32 side, int32 index, int32 selected,
int32 first, int32 last)
{
if (!rect.IsValid() || !rect.Intersects(updateRect))
return;
bool isFirst = index == first;
bool isFull = index != selected - 1;
view->PushState();
// set clipping constraints to updateRect plus 2px extra
@ -1551,16 +1620,12 @@ BeControlLook::DrawInactiveTab(BView* view, BRect& rect,
view->SetHighColor(darkenmax);
view->SetLowColor(base);
BTabView* tabView = dynamic_cast<BTabView*>(view);
if (tabView == NULL)
return;
view->BeginLineArray(12);
switch (side) {
case BTabView::kLeftSide:
// only draw if first tab is unselected
if (updateRect == tabView->TabFrame(0)) {
if (isFirst) {
// before going left
view->AddLine(BPoint(rect.right - 1, rect.top - 1),
BPoint(rect.right - 1, rect.top - 1), lightenmax);
@ -1593,7 +1658,7 @@ BeControlLook::DrawInactiveTab(BView* view, BRect& rect,
BPoint(rect.right - 4, rect.bottom - 1), darken4);
// only draw if not before selected tab
if (updateRect != tabView->TabFrame(tabView->Selection() - 1)) {
if (isFull) {
// after going right
view->AddLine(BPoint(rect.right - 3, rect.bottom),
BPoint(rect.right - 2, rect.bottom), darken4);
@ -1604,7 +1669,7 @@ BeControlLook::DrawInactiveTab(BView* view, BRect& rect,
case BTabView::kRightSide:
// only draw if first tab is unselected
if (updateRect == tabView->TabFrame(0)) {
if (isFirst) {
// before going right
view->AddLine(BPoint(rect.left - 1, rect.top - 1),
BPoint(rect.left - 1, rect.top - 1), lightenmax);
@ -1637,7 +1702,7 @@ BeControlLook::DrawInactiveTab(BView* view, BRect& rect,
BPoint(rect.left - 4, rect.bottom - 1), darken4);
// only draw if not before selected tab
if (updateRect != tabView->TabFrame(tabView->Selection() - 1)) {
if (isFull) {
// after going left
view->AddLine(BPoint(rect.left - 3, rect.bottom),
BPoint(rect.left - 2, rect.bottom), darken4);
@ -1649,7 +1714,7 @@ BeControlLook::DrawInactiveTab(BView* view, BRect& rect,
default:
case BTabView::kTopSide:
// only draw if first tab is unselected
if (updateRect == tabView->TabFrame(0)) {
if (isFirst) {
// before going up
view->AddLine(BPoint(rect.left - 1, rect.bottom - 1),
BPoint(rect.left - 1, rect.bottom - 1), lightenmax);
@ -1682,7 +1747,7 @@ BeControlLook::DrawInactiveTab(BView* view, BRect& rect,
BPoint(rect.right - 1, rect.bottom - 4), darken4);
// only draw if not before selected tab
if (updateRect != tabView->TabFrame(tabView->Selection() - 1)) {
if (isFull) {
// after going down
view->AddLine(BPoint(rect.right, rect.bottom - 3),
BPoint(rect.right, rect.bottom - 2), darken4);
@ -1693,7 +1758,7 @@ BeControlLook::DrawInactiveTab(BView* view, BRect& rect,
case BTabView::kBottomSide:
// only draw if first tab is unselected
if (updateRect == tabView->TabFrame(0)) {
if (isFirst) {
// before going down
view->AddLine(BPoint(rect.left - 1, rect.top - 1),
BPoint(rect.left - 1, rect.top - 1), lightenmax);
@ -1726,7 +1791,7 @@ BeControlLook::DrawInactiveTab(BView* view, BRect& rect,
BPoint(rect.right - 1, rect.top - 4), darken4);
// only draw if not before selected tab
if (updateRect != tabView->TabFrame(tabView->Selection() - 1)) {
if (isFull) {
// after going up
view->AddLine(BPoint(rect.right, rect.top - 3),
BPoint(rect.right, rect.top - 2), darken4);
@ -1876,69 +1941,90 @@ BeControlLook::DrawBorder(BView* view, BRect& rect, const BRect& updateRect,
BRegion clipping(updateRect);
view->ConstrainClippingRegion(&clipping);
rgb_color lightColor = tint_color(base, B_LIGHTEN_MAX_TINT);
rgb_color shadowColor = tint_color(base, B_DARKEN_3_TINT);
rgb_color lightColor;
rgb_color shadowColor;
if (base.Brightness() > 128) {
lightColor = tint_color(base, B_DARKEN_2_TINT);
shadowColor = tint_color(base, B_LIGHTEN_2_TINT);
} else {
lightColor = tint_color(base, B_LIGHTEN_MAX_TINT);
shadowColor = tint_color(base, B_DARKEN_3_TINT);
}
view->BeginLineArray(8);
if (borderStyle == B_FANCY_BORDER) {
rect.left++;
rect.top++;
view->BeginLineArray(4);
if ((borders & B_LEFT_BORDER) != 0)
if ((borders & B_LEFT_BORDER) != 0) {
view->AddLine(rect.LeftBottom(), rect.LeftTop(), shadowColor);
if ((borders & B_TOP_BORDER) != 0)
rect.left++;
}
if ((borders & B_TOP_BORDER) != 0) {
view->AddLine(rect.LeftTop(), rect.RightTop(), shadowColor);
if ((borders & B_RIGHT_BORDER) != 0)
rect.top++;
}
if ((borders & B_RIGHT_BORDER) != 0) {
view->AddLine(rect.RightTop(), rect.RightBottom(), shadowColor);
if ((borders & B_BOTTOM_BORDER) != 0)
rect.right--;
}
if ((borders & B_BOTTOM_BORDER) != 0) {
view->AddLine(rect.RightBottom(), rect.LeftBottom(), shadowColor);
view->EndLineArray();
rect.bottom--;
}
rect.OffsetBy(-1, -1);
view->BeginLineArray(4);
if ((borders & B_LEFT_BORDER) != 0)
if ((borders & B_LEFT_BORDER) != 0) {
view->AddLine(rect.LeftBottom(), rect.LeftTop(), lightColor);
if ((borders & B_TOP_BORDER) != 0)
rect.left++;
}
if ((borders & B_TOP_BORDER) != 0) {
view->AddLine(rect.LeftTop(), rect.RightTop(), lightColor);
if ((borders & B_RIGHT_BORDER) != 0)
rect.top++;
}
if ((borders & B_RIGHT_BORDER) != 0) {
view->AddLine(rect.RightTop(), rect.RightBottom(), lightColor);
if ((borders & B_BOTTOM_BORDER) != 0)
rect.right--;
}
if ((borders & B_BOTTOM_BORDER) != 0) {
view->AddLine(rect.RightBottom(), rect.LeftBottom(), lightColor);
view->EndLineArray();
rect.bottom--;
}
} else if (borderStyle == B_PLAIN_BORDER) {
rect.left++;
rect.top++;
view->BeginLineArray(4);
if ((borders & B_LEFT_BORDER) != 0)
if ((borders & B_LEFT_BORDER) != 0) {
view->AddLine(rect.LeftBottom(), rect.LeftTop(), shadowColor);
if ((borders & B_TOP_BORDER) != 0)
rect.left++;
}
if ((borders & B_TOP_BORDER) != 0) {
view->AddLine(rect.LeftTop(), rect.RightTop(), shadowColor);
if ((borders & B_RIGHT_BORDER) != 0)
rect.top++;
}
if ((borders & B_RIGHT_BORDER) != 0) {
view->AddLine(rect.RightTop(), rect.RightBottom(), shadowColor);
if ((borders & B_BOTTOM_BORDER) != 0)
rect.right--;
}
if ((borders & B_BOTTOM_BORDER) != 0) {
view->AddLine(rect.RightBottom(), rect.LeftBottom(), shadowColor);
view->EndLineArray();
rect.bottom--;
}
rect.OffsetBy(-1, -1);
view->BeginLineArray(4);
if ((borders & B_LEFT_BORDER) != 0)
if ((borders & B_LEFT_BORDER) != 0) {
view->AddLine(rect.LeftBottom(), rect.LeftTop(), lightColor);
if ((borders & B_TOP_BORDER) != 0)
rect.left++;
}
if ((borders & B_TOP_BORDER) != 0) {
view->AddLine(rect.LeftTop(), rect.RightTop(), lightColor);
if ((borders & B_RIGHT_BORDER) != 0)
rect.top++;
}
if ((borders & B_RIGHT_BORDER) != 0) {
view->AddLine(rect.RightTop(), rect.RightBottom(), lightColor);
if ((borders & B_BOTTOM_BORDER) != 0)
rect.right--;
}
if ((borders & B_BOTTOM_BORDER) != 0) {
view->AddLine(rect.RightBottom(), rect.LeftBottom(), lightColor);
view->EndLineArray();
rect.bottom--;
}
}
view->EndLineArray();
view->PopState();
}
@ -1967,31 +2053,42 @@ BeControlLook::DrawRaisedBorder(BView* view, BRect& rect,
shadowColor = tint_color(base, 1.07);
}
rect.left++;
rect.top++;
view->BeginLineArray(8);
view->BeginLineArray(4);
if ((borders & B_LEFT_BORDER) != 0)
if ((borders & B_LEFT_BORDER) != 0) {
view->AddLine(rect.LeftBottom(), rect.LeftTop(), lightColor);
if ((borders & B_TOP_BORDER) != 0)
rect.left++;
}
if ((borders & B_TOP_BORDER) != 0) {
view->AddLine(rect.LeftTop(), rect.RightTop(), lightColor);
if ((borders & B_RIGHT_BORDER) != 0)
rect.top++;
}
if ((borders & B_RIGHT_BORDER) != 0) {
view->AddLine(rect.RightTop(), rect.RightBottom(), lightColor);
if ((borders & B_BOTTOM_BORDER) != 0)
rect.right--;
}
if ((borders & B_BOTTOM_BORDER) != 0) {
view->AddLine(rect.RightBottom(), rect.LeftBottom(), lightColor);
view->EndLineArray();
rect.bottom--;
}
rect.OffsetBy(-1, -1);
view->BeginLineArray(4);
if ((borders & B_LEFT_BORDER) != 0)
if ((borders & B_LEFT_BORDER) != 0) {
view->AddLine(rect.LeftBottom(), rect.LeftTop(), shadowColor);
if ((borders & B_TOP_BORDER) != 0)
rect.left++;
}
if ((borders & B_TOP_BORDER) != 0) {
view->AddLine(rect.LeftTop(), rect.RightTop(), shadowColor);
if ((borders & B_RIGHT_BORDER) != 0)
rect.top++;
}
if ((borders & B_RIGHT_BORDER) != 0) {
view->AddLine(rect.RightTop(), rect.RightBottom(), shadowColor);
if ((borders & B_BOTTOM_BORDER) != 0)
rect.right--;
}
if ((borders & B_BOTTOM_BORDER) != 0) {
view->AddLine(rect.RightBottom(), rect.LeftBottom(), shadowColor);
rect.bottom--;
}
view->EndLineArray();
view->PopState();
@ -2029,43 +2126,54 @@ BeControlLook::DrawTextControlBorder(BView* view, BRect& rect,
bevelLight = isEnabled ? lightenmax : lighten1;
view->BeginLineArray(4);
if ((borders & B_LEFT_BORDER) != 0)
if ((borders & B_LEFT_BORDER) != 0) {
view->AddLine(rect.LeftBottom(), rect.LeftTop(), bevelShadow);
if ((borders & B_TOP_BORDER) != 0)
rect.left++;
}
if ((borders & B_TOP_BORDER) != 0) {
view->AddLine(rect.LeftTop(), rect.RightTop(), bevelShadow);
rect.top++;
}
if ((borders & B_RIGHT_BORDER) != 0) {
view->AddLine(BPoint(rect.left + 1, rect.bottom), rect.RightBottom(),
bevelLight);
rect.right--;
}
if ((borders & B_BOTTOM_BORDER) != 0) {
view->AddLine(rect.RightBottom(), BPoint(rect.right, rect.top + 1),
bevelLight);
rect.bottom--;
}
view->EndLineArray();
rect.InsetBy(1, 1);
// second bevel
if (isEnabled && isFocused) {
view->SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
view->StrokeRect(rect);
rect.InsetBy(1, 1);
} else {
bevelShadow = isEnabled ? darken4 : darken2;
bevelLight = base;
view->BeginLineArray(4);
if ((borders & B_LEFT_BORDER) != 0)
if ((borders & B_LEFT_BORDER) != 0) {
view->AddLine(rect.LeftBottom(), rect.LeftTop(), bevelShadow);
if ((borders & B_TOP_BORDER) != 0)
rect.left++;
}
if ((borders & B_TOP_BORDER) != 0) {
view->AddLine(rect.LeftTop(), rect.RightTop(), bevelShadow);
rect.top++;
}
if ((borders & B_RIGHT_BORDER) != 0) {
view->AddLine(BPoint(rect.left + 1, rect.bottom), rect.RightBottom(),
bevelLight);
rect.right--;
}
if ((borders & B_BOTTOM_BORDER) != 0) {
view->AddLine(rect.RightBottom(), BPoint(rect.right, rect.top + 1),
bevelLight);
rect.bottom--;
}
view->EndLineArray();
}
@ -2111,6 +2219,8 @@ BeControlLook::DrawLabel(BView* view, const char* label, const rgb_color& base,
{
view->PushState();
bool isButton = (flags & B_FLAT) != 0 || (flags & B_HOVER) != 0
|| (flags & B_DEFAULT_BUTTON) != 0;
bool isEnabled = (flags & B_DISABLED) == 0;
bool isActivated = (flags & B_ACTIVATED) != 0;
@ -2222,7 +2332,7 @@ BeControlLook::DrawLabel(BView* view, const char* label, const rgb_color& base,
}
rgb_color invertedIfClicked = color;
if (isEnabled && isActivated && dynamic_cast<BButton*>(view) != NULL) {
if (isButton && isEnabled && isActivated) {
// only for enabled and activated buttons
invertedIfClicked.red = 255 - invertedIfClicked.red;
invertedIfClicked.green = 255 - invertedIfClicked.green;
@ -2283,7 +2393,7 @@ BeControlLook::DrawLabel(BView* view, const char* label, const BBitmap* icon,
BFont font;
view->GetFont(&font);
font.TruncateString(&truncatedLabel, B_TRUNCATE_END, availableWidth);
font.TruncateString(&truncatedLabel, B_TRUNCATE_MIDDLE, availableWidth);
width += ceilf(font.StringWidth(truncatedLabel.String()));
font_height fontHeight;
@ -2316,10 +2426,10 @@ BeControlLook::DrawLabel(BView* view, const char* label, const BBitmap* icon,
float y = location.y + ceilf(fontHeight.descent);
view->SetHighColor(ui_color(B_KEYBOARD_NAVIGATION_COLOR));
view->StrokeLine(BPoint(x, y),
BPoint(x + view->StringWidth(label), y));
BPoint(x + view->StringWidth(truncatedLabel.String()), y));
}
DrawLabel(view, label, base, flags, location, textColor);
DrawLabel(view, truncatedLabel.String(), base, flags, location, textColor);
view->PopState();
}
@ -2525,25 +2635,27 @@ BeControlLook::_DrawButtonFrame(BView* view, BRect& rect,
// dark border
view->BeginLineArray(4);
if ((borders & B_LEFT_BORDER) != 0) {
view->AddLine(BPoint(rect.left, rect.bottom - 1),
BPoint(rect.left, rect.top + 1), dark2BorderColor);
view->AddLine(BPoint(rect.left, rect.top + 1),
BPoint(rect.left, rect.bottom - 1), dark2BorderColor);
rect.left++;
}
if ((borders & B_TOP_BORDER) != 0) {
view->AddLine(BPoint(rect.left + 1, rect.top),
view->AddLine(BPoint(rect.left, rect.top),
BPoint(rect.right - 1, rect.top), dark2BorderColor);
rect.top++;
}
if ((borders & B_RIGHT_BORDER) != 0) {
view->AddLine(BPoint(rect.right, rect.top + 1),
view->AddLine(BPoint(rect.right, rect.top),
BPoint(rect.right, rect.bottom - 1), dark2BorderColor);
rect.right--;
}
if ((borders & B_BOTTOM_BORDER) != 0) {
view->AddLine(BPoint(rect.left + 1, rect.bottom),
BPoint(rect.right - 1, rect.bottom), dark2BorderColor);
view->AddLine(BPoint(rect.left, rect.bottom),
BPoint(rect.right, rect.bottom), dark2BorderColor);
rect.bottom--;
}
view->EndLineArray();
rect.InsetBy(1, 1);
// bevel
view->SetHighColor(darken1);
view->StrokeRect(rect);
@ -2559,25 +2671,27 @@ BeControlLook::_DrawButtonFrame(BView* view, BRect& rect,
// dark border
view->BeginLineArray(4);
if ((borders & B_LEFT_BORDER) != 0) {
view->AddLine(BPoint(rect.left, rect.bottom - 1),
BPoint(rect.left, rect.top + 1), darken1);
view->AddLine(BPoint(rect.left, rect.top + 1),
BPoint(rect.left, rect.bottom - 1), darken1);
rect.left++;
}
if ((borders & B_TOP_BORDER) != 0) {
view->AddLine(BPoint(rect.left + 1, rect.top),
view->AddLine(BPoint(rect.left, rect.top),
BPoint(rect.right - 1, rect.top), darken1);
rect.top++;
}
if ((borders & B_RIGHT_BORDER) != 0) {
view->AddLine(BPoint(rect.right, rect.top + 1),
view->AddLine(BPoint(rect.right, rect.top),
BPoint(rect.right, rect.bottom - 1), darken1);
rect.right--;
}
if ((borders & B_BOTTOM_BORDER) != 0) {
view->AddLine(BPoint(rect.left + 1, rect.bottom),
BPoint(rect.right - 1, rect.bottom), darken1);
view->AddLine(BPoint(rect.left, rect.bottom),
BPoint(rect.right, rect.bottom), darken1);
rect.bottom--;
}
view->EndLineArray();
rect.InsetBy(1, 1);
// fill
view->SetHighColor(lighten1);
view->FillRect(rect);
@ -2585,10 +2699,8 @@ BeControlLook::_DrawButtonFrame(BView* view, BRect& rect,
rect.InsetBy(3, 3);
}
} else {
// if not default button, add a 1px base color border
view->SetHighColor(ui_color(B_PANEL_BACKGROUND_COLOR));
view->StrokeRect(rect);
rect.InsetBy(1, 1);
// if not default button, inset top and bottom by 1px
rect.InsetBy(1, 0);
}
// stroke frame to draw four corners, then write on top

View File

@ -222,12 +222,16 @@ public:
const BRect& updateRect,
const rgb_color& base, uint32 flags = 0,
uint32 borders = B_ALL_BORDERS,
uint32 side = B_TOP_BORDER);
uint32 side = B_TOP_BORDER,
int32 index = 0, int32 selected = -1,
int32 first = 0, int32 last = 0);
virtual void DrawInactiveTab(BView* view, BRect& rect,
const BRect& updateRect,
const rgb_color& base, uint32 flags = 0,
uint32 borders = B_ALL_BORDERS,
uint32 side = B_TOP_BORDER);
uint32 side = B_TOP_BORDER,
int32 index = 0, int32 selected = -1,
int32 first = 0, int32 last = 0);
virtual void DrawSplitter(BView* view, BRect& rect,
const BRect& updateRect,

View File

@ -75,44 +75,48 @@ TabContainerView::MessageReceived(BMessage* message)
void
TabContainerView::Draw(BRect updateRect)
{
// draw tab frame
BRect rect(Bounds());
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
BRect frame(Bounds());
uint32 borders = BControlLook::B_TOP_BORDER
| BControlLook::B_BOTTOM_BORDER;
be_control_look->DrawTabFrame(this, rect, updateRect, base, 0,
borders, B_NO_BORDER);
// Draw empty area before first tab.
uint32 borders = BControlLook::B_TOP_BORDER | BControlLook::B_BOTTOM_BORDER;
BRect leftFrame(frame.left, frame.top, kLeftTabInset, frame.bottom);
be_control_look->DrawInactiveTab(this, leftFrame, updateRect, base, 0,
borders);
// Draw all tabs, keeping track of where they end.
// draw tabs on top of frame
BGroupLayout* layout = GroupLayout();
int32 count = layout->CountItems() - 1;
for (int32 i = 0; i < count; i++) {
TabLayoutItem* item = dynamic_cast<TabLayoutItem*>(
layout->ItemAt(i));
if (!item || !item->IsVisible())
TabLayoutItem* item = dynamic_cast<TabLayoutItem*>(layout->ItemAt(i));
if (item == NULL || !item->IsVisible())
continue;
item->Parent()->Draw(updateRect);
frame.left = item->Frame().right + 1;
item->Parent()->Draw(item->Frame());
}
// Draw empty area after last tab.
be_control_look->DrawInactiveTab(this, frame, updateRect, base, 0, borders);
}
void
TabContainerView::MouseDown(BPoint where)
{
if (Window() == NULL)
return;
BMessage* currentMessage = Window()->CurrentMessage();
if (currentMessage == NULL)
return;
uint32 buttons;
if (Window()->CurrentMessage()->FindInt32("buttons", (int32*)&buttons) != B_OK)
if (currentMessage->FindInt32("buttons", (int32*)&buttons) != B_OK)
buttons = B_PRIMARY_MOUSE_BUTTON;
uint32 clicks;
if (Window()->CurrentMessage()->FindInt32("clicks", (int32*)&clicks) != B_OK)
if (currentMessage->FindInt32("clicks", (int32*)&clicks) != B_OK)
clicks = 1;
fMouseDown = true;
SetMouseEventMask(B_POINTER_EVENTS, B_LOCK_WINDOW_FOCUS);
if (fLastMouseEventTab)
if (fLastMouseEventTab != NULL)
fLastMouseEventTab->MouseDown(where, buttons);
else {
if ((buttons & B_TERTIARY_MOUSE_BUTTON) != 0) {
@ -168,10 +172,11 @@ void
TabContainerView::AddTab(const char* label, int32 index)
{
TabView* tab;
if (fController)
if (fController != NULL)
tab = fController->CreateTabView();
else
tab = new TabView();
tab->SetLabel(label);
AddTab(tab, index);
}
@ -185,23 +190,22 @@ TabContainerView::AddTab(TabView* tab, int32 index)
if (index == -1)
index = GroupLayout()->CountItems() - 1;
bool hasFrames = fController != NULL && fController->HasFrames();
bool isFirst = index == 0 && hasFrames;
bool isLast = index == GroupLayout()->CountItems() - 1 && hasFrames;
bool isFront = fSelectedTab == NULL;
tab->Update(isFirst, isLast, isFront);
tab->Update();
GroupLayout()->AddItem(index, tab->LayoutItem());
if (isFront)
if (fSelectedTab == NULL)
SelectTab(tab);
bool isLast = index == GroupLayout()->CountItems() - 1;
if (isLast) {
TabLayoutItem* item
= dynamic_cast<TabLayoutItem*>(GroupLayout()->ItemAt(index - 1));
if (item)
item->Parent()->SetIsLast(false);
if (item != NULL)
item->Parent()->Update();
}
SetFirstVisibleTabIndex(MaxFirstVisibleTabIndex());
_ValidateTabVisibility();
}
@ -212,8 +216,7 @@ TabContainerView::RemoveTab(int32 index)
{
TabLayoutItem* item
= dynamic_cast<TabLayoutItem*>(GroupLayout()->RemoveItem(index));
if (!item)
if (item == NULL)
return NULL;
BRect dirty(Bounds());
@ -225,27 +228,22 @@ TabContainerView::RemoveTab(int32 index)
fLastMouseEventTab = NULL;
// Update tabs after or before the removed tab.
bool hasFrames = fController != NULL && fController->HasFrames();
item = dynamic_cast<TabLayoutItem*>(GroupLayout()->ItemAt(index));
if (item) {
if (item != NULL) {
// This tab is behind the removed tab.
TabView* tab = item->Parent();
tab->Update(index == 0 && hasFrames,
index == GroupLayout()->CountItems() - 2 && hasFrames,
tab == fSelectedTab);
tab->Update();
if (removedTab == fSelectedTab) {
fSelectedTab = NULL;
SelectTab(tab);
} else if (fController && tab == fSelectedTab)
fController->TabSelected(index);
} else if (fController != NULL && tab == fSelectedTab)
fController->UpdateSelection(index);
} else {
// The removed tab was the last tab.
item = dynamic_cast<TabLayoutItem*>(GroupLayout()->ItemAt(index - 1));
if (item) {
if (item != NULL) {
TabView* tab = item->Parent();
tab->Update(index == 0 && hasFrames,
index == GroupLayout()->CountItems() - 2 && hasFrames,
tab == fSelectedTab);
tab->Update();
if (removedTab == fSelectedTab) {
fSelectedTab = NULL;
SelectTab(tab);
@ -265,8 +263,9 @@ TabContainerView::TabAt(int32 index) const
{
TabLayoutItem* item = dynamic_cast<TabLayoutItem*>(
GroupLayout()->ItemAt(index));
if (item)
if (item != NULL)
return item->Parent();
return NULL;
}
@ -274,6 +273,9 @@ TabContainerView::TabAt(int32 index) const
int32
TabContainerView::IndexOf(TabView* tab) const
{
if (tab == NULL || GroupLayout() == NULL)
return -1;
return GroupLayout()->IndexOfItem(tab->LayoutItem());
}
@ -284,7 +286,7 @@ TabContainerView::SelectTab(int32 index)
TabView* tab = NULL;
TabLayoutItem* item = dynamic_cast<TabLayoutItem*>(
GroupLayout()->ItemAt(index));
if (item)
if (item != NULL)
tab = item->Parent();
SelectTab(tab);
@ -297,32 +299,33 @@ TabContainerView::SelectTab(TabView* tab)
if (tab == fSelectedTab)
return;
if (fSelectedTab)
fSelectedTab->SetIsFront(false);
// update old selected tab
if (fSelectedTab != NULL)
fSelectedTab->Update();
fSelectedTab = tab;
if (fSelectedTab)
fSelectedTab->SetIsFront(true);
// update new selected tab
if (fSelectedTab != NULL)
fSelectedTab->Update();
if (fController != NULL) {
int32 index = -1;
if (fSelectedTab != NULL)
index = GroupLayout()->IndexOfItem(tab->LayoutItem());
int32 index = -1;
if (fSelectedTab != NULL)
index = GroupLayout()->IndexOfItem(tab->LayoutItem());
if (!tab->LayoutItem()->IsVisible())
SetFirstVisibleTabIndex(index);
if (!tab->LayoutItem()->IsVisible())
SetFirstVisibleTabIndex(index);
fController->TabSelected(index);
}
if (fController != NULL)
fController->UpdateSelection(index);
}
void
TabContainerView::SetTabLabel(int32 tabIndex, const char* label)
TabContainerView::SetTabLabel(int32 index, const char* label)
{
TabLayoutItem* item = dynamic_cast<TabLayoutItem*>(
GroupLayout()->ItemAt(tabIndex));
GroupLayout()->ItemAt(index));
if (item == NULL)
return;

View File

@ -16,7 +16,7 @@ class TabContainerView : public BGroupView {
public:
class Controller {
public:
virtual void TabSelected(int32 tabIndex) = 0;
virtual void UpdateSelection(int32 index) = 0;
virtual bool HasFrames() = 0;
virtual TabView* CreateTabView() = 0;
virtual void DoubleClickOutsideTabs() = 0;
@ -49,6 +49,16 @@ public:
int32 IndexOf(TabView* tab) const;
int32 FirstTabIndex() { return 0; };
int32 LastTabIndex()
{ return GroupLayout() == NULL ? -1
: GroupLayout()->CountItems() - 1; };
int32 SelectedTabIndex()
{ return fSelectedTab == NULL ? -1
: IndexOf(fSelectedTab); };
TabView* SelectedTab() { return fSelectedTab; };
void SelectTab(int32 tabIndex);
void SelectTab(TabView* tab);

View File

@ -9,6 +9,8 @@
#include <stdio.h>
#include <new>
#include <Application.h>
#include <AbstractLayoutItem.h>
#include <Bitmap.h>
@ -67,19 +69,20 @@ public:
uint32 flags = be_control_look->Flags(this);
uint32 borders = BControlLook::B_TOP_BORDER
| BControlLook::B_BOTTOM_BORDER;
be_control_look->DrawInactiveTab(this, bounds, updateRect, base,
0, borders);
be_control_look->DrawTabFrame(this, bounds, updateRect, base,
0, borders, B_NO_BORDER);
if (IsEnabled()) {
rgb_color button = tint_color(base, 1.07);
be_control_look->DrawButtonBackground(this, bounds, updateRect,
button, flags, 0);
}
bounds.left = (bounds.left + bounds.right) / 2 - 6;
bounds.top = (bounds.top + bounds.bottom) / 2 - 6;
bounds.right = bounds.left + 12;
bounds.bottom = bounds.top + 12;
DrawSymbol(bounds, updateRect, base);
BRect symbolRect(bounds);
symbolRect.left = (symbolRect.left + symbolRect.right) / 2 - 6;
symbolRect.top = (symbolRect.top + symbolRect.bottom) / 2 - 6;
symbolRect.right = symbolRect.left + 12;
symbolRect.bottom = symbolRect.top + 12;
DrawSymbol(symbolRect, updateRect, base);
}
virtual void DrawSymbol(BRect frame, const BRect& updateRect,
@ -237,26 +240,34 @@ public:
virtual void MessageReceived(BMessage* message)
{
if (fTabContainerView == NULL)
return BGroupView::MessageReceived(message);
switch (message->what) {
case MSG_SCROLL_TABS_LEFT:
fTabContainerView->SetFirstVisibleTabIndex(
fTabContainerView->FirstVisibleTabIndex() - 1);
break;
case MSG_SCROLL_TABS_RIGHT:
fTabContainerView->SetFirstVisibleTabIndex(
fTabContainerView->FirstVisibleTabIndex() + 1);
break;
case MSG_OPEN_TAB_MENU:
{
BPopUpMenu* tabMenu = new BPopUpMenu("tab menu", true, false);
int tabCount = fTabContainerView->GetLayout()->CountItems();
for (int i = 0; i < tabCount; i++) {
TabView* tab = fTabContainerView->TabAt(i);
if (tab) {
BMenuItem* item = new BMenuItem(tab->Label(), NULL);
tabMenu->AddItem(item);
if (tab->IsFront())
item->SetMarked(true);
if (tab != NULL) {
BMenuItem* item = new(std::nothrow)
BMenuItem(tab->Label(), NULL);
if (item != NULL) {
tabMenu->AddItem(item);
if (i == fTabContainerView->SelectedTabIndex())
item->SetMarked(true);
}
}
}
@ -284,6 +295,7 @@ public:
break;
}
default:
BGroupView::MessageReceived(message);
break;
@ -341,10 +353,7 @@ public:
virtual void Draw(BRect updateRect)
{
BRect bounds(Bounds());
rgb_color base = LowColor();
be_control_look->DrawInactiveTab(this, bounds, updateRect,
base, 0, BControlLook::B_TOP_BORDER);
// draw nothing
}
};
@ -355,7 +364,7 @@ public:
virtual ~TabManagerController();
virtual void TabSelected(int32 index)
virtual void UpdateSelection(int32 index)
{
fManager->SelectTab(index);
}
@ -379,6 +388,7 @@ public:
{
if (fCurrentToolTip == text)
return;
fCurrentToolTip = text;
fManager->GetTabContainerView()->HideToolTip();
fManager->GetTabContainerView()->SetToolTip(
@ -426,8 +436,8 @@ public:
virtual BSize MaxSize();
virtual void DrawContents(BView* owner, BRect frame, const BRect& updateRect,
bool isFirst, bool isLast, bool isFront);
virtual void DrawContents(BView* owner, BRect frame,
const BRect& updateRect);
virtual void MouseDown(BPoint where, uint32 buttons);
virtual void MouseUp(BPoint where);
@ -437,8 +447,7 @@ public:
void SetIcon(const BBitmap* icon);
private:
void _DrawCloseButton(BView* owner, BRect& frame, const BRect& updateRect,
bool isFirst, bool isLast, bool isFront);
void _DrawCloseButton(BView* owner, BRect& frame, const BRect& updateRect);
BRect _CloseRectFrame(BRect frame) const;
private:
@ -485,13 +494,12 @@ WebTabView::MaxSize()
void
WebTabView::DrawContents(BView* owner, BRect frame, const BRect& updateRect,
bool isFirst, bool isLast, bool isFront)
WebTabView::DrawContents(BView* owner, BRect frame, const BRect& updateRect)
{
if (fController->CloseButtonsAvailable())
_DrawCloseButton(owner, frame, updateRect, isFirst, isLast, isFront);
_DrawCloseButton(owner, frame, updateRect);
if (fIcon) {
if (fIcon != NULL) {
BRect iconBounds(0, 0, kIconSize - 1, kIconSize - 1);
// clip to icon bounds, if they are smaller
if (iconBounds.Contains(fIcon->Bounds()))
@ -523,7 +531,7 @@ WebTabView::DrawContents(BView* owner, BRect frame, const BRect& updateRect,
frame.left = frame.left + kIconSize + kIconInset * 2;
}
TabView::DrawContents(owner, frame, updateRect, isFirst, isLast, isFront);
TabView::DrawContents(owner, frame, updateRect);
}
@ -602,8 +610,9 @@ WebTabView::_CloseRectFrame(BRect frame) const
}
void WebTabView::_DrawCloseButton(BView* owner, BRect& frame,
const BRect& updateRect, bool isFirst, bool isLast, bool isFront)
void
WebTabView::_DrawCloseButton(BView* owner, BRect& frame,
const BRect& updateRect)
{
BRect closeRect = _CloseRectFrame(frame);
frame.right = closeRect.left - be_control_look->DefaultLabelSpacing();
@ -615,7 +624,10 @@ void WebTabView::_DrawCloseButton(BView* owner, BRect& frame,
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
float tint = B_DARKEN_1_TINT;
if (!IsFront()) {
float isFront = ContainerView()->SelectedTab()
== static_cast<TabView*>(this);
if (!isFront) {
base = tint_color(base, tint);
tint *= 1.02;
}

View File

@ -16,6 +16,7 @@
#include <ControlLook.h>
#include <GroupView.h>
#include <SpaceLayoutItem.h>
#include <TabView.h>
#include <Window.h>
#include "TabContainerView.h"
@ -36,7 +37,7 @@ TabView::TabView()
TabView::~TabView()
{
// The layout item is deleted for us by the layout which contains it.
if (!fContainerView)
if (fContainerView == NULL)
delete fLayoutItem;
}
@ -70,60 +71,55 @@ void
TabView::Draw(BRect updateRect)
{
BRect frame(fLayoutItem->Frame());
if (fIsFront) {
// Extend the front tab outward left/right in order to merge
// the frames of adjacent tabs.
if (!fIsFirst)
frame.left--;
if (!fIsLast)
frame.right++;
}
frame.right++;
frame.bottom++;
DrawBackground(fContainerView, frame, updateRect, fIsFirst, fIsLast,
fIsFront);
int32 index = fContainerView->IndexOf(this);
if (fIsFront) {
// make room for tail of last tab
bool isLast = index == fContainerView->LastTabIndex();
if (isLast)
frame.right -= 2;
DrawBackground(fContainerView, frame, updateRect);
bool isFront = index == fContainerView->SelectedTabIndex();
if (isFront)
frame.top += 3.0f;
if (!fIsFirst)
frame.left++;
if (!fIsLast)
frame.right--;
} else
else
frame.top += 6.0f;
float spacing = be_control_look->DefaultLabelSpacing();
frame.InsetBy(spacing, spacing / 2);
DrawContents(fContainerView, frame, updateRect, fIsFirst, fIsLast,
fIsFront);
DrawContents(fContainerView, frame, updateRect);
}
void
TabView::DrawBackground(BView* owner, BRect frame, const BRect& updateRect,
bool isFirst, bool isLast, bool isFront)
TabView::DrawBackground(BView* owner, BRect frame, const BRect& updateRect)
{
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
uint32 flags = 0;
uint32 borders = BControlLook::B_TOP_BORDER
| BControlLook::B_BOTTOM_BORDER;
if (isFirst)
borders |= BControlLook::B_LEFT_BORDER;
if (isLast)
borders |= BControlLook::B_RIGHT_BORDER;
if (isFront) {
be_control_look->DrawActiveTab(owner, frame, updateRect, base,
0, borders);
int32 index = fContainerView->IndexOf(this);
int32 selected = fContainerView->SelectedTabIndex();
int32 first = fContainerView->FirstTabIndex();
int32 last = fContainerView->LastTabIndex();
if (index == selected) {
be_control_look->DrawActiveTab(owner, frame, updateRect, base, flags,
borders, BControlLook::B_TOP_BORDER, index, selected, first, last);
} else {
be_control_look->DrawInactiveTab(owner, frame, updateRect, base,
0, borders);
be_control_look->DrawInactiveTab(owner, frame, updateRect, base, flags,
borders, BControlLook::B_TOP_BORDER, index, selected, first, last);
}
}
void
TabView::DrawContents(BView* owner, BRect frame, const BRect& updateRect,
bool isFirst, bool isLast, bool isFront)
TabView::DrawContents(BView* owner, BRect frame, const BRect& updateRect)
{
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
be_control_look->DrawLabel(owner, fLabel.String(), frame, updateRect,
@ -151,35 +147,8 @@ TabView::MouseMoved(BPoint where, uint32 transit, const BMessage* dragMessage)
void
TabView::SetIsFront(bool isFront)
TabView::Update()
{
Update(fIsFirst, fIsLast, isFront);
}
bool
TabView::IsFront() const
{
return fIsFront;
}
void
TabView::SetIsLast(bool isLast)
{
Update(fIsFirst, isLast, fIsFront);
}
void
TabView::Update(bool isFirst, bool isLast, bool isFront)
{
if (fIsFirst == isFirst && fIsLast == isLast && fIsFront == isFront)
return;
fIsFirst = isFirst;
fIsLast = isLast;
fIsFront = isFront;
fLayoutItem->InvalidateContainer();
}
@ -210,6 +179,7 @@ TabView::SetLabel(const char* label)
{
if (fLabel == label)
return;
fLabel = label;
fLayoutItem->InvalidateLayout();
}
@ -339,8 +309,8 @@ void
TabLayoutItem::InvalidateContainer(BRect frame)
{
// Invalidate more than necessary, to help the TabContainerView
// redraw the parts outside any tabs...
frame.bottom++;
frame.right++;
// redraw the parts outside any tabs... need 2px
frame.bottom += 2;
frame.right += 2;
fParent->ContainerView()->Invalidate(frame);
}

View File

@ -28,26 +28,20 @@ public:
void Draw(BRect updateRect);
virtual void DrawBackground(BView* owner, BRect frame,
const BRect& updateRect, bool isFirst,
bool isLast, bool isFront);
const BRect& updateRect);
virtual void DrawContents(BView* owner, BRect frame,
const BRect& updateRect, bool isFirst,
bool isLast, bool isFront);
const BRect& updateRect);
virtual void MouseDown(BPoint where, uint32 buttons);
virtual void MouseUp(BPoint where);
virtual void MouseMoved(BPoint where, uint32 transit,
const BMessage* dragMessage);
void SetIsFront(bool isFront);
bool IsFront() const;
void SetIsLast(bool isLast);
virtual void Update(bool isFirst, bool isLast,
bool isFront);
virtual void Update();
BLayoutItem* LayoutItem() const;
void SetContainerView(
TabContainerView* containerView);
void SetContainerView(TabContainerView* view);
TabContainerView* ContainerView() const;
void SetLabel(const char* label);
@ -63,10 +57,6 @@ private:
TabLayoutItem* fLayoutItem;
BString fLabel;
bool fIsFirst;
bool fIsLast;
bool fIsFront;
};

View File

@ -1635,33 +1635,23 @@ HaikuControlLook::DrawTabFrame(BView* view, BRect& rect,
if (side == BTabView::kTopSide || side == BTabView::kBottomSide) {
// draw an inactive tab frame behind all tabs
borders = B_TOP_BORDER | B_BOTTOM_BORDER;
if (borderStyle == B_NO_BORDER) {
// removes left border that is an artifact of DrawInactiveTab()
rect.left -= 1;
} else
if (borderStyle != B_NO_BORDER)
borders |= B_LEFT_BORDER | B_RIGHT_BORDER;
// DrawInactiveTab draws 2px border
// draw a little wider tab frame to align B_PLAIN_BORDER with it
if (borderStyle == B_PLAIN_BORDER) {
rect.left -= 1;
rect.right += 1;
}
// draw tab frame wider to align B_PLAIN_BORDER with it
if (borderStyle == B_PLAIN_BORDER)
rect.InsetBy(-1, 0);
} else if (side == BTabView::kLeftSide || side == BTabView::kRightSide) {
// draw an inactive tab frame behind all tabs
borders = B_LEFT_BORDER | B_RIGHT_BORDER;
if (borderStyle == B_NO_BORDER) {
// removes top border that is an artifact of DrawInactiveTab()
rect.top -= 1;
} else
if (borderStyle != B_NO_BORDER)
borders |= B_TOP_BORDER | B_BOTTOM_BORDER;
// DrawInactiveTab draws 2px border
// draw a little wider tab frame to align B_PLAIN_BORDER with it
if (borderStyle == B_PLAIN_BORDER) {
rect.top -= 1;
rect.bottom += 1;
}
// draw tab frame wider to align B_PLAIN_BORDER with it
if (borderStyle == B_PLAIN_BORDER)
rect.InsetBy(0, -1);
}
DrawInactiveTab(view, rect, rect, base, 0, borders, side);
@ -1669,8 +1659,9 @@ HaikuControlLook::DrawTabFrame(BView* view, BRect& rect,
void
HaikuControlLook::DrawActiveTab(BView* view, BRect& rect, const BRect& updateRect,
const rgb_color& base, uint32 flags, uint32 borders, uint32 side)
HaikuControlLook::DrawActiveTab(BView* view, BRect& rect,
const BRect& updateRect, const rgb_color& base, uint32 flags,
uint32 borders, uint32 side, int32, int32, int32, int32)
{
if (!rect.IsValid() || !rect.Intersects(updateRect))
return;
@ -1848,8 +1839,9 @@ HaikuControlLook::DrawActiveTab(BView* view, BRect& rect, const BRect& updateRec
void
HaikuControlLook::DrawInactiveTab(BView* view, BRect& rect, const BRect& updateRect,
const rgb_color& base, uint32 flags, uint32 borders, uint32 side)
HaikuControlLook::DrawInactiveTab(BView* view, BRect& rect,
const BRect& updateRect, const rgb_color& base, uint32 flags,
uint32 borders, uint32 side, int32, int32, int32, int32)
{
if (!rect.IsValid() || !rect.Intersects(updateRect))
return;
@ -1886,22 +1878,26 @@ HaikuControlLook::DrawInactiveTab(BView* view, BRect& rect, const BRect& updateR
BRect background = rect;
switch (side) {
default:
case B_TOP_BORDER:
rect.top += 4;
background.bottom = rect.top;
break;
case B_BOTTOM_BORDER:
rect.bottom -= 4;
background.top = rect.bottom;
break;
case B_LEFT_BORDER:
rect.left += 4;
background.right = rect.left;
break;
case B_RIGHT_BORDER:
rect.right -= 4;
background.left = rect.right;
break;
break;
}
// active tabs stand out at the top, but this is an inactive tab
@ -1915,22 +1911,20 @@ HaikuControlLook::DrawInactiveTab(BView* view, BRect& rect, const BRect& updateR
_DrawFrame(view, rect, frameLightColor, frameLightColor, frameShadowColor,
frameShadowColor, borders);
if (rect.IsValid()) {
if (side == B_TOP_BORDER || side == B_BOTTOM_BORDER) {
if ((side == B_TOP_BORDER || side == B_BOTTOM_BORDER)
&& (borders & B_LEFT_BORDER) != 0) {
if (rect.IsValid()) {
_DrawFrame(view, rect, bevelShadowColor, bevelShadowColor,
bevelLightColor, bevelLightColor, B_LEFT_BORDER & ~borders);
} else if (side == B_LEFT_BORDER || side == B_RIGHT_BORDER) {
} else if ((B_LEFT_BORDER & ~borders) != 0)
rect.left++;
} else if ((side == B_LEFT_BORDER || side == B_RIGHT_BORDER)
&& (borders & B_TOP_BORDER) != 0) {
if (rect.IsValid()) {
_DrawFrame(view, rect, bevelShadowColor, bevelShadowColor,
bevelLightColor, bevelLightColor, B_TOP_BORDER & ~borders);
}
} else {
if (side == B_TOP_BORDER || side == B_BOTTOM_BORDER) {
if ((B_LEFT_BORDER & ~borders) != 0)
rect.left++;
} else if (side == B_LEFT_BORDER || side == B_RIGHT_BORDER) {
if ((B_TOP_BORDER & ~borders) != 0)
rect.top++;
}
} else if ((B_TOP_BORDER & ~borders) != 0)
rect.top++;
}
view->FillRect(rect, fillGradient);

View File

@ -316,10 +316,42 @@ BTab::DrawLabel(BView* owner, BRect frame)
void
BTab::DrawTab(BView* owner, BRect frame, tab_position position, bool full)
BTab::DrawTab(BView* owner, BRect frame, tab_position, bool)
{
if (fTabView == NULL)
return;
rgb_color base = ui_color(B_PANEL_BACKGROUND_COLOR);
uint32 flags = 0;
uint32 borders = _Borders(owner, frame);
int32 index = fTabView->IndexOf(this);
int32 selected = fTabView->Selection();
int32 first = 0;
int32 last = fTabView->CountTabs() - 1;
if (index == selected) {
be_control_look->DrawActiveTab(owner, frame, frame, base, flags,
borders, fTabView->TabSide(), index, selected, first, last);
} else {
be_control_look->DrawInactiveTab(owner, frame, frame, base, flags,
borders, fTabView->TabSide(), index, selected, first, last);
}
DrawLabel(owner, frame);
}
// #pragma mark - BTab private methods
uint32
BTab::_Borders(BView* owner, BRect frame)
{
rgb_color no_tint = ui_color(B_PANEL_BACKGROUND_COLOR);
uint32 borders = 0;
if (owner == NULL || fTabView == NULL)
return borders;
if (fTabView->TabSide() == BTabView::kTopSide
|| fTabView->TabSide() == BTabView::kBottomSide) {
borders = BControlLook::B_TOP_BORDER | BControlLook::B_BOTTOM_BORDER;
@ -340,15 +372,7 @@ BTab::DrawTab(BView* owner, BRect frame, tab_position position, bool full)
borders |= BControlLook::B_BOTTOM_BORDER;
}
if (position == B_TAB_FRONT) {
be_control_look->DrawActiveTab(owner, frame, frame, no_tint, 0,
borders, fTabView->TabSide());
} else {
be_control_look->DrawInactiveTab(owner, frame, frame, no_tint, 0,
borders, fTabView->TabSide());
}
DrawLabel(owner, frame);
return borders;
}
@ -921,9 +945,9 @@ BTabView::DrawTabs()
activeTabFrame = tabFrame;
TabAt(i)->DrawTab(this, tabFrame,
i == fSelection ? B_TAB_FRONT :
(i == 0) ? B_TAB_FIRST : B_TAB_ANY,
i + 1 != fSelection);
i == fSelection ? B_TAB_FRONT
: (i == 0) ? B_TAB_FIRST : B_TAB_ANY,
i != fSelection - 1);
}
BRect tabsBounds;
@ -1348,6 +1372,21 @@ BTabView::ViewForTab(int32 tabIndex) const
}
int32
BTabView::IndexOf(BTab* tab) const
{
if (tab != NULL) {
int32 tabCount = CountTabs();
for (int32 index = 0; index < tabCount; index++) {
if (TabAt(index) == tab)
return index;
}
}
return -1;
}
void
BTabView::_InitObject(bool layouted, button_width width)
{

View File

@ -699,6 +699,9 @@ void
KeyboardLayoutView::_DrawKeyButton(BView* view, BRect& rect, BRect updateRect,
rgb_color base, rgb_color background, bool pressed)
{
uint32 flags = pressed ? BControlLook::B_ACTIVATED : 0;
flags |= BControlLook::B_FLAT;
be_control_look->DrawButtonFrame(view, rect, updateRect, 4.0f, base,
background, pressed ? BControlLook::B_ACTIVATED : 0);
be_control_look->DrawButtonBackground(view, rect, updateRect, 4.0f,
@ -731,6 +734,9 @@ KeyboardLayoutView::_DrawKey(BView* view, BRect updateRect, const Key* key,
_SetFontSize(view, keyKind);
uint32 flags = pressed ? BControlLook::B_ACTIVATED : 0;
flags |= BControlLook::B_FLAT;
if (secondDeadKey)
base = kSecondDeadKeyColor;
else if (deadKey > 0 && isDeadKeyEnabled)
@ -743,7 +749,8 @@ KeyboardLayoutView::_DrawKey(BView* view, BRect updateRect, const Key* key,
_GetAbbreviatedKeyLabelIfNeeded(view, rect, key, text, sizeof(text));
be_control_look->DrawLabel(view, text, rect, updateRect,
base, 0, BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE), &keyLabelColor);
base, flags, BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE),
&keyLabelColor);
} else if (key->shape == kEnterKeyShape) {
BRect topLeft = rect;
BRect topRight = rect;
@ -769,35 +776,29 @@ KeyboardLayoutView::_DrawKey(BView* view, BRect updateRect, const Key* key,
// draw top left corner
be_control_look->DrawButtonFrame(view, topLeft, updateRect,
4.0f, 0.0f, 4.0f, 0.0f, base, background,
pressed ? BControlLook::B_ACTIVATED : 0,
4.0f, 0.0f, 4.0f, 0.0f, base, background, flags,
BControlLook::B_LEFT_BORDER | BControlLook::B_TOP_BORDER
| BControlLook::B_BOTTOM_BORDER);
be_control_look->DrawButtonBackground(view, topLeft, updateRect,
4.0f, 0.0f, 4.0f, 0.0f, base,
pressed ? BControlLook::B_ACTIVATED : 0,
4.0f, 0.0f, 4.0f, 0.0f, base, flags,
BControlLook::B_LEFT_BORDER | BControlLook::B_TOP_BORDER
| BControlLook::B_BOTTOM_BORDER);
// draw top right corner
be_control_look->DrawButtonFrame(view, topRight, updateRect,
0.0f, 4.0f, 0.0f, 0.0f, base, background,
pressed ? BControlLook::B_ACTIVATED : 0,
0.0f, 4.0f, 0.0f, 0.0f, base, background, flags,
BControlLook::B_TOP_BORDER | BControlLook::B_RIGHT_BORDER);
be_control_look->DrawButtonBackground(view, topRight, updateRect,
0.0f, 4.0f, 0.0f, 0.0f, base,
pressed ? BControlLook::B_ACTIVATED : 0,
0.0f, 4.0f, 0.0f, 0.0f, base, flags,
BControlLook::B_TOP_BORDER | BControlLook::B_RIGHT_BORDER);
// draw bottom right corner
be_control_look->DrawButtonFrame(view, bottomRight, updateRect,
0.0f, 0.0f, 4.0f, 4.0f, base, background,
pressed ? BControlLook::B_ACTIVATED : 0,
0.0f, 0.0f, 4.0f, 4.0f, base, background, flags,
BControlLook::B_LEFT_BORDER | BControlLook::B_RIGHT_BORDER
| BControlLook::B_BOTTOM_BORDER);
be_control_look->DrawButtonBackground(view, bottomRight, updateRect,
0.0f, 0.0f, 4.0f, 4.0f, base,
pressed ? BControlLook::B_ACTIVATED : 0,
0.0f, 0.0f, 4.0f, 4.0f, base, flags,
BControlLook::B_LEFT_BORDER | BControlLook::B_RIGHT_BORDER
| BControlLook::B_BOTTOM_BORDER);
@ -811,15 +812,15 @@ KeyboardLayoutView::_DrawKey(BView* view, BRect updateRect, const Key* key,
// draw the button background
BRect bgRect = rect.InsetByCopy(2, 2);
be_control_look->DrawButtonBackground(view, bgRect, updateRect,
4.0f, 4.0f, 0.0f, 4.0f, base,
pressed ? BControlLook::B_ACTIVATED : 0);
4.0f, 4.0f, 0.0f, 4.0f, base, flags);
rect.left = bottomLeft.right;
_GetAbbreviatedKeyLabelIfNeeded(view, rect, key, text, sizeof(text));
// draw the button label
be_control_look->DrawLabel(view, text, rect, updateRect,
base, 0, BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE), &keyLabelColor);
base, flags, BAlignment(B_ALIGN_CENTER, B_ALIGN_MIDDLE),
&keyLabelColor);
// reset the clipping region
view->ConstrainClippingRegion(NULL);