integrate optional SDI mode into main explorer branch
[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, HIMAGELIST himl, BrowserCallback* cb);
61 virtual ~ShellBrowser();
62
63 //IOleWindow
64 virtual HRESULT STDMETHODCALLTYPE GetWindow(HWND* lphwnd)
65 {
66 *lphwnd = _hwnd;
67 return S_OK;
68 }
69
70 //IShellBrowser
71 virtual HRESULT STDMETHODCALLTYPE QueryActiveShellView(IShellView** ppshv)
72 {
73 _pShellView->AddRef();
74 *ppshv = _pShellView;
75 return S_OK;
76 }
77
78 virtual HRESULT STDMETHODCALLTYPE GetControlWindow(UINT id, HWND* lphwnd)
79 {
80 if (!lphwnd)
81 return E_POINTER;
82
83 if (id == FCW_TREE) {
84 *lphwnd = _left_hwnd;
85 return S_OK;
86 }
87
88 HWND hwnd = (HWND)SendMessage(_hWndFrame, PM_GET_CONTROLWINDOW, id, 0);
89
90 if (hwnd) {
91 *lphwnd = hwnd;
92 return S_OK;
93 }
94
95 return E_NOTIMPL;
96 }
97
98 virtual HRESULT STDMETHODCALLTYPE SendControlMsg(UINT id, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* pret)
99 {
100 if (!pret)
101 return E_POINTER;
102
103 HWND hstatusbar = (HWND)SendMessage(_hWndFrame, PM_GET_CONTROLWINDOW, id, 0);
104
105 if (hstatusbar) {
106 *pret = ::SendMessage(hstatusbar, uMsg, wParam, lParam);
107 return S_OK;
108 }
109
110 return E_NOTIMPL;
111 }
112
113 const Root& get_root() const {return _root;}
114
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);
119
120 LRESULT Init(HWND hWndFrame);
121
122 void Init(HIMAGELIST himl)
123 {
124 InitializeTree(himl);
125 InitDragDrop();
126 }
127
128 int InsertSubitems(HTREEITEM hParentItem, Entry* entry, IShellFolder* pParentFolder);
129
130 bool jump_to_pidl(LPCITEMIDLIST pidl);
131
132 HRESULT OnDefaultCommand(LPIDA pida);
133
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);
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 void InitializeTree(HIMAGELIST himl);
158 bool InitDragDrop();
159
160 // for SDIMainFrame
161 void jump_to(LPCITEMIDLIST pidl);
162 };
163
164
165 template<typename BASE> struct ShellBrowserChildT
166 : public BASE, public BrowserCallback
167 {
168 typedef BASE super;
169
170 // constructor for SDIMainFrame
171 ShellBrowserChildT(HWND hwnd)
172 : super(hwnd)
173 {
174 _himlSmall = 0;
175 }
176
177 // constructor for MDIShellBrowserChild
178 ShellBrowserChildT(HWND hwnd, const ShellChildWndInfo& info)
179 : super(hwnd, info)
180 {
181 _himlSmall = 0;
182 }
183
184 void init_himl()
185 {
186 SHFILEINFO sfi;
187
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);
190 }
191
192 protected:
193 HIMAGELIST _himlSmall; // list
194 // HIMAGELIST _himlLarge; // shell image
195
196 protected:
197 auto_ptr<ShellBrowser> _shellBrowser;
198
199 LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
200 {
201 switch(nmsg) {
202 case PM_GET_SHELLBROWSER_PTR:
203 return (LRESULT)&*_shellBrowser;
204
205 case WM_GETISHELLBROWSER: // for Registry Explorer Plugin
206 return (LRESULT)static_cast<IShellBrowser*>(&*_shellBrowser);
207
208 default:
209 return super::WndProc(nmsg, wparam, lparam);
210 }
211
212 return 0;
213 }
214
215 int Notify(int id, NMHDR* pnmh)
216 {
217 if (&*_shellBrowser)
218 switch(pnmh->code) {
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);
224 }
225 else
226 return super::Notify(id, pnmh);
227
228 return 0;
229 }
230 };
231
232
233 #ifndef _NO_MDI
234
235 struct MDIShellBrowserChild : public ShellBrowserChildT<ChildWindow>
236 {
237 typedef ShellBrowserChildT<ChildWindow> super;
238
239 MDIShellBrowserChild(HWND hwnd, const ShellChildWndInfo& info);
240
241 static MDIShellBrowserChild* create(const ShellChildWndInfo& info);
242
243 LRESULT Init(LPCREATESTRUCT);
244
245 virtual String jump_to_int(LPCTSTR url);
246
247 protected:
248 ShellChildWndInfo _create_info;
249 ShellPathInfo _shellpath_info;
250
251 LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam);
252
253 void update_shell_browser();
254
255 // interface BrowserCallback
256 virtual void entry_selected(Entry* entry);
257 };
258
259 #endif