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