PackageInstaller: Yet more cleanup and code simplifications
This commit is contained in:
parent
4450737441
commit
79350dde31
@ -25,21 +25,19 @@ enum {
|
||||
};
|
||||
|
||||
|
||||
ImageView::ImageView(BPositionIO *image)
|
||||
ImageView::ImageView(BPositionIO* imageIO)
|
||||
:
|
||||
BView(BRect(0, 0, 1, 1), "image_view", B_FOLLOW_NONE, B_WILL_DRAW),
|
||||
fSuccess(true)
|
||||
fImage(NULL)
|
||||
{
|
||||
if (!image) {
|
||||
fSuccess = false;
|
||||
if (imageIO == NULL)
|
||||
return;
|
||||
}
|
||||
|
||||
// Initialize and translate the image
|
||||
BTranslatorRoster *roster = BTranslatorRoster::Default();
|
||||
BTranslatorRoster* roster = BTranslatorRoster::Default();
|
||||
BBitmapStream stream;
|
||||
if (roster->Translate(image, NULL, NULL, &stream, B_TRANSLATOR_BITMAP)
|
||||
< B_OK) {
|
||||
fSuccess = false;
|
||||
if (roster->Translate(imageIO, NULL, NULL, &stream, B_TRANSLATOR_BITMAP)
|
||||
!= B_OK) {
|
||||
return;
|
||||
}
|
||||
stream.DetachBitmap(&fImage);
|
||||
@ -48,13 +46,14 @@ ImageView::ImageView(BPositionIO *image)
|
||||
|
||||
ImageView::~ImageView()
|
||||
{
|
||||
delete fImage;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ImageView::AttachedToWindow()
|
||||
{
|
||||
if (!fSuccess) {
|
||||
if (fImage == NULL) {
|
||||
ResizeTo(75, 75);
|
||||
return;
|
||||
}
|
||||
@ -77,12 +76,12 @@ ImageView::AttachedToWindow()
|
||||
void
|
||||
ImageView::Draw(BRect updateRect)
|
||||
{
|
||||
if (fSuccess)
|
||||
if (fImage != NULL)
|
||||
DrawBitmapAsync(fImage, Bounds());
|
||||
else {
|
||||
float length = StringWidth(B_TRANSLATE("Image not loaded correctly"));
|
||||
DrawString(B_TRANSLATE("Image not loaded correctly"),
|
||||
BPoint((Bounds().Width() - length) / 2.0f, 30.0f));
|
||||
const char* message = B_TRANSLATE("Image not loaded correctly");
|
||||
float width = StringWidth(message);
|
||||
DrawString(message, BPoint((Bounds().Width() - width) / 2.0f, 30.0f));
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,7 +89,7 @@ ImageView::Draw(BRect updateRect)
|
||||
void
|
||||
ImageView::MouseUp(BPoint point)
|
||||
{
|
||||
BWindow *parent = Window();
|
||||
BWindow* parent = Window();
|
||||
if (parent)
|
||||
parent->PostMessage(P_MSG_CLOSE);
|
||||
}
|
||||
@ -99,12 +98,12 @@ ImageView::MouseUp(BPoint point)
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
PackageImageViewer::PackageImageViewer(BPositionIO *image)
|
||||
PackageImageViewer::PackageImageViewer(BPositionIO* imageIO)
|
||||
:
|
||||
BWindow(BRect(100, 100, 100, 100), "", B_MODAL_WINDOW,
|
||||
B_NOT_ZOOMABLE | B_NOT_RESIZABLE | B_NOT_CLOSABLE)
|
||||
{
|
||||
fBackground = new ImageView(image);
|
||||
fBackground = new ImageView(imageIO);
|
||||
AddChild(fBackground);
|
||||
|
||||
ResizeTo(fBackground->Bounds().Width(), fBackground->Bounds().Height());
|
||||
@ -112,7 +111,7 @@ PackageImageViewer::PackageImageViewer(BPositionIO *image)
|
||||
BScreen screen(this);
|
||||
BRect frame = screen.Frame();
|
||||
MoveTo((frame.Width() - Bounds().Width()) / 2.0f,
|
||||
(frame.Height() - Bounds().Height()) / 2.0f);
|
||||
(frame.Height() - Bounds().Height()) / 2.0f);
|
||||
}
|
||||
|
||||
|
||||
@ -121,6 +120,19 @@ PackageImageViewer::~PackageImageViewer()
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageImageViewer::MessageReceived(BMessage* message)
|
||||
{
|
||||
if (message->what == P_MSG_CLOSE) {
|
||||
if (fSemaphore >= B_OK) {
|
||||
delete_sem(fSemaphore);
|
||||
fSemaphore = -1;
|
||||
}
|
||||
} else
|
||||
BWindow::MessageReceived(message);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageImageViewer::Go()
|
||||
{
|
||||
@ -133,11 +145,14 @@ PackageImageViewer::Go()
|
||||
return;
|
||||
}
|
||||
|
||||
BWindow *parent =
|
||||
dynamic_cast<BWindow *>(BLooper::LooperForThread(find_thread(NULL)));
|
||||
thread_id callingThread = find_thread(NULL);
|
||||
BWindow* window = dynamic_cast<BWindow*>(BLooper::LooperForThread(
|
||||
callingThread));
|
||||
Show();
|
||||
|
||||
if (parent) {
|
||||
if (window != NULL) {
|
||||
// Make sure calling window thread, which is blocked here, is updating
|
||||
// the window from time to time.
|
||||
status_t ret;
|
||||
for (;;) {
|
||||
do {
|
||||
@ -146,10 +161,9 @@ PackageImageViewer::Go()
|
||||
|
||||
if (ret == B_BAD_SEM_ID)
|
||||
break;
|
||||
parent->UpdateIfNeeded();
|
||||
window->UpdateIfNeeded();
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Since there are no spinlocks, wait until the semaphore is free
|
||||
while (acquire_sem(fSemaphore) == B_INTERRUPTED) {
|
||||
}
|
||||
@ -159,16 +173,3 @@ PackageImageViewer::Go()
|
||||
Quit();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
PackageImageViewer::MessageReceived(BMessage *msg)
|
||||
{
|
||||
if (msg->what == P_MSG_CLOSE) {
|
||||
if (fSemaphore >= B_OK) {
|
||||
delete_sem(fSemaphore);
|
||||
fSemaphore = -1;
|
||||
}
|
||||
} else
|
||||
BWindow::MessageReceived(msg);
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,8 @@
|
||||
* Author:
|
||||
* Łukasz 'Sil2100' Zemczak <sil2100@vexillium.org>
|
||||
*/
|
||||
#ifndef PACKAGEIMAGEVIEWER_H
|
||||
#define PACKAGEIMAGEVIEWER_H
|
||||
#ifndef PACKAGE_IMAGE_VIEWER_H
|
||||
#define PACKAGE_IMAGE_VIEWER_H
|
||||
|
||||
#include <Window.h>
|
||||
#include <View.h>
|
||||
@ -16,35 +16,34 @@
|
||||
|
||||
|
||||
class ImageView : public BView {
|
||||
public:
|
||||
ImageView(BPositionIO *image);
|
||||
~ImageView();
|
||||
public:
|
||||
ImageView(BPositionIO* image);
|
||||
virtual ~ImageView();
|
||||
|
||||
void AttachedToWindow();
|
||||
void Draw(BRect updateRect);
|
||||
void MouseUp(BPoint point);
|
||||
virtual void AttachedToWindow();
|
||||
virtual void Draw(BRect updateRect);
|
||||
virtual void MouseUp(BPoint point);
|
||||
|
||||
private:
|
||||
BBitmap *fImage;
|
||||
bool fSuccess;
|
||||
private:
|
||||
BBitmap* fImage;
|
||||
};
|
||||
|
||||
|
||||
class PackageImageViewer : public BWindow {
|
||||
public:
|
||||
PackageImageViewer(BPositionIO *image);
|
||||
~PackageImageViewer();
|
||||
public:
|
||||
PackageImageViewer(BPositionIO* image);
|
||||
virtual ~PackageImageViewer();
|
||||
|
||||
void Go();
|
||||
|
||||
void MessageReceived(BMessage *msg);
|
||||
virtual void MessageReceived(BMessage* message);
|
||||
|
||||
private:
|
||||
ImageView *fBackground;
|
||||
void Go();
|
||||
|
||||
sem_id fSemaphore;
|
||||
private:
|
||||
ImageView* fBackground;
|
||||
|
||||
sem_id fSemaphore;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
#endif // PACKAGE_IMAGE_VIEWER_H
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user