00001 /* 00002 * Copyright 2003, 2004 Martin Fuchs 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 */ 00018 00019 00020 // 00021 // Explorer clone 00022 // 00023 // globals.h 00024 // 00025 // Martin Fuchs, 23.07.2003 00026 // 00027 00028 00029 #include "utility/xmlstorage.h" 00030 00031 using namespace XMLStorage; 00032 00033 #include "taskbar/favorites.h" 00034 00035 00036 /// management of file types 00037 struct FileTypeInfo { 00038 String _classname; 00039 String _displayname; 00040 bool _neverShowExt; 00041 }; 00042 00043 struct FileTypeManager : public map<String, FileTypeInfo> 00044 { 00045 typedef map<String, FileTypeInfo> super; 00046 00047 const FileTypeInfo& operator[](String ext); 00048 00049 static bool is_exe_file(LPCTSTR ext); 00050 00051 LPCTSTR set_type(struct Entry* entry, bool dont_hide_ext=false); 00052 }; 00053 00054 00055 enum ICON_TYPE { 00056 IT_STATIC, 00057 IT_CACHED, 00058 IT_DYNAMIC, 00059 IT_SYSCACHE 00060 }; 00061 00062 enum ICON_ID { 00063 ICID_UNKNOWN, 00064 ICID_NONE, 00065 00066 ICID_FOLDER, 00067 //ICID_DOCUMENT, 00068 ICID_APP, 00069 ICID_EXPLORER, 00070 00071 ICID_CONFIG, 00072 ICID_DOCUMENTS, 00073 ICID_FAVORITES, 00074 ICID_INFO, 00075 ICID_APPS, 00076 ICID_SEARCH, 00077 ICID_ACTION, 00078 ICID_SEARCH_DOC, 00079 ICID_PRINTER, 00080 ICID_NETWORK, 00081 ICID_COMPUTER, 00082 ICID_LOGOFF, 00083 ICID_SHUTDOWN, 00084 ICID_RESTART, 00085 ICID_BOOKMARK, 00086 ICID_MINIMIZE, 00087 ICID_CONTROLPAN, 00088 ICID_DESKSETTING, 00089 ICID_NETCONNS, 00090 ICID_ADMIN, 00091 ICID_RECENT, 00092 00093 ICID_DYNAMIC 00094 }; 00095 00096 struct Icon { 00097 Icon(); 00098 Icon(ICON_ID id, UINT nid); 00099 Icon(ICON_ID id, UINT nid, int icon_size); 00100 Icon(ICON_TYPE itype, int id, HICON hIcon); 00101 Icon(ICON_TYPE itype, int id, int sys_idx); 00102 00103 operator ICON_ID() const {return _id;} 00104 00105 void draw(HDC hdc, int x, int y, int cx, int cy, COLORREF bk_color, HBRUSH bk_brush) const; 00106 HBITMAP create_bitmap(COLORREF bk_color, HBRUSH hbrBkgnd, HDC hdc_wnd) const; 00107 int add_to_imagelist(HIMAGELIST himl, HDC hdc_wnd, COLORREF bk_color=GetSysColor(COLOR_WINDOW), HBRUSH bk_brush=GetSysColorBrush(COLOR_WINDOW)) const; 00108 00109 int get_sysiml_idx() const {return _itype==IT_SYSCACHE? _sys_idx: -1;} 00110 HICON get_hicon() const {return _itype!=IT_SYSCACHE? _hicon: 0;} 00111 ICON_TYPE get_icontype() const { return _itype; } 00112 00113 bool destroy() {if (_itype == IT_DYNAMIC) {DestroyIcon(_hicon); return true;} else return false;} 00114 00115 protected: 00116 ICON_ID _id; 00117 ICON_TYPE _itype; 00118 HICON _hicon; 00119 int _sys_idx; 00120 }; 00121 00122 struct SysCacheIcon : public Icon { 00123 SysCacheIcon(int id, int sys_idx) 00124 : Icon(IT_SYSCACHE, id, sys_idx) {} 00125 }; 00126 00127 struct IconCache { 00128 IconCache() : _himlSys_small(0) {} 00129 00130 virtual ~IconCache(); 00131 void init(); 00132 00133 const Icon& extract(LPCTSTR path, ICONCACHE_FLAGS flags=ICF_NORMAL); 00134 const Icon& extract(LPCTSTR path, int icon_idx, ICONCACHE_FLAGS flags=ICF_HICON); 00135 const Icon& extract(IExtractIcon* pExtract, LPCTSTR path, int icon_idx, ICONCACHE_FLAGS flags=ICF_HICON); 00136 const Icon& extract(LPCITEMIDLIST pidl, ICONCACHE_FLAGS flags=ICF_NORMAL); 00137 00138 const Icon& add(HICON hIcon, ICON_TYPE type=IT_DYNAMIC); 00139 const Icon& add(int sys_idx/*, ICON_TYPE type=IT_SYSCACHE*/); 00140 00141 const Icon& get_icon(int icon_id); 00142 00143 HIMAGELIST get_sys_imagelist() const {return _himlSys_small;} 00144 00145 void free_icon(int icon_id); 00146 00147 protected: 00148 static int s_next_id; 00149 00150 typedef map<int, Icon> IconMap; 00151 IconMap _icons; 00152 00153 typedef pair<String,int/*ICONCACHE_FLAGS*/> CacheKey; 00154 typedef map<CacheKey, ICON_ID> PathCacheMap; 00155 PathCacheMap _pathCache; 00156 00157 typedef pair<String,pair<int,int/*ICONCACHE_FLAGS*/> > IdxCacheKey; 00158 typedef map<IdxCacheKey, ICON_ID> IdxCacheMap; 00159 IdxCacheMap _idxCache; 00160 00161 typedef pair<ShellPath,int/*ICONCACHE_FLAGS*/> PidlCacheKey; 00162 typedef map<PidlCacheKey, ICON_ID> PidlCacheMap; 00163 PidlCacheMap _pidlcache; 00164 00165 HIMAGELIST _himlSys_small; 00166 }; 00167 00168 00169 #define ICON_SIZE_SMALL 16 // GetSystemMetrics(SM_CXSMICON) 00170 #define ICON_SIZE_MIDDLE 24 // special size for start menu root icons 00171 #define ICON_SIZE_LARGE 32 // GetSystemMetrics(SM_CXICON) 00172 00173 #define STARTMENUROOT_ICON_SIZE ICON_SIZE_MIDDLE // ICON_SIZE_LARGE 00174 00175 #define ICON_SIZE_FROM_ICF(flags) (flags&ICF_LARGE? ICON_SIZE_LARGE: flags&ICF_MIDDLE? ICON_SIZE_MIDDLE: ICON_SIZE_SMALL) 00176 #define ICF_FROM_ICON_SIZE(size) (size>=ICON_SIZE_LARGE? ICF_LARGE: size>=ICON_SIZE_MIDDLE? ICF_MIDDLE: (ICONCACHE_FLAGS)0) 00177 00178 00179 /// create a bitmap from an icon 00180 extern HBITMAP create_bitmap_from_icon(HICON hIcon, HBRUSH hbrush_bkgnd, HDC hdc_wnd/*, int icon_size*/); 00181 00182 /// add icon with alpha channel to imagelist using the specified background color 00183 extern int ImageList_AddAlphaIcon(HIMAGELIST himl, HICON hIcon, HBRUSH hbrush_bkgnd, HDC hdc_wnd); 00184 00185 /// retrieve icon from window 00186 extern HICON get_window_icon_small(HWND hwnd); 00187 extern HICON get_window_icon_big(HWND hwnd, bool allow_from_class=true); 00188 00189 00190 /// desktop management 00191 #ifdef _USE_HDESK 00192 00193 typedef auto_ptr<struct DesktopThread> DesktopThreadPtr; 00194 00195 struct Desktop 00196 { 00197 HDESK _hdesktop; 00198 // HWINSTA _hwinsta; 00199 DesktopThreadPtr _pThread; 00200 WindowHandle _hwndDesktop; 00201 00202 Desktop(HDESK hdesktop=0/*, HWINSTA hwinsta=0*/); 00203 ~Desktop(); 00204 }; 00205 00206 typedef auto_ptr<Desktop> DesktopPtr; 00207 typedef DesktopPtr DesktopRef; 00208 00209 /// Thread class for additional desktops 00210 struct DesktopThread : public Thread 00211 { 00212 DesktopThread(Desktop& desktop) 00213 : _desktop(desktop) 00214 { 00215 } 00216 00217 int Run(); 00218 00219 protected: 00220 Desktop& _desktop; 00221 }; 00222 00223 #else 00224 00225 typedef pair<HWND, DWORD> MinimizeStruct; 00226 00227 struct Desktop 00228 { 00229 set<HWND> _windows; 00230 WindowHandle _hwndForeground; 00231 list<MinimizeStruct> _minimized; 00232 }; 00233 typedef Desktop DesktopRef; 00234 00235 #endif 00236 00237 00238 #define DESKTOP_COUNT 4 00239 00240 struct Desktops : public vector<DesktopRef> 00241 { 00242 Desktops(); 00243 ~Desktops(); 00244 00245 void init(); 00246 void SwitchToDesktop(int idx); 00247 void ToggleMinimize(); 00248 00249 #ifdef _USE_HDESK 00250 DesktopRef& get_current_Desktop() {return (*this)[_current_desktop];} 00251 #endif 00252 00253 int _current_desktop; 00254 }; 00255 00256 00257 /// structure containing global variables of Explorer 00258 extern struct ExplorerGlobals 00259 { 00260 ExplorerGlobals(); 00261 00262 void init(HINSTANCE hInstance); 00263 00264 void read_persistent(); 00265 void write_persistent(); 00266 00267 XMLPos get_cfg(); 00268 XMLPos get_cfg(const char* path); 00269 00270 HINSTANCE _hInstance; 00271 UINT _cfStrFName; 00272 00273 #ifndef ROSSHELL 00274 ATOM _hframeClass; 00275 HWND _hMainWnd; 00276 bool _desktop_mode; 00277 bool _prescan_nodes; 00278 #endif 00279 00280 FILE* _log; 00281 00282 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003) 00283 DWORD(STDAPICALLTYPE* _SHRestricted)(RESTRICTIONS); 00284 #endif 00285 00286 FileTypeManager _ftype_mgr; 00287 IconCache _icon_cache; 00288 00289 HWND _hwndDesktopBar; 00290 HWND _hwndShellView; 00291 HWND _hwndDesktop; 00292 00293 Desktops _desktops; 00294 00295 XMLDoc _cfg; 00296 String _cfg_dir; 00297 String _cfg_path; 00298 00299 Favorites _favorites; 00300 String _favorites_path; 00301 } g_Globals; 00302 00303 00304 /// convenient loading of string resources 00305 struct ResString : public String 00306 { 00307 ResString(UINT nid); 00308 }; 00309 00310 /// convenient loading of standard (32x32) icon resources 00311 struct ResIcon 00312 { 00313 ResIcon(UINT nid); 00314 00315 operator HICON() const {return _hicon;} 00316 00317 protected: 00318 HICON _hicon; 00319 }; 00320 00321 /// convenient loading of small (16x16) icon resources 00322 struct SmallIcon 00323 { 00324 SmallIcon(UINT nid); 00325 00326 operator HICON() const {return _hicon;} 00327 00328 protected: 00329 HICON _hicon; 00330 }; 00331 00332 /// convenient loading of icon resources with specified sizes 00333 struct ResIconEx 00334 { 00335 ResIconEx(UINT nid, int w, int h); 00336 00337 operator HICON() const {return _hicon;} 00338 00339 protected: 00340 HICON _hicon; 00341 }; 00342 00343 /// set big and small icons out of the resources for a window 00344 extern void SetWindowIcon(HWND hwnd, UINT nid); 00345 00346 /// convenient loading of bitmap resources 00347 struct ResBitmap 00348 { 00349 ResBitmap(UINT nid); 00350 ~ResBitmap() {DeleteObject(_hBmp);} 00351 00352 operator HBITMAP() const {return _hBmp;} 00353 00354 protected: 00355 HBITMAP _hBmp; 00356 };
ROS Explorer Source Code Documentation
generated on 02.01.2013 by ![]() |