Fix warning
[TortoiseGit.git] / src / Utils / SysImageList.h
blobcfd2b2b8fc6766207a32336c60acbfa708b44796
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2017 - TortoiseGit
4 // Copyright (C) 2003-2006,2009-2010,2015,2017 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #pragma once
22 class CTGitPath;
24 /**
25 * \ingroup Utils
26 * Provides simplified access to the system icons. Only small system icons
27 * are supported.
29 * \note This class is implemented as a singleton.
30 * The singleton instance is created when first accessed. See SYS_IMAGE_LIST() function
31 * easy access of the singleton instance. All
33 class CSysImageList : public CImageList
35 // Singleton constructor and destructor (private)
36 private:
37 CSysImageList();
38 ~CSysImageList();
39 // prevent cloning
40 CSysImageList(const CSysImageList&) = delete;
41 CSysImageList& operator=(const CSysImageList&) = delete;
43 // Singleton specific operations
44 public:
45 /**
46 * Returns a reference to the one and only instance of this class.
48 static CSysImageList& GetInstance();
49 /**
50 * Frees all allocated resources (if necessary). Don't call this
51 * function when the image list is currently bound to any control!
53 static void Cleanup();
55 // Operations
56 public:
57 /**
58 * Returns the icon index for a directory.
60 int GetDirIconIndex();
61 /**
62 * Returns the icon index for a directory that's open (e.g. for a tree control)
64 int GetDirOpenIconIndex();
65 /**
66 * Returns the icon index for a file which has no special icon associated.
68 int GetDefaultIconIndex();
69 /**
70 * Get the index for a Git-style path file.
71 * Uses a cache to speed things up
73 int GetPathIconIndex(const CTGitPath& file);
74 int GetPathIconIndex(const CString& file);
76 /**
77 * Adds an icon to the image list and returns the index of the
78 * added icon (or -1 if adding the icon fails)
80 int AddIcon(const HICON hIcon);
82 private:
83 /**
84 * Returns the icon index for the specified \a file. Only the file extension
85 * is used to determine the file's icon.
87 int GetFileIconIndex(const CString& file);
88 int GetFileIcon(LPCTSTR file, DWORD attributes, UINT extraFlags);
90 static CSysImageList *instance;
92 HIMAGELIST hSystemImageList;
93 mutable std::map<CString, int> m_indexCache;
94 int m_dirIconIndex;
95 int m_dirOpenIconIndex;
96 int m_defaultIconIndex;
101 * \relates CSysImageList
102 * Singleton access for CSysImageList.
104 inline CSysImageList& SYS_IMAGE_LIST() { return CSysImageList::GetInstance(); }