1 /* 2 * PROJECT: ReactOS shdocvw 3 * LICENSE: LGPL-2.1-or-later (https://spdx.org/licenses/LGPL-2.1-or-later) 4 * PURPOSE: NameSpace Control Band 5 * COPYRIGHT: Copyright 2024 Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com> 6 */ 7 8 #pragma once 9 10 #define NSCBANDCLASSNAME L"ReactOS NameSpace Control Band" 11 12 #define WM_USER_SHELLEVENT (WM_USER + 88) 13 14 #ifdef __cplusplus 15 class CNSCBand 16 : public CWindowImpl<CNSCBand> 17 , public IDeskBand 18 , public IObjectWithSite 19 , public IInputObject 20 , public IPersistStream 21 , public IOleCommandTarget 22 , public IServiceProvider 23 , public IContextMenu 24 , public IBandNavigate 25 , public IWinEventHandler 26 , public INamespaceProxy 27 , public IDropTarget 28 , public IDropSource 29 { 30 public: 31 DECLARE_WND_CLASS_EX(NSCBANDCLASSNAME, 0, COLOR_3DFACE) 32 static LPCWSTR GetWndClassName() { return NSCBANDCLASSNAME; } 33 34 CNSCBand(); 35 virtual ~CNSCBand(); 36 37 // The node of TreeView 38 struct CItemData 39 { 40 CComHeapPtr<ITEMIDLIST> absolutePidl; 41 CComHeapPtr<ITEMIDLIST> relativePidl; 42 BOOL expanded = FALSE; 43 }; 44 CItemData* GetItemData(_In_ HTREEITEM hItem); 45 46 // *** IOleWindow methods *** 47 STDMETHODIMP GetWindow(HWND *lphwnd) override; 48 STDMETHODIMP ContextSensitiveHelp(BOOL fEnterMode) override; 49 50 // *** IDockingWindow methods *** 51 STDMETHODIMP CloseDW(DWORD dwReserved) override; 52 STDMETHODIMP ResizeBorderDW(const RECT *prcBorder, IUnknown *punkToolbarSite, BOOL fReserved) override; 53 STDMETHODIMP ShowDW(BOOL fShow) override; 54 55 // *** IDeskBand methods *** 56 STDMETHODIMP GetBandInfo(DWORD dwBandID, DWORD dwViewMode, DESKBANDINFO *pdbi) override; 57 58 // *** IObjectWithSite methods *** 59 STDMETHODIMP SetSite(IUnknown *pUnkSite) override; 60 STDMETHODIMP GetSite(REFIID riid, void **ppvSite) override; 61 62 // *** IOleCommandTarget methods *** 63 STDMETHODIMP QueryStatus(const GUID *pguidCmdGroup, ULONG cCmds, OLECMD prgCmds [], OLECMDTEXT *pCmdText) override; 64 STDMETHODIMP Exec(const GUID *pguidCmdGroup, DWORD nCmdID, DWORD nCmdexecopt, VARIANT *pvaIn, VARIANT *pvaOut) override; 65 66 // *** IServiceProvider methods *** 67 STDMETHODIMP QueryService(REFGUID guidService, REFIID riid, void **ppvObject) override; 68 69 // *** IContextMenu methods *** 70 STDMETHODIMP QueryContextMenu( 71 HMENU hmenu, 72 UINT indexMenu, 73 UINT idCmdFirst, 74 UINT idCmdLast, 75 UINT uFlags) override; 76 STDMETHODIMP InvokeCommand(LPCMINVOKECOMMANDINFO lpici) override; 77 STDMETHODIMP GetCommandString( 78 UINT_PTR idCmd, 79 UINT uType, 80 UINT *pwReserved, 81 LPSTR pszName, 82 UINT cchMax) override; 83 84 // *** IInputObject methods *** 85 STDMETHODIMP UIActivateIO(BOOL fActivate, LPMSG lpMsg) override; 86 STDMETHODIMP HasFocusIO() override; 87 STDMETHODIMP TranslateAcceleratorIO(LPMSG lpMsg) override; 88 89 // *** IPersist methods *** 90 STDMETHODIMP GetClassID(CLSID *pClassID) override; 91 92 // *** IPersistStream methods *** 93 STDMETHODIMP IsDirty() override; 94 STDMETHODIMP Load(IStream *pStm) override; 95 STDMETHODIMP Save(IStream *pStm, BOOL fClearDirty) override; 96 STDMETHODIMP GetSizeMax(ULARGE_INTEGER *pcbSize) override; 97 98 // *** IWinEventHandler methods *** 99 STDMETHODIMP OnWinEvent(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *theResult) override; 100 STDMETHODIMP IsWindowOwner(HWND hWnd) override; 101 102 // *** IBandNavigate methods *** 103 STDMETHODIMP Select(LPCITEMIDLIST pidl) override; 104 105 // *** INamespaceProxy methods *** 106 STDMETHODIMP GetNavigateTarget( 107 _In_ PCIDLIST_ABSOLUTE pidl, 108 _Out_ PIDLIST_ABSOLUTE *ppidlTarget, 109 _Out_ ULONG *pulAttrib) override; 110 STDMETHODIMP Invoke(_In_ PCIDLIST_ABSOLUTE pidl) override; 111 STDMETHODIMP OnSelectionChanged(_In_ PCIDLIST_ABSOLUTE pidl) override; 112 STDMETHODIMP RefreshFlags( 113 _Out_ DWORD *pdwStyle, 114 _Out_ DWORD *pdwExStyle, 115 _Out_ DWORD *dwEnum) override; 116 STDMETHODIMP CacheItem(_In_ PCIDLIST_ABSOLUTE pidl) override; 117 118 // *** IDropTarget methods *** 119 STDMETHODIMP DragEnter(IDataObject *pObj, DWORD glfKeyState, POINTL pt, DWORD *pdwEffect) override; 120 STDMETHODIMP DragOver(DWORD glfKeyState, POINTL pt, DWORD *pdwEffect) override; 121 STDMETHODIMP DragLeave() override; 122 STDMETHODIMP Drop(IDataObject *pObj, DWORD glfKeyState, POINTL pt, DWORD *pdwEffect) override; 123 124 // *** IDropSource methods *** 125 STDMETHODIMP QueryContinueDrag(BOOL fEscapePressed, DWORD grfKeyState) override; 126 STDMETHODIMP GiveFeedback(DWORD dwEffect) override; 127 128 protected: 129 DWORD m_dwTVStyle = 0; 130 DWORD m_dwTVExStyle = 0; 131 DWORD m_dwEnumFlags = 0; 132 BOOL m_fVisible = FALSE; 133 BOOL m_bFocused = FALSE; 134 DWORD m_dwBandID = 0; 135 CComPtr<IUnknown> m_pSite; 136 CComPtr<IShellFolder> m_pDesktop; 137 CComHeapPtr<ITEMIDLIST> m_pidlRoot; 138 HIMAGELIST m_hToolbarImageList = NULL; 139 CToolbar<> m_hwndToolbar; 140 CTreeView m_hwndTreeView; 141 LONG m_mtxBlockNavigate = 0; // A "lock" that prevents internal selection changes to initiate a navigation to the newly selected item. 142 BOOL m_isEditing = FALSE; 143 HTREEITEM m_hRoot = NULL; 144 HTREEITEM m_oldSelected = NULL; 145 DWORD m_adviseCookie = 0; 146 ULONG m_shellRegID = 0; 147 148 // *** Drop target information *** 149 CComPtr<IDropTarget> m_pDropTarget; 150 HTREEITEM m_childTargetNode = NULL; 151 CComPtr<IDataObject> m_pCurObject; 152 153 VOID OnFinalMessage(HWND) override; 154 155 // *** helper methods *** 156 virtual INT _GetRootCsidl() = 0; 157 virtual HRESULT _CreateTreeView(HWND hwndParent); 158 virtual HRESULT _CreateToolbar(HWND hwndParent) { return S_OK; } 159 virtual void _DestroyTreeView(); 160 virtual void _DestroyToolbar(); 161 virtual DWORD _GetTVStyle() = 0; 162 virtual DWORD _GetTVExStyle() = 0; 163 virtual DWORD _GetEnumFlags() = 0; 164 virtual BOOL _GetTitle(LPWSTR pszTitle, INT cchTitle) = 0; 165 virtual BOOL _WantsRootItem() = 0; 166 virtual void _SortItems(HTREEITEM hParent) = 0; 167 void _RegisterChangeNotify(); 168 void _UnregisterChangeNotify(); 169 BOOL OnTreeItemExpanding(_In_ LPNMTREEVIEW pnmtv); 170 BOOL OnTreeItemDeleted(_In_ LPNMTREEVIEW pnmtv); 171 void _OnSelectionChanged(_In_ LPNMTREEVIEW pnmtv); 172 void OnTreeItemDragging(_In_ LPNMTREEVIEW pnmtv, _In_ BOOL isRightClick); 173 LRESULT OnBeginLabelEdit(_In_ LPNMTVDISPINFO dispInfo); 174 LRESULT OnEndLabelEdit(_In_ LPNMTVDISPINFO dispInfo); 175 void OnChangeNotify( 176 _In_opt_ LPCITEMIDLIST pidl0, 177 _In_opt_ LPCITEMIDLIST pidl1, 178 _In_ LONG lEvent); 179 HRESULT _ExecuteCommand(_In_ CComPtr<IContextMenu>& menu, _In_ UINT nCmd); 180 HTREEITEM _InsertItem( 181 _In_opt_ HTREEITEM hParent, 182 _Inout_ IShellFolder *psfParent, 183 _In_ LPCITEMIDLIST pElt, 184 _In_ LPCITEMIDLIST pEltRelative, 185 _In_ BOOL bSort); 186 HTREEITEM _InsertItem( 187 _In_opt_ HTREEITEM hParent, 188 _In_ LPCITEMIDLIST pElt, 189 _In_ LPCITEMIDLIST pEltRelative, 190 _In_ BOOL bSort); 191 BOOL _InsertSubitems(HTREEITEM hItem, LPCITEMIDLIST entry); 192 HRESULT _UpdateBrowser(LPCITEMIDLIST pidlGoto); 193 HRESULT _GetCurrentLocation(_Out_ PIDLIST_ABSOLUTE *ppidl); 194 HRESULT _IsCurrentLocation(_In_ PCIDLIST_ABSOLUTE pidl); 195 void _Refresh(); 196 void _RefreshRecurse(_In_ HTREEITEM hItem); 197 BOOL _IsTreeItemInEnum(_In_ HTREEITEM hItem, _In_ IEnumIDList *pEnum); 198 BOOL _TreeItemHasThisChild(_In_ HTREEITEM hItem, _In_ PCITEMID_CHILD pidlChild); 199 HRESULT _GetItemEnum( 200 _Out_ CComPtr<IEnumIDList>& pEnum, 201 _In_ HTREEITEM hItem, 202 _Out_opt_ IShellFolder **ppFolder = NULL); 203 BOOL _ItemHasAnyChild(_In_ HTREEITEM hItem); 204 HRESULT _AddFavorite(); 205 206 // *** ATL message handlers *** 207 LRESULT OnContextMenu(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 208 LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 209 LRESULT OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 210 LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); 211 LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 212 LRESULT OnKillFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 213 LRESULT OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 214 LRESULT OnNotify(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 215 LRESULT OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 216 LRESULT OnShellEvent(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled); 217 218 BEGIN_MSG_MAP(CNSCBand) 219 MESSAGE_HANDLER(WM_CREATE, OnCreate) 220 MESSAGE_HANDLER(WM_DESTROY, OnDestroy) 221 MESSAGE_HANDLER(WM_SIZE, OnSize) 222 MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus) 223 MESSAGE_HANDLER(WM_KILLFOCUS, OnKillFocus) 224 MESSAGE_HANDLER(WM_COMMAND, OnCommand) 225 MESSAGE_HANDLER(WM_NOTIFY, OnNotify) 226 MESSAGE_HANDLER(WM_TIMER, OnTimer) 227 MESSAGE_HANDLER(WM_CONTEXTMENU, OnContextMenu) 228 MESSAGE_HANDLER(WM_USER_SHELLEVENT, OnShellEvent) 229 END_MSG_MAP() 230 }; 231 #endif // def __cplusplus 232