TextDocumentView: Implemented beginnings of mouse-selection
This commit is contained in:
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <ScrollBar.h>
|
#include <ScrollBar.h>
|
||||||
#include <Shape.h>
|
#include <Shape.h>
|
||||||
|
#include <Window.h>
|
||||||
|
|
||||||
|
|
||||||
TextDocumentView::TextDocumentView(const char* name)
|
TextDocumentView::TextDocumentView(const char* name)
|
||||||
@@ -88,12 +89,20 @@ TextDocumentView::FrameResized(float width, float height)
|
|||||||
void
|
void
|
||||||
TextDocumentView::MouseDown(BPoint where)
|
TextDocumentView::MouseDown(BPoint where)
|
||||||
{
|
{
|
||||||
|
int32 modifiers = 0;
|
||||||
|
if (Window() != NULL && Window()->CurrentMessage() != NULL)
|
||||||
|
Window()->CurrentMessage()->FindInt32("modifiers", modifiers);
|
||||||
|
|
||||||
|
fMouseDown = true;
|
||||||
|
bool extendSelection = (modifiers & B_SHIFT_KEY) != 0;
|
||||||
|
SetCaret(where, extendSelection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
TextDocumentView::MouseUp(BPoint where)
|
TextDocumentView::MouseUp(BPoint where)
|
||||||
{
|
{
|
||||||
|
fMouseDown = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -101,6 +110,8 @@ void
|
|||||||
TextDocumentView::MouseMoved(BPoint where, uint32 transit,
|
TextDocumentView::MouseMoved(BPoint where, uint32 transit,
|
||||||
const BMessage* dragMessage)
|
const BMessage* dragMessage)
|
||||||
{
|
{
|
||||||
|
if (fMouseDown)
|
||||||
|
SetCaret(where, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -198,6 +209,23 @@ TextDocumentView::SetInsets(float left, float top, float right, float bottom)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
TextDocumentView::SetCaret(const BPoint& location, bool extendSelection)
|
||||||
|
{
|
||||||
|
if (fTextDocument.Get() == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
bool rightOfChar = false;
|
||||||
|
int32 caretOffset = fTextDocumentLayout.TextOffsetAt(
|
||||||
|
location.x - fInsetLeft, location.y - fInsetTop, rightOfChar);
|
||||||
|
|
||||||
|
if (rightOfChar)
|
||||||
|
caretOffset++;
|
||||||
|
|
||||||
|
_SetCaretOffset(caretOffset, true, extendSelection);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// #pragma mark - private
|
// #pragma mark - private
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ public:
|
|||||||
void SetInsets(float horizontal, float vertical);
|
void SetInsets(float horizontal, float vertical);
|
||||||
void SetInsets(float left, float top, float right,
|
void SetInsets(float left, float top, float right,
|
||||||
float bottom);
|
float bottom);
|
||||||
|
|
||||||
|
void SetCaret(const BPoint& where,
|
||||||
|
bool extendSelection);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float _TextLayoutWidth(float viewWidth) const;
|
float _TextLayoutWidth(float viewWidth) const;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user