* The window size is no longer directly saved when you change it in the menu.

* "Save as Default" now also saves the current Terminal size.
* Exchanged the strange default Termina sizes with some others, added a
  separator between the full screen setting.
* Removed the "Term" prefix from TermView::fTerm{Columns|Rows}.
* Whitespace cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29513 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2009-03-14 13:50:08 +00:00
parent 4dabc2e663
commit 7aed1511f6
3 changed files with 92 additions and 97 deletions
+49 -49
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2008, Haiku, Inc. * Copyright 2001-2009, Haiku, Inc.
* Copyright 2003-2004 Kian Duffy, [email protected] * Copyright 2003-2004 Kian Duffy, [email protected]
* Parts Copyright 1998-1999 Kazuho Okui and Takashi Murai. * Parts Copyright 1998-1999 Kazuho Okui and Takashi Murai.
* All rights reserved. Distributed under the terms of the MIT license. * All rights reserved. Distributed under the terms of the MIT license.
@@ -47,6 +47,7 @@
#include "CodeConv.h" #include "CodeConv.h"
#include "Globals.h" #include "Globals.h"
#include "PrefHandler.h"
#include "Shell.h" #include "Shell.h"
#include "TermConst.h" #include "TermConst.h"
#include "TerminalCharClassifier.h" #include "TerminalCharClassifier.h"
@@ -166,8 +167,8 @@ private:
TermView::TermView(BRect frame, int32 argc, const char** argv, int32 historySize) TermView::TermView(BRect frame, int32 argc, const char** argv, int32 historySize)
: BView(frame, "termview", B_FOLLOW_ALL, : BView(frame, "termview", B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE | B_PULSE_NEEDED), B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE | B_PULSE_NEEDED),
fTermRows(ROWS_DEFAULT), fColumns(COLUMNS_DEFAULT),
fTermColumns(COLUMNS_DEFAULT), fRows(ROWS_DEFAULT),
fEncoding(M_UTF8), fEncoding(M_UTF8),
fScrBufSize(historySize) fScrBufSize(historySize)
{ {
@@ -179,13 +180,13 @@ TermView::TermView(int rows, int columns, int32 argc, const char** argv,
int32 historySize) int32 historySize)
: BView(BRect(0, 0, 0, 0), "termview", B_FOLLOW_ALL, : BView(BRect(0, 0, 0, 0), "termview", B_FOLLOW_ALL,
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE | B_PULSE_NEEDED), B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE | B_PULSE_NEEDED),
fTermRows(rows), fColumns(columns),
fTermColumns(columns), fRows(rows),
fEncoding(M_UTF8), fEncoding(M_UTF8),
fScrBufSize(historySize) fScrBufSize(historySize)
{ {
_InitObject(argc, argv); _InitObject(argc, argv);
SetTermSize(fTermRows, fTermColumns, true); SetTermSize(fRows, fColumns, true);
// TODO: Don't show the dragger, since replicant capabilities // TODO: Don't show the dragger, since replicant capabilities
// don't work very well ATM. // don't work very well ATM.
@@ -203,8 +204,8 @@ TermView::TermView(int rows, int columns, int32 argc, const char** argv,
TermView::TermView(BMessage* archive) TermView::TermView(BMessage* archive)
: :
BView(archive), BView(archive),
fTermRows(ROWS_DEFAULT), fColumns(COLUMNS_DEFAULT),
fTermColumns(COLUMNS_DEFAULT), fRows(ROWS_DEFAULT),
fEncoding(M_UTF8), fEncoding(M_UTF8),
fScrBufSize(1000) fScrBufSize(1000)
{ {
@@ -213,10 +214,10 @@ TermView::TermView(BMessage* archive)
if (archive->FindInt32("encoding", (int32*)&fEncoding) < B_OK) if (archive->FindInt32("encoding", (int32*)&fEncoding) < B_OK)
fEncoding = M_UTF8; fEncoding = M_UTF8;
if (archive->FindInt32("columns", (int32*)&fTermColumns) < B_OK) if (archive->FindInt32("columns", (int32*)&fColumns) < B_OK)
fTermColumns = COLUMNS_DEFAULT; fColumns = COLUMNS_DEFAULT;
if (archive->FindInt32("rows", (int32*)&fTermRows) < B_OK) if (archive->FindInt32("rows", (int32*)&fRows) < B_OK)
fTermRows = ROWS_DEFAULT; fRows = ROWS_DEFAULT;
int32 argc = 0; int32 argc = 0;
if (archive->HasInt32("argc")) if (archive->HasInt32("argc"))
@@ -235,7 +236,7 @@ TermView::TermView(BMessage* archive)
/*! Initializes the object for further use. /*! Initializes the object for further use.
The members fTermRows, fTermColumns, fEncoding, and fScrBufSize must The members fRows, fColumns, fEncoding, and fScrBufSize must
already be initialized; they are not touched by this method. already be initialized; they are not touched by this method.
*/ */
status_t status_t
@@ -290,12 +291,12 @@ TermView::_InitObject(int32 argc, const char** argv)
if (fCharClassifier == NULL) if (fCharClassifier == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
status_t error = fTextBuffer->Init(fTermColumns, fTermRows, fScrBufSize); status_t error = fTextBuffer->Init(fColumns, fRows, fScrBufSize);
if (error != B_OK) if (error != B_OK)
return error; return error;
fTextBuffer->SetEncoding(fEncoding); fTextBuffer->SetEncoding(fEncoding);
error = fVisibleTextBuffer->Init(fTermColumns, fTermRows + 2, 0); error = fVisibleTextBuffer->Init(fColumns, fRows + 2, 0);
if (error != B_OK) if (error != B_OK)
return error; return error;
@@ -304,10 +305,10 @@ TermView::_InitObject(int32 argc, const char** argv)
return B_NO_MEMORY; return B_NO_MEMORY;
SetTermFont(be_fixed_font); SetTermFont(be_fixed_font);
SetTermSize(fTermRows, fTermColumns, false); SetTermSize(fRows, fColumns, false);
//SetIMAware(false); //SetIMAware(false);
status_t status = fShell->Open(fTermRows, fTermColumns, status_t status = fShell->Open(fRows, fColumns,
EncodingAsShortString(fEncoding), argc, argv); EncodingAsShortString(fEncoding), argc, argv);
if (status < B_OK) if (status < B_OK)
@@ -360,9 +361,9 @@ TermView::Archive(BMessage* data, bool deep) const
if (status == B_OK) if (status == B_OK)
status = data->AddInt32("encoding", (int32)fEncoding); status = data->AddInt32("encoding", (int32)fEncoding);
if (status == B_OK) if (status == B_OK)
status = data->AddInt32("columns", (int32)fTermColumns); status = data->AddInt32("columns", (int32)fColumns);
if (status == B_OK) if (status == B_OK)
status = data->AddInt32("rows", (int32)fTermRows); status = data->AddInt32("rows", (int32)fRows);
if (data->ReplaceString("class", "TermView") != B_OK) if (data->ReplaceString("class", "TermView") != B_OK)
data->AddString("class", "TermView"); data->AddString("class", "TermView");
@@ -422,9 +423,9 @@ void
TermView::GetPreferredSize(float *width, float *height) TermView::GetPreferredSize(float *width, float *height)
{ {
if (width) if (width)
*width = fTermColumns * fFontWidth - 1; *width = fColumns * fFontWidth - 1;
if (height) if (height)
*height = fTermRows * fFontHeight - 1; *height = fRows * fFontHeight - 1;
} }
@@ -453,9 +454,12 @@ TermView::SetTermSize(int rows, int columns, bool resize)
{ {
//debug_printf("TermView::SetTermSize(%d, %d)\n", rows, columns); //debug_printf("TermView::SetTermSize(%d, %d)\n", rows, columns);
if (rows > 0) if (rows > 0)
fTermRows = rows; fRows = rows;
if (columns > 0) if (columns > 0)
fTermColumns = columns; fColumns = columns;
PrefHandler::Default()->setInt32(PREF_COLS, fColumns);
PrefHandler::Default()->setInt32(PREF_ROWS, fRows);
// To keep things simple, get rid of the selection first. // To keep things simple, get rid of the selection first.
_Deselect(); _Deselect();
@@ -469,23 +473,19 @@ TermView::SetTermSize(int rows, int columns, bool resize)
} }
} }
fTermRows = rows;
fTermColumns = columns;
//debug_printf("Invalidate()\n"); //debug_printf("Invalidate()\n");
Invalidate(); Invalidate();
if (fScrollBar != NULL) { if (fScrollBar != NULL) {
_UpdateScrollBarRange(); _UpdateScrollBarRange();
fScrollBar->SetSteps(fFontHeight, fFontHeight * fTermRows); fScrollBar->SetSteps(fFontHeight, fFontHeight * fRows);
} }
BRect rect(0, 0, fTermColumns * fFontWidth, fTermRows * fFontHeight); BRect rect(0, 0, fColumns * fFontWidth, fRows * fFontHeight);
if (resize) if (resize)
ResizeTo(rect.Width(), rect.Height()); ResizeTo(rect.Width(), rect.Height());
// synchronize the visible text buffer // synchronize the visible text buffer
{ {
BAutolock _(fTextBuffer); BAutolock _(fTextBuffer);
@@ -593,7 +593,7 @@ TermView::SetTermFont(const BFont *font)
_ScrollTo(0, false); _ScrollTo(0, false);
if (fScrollBar != NULL) if (fScrollBar != NULL)
fScrollBar->SetSteps(fFontHeight, fFontHeight * fTermRows); fScrollBar->SetSteps(fFontHeight, fFontHeight * fRows);
} }
@@ -602,7 +602,7 @@ TermView::SetScrollBar(BScrollBar *scrollBar)
{ {
fScrollBar = scrollBar; fScrollBar = scrollBar;
if (fScrollBar != NULL) { if (fScrollBar != NULL) {
fScrollBar->SetSteps(fFontHeight, fFontHeight * fTermRows); fScrollBar->SetSteps(fFontHeight, fFontHeight * fRows);
} }
} }
@@ -703,10 +703,10 @@ TermView::_InvalidateTextRange(TermPos start, TermPos end)
if (start.y == end.y) { if (start.y == end.y) {
_InvalidateTextRect(start.x, start.y, end.x, end.y); _InvalidateTextRect(start.x, start.y, end.x, end.y);
} else { } else {
_InvalidateTextRect(start.x, start.y, fTermColumns, start.y); _InvalidateTextRect(start.x, start.y, fColumns, start.y);
if (end.y - start.y > 0) if (end.y - start.y > 0)
_InvalidateTextRect(0, start.y + 1, fTermColumns, end.y - 1); _InvalidateTextRect(0, start.y + 1, fColumns, end.y - 1);
_InvalidateTextRect(0, end.y, end.x, end.y); _InvalidateTextRect(0, end.y, end.x, end.y);
} }
@@ -891,7 +891,7 @@ TermView::_UpdateScrollBarRange()
historySize = fTextBuffer->HistorySize(); historySize = fTextBuffer->HistorySize();
} }
float viewHeight = fTermRows * fFontHeight; float viewHeight = fRows * fFontHeight;
float historyHeight = (float)historySize * fFontHeight; float historyHeight = (float)historySize * fFontHeight;
//debug_printf("TermView::_UpdateScrollBarRange(): history: %ld, range: %f - 0\n", //debug_printf("TermView::_UpdateScrollBarRange(): history: %ld, range: %f - 0\n",
@@ -908,7 +908,7 @@ void
TermView::_UpdateSIGWINCH() TermView::_UpdateSIGWINCH()
{ {
if (fFrameResized) { if (fFrameResized) {
fShell->UpdateWindowSize(fTermRows, fTermColumns); fShell->UpdateWindowSize(fRows, fColumns);
fFrameResized = false; fFrameResized = false;
} }
} }
@@ -921,7 +921,7 @@ TermView::AttachedToWindow()
MakeFocus(true); MakeFocus(true);
if (fScrollBar) { if (fScrollBar) {
fScrollBar->SetSteps(fFontHeight, fFontHeight * fTermRows); fScrollBar->SetSteps(fFontHeight, fFontHeight * fRows);
_UpdateScrollBarRange(); _UpdateScrollBarRange();
} }
@@ -994,7 +994,7 @@ TermView::Draw(BRect updateRect)
for (int32 j = y1; j <= y2; j++) { for (int32 j = y1; j <= y2; j++) {
int32 k = x1; int32 k = x1;
char buf[fTermColumns * 4 + 1]; char buf[fColumns * 4 + 1];
if (fVisibleTextBuffer->IsFullWidthChar(j - firstVisible, k)) if (fVisibleTextBuffer->IsFullWidthChar(j - firstVisible, k))
k--; k--;
@@ -1233,7 +1233,7 @@ TermView::KeyDown(const char *bytes, int32 numBytes)
case B_PAGE_UP: case B_PAGE_UP:
if (mod & B_SHIFT_KEY) { if (mod & B_SHIFT_KEY) {
_ScrollTo(fScrollOffset - fFontHeight * fTermRows, true); _ScrollTo(fScrollOffset - fFontHeight * fRows, true);
return; return;
} }
if (rawChar == B_PAGE_UP) if (rawChar == B_PAGE_UP)
@@ -1242,7 +1242,7 @@ TermView::KeyDown(const char *bytes, int32 numBytes)
case B_PAGE_DOWN: case B_PAGE_DOWN:
if (mod & B_SHIFT_KEY) { if (mod & B_SHIFT_KEY) {
_ScrollTo(fScrollOffset + fFontHeight * fTermRows, true); _ScrollTo(fScrollOffset + fFontHeight * fRows, true);
return; return;
} }
if (rawChar == B_PAGE_DOWN) if (rawChar == B_PAGE_DOWN)
@@ -1281,7 +1281,7 @@ TermView::FrameResized(float width, float height)
int32 columns = ((int32)width + 1) / fFontWidth; int32 columns = ((int32)width + 1) / fFontWidth;
int32 rows = ((int32)height + 1) / fFontHeight; int32 rows = ((int32)height + 1) / fFontHeight;
if (columns == fTermColumns && rows == fTermRows) if (columns == fColumns && rows == fRows)
return; return;
bool hasResizeView = fResizeRunner != NULL; bool hasResizeView = fResizeRunner != NULL;
@@ -1775,7 +1775,7 @@ TermView::_SynchronizeWithTextBuffer(int32 visibleDirtyTop,
// been scrolled in less than a sync update period. Once we're // been scrolled in less than a sync update period. Once we're
// actively considering it, the same condition will convince us to // actively considering it, the same condition will convince us to
// actually do it. // actually do it.
if (fScrolledSinceLastSync + linesScrolled <= fTermRows) { if (fScrolledSinceLastSync + linesScrolled <= fRows) {
// Condition doesn't hold yet. Reset if time is up, or otherwise // Condition doesn't hold yet. Reset if time is up, or otherwise
// keep counting. // keep counting.
if (timeElapsed > kSyncUpdateGranularity) { if (timeElapsed > kSyncUpdateGranularity) {
@@ -1808,7 +1808,7 @@ TermView::_SynchronizeWithTextBuffer(int32 visibleDirtyTop,
// sync time not passed yet -- keep counting // sync time not passed yet -- keep counting
fScrolledSinceLastSync += linesScrolled; fScrolledSinceLastSync += linesScrolled;
return; return;
} else if (fScrolledSinceLastSync + linesScrolled <= fTermRows) { } else if (fScrolledSinceLastSync + linesScrolled <= fRows) {
// time's up, but not enough happened // time's up, but not enough happened
delete fSyncRunner; delete fSyncRunner;
fSyncRunner = NULL; fSyncRunner = NULL;
@@ -2194,8 +2194,8 @@ TermView::_Select(TermPos start, TermPos end, bool inclusive,
if (start.x < 0) if (start.x < 0)
start.x = 0; start.x = 0;
if (end.x >= fTermColumns) if (end.x >= fColumns)
end.x = fTermColumns; end.x = fColumns;
TermPos minPos(0, -fTextBuffer->HistorySize()); TermPos minPos(0, -fTextBuffer->HistorySize());
TermPos maxPos(0, fTextBuffer->Height()); TermPos maxPos(0, fTextBuffer->Height());
@@ -2217,8 +2217,8 @@ TermView::_Select(TermPos start, TermPos end, bool inclusive,
if (fTextBuffer->IsFullWidthChar(end.y, end.x)) { if (fTextBuffer->IsFullWidthChar(end.y, end.x)) {
end.x++; end.x++;
if (end.x >= fTermColumns) if (end.x >= fColumns)
end.x = fTermColumns; end.x = fColumns;
} }
if (fSelStart != fSelEnd) if (fSelStart != fSelEnd)
@@ -2389,10 +2389,10 @@ TermView::GetFrameSize(float *width, float *height)
} }
if (width != NULL) if (width != NULL)
*width = fTermColumns * fFontWidth; *width = fColumns * fFontWidth;
if (height != NULL) if (height != NULL)
*height = (fTermRows + historySize) * fFontHeight; *height = (fRows + historySize) * fFontHeight;
} }
@@ -2483,7 +2483,7 @@ TermView::InitiateDrag()
if (fSelStart.y == fSelEnd.y) if (fSelStart.y == fSelEnd.y)
rect.Set(start.x, start.y, end.x + fFontWidth, end.y + fFontHeight); rect.Set(start.x, start.y, end.x + fFontWidth, end.y + fFontHeight);
else else
rect.Set(0, start.y, fTermColumns * fFontWidth, end.y + fFontHeight); rect.Set(0, start.y, fColumns * fFontWidth, end.y + fFontHeight);
rect = rect & Bounds(); rect = rect & Bounds();
+3 -3
View File
@@ -1,5 +1,5 @@
/* /*
* Copyright 2001-2008, Haiku. * Copyright 2001-2009, Haiku.
* Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net> * Copyright (c) 2003-4 Kian Duffy <myob@users.sourceforge.net>
* Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai. * Parts Copyright (C) 1998,99 Kazuho Okui and Takashi Murai.
* *
@@ -208,8 +208,8 @@ private:
int32 fMouseButtons; int32 fMouseButtons;
// Terminal rows and columns. // Terminal rows and columns.
int fTermRows; int fColumns;
int fTermColumns; int fRows;
int fEncoding; int fEncoding;
+16 -21
View File
@@ -461,16 +461,10 @@ TermWindow::MessageReceived(BMessage *message)
int32 columns, rows; int32 columns, rows;
message->FindInt32("columns", &columns); message->FindInt32("columns", &columns);
message->FindInt32("rows", &rows); message->FindInt32("rows", &rows);
PrefHandler::Default()->setInt32(PREF_COLS, columns);
PrefHandler::Default()->setInt32(PREF_ROWS, rows);
_ActiveTermView()->SetTermSize(rows, columns, 0); _ActiveTermView()->SetTermSize(rows, columns, false);
_ResizeView(_ActiveTermView()); _ResizeView(_ActiveTermView());
BPath path;
if (PrefHandler::GetDefaultPath(path) == B_OK)
PrefHandler::Default()->SaveAsText(path.Path(), PREFFILE_MIMETYPE);
break; break;
} }
case MSG_HALF_FONT_CHANGED: case MSG_HALF_FONT_CHANGED:
@@ -483,7 +477,6 @@ TermWindow::MessageReceived(BMessage *message)
_ActiveTermView()->SetTermFont(&font); _ActiveTermView()->SetTermFont(&font);
_ResizeView(_ActiveTermView()); _ResizeView(_ActiveTermView());
break; break;
} }
@@ -515,7 +508,7 @@ TermWindow::MessageReceived(BMessage *message)
break; break;
case MSG_FONT_CHANGED: case MSG_FONT_CHANGED:
PostMessage(MSG_HALF_FONT_CHANGED); PostMessage(MSG_HALF_FONT_CHANGED);
break; break;
case MSG_COLOR_CHANGED: case MSG_COLOR_CHANGED:
@@ -691,12 +684,13 @@ TermWindow::_DoPrint()
job.DrawView(_ActiveTermView(), curPageRect, B_ORIGIN); job.DrawView(_ActiveTermView(), curPageRect, B_ORIGIN);
job.SpoolPage(); job.SpoolPage();
if (!job.CanContinue()){ if (!job.CanContinue()) {
// It is likely that the only way that the job was cancelled is // It is likely that the only way that the job was cancelled is
// because the user hit 'Cancel' in the page setup window, in which // because the user hit 'Cancel' in the page setup window, in
// case, the user does *not* need to be told that it was cancelled. // which case, the user does *not* need to be told that it was
// He/she will simply expect that it was done. // cancelled.
return; // He/she will simply expect that it was done.
return;
} }
} }
} }
@@ -716,7 +710,8 @@ TermWindow::_AddTab(Arguments *args)
try { try {
// Note: I don't pass the Arguments class directly to the termview, // Note: I don't pass the Arguments class directly to the termview,
// only to avoid adding it as a dependency: in other words, to keep // only to avoid adding it as a dependency: in other words, to keep
// the TermView class as agnostic as possible about the surrounding world. // the TermView class as agnostic as possible about the surrounding
// world.
CustomTermView *view = new CustomTermView( CustomTermView *view = new CustomTermView(
PrefHandler::Default()->getInt32(PREF_ROWS), PrefHandler::Default()->getInt32(PREF_ROWS),
PrefHandler::Default()->getInt32(PREF_COLS), PrefHandler::Default()->getInt32(PREF_COLS),
@@ -883,12 +878,11 @@ TermWindow::_ResizeView(TermView *view)
void void
TermWindow::_BuildWindowSizeMenu(BMenu *menu) TermWindow::_BuildWindowSizeMenu(BMenu *menu)
{ {
const int32 windowSizes[5][2] = { const int32 windowSizes[4][2] = {
{ 80, 24 },
{ 80, 25 }, { 80, 25 },
{ 80, 40 }, { 80, 40 },
{ 132, 24 }, { 132, 25 },
{ 132, 25 } { 132, 40 }
}; };
const int32 sizeNum = sizeof(windowSizes) / sizeof(windowSizes[0]); const int32 sizeNum = sizeof(windowSizes) / sizeof(windowSizes[0]);
@@ -903,8 +897,9 @@ TermWindow::_BuildWindowSizeMenu(BMenu *menu)
menu->AddItem(new BMenuItem(label, message)); menu->AddItem(new BMenuItem(label, message));
} }
menu->AddItem(new BMenuItem("Fullscreen", menu->AddSeparatorItem();
new BMessage(FULLSCREEN), B_ENTER)); menu->AddItem(new BMenuItem("Fullscreen", new BMessage(FULLSCREEN),
B_ENTER));
} }