2 * Copyright 2007-2010, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
7 #include "ProgressWindow.h"
15 #include <MessageRunner.h>
17 #include <StatusBar.h>
19 #include "ShowImageConstants.h"
22 static const uint32 kMsgShow
= 'show';
24 #undef B_TRANSLATION_CONTEXT
25 #define B_TRANSLATION_CONTEXT "ProgressWindow"
28 ProgressWindow::ProgressWindow()
30 BWindow(BRect(0, 0, 250, 100), B_TRANSLATE("Progress monitor"),
31 B_MODAL_WINDOW_LOOK
, B_NORMAL_WINDOW_FEEL
,// B_FLOATING_APP_WINDOW_FEEL,
32 // TODO: a bug in the app_server prevents an initial floating-app feel
33 // to work correctly; the window will then not be visible for the first
34 // image, even though it's later set to normal feel in that case.
35 B_NOT_ZOOMABLE
| B_NOT_RESIZABLE
| B_ASYNCHRONOUS_CONTROLS
),
38 BRect rect
= Bounds();
40 BView
* view
= new BView(rect
, NULL
, B_FOLLOW_ALL
, B_WILL_DRAW
);
41 view
->SetViewUIColor(B_PANEL_BACKGROUND_COLOR
);
44 rect
= view
->Bounds().InsetByCopy(5, 5);
45 fStatusBar
= new BStatusBar(rect
, "status", NULL
, NULL
);
47 fStatusBar
->GetPreferredSize(&width
, &height
);
48 fStatusBar
->ResizeTo(rect
.Width(), height
);
49 fStatusBar
->SetResizingMode(B_FOLLOW_TOP
| B_FOLLOW_LEFT_RIGHT
);
50 view
->AddChild(fStatusBar
);
52 ResizeTo(Bounds().Width(), height
+ 9);
58 ProgressWindow::~ProgressWindow()
65 ProgressWindow::Start(BWindow
* referenceWindow
, bool center
)
69 BScreen
screen(referenceWindow
);
72 GetDecoratorSettings(&settings
);
75 if (settings
.FindInt32("border width", &borderWidth
) != B_OK
)
78 MoveTo(screen
.Frame().left
+ borderWidth
,
79 screen
.Frame().bottom
- Bounds().Height() - borderWidth
);
81 CenterIn(screen
.Frame());
83 SetFeel(referenceWindow
->IsHidden()
84 ? B_NORMAL_WINDOW_FEEL
: B_FLOATING_APP_WINDOW_FEEL
);
86 fRetrievedUpdate
= false;
87 fRetrievedShow
= false;
90 BMessage
show(kMsgShow
);
91 fRunner
= new BMessageRunner(this, &show
, 1000000, 1);
96 ProgressWindow::Stop()
109 ProgressWindow::MessageReceived(BMessage
* message
)
111 switch (message
->what
) {
113 if (fRetrievedUpdate
&& IsHidden()) {
118 fRetrievedShow
= true;
121 case kMsgProgressUpdate
:
123 if (message
->FindFloat("percent", &percent
) == B_OK
)
124 fStatusBar
->Update(percent
- fStatusBar
->CurrentValue());
127 if (message
->FindString("message", &text
) == B_OK
)
128 fStatusBar
->SetText(text
);
130 fRetrievedUpdate
= true;
132 if (fRetrievedShow
&& IsHidden()) {
139 BWindow::MessageReceived(message
);