Added feature where a file dropped from the Tracker becomes the current selection

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6121 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Matthew Wilber
2004-01-18 00:32:51 +00:00
parent ff3a346fc5
commit 869e256d67
2 changed files with 68 additions and 25 deletions
+65 -23
View File
@@ -406,6 +406,31 @@ ShowImageView::SetImage(const entry_ref *pref)
return B_OK; return B_OK;
} }
status_t
ShowImageView::SetSelection(const entry_ref *pref, BPoint point)
{
BTranslatorRoster *proster = BTranslatorRoster::Default();
if (!proster)
return B_ERROR;
BFile file(pref, B_READ_ONLY);
translator_info info;
memset(&info, 0, sizeof(translator_info));
if (proster->Identify(&file, NULL, &info, 0, NULL,
B_TRANSLATOR_BITMAP) != B_OK)
return B_ERROR;
// Translate image data and create a new ShowImage window
BBitmapStream outstream;
if (proster->Translate(&file, &info, NULL, &outstream,
B_TRANSLATOR_BITMAP) != B_OK)
return B_ERROR;
BBitmap *newBitmap = NULL;
if (outstream.DetachBitmap(&newBitmap) != B_OK)
return B_ERROR;
return PasteBitmap(newBitmap, point);
}
void void
ShowImageView::SetDither(bool dither) ShowImageView::SetDither(bool dither)
{ {
@@ -1449,33 +1474,46 @@ ShowImageView::MessageReceived(BMessage *pmsg)
} }
case B_SIMPLE_DATA: case B_SIMPLE_DATA:
// If a user drags a clip from another ShowImage window,
// request a BBitmap pointer to that clip, allocated by the
// other view, for use solely by this view, so that it can
// be dropped/pasted onto this view.
if (pmsg->WasDropped()) { if (pmsg->WasDropped()) {
BMessenger retMsgr, localMsgr(this); uint32 type;
retMsgr = pmsg->ReturnAddress(); int32 count;
if (retMsgr != localMsgr) { status_t ret = pmsg->GetInfo("refs", &type, &count);
BMessage msgReply; if (ret == B_OK && type == B_REF_TYPE) {
retMsgr.SendMessage(MSG_SELECTION_BITMAP, &msgReply); // If file was dropped, open it as the selection
BBitmap *bitmap = NULL; entry_ref ref;
if (msgReply.FindPointer("be:_bitmap_ptr", if (pmsg->FindRef("refs", 0, &ref) == B_OK) {
reinterpret_cast<void **>(&bitmap)) == B_OK) { BPoint point = pmsg->DropPoint();
BRect sourceRect;
BPoint point, sourcePoint;
pmsg->FindPoint("be:_source_point", &sourcePoint);
pmsg->FindRect("be:_frame", &sourceRect);
point = pmsg->DropPoint();
point.Set(point.x - (sourcePoint.x - sourceRect.left),
point.y - (sourcePoint.y - sourceRect.top));
// adjust drop point before scaling is factored in
point = ConvertFromScreen(point); point = ConvertFromScreen(point);
point = ViewToImage(point); point = ViewToImage(point);
SetSelection(&ref, point);
PasteBitmap(bitmap, point);
} }
} else {
// If a user drags a clip from another ShowImage window,
// request a BBitmap pointer to that clip, allocated by the
// other view, for use solely by this view, so that it can
// be dropped/pasted onto this view.
BMessenger retMsgr, localMsgr(this);
retMsgr = pmsg->ReturnAddress();
if (retMsgr != localMsgr) {
BMessage msgReply;
retMsgr.SendMessage(MSG_SELECTION_BITMAP, &msgReply);
BBitmap *bitmap = NULL;
if (msgReply.FindPointer("be:_bitmap_ptr",
reinterpret_cast<void **>(&bitmap)) == B_OK) {
BRect sourceRect;
BPoint point, sourcePoint;
pmsg->FindPoint("be:_source_point", &sourcePoint);
pmsg->FindRect("be:_frame", &sourceRect);
point = pmsg->DropPoint();
point.Set(point.x - (sourcePoint.x - sourceRect.left),
point.y - (sourcePoint.y - sourceRect.top));
// adjust drop point before scaling is factored in
point = ConvertFromScreen(point);
point = ViewToImage(point);
PasteBitmap(bitmap, point);
}
}
} }
} }
break; break;
@@ -1646,7 +1684,7 @@ ShowImageView::Cut()
RemoveSelection(true); RemoveSelection(true);
} }
void status_t
ShowImageView::PasteBitmap(BBitmap *bitmap, BPoint point) ShowImageView::PasteBitmap(BBitmap *bitmap, BPoint point)
{ {
if (bitmap && bitmap->IsValid()) { if (bitmap && bitmap->IsValid()) {
@@ -1666,7 +1704,11 @@ ShowImageView::PasteBitmap(BBitmap *bitmap, BPoint point)
fSelectionRect = offsetRect; fSelectionRect = offsetRect;
Invalidate(); Invalidate();
return B_OK;
} }
return B_ERROR;
} }
void void
+2 -1
View File
@@ -138,7 +138,8 @@ private:
void AddWhiteRect(BRect &rect); void AddWhiteRect(BRect &rect);
void GetMergeRects(BBitmap *merge, BRect selection, BRect &srcBits, BRect &destRect); void GetMergeRects(BBitmap *merge, BRect selection, BRect &srcBits, BRect &destRect);
void GetSelMergeRects(BRect &srcBits, BRect &destRect); void GetSelMergeRects(BRect &srcBits, BRect &destRect);
void PasteBitmap(BBitmap *bitmap, BPoint point); status_t SetSelection(const entry_ref *pref, BPoint point);
status_t PasteBitmap(BBitmap *bitmap, BPoint point);
void MergeWithBitmap(BBitmap *merge, BRect selection); void MergeWithBitmap(BBitmap *merge, BRect selection);
void MergeSelection(); void MergeSelection();
void DeleteScaler(); void DeleteScaler();