Implemented Cut and Paste. Still need to implement Undo and check for a dirty document when the window or app is closed.
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5414 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -714,14 +714,17 @@ ShowImageView::CopySelection(uchar alpha)
|
|||||||
|
|
||||||
if (!HasSelection()) return NULL;
|
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);
|
BView view(rect, NULL, B_FOLLOW_NONE, B_WILL_DRAW);
|
||||||
BBitmap *bitmap = new BBitmap(rect, hasAlpha ? B_RGBA32 : fBitmap->ColorSpace(), true);
|
BBitmap *bitmap = new BBitmap(rect, hasAlpha ? B_RGBA32 : fBitmap->ColorSpace(), true);
|
||||||
if (bitmap == NULL) return NULL;
|
if (bitmap == NULL) return NULL;
|
||||||
|
|
||||||
if (bitmap->Lock()) {
|
if (bitmap->Lock()) {
|
||||||
bitmap->AddChild(&view);
|
bitmap->AddChild(&view);
|
||||||
view.DrawBitmap(fBitmap, fCopyFromRect, rect);
|
if (fSelBitmap)
|
||||||
|
view.DrawBitmap(fSelBitmap, fSelBitmap->Bounds(), rect);
|
||||||
|
else
|
||||||
|
view.DrawBitmap(fBitmap, fCopyFromRect, rect);
|
||||||
if (hasAlpha) {
|
if (hasAlpha) {
|
||||||
view.SetDrawingMode(B_OP_SUBTRACT);
|
view.SetDrawingMode(B_OP_SUBTRACT);
|
||||||
view.SetHighColor(0, 0, 0, 255-alpha);
|
view.SetHighColor(0, 0, 0, 255-alpha);
|
||||||
@@ -1026,10 +1029,9 @@ ShowImageView::MouseDown(BPoint position)
|
|||||||
AnimateSelection(true);
|
AnimateSelection(true);
|
||||||
|
|
||||||
} else if (buttons == B_PRIMARY_MOUSE_BUTTON) {
|
} else if (buttons == B_PRIMARY_MOUSE_BUTTON) {
|
||||||
if (HasSelection())
|
MergeSelection();
|
||||||
// If there is an existing selection,
|
// If there is an existing selection,
|
||||||
// Make it part of the background image
|
// Make it part of the background image
|
||||||
MergeSelection();
|
|
||||||
|
|
||||||
// begin new selection
|
// begin new selection
|
||||||
SetHasSelection(true);
|
SetHasSelection(true);
|
||||||
@@ -1314,6 +1316,44 @@ ShowImageView::PageCount()
|
|||||||
return fDocumentCount;
|
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 *>(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
|
void
|
||||||
ShowImageView::SelectAll()
|
ShowImageView::SelectAll()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -77,6 +77,8 @@ public:
|
|||||||
int32 CurrentPage();
|
int32 CurrentPage();
|
||||||
int32 PageCount();
|
int32 PageCount();
|
||||||
|
|
||||||
|
void Cut();
|
||||||
|
void Paste();
|
||||||
void SelectAll();
|
void SelectAll();
|
||||||
void ClearSelection();
|
void ClearSelection();
|
||||||
|
|
||||||
|
|||||||
@@ -554,11 +554,13 @@ ShowImageWindow::MessageReceived(BMessage *pmsg)
|
|||||||
case B_UNDO:
|
case B_UNDO:
|
||||||
break;
|
break;
|
||||||
case B_CUT:
|
case B_CUT:
|
||||||
|
fpImageView->Cut();
|
||||||
break;
|
break;
|
||||||
case B_COPY:
|
case B_COPY:
|
||||||
fpImageView->CopySelectionToClipboard();
|
fpImageView->CopySelectionToClipboard();
|
||||||
break;
|
break;
|
||||||
case B_PASTE:
|
case B_PASTE:
|
||||||
|
fpImageView->Paste();
|
||||||
break;
|
break;
|
||||||
case MSG_CLEAR_SELECT:
|
case MSG_CLEAR_SELECT:
|
||||||
fpImageView->ClearSelection();
|
fpImageView->ClearSelection();
|
||||||
|
|||||||
Reference in New Issue
Block a user