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