* Moved duplicated initializers to the _InitObject() method.
* Cleanup. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@28127 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+95
-154
@@ -147,138 +147,26 @@ private:
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
inline int32
|
||||
TermView::_LineAt(float y)
|
||||
{
|
||||
int32 location = int32(y + fScrollOffset);
|
||||
|
||||
// Make sure negative offsets are rounded towards the lower neighbor, too.
|
||||
if (location < 0)
|
||||
location -= fFontHeight - 1;
|
||||
|
||||
return location / fFontHeight;
|
||||
}
|
||||
|
||||
|
||||
inline float
|
||||
TermView::_LineOffset(int32 index)
|
||||
{
|
||||
return index * fFontHeight - fScrollOffset;
|
||||
}
|
||||
|
||||
|
||||
// convert view coordinates to terminal text buffer position
|
||||
inline TermPos
|
||||
TermView::_ConvertToTerminal(const BPoint &p)
|
||||
{
|
||||
return TermPos(p.x >= 0 ? (int32)p.x / fFontWidth : -1, _LineAt(p.y));
|
||||
}
|
||||
|
||||
|
||||
// convert terminal text buffer position to view coordinates
|
||||
inline BPoint
|
||||
TermView::_ConvertFromTerminal(const TermPos &pos)
|
||||
{
|
||||
return BPoint(fFontWidth * pos.x, _LineOffset(pos.y));
|
||||
}
|
||||
|
||||
|
||||
inline void
|
||||
TermView::_InvalidateTextRect(int32 x1, int32 y1, int32 x2, int32 y2)
|
||||
{
|
||||
BRect rect(x1 * fFontWidth, _LineOffset(y1),
|
||||
(x2 + 1) * fFontWidth - 1, _LineOffset(y2 + 1) - 1);
|
||||
//debug_printf("Invalidate((%f, %f) - (%f, %f))\n", rect.left, rect.top,
|
||||
//rect.right, rect.bottom);
|
||||
Invalidate(rect);
|
||||
}
|
||||
|
||||
|
||||
TermView::TermView(BRect frame, int32 argc, const char** argv, int32 historySize)
|
||||
: BView(frame, "termview", B_FOLLOW_ALL,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE | B_PULSE_NEEDED),
|
||||
fShell(NULL),
|
||||
fWinchRunner(NULL),
|
||||
fCursorBlinkRunner(NULL),
|
||||
fAutoScrollRunner(NULL),
|
||||
fResizeRunner(NULL),
|
||||
fResizeView(NULL),
|
||||
fCharClassifier(NULL),
|
||||
fFontWidth(0),
|
||||
fFontHeight(0),
|
||||
fFontAscent(0),
|
||||
fFrameResized(false),
|
||||
fLastActivityTime(0),
|
||||
fCursorState(0),
|
||||
fCursorHeight(0),
|
||||
fCursor(0, 0),
|
||||
fTermRows(ROWS_DEFAULT),
|
||||
fTermColumns(COLUMNS_DEFAULT),
|
||||
fEncoding(M_UTF8),
|
||||
fTextBuffer(NULL),
|
||||
fVisibleTextBuffer(NULL),
|
||||
fScrollBar(NULL),
|
||||
fTextForeColor(kBlackColor),
|
||||
fTextBackColor(kWhiteColor),
|
||||
fCursorForeColor(kWhiteColor),
|
||||
fCursorBackColor(kBlackColor),
|
||||
fSelectForeColor(kWhiteColor),
|
||||
fSelectBackColor(kBlackColor),
|
||||
fScrollOffset(0),
|
||||
fScrBufSize(historySize),
|
||||
fLastSyncTime(0),
|
||||
fScrolledSinceLastSync(0),
|
||||
fSyncRunner(NULL),
|
||||
fConsiderClockedSync(false),
|
||||
fSelStart(-1, -1),
|
||||
fSelEnd(-1, -1),
|
||||
fMouseTracking(false),
|
||||
fIMflag(false)
|
||||
fScrBufSize(historySize)
|
||||
{
|
||||
_InitObject(argc, argv);
|
||||
}
|
||||
|
||||
|
||||
TermView::TermView(int rows, int columns, int32 argc, const char **argv, int32 historySize)
|
||||
TermView::TermView(int rows, int columns, int32 argc, const char** argv,
|
||||
int32 historySize)
|
||||
: BView(BRect(0, 0, 0, 0), "termview", B_FOLLOW_ALL,
|
||||
B_WILL_DRAW | B_FRAME_EVENTS | B_FULL_UPDATE_ON_RESIZE | B_PULSE_NEEDED),
|
||||
fShell(NULL),
|
||||
fWinchRunner(NULL),
|
||||
fCursorBlinkRunner(NULL),
|
||||
fAutoScrollRunner(NULL),
|
||||
fResizeRunner(NULL),
|
||||
fResizeView(NULL),
|
||||
fCharClassifier(NULL),
|
||||
fFontWidth(0),
|
||||
fFontHeight(0),
|
||||
fFontAscent(0),
|
||||
fFrameResized(false),
|
||||
fLastActivityTime(0),
|
||||
fCursorState(0),
|
||||
fCursorHeight(0),
|
||||
fCursor(0, 0),
|
||||
fTermRows(rows),
|
||||
fTermColumns(columns),
|
||||
fEncoding(M_UTF8),
|
||||
fTextBuffer(NULL),
|
||||
fVisibleTextBuffer(NULL),
|
||||
fScrollBar(NULL),
|
||||
fTextForeColor(kBlackColor),
|
||||
fTextBackColor(kWhiteColor),
|
||||
fCursorForeColor(kWhiteColor),
|
||||
fCursorBackColor(kBlackColor),
|
||||
fSelectForeColor(kWhiteColor),
|
||||
fSelectBackColor(kBlackColor),
|
||||
fScrollOffset(0),
|
||||
fScrBufSize(historySize),
|
||||
fLastSyncTime(0),
|
||||
fScrolledSinceLastSync(0),
|
||||
fSyncRunner(NULL),
|
||||
fConsiderClockedSync(false),
|
||||
fSelStart(-1, -1),
|
||||
fSelEnd(-1, -1),
|
||||
fMouseTracking(false),
|
||||
fIMflag(false)
|
||||
fScrBufSize(historySize)
|
||||
{
|
||||
_InitObject(argc, argv);
|
||||
SetTermSize(fTermRows, fTermColumns, true);
|
||||
@@ -299,42 +187,10 @@ TermView::TermView(int rows, int columns, int32 argc, const char **argv, int32 h
|
||||
TermView::TermView(BMessage* archive)
|
||||
:
|
||||
BView(archive),
|
||||
fShell(NULL),
|
||||
fWinchRunner(NULL),
|
||||
fCursorBlinkRunner(NULL),
|
||||
fAutoScrollRunner(NULL),
|
||||
fResizeRunner(NULL),
|
||||
fResizeView(NULL),
|
||||
fCharClassifier(NULL),
|
||||
fFontWidth(0),
|
||||
fFontHeight(0),
|
||||
fFontAscent(0),
|
||||
fFrameResized(false),
|
||||
fLastActivityTime(0),
|
||||
fCursorState(0),
|
||||
fCursorHeight(0),
|
||||
fCursor(0, 0),
|
||||
fTermRows(ROWS_DEFAULT),
|
||||
fTermColumns(COLUMNS_DEFAULT),
|
||||
fEncoding(M_UTF8),
|
||||
fTextBuffer(NULL),
|
||||
fVisibleTextBuffer(NULL),
|
||||
fScrollBar(NULL),
|
||||
fTextForeColor(kBlackColor),
|
||||
fTextBackColor(kWhiteColor),
|
||||
fCursorForeColor(kWhiteColor),
|
||||
fCursorBackColor(kBlackColor),
|
||||
fSelectForeColor(kWhiteColor),
|
||||
fSelectBackColor(kBlackColor),
|
||||
fScrBufSize(1000),
|
||||
fLastSyncTime(0),
|
||||
fScrolledSinceLastSync(0),
|
||||
fSyncRunner(NULL),
|
||||
fConsiderClockedSync(false),
|
||||
fSelStart(-1, -1),
|
||||
fSelEnd(-1, -1),
|
||||
fMouseTracking(false),
|
||||
fIMflag(false)
|
||||
fScrBufSize(1000)
|
||||
{
|
||||
// We need this
|
||||
SetFlags(Flags() | B_WILL_DRAW | B_PULSE_NEEDED);
|
||||
@@ -362,9 +218,47 @@ TermView::TermView(BMessage *archive)
|
||||
}
|
||||
|
||||
|
||||
/*! Initializes the object for further use.
|
||||
The members fTermRows, fTermColumns, fEncoding, and fScrBufSize must
|
||||
already be initialized; they are not touched by this method.
|
||||
*/
|
||||
status_t
|
||||
TermView::_InitObject(int32 argc, const char** argv)
|
||||
{
|
||||
fShell = NULL;
|
||||
fWinchRunner = NULL;
|
||||
fCursorBlinkRunner = NULL;
|
||||
fAutoScrollRunner = NULL;
|
||||
fResizeRunner = NULL;
|
||||
fResizeView = NULL;
|
||||
fCharClassifier = NULL;
|
||||
fFontWidth = 0;
|
||||
fFontHeight = 0;
|
||||
fFontAscent = 0;
|
||||
fFrameResized = false;
|
||||
fLastActivityTime = 0;
|
||||
fCursorState = 0;
|
||||
fCursorHeight = 0;
|
||||
fCursor = TermPos(0, 0);
|
||||
fTextBuffer = NULL;
|
||||
fVisibleTextBuffer = NULL;
|
||||
fScrollBar = NULL;
|
||||
fTextForeColor = kBlackColor;
|
||||
fTextBackColor = kWhiteColor;
|
||||
fCursorForeColor = kWhiteColor;
|
||||
fCursorBackColor = kBlackColor;
|
||||
fSelectForeColor = kWhiteColor;
|
||||
fSelectBackColor = kBlackColor;
|
||||
fScrollOffset = 0;
|
||||
fLastSyncTime = 0;
|
||||
fScrolledSinceLastSync = 0;
|
||||
fSyncRunner = NULL;
|
||||
fConsiderClockedSync = false;
|
||||
fSelStart = TermPos(-1, -1);
|
||||
fSelEnd = TermPos(-1, -1);
|
||||
fMouseTracking = false;
|
||||
fIMflag = false;
|
||||
|
||||
fTextBuffer = new(std::nothrow) TerminalBuffer;
|
||||
if (fTextBuffer == NULL)
|
||||
return B_NO_MEMORY;
|
||||
@@ -397,8 +291,7 @@ TermView::_InitObject(int32 argc, const char **argv)
|
||||
//SetIMAware(false);
|
||||
|
||||
status_t status = fShell->Open(fTermRows, fTermColumns,
|
||||
EncodingAsShortString(fEncoding),
|
||||
argc, argv);
|
||||
EncodingAsShortString(fEncoding), argc, argv);
|
||||
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
@@ -407,7 +300,6 @@ TermView::_InitObject(int32 argc, const char **argv)
|
||||
if (status < B_OK)
|
||||
return status;
|
||||
|
||||
|
||||
SetLowColor(fTextBackColor);
|
||||
SetViewColor(B_TRANSPARENT_32_BIT);
|
||||
|
||||
@@ -462,6 +354,53 @@ TermView::Archive(BMessage* data, bool deep) const
|
||||
}
|
||||
|
||||
|
||||
inline int32
|
||||
TermView::_LineAt(float y)
|
||||
{
|
||||
int32 location = int32(y + fScrollOffset);
|
||||
|
||||
// Make sure negative offsets are rounded towards the lower neighbor, too.
|
||||
if (location < 0)
|
||||
location -= fFontHeight - 1;
|
||||
|
||||
return location / fFontHeight;
|
||||
}
|
||||
|
||||
|
||||
inline float
|
||||
TermView::_LineOffset(int32 index)
|
||||
{
|
||||
return index * fFontHeight - fScrollOffset;
|
||||
}
|
||||
|
||||
|
||||
// convert view coordinates to terminal text buffer position
|
||||
inline TermPos
|
||||
TermView::_ConvertToTerminal(const BPoint &p)
|
||||
{
|
||||
return TermPos(p.x >= 0 ? (int32)p.x / fFontWidth : -1, _LineAt(p.y));
|
||||
}
|
||||
|
||||
|
||||
// convert terminal text buffer position to view coordinates
|
||||
inline BPoint
|
||||
TermView::_ConvertFromTerminal(const TermPos &pos)
|
||||
{
|
||||
return BPoint(fFontWidth * pos.x, _LineOffset(pos.y));
|
||||
}
|
||||
|
||||
|
||||
inline void
|
||||
TermView::_InvalidateTextRect(int32 x1, int32 y1, int32 x2, int32 y2)
|
||||
{
|
||||
BRect rect(x1 * fFontWidth, _LineOffset(y1),
|
||||
(x2 + 1) * fFontWidth - 1, _LineOffset(y2 + 1) - 1);
|
||||
//debug_printf("Invalidate((%f, %f) - (%f, %f))\n", rect.left, rect.top,
|
||||
//rect.right, rect.bottom);
|
||||
Invalidate(rect);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
TermView::GetPreferredSize(float *width, float *height)
|
||||
{
|
||||
@@ -1607,8 +1546,10 @@ TermView::ResolveSpecifier(BMessage *message, int32 index, BMessage *specifier,
|
||||
{
|
||||
BHandler* target = this;
|
||||
BPropertyInfo propInfo(sPropList);
|
||||
if (propInfo.FindMatch(message, index, specifier, what, property) < B_OK)
|
||||
target = BView::ResolveSpecifier(message, index, specifier, what, property);
|
||||
if (propInfo.FindMatch(message, index, specifier, what, property) < B_OK) {
|
||||
target = BView::ResolveSpecifier(message, index, specifier, what,
|
||||
property);
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
* Stefano Ceccherini <stefano.ceccherini@gmail.com>
|
||||
* Kian Duffy, myob@users.sourceforge.net
|
||||
*/
|
||||
|
||||
#ifndef TERMVIEW_H
|
||||
#define TERMVIEW_H
|
||||
|
||||
@@ -32,16 +31,17 @@ class ResizeWindow;
|
||||
|
||||
class TermView : public BView {
|
||||
public:
|
||||
TermView(BRect frame, int32 argc, const char **argv, int32 historySize);
|
||||
TermView(int rows, int columns, int32 argc, const char **argv,
|
||||
TermView(BRect frame, int32 argc, const char** argv,
|
||||
int32 historySize);
|
||||
TermView(int rows, int columns, int32 argc,
|
||||
const char** argv, int32 historySize);
|
||||
TermView(BMessage* archive);
|
||||
~TermView();
|
||||
|
||||
static BArchivable* Instantiate(BMessage* data);
|
||||
virtual status_t Archive(BMessage* data, bool deep = true) const;
|
||||
|
||||
virtual void GetPreferredSize(float *width, float *height);
|
||||
virtual void GetPreferredSize(float* _width, float* _height);
|
||||
|
||||
const char* TerminalName() const;
|
||||
|
||||
@@ -61,7 +61,7 @@ public:
|
||||
void SetEncoding(int encoding);
|
||||
|
||||
//void SetIMAware(bool);
|
||||
void SetScrollBar(BScrollBar *scrbar);
|
||||
void SetScrollBar(BScrollBar* scrollBar);
|
||||
BScrollBar* ScrollBar() const { return fScrollBar; };
|
||||
|
||||
virtual void SetTitle(const char* title);
|
||||
@@ -75,8 +75,9 @@ public:
|
||||
|
||||
// Other
|
||||
void GetFrameSize(float* width, float* height);
|
||||
bool Find(const BString &str, bool forwardSearch, bool matchCase, bool matchWord);
|
||||
void GetSelection(BString &str);
|
||||
bool Find(const BString& str, bool forwardSearch,
|
||||
bool matchCase, bool matchWord);
|
||||
void GetSelection(BString& string);
|
||||
|
||||
void CheckShellGone();
|
||||
|
||||
@@ -87,10 +88,11 @@ protected:
|
||||
virtual void DetachedFromWindow();
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void WindowActivated(bool active);
|
||||
virtual void KeyDown(const char*, int32);
|
||||
virtual void KeyDown(const char* bytes, int32 numBytes);
|
||||
|
||||
virtual void MouseDown(BPoint where);
|
||||
virtual void MouseMoved(BPoint, uint32, const BMessage *);
|
||||
virtual void MouseMoved(BPoint where, uint32 transit,
|
||||
const BMessage* message);
|
||||
virtual void MouseUp(BPoint where);
|
||||
|
||||
virtual void FrameResized(float width, float height);
|
||||
@@ -107,10 +109,11 @@ private:
|
||||
// point and text offset conversion
|
||||
inline int32 _LineAt(float y);
|
||||
inline float _LineOffset(int32 index);
|
||||
inline TermPos _ConvertToTerminal(const BPoint &p);
|
||||
inline TermPos _ConvertToTerminal(const BPoint& point);
|
||||
inline BPoint _ConvertFromTerminal(const TermPos& pos);
|
||||
|
||||
inline void _InvalidateTextRect(int32 x1, int32 y1, int32 x2, int32 y2);
|
||||
inline void _InvalidateTextRect(int32 x1, int32 y1, int32 x2,
|
||||
int32 y2);
|
||||
|
||||
status_t _InitObject(int32 argc, const char** argv);
|
||||
|
||||
@@ -119,8 +122,9 @@ private:
|
||||
|
||||
void _AboutRequested();
|
||||
|
||||
void _DrawLinePart(int32 x1, int32 y1, uint16 attr, char *buf,
|
||||
int32 width, bool mouse, bool cursor, BView *inView);
|
||||
void _DrawLinePart(int32 x1, int32 y1, uint16 attr,
|
||||
char* buffer, int32 width, bool mouse,
|
||||
bool cursor, BView* inView);
|
||||
void _DrawCursor();
|
||||
void _InvalidateTextRange(TermPos start, TermPos end);
|
||||
|
||||
@@ -148,11 +152,14 @@ private:
|
||||
// selection
|
||||
void _Select(TermPos start, TermPos end, bool inclusive,
|
||||
bool setInitialSelection);
|
||||
void _ExtendSelection(TermPos, bool inclusive, bool useInitialSelection);
|
||||
void _ExtendSelection(TermPos, bool inclusive,
|
||||
bool useInitialSelection);
|
||||
void _Deselect();
|
||||
bool _HasSelection() const;
|
||||
void _SelectWord(BPoint where, bool extend, bool useInitialSelection);
|
||||
void _SelectLine(BPoint where, bool extend, bool useInitialSelection);
|
||||
void _SelectWord(BPoint where, bool extend,
|
||||
bool useInitialSelection);
|
||||
void _SelectLine(BPoint where, bool extend,
|
||||
bool useInitialSelection);
|
||||
|
||||
void _AutoScrollUpdate();
|
||||
|
||||
@@ -209,15 +216,18 @@ private:
|
||||
BScrollBar* fScrollBar;
|
||||
|
||||
// Color and Attribute.
|
||||
rgb_color fTextForeColor, fTextBackColor;
|
||||
rgb_color fCursorForeColor, fCursorBackColor;
|
||||
rgb_color fSelectForeColor, fSelectBackColor;
|
||||
rgb_color fTextForeColor;
|
||||
rgb_color fTextBackColor;
|
||||
rgb_color fCursorForeColor;
|
||||
rgb_color fCursorBackColor;
|
||||
rgb_color fSelectForeColor;
|
||||
rgb_color fSelectBackColor;
|
||||
|
||||
// Scroll Region
|
||||
float fScrollOffset;
|
||||
int32 fScrBufSize;
|
||||
// TODO: That's the history capacity -- only needed until the text
|
||||
// buffer is created.
|
||||
// TODO: That's the history capacity -- only needed
|
||||
// until the text buffer is created.
|
||||
float fAutoScrollSpeed;
|
||||
|
||||
// redraw management
|
||||
|
||||
Reference in New Issue
Block a user