Fixed TermView when used with the constructor which accepts a BRect:
In that case TermView computes rows and columns based on the frame size. This also made simpler to attach a TermView to a given BWindow, like done in the RepliTerminal test app. Changed Repliterminal accordingly. Removed the bool parameter from SetTermSize(), and added a SetTermSize which accept a BRect, as well. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34184 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -41,6 +41,7 @@
|
|||||||
#include <Region.h>
|
#include <Region.h>
|
||||||
#include <Roster.h>
|
#include <Roster.h>
|
||||||
#include <ScrollBar.h>
|
#include <ScrollBar.h>
|
||||||
|
#include <ScrollView.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
#include <StringView.h>
|
#include <StringView.h>
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
@@ -176,6 +177,7 @@ TermView::TermView(BRect frame, int32 argc, const char** argv, int32 historySize
|
|||||||
fReportAnyMouseEvent(false)
|
fReportAnyMouseEvent(false)
|
||||||
{
|
{
|
||||||
_InitObject(argc, argv);
|
_InitObject(argc, argv);
|
||||||
|
SetTermSize(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -194,7 +196,7 @@ TermView::TermView(int rows, int columns, int32 argc, const char** argv,
|
|||||||
fReportAnyMouseEvent(false)
|
fReportAnyMouseEvent(false)
|
||||||
{
|
{
|
||||||
_InitObject(argc, argv);
|
_InitObject(argc, argv);
|
||||||
SetTermSize(fRows, fColumns, true);
|
//SetTermSize(fRows, fColumns);
|
||||||
|
|
||||||
// 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.
|
||||||
@@ -225,6 +227,8 @@ TermView::TermView(BMessage* archive)
|
|||||||
SetFlags(Flags() | B_WILL_DRAW | B_FRAME_EVENTS
|
SetFlags(Flags() | B_WILL_DRAW | B_FRAME_EVENTS
|
||||||
| B_FULL_UPDATE_ON_RESIZE);
|
| B_FULL_UPDATE_ON_RESIZE);
|
||||||
|
|
||||||
|
BRect frame = Bounds();
|
||||||
|
|
||||||
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*)&fColumns) < B_OK)
|
if (archive->FindInt32("columns", (int32*)&fColumns) < B_OK)
|
||||||
@@ -244,6 +248,10 @@ TermView::TermView(BMessage* archive)
|
|||||||
// TODO: Retrieve colors, history size, etc. from archive
|
// TODO: Retrieve colors, history size, etc. from archive
|
||||||
_InitObject(argc, argv);
|
_InitObject(argc, argv);
|
||||||
|
|
||||||
|
bool useRect = false;
|
||||||
|
if ((archive->FindBool("use_rect", &useRect) == B_OK) && useRect)
|
||||||
|
SetTermSize(frame);
|
||||||
|
|
||||||
delete[] argv;
|
delete[] argv;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -325,7 +333,7 @@ TermView::_InitObject(int32 argc, const char** argv)
|
|||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
|
||||||
SetTermFont(be_fixed_font);
|
SetTermFont(be_fixed_font);
|
||||||
SetTermSize(fRows, fColumns, false);
|
SetTermSize(fRows, fColumns);
|
||||||
|
|
||||||
status_t status = fShell->Open(fRows, fColumns,
|
status_t status = fShell->Open(fRows, fColumns,
|
||||||
EncodingAsShortString(fEncoding), argc, argv);
|
EncodingAsShortString(fEncoding), argc, argv);
|
||||||
@@ -365,7 +373,13 @@ BArchivable *
|
|||||||
TermView::Instantiate(BMessage* data)
|
TermView::Instantiate(BMessage* data)
|
||||||
{
|
{
|
||||||
if (validate_instantiation(data, "TermView")) {
|
if (validate_instantiation(data, "TermView")) {
|
||||||
return new (std::nothrow) TermView(data);
|
TermView *view = new (std::nothrow) TermView(data);
|
||||||
|
/*BScrollView *scrollView = new BScrollView("term_scrollview",
|
||||||
|
view, B_FOLLOW_ALL, B_WILL_DRAW | B_FRAME_EVENTS, true, true);
|
||||||
|
view->SetScrollBar(scrollView->ScrollBar(B_VERTICAL));
|
||||||
|
scrollView->ResizeTo(200, 200);
|
||||||
|
return scrollView; */
|
||||||
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -484,7 +498,7 @@ TermView::Columns() const
|
|||||||
|
|
||||||
//! Set number of rows and columns in terminal
|
//! Set number of rows and columns in terminal
|
||||||
BRect
|
BRect
|
||||||
TermView::SetTermSize(int rows, int columns, bool resize)
|
TermView::SetTermSize(int rows, int columns)
|
||||||
{
|
{
|
||||||
//debug_printf("TermView::SetTermSize(%d, %d)\n", rows, columns);
|
//debug_printf("TermView::SetTermSize(%d, %d)\n", rows, columns);
|
||||||
if (rows > 0)
|
if (rows > 0)
|
||||||
@@ -514,9 +528,6 @@ TermView::SetTermSize(int rows, int columns, bool resize)
|
|||||||
|
|
||||||
BRect rect(0, 0, fColumns * fFontWidth, fRows * fFontHeight);
|
BRect rect(0, 0, fColumns * fFontWidth, fRows * fFontHeight);
|
||||||
|
|
||||||
if (resize)
|
|
||||||
ResizeTo(rect.Width(), rect.Height());
|
|
||||||
|
|
||||||
// synchronize the visible text buffer
|
// synchronize the visible text buffer
|
||||||
{
|
{
|
||||||
BAutolock _(fTextBuffer);
|
BAutolock _(fTextBuffer);
|
||||||
@@ -531,6 +542,28 @@ TermView::SetTermSize(int rows, int columns, bool resize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TermView::SetTermSize(BRect rect)
|
||||||
|
{
|
||||||
|
GetTermSizeFromRect(rect, &fRows, &fColumns);
|
||||||
|
SetTermSize(fRows, fColumns);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TermView::GetTermSizeFromRect(const BRect &rect, int *_rows,
|
||||||
|
int *_columns)
|
||||||
|
{
|
||||||
|
int columns = (rect.IntegerWidth() + 1) / fFontWidth;
|
||||||
|
int rows = (rect.IntegerHeight() + 1) / fFontHeight;
|
||||||
|
|
||||||
|
if (_rows)
|
||||||
|
*_rows = rows;
|
||||||
|
if (_columns)
|
||||||
|
*_columns = columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TermView::SetTextColor(rgb_color fore, rgb_color back)
|
TermView::SetTextColor(rgb_color fore, rgb_color back)
|
||||||
{
|
{
|
||||||
@@ -1383,7 +1416,7 @@ TermView::FrameResized(float width, float height)
|
|||||||
if (fResizeViewDisableCount > 0)
|
if (fResizeViewDisableCount > 0)
|
||||||
fResizeViewDisableCount--;
|
fResizeViewDisableCount--;
|
||||||
|
|
||||||
SetTermSize(rows, columns, false);
|
SetTermSize(rows, columns);
|
||||||
|
|
||||||
fFrameResized = true;
|
fFrameResized = true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,10 @@ public:
|
|||||||
void GetFontSize(int* width, int* height);
|
void GetFontSize(int* width, int* height);
|
||||||
int Rows() const;
|
int Rows() const;
|
||||||
int Columns() const;
|
int Columns() const;
|
||||||
BRect SetTermSize(int rows, int cols, bool resize);
|
BRect SetTermSize(int rows, int cols);
|
||||||
|
void SetTermSize(BRect rect);
|
||||||
|
void GetTermSizeFromRect(const BRect &rect,
|
||||||
|
int *rows, int *columns);
|
||||||
|
|
||||||
void SetTextColor(rgb_color fore, rgb_color back);
|
void SetTextColor(rgb_color fore, rgb_color back);
|
||||||
void SetSelectColor(rgb_color fore, rgb_color back);
|
void SetSelectColor(rgb_color fore, rgb_color back);
|
||||||
|
|||||||
@@ -514,7 +514,7 @@ TermWindow::MessageReceived(BMessage *message)
|
|||||||
message->FindInt32("columns", &columns);
|
message->FindInt32("columns", &columns);
|
||||||
message->FindInt32("rows", &rows);
|
message->FindInt32("rows", &rows);
|
||||||
|
|
||||||
_ActiveTermView()->SetTermSize(rows, columns, false);
|
_ActiveTermView()->SetTermSize(rows, columns);
|
||||||
|
|
||||||
_ResizeView(_ActiveTermView());
|
_ResizeView(_ActiveTermView());
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -61,6 +61,8 @@ Window::AttachTermView()
|
|||||||
BMessage message;
|
BMessage message;
|
||||||
message.AddString("class", "TermView");
|
message.AddString("class", "TermView");
|
||||||
message.AddString("add_on", TERM_SIGNATURE);
|
message.AddString("add_on", TERM_SIGNATURE);
|
||||||
|
message.AddBool("use_rect", true);
|
||||||
|
message.AddRect("_frame", Bounds().InsetByCopy(2, 2));
|
||||||
|
|
||||||
BView *termView = dynamic_cast<BView *>(instantiate_object(&message));
|
BView *termView = dynamic_cast<BView *>(instantiate_object(&message));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user