ReactOS  0.4.12-dev-75-g00dd17e
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
IconMap _icons
Definition: globals.h:151
HICON hIcon
Definition: msconfig.c:44
Definition: globals.h:96
GLenum GLuint id
Definition: glext.h:5579
static int s_next_id
Definition: globals.h:148

◆ 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 }
IconMap _icons
Definition: globals.h:151
GLenum GLuint id
Definition: glext.h:5579
static int s_next_id
Definition: globals.h:148

◆ extract() [1/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.

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

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 {
469  assert(!(flags&ICF_OVERLAYS));
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 }
#define SHGFI_SYSICONINDEX
Definition: shellapi.h:168
PathCacheMap _pathCache
Definition: globals.h:155
#define assert(x)
Definition: debug.h:53
IconMap _icons
Definition: globals.h:151
#define SHGFI_SMALLICON
Definition: shellapi.h:173
HIMAGELIST _himlSys_small
Definition: globals.h:165
#define SHGFI_OPENICON
Definition: shellapi.h:174
#define SHGFI_ADDOVERLAYS
Definition: entries.h:77
GLbitfield flags
Definition: glext.h:7161
struct _IMAGELIST * HIMAGELIST
Definition: commctrl.h:309
const Icon & add(HICON hIcon, ICON_TYPE type=IT_DYNAMIC)
Definition: explorer.cpp:611
pair< String, int > CacheKey
Definition: globals.h:153
Definition: services.c:325
Definition: globals.h:96
#define SHGetFileInfo
Definition: shellapi.h:683
HICON hIcon
Definition: shellapi.h:361
#define SHGFI_ICON
Definition: shellapi.h:162

◆ extract() [2/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 }
static HICON
Definition: imagelist.c:84
IconMap _icons
Definition: globals.h:151
pair< _T1, _T2 > _STLP_CALL make_pair(_T1 __x, _T2 __y)
Definition: _pair.h:124
smooth NULL
Definition: ftsmooth.c:416
pair< String, pair< int, int > > IdxCacheKey
Definition: globals.h:157
if(!(yy_init))
Definition: macro.lex.yy.c:717
GLbitfield flags
Definition: glext.h:7161
HKEY key
Definition: reg.c:42
const Icon & add(HICON hIcon, ICON_TYPE type=IT_DYNAMIC)
Definition: explorer.cpp:611
HICON hIcon
Definition: msconfig.c:44
Definition: services.c:325
IdxCacheMap _idxCache
Definition: globals.h:159
Definition: globals.h:96
Definition: path.c:42
#define ExtractIconEx
Definition: shellapi.h:675

◆ extract() [3/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)
529  DestroyIcon(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 }
#define ICON_SIZE_FROM_ICF(flags)
Definition: globals.h:175
static HICON
Definition: imagelist.c:84
#define NOERROR
Definition: winerror.h:2354
BOOL WINAPI DestroyIcon(_In_ HICON)
Definition: cursoricon.c:2022
IconMap _icons
Definition: globals.h:151
#define SM_CXICON
Definition: winuser.h:962
#define MAKELONG(a, b)
Definition: typedefs.h:248
LONG HRESULT
Definition: typedefs.h:77
int WINAPI GetSystemMetrics(_In_ int)
#define ICON_SIZE_SMALL
Definition: globals.h:169
GLbitfield flags
Definition: glext.h:7161
const Icon & add(HICON hIcon, ICON_TYPE type=IT_DYNAMIC)
Definition: explorer.cpp:611
HICON hIcon
Definition: msconfig.c:44
Definition: services.c:325
iconPos iconPos icon_size
Definition: startmenu.cpp:1416

◆ extract() [4/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 SHGFI_SYSICONINDEX
Definition: shellapi.h:168
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
#define assert(x)
Definition: debug.h:53
IconMap _icons
Definition: globals.h:151
#define SHGFI_SMALLICON
Definition: shellapi.h:173
#define SHGFI_PIDL
Definition: shellapi.h:176
#define SHGFI_OPENICON
Definition: shellapi.h:174
#define SHGFI_ADDOVERLAYS
Definition: entries.h:77
PidlCacheMap _pidlcache
Definition: globals.h:163
GLbitfield flags
Definition: glext.h:7161
struct _IMAGELIST * HIMAGELIST
Definition: commctrl.h:309
pair< ShellPath, int > PidlCacheKey
Definition: globals.h:161
const Icon & add(HICON hIcon, ICON_TYPE type=IT_DYNAMIC)
Definition: explorer.cpp:611
Definition: globals.h:96
#define SHGetFileInfo
Definition: shellapi.h:683
#define SHGFI_ICON
Definition: shellapi.h:162

◆ free_icon()

void IconCache::free_icon ( int  icon_id)

Definition at line 650 of file explorer.cpp.

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

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 }
IconMap _icons
Definition: globals.h:151
Definition: globals.h:96
bool destroy()
Definition: globals.h:113
_Rep_type::iterator iterator
Definition: _map.h:85

◆ get_icon()

const Icon & IconCache::get_icon ( int  icon_id)

Definition at line 625 of file explorer.cpp.

Referenced by StartMenu::AddButton(), QuickLaunchBar::AddShortcuts(), Pane::draw_item(), MainFrameBase::FillBookmarks(), ShellBrowser::get_image_idx(), and FindProgramDlg::Notify().

626 {
627  return _icons[id];
628 }
IconMap _icons
Definition: globals.h:151
GLenum GLuint id
Definition: glext.h:5579

◆ get_sys_imagelist()

HIMAGELIST IconCache::get_sys_imagelist ( ) const
inline

Definition at line 143 of file globals.h.

Referenced by Icon::add_to_imagelist(), Icon::create_bitmap(), Icon::draw(), and FindProgramDlg::FindProgramDlg().

143 {return _himlSys_small;}
HIMAGELIST _himlSys_small
Definition: globals.h:165

◆ init()

void IconCache::init ( void  )

Definition at line 381 of file explorer.cpp.

Referenced by ExplorerGlobals::init().

382 {
384 
386 
388  //_icons[ICID_DOCUMENT] = Icon(ICID_DOCUMENT, IDI_DOCUMENT);
390  //_icons[ICID_APP] = Icon(ICID_APP, IDI_APPICON);
391 
392  _icons[ICID_CONFIG] = Icon(ICID_CONFIG, IDI_CONFIG, icon_size);
395  _icons[ICID_INFO] = Icon(ICID_INFO, IDI_INFO, icon_size);
396  _icons[ICID_APPS] = Icon(ICID_APPS, IDI_APPS, icon_size);
397  _icons[ICID_SEARCH] = Icon(ICID_SEARCH, IDI_SEARCH, icon_size);
398  _icons[ICID_ACTION] = Icon(ICID_ACTION, IDI_ACTION, icon_size);
403  _icons[ICID_LOGOFF] = Icon(ICID_LOGOFF, IDI_LOGOFF, icon_size);
411  _icons[ICID_ADMIN] = Icon(ICID_ADMIN, IDI_ADMIN, icon_size);
412  _icons[ICID_RECENT] = Icon(ICID_RECENT, IDI_RECENT, icon_size);
413 }
#define IDI_FAVORITES
Definition: resource.h:85
#define IDI_CONFIG
Definition: resource.h:84
#define IDI_ADMIN
Definition: resource.h:128
static HICON
Definition: imagelist.c:84
#define IDI_EXPLORER
Definition: resource.h:56
#define IDI_PRINTER
Definition: resource.h:11
#define IDI_RESTART
Definition: resource.h:130
#define IDI_SHUTDOWN
Definition: resource.h:64
#define IDI_DESKSETTING
Definition: resource.h:126
#define IDI_NETWORK
Definition: resource.h:93
IconMap _icons
Definition: globals.h:151
#define IDI_FOLDER
Definition: resource.h:22
#define IDI_CONTROLPAN
Definition: resource.h:125
#define IDI_LOGOFF
Definition: resource.h:63
#define IDI_DOCUMENTS
Definition: resource.h:83
#define IDI_INFO
Definition: resource.h:86
#define IDI_MINIMIZE
Definition: resource.h:124
#define IDI_SEARCH
Definition: resource.h:88
#define IDI_ACTION
Definition: resource.h:89
#define IDI_SEARCH_DOC
Definition: resource.h:91
#define IDI_COMPUTER
Definition: resource.h:19
#define IDI_RECENT
Definition: resource.h:129
#define IDI_NETCONNS
Definition: resource.h:127
#define STARTMENUROOT_ICON_SIZE
Definition: globals.h:173
#define IDI_DOT_TRANS
Definition: resource.h:116
Definition: globals.h:96
#define IDI_APPS
Definition: resource.h:11
iconPos iconPos icon_size
Definition: startmenu.cpp:1416

Member Data Documentation

◆ _himlSys_small

HIMAGELIST IconCache::_himlSys_small
protected

Definition at line 165 of file globals.h.

◆ _icons

IconMap IconCache::_icons
protected

Definition at line 151 of file globals.h.

◆ _idxCache

IdxCacheMap IconCache::_idxCache
protected

Definition at line 159 of file globals.h.

◆ _pathCache

PathCacheMap IconCache::_pathCache
protected

Definition at line 155 of file globals.h.

◆ _pidlcache

PidlCacheMap IconCache::_pidlcache
protected

Definition at line 163 of file globals.h.

◆ s_next_id

int IconCache::s_next_id = ICID_DYNAMIC
staticprotected

Definition at line 148 of file globals.h.

Referenced by ImageList_AddAlphaIcon().


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