hrev46699 adds 2 changesets to branch 'master' old head: 3828ba8a3fa427681ab57eb534fcbc3d04e2d3dc new head: a512ed9a8f16443b1b87f795e9a62bc85fbf2377 overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=a512ed9+%5E3828ba8 ---------------------------------------------------------------------------- 02d77b7: HaikuDepot: Implement a BScrollView which works. Need to investigate why the original one wouldn't layout the TextDocumentView to the inner size... a512ed9: HaikuDepot: Implement support for a blinking cursor. However, since the selection is actually maintained in TextEditor, the cursor can't be navigated. The code needs to shuffle around a bit. [ Stephan Aßmus <superstippi@xxxxxx> ] ---------------------------------------------------------------------------- 3 files changed, 119 insertions(+), 23 deletions(-) src/apps/haiku-depot/RatePackageWindow.cpp | 57 +++++++++++++- .../haiku-depot/textview/TextDocumentView.cpp | 82 +++++++++++++++----- src/apps/haiku-depot/textview/TextDocumentView.h | 3 + ############################################################################ Commit: 02d77b77aa0def149a59128d4df0a593a40ff1c1 URL: http://cgit.haiku-os.org/haiku/commit/?id=02d77b7 Author: Stephan Aßmus <superstippi@xxxxxx> Date: Fri Jan 17 22:23:30 2014 UTC HaikuDepot: Implement a BScrollView which works. Need to investigate why the original one wouldn't layout the TextDocumentView to the inner size... ---------------------------------------------------------------------------- diff --git a/src/apps/haiku-depot/RatePackageWindow.cpp b/src/apps/haiku-depot/RatePackageWindow.cpp index 2a7833a..19fefe6 100644 --- a/src/apps/haiku-depot/RatePackageWindow.cpp +++ b/src/apps/haiku-depot/RatePackageWindow.cpp @@ -26,6 +26,59 @@ enum { MSG_SEND = 'send' }; +//! Layouts the scrollbar so it looks nice with no border and the document +// window look. +class ScrollView : public BScrollView { +public: + ScrollView(const char* name, BView* target) + : + BScrollView(name, target, 0, false, true, B_FANCY_BORDER) + { + } + + virtual void DoLayout() + { + BRect innerFrame = Bounds(); + innerFrame.InsetBy(2, 2); + + BScrollBar* vScrollBar = ScrollBar(B_VERTICAL); + BScrollBar* hScrollBar = ScrollBar(B_HORIZONTAL); + + if (vScrollBar != NULL) + innerFrame.right -= vScrollBar->Bounds().Width() - 1; + if (hScrollBar != NULL) + innerFrame.bottom -= hScrollBar->Bounds().Height() - 1; + + BView* target = Target(); + if (target != NULL) { + Target()->MoveTo(innerFrame.left, innerFrame.top); + Target()->ResizeTo(innerFrame.Width(), innerFrame.Height()); + } + + if (vScrollBar != NULL) { + BRect rect = innerFrame; + rect.left = rect.right + 1; + rect.right = rect.left + vScrollBar->Bounds().Width(); + rect.top -= 1; + rect.bottom += 1; + + vScrollBar->MoveTo(rect.left, rect.top); + vScrollBar->ResizeTo(rect.Width(), rect.Height()); + } + + if (hScrollBar != NULL) { + BRect rect = innerFrame; + rect.top = rect.bottom + 1; + rect.bottom = rect.top + hScrollBar->Bounds().Height(); + rect.left -= 1; + rect.right += 1; + + hScrollBar->MoveTo(rect.left, rect.top); + hScrollBar->ResizeTo(rect.Width(), rect.Height()); + } + } +}; + RatePackageWindow::RatePackageWindow(BWindow* parent, BRect frame) : @@ -38,8 +91,8 @@ RatePackageWindow::RatePackageWindow(BWindow* parent, BRect frame) CenterIn(parent->Frame()); TextDocumentView* textView = new TextDocumentView(); - BScrollView* textScrollView = new BScrollView("rating scroll view", - textView); + ScrollView* textScrollView = new ScrollView( + "rating scroll view", textView); MarkupParser parser; fRatingText = parser.CreateDocumentFromMarkup( ############################################################################ Revision: hrev46699 Commit: a512ed9a8f16443b1b87f795e9a62bc85fbf2377 URL: http://cgit.haiku-os.org/haiku/commit/?id=a512ed9 Author: Stephan Aßmus <superstippi@xxxxxx> Date: Fri Jan 17 22:26:21 2014 UTC HaikuDepot: Implement support for a blinking cursor. However, since the selection is actually maintained in TextEditor, the cursor can't be navigated. The code needs to shuffle around a bit. ---------------------------------------------------------------------------- diff --git a/src/apps/haiku-depot/textview/TextDocumentView.cpp b/src/apps/haiku-depot/textview/TextDocumentView.cpp index ab7df8d..a9aea3e 100644 --- a/src/apps/haiku-depot/textview/TextDocumentView.cpp +++ b/src/apps/haiku-depot/textview/TextDocumentView.cpp @@ -67,34 +67,29 @@ TextDocumentView::Draw(BRect updateRect) fTextDocumentLayout.SetWidth(_TextLayoutWidth(Bounds().Width())); fTextDocumentLayout.Draw(this, BPoint(fInsetLeft, fInsetTop), updateRect); - if (fSelectionAnchorOffset == fCaretOffset) - return; - - int32 start; - int32 end; - GetSelection(start, end); - - BShape shape; - _GetSelectionShape(shape, start, end); + bool isCaret = fSelectionAnchorOffset == fCaretOffset; - SetDrawingMode(B_OP_SUBTRACT); - SetLineMode(B_ROUND_CAP, B_ROUND_JOIN); - MovePenTo(fInsetLeft - 0.5f, fInsetTop - 0.5f); - - if (IsFocus() && Window() != NULL && Window()->IsActive()) { - SetHighColor(30, 30, 30); - FillShape(&shape); + if (isCaret) { + if (fShowCaret && fTextEditor.Get() != NULL) + _DrawCaret(fCaretOffset); + } else { + _DrawSelection(); } - - SetHighColor(40, 40, 40); - StrokeShape(&shape); } void TextDocumentView::Pulse() { - // TODO: Blink cursor + if (fTextEditor.Get() == NULL) + return; + + // Blink cursor + fShowCaret = !fShowCaret; + if (fCaretBounds.IsValid()) + Invalidate(fCaretBounds); + else + Invalidate(); } @@ -465,7 +460,50 @@ TextDocumentView::_SetCaretOffset(int32 offset, bool updateAnchor, } -// _GetSelectionShape +void +TextDocumentView::_DrawCaret(int32 textOffset) +{ + float x1; + float y1; + float x2; + float y2; + + fTextDocumentLayout.GetTextBounds(textOffset, x1, y1, x2, y2); + x2 = x1 + 1; + + fCaretBounds = BRect(x1, y1, x2, y2); + fCaretBounds.OffsetBy(fInsetLeft, fInsetTop); + + SetDrawingMode(B_OP_INVERT); + FillRect(fCaretBounds); +} + + +void +TextDocumentView::_DrawSelection() +{ + int32 start; + int32 end; + GetSelection(start, end); + + BShape shape; + _GetSelectionShape(shape, start, end); + + SetDrawingMode(B_OP_SUBTRACT); + + SetLineMode(B_ROUND_CAP, B_ROUND_JOIN); + MovePenTo(fInsetLeft - 0.5f, fInsetTop - 0.5f); + + if (IsFocus() && Window() != NULL && Window()->IsActive()) { + SetHighColor(30, 30, 30); + FillShape(&shape); + } + + SetHighColor(40, 40, 40); + StrokeShape(&shape); +} + + void TextDocumentView::_GetSelectionShape(BShape& shape, int32 start, int32 end) { @@ -551,3 +589,5 @@ TextDocumentView::_GetSelectionShape(BShape& shape, int32 start, int32 end) shape.Close(); } } + + diff --git a/src/apps/haiku-depot/textview/TextDocumentView.h b/src/apps/haiku-depot/textview/TextDocumentView.h index 1d9498f..85094d9 100644 --- a/src/apps/haiku-depot/textview/TextDocumentView.h +++ b/src/apps/haiku-depot/textview/TextDocumentView.h @@ -76,6 +76,8 @@ private: void _SetCaretOffset(int32 offset, bool updateAnchor, bool lockSelectionAnchor); + void _DrawCaret(int32 textOffset); + void _DrawSelection(); void _GetSelectionShape(BShape& shape, int32 start, int32 end); @@ -93,6 +95,7 @@ private: int32 fCaretOffset; float fCaretAnchorX; bool fShowCaret; + BRect fCaretBounds; bool fMouseDown; };