forked from slorelee/PExplorer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathglobals.h
296 lines (219 loc) · 7.68 KB
/
globals.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/*
* Copyright 2003, 2004 Martin Fuchs
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
//
// Explorer clone
//
// globals.h
//
// Martin Fuchs, 23.07.2003
//
#include "vendor/json.h"
#include "taskbar/favorites.h"
#include "jconfig/jcfg.h"
/// management of file types
struct FileTypeInfo {
String _classname;
String _displayname;
bool _neverShowExt;
};
struct FileTypeManager : public map<String, FileTypeInfo> {
typedef map<String, FileTypeInfo> super;
const FileTypeInfo &operator[](String ext);
static bool is_exe_file(LPCTSTR ext);
LPCTSTR set_type(struct Entry *entry, bool dont_hide_ext = false);
};
enum ICON_TYPE {
IT_STATIC,
IT_CACHED,
IT_DYNAMIC,
IT_SYSCACHE
};
enum ICON_ID {
ICID_UNKNOWN,
ICID_NONE,
ICID_FOLDER,
//ICID_DOCUMENT,
ICID_APP,
ICID_EXPLORER,
ICID_CONFIG,
ICID_DOCUMENTS,
ICID_FAVORITES,
ICID_INFO,
ICID_APPS,
ICID_SEARCH,
ICID_ACTION,
ICID_SEARCH_DOC,
ICID_PRINTER,
ICID_NETWORK,
ICID_COMPUTER,
ICID_LOGOFF,
ICID_SHUTDOWN,
ICID_RESTART,
ICID_TERMINATE,
ICID_BOOKMARK,
ICID_MINIMIZE,
ICID_CONTROLPAN,
ICID_DESKSETTING,
ICID_NETCONNS,
ICID_ADMIN,
ICID_RECENT,
ICID_DYNAMIC
};
#define ICON_SIZE_SMALL 16 // GetSystemMetrics(SM_CXSMICON)
#define ICON_SIZE_MIDDLE 24 // special size for start menu root icons
#define ICON_SIZE_LARGE 32 // GetSystemMetrics(SM_CXICON)
#define ICON_SIZE_FROM_ICF(flags) (flags&ICF_LARGE? ICON_SIZE_LARGE: flags&ICF_MIDDLE? ICON_SIZE_MIDDLE: ICON_SIZE_SMALL)
#define ICF_FROM_ICON_SIZE(size) (size>=ICON_SIZE_LARGE? ICF_LARGE: size>=ICON_SIZE_MIDDLE? ICF_MIDDLE: ICF_SMALL)
struct Icon {
Icon();
Icon(ICON_ID id, UINT nid);
Icon(ICON_ID id, UINT nid, int icon_size);
Icon(ICON_TYPE itype, int id, HICON hIcon);
Icon(ICON_TYPE itype, int id, int sys_idx);
operator ICON_ID() const {return _id;}
void draw(HDC hdc, int x, int y, int cx, int cy, COLORREF bk_color, HBRUSH bk_brush) const;
HBITMAP create_bitmap(COLORREF bk_color, HBRUSH hbrBkgnd, HDC hdc_wnd, int icon_size = ICON_SIZE_SMALL) const;
int add_to_imagelist(HIMAGELIST himl, HDC hdc_wnd, COLORREF bk_color = GetSysColor(COLOR_WINDOW), HBRUSH bk_brush = GetSysColorBrush(COLOR_WINDOW)) const;
int get_sysiml_idx() const {return _itype == IT_SYSCACHE ? _sys_idx : -1;}
HICON get_hicon() const {return _itype != IT_SYSCACHE ? _hicon : 0;}
ICON_TYPE get_icontype() const { return _itype; }
bool destroy() {if (_itype == IT_DYNAMIC) {DestroyIcon(_hicon); return true;} else return false;}
protected:
ICON_ID _id;
ICON_TYPE _itype;
HICON _hicon;
int _sys_idx;
};
struct SysCacheIcon : public Icon {
SysCacheIcon(int id, int sys_idx)
: Icon(IT_SYSCACHE, id, sys_idx) {}
};
struct IconCache {
IconCache() : _himlSys_small(0) {}
virtual ~IconCache();
void init();
const Icon &extract(LPCTSTR path, UINT flags = ICF_NORMAL);
const Icon &extract(LPCTSTR path, int icon_idx, UINT flags = ICF_HICON);
const Icon &extract(IExtractIcon *pExtract, LPCTSTR path, int icon_idx, UINT flags = ICF_HICON);
const Icon &extract(LPCITEMIDLIST pidl, UINT flags = ICF_NORMAL);
const Icon &add(HICON hIcon, ICON_TYPE type = IT_DYNAMIC);
const Icon &add(int sys_idx/*, ICON_TYPE type=IT_SYSCACHE*/);
const Icon &get_icon(int icon_id);
HIMAGELIST get_sys_imagelist() const {return _himlSys_small;}
void free_icon(int icon_id);
protected:
static int s_next_id;
typedef map<int, Icon> IconMap;
IconMap _icons;
typedef pair<String, int/*ICONCACHE_FLAGS*/> CacheKey;
typedef map<CacheKey, ICON_ID> PathCacheMap;
PathCacheMap _pathCache;
typedef pair<String, pair<int, int/*ICONCACHE_FLAGS*/> > IdxCacheKey;
typedef map<IdxCacheKey, ICON_ID> IdxCacheMap;
IdxCacheMap _idxCache;
typedef pair<ShellPath, int/*ICONCACHE_FLAGS*/> PidlCacheKey;
typedef map<PidlCacheKey, ICON_ID> PidlCacheMap;
PidlCacheMap _pidlcache;
HIMAGELIST _himlSys_small;
};
/// create a bitmap from an icon
extern HBITMAP create_bitmap_from_icon(HICON hIcon, HBRUSH hbrush_bkgnd, HDC hdc_wnd, int icon_size = ICON_SIZE_SMALL);
/// add icon with alpha channel to imagelist using the specified background color
extern int ImageList_AddAlphaIcon(HIMAGELIST himl, HICON hIcon, HBRUSH hbrush_bkgnd, HDC hdc_wnd);
/// retrieve icon from window
extern HICON get_window_icon_small(HWND hwnd);
extern HICON get_window_icon_big(HWND hwnd, bool allow_from_class = true);
typedef pair<HWND, DWORD> MinimizeStruct;
struct Desktop {
set<HWND> _windows;
WindowHandle _hwndForeground;
list<MinimizeStruct> _minimized;
void ToggleMinimize();
};
typedef Desktop DesktopRef;
/// structure containing global variables of Explorer
extern struct ExplorerGlobals {
ExplorerGlobals();
void init(HINSTANCE hInstance);
void read_persistent();
void write_persistent();
void load_config();
void get_systeminfo();
HINSTANCE _hInstance;
UINT _cfStrFName;
BOOL _isWinPE;
BOOL _isNT5;
String _langID;
#ifndef ROSSHELL
ATOM _hframeClass;
HWND _hMainWnd;
bool _desktop_mode;
bool _prescan_nodes;
#endif
FILE *_log;
DWORD(STDAPICALLTYPE *_SHRestricted)(RESTRICTIONS);
FileTypeManager _ftype_mgr;
IconCache _icon_cache;
HWND _hwndDesktopBar;
HWND _hwndShellView;
HWND _hwndDesktop;
Desktop _desktop;
String _cfg_dir;
String _cfg_path;
} g_Globals;
/// convenient loading of string resources
struct ResString : public String {
ResString(UINT nid);
};
/// convenient loading of standard (32x32) icon resources
struct ResIcon {
ResIcon(UINT nid);
operator HICON() const {return _hicon;}
protected:
HICON _hicon;
};
/// convenient loading of small (16x16) icon resources
struct SmallIcon {
SmallIcon(UINT nid);
operator HICON() const {return _hicon;}
protected:
HICON _hicon;
};
struct SizeIcon {
SizeIcon(UINT nid, int size);
operator HICON() const { return _hicon; }
protected:
HICON _hicon;
};
/// convenient loading of icon resources with specified sizes
struct ResIconEx {
ResIconEx(UINT nid, int w, int h);
operator HICON() const {return _hicon;}
protected:
HICON _hicon;
};
/// set big and small icons out of the resources for a window
extern void SetWindowIcon(HWND hwnd, UINT nid);
/// convenient loading of bitmap resources
struct ResBitmap {
ResBitmap(UINT nid);
~ResBitmap() {DeleteObject(_hBmp);}
operator HBITMAP() const {return _hBmp;}
protected:
HBITMAP _hBmp;
};