* 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

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.
*
* Authors:
* Stefano Ceccherini (burton666@libero.it)
* Ingo Weinhold (ingo_weinhold@gmx.de)
*/
@ -16,20 +17,18 @@
#include "SmartTabView.h"
#include <stdio.h>
#include <Catalog.h>
#include <Locale.h>
#include <MenuItem.h>
#include <Message.h>
#include <Messenger.h>
#include <PopUpMenu.h>
#include <Screen.h>
#include <ScrollView.h>
#include <Window.h>
#include <stdio.h>
const static uint32 kCloseTab = 'ClTb';
// #pragma mark - SmartTabView
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),
fInsets(0, 0, 0, 0),
fScrollView(NULL)
fScrollView(NULL),
fListener(NULL)
{
// 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
@ -62,8 +62,6 @@ SmartTabView::SetInsets(float left, float top, float right, float bottom)
fInsets.bottom = bottom;
}
#undef B_TRANSLATE_CONTEXT
#define B_TRANSLATE_CONTEXT "Terminal SmartTabView"
void
SmartTabView::MouseDown(BPoint point)
@ -73,22 +71,21 @@ SmartTabView::MouseDown(BPoint point)
if (CountTabs() > 1) {
int32 tabIndex = _ClickedTabIndex(point);
if (tabIndex >= 0) {
int32 buttons;
int32 buttons = 0;
int32 clickCount = 0;
Window()->CurrentMessage()->FindInt32("buttons", &buttons);
if ((buttons & B_SECONDARY_MOUSE_BUTTON) != 0) {
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);
Window()->CurrentMessage()->FindInt32("clicks", &clickCount);
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;
} else if ((buttons & B_TERTIARY_MOUSE_BUTTON) != 0) {
RemoveAndDeleteTab(tabIndex);
if (fListener != NULL)
fListener->TabMiddleClicked(this, point, tabIndex);
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
SmartTabView::Select(int32 index)
{
@ -142,20 +121,9 @@ SmartTabView::Select(int32 index)
- fInsets.left - fInsets.right,
ContainerView()->Bounds().Height() - fInsets.top - fInsets.bottom);
}
}
void
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);
if (fListener != NULL)
fListener->TabSelected(this, index);
}
@ -272,3 +240,38 @@ SmartTabView::_ClickedTabIndex(const BPoint& point)
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)
{
}

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.
*
* Authors:
* Stefano Ceccherini (burton666@libero.it)
* Ingo Weinhold (ingo_weinhold@gmx.de)
*/
#ifndef SMART_TAB_VIEW_H
#define SMART_TAB_VIEW_H
@ -17,6 +18,9 @@ class BScrollView;
class SmartTabView : public BTabView {
public:
class Listener;
public:
SmartTabView(BRect frame, const char* name,
button_width width = B_WIDTH_AS_USUAL,
@ -40,12 +44,8 @@ public:
virtual void AttachedToWindow();
virtual void AllAttached();
virtual void MessageReceived(BMessage* message);
virtual void Select(int32 tab);
virtual void RemoveAndDeleteTab(int32 index);
virtual void AddTab(BView* target, BTab* tab = NULL);
virtual BTab* RemoveTab(int32 index);
@ -53,12 +53,31 @@ public:
void SetScrollView(BScrollView* scrollView);
void SetListener(Listener* listener)
{ fListener = listener; }
private:
int32 _ClickedTabIndex(const BPoint& point);
private:
BRect fInsets;
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

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 <assimil8or@users.sourceforge.net>
* Copyright (c) 2003-2004 Kian Duffy <myob@users.sourceforge.net>
* Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
@ -24,6 +24,7 @@
#include <MenuBar.h>
#include <MenuItem.h>
#include <Path.h>
#include <PopUpMenu.h>
#include <PrintJob.h>
#include <Roster.h>
#include <Screen.h>
@ -40,7 +41,6 @@
#include "PrefWindow.h"
#include "PrefHandler.h"
#include "ShellParameters.h"
#include "SmartTabView.h"
#include "TermConst.h"
#include "TermScrollView.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,
bool isUserDefinedTitle, int32 windowIndex, uint32 workspaces,
Arguments* args)
@ -234,7 +208,8 @@ TermWindow::_InitWindow()
BRect textFrame = Bounds();
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);
// 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
TermWindow::_ResizeView(TermView *view)
{

View File

@ -36,6 +36,8 @@
#include <String.h>
#include <Window.h>
#include "SmartTabView.h"
class Arguments;
class BFont;
@ -43,12 +45,11 @@ class BMenu;
class BMenuBar;
class FindWindow;
class PrefWindow;
class SmartTabView;
class TermView;
class TermViewContainerView;
class TermWindow : public BWindow {
class TermWindow : public BWindow, private SmartTabView::Listener {
public:
TermWindow(BRect frame, const BString& title,
bool isUserDefinedTitle, int32 windowIndex,
@ -67,6 +68,16 @@ protected:
virtual void Zoom(BPoint leftTop, float width, float height);
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:
struct Title {
BString title;
@ -75,8 +86,6 @@ private:
};
struct Session;
class TabView;
friend class TabView;
void _SetTermColors(TermViewContainerView* termView);
void _InitWindow();
@ -114,7 +123,7 @@ private:
BList fSessions;
TabView* fTabView;
SmartTabView* fTabView;
TermView* fTermView;
BMenuBar* fMenubar;