- Use a separate icon for minimizing windows.
[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_BOOKMARK,
84 ICID_MINIMIZE,
85
86 ICID_DYNAMIC
87 };
88
89 struct Icon {
90 Icon();
91 Icon(ICON_ID id, UINT nid);
92 Icon(ICON_TYPE itype, int id, HICON hIcon);
93 Icon(ICON_TYPE itype, int id, int sys_idx);
94
95 operator ICON_ID() const {return _id;}
96
97 void draw(HDC hdc, int x, int y, int cx, int cy, COLORREF bk_color, HBRUSH bk_brush) const;
98 HBITMAP create_bitmap(COLORREF bk_color, HBRUSH hbrBkgnd, HDC hdc_wnd) const;
99 int add_to_imagelist(HIMAGELIST himl, HDC hdc_wnd, COLORREF bk_color=GetSysColor(COLOR_WINDOW), HBRUSH bk_brush=GetSysColorBrush(COLOR_WINDOW)) const;
100
101 int get_sysiml_idx() const {return _itype==IT_SYSCACHE? _sys_idx: -1;}
102 HICON get_hicon() const {return _itype!=IT_SYSCACHE? _hicon: 0;}
103
104 bool destroy() {if (_itype == IT_DYNAMIC) {DestroyIcon(_hicon); return true;} else return false;}
105
106 protected:
107 ICON_ID _id;
108 ICON_TYPE _itype;
109 HICON _hicon;
110 int _sys_idx;
111 };
112
113 struct SysCacheIcon : public Icon {
114 SysCacheIcon(int id, int sys_idx)
115 : Icon(IT_SYSCACHE, id, sys_idx) {}
116 };
117
118 struct IconCache {
119 IconCache() : _himlSys_small(0) {}
120
121 void init();
122
123 const Icon& extract(LPCTSTR path, ICONCACHE_FLAGS flags=ICF_NORMAL);
124 const Icon& extract(LPCTSTR path, int idx, ICONCACHE_FLAGS flags=ICF_HICON);
125 const Icon& extract(IExtractIcon* pExtract, LPCTSTR path, int idx, ICONCACHE_FLAGS flags=ICF_HICON);
126
127 const Icon& add(HICON hIcon, ICON_TYPE type=IT_DYNAMIC);
128 const Icon& add(int sys_idx/*, ICON_TYPE type=IT_SYSCACHE*/);
129
130 const Icon& get_icon(int icon_id);
131
132 HIMAGELIST get_sys_imagelist() const {return _himlSys_small;}
133
134 void free_icon(int icon_id);
135
136 protected:
137 static int s_next_id;
138
139 typedef map<int, Icon> IconMap;
140 IconMap _icons;
141
142 typedef pair<String,int/*ICONCACHE_FLAGS*/> CacheKey;
143 typedef map<CacheKey, ICON_ID> PathCacheMap;
144 PathCacheMap _pathCache;
145
146 typedef pair<String,pair<int,int/*ICONCACHE_FLAGS*/> > IdxCacheKey;
147 typedef map<IdxCacheKey, ICON_ID> IdxCacheMap;
148 IdxCacheMap _idxCache;
149
150 HIMAGELIST _himlSys_small;
151 };
152
153
154 #define ICON_SIZE_X GetSystemMetrics(large_icons? SM_CXICON: SM_CXSMICON)
155 #define ICON_SIZE_Y GetSystemMetrics(large_icons? SM_CYICON: SM_CYSMICON)
156
157
158 /// create a bitmap from an icon
159 extern HBITMAP create_bitmap_from_icon(HICON hIcon, HBRUSH hbrush_bkgnd, HDC hdc_wnd/*, bool large_icons*/);
160
161 /// add icon with alpha channel to imagelist using the specified background color
162 extern int ImageList_AddAlphaIcon(HIMAGELIST himl, HICON hIcon, HBRUSH hbrush_bkgnd, HDC hdc_wnd);
163
164 /// retrieve icon from window
165 extern HICON get_window_icon_small(HWND hwnd);
166 extern HICON get_window_icon_big(HWND hwnd, bool allow_from_class=true);
167
168
169 /// desktop management
170 #ifdef _USE_HDESK
171
172 typedef auto_ptr<struct DesktopThread> DesktopThreadPtr;
173
174 struct Desktop
175 {
176 HDESK _hdesktop;
177 // HWINSTA _hwinsta;
178 DesktopThreadPtr _pThread;
179 WindowHandle _hwndDesktop;
180
181 Desktop(HDESK hdesktop=0/*, HWINSTA hwinsta=0*/);
182 ~Desktop();
183 };
184
185 typedef auto_ptr<Desktop> DesktopPtr;
186 typedef DesktopPtr DesktopRef;
187
188 /// Thread class for additional desktops
189 struct DesktopThread : public Thread
190 {
191 DesktopThread(Desktop& desktop)
192 : _desktop(desktop)
193 {
194 }
195
196 int Run();
197
198 protected:
199 Desktop& _desktop;
200 };
201
202 #else
203
204 typedef pair<HWND, DWORD> MinimizeStruct;
205
206 struct Desktop
207 {
208 set<HWND> _windows;
209 WindowHandle _hwndForeground;
210 list<MinimizeStruct> _minimized;
211 };
212 typedef Desktop DesktopRef;
213
214 #endif
215
216
217 #define DESKTOP_COUNT 4
218
219 struct Desktops : public vector<DesktopRef>
220 {
221 Desktops();
222 ~Desktops();
223
224 void init();
225 void SwitchToDesktop(int idx);
226 void ToggleMinimize();
227
228 #ifdef _USE_HDESK
229 DesktopRef& get_current_Desktop() {return (*this)[_current_desktop];}
230 #endif
231
232 int _current_desktop;
233 };
234
235
236 /// structure containing global variables of Explorer
237 extern struct ExplorerGlobals
238 {
239 ExplorerGlobals();
240
241 void init(HINSTANCE hInstance);
242
243 void read_persistent();
244 void write_persistent();
245
246 XMLPos get_cfg();
247 XMLPos get_cfg(const char* path);
248
249 HINSTANCE _hInstance;
250 UINT _cfStrFName;
251
252 #ifndef ROSSHELL
253 ATOM _hframeClass;
254 HWND _hMainWnd;
255 bool _desktop_mode;
256 bool _prescan_nodes;
257 #endif
258
259 FILE* _log;
260
261 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
262 DWORD(STDAPICALLTYPE* _SHRestricted)(RESTRICTIONS);
263 #endif
264
265 FileTypeManager _ftype_mgr;
266 IconCache _icon_cache;
267
268 HWND _hwndDesktopBar;
269 HWND _hwndShellView;
270 HWND _hwndDesktop;
271
272 Desktops _desktops;
273
274 XMLDoc _cfg;
275 String _cfg_dir;
276 String _cfg_path;
277
278 Favorites _favorites;
279 String _favorites_path;
280 } g_Globals;
281
282
283 /// convenient loading of string resources
284 struct ResString : public String
285 {
286 ResString(UINT nid);
287 };
288
289 /// convenient loading of standard (32x32) icon resources
290 struct ResIcon
291 {
292 ResIcon(UINT nid);
293
294 operator HICON() const {return _hicon;}
295
296 protected:
297 HICON _hicon;
298 };
299
300 /// convenient loading of small (16x16) icon resources
301 struct SmallIcon
302 {
303 SmallIcon(UINT nid);
304
305 operator HICON() const {return _hicon;}
306
307 protected:
308 HICON _hicon;
309 };
310
311 /// convenient loading of icon resources with specified sizes
312 struct ResIconEx
313 {
314 ResIconEx(UINT nid, int w, int h);
315
316 operator HICON() const {return _hicon;}
317
318 protected:
319 HICON _hicon;
320 };
321
322 /// set big and small icons out of the resources for a window
323 extern void SetWindowIcon(HWND hwnd, UINT nid);
324
325 /// convenient loading of bitmap resources
326 struct ResBitmap
327 {
328 ResBitmap(UINT nid);
329 ~ResBitmap() {DeleteObject(_hBmp);}
330
331 operator HBITMAP() const {return _hBmp;}
332
333 protected:
334 HBITMAP _hBmp;
335 };