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 #ifndef __MINGW32__ // IShellFolderViewCB missing in MinGW (as of 25.09.2005)
62 , public IComSrvBase
<IShellFolderViewCB
, ShellBrowser
>, public SimpleComObject
65 ShellBrowser(HWND hwnd
, HWND hwndFrame
, HWND left_hwnd
, WindowHandle
& right_hwnd
, ShellPathInfo
& create_info
,
66 BrowserCallback
* cb
, CtxMenuInterfaces
& cm_ifs
);
67 virtual ~ShellBrowser();
70 virtual HRESULT STDMETHODCALLTYPE
GetWindow(HWND
* lphwnd
)
77 virtual HRESULT STDMETHODCALLTYPE
QueryActiveShellView(IShellView
** ppshv
)
79 _pShellView
->AddRef();
84 virtual HRESULT STDMETHODCALLTYPE
GetControlWindow(UINT id
, HWND
* lphwnd
)
94 HWND hwnd
= (HWND
)SendMessage(_hwndFrame
, PM_GET_CONTROLWINDOW
, id
, 0);
104 virtual HRESULT STDMETHODCALLTYPE
SendControlMsg(UINT id
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
* pret
)
109 HWND hstatusbar
= (HWND
)SendMessage(_hwndFrame
, PM_GET_CONTROLWINDOW
, id
, 0);
112 *pret
= ::SendMessage(hstatusbar
, uMsg
, wParam
, lParam
);
119 const Root
& get_root() const {return _root
;}
121 void OnTreeGetDispInfo(int idCtrl
, LPNMHDR pnmh
);
122 void OnTreeItemExpanding(int idCtrl
, LPNMTREEVIEW pnmtv
);
123 void OnTreeItemRClick(int idCtrl
, LPNMHDR pnmh
);
124 void OnTreeItemSelected(int idCtrl
, LPNMTREEVIEW pnmtv
);
128 int InsertSubitems(HTREEITEM hParentItem
, Entry
* entry
, IShellFolder
* pParentFolder
);
130 bool jump_to_pidl(LPCITEMIDLIST pidl
);
132 HRESULT
OnDefaultCommand(LPIDA pida
);
134 void UpdateFolderView(IShellFolder
* folder
);
135 HTREEITEM
select_entry(HTREEITEM hitem
, Entry
* entry
, bool expand
=true);
137 bool select_folder(Entry
* entry
, bool expand
);
140 void jump_to(LPCITEMIDLIST pidl
);
142 void invalidate_cache();
144 bool TranslateAccelerator(LPMSG lpmsg
);
150 WindowHandle
& _right_hwnd
;
151 ShellPathInfo
& _create_info
;
153 HIMAGELIST _himl_old
;
154 BrowserCallback
* _callback
;
158 IShellView
* _pShellView
; // current hosted shellview
159 TreeDropTarget
* _pDropTarget
;
164 ShellDirectory
* _cur_dir
;
166 CtxMenuInterfaces
& _cm_ifs
;
168 void InitializeTree();
171 #ifndef __MINGW32__ // IShellFolderViewCB missing in MinGW (as of 25.09.2005)
172 typedef IComSrvBase
<IShellFolderViewCB
, ShellBrowser
> super
;
174 // IShellFolderViewCB
175 virtual HRESULT STDMETHODCALLTYPE
MessageSFVCB(UINT uMsg
, WPARAM wParam
, LPARAM lParam
);
178 map
<int, int> _image_map
;
180 int get_image_idx(int icon_id
);
186 #define C_DRIVE_STR TEXT("C:\\")
188 // work around GCC's wide string constant bug
190 extern const LPCTSTR C_DRIVE
;
192 #define C_DRIVE C_DRIVE_STR
195 template<typename BASE
> struct ShellBrowserChildT
196 : public BASE
, public BrowserCallback
200 // constructor for SDIMainFrame
201 ShellBrowserChildT(HWND hwnd
)
206 // constructor for MDIShellBrowserChild
207 ShellBrowserChildT(HWND hwnd
, const ShellChildWndInfo
& info
)
213 auto_ptr
<ShellBrowser
> _shellBrowser
;
215 LRESULT
WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
218 case PM_GET_SHELLBROWSER_PTR
:
219 return (LRESULT
)&*_shellBrowser
;
221 case WM_GETISHELLBROWSER
: // for Registry Explorer Plugin
222 return (LRESULT
)static_cast<IShellBrowser
*>(&*_shellBrowser
);
225 return super::WndProc(nmsg
, wparam
, lparam
);
231 int Notify(int id
, NMHDR
* pnmh
)
233 if (_shellBrowser
.get())
235 case TVN_GETDISPINFO
: _shellBrowser
->OnTreeGetDispInfo(id
, pnmh
); break;
236 case TVN_SELCHANGED
: _shellBrowser
->OnTreeItemSelected(id
, (LPNMTREEVIEW
)pnmh
); break;
237 case TVN_ITEMEXPANDING
: _shellBrowser
->OnTreeItemExpanding(id
, (LPNMTREEVIEW
)pnmh
); break;
238 case NM_RCLICK
: _shellBrowser
->OnTreeItemRClick(id
, pnmh
); break;
239 default: return super::Notify(id
, pnmh
);
242 return super::Notify(id
, pnmh
);
251 struct MDIShellBrowserChild
: public ExtContextMenuHandlerT
<
252 ShellBrowserChildT
<ChildWindow
>
255 typedef ExtContextMenuHandlerT
<
256 ShellBrowserChildT
<ChildWindow
>
259 MDIShellBrowserChild(HWND hwnd
, const ShellChildWndInfo
& info
);
261 static MDIShellBrowserChild
* create(const ShellChildWndInfo
& info
);
263 LRESULT
Init(LPCREATESTRUCT
);
265 virtual String
jump_to_int(LPCTSTR url
);
268 ShellChildWndInfo _create_info
;
269 ShellPathInfo _shellpath_info
;
271 LRESULT
WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
273 void update_shell_browser();
275 // interface BrowserCallback
276 virtual void entry_selected(Entry
* entry
);