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