* Update indentation style in TabView.h
* Added _MinTabeSize() to BTabView. It makes sure that the BTabView displays at least two tabs. In the future it should also add the room to display some buttons for cycling the currently displayed tabs left/right if there is more than can fit. * In BTabView::Min/Max/PreferredSize(), use _MinTabSize() to compute the respective size. * Improve Tab rendering code so there are no ugly overlaps at the right edge if the tabs falls directly on the view edge. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31157 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+139
-163
@@ -1,37 +1,11 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) 2001-2002, OpenBeOS
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a
|
||||
// copy of this software and associated documentation files (the "Software"),
|
||||
// to deal in the Software without restriction, including without limitation
|
||||
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
// and/or sell copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
// DEALINGS IN THE SOFTWARE.
|
||||
//
|
||||
// File Name: TabView.h
|
||||
// Author: Marc Flerackers ([email protected])
|
||||
// Description: BTab creates individual "tabs" that can be assigned
|
||||
// to specific views.
|
||||
// BTabView provides the framework for containing and
|
||||
// managing groups of BTab objects.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
* Copyright 2001-2009, Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT license.
|
||||
*/
|
||||
#ifndef _TAB_VIEW_H
|
||||
#define _TAB_VIEW_H
|
||||
|
||||
|
||||
#include <BeBuild.h>
|
||||
#include <View.h>
|
||||
|
||||
|
||||
@@ -42,175 +16,177 @@ enum tab_position {
|
||||
};
|
||||
|
||||
|
||||
// BTab class ------------------------------------------------------------------
|
||||
class BTab : public BArchivable {
|
||||
|
||||
public:
|
||||
BTab(BView * tabView = NULL);
|
||||
virtual ~BTab();
|
||||
BTab(BView* tabView = NULL);
|
||||
virtual ~BTab();
|
||||
|
||||
BTab(BMessage *archive);
|
||||
static BArchivable *Instantiate(BMessage *archive);
|
||||
BTab(BMessage* archive);
|
||||
static BArchivable* Instantiate(BMessage* archive);
|
||||
|
||||
virtual status_t Archive(BMessage *archive, bool deep = true) const;
|
||||
virtual status_t Perform(uint32 d, void *arg);
|
||||
virtual status_t Archive(BMessage* archive,
|
||||
bool deep = true) const;
|
||||
virtual status_t Perform(uint32 d, void* arg);
|
||||
|
||||
const char *Label() const;
|
||||
virtual void SetLabel(const char *label);
|
||||
const char* Label() const;
|
||||
virtual void SetLabel(const char* label);
|
||||
|
||||
bool IsSelected() const;
|
||||
virtual void Select(BView *owner);
|
||||
virtual void Deselect();
|
||||
bool IsSelected() const;
|
||||
virtual void Select(BView* owner);
|
||||
virtual void Deselect();
|
||||
|
||||
virtual void SetEnabled(bool enabled);
|
||||
bool IsEnabled() const;
|
||||
virtual void SetEnabled(bool enabled);
|
||||
bool IsEnabled() const;
|
||||
|
||||
void MakeFocus(bool inFocus = true);
|
||||
bool IsFocus() const;
|
||||
void MakeFocus(bool inFocus = true);
|
||||
bool IsFocus() const;
|
||||
|
||||
// sets/gets the view to be displayed for this tab
|
||||
virtual void SetView(BView *view);
|
||||
BView *View() const;
|
||||
// sets/gets the view to be displayed for this tab
|
||||
virtual void SetView(BView* view);
|
||||
BView* View() const;
|
||||
|
||||
virtual void DrawFocusMark(BView *owner, BRect frame);
|
||||
virtual void DrawLabel(BView *owner, BRect frame);
|
||||
virtual void DrawTab(BView *owner, BRect frame, tab_position position,
|
||||
bool full = true);
|
||||
virtual void DrawFocusMark(BView* owner, BRect frame);
|
||||
virtual void DrawLabel(BView* owner, BRect frame);
|
||||
virtual void DrawTab(BView* owner, BRect frame,
|
||||
tab_position position, bool full = true);
|
||||
|
||||
private:
|
||||
virtual void _ReservedTab1();
|
||||
virtual void _ReservedTab2();
|
||||
virtual void _ReservedTab3();
|
||||
virtual void _ReservedTab4();
|
||||
virtual void _ReservedTab5();
|
||||
virtual void _ReservedTab6();
|
||||
virtual void _ReservedTab7();
|
||||
virtual void _ReservedTab8();
|
||||
virtual void _ReservedTab9();
|
||||
virtual void _ReservedTab10();
|
||||
virtual void _ReservedTab11();
|
||||
virtual void _ReservedTab12();
|
||||
virtual void _ReservedTab1();
|
||||
virtual void _ReservedTab2();
|
||||
virtual void _ReservedTab3();
|
||||
virtual void _ReservedTab4();
|
||||
virtual void _ReservedTab5();
|
||||
virtual void _ReservedTab6();
|
||||
virtual void _ReservedTab7();
|
||||
virtual void _ReservedTab8();
|
||||
virtual void _ReservedTab9();
|
||||
virtual void _ReservedTab10();
|
||||
virtual void _ReservedTab11();
|
||||
virtual void _ReservedTab12();
|
||||
|
||||
BTab &operator=(const BTab &);
|
||||
|
||||
bool fEnabled;
|
||||
bool fSelected;
|
||||
bool fFocus;
|
||||
BView *fView;
|
||||
uint32 _reserved[12];
|
||||
BTab& operator=(const BTab&);
|
||||
|
||||
bool fEnabled;
|
||||
bool fSelected;
|
||||
bool fFocus;
|
||||
BView* fView;
|
||||
|
||||
uint32 _reserved[12];
|
||||
};
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
|
||||
// BTabView class --------------------------------------------------------------
|
||||
class BTabView : public BView
|
||||
{
|
||||
class BTabView : public BView {
|
||||
public:
|
||||
BTabView(const char *name,
|
||||
button_width width = B_WIDTH_AS_USUAL,
|
||||
uint32 flags = B_FULL_UPDATE_ON_RESIZE |
|
||||
B_WILL_DRAW | B_NAVIGABLE_JUMP |
|
||||
B_FRAME_EVENTS | B_NAVIGABLE);
|
||||
BTabView(BRect frame, const char *name,
|
||||
button_width width = B_WIDTH_AS_USUAL,
|
||||
uint32 resizingMode = B_FOLLOW_ALL,
|
||||
uint32 flags = B_FULL_UPDATE_ON_RESIZE |
|
||||
B_WILL_DRAW | B_NAVIGABLE_JUMP |
|
||||
B_FRAME_EVENTS | B_NAVIGABLE);
|
||||
~BTabView();
|
||||
BTabView(const char* name,
|
||||
button_width width = B_WIDTH_AS_USUAL,
|
||||
uint32 flags = B_FULL_UPDATE_ON_RESIZE |
|
||||
B_WILL_DRAW | B_NAVIGABLE_JUMP |
|
||||
B_FRAME_EVENTS | B_NAVIGABLE);
|
||||
BTabView(BRect frame, const char* name,
|
||||
button_width width = B_WIDTH_AS_USUAL,
|
||||
uint32 resizingMode = B_FOLLOW_ALL,
|
||||
uint32 flags = B_FULL_UPDATE_ON_RESIZE |
|
||||
B_WILL_DRAW | B_NAVIGABLE_JUMP |
|
||||
B_FRAME_EVENTS | B_NAVIGABLE);
|
||||
virtual ~BTabView();
|
||||
|
||||
BTabView(BMessage *archive);
|
||||
static BArchivable *Instantiate(BMessage *archive);
|
||||
virtual status_t Archive(BMessage*, bool deep=true) const;
|
||||
virtual status_t Perform(perform_code d, void *arg);
|
||||
BTabView(BMessage* archive);
|
||||
static BArchivable* Instantiate(BMessage* archive);
|
||||
virtual status_t Archive(BMessage* into,
|
||||
bool deep = true) const;
|
||||
virtual status_t Perform(perform_code d, void* arg);
|
||||
|
||||
virtual void WindowActivated(bool active);
|
||||
virtual void AttachedToWindow();
|
||||
virtual void AllAttached();
|
||||
virtual void AllDetached();
|
||||
virtual void DetachedFromWindow();
|
||||
virtual void WindowActivated(bool active);
|
||||
virtual void AttachedToWindow();
|
||||
virtual void AllAttached();
|
||||
virtual void AllDetached();
|
||||
virtual void DetachedFromWindow();
|
||||
|
||||
virtual void MessageReceived(BMessage *message);
|
||||
virtual void FrameMoved(BPoint newLocation);
|
||||
virtual void FrameResized(float width,float height);
|
||||
virtual void KeyDown(const char *bytes, int32 numBytes);
|
||||
virtual void MouseDown(BPoint point);
|
||||
virtual void MouseUp(BPoint point);
|
||||
virtual void MouseMoved(BPoint point, uint32 transit,
|
||||
const BMessage *message);
|
||||
virtual void Pulse();
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
virtual void FrameMoved(BPoint newLocation);
|
||||
virtual void FrameResized(float width,float height);
|
||||
virtual void KeyDown(const char* bytes, int32 numBytes);
|
||||
virtual void MouseDown(BPoint point);
|
||||
virtual void MouseUp(BPoint point);
|
||||
virtual void MouseMoved(BPoint point, uint32 transit,
|
||||
const BMessage* dragMessage);
|
||||
virtual void Pulse();
|
||||
|
||||
virtual void Select(int32 tab);
|
||||
int32 Selection() const;
|
||||
virtual void Select(int32 tab);
|
||||
int32 Selection() const;
|
||||
|
||||
virtual void MakeFocus(bool focused = true);
|
||||
virtual void SetFocusTab(int32 tab, bool focused);
|
||||
int32 FocusTab() const;
|
||||
virtual void MakeFocus(bool focused = true);
|
||||
virtual void SetFocusTab(int32 tab, bool focused);
|
||||
int32 FocusTab() const;
|
||||
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual BRect DrawTabs();
|
||||
virtual void DrawBox(BRect selTabRect);
|
||||
virtual BRect TabFrame(int32 tab_index) const;
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual BRect DrawTabs();
|
||||
virtual void DrawBox(BRect selectedTabRect);
|
||||
virtual BRect TabFrame(int32 index) const;
|
||||
|
||||
virtual void SetFlags(uint32 flags);
|
||||
virtual void SetResizingMode(uint32 mode);
|
||||
virtual void SetFlags(uint32 flags);
|
||||
virtual void SetResizingMode(uint32 mode);
|
||||
|
||||
virtual void ResizeToPreferred();
|
||||
virtual void GetPreferredSize(float* _width, float* _height);
|
||||
virtual void ResizeToPreferred();
|
||||
virtual void GetPreferredSize(float* _width,
|
||||
float* _height);
|
||||
|
||||
virtual BSize MinSize();
|
||||
virtual BSize MaxSize();
|
||||
virtual BSize PreferredSize();
|
||||
virtual BSize MinSize();
|
||||
virtual BSize MaxSize();
|
||||
virtual BSize PreferredSize();
|
||||
|
||||
virtual BHandler *ResolveSpecifier(BMessage *message, int32 index,
|
||||
BMessage *specifier, int32 what, const char *property);
|
||||
virtual status_t GetSupportedSuites(BMessage *message);
|
||||
virtual BHandler* ResolveSpecifier(BMessage* message,
|
||||
int32 index, BMessage* specifier,
|
||||
int32 what, const char* property);
|
||||
virtual status_t GetSupportedSuites(BMessage* message);
|
||||
|
||||
virtual void AddTab(BView *target, BTab *tab = NULL);
|
||||
virtual BTab *RemoveTab(int32 tabIndex);
|
||||
virtual void AddTab(BView* target, BTab* tab = NULL);
|
||||
virtual BTab* RemoveTab(int32 tabIndex);
|
||||
|
||||
virtual BTab *TabAt ( int32 tab_index ) const;
|
||||
virtual BTab* TabAt(int32 index) const;
|
||||
|
||||
virtual void SetTabWidth(button_width width);
|
||||
button_width TabWidth() const;
|
||||
|
||||
virtual void SetTabHeight(float height);
|
||||
float TabHeight() const;
|
||||
virtual void SetTabWidth(button_width width);
|
||||
button_width TabWidth() const;
|
||||
|
||||
BView *ContainerView() const;
|
||||
virtual void SetTabHeight(float height);
|
||||
float TabHeight() const;
|
||||
|
||||
int32 CountTabs() const;
|
||||
BView *ViewForTab(int32 tabIndex) const;
|
||||
BView* ContainerView() const;
|
||||
|
||||
int32 CountTabs() const;
|
||||
BView* ViewForTab(int32 tabIndex) const;
|
||||
|
||||
private:
|
||||
void _InitObject(bool layouted, button_width width);
|
||||
void _InitObject(bool layouted, button_width width);
|
||||
BSize _TabsMinSize() const;
|
||||
|
||||
virtual void _ReservedTabView1();
|
||||
virtual void _ReservedTabView2();
|
||||
virtual void _ReservedTabView3();
|
||||
virtual void _ReservedTabView4();
|
||||
virtual void _ReservedTabView5();
|
||||
virtual void _ReservedTabView6();
|
||||
virtual void _ReservedTabView7();
|
||||
virtual void _ReservedTabView8();
|
||||
virtual void _ReservedTabView9();
|
||||
virtual void _ReservedTabView10();
|
||||
virtual void _ReservedTabView11();
|
||||
virtual void _ReservedTabView12();
|
||||
virtual void _ReservedTabView1();
|
||||
virtual void _ReservedTabView2();
|
||||
virtual void _ReservedTabView3();
|
||||
virtual void _ReservedTabView4();
|
||||
virtual void _ReservedTabView5();
|
||||
virtual void _ReservedTabView6();
|
||||
virtual void _ReservedTabView7();
|
||||
virtual void _ReservedTabView8();
|
||||
virtual void _ReservedTabView9();
|
||||
virtual void _ReservedTabView10();
|
||||
virtual void _ReservedTabView11();
|
||||
virtual void _ReservedTabView12();
|
||||
|
||||
BTabView(const BTabView &);
|
||||
BTabView &operator=(const BTabView &);
|
||||
|
||||
BList *fTabList;
|
||||
BView *fContainerView;
|
||||
button_width fTabWidthSetting;
|
||||
float fTabWidth;
|
||||
float fTabHeight;
|
||||
int32 fSelection;
|
||||
int32 fInitialSelection;
|
||||
int32 fFocus;
|
||||
float fTabOffset;
|
||||
uint32 _reserved[11];
|
||||
BTabView(const BTabView&);
|
||||
BTabView& operator=(const BTabView&);
|
||||
|
||||
BList* fTabList;
|
||||
BView* fContainerView;
|
||||
button_width fTabWidthSetting;
|
||||
float fTabWidth;
|
||||
float fTabHeight;
|
||||
int32 fSelection;
|
||||
int32 fInitialSelection;
|
||||
int32 fFocus;
|
||||
float fTabOffset;
|
||||
|
||||
uint32 _reserved[11];
|
||||
};
|
||||
|
||||
#endif // _TAB_VIEW_H
|
||||
|
||||
@@ -1433,8 +1433,13 @@ BControlLook::DrawInactiveTab(BView* view, BRect& rect, const BRect& updateRect,
|
||||
frameShadowColor,
|
||||
borders & (B_LEFT_BORDER | B_TOP_BORDER | B_RIGHT_BORDER));
|
||||
|
||||
_DrawFrame(view, rect, bevelShadowColor, bevelShadowColor, bevelLightColor,
|
||||
bevelLightColor, B_LEFT_BORDER & ~borders);
|
||||
if (rect.IsValid()) {
|
||||
_DrawFrame(view, rect, bevelShadowColor, bevelShadowColor,
|
||||
bevelLightColor, bevelLightColor, B_LEFT_BORDER & ~borders);
|
||||
} else {
|
||||
if ((B_LEFT_BORDER & ~borders) != 0)
|
||||
rect.left++;
|
||||
}
|
||||
|
||||
view->FillRect(rect, fillGradient);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2001-2008, Haiku, Inc.
|
||||
* Copyright 2001-2009, Haiku, Inc. All rights reserved.
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Authors:
|
||||
@@ -851,14 +851,17 @@ BTabView::DrawTabs()
|
||||
|
||||
if (be_control_look != NULL) {
|
||||
BRect frame(Bounds());
|
||||
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 (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 (fSelection < CountTabs())
|
||||
@@ -1061,9 +1064,11 @@ BTabView::GetPreferredSize(float *width, float *height)
|
||||
BSize
|
||||
BTabView::MinSize()
|
||||
{
|
||||
BSize size = fContainerView->MinSize();
|
||||
size.height += TabHeight() + 6.0f;
|
||||
size.width += 6.0f;
|
||||
BSize size(_TabsMinSize());
|
||||
BSize containerSize = fContainerView->MinSize();
|
||||
if (containerSize.width > size.width)
|
||||
size.width = containerSize.width;
|
||||
size.height += containerSize.height;
|
||||
return BLayoutUtils::ComposeSize(ExplicitMinSize(), size);
|
||||
}
|
||||
|
||||
@@ -1071,9 +1076,11 @@ BTabView::MinSize()
|
||||
BSize
|
||||
BTabView::MaxSize()
|
||||
{
|
||||
BSize size = fContainerView->MaxSize();
|
||||
size.height += TabHeight() + 6.0f;
|
||||
size.width += 6.0f;
|
||||
BSize size(_TabsMinSize());
|
||||
BSize containerSize = fContainerView->MaxSize();
|
||||
if (containerSize.width > size.width)
|
||||
size.width = containerSize.width;
|
||||
size.height += containerSize.height;
|
||||
return BLayoutUtils::ComposeSize(ExplicitMaxSize(), size);
|
||||
}
|
||||
|
||||
@@ -1081,9 +1088,11 @@ BTabView::MaxSize()
|
||||
BSize
|
||||
BTabView::PreferredSize()
|
||||
{
|
||||
BSize size = fContainerView->PreferredSize();
|
||||
size.height += TabHeight() + 6.0f;
|
||||
size.width += 6.0f;
|
||||
BSize size(_TabsMinSize());
|
||||
BSize containerSize = fContainerView->PreferredSize();
|
||||
if (containerSize.width > size.width)
|
||||
size.width = containerSize.width;
|
||||
size.height += containerSize.height;
|
||||
return BLayoutUtils::ComposeSize(ExplicitPreferredSize(), size);
|
||||
}
|
||||
|
||||
@@ -1291,6 +1300,28 @@ BTabView::_InitObject(bool layouted, button_width width)
|
||||
}
|
||||
|
||||
|
||||
BSize
|
||||
BTabView::_TabsMinSize() const
|
||||
{
|
||||
BSize size(0.0f, TabHeight() + 6.0f);
|
||||
int32 count = min_c(2, CountTabs());
|
||||
for (int32 i = 0; i < count; i++) {
|
||||
BRect frame = TabFrame(i);
|
||||
size.width += frame.Width();
|
||||
}
|
||||
|
||||
if (count < CountTabs()) {
|
||||
// TODO: Add size for yet to be implemented buttons that allow
|
||||
// "scrolling" the displayed tabs left/right.
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
// #pragma mark - FBC and forbidden
|
||||
|
||||
|
||||
void BTabView::_ReservedTabView1() {}
|
||||
void BTabView::_ReservedTabView2() {}
|
||||
void BTabView::_ReservedTabView3() {}
|
||||
@@ -1305,14 +1336,15 @@ void BTabView::_ReservedTabView11() {}
|
||||
void BTabView::_ReservedTabView12() {}
|
||||
|
||||
|
||||
BTabView::BTabView(const BTabView &tabView)
|
||||
BTabView::BTabView(const BTabView& tabView)
|
||||
: BView(tabView)
|
||||
{
|
||||
// this is private and not functional, but exported
|
||||
}
|
||||
|
||||
|
||||
BTabView &BTabView::operator=(const BTabView &)
|
||||
BTabView&
|
||||
BTabView::operator=(const BTabView&)
|
||||
{
|
||||
// this is private and not functional, but exported
|
||||
return *this;
|
||||
|
||||
Reference in New Issue
Block a user