The DataView can now also accept drop messages from others and itself; the
mouse is tracked when you're dragging over the view, and the affected area is selected. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10470 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -60,7 +60,8 @@ DataView::DataView(BRect rect, DataEditor &editor)
|
||||
fMouseSelectionStart(-1),
|
||||
fKeySelectionStart(-1),
|
||||
fBitPosition(0),
|
||||
fFitFontSize(false)
|
||||
fFitFontSize(false),
|
||||
fDragMessageSize(-1)
|
||||
{
|
||||
fPositionLength = 4;
|
||||
fStart = fEnd = 0;
|
||||
@@ -154,7 +155,16 @@ DataView::UpdateFromEditor(BMessage *message)
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
bool
|
||||
DataView::AcceptsDrop(const BMessage *message)
|
||||
{
|
||||
return !fEditor.IsReadOnly()
|
||||
&& (message->HasData("text/plain", B_MIME_TYPE)
|
||||
|| message->HasData(B_FILE_MIME_TYPE, B_MIME_TYPE));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DataView::MessageReceived(BMessage *message)
|
||||
{
|
||||
switch (message->what) {
|
||||
@@ -224,6 +234,20 @@ DataView::MessageReceived(BMessage *message)
|
||||
fEditor.Redo();
|
||||
break;
|
||||
|
||||
case B_MIME_DATA:
|
||||
if (AcceptsDrop(message)) {
|
||||
const void *data;
|
||||
ssize_t size;
|
||||
if (message->FindData("text/plain", B_MIME_TYPE, &data, &size) == B_OK
|
||||
|| message->FindData(B_FILE_MIME_TYPE, B_MIME_TYPE, &data, &size) == B_OK) {
|
||||
if (fEditor.Replace(fOffset + fStart, (const uint8 *)data, size) != B_OK)
|
||||
SetSelection(fStoredStart, fStoredEnd);
|
||||
|
||||
fDragMessageSize = -1;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
BView::MessageReceived(message);
|
||||
}
|
||||
@@ -933,6 +957,10 @@ DataView::InitiateDrag(view_focus focus)
|
||||
frame = bounds & frame;
|
||||
|
||||
DragMessage(drag, frame, NULL);
|
||||
|
||||
fStoredStart = fStart;
|
||||
fStoredEnd = fEnd;
|
||||
fDragMessageSize = length;
|
||||
}
|
||||
|
||||
|
||||
@@ -982,8 +1010,36 @@ DataView::MouseDown(BPoint where)
|
||||
|
||||
|
||||
void
|
||||
DataView::MouseMoved(BPoint where, uint32 transit, const BMessage */*dragMessage*/)
|
||||
DataView::MouseMoved(BPoint where, uint32 transit, const BMessage *dragMessage)
|
||||
{
|
||||
if (transit == B_EXITED_VIEW && fDragMessageSize > 0) {
|
||||
SetSelection(fStoredStart, fStoredEnd);
|
||||
fDragMessageSize = -1;
|
||||
}
|
||||
|
||||
if (dragMessage && AcceptsDrop(dragMessage)) {
|
||||
// handle drag message and tracking
|
||||
|
||||
if (transit == B_ENTERED_VIEW) {
|
||||
fStoredStart = fStart;
|
||||
fStoredEnd = fEnd;
|
||||
|
||||
const void *data;
|
||||
ssize_t size;
|
||||
if (dragMessage->FindData("text/plain", B_MIME_TYPE, &data, &size) == B_OK
|
||||
|| dragMessage->FindData("text/plain", B_MIME_TYPE, &data, &size) == B_OK)
|
||||
fDragMessageSize = size;
|
||||
} else if (fDragMessageSize > 0) {
|
||||
view_focus newFocus;
|
||||
int32 start = PositionAt(kNoFocus, where, &newFocus);
|
||||
int32 end = start + fDragMessageSize - 1;
|
||||
|
||||
SetSelection(start, end);
|
||||
MakeVisible(start);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (fMouseSelectionStart == -1)
|
||||
return;
|
||||
|
||||
|
||||
@@ -77,6 +77,7 @@ class DataView : public BView {
|
||||
void UpdateFromEditor(BMessage *message = NULL);
|
||||
void ConvertLine(char *line, off_t offset, const uint8 *buffer, size_t size);
|
||||
|
||||
bool AcceptsDrop(const BMessage *message);
|
||||
void InitiateDrag(view_focus focus);
|
||||
void Copy();
|
||||
void Paste();
|
||||
@@ -99,6 +100,8 @@ class DataView : public BView {
|
||||
int32 fKeySelectionStart;
|
||||
int32 fBitPosition;
|
||||
bool fFitFontSize;
|
||||
int32 fDragMessageSize;
|
||||
int32 fStoredStart, fStoredEnd;
|
||||
};
|
||||
|
||||
static const uint32 kMsgBaseType = 'base';
|
||||
|
||||
Reference in New Issue
Block a user