Fixed various layout/size related issues (mostly off-by-one bugs). The

terminal opens with the correct size, now.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25969 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2008-06-16 01:30:10 +00:00
parent 535841fcb5
commit 272f87d67b
5 changed files with 60 additions and 30 deletions
+22 -6
View File
@@ -21,11 +21,15 @@ const static uint32 kCloseTab = 'ClTb';
SmartTabView::SmartTabView(BRect frame, const char *name, button_width width, SmartTabView::SmartTabView(BRect frame, const char *name, button_width width,
uint32 resizingMode, uint32 flags) uint32 resizingMode, uint32 flags)
: :
BTabView(frame, name, width, resizingMode, flags) BTabView(frame, name, width, resizingMode, flags),
fInsets(0, 0, 0, 0)
{ {
// See BTabView::_InitObject() to see why we are doing this // Resize the container view to fill the complete tab view for single-tab
ContainerView()->MoveBy(-3, -TabHeight() - 3); // mode. Later, when more than one tab is added, we shrink the container
ContainerView()->ResizeBy(10, TabHeight() + 9); // view again.
frame.OffsetTo(B_ORIGIN);
ContainerView()->MoveTo(frame.LeftTop());
ContainerView()->ResizeTo(frame.Width(), frame.Height());
} }
@@ -34,6 +38,16 @@ SmartTabView::~SmartTabView()
} }
void
SmartTabView::SetInsets(float left, float top, float right, float bottom)
{
fInsets.left = left;
fInsets.top = top;
fInsets.right = right;
fInsets.bottom = bottom;
}
void void
SmartTabView::MouseDown(BPoint point) SmartTabView::MouseDown(BPoint point)
{ {
@@ -106,8 +120,10 @@ SmartTabView::Select(int32 index)
BTabView::Select(index); BTabView::Select(index);
BView *view = ViewForTab(index); BView *view = ViewForTab(index);
if (view != NULL) { if (view != NULL) {
view->ResizeTo(ContainerView()->Bounds().Width(), view->MoveTo(fInsets.LeftTop());
ContainerView()->Bounds().Height()); view->ResizeTo(ContainerView()->Bounds().Width()
- fInsets.left - fInsets.right,
ContainerView()->Bounds().Height() - fInsets.top - fInsets.bottom);
} }
} }
+5
View File
@@ -21,6 +21,8 @@ public:
B_FRAME_EVENTS | B_NAVIGABLE); B_FRAME_EVENTS | B_NAVIGABLE);
virtual ~SmartTabView(); virtual ~SmartTabView();
void SetInsets(float left, float top, float right, float bottom);
virtual void MouseDown(BPoint where); virtual void MouseDown(BPoint where);
virtual void AttachedToWindow(); virtual void AttachedToWindow();
@@ -39,6 +41,9 @@ public:
private: private:
int32 _ClickedTabIndex(const BPoint &point); int32 _ClickedTabIndex(const BPoint &point);
private:
BRect fInsets;
}; };
#endif // __SMARTTABVIEW_H #endif // __SMARTTABVIEW_H
+6 -1
View File
@@ -32,13 +32,18 @@ public:
TermScrollView::TermScrollView(const char* name, BView* child, BView* target, TermScrollView::TermScrollView(const char* name, BView* child, BView* target,
uint32 resizingMode) uint32 resizingMode)
: :
BScrollView(name, child, resizingMode, 0, false, true) BScrollView(name, child, resizingMode, 0, false, true, B_NO_BORDER)
{ {
// replace the vertical scroll bar with our own // replace the vertical scroll bar with our own
if (fVerticalScrollBar != NULL) { if (fVerticalScrollBar != NULL) {
BRect frame(fVerticalScrollBar->Frame()); BRect frame(fVerticalScrollBar->Frame());
RemoveChild(fVerticalScrollBar); RemoveChild(fVerticalScrollBar);
// Overlap one pixel at the top and the bottom of the scroll bar with
// the menu respectively resize knob for aesthetical reasons.
frame.top -= 1;
frame.bottom += 1;
TermScrollBar* scrollBar = new TermScrollBar(frame, "_VSB_", target, 0, TermScrollBar* scrollBar = new TermScrollBar(frame, "_VSB_", target, 0,
1000, B_VERTICAL); 1000, B_VERTICAL);
AddChild(scrollBar); AddChild(scrollBar);
+2 -2
View File
@@ -456,9 +456,9 @@ void
TermView::GetPreferredSize(float *width, float *height) TermView::GetPreferredSize(float *width, float *height)
{ {
if (width) if (width)
*width = fTermColumns * fFontWidth; *width = fTermColumns * fFontWidth - 1;
if (height) if (height)
*height = fTermRows * fFontHeight; *height = fTermRows * fFontHeight - 1;
} }
+25 -21
View File
@@ -179,6 +179,10 @@ TermWindow::_InitWindow()
fTabView = new TabView(this, textFrame, "tab view"); fTabView = new TabView(this, textFrame, "tab view");
AddChild(fTabView); AddChild(fTabView);
// Make the scroll view one pixel wider than the tab view container view, so
// the scroll bar will look good.
fTabView->SetInsets(0, 0, -1, 0);
} }
@@ -670,10 +674,6 @@ TermWindow::_AddTab(Arguments *args)
tab->SetLabel(session->name.String()); tab->SetLabel(session->name.String());
view->SetScrollBar(scrollView->ScrollBar(B_VERTICAL)); view->SetScrollBar(scrollView->ScrollBar(B_VERTICAL));
// Resize the vertical scrollbar to take the window gripping handle into account
// TODO: shouldn't this be done in BScrollView itself ? At least BScrollBar does that.
scrollView->ScrollBar(B_VERTICAL)->ResizeBy(0, -13);
view->SetEncoding(EncodingID(PrefHandler::Default()->getString(PREF_TEXT_ENCODING))); view->SetEncoding(EncodingID(PrefHandler::Default()->getString(PREF_TEXT_ENCODING)));
BFont font; BFont font;
@@ -685,14 +685,14 @@ TermWindow::_AddTab(Arguments *args)
int width, height; int width, height;
view->GetFontSize(&width, &height); view->GetFontSize(&width, &height);
float minimumHeight = 0; float minimumHeight = -1;
if (fMenubar) if (fMenubar)
minimumHeight += fMenubar->Bounds().Height(); minimumHeight += fMenubar->Bounds().Height() + 1;
if (fTabView && fTabView->CountTabs() > 1) if (fTabView && fTabView->CountTabs() > 1)
minimumHeight += fTabView->TabHeight(); minimumHeight += fTabView->TabHeight() + 1;
SetSizeLimits(MIN_COLS * width, MAX_COLS * width, SetSizeLimits(MIN_COLS * width - 1, MAX_COLS * width - 1,
minimumHeight + MIN_ROWS * height, minimumHeight + MIN_ROWS * height - 1,
minimumHeight + MAX_ROWS * height); minimumHeight + MAX_ROWS * height - 1);
// If it's the first time we're called, setup the window // If it's the first time we're called, setup the window
if (fTabView->CountTabs() == 1) { if (fTabView->CountTabs() == 1) {
@@ -701,7 +701,9 @@ TermWindow::_AddTab(Arguments *args)
// Resize Window // Resize Window
ResizeTo(viewWidth + B_V_SCROLL_BAR_WIDTH, ResizeTo(viewWidth + B_V_SCROLL_BAR_WIDTH,
viewHeight + fMenubar->Bounds().Height()); viewHeight + fMenubar->Bounds().Height() + 1);
// NOTE: Width is one pixel too small, since the scroll view
// is one pixel wider than its parent.
} }
// TODO: No fTabView->Select(tab); ? // TODO: No fTabView->Select(tab); ?
fTabView->Select(fTabView->CountTabs() - 1); fTabView->Select(fTabView->CountTabs() - 1);
@@ -789,24 +791,26 @@ TermWindow::_ResizeView(TermView *view)
{ {
int fontWidth, fontHeight; int fontWidth, fontHeight;
view->GetFontSize(&fontWidth, &fontHeight); view->GetFontSize(&fontWidth, &fontHeight);
float minimumHeight = 0; float minimumHeight = -1;
if (fMenubar) if (fMenubar)
minimumHeight += fMenubar->Bounds().Height(); minimumHeight += fMenubar->Bounds().Height() + 1;
if (fTabView && fTabView->CountTabs() > 1) if (fTabView && fTabView->CountTabs() > 1)
minimumHeight += fTabView->TabHeight(); minimumHeight += fTabView->TabHeight() + 1;
SetSizeLimits(MIN_COLS * fontWidth, MAX_COLS * fontWidth, SetSizeLimits(MIN_COLS * fontWidth - 1, MAX_COLS * fontWidth - 1,
minimumHeight + MIN_ROWS * fontHeight, minimumHeight + MIN_ROWS * fontHeight - 1,
minimumHeight + MAX_ROWS * fontHeight); minimumHeight + MAX_ROWS * fontHeight - 1);
float width, height; float width, height;
view->Parent()->GetPreferredSize(&width, &height); view->Parent()->GetPreferredSize(&width, &height);
width += B_V_SCROLL_BAR_WIDTH; width += B_V_SCROLL_BAR_WIDTH;
height += fMenubar->Bounds().Height() + 2; // NOTE: Width is one pixel too small, since the scroll view
// is one pixel wider than its parent.
height += fMenubar->Bounds().Height() + 1;
ResizeTo(width, height); ResizeTo(width, height);
view->Invalidate(); view->Invalidate();
} }