ReactOS 0.4.16-dev-334-g4d9f67c
IconCache Struct Reference

#include <globals.h>

Collaboration diagram for IconCache:

Public Member Functions

 IconCache ()
 
virtual ~IconCache ()
 
void init ()
 
const Iconextract (LPCTSTR path, ICONCACHE_FLAGS flags=ICF_NORMAL)
 
const Iconextract (LPCTSTR path, int icon_idx, ICONCACHE_FLAGS flags=ICF_HICON)
 
const Iconextract (IExtractIcon *pExtract, LPCTSTR path, int icon_idx, ICONCACHE_FLAGS flags=ICF_HICON)
 
const Iconextract (LPCITEMIDLIST pidl, ICONCACHE_FLAGS flags=ICF_NORMAL)
 
const Iconadd (HICON hIcon, ICON_TYPE type=IT_DYNAMIC)
 
const Iconadd (int sys_idx)
 
const Iconget_icon (int icon_id)
 
HIMAGELIST get_sys_imagelist () const
 
void free_icon (int icon_id)
 

Protected Types

typedef map< int, IconIconMap
 
typedef pair< String, intCacheKey
 
typedef map< CacheKey, ICON_IDPathCacheMap
 
typedef pair< String, pair< int, int > > IdxCacheKey
 
typedef map< IdxCacheKey, ICON_IDIdxCacheMap
 
typedef pair< ShellPath, intPidlCacheKey
 
typedef map< PidlCacheKey, ICON_IDPidlCacheMap
 

Protected Attributes

IconMap _icons
 
PathCacheMap _pathCache
 
IdxCacheMap _idxCache
 
PidlCacheMap _pidlcache
 
HIMAGELIST _himlSys_small
 

Static Protected Attributes

static int s_next_id = ICID_DYNAMIC
 

Detailed Description

Definition at line 127 of file globals.h.

Member Typedef Documentation

◆ CacheKey

typedef pair<String,int> IconCache::CacheKey
protected

Definition at line 153 of file globals.h.

◆ IconMap

typedef map<int, Icon> IconCache::IconMap
protected

Definition at line 150 of file globals.h.

◆ IdxCacheKey

typedef pair<String,pair<int,int> > IconCache::IdxCacheKey
protected

Definition at line 157 of file globals.h.

◆ IdxCacheMap

Definition at line 158 of file globals.h.

◆ PathCacheMap

Definition at line 154 of file globals.h.

◆ PidlCacheKey

Definition at line 161 of file globals.h.

◆ PidlCacheMap

Definition at line 162 of file globals.h.

Constructor & Destructor Documentation

◆ IconCache()

IconCache::IconCache ( )
inline

Definition at line 128 of file globals.h.

128: _himlSys_small(0) {}
HIMAGELIST _himlSys_small
Definition: globals.h:165

◆ ~IconCache()

IconCache::~IconCache ( )
virtual

Definition at line 630 of file explorer.cpp.

631{
632/* We don't need to free cached resources - they are automatically freed at process termination
633 for (int index = s_next_id; index >= 0; index--) {
634 IconMap::iterator found = _icons.find(index);
635
636 if (found != _icons.end()) {
637 Icon& icon = found->second;
638
639 if ((icon.get_icontype() == IT_DYNAMIC) ||
640 (icon.get_icontype() == IT_CACHED))
641 {
642 DestroyIcon(icon.get_hicon());
643 _icons.erase(found);
644 }
645 }
646 }
647*/
648}

Member Function Documentation

◆ add() [1/2]

const Icon & IconCache::add ( HICON  hIcon,
ICON_TYPE  type = IT_DYNAMIC 
)

Definition at line 611 of file explorer.cpp.

612{
613 int id = ++s_next_id;
614
615 return _icons[id] = Icon(type, id, hIcon);
616}
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLuint id
Definition: glext.h:5910
HICON hIcon
Definition: msconfig.c:44
static int s_next_id
Definition: globals.h:148
IconMap _icons
Definition: globals.h:151
Definition: globals.h:96

Referenced by extract().

◆ add() [2/2]

const Icon & IconCache::add ( int  sys_idx)

Definition at line 618 of file explorer.cpp.

619{
620 int id = ++s_next_id;
621
622 return _icons[id] = SysCacheIcon(id, sys_idx);
623}

◆ extract() [1/4]

const Icon & IconCache::extract ( IExtractIcon *  pExtract,
LPCTSTR  path,
int  icon_idx,
ICONCACHE_FLAGS  flags = ICF_HICON 
)

Definition at line 518 of file explorer.cpp.

519{
520 HICON hIconLarge = 0;
521 HICON hIcon;
522
524 HRESULT hr = pExtract->Extract(path, icon_idx, &hIconLarge, &hIcon, MAKELONG(GetSystemMetrics(SM_CXICON), icon_size));
525
526 if (hr == NOERROR) { //@@ oder SUCCEEDED(hr) ?
527 if (icon_size > ICON_SIZE_SMALL) { //@@ OK?
528 if (hIcon)
530
531 hIcon = hIconLarge;
532 } else {
533 if (hIconLarge)
534 DestroyIcon(hIconLarge);
535 }
536
537 if (hIcon)
538 return add(hIcon); //@@ When do we want not to free this icons?
539 }
540
541 return _icons[ICID_NONE];
542}
GLbitfield flags
Definition: glext.h:7161
@ ICID_NONE
Definition: globals.h:64
#define ICON_SIZE_FROM_ICF(flags)
Definition: globals.h:175
#define ICON_SIZE_SMALL
Definition: globals.h:169
static HICON
Definition: imagelist.c:80
HRESULT hr
Definition: shlfolder.c:183
iconPos iconPos icon_size
Definition: startmenu.cpp:1416
const Icon & add(HICON hIcon, ICON_TYPE type=IT_DYNAMIC)
Definition: explorer.cpp:611
#define MAKELONG(a, b)
Definition: typedefs.h:249
#define NOERROR
Definition: winerror.h:2354
#define SM_CXICON
Definition: winuser.h:975
int WINAPI GetSystemMetrics(_In_ int)
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2105

◆ extract() [2/4]

const Icon & IconCache::extract ( LPCITEMIDLIST  pidl,
ICONCACHE_FLAGS  flags = ICF_NORMAL 
)
Todo:
limit cache size
Todo:
limit cache size

Definition at line 544 of file explorer.cpp.

545{
546 // search for matching icon with unchanged flags in the cache
547 PidlCacheKey mapkey(pidl, flags);
548 PidlCacheMap::iterator found = _pidlcache.find(mapkey);
549
550 if (found != _pidlcache.end())
551 return _icons[found->second];
552
553 // search for matching icon with handle
554 PidlCacheKey mapkey_hicon(pidl, flags|ICF_HICON);
555 if (flags != mapkey_hicon.second) {
556 found = _pidlcache.find(mapkey_hicon);
557
558 if (found != _pidlcache.end())
559 return _icons[found->second];
560 }
561
562 // search for matching icon in the system image list cache
563 PidlCacheKey mapkey_syscache(pidl, flags|ICF_SYSCACHE);
564 if (flags != mapkey_syscache.second) {
565 found = _pidlcache.find(mapkey_syscache);
566
567 if (found != _pidlcache.end())
568 return _icons[found->second];
569 }
570
571 SHFILEINFO sfi;
572
573 int shgfi_flags = SHGFI_PIDL;
574
575 if (!(flags & (ICF_LARGE|ICF_MIDDLE)))
576 shgfi_flags |= SHGFI_SMALLICON;
577
578 if (flags & ICF_OPEN)
579 shgfi_flags |= SHGFI_OPENICON;
580
581 if (flags & ICF_SYSCACHE) {
583
584 HIMAGELIST himlSys = (HIMAGELIST) SHGetFileInfo((LPCTSTR)pidl, 0, &sfi, sizeof(sfi), SHGFI_SYSICONINDEX|shgfi_flags);
585 if (himlSys) {
586 const Icon& icon = add(sfi.iIcon/*, IT_SYSCACHE*/);
587
589 _pidlcache[mapkey_syscache] = icon;
590
591 return icon;
592 }
593 } else {
594 if (flags & ICF_OVERLAYS)
595 shgfi_flags |= SHGFI_ADDOVERLAYS;
596
597 if (SHGetFileInfo((LPCTSTR)pidl, 0, &sfi, sizeof(sfi), SHGFI_ICON|shgfi_flags)) {
598 const Icon& icon = add(sfi.hIcon, IT_CACHED);
599
601 _pidlcache[mapkey_hicon] = icon;
602
603 return icon;
604 }
605 }
606
607 return _icons[ICID_NONE];
608}
#define assert(x)
Definition: debug.h:53
@ ICF_MIDDLE
Definition: entries.h:68
@ ICF_HICON
Definition: entries.h:72
@ ICF_LARGE
Definition: entries.h:69
@ ICF_SYSCACHE
Definition: entries.h:73
@ ICF_OVERLAYS
Definition: entries.h:71
@ ICF_OPEN
Definition: entries.h:70
#define SHGFI_ADDOVERLAYS
Definition: entries.h:77
@ IT_CACHED
Definition: globals.h:57
struct _IMAGELIST * HIMAGELIST
Definition: commctrl.h:324
#define SHGFI_OPENICON
Definition: shellapi.h:179
#define SHGetFileInfo
Definition: shellapi.h:698
#define SHGFI_SYSICONINDEX
Definition: shellapi.h:172
#define SHGFI_ICON
Definition: shellapi.h:165
#define SHGFI_SMALLICON
Definition: shellapi.h:177
#define SHGFI_PIDL
Definition: shellapi.h:181
pair< ShellPath, int > PidlCacheKey
Definition: globals.h:161
PidlCacheMap _pidlcache
Definition: globals.h:163
const CHAR * LPCTSTR
Definition: xmlstorage.h:193

◆ extract() [3/4]

const Icon & IconCache::extract ( LPCTSTR  path,
ICONCACHE_FLAGS  flags = ICF_NORMAL 
)
Todo:
limit cache size
Todo:
limit cache size

Definition at line 416 of file explorer.cpp.

417{
418 // search for matching icon with unchanged flags in the cache
419 CacheKey mapkey(path, flags);
420 PathCacheMap::iterator found = _pathCache.find(mapkey);
421
422 if (found != _pathCache.end())
423 return _icons[found->second];
424
425 // search for matching icon with handle
426 CacheKey mapkey_hicon(path, flags|ICF_HICON);
427 if (flags != mapkey_hicon.second) {
428 found = _pathCache.find(mapkey_hicon);
429
430 if (found != _pathCache.end())
431 return _icons[found->second];
432 }
433
434 // search for matching icon in the system image list cache
435 CacheKey mapkey_syscache(path, flags|ICF_SYSCACHE);
436 if (flags != mapkey_syscache.second) {
437 found = _pathCache.find(mapkey_syscache);
438
439 if (found != _pathCache.end())
440 return _icons[found->second];
441 }
442
443 SHFILEINFO sfi;
444
445 int shgfi_flags = 0;
446
447 if (flags & ICF_OPEN)
448 shgfi_flags |= SHGFI_OPENICON;
449
451 shgfi_flags |= SHGFI_ICON;
452
453 if (!(flags & (ICF_LARGE|ICF_MIDDLE)))
454 shgfi_flags |= SHGFI_SMALLICON;
455
456 if (flags & ICF_OVERLAYS)
457 shgfi_flags |= SHGFI_ADDOVERLAYS;
458
459 // get small/big icons with/without overlays
460 if (SHGetFileInfo(path, 0, &sfi, sizeof(sfi), shgfi_flags)) {
461 const Icon& icon = add(sfi.hIcon, IT_CACHED);
462
464 _pathCache[mapkey_hicon] = icon;
465
466 return icon;
467 }
468 } else {
470
471 shgfi_flags |= SHGFI_SYSICONINDEX|SHGFI_SMALLICON;
472
473 // use system image list - the "search program dialog" needs it
474 HIMAGELIST himlSys_small = (HIMAGELIST) SHGetFileInfo(path, 0, &sfi, sizeof(sfi), shgfi_flags);
475
476 if (himlSys_small) {
477 _himlSys_small = himlSys_small;
478
479 const Icon& icon = add(sfi.iIcon/*, IT_SYSCACHE*/);
480
482 _pathCache[mapkey_syscache] = icon;
483
484 return icon;
485 }
486 }
487
488 return _icons[ICID_NONE];
489}
pair< String, int > CacheKey
Definition: globals.h:153
PathCacheMap _pathCache
Definition: globals.h:155
HICON hIcon
Definition: shellapi.h:366

Referenced by FavoritesMenu::AddEntries(), Entry::extract_icon(), and BookmarkList::fill_tree().

◆ extract() [4/4]

const Icon & IconCache::extract ( LPCTSTR  path,
int  icon_idx,
ICONCACHE_FLAGS  flags = ICF_HICON 
)
Todo:
retreive "http://.../favicon.ico" format icons

Definition at line 491 of file explorer.cpp.

492{
494
495 key.first.toLower();
496
497 IdxCacheMap::iterator found = _idxCache.find(key);
498
499 if (found != _idxCache.end())
500 return _icons[found->second];
501
502 HICON hIcon;
503
504 if ((int)ExtractIconEx(path, icon_idx, NULL, &hIcon, 1) > 0) {
505 const Icon& icon = add(hIcon, IT_CACHED);
506
507 _idxCache[key] = icon;
508
509 return icon;
510 } else {
511
513
514 return _icons[ICID_NONE];
515 }
516}
pair< _T1, _T2 > _STLP_CALL make_pair(_T1 __x, _T2 __y)
Definition: _pair.h:124
#define NULL
Definition: types.h:112
#define ExtractIconEx
Definition: shellapi.h:690
pair< String, pair< int, int > > IdxCacheKey
Definition: globals.h:157
IdxCacheMap _idxCache
Definition: globals.h:159
Definition: copy.c:22

◆ free_icon()

void IconCache::free_icon ( int  icon_id)

Definition at line 650 of file explorer.cpp.

651{
652 IconMap::iterator found = _icons.find(icon_id);
653
654 if (found != _icons.end()) {
655 Icon& icon = found->second;
656
657 if (icon.destroy())
658 _icons.erase(found);
659 }
660}
_Rep_type::iterator iterator
Definition: _map.h:85
bool destroy()
Definition: globals.h:113

Referenced by ShellBrowser::invalidate_cache(), and Entry::~Entry().

◆ get_icon()

◆ get_sys_imagelist()

HIMAGELIST IconCache::get_sys_imagelist ( ) const
inline

Definition at line 143 of file globals.h.

143{return _himlSys_small;}

Referenced by FindProgramDlg::FindProgramDlg().

◆ init()

void IconCache::init ( )

Definition at line 381 of file explorer.cpp.

382{
384
386
388 //_icons[ICID_DOCUMENT] = Icon(ICID_DOCUMENT, IDI_DOCUMENT);
390 //_icons[ICID_APP] = Icon(ICID_APP, IDI_APPICON);
391
413}
#define IDI_APPS
Definition: resource.h:11
#define IDI_PRINTER
Definition: resource.h:11
#define IDI_COMPUTER
Definition: resource.h:19
#define IDI_FOLDER
Definition: resource.h:22
#define IDI_SHUTDOWN
Definition: resource.h:83
#define IDI_LOGOFF
Definition: resource.h:82
#define IDI_NETWORK
Definition: resource.h:4
@ ICID_INFO
Definition: globals.h:74
@ ICID_NETWORK
Definition: globals.h:80
@ ICID_DOCUMENTS
Definition: globals.h:72
@ ICID_RECENT
Definition: globals.h:91
@ ICID_PRINTER
Definition: globals.h:79
@ ICID_CONTROLPAN
Definition: globals.h:87
@ ICID_RESTART
Definition: globals.h:84
@ ICID_SHUTDOWN
Definition: globals.h:83
@ ICID_EXPLORER
Definition: globals.h:69
@ ICID_SEARCH_DOC
Definition: globals.h:78
@ ICID_ACTION
Definition: globals.h:77
@ ICID_CONFIG
Definition: globals.h:71
@ ICID_FAVORITES
Definition: globals.h:73
@ ICID_COMPUTER
Definition: globals.h:81
@ ICID_SEARCH
Definition: globals.h:76
@ ICID_ADMIN
Definition: globals.h:90
@ ICID_DESKSETTING
Definition: globals.h:88
@ ICID_LOGOFF
Definition: globals.h:82
@ ICID_BOOKMARK
Definition: globals.h:85
@ ICID_MINIMIZE
Definition: globals.h:86
@ ICID_FOLDER
Definition: globals.h:66
@ ICID_APPS
Definition: globals.h:75
@ ICID_NETCONNS
Definition: globals.h:89
#define STARTMENUROOT_ICON_SIZE
Definition: globals.h:173
@ IT_STATIC
Definition: globals.h:56
#define IDI_CONTROLPAN
Definition: resource.h:125
#define IDI_INFO
Definition: resource.h:86
#define IDI_SEARCH_DOC
Definition: resource.h:91
#define IDI_MINIMIZE
Definition: resource.h:124
#define IDI_RECENT
Definition: resource.h:129
#define IDI_FAVORITES
Definition: resource.h:85
#define IDI_SEARCH
Definition: resource.h:88
#define IDI_CONFIG
Definition: resource.h:84
#define IDI_NETCONNS
Definition: resource.h:127
#define IDI_DESKSETTING
Definition: resource.h:126
#define IDI_RESTART
Definition: resource.h:130
#define IDI_ACTION
Definition: resource.h:89
#define IDI_DOT_TRANS
Definition: resource.h:116
#define IDI_EXPLORER
Definition: resource.h:56
#define IDI_DOCUMENTS
Definition: resource.h:83
#define IDI_ADMIN
Definition: resource.h:128

Referenced by ExplorerGlobals::init().

Member Data Documentation

◆ _himlSys_small

HIMAGELIST IconCache::_himlSys_small
protected

Definition at line 165 of file globals.h.

Referenced by extract(), and get_sys_imagelist().

◆ _icons

IconMap IconCache::_icons
protected

Definition at line 151 of file globals.h.

Referenced by add(), extract(), free_icon(), get_icon(), and init().

◆ _idxCache

IdxCacheMap IconCache::_idxCache
protected

Definition at line 159 of file globals.h.

Referenced by extract().

◆ _pathCache

PathCacheMap IconCache::_pathCache
protected

Definition at line 155 of file globals.h.

Referenced by extract().

◆ _pidlcache

PidlCacheMap IconCache::_pidlcache
protected

Definition at line 163 of file globals.h.

Referenced by extract().

◆ s_next_id

int IconCache::s_next_id = ICID_DYNAMIC
staticprotected

Definition at line 148 of file globals.h.

Referenced by add().


The documentation for this struct was generated from the following files: