* 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:
Axel Dörfler
2009-11-04 08:52:06 +00:00
parent d08a8df7ca
commit 0928ac3904
3 changed files with 71 additions and 53 deletions
+28 -12
View File
@@ -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)
@@ -59,18 +69,18 @@ SmartTabView::MouseDown(BPoint 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;
} }
@@ -79,7 +89,6 @@ SmartTabView::MouseDown(BPoint point)
if (!handled) if (!handled)
BTabView::MouseDown(point); BTabView::MouseDown(point);
} }
@@ -144,7 +153,7 @@ SmartTabView::RemoveAndDeleteTab(int32 index)
void void
SmartTabView::AddTab(BView *target, BTab *tab) SmartTabView::AddTab(BView* target, BTab* tab)
{ {
if (target == NULL) if (target == NULL)
return; return;
@@ -157,11 +166,13 @@ SmartTabView::AddTab(BView *target, BTab *tab)
// 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()) {
@@ -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()) {
@@ -196,6 +210,7 @@ SmartTabView::RemoveTab(int32 index)
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++) {
+28 -24
View File
@@ -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
+1 -3
View File
@@ -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: