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