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.

339 lines
8.3 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1999
  5. //
  6. // File: output.h
  7. //
  8. // Contents: Header file for classes and function used for display
  9. //
  10. // History: 3-oct-2000 hiteshr Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include "gettable.h"
  14. HRESULT LocalCopyString(LPTSTR* ppResult, LPCTSTR pString);
  15. //+--------------------------------------------------------------------------
  16. //
  17. // Class: CDisplay
  18. //
  19. // Purpose: This class is used for displaying a column
  20. //
  21. // History: 3-oct-2000 hiteshr Created
  22. //
  23. //---------------------------------------------------------------------------
  24. class CDisplay
  25. {
  26. #define MAXPAD 80
  27. public:
  28. //
  29. //Initialize the Pad
  30. //
  31. CDisplay()
  32. {
  33. PadChar = L' ';
  34. //Initialize the pad.
  35. for( int i = 0; i < MAXPAD; ++i)
  36. Pad[i] = PadChar;
  37. }
  38. //
  39. //Display width number of Pad Charachter
  40. //
  41. VOID DisplayPad(LONG width)
  42. {
  43. if(width <= 0 )
  44. return;
  45. if(width >= MAXPAD)
  46. width = MAXPAD -1;
  47. Pad[width] = 0;
  48. WriteStandardOut(L"%s",Pad);
  49. Pad[width] = PadChar;
  50. }
  51. //
  52. //Dispaly a column with two starting pad,
  53. //column value and two ending pad
  54. //
  55. VOID DisplayColumn(LONG width, PCWSTR lpszValue)
  56. {
  57. //Display Two PadChar in the begining
  58. DisplayPad(2);
  59. if(lpszValue)
  60. {
  61. WriteStandardOut(lpszValue);
  62. DisplayPad(width- static_cast<LONG>(wcslen(lpszValue)));
  63. }
  64. else
  65. DisplayPad(width);
  66. //Display Two Trailing Padchar
  67. DisplayPad(2);
  68. }
  69. //
  70. //Display Newline
  71. //
  72. VOID DisplayNewLine()
  73. {
  74. WriteStandardOut(L"%s",L"\n");
  75. }
  76. private:
  77. WCHAR Pad[MAXPAD];
  78. WCHAR PadChar;
  79. };
  80. //+--------------------------------------------------------------------------
  81. //
  82. // Class: CFormatInfo
  83. //
  84. // Purpose: Used to format table columns and display table
  85. //
  86. // History: 17-Oct-2000 JeffJon Created
  87. //
  88. //---------------------------------------------------------------------------
  89. class CFormatInfo
  90. {
  91. public:
  92. //
  93. // Constructor
  94. //
  95. CFormatInfo();
  96. //
  97. // Destructor
  98. //
  99. ~CFormatInfo();
  100. //
  101. // Public methods
  102. //
  103. HRESULT Initialize(DWORD dwSampleSize, bool bShowAsList = false, bool bQuiet = false);
  104. inline DWORD GetColWidth(DWORD dwColNum)
  105. {
  106. ASSERT(m_bInitialized);
  107. if(dwColNum >= m_dwNumColumns)
  108. {
  109. ASSERT(FALSE);
  110. return 0;
  111. }
  112. return m_pColWidth[dwColNum];
  113. }
  114. inline void SetColWidth(DWORD dwColNum, DWORD dwWidth)
  115. {
  116. ASSERT(m_bInitialized);
  117. if(dwColNum >= m_dwNumColumns)
  118. {
  119. ASSERT(FALSE);
  120. return;
  121. }
  122. if(dwWidth > m_pColWidth[dwColNum])
  123. {
  124. m_pColWidth[dwColNum] = dwWidth;
  125. }
  126. }
  127. HRESULT AddRow(PDSGET_DISPLAY_INFO pDisplayInfo, DWORD dwColumnCount);
  128. DWORD GetRowCount() { return m_dwTotalRows; }
  129. inline HRESULT Get(DWORD dwRow, DWORD dwCol, CComBSTR& refsbstrColValue)
  130. {
  131. refsbstrColValue.Empty();
  132. ASSERT(m_bInitialized);
  133. if(dwRow >= m_dwTotalRows || dwCol >= m_dwNumColumns)
  134. {
  135. ASSERT(FALSE);
  136. return E_INVALIDARG;
  137. }
  138. refsbstrColValue += m_ppDisplayInfoArray[dwRow][dwCol].GetValue(0);
  139. for (DWORD dwIdx = 1; dwIdx < m_ppDisplayInfoArray[dwRow][dwCol].GetValueCount(); dwIdx++)
  140. {
  141. refsbstrColValue += L";";
  142. refsbstrColValue += m_ppDisplayInfoArray[dwRow][dwCol].GetValue(dwIdx);
  143. }
  144. return S_OK;
  145. }
  146. void DisplayHeaders()
  147. {
  148. ASSERT(m_bInitialized);
  149. if (!m_bQuiet)
  150. {
  151. for( DWORD i = 0; i < m_dwNumColumns; ++i)
  152. {
  153. m_display.DisplayColumn(GetColWidth(i),m_ppDisplayInfoArray[0][i].GetDisplayName());
  154. }
  155. NewLine();
  156. }
  157. }
  158. void DisplayColumn(DWORD dwRow, DWORD dwCol)
  159. {
  160. ASSERT(m_bInitialized);
  161. if(dwRow >= m_dwTotalRows || dwCol >= m_dwNumColumns)
  162. {
  163. ASSERT(FALSE);
  164. return ;
  165. }
  166. if (!m_bQuiet)
  167. {
  168. CComBSTR sbstrValue;
  169. HRESULT hr = Get(dwRow, dwCol, sbstrValue);
  170. if (SUCCEEDED(hr))
  171. {
  172. m_display.DisplayColumn(GetColWidth(dwCol), sbstrValue);
  173. }
  174. }
  175. }
  176. void DisplayColumn(DWORD dwCol, PCWSTR pszValue)
  177. {
  178. ASSERT(m_bInitialized);
  179. if(dwCol >= m_dwNumColumns)
  180. {
  181. ASSERT(FALSE);
  182. return;
  183. }
  184. if (!m_bQuiet)
  185. {
  186. m_display.DisplayColumn(GetColWidth(dwCol), pszValue);
  187. }
  188. }
  189. void Display()
  190. {
  191. ASSERT(m_bInitialized);
  192. if (!m_bListFormat && !m_bQuiet)
  193. {
  194. DisplayHeaders();
  195. for(DWORD i = 0; i < m_dwTotalRows; ++i)
  196. {
  197. for(DWORD j = 0; j < m_dwNumColumns; ++j)
  198. {
  199. DisplayColumn(i,j);
  200. }
  201. NewLine();
  202. }
  203. }
  204. }
  205. void NewLine()
  206. {
  207. if (!m_bQuiet)
  208. {
  209. m_display.DisplayNewLine();
  210. }
  211. }
  212. private:
  213. //
  214. // Private data
  215. //
  216. bool m_bInitialized;
  217. bool m_bListFormat;
  218. bool m_bQuiet;
  219. //
  220. //Number of rows to be used for calulating
  221. //column width. This is also the size of the table.
  222. //
  223. DWORD m_dwSampleSize;
  224. //
  225. //Count of rows in cache
  226. //
  227. DWORD m_dwTotalRows;
  228. //
  229. //Number of columns
  230. //
  231. DWORD m_dwNumColumns;
  232. //
  233. // Array of column widths
  234. //
  235. DWORD* m_pColWidth;
  236. //
  237. // Array of column header/value pairs
  238. //
  239. PDSGET_DISPLAY_INFO* m_ppDisplayInfoArray;
  240. CDisplay m_display;
  241. };
  242. //+--------------------------------------------------------------------------
  243. //
  244. // Function: DsGetOutputValuesList
  245. //
  246. // Synopsis: This function gets the values for the columns and then adds
  247. // the row to the format helper
  248. //
  249. // Arguments: [pszDN IN] : the DN of the object
  250. // [refBasePathsInfo IN] : reference to path info
  251. // [refCredentialObject IN] : reference to the credential manager
  252. // [pCommandArgs IN] : Command line arguments
  253. // [pObjectEntry IN] : Entry in the object table being processed
  254. // [pAttrInfo IN] : the values to display
  255. // [dwAttrCount IN] : Number of arributes in above array
  256. // [spDirObject IN] : Interface pointer to the object
  257. // [refFormatInfo IN]: Reference to the format helper
  258. //
  259. // Returns: HRESULT : S_OK if everything succeeded
  260. // E_INVALIDARG
  261. //
  262. // History: 16-Oct-2000 JeffJon Created
  263. //
  264. //---------------------------------------------------------------------------
  265. HRESULT DsGetOutputValuesList(PCWSTR pszDN,
  266. CDSCmdBasePathsInfo& refBasePathsInfo,
  267. const CDSCmdCredentialObject& refCredentialObject,
  268. PARG_RECORD pCommandArgs,
  269. PDSGetObjectTableEntry pObjectEntry,
  270. DWORD dwAttrCount,
  271. PADS_ATTR_INFO pAttrInfo,
  272. CComPtr<IDirectoryObject>& spDirObject,
  273. CFormatInfo& refFormatInfo);
  274. //+--------------------------------------------------------------------------
  275. //
  276. // Function: GetStringFromADs
  277. //
  278. // Synopsis: Converts Value into string depending upon type
  279. // Arguments: [pValues - IN]: Value to be converted to string
  280. // [dwADsType-IN]: ADSTYPE of pValue
  281. // [pBuffer - OUT]:Output buffer which gets the string
  282. // [dwBufferLen-IN]:Size of output buffer
  283. // Returns HRESULT S_OK if Successful
  284. // E_INVALIDARG
  285. // Anything else is a failure code from an ADSI
  286. // call
  287. //
  288. //
  289. // History: 05-OCT-2000 hiteshr Created
  290. //
  291. //---------------------------------------------------------------------------
  292. HRESULT GetStringFromADs(IN const ADSVALUE *pValues,
  293. IN ADSTYPE dwADsType,
  294. OUT LPWSTR pBuffer,
  295. IN DWORD dwBufferLen);