Author: axeld Date: 2010-11-15 00:45:15 +0100 (Mon, 15 Nov 2010) New Revision: 39431 Changeset: http://dev.haiku-os.org/changeset/39431 Ticket: http://dev.haiku-os.org/ticket/6765 Ticket: http://dev.haiku-os.org/ticket/6810 Removed: haiku/trunk/src/apps/showimage/EntryMenuItem.cpp haiku/trunk/src/apps/showimage/EntryMenuItem.h Modified: haiku/trunk/src/apps/showimage/ImageCache.cpp haiku/trunk/src/apps/showimage/ImageCache.h haiku/trunk/src/apps/showimage/Jamfile haiku/trunk/src/apps/showimage/ProgressWindow.cpp haiku/trunk/src/apps/showimage/ProgressWindow.h haiku/trunk/src/apps/showimage/ShowImageApp.cpp haiku/trunk/src/apps/showimage/ShowImageApp.h haiku/trunk/src/apps/showimage/ShowImageConstants.h haiku/trunk/src/apps/showimage/ShowImageView.cpp haiku/trunk/src/apps/showimage/ShowImageView.h haiku/trunk/src/apps/showimage/ShowImageWindow.cpp haiku/trunk/src/apps/showimage/ShowImageWindow.h Log: * Removed the "shrink to window" option. Instead, there is now a "Fit to window" menu item that just does that. Additionally, the image is always fit to the window size when first shown, or if the full screen mode switches. That also fixes #6765, and #6810. * The ImageCache now also passes a referenced BitmapOwner object, and bitmaps are now actually freed when it's allowed to. * Pressing the zoom button will cause ShowImage to enter full screen again. For some reason this has been removed as part of r19540. * The progress window is now visible again, although not that often, as you will only see it for images that were not in the queue already. The window is now known to the ShowImageWindow instead of the ShowImageView. * Moved most constants out of ShowImageConstants.h to where they belong. * Dropping an image now opens it in another window. * Removed EntryMenuItem as it's no longer used anywhere. * Minor other cleanup. Modified: haiku/trunk/src/apps/showimage/ImageCache.cpp =================================================================== --- haiku/trunk/src/apps/showimage/ImageCache.cpp 2010-11-14 19:04:48 UTC (rev 39430) +++ haiku/trunk/src/apps/showimage/ImageCache.cpp 2010-11-14 23:45:15 UTC (rev 39431) @@ -35,6 +35,22 @@ // #pragma mark - +BitmapOwner::BitmapOwner(BBitmap* bitmap) + : + fBitmap(bitmap) +{ +} + + +BitmapOwner::~BitmapOwner() +{ + delete fBitmap; +} + + +// #pragma mark - + + ImageCache::ImageCache() : fLocker("image cache"), @@ -177,16 +193,14 @@ && ioExtension.AddInt32("/documentIndex", queueEntry->page) != B_OK) return B_NO_MEMORY; -// TODO: rethink this! -#if 0 - if (fProgressWindow != NULL) { - BMessage progress(kMsgProgressStatusUpdate); - if (ioExtension.AddMessenger("/progressMonitor", - fProgressWindow) == B_OK - && ioExtension.AddMessage("/progressMessage", &progress) == B_OK) - fProgressWindow->Start(); + // TODO: this doesn't work for images that already are in the queue... + if (!queueEntry->listeners.empty()) { + BMessage progress(kMsgImageCacheProgressUpdate); + progress.AddRef("ref", &queueEntry->ref); + ioExtension.AddMessenger("/progressMonitor", + *queueEntry->listeners.begin()); + ioExtension.AddMessage("/progressMessage", &progress); } -#endif // Translate image data and create a new ShowImage window @@ -198,12 +212,6 @@ status = roster->Translate(&file, &info, &ioExtension, &outstream, B_TRANSLATOR_BITMAP); } - -#if 0 - if (fProgressWindow != NULL) - fProgressWindow->Stop(); -#endif - if (status != B_OK) return status; @@ -211,6 +219,12 @@ if (outstream.DetachBitmap(&bitmap) != B_OK) return B_ERROR; + entry->bitmapOwner = new(std::nothrow) BitmapOwner(bitmap); + if (entry->bitmapOwner == NULL) { + delete bitmap; + return B_NO_MEMORY; + } + entry->ref = queueEntry->ref; entry->page = queueEntry->page; entry->bitmap = bitmap; @@ -244,6 +258,8 @@ entry = fCacheEntriesByAge.RemoveHead(); fBytes -= entry->bitmap->BitsLength(); fCacheMap.erase(std::make_pair(entry->ref, entry->page)); + + entry->bitmapOwner->ReleaseReference(); delete entry; } @@ -259,7 +275,7 @@ if (queueEntry->listeners.empty()) return; - BMessage notification(kMsgImageLoaded); + BMessage notification(kMsgImageCacheImageLoaded); _BuildNotification(entry, notification); if (queueEntry->status != B_OK) @@ -278,7 +294,7 @@ if (target == NULL) return; - BMessage notification(kMsgImageLoaded); + BMessage notification(kMsgImageCacheImageLoaded); _BuildNotification(entry, notification); target->SendMessage(¬ification); @@ -291,10 +307,14 @@ if (entry == NULL) return; + entry->bitmapOwner->AcquireReference(); + // this is the reference owned by the target + message.AddString("type", entry->type); message.AddString("mime", entry->mimeType); message.AddRef("ref", &entry->ref); message.AddInt32("page", entry->page); message.AddInt32("pageCount", entry->pageCount); message.AddPointer("bitmap", (void*)entry->bitmap); + message.AddPointer("bitmapOwner", (void*)entry->bitmapOwner); } Modified: haiku/trunk/src/apps/showimage/ImageCache.h =================================================================== --- haiku/trunk/src/apps/showimage/ImageCache.h 2010-11-14 19:04:48 UTC (rev 39430) +++ haiku/trunk/src/apps/showimage/ImageCache.h 2010-11-14 23:45:15 UTC (rev 39431) @@ -15,6 +15,7 @@ #include <String.h> #include <kernel/util/DoublyLinkedList.h> +#include <Referenceable.h> class BBitmap; @@ -24,15 +25,27 @@ enum { - kMsgImageLoaded = 'ifnL' + kMsgImageCacheImageLoaded = 'icIL', + kMsgImageCacheProgressUpdate = 'icPU' }; +class BitmapOwner : public Referenceable { +public: + BitmapOwner(BBitmap* bitmap); + virtual ~BitmapOwner(); + +private: + BBitmap* fBitmap; +}; + + struct CacheEntry : DoublyLinkedListLinkImpl<CacheEntry> { entry_ref ref; int32 page; int32 pageCount; BBitmap* bitmap; + BitmapOwner* bitmapOwner; BString type; BString mimeType; }; Modified: haiku/trunk/src/apps/showimage/Jamfile =================================================================== --- haiku/trunk/src/apps/showimage/Jamfile 2010-11-14 19:04:48 UTC (rev 39430) +++ haiku/trunk/src/apps/showimage/Jamfile 2010-11-14 23:45:15 UTC (rev 39431) @@ -6,7 +6,6 @@ SubDirHdrs $(HAIKU_TOP) src kits tracker ; Application ShowImage : - EntryMenuItem.cpp Filter.cpp ImageCache.cpp ImageFileNavigator.cpp @@ -19,11 +18,10 @@ ShowImageUndo.cpp ShowImageView.cpp ShowImageWindow.cpp - : libshared.a - be tracker translation $(HAIKU_LOCALE_LIBS) $(TARGET_LIBSTDC++) - $(TARGET_LIBSUPC++) + : libshared.a be tracker translation $(HAIKU_LOCALE_LIBS) + $(TARGET_LIBSTDC++) $(TARGET_LIBSUPC++) : ShowImage.rdef - ; +; DoCatalogs ShowImage : x-vnd.Haiku-ShowImage Modified: haiku/trunk/src/apps/showimage/ProgressWindow.cpp =================================================================== --- haiku/trunk/src/apps/showimage/ProgressWindow.cpp 2010-11-14 19:04:48 UTC (rev 39430) +++ haiku/trunk/src/apps/showimage/ProgressWindow.cpp 2010-11-14 23:45:15 UTC (rev 39431) @@ -1,5 +1,5 @@ /* - * Copyright 2007-2009, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx + * Copyright 2007-2010, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx * Distributed under the terms of the MIT License. */ @@ -7,6 +7,7 @@ #include "ProgressWindow.h" #include <stdio.h> +#include <string.h> #include <Autolock.h> #include <Catalog.h> @@ -24,10 +25,13 @@ #define B_TRANSLATE_CONTEXT "ProgressWindow" -ProgressWindow::ProgressWindow(BWindow* referenceWindow, bool center) +ProgressWindow::ProgressWindow() : BWindow(BRect(0, 0, 250, 100), B_TRANSLATE("Progress monitor"), - B_MODAL_WINDOW_LOOK, B_FLOATING_APP_WINDOW_FEEL, + B_MODAL_WINDOW_LOOK, B_NORMAL_WINDOW_FEEL,// B_FLOATING_APP_WINDOW_FEEL, + // TODO: a bug in the app_server prevents an initial floating-app feel + // to work correctly; the window will then not be visible for the first + // image, even though it's later set to normal feel in that case. B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS), fRunner(NULL) { @@ -45,14 +49,7 @@ fStatusBar->SetResizingMode(B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT); view->AddChild(fStatusBar); - BScreen screen(referenceWindow); - if (!center) { - ResizeTo(Bounds().Width(), height + 9); - // TODO: frame width! - MoveTo(screen.Frame().left + 5, - screen.Frame().bottom - Bounds().Height() - 5); - } else - CenterIn(screen.Frame()); + ResizeTo(Bounds().Width(), height + 9); Run(); } @@ -65,10 +62,27 @@ void -ProgressWindow::Start() +ProgressWindow::Start(BWindow* referenceWindow, bool center) { BAutolock _(this); + BScreen screen(referenceWindow); + if (!center) { + BMessage settings; + GetDecoratorSettings(&settings); + + int32 borderWidth; + if (settings.FindInt32("border", &borderWidth) != B_OK) + borderWidth = 5; + + MoveTo(screen.Frame().left + borderWidth, + screen.Frame().bottom - Bounds().Height() - borderWidth); + } else + CenterIn(screen.Frame()); + + SetFeel(referenceWindow->IsHidden() + ? B_NORMAL_WINDOW_FEEL : B_FLOATING_APP_WINDOW_FEEL); + fRetrievedUpdate = false; fRetrievedShow = false; delete fRunner; @@ -104,7 +118,7 @@ fRetrievedShow = true; break; - case kMsgProgressStatusUpdate: + case kMsgProgressUpdate: float percent; if (message->FindFloat("percent", &percent) == B_OK) fStatusBar->Update(percent - fStatusBar->CurrentValue()); Modified: haiku/trunk/src/apps/showimage/ProgressWindow.h =================================================================== --- haiku/trunk/src/apps/showimage/ProgressWindow.h 2010-11-14 19:04:48 UTC (rev 39430) +++ haiku/trunk/src/apps/showimage/ProgressWindow.h 2010-11-14 23:45:15 UTC (rev 39431) @@ -1,5 +1,5 @@ /* - * Copyright 2007-2009, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx + * Copyright 2007-2010, Axel Dörfler, axeld@xxxxxxxxxxxxxxxxx * Distributed under the terms of the MIT License. */ #ifndef PROGRESS_WINDOW_H @@ -13,15 +13,21 @@ class BStatusBar; +// public message constants +enum { + kMsgProgressUpdate = 'pwPU' +}; + + class ProgressWindow : public BWindow { public: - ProgressWindow(BWindow* referenceWindow, - bool center = false); + ProgressWindow(); virtual ~ProgressWindow(); virtual void MessageReceived(BMessage* message); - void Start(); + void Start(BWindow* referenceWindow, + bool center = false); void Stop(); private: Modified: haiku/trunk/src/apps/showimage/ShowImageApp.cpp =================================================================== --- haiku/trunk/src/apps/showimage/ShowImageApp.cpp 2010-11-14 19:04:48 UTC (rev 39430) +++ haiku/trunk/src/apps/showimage/ShowImageApp.cpp 2010-11-14 23:45:15 UTC (rev 39431) @@ -9,6 +9,7 @@ * Ryan Leavengood */ + #include "ShowImageApp.h" #include <stdio.h> @@ -26,12 +27,13 @@ #include "ShowImageWindow.h" -#define WINDOWS_TO_IGNORE 1 - #undef B_TRANSLATE_CONTEXT #define B_TRANSLATE_CONTEXT "AboutWindow" + const char* kApplicationSignature = "application/x-vnd.Haiku-ShowImage"; +const int32 kWindowsToIgnore = 1; + // ignore the always open file panel ShowImageApp::ShowImageApp() @@ -87,7 +89,7 @@ void ShowImageApp::ReadyToRun() { - if (CountWindows() == WINDOWS_TO_IGNORE) + if (CountWindows() == kWindowsToIgnore) fOpenPanel->Show(); else { // If image windows are already open @@ -109,9 +111,6 @@ fOpenPanel->Show(); break; - case MSG_WINDOW_QUIT: - break; - case B_CANCEL: // File open panel was closed, // start checking count of open windows @@ -137,6 +136,7 @@ "Michael Wilber", "Michael Pfeiffer", "Ryan Leavengood", + "Axel Dörfler", NULL }; BAboutWindow about(B_TRANSLATE("ShowImage"), 2003, authors); @@ -149,7 +149,7 @@ { // Bug: The BFilePanel is automatically closed if the volume that // is displayed is unmounted. - if (!IsLaunching() && CountWindows() <= WINDOWS_TO_IGNORE) { + if (!IsLaunching() && CountWindows() <= kWindowsToIgnore) { // If the application is not launching and // all windows are closed except for the file open panel, // quit the application @@ -212,8 +212,8 @@ const int32 count = CountWindows(); for (int32 i = 0; i < count; i ++) { // BMessenger checks for us if BWindow is still a valid object - BMessenger msgr(WindowAt(i)); - msgr.SendMessage(message); + BMessenger messenger(WindowAt(i)); + messenger.SendMessage(message); } } @@ -238,7 +238,7 @@ be_clipboard->Unlock(); } - BMessage msg(MSG_CLIPBOARD_CHANGED); + BMessage msg(B_CLIPBOARD_CHANGED); msg.AddBool("data_available", dataAvailable); _BroadcastToWindows(&msg); } Modified: haiku/trunk/src/apps/showimage/ShowImageApp.h =================================================================== --- haiku/trunk/src/apps/showimage/ShowImageApp.h 2010-11-14 19:04:48 UTC (rev 39430) +++ haiku/trunk/src/apps/showimage/ShowImageApp.h 2010-11-14 23:45:15 UTC (rev 39431) @@ -18,6 +18,11 @@ #include <FilePanel.h> +enum { + MSG_FILE_OPEN = 'mFOP', +}; + + class ShowImageApp : public BApplication { public: ShowImageApp(); Modified: haiku/trunk/src/apps/showimage/ShowImageConstants.h =================================================================== --- haiku/trunk/src/apps/showimage/ShowImageConstants.h 2010-11-14 19:04:48 UTC (rev 39430) +++ haiku/trunk/src/apps/showimage/ShowImageConstants.h 2010-11-14 23:45:15 UTC (rev 39431) @@ -16,49 +16,8 @@ enum { - MSG_CAPTURE_MOUSE = 'mCPM', - MSG_CHANGE_FOCUS = 'mCFS', - MSG_FILE_OPEN = 'mFOP', - MSG_WINDOW_QUIT = 'mWQT', - MSG_OUTPUT_TYPE = 'BTMN', - MSG_SAVE_PANEL = 'mFSP', - MSG_CLEAR_SELECT = 'mCSL', - MSG_SELECT_ALL = 'mSAL', - MSG_CLIPBOARD_CHANGED = 'mCLP', - MSG_MODIFIED = 'mMOD', - 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', - MSG_PAGE_NEXT = 'mPGN', - MSG_PAGE_PREV = 'mPGP', - MSG_GOTO_PAGE = 'mGTP', - MSG_FILE_NEXT = 'mFLN', - MSG_FILE_PREV = 'mFLP', - kMsgDeleteCurrentFile = 'mDcF', - MSG_SHRINK_TO_WINDOW = 'mSTW', - MSG_STRETCH_TO_WINDOW = 'mZTW', - MSG_ROTATE_90 = 'mR90', - MSG_ROTATE_270 = 'mR27', - MSG_FLIP_LEFT_TO_RIGHT = 'mFLR', - MSG_FLIP_TOP_TO_BOTTOM = 'mFTB', - MSG_SLIDE_SHOW = 'mSSW', - MSG_SLIDE_SHOW_DELAY = 'mSSD', - MSG_FULL_SCREEN = 'mFSC', - MSG_EXIT_FULL_SCREEN = 'mEFS', - MSG_SHOW_CAPTION = 'mSCP', - MSG_PAGE_SETUP = 'mPSU', - MSG_PREPARE_PRINT = 'mPPT', - MSG_PRINT = 'mPRT', - MSG_ZOOM_IN = 'mZIN', - MSG_ZOOM_OUT = 'mZOU', - MSG_ORIGINAL_SIZE = 'mOSZ', - MSG_SCALE_BILINEAR = 'mSBL', - MSG_DESKTOP_BACKGROUND = 'mDBG', - kMsgProgressStatusUpdate = 'SIup' + MSG_PRINT = 'mPRT' }; Modified: haiku/trunk/src/apps/showimage/ShowImageView.cpp =================================================================== --- haiku/trunk/src/apps/showimage/ShowImageView.cpp 2010-11-14 19:04:48 UTC (rev 39430) +++ haiku/trunk/src/apps/showimage/ShowImageView.cpp 2010-11-14 23:45:15 UTC (rev 39431) @@ -12,6 +12,7 @@ * yellowTAB GmbH * Bernd Korz * Stephan Aßmus <superstippi@xxxxxx> + * Axel Dörfler, axeld@xxxxxxxxxxxxxxxx */ @@ -49,9 +50,8 @@ #include <tracker_private.h> -#include "ProgressWindow.h" +#include "ImageCache.h" #include "ShowImageApp.h" -#include "ShowImageConstants.h" #include "ShowImageWindow.h" @@ -68,11 +68,16 @@ }; +// the delay time for hiding the cursor in 1/10 seconds (the pulse rate) +#define HIDE_CURSOR_DELAY_TIME 20 #define SHOW_IMAGE_ORIENTATION_ATTRIBUTE "ShowImage:orientation" + + const rgb_color kBorderColor = { 0, 0, 0, 255 }; enum ShowImageView::image_orientation -ShowImageView::fTransformation[ImageProcessor::kNumberOfAffineTransformations][kNumberOfOrientations] = { +ShowImageView::fTransformation[ImageProcessor::kNumberOfAffineTransformations] + [kNumberOfOrientations] = { // rotate 90° {k90, k180, k270, k0, k270V, k0V, k90V, k0H}, // rotate -90° @@ -168,6 +173,7 @@ uint32 flags) : BView(rect, name, resizingMode, flags), + fBitmapOwner(NULL), fBitmap(NULL), fDisplayBitmap(NULL), fSelectionBitmap(NULL), @@ -178,10 +184,8 @@ fBitmapLocationInView(0.0, 0.0), - fShrinkToBounds(true), fStretchToBounds(false), - fFitToBoundsZoom(1.0), - fFullScreen(false), + fHideCursor(false), fScrollingBitmap(false), fCreatingSelection(false), fFirstPoint(0.0, 0.0), @@ -194,14 +198,13 @@ fShowCaption(false), fShowingPopUpMenu(false), fHideCursorCountDown(HIDE_CURSOR_DELAY_TIME), - fIsActiveWin(true), - fProgressWindow(NULL) + fIsActiveWin(true) { ShowImageSettings* settings; settings = my_app->Settings(); if (settings->Lock()) { - fShrinkToBounds = settings->GetBool("ShrinksToBounds", fShrinkToBounds); - fStretchToBounds = settings->GetBool("ZoomToBounds", fStretchToBounds); + fStretchToBounds = settings->GetBool("StretchToBounds", + fStretchToBounds); fSlideShowDelay = settings->GetInt32("SlideShowDelay", fSlideShowDelay); fScaleBilinear = settings->GetBool("ScaleBilinear", fScaleBilinear); settings->Unlock(); @@ -246,8 +249,7 @@ } #endif - // Hide cursor in full screen mode - if (fFullScreen && !fHasSelection && !fShowingPopUpMenu && fIsActiveWin) { + if (fHideCursor && !fHasSelection && !fShowingPopUpMenu && fIsActiveWin) { if (fHideCursorCountDown <= 0) be_app->ObscureCursor(); else @@ -316,7 +318,12 @@ delete fDisplayBitmap; fDisplayBitmap = NULL; - // TODO: the bitmap is currently only owned by the cache!!! + if (fBitmapOwner != NULL) + fBitmapOwner->ReleaseReference(); + else + delete fBitmap; + + fBitmapOwner = NULL; fBitmap = NULL; } @@ -342,6 +349,8 @@ if (status == B_OK) { fFormatDescription = message->FindString("type"); fMimeType = message->FindString("mime"); + + message->FindPointer("bitmapOwner", (void**)&fBitmapOwner); } return status; @@ -417,9 +426,7 @@ be_roster->AddToRecentDocuments(ref, kApplicationSignature); - fFitToBoundsZoom = _FitToBoundsZoom(); - ResetZoom(); - Invalidate(); + FitToBounds(); _Notify(); return B_OK; } @@ -480,33 +487,22 @@ void -ShowImageView::SetShrinkToBounds(bool enable) -{ - if (fShrinkToBounds != enable) { - _SettingsSetBool("ShrinksToBounds", enable); - fShrinkToBounds = enable; - if (enable) - SetZoom(fFitToBoundsZoom); - } -} - - -void ShowImageView::SetStretchToBounds(bool enable) { if (fStretchToBounds != enable) { - _SettingsSetBool("ZoomToBounds", enable); + _SettingsSetBool("StretchToBounds", enable); fStretchToBounds = enable; if (enable) - SetZoom(fFitToBoundsZoom); + FitToBounds(); } } void -ShowImageView::SetFullScreen(bool fullScreen) +ShowImageView::SetHideIdlingCursor(bool hide) { - fFullScreen = fullScreen; + fHideCursor = hide; + FitToBounds(); } @@ -531,38 +527,19 @@ void ShowImageView::AttachedToWindow() { - ResetZoom(); + FitToBounds(); fUndo.SetWindow(Window()); FixupScrollBars(); - - fProgressWindow = new ProgressWindow(Window()); } void -ShowImageView::DetachedFromWindow() +ShowImageView::FrameResized(float width, float height) { - fProgressWindow->Lock(); - fProgressWindow->Quit(); + FixupScrollBars(); } -bool -ShowImageView::_ShouldShrink() const -{ - return fShrinkToBounds && fBitmap->Bounds().Width() > Bounds().Width() - && fBitmap->Bounds().Height() > Bounds().Height(); -} - - -bool -ShowImageView::_ShouldStretch() const -{ - return fStretchToBounds && fBitmap->Bounds().Width() < Bounds().Width() - && fBitmap->Bounds().Height() < Bounds().Height(); -} - - float ShowImageView::_FitToBoundsZoom() const { @@ -748,17 +725,6 @@ } -void -ShowImageView::FrameResized(float /*width*/, float /*height*/) -{ - if (fBitmap == NULL) - return; - - fFitToBoundsZoom = _FitToBoundsZoom(); - SetZoom(_ShouldStretch() ? fFitToBoundsZoom : fZoom); -} - - BBitmap* ShowImageView::_CopySelection(uchar alpha, bool imageSize) { @@ -1336,6 +1302,12 @@ case B_DELETE: _SendMessageToWindow(kMsgDeleteCurrentFile); break; + case '0': + FitToBounds(); + break; + case '1': + SetZoom(1.0f); + break; case '+': case '=': ZoomIn(); @@ -1394,9 +1366,9 @@ if (!fShowingPopUpMenu) { PopUpMenu* menu = new PopUpMenu("PopUpMenu", this); - ShowImageWindow* showImage = dynamic_cast<ShowImageWindow*>(Window()); - if (showImage) - showImage->BuildContextMenu(menu); + ShowImageWindow* window = dynamic_cast<ShowImageWindow*>(Window()); + if (window != NULL) + window->BuildContextMenu(menu); screen += BPoint(2, 2); menu->Go(screen, true, true, true); @@ -1421,22 +1393,6 @@ ShowImageView::MessageReceived(BMessage* message) { switch (message->what) { -// TODO! -#if 0 - case B_SIMPLE_DATA: - if (message->WasDropped()) { - uint32 type; - int32 count; - status_t ret = message->GetInfo("refs", &type, &count); - if (ret == B_OK && type == B_REF_TYPE) { - // If file was dropped, open it as the selection - entry_ref ref; - if (message->FindRef("refs", 0, &ref) == B_OK) - SetImage(&ref); - } - } - break; -#endif case B_COPY_TARGET: _HandleDrop(message); break; @@ -1456,7 +1412,8 @@ void -ShowImageView::FixupScrollBar(orientation o, float bitmapLength, float viewLength) +ShowImageView::FixupScrollBar(orientation o, float bitmapLength, + float viewLength) { float prop, range; BScrollBar *psb; @@ -1609,10 +1566,11 @@ void ShowImageView::SetZoom(float zoom, BPoint where) { + float fitToBoundsZoom = _FitToBoundsZoom(); if (zoom > 32) zoom = 32; - if (zoom < fFitToBoundsZoom / 2) - zoom = fFitToBoundsZoom / 2; + if (zoom < fitToBoundsZoom / 2) + zoom = fitToBoundsZoom / 2; if (zoom == fZoom) { // window size might have changed @@ -1652,8 +1610,9 @@ // snap zoom to "fit to bounds", and "original size" float zoom = fZoom * 1.2; float zoomSnap = fZoom * 1.25; - if (fZoom < fFitToBoundsZoom && zoomSnap > fFitToBoundsZoom) - zoom = fFitToBoundsZoom; + float fitToBoundsZoom = _FitToBoundsZoom(); + if (fZoom < fitToBoundsZoom - 0.001 && zoomSnap > fitToBoundsZoom) + zoom = fitToBoundsZoom; if (fZoom < 1.0 && zoomSnap > 1.0) zoom = 1.0; @@ -1667,8 +1626,9 @@ // snap zoom to "fit to bounds", and "original size" float zoom = fZoom / 1.2; float zoomSnap = fZoom / 1.25; - if (fZoom > fFitToBoundsZoom && zoomSnap < fFitToBoundsZoom) - zoom = fFitToBoundsZoom; + float fitToBoundsZoom = _FitToBoundsZoom(); + if (fZoom > fitToBoundsZoom + 0.001 && zoomSnap < fitToBoundsZoom) + zoom = fitToBoundsZoom; if (fZoom > 1.0 && zoomSnap < 1.0) zoom = 1.0; @@ -1676,21 +1636,21 @@ } -/*! Resets the zoom to what it should be when opening an image, depending - on the current settings. +/*! Fits to image to the view bounds. */ void -ShowImageView::ResetZoom() +ShowImageView::FitToBounds() { if (fBitmap == NULL) return; - fFitToBoundsZoom = _FitToBoundsZoom(); - - if (_ShouldShrink() || _ShouldStretch()) - SetZoom(fFitToBoundsZoom); + float fitToBoundsZoom = _FitToBoundsZoom(); + if (!fStretchToBounds && fitToBoundsZoom > 1.0f) + SetZoom(1.0f); else - SetZoom(1.0); + SetZoom(fitToBoundsZoom); + + FixupScrollBars(); } Modified: haiku/trunk/src/apps/showimage/ShowImageView.h =================================================================== --- haiku/trunk/src/apps/showimage/ShowImageView.h 2010-11-14 19:04:48 UTC (rev 39430) +++ haiku/trunk/src/apps/showimage/ShowImageView.h 2010-11-14 23:45:15 UTC (rev 39431) @@ -15,10 +15,6 @@ #define SHOW_IMAGE_VIEW_H -#include "Filter.h" -#include "SelectionBox.h" -#include "ShowImageUndo.h" - #include <Bitmap.h> #include <Entry.h> #include <NodeInfo.h> @@ -26,12 +22,14 @@ #include <TranslatorRoster.h> #include <View.h> +#include "Filter.h" +#include "SelectionBox.h" +#include "ShowImageUndo.h" -// the delay time for hiding the cursor in 1/10 seconds (the pulse rate) -#define HIDE_CURSOR_DELAY_TIME 20 -class ProgressWindow; +class BitmapOwner; + class ShowImageView : public BView { public: ShowImageView(BRect rect, const char* name, @@ -39,9 +37,8 @@ virtual ~ShowImageView(); virtual void AttachedToWindow(); - virtual void DetachedFromWindow(); + virtual void FrameResized(float width, float height); virtual void Draw(BRect updateRect); - virtual void FrameResized(float width, float height); virtual void MouseDown(BPoint point); virtual void MouseMoved(BPoint point, uint32 state, const BMessage* dragMessage); @@ -68,16 +65,14 @@ void SaveToFile(BDirectory* dir, const char* name, BBitmap* bitmap, const translation_format* format); + void SetScaleBilinear(bool b); - bool GetScaleBilinear() { return fScaleBilinear; } + bool ScaleBilinear() { return fScaleBilinear; } void SetShowCaption(bool show); - void SetShrinkToBounds(bool enable); - bool ShrinksToBounds() const - { return fShrinkToBounds; } void SetStretchToBounds(bool enable); bool StretchesToBounds() const { return fStretchToBounds; } - void SetFullScreen(bool fullScreen); + void SetHideIdlingCursor(bool hide); void FixupScrollBar(enum orientation orientation, float bitmapLength, float viewLength); @@ -99,11 +94,13 @@ void StartSlideShow(); void StopSlideShow(); + void FitToBounds(); void SetZoom(float zoom, BPoint where = BPoint(-1, -1)); + float Zoom() const + { return fZoom; } void ZoomIn(BPoint where = BPoint(-1, -1)); void ZoomOut(BPoint where = BPoint(-1, -1)); - void ResetZoom(); // Image manipulation void Rotate(int degree); // 90 and 270 only @@ -151,7 +148,6 @@ void _UserDoImageOperation( enum ImageProcessor::operation op, bool quiet = false); - bool _ShouldShrink() const; bool _ShouldStretch() const; float _FitToBoundsZoom() const; BRect _AlignBitmap(); @@ -193,6 +189,7 @@ ShowImageUndo fUndo; entry_ref fCurrentRef; + BitmapOwner* fBitmapOwner; BBitmap* fBitmap; BBitmap* fDisplayBitmap; BBitmap* fSelectionBitmap; @@ -203,10 +200,8 @@ BPoint fBitmapLocationInView; - bool fShrinkToBounds; bool fStretchToBounds; - float fFitToBoundsZoom; - bool fFullScreen; + bool fHideCursor; bool fScrollingBitmap; bool fCreatingSelection; BPoint fFirstPoint; @@ -238,8 +233,6 @@ bool fIsActiveWin; // Is the parent window the active window? - ProgressWindow* fProgressWindow; - image_orientation fImageOrientation; static image_orientation fTransformation[ ImageProcessor Modified: haiku/trunk/src/apps/showimage/ShowImageWindow.cpp =================================================================== --- haiku/trunk/src/apps/showimage/ShowImageWindow.cpp 2010-11-14 19:04:48 UTC (rev 39430) +++ haiku/trunk/src/apps/showimage/ShowImageWindow.cpp 2010-11-14 23:45:15 UTC (rev 39431) @@ -10,6 +10,7 @@ * Michael Pfeiffer * yellowTAB GmbH * Bernd Korz + * Axel Dörfler, axeld@xxxxxxxxxxxxxxxx */ @@ -45,6 +46,7 @@ #include <TranslatorRoster.h> #include "ImageCache.h" +#include "ProgressWindow.h" #include "ShowImageApp.h" #include "ShowImageConstants.h" #include "ShowImageStatusView.h" @@ -56,6 +58,40 @@ const char* kTranslatorField = "be:translator"; +// message constants +enum { + MSG_CAPTURE_MOUSE = 'mCPM', + MSG_CHANGE_FOCUS = 'mCFS', + MSG_WINDOW_QUIT = 'mWQT', + MSG_OUTPUT_TYPE = 'BTMN', + MSG_SAVE_PANEL = 'mFSP', + MSG_CLEAR_SELECT = 'mCSL', + MSG_SELECT_ALL = 'mSAL', + MSG_SELECTION_MODE = 'mSLM', + MSG_PAGE_FIRST = 'mPGF', + MSG_PAGE_LAST = 'mPGL', + MSG_PAGE_NEXT = 'mPGN', + MSG_PAGE_PREV = 'mPGP', + MSG_GOTO_PAGE = 'mGTP', + MSG_ZOOM_IN = 'mZIN', + MSG_ZOOM_OUT = 'mZOU', + MSG_SCALE_BILINEAR = 'mSBL', + MSG_DESKTOP_BACKGROUND = 'mDBG', + MSG_ROTATE_90 = 'mR90', + MSG_ROTATE_270 = 'mR27', + MSG_FLIP_LEFT_TO_RIGHT = 'mFLR', + MSG_FLIP_TOP_TO_BOTTOM = 'mFTB', + MSG_SLIDE_SHOW_DELAY = 'mSSD', + MSG_FULL_SCREEN = 'mFSC', + MSG_SHOW_CAPTION = 'mSCP', + MSG_PAGE_SETUP = 'mPSU', + MSG_PREPARE_PRINT = 'mPPT', + kMsgFitToWindow = 'mFtW', + kMsgOriginalSize = 'mOSZ', + kMsgStretchToWindow = 'mStW' +}; + + [... truncated: 300 lines follow ...]