* Added a selection mode that can currently only be enabled via the menu

(should be part of an optional tool bar in the future). Now the primary, and
  the tertiary mouse button pan the image. You still get the selection when
  using alt or ctrl and the primary mouse button, even outside of the selection
  mode. In selection mode, the primary button changes the selection.
* Renamed {Shrink|Stretch}ToBounds() to comply to our coding style, thanks Ingo.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@39132 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2010-10-24 20:59:34 +00:00
parent 4a5a077ff7
commit 6db01936fe
4 changed files with 71 additions and 47 deletions
+1
View File
@@ -29,6 +29,7 @@ enum {
MSG_UPDATE_STATUS = 'mUPS', MSG_UPDATE_STATUS = 'mUPS',
MSG_UPDATE_STATUS_TEXT = 'mUPT', MSG_UPDATE_STATUS_TEXT = 'mUPT',
MSG_UNDO_STATE = 'mUNS', MSG_UNDO_STATE = 'mUNS',
MSG_SELECTION_MODE = 'mSLM',
MSG_SELECTION = 'mSEL', MSG_SELECTION = 'mSEL',
MSG_PAGE_FIRST = 'mPGF', MSG_PAGE_FIRST = 'mPGF',
MSG_PAGE_LAST = 'mPGL', MSG_PAGE_LAST = 'mPGL',
+18 -7
View File
@@ -203,6 +203,7 @@ ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode,
fScrollingBitmap(false), fScrollingBitmap(false),
fCreatingSelection(false), fCreatingSelection(false),
fFirstPoint(0.0, 0.0), fFirstPoint(0.0, 0.0),
fSelectionMode(false),
fAnimateSelection(true), fAnimateSelection(true),
fHasSelection(false), fHasSelection(false),
fSlideShow(false), fSlideShow(false),
@@ -217,7 +218,7 @@ ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode,
ShowImageSettings* settings; ShowImageSettings* settings;
settings = my_app->Settings(); settings = my_app->Settings();
if (settings->Lock()) { if (settings->Lock()) {
fShrinkToBounds = settings->GetBool("ShrinkToBounds", fShrinkToBounds); fShrinkToBounds = settings->GetBool("ShrinksToBounds", fShrinkToBounds);
fStretchToBounds = settings->GetBool("ZoomToBounds", fStretchToBounds); fStretchToBounds = settings->GetBool("ZoomToBounds", fStretchToBounds);
fSlideShowDelay = settings->GetInt32("SlideShowDelay", fSlideShowDelay); fSlideShowDelay = settings->GetInt32("SlideShowDelay", fSlideShowDelay);
fScaleBilinear = settings->GetBool("ScaleBilinear", fScaleBilinear); fScaleBilinear = settings->GetBool("ScaleBilinear", fScaleBilinear);
@@ -571,7 +572,7 @@ void
ShowImageView::SetShrinkToBounds(bool enable) ShowImageView::SetShrinkToBounds(bool enable)
{ {
if (fShrinkToBounds != enable) { if (fShrinkToBounds != enable) {
_SettingsSetBool("ShrinkToBounds", enable); _SettingsSetBool("ShrinksToBounds", enable);
fShrinkToBounds = enable; fShrinkToBounds = enable;
if (enable) if (enable)
SetZoom(fFitToBoundsZoom); SetZoom(fFitToBoundsZoom);
@@ -1232,14 +1233,15 @@ ShowImageView::MouseDown(BPoint position)
buttons = Window()->CurrentMessage()->FindInt32("buttons"); buttons = Window()->CurrentMessage()->FindInt32("buttons");
if (fHasSelection && fSelectionBox.Bounds().Contains(point) if (fHasSelection && fSelectionBox.Bounds().Contains(point)
&& (buttons & (B_PRIMARY_MOUSE_BUTTON | B_SECONDARY_MOUSE_BUTTON))) { && (buttons
& (B_PRIMARY_MOUSE_BUTTON | B_SECONDARY_MOUSE_BUTTON)) != 0) {
if (!fSelectionBitmap) if (!fSelectionBitmap)
fSelectionBitmap = _CopySelection(); fSelectionBitmap = _CopySelection();
_BeginDrag(point); _BeginDrag(point);
} else if (buttons == B_TERTIARY_MOUSE_BUTTON } else if (buttons == B_PRIMARY_MOUSE_BUTTON
|| (buttons == B_PRIMARY_MOUSE_BUTTON && (fSelectionMode
&& (modifiers() & (B_COMMAND_KEY | B_CONTROL_KEY)) != 0)) { || (modifiers() & (B_COMMAND_KEY | B_CONTROL_KEY)) != 0)) {
// begin new selection // begin new selection
_SetHasSelection(true); _SetHasSelection(true);
fCreatingSelection = true; fCreatingSelection = true;
@@ -1251,7 +1253,8 @@ ShowImageView::MouseDown(BPoint position)
Invalidate(); Invalidate();
} else if (buttons == B_SECONDARY_MOUSE_BUTTON) { } else if (buttons == B_SECONDARY_MOUSE_BUTTON) {
_ShowPopUpMenu(ConvertToScreen(position)); _ShowPopUpMenu(ConvertToScreen(position));
} else if (buttons == B_PRIMARY_MOUSE_BUTTON) { } else if (buttons == B_PRIMARY_MOUSE_BUTTON
|| buttons == B_TERTIARY_MOUSE_BUTTON) {
// move image in window // move image in window
SetMouseEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY); SetMouseEventMask(B_POINTER_EVENTS, B_NO_POINTER_HISTORY);
fScrollingBitmap = true; fScrollingBitmap = true;
@@ -1621,6 +1624,14 @@ ShowImageView::PageCount()
} }
void
ShowImageView::SetSelectionMode(bool selectionMode)
{
// The mode only has an effect in MouseDown()
fSelectionMode = selectionMode;
}
void void
ShowImageView::Undo() ShowImageView::Undo()
{ {
+6 -2
View File
@@ -70,10 +70,10 @@ public:
bool GetScaleBilinear() { return fScaleBilinear; } bool GetScaleBilinear() { return fScaleBilinear; }
void SetShowCaption(bool show); void SetShowCaption(bool show);
void SetShrinkToBounds(bool enable); void SetShrinkToBounds(bool enable);
bool ShrinkToBounds() const bool ShrinksToBounds() const
{ return fShrinkToBounds; } { return fShrinkToBounds; }
void SetStretchToBounds(bool enable); void SetStretchToBounds(bool enable);
bool StretchToBounds() const bool StretchesToBounds() const
{ return fStretchToBounds; } { return fStretchToBounds; }
void SetFullScreen(bool fullScreen); void SetFullScreen(bool fullScreen);
@@ -85,6 +85,9 @@ public:
float bitmapLength, float viewLength); float bitmapLength, float viewLength);
void FixupScrollBars(); void FixupScrollBars();
void SetSelectionMode(bool selectionMode);
bool IsSelectionModeEnabled() const
{ return fSelectionMode; }
void Undo(); void Undo();
void SelectAll(); void SelectAll();
void ClearSelection(); void ClearSelection();
@@ -239,6 +242,7 @@ private:
bool fCreatingSelection; bool fCreatingSelection;
BPoint fFirstPoint; BPoint fFirstPoint;
// first point in image space of selection // first point in image space of selection
bool fSelectionMode;
bool fAnimateSelection; bool fAnimateSelection;
bool fHasSelection; bool fHasSelection;
SelectionBox fSelectionBox; SelectionBox fSelectionBox;
+46 -38
View File
@@ -154,9 +154,9 @@ ShowImageWindow::ShowImageWindow(const entry_ref* ref,
const int32 kstatusWidth = 190; const int32 kstatusWidth = 190;
BRect rect; BRect rect;
rect = Bounds(); rect = Bounds();
rect.top = viewFrame.bottom + 1; rect.top = viewFrame.bottom + 1;
rect.left = viewFrame.left + kstatusWidth; rect.left = viewFrame.left + kstatusWidth;
rect.right = viewFrame.right + 1; rect.right = viewFrame.right + 1;
rect.bottom += 1; rect.bottom += 1;
BScrollBar* horizontalScrollBar = new BScrollBar(rect, "hscroll", BScrollBar* horizontalScrollBar = new BScrollBar(rect, "hscroll",
fImageView, 0, 150, B_HORIZONTAL); fImageView, 0, 150, B_HORIZONTAL);
@@ -170,10 +170,10 @@ ShowImageWindow::ShowImageWindow(const entry_ref* ref,
AddChild(fStatusView); AddChild(fStatusView);
rect = Bounds(); rect = Bounds();
rect.top = viewFrame.top - 1; rect.top = viewFrame.top - 1;
rect.left = viewFrame.right + 1; rect.left = viewFrame.right + 1;
rect.bottom = viewFrame.bottom + 1; rect.bottom = viewFrame.bottom + 1;
rect.right += 1; rect.right += 1;
BScrollBar* verticalScrollBar = new BScrollBar(rect, "vscroll", fImageView, BScrollBar* verticalScrollBar = new BScrollBar(rect, "vscroll", fImageView,
0, 150, B_VERTICAL); 0, 150, B_VERTICAL);
AddChild(verticalScrollBar); AddChild(verticalScrollBar);
@@ -213,6 +213,9 @@ ShowImageWindow::ShowImageWindow(const entry_ref* ref,
SetPulseRate(100000); SetPulseRate(100000);
// every 1/10 second; ShowImageView needs it for marching ants // every 1/10 second; ShowImageView needs it for marching ants
_MarkMenuItem(menu, MSG_SELECTION_MODE,
fImageView->IsSelectionModeEnabled());
WindowRedimension(fImageView->GetBitmap()); WindowRedimension(fImageView->GetBitmap());
fImageView->ResetZoom(); fImageView->ResetZoom();
fImageView->MakeFocus(true); // to receive KeyDown messages fImageView->MakeFocus(true); // to receive KeyDown messages
@@ -317,8 +320,8 @@ ShowImageWindow::_BuildViewMenu(BMenu* menu, bool popupMenu)
_MarkMenuItem(menu, MSG_SHOW_CAPTION, fShowCaption); _MarkMenuItem(menu, MSG_SHOW_CAPTION, fShowCaption);
_MarkMenuItem(menu, MSG_SCALE_BILINEAR, fImageView->GetScaleBilinear()); _MarkMenuItem(menu, MSG_SCALE_BILINEAR, fImageView->GetScaleBilinear());
_MarkMenuItem(menu, MSG_SHRINK_TO_WINDOW, fImageView->ShrinkToBounds()); _MarkMenuItem(menu, MSG_SHRINK_TO_WINDOW, fImageView->ShrinksToBounds());
_MarkMenuItem(menu, MSG_STRETCH_TO_WINDOW, fImageView->StretchToBounds()); _MarkMenuItem(menu, MSG_STRETCH_TO_WINDOW, fImageView->StretchesToBounds());
if (popupMenu) { if (popupMenu) {
menu->AddSeparatorItem(); menu->AddSeparatorItem();
@@ -339,12 +342,12 @@ ShowImageWindow::AddMenus(BMenuBar* bar)
fOpenMenu->Superitem()->SetTarget(be_app); fOpenMenu->Superitem()->SetTarget(be_app);
fOpenMenu->Superitem()->SetShortcut('O', 0); fOpenMenu->Superitem()->SetShortcut('O', 0);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
BMenu *pmenuSaveAs = new BMenu(B_TRANSLATE("Save as" B_UTF8_ELLIPSIS), BMenu* menuSaveAs = new BMenu(B_TRANSLATE("Save as" B_UTF8_ELLIPSIS),
B_ITEMS_IN_COLUMN); B_ITEMS_IN_COLUMN);
BTranslationUtils::AddTranslationItems(pmenuSaveAs, B_TRANSLATOR_BITMAP); BTranslationUtils::AddTranslationItems(menuSaveAs, B_TRANSLATOR_BITMAP);
// Fill Save As submenu with all types that can be converted // Fill Save As submenu with all types that can be converted
// to from the Be bitmap image format // to from the Be bitmap image format
menu->AddItem(pmenuSaveAs); menu->AddItem(menuSaveAs);
_AddItemMenu(menu, B_TRANSLATE("Close"), B_QUIT_REQUESTED, 'W', 0, this); _AddItemMenu(menu, B_TRANSLATE("Close"), B_QUIT_REQUESTED, 'W', 0, this);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
_AddItemMenu(menu, B_TRANSLATE("Page setup" B_UTF8_ELLIPSIS), _AddItemMenu(menu, B_TRANSLATE("Page setup" B_UTF8_ELLIPSIS),
@@ -363,6 +366,8 @@ ShowImageWindow::AddMenus(BMenuBar* bar)
menu->AddSeparatorItem(); menu->AddSeparatorItem();
_AddItemMenu(menu, B_TRANSLATE("Copy"), B_COPY, 'C', 0, this, false); _AddItemMenu(menu, B_TRANSLATE("Copy"), B_COPY, 'C', 0, this, false);
menu->AddSeparatorItem(); menu->AddSeparatorItem();
_AddItemMenu(menu, B_TRANSLATE("Selection Mode"), MSG_SELECTION_MODE, 0, 0,
this);
_AddItemMenu(menu, B_TRANSLATE("Clear selection"), _AddItemMenu(menu, B_TRANSLATE("Clear selection"),
MSG_CLEAR_SELECT, 0, 0, this, false); MSG_CLEAR_SELECT, 0, 0, this, false);
_AddItemMenu(menu, B_TRANSLATE("Select all"), _AddItemMenu(menu, B_TRANSLATE("Select all"),
@@ -576,7 +581,8 @@ ShowImageWindow::MessageReceived(BMessage* message)
fSavePanel = NULL; fSavePanel = NULL;
break; break;
case MSG_UPDATE_STATUS: { case MSG_UPDATE_STATUS:
{
int32 pages = fImageView->PageCount(); int32 pages = fImageView->PageCount();
int32 curPage = fImageView->CurrentPage(); int32 curPage = fImageView->CurrentPage();
@@ -645,8 +651,8 @@ ShowImageWindow::MessageReceived(BMessage* message)
if (messageProvidesSize) { if (messageProvidesSize) {
_UpdateResizerWindow(fWidth, fHeight); _UpdateResizerWindow(fWidth, fHeight);
if (!fImageView->StretchToBounds() if (!fImageView->StretchesToBounds()
&& !fImageView->ShrinkToBounds() && !fImageView->ShrinksToBounds()
&& !fFullScreen) && !fFullScreen)
WindowRedimension(fImageView->GetBitmap()); WindowRedimension(fImageView->GetBitmap());
} }
@@ -654,9 +660,11 @@ ShowImageWindow::MessageReceived(BMessage* message)
fStatusView->SetText(status); fStatusView->SetText(status);
UpdateTitle(); UpdateTitle();
} break; break;
}
case MSG_UPDATE_STATUS_TEXT: { case MSG_UPDATE_STATUS_TEXT:
{
BString status; BString status;
status << fWidth << "x" << fHeight; status << fWidth << "x" << fHeight;
BString str; BString str;
@@ -664,33 +672,29 @@ ShowImageWindow::MessageReceived(BMessage* message)
status << ", " << str; status << ", " << str;
fStatusView->SetText(status); fStatusView->SetText(status);
} }
} break; break;
}
case MSG_SELECTION: { case MSG_SELECTION:
{
// The view sends this message when a selection is // The view sends this message when a selection is
// made or the selection is cleared so that the window // made or the selection is cleared so that the window
// can update the state of the appropriate menu items // can update the state of the appropriate menu items
bool benable; bool enable;
if (message->FindBool("has_selection", &benable) == B_OK) { if (message->FindBool("has_selection", &enable) == B_OK) {
_EnableMenuItem(fBar, B_CUT, benable); _EnableMenuItem(fBar, B_COPY, enable);
_EnableMenuItem(fBar, B_COPY, benable); _EnableMenuItem(fBar, MSG_CLEAR_SELECT, enable);
_EnableMenuItem(fBar, MSG_CLEAR_SELECT, benable);
} }
} break; break;
}
case MSG_UNDO_STATE: { case MSG_UNDO_STATE:
bool benable; {
if (message->FindBool("can_undo", &benable) == B_OK) bool enable;
_EnableMenuItem(fBar, B_UNDO, benable); if (message->FindBool("can_undo", &enable) == B_OK)
} break; _EnableMenuItem(fBar, B_UNDO, enable);
break;
case MSG_CLIPBOARD_CHANGED: { }
// The app sends this message after it examines the clipboard in
// response to a B_CLIPBOARD_CHANGED message
bool bdata;
if (message->FindBool("data_available", &bdata) == B_OK)
_EnableMenuItem(fBar, B_PASTE, bdata);
} break;
case B_UNDO: case B_UNDO:
fImageView->Undo(); fImageView->Undo();
@@ -700,6 +704,10 @@ ShowImageWindow::MessageReceived(BMessage* message)
fImageView->CopySelectionToClipboard(); fImageView->CopySelectionToClipboard();
break; break;
case MSG_SELECTION_MODE:
fImageView->SetSelectionMode(_ToggleMenuItem(MSG_SELECTION_MODE));
break;
case MSG_CLEAR_SELECT: case MSG_CLEAR_SELECT:
fImageView->ClearSelection(); fImageView->ClearSelection();
break; break;