diff --git a/src/apps/showimage/Jamfile b/src/apps/showimage/Jamfile index 59cc2b500c..dbcd86020e 100644 --- a/src/apps/showimage/Jamfile +++ b/src/apps/showimage/Jamfile @@ -4,7 +4,8 @@ UsePrivateHeaders tracker ; SetSubDirSupportedPlatformsBeOSCompatible ; -Application ShowImage : ShowImageApp.cpp +Application ShowImage : + ShowImageApp.cpp ShowImageSettings.cpp ShowImageStatusView.cpp ShowImageUndo.cpp @@ -14,6 +15,7 @@ Application ShowImage : ShowImageApp.cpp Filter.cpp EntryMenuItem.cpp BackgroundImage.cpp + ProgressWindow.cpp ResizerWindow.cpp : be tracker translation : ShowImage.rdef diff --git a/src/apps/showimage/ProgressWindow.cpp b/src/apps/showimage/ProgressWindow.cpp new file mode 100644 index 0000000000..f279a9cd01 --- /dev/null +++ b/src/apps/showimage/ProgressWindow.cpp @@ -0,0 +1,116 @@ +/* + * Copyright 2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ + + +#include "ProgressWindow.h" + +#include +#include +#include +#include + +#include + + +static const uint32 kMsgShow = 'show'; +static const uint32 kMsgStatusUpdate = 'SIup'; + + +ProgressWindow::ProgressWindow(BWindow* referenceWindow) + : BWindow(BRect(0, 0, 250, 100), "Progress Monitor", + B_MODAL_WINDOW_LOOK, B_FLOATING_APP_WINDOW_FEEL, + B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_ASYNCHRONOUS_CONTROLS), + fRunner(NULL) +{ + BRect rect = Bounds(); + + BView *view = new BView(rect, NULL, B_FOLLOW_ALL, B_WILL_DRAW); + view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + AddChild(view); + + rect = view->Bounds().InsetByCopy(5, 5); + fStatusBar = new BStatusBar(rect, "status", NULL, NULL); + float width, height; + fStatusBar->GetPreferredSize(&width, &height); + fStatusBar->ResizeTo(rect.Width(), height); + fStatusBar->SetResizingMode(B_FOLLOW_TOP | B_FOLLOW_LEFT_RIGHT); + view->AddChild(fStatusBar); + + BScreen screen(referenceWindow); + ResizeTo(Bounds().Width(), height + 9); + MoveTo(screen.Frame().left + 5, screen.Frame().bottom - Bounds().Height() - 5); + + Run(); +} + + +ProgressWindow::~ProgressWindow() +{ + delete fRunner; +} + + +void +ProgressWindow::Start() +{ + BAutolock _(this); + + fRetrievedUpdate = false; + fRetrievedShow = false; + delete fRunner; + + BMessage show(kMsgShow); + fRunner = new BMessageRunner(this, &show, 1000000, 1); +} + + +void +ProgressWindow::Stop() +{ + BAutolock _(this); + + delete fRunner; + fRunner = NULL; + + if (!IsHidden()) + Hide(); +} + + +void +ProgressWindow::MessageReceived(BMessage *message) +{ + switch (message->what) { + case kMsgShow: + if (fRetrievedUpdate && IsHidden()) { + Show(); + Minimize(false); + } + + fRetrievedShow = true; + break; + + case kMsgStatusUpdate: + float percent; + if (message->FindFloat("percent", &percent) == B_OK) + fStatusBar->Update(percent - fStatusBar->CurrentValue()); + + const char *text; + if (message->FindString("message", &text) == B_OK) + fStatusBar->SetText(text); + + fRetrievedUpdate = true; + + if (fRetrievedShow && IsHidden()) { + Show(); + Minimize(false); + } + break; + + default: + BWindow::MessageReceived(message); + } +} + diff --git a/src/apps/showimage/ProgressWindow.h b/src/apps/showimage/ProgressWindow.h new file mode 100644 index 0000000000..7af34be565 --- /dev/null +++ b/src/apps/showimage/ProgressWindow.h @@ -0,0 +1,32 @@ +/* + * Copyright 2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. + * Distributed under the terms of the MIT License. + */ +#ifndef PROGRESS_WINDOW_H +#define PROGRESS_WINDOW_H + + +#include + +class BMessageRunner; +class BStatusBar; + + +class ProgressWindow : public BWindow { + public: + ProgressWindow(BWindow* referenceWindow); + virtual ~ProgressWindow(); + + virtual void MessageReceived(BMessage *message); + + void Start(); + void Stop(); + + private: + BStatusBar* fStatusBar; + BMessageRunner* fRunner; + bool fRetrievedUpdate; + bool fRetrievedShow; +}; + +#endif // PROGRESS_WINDOW_H diff --git a/src/apps/showimage/ShowImageView.cpp b/src/apps/showimage/ShowImageView.cpp index 161e625f4d..4612c3e0c5 100644 --- a/src/apps/showimage/ShowImageView.cpp +++ b/src/apps/showimage/ShowImageView.cpp @@ -14,6 +14,7 @@ */ +#include "ProgressWindow.h" #include "ShowImageApp.h" #include "ShowImageConstants.h" #include "ShowImageView.h" @@ -174,8 +175,9 @@ PopUpMenu::~PopUpMenu() ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode, - uint32 flags) - : BView(rect, name, resizingMode, flags) + uint32 flags) + : BView(rect, name, resizingMode, flags), + fProgressWindow(NULL) { ShowImageSettings* settings; settings = my_app->Settings(); @@ -214,7 +216,7 @@ ShowImageView::ShowImageView(BRect rect, const char *name, uint32 resizingMode, fScaleBilinear = settings->GetBool("ScaleBilinear", fScaleBilinear); settings->Unlock(); } - + SetViewColor(B_TRANSPARENT_COLOR); SetHighColor(kBorderColor); SetLowColor(ui_color(B_PANEL_BACKGROUND_COLOR)); @@ -488,17 +490,28 @@ ShowImageView::SetImage(const entry_ref *ref) // if new image, reset to first document fDocumentIndex = 1; } + if (ioExtension.AddInt32("/documentIndex", fDocumentIndex) != B_OK) return B_ERROR; - if (roster->Identify(&file, &ioExtension, &info, 0, NULL, - B_TRANSLATOR_BITMAP) != B_OK) - return B_ERROR; + + if (ioExtension.AddMessenger("/progressMonitor", fProgressWindow) == B_OK) + fProgressWindow->Start(); // Translate image data and create a new ShowImage window + BBitmapStream outstream; - if (roster->Translate(&file, &info, &ioExtension, &outstream, - B_TRANSLATOR_BITMAP) != B_OK) - return B_ERROR; + + status_t status = roster->Identify(&file, &ioExtension, &info, 0, NULL, + B_TRANSLATOR_BITMAP); + if (status == B_OK) { + status = roster->Translate(&file, &info, &ioExtension, &outstream, + B_TRANSLATOR_BITMAP); + } + + fProgressWindow->Stop(); + + if (status != B_OK) + return status; BBitmap *newBitmap = NULL; if (outstream.DetachBitmap(&newBitmap) != B_OK) @@ -565,8 +578,8 @@ ShowImageView::SetImage(const entry_ref *ref) // get the number of documents (pages) if it has been supplied int32 documentCount = 0; - if (ioExtension.FindInt32("/documentCount", &documentCount) == B_OK && - documentCount > 0) + if (ioExtension.FindInt32("/documentCount", &documentCount) == B_OK + && documentCount > 0) fDocumentCount = documentCount; else fDocumentCount = 1; @@ -719,6 +732,16 @@ ShowImageView::AttachedToWindow() { fUndo.SetWindow(Window()); FixupScrollBars(); + + fProgressWindow = new ProgressWindow(Window()); +} + + +void +ShowImageView::DetachedFromWindow() +{ + fProgressWindow->Lock(); + fProgressWindow->Quit(); } diff --git a/src/apps/showimage/ShowImageView.h b/src/apps/showimage/ShowImageView.h index db5b88198e..35c9041eaa 100644 --- a/src/apps/showimage/ShowImageView.h +++ b/src/apps/showimage/ShowImageView.h @@ -1,5 +1,5 @@ /* - * Copyright 2003-2006, Haiku, Inc. All Rights Reserved. + * Copyright 2003-2007, Haiku, Inc. All Rights Reserved. * Copyright 2004-2005 yellowTAB GmbH. All Rights Reserverd. * Copyright 2006 Bernd Korz. All Rights Reserved * Distributed under the terms of the MIT License. @@ -36,6 +36,8 @@ // the delay time for hiding the cursor in 1/10 seconds (the pulse rate) #define HIDE_CURSOR_DELAY_TIME 20 +class ProgressWindow; + class ShowImageView : public BView { public: ShowImageView(BRect rect, const char *name, uint32 resizingMode, @@ -43,6 +45,7 @@ class ShowImageView : public BView { virtual ~ShowImageView(); virtual void AttachedToWindow(); + virtual void DetachedFromWindow(); virtual void Draw(BRect updateRect); virtual void FrameResized(float width, float height); virtual void MouseDown(BPoint point); @@ -249,6 +252,8 @@ class ShowImageView : public BView { int fHideCursorCountDown; // Hides the cursor when it reaches zero bool fIsActiveWin; // Is the parent window the active window? + ProgressWindow* fProgressWindow; + enum image_orientation fImageOrientation; static enum image_orientation fTransformation[ ImageProcessor::kNumberOfAffineTransformations][kNumberOfOrientations];