diff --git a/src/apps/terminal/Jamfile b/src/apps/terminal/Jamfile index 7a68a26b08..0cdfb7e4f6 100644 --- a/src/apps/terminal/Jamfile +++ b/src/apps/terminal/Jamfile @@ -16,6 +16,7 @@ Application Terminal : PrefView.cpp PrefWindow.cpp Shell.cpp + SmartTabView.cpp TermApp.cpp TermBuffer.cpp TermParse.cpp diff --git a/src/apps/terminal/Shell.cpp b/src/apps/terminal/Shell.cpp index 0d53785455..4edd17955d 100644 --- a/src/apps/terminal/Shell.cpp +++ b/src/apps/terminal/Shell.cpp @@ -172,12 +172,12 @@ Shell::~Shell() status_t -Shell::Open(int row, int col, const char *command, const char *coding) +Shell::Open(int row, int col, const char *command, const char *encoding) { if (fFd >= 0) return B_ERROR; - status_t status = _Spawn(row, col, command, coding); + status_t status = _Spawn(row, col, command, encoding); if (status < B_OK) return status; @@ -314,7 +314,7 @@ receive_handshake_message(handshake_t& handshake) status_t -Shell::_Spawn(int row, int col, const char *command, const char *coding) +Shell::_Spawn(int row, int col, const char *command, const char *encoding) { signal(SIGTTOU, SIG_IGN); @@ -536,7 +536,7 @@ Shell::_Spawn(int row, int col, const char *command, const char *coding) */ setenv("TERM", "beterm", true); setenv("TTY", ttyName, true); - setenv("TTYPE", coding, true); + setenv("TTYPE", encoding, true); /* * If don't set command args, exec SHELL_COMMAND. diff --git a/src/apps/terminal/Shell.h b/src/apps/terminal/Shell.h index f6497ff426..5c836ddf3e 100644 --- a/src/apps/terminal/Shell.h +++ b/src/apps/terminal/Shell.h @@ -3,33 +3,13 @@ * Copyright (c) 2003-4 Kian Duffy * Copyright (c) 2004 Daniel Furrer * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files or portions - * thereof (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, - * publish, distribute, sublicense, and/or sell copies of the Software, - * and to permit persons to whom the Software is furnished to do so, subject - * to the following conditions: - * - * * Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * - * * Redistributions in binary form must reproduce the above copyright notice - * in the binary, as well as this list of conditions and the following - * disclaimer in the documentation and/or other materials provided with - * the distribution. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * + * Distributed under the terms of the MIT License. + * Authors: + * Stefano Ceccherini + * Kian Duffy + * Kazuho Okui + * Takashi Murai */ - #ifndef _SHELL_H #define _SHELL_H diff --git a/src/apps/terminal/SmartTabView.cpp b/src/apps/terminal/SmartTabView.cpp new file mode 100644 index 0000000000..94fb80d2dc --- /dev/null +++ b/src/apps/terminal/SmartTabView.cpp @@ -0,0 +1,35 @@ +/* + * Copyright 2007, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Stefano Ceccherini (burton666@libero.it) + */ + +#include "SmartTabView.h" + +SmartTabView::SmartTabView(BRect frame, const char *name, button_width width, + uint32 resizingMode, uint32 flags) + : + BTabView(frame, name, width, resizingMode, flags) +{ +} + + +SmartTabView::~SmartTabView() +{ +} + + +void +SmartTabView::Select(int32 index) +{ + BTabView::Select(index); + BTab *tab = TabAt(Selection()); + if (tab != NULL) { + BView *view = tab->View(); + if (view != NULL) + view->ResizeTo(Bounds().Width(), Bounds().Height()); + } +} + diff --git a/src/apps/terminal/SmartTabView.h b/src/apps/terminal/SmartTabView.h new file mode 100644 index 0000000000..741830321a --- /dev/null +++ b/src/apps/terminal/SmartTabView.h @@ -0,0 +1,28 @@ +/* + * Copyright 2007, Haiku. All rights reserved. + * Distributed under the terms of the MIT License. + * + * Authors: + * Stefano Ceccherini (burton666@libero.it) + */ + +#ifndef __SMARTTABVIEW_H +#define __SMARTTABVIEW_H + +#include + +class SmartTabView : public BTabView { +public: + SmartTabView(BRect frame, const char *name, + button_width width = B_WIDTH_AS_USUAL, + uint32 resizingMode = B_FOLLOW_ALL, + uint32 flags = B_FULL_UPDATE_ON_RESIZE | + B_WILL_DRAW | B_NAVIGABLE_JUMP | + B_FRAME_EVENTS | B_NAVIGABLE); + virtual ~SmartTabView(); + virtual void Select(int32 tab); + +}; + +#endif // __SMARTTABVIEW_H + diff --git a/src/apps/terminal/TermBuffer.cpp b/src/apps/terminal/TermBuffer.cpp index 5a60e5ea8b..6fa6b0c1aa 100644 --- a/src/apps/terminal/TermBuffer.cpp +++ b/src/apps/terminal/TermBuffer.cpp @@ -87,11 +87,10 @@ but it font is full width font on preference panel. #include -#define ARRAY_SIZE 512 #define ROW(x) (((x) + fRowOffset) % fBufferSize) -TermBuffer::TermBuffer(int rows, int cols) +TermBuffer::TermBuffer(int rows, int cols, int bufferSize) { if (rows < 1) rows = 1; @@ -109,7 +108,7 @@ TermBuffer::TermBuffer(int rows, int cols) fSelStart.Set(-1,-1); fSelEnd.Set(-1,-1); - fBufferSize = PrefHandler::Default()->getInt32(PREF_HISTORY_SIZE); + fBufferSize = bufferSize; if (fBufferSize < 1000) fBufferSize = 1000; diff --git a/src/apps/terminal/TermBuffer.h b/src/apps/terminal/TermBuffer.h index 3944452f3a..c3388a785e 100644 --- a/src/apps/terminal/TermBuffer.h +++ b/src/apps/terminal/TermBuffer.h @@ -30,10 +30,10 @@ #ifndef _TERMBUFFER_H #define _TERMBUFFER_H -#include -#include "TermConst.h" #include "CurPos.h" +#include "TermConst.h" +#include struct term_buffer @@ -49,7 +49,7 @@ class BString; class TermBuffer { public: - TermBuffer(int row, int col); + TermBuffer(int row, int col, int bufferSize = 1000); ~TermBuffer(); // diff --git a/src/apps/terminal/TermParse.cpp b/src/apps/terminal/TermParse.cpp index 1eec44c92b..577894699f 100644 --- a/src/apps/terminal/TermParse.cpp +++ b/src/apps/terminal/TermParse.cpp @@ -20,6 +20,7 @@ #include #include #include +#include ////////////////////////////////////////////////////////////////////////////// diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index 16e2fc18b5..60b732e576 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -31,9 +31,11 @@ #include #include #include +#include #include #include #include +#include #include #include @@ -134,7 +136,7 @@ TermView::TermView(BRect frame, const char *command) fTermColumns(PrefHandler::Default()->getInt32(PREF_COLS)), fEncoding(M_UTF8), fTop(0), - fTextBuffer(new (nothrow) TermBuffer(fTermRows, fTermColumns)), + fTextBuffer(NULL), fScrollBar(NULL), fScrTop(0), fScrBot(fTermRows - 1), @@ -156,17 +158,17 @@ TermView::TermView(BRect frame, const char *command) void TermView::_InitObject(const char *command) { + fTextBuffer = new TermBuffer(fTermRows, fTermColumns, fScrBufSize); + SetMouseCursor(); SetTermFont(be_fixed_font, be_fixed_font); SetTermColor(); //SetIMAware(PrefHandler::Default()->getInt32(PREF_IM_AWARE)); - const char *encoding = PrefHandler::Default()->getString(PREF_TEXT_ENCODING); - SetEncoding(longname2id(encoding)); - fShell = new Shell(); - status_t status = fShell->Open(fTermRows, fTermColumns, command, longname2shortname(encoding)); + status_t status = fShell->Open(fTermRows, fTermColumns, + command, longname2shortname(id2longname(fEncoding))); if (status < B_OK) throw status; @@ -1531,7 +1533,41 @@ TermView::MessageReceived(BMessage *msg) case B_SELECT_ALL: DoSelectAll(); break; + + case B_SET_PROPERTY: { + int32 i; + int32 encodingID; + BMessage spe; + msg->GetCurrentSpecifier(&i, &spe); + if (!strcmp("encoding", spe.FindString("property", i))){ + msg->FindInt32 ("data", &encodingID); + SetEncoding(encodingID); + msg->SendReply(B_REPLY); + } else { + BView::MessageReceived(msg); + } + break; + } + case B_GET_PROPERTY: { + int32 i; + BMessage spe; + msg->GetCurrentSpecifier(&i, &spe); + if (!strcmp("encoding", spe.FindString("property", i))){ + BMessage reply(B_REPLY); + reply.AddInt32("result", Encoding()); + msg->SendReply(&reply); + } + else if (!strcmp("tty", spe.FindString("property", i))) { + BMessage reply(B_REPLY); + reply.AddString("result", TerminalName()); + msg->SendReply(&reply); + } else { + BView::MessageReceived(msg); + } + break; + } + case MENU_CLEAR_ALL: DoClearAll(); fShell->Write(ctrl_l, 1); @@ -1570,6 +1606,46 @@ TermView::MessageReceived(BMessage *msg) } +status_t +TermView::GetSupportedSuites(BMessage *message) +{ + static property_info propList[] = { + { "encoding", + {B_GET_PROPERTY, 0}, + {B_DIRECT_SPECIFIER, 0}, + "get muterminal encoding"}, + { "encoding", + {B_SET_PROPERTY, 0}, + {B_DIRECT_SPECIFIER, 0}, + "set muterminal encoding"}, + { "tty", + {B_GET_PROPERTY, 0}, + {B_DIRECT_SPECIFIER, 0}, + "get tty_name."}, + { 0 } + + }; + + message->AddString("suites", "suite/vnd.naan-termview"); + BPropertyInfo propInfo(propList); + message->AddFlat("messages", &propInfo); + return BView::GetSupportedSuites(message); +} + + +BHandler* +TermView::ResolveSpecifier(BMessage *msg, int32 index, BMessage *specifier, + int32 form, const char *property) +{ + if (((strcmp(property, "encode") == 0) + && ((msg->what == B_SET_PROPERTY) || (msg->what == B_GET_PROPERTY))) + || ((strcmp(property, "tty") == 0) && (msg->what == B_GET_PROPERTY))) + return this; + + return BView::ResolveSpecifier(msg, index, specifier, form, property); +} + + //! Gets dropped file full path and display it at cursor position. void TermView::DoFileDrop(entry_ref &ref) diff --git a/src/apps/terminal/TermView.h b/src/apps/terminal/TermView.h index 830a97eedd..f10d4b2ebe 100644 --- a/src/apps/terminal/TermView.h +++ b/src/apps/terminal/TermView.h @@ -33,8 +33,6 @@ #include "CurPos.h" -#include "TermConst.h" -#include "TermWindow.h" #include #include @@ -52,7 +50,7 @@ class Shell; class TermBuffer; class TermView : public BView { public: - TermView(BRect frame, const char *command); + TermView(BRect frame, const char *command = NULL); ~TermView(); virtual void GetPreferredSize(float *width, float *height); @@ -142,6 +140,11 @@ protected: virtual void FrameResized(float width, float height); virtual void MessageReceived(BMessage* message); + virtual status_t GetSupportedSuites(BMessage *msg); + virtual BHandler* ResolveSpecifier(BMessage *msg, int32 index, + BMessage *specifier, int32 form, + const char *property); + private: void _InitObject(const char *command); diff --git a/src/apps/terminal/TermWindow.cpp b/src/apps/terminal/TermWindow.cpp index b000ce9719..b0712a3bff 100644 --- a/src/apps/terminal/TermWindow.cpp +++ b/src/apps/terminal/TermWindow.cpp @@ -16,6 +16,7 @@ #include "PrefWindow.h" #include "PrefView.h" #include "PrefHandler.h" +#include "SmartTabView.h" #include "TermConst.h" #include "TermView.h" @@ -26,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -52,14 +52,14 @@ const static float kViewOffset = 3; #if 0 TermWindow::TermWindow(BRect frame, const char* title, const char *command) : - BWindow(frame, title, B_DOCUMENT_WINDOW, B_CURRENT_WORKSPACE|B_QUIT_ON_WINDOW_CLOSE) + BWindow(frame, title, B_DOCUMENT_WINDOW, B_CURRENT_WORKSPACE|B_QUIT_ON_WINDOW_CLOSE), + fTabView(NULL) { - fTermView = new TermView(Bounds(), command); - AddChild(fTermView); - - float width, height; - fTermView->GetPreferredSize(&width, &height); - ResizeTo(width, height); + fTabView = new SmartTabView(Bounds(), "Tab view"); + AddChild(fTabView); + + _NewTab(command); + _NewTab(NULL); } #else @@ -386,43 +386,7 @@ TermWindow::MessageReceived(BMessage *message) fTermView->SetEncoding(coding_id); break; } - // Extended B_SET_PROPERTY. Dispatch this message, - // Set coding ID. - case B_SET_PROPERTY: { - int32 i; - BMessage spe; - message->GetCurrentSpecifier(&i, &spe); - if (!strcmp("encode", spe.FindString("property", i))){ - message->FindInt32 ("data", &coding_id); - fTermView->SetEncoding (coding_id); - - message->SendReply(B_REPLY); - } else { - BWindow::MessageReceived(message); - } - break; - } - - // Extended B_GET_PROPERTY. Dispatch this message, reply now coding ID. - case B_GET_PROPERTY: { - int32 i; - BMessage spe; - message->GetCurrentSpecifier(&i, &spe); - if (!strcmp("encode", spe.FindString("property", i))){ - BMessage reply(B_REPLY); - reply.AddInt32("result", fTermView->Encoding()); - message->SendReply(&reply); - } - else if (!strcmp("tty", spe.FindString("property", i))) { - BMessage reply(B_REPLY); - reply.AddString("result", fTermView->TerminalName()); - message->SendReply(&reply); - } else { - BWindow::MessageReceived(message); - } - break; - } - + // Message from Preference panel. case MSG_ROWS_CHANGED: case MSG_COLS_CHANGED: { @@ -579,51 +543,6 @@ TermWindow::QuitRequested() } -status_t -TermWindow::GetSupportedSuites(BMessage *msg) -{ - static property_info propList[] = { - { "encode", - {B_GET_PROPERTY, 0}, - {B_DIRECT_SPECIFIER, 0}, - "get muterminal encode"}, - { "encode", - {B_SET_PROPERTY, 0}, - {B_DIRECT_SPECIFIER, 0}, - "set muterminal encode"}, - { "tty", - {B_GET_PROPERTY, 0}, - {B_DIRECT_SPECIFIER, 0}, - "get tty_name."}, - { 0 } - - }; - - msg->AddString("suites", "suite/vnd.naan-termwindow"); - BPropertyInfo propInfo(propList); - msg->AddFlat("messages", &propInfo); - return BWindow::GetSupportedSuites(msg); -} - - -//////////////////////////////////////////////////////////////////////////// -// ResolveSpecifier -// -//////////////////////////////////////////////////////////////////////////// -BHandler* -TermWindow::ResolveSpecifier(BMessage *msg, int32 index, - BMessage *specifier, int32 form, - const char *property) -{ - if (((strcmp(property, "encode") == 0) - && ((msg->what == B_SET_PROPERTY) || (msg->what == B_GET_PROPERTY))) - || ((strcmp(property, "tty") == 0) && (msg->what == B_GET_PROPERTY))) - return this; - - return BWindow::ResolveSpecifier(msg, index, specifier, form, property); -} - - status_t TermWindow::_DoPageSetup() { @@ -684,3 +603,12 @@ TermWindow::_DoPrint() } #endif +void +TermWindow::_NewTab(const char *command) +{ + TermView *view = new TermView(Bounds(), command); + fTabView->AddTab(view); +} + + + diff --git a/src/apps/terminal/TermWindow.h b/src/apps/terminal/TermWindow.h index 41979a77ee..a8b1ad68e4 100644 --- a/src/apps/terminal/TermWindow.h +++ b/src/apps/terminal/TermWindow.h @@ -40,7 +40,7 @@ class BMenuBar; class FindWindow; class PrefWindow; class TermView; - +class SmartTabView; class TermWindow : public BWindow { public: TermWindow(BRect frame, const char* title, const char *command); @@ -52,17 +52,15 @@ protected: virtual void MenusBeginning(); virtual bool QuitRequested(); - status_t GetSupportedSuites(BMessage *msg); - BHandler* ResolveSpecifier(BMessage *msg, int32 index, - BMessage *specifier, int32 form, - const char *property); private: void _InitWindow(const char *command); void _SetupMenu(); status_t _DoPageSetup(); void _DoPrint(); - + void _NewTab(const char *command); + + SmartTabView *fTabView; TermView *fTermView; BMenuBar *fMenubar; BMenu *fFilemenu,