Moved the "get icon engine" from IconView into a function in MimeTypeListView.cpp; it's

now used by the MimeTypeItems as well, if showIcon mode is used.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16409 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler 2006-02-15 16:46:58 +00:00
parent fa815db338
commit 4f92605003
3 changed files with 71 additions and 47 deletions

View File

@ -87,14 +87,8 @@ class IconView : public BControl {
#endif
private:
enum {
kNoIcon = 0,
kOwnIcon,
kApplicationIcon,
kSupertypeIcon
};
BBitmap* fIcon;
int32 fIconSource;
icon_source fIconSource;
};
class AttributeListView : public BListView {
@ -228,42 +222,7 @@ IconView::SetTo(BMimeType* type)
B_CMAP8);
}
if (type->GetIcon(fIcon, B_LARGE_ICON) == B_OK)
fIconSource = kOwnIcon;
if (fIconSource == kNoIcon) {
// check for icon from preferred app
char preferred[B_MIME_TYPE_LENGTH];
if (type->GetPreferredApp(preferred) == B_OK) {
BMimeType preferredApp(preferred);
if (preferredApp.GetIconForType(type->Type(), fIcon,
B_LARGE_ICON) == B_OK)
fIconSource = kApplicationIcon;
}
}
if (fIconSource == kNoIcon) {
// check super type for an icon
BMimeType superType;
if (type->GetSupertype(&superType) == B_OK) {
if (superType.GetIcon(fIcon, B_LARGE_ICON) == B_OK)
fIconSource = kSupertypeIcon;
else {
// check the super type's preferred app
char preferred[B_MIME_TYPE_LENGTH];
if (superType.GetPreferredApp(preferred) == B_OK) {
BMimeType preferredApp(preferred);
if (preferredApp.GetIconForType(superType.Type(),
fIcon, B_LARGE_ICON) == B_OK)
fIconSource = kSupertypeIcon;
}
}
}
}
icon_for_type(*type, *fIcon, B_LARGE_ICON, &fIconSource);
}
if (fIconSource == kNoIcon) {
@ -558,7 +517,7 @@ FileTypesWindow::FileTypesWindow(BRect frame)
if (rect.right < 180)
rect.right = 180;
fTypeListView = new MimeTypeListView(rect, "listview", NULL, false, false,
fTypeListView = new MimeTypeListView(rect, "typeview", NULL, false, false,
B_FOLLOW_LEFT | B_FOLLOW_TOP_BOTTOM);
fTypeListView->SetSelectionMessage(new BMessage(kMsgTypeSelected));
@ -733,7 +692,12 @@ FileTypesWindow::FileTypesWindow(BRect frame)
fRemoveAttributeButton = new BButton(innerRect, "remove attr", "Remove",
new BMessage(kMsgRemoveAttribute), B_FOLLOW_RIGHT);
box->AddChild(fRemoveAttributeButton);
/*
innerRect.OffsetBy(0, innerRect.Height() + 4.0f);
button = new BButton(innerRect, "push attr", "Push Up",
new BMessage(kMsgRemoveAttribute), B_FOLLOW_RIGHT);
box->AddChild(button);
*/
innerRect.right = innerRect.left - 10.0f - B_V_SCROLL_BAR_WIDTH;
innerRect.left = 10.0f;
innerRect.top = 8.0f + ceilf(fontHeight.ascent);

View File

@ -12,6 +12,57 @@
// TODO: lazy type collecting (super types only at startup)
status_t
icon_for_type(BMimeType& type, BBitmap& bitmap, icon_size size,
icon_source* _source)
{
icon_source source = kNoIcon;
if (type.GetIcon(&bitmap, size) == B_OK) {
source = kOwnIcon;
return B_OK;
}
if (source == kNoIcon) {
// check for icon from preferred app
char preferred[B_MIME_TYPE_LENGTH];
if (type.GetPreferredApp(preferred) != B_OK) {
BMimeType preferredApp(preferred);
if (preferredApp.GetIconForType(type.Type(), &bitmap, size) == B_OK)
source = kApplicationIcon;
}
}
if (source == kNoIcon) {
// check super type for an icon
BMimeType superType;
if (type.GetSupertype(&superType) == B_OK) {
if (superType.GetIcon(&bitmap, size) == B_OK)
source = kSupertypeIcon;
else {
// check the super type's preferred app
char preferred[B_MIME_TYPE_LENGTH];
if (superType.GetPreferredApp(preferred) == B_OK) {
BMimeType preferredApp(preferred);
if (preferredApp.GetIconForType(superType.Type(),
&bitmap, size) == B_OK)
source = kSupertypeIcon;
}
}
}
}
if (_source)
*_source = source;
return source != kNoIcon ? B_OK : B_ERROR;
}
bool
mimetype_is_application_signature(BMimeType& type)
{
@ -86,7 +137,7 @@ MimeTypeItem::DrawItem(BView* owner, BRect frame, bool complete)
BBitmap bitmap(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1), B_CMAP8);
BMimeType mimeType(fType.String());
if (mimeType.GetIcon(&bitmap, B_MINI_ICON) == B_OK) {
if (icon_for_type(mimeType, bitmap, B_MINI_ICON) == B_OK) {
BPoint point(rect.left + 2.0f,
rect.top + (rect.Height() - B_MINI_ICON) / 2.0f);

View File

@ -79,6 +79,15 @@ class MimeTypeListView : public BOutlineListView {
bool fApplicationMode;
};
bool mimetype_is_application_signature(BMimeType& type);
enum icon_source {
kNoIcon = 0,
kOwnIcon,
kApplicationIcon,
kSupertypeIcon
};
extern status_t icon_for_type(BMimeType& type, BBitmap& bitmap, icon_size size,
icon_source* _source = NULL);
extern bool mimetype_is_application_signature(BMimeType& type);
#endif // MIME_TYPE_LIST_VIEW_H