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
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 void entry_selected(Entry
* entry
) = 0;
57 /// Implementation of IShellBrowserImpl interface in explorer child windows
58 struct ShellBrowser
: public IShellBrowserImpl
60 ShellBrowser(HWND hwnd
, HWND left_hwnd
, WindowHandle
& right_hwnd
, ShellPathInfo
& create_info
, HIMAGELIST himl
, BrowserCallback
* cb
);
61 virtual ~ShellBrowser();
64 virtual HRESULT STDMETHODCALLTYPE
GetWindow(HWND
* lphwnd
)
71 virtual HRESULT STDMETHODCALLTYPE
QueryActiveShellView(IShellView
** ppshv
)
73 _pShellView
->AddRef();
78 virtual HRESULT STDMETHODCALLTYPE
GetControlWindow(UINT id
, HWND
* lphwnd
)
88 HWND hwnd
= (HWND
)SendMessage(_hWndFrame
, PM_GET_CONTROLWINDOW
, id
, 0);
98 virtual HRESULT STDMETHODCALLTYPE
SendControlMsg(UINT id
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, LRESULT
* pret
)
103 HWND hstatusbar
= (HWND
)SendMessage(_hWndFrame
, PM_GET_CONTROLWINDOW
, id
, 0);
106 *pret
= ::SendMessage(hstatusbar
, uMsg
, wParam
, lParam
);
113 const Root
& get_root() const {return _root
;}
115 void OnTreeGetDispInfo(int idCtrl
, LPNMHDR pnmh
);
116 void OnTreeItemExpanding(int idCtrl
, LPNMTREEVIEW pnmtv
);
117 void OnTreeItemRClick(int idCtrl
, LPNMHDR pnmh
);
118 void OnTreeItemSelected(int idCtrl
, LPNMTREEVIEW pnmtv
);
120 LRESULT
Init(HWND hWndFrame
);
122 void Init(HIMAGELIST himl
)
124 InitializeTree(himl
);
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 void Tree_DoItemMenu(HWND hwndTreeView
, HTREEITEM hItem
, LPPOINT pptScreen
);
136 HTREEITEM
select_entry(HTREEITEM hitem
, Entry
* entry
, bool expand
=true);
141 WindowHandle
& _right_hwnd
;
142 ShellPathInfo
& _create_info
;
144 BrowserCallback
* _callback
;
146 WindowHandle _hWndFrame
;
149 IShellView
* _pShellView
; // current hosted shellview
150 TreeDropTarget
* _pDropTarget
;
155 ShellDirectory
* _cur_dir
;
157 void InitializeTree(HIMAGELIST himl
);
161 void jump_to(LPCITEMIDLIST pidl
);
165 template<typename BASE
> struct ShellBrowserChildT
166 : public BASE
, public BrowserCallback
170 // constructor for SDIMainFrame
171 ShellBrowserChildT(HWND hwnd
)
177 // constructor for MDIShellBrowserChild
178 ShellBrowserChildT(HWND hwnd
, const ShellChildWndInfo
& info
)
188 _himlSmall
= (HIMAGELIST
)SHGetFileInfo(TEXT("C:\\"), 0, &sfi
, sizeof(SHFILEINFO
), SHGFI_SYSICONINDEX
|SHGFI_SMALLICON
);
189 // _himlLarge = (HIMAGELIST)SHGetFileInfo(TEXT("C:\\"), 0, &sfi, sizeof(SHFILEINFO), SHGFI_SYSICONINDEX|SHGFI_LARGEICON);
193 HIMAGELIST _himlSmall
; // list
194 // HIMAGELIST _himlLarge; // shell image
197 auto_ptr
<ShellBrowser
> _shellBrowser
;
199 LRESULT
WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
)
202 case PM_GET_SHELLBROWSER_PTR
:
203 return (LRESULT
)&*_shellBrowser
;
205 case WM_GETISHELLBROWSER
: // for Registry Explorer Plugin
206 return (LRESULT
)static_cast<IShellBrowser
*>(&*_shellBrowser
);
209 return super::WndProc(nmsg
, wparam
, lparam
);
215 int Notify(int id
, NMHDR
* pnmh
)
219 case TVN_GETDISPINFO
: _shellBrowser
->OnTreeGetDispInfo(id
, pnmh
); break;
220 case TVN_SELCHANGED
: _shellBrowser
->OnTreeItemSelected(id
, (LPNMTREEVIEW
)pnmh
); break;
221 case TVN_ITEMEXPANDING
: _shellBrowser
->OnTreeItemExpanding(id
, (LPNMTREEVIEW
)pnmh
); break;
222 case NM_RCLICK
: _shellBrowser
->OnTreeItemRClick(id
, pnmh
); break;
223 default: return super::Notify(id
, pnmh
);
226 return super::Notify(id
, pnmh
);
235 struct MDIShellBrowserChild
: public ShellBrowserChildT
<ChildWindow
>
237 typedef ShellBrowserChildT
<ChildWindow
> super
;
239 MDIShellBrowserChild(HWND hwnd
, const ShellChildWndInfo
& info
);
241 static MDIShellBrowserChild
* create(const ShellChildWndInfo
& info
);
243 LRESULT
Init(LPCREATESTRUCT
);
245 virtual String
jump_to_int(LPCTSTR url
);
248 ShellChildWndInfo _create_info
;
249 ShellPathInfo _shellpath_info
;
251 LRESULT
WndProc(UINT nmsg
, WPARAM wparam
, LPARAM lparam
);
253 void update_shell_browser();
255 // interface BrowserCallback
256 virtual void entry_selected(Entry
* entry
);