OSDN Git Service

Build Success
[tortoisegit/TortoiseGitJp.git] / Utils / SysImageList.cpp
1 // TortoiseSVN - a Windows shell extension for easy version control\r
2 \r
3 // Copyright (C) 2003-2006, 2008 - TortoiseSVN\r
4 \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
9 \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
14 \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
18 //\r
19 #include "stdafx.h"\r
20 #include "SysImageList.h"\r
21 #include "TSVNPath.h"\r
22 \r
23 \r
24 // Singleton constructor and destructor (private)\r
25 \r
26 CSysImageList * CSysImageList::instance = 0;\r
27 \r
28 CSysImageList::CSysImageList()\r
29 {\r
30         SHFILEINFO ssfi;\r
31         TCHAR windir[MAX_PATH];\r
32         GetWindowsDirectory(windir, MAX_PATH);  // MAX_PATH ok.\r
33         HIMAGELIST hSystemImageList =\r
34                 (HIMAGELIST)SHGetFileInfo(\r
35                         windir,\r
36                         0,\r
37                         &ssfi, sizeof ssfi,\r
38                         SHGFI_SYSICONINDEX | SHGFI_SMALLICON);\r
39         Attach(hSystemImageList);\r
40 }\r
41 \r
42 CSysImageList::~CSysImageList()\r
43 {\r
44         Detach();\r
45 }\r
46 \r
47 \r
48 // Singleton specific operations\r
49 \r
50 CSysImageList& CSysImageList::GetInstance()\r
51 {\r
52         if (instance == 0)\r
53                 instance = new CSysImageList;\r
54         return *instance;\r
55 }\r
56 \r
57 void CSysImageList::Cleanup()\r
58 {\r
59         delete instance;\r
60         instance = 0;\r
61 }\r
62 \r
63 \r
64 // Operations\r
65 \r
66 int CSysImageList::GetDirIconIndex() const\r
67 {\r
68         SHFILEINFO sfi;\r
69         SecureZeroMemory(&sfi, sizeof sfi);\r
70 \r
71         SHGetFileInfo(\r
72                 _T("Doesn't matter"),\r
73                 FILE_ATTRIBUTE_DIRECTORY,\r
74                 &sfi, sizeof sfi,\r
75                 SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);\r
76 \r
77         return sfi.iIcon;\r
78 }\r
79 \r
80 int CSysImageList::GetDirOpenIconIndex() const\r
81 {\r
82         SHFILEINFO sfi;\r
83         SecureZeroMemory(&sfi, sizeof sfi);\r
84 \r
85         SHGetFileInfo(\r
86                 _T("Doesn't matter"),\r
87                 FILE_ATTRIBUTE_DIRECTORY,\r
88                 &sfi, sizeof sfi,\r
89                 SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES | SHGFI_OPENICON);\r
90 \r
91         return sfi.iIcon;\r
92 }\r
93 \r
94 int CSysImageList::GetDefaultIconIndex() const\r
95 {\r
96         SHFILEINFO sfi;\r
97         SecureZeroMemory(&sfi, sizeof sfi);\r
98 \r
99         SHGetFileInfo(\r
100                 _T(""),\r
101                 FILE_ATTRIBUTE_NORMAL,\r
102                 &sfi, sizeof sfi,\r
103                 SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);\r
104 \r
105         return sfi.iIcon;\r
106 }\r
107 \r
108 int CSysImageList::GetFileIconIndex(const CString& file) const\r
109 {\r
110         SHFILEINFO sfi;\r
111         SecureZeroMemory(&sfi, sizeof sfi);\r
112 \r
113         SHGetFileInfo(\r
114                 file,\r
115                 FILE_ATTRIBUTE_NORMAL,\r
116                 &sfi, sizeof sfi,\r
117                 SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_USEFILEATTRIBUTES);\r
118 \r
119         return sfi.iIcon;\r
120 }\r
121 \r
122 int CSysImageList::GetPathIconIndex(const CTSVNPath& filePath) const\r
123 {\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
128         {\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
132         }\r
133         // We must have found it\r
134         return it->second;\r
135 }\r