Leaked source code of windows server 2003
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.

389 lines
13 KiB

  1. #ifndef __COLUMNS_H_
  2. #define __COLUMNS_H_
  3. #include "ourguid.h"
  4. #include "resource.h"
  5. //
  6. // This defines all the available columns in Athena. It maps the column ID,
  7. // the name of the column, the default width, and the format (alignment).
  8. //
  9. #define IICON_TEXTHDR -1
  10. typedef struct tagCOLUMN_DATA {
  11. UINT idsColumnName; // Name of the column
  12. UINT cxWidth; // Default width for this column
  13. UINT format; // Format for the column (LVCFMT enum)
  14. int iIcon; // Icon for the column header
  15. } COLUMN_DATA, *PCOLUMN_DATA;
  16. //
  17. // This structure is used to define the column set for a particular
  18. // folder type.
  19. //
  20. #define COLFLAG_VISIBLE 0x00000001 // This column is on by default
  21. #define COLFLAG_SORT_ASCENDING 0x00000002 // This column is the sort column, and it's sorted ascending
  22. #define COLFLAG_SORT_DESCENDING 0x00000004 // This column is the sort column, and it's sorted descending
  23. #define COLFLAG_FIXED_WIDTH 0x00000008 // This column is a fixed width, it won't resize dynamically
  24. typedef struct tagCOLUMN_SET {
  25. COLUMN_ID id; // Id of the column
  26. DWORD flags; // Combination of the COLUMN_ flags above
  27. DWORD cxWidth; // Width of the column. If -1, then use the default.
  28. } COLUMN_SET, *PCOLUMN_SET;
  29. //
  30. // This enumeration lists all the different column sets we currently have
  31. // defined.
  32. //
  33. typedef enum tagCOLUMN_SET_TYPE
  34. {
  35. COLUMN_SET_MAIL = 0,
  36. COLUMN_SET_OUTBOX,
  37. COLUMN_SET_NEWS,
  38. COLUMN_SET_IMAP,
  39. COLUMN_SET_IMAP_OUTBOX,
  40. COLUMN_SET_FIND,
  41. COLUMN_SET_NEWS_ACCOUNT,
  42. COLUMN_SET_IMAP_ACCOUNT,
  43. COLUMN_SET_LOCAL_STORE,
  44. COLUMN_SET_NEWS_SUB,
  45. COLUMN_SET_IMAP_SUB,
  46. COLUMN_SET_OFFLINE,
  47. COLUMN_SET_PICKGRP,
  48. COLUMN_SET_HTTPMAIL,
  49. COLUMN_SET_HTTPMAIL_ACCOUNT,
  50. COLUMN_SET_HTTPMAIL_OUTBOX,
  51. COLUMN_SET_MAX
  52. } COLUMN_SET_TYPE;
  53. //
  54. // This struct maps the different column set types to the default column set
  55. // and the place where this information is persisted.
  56. //
  57. typedef struct tagCOLUMN_SET_INFO {
  58. COLUMN_SET_TYPE type;
  59. DWORD cColumns;
  60. const COLUMN_SET *rgColumns;
  61. LPCTSTR pszRegValue;
  62. BOOL fSort;
  63. } COLUMN_SET_INFO;
  64. //
  65. // This structure defines what is saved when we persist the columns
  66. //
  67. #define COLUMN_PERSIST_VERSION 0x00000010
  68. typedef struct tagCOLUMN_PERSIST_INFO {
  69. DWORD dwVersion; // Version stamp for this structure
  70. DWORD cColumns; // Number of entries in rgColumns
  71. COLUMN_SET rgColumns[1]; // Actual array of visible columns
  72. } COLUMN_PERSIST_INFO, *PCOLUMN_PERSIST_INFO;
  73. /////////////////////////////////////////////////////////////////////////////
  74. // Defines for the control ID's in the dialog
  75. //
  76. #define IDC_COLUMN_LIST 20000
  77. #define IDC_MOVEUP 20001
  78. #define IDC_MOVEDOWN 20002
  79. #define IDC_SHOW 20003
  80. #define IDC_HIDE 20004
  81. #define IDC_RESET_COLUMNS 20005
  82. #define IDC_WIDTH 20006
  83. /////////////////////////////////////////////////////////////////////////////
  84. // IColumnsInfo
  85. //
  86. typedef enum
  87. {
  88. COLUMN_LOAD_DEFAULT = 0,
  89. COLUMN_LOAD_BUFFER,
  90. COLUMN_LOAD_REGISTRY,
  91. COLUMN_LOAD_MAX
  92. } COLUMN_LOAD_TYPE;
  93. interface IColumnInfo : public IUnknown
  94. {
  95. // Initializes the object and tells it which ListView it will be using
  96. // and which column set should be applied.
  97. STDMETHOD(Initialize)(/*[in]*/ HWND hwndList,
  98. /*[in]*/ COLUMN_SET_TYPE type) PURE;
  99. // Tells the class to configure the columns in the ListView. The user
  100. // can either tell the class to use the default columns or use a set
  101. // that was persisted by the caller.
  102. STDMETHOD(ApplyColumns)(/*[in]*/ COLUMN_LOAD_TYPE type,
  103. /*[in, optional]*/ LPBYTE pBuffer,
  104. /*[in]*/ DWORD cb) PURE;
  105. // Saves the current column configuration into the buffer provided by the
  106. // caller. pcb should have the size of pBuffer when the function is called,
  107. // and will be updated to contain the number of bytes written into the
  108. // buffer if the function succeeds.
  109. // if both params are null, it saves to registry
  110. STDMETHOD(Save)(/*[in, out]*/ LPBYTE pBuffer,
  111. /*[in, out]*/ DWORD *pcb) PURE;
  112. // Returns the total number of columns in the ListView.
  113. STDMETHOD_(DWORD, GetCount)(void) PURE;
  114. // Returns the column ID for the specified column index.
  115. STDMETHOD_(COLUMN_ID, GetId)(/*[in]*/ DWORD iColumn) PURE;
  116. // Returns the index for the specified column ID.
  117. STDMETHOD_(DWORD, GetColumn)(/*[in]*/ COLUMN_ID id) PURE;
  118. // Set's the width of the specified column index.
  119. STDMETHOD(SetColumnWidth)(/*[in]*/ DWORD iColumn,
  120. /*[in]*/ DWORD cxWidth) PURE;
  121. // Allows the caller to ask for the column that we're sorted by and/or
  122. // the direction of the sort. If the caller doesn't care about one of
  123. // those pieces of information, they can pass in NULL for that
  124. // parameter.
  125. STDMETHOD(GetSortInfo)(/*[out, optional]*/ COLUMN_ID *pidColumn,
  126. /*[out, optional]*/ BOOL *pfAscending) PURE;
  127. // Allows the caller to update the column and direction of the current
  128. // sort.
  129. STDMETHOD(SetSortInfo)(/*[in]*/ COLUMN_ID idColumn,
  130. /*[in]*/ BOOL fAscending) PURE;
  131. STDMETHOD(GetColumnInfo)(COLUMN_SET_TYPE* pType, COLUMN_SET** prgColumns, DWORD *pcColumns) PURE;
  132. STDMETHOD(SetColumnInfo)(COLUMN_SET* rgColumns, DWORD cColumns) PURE;
  133. // Displays a dialog that allows users to configure the columns.
  134. STDMETHOD(ColumnsDialog)(/*[in]*/ HWND hwndParent) PURE;
  135. // Fills the provided menu with the columns visible and the sort info.
  136. STDMETHOD(FillSortMenu)(/*[in]*/ HMENU hMenu,
  137. /*[in]*/ DWORD idBase,
  138. /*[out]*/ DWORD *pcItems,
  139. /*[out]*/ DWORD *pidCurrent) PURE;
  140. // Inserts a column into the current column array
  141. STDMETHOD(InsertColumn)(/*[in]*/ COLUMN_ID id,
  142. /*[in]*/ DWORD iInsertBefore) PURE;
  143. // Checks to see if the specified column is visible
  144. STDMETHOD(IsColumnVisible)(/*[in]*/ COLUMN_ID id,
  145. /*[out]*/ BOOL *pfVisible) PURE;
  146. };
  147. /////////////////////////////////////////////////////////////////////////////
  148. // CColumns
  149. //
  150. class CColumns : public IColumnInfo
  151. {
  152. public:
  153. /////////////////////////////////////////////////////////////////////////
  154. // Construction, Initialization, and Destruction
  155. //
  156. CColumns();
  157. ~CColumns();
  158. /////////////////////////////////////////////////////////////////////////
  159. // IUnknown
  160. //
  161. STDMETHOD_(ULONG, AddRef)(void)
  162. {
  163. return InterlockedIncrement(&m_cRef);
  164. }
  165. STDMETHOD_(ULONG, Release)(void)
  166. {
  167. InterlockedDecrement(&m_cRef);
  168. if (0 == m_cRef)
  169. {
  170. delete this;
  171. return (0);
  172. }
  173. return (m_cRef);
  174. }
  175. STDMETHOD(QueryInterface)(REFIID riid, LPVOID *ppvObj)
  176. {
  177. *ppvObj = NULL;
  178. if (IsEqualIID(riid, IID_IUnknown))
  179. *ppvObj = (LPVOID) (IUnknown *) this;
  180. if (IsEqualIID(riid, IID_IColumnInfo))
  181. *ppvObj = (LPVOID) this;
  182. if (*ppvObj)
  183. {
  184. AddRef();
  185. return (S_OK);
  186. }
  187. return (E_NOINTERFACE);
  188. }
  189. /////////////////////////////////////////////////////////////////////////
  190. // IColumnInfo
  191. //
  192. STDMETHODIMP Initialize(HWND hwndList, COLUMN_SET_TYPE type);
  193. STDMETHODIMP ApplyColumns(COLUMN_LOAD_TYPE type, LPBYTE pBuffer, DWORD cb);
  194. STDMETHODIMP Save(LPBYTE pBuffer, DWORD *pcb);
  195. DWORD STDMETHODCALLTYPE GetCount(void);
  196. COLUMN_ID STDMETHODCALLTYPE GetId(DWORD iColumn);
  197. DWORD STDMETHODCALLTYPE GetColumn(COLUMN_ID id);
  198. STDMETHODIMP SetColumnWidth(DWORD iColumn, DWORD cxWidth);
  199. STDMETHODIMP GetSortInfo(COLUMN_ID *pidColumn, BOOL *pfAscending);
  200. STDMETHODIMP SetSortInfo(COLUMN_ID idColumn, BOOL fAscending);
  201. STDMETHODIMP GetColumnInfo(COLUMN_SET_TYPE* pType, COLUMN_SET** prgColumns, DWORD *pcColumns);
  202. STDMETHODIMP SetColumnInfo(COLUMN_SET* rgColumns, DWORD cColumns);
  203. STDMETHODIMP ColumnsDialog(HWND hwndParent);
  204. STDMETHODIMP FillSortMenu(HMENU hMenu, DWORD idBase, DWORD *pcItems, DWORD *pidCurrent);
  205. STDMETHODIMP InsertColumn(COLUMN_ID id, DWORD iInsertBefore);
  206. STDMETHODIMP IsColumnVisible(COLUMN_ID id, BOOL *pfVisible);
  207. /////////////////////////////////////////////////////////////////////////
  208. // Utility functions
  209. //
  210. protected:
  211. HRESULT _GetListViewColumns(COLUMN_SET* rgColumns, DWORD *pcColumns);
  212. HRESULT _SetListViewColumns(const COLUMN_SET *rgColumns, DWORD cColumns);
  213. private:
  214. /////////////////////////////////////////////////////////////////////////
  215. // Class data
  216. //
  217. LONG m_cRef;
  218. BOOL m_fInitialized;
  219. CWindow m_wndList;
  220. HWND m_hwndHdr;
  221. COLUMN_SET_TYPE m_type;
  222. COLUMN_SET *m_pColumnSet;
  223. DWORD m_cColumns;
  224. COLUMN_ID m_idColumnSort;
  225. BOOL m_fAscending;
  226. };
  227. /////////////////////////////////////////////////////////////////////////////
  228. // CColumnsDlg
  229. //
  230. class CColumnsDlg : public CDialogImpl<CColumnsDlg>
  231. {
  232. public:
  233. enum {IDD = iddColumns};
  234. BEGIN_MSG_MAP(CColumnsDlg)
  235. MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
  236. MESSAGE_HANDLER(WM_HELP, OnHelp)
  237. MESSAGE_HANDLER(WM_CONTEXTMENU, OnHelp)
  238. COMMAND_ID_HANDLER(IDC_SHOW, OnShowHide)
  239. COMMAND_ID_HANDLER(IDC_HIDE, OnShowHide)
  240. COMMAND_ID_HANDLER(IDC_RESET_COLUMNS, OnReset)
  241. COMMAND_ID_HANDLER(IDC_MOVEUP, OnMove)
  242. COMMAND_ID_HANDLER(IDC_MOVEDOWN, OnMove)
  243. COMMAND_ID_HANDLER(IDOK, OnOK)
  244. COMMAND_ID_HANDLER(IDCANCEL, OnCancel)
  245. NOTIFY_HANDLER(IDC_COLUMN_LIST, NM_CLICK, OnClick)
  246. NOTIFY_HANDLER(IDC_COLUMN_LIST, NM_DBLCLK, OnClick)
  247. NOTIFY_HANDLER(IDC_COLUMN_LIST, LVN_ITEMCHANGED, OnItemChanged)
  248. ALT_MSG_MAP(1)
  249. // Here's our edit control subclass
  250. MESSAGE_HANDLER(WM_CHAR, OnChar)
  251. END_MSG_MAP()
  252. /////////////////////////////////////////////////////////////////////////
  253. // Construction, Initialization, and Destruction
  254. //
  255. CColumnsDlg();
  256. ~CColumnsDlg();
  257. HRESULT Init(IColumnInfo *pColumnInfo)
  258. {
  259. m_pColumnInfo = pColumnInfo;
  260. m_pColumnInfo->AddRef();
  261. return (S_OK);
  262. }
  263. /////////////////////////////////////////////////////////////////////////
  264. // Overrides of the standard interface implementations
  265. //
  266. STDMETHOD(Apply)(void);
  267. /////////////////////////////////////////////////////////////////////////
  268. // Message Handlers
  269. //
  270. LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  271. LRESULT OnHelp(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  272. LRESULT OnChar(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  273. {
  274. SetDirty(TRUE);
  275. bHandled = FALSE;
  276. return (0);
  277. }
  278. LRESULT OnShowHide(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  279. LRESULT OnReset(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  280. LRESULT OnMove(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled);
  281. LRESULT OnOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  282. {
  283. if (SUCCEEDED(Apply()))
  284. EndDialog(0);
  285. return (0);
  286. }
  287. LRESULT OnCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
  288. {
  289. EndDialog(0);
  290. return (0);
  291. }
  292. LRESULT OnClick(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
  293. LRESULT OnItemChanged(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
  294. LRESULT OnApply(int idCtrl, LPNMHDR pnmh, BOOL& bHandled);
  295. private:
  296. /////////////////////////////////////////////////////////////////////////
  297. // Utility Functions
  298. //
  299. void _FillList(const COLUMN_SET *rgColumns, DWORD cColumns);
  300. BOOL _IsChecked(DWORD iItem);
  301. void _SetCheck(DWORD iItem, BOOL fChecked);
  302. void _UpdateButtonState(DWORD iItemSel);
  303. void SetDirty(BOOL fDirty)
  304. {
  305. ::SendMessage(GetParent(), fDirty ? PSM_CHANGED : PSM_UNCHANGED,
  306. (WPARAM) m_hWnd, 0);
  307. }
  308. private:
  309. CContainedWindow m_ctlEdit;
  310. COLUMN_SET_TYPE m_type;
  311. COLUMN_SET *m_rgColumns;
  312. DWORD m_cColumns;
  313. HWND m_hwndList;
  314. UINT m_iItemWidth;
  315. IColumnInfo *m_pColumnInfo;
  316. };
  317. #endif //__COLUMNS_H_