00001 /* 00002 * Copyright 2003, 2004, 2005 Martin Fuchs 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 */ 00018 00019 00020 // 00021 // Explorer clone 00022 // 00023 // shellbrowser.h 00024 // 00025 // Martin Fuchs, 23.07.2003 00026 // 00027 00028 #include "../utility/treedroptarget.h" 00029 #include "../utility/shellbrowserimpl.h" 00030 00031 #include <memory> 00032 00033 /// information structure to hold current shell folder information 00034 struct ShellPathInfo 00035 { 00036 ShellPathInfo(int mode=0) : _open_mode(mode) {} 00037 00038 ShellPathInfo(const ShellChildWndInfo& info) 00039 : _shell_path(info._shell_path), 00040 _root_shell_path(info._root_shell_path), 00041 _open_mode(info._open_mode) 00042 { 00043 } 00044 00045 ShellPath _shell_path; 00046 ShellPath _root_shell_path; 00047 00048 int _open_mode; //OPEN_WINDOW_MODE 00049 }; 00050 00051 00052 struct BrowserCallback 00053 { 00054 virtual ~BrowserCallback() {} 00055 virtual void entry_selected(Entry* entry) = 0; 00056 }; 00057 00058 00059 /// Implementation of IShellBrowserImpl interface in explorer child windows 00060 struct ShellBrowser : public IShellBrowserImpl 00061 #ifndef __MINGW32__ // IShellFolderViewCB missing in MinGW (as of 25.09.2005) 00062 , public IComSrvBase<IShellFolderViewCB, ShellBrowser>, public SimpleComObject 00063 #endif 00064 { 00065 ShellBrowser(HWND hwnd, HWND hwndFrame, HWND left_hwnd, WindowHandle& right_hwnd, ShellPathInfo& create_info, 00066 BrowserCallback* cb, CtxMenuInterfaces& cm_ifs); 00067 virtual ~ShellBrowser(); 00068 00069 //IOleWindow 00070 virtual HRESULT STDMETHODCALLTYPE GetWindow(HWND* lphwnd) 00071 { 00072 *lphwnd = _hwnd; 00073 return S_OK; 00074 } 00075 00076 //IShellBrowser 00077 virtual HRESULT STDMETHODCALLTYPE QueryActiveShellView(IShellView** ppshv) 00078 { 00079 _pShellView->AddRef(); 00080 *ppshv = _pShellView; 00081 return S_OK; 00082 } 00083 00084 virtual HRESULT STDMETHODCALLTYPE GetControlWindow(UINT id, HWND* lphwnd) 00085 { 00086 if (!lphwnd) 00087 return E_POINTER; 00088 00089 if (id == FCW_TREE) { 00090 *lphwnd = _left_hwnd; 00091 return S_OK; 00092 } 00093 00094 HWND hwnd = (HWND)SendMessage(_hwndFrame, PM_GET_CONTROLWINDOW, id, 0); 00095 00096 if (hwnd) { 00097 *lphwnd = hwnd; 00098 return S_OK; 00099 } 00100 00101 return E_NOTIMPL; 00102 } 00103 00104 virtual HRESULT STDMETHODCALLTYPE SendControlMsg(UINT id, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT* pret) 00105 { 00106 if (!pret) 00107 return E_POINTER; 00108 00109 HWND hstatusbar = (HWND)SendMessage(_hwndFrame, PM_GET_CONTROLWINDOW, id, 0); 00110 00111 if (hstatusbar) { 00112 *pret = ::SendMessage(hstatusbar, uMsg, wParam, lParam); 00113 return S_OK; 00114 } 00115 00116 return E_NOTIMPL; 00117 } 00118 00119 const Root& get_root() const {return _root;} 00120 00121 void OnTreeGetDispInfo(int idCtrl, LPNMHDR pnmh); 00122 void OnTreeItemExpanding(int idCtrl, LPNMTREEVIEW pnmtv); 00123 void OnTreeItemRClick(int idCtrl, LPNMHDR pnmh); 00124 void OnTreeItemSelected(int idCtrl, LPNMTREEVIEW pnmtv); 00125 00126 void Init(); 00127 00128 int InsertSubitems(HTREEITEM hParentItem, Entry* entry, IShellFolder* pParentFolder); 00129 00130 bool jump_to_pidl(LPCITEMIDLIST pidl); 00131 00132 HRESULT OnDefaultCommand(LPIDA pida); 00133 00134 void UpdateFolderView(IShellFolder* folder); 00135 HTREEITEM select_entry(HTREEITEM hitem, Entry* entry, bool expand=true); 00136 00137 bool select_folder(Entry* entry, bool expand); 00138 00139 // for SDIMainFrame 00140 void jump_to(LPCITEMIDLIST pidl); 00141 00142 void invalidate_cache(); 00143 00144 protected: 00145 HWND _hwnd; 00146 HWND _hwndFrame; 00147 HWND _left_hwnd; 00148 WindowHandle& _right_hwnd; 00149 ShellPathInfo& _create_info; 00150 HIMAGELIST _himl; 00151 HIMAGELIST _himl_old; 00152 BrowserCallback* _callback; 00153 00154 ShellFolder _folder; 00155 00156 IShellView* _pShellView; // current hosted shellview 00157 TreeDropTarget* _pDropTarget; 00158 00159 HTREEITEM _last_sel; 00160 00161 Root _root; 00162 ShellDirectory* _cur_dir; 00163 00164 CtxMenuInterfaces& _cm_ifs; 00165 00166 void InitializeTree(); 00167 bool InitDragDrop(); 00168 00169 #ifndef __MINGW32__ // IShellFolderViewCB missing in MinGW (as of 25.09.2005) 00170 typedef IComSrvBase<IShellFolderViewCB, ShellBrowser> super; 00171 00172 // IShellFolderViewCB 00173 virtual HRESULT STDMETHODCALLTYPE MessageSFVCB(UINT uMsg, WPARAM wParam, LPARAM lParam); 00174 #endif 00175 00176 map<int, int> _image_map; 00177 00178 int get_image_idx(int icon_id); 00179 00180 void refresh(); 00181 }; 00182 00183 00184 #define C_DRIVE_STR TEXT("C:\\") 00185 00186 // work around GCC's wide string constant bug 00187 #ifdef __GNUC__ 00188 extern const LPCTSTR C_DRIVE; 00189 #else 00190 #define C_DRIVE C_DRIVE_STR 00191 #endif 00192 00193 template<typename BASE> struct ShellBrowserChildT 00194 : public BASE, public BrowserCallback 00195 { 00196 typedef BASE super; 00197 00198 // constructor for SDIMainFrame 00199 ShellBrowserChildT(HWND hwnd) 00200 : super(hwnd) 00201 { 00202 } 00203 00204 // constructor for MDIShellBrowserChild 00205 ShellBrowserChildT(HWND hwnd, const ShellChildWndInfo& info) 00206 : super(hwnd, info) 00207 { 00208 } 00209 00210 protected: 00211 auto_ptr<ShellBrowser> _shellBrowser; 00212 00213 LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam) 00214 { 00215 switch(nmsg) { 00216 case PM_GET_SHELLBROWSER_PTR: 00217 return (LRESULT)&*_shellBrowser; 00218 00219 case WM_GETISHELLBROWSER: // for Registry Explorer Plugin 00220 return (LRESULT)static_cast<IShellBrowser*>(&*_shellBrowser); 00221 00222 default: 00223 return super::WndProc(nmsg, wparam, lparam); 00224 } 00225 00226 return 0; 00227 } 00228 00229 int Notify(int id, NMHDR* pnmh) 00230 { 00231 if (_shellBrowser.get()) 00232 switch(pnmh->code) { 00233 case TVN_GETDISPINFO: _shellBrowser->OnTreeGetDispInfo(id, pnmh); break; 00234 case TVN_SELCHANGED: _shellBrowser->OnTreeItemSelected(id, (LPNMTREEVIEW)pnmh); break; 00235 case TVN_ITEMEXPANDING: _shellBrowser->OnTreeItemExpanding(id, (LPNMTREEVIEW)pnmh); break; 00236 case NM_RCLICK: _shellBrowser->OnTreeItemRClick(id, pnmh); break; 00237 default: return super::Notify(id, pnmh); 00238 } 00239 else 00240 return super::Notify(id, pnmh); 00241 00242 return 0; 00243 } 00244 }; 00245 00246 00247 #ifndef _NO_MDI 00248 00249 struct MDIShellBrowserChild : public ExtContextMenuHandlerT< 00250 ShellBrowserChildT<ChildWindow> 00251 > 00252 { 00253 typedef ExtContextMenuHandlerT< 00254 ShellBrowserChildT<ChildWindow> 00255 > super; 00256 00257 MDIShellBrowserChild(HWND hwnd, const ShellChildWndInfo& info); 00258 00259 static MDIShellBrowserChild* create(const ShellChildWndInfo& info); 00260 00261 LRESULT Init(LPCREATESTRUCT); 00262 00263 virtual String jump_to_int(LPCTSTR url); 00264 00265 protected: 00266 ShellChildWndInfo _create_info; 00267 ShellPathInfo _shellpath_info; 00268 00269 LRESULT WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam); 00270 00271 void update_shell_browser(); 00272 00273 // interface BrowserCallback 00274 virtual void entry_selected(Entry* entry); 00275 }; 00276 00277 #endif
ROS Explorer Source Code Documentation
generated on 02.01.2013 by ![]() |