Make more use of SSL
[TortoiseGit.git] / src / Utils / SysImageList.cpp
blob36525b91b650cc05bd83cd52f6aa26897217d51f
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2003-2006, 2008-2010 - 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.
19 #include "stdafx.h"
20 #include "SysImageList.h"
21 #include "TGitPath.h"
23 // Singleton constructor and destructor (private)
25 CSysImageList * CSysImageList::instance = 0;
27 CSysImageList::CSysImageList()
29 SHFILEINFO ssfi;
30 TCHAR windir[MAX_PATH] = {0};
31 GetWindowsDirectory(windir, _countof(windir)); // MAX_PATH ok.
32 HIMAGELIST hSystemImageList =
33 (HIMAGELIST)SHGetFileInfo(
34 windir,
36 &ssfi, sizeof ssfi,
37 SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
38 Attach(hSystemImageList);
41 CSysImageList::~CSysImageList()
43 Detach();
46 // Singleton specific operations
48 CSysImageList& CSysImageList::GetInstance()
50 if (instance == 0)
51 instance = new CSysImageList;
52 return *instance;
55 void CSysImageList::Cleanup()
57 delete instance;
58 instance = 0;
61 // Operations
63 int CSysImageList::AddIcon(const HICON hIcon)
65 return this->Add(hIcon);
68 int CSysImageList::GetDirIconIndex() const
70 return GetFileIcon(_T("Doesn't matter"), FILE_ATTRIBUTE_DIRECTORY, 0);
73 int CSysImageList::GetDirOpenIconIndex() const
75 return GetFileIcon(_T("Doesn't matter"), FILE_ATTRIBUTE_DIRECTORY, SHGFI_OPENICON);
78 int CSysImageList::GetDefaultIconIndex() const
80 return GetFileIcon(_T(""), FILE_ATTRIBUTE_NORMAL, 0);
83 int CSysImageList::GetFileIconIndex(const CString& file) const
85 return GetFileIcon(file, FILE_ATTRIBUTE_NORMAL, 0);
88 int CSysImageList::GetPathIconIndex(const CTGitPath& filePath) const
90 CString strExtension = filePath.GetFileExtension();
91 strExtension.MakeUpper();
92 IconIndexMap::iterator it = m_indexCache.lower_bound(strExtension);
93 if (it == m_indexCache.end() || strExtension < it->first)
95 // We don't have this extension in the map
96 int iconIndex = GetFileIconIndex(filePath.GetFilename());
97 it = m_indexCache.insert(it, std::make_pair(strExtension, iconIndex));
99 // We must have found it
100 return it->second;
103 int CSysImageList::GetFileIcon( LPCTSTR file, DWORD attributes, UINT extraFlags ) const
105 SHFILEINFO sfi;
106 SecureZeroMemory(&sfi, sizeof sfi);
108 SHGetFileInfo(
109 file,
110 attributes,
111 &sfi, sizeof sfi,
112 SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES | extraFlags);
114 return sfi.iIcon;