more rosshell separations
[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, lean version
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
147 typedef pair<HWND, DWORD> MinimizeStruct;
148
149 struct Desktop
150 {
151 set<HWND> _windows;
152 WindowHandle _hwndForeground;
153 list<MinimizeStruct> _minimized;
154 };
155 typedef Desktop DesktopRef;
156
157
158 #define DESKTOP_COUNT 4
159
160 struct Desktops : public vector<DesktopRef>
161 {
162 Desktops();
163 ~Desktops();
164
165 void init();
166 void SwitchToDesktop(int idx);
167 void ToggleMinimize();
168
169 int _current_desktop;
170 };
171
172
173 /// structure containing global variables of Explorer
174 extern struct ExplorerGlobals
175 {
176 ExplorerGlobals();
177
178 void init(HINSTANCE hInstance);
179
180 HINSTANCE _hInstance;
181 UINT _cfStrFName;
182
183 #ifndef ROSSHELL
184 ATOM _hframeClass;
185 HWND _hMainWnd;
186 bool _desktop_mode;
187 bool _prescan_nodes;
188 #endif
189
190 FILE* _log;
191
192 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
193 DWORD(STDAPICALLTYPE* _SHRestricted)(RESTRICTIONS);
194 #endif
195
196 FileTypeManager _ftype_mgr;
197 IconCache _icon_cache;
198
199 HWND _hwndDesktopBar;
200 HWND _hwndShellView;
201 HWND _hwndDesktop;
202
203 Desktops _desktops;
204 } g_Globals;
205
206
207 /// convenient loading of string resources
208 struct ResString : public String
209 {
210 ResString(UINT nid);
211 };
212
213 /// convenient loading of standard (32x32) icon resources
214 struct ResIcon
215 {
216 ResIcon(UINT nid);
217
218 operator HICON() const {return _hicon;}
219
220 protected:
221 HICON _hicon;
222 };
223
224 /// convenient loading of small (16x16) icon resources
225 struct SmallIcon
226 {
227 SmallIcon(UINT nid);
228
229 operator HICON() const {return _hicon;}
230
231 protected:
232 HICON _hicon;
233 };
234
235 /// convenient loading of icon resources with specified sizes
236 struct ResIconEx
237 {
238 ResIconEx(UINT nid, int w, int h);
239
240 operator HICON() const {return _hicon;}
241
242 protected:
243 HICON _hicon;
244 };
245
246 /// set big and small icons out of the resources for a window
247 extern void SetWindowIcon(HWND hwnd, UINT nid);
248
249 /// convenient loading of bitmap resources
250 struct ResBitmap
251 {
252 ResBitmap(UINT nid);
253 ~ResBitmap() {DeleteObject(_hBmp);}
254
255 operator HBITMAP() const {return _hBmp;}
256
257 protected:
258 HBITMAP _hBmp;
259 };