* 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:
@@ -21,6 +21,7 @@
|
|||||||
#include <Messenger.h>
|
#include <Messenger.h>
|
||||||
#include <PopUpMenu.h>
|
#include <PopUpMenu.h>
|
||||||
#include <Screen.h>
|
#include <Screen.h>
|
||||||
|
#include <ScrollView.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -33,7 +34,8 @@ 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)
|
fInsets(0, 0, 0, 0),
|
||||||
|
fScrollView(NULL)
|
||||||
{
|
{
|
||||||
// Resize the container view to fill the complete tab view for single-tab
|
// 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
|
// 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());
|
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));
|
Invalidate(TabFrame(CountTabs() - 1).InsetByCopy(-2, -2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
BTab *
|
BTab*
|
||||||
SmartTabView::RemoveTab(int32 index)
|
SmartTabView::RemoveTab(int32 index)
|
||||||
{
|
{
|
||||||
if (CountTabs() == 2) {
|
if (CountTabs() == 2) {
|
||||||
@@ -207,6 +218,15 @@ SmartTabView::RemoveTab(int32 index)
|
|||||||
Window()->ResizeBy(0, -TabHeight());
|
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()->MoveBy(0, -TabHeight());
|
||||||
ContainerView()->ResizeBy(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
|
int32
|
||||||
SmartTabView::_ClickedTabIndex(const BPoint& point)
|
SmartTabView::_ClickedTabIndex(const BPoint& point)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
|
|
||||||
class BPopUpMenu;
|
class BPopUpMenu;
|
||||||
|
class BScrollView;
|
||||||
|
|
||||||
|
|
||||||
class SmartTabView : public BTabView {
|
class SmartTabView : public BTabView {
|
||||||
@@ -44,11 +45,14 @@ public:
|
|||||||
|
|
||||||
virtual BRect DrawTabs();
|
virtual BRect DrawTabs();
|
||||||
|
|
||||||
|
void SetScrollView(BScrollView* scrollView);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int32 _ClickedTabIndex(const BPoint& point);
|
int32 _ClickedTabIndex(const BPoint& point);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BRect fInsets;
|
BRect fInsets;
|
||||||
|
BScrollView* fScrollView;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SMART_TAB_VIEW_H
|
#endif // SMART_TAB_VIEW_H
|
||||||
|
|||||||
@@ -12,6 +12,8 @@
|
|||||||
|
|
||||||
#include "TermScrollView.h"
|
#include "TermScrollView.h"
|
||||||
|
|
||||||
|
#include <Message.h>
|
||||||
|
|
||||||
|
|
||||||
class TermScrollBar : public BScrollBar {
|
class TermScrollBar : public BScrollBar {
|
||||||
public:
|
public:
|
||||||
@@ -31,7 +33,7 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
TermScrollView::TermScrollView(const char* name, BView* child, BView* target,
|
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)
|
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());
|
BRect frame(fVerticalScrollBar->Frame());
|
||||||
RemoveChild(fVerticalScrollBar);
|
RemoveChild(fVerticalScrollBar);
|
||||||
|
|
||||||
// Overlap one pixel at the bottom of the scroll bar with
|
// Overlap one pixel at the top (if required) and the bottom of the
|
||||||
// the resize knob for aesthetical reasons.
|
// scroll bar with the menu respectively resize knob for aesthetical
|
||||||
|
// reasons.
|
||||||
|
if (overlapTop)
|
||||||
|
frame.top--;
|
||||||
frame.bottom -= B_H_SCROLL_BAR_HEIGHT - 1;
|
frame.bottom -= B_H_SCROLL_BAR_HEIGHT - 1;
|
||||||
|
|
||||||
TermScrollBar* scrollBar = new TermScrollBar(frame, "_VSB_", target, 0,
|
TermScrollBar* scrollBar = new TermScrollBar(frame, "_VSB_", target, 0,
|
||||||
|
|||||||
@@ -11,9 +11,9 @@
|
|||||||
class TermScrollView : public BScrollView {
|
class TermScrollView : public BScrollView {
|
||||||
public:
|
public:
|
||||||
TermScrollView(const char* name, BView* child,
|
TermScrollView(const char* name, BView* child,
|
||||||
BView* target,
|
BView* target, bool overlapTop,
|
||||||
uint32 resizingMode = B_FOLLOW_ALL);
|
uint32 resizingMode = B_FOLLOW_ALL);
|
||||||
~TermScrollView();
|
virtual ~TermScrollView();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -425,10 +425,11 @@ TermWindow::MessageReceived(BMessage *message)
|
|||||||
_ActiveTermView()->GetSelection(fFindString);
|
_ActiveTermView()->GetSelection(fFindString);
|
||||||
|
|
||||||
if (fFindString.Length() == 0) {
|
if (fFindString.Length() == 0) {
|
||||||
const char *errorMsg = (!fFindSelection) ? "No search string was entered." : "Nothing is selected.";
|
const char* errorMsg = !fFindSelection
|
||||||
BAlert *alert = new BAlert("Find failed", errorMsg, "Ok", NULL,
|
? "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);
|
NULL, B_WIDTH_AS_USUAL, B_WARNING_ALERT);
|
||||||
|
|
||||||
alert->Go();
|
alert->Go();
|
||||||
fFindPreviousMenuItem->SetEnabled(false);
|
fFindPreviousMenuItem->SetEnabled(false);
|
||||||
fFindNextMenuItem->SetEnabled(false);
|
fFindNextMenuItem->SetEnabled(false);
|
||||||
@@ -752,21 +753,25 @@ TermWindow::_AddTab(Arguments *args)
|
|||||||
|
|
||||||
TermViewContainerView *containerView = new TermViewContainerView(view);
|
TermViewContainerView *containerView = new TermViewContainerView(view);
|
||||||
BScrollView *scrollView = new TermScrollView("scrollView",
|
BScrollView *scrollView = new TermScrollView("scrollView",
|
||||||
containerView, view);
|
containerView, view, fSessions.IsEmpty());
|
||||||
|
|
||||||
|
if (fSessions.IsEmpty())
|
||||||
|
fTabView->SetScrollView(scrollView);
|
||||||
|
|
||||||
Session* session = new Session(_NewSessionID(), containerView);
|
Session* session = new Session(_NewSessionID(), containerView);
|
||||||
session->windowTitle = fInitialTitle;
|
session->windowTitle = fInitialTitle;
|
||||||
fSessions.AddItem(session);
|
fSessions.AddItem(session);
|
||||||
|
|
||||||
BTab *tab = new BTab;
|
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);
|
fTabView->AddTab(scrollView, tab);
|
||||||
tab->SetLabel(session->name.String());
|
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->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;
|
BFont font;
|
||||||
_GetPreferredFont(font);
|
_GetPreferredFont(font);
|
||||||
@@ -811,6 +816,11 @@ TermWindow::_RemoveTab(int32 index)
|
|||||||
{
|
{
|
||||||
if (fSessions.CountItems() > 1) {
|
if (fSessions.CountItems() > 1) {
|
||||||
if (Session* session = (Session*)fSessions.RemoveItem(index)) {
|
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 session;
|
||||||
delete fTabView->RemoveTab(index);
|
delete fTabView->RemoveTab(index);
|
||||||
if (fFullScreen)
|
if (fFullScreen)
|
||||||
|
|||||||
Reference in New Issue
Block a user