* Removed BeOS work-around in TermScrollView.cpp.
* Improved comments. * Coding style cleanup, no functional change. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@33869 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -6,6 +6,14 @@
|
|||||||
* Stefano Ceccherini ([email protected])
|
* Stefano Ceccherini ([email protected])
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
/*! The SmartTabView class is a BTabView descendant that hides the tab bar
|
||||||
|
as long as there is only a single tab.
|
||||||
|
Furthermore, it provides a tab context menu, as well as allowing you to
|
||||||
|
close buttons with the middle mouse button.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "SmartTabView.h"
|
#include "SmartTabView.h"
|
||||||
|
|
||||||
#include <MenuItem.h>
|
#include <MenuItem.h>
|
||||||
@@ -17,10 +25,12 @@
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
|
||||||
const static uint32 kCloseTab = 'ClTb';
|
const static uint32 kCloseTab = 'ClTb';
|
||||||
|
|
||||||
SmartTabView::SmartTabView(BRect frame, const char *name, button_width width,
|
|
||||||
uint32 resizingMode, uint32 flags)
|
SmartTabView::SmartTabView(BRect frame, const char* name, button_width width,
|
||||||
|
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)
|
||||||
@@ -56,30 +66,29 @@ SmartTabView::MouseDown(BPoint point)
|
|||||||
|
|
||||||
if (CountTabs() > 1) {
|
if (CountTabs() > 1) {
|
||||||
int32 tabIndex = _ClickedTabIndex(point);
|
int32 tabIndex = _ClickedTabIndex(point);
|
||||||
if (tabIndex >= 0) {
|
if (tabIndex >= 0) {
|
||||||
int32 buttons;
|
int32 buttons;
|
||||||
Window()->CurrentMessage()->FindInt32("buttons", &buttons);
|
Window()->CurrentMessage()->FindInt32("buttons", &buttons);
|
||||||
if (buttons & B_SECONDARY_MOUSE_BUTTON) {
|
if ((buttons & B_SECONDARY_MOUSE_BUTTON) != 0) {
|
||||||
BMessage *message = new BMessage(kCloseTab);
|
BMessage* message = new BMessage(kCloseTab);
|
||||||
message->AddInt32("index", tabIndex);
|
message->AddInt32("index", tabIndex);
|
||||||
|
|
||||||
BPopUpMenu *popUpMenu = new BPopUpMenu("tab menu");
|
BPopUpMenu* popUpMenu = new BPopUpMenu("tab menu");
|
||||||
popUpMenu->AddItem(new BMenuItem("Close Tab", message));
|
popUpMenu->AddItem(new BMenuItem("Close Tab", message));
|
||||||
popUpMenu->SetAsyncAutoDestruct(true);
|
popUpMenu->SetAsyncAutoDestruct(true);
|
||||||
popUpMenu->SetTargetForItems(BMessenger(this));
|
popUpMenu->SetTargetForItems(BMessenger(this));
|
||||||
popUpMenu->Go(ConvertToScreen(point), true, true, true);
|
popUpMenu->Go(ConvertToScreen(point), true, true, true);
|
||||||
|
|
||||||
handled = true;
|
handled = true;
|
||||||
} else if (buttons & B_TERTIARY_MOUSE_BUTTON) {
|
} else if ((buttons & B_TERTIARY_MOUSE_BUTTON) != 0) {
|
||||||
RemoveAndDeleteTab(tabIndex);
|
RemoveAndDeleteTab(tabIndex);
|
||||||
handled = true;
|
handled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!handled)
|
if (!handled)
|
||||||
BTabView::MouseDown(point);
|
BTabView::MouseDown(point);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -107,10 +116,10 @@ SmartTabView::MessageReceived(BMessage *message)
|
|||||||
if (message->FindInt32("index", &tabIndex) == B_OK)
|
if (message->FindInt32("index", &tabIndex) == B_OK)
|
||||||
RemoveAndDeleteTab(tabIndex);
|
RemoveAndDeleteTab(tabIndex);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
BTabView::MessageReceived(message);
|
BTabView::MessageReceived(message);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,30 +147,32 @@ SmartTabView::RemoveAndDeleteTab(int32 index)
|
|||||||
Select(index - 1);
|
Select(index - 1);
|
||||||
else if (index < CountTabs())
|
else if (index < CountTabs())
|
||||||
Select(index + 1);
|
Select(index + 1);
|
||||||
}
|
}
|
||||||
delete RemoveTab(index);
|
delete RemoveTab(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SmartTabView::AddTab(BView *target, BTab *tab)
|
SmartTabView::AddTab(BView* target, BTab* tab)
|
||||||
{
|
{
|
||||||
if (target == NULL)
|
if (target == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
BTabView::AddTab(target, tab);
|
BTabView::AddTab(target, tab);
|
||||||
|
|
||||||
if (CountTabs() == 1) {
|
if (CountTabs() == 1) {
|
||||||
// Call select on the tab, since
|
// Call select on the tab, since
|
||||||
// we're resizing the contained view
|
// we're resizing the contained view
|
||||||
// inside that function
|
// inside that function
|
||||||
Select(0);
|
Select(0);
|
||||||
} else if (CountTabs() == 2) {
|
} else if (CountTabs() == 2) {
|
||||||
// Need to resize the view, since we're
|
// Need to resize the view, since we're switching from "normal"
|
||||||
// switching from "normal" to tabbed mode
|
// to tabbed mode
|
||||||
ContainerView()->ResizeBy(0, -TabHeight());
|
ContainerView()->ResizeBy(0, -TabHeight());
|
||||||
ContainerView()->MoveBy(0, TabHeight());
|
ContainerView()->MoveBy(0, TabHeight());
|
||||||
|
|
||||||
|
// Make sure the content size stays the same, but take special care
|
||||||
|
// of full screen mode
|
||||||
BScreen screen(Window());
|
BScreen screen(Window());
|
||||||
if (Window()->DecoratorFrame().Height() + 2 * TabHeight()
|
if (Window()->DecoratorFrame().Height() + 2 * TabHeight()
|
||||||
< screen.Frame().Height()) {
|
< screen.Frame().Height()) {
|
||||||
@@ -169,11 +180,11 @@ SmartTabView::AddTab(BView *target, BTab *tab)
|
|||||||
> screen.Frame().bottom - 5) {
|
> screen.Frame().bottom - 5) {
|
||||||
Window()->MoveBy(0, -TabHeight());
|
Window()->MoveBy(0, -TabHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
Window()->ResizeBy(0, TabHeight());
|
Window()->ResizeBy(0, TabHeight());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Invalidate(TabFrame(CountTabs() - 1).InsetByCopy(-2, -2));
|
Invalidate(TabFrame(CountTabs() - 1).InsetByCopy(-2, -2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,7 +193,10 @@ BTab *
|
|||||||
SmartTabView::RemoveTab(int32 index)
|
SmartTabView::RemoveTab(int32 index)
|
||||||
{
|
{
|
||||||
if (CountTabs() == 2) {
|
if (CountTabs() == 2) {
|
||||||
// see AddTab()
|
// Hide the tab bar again by resizing the container view
|
||||||
|
|
||||||
|
// Make sure the content size stays the same, but take special care
|
||||||
|
// of full screen mode
|
||||||
BScreen screen(Window());
|
BScreen screen(Window());
|
||||||
if (Window()->DecoratorFrame().Height() + 2 * TabHeight()
|
if (Window()->DecoratorFrame().Height() + 2 * TabHeight()
|
||||||
< screen.Frame().Height()) {
|
< screen.Frame().Height()) {
|
||||||
@@ -193,9 +207,10 @@ SmartTabView::RemoveTab(int32 index)
|
|||||||
Window()->ResizeBy(0, -TabHeight());
|
Window()->ResizeBy(0, -TabHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
ContainerView()->MoveBy(0, -TabHeight());
|
ContainerView()->MoveBy(0, -TabHeight());
|
||||||
ContainerView()->ResizeBy(0, TabHeight());
|
ContainerView()->ResizeBy(0, TabHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
return BTabView::RemoveTab(index);
|
return BTabView::RemoveTab(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,12 +220,13 @@ SmartTabView::DrawTabs()
|
|||||||
{
|
{
|
||||||
if (CountTabs() > 1)
|
if (CountTabs() > 1)
|
||||||
return BTabView::DrawTabs();
|
return BTabView::DrawTabs();
|
||||||
|
|
||||||
return BRect();
|
return BRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int32
|
int32
|
||||||
SmartTabView::_ClickedTabIndex(const BPoint &point)
|
SmartTabView::_ClickedTabIndex(const BPoint& point)
|
||||||
{
|
{
|
||||||
if (point.y <= TabHeight()) {
|
if (point.y <= TabHeight()) {
|
||||||
for (int32 i = 0; i < CountTabs(); i++) {
|
for (int32 i = 0; i < CountTabs(); i++) {
|
||||||
|
|||||||
@@ -1,50 +1,54 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2007, Haiku. All rights reserved.
|
* Copyright 2007-2009, Haiku. All rights reserved.
|
||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*
|
*
|
||||||
* Authors:
|
* Authors:
|
||||||
* Stefano Ceccherini ([email protected])
|
* Stefano Ceccherini ([email protected])
|
||||||
*/
|
*/
|
||||||
#ifndef __SMARTTABVIEW_H
|
#ifndef SMART_TAB_VIEW_H
|
||||||
#define __SMARTTABVIEW_H
|
#define SMART_TAB_VIEW_H
|
||||||
|
|
||||||
|
|
||||||
#include <TabView.h>
|
#include <TabView.h>
|
||||||
|
|
||||||
|
|
||||||
class BPopUpMenu;
|
class BPopUpMenu;
|
||||||
|
|
||||||
|
|
||||||
class SmartTabView : public BTabView {
|
class SmartTabView : public BTabView {
|
||||||
public:
|
public:
|
||||||
SmartTabView(BRect frame, const char *name,
|
SmartTabView(BRect frame, const char* name,
|
||||||
button_width width = B_WIDTH_AS_USUAL,
|
button_width width = B_WIDTH_AS_USUAL,
|
||||||
uint32 resizingMode = B_FOLLOW_ALL,
|
uint32 resizingMode = B_FOLLOW_ALL,
|
||||||
uint32 flags = B_FULL_UPDATE_ON_RESIZE |
|
uint32 flags = B_FULL_UPDATE_ON_RESIZE
|
||||||
B_WILL_DRAW | B_NAVIGABLE_JUMP |
|
| B_WILL_DRAW | B_NAVIGABLE_JUMP
|
||||||
B_FRAME_EVENTS | B_NAVIGABLE);
|
| B_FRAME_EVENTS | B_NAVIGABLE);
|
||||||
virtual ~SmartTabView();
|
virtual ~SmartTabView();
|
||||||
|
|
||||||
void SetInsets(float left, float top, float right, float bottom);
|
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();
|
||||||
virtual void AllAttached();
|
virtual void AllAttached();
|
||||||
|
|
||||||
virtual void MessageReceived(BMessage *message);
|
virtual void MessageReceived(BMessage* message);
|
||||||
|
|
||||||
virtual void Select(int32 tab);
|
virtual void Select(int32 tab);
|
||||||
|
|
||||||
virtual void RemoveAndDeleteTab(int32 index);
|
virtual void RemoveAndDeleteTab(int32 index);
|
||||||
|
|
||||||
virtual void AddTab(BView *target, BTab *tab = NULL);
|
virtual void AddTab(BView* target, BTab* tab = NULL);
|
||||||
virtual BTab* RemoveTab(int32 index);
|
virtual BTab* RemoveTab(int32 index);
|
||||||
|
|
||||||
virtual BRect DrawTabs();
|
virtual BRect DrawTabs();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int32 _ClickedTabIndex(const BPoint &point);
|
int32 _ClickedTabIndex(const BPoint& point);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
BRect fInsets;
|
BRect fInsets;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __SMARTTABVIEW_H
|
#endif // SMART_TAB_VIEW_H
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
* Distributed under the terms of the MIT License.
|
* Distributed under the terms of the MIT License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// NOTE: Nasty hack to get access to BScrollView's private parts.
|
// NOTE: Nasty hack to get access to BScrollView's private parts.
|
||||||
#include <ScrollBar.h>
|
#include <ScrollBar.h>
|
||||||
#define private protected
|
#define private protected
|
||||||
@@ -11,9 +12,6 @@
|
|||||||
|
|
||||||
#include "TermScrollView.h"
|
#include "TermScrollView.h"
|
||||||
|
|
||||||
#ifndef __HAIKU__
|
|
||||||
#define fVerticalScrollBar fVSB
|
|
||||||
#endif
|
|
||||||
|
|
||||||
class TermScrollBar : public BScrollBar {
|
class TermScrollBar : public BScrollBar {
|
||||||
public:
|
public:
|
||||||
|
|||||||
Reference in New Issue
Block a user