icon caching
[reactos.git] / reactos / subsys / system / explorer / globals.h
1 /*
2 * Copyright 2003 Martin Fuchs
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19
20 //
21 // Explorer clone
22 //
23 // globals.h
24 //
25 // Martin Fuchs, 23.07.2003
26 //
27
28
29 /// management of file types
30 struct FileTypeInfo {
31 String _classname;
32 bool _neverShowExt;
33 };
34
35 struct FileTypeManager : public map<String, FileTypeInfo>
36 {
37 typedef map<String, FileTypeInfo> super;
38
39 const FileTypeInfo& operator[](String ext);
40 };
41
42
43 enum ICON_TYPE {
44 IT_STATIC,
45 IT_CACHED,
46 IT_DYNAMIC,
47 IT_SYSCACHE
48 };
49
50 enum ICON_ID {
51 ICID_UNKNOWN,
52 ICID_NONE,
53
54 ICID_FOLDER,
55 //ICID_DOCUMENT,
56 ICID_APP,
57 ICID_EXPLORER,
58
59 ICID_CONFIG,
60 ICID_DOCUMENTS,
61 ICID_FAVORITES,
62 ICID_INFO,
63 ICID_APPS,
64 ICID_SEARCH,
65 ICID_ACTION,
66 ICID_SEARCH_DOC,
67 ICID_PRINTER,
68 ICID_NETWORK,
69 ICID_COMPUTER,
70 ICID_LOGOFF,
71
72 ICID_DYNAMIC
73 };
74
75 struct Icon {
76 ICON_ID _id;
77 ICON_TYPE _itype;
78 HICON _hIcon;
79
80 Icon();
81 Icon(ICON_ID id, UINT nid);
82 Icon(ICON_TYPE itype, int id, HICON hIcon);
83 };
84
85 struct IconCache {
86 void init();
87
88 const Icon& extract(IExtractIcon* pExtract, LPCTSTR path, int idx);
89 const Icon& extract_from_file(LPCTSTR path, int idx);
90
91 const Icon& add(HICON hIcon);
92 const Icon& add_cached(HICON hIcon, LPCTSTR path, int idx);
93
94 const Icon& get_icon(int icon_id);
95 HBITMAP get_icon_bitmap(int icon_id, HBRUSH hbrBkgnd, HDC hdc);
96
97 void free_icon(int icon_id);
98
99 protected:
100 typedef map<int, Icon> IconMap;
101
102 typedef pair<String, int> CachePair;
103 typedef map<CachePair, ICON_ID> CacheMap;
104
105 static int s_next_id;
106
107 IconMap _icons;
108 CacheMap _cache_map;
109 };
110
111
112 /// create a bitmap from an icon
113 extern HBITMAP create_bitmap_from_icon(HICON hIcon, HBRUSH hbrush_bkgnd, HDC hdc_wnd);
114
115
116 /// structure containing global variables of Explorer
117 extern struct ExplorerGlobals
118 {
119 ExplorerGlobals();
120
121 void init(HINSTANCE hInstance);
122
123 HINSTANCE _hInstance;
124 ATOM _hframeClass;
125 UINT _cfStrFName;
126 HWND _hMainWnd;
127 bool _prescan_nodes;
128 bool _desktop_mode;
129
130 FILE* _log;
131
132 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
133 DWORD(STDAPICALLTYPE* _SHRestricted)(RESTRICTIONS);
134 #endif
135
136 FileTypeManager _ftype_mgr;
137 IconCache _icon_cache;
138 } g_Globals;
139
140
141 /// convenient loading of string resources
142 struct ResString : public String
143 {
144 ResString(UINT nid);
145 };
146
147 /// convenient loading of standard (32x32) icon resources
148 struct ResIcon
149 {
150 ResIcon(UINT nid);
151
152 operator HICON() const {return _hIcon;}
153
154 protected:
155 HICON _hIcon;
156 };
157
158 /// convenient loading of small (16x16) icon resources
159 struct SmallIcon
160 {
161 SmallIcon(UINT nid);
162
163 operator HICON() const {return _hIcon;}
164
165 protected:
166 HICON _hIcon;
167 };
168
169 /// convenient loading of icon resources with specified sizes
170 struct ResIconEx
171 {
172 ResIconEx(UINT nid, int w, int h);
173
174 operator HICON() const {return _hIcon;}
175
176 protected:
177 HICON _hIcon;
178 };
179
180 /// set big and small icons out of the resources for a window
181 extern void SetWindowIcon(HWND hwnd, UINT nid);
182
183 /// convenient loading of bitmap resources
184 struct ResBitmap
185 {
186 ResBitmap(UINT nid);
187 ~ResBitmap() {DeleteObject(_hBmp);}
188
189 operator HBITMAP() const {return _hBmp;}
190
191 protected:
192 HBITMAP _hBmp;
193 };