Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

305 lines
7.4 KiB

  1. //*******************************************************************************************
  2. //
  3. // Filename : SFVWnd.h
  4. //
  5. // Definitions of CListView, CSFViewDlg, CAccelerator, CSFView
  6. //
  7. // Copyright (c) 1994 - 1996 Microsoft Corporation. All rights reserved
  8. //
  9. //*******************************************************************************************
  10. #ifndef _SFVWnd_H_
  11. #define _SFVWnd_H_
  12. #include "ThisDll.H"
  13. #include "SFView.H"
  14. #include "XIcon.H"
  15. #include "Dlg.H"
  16. #include "Unknown.H"
  17. #define IDC_ARRANGE_BY (FCIDM_SHVIEWFIRST + 0x100)
  18. #define MAX_COL 0x20
  19. #define SFV_CONTEXT_FIRST (FCIDM_SHVIEWFIRST + 0x1000)
  20. #define SFV_CONTEXT_LAST (FCIDM_SHVIEWFIRST + 0x2000)
  21. BOOL StrRetToStr(LPSTR szOut, UINT uszOut, LPSTRRET pStrRet, LPCITEMIDLIST pidl);
  22. class CListView
  23. {
  24. public:
  25. CListView() {}
  26. ~CListView() {}
  27. operator HWND() const {return(m_hwndList);}
  28. void Init(HWND hwndList, HWND hwndLB, UINT idiDef)
  29. {
  30. m_hwndList = hwndList;
  31. m_cxi.Init(hwndLB, idiDef);
  32. ListView_SetImageList(hwndList, m_cxi.GetIML(TRUE), LVSIL_NORMAL);
  33. ListView_SetImageList(hwndList, m_cxi.GetIML(FALSE), LVSIL_SMALL);
  34. }
  35. int InsertItem(LV_ITEM *pItem)
  36. {
  37. return(ListView_InsertItem(m_hwndList, pItem));
  38. }
  39. void DeleteAllItems() {ListView_DeleteAllItems(m_hwndList);}
  40. enum
  41. {
  42. AI_LARGE = CXIcon::AI_LARGE,
  43. AI_SMALL = CXIcon::AI_SMALL,
  44. } ;
  45. int GetIcon(IShellFolder *psf, LPCITEMIDLIST pidl)
  46. {
  47. return(m_cxi.GetIcon(psf, pidl));
  48. }
  49. private:
  50. HWND m_hwndList;
  51. CXIcon m_cxi;
  52. } ;
  53. class CSFViewDlg : public CDlg
  54. {
  55. public:
  56. CSFViewDlg(class CSFView *psfv) : m_psfv(psfv), m_hrOLE(E_UNEXPECTED)
  57. {
  58. m_hDlg = NULL;
  59. }
  60. ~CSFViewDlg() {}
  61. operator HWND() const {return(m_hDlg);}
  62. int AddObject(LPCITEMIDLIST pidl);
  63. void DeleteAllItems() {m_cList.DeleteAllItems();}
  64. BOOL DestroyWindow() {BOOL bRet=::DestroyWindow(m_hDlg); m_hDlg = NULL; return(bRet);}
  65. void SetStyle(DWORD dwAdd, DWORD dwRemove)
  66. {
  67. SetWindowLong(m_cList, GWL_STYLE, dwAdd |
  68. (GetWindowStyle(m_cList) & ~dwRemove));
  69. }
  70. void SelAll()
  71. {
  72. ListView_SetItemState(m_cList, -1, LVIS_SELECTED, LVIS_SELECTED);
  73. }
  74. void InvSel()
  75. {
  76. int iItem = -1;
  77. while ((iItem=ListView_GetNextItem(m_cList, iItem, 0)) != -1)
  78. {
  79. UINT flag;
  80. // flip the selection bit on each item
  81. flag = ListView_GetItemState(m_cList, iItem, LVIS_SELECTED);
  82. flag ^= LVNI_SELECTED;
  83. ListView_SetItemState(m_cList, iItem, flag, LVIS_SELECTED);
  84. }
  85. }
  86. UINT CharWidth();
  87. BOOL GetColumn(int i, LV_COLUMN *pcol) {return(ListView_GetColumn(m_cList, i, pcol));}
  88. BOOL SetColumn(int i, LV_COLUMN *pcol) {return(ListView_SetColumn(m_cList, i, pcol));}
  89. UINT InsertColumn(int i, LV_COLUMN *pcol) {return(ListView_InsertColumn(m_cList, i, pcol));}
  90. void SortItems(PFNDPACOMPARE pfnCmp) {ListView_SortItems(m_cList, pfnCmp, m_psfv);}
  91. static BOOL IsMenuSeparator(HMENU hm, int i);
  92. HRESULT GetUIObjectFromItem(REFIID riid, LPVOID * ppv, UINT uItem);
  93. HRESULT GetAttributesFromItem(ULONG *pdwAttr, UINT uItem);
  94. BOOL OleInited() {return(SUCCEEDED(m_hrOLE));}
  95. private:
  96. virtual BOOL RealDlgProc(UINT uMsg, WPARAM wParam, LPARAM lParam);
  97. UINT GetItemPIDLS(LPCITEMIDLIST apidl[], UINT cItemMax, UINT uItem);
  98. HRESULT GetItemObjects(LPCITEMIDLIST **ppidl, UINT uItem);
  99. LPCITEMIDLIST GetPIDL(int iItem);
  100. void InitDialog();
  101. LRESULT BeginDrag();
  102. BOOL Notify(LPNMHDR pNotify);
  103. void ContextMenu(DWORD dwPos, BOOL bDoDefault=FALSE);
  104. CListView m_cList;
  105. HRESULT m_hrOLE;
  106. class CSFView *m_psfv;
  107. } ;
  108. struct SFSTATE
  109. {
  110. LPARAM lParamSort;
  111. } ;
  112. class CAccelerator
  113. {
  114. public:
  115. CAccelerator(UINT uID)
  116. {
  117. m_hAccel = LoadAccelerators(g_ThisDll.GetInstance(), MAKEINTRESOURCE(uID));
  118. }
  119. int TranslateAccelerator(HWND hwnd, LPMSG pmsg)
  120. {
  121. if (!m_hAccel)
  122. {
  123. return(FALSE);
  124. }
  125. return(::TranslateAccelerator(hwnd, m_hAccel, pmsg));
  126. }
  127. private:
  128. HACCEL m_hAccel;
  129. } ;
  130. //
  131. // CSFView - IShellView implementation
  132. //
  133. class CSFView : public CUnknown, public IShellView
  134. {
  135. public:
  136. CSFView(LPSHELLFOLDER psf, IShellFolderViewCallback *psfvcb);
  137. virtual ~CSFView();
  138. STDMETHODIMP QueryInterface(REFIID riid, LPVOID * ppvObj);
  139. STDMETHODIMP_(ULONG) AddRef();
  140. STDMETHODIMP_(ULONG) Release();
  141. // *** IOleWindow methods ***
  142. STDMETHODIMP GetWindow(HWND * lphwnd);
  143. STDMETHODIMP ContextSensitiveHelp(BOOL fEnterMode);
  144. // *** IShellView methods ***
  145. STDMETHODIMP TranslateAccelerator(LPMSG lpmsg);
  146. STDMETHODIMP EnableModeless(BOOL fEnable);
  147. STDMETHODIMP UIActivate(UINT uState);
  148. STDMETHODIMP Refresh();
  149. STDMETHODIMP CreateViewWindow(IShellView *lpPrevView,
  150. LPCFOLDERSETTINGS lpfs, IShellBrowser * psb,
  151. RECT * prcView, HWND *phWnd);
  152. STDMETHODIMP DestroyViewWindow();
  153. STDMETHODIMP GetCurrentInfo(LPFOLDERSETTINGS lpfs);
  154. STDMETHODIMP AddPropertySheetPages(DWORD dwReserved,
  155. LPFNADDPROPSHEETPAGE lpfn, LPARAM lparam);
  156. STDMETHODIMP SaveViewState();
  157. STDMETHODIMP SelectItem(LPCITEMIDLIST pidlItem, UINT uFlags);
  158. STDMETHODIMP GetItemObject(UINT uItem, REFIID riid,
  159. LPVOID *ppv);
  160. private:
  161. static int CALLBACK CSFView::CompareIDs(LPVOID p1, LPVOID p2, LPARAM lParam);
  162. void AddColumns();
  163. BOOL SaveColumns(LPSTREAM pstm);
  164. void RestoreColumns(LPSTREAM pstm, int nCols);
  165. void RestoreViewState();
  166. void ColumnClick(int iCol)
  167. {
  168. m_sfState.lParamSort = (LPARAM)DPA_GetPtr(m_aParamSort, iCol);
  169. m_cView.SortItems(CompareIDs);
  170. }
  171. HRESULT CallCB(UINT uMsg, WPARAM wParam, LPARAM lParam)
  172. {
  173. return(m_psfvcb ? m_psfvcb->Message(uMsg, wParam, lParam) : E_NOTIMPL);
  174. }
  175. int GetMenuIDFromViewMode();
  176. BOOL IsInCommDlg() {return(m_pCDB != NULL);}
  177. HRESULT IncludeObject(LPCITEMIDLIST pidl)
  178. {
  179. return(IsInCommDlg() ? m_pCDB->IncludeObject(this, pidl) : S_OK);
  180. }
  181. HRESULT OnDefaultCommand()
  182. {
  183. return(IsInCommDlg() ? m_pCDB->OnDefaultCommand(this) : S_FALSE);
  184. }
  185. HRESULT OnStateChange(UINT uFlags)
  186. {
  187. return(IsInCommDlg() ? m_pCDB->OnStateChange(this, uFlags) : S_FALSE);
  188. }
  189. void InitFileMenu(HMENU hmInit);
  190. void InitEditMenu(HMENU hmInit);
  191. void InitViewMenu(HMENU hmInit);
  192. int AddObject(LPCITEMIDLIST pidl);
  193. HRESULT FillList(BOOL bInteractive);
  194. BOOL ShowAllObjects() {return(TRUE);}
  195. void MergeArrangeMenu(HMENU hmView);
  196. void MergeViewMenu(HMENU hmenu, HMENU hmMerge);
  197. BOOL OnActivate(UINT uState);
  198. BOOL OnDeactivate();
  199. IContextMenu * GetSelContextMenu();
  200. void ReleaseSelContextMenu();
  201. BOOL OnInitMenuPopup(HMENU hmInit, int nIndex, BOOL fSystemMenu);
  202. void OnCommand(IContextMenu *pcm, WPARAM wParam, LPARAM lParam);
  203. void CheckToolbar();
  204. void MergeToolBar();
  205. BOOL GetArrangeText(int iCol, UINT idFmt, LPSTR pszText, UINT cText);
  206. void GetCommandHelpText(UINT id, LPSTR pszText, UINT cchText, BOOL bToolTip);
  207. LRESULT OnMenuSelect(UINT idCmd, UINT uFlags, HMENU hmenu);
  208. LPSHELLFOLDER m_psf; // ShellFolder pointer
  209. ICommDlgBrowser *m_pCDB; // ICommdlgBrowser
  210. IShellFolderViewCallback *m_psfvcb; // pointer to ShellFolderView
  211. // callback
  212. CEnsureRelease m_erFolder;
  213. CEnsureRelease m_erCB;
  214. CSFViewDlg m_cView; // ViewDlg which contains the
  215. // listview in the right pane
  216. HWND m_hwndMain;
  217. FOLDERSETTINGS m_fs;
  218. IShellBrowser *m_psb;
  219. SFSTATE m_sfState;
  220. CMenuTemp m_cmCur;
  221. UINT m_uState;
  222. IContextMenu *m_pcmSel;
  223. HDPA m_aParamSort; // maintains a sorted list of
  224. // items in a DPA
  225. CAccelerator m_cAccel;
  226. CSafeMalloc m_cMalloc;
  227. friend class CSFViewDlg;
  228. } ;
  229. #endif // _SFVWnd_H_