From 61646809a3b5f7119937aedaba55b8c3f77fdfd9 Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Sun, 15 Nov 2009 16:15:28 +0000 Subject: [PATCH] The cursor didn't start blinking, unless the window was activated (by clicking outside and then inside the window). Copied the BTextView mechanism: Activate and Deactivate the view on MakeFocus and WindowActivated. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@34061 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/terminal/TermView.cpp | 62 +++++++++++++++++++++++++++------- src/apps/terminal/TermView.h | 6 +++- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/src/apps/terminal/TermView.cpp b/src/apps/terminal/TermView.cpp index c8e7a60861..c0487fe4c1 100644 --- a/src/apps/terminal/TermView.cpp +++ b/src/apps/terminal/TermView.cpp @@ -170,6 +170,7 @@ TermView::TermView(BRect frame, int32 argc, const char** argv, int32 historySize fColumns(COLUMNS_DEFAULT), fRows(ROWS_DEFAULT), fEncoding(M_UTF8), + fActive(false), fScrBufSize(historySize), fReportX10MouseEvent(false), fReportNormalMouseEvent(false), @@ -187,6 +188,7 @@ TermView::TermView(int rows, int columns, int32 argc, const char** argv, fColumns(columns), fRows(rows), fEncoding(M_UTF8), + fActive(false), fScrBufSize(historySize), fReportX10MouseEvent(false), fReportNormalMouseEvent(false), @@ -215,6 +217,7 @@ TermView::TermView(BMessage* archive) fColumns(COLUMNS_DEFAULT), fRows(ROWS_DEFAULT), fEncoding(M_UTF8), + fActive(false), fScrBufSize(1000), fReportX10MouseEvent(false), fReportNormalMouseEvent(false), @@ -752,6 +755,33 @@ TermView::_DetachShell() } +void +TermView::_Activate() +{ + fActive = true; + + if (fCursorBlinkRunner == NULL) { + BMessage blinkMessage(kBlinkCursor); + fCursorBlinkRunner = new (std::nothrow) BMessageRunner( + BMessenger(this), &blinkMessage, kCursorBlinkInterval); + } +} + + +void +TermView::_Deactivate() +{ + // DoIMConfirm(); + // make sure the cursor becomes visible + fCursorState = 0; + _InvalidateTextRect(fCursor.x, fCursor.y, fCursor.x, fCursor.y); + delete fCursorBlinkRunner; + fCursorBlinkRunner = NULL; + + fActive = false; +} + + //! Draw part of a line in the given view. void TermView::_DrawLinePart(int32 x1, int32 y1, uint16 attr, char *buf, @@ -1111,21 +1141,27 @@ void TermView::WindowActivated(bool active) { BView::WindowActivated(active); - if (active) { - // start cursor blinking - if (fCursorBlinkRunner == NULL) { - BMessage blinkMessage(kBlinkCursor); - fCursorBlinkRunner = new (std::nothrow) BMessageRunner( - BMessenger(this), &blinkMessage, kCursorBlinkInterval); - } + if (active && IsFocus()) { + if (!fActive) + _Activate(); } else { - // DoIMConfirm(); + if (fActive) + _Deactivate(); + } +} - // make sure the cursor becomes visible - fCursorState = 0; - _InvalidateTextRect(fCursor.x, fCursor.y, fCursor.x, fCursor.y); - delete fCursorBlinkRunner; - fCursorBlinkRunner = NULL; + +void +TermView::MakeFocus(bool focusState) +{ + BView::MakeFocus(focusState); + + if (focusState && Window() && Window()->IsActive()) { + if (!fActive) + _Activate(); + } else { + if (fActive) + _Deactivate(); } } diff --git a/src/apps/terminal/TermView.h b/src/apps/terminal/TermView.h index 9e843b3a0e..a355c19735 100644 --- a/src/apps/terminal/TermView.h +++ b/src/apps/terminal/TermView.h @@ -90,6 +90,7 @@ protected: virtual void DetachedFromWindow(); virtual void Draw(BRect updateRect); virtual void WindowActivated(bool active); + virtual void MakeFocus(bool focusState = true); virtual void KeyDown(const char* bytes, int32 numBytes); virtual void MouseDown(BPoint where); @@ -122,6 +123,9 @@ private: status_t _AttachShell(Shell* shell); void _DetachShell(); + void _Activate(); + void _Deactivate(); + void _AboutRequested(); void _DrawLinePart(int32 x1, int32 y1, uint16 attr, @@ -217,7 +221,7 @@ private: int fRows; int fEncoding; - + bool fActive; // Object pointer. TerminalBuffer* fTextBuffer; BasicTerminalBuffer* fVisibleTextBuffer;