BTRFS: Implement BTree::Path and change _Find.
[haiku.git] / src / apps / packageinstaller / PackageImageViewer.cpp
blobc486b519121feee0e66c339156307764cf45961e
1 /*
2 * Copyright (c) 2007, Haiku, Inc.
3 * Distributed under the terms of the MIT license.
5 * Author:
6 * Ɓukasz 'Sil2100' Zemczak <sil2100@vexillium.org>
7 */
10 #include "PackageImageViewer.h"
12 #include <BitmapStream.h>
13 #include <Catalog.h>
14 #include <Locale.h>
15 #include <Message.h>
16 #include <Screen.h>
17 #include <TranslatorRoster.h>
20 #undef B_TRANSLATION_CONTEXT
21 #define B_TRANSLATION_CONTEXT "PackageImageViewer"
24 ImageView::ImageView(BPositionIO* imageIO)
26 BView(BRect(0, 0, 1, 1), "image_view", B_FOLLOW_NONE, B_WILL_DRAW),
27 fImage(NULL)
29 if (imageIO == NULL)
30 return;
32 // Initialize and translate the image
33 BTranslatorRoster* roster = BTranslatorRoster::Default();
34 BBitmapStream stream;
35 if (roster->Translate(imageIO, NULL, NULL, &stream, B_TRANSLATOR_BITMAP)
36 != B_OK) {
37 return;
39 stream.DetachBitmap(&fImage);
43 ImageView::~ImageView()
45 delete fImage;
49 void
50 ImageView::AttachedToWindow()
52 if (fImage == NULL) {
53 ResizeTo(75, 75);
54 return;
57 // We need to resize the view depending on what size has the screen and
58 // the image we will be viewing
59 BScreen screen(Window());
60 BRect frame = screen.Frame();
61 BRect image = fImage->Bounds();
63 if (image.Width() > (frame.Width() - 100.0f))
64 image.right = frame.Width() - 100.0f;
65 if (image.Height() > (frame.Height() - 100.0f))
66 image.bottom = frame.Height() - 100.f;
68 ResizeTo(image.Width(), image.Height());
72 void
73 ImageView::Draw(BRect updateRect)
75 if (fImage != NULL)
76 DrawBitmapAsync(fImage, Bounds());
77 else {
78 const char* message = B_TRANSLATE("Image not loaded correctly");
79 float width = StringWidth(message);
80 DrawString(message, BPoint((Bounds().Width() - width) / 2.0f, 30.0f));
85 void
86 ImageView::MouseUp(BPoint point)
88 BWindow* window = Window();
89 if (window != NULL)
90 window->PostMessage(B_QUIT_REQUESTED);
94 // #pragma mark -
97 PackageImageViewer::PackageImageViewer(BPositionIO* imageIO)
99 BlockingWindow(BRect(100, 100, 100, 100), "")
101 fBackground = new ImageView(imageIO);
102 AddChild(fBackground);
104 ResizeTo(fBackground->Bounds().Width(), fBackground->Bounds().Height());
106 BScreen screen(this);
107 BRect frame = screen.Frame();
108 MoveTo((frame.Width() - Bounds().Width()) / 2.0f,
109 (frame.Height() - Bounds().Height()) / 2.0f);