43b7ff915d96a470c6cdcc06b612a65de1354e7f
[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 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()
128 {
129 InitializeTree();
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 void invalidate_cache();
146
147 protected:
148 HWND _hwnd;
149 HWND _left_hwnd;
150 WindowHandle& _right_hwnd;
151 ShellPathInfo& _create_info;
152 HIMAGELIST _himl;
153 HIMAGELIST _himl_old;
154 BrowserCallback* _callback;
155
156 WindowHandle _hWndFrame;
157 ShellFolder _folder;
158
159 IShellView* _pShellView; // current hosted shellview
160 TreeDropTarget* _pDropTarget;
161
162 HTREEITEM _last_sel;
163
164 Root _root;
165 ShellDirectory* _cur_dir;
166
167 CtxMenuInterfaces& _cm_ifs;
168
169 void InitializeTree();
170 bool InitDragDrop();
171
172 #ifndef __MINGW32__ // IShellFolderViewCB missing in MinGW (as of 25.09.2005)
173 typedef IComSrvBase<IShellFolderViewCB, ShellBrowser> super;
174
175 // IShellFolderViewCB
176 virtual HRESULT STDMETHODCALLTYPE MessageSFVCB(UINT uMsg, WPARAM wParam, LPARAM lParam);
177 #endif
178
179 map<int, int> _image_map;
180
181 int get_image_idx(int icon_id);
182 };
183
184
185 #define C_DRIVE_STR TEXT("C:\\")
186
187 // work around GCC's wide string constant bug
188 #ifdef __GNUC__
189 extern const LPCTSTR C_DRIVE;
190 #else
191 #define C_DRIVE C_DRIVE_STR
192 #endif
193
194 template<typename BASE> struct ShellBrowserChildT
195 : public BASE, public BrowserCallback
196 {
197 typedef BASE super;
198
199 // constructor for SDIMainFrame
200 ShellBrowserChildT(HWND hwnd)
201 : super(hwnd)
202 {
203 }
204
205 // constructor for MDIShellBrowserChild
206 ShellBrowserChildT(HWND hwnd, const ShellChildWndInfo& info)
207 : super(hwnd, info)
208 {
209 }
210
211 protected:
212 auto_ptr<ShellBrowser> _shellBrowser;
213
214 LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
215 {
216 switch(nmsg) {
217 case PM_GET_SHELLBROWSER_PTR:
218 return (LRESULT)&*_shellBrowser;
219
220 case WM_GETISHELLBROWSER: // for Registry Explorer Plugin
221 return (LRESULT)static_cast<IShellBrowser*>(&*_shellBrowser);
222
223 default:
224 return super::WndProc(nmsg, wparam, lparam);
225 }
226
227 return 0;
228 }
229
230 int Notify(int id, NMHDR* pnmh)
231 {
232 if (_shellBrowser.get())
233 switch(pnmh->code) {
234 case TVN_GETDISPINFO: _shellBrowser->OnTreeGetDispInfo(id, pnmh); break;
235 case TVN_SELCHANGED: _shellBrowser->OnTreeItemSelected(id, (LPNMTREEVIEW)pnmh); break;
236 case TVN_ITEMEXPANDING: _shellBrowser->OnTreeItemExpanding(id, (LPNMTREEVIEW)pnmh); break;
237 case NM_RCLICK: _shellBrowser->OnTreeItemRClick(id, pnmh); break;
238 default: return super::Notify(id, pnmh);
239 }
240 else
241 return super::Notify(id, pnmh);
242
243 return 0;
244 }
245 };
246
247
248 #ifndef _NO_MDI
249
250 struct MDIShellBrowserChild : public ExtContextMenuHandlerT<
251 ShellBrowserChildT<ChildWindow>
252 >
253 {
254 typedef ExtContextMenuHandlerT<
255 ShellBrowserChildT<ChildWindow>
256 > super;
257
258 MDIShellBrowserChild(HWND hwnd, const ShellChildWndInfo& info);
259
260 static MDIShellBrowserChild* create(const ShellChildWndInfo& info);
261
262 LRESULT Init(LPCREATESTRUCT);
263
264 virtual String jump_to_int(LPCTSTR url);
265
266 protected:
267 ShellChildWndInfo _create_info;
268 ShellPathInfo _shellpath_info;
269
270 LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam);
271
272 void update_shell_browser();
273
274 // interface BrowserCallback
275 virtual void entry_selected(Entry* entry);
276 };
277
278 #endif