7db8f6be4c9f4c9aca8321a4e1586c032fbdc03a
[reactos.git] / reactos / subsys / system / explorer / shell / shellbrowser.h
1 /*
2 * Copyright 2003, 2004, 2005 Martin Fuchs
3 *
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.
8 *
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.
13 *
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
17 */
18
19
20 //
21 // Explorer clone
22 //
23 // shellbrowser.h
24 //
25 // Martin Fuchs, 23.07.2003
26 //
27
28 #include "../utility/treedroptarget.h"
29 #include "../utility/shellbrowserimpl.h"
30
31
32 /// information structure to hold current shell folder information
33 struct ShellPathInfo
34 {
35 ShellPathInfo(int mode=0) : _open_mode(mode) {}
36
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)
41 {
42 }
43
44 ShellPath _shell_path;
45 ShellPath _root_shell_path;
46
47 int _open_mode; //OPEN_WINDOW_MODE
48 };
49
50
51 struct BrowserCallback
52 {
53 virtual ~BrowserCallback() {}
54 virtual void entry_selected(Entry* entry) = 0;
55 };
56
57
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
62 #endif
63 {
64 ShellBrowser(HWND hwnd, HWND left_hwnd, WindowHandle& right_hwnd, ShellPathInfo& create_info,
65 HIMAGELIST himl, BrowserCallback* cb, CtxMenuInterfaces& cm_ifs);
66 virtual ~ShellBrowser();
67
68 //IOleWindow
69 virtual HRESULT STDMETHODCALLTYPE GetWindow(HWND* lphwnd)
70 {
71 *lphwnd = _hwnd;
72 return S_OK;
73 }
74
75 //IShellBrowser
76 virtual HRESULT STDMETHODCALLTYPE QueryActiveShellView(IShellView** ppshv)
77 {
78 _pShellView->AddRef();
79 *ppshv = _pShellView;
80 return S_OK;
81 }
82
83 virtual HRESULT STDMETHODCALLTYPE GetControlWindow(UINT id, HWND* lphwnd)
84 {
85 if (!lphwnd)
86 return E_POINTER;
87
88 if (id == FCW_TREE) {
89 *lphwnd = _left_hwnd;
90 return S_OK;
91 }
92
93 HWND hwnd = (HWND)SendMessage(_hWndFrame, PM_GET_CONTROLWINDOW, id, 0);
94
95 if (hwnd) {
96 *lphwnd = hwnd;
97 return S_OK;
98 }
99
100 return E_NOTIMPL;
101 }
102
103 virtual HRESULT STDMETHODCALLTYPE SendControlMsg(UINT id, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* pret)
104 {
105 if (!pret)
106 return E_POINTER;
107
108 HWND hstatusbar = (HWND)SendMessage(_hWndFrame, PM_GET_CONTROLWINDOW, id, 0);
109
110 if (hstatusbar) {
111 *pret = ::SendMessage(hstatusbar, uMsg, wParam, lParam);
112 return S_OK;
113 }
114
115 return E_NOTIMPL;
116 }
117
118 const Root& get_root() const {return _root;}
119
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);
124
125 LRESULT Init(HWND hWndFrame);
126
127 void Init(HIMAGELIST himl)
128 {
129 InitializeTree(himl);
130 InitDragDrop();
131 }
132
133 int InsertSubitems(HTREEITEM hParentItem, Entry* entry, IShellFolder* pParentFolder);
134
135 bool jump_to_pidl(LPCITEMIDLIST pidl);
136
137 HRESULT OnDefaultCommand(LPIDA pida);
138
139 void UpdateFolderView(IShellFolder* folder);
140 HTREEITEM select_entry(HTREEITEM hitem, Entry* entry, bool expand=true);
141
142 // for SDIMainFrame
143 void jump_to(LPCITEMIDLIST pidl);
144
145 protected:
146 HWND _hwnd;
147 HWND _left_hwnd;
148 WindowHandle& _right_hwnd;
149 ShellPathInfo& _create_info;
150 HIMAGELIST _himl;
151 BrowserCallback* _callback;
152
153 WindowHandle _hWndFrame;
154 ShellFolder _folder;
155
156 IShellView* _pShellView; // current hosted shellview
157 TreeDropTarget* _pDropTarget;
158
159 HTREEITEM _last_sel;
160
161 Root _root;
162 ShellDirectory* _cur_dir;
163
164 CtxMenuInterfaces& _cm_ifs;
165
166 void InitializeTree(HIMAGELIST himl);
167 bool InitDragDrop();
168
169 #ifndef __MINGW32__ // IShellFolderViewCB missing in MinGW (as of 25.09.2005)
170 typedef IComSrvBase<IShellFolderViewCB, ShellBrowser> super;
171
172 // IShellFolderViewCB
173 virtual HRESULT STDMETHODCALLTYPE MessageSFVCB(UINT uMsg, WPARAM wParam, LPARAM lParam);
174 #endif
175 };
176
177
178 template<typename BASE> struct ShellBrowserChildT
179 : public BASE, public BrowserCallback
180 {
181 typedef BASE super;
182
183 // constructor for SDIMainFrame
184 ShellBrowserChildT(HWND hwnd)
185 : super(hwnd)
186 {
187 _himlSmall = 0;
188 }
189
190 // constructor for MDIShellBrowserChild
191 ShellBrowserChildT(HWND hwnd, const ShellChildWndInfo& info)
192 : super(hwnd, info)
193 {
194 _himlSmall = 0;
195 }
196
197 void init_himl()
198 {
199 SHFILEINFO sfi;
200
201 _himlSmall = (HIMAGELIST)SHGetFileInfo(TEXT("C:\\"), 0, &sfi, sizeof(SHFILEINFO), SHGFI_SYSICONINDEX|SHGFI_SMALLICON);
202 // _himlLarge = (HIMAGELIST)SHGetFileInfo(TEXT("C:\\"), 0, &sfi, sizeof(SHFILEINFO), SHGFI_SYSICONINDEX|SHGFI_LARGEICON);
203 }
204
205 protected:
206 HIMAGELIST _himlSmall; // list
207 // HIMAGELIST _himlLarge; // shell image
208
209 protected:
210 auto_ptr<ShellBrowser> _shellBrowser;
211
212 LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
213 {
214 switch(nmsg) {
215 case PM_GET_SHELLBROWSER_PTR:
216 return (LRESULT)&*_shellBrowser;
217
218 case WM_GETISHELLBROWSER: // for Registry Explorer Plugin
219 return (LRESULT)static_cast<IShellBrowser*>(&*_shellBrowser);
220
221 default:
222 return super::WndProc(nmsg, wparam, lparam);
223 }
224
225 return 0;
226 }
227
228 int Notify(int id, NMHDR* pnmh)
229 {
230 if (&*_shellBrowser)
231 switch(pnmh->code) {
232 case TVN_GETDISPINFO: _shellBrowser->OnTreeGetDispInfo(id, pnmh); break;
233 case TVN_SELCHANGED: _shellBrowser->OnTreeItemSelected(id, (LPNMTREEVIEW)pnmh); break;
234 case TVN_ITEMEXPANDING: _shellBrowser->OnTreeItemExpanding(id, (LPNMTREEVIEW)pnmh); break;
235 case NM_RCLICK: _shellBrowser->OnTreeItemRClick(id, pnmh); break;
236 default: return super::Notify(id, pnmh);
237 }
238 else
239 return super::Notify(id, pnmh);
240
241 return 0;
242 }
243 };
244
245
246 #ifndef _NO_MDI
247
248 struct MDIShellBrowserChild : public ExtContextMenuHandlerT<
249 ShellBrowserChildT<ChildWindow>
250 >
251 {
252 typedef ExtContextMenuHandlerT<
253 ShellBrowserChildT<ChildWindow>
254 > super;
255
256 MDIShellBrowserChild(HWND hwnd, const ShellChildWndInfo& info);
257
258 static MDIShellBrowserChild* create(const ShellChildWndInfo& info);
259
260 LRESULT Init(LPCREATESTRUCT);
261
262 virtual String jump_to_int(LPCTSTR url);
263
264 protected:
265 ShellChildWndInfo _create_info;
266 ShellPathInfo _shellpath_info;
267
268 LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam);
269
270 void update_shell_browser();
271
272 // interface BrowserCallback
273 virtual void entry_selected(Entry* entry);
274 };
275
276 #endif