2 * Copyright 2002-2009 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Jerome Duval, jerome.duval@free.fr
10 #include "ImageFilePanel.h"
17 #include <StringView.h>
18 #include <TranslationUtils.h>
22 #undef B_TRANSLATION_CONTEXT
23 #define B_TRANSLATION_CONTEXT "Image Filepanel"
26 // #pragma mark - ImageFilePanel
29 ImageFilePanel::ImageFilePanel(file_panel_mode mode
, BMessenger
* target
,
30 const entry_ref
* startDirectory
, uint32 nodeFlavors
,
31 bool allowMultipleSelection
, BMessage
* message
, BRefFilter
* filter
,
32 bool modal
, bool hideWhenDone
)
34 BFilePanel(mode
, target
, startDirectory
, nodeFlavors
,
35 allowMultipleSelection
, message
, filter
, modal
, hideWhenDone
),
37 fResolutionView(NULL
),
43 ImageFilePanel::~ImageFilePanel()
51 ImageFilePanel::Show()
53 if (fImageView
== NULL
) {
55 BView
* background
= Window()->ChildAt(0);
56 uint32 poseViewResizingMode
57 = background
->FindView("PoseView")->ResizingMode();
58 uint32 countVwResizingMode
59 = background
->FindView("CountVw")->ResizingMode();
60 uint32 vScrollBarResizingMode
61 = background
->FindView("VScrollBar")->ResizingMode();
62 uint32 hScrollBarResizingMode
63 = background
->FindView("HScrollBar")->ResizingMode();
65 background
->FindView("PoseView")
66 ->SetResizingMode(B_FOLLOW_LEFT
| B_FOLLOW_TOP
);
67 background
->FindView("CountVw")
68 ->SetResizingMode(B_FOLLOW_LEFT
| B_FOLLOW_TOP
);
69 background
->FindView("VScrollBar")
70 ->SetResizingMode(B_FOLLOW_LEFT
| B_FOLLOW_TOP
);
71 background
->FindView("HScrollBar")
72 ->SetResizingMode(B_FOLLOW_LEFT
| B_FOLLOW_TOP
);
73 Window()->ResizeBy(0, 70);
74 background
->FindView("PoseView")->SetResizingMode(poseViewResizingMode
);
75 background
->FindView("CountVw")->SetResizingMode(countVwResizingMode
);
76 background
->FindView("VScrollBar")
77 ->SetResizingMode(vScrollBarResizingMode
);
78 background
->FindView("HScrollBar")
79 ->SetResizingMode(hScrollBarResizingMode
);
81 BRect
rect(background
->Bounds().left
+ 15,
82 background
->Bounds().bottom
- 94, background
->Bounds().left
+ 122,
83 background
->Bounds().bottom
- 15);
84 fImageView
= new BView(rect
, "ImageView",
85 B_FOLLOW_LEFT
| B_FOLLOW_BOTTOM
, B_SUBPIXEL_PRECISE
);
86 fImageView
->SetViewColor(background
->ViewColor());
87 background
->AddChild(fImageView
);
89 rect
= BRect(background
->Bounds().left
+ 132,
90 background
->Bounds().bottom
- 85, background
->Bounds().right
,
91 background
->Bounds().bottom
- 65);
92 fResolutionView
= new BStringView(rect
, "ResolutionView", NULL
,
93 B_FOLLOW_LEFT
| B_FOLLOW_BOTTOM
);
94 background
->AddChild(fResolutionView
);
96 rect
.OffsetBy(0, -16);
97 fImageTypeView
= new BStringView(rect
, "ImageTypeView", NULL
,
98 B_FOLLOW_LEFT
| B_FOLLOW_BOTTOM
);
99 background
->AddChild(fImageTypeView
);
109 ImageFilePanel::SelectionChanged()
114 if (GetNextSelectedRef(&ref
) == B_OK
) {
117 fImageView
->ClearViewBitmap();
120 BBitmap
* bitmap
= BTranslationUtils::GetBitmap(&ref
);
122 if (bitmap
!= NULL
) {
123 BRect
dest(fImageView
->Bounds());
124 if (bitmap
->Bounds().Width() > bitmap
->Bounds().Height()) {
125 dest
.InsetBy(0, (dest
.Height() + 1
126 - ((bitmap
->Bounds().Height() + 1)
127 / (bitmap
->Bounds().Width() + 1)
128 * (dest
.Width() + 1))) / 2);
130 dest
.InsetBy((dest
.Width() + 1
131 - ((bitmap
->Bounds().Width() + 1)
132 / (bitmap
->Bounds().Height() + 1)
133 * (dest
.Height() + 1))) / 2, 0);
135 fImageView
->SetViewBitmap(bitmap
, bitmap
->Bounds(), dest
,
136 B_FOLLOW_LEFT
| B_FOLLOW_TOP
, 0);
139 resolution
<< B_TRANSLATE("Resolution: ")
140 << (int)(bitmap
->Bounds().Width() + 1)
141 << "x" << (int)(bitmap
->Bounds().Height() + 1);
142 fResolutionView
->SetText(resolution
.String());
145 BNodeInfo
nodeInfo(&node
);
146 char type
[B_MIME_TYPE_LENGTH
];
147 if (nodeInfo
.GetType(type
) == B_OK
) {
148 BMimeType
mimeType(type
);
149 mimeType
.GetShortDescription(type
);
150 // if this fails, the MIME type will be displayed
151 fImageTypeView
->SetText(type
);
154 if (BMimeType::GuessMimeType(&ref
, &refType
) == B_OK
) {
155 refType
.GetShortDescription(type
);
156 // if this fails, the MIME type will be displayed
157 fImageTypeView
->SetText(type
);
159 fImageTypeView
->SetText("");
163 fResolutionView
->SetText("");
164 fImageTypeView
->SetText("");
166 fImageView
->Invalidate();
167 fResolutionView
->Invalidate();
170 BFilePanel::SelectionChanged();
174 // #pragma mark - CustomRefFilter
177 CustomRefFilter::CustomRefFilter(bool imageFiltering
)
179 fImageFiltering(imageFiltering
)
185 CustomRefFilter::Filter(const entry_ref
* ref
, BNode
* node
,
186 struct stat_beos
* stat
, const char* filetype
)
188 if (!fImageFiltering
)
189 return node
->IsDirectory();
191 if (node
->IsDirectory())
194 BMimeType
imageType("image"), refType
;
195 BMimeType::GuessMimeType(ref
, &refType
);
196 if (imageType
.Contains(&refType
))