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