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