added first draft of RequestPull Dialog
[TortoiseGit.git] / src / Utils / SysImageList.cpp
blob044cbcfebb63301b76e1a61395b9276b00dfbc7f
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.
19 #include "stdafx.h"
20 #include "SysImageList.h"
21 #include "TGitPath.h"
24 // Singleton constructor and destructor (private)
26 CSysImageList * CSysImageList::instance = 0;
28 CSysImageList::CSysImageList()
30 SHFILEINFO ssfi;
31 TCHAR windir[MAX_PATH];
32 GetWindowsDirectory(windir, MAX_PATH); // MAX_PATH ok.
33 HIMAGELIST hSystemImageList =
34 (HIMAGELIST)SHGetFileInfo(
35 windir,
37 &ssfi, sizeof ssfi,
38 SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
39 Attach(hSystemImageList);
42 CSysImageList::~CSysImageList()
44 Detach();
48 // Singleton specific operations
50 CSysImageList& CSysImageList::GetInstance()
52 if (instance == 0)
53 instance = new CSysImageList;
54 return *instance;
57 void CSysImageList::Cleanup()
59 delete instance;
60 instance = 0;
64 // Operations
66 int CSysImageList::GetDirIconIndex() const
68 SHFILEINFO sfi;
69 SecureZeroMemory(&sfi, sizeof sfi);
71 SHGetFileInfo(
72 _T("Doesn't matter"),
73 FILE_ATTRIBUTE_DIRECTORY,
74 &sfi, sizeof sfi,
75 SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);
77 return sfi.iIcon;
80 int CSysImageList::GetDirOpenIconIndex() const
82 SHFILEINFO sfi;
83 SecureZeroMemory(&sfi, sizeof sfi);
85 SHGetFileInfo(
86 _T("Doesn't matter"),
87 FILE_ATTRIBUTE_DIRECTORY,
88 &sfi, sizeof sfi,
89 SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES | SHGFI_OPENICON);
91 return sfi.iIcon;
94 int CSysImageList::GetDefaultIconIndex() const
96 SHFILEINFO sfi;
97 SecureZeroMemory(&sfi, sizeof sfi);
99 SHGetFileInfo(
100 _T(""),
101 FILE_ATTRIBUTE_NORMAL,
102 &sfi, sizeof sfi,
103 SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);
105 return sfi.iIcon;
108 int CSysImageList::GetFileIconIndex(const CString& file) const
110 SHFILEINFO sfi;
111 SecureZeroMemory(&sfi, sizeof sfi);
113 SHGetFileInfo(
114 file,
115 FILE_ATTRIBUTE_NORMAL,
116 &sfi, sizeof sfi,
117 SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);
119 return sfi.iIcon;
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
134 return it->second;