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