* The bitmap variant of get_device_icon() should now support getting all sizes
even if the icon is not available in that size (ie. is not a vector icon). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@27034 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+19
-18
@@ -219,38 +219,39 @@ get_device_icon(const char *device, BBitmap *icon, icon_size which)
|
|||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vector icon was not available, try old one, also checking the icon_size
|
// Vector icon was not available, try old one
|
||||||
// parameter
|
|
||||||
|
|
||||||
BRect rect;
|
BRect rect;
|
||||||
if (which == B_MINI_ICON)
|
if (which == B_MINI_ICON)
|
||||||
rect.Set(0, 0, 15, 15);
|
rect.Set(0, 0, 15, 15);
|
||||||
else if (which == B_LARGE_ICON)
|
else if (which == B_LARGE_ICON)
|
||||||
rect.Set(0, 0, 31, 31);
|
rect.Set(0, 0, 31, 31);
|
||||||
else
|
|
||||||
return B_BAD_VALUE;
|
|
||||||
|
|
||||||
// check whether icon size and bitmap dimensions do match
|
BBitmap* bitmap = icon;
|
||||||
if (icon->Bounds() != rect)
|
int32 iconSize = which;
|
||||||
return B_MISMATCHED_VALUES;
|
|
||||||
|
|
||||||
void* iconData = icon->Bits();
|
if (icon->ColorSpace() != B_CMAP8
|
||||||
size_t iconSize = icon->BitsLength();
|
|| (which != B_MINI_ICON && which != B_LARGE_ICON)) {
|
||||||
|
if (which < B_LARGE_ICON)
|
||||||
|
iconSize = B_MINI_ICON;
|
||||||
|
else
|
||||||
|
iconSize = B_LARGE_ICON;
|
||||||
|
|
||||||
if (icon->ColorSpace() != B_CMAP8) {
|
bitmap = new(std::nothrow) BBitmap(
|
||||||
iconSize = (size_t)which * (size_t)which;
|
BRect(0, 0, iconSize - 1, iconSize -1), B_CMAP8);
|
||||||
iconData = malloc(iconSize);
|
if (bitmap == NULL || bitmap->InitCheck() != B_OK) {
|
||||||
if (iconData == NULL)
|
delete bitmap;
|
||||||
return B_NO_MEMORY;
|
return B_NO_MEMORY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the icon, convert temporary data into bitmap if necessary
|
// get the icon, convert temporary data into bitmap if necessary
|
||||||
status = get_device_icon(device, iconData, which);
|
status = get_device_icon(device, bitmap->Bits(), iconSize);
|
||||||
if (status == B_OK && iconData != icon->Bits())
|
if (status == B_OK && icon != bitmap)
|
||||||
icon->SetBits(iconData, iconSize, 0, B_CMAP8);
|
status = BIconUtils::ConvertFromCMAP8(bitmap, icon);
|
||||||
|
|
||||||
if (iconData != icon->Bits())
|
if (icon != bitmap)
|
||||||
free(iconData);
|
delete bitmap;
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user