* 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
+22 -6
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,8 +25,10 @@
#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, SmartTabView::SmartTabView(BRect frame, const char* name, button_width width,
uint32 resizingMode, uint32 flags) uint32 resizingMode, uint32 flags)
: :
@@ -59,7 +69,7 @@ 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);
@@ -70,7 +80,7 @@ SmartTabView::MouseDown(BPoint point)
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);
} }
@@ -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,6 +220,7 @@ SmartTabView::DrawTabs()
{ {
if (CountTabs() > 1) if (CountTabs() > 1)
return BTabView::DrawTabs(); return BTabView::DrawTabs();
return BRect(); return BRect();
} }
+13 -9
View File
@@ -1,27 +1,32 @@
/* /*
* 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);
@@ -46,5 +51,4 @@ 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: