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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 // Martin Fuchs, 23.07.2003
28 #include "../utility/treedroptarget.h"
29 #include "../utility/shellbrowserimpl.h"
32 /// information structure to hold current shell folder information
35 ShellPathInfo(int mode
=0) : _open_mode(mode
) {}
37 ShellPathInfo(const ShellChildWndInfo
& info
)
38 : _shell_path(info
._shell_path
),
39 _root_shell_path(info
._root_shell_path
),
40 _open_mode(info
._open_mode
)
44 ShellPath _shell_path
;
45 ShellPath _root_shell_path
;
47 int _open_mode
; //OPEN_WINDOW_MODE
51 struct BrowserCallback
53 virtual ~BrowserCallback() {}
54 virtual void entry_selected(Entry
* entry
) = 0;
58 /// Implementation of IShellBrowserImpl interface in explorer child windows
59 struct ShellBrowser
: public IShellBrowserImpl
60 #ifndef __MINGW32__ // IShellFolderViewCB missing in MinGW (as of 25.09.2005)
61 , public IComSrvBase
<IShellFolderViewCB
, ShellBrowser
>, public SimpleComObject
64 ShellBrowser(HWND hwnd
, HWND hwndFrame
, HWND left_hwnd
, WindowHandle
& right_hwnd
, ShellPathInfo
& create_info
,
65 BrowserCallback
* cb
, CtxMenuInterfaces
& cm_ifs
);
66 virtual ~ShellBrowser();
69 virtual HRESULT STDMETHODCALLTYPE
GetWindow(HWND
* lphwnd
)
76 virtual HRESULT STDMETHODCALLTYPE
QueryActiveShellView(IShellView
** ppshv
)
78 _pShellView
->AddRef();
83 virtual HRESULT STDMETHODCALLTYPE
GetControlWindow(UINT id
, HWND
* lphwnd
)
93 HWND hwnd
= (HWND
)SendMessage(_hwndFrame
, PM_GET_CONTROLWINDOW
, id
, 0);
103 virtual HRESULT STDMETHODCALLTYPE
SendControlMsg(UINT id
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
* pret
)
108 HWND hstatusbar
= (HWND
)SendMessage(_hwndFrame
, PM_GET_CONTROLWINDOW
, id
, 0);
111 *pret
= ::SendMessage(hstatusbar
, uMsg
, wParam
, lParam
);
118 const Root
& get_root() const {return _root
;}
120 void OnTreeGetDispInfo(int idCtrl
, LPNMHDR pnmh
);
121 void OnTreeItemExpanding(int idCtrl
, LPNMTREEVIEW pnmtv
);
122 void OnTreeItemRClick(int idCtrl
, LPNMHDR pnmh
);
123 void OnTreeItemSelected(int idCtrl
, LPNMTREEVIEW pnmtv
);
127 int InsertSubitems(HTREEITEM hParentItem
, Entry
* entry
, IShellFolder
* pParentFolder
);
129 bool jump_to_pidl(LPCITEMIDLIST pidl
);
131 HRESULT
OnDefaultCommand(LPIDA pida
);
133 void UpdateFolderView(IShellFolder
* folder
);
134 HTREEITEM
select_entry(HTREEITEM hitem
, Entry
* entry
, bool expand
=true);
136 bool select_folder(Entry
* entry
, bool expand
);
139 void jump_to(LPCITEMIDLIST pidl
);
141 void invalidate_cache();
146 WindowHandle
& _right_hwnd
;
147 ShellPathInfo
& _create_info
;
149 HIMAGELIST _himl_old
;
150 BrowserCallback
* _callback
;
155 IShellView
* _pShellView
; // current hosted shellview
156 TreeDropTarget
* _pDropTarget
;
161 ShellDirectory
* _cur_dir
;
163 CtxMenuInterfaces
& _cm_ifs
;
165 void InitializeTree();
168 #ifndef __MINGW32__ // IShellFolderViewCB missing in MinGW (as of 25.09.2005)
169 typedef IComSrvBase
<IShellFolderViewCB
, ShellBrowser
> super
;
171 // IShellFolderViewCB
172 virtual HRESULT STDMETHODCALLTYPE
MessageSFVCB(UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
175 map
<int, int> _image_map
;
177 int get_image_idx(int icon_id
);
181 #define C_DRIVE_STR TEXT("C:\\")
183 // work around GCC's wide string constant bug
185 extern const LPCTSTR C_DRIVE
;
187 #define C_DRIVE C_DRIVE_STR
190 template<typename BASE
> struct ShellBrowserChildT
191 : public BASE
, public BrowserCallback
195 // constructor for SDIMainFrame
196 ShellBrowserChildT(HWND hwnd
)
201 // constructor for MDIShellBrowserChild
202 ShellBrowserChildT(HWND hwnd
, const ShellChildWndInfo
& info
)
208 auto_ptr
<ShellBrowser
> _shellBrowser
;
210 LRESULT
WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
213 case PM_GET_SHELLBROWSER_PTR
:
214 return (LRESULT
)&*_shellBrowser
;
216 case WM_GETISHELLBROWSER
: // for Registry Explorer Plugin
217 return (LRESULT
)static_cast<IShellBrowser
*>(&*_shellBrowser
);
220 return super::WndProc(nmsg
, wparam
, lparam
);
226 int Notify(int id
, NMHDR
* pnmh
)
228 if (_shellBrowser
.get())
230 case TVN_GETDISPINFO
: _shellBrowser
->OnTreeGetDispInfo(id
, pnmh
); break;
231 case TVN_SELCHANGED
: _shellBrowser
->OnTreeItemSelected(id
, (LPNMTREEVIEW
)pnmh
); break;
232 case TVN_ITEMEXPANDING
: _shellBrowser
->OnTreeItemExpanding(id
, (LPNMTREEVIEW
)pnmh
); break;
233 case NM_RCLICK
: _shellBrowser
->OnTreeItemRClick(id
, pnmh
); break;
234 default: return super::Notify(id
, pnmh
);
237 return super::Notify(id
, pnmh
);
246 struct MDIShellBrowserChild
: public ExtContextMenuHandlerT
<
247 ShellBrowserChildT
<ChildWindow
>
250 typedef ExtContextMenuHandlerT
<
251 ShellBrowserChildT
<ChildWindow
>
254 MDIShellBrowserChild(HWND hwnd
, const ShellChildWndInfo
& info
);
256 static MDIShellBrowserChild
* create(const ShellChildWndInfo
& info
);
258 LRESULT
Init(LPCREATESTRUCT
);
260 virtual String
jump_to_int(LPCTSTR url
);
263 ShellChildWndInfo _create_info
;
264 ShellPathInfo _shellpath_info
;
266 LRESULT
WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
268 void update_shell_browser();
270 // interface BrowserCallback
271 virtual void entry_selected(Entry
* entry
);