From 69adf535c1b4469dc0991c4c9c07f2dea81f18a4 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Sat, 28 Jul 2007 14:49:39 +0000 Subject: [PATCH] TermView and the classes used by it now don't know about PrefHandler anymore, but have methods to set the needed options. Various cleanups. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21728 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/terminal/PrefHandler.cpp | 3 - src/apps/terminal/Shell.cpp | 25 +------- src/apps/terminal/TermBuffer.cpp | 1 - src/apps/terminal/TermConst.h | 2 - src/apps/terminal/TermView.cpp | 98 ++++++++++++++++--------------- src/apps/terminal/TermView.h | 49 +++++----------- src/apps/terminal/TermWindow.cpp | 51 +++++++++++++--- src/apps/terminal/TermWindow.h | 1 + 8 files changed, 112 insertions(+), 118 deletions(-) diff --git a/src/apps/terminal/PrefHandler.cpp b/src/apps/terminal/PrefHandler.cpp index b081583620..ed0a58efe5 100644 --- a/src/apps/terminal/PrefHandler.cpp +++ b/src/apps/terminal/PrefHandler.cpp @@ -55,9 +55,6 @@ static const pref_defaults kTermDefaults[] = { { PREF_TEXT_ENCODING, "UTF-8" }, - { PREF_MOUSE_IMAGE, "Hand cursor"}, - { PREF_DRAGN_COPY, "0"}, - { PREF_GUI_LANGUAGE, "English"}, { PREF_IM_AWARE, "0"}, { NULL, NULL}, diff --git a/src/apps/terminal/Shell.cpp b/src/apps/terminal/Shell.cpp index 4edd17955d..b90005d0ee 100644 --- a/src/apps/terminal/Shell.cpp +++ b/src/apps/terminal/Shell.cpp @@ -4,33 +4,10 @@ * 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. * */ - #include "Shell.h" #include "TermConst.h" diff --git a/src/apps/terminal/TermBuffer.cpp b/src/apps/terminal/TermBuffer.cpp index 6fa6b0c1aa..b816c3d9a7 100644 --- a/src/apps/terminal/TermBuffer.cpp +++ b/src/apps/terminal/TermBuffer.cpp @@ -76,7 +76,6 @@ but it font is full width font on preference panel. #include "TermBuffer.h" #include "CurPos.h" -#include "PrefHandler.h" #include "TermConst.h" #include diff --git a/src/apps/terminal/TermConst.h b/src/apps/terminal/TermConst.h index 357785c19f..e47e544903 100644 --- a/src/apps/terminal/TermConst.h +++ b/src/apps/terminal/TermConst.h @@ -103,13 +103,11 @@ const char* const PREF_CURSOR_BACK_COLOR = "Cursor Background Color"; const char* const PREF_IM_FORE_COLOR = "IM Foreground Color"; const char* const PREF_IM_BACK_COLOR = "IM Background Color"; const char* const PREF_IM_SELECT_COLOR = "IM Selection Color"; -const char* const PREF_DRAGN_COPY = "Drag'n Copy"; const char* const PREF_HISTORY_SIZE = "Histry Size"; const char* const PREF_CURSOR_BLINKING = "Cursor Blinking rate"; const char* const PREF_IM_AWARE = "Input Method Aware"; -const char* const PREF_MOUSE_IMAGE = "Cursor Image"; const char* const PREF_COLS = "Cols"; const char* const PREF_ROWS = "Rows"; diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index e2ce2f9331..aa8dba4563 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -5,6 +5,7 @@ * All rights reserved. Distributed under the terms of the MIT license. * * Authors: + * Stefano Ceccherini * Kian Duffy, myob@users.sourceforge.net * Y.Hayakawa, hida@sawada.riec.tohoku.ac.jp */ @@ -13,8 +14,6 @@ #include "TermView.h" #include "CodeConv.h" -#include "MenuUtil.h" -#include "PrefHandler.h" #include "PrefView.h" #include "Shell.h" #include "TermBuffer.h" @@ -108,11 +107,16 @@ const unsigned char M_ADD_CURSOR[] = { #define MOUSE_THR_CODE 'mtcd' +#define ROWS_DEFAULT 25 +#define COLUMNS_DEFAULT 80 const static uint32 kUpdateSigWinch = 'Rwin'; +const static rgb_color kBlackColor = { 0, 0, 0, 255 }; +const static rgb_color kWhiteColor = { 255, 255, 255, 255 }; -TermView::TermView(BRect frame, const char *command) + +TermView::TermView(BRect frame, const char *command, int32 historySize) : BView(frame, "termview", B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS | B_PULSE_NEEDED), fShell(NULL), fFontWidth(0), @@ -132,17 +136,22 @@ TermView::TermView(BRect frame, const char *command) fCurPos(0, 0), fCurStack(0, 0), fBufferStartPos(-1), - fTermRows(PrefHandler::Default()->getInt32(PREF_ROWS)), - fTermColumns(PrefHandler::Default()->getInt32(PREF_COLS)), + fTermRows(ROWS_DEFAULT), + fTermColumns(COLUMNS_DEFAULT), fEncoding(M_UTF8), fTop(0), fTextBuffer(NULL), fScrollBar(NULL), + fTextForeColor(kBlackColor), + fTextBackColor(kWhiteColor), + fCursorForeColor(kWhiteColor), + fCursorBackColor(kBlackColor), + fSelectForeColor(kWhiteColor), + fSelectBackColor(kBlackColor), fScrTop(0), fScrBot(fTermRows - 1), - fScrBufSize(PrefHandler::Default()->getInt32(PREF_HISTORY_SIZE)), + fScrBufSize(historySize), fScrRegionSet(0), - fMouseImage(false), fPreviousMousePoint(0, 0), fSelStart(-1, -1), fSelEnd(-1, -1), @@ -176,17 +185,22 @@ TermView::TermView(BMessage *archive) fCurPos(0, 0), fCurStack(0, 0), fBufferStartPos(-1), - fTermRows(25), - fTermColumns(80), + fTermRows(ROWS_DEFAULT), + fTermColumns(COLUMNS_DEFAULT), fEncoding(M_UTF8), fTop(0), fTextBuffer(NULL), fScrollBar(NULL), + fTextForeColor(kBlackColor), + fTextBackColor(kWhiteColor), + fCursorForeColor(kWhiteColor), + fCursorBackColor(kBlackColor), + fSelectForeColor(kWhiteColor), + fSelectBackColor(kBlackColor), fScrTop(0), fScrBot(fTermRows - 1), fScrBufSize(1000), fScrRegionSet(0), - fMouseImage(false), fPreviousMousePoint(0, 0), fSelStart(-1, -1), fSelEnd(-1, -1), @@ -202,7 +216,7 @@ TermView::TermView(BMessage *archive) if (archive->FindInt32("rows", (int32 *)&fTermRows) < B_OK) fTermRows = 25; - // TODO: Retrieve command from archive + // TODO: Retrieve command, colors, history size, etc. from archive _InitObject(NULL); } @@ -212,11 +226,9 @@ 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)); + //SetIMAware(false); fShell = new Shell(); status_t status = fShell->Open(fTermRows, fTermColumns, @@ -349,33 +361,33 @@ TermView::SetTermSize(int rows, int cols, bool resize) } -//! Sets the mouse cursor image void -TermView::SetMouseCursor() +TermView::SetTextColor(rgb_color fore, rgb_color back) { - if (!strcmp(PrefHandler::Default()->getString(PREF_MOUSE_IMAGE), "Hand cursor")) - fMouseImage = false; - else - fMouseImage = true; -} - - -//! Sets colors for the terminal -void -TermView::SetTermColor() -{ - fTextForeColor = PrefHandler::Default()->getRGB(PREF_TEXT_FORE_COLOR); - fTextBackColor = PrefHandler::Default()->getRGB(PREF_TEXT_BACK_COLOR); - fSelectForeColor = PrefHandler::Default()->getRGB(PREF_SELECT_FORE_COLOR); - fSelectBackColor = PrefHandler::Default()->getRGB(PREF_SELECT_BACK_COLOR); - fCursorForeColor = PrefHandler::Default()->getRGB(PREF_CURSOR_FORE_COLOR); - fCursorBackColor = PrefHandler::Default()->getRGB(PREF_CURSOR_BACK_COLOR); + fTextForeColor = fore; + fTextBackColor = back; SetLowColor(fTextBackColor); SetViewColor(fTextBackColor); } +void +TermView::SetSelectColor(rgb_color fore, rgb_color back) +{ + fSelectForeColor = fore; + fSelectBackColor = back; +} + + +void +TermView::SetCursorColor(rgb_color fore, rgb_color back) +{ + fCursorForeColor = fore; + fCursorBackColor = back; +} + + int TermView::Encoding() const { @@ -386,6 +398,9 @@ TermView::Encoding() const void TermView::SetEncoding(int encoding) { + // TODO: Shell::_Spawn() sets the "TTYPE" environment variable using + // the string value of encoding. But when this function is called and + // the encoding changes, the new value is never passed to Shell. fEncoding = encoding; } @@ -963,8 +978,7 @@ TermView::MouseTracking(void *data) BRect r; if (theObj->HasSelection() - && ( PrefHandler::Default()->getInt32(PREF_DRAGN_COPY) - || modifiers() & B_CONTROL_KEY)) { + && (modifiers() & B_CONTROL_KEY)) { if (theObj->LockLooper()) { theObj->GetMouse(&stpoint, &button); @@ -1411,9 +1425,6 @@ TermView::WindowActivated(bool active) if (active == false) { // DoIMConfirm(); } - - if (active && fMouseImage) - be_app->SetCursor(B_I_BEAM_CURSOR); } @@ -1901,7 +1912,7 @@ TermView::MouseDown(BPoint where) // If mouse pointer is avove selected Region, start Drag'n Copy. if (inPos > stPos && inPos < edPos) { - if (mod & B_CONTROL_KEY || PrefHandler::Default()->getInt32(PREF_DRAGN_COPY)) { + if (mod & B_CONTROL_KEY) { BPoint p; uint32 bt; do { @@ -1984,14 +1995,9 @@ TermView::MouseDown(BPoint where) } void -TermView::MouseMoved(BPoint where, uint32 transit, const BMessage *) +TermView::MouseMoved(BPoint where, uint32 transit, const BMessage *message) { - if (fMouseImage && Window()->IsActive()) { - if (transit == B_ENTERED_VIEW) - be_app->SetCursor(B_I_BEAM_CURSOR); - if (transit == B_EXITED_VIEW) - be_app->SetCursor(B_HAND_CURSOR); - } + BView::MouseMoved(where, transit, message); } diff --git a/src/apps/terminal/TermView.h b/src/apps/terminal/TermView.h index 604ee1fa22..16ccc52965 100644 --- a/src/apps/terminal/TermView.h +++ b/src/apps/terminal/TermView.h @@ -3,31 +3,12 @@ * Copyright (c) 2003-4 Kian Duffy * 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, myob@users.sourceforge.net */ + #ifndef TERMVIEW_H #define TERMVIEW_H @@ -50,7 +31,7 @@ class Shell; class TermBuffer; class TermView : public BView { public: - TermView(BRect frame, const char *command = NULL); + TermView(BRect frame, const char *command = NULL, int32 historySize = 1000); TermView(BMessage *archive); ~TermView(); @@ -67,12 +48,13 @@ public: void GetFontSize(int *width, int *height); BRect SetTermSize(int rows, int cols, bool flag); - void SetTermColor(); + void SetTextColor(rgb_color fore, rgb_color back); + void SetSelectColor(rgb_color fore, rgb_color back); + void SetCursorColor(rgb_color fore, rgb_color back); int Encoding() const; void SetEncoding(int encoding); - void SetMouseCursor(); // void SetIMAware (bool); void SetScrollBar(BScrollBar *scrbar); BScrollBar *ScrollBar() const { return fScrollBar; }; @@ -84,9 +66,9 @@ public: void PutNL(int num); void SetInsertMode(int flag); void InsertSpace(int num); - int TermDraw(const CurPos &start, const CurPos &end); - int TermDrawRegion(CurPos start, CurPos end); - int TermDrawSelectedRegion(CurPos start, CurPos end); + int TermDraw(const CurPos &start, const CurPos &end); + int TermDrawRegion(CurPos start, CurPos end); + int TermDrawSelectedRegion(CurPos start, CurPos end); // Delete Charactor void EraseBelow(); void DeleteChar(int num); @@ -259,16 +241,13 @@ private: rgb_color fTextForeColor, fTextBackColor; rgb_color fCursorForeColor, fCursorBackColor; rgb_color fSelectForeColor, fSelectBackColor; - uchar fTermAttr; - + // Scroll Region int fScrTop; int fScrBot; - int fScrBufSize; + int32 fScrBufSize; bool fScrRegionSet; - bool fMouseImage; - BPoint fPreviousMousePoint; // view selection diff --git a/src/apps/terminal/TermWindow.cpp b/src/apps/terminal/TermWindow.cpp index 0ab745e5ff..8630a9610f 100644 --- a/src/apps/terminal/TermWindow.cpp +++ b/src/apps/terminal/TermWindow.cpp @@ -1,10 +1,10 @@ /* * Copyright 2007 Haiku, Inc. + * Copyright (c) 2004 Daniel Furrer * Copyright (c) 2003-2004 Kian Duffy * Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. - * Copyright (c) 2004 Daniel Furrer * - * Distributed unter the terms of the MIT license. + * Distributed under the terms of the MIT license. */ #include "TermWindow.h" @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -53,7 +54,27 @@ const static float kViewOffset = 3; TermWindow::TermWindow(BRect frame, const char* title, const char *command) : BWindow(frame, title, B_DOCUMENT_WINDOW, B_CURRENT_WORKSPACE|B_QUIT_ON_WINDOW_CLOSE), - fTabView(NULL) + fTabView(NULL), + fTermView(NULL), + fMenubar(NULL), + fFilemenu(NULL), + fEditmenu(NULL), + fEncodingmenu(NULL), + fHelpmenu(NULL), + fFontMenu(NULL), + fWindowSizeMenu(NULL), + fNewFontMenu(NULL), + fPrintSettings(NULL), + fPrefWindow(NULL), + fFindPanel(NULL), + fSavedFrame(0, 0, -1, -1), + fFindString(""), + fFindForwardMenuItem(NULL), + fFindBackwardMenuItem(NULL), + fFindSelection(false), + fForwardSearch(false), + fMatchCase(false), + fMatchWord(false) { fTabView = new SmartTabView(Bounds(), "Tab view"); AddChild(fTabView); @@ -61,11 +82,12 @@ TermWindow::TermWindow(BRect frame, const char* title, const char *command) _NewTab(command); _NewTab(NULL); } +#endif -#else TermWindow::TermWindow(BRect frame, const char* title, const char *command) : BWindow(frame, title, B_DOCUMENT_WINDOW, B_CURRENT_WORKSPACE|B_QUIT_ON_WINDOW_CLOSE), + fTabView(NULL), fTermView(NULL), fMenubar(NULL), fFilemenu(NULL), @@ -147,8 +169,9 @@ TermWindow::_InitWindow(const char *command) // Initialize TermView. (font, size and color) fTermView->SetTermFont(&halfFont, &fullFont); + _SetTermColors(); BRect rect = fTermView->SetTermSize(PrefHandler::Default()->getInt32(PREF_ROWS), - PrefHandler::Default()->getInt32(PREF_COLS), true); + PrefHandler::Default()->getInt32(PREF_COLS), true); int width, height; fTermView->GetFontSize(&width, &height); @@ -491,7 +514,7 @@ TermWindow::MessageReceived(BMessage *message) break; } case MSG_COLOR_CHANGED: { - fTermView->SetTermColor(); + _SetTermColors(); fTermView->Invalidate(); break; } @@ -537,6 +560,20 @@ TermWindow::QuitRequested() } +void +TermWindow::_SetTermColors() +{ + fTermView->SetTextColor(PrefHandler::Default()->getRGB(PREF_TEXT_FORE_COLOR), + PrefHandler::Default()->getRGB(PREF_TEXT_BACK_COLOR)); + + fTermView->SetSelectColor(PrefHandler::Default()->getRGB(PREF_SELECT_FORE_COLOR), + PrefHandler::Default()->getRGB(PREF_SELECT_BACK_COLOR)); + + fTermView->SetCursorColor(PrefHandler::Default()->getRGB(PREF_CURSOR_FORE_COLOR), + PrefHandler::Default()->getRGB(PREF_CURSOR_BACK_COLOR)); +} + + status_t TermWindow::_DoPageSetup() { @@ -595,7 +632,7 @@ TermWindow::_DoPrint() job.CommitJob(); } -#endif + void TermWindow::_NewTab(const char *command) diff --git a/src/apps/terminal/TermWindow.h b/src/apps/terminal/TermWindow.h index a8b1ad68e4..326465482c 100644 --- a/src/apps/terminal/TermWindow.h +++ b/src/apps/terminal/TermWindow.h @@ -54,6 +54,7 @@ protected: private: + void _SetTermColors(); void _InitWindow(const char *command); void _SetupMenu(); status_t _DoPageSetup();