some small improvements
[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 bool _neverShowExt;
33 };
34
35 struct FileTypeManager : public map<String, FileTypeInfo>
36 {
37 typedef map<String, FileTypeInfo> super;
38
39 const FileTypeInfo& operator[](String ext);
40 };
41
42
43 enum ICON_TYPE {
44 IT_STATIC,
45 IT_CACHED,
46 IT_DYNAMIC,
47 IT_SYSCACHE ///@todo
48 };
49
50 enum ICON_ID {
51 ICID_UNKNOWN,
52 ICID_NONE,
53
54 ICID_FOLDER,
55 //ICID_DOCUMENT,
56 ICID_APP,
57 ICID_EXPLORER,
58
59 ICID_CONFIG,
60 ICID_DOCUMENTS,
61 ICID_FAVORITES,
62 ICID_INFO,
63 ICID_APPS,
64 ICID_SEARCH,
65 ICID_ACTION,
66 ICID_SEARCH_DOC,
67 ICID_PRINTER,
68 ICID_NETWORK,
69 ICID_COMPUTER,
70 ICID_LOGOFF,
71
72 ICID_DYNAMIC
73 };
74
75 struct Icon {
76 ICON_ID _id;
77 ICON_TYPE _itype;
78 HICON _hIcon;
79
80 Icon();
81 Icon(ICON_ID id, UINT nid);
82 Icon(ICON_TYPE itype, int id, HICON hIcon);
83 };
84
85 struct IconCache {
86 void init();
87
88 const Icon& extract(const String& path);
89 const Icon& extract(LPCTSTR path, int idx);
90 const Icon& extract(IExtractIcon* pExtract, LPCTSTR path, int idx);
91
92 const Icon& add(HICON hIcon, ICON_TYPE type=IT_DYNAMIC);
93
94 const Icon& get_icon(int icon_id);
95 HBITMAP get_icon_bitmap(int icon_id, HBRUSH hbrBkgnd, HDC hdc);
96
97 void free_icon(int icon_id);
98
99 protected:
100 static int s_next_id;
101
102 typedef map<int, Icon> IconMap;
103 IconMap _icons;
104
105 typedef map<String, ICON_ID> PathMap;
106 PathMap _pathMap;
107
108 typedef pair<String, int> CachePair;
109 typedef map<CachePair, ICON_ID> PathIdxMap;
110 PathIdxMap _pathIdxMap;
111 };
112
113
114 /// create a bitmap from an icon
115 extern HBITMAP create_bitmap_from_icon(HICON hIcon, HBRUSH hbrush_bkgnd, HDC hdc_wnd);
116
117
118 /// structure containing global variables of Explorer
119 extern struct ExplorerGlobals
120 {
121 ExplorerGlobals();
122
123 void init(HINSTANCE hInstance);
124
125 HINSTANCE _hInstance;
126 ATOM _hframeClass;
127 UINT _cfStrFName;
128 HWND _hMainWnd;
129 bool _prescan_nodes;
130 bool _desktop_mode;
131
132 FILE* _log;
133
134 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
135 DWORD(STDAPICALLTYPE* _SHRestricted)(RESTRICTIONS);
136 #endif
137
138 FileTypeManager _ftype_mgr;
139 IconCache _icon_cache;
140 } g_Globals;
141
142
143 /// convenient loading of string resources
144 struct ResString : public String
145 {
146 ResString(UINT nid);
147 };
148
149 /// convenient loading of standard (32x32) icon resources
150 struct ResIcon
151 {
152 ResIcon(UINT nid);
153
154 operator HICON() const {return _hIcon;}
155
156 protected:
157 HICON _hIcon;
158 };
159
160 /// convenient loading of small (16x16) icon resources
161 struct SmallIcon
162 {
163 SmallIcon(UINT nid);
164
165 operator HICON() const {return _hIcon;}
166
167 protected:
168 HICON _hIcon;
169 };
170
171 /// convenient loading of icon resources with specified sizes
172 struct ResIconEx
173 {
174 ResIconEx(UINT nid, int w, int h);
175
176 operator HICON() const {return _hIcon;}
177
178 protected:
179 HICON _hIcon;
180 };
181
182 /// set big and small icons out of the resources for a window
183 extern void SetWindowIcon(HWND hwnd, UINT nid);
184
185 /// convenient loading of bitmap resources
186 struct ResBitmap
187 {
188 ResBitmap(UINT nid);
189 ~ResBitmap() {DeleteObject(_hBmp);}
190
191 operator HBITMAP() const {return _hBmp;}
192
193 protected:
194 HBITMAP _hBmp;
195 };