* Added a listener interface to SmartTabView and moved functionality that

doesn't belong in SmartTabView to TermWindow. This also allowed to get rid of
  TermWindow::TabView.
* Also check for double clicks on tabs. No action attached yet.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39480 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2010-11-18 15:08:58 +00:00
parent d769c15ad5
commit d365030ea5
4 changed files with 136 additions and 91 deletions
+55 -52
View File
@@ -1,9 +1,10 @@
/* /*
* Copyright 2007-2009, Haiku. All rights reserved. * Copyright 2007-2010, 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])
* Ingo Weinhold ([email protected])
*/ */
@@ -16,20 +17,18 @@
#include "SmartTabView.h" #include "SmartTabView.h"
#include <stdio.h>
#include <Catalog.h> #include <Catalog.h>
#include <Locale.h> #include <Locale.h>
#include <MenuItem.h>
#include <Message.h> #include <Message.h>
#include <Messenger.h> #include <Messenger.h>
#include <PopUpMenu.h>
#include <Screen.h> #include <Screen.h>
#include <ScrollView.h> #include <ScrollView.h>
#include <Window.h> #include <Window.h>
#include <stdio.h>
// #pragma mark - SmartTabView
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,
@@ -37,7 +36,8 @@ SmartTabView::SmartTabView(BRect frame, const char* name, button_width width,
: :
BTabView(frame, name, width, resizingMode, flags), BTabView(frame, name, width, resizingMode, flags),
fInsets(0, 0, 0, 0), fInsets(0, 0, 0, 0),
fScrollView(NULL) fScrollView(NULL),
fListener(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
@@ -62,8 +62,6 @@ SmartTabView::SetInsets(float left, float top, float right, float bottom)
fInsets.bottom = bottom; fInsets.bottom = bottom;
} }
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "Terminal SmartTabView"
void void
SmartTabView::MouseDown(BPoint point) SmartTabView::MouseDown(BPoint point)
@@ -73,22 +71,21 @@ 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 = 0;
int32 clickCount = 0;
Window()->CurrentMessage()->FindInt32("buttons", &buttons); Window()->CurrentMessage()->FindInt32("buttons", &buttons);
if ((buttons & B_SECONDARY_MOUSE_BUTTON) != 0) { Window()->CurrentMessage()->FindInt32("clicks", &clickCount);
BMessage* message = new BMessage(kCloseTab);
message->AddInt32("index", tabIndex);
BPopUpMenu* popUpMenu = new BPopUpMenu("tab menu");
popUpMenu->AddItem(new BMenuItem(B_TRANSLATE("Close tab"),
message));
popUpMenu->SetAsyncAutoDestruct(true);
popUpMenu->SetTargetForItems(BMessenger(this));
popUpMenu->Go(ConvertToScreen(point), true, true, true);
if ((buttons & B_PRIMARY_MOUSE_BUTTON) != 0 && clickCount == 2) {
if (fListener != NULL)
fListener->TabDoubleClicked(this, point, tabIndex);
} else if ((buttons & B_SECONDARY_MOUSE_BUTTON) != 0) {
if (fListener != NULL)
fListener->TabRightClicked(this, point, tabIndex);
handled = true; handled = true;
} else if ((buttons & B_TERTIARY_MOUSE_BUTTON) != 0) { } else if ((buttons & B_TERTIARY_MOUSE_BUTTON) != 0) {
RemoveAndDeleteTab(tabIndex); if (fListener != NULL)
fListener->TabMiddleClicked(this, point, tabIndex);
handled = true; handled = true;
} }
} }
@@ -113,24 +110,6 @@ SmartTabView::AllAttached()
} }
void
SmartTabView::MessageReceived(BMessage *message)
{
switch (message->what) {
case kCloseTab:
{
int32 tabIndex = 0;
if (message->FindInt32("index", &tabIndex) == B_OK)
RemoveAndDeleteTab(tabIndex);
break;
}
default:
BTabView::MessageReceived(message);
break;
}
}
void void
SmartTabView::Select(int32 index) SmartTabView::Select(int32 index)
{ {
@@ -142,20 +121,9 @@ SmartTabView::Select(int32 index)
- fInsets.left - fInsets.right, - fInsets.left - fInsets.right,
ContainerView()->Bounds().Height() - fInsets.top - fInsets.bottom); ContainerView()->Bounds().Height() - fInsets.top - fInsets.bottom);
} }
}
if (fListener != NULL)
void fListener->TabSelected(this, index);
SmartTabView::RemoveAndDeleteTab(int32 index)
{
// Select another tab
if (index == Selection()) {
if (index > 0)
Select(index - 1);
else if (index < CountTabs())
Select(index + 1);
}
delete RemoveTab(index);
} }
@@ -272,3 +240,38 @@ SmartTabView::_ClickedTabIndex(const BPoint& point)
return -1; return -1;
} }
// #pragma mark - Listener
SmartTabView::Listener::~Listener()
{
}
void
SmartTabView::Listener::TabSelected(SmartTabView* tabView, int32 index)
{
}
void
SmartTabView::Listener::TabDoubleClicked(SmartTabView* tabView, BPoint point,
int32 index)
{
}
void
SmartTabView::Listener::TabMiddleClicked(SmartTabView* tabView, BPoint point,
int32 index)
{
}
void
SmartTabView::Listener::TabRightClicked(SmartTabView* tabView, BPoint point,
int32 index)
{
}
+24 -5
View File
@@ -1,9 +1,10 @@
/* /*
* Copyright 2007-2009, Haiku. All rights reserved. * Copyright 2007-2010, 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])
* Ingo Weinhold ([email protected])
*/ */
#ifndef SMART_TAB_VIEW_H #ifndef SMART_TAB_VIEW_H
#define SMART_TAB_VIEW_H #define SMART_TAB_VIEW_H
@@ -17,6 +18,9 @@ class BScrollView;
class SmartTabView : public BTabView { class SmartTabView : public BTabView {
public:
class Listener;
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,
@@ -40,12 +44,8 @@ public:
virtual void AttachedToWindow(); virtual void AttachedToWindow();
virtual void AllAttached(); virtual void AllAttached();
virtual void MessageReceived(BMessage* message);
virtual void Select(int32 tab); virtual void Select(int32 tab);
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);
@@ -53,12 +53,31 @@ public:
void SetScrollView(BScrollView* scrollView); void SetScrollView(BScrollView* scrollView);
void SetListener(Listener* listener)
{ fListener = listener; }
private: private:
int32 _ClickedTabIndex(const BPoint& point); int32 _ClickedTabIndex(const BPoint& point);
private: private:
BRect fInsets; BRect fInsets;
BScrollView* fScrollView; BScrollView* fScrollView;
Listener* fListener;
}; };
class SmartTabView::Listener {
public:
virtual ~Listener();
virtual void TabSelected(SmartTabView* tabView, int32 index);
virtual void TabDoubleClicked(SmartTabView* tabView,
BPoint point, int32 index);
virtual void TabMiddleClicked(SmartTabView* tabView,
BPoint point, int32 index);
virtual void TabRightClicked(SmartTabView* tabView,
BPoint point, int32 index);
};
#endif // SMART_TAB_VIEW_H #endif // SMART_TAB_VIEW_H
+43 -29
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2007-2009, Haiku, Inc. All rights reserved. * Copyright 2007-2010, Haiku, Inc. All rights reserved.
* Copyright (c) 2004 Daniel Furrer <[email protected]> * Copyright (c) 2004 Daniel Furrer <[email protected]>
* Copyright (c) 2003-2004 Kian Duffy <[email protected]> * Copyright (c) 2003-2004 Kian Duffy <[email protected]>
* Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. * Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
@@ -24,6 +24,7 @@
#include <MenuBar.h> #include <MenuBar.h>
#include <MenuItem.h> #include <MenuItem.h>
#include <Path.h> #include <Path.h>
#include <PopUpMenu.h>
#include <PrintJob.h> #include <PrintJob.h>
#include <Roster.h> #include <Roster.h>
#include <Screen.h> #include <Screen.h>
@@ -40,7 +41,6 @@
#include "PrefWindow.h" #include "PrefWindow.h"
#include "PrefHandler.h" #include "PrefHandler.h"
#include "ShellParameters.h" #include "ShellParameters.h"
#include "SmartTabView.h"
#include "TermConst.h" #include "TermConst.h"
#include "TermScrollView.h" #include "TermScrollView.h"
#include "TermView.h" #include "TermView.h"
@@ -117,32 +117,6 @@ struct TermWindow::Session {
}; };
class TermWindow::TabView : public SmartTabView {
public:
TabView(TermWindow* window, BRect frame, const char *name,
button_width width)
:
SmartTabView(frame, name, width),
fWindow(window)
{
}
virtual void Select(int32 tab)
{
SmartTabView::Select(tab);
fWindow->SessionChanged();
}
virtual void RemoveAndDeleteTab(int32 index)
{
fWindow->_RemoveTab(index);
}
private:
TermWindow* fWindow;
};
TermWindow::TermWindow(BRect frame, const BString& title, TermWindow::TermWindow(BRect frame, const BString& title,
bool isUserDefinedTitle, int32 windowIndex, uint32 workspaces, bool isUserDefinedTitle, int32 windowIndex, uint32 workspaces,
Arguments* args) Arguments* args)
@@ -234,7 +208,8 @@ TermWindow::_InitWindow()
BRect textFrame = Bounds(); BRect textFrame = Bounds();
textFrame.top = fMenubar->Bounds().bottom + 1.0; textFrame.top = fMenubar->Bounds().bottom + 1.0;
fTabView = new TabView(this, textFrame, "tab view", B_WIDTH_FROM_WIDEST); fTabView = new SmartTabView(textFrame, "tab view", B_WIDTH_FROM_WIDEST);
fTabView->SetListener(this);
AddChild(fTabView); AddChild(fTabView);
// Make the scroll view one pixel wider than the tab view container view, so // Make the scroll view one pixel wider than the tab view container view, so
@@ -1044,6 +1019,45 @@ TermWindow::FrameResized(float newWidth, float newHeight)
} }
void
TermWindow::TabSelected(SmartTabView* tabView, int32 index)
{
SessionChanged();
}
void
TermWindow::TabDoubleClicked(SmartTabView* tabView, BPoint point, int32 index)
{
// TODO:...
}
void
TermWindow::TabMiddleClicked(SmartTabView* tabView, BPoint point, int32 index)
{
_RemoveTab(index);
}
void
TermWindow::TabRightClicked(SmartTabView* tabView, BPoint point, int32 index)
{
TermView* termView = _TermViewAt(index);
if (termView == NULL)
return;
BMessage* message = new BMessage(kCloseView);
message->AddPointer("termview", termView);
BPopUpMenu* popUpMenu = new BPopUpMenu("tab menu");
popUpMenu->AddItem(new BMenuItem(B_TRANSLATE("Close tab"), message));
popUpMenu->SetAsyncAutoDestruct(true);
popUpMenu->SetTargetForItems(BMessenger(this));
popUpMenu->Go(tabView->ConvertToScreen(point), true, true, true);
}
void void
TermWindow::_ResizeView(TermView *view) TermWindow::_ResizeView(TermView *view)
{ {
+14 -5
View File
@@ -36,6 +36,8 @@
#include <String.h> #include <String.h>
#include <Window.h> #include <Window.h>
#include "SmartTabView.h"
class Arguments; class Arguments;
class BFont; class BFont;
@@ -43,12 +45,11 @@ class BMenu;
class BMenuBar; class BMenuBar;
class FindWindow; class FindWindow;
class PrefWindow; class PrefWindow;
class SmartTabView;
class TermView; class TermView;
class TermViewContainerView; class TermViewContainerView;
class TermWindow : public BWindow { class TermWindow : public BWindow, private SmartTabView::Listener {
public: public:
TermWindow(BRect frame, const BString& title, TermWindow(BRect frame, const BString& title,
bool isUserDefinedTitle, int32 windowIndex, bool isUserDefinedTitle, int32 windowIndex,
@@ -67,6 +68,16 @@ protected:
virtual void Zoom(BPoint leftTop, float width, float height); virtual void Zoom(BPoint leftTop, float width, float height);
virtual void FrameResized(float newWidth, float newHeight); virtual void FrameResized(float newWidth, float newHeight);
private:
// SmartTabView::Listener
virtual void TabSelected(SmartTabView* tabView, int32 index);
virtual void TabDoubleClicked(SmartTabView* tabView,
BPoint point, int32 index);
virtual void TabMiddleClicked(SmartTabView* tabView,
BPoint point, int32 index);
virtual void TabRightClicked(SmartTabView* tabView,
BPoint point, int32 index);
private: private:
struct Title { struct Title {
BString title; BString title;
@@ -75,8 +86,6 @@ private:
}; };
struct Session; struct Session;
class TabView;
friend class TabView;
void _SetTermColors(TermViewContainerView* termView); void _SetTermColors(TermViewContainerView* termView);
void _InitWindow(); void _InitWindow();
@@ -114,7 +123,7 @@ private:
BList fSessions; BList fSessions;
TabView* fTabView; SmartTabView* fTabView;
TermView* fTermView; TermView* fTermView;
BMenuBar* fMenubar; BMenuBar* fMenubar;