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