icon alignment algorithms
[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
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();
77 Icon(ICON_ID id, UINT nid);
78 Icon(ICON_TYPE itype, int id, HICON hIcon);
79 Icon(ICON_TYPE itype, int id, int sys_idx);
80
81 operator ICON_ID() const {return _id;}
82
83 void draw(HDC hdc, int x, int y, int cx, int cy, COLORREF bk_color, HBRUSH bk_brush) const;
84 HBITMAP create_bitmap(COLORREF bk_color, HBRUSH hbrBkgnd, HDC hdc_wnd) const;
85
86 int get_sysiml_idx() const {return _itype==IT_SYSCACHE? _sys_idx: -1;}
87
88 bool destroy() {if (_itype == IT_DYNAMIC) {DestroyIcon(_hicon); return true;} else return false;}
89
90 protected:
91 ICON_ID _id;
92 ICON_TYPE _itype;
93 HICON _hicon;
94 int _sys_idx;
95 };
96
97 struct SysCacheIcon : public Icon {
98 SysCacheIcon(int id, int sys_idx)
99 : Icon(IT_SYSCACHE, id, sys_idx) {}
100 };
101
102 struct IconCache {
103 IconCache() : _himlSys(0) {}
104
105 void init();
106
107 const Icon& extract(const String& path);
108 const Icon& extract(LPCTSTR path, int idx);
109 const Icon& extract(IExtractIcon* pExtract, LPCTSTR path, int idx);
110
111 const Icon& add(HICON hIcon, ICON_TYPE type=IT_DYNAMIC);
112 const Icon& add(int sys_idx/*, ICON_TYPE type=IT_SYSCACHE*/);
113
114 const Icon& get_icon(int icon_id);
115 HIMAGELIST get_sys_imagelist() const {return _himlSys;}
116
117 void free_icon(int icon_id);
118
119 protected:
120 static int s_next_id;
121
122 typedef map<int, Icon> IconMap;
123 IconMap _icons;
124
125 typedef map<String, ICON_ID> PathMap;
126 PathMap _pathMap;
127
128 typedef pair<String, int> CachePair;
129 typedef map<CachePair, ICON_ID> PathIdxMap;
130 PathIdxMap _pathIdxMap;
131
132 HIMAGELIST _himlSys;
133 };
134
135
136 /// create a bitmap from an icon
137 extern HBITMAP create_bitmap_from_icon(HICON hIcon, HBRUSH hbrush_bkgnd, HDC hdc_wnd);
138
139
140 /// structure containing global variables of Explorer
141 extern struct ExplorerGlobals
142 {
143 ExplorerGlobals();
144
145 void init(HINSTANCE hInstance);
146
147 HINSTANCE _hInstance;
148 ATOM _hframeClass;
149 UINT _cfStrFName;
150 HWND _hMainWnd;
151 bool _prescan_nodes;
152 bool _desktop_mode;
153
154 FILE* _log;
155
156 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
157 DWORD(STDAPICALLTYPE* _SHRestricted)(RESTRICTIONS);
158 #endif
159
160 FileTypeManager _ftype_mgr;
161 IconCache _icon_cache;
162
163 HWND _hwndDesktopBar;
164 HWND _hwndShellView;
165 } g_Globals;
166
167
168 /// convenient loading of string resources
169 struct ResString : public String
170 {
171 ResString(UINT nid);
172 };
173
174 /// convenient loading of standard (32x32) icon resources
175 struct ResIcon
176 {
177 ResIcon(UINT nid);
178
179 operator HICON() const {return _hicon;}
180
181 protected:
182 HICON _hicon;
183 };
184
185 /// convenient loading of small (16x16) icon resources
186 struct SmallIcon
187 {
188 SmallIcon(UINT nid);
189
190 operator HICON() const {return _hicon;}
191
192 protected:
193 HICON _hicon;
194 };
195
196 /// convenient loading of icon resources with specified sizes
197 struct ResIconEx
198 {
199 ResIconEx(UINT nid, int w, int h);
200
201 operator HICON() const {return _hicon;}
202
203 protected:
204 HICON _hicon;
205 };
206
207 /// set big and small icons out of the resources for a window
208 extern void SetWindowIcon(HWND hwnd, UINT nid);
209
210 /// convenient loading of bitmap resources
211 struct ResBitmap
212 {
213 ResBitmap(UINT nid);
214 ~ResBitmap() {DeleteObject(_hBmp);}
215
216 operator HBITMAP() const {return _hBmp;}
217
218 protected:
219 HBITMAP _hBmp;
220 };