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),
fCaretBounds(),
fSelectionEnabled(true),
fShowCaret(false),
fMouseDown(false)
{
@@ -70,7 +71,7 @@ TextDocumentView::Draw(BRect updateRect)
fTextDocumentLayout.SetWidth(_TextLayoutWidth(Bounds().Width()));
fTextDocumentLayout.Draw(this, BPoint(fInsetLeft, fInsetTop), updateRect);
if (fTextEditor.Get() == NULL)
if (!fSelectionEnabled || fTextEditor.Get() == NULL)
return;
bool isCaret = fTextEditor->SelectionLength() == 0;
@@ -87,7 +88,7 @@ TextDocumentView::Draw(BRect updateRect)
void
TextDocumentView::Pulse()
{
if (fTextEditor.Get() == NULL)
if (!fSelectionEnabled || fTextEditor.Get() == NULL)
return;
// Blink cursor
@@ -133,6 +134,9 @@ TextDocumentView::MakeFocus(bool focus)
void
TextDocumentView::MouseDown(BPoint where)
{
if (!fSelectionEnabled)
return;
MakeFocus();
int32 modifiers = 0;
@@ -158,6 +162,9 @@ void
TextDocumentView::MouseMoved(BPoint where, uint32 transit,
const BMessage* dragMessage)
{
if (!fSelectionEnabled)
return;
BCursor iBeamCursor(B_CURSOR_ID_I_BEAM);
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
TextDocumentView::SetCaret(BPoint location, bool extendSelection)
{
if (fTextEditor.Get() == NULL)
if (!fSelectionEnabled || fTextEditor.Get() == NULL)
return;
location.x -= fInsetLeft;
@@ -340,7 +358,7 @@ TextDocumentView::SetCaret(BPoint location, bool extendSelection)
void
TextDocumentView::SelectAll()
{
if (fTextEditor.Get() == NULL)
if (!fSelectionEnabled || fTextEditor.Get() == NULL)
return;
fTextEditor->SelectAll();
@@ -61,6 +61,7 @@ public:
void SetInsets(float left, float top, float right,
float bottom);
void SetSelectionEnabled(bool enabled);
void SetCaret(BPoint where, bool extendSelection);
void SelectAll();
@@ -90,6 +91,7 @@ private:
float fInsetBottom;
BRect fCaretBounds;
bool fSelectionEnabled;
bool fShowCaret;
bool fMouseDown;
};