BScrollView::SetBorders() added to disable borders.

* You can specify which borders will be drawn using the
  BControlLook::B_TOP_BORDER, ... constants.
* Adapted Mail to no longer need the SetInsets() hack.
This commit is contained in:
Axel Dörfler
2015-09-09 20:51:49 +02:00
parent 635fe4746d
commit fd79684a5f
3 changed files with 73 additions and 36 deletions
+11 -10
View File
@@ -1,11 +1,6 @@
/* /*
* Copyright 2004-2009, Axel Dörfler, [email protected]. * Copyright 2004-2015 Haiku, Inc. All rights reserved.
* Copyright 2014 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
*
* Authors:
* Axel Dörfler, [email protected]
* John Scipione, [email protected]
*/ */
#ifndef _SCROLL_VIEW_H #ifndef _SCROLL_VIEW_H
#define _SCROLL_VIEW_H #define _SCROLL_VIEW_H
@@ -71,6 +66,8 @@ public:
virtual void SetBorder(border_style border); virtual void SetBorder(border_style border);
border_style Border() const; border_style Border() const;
void SetBorders(uint32 borders);
uint32 Borders() const;
virtual status_t SetBorderHighlighted(bool highlight); virtual status_t SetBorderHighlighted(bool highlight);
bool IsBorderHighlighted() const; bool IsBorderHighlighted() const;
@@ -111,12 +108,15 @@ private:
bool vertical, BRect targetFrame); bool vertical, BRect targetFrame);
static BRect _ComputeFrame(BRect frame, bool horizontal, static BRect _ComputeFrame(BRect frame, bool horizontal,
bool vertical, border_style border); bool vertical, border_style border,
uint32 borders);
static BRect _ComputeFrame(BView* target, bool horizontal, static BRect _ComputeFrame(BView* target, bool horizontal,
bool vertical, border_style border); bool vertical, border_style border,
uint32 borders);
static float _BorderSize(border_style border); static float _BorderSize(border_style border);
static int32 _ModifyFlags(int32 flags, border_style border); static int32 _ModifyFlags(int32 flags, border_style border);
static void _InsetBorders(BRect& frame, border_style border,
uint32 borders);
private: private:
BView* fTarget; BView* fTarget;
BScrollBar* fHorizontalScrollBar; BScrollBar* fHorizontalScrollBar;
@@ -125,8 +125,9 @@ private:
uint16 fPreviousWidth; uint16 fPreviousWidth;
uint16 fPreviousHeight; uint16 fPreviousHeight;
bool fHighlighted; bool fHighlighted;
uint32 fBorders;
uint32 _reserved[3]; uint32 _reserved[2];
}; };
#endif // _SCROLL_VIEW_H #endif // _SCROLL_VIEW_H
+5 -4
View File
@@ -41,6 +41,7 @@ of their respective holders. All rights reserved.
#include <Alert.h> #include <Alert.h>
#include <Beep.h> #include <Beep.h>
#include <Clipboard.h> #include <Clipboard.h>
#include <ControlLook.h>
#include <Debug.h> #include <Debug.h>
#include <E-mail.h> #include <E-mail.h>
#include <Input.h> #include <Input.h>
@@ -648,14 +649,14 @@ TContentView::TContentView(bool incoming, BFont* font,
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
BGroupLayout* layout = new BGroupLayout(B_VERTICAL, 0); BGroupLayout* layout = new BGroupLayout(B_VERTICAL, 0);
// TODO: control look should give us the spacing information
layout->SetInsets(-2, 0, -2, -2);
SetLayout(layout); SetLayout(layout);
fTextView = new TTextView(fIncoming, this, font, showHeader, fTextView = new TTextView(fIncoming, this, font, showHeader,
coloredQuotes); coloredQuotes);
BScrollView *scroll = new BScrollView("", fTextView, 0, true, true);
AddChild(scroll); BScrollView* scrollView = new BScrollView("", fTextView, 0, true, true);
scrollView->SetBorders(BControlLook::B_TOP_BORDER);
AddChild(scrollView);
} }
+57 -22
View File
@@ -1,7 +1,7 @@
/* /*
* Copyright 2004-2009, Axel Dörfler, axeld@pinc-software.de. * Copyright 2004-2015, Axel Dörfler, axeld@pinc-software.de.
* Copyright 2009 Stephan Aßmus, superstippi@gmx.de. * Copyright 2009 Stephan Aßmus, superstippi@gmx.de.
* Copyright 2014 Haiku, Inc. All rights reserved. * Copyright 2014-2015 Haiku, Inc. All rights reserved.
* Distributed under the terms of the MIT License. * Distributed under the terms of the MIT License.
* *
* Authors: * Authors:
@@ -29,8 +29,9 @@ static const float kPlainBorderSize = 1;
BScrollView::BScrollView(const char* name, BView* target, uint32 resizingMode, BScrollView::BScrollView(const char* name, BView* target, uint32 resizingMode,
uint32 flags, bool horizontal, bool vertical, border_style border) uint32 flags, bool horizontal, bool vertical, border_style border)
: :
BView(_ComputeFrame(target, horizontal, vertical, border), name, BView(_ComputeFrame(target, horizontal, vertical, border,
resizingMode, _ModifyFlags(flags, border)), BControlLook::B_ALL_BORDERS), name, resizingMode,
_ModifyFlags(flags, border)),
fTarget(target), fTarget(target),
fBorder(border) fBorder(border)
{ {
@@ -131,7 +132,7 @@ BScrollView::Archive(BMessage* archive, bool deep) const
// The highlighted state is not archived, but since it is // The highlighted state is not archived, but since it is
// usually (or should be) used to indicate focus, this // usually (or should be) used to indicate focus, this
// is probably the right thing to do. // is probably the right thing to do.
return status; return status;
} }
@@ -206,9 +207,9 @@ BScrollView::AttachedToWindow()
return; return;
} }
if (fHorizontalScrollBar) if (fHorizontalScrollBar != NULL)
fHorizontalScrollBar->ResizeBy(-B_V_SCROLL_BAR_WIDTH, 0); fHorizontalScrollBar->ResizeBy(-B_V_SCROLL_BAR_WIDTH, 0);
else if (fVerticalScrollBar) else if (fVerticalScrollBar != NULL)
fVerticalScrollBar->ResizeBy(0, -B_H_SCROLL_BAR_HEIGHT); fVerticalScrollBar->ResizeBy(0, -B_H_SCROLL_BAR_HEIGHT);
} }
@@ -254,7 +255,7 @@ BScrollView::Draw(BRect updateRect)
be_control_look->DrawScrollViewFrame(this, rect, updateRect, be_control_look->DrawScrollViewFrame(this, rect, updateRect,
verticalScrollBarFrame, horizontalScrollBarFrame, base, fBorder, verticalScrollBarFrame, horizontalScrollBarFrame, base, fBorder,
flags); flags, fBorders);
} }
@@ -276,7 +277,7 @@ BScrollView::FrameResized(float newWidth, float newHeight)
BRect bounds = Bounds(); BRect bounds = Bounds();
float border = _BorderSize() - 1; float border = _BorderSize() - 1;
if (be_control_look && fHorizontalScrollBar && fVerticalScrollBar) { if (fHorizontalScrollBar != NULL && fVerticalScrollBar != NULL) {
BRect scrollCorner(bounds); BRect scrollCorner(bounds);
scrollCorner.left = min_c( scrollCorner.left = min_c(
fPreviousWidth - fVerticalScrollBar->Frame().Height(), fPreviousWidth - fVerticalScrollBar->Frame().Height(),
@@ -447,10 +448,7 @@ BScrollView::SetBorder(border_style border)
SetFlags(_ModifyFlags(Flags(), border)); SetFlags(_ModifyFlags(Flags(), border));
DoLayout(); DoLayout();
Invalidate();
BRect bounds(Bounds());
Invalidate(BRect(bounds.LeftTop(), bounds.RightBottom()));
Invalidate(BRect(bounds.LeftBottom(), bounds.RightBottom()));
return; return;
} }
@@ -506,6 +504,25 @@ BScrollView::Border() const
} }
void
BScrollView::SetBorders(uint32 borders)
{
if (fBorders == borders || (Flags() & B_SUPPORTS_LAYOUT) == 0)
return;
fBorders = borders;
DoLayout();
Invalidate();
}
uint32
BScrollView::Borders() const
{
return fBorders;
}
status_t status_t
BScrollView::SetBorderHighlighted(bool highlight) BScrollView::SetBorderHighlighted(bool highlight)
{ {
@@ -565,7 +582,10 @@ BScrollView::SetTarget(BView* target)
fVerticalScrollBar->SetTarget(target); fVerticalScrollBar->SetTarget(target);
if (target != NULL) { if (target != NULL) {
target->MoveTo(_BorderSize(), _BorderSize()); float borderSize = _BorderSize();
target->MoveTo((fBorders & BControlLook::B_LEFT_BORDER) != 0
? borderSize : 0, (fBorders & BControlLook::B_TOP_BORDER) != 0
? borderSize : 0);
BRect innerFrame = _InnerFrame(); BRect innerFrame = _InnerFrame();
target->ResizeTo(innerFrame.Width() - 1, innerFrame.Height() - 1); target->ResizeTo(innerFrame.Width() - 1, innerFrame.Height() - 1);
target->TargetedByScrollView(this); target->TargetedByScrollView(this);
@@ -715,6 +735,7 @@ BScrollView::_Init(bool horizontal, bool vertical)
fHorizontalScrollBar = NULL; fHorizontalScrollBar = NULL;
fVerticalScrollBar = NULL; fVerticalScrollBar = NULL;
fHighlighted = false; fHighlighted = false;
fBorders = BControlLook::B_ALL_BORDERS;
if (be_control_look != NULL) if (be_control_look != NULL)
SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
@@ -773,9 +794,9 @@ BRect
BScrollView::_InnerFrame() const BScrollView::_InnerFrame() const
{ {
BRect frame = Bounds(); BRect frame = Bounds();
_InsetBorders(frame, fBorder, fBorders);
float borderSize = _BorderSize(); float borderSize = _BorderSize();
frame.InsetBy(borderSize, borderSize);
if (fHorizontalScrollBar != NULL) { if (fHorizontalScrollBar != NULL) {
frame.bottom -= B_H_SCROLL_BAR_HEIGHT; frame.bottom -= B_H_SCROLL_BAR_HEIGHT;
@@ -806,7 +827,7 @@ BRect
BScrollView::_ComputeFrame(BRect targetRect) const BScrollView::_ComputeFrame(BRect targetRect) const
{ {
return _ComputeFrame(targetRect, fHorizontalScrollBar != NULL, return _ComputeFrame(targetRect, fHorizontalScrollBar != NULL,
fVerticalScrollBar != NULL, fBorder); fVerticalScrollBar != NULL, fBorder, fBorders);
} }
@@ -860,17 +881,16 @@ BScrollView::_AlignScrollBars(bool horizontal, bool vertical, BRect targetFrame)
*/ */
/*static*/ BRect /*static*/ BRect
BScrollView::_ComputeFrame(BRect frame, bool horizontal, bool vertical, BScrollView::_ComputeFrame(BRect frame, bool horizontal, bool vertical,
border_style border) border_style border, uint32 borders)
{ {
if (vertical) if (vertical)
frame.right += B_V_SCROLL_BAR_WIDTH; frame.right += B_V_SCROLL_BAR_WIDTH;
if (horizontal) if (horizontal)
frame.bottom += B_H_SCROLL_BAR_HEIGHT; frame.bottom += B_H_SCROLL_BAR_HEIGHT;
float borderSize = _BorderSize(border); _InsetBorders(frame, border, borders);
frame.InsetBy(-borderSize, -borderSize);
if (borderSize == 0) { if (_BorderSize(border) == 0) {
if (vertical) if (vertical)
frame.right++; frame.right++;
if (horizontal) if (horizontal)
@@ -883,10 +903,10 @@ BScrollView::_ComputeFrame(BRect frame, bool horizontal, bool vertical,
/*static*/ BRect /*static*/ BRect
BScrollView::_ComputeFrame(BView *target, bool horizontal, bool vertical, BScrollView::_ComputeFrame(BView *target, bool horizontal, bool vertical,
border_style border) border_style border, uint32 borders)
{ {
return _ComputeFrame(target != NULL ? target->Frame() return _ComputeFrame(target != NULL ? target->Frame()
: BRect(0, 0, 16, 16), horizontal, vertical, border); : BRect(0, 0, 16, 16), horizontal, vertical, border, borders);
} }
@@ -919,6 +939,21 @@ BScrollView::_ModifyFlags(int32 flags, border_style border)
} }
/*static*/ void
BScrollView::_InsetBorders(BRect& frame, border_style border, uint32 borders)
{
float borderSize = _BorderSize(border);
if ((borders & BControlLook::B_LEFT_BORDER) != 0)
frame.left += borderSize;
if ((borders & BControlLook::B_TOP_BORDER) != 0)
frame.top += borderSize;
if ((borders & BControlLook::B_RIGHT_BORDER) != 0)
frame.right -= borderSize;
if ((borders & BControlLook::B_BOTTOM_BORDER) != 0)
frame.bottom -= borderSize;
}
// #pragma mark - FBC and forbidden // #pragma mark - FBC and forbidden