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.

433 lines
12 KiB

  1. /**********************************************************************/
  2. /** Microsoft Windows/NT **/
  3. /** Copyright(c) Microsoft Corporation, 1997 - 1999 **/
  4. /**********************************************************************/
  5. /*
  6. summary.cpp
  7. IP summary node implementation.
  8. FILE HISTORY:
  9. */
  10. #include "stdafx.h"
  11. #include "util.h"
  12. #include "basecon.h"
  13. #include "tfschar.h"
  14. #include "strmap.h" // XXXtoCString functions
  15. #include "service.h" // TFS service APIs
  16. #include "rtrstr.h" // const strings used
  17. #include "coldlg.h" // columndlg
  18. #include "column.h" // column stuff
  19. /*---------------------------------------------------------------------------
  20. BaseContainerHandler implementation
  21. ---------------------------------------------------------------------------*/
  22. HRESULT BaseContainerHandler::OnResultColumnClick(ITFSComponent *pComponent,
  23. LPARAM iColumn, BOOL fAsc)
  24. {
  25. HRESULT hr = hrOK;
  26. ConfigStream * pConfig;
  27. //
  28. // Get the configuration data
  29. //
  30. pComponent->GetUserData((LONG_PTR *) &pConfig);
  31. Assert(pConfig);
  32. pConfig->SetSortColumn(m_ulColumnId, (long)iColumn);
  33. pConfig->SetSortDirection(m_ulColumnId, fAsc);
  34. return hr;
  35. }
  36. /*!--------------------------------------------------------------------------
  37. BaseContainerHandler::SortColumns
  38. -
  39. Author: KennT
  40. ---------------------------------------------------------------------------*/
  41. HRESULT BaseContainerHandler::SortColumns(ITFSComponent *pComponent)
  42. {
  43. HRESULT hr = hrOK;
  44. SPIResultData spResultData;
  45. ULONG ulSortColumn, ulSortDirection;
  46. ConfigStream * pConfig;
  47. //
  48. // Get the configuration data
  49. //
  50. pComponent->GetUserData((LONG_PTR *) &pConfig);
  51. Assert(pConfig);
  52. // Setup the sort order and direction
  53. ulSortColumn = pConfig->GetSortColumn(m_ulColumnId);
  54. ulSortDirection = pConfig->GetSortDirection(m_ulColumnId);
  55. CORg( pComponent->GetResultData(&spResultData) );
  56. CORg( spResultData->Sort(ulSortColumn, ulSortDirection, 0) );
  57. Error:
  58. return hr;
  59. }
  60. /*!--------------------------------------------------------------------------
  61. BaseContainerHandler::LoadColumns
  62. -
  63. Author: KennT
  64. ---------------------------------------------------------------------------*/
  65. HRESULT BaseContainerHandler::LoadColumns(ITFSComponent *pComponent, MMC_COOKIE cookie, LPARAM arg, LPARAM lParam)
  66. {
  67. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  68. SPIHeaderCtrl spHeaderCtrl;
  69. pComponent->GetHeaderCtrl(&spHeaderCtrl);
  70. return PrivateLoadColumns(pComponent, spHeaderCtrl, cookie);
  71. }
  72. /*!--------------------------------------------------------------------------
  73. BaseContainerHandler::SaveColumns
  74. Override of CBaseResultHandler::SaveColumns.
  75. This just writes back out the width information. Changes made
  76. to the column order or what is visible is written directly back
  77. to the ConfigStream by the "Select Columns" dialog.
  78. Even though MMC saves this data for us, we still need to save
  79. the data ourselves.
  80. Author: KennT
  81. ---------------------------------------------------------------------------*/
  82. HRESULT BaseContainerHandler::SaveColumns(ITFSComponent *pComponent, MMC_COOKIE cookie, LPARAM arg, LPARAM lParam)
  83. {
  84. // Get information from the column map in the nodedata
  85. // and save it back out
  86. ColumnData *prgColData;
  87. HRESULT hr = hrOK;
  88. UINT i;
  89. ULONG ulPos;
  90. SPIHeaderCtrl spHeaderCtrl;
  91. int iWidth;
  92. ConfigStream * pConfig;
  93. ULONG cColumns;
  94. CORg( pComponent->GetHeaderCtrl(&spHeaderCtrl) );
  95. //
  96. // Get the configuration data
  97. //
  98. pComponent->GetUserData((LONG_PTR *) &pConfig);
  99. Assert(pConfig);
  100. //
  101. // Get the information about the columns
  102. //
  103. cColumns = pConfig->GetColumnCount(m_ulColumnId);
  104. //
  105. // Allocate temporary space for the column data
  106. //
  107. prgColData = (ColumnData *) alloca(sizeof(ColumnData)*cColumns);
  108. CORg( pConfig->GetColumnData(m_ulColumnId, cColumns, prgColData) );
  109. //
  110. // Now write over the old data with the new data (this way we preserve
  111. // defaults).
  112. //
  113. for (i=0; i<cColumns; i++)
  114. {
  115. // if (i < pConfig->GetVisibleColumns(m_ulColumnId))
  116. {
  117. // ulPos = pConfig->MapColumnToSubitem(m_ulColumnId, i);
  118. ulPos = i;
  119. if (FHrSucceeded(spHeaderCtrl->GetColumnWidth(i, &iWidth)))
  120. prgColData[ulPos].m_dwWidth = iWidth;
  121. }
  122. }
  123. //
  124. // Write the data back
  125. //
  126. CORg( pConfig->SetColumnData(m_ulColumnId, cColumns, prgColData) );
  127. Error:
  128. return hr;
  129. }
  130. /*!--------------------------------------------------------------------------
  131. BaseContainerHandler::PrivateLoadColumns
  132. -
  133. Author: KennT
  134. ---------------------------------------------------------------------------*/
  135. HRESULT BaseContainerHandler::PrivateLoadColumns(ITFSComponent *pComponent,
  136. IHeaderCtrl *pHeaderCtrl, MMC_COOKIE cookie)
  137. {
  138. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  139. HRESULT hr = hrOK;
  140. CString st;
  141. ULONG i = 0;
  142. ColumnData *prgColData;
  143. int iPos;
  144. ConfigStream * pConfig;
  145. ULONG cColumns;
  146. static UINT s_uCharWidth = 0;
  147. DWORD dwWidth;
  148. if (s_uCharWidth == 0)
  149. {
  150. const TCHAR s_szTestData[] = _T("abcdABCD");
  151. s_uCharWidth = CalculateStringWidth(NULL, s_szTestData);
  152. s_uCharWidth /= 8;
  153. }
  154. pComponent->GetUserData((LONG_PTR *) &pConfig);
  155. Assert(pConfig);
  156. cColumns = pConfig->GetColumnCount(m_ulColumnId);
  157. prgColData = (ColumnData *) alloca(sizeof(ColumnData)*cColumns);
  158. //
  159. // Build up the column data from the current list in the
  160. // node data
  161. //
  162. pConfig->GetColumnData(m_ulColumnId, cColumns, prgColData);
  163. // for (i=0; i<pConfig->GetVisibleColumns(m_ulColumnId); i++)
  164. for (i=0; i<cColumns; i++)
  165. {
  166. // Add this column to the list view
  167. // iPos = pConfig->MapColumnToSubitem(m_ulColumnId, i);
  168. iPos = i;
  169. st.LoadString(m_prgColumnInfo[iPos].m_ulStringId);
  170. if (prgColData[iPos].m_nPosition < 0)
  171. dwWidth = HIDE_COLUMN;
  172. else
  173. dwWidth = prgColData[iPos].m_dwWidth;
  174. pHeaderCtrl->InsertColumn(i,
  175. const_cast<LPTSTR>((LPCWSTR)st),
  176. LVCFMT_LEFT,
  177. dwWidth);
  178. if (dwWidth == AUTO_WIDTH)
  179. {
  180. ULONG uLength = max((ULONG)st.GetLength() + 4, m_prgColumnInfo[iPos].m_ulDefaultColumnWidth);
  181. dwWidth = uLength * s_uCharWidth;
  182. pHeaderCtrl->SetColumnWidth(i, dwWidth);
  183. }
  184. }
  185. //Error:
  186. return hr;
  187. }
  188. HRESULT BaseContainerHandler::UserResultNotify(ITFSNode *pNode,
  189. LPARAM lParam1,
  190. LPARAM lParam2)
  191. {
  192. HRESULT hr = hrOK;
  193. COM_PROTECT_TRY
  194. {
  195. if (lParam1 == RRAS_ON_SAVE)
  196. {
  197. hr = SaveColumns((ITFSComponent *) lParam2,
  198. (MMC_COOKIE) pNode->GetData(TFS_DATA_COOKIE),
  199. 0, 0);
  200. }
  201. else
  202. hr = BaseRouterHandler::UserResultNotify(pNode, lParam1, lParam2);
  203. }
  204. COM_PROTECT_CATCH;
  205. return hr;
  206. }
  207. /*!--------------------------------------------------------------------------
  208. BaseContainerHandler::TaskPadGetTitle
  209. -
  210. Author: MikeG (a-migall)
  211. ---------------------------------------------------------------------------*/
  212. STDMETHODIMP BaseContainerHandler::TaskPadGetTitle(ITFSComponent * pComponent,
  213. MMC_COOKIE cookie,
  214. LPOLESTR pszGroup,
  215. LPOLESTR * ppszTitle)
  216. {
  217. // Check parameters;
  218. Assert(ppszTitle);
  219. // Not using...
  220. UNREFERENCED_PARAMETER(pComponent);
  221. UNREFERENCED_PARAMETER(cookie);
  222. UNREFERENCED_PARAMETER(pszGroup);
  223. // Need to call this so we can safely call the LoadString()
  224. // member on CString.
  225. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  226. // Load the TaskPad's display name from a string table in
  227. // the resources.
  228. *ppszTitle = NULL;
  229. CString sTaskpadTitle;
  230. Assert(m_nTaskPadDisplayNameId > 0);
  231. if (!sTaskpadTitle.LoadString(m_nTaskPadDisplayNameId))
  232. return E_OUTOFMEMORY;
  233. // Allocate a buffer for the string.
  234. *ppszTitle =
  235. reinterpret_cast<LPOLESTR>(::CoTaskMemAlloc(sizeof(OLECHAR)*(sTaskpadTitle.GetLength()+1)));
  236. if (!*ppszTitle)
  237. {
  238. *ppszTitle = NULL; // cleanup to a steady state...
  239. return E_OUTOFMEMORY;
  240. }
  241. // Package the display name for return to the MMC console.
  242. HRESULT hr = S_OK;
  243. if (::lstrcpy(*ppszTitle, (LPCTSTR)sTaskpadTitle) == NULL)
  244. {
  245. hr = HRESULT_FROM_WIN32(::GetLastError());
  246. ::CoTaskMemFree(*ppszTitle);
  247. *ppszTitle = NULL;
  248. // Future: Wonder if it is safe for us to cleanup this unused
  249. // memory here in the snapin versus letting the MMC
  250. // handle it? Well, the MMC should be smart enough to
  251. // realize that there is no string buffer.
  252. }
  253. return hr;
  254. }
  255. /*!--------------------------------------------------------------------------
  256. BaseContainerHandler::OnResultContextHelp
  257. -
  258. Author: MikeG (a-migall)
  259. ---------------------------------------------------------------------------*/
  260. HRESULT BaseContainerHandler::OnResultContextHelp(ITFSComponent * pComponent,
  261. LPDATAOBJECT pDataObject,
  262. MMC_COOKIE cookie,
  263. LPARAM arg,
  264. LPARAM lParam)
  265. {
  266. // Not used...
  267. UNREFERENCED_PARAMETER(pDataObject);
  268. UNREFERENCED_PARAMETER(cookie);
  269. UNREFERENCED_PARAMETER(arg);
  270. UNREFERENCED_PARAMETER(lParam);
  271. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  272. return HrDisplayHelp(pComponent, m_spTFSCompData->GetHTMLHelpFileName(), m_nHelpTopicId);
  273. }
  274. /*!--------------------------------------------------------------------------
  275. BaseContainerHandler::TaskPadNotify
  276. -
  277. Author: MikeG (a-migall)
  278. ---------------------------------------------------------------------------*/
  279. STDMETHODIMP BaseContainerHandler::TaskPadNotify(ITFSComponent * pComponent,
  280. IN MMC_COOKIE cookie,
  281. IN LPDATAOBJECT pDataObject,
  282. IN VARIANT * arg,
  283. IN VARIANT * param)
  284. {
  285. // Not used...
  286. UNREFERENCED_PARAMETER(cookie);
  287. UNREFERENCED_PARAMETER(pDataObject);
  288. UNREFERENCED_PARAMETER(param);
  289. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  290. HRESULT hr = hrOK;
  291. if (arg->vt == VT_I4)
  292. {
  293. switch (arg->lVal)
  294. {
  295. case 0: // for a lack of anything better!!!
  296. hr = HrDisplayHelp(pComponent, m_spTFSCompData->GetHTMLHelpFileName(), m_nHelpTopicId);
  297. break;
  298. default:
  299. Panic1("BaseContainerHandler::TaskPadNotify - Unrecognized command! %d", arg->lVal);
  300. break;
  301. }
  302. }
  303. return hrOK;
  304. }
  305. /*!--------------------------------------------------------------------------
  306. HrDisplayHelp
  307. -
  308. Author: MikeG (a-migall)
  309. ---------------------------------------------------------------------------*/
  310. HRESULT HrDisplayHelp(ITFSComponent * pComponent,
  311. LPCTSTR pcszHelpFile,
  312. UINT nHelpTopicId)
  313. {
  314. Assert(nHelpTopicId > 0);
  315. CString sHelpTopic;
  316. if (!sHelpTopic.LoadString(nHelpTopicId))
  317. return E_FAIL;
  318. return HrDisplayHelp(pComponent, pcszHelpFile, (LPCTSTR)sHelpTopic);
  319. }
  320. HRESULT HrDisplayHelp(ITFSComponent * pComponent,
  321. LPCTSTR pcszHelpFile,
  322. LPCTSTR pcszHelpTopic)
  323. {
  324. Assert(!::IsBadStringPtr(pcszHelpFile, ::lstrlen(pcszHelpFile)));
  325. if (pcszHelpFile == NULL)
  326. //return E_FAIL;
  327. return S_OK; // ???
  328. Trace1("HTML Help Filename = %s\n", pcszHelpFile);
  329. //
  330. // Future: Why do we hand this in when we don't even use it? There
  331. // was a reason, but I'll be damned if I can remember why.
  332. //
  333. // Get an interface to the MMC console.
  334. SPIConsole spConsole;
  335. Assert(pComponent);
  336. pComponent->GetConsole(&spConsole);
  337. // Get the MMC console's help interface.
  338. SPIDisplayHelp spDisplayHelp;
  339. HRESULT hr = spConsole->QueryInterface(IID_IDisplayHelp,
  340. reinterpret_cast<LPVOID*>(&spDisplayHelp));
  341. //ASSERT(SUCCEEDED(hr));
  342. if (FAILED(hr))
  343. return hr;
  344. CString sHelpFilePath;
  345. UINT nLen = ::GetWindowsDirectory(sHelpFilePath.GetBufferSetLength(2*MAX_PATH), 2*MAX_PATH);
  346. sHelpFilePath.ReleaseBuffer();
  347. if (nLen == 0)
  348. return E_FAIL;
  349. Assert(!::IsBadStringPtr(pcszHelpTopic, ::lstrlen(pcszHelpTopic)));
  350. sHelpFilePath += pcszHelpTopic;
  351. LPTSTR psz = const_cast<LPTSTR>((LPCTSTR)sHelpFilePath);
  352. Assert(!::IsBadStringPtr(psz, ::lstrlen(psz)));
  353. Trace1("Help Filename (with path) = %s\n", psz);
  354. hr = spDisplayHelp->ShowTopic(T2OLE(psz));
  355. //ASSERT(SUCCEEDED(hr));
  356. return hr;
  357. }