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
This commit is contained in:
Stefano Ceccherini
2007-07-28 14:49:39 +00:00
parent f00954fc65
commit 69adf535c1
8 changed files with 112 additions and 118 deletions
-3
View File
@@ -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},
+1 -24
View File
@@ -4,33 +4,10 @@
* Copyright (c) 2004 Daniel Furrer <[email protected]>
* 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"
-1
View File
@@ -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 <SupportDefs.h>
-2
View File
@@ -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";
+52 -46
View File
@@ -5,6 +5,7 @@
* All rights reserved. Distributed under the terms of the MIT license.
*
* Authors:
* Stefano Ceccherini <stefano.ceccherini@gmail.com>
* 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);
}
+14 -35
View File
@@ -3,31 +3,12 @@
* Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
* 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 <stefano.ceccherini@gmail.com>
* 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
+44 -7
View File
@@ -1,10 +1,10 @@
/*
* Copyright 2007 Haiku, Inc.
* 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.
* Copyright (c) 2004 Daniel Furrer <assimil8or@users.sourceforge.net>
*
* Distributed unter the terms of the MIT license.
* Distributed under the terms of the MIT license.
*/
#include "TermWindow.h"
@@ -22,6 +22,7 @@
#include <Alert.h>
#include <Application.h>
#include <Dragger.h>
#include <Menu.h>
#include <MenuBar.h>
#include <MenuItem.h>
@@ -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)
+1
View File
@@ -54,6 +54,7 @@ protected:
private:
void _SetTermColors();
void _InitWindow(const char *command);
void _SetupMenu();
status_t _DoPageSetup();