* SmartTabView can now also resize a vertical scroll bar, if needed (ie. if one

overlaps with the menu bar). Not a perfect solution, but works well enough.
* When you only have a single tab, the vertical scroll bar now overlaps again
  with the menu bar.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33870 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2009-11-04 09:57:10 +00:00
parent 0928ac3904
commit 8fd171c8d1
5 changed files with 64 additions and 15 deletions

View File

@ -21,6 +21,7 @@
#include <Messenger.h>
#include <PopUpMenu.h>
#include <Screen.h>
#include <ScrollView.h>
#include <Window.h>
#include <stdio.h>
@ -33,7 +34,8 @@ SmartTabView::SmartTabView(BRect frame, const char* name, button_width width,
uint32 resizingMode, uint32 flags)
:
BTabView(frame, name, width, resizingMode, flags),
fInsets(0, 0, 0, 0)
fInsets(0, 0, 0, 0),
fScrollView(NULL)
{
// Resize the container view to fill the complete tab view for single-tab
// mode. Later, when more than one tab is added, we shrink the container
@ -183,13 +185,22 @@ SmartTabView::AddTab(BView* target, BTab* tab)
Window()->ResizeBy(0, TabHeight());
}
// Adapt scroll bar if there is one
if (fScrollView != NULL) {
BScrollBar* bar = fScrollView->ScrollBar(B_VERTICAL);
if (bar != NULL) {
bar->ResizeBy(0, -1);
bar->MoveBy(0, 1);
}
}
}
Invalidate(TabFrame(CountTabs() - 1).InsetByCopy(-2, -2));
}
BTab *
BTab*
SmartTabView::RemoveTab(int32 index)
{
if (CountTabs() == 2) {
@ -207,6 +218,15 @@ SmartTabView::RemoveTab(int32 index)
Window()->ResizeBy(0, -TabHeight());
}
// Adapt scroll bar if there is one
if (fScrollView != NULL) {
BScrollBar* bar = fScrollView->ScrollBar(B_VERTICAL);
if (bar != NULL) {
bar->ResizeBy(0, 1);
bar->MoveBy(0, -1);
}
}
ContainerView()->MoveBy(0, -TabHeight());
ContainerView()->ResizeBy(0, TabHeight());
}
@ -225,6 +245,16 @@ SmartTabView::DrawTabs()
}
/*! If you have a vertical scroll view that overlaps with the menu bar, it will
be resized automatically when the tabs are hidden/shown.
*/
void
SmartTabView::SetScrollView(BScrollView* scrollView)
{
fScrollView = scrollView;
}
int32
SmartTabView::_ClickedTabIndex(const BPoint& point)
{

View File

@ -13,6 +13,7 @@
class BPopUpMenu;
class BScrollView;
class SmartTabView : public BTabView {
@ -44,11 +45,14 @@ public:
virtual BRect DrawTabs();
void SetScrollView(BScrollView* scrollView);
private:
int32 _ClickedTabIndex(const BPoint& point);
private:
BRect fInsets;
BScrollView* fScrollView;
};
#endif // SMART_TAB_VIEW_H

View File

@ -12,6 +12,8 @@
#include "TermScrollView.h"
#include <Message.h>
class TermScrollBar : public BScrollBar {
public:
@ -31,7 +33,7 @@ public:
TermScrollView::TermScrollView(const char* name, BView* child, BView* target,
uint32 resizingMode)
bool overlapTop, uint32 resizingMode)
:
BScrollView(name, child, resizingMode, 0, false, true, B_NO_BORDER)
{
@ -40,8 +42,11 @@ TermScrollView::TermScrollView(const char* name, BView* child, BView* target,
BRect frame(fVerticalScrollBar->Frame());
RemoveChild(fVerticalScrollBar);
// Overlap one pixel at the bottom of the scroll bar with
// the resize knob for aesthetical reasons.
// Overlap one pixel at the top (if required) and the bottom of the
// scroll bar with the menu respectively resize knob for aesthetical
// reasons.
if (overlapTop)
frame.top--;
frame.bottom -= B_H_SCROLL_BAR_HEIGHT - 1;
TermScrollBar* scrollBar = new TermScrollBar(frame, "_VSB_", target, 0,

View File

@ -11,9 +11,9 @@
class TermScrollView : public BScrollView {
public:
TermScrollView(const char* name, BView* child,
BView* target,
BView* target, bool overlapTop,
uint32 resizingMode = B_FOLLOW_ALL);
~TermScrollView();
virtual ~TermScrollView();
};

View File

@ -425,10 +425,11 @@ TermWindow::MessageReceived(BMessage *message)
_ActiveTermView()->GetSelection(fFindString);
if (fFindString.Length() == 0) {
const char *errorMsg = (!fFindSelection) ? "No search string was entered." : "Nothing is selected.";
BAlert *alert = new BAlert("Find failed", errorMsg, "Ok", NULL,
const char* errorMsg = !fFindSelection
? "No search string was entered." : "Nothing is selected.";
BAlert* alert = new BAlert("Find failed", errorMsg, "Ok", NULL,
NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
alert->Go();
fFindPreviousMenuItem->SetEnabled(false);
fFindNextMenuItem->SetEnabled(false);
@ -752,21 +753,25 @@ TermWindow::_AddTab(Arguments *args)
TermViewContainerView *containerView = new TermViewContainerView(view);
BScrollView *scrollView = new TermScrollView("scrollView",
containerView, view);
containerView, view, fSessions.IsEmpty());
if (fSessions.IsEmpty())
fTabView->SetScrollView(scrollView);
Session* session = new Session(_NewSessionID(), containerView);
session->windowTitle = fInitialTitle;
fSessions.AddItem(session);
BTab *tab = new BTab;
// TODO: Use a better name. For example, do like MacOsX's Terminal
// and update the title using the last executed command ?
// Or like Gnome's Terminal and use the current path ?
fTabView->AddTab(scrollView, tab);
tab->SetLabel(session->name.String());
// TODO: Use a better name. For example, do like MacOS X's Terminal
// and update the title using the last executed command ?
// Or like Gnome's Terminal and use the current path ?
view->SetScrollBar(scrollView->ScrollBar(B_VERTICAL));
view->SetEncoding(EncodingID(PrefHandler::Default()->getString(PREF_TEXT_ENCODING)));
view->SetEncoding(EncodingID(
PrefHandler::Default()->getString(PREF_TEXT_ENCODING)));
BFont font;
_GetPreferredFont(font);
@ -811,6 +816,11 @@ TermWindow::_RemoveTab(int32 index)
{
if (fSessions.CountItems() > 1) {
if (Session* session = (Session*)fSessions.RemoveItem(index)) {
if (fSessions.CountItems() == 1) {
fTabView->SetScrollView(dynamic_cast<BScrollView*>(
((Session*)fSessions.ItemAt(0))->containerView->Parent()));
}
delete session;
delete fTabView->RemoveTab(index);
if (fFullScreen)