2 * Copyright 2003, 2004 Martin Fuchs
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.
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.
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
25 // Martin Fuchs, 23.07.2003
29 #include "utility/xmlstorage.h"
31 using namespace XMLStorage
;
33 #include "taskbar/favorites.h"
36 /// management of file types
43 struct FileTypeManager
: public map
<String
, FileTypeInfo
>
45 typedef map
<String
, FileTypeInfo
> super
;
47 const FileTypeInfo
& operator[](String ext
);
49 static bool is_exe_file(LPCTSTR ext
);
51 LPCTSTR
set_type(struct Entry
* entry
, bool dont_hide_ext
=false);
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
);
103 operator ICON_ID() const {return _id
;}
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;
109 int get_sysiml_idx() const {return _itype
==IT_SYSCACHE
? _sys_idx
: -1;}
110 HICON
get_hicon() const {return _itype
!=IT_SYSCACHE
? _hicon
: 0;}
111 ICON_TYPE
get_icontype() const { return _itype
; }
113 bool destroy() {if (_itype
== IT_DYNAMIC
) {DestroyIcon(_hicon
); return true;} else return false;}
122 struct SysCacheIcon
: public Icon
{
123 SysCacheIcon(int id
, int sys_idx
)
124 : Icon(IT_SYSCACHE
, id
, sys_idx
) {}
128 IconCache() : _himlSys_small(0) {}
130 virtual ~IconCache();
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
);
138 const Icon
& add(HICON hIcon
, ICON_TYPE type
=IT_DYNAMIC
);
139 const Icon
& add(int sys_idx
/*, ICON_TYPE type=IT_SYSCACHE*/);
141 const Icon
& get_icon(int icon_id
);
143 HIMAGELIST
get_sys_imagelist() const {return _himlSys_small
;}
145 void free_icon(int icon_id
);
148 static int s_next_id
;
150 typedef map
<int, Icon
> IconMap
;
153 typedef pair
<String
,int/*ICONCACHE_FLAGS*/> CacheKey
;
154 typedef map
<CacheKey
, ICON_ID
> PathCacheMap
;
155 PathCacheMap _pathCache
;
157 typedef pair
<String
,pair
<int,int/*ICONCACHE_FLAGS*/> > IdxCacheKey
;
158 typedef map
<IdxCacheKey
, ICON_ID
> IdxCacheMap
;
159 IdxCacheMap _idxCache
;
161 typedef pair
<ShellPath
,int/*ICONCACHE_FLAGS*/> PidlCacheKey
;
162 typedef map
<PidlCacheKey
, ICON_ID
> PidlCacheMap
;
163 PidlCacheMap _pidlcache
;
165 HIMAGELIST _himlSys_small
;
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)
173 #define STARTMENUROOT_ICON_SIZE ICON_SIZE_MIDDLE // ICON_SIZE_LARGE
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)
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*/);
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
);
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);
190 /// desktop management
193 typedef auto_ptr
<struct DesktopThread
> DesktopThreadPtr
;
199 DesktopThreadPtr _pThread
;
200 WindowHandle _hwndDesktop
;
202 Desktop(HDESK hdesktop
=0/*, HWINSTA hwinsta=0*/);
206 typedef auto_ptr
<Desktop
> DesktopPtr
;
207 typedef DesktopPtr DesktopRef
;
209 /// Thread class for additional desktops
210 struct DesktopThread
: public Thread
212 DesktopThread(Desktop
& desktop
)
225 typedef pair
<HWND
, DWORD
> MinimizeStruct
;
230 WindowHandle _hwndForeground
;
231 list
<MinimizeStruct
> _minimized
;
233 typedef Desktop DesktopRef
;
238 #define DESKTOP_COUNT 4
240 struct Desktops
: public vector
<DesktopRef
>
246 void SwitchToDesktop(int idx
);
247 void ToggleMinimize();
250 DesktopRef
& get_current_Desktop() {return (*this)[_current_desktop
];}
253 int _current_desktop
;
257 /// structure containing global variables of Explorer
258 extern struct ExplorerGlobals
262 void init(HINSTANCE hInstance
);
264 void read_persistent();
265 void write_persistent();
268 XMLPos
get_cfg(const char* path
);
270 HINSTANCE _hInstance
;
282 DWORD(STDAPICALLTYPE
* _SHRestricted
)(RESTRICTIONS
);
284 FileTypeManager _ftype_mgr
;
285 IconCache _icon_cache
;
287 HWND _hwndDesktopBar
;
297 Favorites _favorites
;
298 String _favorites_path
;
302 /// convenient loading of string resources
303 struct ResString
: public String
308 /// convenient loading of standard (32x32) icon resources
313 operator HICON() const {return _hicon
;}
319 /// convenient loading of small (16x16) icon resources
324 operator HICON() const {return _hicon
;}
330 /// convenient loading of icon resources with specified sizes
333 ResIconEx(UINT nid
, int w
, int h
);
335 operator HICON() const {return _hicon
;}
341 /// set big and small icons out of the resources for a window
342 extern void SetWindowIcon(HWND hwnd
, UINT nid
);
344 /// convenient loading of bitmap resources
348 ~ResBitmap() {DeleteObject(_hBmp
);}
350 operator HBITMAP() const {return _hBmp
;}