From 75238186d75d8422e6916ad8c6004ab881fe1af8 Mon Sep 17 00:00:00 2001 From: Matthew Wilber Date: Sun, 21 Dec 2003 19:44:13 +0000 Subject: [PATCH] Fixed Edit-->Clear to leave behind a white box if the selection box is not moved after it is made, added Undo capability for Cut and Clear actions git-svn-id: file:///srv/svn/repos/haiku/trunk/current@5719 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/showimage/ShowImageView.cpp | 45 +++++++++++++++++++--------- src/apps/showimage/ShowImageView.h | 1 + 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/apps/showimage/ShowImageView.cpp b/src/apps/showimage/ShowImageView.cpp index 10eb4e70a4..c2c6a1c711 100644 --- a/src/apps/showimage/ShowImageView.cpp +++ b/src/apps/showimage/ShowImageView.cpp @@ -1594,19 +1594,37 @@ ShowImageView::AddWhiteRect(BRect &rect) delete bitmap; } +void +ShowImageView::RemoveSelection(bool bToClipboard) +{ + if (HasSelection()) { + BRect rect = fSelectionRect; + bool bCutBackground = (fSelBitmap) ? false : true; + BBitmap *selection, *restore = NULL; + selection = CopySelection(); + + if (bToClipboard) + CopySelectionToClipboard(); + SetHasSelection(false); + + if (bCutBackground) { + // If the user hasn't dragged the selection, + // paint a white rectangle where the selection was + restore = CopyFromRect(rect); + AddWhiteRect(rect); + } + + fUndo.SetTo(rect, restore, selection); + Invalidate(); + } +} + void ShowImageView::Cut() { - BRect rect = fSelectionRect; - bool bCutBackground = (fSelBitmap) ? false : true; - - CopySelectionToClipboard(); - ClearSelection(); - - if (bCutBackground) - // If the user hasn't dragged the selection, - // paint a white rectangle where the selection was - AddWhiteRect(rect); + // Copy the selection to the clipboard, + // then remove it + RemoveSelection(true); } void @@ -1661,10 +1679,9 @@ ShowImageView::SelectAll() void ShowImageView::ClearSelection() { - if (HasSelection()) { - SetHasSelection(false); - Invalidate(); - } + // Remove the selection, + // DON'T copy it to the clipboard + RemoveSelection(false); } void diff --git a/src/apps/showimage/ShowImageView.h b/src/apps/showimage/ShowImageView.h index bd37c17567..3ec32ea3a7 100644 --- a/src/apps/showimage/ShowImageView.h +++ b/src/apps/showimage/ShowImageView.h @@ -129,6 +129,7 @@ private: }; void InitPatterns(); void RotatePatterns(); + void RemoveSelection(bool bToClipboard); bool HasSelection() { return fHasSelection; } void SetHasSelection(bool bHasSelection); void AnimateSelection(bool a);