2 * Copyright 2003, 2004, 2005 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
28 #include "../utility/treedroptarget.h"
29 #include "../utility/shellbrowserimpl.h"
33 /// information structure to hold current shell folder information
36 ShellPathInfo(int mode
=0) : _open_mode(mode
) {}
38 ShellPathInfo(const ShellChildWndInfo
& info
)
39 : _shell_path(info
._shell_path
),
40 _root_shell_path(info
._root_shell_path
),
41 _open_mode(info
._open_mode
)
45 ShellPath _shell_path
;
46 ShellPath _root_shell_path
;
48 int _open_mode
; //OPEN_WINDOW_MODE
52 struct BrowserCallback
54 virtual ~BrowserCallback() {}
55 virtual void entry_selected(Entry
* entry
) = 0;
59 /// Implementation of IShellBrowserImpl interface in explorer child windows
60 struct ShellBrowser
: public IShellBrowserImpl
,
61 public IComSrvBase
<IShellFolderViewCB
, ShellBrowser
>, public SimpleComObject
63 ShellBrowser(HWND hwnd
, HWND hwndFrame
, HWND left_hwnd
, WindowHandle
& right_hwnd
, ShellPathInfo
& create_info
,
64 BrowserCallback
* cb
, CtxMenuInterfaces
& cm_ifs
);
65 virtual ~ShellBrowser();
68 virtual HRESULT STDMETHODCALLTYPE
GetWindow(HWND
* lphwnd
)
75 virtual HRESULT STDMETHODCALLTYPE
QueryActiveShellView(IShellView
** ppshv
)
77 _pShellView
->AddRef();
82 virtual HRESULT STDMETHODCALLTYPE
GetControlWindow(UINT id
, HWND
* lphwnd
)
92 HWND hwnd
= (HWND
)SendMessage(_hwndFrame
, PM_GET_CONTROLWINDOW
, id
, 0);
102 virtual HRESULT STDMETHODCALLTYPE
SendControlMsg(UINT id
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
* pret
)
107 HWND hstatusbar
= (HWND
)SendMessage(_hwndFrame
, PM_GET_CONTROLWINDOW
, id
, 0);
110 *pret
= ::SendMessage(hstatusbar
, uMsg
, wParam
, lParam
);
117 const Root
& get_root() const {return _root
;}
119 void OnTreeGetDispInfo(int idCtrl
, LPNMHDR pnmh
);
120 void OnTreeItemExpanding(int idCtrl
, LPNMTREEVIEW pnmtv
);
121 void OnTreeItemRClick(int idCtrl
, LPNMHDR pnmh
);
122 void OnTreeItemSelected(int idCtrl
, LPNMTREEVIEW pnmtv
);
126 int InsertSubitems(HTREEITEM hParentItem
, Entry
* entry
, IShellFolder
* pParentFolder
);
128 bool jump_to_pidl(LPCITEMIDLIST pidl
);
130 HRESULT
OnDefaultCommand(LPIDA pida
);
132 void UpdateFolderView(IShellFolder
* folder
);
133 HTREEITEM
select_entry(HTREEITEM hitem
, Entry
* entry
, bool expand
=true);
135 bool select_folder(Entry
* entry
, bool expand
);
138 void jump_to(LPCITEMIDLIST pidl
);
140 void invalidate_cache();
142 bool TranslateAccelerator(LPMSG lpmsg
);
148 WindowHandle
& _right_hwnd
;
149 ShellPathInfo
& _create_info
;
151 HIMAGELIST _himl_old
;
152 BrowserCallback
* _callback
;
156 IShellView
* _pShellView
; // current hosted shellview
157 TreeDropTarget
* _pDropTarget
;
162 ShellDirectory
* _cur_dir
;
164 CtxMenuInterfaces
& _cm_ifs
;
166 void InitializeTree();
169 typedef IComSrvBase
<IShellFolderViewCB
, ShellBrowser
> super
;
171 // IShellFolderViewCB
172 virtual HRESULT STDMETHODCALLTYPE
MessageSFVCB(UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
174 map
<int, int> _image_map
;
176 int get_image_idx(int icon_id
);
182 #define C_DRIVE_STR TEXT("C:\\")
184 // work around GCC's wide string constant bug
186 extern const LPCTSTR C_DRIVE
;
188 #define C_DRIVE C_DRIVE_STR
191 template<typename BASE
> struct ShellBrowserChildT
192 : public BASE
, public BrowserCallback
196 // constructor for SDIMainFrame
197 ShellBrowserChildT(HWND hwnd
)
202 // constructor for MDIShellBrowserChild
203 ShellBrowserChildT(HWND hwnd
, const ShellChildWndInfo
& info
)
209 auto_ptr
<ShellBrowser
> _shellBrowser
;
211 LRESULT
WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
214 case PM_GET_SHELLBROWSER_PTR
:
215 return (LRESULT
)&*_shellBrowser
;
217 case WM_GETISHELLBROWSER
: // for Registry Explorer Plugin
218 return (LRESULT
)static_cast<IShellBrowser
*>(&*_shellBrowser
);
221 return super::WndProc(nmsg
, wparam
, lparam
);
227 int Notify(int id
, NMHDR
* pnmh
)
229 if (_shellBrowser
.get())
231 case TVN_GETDISPINFO
: _shellBrowser
->OnTreeGetDispInfo(id
, pnmh
); break;
232 case TVN_SELCHANGED
: _shellBrowser
->OnTreeItemSelected(id
, (LPNMTREEVIEW
)pnmh
); break;
233 case TVN_ITEMEXPANDING
: _shellBrowser
->OnTreeItemExpanding(id
, (LPNMTREEVIEW
)pnmh
); break;
234 case NM_RCLICK
: _shellBrowser
->OnTreeItemRClick(id
, pnmh
); break;
235 default: return super::Notify(id
, pnmh
);
238 return super::Notify(id
, pnmh
);
247 struct MDIShellBrowserChild
: public ExtContextMenuHandlerT
<
248 ShellBrowserChildT
<ChildWindow
>
251 typedef ExtContextMenuHandlerT
<
252 ShellBrowserChildT
<ChildWindow
>
255 MDIShellBrowserChild(HWND hwnd
, const ShellChildWndInfo
& info
);
257 static MDIShellBrowserChild
* create(const ShellChildWndInfo
& info
);
259 LRESULT
Init(LPCREATESTRUCT
);
261 virtual String
jump_to_int(LPCTSTR url
);
264 ShellChildWndInfo _create_info
;
265 ShellPathInfo _shellpath_info
;
267 LRESULT
WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
269 void update_shell_browser();
271 // interface BrowserCallback
272 virtual void entry_selected(Entry
* entry
);