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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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);
97 Icon(ICON_ID id
, UINT nid
);
98 Icon(ICON_TYPE itype
, int id
, HICON hIcon
);
99 Icon(ICON_TYPE itype
, int id
, int sys_idx
);
101 operator ICON_ID() const {return _id
;}
103 void draw(HDC hdc
, int x
, int y
, int cx
, int cy
, COLORREF bk_color
, HBRUSH bk_brush
) const;
104 HBITMAP
create_bitmap(COLORREF bk_color
, HBRUSH hbrBkgnd
, HDC hdc_wnd
) const;
105 int add_to_imagelist(HIMAGELIST himl
, HDC hdc_wnd
, COLORREF bk_color
=GetSysColor(COLOR_WINDOW
), HBRUSH bk_brush
=GetSysColorBrush(COLOR_WINDOW
)) const;
107 int get_sysiml_idx() const {return _itype
==IT_SYSCACHE
? _sys_idx
: -1;}
108 HICON
get_hicon() const {return _itype
!=IT_SYSCACHE
? _hicon
: 0;}
110 bool destroy() {if (_itype
== IT_DYNAMIC
) {DestroyIcon(_hicon
); return true;} else return false;}
119 struct SysCacheIcon
: public Icon
{
120 SysCacheIcon(int id
, int sys_idx
)
121 : Icon(IT_SYSCACHE
, id
, sys_idx
) {}
125 IconCache() : _himlSys_small(0) {}
129 const Icon
& extract(LPCTSTR path
, ICONCACHE_FLAGS flags
=ICF_NORMAL
);
130 const Icon
& extract(LPCTSTR path
, int idx
, ICONCACHE_FLAGS flags
=ICF_HICON
);
131 const Icon
& extract(IExtractIcon
* pExtract
, LPCTSTR path
, int idx
, ICONCACHE_FLAGS flags
=ICF_HICON
);
133 const Icon
& add(HICON hIcon
, ICON_TYPE type
=IT_DYNAMIC
);
134 const Icon
& add(int sys_idx
/*, ICON_TYPE type=IT_SYSCACHE*/);
136 const Icon
& get_icon(int icon_id
);
138 HIMAGELIST
get_sys_imagelist() const {return _himlSys_small
;}
140 void free_icon(int icon_id
);
143 static int s_next_id
;
145 typedef map
<int, Icon
> IconMap
;
148 typedef pair
<String
,int/*ICONCACHE_FLAGS*/> CacheKey
;
149 typedef map
<CacheKey
, ICON_ID
> PathCacheMap
;
150 PathCacheMap _pathCache
;
152 typedef pair
<String
,pair
<int,int/*ICONCACHE_FLAGS*/> > IdxCacheKey
;
153 typedef map
<IdxCacheKey
, ICON_ID
> IdxCacheMap
;
154 IdxCacheMap _idxCache
;
156 HIMAGELIST _himlSys_small
;
160 #define ICON_SIZE_X GetSystemMetrics(large_icons? SM_CXICON: SM_CXSMICON)
161 #define ICON_SIZE_Y GetSystemMetrics(large_icons? SM_CYICON: SM_CYSMICON)
164 /// create a bitmap from an icon
165 extern HBITMAP
create_bitmap_from_icon(HICON hIcon
, HBRUSH hbrush_bkgnd
, HDC hdc_wnd
/*, bool large_icons*/);
167 /// add icon with alpha channel to imagelist using the specified background color
168 extern int ImageList_AddAlphaIcon(HIMAGELIST himl
, HICON hIcon
, HBRUSH hbrush_bkgnd
, HDC hdc_wnd
);
170 /// retrieve icon from window
171 extern HICON
get_window_icon_small(HWND hwnd
);
172 extern HICON
get_window_icon_big(HWND hwnd
, bool allow_from_class
=true);
175 /// desktop management
178 typedef auto_ptr
<struct DesktopThread
> DesktopThreadPtr
;
184 DesktopThreadPtr _pThread
;
185 WindowHandle _hwndDesktop
;
187 Desktop(HDESK hdesktop
=0/*, HWINSTA hwinsta=0*/);
191 typedef auto_ptr
<Desktop
> DesktopPtr
;
192 typedef DesktopPtr DesktopRef
;
194 /// Thread class for additional desktops
195 struct DesktopThread
: public Thread
197 DesktopThread(Desktop
& desktop
)
210 typedef pair
<HWND
, DWORD
> MinimizeStruct
;
215 WindowHandle _hwndForeground
;
216 list
<MinimizeStruct
> _minimized
;
218 typedef Desktop DesktopRef
;
223 #define DESKTOP_COUNT 4
225 struct Desktops
: public vector
<DesktopRef
>
231 void SwitchToDesktop(int idx
);
232 void ToggleMinimize();
235 DesktopRef
& get_current_Desktop() {return (*this)[_current_desktop
];}
238 int _current_desktop
;
242 /// structure containing global variables of Explorer
243 extern struct ExplorerGlobals
247 void init(HINSTANCE hInstance
);
249 void read_persistent();
250 void write_persistent();
253 XMLPos
get_cfg(const char* path
);
255 HINSTANCE _hInstance
;
267 #ifndef __MINGW32__ // SHRestricted() missing in MinGW (as of 29.10.2003)
268 DWORD(STDAPICALLTYPE
* _SHRestricted
)(RESTRICTIONS
);
271 FileTypeManager _ftype_mgr
;
272 IconCache _icon_cache
;
274 HWND _hwndDesktopBar
;
284 Favorites _favorites
;
285 String _favorites_path
;
289 /// convenient loading of string resources
290 struct ResString
: public String
295 /// convenient loading of standard (32x32) icon resources
300 operator HICON() const {return _hicon
;}
306 /// convenient loading of small (16x16) icon resources
311 operator HICON() const {return _hicon
;}
317 /// convenient loading of icon resources with specified sizes
320 ResIconEx(UINT nid
, int w
, int h
);
322 operator HICON() const {return _hicon
;}
328 /// set big and small icons out of the resources for a window
329 extern void SetWindowIcon(HWND hwnd
, UINT nid
);
331 /// convenient loading of bitmap resources
335 ~ResBitmap() {DeleteObject(_hBmp
);}
337 operator HBITMAP() const {return _hBmp
;}