* 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:
Axel Dörfler
2008-10-15 12:23:17 +00:00
parent a326b4f1b1
commit 302809b46f
2 changed files with 381 additions and 430 deletions
+95 -154
View File
@@ -147,138 +147,26 @@ private:
// #pragma mark - // #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) 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),
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), fTermRows(ROWS_DEFAULT),
fTermColumns(COLUMNS_DEFAULT), fTermColumns(COLUMNS_DEFAULT),
fEncoding(M_UTF8), fEncoding(M_UTF8),
fTextBuffer(NULL), fScrBufSize(historySize)
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)
{ {
_InitObject(argc, argv); _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, : 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),
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), fTermRows(rows),
fTermColumns(columns), fTermColumns(columns),
fEncoding(M_UTF8), fEncoding(M_UTF8),
fTextBuffer(NULL), fScrBufSize(historySize)
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)
{ {
_InitObject(argc, argv); _InitObject(argc, argv);
SetTermSize(fTermRows, fTermColumns, true); 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) TermView::TermView(BMessage* archive)
: :
BView(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), fTermRows(ROWS_DEFAULT),
fTermColumns(COLUMNS_DEFAULT), fTermColumns(COLUMNS_DEFAULT),
fEncoding(M_UTF8), fEncoding(M_UTF8),
fTextBuffer(NULL), fScrBufSize(1000)
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)
{ {
// We need this // We need this
SetFlags(Flags() | B_WILL_DRAW | B_PULSE_NEEDED); 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 status_t
TermView::_InitObject(int32 argc, const char** argv) 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; fTextBuffer = new(std::nothrow) TerminalBuffer;
if (fTextBuffer == NULL) if (fTextBuffer == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -397,8 +291,7 @@ TermView::_InitObject(int32 argc, const char **argv)
//SetIMAware(false); //SetIMAware(false);
status_t status = fShell->Open(fTermRows, fTermColumns, status_t status = fShell->Open(fTermRows, fTermColumns,
EncodingAsShortString(fEncoding), EncodingAsShortString(fEncoding), argc, argv);
argc, argv);
if (status < B_OK) if (status < B_OK)
return status; return status;
@@ -407,7 +300,6 @@ TermView::_InitObject(int32 argc, const char **argv)
if (status < B_OK) if (status < B_OK)
return status; return status;
SetLowColor(fTextBackColor); SetLowColor(fTextBackColor);
SetViewColor(B_TRANSPARENT_32_BIT); 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 void
TermView::GetPreferredSize(float *width, float *height) TermView::GetPreferredSize(float *width, float *height)
{ {
@@ -1607,8 +1546,10 @@ TermView::ResolveSpecifier(BMessage *message, int32 index, BMessage *specifier,
{ {
BHandler* target = this; BHandler* target = this;
BPropertyInfo propInfo(sPropList); BPropertyInfo propInfo(sPropList);
if (propInfo.FindMatch(message, index, specifier, what, property) < B_OK) if (propInfo.FindMatch(message, index, specifier, what, property) < B_OK) {
target = BView::ResolveSpecifier(message, index, specifier, what, property); target = BView::ResolveSpecifier(message, index, specifier, what,
property);
}
return target; return target;
} }
+31 -21
View File
@@ -8,7 +8,6 @@
* Stefano Ceccherini <stefano.ceccherini@gmail.com> * Stefano Ceccherini <stefano.ceccherini@gmail.com>
* Kian Duffy, myob@users.sourceforge.net * Kian Duffy, myob@users.sourceforge.net
*/ */
#ifndef TERMVIEW_H #ifndef TERMVIEW_H
#define TERMVIEW_H #define TERMVIEW_H
@@ -32,16 +31,17 @@ class ResizeWindow;
class TermView : public BView { class TermView : public BView {
public: public:
TermView(BRect frame, int32 argc, const char **argv, int32 historySize); TermView(BRect frame, int32 argc, const char** argv,
TermView(int rows, int columns, int32 argc, const char **argv,
int32 historySize); int32 historySize);
TermView(int rows, int columns, int32 argc,
const char** argv, int32 historySize);
TermView(BMessage* archive); TermView(BMessage* archive);
~TermView(); ~TermView();
static BArchivable* Instantiate(BMessage* data); static BArchivable* Instantiate(BMessage* data);
virtual status_t Archive(BMessage* data, bool deep = true) const; 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; const char* TerminalName() const;
@@ -61,7 +61,7 @@ public:
void SetEncoding(int encoding); void SetEncoding(int encoding);
//void SetIMAware(bool); //void SetIMAware(bool);
void SetScrollBar(BScrollBar *scrbar); void SetScrollBar(BScrollBar* scrollBar);
BScrollBar* ScrollBar() const { return fScrollBar; }; BScrollBar* ScrollBar() const { return fScrollBar; };
virtual void SetTitle(const char* title); virtual void SetTitle(const char* title);
@@ -75,8 +75,9 @@ public:
// Other // Other
void GetFrameSize(float* width, float* height); void GetFrameSize(float* width, float* height);
bool Find(const BString &str, bool forwardSearch, bool matchCase, bool matchWord); bool Find(const BString& str, bool forwardSearch,
void GetSelection(BString &str); bool matchCase, bool matchWord);
void GetSelection(BString& string);
void CheckShellGone(); void CheckShellGone();
@@ -87,10 +88,11 @@ protected:
virtual void DetachedFromWindow(); virtual void DetachedFromWindow();
virtual void Draw(BRect updateRect); virtual void Draw(BRect updateRect);
virtual void WindowActivated(bool active); 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 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 MouseUp(BPoint where);
virtual void FrameResized(float width, float height); virtual void FrameResized(float width, float height);
@@ -107,10 +109,11 @@ private:
// point and text offset conversion // point and text offset conversion
inline int32 _LineAt(float y); inline int32 _LineAt(float y);
inline float _LineOffset(int32 index); inline float _LineOffset(int32 index);
inline TermPos _ConvertToTerminal(const BPoint &p); inline TermPos _ConvertToTerminal(const BPoint& point);
inline BPoint _ConvertFromTerminal(const TermPos& pos); 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); status_t _InitObject(int32 argc, const char** argv);
@@ -119,8 +122,9 @@ private:
void _AboutRequested(); void _AboutRequested();
void _DrawLinePart(int32 x1, int32 y1, uint16 attr, char *buf, void _DrawLinePart(int32 x1, int32 y1, uint16 attr,
int32 width, bool mouse, bool cursor, BView *inView); char* buffer, int32 width, bool mouse,
bool cursor, BView* inView);
void _DrawCursor(); void _DrawCursor();
void _InvalidateTextRange(TermPos start, TermPos end); void _InvalidateTextRange(TermPos start, TermPos end);
@@ -148,11 +152,14 @@ private:
// selection // selection
void _Select(TermPos start, TermPos end, bool inclusive, void _Select(TermPos start, TermPos end, bool inclusive,
bool setInitialSelection); bool setInitialSelection);
void _ExtendSelection(TermPos, bool inclusive, bool useInitialSelection); void _ExtendSelection(TermPos, bool inclusive,
bool useInitialSelection);
void _Deselect(); void _Deselect();
bool _HasSelection() const; bool _HasSelection() const;
void _SelectWord(BPoint where, bool extend, bool useInitialSelection); void _SelectWord(BPoint where, bool extend,
void _SelectLine(BPoint where, bool extend, bool useInitialSelection); bool useInitialSelection);
void _SelectLine(BPoint where, bool extend,
bool useInitialSelection);
void _AutoScrollUpdate(); void _AutoScrollUpdate();
@@ -209,15 +216,18 @@ private:
BScrollBar* fScrollBar; BScrollBar* fScrollBar;
// Color and Attribute. // Color and Attribute.
rgb_color fTextForeColor, fTextBackColor; rgb_color fTextForeColor;
rgb_color fCursorForeColor, fCursorBackColor; rgb_color fTextBackColor;
rgb_color fSelectForeColor, fSelectBackColor; rgb_color fCursorForeColor;
rgb_color fCursorBackColor;
rgb_color fSelectForeColor;
rgb_color fSelectBackColor;
// Scroll Region // Scroll Region
float fScrollOffset; float fScrollOffset;
int32 fScrBufSize; int32 fScrBufSize;
// TODO: That's the history capacity -- only needed until the text // TODO: That's the history capacity -- only needed
// buffer is created. // until the text buffer is created.
float fAutoScrollSpeed; float fAutoScrollSpeed;
// redraw management // redraw management