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.

386 lines
8.9 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. column.cpp
  7. FILE HISTORY:
  8. */
  9. #include "stdafx.h"
  10. #include "tfschar.h"
  11. #include "column.h"
  12. #include "coldlg.h"
  13. //----------------------------------------------------------------------------
  14. // Class: ColumnDlg
  15. //
  16. //----------------------------------------------------------------------------
  17. //----------------------------------------------------------------------------
  18. // Function: ColumnDlg::ColumnDlg
  19. //----------------------------------------------------------------------------
  20. ColumnDlg::ColumnDlg(
  21. CWnd* pParent
  22. ) : CBaseDialog(IDD_COMMON_SELECT_COLUMNS, pParent)
  23. {
  24. }
  25. //----------------------------------------------------------------------------
  26. // Function: ColumnDlg::~ColumnDlg
  27. //----------------------------------------------------------------------------
  28. ColumnDlg::~ColumnDlg() { }
  29. void ColumnDlg::Init(const ContainerColumnInfo *prgColInfo,
  30. UINT cColumns,
  31. ColumnData *prgColumnData)
  32. {
  33. Assert(prgColInfo);
  34. Assert(prgColumnData);
  35. m_pColumnInfo = prgColInfo;
  36. m_cColumnInfo = cColumns;
  37. m_pColumnData = prgColumnData;
  38. }
  39. //----------------------------------------------------------------------------
  40. // Function: ColumnDlg::DoDataExchange
  41. //----------------------------------------------------------------------------
  42. void ColumnDlg::DoDataExchange(CDataExchange* pDX) {
  43. CBaseDialog::DoDataExchange(pDX);
  44. //{{AFX_DATA_MAP(ColumnDlg)
  45. DDX_Control(pDX, IDC_DISPLAYED_COLUMNS, m_lboxDisplayed);
  46. DDX_Control(pDX, IDC_HIDDEN_COLUMNS, m_lboxHidden);
  47. //}}AFX_DATA_MAP
  48. }
  49. BEGIN_MESSAGE_MAP(ColumnDlg, CBaseDialog)
  50. //{{AFX_MSG_MAP(ColumnDlg)
  51. ON_WM_HSCROLL()
  52. ON_BN_CLICKED(IDC_RESET_COLUMNS, OnUseDefaults)
  53. ON_BN_CLICKED(IDC_MOVEUP_COLUMN, OnMoveUp)
  54. ON_BN_CLICKED(IDC_MOVEDOWN_COLUMN, OnMoveDown)
  55. ON_BN_CLICKED(IDC_ADD_COLUMNS, OnAddColumn)
  56. ON_BN_CLICKED(IDC_REMOVE_COLUMNS, OnRemoveColumn)
  57. ON_LBN_DBLCLK(IDC_HIDDEN_COLUMNS, OnAddColumn)
  58. ON_LBN_DBLCLK(IDC_DISPLAYED_COLUMNS, OnRemoveColumn)
  59. //}}AFX_MSG_MAP
  60. END_MESSAGE_MAP()
  61. DWORD ColumnDlg::m_dwHelpMap[] =
  62. {
  63. // IDC_LCX_COLUMNS, HIDC_LCX_COLUMNS,
  64. // IDC_LCX_MOVEUP, HIDC_LCX_MOVEUP,
  65. // IDC_LCX_MOVEDOWN, HIDC_LCX_MOVEDOWN,
  66. // IDC_LCX_WIDTH, HIDC_LCX_WIDTH,
  67. // IDC_LCX_LEFT, HIDC_LCX_LEFT,
  68. // IDC_LCX_SCALE, HIDC_LCX_SCALE,
  69. // IDC_LCX_RIGHT, HIDC_LCX_RIGHT,
  70. 0,0
  71. };
  72. //----------------------------------------------------------------------------
  73. // Function: ColumnDlg::OnInitDialog
  74. //
  75. // Handles the 'WM_INITDIALOG' message.
  76. //----------------------------------------------------------------------------
  77. BOOL ColumnDlg::OnInitDialog() {
  78. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  79. ULONG i, j;
  80. int iPos, iItem;
  81. RECT rc;
  82. POSITION pos;
  83. CString sItem;
  84. ULONG uCol;
  85. CBaseDialog::OnInitDialog();
  86. // Fill the list with the titles of the columns
  87. //
  88. if (!AddColumnsToList())
  89. return FALSE;
  90. //
  91. // Select the first item
  92. //
  93. return TRUE;
  94. }
  95. void ColumnDlg::OnUseDefaults()
  96. {
  97. int count, i;
  98. HDWP hdwp;
  99. // Reset the column information
  100. for (i=0; i<(int)m_cColumnInfo; i++)
  101. {
  102. if (m_pColumnInfo[i].m_fVisibleByDefault)
  103. m_pColumnData[i].m_nPosition = i+1;
  104. else
  105. m_pColumnData[i].m_nPosition = -(i+1);
  106. }
  107. // Get rid of all of the current columns
  108. hdwp = BeginDeferWindowPos(2);
  109. m_lboxDisplayed.ResetContent();
  110. m_lboxHidden.ResetContent();
  111. // add the columns back to the list
  112. AddColumnsToList();
  113. if (hdwp)
  114. EndDeferWindowPos(hdwp);
  115. }
  116. //----------------------------------------------------------------------------
  117. // Function:: ColumnDlg::OnOK
  118. //----------------------------------------------------------------------------
  119. VOID
  120. ColumnDlg::OnOK(
  121. ) {
  122. BOOL bEmpty;
  123. INT i;
  124. INT count;
  125. DWORD_PTR nPosition;
  126. count = m_lboxDisplayed.GetCount();
  127. //
  128. // Check to see whether any columns are enabled
  129. //
  130. bEmpty = (count == 0);
  131. //
  132. // If no columns are enabled and the caller needs at least one column,
  133. // complain to the user and don't close the dialog.
  134. //
  135. if (bEmpty)
  136. {
  137. AfxMessageBox(IDS_ERR_NOCOLUMNS);
  138. return;
  139. }
  140. // Ok, we need to write the info back out
  141. for (i = 0; i < count; i++)
  142. {
  143. nPosition = m_lboxDisplayed.GetItemData(i);
  144. m_pColumnData[nPosition].m_nPosition = (i+1);
  145. }
  146. INT HiddenCount = m_lboxHidden.GetCount();
  147. for (i = 0; i < HiddenCount; i++)
  148. {
  149. nPosition = m_lboxHidden.GetItemData(i);
  150. m_pColumnData[nPosition].m_nPosition = -(1+i+count);
  151. }
  152. CBaseDialog::OnOK();
  153. }
  154. //----------------------------------------------------------------------------
  155. // Function:: ColumnDlg::OnMoveUp
  156. //----------------------------------------------------------------------------
  157. VOID
  158. ColumnDlg::OnMoveUp( ) { MoveItem(-1); }
  159. //----------------------------------------------------------------------------
  160. // Function:: ColumnDlg::OnMoveDown
  161. //----------------------------------------------------------------------------
  162. VOID
  163. ColumnDlg::OnMoveDown( ) { MoveItem(1); }
  164. //----------------------------------------------------------------------------
  165. // Function:: ColumnDlg::OnRemoveColumn
  166. //----------------------------------------------------------------------------
  167. VOID
  168. ColumnDlg::OnRemoveColumn( )
  169. {
  170. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  171. INT i;
  172. BOOL bEnabled;
  173. CString sItem;
  174. DWORD_PTR iItem;
  175. //
  176. // Get the selected item
  177. //
  178. i = m_lboxDisplayed.GetCurSel();
  179. if (LB_ERR == i)
  180. return;
  181. iItem = m_lboxDisplayed.GetItemData(i);
  182. //
  183. // Remove the item from its current position
  184. //
  185. m_lboxDisplayed.DeleteString(i);
  186. //
  187. // Insert the item at its new position
  188. //
  189. sItem.LoadString(m_pColumnInfo[iItem].m_ulStringId);
  190. i = m_lboxHidden.GetCount();
  191. m_lboxHidden.InsertString(i, sItem);
  192. m_lboxHidden.SetItemData(i, (DWORD)iItem);
  193. m_lboxHidden.SetCurSel(i);
  194. }
  195. //----------------------------------------------------------------------------
  196. // Function:: ColumnDlg::OnAddColumn
  197. //----------------------------------------------------------------------------
  198. VOID
  199. ColumnDlg::OnAddColumn( )
  200. {
  201. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  202. INT i;
  203. BOOL bEnabled;
  204. CString sItem;
  205. DWORD_PTR iItem;
  206. //
  207. // Get the selected item
  208. //
  209. i = m_lboxHidden.GetCurSel();
  210. if (LB_ERR == i)
  211. return;
  212. iItem = m_lboxHidden.GetItemData(i);
  213. //
  214. // Remove the item from its current position
  215. //
  216. m_lboxHidden.DeleteString(i);
  217. //
  218. // Insert the item at its new position
  219. //
  220. sItem.LoadString(m_pColumnInfo[iItem].m_ulStringId);
  221. i = m_lboxDisplayed.GetCount();
  222. m_lboxDisplayed.InsertString(i, sItem);
  223. m_lboxDisplayed.SetItemData(i, (DWORD)iItem);
  224. m_lboxDisplayed.SetCurSel(i);
  225. }
  226. //----------------------------------------------------------------------------
  227. // Function:: ColumnDlg::MoveItem
  228. //----------------------------------------------------------------------------
  229. VOID
  230. ColumnDlg::MoveItem(
  231. INT dir
  232. )
  233. {
  234. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  235. INT i;
  236. BOOL bEnabled;
  237. CString sItem;
  238. DWORD_PTR iItem;
  239. //
  240. // Get the selected item
  241. //
  242. i = m_lboxDisplayed.GetCurSel();
  243. if (i == -1 || (i + dir) < 0 || (i + dir) >= m_lboxDisplayed.GetCount())
  244. return;
  245. iItem = m_lboxDisplayed.GetItemData(i);
  246. //
  247. // Remove the item from its current position
  248. //
  249. m_lboxDisplayed.DeleteString(i);
  250. //
  251. // Insert the item at its new position
  252. //
  253. i += dir;
  254. sItem.LoadString(m_pColumnInfo[iItem].m_ulStringId);
  255. m_lboxDisplayed.InsertString(i, sItem);
  256. m_lboxDisplayed.SetItemData(i, (DWORD)iItem);
  257. m_lboxDisplayed.SetCurSel(i);
  258. }
  259. BOOL ColumnDlg::AddColumnsToList()
  260. {
  261. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  262. ULONG i, j;
  263. int iPos, iItem;
  264. CString sItem;
  265. Assert(m_pColumnData);
  266. m_lboxDisplayed.ResetContent();
  267. m_lboxHidden.ResetContent();
  268. int cDisplayItems = 0;
  269. int HiddenItems = 0;
  270. for (i=0; i<m_cColumnInfo; i++)
  271. {
  272. // look for the column at position (i+1)
  273. for (j=0; j<m_cColumnInfo; j++)
  274. {
  275. iPos = m_pColumnData[j].m_nPosition;
  276. iPos = abs(iPos);
  277. if ((ULONG)iPos == (i+1))
  278. break;
  279. }
  280. Assert( j < m_cColumnInfo );
  281. sItem.LoadString(m_pColumnInfo[j].m_ulStringId);
  282. if (m_pColumnData[j].m_nPosition > 0)
  283. {
  284. iItem = m_lboxDisplayed.InsertString(cDisplayItems++, sItem);
  285. if (iItem == -1) { OnCancel(); return FALSE; }
  286. m_lboxDisplayed.SetItemData(iItem, j);
  287. }
  288. else
  289. {
  290. iItem = m_lboxHidden.InsertString(HiddenItems++, sItem);
  291. if (iItem == -1) { OnCancel(); return FALSE; }
  292. m_lboxHidden.SetItemData(iItem, j);
  293. }
  294. }
  295. return TRUE;
  296. }