Work in progress, almost synched with the code on my hard drive:
Moved some functionalities to private methods, some small fix. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8336 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -175,41 +175,7 @@ int32 BTextView::sWidthAtom = 0;
|
|||||||
BTextView::BTextView(BRect frame, const char *name, BRect textRect,
|
BTextView::BTextView(BRect frame, const char *name, BRect textRect,
|
||||||
uint32 resizeMask, uint32 flags)
|
uint32 resizeMask, uint32 flags)
|
||||||
: BView(frame, name, resizeMask,
|
: BView(frame, name, resizeMask,
|
||||||
flags | B_FRAME_EVENTS | B_PULSE_NEEDED | B_INPUT_METHOD_AWARE),
|
flags | B_FRAME_EVENTS | B_PULSE_NEEDED | B_INPUT_METHOD_AWARE)
|
||||||
fText(NULL),
|
|
||||||
fLines(NULL),
|
|
||||||
fStyles(NULL),
|
|
||||||
fTextRect(textRect),
|
|
||||||
fSelStart(0),
|
|
||||||
fSelEnd(0),
|
|
||||||
fCaretVisible(false),
|
|
||||||
fCaretTime(0),
|
|
||||||
fClickOffset(-1),
|
|
||||||
fClickCount(0),
|
|
||||||
fClickTime(0),
|
|
||||||
fDragOffset(-1),
|
|
||||||
//fCursor
|
|
||||||
fActive(false),
|
|
||||||
fStylable(false),
|
|
||||||
fTabWidth(28.0f),
|
|
||||||
fSelectable(true),
|
|
||||||
fEditable(true),
|
|
||||||
fWrap(true),
|
|
||||||
fMaxBytes(0),
|
|
||||||
fDisallowedChars(NULL),
|
|
||||||
fAlignment(B_ALIGN_LEFT),
|
|
||||||
fAutoindent(false),
|
|
||||||
fOffscreen(NULL),
|
|
||||||
fColorSpace(B_CMAP8),
|
|
||||||
fResizable(false),
|
|
||||||
fContainerView(NULL),
|
|
||||||
fUndo(NULL),
|
|
||||||
fInline(NULL),
|
|
||||||
fDragRunner(NULL),
|
|
||||||
fClickRunner(NULL),
|
|
||||||
//fWhere
|
|
||||||
fTrackingMouse(NULL),
|
|
||||||
fTextChange(NULL)
|
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
InitObject(textRect, NULL, NULL);
|
InitObject(textRect, NULL, NULL);
|
||||||
@@ -220,41 +186,7 @@ BTextView::BTextView(BRect frame, const char *name, BRect textRect,
|
|||||||
const BFont *initialFont, const rgb_color *initialColor,
|
const BFont *initialFont, const rgb_color *initialColor,
|
||||||
uint32 resizeMask, uint32 flags)
|
uint32 resizeMask, uint32 flags)
|
||||||
: BView(frame, name, resizeMask,
|
: BView(frame, name, resizeMask,
|
||||||
flags | B_FRAME_EVENTS | B_PULSE_NEEDED | B_INPUT_METHOD_AWARE),
|
flags | B_FRAME_EVENTS | B_PULSE_NEEDED | B_INPUT_METHOD_AWARE)
|
||||||
fText(NULL),
|
|
||||||
fLines(NULL),
|
|
||||||
fStyles(NULL),
|
|
||||||
fTextRect(textRect),
|
|
||||||
fSelStart(0),
|
|
||||||
fSelEnd(0),
|
|
||||||
fCaretVisible(false),
|
|
||||||
fCaretTime(0),
|
|
||||||
fClickOffset(-1),
|
|
||||||
fClickCount(0),
|
|
||||||
fClickTime(0),
|
|
||||||
fDragOffset(-1),
|
|
||||||
//fCursor
|
|
||||||
fActive(false),
|
|
||||||
fStylable(false),
|
|
||||||
fTabWidth(28.0f),
|
|
||||||
fSelectable(true),
|
|
||||||
fEditable(true),
|
|
||||||
fWrap(true),
|
|
||||||
fMaxBytes(0),
|
|
||||||
fDisallowedChars(NULL),
|
|
||||||
fAlignment(B_ALIGN_LEFT),
|
|
||||||
fAutoindent(false),
|
|
||||||
fOffscreen(NULL),
|
|
||||||
fColorSpace(B_CMAP8),
|
|
||||||
fResizable(false),
|
|
||||||
fContainerView(NULL),
|
|
||||||
fUndo(NULL),
|
|
||||||
fInline(NULL),
|
|
||||||
fDragRunner(NULL),
|
|
||||||
fClickRunner(NULL),
|
|
||||||
//fWhere
|
|
||||||
fTrackingMouse(NULL),
|
|
||||||
fTextChange(NULL)
|
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
InitObject(textRect, initialFont, initialColor);
|
InitObject(textRect, initialFont, initialColor);
|
||||||
@@ -345,13 +277,14 @@ BTextView::BTextView(BMessage *archive)
|
|||||||
BTextView::~BTextView()
|
BTextView::~BTextView()
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
|
CancelInputMethod();
|
||||||
|
DeleteOffscreen();
|
||||||
|
|
||||||
delete fText;
|
delete fText;
|
||||||
delete fLines;
|
delete fLines;
|
||||||
delete fStyles;
|
delete fStyles;
|
||||||
delete fDisallowedChars;
|
delete fDisallowedChars;
|
||||||
delete fUndo;
|
delete fUndo;
|
||||||
|
|
||||||
DeleteOffscreen();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -441,6 +374,11 @@ BTextView::AttachedToWindow()
|
|||||||
AutoResize(true);
|
AutoResize(true);
|
||||||
|
|
||||||
UpdateScrollbars();
|
UpdateScrollbars();
|
||||||
|
|
||||||
|
if (!fCursor)
|
||||||
|
SetViewCursor(B_CURSOR_I_BEAM);
|
||||||
|
else
|
||||||
|
SetViewCursor(B_CURSOR_SYSTEM_DEFAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -493,10 +431,8 @@ BTextView::MouseDown(BPoint where)
|
|||||||
if (!fEditable && !fSelectable)
|
if (!fEditable && !fSelectable)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!IsFocus()) {
|
if (!IsFocus())
|
||||||
MakeFocus();
|
MakeFocus();
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// hide the caret if it's visible
|
// hide the caret if it's visible
|
||||||
if (fCaretVisible)
|
if (fCaretVisible)
|
||||||
@@ -660,22 +596,19 @@ void
|
|||||||
BTextView::MouseMoved(BPoint where, uint32 code, const BMessage *message)
|
BTextView::MouseMoved(BPoint where, uint32 code, const BMessage *message)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
|
bool sync = false;
|
||||||
switch (code) {
|
switch (code) {
|
||||||
|
// We force a sync when the mouse enters the view
|
||||||
case B_ENTERED_VIEW:
|
case B_ENTERED_VIEW:
|
||||||
if (fActive && message == NULL)
|
sync = true;
|
||||||
SetViewCursor(B_CURSOR_I_BEAM);
|
// supposed to fall through
|
||||||
break;
|
|
||||||
|
|
||||||
case B_INSIDE_VIEW:
|
case B_INSIDE_VIEW:
|
||||||
if (message != NULL) {
|
TrackMouse(where, message, sync);
|
||||||
if (AcceptsDrop(message))
|
|
||||||
DragCaret(OffsetAt(where));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case B_EXITED_VIEW:
|
case B_EXITED_VIEW:
|
||||||
DragCaret(-1);
|
DragCaret(-1);
|
||||||
if (fActive)
|
if (Window()->IsActive() && message == NULL)
|
||||||
SetViewCursor(B_CURSOR_SYSTEM_DEFAULT);
|
SetViewCursor(B_CURSOR_SYSTEM_DEFAULT);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -703,7 +636,14 @@ BTextView::WindowActivated(bool state)
|
|||||||
} else {
|
} else {
|
||||||
if (fActive)
|
if (fActive)
|
||||||
Deactivate();
|
Deactivate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BPoint where;
|
||||||
|
ulong buttons;
|
||||||
|
GetMouse(&where, &buttons, true);
|
||||||
|
|
||||||
|
if (Bounds().Contains(where))
|
||||||
|
TrackMouse(where, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -985,7 +925,7 @@ BTextView::ResolveSpecifier(BMessage *message, int32 index,
|
|||||||
BPropertyInfo propInfo(sPropertyList);
|
BPropertyInfo propInfo(sPropertyList);
|
||||||
BHandler *target = NULL;
|
BHandler *target = NULL;
|
||||||
|
|
||||||
if (propInfo.FindMatch(message, index, specifier, what, property) != B_ERROR)
|
if (propInfo.FindMatch(message, index, specifier, what, property) > B_ERROR)
|
||||||
target = this;
|
target = this;
|
||||||
|
|
||||||
if (!target)
|
if (!target)
|
||||||
@@ -1470,7 +1410,7 @@ bool
|
|||||||
BTextView::AcceptsDrop(const BMessage *inMessage)
|
BTextView::AcceptsDrop(const BMessage *inMessage)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
if (fEditable && inMessage->HasData("text/plain", B_MIME_TYPE))
|
if (fEditable && inMessage && inMessage->HasData("text/plain", B_MIME_TYPE))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
@@ -2761,6 +2701,38 @@ BTextView::InitObject(BRect textRect, const BFont *initialFont,
|
|||||||
fText = new _BTextGapBuffer_;
|
fText = new _BTextGapBuffer_;
|
||||||
fLines = new _BLineBuffer_;
|
fLines = new _BLineBuffer_;
|
||||||
fStyles = new _BStyleBuffer_(&font, initialColor);
|
fStyles = new _BStyleBuffer_(&font, initialColor);
|
||||||
|
|
||||||
|
// We put these here instead of in the constructor initializer list
|
||||||
|
// to have less code duplication, and a single place where to do changes
|
||||||
|
// if needed.,
|
||||||
|
fTextRect = textRect;
|
||||||
|
fSelStart = fSelEnd = 0;
|
||||||
|
fCaretVisible = false;
|
||||||
|
fCaretTime = 0;
|
||||||
|
fClickOffset = 0;
|
||||||
|
fClickCount = 0;
|
||||||
|
fClickTime = 0;
|
||||||
|
fDragOffset = -1;
|
||||||
|
fCursor = 0;
|
||||||
|
fActive = false;
|
||||||
|
fStylable = false;
|
||||||
|
fSelectable = true;
|
||||||
|
fEditable = true;
|
||||||
|
fWrap = true;
|
||||||
|
fMaxBytes = LONG_MAX;
|
||||||
|
fDisallowedChars = NULL;
|
||||||
|
fAlignment = B_ALIGN_LEFT;
|
||||||
|
fAutoindent = false;
|
||||||
|
fOffscreen = NULL;
|
||||||
|
fColorSpace = B_CMAP8;
|
||||||
|
fResizable = false;
|
||||||
|
fContainerView = NULL;
|
||||||
|
fUndo = NULL;
|
||||||
|
fInline = NULL;
|
||||||
|
fDragRunner = NULL;
|
||||||
|
fClickRunner = NULL;
|
||||||
|
fTrackingMouse = NULL;
|
||||||
|
fTextChange = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -3583,17 +3555,42 @@ bool BTextView::PerformMouseMoved(BPoint where, uint32 code)
|
|||||||
CALLED();
|
CALLED();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
/*! \brief Tracks the mouse position, doing special actions like changing the view cursor.
|
||||||
|
\param where The point where the mouse has moved.
|
||||||
|
\param message The dragging message, if there is any.
|
||||||
|
\param force Passed as second parameter of SetViewCursor()
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
BTextView::TrackMouse(BPoint where, const BMessage *message, bool force)
|
BTextView::TrackMouse(BPoint where, const BMessage *message, bool force)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
|
|
||||||
|
BRegion textRegion;
|
||||||
|
GetTextRegion(fSelStart, fSelEnd, &textRegion);
|
||||||
|
|
||||||
|
if (AcceptsDrop(message))
|
||||||
|
TrackDrag(where);
|
||||||
|
else if (!textRegion.Contains(where))
|
||||||
|
SetViewCursor(B_CURSOR_I_BEAM, force);
|
||||||
|
// If we are within the selection, switch to the "hand" cursor,
|
||||||
|
else
|
||||||
|
SetViewCursor(B_CURSOR_SYSTEM_DEFAULT, force);
|
||||||
}
|
}
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
|
/*! \brief Tracks the mouse position when the user is dragging some data.
|
||||||
|
\param where The point where the mouse has moved.
|
||||||
|
*/
|
||||||
void
|
void
|
||||||
BTextView::TrackDrag(BPoint where)
|
BTextView::TrackDrag(BPoint where)
|
||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
|
if (Bounds().Contains(where)) {
|
||||||
|
int32 offset = OffsetAt(where);
|
||||||
|
DragCaret(offset);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -3637,8 +3634,8 @@ BTextView::MessageDropped(BMessage *inMessage, BPoint where, BPoint offset)
|
|||||||
&& from == this && fSelEnd != fSelStart)
|
&& from == this && fSelEnd != fSelStart)
|
||||||
internalDrop = true;
|
internalDrop = true;
|
||||||
|
|
||||||
if (fActive)
|
DragCaret(-1);
|
||||||
SetViewCursor(B_CURSOR_I_BEAM);
|
TrackMouse(where, NULL);
|
||||||
|
|
||||||
// are we sure we like this message?
|
// are we sure we like this message?
|
||||||
if (!AcceptsDrop(inMessage))
|
if (!AcceptsDrop(inMessage))
|
||||||
@@ -4015,6 +4012,9 @@ BTextView::HandleInputMethodChanged(BMessage *message)
|
|||||||
{
|
{
|
||||||
CALLED();
|
CALLED();
|
||||||
// TODO: Implement me
|
// TODO: Implement me
|
||||||
|
if (!fInline)
|
||||||
|
return;
|
||||||
|
|
||||||
message->PrintToStream();
|
message->PrintToStream();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4024,8 +4024,10 @@ BTextView::HandleInputMethodChanged(BMessage *message)
|
|||||||
void
|
void
|
||||||
BTextView::HandleInputMethodLocationRequest()
|
BTextView::HandleInputMethodLocationRequest()
|
||||||
{
|
{
|
||||||
// TODO: Implement me
|
|
||||||
CALLED();
|
CALLED();
|
||||||
|
if (!fInline)
|
||||||
|
return;
|
||||||
|
// TODO: Implement me
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user