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.

1189 lines
42 KiB

  1. #ifndef _INC_DSKQUOTA_DETAILS_H
  2. #define _INC_DSKQUOTA_DETAILS_H
  3. ///////////////////////////////////////////////////////////////////////////////
  4. /* File: details.h
  5. Description: Declaration for class DetailsView.
  6. This is a complex class but don't be intimidated by it.
  7. Much of the functionality has been layered in private subclasses
  8. so that the scope of any individual piece is minimized.
  9. Revision History:
  10. Date Description Programmer
  11. -------- --------------------------------------------------- ----------
  12. 08/20/96 Initial creation. BrianAu
  13. 12/06/96 Removed INLINE from message handler methods. BrianAu
  14. It's just too hard to debug when they're inline.
  15. 05/28/97 Major changes. BrianAu
  16. - Added "User Finder".
  17. - Added promotion of selected item to front of
  18. name resolution queue.
  19. - Improved name resolution status reporting through
  20. listview.
  21. - Moved drag/drop and report generation code
  22. from dragdrop.cpp and reptgen.cpp into the
  23. DetailsView class. DetailsView now implements
  24. IDataObject, IDropSource and IDropTarget instead
  25. of deferring implementation to secondary objects.
  26. dragdrop.cpp and reptgen.cpp have been dropped
  27. from the project.
  28. - Added support for CF_HDROP and private import/
  29. export clipboard formats.
  30. - Added import/export functionality.
  31. 07/28/97 Removed export support for CF_HDROP. Replaced BrianAu
  32. with FileContents and FileGroupDescriptor. Import
  33. from CF_HDROP is still supported.
  34. Added Import Source object hierarchy.
  35. */
  36. ///////////////////////////////////////////////////////////////////////////////
  37. #ifndef _INC_DSKQUOTA_H
  38. # include "dskquota.h"
  39. #endif
  40. #ifndef _INC_DSKQUOTA_CONTROL_H
  41. # include "control.h"
  42. #endif
  43. #ifndef _INC_DSKQUOTA_UNDO_H
  44. # include "undo.h"
  45. #endif
  46. #ifndef _INC_DSKQUOTA_FORMAT_H
  47. # include "format.h"
  48. #endif
  49. #ifndef _INC_DSKQUOTA_PROGRESS_H
  50. # include "progress.h"
  51. #endif
  52. //
  53. // Custom messages for this implementation.
  54. //
  55. #define WM_MAINWINDOW_CREATED (WM_USER + 1)
  56. #define WM_ADD_USER_TO_DETAILS_VIEW (WM_USER + 2)
  57. #define WM_DEL_USER_FROM_DETAILS_VIEW (WM_USER + 3)
  58. //
  59. // Structure containing column definition data for the listview.
  60. //
  61. struct DV_COLDATA
  62. {
  63. int fmt;
  64. int cx;
  65. DWORD idMsgText;
  66. int iColId;
  67. };
  68. //
  69. // Listview report item structure.
  70. // Used for obtaining text/numeric data for a given item in the listview
  71. // for purposes of generating a drag-drop data source.
  72. //
  73. typedef struct
  74. {
  75. DWORD fType;
  76. LPTSTR pszText;
  77. UINT cchMaxText;
  78. DWORD dwValue;
  79. double dblValue;
  80. } LV_REPORT_ITEM, *PLV_REPORT_ITEM;
  81. //
  82. // Listview Report Item (LVRI) type constants (fType)
  83. // These indicate what type of data is requested for a LV_REPORT_ITEM and
  84. // also what type of data is provided in LV_REPORT_ITEM. A caller of
  85. // DetailsView::GetReportItem provides an LV_REPORT_ITEM that acts as the
  86. // communication mechanism between the caller and the DetailsView. The
  87. // caller fills in the fType member indicating what format of information
  88. // is desired for that row/col item. The request may be any one of the
  89. // following constants:
  90. //
  91. // LVRI_TEXT = Would like data in text format if possible.
  92. // LVRI_INT = Would like data in integer format if possible.
  93. // LVRI_REAL = Would like data in floating point format if possible.
  94. // LVRI_NUMBER = Would like data in either INT or REAL format if possible.
  95. //
  96. // This value in fType is merely a hint. If the data can't be provided in the
  97. // requested format, the next best format is supplied. Upon return, the fType
  98. // flag may be modified to indicate the actual format of the data returned.
  99. // This value may be either LVRI_TEXT, LVRI_INT or LVRI_REAL. LVRI_NUMBER is
  100. // only used for hinting by the caller.
  101. //
  102. const DWORD LVRI_TEXT = 0x00000001;
  103. const DWORD LVRI_INT = 0x00000002;
  104. const DWORD LVRI_REAL = 0x00000004;
  105. const DWORD LVRI_NUMBER = (LVRI_INT | LVRI_REAL);
  106. //
  107. // Structure of "ListViewState" information stored in registry per-user.
  108. // Note that we include the structure size and the screen width/height
  109. // to validate the information when we read it from the registry. If the
  110. // structure size has changed, we don't trust the data and use defaults.
  111. // If the screen size has changed, we use defaults.
  112. //
  113. //
  114. //
  115. // WARNING: I really don't like this but...
  116. // The size of the rgcxCol[] member must be at least as large
  117. // as the value of DetailsView::idCol_Last. Because of the
  118. // order dependencies of the LV_STATE_INFO and DetailsView
  119. // structures, I can't use idCol_Last in this declaration.
  120. // If you have to add a new column and change the value of
  121. // idCol_Last, make sure the size of rgcxCol[] is adjusted
  122. // appropriately. Also adjust rgColIndices[].
  123. //
  124. typedef struct
  125. {
  126. WORD cb; // Count of bytes in structure.
  127. WORD wVersion; // Version of state info (for upgrades).
  128. LONG cxScreen; // Screen width.
  129. LONG cyScreen; // Screen height.
  130. LONG cx; // Width of window (pixels).
  131. LONG cy; // Height of window (pixels).
  132. WORD fToolBar : 1; // Toolbar visible?
  133. WORD fStatusBar : 1; // Status bar visible?
  134. WORD fShowFolder : 1; // Folder column visible?
  135. WORD iLastColSorted : 4; // Current sort column.
  136. WORD fSortDirection : 1; // 0 = Ascending, 1 = Descending.
  137. WORD fReserved : 8; // Unused bits.
  138. INT rgcxCol[8]; // Width of each column (pixels).
  139. INT rgColIndices[8]; // Order of subitems in listview.
  140. } LV_STATE_INFO, *PLV_STATE_INFO;
  141. //
  142. // Increment this if you make a change that causes problems with
  143. // state info saved for existing users. It will cause us to invalidate
  144. // any existing state information and to use defaults. It may cancel
  145. // any user's existing preferences but at least the view will look OK.
  146. //
  147. const WORD wLV_STATE_INFO_VERSION = 3;
  148. //
  149. // This class maps our column ids (idCol_XXXX) to a listview column
  150. // index (SubItem).
  151. //
  152. class ColumnMap
  153. {
  154. private:
  155. INT *m_pMap;
  156. UINT m_cMapSize;
  157. //
  158. // Prevent copying.
  159. //
  160. ColumnMap(const ColumnMap&);
  161. void operator = (const ColumnMap&);
  162. public:
  163. ColumnMap(UINT cMapSize);
  164. ~ColumnMap(VOID);
  165. INT SubItemToId(INT iSubItem) const;
  166. INT IdToSubItem(INT iColId) const;
  167. VOID RemoveId(INT iSubItem);
  168. VOID InsertId(INT iSubItem, INT iColId);
  169. };
  170. class DetailsView : public IDiskQuotaEvents,
  171. public IDropSource,
  172. public IDropTarget,
  173. public IDataObject
  174. {
  175. private:
  176. //
  177. // DetailsView::Finder ------------------------------------------------
  178. //
  179. //
  180. // This class implements the "find a user" feature.
  181. // 1. "Attaches" to the "find" combo box in the toolbar by subclassing
  182. // that combo box window.
  183. // 2. Invokes the "Find User" dialog on command.
  184. // 3. Repositions the listview highlight bar on a user if found.
  185. // 4. Maintains an MRU list for populating the toolbar and dialog
  186. // combo boxes.
  187. //
  188. class Finder
  189. {
  190. public:
  191. Finder(DetailsView& DetailsView, INT cMaxMru);
  192. VOID ConnectToolbarCombo(HWND hwndToolbarCombo);
  193. VOID InvokeFindDialog(HWND hwndParent);
  194. static INT_PTR CALLBACK DlgProc(HWND, UINT, WPARAM, LPARAM);
  195. static LRESULT CALLBACK ToolbarComboSubClassWndProc(HWND, UINT, WPARAM, LPARAM);
  196. private:
  197. HWND m_hwndToolbarCombo; // Combo box in toolbar.
  198. INT m_cMaxComboEntries; // Max entries allowed in combo MRU.
  199. DetailsView& m_DetailsView; // Reference to associated details view.
  200. WNDPROC m_pfnOldToolbarComboWndProc; // Saved wnd proc address.
  201. VOID AddNameToCombo(HWND hwndCombo, LPCTSTR pszName, INT cMaxEntries);
  202. BOOL UserNameEntered(HWND hwndCombo);
  203. VOID FillDialogCombo(HWND hwndComboSrc, HWND hwndComboDest);
  204. //
  205. // Prevent copy.
  206. //
  207. Finder(const Finder& rhs);
  208. Finder& operator = (const Finder& rhs);
  209. };
  210. //
  211. // DetailsView::Importer ----------------------------------------------
  212. //
  213. class Importer
  214. {
  215. public:
  216. Importer(DetailsView& DV);
  217. ~Importer(VOID);
  218. HRESULT Import(IDataObject *pIDataObject);
  219. HRESULT Import(const FORMATETC& fmt, const STGMEDIUM& medium);
  220. HRESULT Import(LPCTSTR pszFilePath);
  221. HRESULT Import(HDROP hDrop);
  222. private:
  223. //
  224. // DetailsView::Importer::AnySource ---------------------------
  225. //
  226. // This small hierarchy of "Source" classes is here to insulate
  227. // the import process from the import source. There are two
  228. // basic forms of import source data; OLE stream and memory-
  229. // mapped file. So that we only have one function that actually
  230. // contains the import logic, this layer of abstraction insulates
  231. // that import function from any differences between streams
  232. // and simple memory blocks.
  233. // Instead of calling Import(pStream) or Import(pbBlock), a
  234. // client uses Import(Source(pIStream)) or Import(Source(pbBlock)).
  235. // The Source object uses the virtual constructor technique to
  236. // create the correct object for the input source. Each
  237. // descendant of AnySource implements the single Read() function
  238. // to read data from it's specific source.
  239. //
  240. class AnySource
  241. {
  242. public:
  243. AnySource(VOID) { }
  244. virtual ~AnySource(VOID) { }
  245. virtual HRESULT Read(LPVOID pvOut, ULONG cb, ULONG *pcbRead) = 0;
  246. private:
  247. //
  248. // Prevent copy.
  249. //
  250. AnySource(const AnySource& rhs);
  251. AnySource& operator = (const AnySource& rhs);
  252. };
  253. //
  254. // DetailsView::Importer::StreamSource ------------------------
  255. //
  256. class StreamSource : public AnySource
  257. {
  258. public:
  259. StreamSource(IStream *pStm);
  260. virtual ~StreamSource(VOID);
  261. virtual HRESULT Read(LPVOID pvOut, ULONG cb, ULONG *pcbRead);
  262. private:
  263. IStream *m_pStm;
  264. //
  265. // Prevent copy.
  266. //
  267. StreamSource(const StreamSource& rhs);
  268. StreamSource& operator = (const StreamSource& rhs);
  269. };
  270. //
  271. // DetailsView::Importer::MemorySource ------------------------
  272. //
  273. class MemorySource : public AnySource
  274. {
  275. public:
  276. MemorySource(LPBYTE pb, ULONG cbMax);
  277. virtual ~MemorySource(VOID) { };
  278. virtual HRESULT Read(LPVOID pvOut, ULONG cb, ULONG *pcbRead);
  279. private:
  280. LPBYTE m_pb;
  281. ULONG m_cbMax;
  282. //
  283. // Prevent copy.
  284. //
  285. MemorySource(const MemorySource& rhs);
  286. MemorySource& operator = (const MemorySource& rhs);
  287. };
  288. //
  289. // DetailsView::Importer::Source ------------------------------
  290. //
  291. class Source
  292. {
  293. public:
  294. Source(IStream *pStm);
  295. Source(LPBYTE pb, ULONG cbMax);
  296. virtual ~Source(VOID);
  297. virtual HRESULT Read(LPVOID pvOut, ULONG cb, ULONG *pcbRead);
  298. private:
  299. AnySource *m_pTheSource;
  300. //
  301. // Prevent copy.
  302. //
  303. Source(const Source& rhs);
  304. Source& operator = (const Source& rhs);
  305. };
  306. //
  307. // These two import functions are the real workers.
  308. // All other import functions eventually end up at
  309. // Import(Source& ) which calls Import(pbSid, Threshold, Limit)
  310. // to import each user record.
  311. //
  312. HRESULT Import(Source& source);
  313. HRESULT Import(LPBYTE pbSid, LONGLONG llQuotaThreshold,
  314. LONGLONG llQuotaLimit);
  315. VOID Destroy(VOID);
  316. HWND GetTopmostWindow(VOID);
  317. DetailsView& m_DV;
  318. BOOL m_bUserCancelled; // User cancelled import.
  319. BOOL m_bPromptOnReplace; // Prompt user when replacing record?
  320. ProgressDialog m_dlgProgress; // Progress dialog.
  321. HWND m_hwndParent; // Parent HWND for any UI elements.
  322. INT m_cImported; // Number of records imported.
  323. //
  324. // Prevent copy.
  325. //
  326. Importer(const Importer& rhs);
  327. Importer& operator = (const Importer& rhs);
  328. };
  329. //
  330. // DetailsView::DataObject --------------------------------------------
  331. //
  332. class DataObject
  333. {
  334. public:
  335. DataObject(DetailsView& DV);
  336. ~DataObject(VOID);
  337. HRESULT IsFormatSupported(FORMATETC *pFormatEtc);
  338. HRESULT RenderData(FORMATETC *pFormatEtc, STGMEDIUM *pMedium);
  339. static VOID SetFormatEtc(FORMATETC& fe,
  340. CLIPFORMAT cfFormat,
  341. DWORD tymed,
  342. DWORD dwAspect = DVASPECT_CONTENT,
  343. DVTARGETDEVICE *ptd = NULL,
  344. LONG lindex = -1);
  345. static LPSTR WideToAnsi(LPCWSTR pszTextW);
  346. static const INT CF_FORMATS_SUPPORTED;
  347. static LPCWSTR SZ_EXPORT_STREAM_NAME;
  348. static LPCTSTR SZ_EXPORT_CF_NAME;
  349. static const DWORD EXPORT_STREAM_VERSION;
  350. LPFORMATETC m_rgFormats; // Array of supported formats.
  351. DWORD m_cFormats; // Number of supported formats.
  352. static CLIPFORMAT m_CF_Csv; // Comma-separated fields format.
  353. static CLIPFORMAT m_CF_RichText; // RTF format.
  354. static CLIPFORMAT m_CF_NtDiskQuotaExport; // Internal fmt for import/export.
  355. static CLIPFORMAT m_CF_FileGroupDescriptor;// Used by shell for drop to folder.
  356. static CLIPFORMAT m_CF_FileContents; // Used by shell for drop to folder.
  357. private:
  358. //
  359. // DetailsView::DataObject::Renderer --------------------------
  360. //
  361. class Renderer
  362. {
  363. protected:
  364. //
  365. // DetailsView::DataObject::Renderer::Stream ----------
  366. //
  367. class Stream
  368. {
  369. private:
  370. IStream *m_pStm;
  371. #ifdef CLIPBOARD_DEBUG_OUTPUT
  372. IStorage *m_pStgDbgOut; // For debugging clipboard output.
  373. IStream *m_pStmDbgOut; // For debugging clipboard output.
  374. #endif // CLIPBOARD_DEBUG_OUTPUT
  375. //
  376. // Prevent copy.
  377. //
  378. Stream(const Stream& rhs);
  379. Stream& operator = (const Stream& rhs);
  380. public:
  381. Stream(IStream *pStm = NULL);
  382. ~Stream(VOID);
  383. VOID SetStream(IStream *pStm);
  384. IStream *GetStream(VOID)
  385. { return m_pStm; }
  386. VOID Write(LPBYTE pbData, UINT cbData);
  387. VOID Write(LPCSTR pszTextA);
  388. VOID Write(LPCWSTR pszTextW);
  389. VOID Write(BYTE bData);
  390. VOID Write(CHAR chDataA);
  391. VOID Write(WCHAR chDataW);
  392. VOID Write(DWORD dwData);
  393. VOID Write(double dblData);
  394. };
  395. DetailsView& m_DV; // Details view is source of data.
  396. Stream m_Stm; // Stream on which report is writtn.
  397. virtual VOID Begin(INT cRows, INT cCols) { }
  398. virtual VOID AddTitle(LPCWSTR pszTitleW) { }
  399. virtual VOID BeginHeaders(VOID) { }
  400. virtual VOID AddHeader(LPCWSTR pszHeaderW) { }
  401. virtual VOID AddHeaderSep(VOID) { }
  402. virtual VOID EndHeaders(VOID) { }
  403. virtual VOID BeginRow(VOID) { }
  404. virtual VOID AddRowColData(INT iRow, INT idCol) { }
  405. virtual VOID AddRowColSep(VOID) { }
  406. virtual VOID EndRow(VOID) { }
  407. virtual VOID End(VOID) { }
  408. //
  409. // Prevent copy.
  410. //
  411. Renderer(const Renderer& rhs);
  412. Renderer& operator = (const Renderer& rhs);
  413. public:
  414. Renderer(DetailsView& DV)
  415. : m_DV(DV) { }
  416. virtual ~Renderer(VOID) { }
  417. virtual VOID Render(IStream *pStm);
  418. };
  419. //
  420. // DetailsView::DataObject::Renderer_UNICODETEXT --------------
  421. //
  422. class Renderer_UNICODETEXT : public Renderer
  423. {
  424. private:
  425. //
  426. // Prevent copy.
  427. //
  428. Renderer_UNICODETEXT(const Renderer_UNICODETEXT& rhs);
  429. Renderer_UNICODETEXT& operator = (const Renderer_UNICODETEXT& rhs);
  430. protected:
  431. virtual VOID AddTitle(LPCWSTR pszTitleW);
  432. virtual VOID AddHeader(LPCWSTR pszHeaderW)
  433. { m_Stm.Write(pszHeaderW); }
  434. virtual VOID AddHeaderSep(VOID)
  435. { m_Stm.Write(L'\t'); }
  436. virtual VOID EndHeaders(VOID)
  437. { m_Stm.Write(L'\r'); m_Stm.Write(L'\n'); }
  438. virtual VOID AddRowColData(INT iRow, INT idCol);
  439. virtual VOID AddRowColSep(VOID)
  440. { m_Stm.Write(L'\t'); }
  441. virtual VOID EndRow(VOID)
  442. { m_Stm.Write(L'\r'); m_Stm.Write(L'\n'); }
  443. public:
  444. Renderer_UNICODETEXT(DetailsView& DV)
  445. : Renderer(DV) { }
  446. virtual ~Renderer_UNICODETEXT(VOID) { }
  447. };
  448. //
  449. // DetailsView::DataObject::Renderer_TEXT ---------------------
  450. //
  451. class Renderer_TEXT : public Renderer_UNICODETEXT
  452. {
  453. private:
  454. //
  455. // Prevent copy.
  456. //
  457. Renderer_TEXT(const Renderer_TEXT& rhs);
  458. Renderer_TEXT& operator = (const Renderer_TEXT& rhs);
  459. protected:
  460. virtual VOID AddTitle(LPCWSTR pszTitleW);
  461. virtual VOID AddHeader(LPCWSTR pszHeaderW);
  462. virtual VOID AddHeaderSep(VOID)
  463. { m_Stm.Write('\t'); }
  464. virtual VOID EndHeaders(VOID)
  465. { m_Stm.Write('\r'); m_Stm.Write('\n'); }
  466. virtual VOID AddRowColData(INT iRow, INT idCol);
  467. virtual VOID AddRowColSep(VOID)
  468. { m_Stm.Write('\t'); }
  469. virtual VOID EndRow(VOID)
  470. { m_Stm.Write('\r'); m_Stm.Write('\n'); }
  471. public:
  472. Renderer_TEXT(DetailsView& DV)
  473. : Renderer_UNICODETEXT(DV) { }
  474. virtual ~Renderer_TEXT(VOID) { }
  475. };
  476. //
  477. // DetailsView::DataObject::Renderer_Csv ----------------------
  478. //
  479. class Renderer_Csv : public Renderer_TEXT
  480. {
  481. private:
  482. //
  483. // Prevent copy.
  484. //
  485. Renderer_Csv(const Renderer_Csv& rhs);
  486. Renderer_Csv& operator = (const Renderer_Csv& rhs);
  487. protected:
  488. virtual VOID AddHeaderSep(VOID)
  489. { m_Stm.Write(','); }
  490. virtual VOID AddRowColSep(VOID)
  491. { m_Stm.Write(','); }
  492. public:
  493. Renderer_Csv(DetailsView& DV)
  494. : Renderer_TEXT(DV) { }
  495. virtual ~Renderer_Csv(VOID) { }
  496. };
  497. //
  498. // DetailsView::DataObject::Renderer_RTF ----------------------
  499. //
  500. class Renderer_RTF : public Renderer
  501. {
  502. private:
  503. INT m_cCols;
  504. LPSTR DoubleBackslashes(LPSTR pszText);
  505. //
  506. // Prevent copy.
  507. //
  508. Renderer_RTF(const Renderer_RTF& rhs);
  509. Renderer_RTF& operator = (const Renderer_RTF& rhs);
  510. protected:
  511. virtual VOID Begin(INT cRows, INT cCols);
  512. virtual VOID AddTitle(LPCWSTR pszTitleW);
  513. virtual VOID BeginHeaders(VOID);
  514. virtual VOID AddHeader(LPCWSTR pszHeaderW);
  515. virtual VOID AddHeaderSep(VOID)
  516. { AddRowColSep(); }
  517. virtual VOID EndHeaders(VOID)
  518. { m_Stm.Write("\\row "); }
  519. virtual VOID BeginRow(VOID)
  520. { BeginHeaderOrRow();
  521. AddCellDefs(); }
  522. virtual VOID AddRowColData(INT iRow, INT idCol);
  523. virtual VOID AddRowColSep(VOID)
  524. { m_Stm.Write("\\cell "); }
  525. virtual VOID EndRow(VOID)
  526. { m_Stm.Write("\\row "); }
  527. virtual VOID End(VOID)
  528. { m_Stm.Write(" \\pard \\widctlpar \\par }"); }
  529. virtual VOID BeginHeaderOrRow(VOID);
  530. virtual VOID AddCellDefs(VOID);
  531. public:
  532. Renderer_RTF(DetailsView& DV)
  533. : Renderer(DV),
  534. m_cCols(0) { }
  535. virtual ~Renderer_RTF(VOID) { }
  536. };
  537. //
  538. // DetailsView::DataObject::Renderer_Export -------------------
  539. //
  540. class Renderer_Export : public Renderer
  541. {
  542. private:
  543. //
  544. // Prevent copy.
  545. //
  546. Renderer_Export(const Renderer_Export& rhs);
  547. Renderer_Export& operator = (const Renderer_Export& rhs);
  548. protected:
  549. virtual VOID Render(IStream *pStm);
  550. virtual VOID Begin(INT cRows, INT cCols);
  551. virtual VOID AddBinaryRecord(INT iRow);
  552. virtual VOID End(VOID) { }
  553. public:
  554. Renderer_Export(DetailsView& DV)
  555. : Renderer(DV) { }
  556. virtual ~Renderer_Export(VOID) { }
  557. };
  558. //
  559. // DetailsView::DataObject::Renderer_FileGroupDescriptor ------
  560. //
  561. class Renderer_FileGroupDescriptor : public Renderer
  562. {
  563. private:
  564. //
  565. // Prevent copy.
  566. //
  567. Renderer_FileGroupDescriptor(const Renderer_FileGroupDescriptor& rhs);
  568. Renderer_FileGroupDescriptor& operator = (const Renderer_FileGroupDescriptor& rhs);
  569. protected:
  570. virtual VOID Begin(INT cRows, INT cCols);
  571. public:
  572. Renderer_FileGroupDescriptor(DetailsView& DV)
  573. : Renderer(DV) { }
  574. virtual ~Renderer_FileGroupDescriptor(VOID) { };
  575. };
  576. //
  577. // DetailsView::DataObject::Renderer_FileContents -------------
  578. //
  579. class Renderer_FileContents : public Renderer_Export
  580. {
  581. private:
  582. //
  583. // Prevent copy.
  584. //
  585. Renderer_FileContents(const Renderer_FileContents& rhs);
  586. Renderer_FileContents& operator = (const Renderer_FileContents& rhs);
  587. protected:
  588. public:
  589. Renderer_FileContents(DetailsView& DV)
  590. : Renderer_Export(DV) { }
  591. virtual ~Renderer_FileContents(VOID) { };
  592. };
  593. //
  594. // DetailsView::DataObject private member variables.
  595. //
  596. IStorage *m_pStg; // Storage pointer.
  597. IStream *m_pStm; // Stream pointer.
  598. DetailsView& m_DV;
  599. //
  600. // Private functions to help with the rendering process.
  601. //
  602. HRESULT CreateRenderStream(DWORD tymed, IStream **ppStm);
  603. HRESULT RenderData(IStream *pStm, CLIPFORMAT cf);
  604. //
  605. // Prevent copy.
  606. //
  607. DataObject(const DataObject& rhs);
  608. DataObject& operator = (const DataObject& rhs);
  609. };
  610. //
  611. // DetailsView::DropSource --------------------------------------------
  612. //
  613. class DropSource
  614. {
  615. public:
  616. DropSource(DWORD grfKeyState)
  617. : m_grfKeyState(grfKeyState) { }
  618. ~DropSource(VOID) { }
  619. DWORD m_grfKeyState; // "Key" used to start drag/drop.
  620. private:
  621. //
  622. // Prevent copying.
  623. //
  624. DropSource(const DropSource&);
  625. void operator = (const DropSource&);
  626. };
  627. //
  628. // DetailsView::DropTarget --------------------------------------------
  629. //
  630. class DropTarget
  631. {
  632. public:
  633. DropTarget(DWORD grfKeyState)
  634. : m_grfKeyState(grfKeyState),
  635. m_pIDataObject(NULL) { }
  636. ~DropTarget(VOID) { };
  637. DWORD m_grfKeyState; // "Key" used to start drag/drop.
  638. IDataObject *m_pIDataObject; // Ptr received through DragEnter.
  639. private:
  640. //
  641. // Prevent copying.
  642. //
  643. DropTarget(const DropTarget&);
  644. void operator = (const DropTarget&);
  645. };
  646. LONG m_cRef;
  647. PointerList m_UserList; // List of user objects.
  648. HWND m_hwndMain; // Main window.
  649. HWND m_hwndListView; // Listview window.
  650. HWND m_hwndStatusBar; // Status bar.
  651. HWND m_hwndToolBar; // Tool bar.
  652. HWND m_hwndToolbarCombo; // "Find User" combo box.
  653. HWND m_hwndListViewToolTip; // Tool tip window.
  654. HWND m_hwndHeader; // Listview header control.
  655. HACCEL m_hKbdAccel; // Accelerator table.
  656. WNDPROC m_lpfnLVWndProc; // We subclass the LV control.
  657. PDISKQUOTA_CONTROL m_pQuotaControl; // Ptr to quota controller.
  658. Finder *m_pUserFinder; // For locating users in listview.
  659. UndoList *m_pUndoList; // For "undoing" mods and deletes.
  660. ColumnMap m_ColMap; // ColId to iSubItem map.
  661. DropSource m_DropSource;
  662. DropTarget m_DropTarget;
  663. DataObject *m_pDataObject;
  664. CVolumeID m_idVolume;
  665. CString m_strVolumeDisplayName;
  666. CString m_strAccountUnresolved;
  667. CString m_strAccountUnavailable;
  668. CString m_strAccountDeleted;
  669. CString m_strAccountUnknown;
  670. CString m_strAccountInvalid;
  671. CString m_strNoLimit;
  672. CString m_strNotApplicable;
  673. CString m_strStatusOK;
  674. CString m_strStatusWarning;
  675. CString m_strStatusOverlimit;
  676. CString m_strDispText;
  677. LPDATAOBJECT m_pIDataObjectOnClipboard;
  678. POINT m_ptMouse; // For hit-testing tooltips.
  679. DWORD m_dwEventCookie; // Event sink cookie.
  680. INT m_iLastItemHit; // Last item mouse was over.
  681. INT m_iLastColSorted;
  682. DWORD m_fSortDirection; // 0 = Ascending, 1 = Descending
  683. CRITICAL_SECTION m_csAsyncUpdate;
  684. LV_STATE_INFO m_lvsi; // Persistent lv state info.
  685. BOOL m_bMenuActive; // Is a menu active?
  686. BOOL m_bWaitCursor; // Show wait cursor?
  687. BOOL m_bStopLoadingObjects;
  688. BOOL m_bDestroyingView;
  689. static const INT MAX_FINDMRU_ENTRIES;
  690. static const INT CX_TOOLBAR_COMBO;
  691. static const INT CY_TOOLBAR_COMBO;
  692. HRESULT InitializeStaticStrings(VOID);
  693. HRESULT CreateMainWindow(VOID);
  694. HRESULT CreateListView(VOID);
  695. HRESULT CreateStatusBar(VOID);
  696. HRESULT CreateToolBar(VOID);
  697. HRESULT CreateListViewToolTip(VOID);
  698. HRESULT AddColumn(INT iColumn, const DV_COLDATA& ColDes);
  699. HRESULT RemoveColumn(INT iColumn);
  700. HRESULT AddImages(VOID);
  701. HRESULT LoadObjects(VOID);
  702. HRESULT ReleaseObjects(VOID);
  703. LRESULT SortObjects(DWORD idColumn, DWORD dwDirection);
  704. LRESULT Refresh(bool bInvalidateCache = false);
  705. LRESULT SelectAllItems(VOID);
  706. LRESULT InvertSelectedItems(VOID);
  707. LRESULT ShowItemCountInStatusBar(VOID);
  708. LRESULT ShowMenuTextInStatusBar(DWORD idMenuOption);
  709. VOID SaveViewStateToRegistry(VOID);
  710. VOID EnableMenuItem_ArrangeByFolder(BOOL bEnable);
  711. VOID EnableMenuItem_Undo(BOOL bEnable);
  712. VOID SetWaitCursor(VOID);
  713. VOID ClearWaitCursor(VOID);
  714. VOID Redraw(VOID)
  715. {
  716. RedrawWindow(m_hwndMain, NULL, NULL,
  717. RDW_ERASE |
  718. RDW_FRAME |
  719. RDW_INVALIDATE |
  720. RDW_ALLCHILDREN |
  721. RDW_UPDATENOW);
  722. }
  723. VOID RedrawItems(VOID)
  724. {
  725. ListView_RedrawItems(m_hwndListView, -1, -1);
  726. UpdateWindow(m_hwndListView);
  727. }
  728. BOOL AddUser(PDISKQUOTA_USER pUser);
  729. INT GetUserQuotaState(PDISKQUOTA_USER pUser);
  730. VOID RegisterAsDropTarget(BOOL bActive);
  731. bool SingleSelectionIsAdmin(void);
  732. //
  733. // Message handlers.
  734. //
  735. LRESULT OnNotify(HWND, UINT, WPARAM, LPARAM);
  736. LRESULT OnSize(HWND, UINT, WPARAM, LPARAM);
  737. LRESULT OnSetCursor(HWND, UINT, WPARAM, LPARAM);
  738. LRESULT OnSetFocus(HWND, UINT, WPARAM, LPARAM);
  739. LRESULT OnDestroy(HWND, UINT, WPARAM, LPARAM);
  740. LRESULT OnMainWindowCreated(HWND, UINT, WPARAM, LPARAM);
  741. LRESULT OnCommand(HWND, UINT, WPARAM, LPARAM);
  742. LRESULT OnCmdViewStatusBar(VOID);
  743. LRESULT OnCmdViewToolBar(VOID);
  744. LRESULT OnCmdViewShowFolder(VOID);
  745. LRESULT OnCmdProperties(VOID);
  746. LRESULT OnCmdNew(VOID);
  747. LRESULT OnCmdDelete(VOID);
  748. LRESULT OnCmdUndo(VOID);
  749. LRESULT OnCmdFind(VOID);
  750. LRESULT OnCmdEditCopy(VOID);
  751. LRESULT OnCmdImport(VOID);
  752. LRESULT OnCmdExport(VOID);
  753. LRESULT OnMenuSelect(HWND, UINT, WPARAM, LPARAM);
  754. LRESULT OnContextMenu(HWND, UINT, WPARAM, LPARAM);
  755. LRESULT OnHelpAbout(HWND);
  756. LRESULT OnHelpTopics(HWND);
  757. LRESULT OnSettingChange(HWND, UINT, WPARAM, LPARAM);
  758. LRESULT OnLVN_OwnerDataFindItem(NMLVFINDITEM *);
  759. LRESULT OnLVN_GetDispInfo(LV_DISPINFO *);
  760. LRESULT OnLVN_GetDispInfo_Text(LV_DISPINFO *, PDISKQUOTA_USER);
  761. LRESULT OnLVN_GetDispInfo_Image(LV_DISPINFO *, PDISKQUOTA_USER);
  762. LRESULT OnLVN_ColumnClick(NM_LISTVIEW *);
  763. LRESULT OnLVN_ItemChanged(NM_LISTVIEW *);
  764. LRESULT OnLVN_BeginDrag(NM_LISTVIEW *);
  765. LRESULT OnTTN_NeedText(TOOLTIPTEXT *);
  766. LRESULT LV_OnTTN_NeedText(TOOLTIPTEXT *);
  767. LRESULT LV_OnMouseMessages(HWND, UINT, WPARAM, LPARAM);
  768. BOOL HitTestHeader(int xPos, int yPos);
  769. INT_PTR ActivateListViewToolTip(BOOL bActivate)
  770. { return SendMessage(m_hwndListViewToolTip, TTM_ACTIVATE, (WPARAM)bActivate, 0); }
  771. VOID FocusOnSomething(VOID);
  772. VOID CleanupAfterAbnormalTermination(VOID);
  773. INT FindUserByName(LPCTSTR pszUserName, PDISKQUOTA_USER *ppIUser = NULL);
  774. INT FindUserBySid(LPBYTE pbUserSid, PDISKQUOTA_USER *ppIUser = NULL);
  775. INT FindUserByObjPtr(PDISKQUOTA_USER pIUser);
  776. BOOL GotoUserName(LPCTSTR pszUser);
  777. //
  778. // Connection point stuff.
  779. //
  780. HRESULT ConnectEventSink(VOID);
  781. HRESULT DisconnectEventSink(VOID);
  782. IConnectionPoint *GetConnectionPoint(VOID);
  783. static DWORD ThreadProc(LPVOID);
  784. static INT CompareItems(LPVOID, LPVOID, LPARAM);
  785. static HRESULT CalcPctQuotaUsed(PDISKQUOTA_USER, LPDWORD);
  786. static LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
  787. static LRESULT CALLBACK LVSubClassWndProc(HWND, UINT, WPARAM, LPARAM);
  788. //
  789. // Prevent copying.
  790. //
  791. DetailsView(const DetailsView&);
  792. void operator = (const DetailsView&);
  793. public:
  794. DetailsView(VOID);
  795. ~DetailsView(VOID);
  796. BOOL Initialize(
  797. const CVolumeID& idVolume);
  798. CVolumeID GetVolumeID(void) const
  799. { return m_idVolume; }
  800. //
  801. // This is public so other UI elements can use it. (i.e. VolPropPage).
  802. //
  803. static HRESULT CreateVolumeDisplayName(
  804. const CVolumeID& idVolume, // [in] - "C:\" or "\\?\Volume{ <guid> }\"
  805. CString *pstrDisplayName); // [out] - "My Disk (C:)"
  806. //
  807. // If you change the value of idCol_Last, see the note with
  808. // the LV_STATE_INFO structure above regarding the rgcxCol[] member
  809. // of LV_STATE_INFO.
  810. //
  811. enum ColumnIDs { idCol_Status,
  812. idCol_Folder,
  813. idCol_Name,
  814. idCol_LogonName,
  815. idCol_AmtUsed,
  816. idCol_Limit,
  817. idCol_Threshold,
  818. idCol_PctUsed,
  819. idCol_Last };
  820. //
  821. // IUnknown methods.
  822. //
  823. STDMETHODIMP
  824. QueryInterface(
  825. REFIID riid,
  826. LPVOID *ppv);
  827. STDMETHODIMP_(ULONG)
  828. AddRef(
  829. VOID);
  830. STDMETHODIMP_(ULONG)
  831. Release(
  832. VOID);
  833. //
  834. // IDiskQuotaEvents method.
  835. //
  836. STDMETHODIMP
  837. OnUserNameChanged(
  838. PDISKQUOTA_USER pUser);
  839. //
  840. // IDropSource methods.
  841. //
  842. STDMETHODIMP
  843. GiveFeedback(
  844. DWORD dwEffect);
  845. STDMETHODIMP
  846. QueryContinueDrag(
  847. BOOL fEscapePressed,
  848. DWORD grfKeyState);
  849. //
  850. // IDropTarget methods.
  851. //
  852. STDMETHODIMP DragEnter(
  853. IDataObject * pDataObject,
  854. DWORD grfKeyState,
  855. POINTL pt,
  856. DWORD * pdwEffect);
  857. STDMETHODIMP DragOver(
  858. DWORD grfKeyState,
  859. POINTL pt,
  860. DWORD * pdwEffect);
  861. STDMETHODIMP DragLeave(
  862. VOID);
  863. STDMETHODIMP Drop(
  864. IDataObject * pDataObject,
  865. DWORD grfKeyState,
  866. POINTL pt,
  867. DWORD * pdwEffect);
  868. //
  869. // IDataObject methods.
  870. //
  871. STDMETHODIMP
  872. GetData(
  873. FORMATETC *pFormatetc,
  874. STGMEDIUM *pmedium);
  875. STDMETHODIMP
  876. GetDataHere(
  877. FORMATETC *pFormatetc,
  878. STGMEDIUM *pmedium);
  879. STDMETHODIMP
  880. QueryGetData(
  881. FORMATETC *pFormatetc);
  882. STDMETHODIMP
  883. GetCanonicalFormatEtc(
  884. FORMATETC *pFormatetcIn,
  885. FORMATETC *pFormatetcOut);
  886. STDMETHODIMP
  887. SetData(
  888. FORMATETC *pFormatetc,
  889. STGMEDIUM *pmedium,
  890. BOOL fRelease);
  891. STDMETHODIMP
  892. EnumFormatEtc(
  893. DWORD dwDirection,
  894. IEnumFORMATETC **ppenumFormatetc);
  895. STDMETHODIMP
  896. DAdvise(
  897. FORMATETC *pFormatetc,
  898. DWORD advf,
  899. IAdviseSink *pAdvSink,
  900. DWORD *pdwConnection);
  901. STDMETHODIMP
  902. DUnadvise(
  903. DWORD dwConnection);
  904. STDMETHODIMP
  905. EnumDAdvise(
  906. IEnumSTATDATA **ppenumAdvise);
  907. HWND GetHWndMain(VOID)
  908. { return m_hwndMain; }
  909. static VOID InitLVStateInfo(PLV_STATE_INFO plvsi);
  910. static BOOL IsValidLVStateInfo(PLV_STATE_INFO plvsi);
  911. void GetVolumeDisplayName(CString *pstrName)
  912. { *pstrName = m_strVolumeDisplayName; }
  913. UINT GetColumnIds(INT *prgColIds, INT cColIds);
  914. //
  915. // Methods for getting drag-drop report data from details view.
  916. //
  917. INT GetNextSelectedItemIndex(INT iRow);
  918. BOOL GetReportItem(UINT iRow, UINT iColId, PLV_REPORT_ITEM pItem);
  919. VOID GetReportTitle(LPTSTR pszDest, UINT cchDest);
  920. VOID GetReportColHeader(UINT iColId, LPTSTR pszDest, UINT cchDest);
  921. UINT GetReportColCount(VOID);
  922. UINT GetReportRowCount(VOID);
  923. //
  924. // These methods are for generating binary "reports" used in exporting
  925. // user quota information for transfer between volumes.
  926. //
  927. UINT GetReportBinaryRecordSize(UINT iRow);
  928. BOOL GetReportBinaryRecord(UINT iRow, LPBYTE pbRecord, UINT cbRecord);
  929. //
  930. // NOTE: If the requirement for friendship between DetailsView and
  931. // DetailsView::Finder exceeds only a few instances, we
  932. // might as well grant total friendship to the Finder class.
  933. // As long as the instance count is small, I like to keep
  934. // the friendship restricted as much as possible.
  935. //
  936. // This Finder::DlgProc needs to call DetailsView::GotoUserName.
  937. //
  938. friend BOOL Finder::UserNameEntered(HWND);
  939. //
  940. // Finder::DlgProc needs access to Details::CY_TOOLBAR_COMBO.
  941. //
  942. friend INT_PTR CALLBACK Finder::DlgProc(HWND, UINT, WPARAM, LPARAM);
  943. friend class Importer;
  944. };
  945. //
  946. // Represents a selection in the listview.
  947. // Objects of this type are used for communicating a selection set to
  948. // a function. The recpient of the LVSelection object can query it
  949. // to obtain information about the selection.
  950. //
  951. class LVSelection
  952. {
  953. private:
  954. HWND m_hwndListView;
  955. struct ListEntry
  956. {
  957. PDISKQUOTA_USER pUser;
  958. INT iItem;
  959. };
  960. StructureList m_List;
  961. //
  962. // Prevent copying.
  963. //
  964. LVSelection(const LVSelection&);
  965. void operator = (const LVSelection&);
  966. public:
  967. LVSelection(HWND hwndListView)
  968. : m_hwndListView(hwndListView),
  969. m_List(sizeof(ListEntry), 10) { }
  970. LVSelection(VOID)
  971. : m_hwndListView(NULL),
  972. m_List(sizeof(ListEntry), 1) { }
  973. ~LVSelection(VOID) { }
  974. VOID Add(PDISKQUOTA_USER pUser, INT iItem);
  975. HWND GetListViewHwnd(VOID)
  976. { return m_hwndListView; }
  977. INT Count(VOID)
  978. { return m_List.Count(); }
  979. BOOL Retrieve(INT i, PDISKQUOTA_USER *ppUser, INT *piItem);
  980. BOOL Retrieve(INT i, PDISKQUOTA_USER *ppUser)
  981. { return Retrieve(i, ppUser, NULL); }
  982. BOOL Retrieve(INT i, INT *pItem)
  983. { return Retrieve(i, NULL, pItem); }
  984. VOID Clear(VOID)
  985. { m_List.Clear(); }
  986. };
  987. #endif // _INC_DSKQUOTA_DETAILS_H