- Split up the icon resources so each start menu entry has it's own icon
[reactos.git] / reactos / subsys / system / explorer / globals.h
1 /*
2 * Copyright 2003, 2004 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 #include "utility/xmlstorage.h"
30
31 using namespace XMLStorage;
32
33 #include "taskbar/favorites.h"
34
35
36 /// management of file types
37 struct FileTypeInfo {
38 String _classname;
39 String _displayname;
40 bool _neverShowExt;
41 };
42
43 struct FileTypeManager : public map<String, FileTypeInfo>
44 {
45 typedef map<String, FileTypeInfo> super;
46
47 const FileTypeInfo& operator[](String ext);
48
49 static bool is_exe_file(LPCTSTR ext);
50
51 LPCTSTR set_type(struct Entry* entry, bool dont_hide_ext=false);
52 };
53
54
55 enum ICON_TYPE {
56 IT_STATIC,
57 IT_CACHED,
58 IT_DYNAMIC,
59 IT_SYSCACHE
60 };
61
62 enum ICON_ID {
63 ICID_UNKNOWN,
64 ICID_NONE,
65
66 ICID_FOLDER,
67 //ICID_DOCUMENT,
68 ICID_APP,
69 ICID_EXPLORER,
70
71 ICID_CONFIG,
72 ICID_DOCUMENTS,
73 ICID_FAVORITES,
74 ICID_INFO,
75 ICID_APPS,
76 ICID_SEARCH,
77 ICID_ACTION,
78 ICID_SEARCH_DOC,
79 ICID_PRINTER,
80 ICID_NETWORK,
81 ICID_COMPUTER,
82 ICID_LOGOFF,
83 ICID_SHUTDOWN,
84 ICID_BOOKMARK,
85 ICID_MINIMIZE,
86 ICID_CONTROLPAN,
87 ICID_DESKSETTING,
88 ICID_NETCONNS,
89 ICID_ADMINISTRATION,
90
91 ICID_DYNAMIC
92 };
93
94 struct Icon {
95 Icon();
96 Icon(ICON_ID id, UINT nid);
97 Icon(ICON_TYPE itype, int id, HICON hIcon);
98 Icon(ICON_TYPE itype, int id, int sys_idx);
99
100 operator ICON_ID() const {return _id;}
101
102 void draw(HDC hdc, int x, int y, int cx, int cy, COLORREF bk_color, HBRUSH bk_brush) const;
103 HBITMAP create_bitmap(COLORREF bk_color, HBRUSH hbrBkgnd, HDC hdc_wnd) const;
104 int add_to_imagelist(HIMAGELIST himl, HDC hdc_wnd, COLORREF bk_color=GetSysColor(COLOR_WINDOW), HBRUSH bk_brush=GetSysColorBrush(COLOR_WINDOW)) const;
105
106 int get_sysiml_idx() const {return _itype==IT_SYSCACHE? _sys_idx: -1;}
107 HICON get_hicon() const {return _itype!=IT_SYSCACHE? _hicon: 0;}
108
109 bool destroy() {if (_itype == IT_DYNAMIC) {DestroyIcon(_hicon); return true;} else return false;}
110
111 protected:
112 ICON_ID _id;
113 ICON_TYPE _itype;
114 HICON _hicon;
115 int _sys_idx;
116 };
117
118 struct SysCacheIcon : public Icon {
119 SysCacheIcon(int id, int sys_idx)
120 : Icon(IT_SYSCACHE, id, sys_idx) {}
121 };
122
123 struct IconCache {
124 IconCache() : _himlSys_small(0) {}
125
126 void init();
127
128 const Icon& extract(LPCTSTR path, ICONCACHE_FLAGS flags=ICF_NORMAL);
129 const Icon& extract(LPCTSTR path, int idx, ICONCACHE_FLAGS flags=ICF_HICON);
130 const Icon& extract(IExtractIcon* pExtract, LPCTSTR path, int idx, ICONCACHE_FLAGS flags=ICF_HICON);
131
132 const Icon& add(HICON hIcon, ICON_TYPE type=IT_DYNAMIC);
133 const Icon& add(int sys_idx/*, ICON_TYPE type=IT_SYSCACHE*/);
134
135 const Icon& get_icon(int icon_id);
136
137 HIMAGELIST get_sys_imagelist() const {return _himlSys_small;}
138
139 void free_icon(int icon_id);
140
141 protected:
142 static int s_next_id;
143
144 typedef map<int, Icon> IconMap;
145 IconMap _icons;
146
147 typedef pair<String,int/*ICONCACHE_FLAGS*/> CacheKey;
148 typedef map<CacheKey, ICON_ID> PathCacheMap;
149 PathCacheMap _pathCache;
150
151 typedef pair<String,pair<int,int/*ICONCACHE_FLAGS*/> > IdxCacheKey;
152 typedef map<IdxCacheKey, ICON_ID> IdxCacheMap;
153 IdxCacheMap _idxCache;
154
155 HIMAGELIST _himlSys_small;
156 };
157
158
159 #define ICON_SIZE_X GetSystemMetrics(large_icons? SM_CXICON: SM_CXSMICON)
160 #define ICON_SIZE_Y GetSystemMetrics(large_icons? SM_CYICON: SM_CYSMICON)
161
162
163 /// create a bitmap from an icon
164 extern HBITMAP create_bitmap_from_icon(HICON hIcon, HBRUSH hbrush_bkgnd, HDC hdc_wnd/*, bool large_icons*/);
165
166 /// add icon with alpha channel to imagelist using the specified background color
167 extern int ImageList_AddAlphaIcon(HIMAGELIST himl, HICON hIcon, HBRUSH hbrush_bkgnd, HDC hdc_wnd);
168
169 /// retrieve icon from window
170 extern HICON get_window_icon_small(HWND hwnd);
171 extern HICON get_window_icon_big(HWND hwnd, bool allow_from_class=true);
172
173
174 /// desktop management
175 #ifdef _USE_HDESK
176
177 typedef auto_ptr<struct DesktopThread> DesktopThreadPtr;
178
179 struct Desktop
180 {
181 HDESK _hdesktop;
182 // HWINSTA _hwinsta;
183 DesktopThreadPtr _pThread;
184 WindowHandle _hwndDesktop;
185
186 Desktop(HDESK hdesktop=0/*, HWINSTA hwinsta=0*/);
187 ~Desktop();
188 };
189
190 typedef auto_ptr<Desktop> DesktopPtr;
191 typedef DesktopPtr DesktopRef;
192
193 /// Thread class for additional desktops
194 struct DesktopThread : public Thread
195 {
196 DesktopThread(Desktop& desktop)
197 : _desktop(desktop)
198 {
199 }
200
201 int Run();
202
203 protected:
204 Desktop& _desktop;
205 };
206
207 #else
208
209 typedef pair<HWND, DWORD> MinimizeStruct;
210
211 struct Desktop
212 {
213 set<HWND> _windows;
214 WindowHandle _hwndForeground;
215 list<MinimizeStruct> _minimized;
216 };
217 typedef Desktop DesktopRef;
218
219 #endif
220
221
222 #define DESKTOP_COUNT 4
223
224 struct Desktops : public vector<DesktopRef>
225 {
226 Desktops();
227 ~Desktops();
228
229 void init();
230 void SwitchToDesktop(int idx);
231 void ToggleMinimize();
232
233 #ifdef _USE_HDESK
234 DesktopRef& get_current_Desktop() {return (*this)[_current_desktop];}
235 #endif
236
237 int _current_desktop;
238 };
239
240
241 /// structure containing global variables of Explorer
242 extern struct ExplorerGlobals
243 {
244 ExplorerGlobals();
245
246 void init(HINSTANCE hInstance);
247
248 void read_persistent();
249 void write_persistent();
250
251 XMLPos get_cfg();
252 XMLPos get_cfg(const char* path);
253
254 HINSTANCE _hInstance;
255 UINT _cfStrFName;
256
257 #ifndef ROSSHELL
258 ATOM _hframeClass;
259 HWND _hMainWnd;
260 bool _desktop_mode;
261 bool _prescan_nodes;
262 #endif
263
264 FILE* _log;
265
266 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
267 DWORD(STDAPICALLTYPE* _SHRestricted)(RESTRICTIONS);
268 #endif
269
270 FileTypeManager _ftype_mgr;
271 IconCache _icon_cache;
272
273 HWND _hwndDesktopBar;
274 HWND _hwndShellView;
275 HWND _hwndDesktop;
276
277 Desktops _desktops;
278
279 XMLDoc _cfg;
280 String _cfg_dir;
281 String _cfg_path;
282
283 Favorites _favorites;
284 String _favorites_path;
285 } g_Globals;
286
287
288 /// convenient loading of string resources
289 struct ResString : public String
290 {
291 ResString(UINT nid);
292 };
293
294 /// convenient loading of standard (32x32) icon resources
295 struct ResIcon
296 {
297 ResIcon(UINT nid);
298
299 operator HICON() const {return _hicon;}
300
301 protected:
302 HICON _hicon;
303 };
304
305 /// convenient loading of small (16x16) icon resources
306 struct SmallIcon
307 {
308 SmallIcon(UINT nid);
309
310 operator HICON() const {return _hicon;}
311
312 protected:
313 HICON _hicon;
314 };
315
316 /// convenient loading of icon resources with specified sizes
317 struct ResIconEx
318 {
319 ResIconEx(UINT nid, int w, int h);
320
321 operator HICON() const {return _hicon;}
322
323 protected:
324 HICON _hicon;
325 };
326
327 /// set big and small icons out of the resources for a window
328 extern void SetWindowIcon(HWND hwnd, UINT nid);
329
330 /// convenient loading of bitmap resources
331 struct ResBitmap
332 {
333 ResBitmap(UINT nid);
334 ~ResBitmap() {DeleteObject(_hBmp);}
335
336 operator HBITMAP() const {return _hBmp;}
337
338 protected:
339 HBITMAP _hBmp;
340 };