diff --git a/src/apps/showimage/ShowImageView.cpp b/src/apps/showimage/ShowImageView.cpp index 752f3b76ea..00ec6e4947 100644 --- a/src/apps/showimage/ShowImageView.cpp +++ b/src/apps/showimage/ShowImageView.cpp @@ -714,14 +714,17 @@ ShowImageView::CopySelection(uchar alpha) if (!HasSelection()) return NULL; - BRect rect(0, 0, fCopyFromRect.IntegerWidth(), fCopyFromRect.IntegerHeight()); + BRect rect(0, 0, fSelectionRect.Width(), fSelectionRect.Height()); BView view(rect, NULL, B_FOLLOW_NONE, B_WILL_DRAW); BBitmap *bitmap = new BBitmap(rect, hasAlpha ? B_RGBA32 : fBitmap->ColorSpace(), true); if (bitmap == NULL) return NULL; if (bitmap->Lock()) { bitmap->AddChild(&view); - view.DrawBitmap(fBitmap, fCopyFromRect, rect); + if (fSelBitmap) + view.DrawBitmap(fSelBitmap, fSelBitmap->Bounds(), rect); + else + view.DrawBitmap(fBitmap, fCopyFromRect, rect); if (hasAlpha) { view.SetDrawingMode(B_OP_SUBTRACT); view.SetHighColor(0, 0, 0, 255-alpha); @@ -1026,10 +1029,9 @@ ShowImageView::MouseDown(BPoint position) AnimateSelection(true); } else if (buttons == B_PRIMARY_MOUSE_BUTTON) { - if (HasSelection()) + MergeSelection(); // If there is an existing selection, // Make it part of the background image - MergeSelection(); // begin new selection SetHasSelection(true); @@ -1314,6 +1316,44 @@ ShowImageView::PageCount() return fDocumentCount; } +void +ShowImageView::Cut() +{ + CopySelectionToClipboard(); + ClearSelection(); +} + +void +ShowImageView::Paste() +{ + if (be_clipboard->Lock()) { + BMessage *pclip; + if ((pclip = be_clipboard->Data()) != NULL) { + BBitmap *pbits = dynamic_cast(BBitmap::Instantiate(pclip)); + if (pbits) { + MergeSelection(); + + SetHasSelection(true); + fSelBitmap = pbits; + fCopyFromRect = BRect(); + fSelectionRect = pbits->Bounds(); + + BPoint point; + if (pclip->FindPoint("be:location", &point) == B_OK && + fBitmap->Bounds().Contains(point)) + // Set the selection rectangle to the same location it was + // copied from, but only if the background bitmap is large enough + // to contain that point + fSelectionRect.OffsetBy(point); + + Invalidate(); + } + } + + be_clipboard->Unlock(); + } +} + void ShowImageView::SelectAll() { diff --git a/src/apps/showimage/ShowImageView.h b/src/apps/showimage/ShowImageView.h index e264c33ac6..77243ca0a8 100644 --- a/src/apps/showimage/ShowImageView.h +++ b/src/apps/showimage/ShowImageView.h @@ -77,6 +77,8 @@ public: int32 CurrentPage(); int32 PageCount(); + void Cut(); + void Paste(); void SelectAll(); void ClearSelection(); diff --git a/src/apps/showimage/ShowImageWindow.cpp b/src/apps/showimage/ShowImageWindow.cpp index f4c122698e..4bec1c8d1a 100644 --- a/src/apps/showimage/ShowImageWindow.cpp +++ b/src/apps/showimage/ShowImageWindow.cpp @@ -554,11 +554,13 @@ ShowImageWindow::MessageReceived(BMessage *pmsg) case B_UNDO: break; case B_CUT: + fpImageView->Cut(); break; case B_COPY: fpImageView->CopySelectionToClipboard(); break; case B_PASTE: + fpImageView->Paste(); break; case MSG_CLEAR_SELECT: fpImageView->ClearSelection();