HaikuDepot: Added SetSelectable(bool) to TextDocumentView.

This commit is contained in:
Stephan Aßmus
2014-11-09 12:04:47 +01:00
parent 3ea675fc93
commit 6e2ac1775e
2 changed files with 24 additions and 4 deletions
@@ -25,6 +25,7 @@ TextDocumentView::TextDocumentView(const char* name)
fInsetBottom(0.0f), fInsetBottom(0.0f),
fCaretBounds(), fCaretBounds(),
fSelectionEnabled(true),
fShowCaret(false), fShowCaret(false),
fMouseDown(false) fMouseDown(false)
{ {
@@ -70,7 +71,7 @@ TextDocumentView::Draw(BRect updateRect)
fTextDocumentLayout.SetWidth(_TextLayoutWidth(Bounds().Width())); fTextDocumentLayout.SetWidth(_TextLayoutWidth(Bounds().Width()));
fTextDocumentLayout.Draw(this, BPoint(fInsetLeft, fInsetTop), updateRect); fTextDocumentLayout.Draw(this, BPoint(fInsetLeft, fInsetTop), updateRect);
if (fTextEditor.Get() == NULL) if (!fSelectionEnabled || fTextEditor.Get() == NULL)
return; return;
bool isCaret = fTextEditor->SelectionLength() == 0; bool isCaret = fTextEditor->SelectionLength() == 0;
@@ -87,7 +88,7 @@ TextDocumentView::Draw(BRect updateRect)
void void
TextDocumentView::Pulse() TextDocumentView::Pulse()
{ {
if (fTextEditor.Get() == NULL) if (!fSelectionEnabled || fTextEditor.Get() == NULL)
return; return;
// Blink cursor // Blink cursor
@@ -133,6 +134,9 @@ TextDocumentView::MakeFocus(bool focus)
void void
TextDocumentView::MouseDown(BPoint where) TextDocumentView::MouseDown(BPoint where)
{ {
if (!fSelectionEnabled)
return;
MakeFocus(); MakeFocus();
int32 modifiers = 0; int32 modifiers = 0;
@@ -158,6 +162,9 @@ void
TextDocumentView::MouseMoved(BPoint where, uint32 transit, TextDocumentView::MouseMoved(BPoint where, uint32 transit,
const BMessage* dragMessage) const BMessage* dragMessage)
{ {
if (!fSelectionEnabled)
return;
BCursor iBeamCursor(B_CURSOR_ID_I_BEAM); BCursor iBeamCursor(B_CURSOR_ID_I_BEAM);
SetViewCursor(&iBeamCursor); SetViewCursor(&iBeamCursor);
@@ -322,10 +329,21 @@ TextDocumentView::SetInsets(float left, float top, float right, float bottom)
} }
void
TextDocumentView::SetSelectionEnabled(bool enabled)
{
if (fSelectionEnabled == enabled)
return;
fSelectionEnabled = enabled;
Invalidate();
// TODO: Deselect
}
void void
TextDocumentView::SetCaret(BPoint location, bool extendSelection) TextDocumentView::SetCaret(BPoint location, bool extendSelection)
{ {
if (fTextEditor.Get() == NULL) if (!fSelectionEnabled || fTextEditor.Get() == NULL)
return; return;
location.x -= fInsetLeft; location.x -= fInsetLeft;
@@ -340,7 +358,7 @@ TextDocumentView::SetCaret(BPoint location, bool extendSelection)
void void
TextDocumentView::SelectAll() TextDocumentView::SelectAll()
{ {
if (fTextEditor.Get() == NULL) if (!fSelectionEnabled || fTextEditor.Get() == NULL)
return; return;
fTextEditor->SelectAll(); fTextEditor->SelectAll();
@@ -61,6 +61,7 @@ public:
void SetInsets(float left, float top, float right, void SetInsets(float left, float top, float right,
float bottom); float bottom);
void SetSelectionEnabled(bool enabled);
void SetCaret(BPoint where, bool extendSelection); void SetCaret(BPoint where, bool extendSelection);
void SelectAll(); void SelectAll();
@@ -90,6 +91,7 @@ private:
float fInsetBottom; float fInsetBottom;
BRect fCaretBounds; BRect fCaretBounds;
bool fSelectionEnabled;
bool fShowCaret; bool fShowCaret;
bool fMouseDown; bool fMouseDown;
}; };