1 // TortoiseSVN - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2006, 2008 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "SysImageList.h"
24 // Singleton constructor and destructor (private)
26 CSysImageList
* CSysImageList::instance
= 0;
28 CSysImageList::CSysImageList()
31 TCHAR windir
[MAX_PATH
];
32 GetWindowsDirectory(windir
, MAX_PATH
); // MAX_PATH ok.
33 HIMAGELIST hSystemImageList
=
34 (HIMAGELIST
)SHGetFileInfo(
38 SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
);
39 Attach(hSystemImageList
);
42 CSysImageList::~CSysImageList()
48 // Singleton specific operations
50 CSysImageList
& CSysImageList::GetInstance()
53 instance
= new CSysImageList
;
57 void CSysImageList::Cleanup()
66 int CSysImageList::GetDirIconIndex() const
69 SecureZeroMemory(&sfi
, sizeof sfi
);
73 FILE_ATTRIBUTE_DIRECTORY
,
75 SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
| SHGFI_USEFILEATTRIBUTES
);
80 int CSysImageList::GetDirOpenIconIndex() const
83 SecureZeroMemory(&sfi
, sizeof sfi
);
87 FILE_ATTRIBUTE_DIRECTORY
,
89 SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
| SHGFI_USEFILEATTRIBUTES
| SHGFI_OPENICON
);
94 int CSysImageList::GetDefaultIconIndex() const
97 SecureZeroMemory(&sfi
, sizeof sfi
);
101 FILE_ATTRIBUTE_NORMAL
,
103 SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
| SHGFI_USEFILEATTRIBUTES
);
108 int CSysImageList::GetFileIconIndex(const CString
& file
) const
111 SecureZeroMemory(&sfi
, sizeof sfi
);
115 FILE_ATTRIBUTE_NORMAL
,
117 SHGFI_SYSICONINDEX
| SHGFI_SMALLICON
| SHGFI_USEFILEATTRIBUTES
);
122 int CSysImageList::GetPathIconIndex(const CTGitPath
& filePath
) const
124 CString strExtension
= filePath
.GetFileExtension();
125 strExtension
.MakeUpper();
126 IconIndexMap::iterator it
= m_indexCache
.lower_bound(strExtension
);
127 if (it
== m_indexCache
.end() || strExtension
< it
->first
)
129 // We don't have this extension in the map
130 int iconIndex
= GetFileIconIndex(filePath
.GetFilename());
131 it
= m_indexCache
.insert(it
, std::make_pair(strExtension
, iconIndex
));
133 // We must have found it