Tracker: Refactor IconCache size handling and usages.

* Instead of taking an icon_size, which we were having to cast
   random integers to anyway, just take a BSize and convert internally
   as needed. This simplifies a lot of usages of IconCache methods.

 * Compute what B_MINI_ICON size will be at startup. This way,
   we do not wind up caching "mini" icons in the fLarge*Icon variables
   under HiDPI.

   This does have a downside that if anything actually
   does try to fetch "true mini" (16x16) icons when the real
   ComposeIconSize(B_MINI_ICON) is larger than that, it will wind up
   (confusingly) in fLarge*Icon, but that should not cause problems
   and after this commit should not happen at all, anyway.

 * Make mini-icon-mode use ComposeSize instead of the hardcoded 16x16,
   and adjust metrics computations around it.

 * Fetch larger icons in MountMenu logic. Also use BString::SetToFormat.

 * Remove an unused, deprecated method from BPoseView.

 * Rename variables in thumbnail generation code to match new behavior.
This commit is contained in:
Augustin Cavalier
2022-08-26 17:24:44 -04:00
parent 9f4bb0f544
commit 0c973c9467
14 changed files with 166 additions and 164 deletions
+3 -4
View File
@@ -414,7 +414,7 @@ DraggableContainerIcon::MouseDown(BPoint where)
window->CurrentMessage()->FindInt32("buttons", (int32*)&buttons); window->CurrentMessage()->FindInt32("buttons", (int32*)&buttons);
if (IconCache::sIconCache->IconHitTest(where, window->TargetModel(), if (IconCache::sIconCache->IconHitTest(where, window->TargetModel(),
kNormalIcon, (icon_size)(fIconSize.IntegerWidth() + 1))) { kNormalIcon, fIconSize)) {
// The click hit the icon, initiate a drag // The click hit the icon, initiate a drag
fDragButton = buttons fDragButton = buttons
& (B_PRIMARY_MOUSE_BUTTON | B_SECONDARY_MOUSE_BUTTON); & (B_PRIMARY_MOUSE_BUTTON | B_SECONDARY_MOUSE_BUTTON);
@@ -487,7 +487,7 @@ DraggableContainerIcon::MouseMoved(BPoint where, uint32, const BMessage*)
// Draw the icon // Draw the icon
float hIconOffset = (rect.Width() - Bounds().Width()) / 2; float hIconOffset = (rect.Width() - Bounds().Width()) / 2;
IconCache::sIconCache->Draw(model, view, BPoint(hIconOffset, 0), IconCache::sIconCache->Draw(model, view, BPoint(hIconOffset, 0),
kNormalIcon, (icon_size)(fIconSize.IntegerWidth() + 1), true); kNormalIcon, fIconSize, true);
// See if we need to truncate the string // See if we need to truncate the string
BString nameString = model->Name(); BString nameString = model->Name();
@@ -549,8 +549,7 @@ DraggableContainerIcon::Draw(BRect updateRect)
float iconOffsetX = (Bounds().Width() - fIconSize.Width()) / 2; float iconOffsetX = (Bounds().Width() - fIconSize.Width()) / 2;
float iconOffsetY = (Bounds().Height() - fIconSize.Height()) / 2; float iconOffsetY = (Bounds().Height() - fIconSize.Height()) / 2;
IconCache::sIconCache->Draw(window->TargetModel(), this, IconCache::sIconCache->Draw(window->TargetModel(), this,
BPoint(iconOffsetX, iconOffsetY), kNormalIcon, (icon_size)(fIconSize.IntegerWidth() + 1), BPoint(iconOffsetX, iconOffsetY), kNormalIcon, fIconSize, true);
true);
} }
+77 -60
View File
@@ -63,6 +63,7 @@ All rights reserved.
// generic icon // generic icon
#include <ControlLook.h>
#include <Debug.h> #include <Debug.h>
#include <Screen.h> #include <Screen.h>
#include <Volume.h> #include <Volume.h>
@@ -102,6 +103,17 @@ All rights reserved.
#undef NODE_CACHE_ASYNC_DRAWS #undef NODE_CACHE_ASYNC_DRAWS
BSize IconCache::sMiniIconSize;
static inline icon_size
icon_size_for(BSize size)
{
ASSERT(size.Width() == size.Height());
return (icon_size)(size.IntegerWidth() + 1);
}
IconCacheEntry::IconCacheEntry() IconCacheEntry::IconCacheEntry()
: :
fLargeIcon(NULL), fLargeIcon(NULL),
@@ -159,7 +171,7 @@ IconCacheEntry::ResolveIfAlias(const SharedIconCache* sharedCache,
bool bool
IconCacheEntry::CanConstructBitmap(IconDrawMode mode, icon_size) const IconCacheEntry::CanConstructBitmap(IconDrawMode mode, BSize) const
{ {
if (mode == kSelected) { if (mode == kSelected) {
// for now only // for now only
@@ -171,19 +183,19 @@ IconCacheEntry::CanConstructBitmap(IconDrawMode mode, icon_size) const
bool bool
IconCacheEntry::HaveIconBitmap(IconDrawMode mode, icon_size size) const IconCacheEntry::HaveIconBitmap(IconDrawMode mode, BSize size) const
{ {
ASSERT(mode == kSelected || mode == kNormalIcon); ASSERT(mode == kSelected || mode == kNormalIcon);
// for now only // for now only
if (mode == kNormalIcon) { if (mode == kNormalIcon) {
return size == B_MINI_ICON ? fMiniIcon != NULL return size == IconCache::sMiniIconSize ? fMiniIcon != NULL
: fLargeIcon != NULL : fLargeIcon != NULL
&& fLargeIcon->Bounds().IntegerWidth() + 1 == size; && fLargeIcon->Bounds().Size() == size;
} else if (mode == kSelected) { } else if (mode == kSelected) {
return size == B_MINI_ICON ? fHighlightedMiniIcon != NULL return size == IconCache::sMiniIconSize ? fHighlightedMiniIcon != NULL
: fHighlightedLargeIcon != NULL : fHighlightedLargeIcon != NULL
&& fHighlightedLargeIcon->Bounds().IntegerWidth() + 1 == size; && fHighlightedLargeIcon->Bounds().Size() == size;
} }
return false; return false;
@@ -191,18 +203,18 @@ IconCacheEntry::HaveIconBitmap(IconDrawMode mode, icon_size size) const
BBitmap* BBitmap*
IconCacheEntry::IconForMode(IconDrawMode mode, icon_size size) const IconCacheEntry::IconForMode(IconDrawMode mode, BSize size) const
{ {
ASSERT(mode == kSelected || mode == kNormalIcon); ASSERT(mode == kSelected || mode == kNormalIcon);
// for now only // for now only
if (mode == kNormalIcon) { if (mode == kNormalIcon) {
if (size == B_MINI_ICON) if (size == IconCache::sMiniIconSize)
return fMiniIcon; return fMiniIcon;
else else
return fLargeIcon; return fLargeIcon;
} else if (mode == kSelected) { } else if (mode == kSelected) {
if (size == B_MINI_ICON) if (size == IconCache::sMiniIconSize)
return fHighlightedMiniIcon; return fHighlightedMiniIcon;
else else
return fHighlightedLargeIcon; return fHighlightedLargeIcon;
@@ -214,7 +226,7 @@ IconCacheEntry::IconForMode(IconDrawMode mode, icon_size size) const
bool bool
IconCacheEntry::IconHitTest(BPoint where, IconDrawMode mode, IconCacheEntry::IconHitTest(BPoint where, IconDrawMode mode,
icon_size size) const BSize size) const
{ {
ASSERT(where.x < size && where.y < size); ASSERT(where.x < size && where.y < size);
BBitmap* bitmap = IconForMode(mode, size); BBitmap* bitmap = IconForMode(mode, size);
@@ -236,7 +248,7 @@ IconCacheEntry::IconHitTest(BPoint where, IconDrawMode mode,
+ floorf(where.x) * 4 + 3)) > 20; + floorf(where.x) * 4 + 3)) > 20;
case B_CMAP8: case B_CMAP8:
return *(bits + (int32)(floorf(where.y) * size + where.x)) return *(bits + (int32)(floorf(where.y) * icon_size_for(size) + where.x))
!= B_TRANSPARENT_8_BIT; != B_TRANSPARENT_8_BIT;
default: default:
@@ -248,7 +260,7 @@ IconCacheEntry::IconHitTest(BPoint where, IconDrawMode mode,
BBitmap* BBitmap*
IconCacheEntry::ConstructBitmap(BBitmap* constructFrom, IconCacheEntry::ConstructBitmap(BBitmap* constructFrom,
IconDrawMode requestedMode, IconDrawMode constructFromMode, IconDrawMode requestedMode, IconDrawMode constructFromMode,
icon_size size, LazyBitmapAllocator* lazyBitmap) BSize size, LazyBitmapAllocator* lazyBitmap)
{ {
ASSERT(requestedMode == kSelected && constructFromMode == kNormalIcon); ASSERT(requestedMode == kSelected && constructFromMode == kNormalIcon);
// for now // for now
@@ -263,10 +275,10 @@ IconCacheEntry::ConstructBitmap(BBitmap* constructFrom,
BBitmap* BBitmap*
IconCacheEntry::ConstructBitmap(IconDrawMode requestedMode, icon_size size, IconCacheEntry::ConstructBitmap(IconDrawMode requestedMode, BSize size,
LazyBitmapAllocator* lazyBitmap) LazyBitmapAllocator* lazyBitmap)
{ {
BBitmap* source = (size == B_MINI_ICON) ? fMiniIcon : fLargeIcon; BBitmap* source = (size == IconCache::sMiniIconSize) ? fMiniIcon : fLargeIcon;
ASSERT(source != NULL); ASSERT(source != NULL);
return ConstructBitmap(source, requestedMode, kNormalIcon, size, return ConstructBitmap(source, requestedMode, kNormalIcon, size,
@@ -276,7 +288,7 @@ IconCacheEntry::ConstructBitmap(IconDrawMode requestedMode, icon_size size,
bool bool
IconCacheEntry::AlternateModeForIconConstructing(IconDrawMode requestedMode, IconCacheEntry::AlternateModeForIconConstructing(IconDrawMode requestedMode,
IconDrawMode &alternate, icon_size) IconDrawMode &alternate, BSize)
{ {
if ((requestedMode & kSelected) != 0) { if ((requestedMode & kSelected) != 0) {
// for now // for now
@@ -289,17 +301,16 @@ IconCacheEntry::AlternateModeForIconConstructing(IconDrawMode requestedMode,
void void
IconCacheEntry::SetIcon(BBitmap* bitmap, IconDrawMode mode, icon_size size, IconCacheEntry::SetIcon(BBitmap* bitmap, IconDrawMode mode, BSize size)
bool /*create*/)
{ {
BBitmap** icon = NULL; BBitmap** icon = NULL;
if (mode == kNormalIcon) { if (mode == kNormalIcon) {
if (size == B_MINI_ICON) if (size == IconCache::sMiniIconSize)
icon = &fMiniIcon; icon = &fMiniIcon;
else else
icon = &fLargeIcon; icon = &fLargeIcon;
} else if (mode == kSelectedIcon) { } else if (mode == kSelectedIcon) {
if (size == B_MINI_ICON) if (size == IconCache::sMiniIconSize)
icon = &fHighlightedMiniIcon; icon = &fHighlightedMiniIcon;
else else
icon = &fHighlightedLargeIcon; icon = &fHighlightedLargeIcon;
@@ -318,6 +329,8 @@ IconCache::IconCache()
fInitHighlightTable(true) fInitHighlightTable(true)
{ {
InitHighlightTable(); InitHighlightTable();
sMiniIconSize = be_control_look->ComposeIconSize(B_MINI_ICON);
} }
@@ -332,7 +345,7 @@ IconCache::IconCache()
IconCacheEntry* IconCacheEntry*
IconCache::GetIconForPreferredApp(const char* fileTypeSignature, IconCache::GetIconForPreferredApp(const char* fileTypeSignature,
const char* preferredApp, IconDrawMode mode, icon_size size, const char* preferredApp, IconDrawMode mode, BSize size,
LazyBitmapAllocator* lazyBitmap, IconCacheEntry* entry) LazyBitmapAllocator* lazyBitmap, IconCacheEntry* entry)
{ {
ASSERT(fSharedCache.IsLocked()); ASSERT(fSharedCache.IsLocked());
@@ -362,7 +375,7 @@ IconCache::GetIconForPreferredApp(const char* fileTypeSignature,
BString signature(fileTypeSignature); BString signature(fileTypeSignature);
signature.ToLower(); signature.ToLower();
if (preferredAppType.GetIconForType(signature.String(), if (preferredAppType.GetIconForType(signature.String(),
lazyBitmap->Get(), size) != B_OK) { lazyBitmap->Get(), icon_size_for(size)) != B_OK) {
return NULL; return NULL;
} }
@@ -389,7 +402,7 @@ IconCache::GetIconForPreferredApp(const char* fileTypeSignature,
IconCacheEntry* IconCacheEntry*
IconCache::GetIconFromMetaMime(const char* fileType, IconDrawMode mode, IconCache::GetIconFromMetaMime(const char* fileType, IconDrawMode mode,
icon_size size, LazyBitmapAllocator* lazyBitmap, IconCacheEntry* entry) BSize size, LazyBitmapAllocator* lazyBitmap, IconCacheEntry* entry)
{ {
ASSERT(fSharedCache.IsLocked()); ASSERT(fSharedCache.IsLocked());
@@ -409,7 +422,7 @@ IconCache::GetIconFromMetaMime(const char* fileType, IconDrawMode mode,
BMimeType mime(fileType); BMimeType mime(fileType);
// try getting the icon directly from the metamime // try getting the icon directly from the metamime
if (mime.GetIcon(lazyBitmap->Get(), size) != B_OK) { if (mime.GetIcon(lazyBitmap->Get(), icon_size_for(size)) != B_OK) {
// try getting it from the preferred app of this type // try getting it from the preferred app of this type
char preferredAppSig[B_MIME_TYPE_LENGTH]; char preferredAppSig[B_MIME_TYPE_LENGTH];
if (mime.GetPreferredApp(preferredAppSig) != B_OK) if (mime.GetPreferredApp(preferredAppSig) != B_OK)
@@ -472,7 +485,7 @@ IconCache::GetIconFromMetaMime(const char* fileType, IconDrawMode mode,
IconCacheEntry* IconCacheEntry*
IconCache::GetIconFromFileTypes(ModelNodeLazyOpener* modelOpener, IconCache::GetIconFromFileTypes(ModelNodeLazyOpener* modelOpener,
IconSource &source, IconDrawMode mode, icon_size size, IconSource &source, IconDrawMode mode, BSize size,
LazyBitmapAllocator* lazyBitmap, IconCacheEntry* entry) LazyBitmapAllocator* lazyBitmap, IconCacheEntry* entry)
{ {
ASSERT(fSharedCache.IsLocked()); ASSERT(fSharedCache.IsLocked());
@@ -564,7 +577,7 @@ IconCache::GetVolumeIcon(AutoLock<SimpleIconCache>*nodeCacheLocker,
AutoLock<SimpleIconCache>* sharedCacheLocker, AutoLock<SimpleIconCache>* sharedCacheLocker,
AutoLock<SimpleIconCache>** resultingOpenCache, AutoLock<SimpleIconCache>** resultingOpenCache,
Model* model, IconSource &source, Model* model, IconSource &source,
IconDrawMode mode, icon_size size, LazyBitmapAllocator* lazyBitmap) IconDrawMode mode, BSize size, LazyBitmapAllocator* lazyBitmap)
{ {
*resultingOpenCache = nodeCacheLocker; *resultingOpenCache = nodeCacheLocker;
nodeCacheLocker->Lock(); nodeCacheLocker->Lock();
@@ -597,7 +610,8 @@ IconCache::GetVolumeIcon(AutoLock<SimpleIconCache>*nodeCacheLocker,
if (volume.IsShared()) { if (volume.IsShared()) {
// check if it's a network share and give it a special icon // check if it's a network share and give it a special icon
BBitmap* bitmap = lazyBitmap->Get(); BBitmap* bitmap = lazyBitmap->Get();
GetTrackerResources()->GetIconResource(R_ShareIcon, size, bitmap); GetTrackerResources()->GetIconResource(R_ShareIcon,
icon_size_for(size), bitmap);
if (entry == NULL) { if (entry == NULL) {
PRINT_ADD_ITEM( PRINT_ADD_ITEM(
("File %s; Line %d # adding entry for model %s\n", ("File %s; Line %d # adding entry for model %s\n",
@@ -605,7 +619,7 @@ IconCache::GetVolumeIcon(AutoLock<SimpleIconCache>*nodeCacheLocker,
entry = fNodeCache.AddItem(model->NodeRef()); entry = fNodeCache.AddItem(model->NodeRef());
} }
entry->SetIcon(lazyBitmap->Adopt(), kNormalIcon, size); entry->SetIcon(lazyBitmap->Adopt(), kNormalIcon, size);
} else if (volume.GetIcon(lazyBitmap->Get(), size) == B_OK) { } else if (volume.GetIcon(lazyBitmap->Get(), icon_size_for(size)) == B_OK) {
// ask the device for an icon // ask the device for an icon
BBitmap* bitmap = lazyBitmap->Adopt(); BBitmap* bitmap = lazyBitmap->Adopt();
ASSERT(bitmap != NULL); ASSERT(bitmap != NULL);
@@ -642,7 +656,7 @@ IconCache::GetRootIcon(AutoLock<SimpleIconCache>*,
AutoLock<SimpleIconCache>* sharedCacheLocker, AutoLock<SimpleIconCache>* sharedCacheLocker,
AutoLock<SimpleIconCache>** resultingOpenCache, AutoLock<SimpleIconCache>** resultingOpenCache,
Model*, IconSource &source, IconDrawMode mode, Model*, IconSource &source, IconDrawMode mode,
icon_size size, LazyBitmapAllocator* lazyBitmap) BSize size, LazyBitmapAllocator* lazyBitmap)
{ {
*resultingOpenCache = sharedCacheLocker; *resultingOpenCache = sharedCacheLocker;
(*resultingOpenCache)->Lock(); (*resultingOpenCache)->Lock();
@@ -657,7 +671,7 @@ IconCacheEntry*
IconCache::GetWellKnownIcon(AutoLock<SimpleIconCache>*, IconCache::GetWellKnownIcon(AutoLock<SimpleIconCache>*,
AutoLock<SimpleIconCache>* sharedCacheLocker, AutoLock<SimpleIconCache>* sharedCacheLocker,
AutoLock<SimpleIconCache>** resultingOpenCache, AutoLock<SimpleIconCache>** resultingOpenCache,
Model* model, IconSource &source, IconDrawMode mode, icon_size size, Model* model, IconSource &source, IconDrawMode mode, BSize size,
LazyBitmapAllocator* lazyBitmap) LazyBitmapAllocator* lazyBitmap)
{ {
const WellKnowEntryList::WellKnownEntry* wellKnownEntry const WellKnowEntryList::WellKnownEntry* wellKnownEntry
@@ -749,7 +763,8 @@ IconCache::GetWellKnownIcon(AutoLock<SimpleIconCache>*,
entry = fSharedCache.AddItem(type.String()); entry = fSharedCache.AddItem(type.String());
BBitmap* bitmap = lazyBitmap->Get(); BBitmap* bitmap = lazyBitmap->Get();
GetTrackerResources()->GetIconResource(resourceId, size, bitmap); GetTrackerResources()->GetIconResource(resourceId,
icon_size_for(size), bitmap);
entry->SetIcon(lazyBitmap->Adopt(), kNormalIcon, size); entry->SetIcon(lazyBitmap->Adopt(), kNormalIcon, size);
} }
@@ -770,7 +785,7 @@ IconCache::GetNodeIcon(ModelNodeLazyOpener* modelOpener,
AutoLock<SimpleIconCache>* nodeCacheLocker, AutoLock<SimpleIconCache>* nodeCacheLocker,
AutoLock<SimpleIconCache>** resultingOpenCache, AutoLock<SimpleIconCache>** resultingOpenCache,
Model* model, IconSource& source, Model* model, IconSource& source,
IconDrawMode mode, icon_size size, IconDrawMode mode, BSize size,
LazyBitmapAllocator* lazyBitmap, IconCacheEntry* entry, bool permanent) LazyBitmapAllocator* lazyBitmap, IconCacheEntry* entry, bool permanent)
{ {
*resultingOpenCache = nodeCacheLocker; *resultingOpenCache = nodeCacheLocker;
@@ -791,11 +806,13 @@ IconCache::GetNodeIcon(ModelNodeLazyOpener* modelOpener,
status_t result = B_ERROR; status_t result = B_ERROR;
if (model->IsExecutable() if (model->IsExecutable()
&& (file = dynamic_cast<BFile*>(model->Node())) != NULL) { && (file = dynamic_cast<BFile*>(model->Node())) != NULL) {
result = GetAppIconFromAttr(file, lazyBitmap->Get(), size); result = GetAppIconFromAttr(file, lazyBitmap->Get(), icon_size_for(size));
} else { } else {
result = GetThumbnailFromAttr(model, lazyBitmap->Get(), size); result = GetThumbnailFromAttr(model, lazyBitmap->Get(), size);
if (result != B_OK && result != B_BUSY) if (result != B_OK && result != B_BUSY) {
result = GetFileIconFromAttr(model->Node(), lazyBitmap->Get(), size); result = GetFileIconFromAttr(model->Node(), lazyBitmap->Get(),
icon_size_for(size));
}
} }
if (result == B_OK) { if (result == B_OK) {
@@ -832,7 +849,7 @@ IconCacheEntry*
IconCache::GetGenericIcon(AutoLock<SimpleIconCache>* sharedCacheLocker, IconCache::GetGenericIcon(AutoLock<SimpleIconCache>* sharedCacheLocker,
AutoLock<SimpleIconCache>** resultingOpenCache, AutoLock<SimpleIconCache>** resultingOpenCache,
Model* model, IconSource &source, Model* model, IconSource &source,
IconDrawMode mode, icon_size size, IconDrawMode mode, BSize size,
LazyBitmapAllocator* lazyBitmap, IconCacheEntry* entry) LazyBitmapAllocator* lazyBitmap, IconCacheEntry* entry)
{ {
*resultingOpenCache = sharedCacheLocker; *resultingOpenCache = sharedCacheLocker;
@@ -863,7 +880,7 @@ IconCache::GetGenericIcon(AutoLock<SimpleIconCache>* sharedCacheLocker,
IconCacheEntry* IconCacheEntry*
IconCache::GetFallbackIcon(AutoLock<SimpleIconCache>* sharedCacheLocker, IconCache::GetFallbackIcon(AutoLock<SimpleIconCache>* sharedCacheLocker,
AutoLock<SimpleIconCache>** resultingOpenCache, AutoLock<SimpleIconCache>** resultingOpenCache,
Model* model, IconDrawMode mode, icon_size size, Model* model, IconDrawMode mode, BSize size,
LazyBitmapAllocator* lazyBitmap, IconCacheEntry* entry) LazyBitmapAllocator* lazyBitmap, IconCacheEntry* entry)
{ {
*resultingOpenCache = sharedCacheLocker; *resultingOpenCache = sharedCacheLocker;
@@ -873,7 +890,8 @@ IconCache::GetFallbackIcon(AutoLock<SimpleIconCache>* sharedCacheLocker,
model->PreferredAppSignature()); model->PreferredAppSignature());
BBitmap* bitmap = lazyBitmap->Get(); BBitmap* bitmap = lazyBitmap->Get();
GetTrackerResources()->GetIconResource(R_FileIcon, size, bitmap); GetTrackerResources()->GetIconResource(R_FileIcon,
icon_size_for(size), bitmap);
entry->SetIcon(lazyBitmap->Adopt(), kNormalIcon, size); entry->SetIcon(lazyBitmap->Adopt(), kNormalIcon, size);
if (mode != kNormalIcon) { if (mode != kNormalIcon) {
@@ -891,7 +909,7 @@ IconCacheEntry*
IconCache::Preload(AutoLock<SimpleIconCache>* nodeCacheLocker, IconCache::Preload(AutoLock<SimpleIconCache>* nodeCacheLocker,
AutoLock<SimpleIconCache>* sharedCacheLocker, AutoLock<SimpleIconCache>* sharedCacheLocker,
AutoLock<SimpleIconCache>** resultingCache, AutoLock<SimpleIconCache>** resultingCache,
Model* model, IconDrawMode mode, icon_size size, Model* model, IconDrawMode mode, BSize size,
bool permanent) bool permanent)
{ {
IconCacheEntry* entry = NULL; IconCacheEntry* entry = NULL;
@@ -1078,7 +1096,7 @@ IconCache::Preload(AutoLock<SimpleIconCache>* nodeCacheLocker,
void void
IconCache::Draw(Model* model, BView* view, BPoint where, IconDrawMode mode, IconCache::Draw(Model* model, BView* view, BPoint where, IconDrawMode mode,
icon_size size, bool async) BSize size, bool async)
{ {
// the following does not actually lock the caches, we are using the // the following does not actually lock the caches, we are using the
// lockLater mode; we will decide which of the two to lock down depending // lockLater mode; we will decide which of the two to lock down depending
@@ -1108,7 +1126,7 @@ IconCache::Draw(Model* model, BView* view, BPoint where, IconDrawMode mode,
void void
IconCache::SyncDraw(Model* model, BView* view, BPoint where, IconCache::SyncDraw(Model* model, BView* view, BPoint where,
IconDrawMode mode, icon_size size, IconDrawMode mode, BSize size,
void (*blitFunc)(BView*, BPoint, BBitmap*, void*), void (*blitFunc)(BView*, BPoint, BBitmap*, void*),
void* passThruState) void* passThruState)
{ {
@@ -1130,7 +1148,7 @@ IconCache::SyncDraw(Model* model, BView* view, BPoint where,
void void
IconCache::Preload(Model* model, IconDrawMode mode, icon_size size, IconCache::Preload(Model* model, IconDrawMode mode, BSize size,
bool permanent) bool permanent)
{ {
AutoLock<SimpleIconCache> nodeCacheLocker(&fNodeCache, false); AutoLock<SimpleIconCache> nodeCacheLocker(&fNodeCache, false);
@@ -1142,7 +1160,7 @@ IconCache::Preload(Model* model, IconDrawMode mode, icon_size size,
status_t status_t
IconCache::Preload(const char* fileType, IconDrawMode mode, icon_size size) IconCache::Preload(const char* fileType, IconDrawMode mode, BSize size)
{ {
AutoLock<SimpleIconCache> sharedCacheLocker(&fSharedCache); AutoLock<SimpleIconCache> sharedCacheLocker(&fSharedCache);
LazyBitmapAllocator lazyBitmap(size); LazyBitmapAllocator lazyBitmap(size);
@@ -1160,7 +1178,7 @@ IconCache::Preload(const char* fileType, IconDrawMode mode, icon_size size)
return B_OK; return B_OK;
// try getting the icon directly from the metamime // try getting the icon directly from the metamime
result = mime.GetIcon(lazyBitmap.Get(), size); result = mime.GetIcon(lazyBitmap.Get(), icon_size_for(size));
if (result != B_OK) if (result != B_OK)
return result; return result;
@@ -1240,7 +1258,7 @@ IconCache::IconChanged(const char* mimeType, const char* appSignature)
BBitmap* BBitmap*
IconCache::MakeSelectedIcon(const BBitmap* normal, icon_size size, IconCache::MakeSelectedIcon(const BBitmap* normal, BSize size,
LazyBitmapAllocator* lazyBitmap) LazyBitmapAllocator* lazyBitmap)
{ {
return MakeTransformedIcon(normal, size, fHighlightTable, lazyBitmap); return MakeTransformedIcon(normal, size, fHighlightTable, lazyBitmap);
@@ -1291,7 +1309,7 @@ IconCache::InitHighlightTable()
BBitmap* BBitmap*
IconCache::MakeTransformedIcon(const BBitmap* source, icon_size /*size*/, IconCache::MakeTransformedIcon(const BBitmap* source, BSize /*size*/,
int32 colorTransformTable[], LazyBitmapAllocator* lazyBitmap) int32 colorTransformTable[], LazyBitmapAllocator* lazyBitmap)
{ {
if (fInitHighlightTable) if (fInitHighlightTable)
@@ -1305,8 +1323,7 @@ IconCache::MakeTransformedIcon(const BBitmap* source, icon_size /*size*/,
// && result->Bounds() == source->Bounds()); // && result->Bounds() == source->Bounds());
if (result->ColorSpace() != source->ColorSpace() if (result->ColorSpace() != source->ColorSpace()
|| result->Bounds() != source->Bounds()) { || result->Bounds() != source->Bounds()) {
printf("IconCache::MakeTransformedIcon() - " printf("IconCache::MakeTransformedIcon() - bitmap format mismatch!\n");
"bitmap format mismatch!\n");
return NULL; return NULL;
} }
@@ -1355,7 +1372,7 @@ IconCache::MakeTransformedIcon(const BBitmap* source, icon_size /*size*/,
bool bool
IconCache::IconHitTest(BPoint where, const Model* model, IconDrawMode mode, IconCache::IconHitTest(BPoint where, const Model* model, IconDrawMode mode,
icon_size size) BSize size)
{ {
AutoLock<SimpleIconCache> nodeCacheLocker(&fNodeCache, false); AutoLock<SimpleIconCache> nodeCacheLocker(&fNodeCache, false);
AutoLock<SimpleIconCache> sharedCacheLocker(&fSharedCache, false); AutoLock<SimpleIconCache> sharedCacheLocker(&fSharedCache, false);
@@ -1417,7 +1434,7 @@ SharedIconCache::SharedIconCache()
void void
SharedIconCache::Draw(IconCacheEntry* entry, BView* view, BPoint where, SharedIconCache::Draw(IconCacheEntry* entry, BView* view, BPoint where,
IconDrawMode mode, icon_size size, bool async) IconDrawMode mode, BSize size, bool async)
{ {
((SharedCacheEntry*)entry)->Draw(view, where, mode, size, async); ((SharedCacheEntry*)entry)->Draw(view, where, mode, size, async);
} }
@@ -1425,7 +1442,7 @@ SharedIconCache::Draw(IconCacheEntry* entry, BView* view, BPoint where,
void void
SharedIconCache::Draw(IconCacheEntry* entry, BView* view, BPoint where, SharedIconCache::Draw(IconCacheEntry* entry, BView* view, BPoint where,
IconDrawMode mode, icon_size size, void (*blitFunc)(BView*, BPoint, IconDrawMode mode, BSize size, void (*blitFunc)(BView*, BPoint,
BBitmap*, void*), void* passThruState) BBitmap*, void*), void* passThruState)
{ {
((SharedCacheEntry*)entry)->Draw(view, where, mode, size, ((SharedCacheEntry*)entry)->Draw(view, where, mode, size,
@@ -1512,7 +1529,7 @@ SharedCacheEntry::SharedCacheEntry(const char* fileType,
void void
SharedCacheEntry::Draw(BView* view, BPoint where, IconDrawMode mode, SharedCacheEntry::Draw(BView* view, BPoint where, IconDrawMode mode,
icon_size size, bool async) BSize size, bool async)
{ {
BBitmap* bitmap = IconForMode(mode, size); BBitmap* bitmap = IconForMode(mode, size);
ASSERT(bitmap != NULL); ASSERT(bitmap != NULL);
@@ -1538,7 +1555,7 @@ SharedCacheEntry::Draw(BView* view, BPoint where, IconDrawMode mode,
void void
SharedCacheEntry::Draw(BView* view, BPoint where, IconDrawMode mode, SharedCacheEntry::Draw(BView* view, BPoint where, IconDrawMode mode,
icon_size size, void (*blitFunc)(BView*, BPoint, BBitmap*, void*), BSize size, void (*blitFunc)(BView*, BPoint, BBitmap*, void*),
void* passThruState) void* passThruState)
{ {
BBitmap* bitmap = IconForMode(mode, size); BBitmap* bitmap = IconForMode(mode, size);
@@ -1598,7 +1615,7 @@ NodeCacheEntry::NodeCacheEntry(const node_ref* node, bool permanent)
void void
NodeCacheEntry::Draw(BView* view, BPoint where, IconDrawMode mode, NodeCacheEntry::Draw(BView* view, BPoint where, IconDrawMode mode,
icon_size size, bool async) BSize size, bool async)
{ {
BBitmap* bitmap = IconForMode(mode, size); BBitmap* bitmap = IconForMode(mode, size);
if (bitmap == NULL) if (bitmap == NULL)
@@ -1627,7 +1644,7 @@ NodeCacheEntry::Draw(BView* view, BPoint where, IconDrawMode mode,
void void
NodeCacheEntry::Draw(BView* view, BPoint where, IconDrawMode mode, NodeCacheEntry::Draw(BView* view, BPoint where, IconDrawMode mode,
icon_size size, void (*blitFunc)(BView*, BPoint, BBitmap*, void*), BSize size, void (*blitFunc)(BView*, BPoint, BBitmap*, void*),
void* passThruState) void* passThruState)
{ {
BBitmap* bitmap = IconForMode(mode, size); BBitmap* bitmap = IconForMode(mode, size);
@@ -1687,7 +1704,7 @@ NodeIconCache::NodeIconCache()
void void
NodeIconCache::Draw(IconCacheEntry* entry, BView* view, BPoint where, NodeIconCache::Draw(IconCacheEntry* entry, BView* view, BPoint where,
IconDrawMode mode, icon_size size, bool async) IconDrawMode mode, BSize size, bool async)
{ {
((NodeCacheEntry*)entry)->Draw(view, where, mode, size, async); ((NodeCacheEntry*)entry)->Draw(view, where, mode, size, async);
} }
@@ -1695,7 +1712,7 @@ NodeIconCache::Draw(IconCacheEntry* entry, BView* view, BPoint where,
void void
NodeIconCache::Draw(IconCacheEntry* entry, BView* view, BPoint where, NodeIconCache::Draw(IconCacheEntry* entry, BView* view, BPoint where,
IconDrawMode mode, icon_size size, IconDrawMode mode, BSize size,
void (*blitFunc)(BView*, BPoint, BBitmap*, void*), void* passThruState) void (*blitFunc)(BView*, BPoint, BBitmap*, void*), void* passThruState)
{ {
((NodeCacheEntry*)entry)->Draw(view, where, mode, size, ((NodeCacheEntry*)entry)->Draw(view, where, mode, size,
@@ -1786,7 +1803,7 @@ SimpleIconCache::SimpleIconCache(const char* name)
void void
SimpleIconCache::Draw(IconCacheEntry*, BView*, BPoint, IconDrawMode, SimpleIconCache::Draw(IconCacheEntry*, BView*, BPoint, IconDrawMode,
icon_size, bool) BSize, bool)
{ {
TRESPASS(); TRESPASS();
// pure virtual, do nothing // pure virtual, do nothing
@@ -1795,7 +1812,7 @@ SimpleIconCache::Draw(IconCacheEntry*, BView*, BPoint, IconDrawMode,
void void
SimpleIconCache::Draw(IconCacheEntry*, BView*, BPoint, IconDrawMode, SimpleIconCache::Draw(IconCacheEntry*, BView*, BPoint, IconDrawMode,
icon_size, void(*)(BView*, BPoint, BBitmap*, void*), void*) BSize, void(*)(BView*, BPoint, BBitmap*, void*), void*)
{ {
TRESPASS(); TRESPASS();
// pure virtual, do nothing // pure virtual, do nothing
@@ -1826,7 +1843,7 @@ SimpleIconCache::IsLocked() const
// #pragma mark - LazyBitmapAllocator // #pragma mark - LazyBitmapAllocator
LazyBitmapAllocator::LazyBitmapAllocator(icon_size size, LazyBitmapAllocator::LazyBitmapAllocator(BSize size,
color_space colorSpace, bool preallocate) color_space colorSpace, bool preallocate)
: :
fBitmap(NULL), fBitmap(NULL),
@@ -1848,7 +1865,7 @@ BBitmap*
LazyBitmapAllocator::Get() LazyBitmapAllocator::Get()
{ {
if (fBitmap == NULL) if (fBitmap == NULL)
fBitmap = new BBitmap(BRect(0, 0, fSize - 1, fSize - 1), fColorSpace); fBitmap = new BBitmap(BRect(BPoint(0, 0), fSize), fColorSpace);
return fBitmap; return fBitmap;
} }
+40 -39
View File
@@ -161,21 +161,20 @@ public:
IconCacheEntry* entry); IconCacheEntry* entry);
IconCacheEntry* ResolveIfAlias(const SharedIconCache* sharedCache); IconCacheEntry* ResolveIfAlias(const SharedIconCache* sharedCache);
void SetIcon(BBitmap* bitmap, IconDrawMode mode, icon_size size, void SetIcon(BBitmap* bitmap, IconDrawMode mode, BSize size);
bool create = false);
bool HaveIconBitmap(IconDrawMode mode, icon_size size) const; bool HaveIconBitmap(IconDrawMode mode, BSize size) const;
bool CanConstructBitmap(IconDrawMode mode, icon_size size) const; bool CanConstructBitmap(IconDrawMode mode, BSize size) const;
static bool AlternateModeForIconConstructing(IconDrawMode requestedMode, static bool AlternateModeForIconConstructing(IconDrawMode requestedMode,
IconDrawMode &alternate, icon_size size); IconDrawMode &alternate, BSize size);
BBitmap* ConstructBitmap(BBitmap* constructFrom, BBitmap* ConstructBitmap(BBitmap* constructFrom,
IconDrawMode requestedMode, IconDrawMode constructFromMode, IconDrawMode requestedMode, IconDrawMode constructFromMode,
icon_size size, LazyBitmapAllocator*); BSize size, LazyBitmapAllocator*);
BBitmap* ConstructBitmap(IconDrawMode requestedMode, icon_size size, BBitmap* ConstructBitmap(IconDrawMode requestedMode, BSize size,
LazyBitmapAllocator*); LazyBitmapAllocator*);
// same as above, always uses normal icon as source // same as above, always uses normal icon as source
bool IconHitTest(BPoint, IconDrawMode, icon_size) const; bool IconHitTest(BPoint, IconDrawMode, BSize) const;
// given a point, returns true if a non-transparent pixel was hit // given a point, returns true if a non-transparent pixel was hit
void RetireIcons(BObjectList<BBitmap>* retiredBitmapList); void RetireIcons(BObjectList<BBitmap>* retiredBitmapList);
@@ -188,8 +187,8 @@ public:
// while we are drawing them, shouldn't be a practical problem // while we are drawing them, shouldn't be a practical problem
protected: protected:
BBitmap* IconForMode(IconDrawMode mode, icon_size size) const; BBitmap* IconForMode(IconDrawMode mode, BSize size) const;
void SetIconForMode(BBitmap* bitmap, IconDrawMode mode, icon_size size); void SetIconForMode(BBitmap* bitmap, IconDrawMode mode, BSize size);
// list of most common icons // list of most common icons
BBitmap* fLargeIcon; BBitmap* fLargeIcon;
@@ -212,9 +211,9 @@ public:
virtual ~SimpleIconCache() {} virtual ~SimpleIconCache() {}
virtual void Draw(IconCacheEntry*, BView*, BPoint, IconDrawMode mode, virtual void Draw(IconCacheEntry*, BView*, BPoint, IconDrawMode mode,
icon_size size, bool async = false) = 0; BSize size, bool async = false) = 0;
virtual void Draw(IconCacheEntry*, BView*, BPoint, IconDrawMode, virtual void Draw(IconCacheEntry*, BView*, BPoint, IconDrawMode,
icon_size, void (*)(BView*, BPoint, BBitmap*, void*), BSize, void (*)(BView*, BPoint, BBitmap*, void*),
void* = NULL) = 0; void* = NULL) = 0;
bool Lock(); bool Lock();
@@ -231,10 +230,10 @@ public:
SharedCacheEntry(); SharedCacheEntry();
SharedCacheEntry(const char* fileType, const char* appSignature = 0); SharedCacheEntry(const char* fileType, const char* appSignature = 0);
void Draw(BView*, BPoint, IconDrawMode mode, icon_size size, void Draw(BView*, BPoint, IconDrawMode mode, BSize size,
bool async = false); bool async = false);
void Draw(BView*, BPoint, IconDrawMode, icon_size, void Draw(BView*, BPoint, IconDrawMode, BSize,
void (*)(BView*, BPoint, BBitmap*, void*), void* = NULL); void (*)(BView*, BPoint, BBitmap*, void*), void* = NULL);
const char* FileType() const; const char* FileType() const;
@@ -270,9 +269,9 @@ public:
SharedIconCache(); SharedIconCache();
virtual void Draw(IconCacheEntry*, BView*, BPoint, IconDrawMode mode, virtual void Draw(IconCacheEntry*, BView*, BPoint, IconDrawMode mode,
icon_size size, bool async = false); BSize size, bool async = false);
virtual void Draw(IconCacheEntry*, BView*, BPoint, IconDrawMode, virtual void Draw(IconCacheEntry*, BView*, BPoint, IconDrawMode,
icon_size, void (*)(BView*, BPoint, BBitmap*, void*), void* = NULL); BSize, void (*)(BView*, BPoint, BBitmap*, void*), void* = NULL);
SharedCacheEntry* FindItem(const char* fileType, SharedCacheEntry* FindItem(const char* fileType,
const char* appSignature = 0) const; const char* appSignature = 0) const;
@@ -301,10 +300,10 @@ class NodeCacheEntry : public IconCacheEntry {
public: public:
NodeCacheEntry(bool permanent = false); NodeCacheEntry(bool permanent = false);
NodeCacheEntry(const node_ref*, bool permanent = false); NodeCacheEntry(const node_ref*, bool permanent = false);
void Draw(BView*, BPoint, IconDrawMode mode, icon_size size, void Draw(BView*, BPoint, IconDrawMode mode, BSize size,
bool async = false); bool async = false);
void Draw(BView*, BPoint, IconDrawMode, icon_size, void Draw(BView*, BPoint, IconDrawMode, BSize,
void (*)(BView*, BPoint, BBitmap*, void*), void* = NULL); void (*)(BView*, BPoint, BBitmap*, void*), void* = NULL);
const node_ref* Node() const; const node_ref* Node() const;
@@ -337,10 +336,10 @@ public:
NodeIconCache(); NodeIconCache();
virtual void Draw(IconCacheEntry*, BView*, BPoint, IconDrawMode, virtual void Draw(IconCacheEntry*, BView*, BPoint, IconDrawMode,
icon_size, bool async = false); BSize, bool async = false);
virtual void Draw(IconCacheEntry*, BView*, BPoint, IconDrawMode, virtual void Draw(IconCacheEntry*, BView*, BPoint, IconDrawMode,
icon_size, void (*)(BView*, BPoint, BBitmap*, void*), void* = 0); BSize, void (*)(BView*, BPoint, BBitmap*, void*), void* = 0);
NodeCacheEntry* FindItem(const node_ref*) const; NodeCacheEntry* FindItem(const node_ref*) const;
NodeCacheEntry* AddItem(const node_ref*, bool permanent = false); NodeCacheEntry* AddItem(const node_ref*, bool permanent = false);
@@ -368,12 +367,12 @@ public:
IconCache(); IconCache();
void Draw(Model*, BView*, BPoint where, IconDrawMode mode, void Draw(Model*, BView*, BPoint where, IconDrawMode mode,
icon_size size, bool async = false); BSize size, bool async = false);
// draw an icon for a model, load the icon from the appropriate // draw an icon for a model, load the icon from the appropriate
// location if not cached already // location if not cached already
void SyncDraw(Model*, BView*, BPoint, IconDrawMode, void SyncDraw(Model*, BView*, BPoint, IconDrawMode,
icon_size, void (*)(BView*, BPoint, BBitmap*, void*), BSize, void (*)(BView*, BPoint, BBitmap*, void*),
void* passThruState = 0); void* passThruState = 0);
// draw an icon for a model, load the icon from the appropriate // draw an icon for a model, load the icon from the appropriate
// location if not cached already; only works for sync draws, // location if not cached already; only works for sync draws,
@@ -382,9 +381,9 @@ public:
// preload calls used to ensure successive cache hit for the respective // preload calls used to ensure successive cache hit for the respective
// icon, used for common tracker types, etc; Not calling these should only // icon, used for common tracker types, etc; Not calling these should only
// cause a slowdown // cause a slowdown
void Preload(Model*, IconDrawMode mode, icon_size size, void Preload(Model*, IconDrawMode mode, BSize size,
bool permanent = false); bool permanent = false);
status_t Preload(const char* mimeType, IconDrawMode mode, icon_size size); status_t Preload(const char* mimeType, IconDrawMode mode, BSize size);
void Deleting(const Model*); void Deleting(const Model*);
// hook to manage unloading icons for nodes that are going away // hook to manage unloading icons for nodes that are going away
@@ -406,70 +405,72 @@ public:
// called when metamime database changed to figure out which models // called when metamime database changed to figure out which models
// to redraw // to redraw
bool IconHitTest(BPoint, const Model*, IconDrawMode, icon_size); bool IconHitTest(BPoint, const Model*, IconDrawMode, BSize);
// utility calls for building specialized icons // utility calls for building specialized icons
BBitmap* MakeSelectedIcon(const BBitmap* normal, icon_size, BBitmap* MakeSelectedIcon(const BBitmap* normal, BSize,
LazyBitmapAllocator*); LazyBitmapAllocator*);
static bool NeedsDeletionNotification(IconSource); static bool NeedsDeletionNotification(IconSource);
static IconCache* sIconCache; static IconCache* sIconCache;
static BSize sMiniIconSize;
private: private:
// shared calls // shared calls
IconCacheEntry* Preload(AutoLock<SimpleIconCache>* nodeCache, IconCacheEntry* Preload(AutoLock<SimpleIconCache>* nodeCache,
AutoLock<SimpleIconCache>* sharedCache, AutoLock<SimpleIconCache>* sharedCache,
AutoLock<SimpleIconCache>** resultingLockedCache, AutoLock<SimpleIconCache>** resultingLockedCache,
Model*, IconDrawMode mode, icon_size size, bool permanent); Model*, IconDrawMode mode, BSize size, bool permanent);
// preload uses lazy locking, returning the cache we decided // preload uses lazy locking, returning the cache we decided
// to use to get the icon // to use to get the icon
// <resultingLockedCache> may be null if we don't care // <resultingLockedCache> may be null if we don't care
// shared mime-based icon retrieval calls // shared mime-based icon retrieval calls
IconCacheEntry* GetIconForPreferredApp(const char* mimeTypeSignature, IconCacheEntry* GetIconForPreferredApp(const char* mimeTypeSignature,
const char* preferredApp, IconDrawMode mode, icon_size size, const char* preferredApp, IconDrawMode mode, BSize size,
LazyBitmapAllocator*, IconCacheEntry*); LazyBitmapAllocator*, IconCacheEntry*);
IconCacheEntry* GetIconFromFileTypes(ModelNodeLazyOpener*, IconCacheEntry* GetIconFromFileTypes(ModelNodeLazyOpener*,
IconSource &source, IconDrawMode mode, icon_size size, IconSource &source, IconDrawMode mode, BSize size,
LazyBitmapAllocator*, IconCacheEntry*); LazyBitmapAllocator*, IconCacheEntry*);
IconCacheEntry* GetIconFromMetaMime(const char* fileType, IconCacheEntry* GetIconFromMetaMime(const char* fileType,
IconDrawMode mode, icon_size size, LazyBitmapAllocator*, IconDrawMode mode, BSize size, LazyBitmapAllocator*,
IconCacheEntry*); IconCacheEntry*);
IconCacheEntry* GetVolumeIcon(AutoLock<SimpleIconCache>* nodeCache, IconCacheEntry* GetVolumeIcon(AutoLock<SimpleIconCache>* nodeCache,
AutoLock<SimpleIconCache>* sharedCache, AutoLock<SimpleIconCache>* sharedCache,
AutoLock<SimpleIconCache>** resultingLockedCache, AutoLock<SimpleIconCache>** resultingLockedCache,
Model*, IconSource&, IconDrawMode mode, Model*, IconSource&, IconDrawMode mode,
icon_size size, LazyBitmapAllocator*); BSize size, LazyBitmapAllocator*);
IconCacheEntry* GetRootIcon(AutoLock<SimpleIconCache>* nodeCache, IconCacheEntry* GetRootIcon(AutoLock<SimpleIconCache>* nodeCache,
AutoLock<SimpleIconCache>* sharedCache, AutoLock<SimpleIconCache>* sharedCache,
AutoLock<SimpleIconCache>** resultingLockedCache, AutoLock<SimpleIconCache>** resultingLockedCache,
Model*, IconSource&, IconDrawMode mode, Model*, IconSource&, IconDrawMode mode,
icon_size size, LazyBitmapAllocator*); BSize size, LazyBitmapAllocator*);
IconCacheEntry* GetWellKnownIcon(AutoLock<SimpleIconCache> *nodeCache, IconCacheEntry* GetWellKnownIcon(AutoLock<SimpleIconCache> *nodeCache,
AutoLock<SimpleIconCache>* sharedCache, AutoLock<SimpleIconCache>* sharedCache,
AutoLock<SimpleIconCache>** resultingLockedCache, AutoLock<SimpleIconCache>** resultingLockedCache,
Model*, IconSource&, IconDrawMode mode, Model*, IconSource&, IconDrawMode mode,
icon_size size, LazyBitmapAllocator*); BSize size, LazyBitmapAllocator*);
IconCacheEntry* GetNodeIcon(ModelNodeLazyOpener *, IconCacheEntry* GetNodeIcon(ModelNodeLazyOpener *,
AutoLock<SimpleIconCache>* nodeCache, AutoLock<SimpleIconCache>* nodeCache,
AutoLock<SimpleIconCache>** resultingLockedCache, AutoLock<SimpleIconCache>** resultingLockedCache,
Model*, IconSource&, IconDrawMode mode, Model*, IconSource&, IconDrawMode mode,
icon_size size, LazyBitmapAllocator*, IconCacheEntry*, BSize size, LazyBitmapAllocator*, IconCacheEntry*,
bool permanent); bool permanent);
IconCacheEntry* GetGenericIcon(AutoLock<SimpleIconCache>* sharedCache, IconCacheEntry* GetGenericIcon(AutoLock<SimpleIconCache>* sharedCache,
AutoLock<SimpleIconCache>** resultingLockedCache, AutoLock<SimpleIconCache>** resultingLockedCache,
Model*, IconSource&, IconDrawMode mode, Model*, IconSource&, IconDrawMode mode,
icon_size size, LazyBitmapAllocator*, IconCacheEntry*); BSize size, LazyBitmapAllocator*, IconCacheEntry*);
IconCacheEntry* GetFallbackIcon( IconCacheEntry* GetFallbackIcon(
AutoLock<SimpleIconCache>* sharedCacheLocker, AutoLock<SimpleIconCache>* sharedCacheLocker,
AutoLock<SimpleIconCache>** resultingOpenCache, AutoLock<SimpleIconCache>** resultingOpenCache,
Model* model, IconDrawMode mode, icon_size size, Model* model, IconDrawMode mode, BSize size,
LazyBitmapAllocator* lazyBitmap, IconCacheEntry* entry); LazyBitmapAllocator* lazyBitmap, IconCacheEntry* entry);
BBitmap* MakeTransformedIcon(const BBitmap*, icon_size, BBitmap* MakeTransformedIcon(const BBitmap*, BSize,
int32 colorTransformTable [], LazyBitmapAllocator*); int32 colorTransformTable [], LazyBitmapAllocator*);
private:
NodeIconCache fNodeCache; NodeIconCache fNodeCache;
SharedIconCache fSharedCache; SharedIconCache fSharedCache;
@@ -487,7 +488,7 @@ class LazyBitmapAllocator {
// Utility class used when we aren't sure that we will keep a bitmap, // Utility class used when we aren't sure that we will keep a bitmap,
// need a bitmap or be able to construct it properly // need a bitmap or be able to construct it properly
public: public:
LazyBitmapAllocator(icon_size size, LazyBitmapAllocator(BSize size,
color_space colorSpace = kDefaultIconDepth, color_space colorSpace = kDefaultIconDepth,
bool preallocate = false); bool preallocate = false);
~LazyBitmapAllocator(); ~LazyBitmapAllocator();
@@ -497,7 +498,7 @@ public:
private: private:
BBitmap* fBitmap; BBitmap* fBitmap;
icon_size fSize; BSize fSize;
color_space fColorSpace; color_space fColorSpace;
}; };
+2 -2
View File
@@ -165,12 +165,12 @@ ModelMenuItem::DrawIcon()
// draw small icon, synchronously // draw small icon, synchronously
if (IsEnabled()) { if (IsEnabled()) {
IconCache::sIconCache->Draw(fModel.ResolveIfLink(), Menu(), where, IconCache::sIconCache->Draw(fModel.ResolveIfLink(), Menu(), where,
kNormalIcon, (icon_size)ListIconSize()); kNormalIcon, BSize(ListIconSize() - 1, ListIconSize() - 1));
} else { } else {
// dimmed, for now use a special blitter; icon cache should // dimmed, for now use a special blitter; icon cache should
// know how to blit one eventually // know how to blit one eventually
IconCache::sIconCache->SyncDraw(fModel.ResolveIfLink(), Menu(), where, IconCache::sIconCache->SyncDraw(fModel.ResolveIfLink(), Menu(), where,
kNormalIcon, (icon_size)ListIconSize(), DimmedIconBlitter); kNormalIcon, BSize(ListIconSize() - 1, ListIconSize() - 1), DimmedIconBlitter);
} }
Menu()->PopState(); Menu()->PopState();
+4 -6
View File
@@ -38,6 +38,7 @@ All rights reserved.
#include "MountMenu.h" #include "MountMenu.h"
#include <Catalog.h> #include <Catalog.h>
#include <ControlLook.h>
#include <Debug.h> #include <Debug.h>
#include <Locale.h> #include <Locale.h>
#include <MenuItem.h> #include <MenuItem.h>
@@ -119,16 +120,13 @@ AddMenuItemVisitor::Visit(BPartition* partition, int32 level)
unit = 'M'; unit = 'M';
} }
char* buffer = name.LockBuffer(256); name.SetToFormat("(%.1f %cB %s)",
snprintf(buffer, 256, "(%.1f %cB %s)",
1.0 * partition->Size() / divisor, unit, type); 1.0 * partition->Size() / divisor, unit, type);
name.UnlockBuffer();
} }
} }
// get icon // get icon
BBitmap* icon = new BBitmap(BRect(0, 0, B_MINI_ICON - 1, B_MINI_ICON - 1), BBitmap* icon = new BBitmap(BRect(BPoint(0, 0), be_control_look->ComposeIconSize(B_MINI_ICON)),
B_RGBA32); B_RGBA32);
if (partition->GetIcon(icon, B_MINI_ICON) != B_OK) { if (partition->GetIcon(icon, B_MINI_ICON) != B_OK) {
delete icon; delete icon;
@@ -206,7 +204,7 @@ MountMenu::AddDynamicItem(add_state)
continue; continue;
} }
// Use the shared icon instead of the device icon // Use the shared icon instead of the device icon
if (get_device_icon(info.device_name, icon->Bits(), B_MINI_ICON) if (get_device_icon(info.device_name, icon, B_MINI_ICON)
!= B_OK) { != B_OK) {
GetTrackerResources()->GetIconResource(R_ShareIcon, GetTrackerResources()->GetIconResource(R_ShareIcon,
B_MINI_ICON, icon); B_MINI_ICON, icon);
+2 -2
View File
@@ -191,8 +191,8 @@ NodePreloader::PreloadOne(const char* dirPath)
if (model->InitCheck() == B_OK && model->IconFrom() == kUnknownSource) { if (model->InitCheck() == B_OK && model->IconFrom() == kUnknownSource) {
TTracker::WatchNode(model->NodeRef(), TTracker::WatchNode(model->NodeRef(),
B_WATCH_STAT | B_WATCH_ATTR, this); B_WATCH_STAT | B_WATCH_ATTR, this);
IconCache::sIconCache->Preload(model, kNormalIcon, B_MINI_ICON, IconCache::sIconCache->Preload(model, kNormalIcon,
true); IconCache::sMiniIconSize, true);
fModelList.AddItem(model); fModelList.AddItem(model);
model->CloseNode(); model->CloseNode();
} else } else
+9 -18
View File
@@ -741,7 +741,7 @@ BPose::MoveTo(BPoint point, BPoseView* poseView, bool invalidate)
float scale = 1.0; float scale = 1.0;
if (poseView->ViewMode() == kIconMode) { if (poseView->ViewMode() == kIconMode) {
scale = poseView->IconSize() / 32.0; scale = (float)poseView->IconSizeInt() / 32.0;
} }
fLocation.x = point.x / scale; fLocation.x = point.x / scale;
fLocation.y = point.y / scale; fLocation.y = point.y / scale;
@@ -799,17 +799,8 @@ BPose::WidgetFor(BColumn* column, BPoseView* poseView,
} }
// the following method is deprecated
bool
BPose::TestLargeIconPixel(BPoint point) const
{
return IconCache::sIconCache->IconHitTest(point, ResolvedModel(),
kNormalIcon, B_LARGE_ICON);
}
void void
BPose::DrawIcon(BPoint where, BView* view, icon_size which, bool direct, BPose::DrawIcon(BPoint where, BView* view, BSize size, bool direct,
bool drawUnselected) bool drawUnselected)
{ {
if (fClipboardMode == kMoveSelectionTo) { if (fClipboardMode == kMoveSelectionTo) {
@@ -821,22 +812,22 @@ BPose::DrawIcon(BPoint where, BView* view, icon_size which, bool direct,
view->SetDrawingMode(B_OP_OVER); view->SetDrawingMode(B_OP_OVER);
IconCache::sIconCache->Draw(ResolvedModel(), view, where, IconCache::sIconCache->Draw(ResolvedModel(), view, where,
fIsSelected && !drawUnselected ? kSelectedIcon : kNormalIcon, which, fIsSelected && !drawUnselected ? kSelectedIcon : kNormalIcon, size,
true); true);
if (fPercent != -1) if (fPercent != -1)
DrawBar(where, view, which); DrawBar(where, view, size);
} }
void void
BPose::DrawBar(BPoint where, BView* view, icon_size which) BPose::DrawBar(BPoint where, BView* view, BSize iconSize)
{ {
view->PushState(); view->PushState();
int32 size = which - 1; int32 size = iconSize.IntegerWidth();
int32 yOffset; int32 yOffset;
int32 barWidth = (int32)(7.0f / 32.0f * (float)which); int32 barWidth = (int32)(7.0f / 32.0f * (float)(size + 1));
if (barWidth < 4) { if (barWidth < 4) {
barWidth = 4; barWidth = 4;
yOffset = 0; yOffset = 0;
@@ -899,7 +890,7 @@ BPose::Location(const BPoseView* poseView) const
{ {
float scale = 1.0; float scale = 1.0;
if (poseView->ViewMode() == kIconMode) if (poseView->ViewMode() == kIconMode)
scale = poseView->IconSize() / 32.0; scale = (float)poseView->IconSizeInt() / 32.0;
return BPoint(fLocation.x * scale, fLocation.y * scale); return BPoint(fLocation.x * scale, fLocation.y * scale);
} }
@@ -910,7 +901,7 @@ BPose::SetLocation(BPoint point, const BPoseView* poseView)
{ {
float scale = 1.0; float scale = 1.0;
if (poseView->ViewMode() == kIconMode) if (poseView->ViewMode() == kIconMode)
scale = poseView->IconSize() / 32.0; scale = (float)poseView->IconSizeInt() / 32.0;
fLocation = BPoint(floorf(point.x / scale), floorf(point.y / scale)); fLocation = BPoint(floorf(point.x / scale), floorf(point.y / scale));
if (isinff(fLocation.x) || isinff(fLocation.y)) if (isinff(fLocation.x) || isinff(fLocation.y))
+3 -3
View File
@@ -75,9 +75,9 @@ public:
// special purpose draw call for deselecting over a textured // special purpose draw call for deselecting over a textured
// background // background
void DrawBar(BPoint where, BView* view, icon_size which); void DrawBar(BPoint where, BView* view, BSize iconSize);
void DrawIcon(BPoint where, BView* view, icon_size which, bool direct, void DrawIcon(BPoint where, BView* view, BSize size, bool direct,
bool drawUnselected = false); bool drawUnselected = false);
void DrawToggleSwitch(BRect, BPoseView*); void DrawToggleSwitch(BRect, BPoseView*);
void MouseUp(BPoint poseLoc, BPoseView*, BPoint where, int32 index); void MouseUp(BPoint poseLoc, BPoseView*, BPoint where, int32 index);
@@ -136,7 +136,7 @@ private:
static bool _PeriodicUpdateCallback(BPose* pose, void* cookie); static bool _PeriodicUpdateCallback(BPose* pose, void* cookie);
void EditPreviousNextWidgetCommon(BPoseView* poseView, bool next); void EditPreviousNextWidgetCommon(BPoseView* poseView, bool next);
void CreateWidgets(BPoseView*); void CreateWidgets(BPoseView*);
bool TestLargeIconPixel(BPoint) const;
BRect _IconRect(const BPoseView* poseView, BRect _IconRect(const BPoseView* poseView,
BPoint location) const; BPoint location) const;
+3 -5
View File
@@ -1019,19 +1019,17 @@ BPoseView::SetIconPoseHeight()
break; break;
case kMiniIconMode: case kMiniIconMode:
fViewState->SetIconSize(B_MINI_ICON); fViewState->SetIconSize(IconCache::sMiniIconSize.IntegerWidth() + 1);
fIconPoseHeight = std::max((float)IconSizeInt(), sFontHeight + 1); fIconPoseHeight = std::max((float)IconSizeInt(), sFontHeight + 1);
break; break;
case kListMode: case kListMode:
default: default:
{
fViewState->SetIconSize(ListIconSize()); fViewState->SetIconSize(ListIconSize());
fIconPoseHeight = fListElemHeight; fIconPoseHeight = fListElemHeight;
break; break;
} }
} }
}
void void
@@ -1039,8 +1037,8 @@ BPoseView::GetLayoutInfo(uint32 mode, BPoint* grid, BPoint* offset) const
{ {
switch (mode) { switch (mode) {
case kMiniIconMode: case kMiniIconMode:
grid->Set(96, 20); grid->Set(IconSizeInt() * 6, ceilf(IconSizeInt() * 1.25f));
offset->Set(10, 5); offset->Set(ceilf(IconSizeInt() * 0.6f), ceilf(IconSizeInt() * 0.3f));
break; break;
case kIconMode: case kIconMode:
+3 -3
View File
@@ -205,7 +205,7 @@ public:
void SetIconPoseHeight(); void SetIconPoseHeight();
float IconPoseHeight() const; float IconPoseHeight() const;
uint32 IconSizeInt() const; uint32 IconSizeInt() const;
icon_size IconSize() const; BSize IconSize() const;
BRect Extent() const; BRect Extent() const;
void GetLayoutInfo(uint32 viewMode, BPoint* grid, void GetLayoutInfo(uint32 viewMode, BPoint* grid,
@@ -889,10 +889,10 @@ BPoseView::IconSizeInt() const
} }
inline icon_size inline BSize
BPoseView::IconSize() const BPoseView::IconSize() const
{ {
return (icon_size)fViewState->IconSize(); return BSize(fViewState->IconSize() - 1, fViewState->IconSize() - 1);
} }
+2 -4
View File
@@ -190,13 +190,11 @@ BTextWidget::CalcRectCommon(BPoint poseLoc, const BColumn* column,
// icon mode // icon mode
result.left = poseLoc.x result.left = poseLoc.x
+ roundf((view->IconSizeInt() - viewWidth) / 2); + roundf((view->IconSizeInt() - viewWidth) / 2);
result.bottom = poseLoc.y + view->IconPoseHeight();
} else { } else {
// mini icon mode // mini icon mode
result.left = poseLoc.x + B_MINI_ICON + kMiniIconSeparator; result.left = poseLoc.x + view->IconSizeInt() + kMiniIconSeparator;
result.bottom = poseLoc.y
+ roundf((B_MINI_ICON + view->FontHeight()) / 2);
} }
result.bottom = poseLoc.y + view->IconPoseHeight();
result.right = result.left + viewWidth; result.right = result.left + viewWidth;
} }
+12 -12
View File
@@ -113,19 +113,19 @@ ScaleBitmap(BBitmap* source, BBitmap& dest, BRect bounds, color_space colorSpace
static status_t static status_t
ScaleBitmap(BBitmap* source, BBitmap& dest, icon_size size, color_space colorSpace) ScaleBitmap(BBitmap* source, BBitmap& dest, BSize size, color_space colorSpace)
{ {
return ScaleBitmap(source, dest, BRect(0, 0, size - 1, size - 1), colorSpace); return ScaleBitmap(source, dest, BRect(BPoint(0, 0), size), colorSpace);
} }
class GenerateThumbnailJob : public BSupportKit::BJob { class GenerateThumbnailJob : public BSupportKit::BJob {
public: public:
GenerateThumbnailJob(Model* model, const BFile& file, GenerateThumbnailJob(Model* model, const BFile& file,
icon_size size, color_space colorSpace) BSize requestedSize, color_space colorSpace)
: BJob("GenerateThumbnail"), : BJob("GenerateThumbnail"),
fMimeType(model->MimeType()), fMimeType(model->MimeType()),
fSize(size), fRequestedSize(requestedSize),
fColorSpace(colorSpace) fColorSpace(colorSpace)
{ {
fFile = new(std::nothrow) BFile(file); fFile = new(std::nothrow) BFile(file);
@@ -154,7 +154,7 @@ public:
public: public:
const BString fMimeType; const BString fMimeType;
const node_ref fNodeRef; const node_ref fNodeRef;
const icon_size fSize; const BSize fRequestedSize;
const color_space fColorSpace; const color_space fColorSpace;
private: private:
@@ -180,7 +180,7 @@ GenerateThumbnailJob::Execute()
// now, scale and directly insert into the icon cache // now, scale and directly insert into the icon cache
BBitmap tmp(NULL, false); BBitmap tmp(NULL, false);
ScaleBitmap(image, tmp, fSize, fColorSpace); ScaleBitmap(image, tmp, fRequestedSize, fColorSpace);
BBitmap* cacheThumb = new BBitmap(tmp.Bounds(), 0, tmp.ColorSpace()); BBitmap* cacheThumb = new BBitmap(tmp.Bounds(), 0, tmp.ColorSpace());
cacheThumb->ImportBits(&tmp); cacheThumb->ImportBits(&tmp);
@@ -195,7 +195,7 @@ GenerateThumbnailJob::Execute()
return B_NO_MEMORY; return B_NO_MEMORY;
} }
entry->SetIcon(cacheThumb, kNormalIcon, fSize); entry->SetIcon(cacheThumb, kNormalIcon, fRequestedSize);
cacheLocker.Unlock(); cacheLocker.Unlock();
// write values to attributes // write values to attributes
@@ -266,7 +266,7 @@ thumbnail_worker(void* castToJobQueue)
static status_t static status_t
GenerateThumbnail(Model* model, color_space colorSpace, icon_size which) GenerateThumbnail(Model* model, color_space colorSpace, BSize size)
{ {
// First check we do not have a job queued already. // First check we do not have a job queued already.
BAutolock jobsLock(sActiveJobsLock); BAutolock jobsLock(sActiveJobsLock);
@@ -287,7 +287,7 @@ GenerateThumbnail(Model* model, color_space colorSpace, icon_size which)
return status; return status;
GenerateThumbnailJob* job = new(std::nothrow) GenerateThumbnailJob(model, GenerateThumbnailJob* job = new(std::nothrow) GenerateThumbnailJob(model,
*file, which, colorSpace); *file, size, colorSpace);
ObjectDeleter<GenerateThumbnailJob> jobDeleter(job); ObjectDeleter<GenerateThumbnailJob> jobDeleter(job);
if (job == NULL) if (job == NULL)
return B_NO_MEMORY; return B_NO_MEMORY;
@@ -328,7 +328,7 @@ GenerateThumbnail(Model* model, color_space colorSpace, icon_size which)
status_t status_t
GetThumbnailFromAttr(Model* model, BBitmap* icon, icon_size which) GetThumbnailFromAttr(Model* model, BBitmap* icon, BSize size)
{ {
if (model == NULL || icon == NULL) if (model == NULL || icon == NULL)
return B_BAD_VALUE; return B_BAD_VALUE;
@@ -362,7 +362,7 @@ GetThumbnailFromAttr(Model* model, BBitmap* icon, icon_size which)
BBitmap thumb(BTranslationUtils::GetBitmap(&webpData)); BBitmap thumb(BTranslationUtils::GetBitmap(&webpData));
// convert thumb to icon size // convert thumb to icon size
if (which == B_XXL_ICON) { if ((size.IntegerWidth() + 1) == B_XXL_ICON) {
// import icon data from attribute without resizing // import icon data from attribute without resizing
result = icon->ImportBits(&thumb); result = icon->ImportBits(&thumb);
} else { } else {
@@ -391,7 +391,7 @@ GetThumbnailFromAttr(Model* model, BBitmap* icon, icon_size which)
} }
if (ShouldGenerateThumbnail(model->MimeType())) if (ShouldGenerateThumbnail(model->MimeType()))
return GenerateThumbnail(model, icon->ColorSpace(), which); return GenerateThumbnail(model, icon->ColorSpace(), size);
return B_NOT_SUPPORTED; return B_NOT_SUPPORTED;
} }
+1 -1
View File
@@ -20,7 +20,7 @@ namespace BPrivate {
class Model; class Model;
status_t GetThumbnailFromAttr(Model* model, BBitmap* icon, icon_size which); status_t GetThumbnailFromAttr(Model* model, BBitmap* icon, BSize size);
bool ShouldGenerateThumbnail(const char* type); bool ShouldGenerateThumbnail(const char* type);
+5 -5
View File
@@ -296,7 +296,7 @@ HeaderView::Draw(BRect)
// Draw the icon, straddling the border // Draw the icon, straddling the border
SetDrawingMode(B_OP_OVER); SetDrawingMode(B_OP_OVER);
IconCache::sIconCache->Draw(fIconModel, this, fIconRect.LeftTop(), IconCache::sIconCache->Draw(fIconModel, this, fIconRect.LeftTop(),
kNormalIcon, B_LARGE_ICON, true); kNormalIcon, fIconRect.Size(), true);
SetDrawingMode(B_OP_COPY); SetDrawingMode(B_OP_COPY);
// Font information // Font information
@@ -387,7 +387,7 @@ HeaderView::MouseDown(BPoint where)
offsetPoint.x = where.x - fIconRect.left; offsetPoint.x = where.x - fIconRect.left;
offsetPoint.y = where.y - fIconRect.top; offsetPoint.y = where.y - fIconRect.top;
if (IconCache::sIconCache->IconHitTest(offsetPoint, fIconModel, if (IconCache::sIconCache->IconHitTest(offsetPoint, fIconModel,
kNormalIcon, B_LARGE_ICON)) { kNormalIcon, fIconRect.Size())) {
// Can't drag the trash anywhere.. // Can't drag the trash anywhere..
fTrackingState = fModel->IsTrash() fTrackingState = fModel->IsTrash()
? open_only_track : icon_track; ? open_only_track : icon_track;
@@ -405,7 +405,7 @@ HeaderView::MouseDown(BPoint where)
offsetPoint.y = fClickPoint.y - fIconRect.top; offsetPoint.y = fClickPoint.y - fIconRect.top;
fDoubleClick fDoubleClick
= IconCache::sIconCache->IconHitTest(offsetPoint, = IconCache::sIconCache->IconHitTest(offsetPoint,
fIconModel, kNormalIcon, B_LARGE_ICON); fIconModel, kNormalIcon, fIconRect.Size());
} }
} }
} }
@@ -430,7 +430,7 @@ HeaderView::MouseMoved(BPoint where, uint32, const BMessage* dragMessage)
SetDrawingMode(B_OP_OVER); SetDrawingMode(B_OP_OVER);
if (overTarget != fIsDropTarget) { if (overTarget != fIsDropTarget) {
IconCache::sIconCache->Draw(fIconModel, this, fIconRect.LeftTop(), IconCache::sIconCache->Draw(fIconModel, this, fIconRect.LeftTop(),
overTarget ? kSelectedIcon : kNormalIcon, B_LARGE_ICON, true); overTarget ? kSelectedIcon : kNormalIcon, fIconRect.Size(), true);
fIsDropTarget = overTarget; fIsDropTarget = overTarget;
} }
} }
@@ -473,7 +473,7 @@ HeaderView::MouseMoved(BPoint where, uint32, const BMessage* dragMessage)
// Draw the icon // Draw the icon
float hIconOffset = (rect.Width() - fIconRect.Width()) / 2; float hIconOffset = (rect.Width() - fIconRect.Width()) / 2;
IconCache::sIconCache->Draw(fIconModel, view, IconCache::sIconCache->Draw(fIconModel, view,
BPoint(hIconOffset, 0), kNormalIcon, B_LARGE_ICON, true); BPoint(hIconOffset, 0), kNormalIcon, fIconRect.Size(), true);
// See if we need to truncate the string // See if we need to truncate the string
BString nameString(fModel->Name()); BString nameString(fModel->Name());