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