include explorer windows in desktop switching
[reactos.git] / reactos / subsys / system / explorer / globals.h
1 /*
2 * Copyright 2003 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 /// management of file types
30 struct FileTypeInfo {
31 String _classname;
32 String _displayname;
33 bool _neverShowExt;
34 };
35
36 struct FileTypeManager : public map<String, FileTypeInfo>
37 {
38 typedef map<String, FileTypeInfo> super;
39
40 const FileTypeInfo& operator[](String ext);
41
42 static bool is_exe_file(LPCTSTR ext);
43
44 LPCTSTR set_type(struct Entry* entry, bool dont_hide_ext=false);
45 };
46
47
48 enum ICON_TYPE {
49 IT_STATIC,
50 IT_CACHED,
51 IT_DYNAMIC,
52 IT_SYSCACHE
53 };
54
55 enum ICON_ID {
56 ICID_UNKNOWN,
57 ICID_NONE,
58
59 ICID_FOLDER,
60 //ICID_DOCUMENT,
61 ICID_APP,
62 ICID_EXPLORER,
63
64 ICID_CONFIG,
65 ICID_DOCUMENTS,
66 ICID_FAVORITES,
67 ICID_INFO,
68 ICID_APPS,
69 ICID_SEARCH,
70 ICID_ACTION,
71 ICID_SEARCH_DOC,
72 ICID_PRINTER,
73 ICID_NETWORK,
74 ICID_COMPUTER,
75 ICID_LOGOFF,
76
77 ICID_DYNAMIC
78 };
79
80 struct Icon {
81 Icon();
82 Icon(ICON_ID id, UINT nid);
83 Icon(ICON_TYPE itype, int id, HICON hIcon);
84 Icon(ICON_TYPE itype, int id, int sys_idx);
85
86 operator ICON_ID() const {return _id;}
87
88 void draw(HDC hdc, int x, int y, int cx, int cy, COLORREF bk_color, HBRUSH bk_brush) const;
89 HBITMAP create_bitmap(COLORREF bk_color, HBRUSH hbrBkgnd, HDC hdc_wnd) const;
90
91 int get_sysiml_idx() const {return _itype==IT_SYSCACHE? _sys_idx: -1;}
92
93 bool destroy() {if (_itype == IT_DYNAMIC) {DestroyIcon(_hicon); return true;} else return false;}
94
95 protected:
96 ICON_ID _id;
97 ICON_TYPE _itype;
98 HICON _hicon;
99 int _sys_idx;
100 };
101
102 struct SysCacheIcon : public Icon {
103 SysCacheIcon(int id, int sys_idx)
104 : Icon(IT_SYSCACHE, id, sys_idx) {}
105 };
106
107 struct IconCache {
108 IconCache() : _himlSys(0) {}
109
110 void init();
111
112 const Icon& extract(const String& path);
113 const Icon& extract(LPCTSTR path, int idx);
114 const Icon& extract(IExtractIcon* pExtract, LPCTSTR path, int idx);
115
116 const Icon& add(HICON hIcon, ICON_TYPE type=IT_DYNAMIC);
117 const Icon& add(int sys_idx/*, ICON_TYPE type=IT_SYSCACHE*/);
118
119 const Icon& get_icon(int icon_id);
120 HIMAGELIST get_sys_imagelist() const {return _himlSys;}
121
122 void free_icon(int icon_id);
123
124 protected:
125 static int s_next_id;
126
127 typedef map<int, Icon> IconMap;
128 IconMap _icons;
129
130 typedef map<String, ICON_ID> PathMap;
131 PathMap _pathMap;
132
133 typedef pair<String, int> CachePair;
134 typedef map<CachePair, ICON_ID> PathIdxMap;
135 PathIdxMap _pathIdxMap;
136
137 HIMAGELIST _himlSys;
138 };
139
140
141 /// create a bitmap from an icon
142 extern HBITMAP create_bitmap_from_icon(HICON hIcon, HBRUSH hbrush_bkgnd, HDC hdc_wnd);
143
144
145 /// desktop management
146 #ifdef _USE_HDESK
147
148 typedef auto_ptr<struct DesktopThread> DesktopThreadPtr;
149
150 struct Desktop
151 {
152 HDESK _hdesktop;
153 // HWINSTA _hwinsta;
154 DesktopThreadPtr _pThread;
155 WindowHandle _hwndDesktop;
156
157 Desktop(HDESK hdesktop=0/*, HWINSTA hwinsta=0*/);
158 ~Desktop();
159 };
160
161 typedef auto_ptr<Desktop> DesktopPtr;
162 typedef DesktopPtr DesktopRef;
163
164 /// Thread class for additional desktops
165 struct DesktopThread : public Thread
166 {
167 DesktopThread(Desktop& desktop)
168 : _desktop(desktop)
169 {
170 }
171
172 int Run();
173
174 protected:
175 Desktop& _desktop;
176 };
177
178 #else
179
180 struct Desktop
181 {
182 set<HWND> _windows;
183 };
184 typedef Desktop DesktopRef;
185
186 #endif
187
188
189 #define DESKTOP_COUNT 4
190
191 struct Desktops : public vector<DesktopRef>
192 {
193 Desktops();
194 ~Desktops();
195
196 void init();
197 void SwitchToDesktop(int idx);
198
199 #ifdef _USE_HDESK
200 DesktopRef& get_current_Desktop() {return (*this)[_current_desktop];}
201 #endif
202
203 int _current_desktop;
204 };
205
206
207 /// structure containing global variables of Explorer
208 extern struct ExplorerGlobals
209 {
210 ExplorerGlobals();
211
212 void init(HINSTANCE hInstance);
213
214 HINSTANCE _hInstance;
215 ATOM _hframeClass;
216 UINT _cfStrFName;
217 HWND _hMainWnd;
218 bool _prescan_nodes;
219 bool _desktop_mode;
220
221 FILE* _log;
222
223 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
224 DWORD(STDAPICALLTYPE* _SHRestricted)(RESTRICTIONS);
225 #endif
226
227 FileTypeManager _ftype_mgr;
228 IconCache _icon_cache;
229
230 HWND _hwndDesktopBar;
231 HWND _hwndShellView;
232 HWND _hwndDesktop;
233
234 Desktops _desktops;
235 } g_Globals;
236
237
238 /// convenient loading of string resources
239 struct ResString : public String
240 {
241 ResString(UINT nid);
242 };
243
244 /// convenient loading of standard (32x32) icon resources
245 struct ResIcon
246 {
247 ResIcon(UINT nid);
248
249 operator HICON() const {return _hicon;}
250
251 protected:
252 HICON _hicon;
253 };
254
255 /// convenient loading of small (16x16) icon resources
256 struct SmallIcon
257 {
258 SmallIcon(UINT nid);
259
260 operator HICON() const {return _hicon;}
261
262 protected:
263 HICON _hicon;
264 };
265
266 /// convenient loading of icon resources with specified sizes
267 struct ResIconEx
268 {
269 ResIconEx(UINT nid, int w, int h);
270
271 operator HICON() const {return _hicon;}
272
273 protected:
274 HICON _hicon;
275 };
276
277 /// set big and small icons out of the resources for a window
278 extern void SetWindowIcon(HWND hwnd, UINT nid);
279
280 /// convenient loading of bitmap resources
281 struct ResBitmap
282 {
283 ResBitmap(UINT nid);
284 ~ResBitmap() {DeleteObject(_hBmp);}
285
286 operator HBITMAP() const {return _hBmp;}
287
288 protected:
289 HBITMAP _hBmp;
290 };