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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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 using namespace XMLStorage; 32 33 #include "taskbar/favorites.h" 34 35 36 /// management of file types 37 struct FileTypeInfo { 38 String _classname; 39 String _displayname; 40 bool _neverShowExt; 41 }; 42 43 struct FileTypeManager : public map<String, FileTypeInfo> 44 { 45 typedef map<String, FileTypeInfo> super; 46 47 const FileTypeInfo& operator[](String ext); 48 49 static bool is_exe_file(LPCTSTR ext); 50 51 LPCTSTR set_type(struct Entry* entry, bool dont_hide_ext=false); 52 }; 53 54 55 enum ICON_TYPE { 56 IT_STATIC, 57 IT_CACHED, 58 IT_DYNAMIC, 59 IT_SYSCACHE 60 }; 61 62 enum ICON_ID { 63 ICID_UNKNOWN, 64 ICID_NONE, 65 66 ICID_FOLDER, 67 //ICID_DOCUMENT, 68 ICID_APP, 69 ICID_EXPLORER, 70 71 ICID_CONFIG, 72 ICID_DOCUMENTS, 73 ICID_FAVORITES, 74 ICID_INFO, 75 ICID_APPS, 76 ICID_SEARCH, 77 ICID_ACTION, 78 ICID_SEARCH_DOC, 79 ICID_PRINTER, 80 ICID_NETWORK, 81 ICID_COMPUTER, 82 ICID_LOGOFF, 83 ICID_SHUTDOWN, 84 ICID_RESTART, 85 ICID_BOOKMARK, 86 ICID_MINIMIZE, 87 ICID_CONTROLPAN, 88 ICID_DESKSETTING, 89 ICID_NETCONNS, 90 ICID_ADMIN, 91 ICID_RECENT, 92 93 ICID_DYNAMIC 94 }; 95 96 struct Icon { 97 Icon(); 98 Icon(ICON_ID id, UINT nid); 99 Icon(ICON_ID id, UINT nid, int icon_size); 100 Icon(ICON_TYPE itype, int id, HICON hIcon); 101 Icon(ICON_TYPE itype, int id, int sys_idx); 102 ICON_IDIcon103 operator ICON_ID() const {return _id;} 104 105 void draw(HDC hdc, int x, int y, int cx, int cy, COLORREF bk_color, HBRUSH bk_brush) const; 106 HBITMAP create_bitmap(COLORREF bk_color, HBRUSH hbrBkgnd, HDC hdc_wnd) const; 107 int add_to_imagelist(HIMAGELIST himl, HDC hdc_wnd, COLORREF bk_color=GetSysColor(COLOR_WINDOW), HBRUSH bk_brush=GetSysColorBrush(COLOR_WINDOW)) const; 108 get_sysiml_idxIcon109 int get_sysiml_idx() const {return _itype==IT_SYSCACHE? _sys_idx: -1;} get_hiconIcon110 HICON get_hicon() const {return _itype!=IT_SYSCACHE? _hicon: 0;} get_icontypeIcon111 ICON_TYPE get_icontype() const { return _itype; } 112 destroyIcon113 bool destroy() {if (_itype == IT_DYNAMIC) {DestroyIcon(_hicon); return true;} else return false;} 114 115 protected: 116 ICON_ID _id; 117 ICON_TYPE _itype; 118 HICON _hicon; 119 int _sys_idx; 120 }; 121 122 struct SysCacheIcon : public Icon { SysCacheIconSysCacheIcon123 SysCacheIcon(int id, int sys_idx) 124 : Icon(IT_SYSCACHE, id, sys_idx) {} 125 }; 126 127 struct IconCache { IconCacheIconCache128 IconCache() : _himlSys_small(0) {} 129 130 virtual ~IconCache(); 131 void init(); 132 133 const Icon& extract(LPCTSTR path, ICONCACHE_FLAGS flags=ICF_NORMAL); 134 const Icon& extract(LPCTSTR path, int icon_idx, ICONCACHE_FLAGS flags=ICF_HICON); 135 const Icon& extract(IExtractIcon* pExtract, LPCTSTR path, int icon_idx, ICONCACHE_FLAGS flags=ICF_HICON); 136 const Icon& extract(LPCITEMIDLIST pidl, ICONCACHE_FLAGS flags=ICF_NORMAL); 137 138 const Icon& add(HICON hIcon, ICON_TYPE type=IT_DYNAMIC); 139 const Icon& add(int sys_idx/*, ICON_TYPE type=IT_SYSCACHE*/); 140 141 const Icon& get_icon(int icon_id); 142 get_sys_imagelistIconCache143 HIMAGELIST get_sys_imagelist() const {return _himlSys_small;} 144 145 void free_icon(int icon_id); 146 147 protected: 148 static int s_next_id; 149 150 typedef map<int, Icon> IconMap; 151 IconMap _icons; 152 153 typedef pair<String,int/*ICONCACHE_FLAGS*/> CacheKey; 154 typedef map<CacheKey, ICON_ID> PathCacheMap; 155 PathCacheMap _pathCache; 156 157 typedef pair<String,pair<int,int/*ICONCACHE_FLAGS*/> > IdxCacheKey; 158 typedef map<IdxCacheKey, ICON_ID> IdxCacheMap; 159 IdxCacheMap _idxCache; 160 161 typedef pair<ShellPath,int/*ICONCACHE_FLAGS*/> PidlCacheKey; 162 typedef map<PidlCacheKey, ICON_ID> PidlCacheMap; 163 PidlCacheMap _pidlcache; 164 165 HIMAGELIST _himlSys_small; 166 }; 167 168 169 #define ICON_SIZE_SMALL 16 // GetSystemMetrics(SM_CXSMICON) 170 #define ICON_SIZE_MIDDLE 24 // special size for start menu root icons 171 #define ICON_SIZE_LARGE 32 // GetSystemMetrics(SM_CXICON) 172 173 #define STARTMENUROOT_ICON_SIZE ICON_SIZE_MIDDLE // ICON_SIZE_LARGE 174 175 #define ICON_SIZE_FROM_ICF(flags) (flags&ICF_LARGE? ICON_SIZE_LARGE: flags&ICF_MIDDLE? ICON_SIZE_MIDDLE: ICON_SIZE_SMALL) 176 #define ICF_FROM_ICON_SIZE(size) (size>=ICON_SIZE_LARGE? ICF_LARGE: size>=ICON_SIZE_MIDDLE? ICF_MIDDLE: (ICONCACHE_FLAGS)0) 177 178 179 /// create a bitmap from an icon 180 extern HBITMAP create_bitmap_from_icon(HICON hIcon, HBRUSH hbrush_bkgnd, HDC hdc_wnd/*, int icon_size*/); 181 182 /// add icon with alpha channel to imagelist using the specified background color 183 extern int ImageList_AddAlphaIcon(HIMAGELIST himl, HICON hIcon, HBRUSH hbrush_bkgnd, HDC hdc_wnd); 184 185 /// retrieve icon from window 186 extern HICON get_window_icon_small(HWND hwnd); 187 extern HICON get_window_icon_big(HWND hwnd, bool allow_from_class=true); 188 189 190 /// desktop management 191 #ifdef _USE_HDESK 192 193 typedef auto_ptr<struct DesktopThread> DesktopThreadPtr; 194 195 struct Desktop 196 { 197 HDESK _hdesktop; 198 // HWINSTA _hwinsta; 199 DesktopThreadPtr _pThread; 200 WindowHandle _hwndDesktop; 201 202 Desktop(HDESK hdesktop=0/*, HWINSTA hwinsta=0*/); 203 ~Desktop(); 204 }; 205 206 typedef auto_ptr<Desktop> DesktopPtr; 207 typedef DesktopPtr DesktopRef; 208 209 /// Thread class for additional desktops 210 struct DesktopThread : public Thread 211 { DesktopThreadDesktopThread212 DesktopThread(Desktop& desktop) 213 : _desktop(desktop) 214 { 215 } 216 217 int Run(); 218 219 protected: 220 Desktop& _desktop; 221 }; 222 223 #else 224 225 typedef pair<HWND, DWORD> MinimizeStruct; 226 227 struct Desktop 228 { 229 set<HWND> _windows; 230 WindowHandle _hwndForeground; 231 list<MinimizeStruct> _minimized; 232 }; 233 typedef Desktop DesktopRef; 234 235 #endif 236 237 238 #define DESKTOP_COUNT 4 239 240 struct Desktops : public vector<DesktopRef> 241 { 242 Desktops(); 243 ~Desktops(); 244 245 void init(); 246 void SwitchToDesktop(int idx); 247 void ToggleMinimize(); 248 249 #ifdef _USE_HDESK get_current_DesktopDesktops250 DesktopRef& get_current_Desktop() {return (*this)[_current_desktop];} 251 #endif 252 253 int _current_desktop; 254 }; 255 256 257 /// structure containing global variables of Explorer 258 extern struct ExplorerGlobals 259 { 260 ExplorerGlobals(); 261 262 void init(HINSTANCE hInstance); 263 264 void read_persistent(); 265 void write_persistent(); 266 267 XMLPos get_cfg(); 268 XMLPos get_cfg(const char* path); 269 270 HINSTANCE _hInstance; 271 UINT _cfStrFName; 272 273 #ifndef ROSSHELL 274 ATOM _hframeClass; 275 HWND _hMainWnd; 276 bool _desktop_mode; 277 bool _prescan_nodes; 278 #endif 279 280 FILE* _log; 281 282 DWORD(STDAPICALLTYPE* _SHRestricted)(RESTRICTIONS); 283 284 FileTypeManager _ftype_mgr; 285 IconCache _icon_cache; 286 287 HWND _hwndDesktopBar; 288 HWND _hwndShellView; 289 HWND _hwndDesktop; 290 291 Desktops _desktops; 292 293 XMLDoc _cfg; 294 String _cfg_dir; 295 String _cfg_path; 296 297 Favorites _favorites; 298 String _favorites_path; 299 } g_Globals; 300 301 302 /// convenient loading of string resources 303 struct ResString : public String 304 { 305 ResString(UINT nid); 306 }; 307 308 /// convenient loading of standard (32x32) icon resources 309 struct ResIcon 310 { 311 ResIcon(UINT nid); 312 HICONResIcon313 operator HICON() const {return _hicon;} 314 315 protected: 316 HICON _hicon; 317 }; 318 319 /// convenient loading of small (16x16) icon resources 320 struct SmallIcon 321 { 322 SmallIcon(UINT nid); 323 HICONSmallIcon324 operator HICON() const {return _hicon;} 325 326 protected: 327 HICON _hicon; 328 }; 329 330 /// convenient loading of icon resources with specified sizes 331 struct ResIconEx 332 { 333 ResIconEx(UINT nid, int w, int h); 334 HICONResIconEx335 operator HICON() const {return _hicon;} 336 337 protected: 338 HICON _hicon; 339 }; 340 341 /// set big and small icons out of the resources for a window 342 extern void SetWindowIcon(HWND hwnd, UINT nid); 343 344 /// convenient loading of bitmap resources 345 struct ResBitmap 346 { 347 ResBitmap(UINT nid); ~ResBitmapResBitmap348 ~ResBitmap() {DeleteObject(_hBmp);} 349 HBITMAPResBitmap350 operator HBITMAP() const {return _hBmp;} 351 352 protected: 353 HBITMAP _hBmp; 354 }; 355