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.

370 lines
11 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. /* File: undo.cpp
  3. Description: Definitions for classes associated with the "undo" feature.
  4. A client first creates an UndoList object. Whenever an "undoable"
  5. action is performed in the quota UI (modification/deletion), an
  6. undo action object is created and added to the UndoList object.
  7. Each type of undo action object knows what is has to do to reverse
  8. the effects of the original operation. When the client wants to
  9. reverse the effects of all operations on the undo list, it merely
  10. commands the UndoList object to "Undo". To clear the undo list,
  11. a client calls UndoList::Clear().
  12. Revision History:
  13. Date Description Programmer
  14. -------- --------------------------------------------------- ----------
  15. 09/30/96 Initial creation. BrianAu
  16. */
  17. ///////////////////////////////////////////////////////////////////////////////
  18. #include "pch.h" // PCH
  19. #pragma hdrstop
  20. #include "undo.h"
  21. ///////////////////////////////////////////////////////////////////////////////
  22. /* Function: UndoAction::UndoAction
  23. Function: UndoAction::~UndoAction
  24. Description: Constructor and Destructor
  25. Arguments:
  26. pUser - Address of IDiskQuotaUser interface for user associated
  27. with this undo action.
  28. llThreshold - Quota threshold value to be restored if action is
  29. undone.
  30. llLimit - Quota limit value to be restored if action is undone.
  31. Returns: Nothing.
  32. Revision History:
  33. Date Description Programmer
  34. -------- --------------------------------------------------- ----------
  35. 09/30/96 Initial creation. BrianAu
  36. */
  37. ///////////////////////////////////////////////////////////////////////////////
  38. UndoAction::UndoAction(
  39. PDISKQUOTA_USER pUser,
  40. LONGLONG llThreshold,
  41. LONGLONG llLimit,
  42. PDISKQUOTA_CONTROL pQuotaControl
  43. ) : m_pUser(pUser),
  44. m_pUndoList(NULL),
  45. m_pQuotaControl(pQuotaControl)
  46. {
  47. DBGTRACE((DM_UNDO, DL_HIGH, TEXT("UndoAction::UndoAction")));
  48. DBGPRINT((DM_UNDO, DL_HIGH, TEXT("\tthis = 0x%08X"), this));
  49. DBGASSERT((NULL != m_pUser));
  50. m_llThreshold = llThreshold;
  51. m_llLimit = llLimit;
  52. }
  53. UndoAction::~UndoAction(
  54. VOID
  55. )
  56. {
  57. DBGTRACE((DM_UNDO, DL_HIGH, TEXT("UndoAction::~UndoAction")));
  58. DBGPRINT((DM_UNDO, DL_HIGH, TEXT("\tthis = 0x%08X"), this));
  59. if (NULL != m_pUser)
  60. m_pUser->Release(); // Release from Undo list.
  61. if (NULL != m_pQuotaControl)
  62. m_pQuotaControl->Release();
  63. }
  64. ///////////////////////////////////////////////////////////////////////////////
  65. /* Function: UndoList::~UndoList
  66. Description: Destructor. Destroys all undo action objects in the
  67. undo list object.
  68. Arguments: None.
  69. Returns: Nothing.
  70. Revision History:
  71. Date Description Programmer
  72. -------- --------------------------------------------------- ----------
  73. 09/30/96 Initial creation. BrianAu
  74. */
  75. ///////////////////////////////////////////////////////////////////////////////
  76. UndoList::~UndoList(
  77. VOID
  78. )
  79. {
  80. Clear();
  81. }
  82. ///////////////////////////////////////////////////////////////////////////////
  83. /* Function: UndoList::Clears
  84. Description: Destroys all undo action objects in the
  85. undo list object.
  86. Arguments: None.
  87. Returns: Nothing.
  88. Revision History:
  89. Date Description Programmer
  90. -------- --------------------------------------------------- ----------
  91. 09/30/96 Initial creation. BrianAu
  92. */
  93. ///////////////////////////////////////////////////////////////////////////////
  94. VOID UndoList::Clear(
  95. VOID
  96. )
  97. {
  98. UndoAction *pAction = NULL;
  99. DBGPRINT((DM_UNDO, DL_MID, TEXT("UNDO - Cleared undo list")));
  100. m_hList.Lock();
  101. while(m_hList.RemoveFirst((LPVOID *)&pAction))
  102. {
  103. DBGASSERT((NULL != pAction));
  104. delete pAction;
  105. }
  106. m_hList.ReleaseLock();
  107. }
  108. ///////////////////////////////////////////////////////////////////////////////
  109. /* Function: UndoList::Undo
  110. Description: Iterates through all undo action objects and commands each
  111. to perform it's undo action. Once the action is performed, the
  112. undo action object is destroyed.
  113. Arguments: None.
  114. Returns: Nothing.
  115. Revision History:
  116. Date Description Programmer
  117. -------- --------------------------------------------------- ----------
  118. 09/30/96 Initial creation. BrianAu
  119. */
  120. ///////////////////////////////////////////////////////////////////////////////
  121. VOID UndoList::Undo(
  122. VOID
  123. )
  124. {
  125. UndoAction *pAction = NULL;
  126. DBGPRINT((DM_UNDO, DL_MID, TEXT("UNDO - Undoing undo list")));
  127. //
  128. // Disable redraw on the listview so that we only update once.
  129. //
  130. CAutoSetRedraw autoredraw(m_hwndListView, false);
  131. m_hList.Lock();
  132. while(m_hList.RemoveFirst((LPVOID *)&pAction))
  133. {
  134. DBGASSERT((NULL != pAction));
  135. pAction->Undo();
  136. delete pAction;
  137. }
  138. m_hList.ReleaseLock();
  139. InvalidateRect(m_hwndListView, NULL, FALSE);
  140. }
  141. ///////////////////////////////////////////////////////////////////////////////
  142. /* Function: UndoDelete::Undo
  143. Description: Reverses the deletion of a user quota record.
  144. Arguments: None.
  145. Returns: Nothing.
  146. Revision History:
  147. Date Description Programmer
  148. -------- --------------------------------------------------- ----------
  149. 09/30/96 Initial creation. BrianAu
  150. */
  151. ///////////////////////////////////////////////////////////////////////////////
  152. HRESULT
  153. UndoDelete::Undo(
  154. VOID
  155. )
  156. {
  157. DBGPRINT((DM_UNDO, DL_MID, TEXT("UNDO - Undoing deletion")));
  158. HRESULT hResult = NO_ERROR;
  159. //
  160. // Just restore the quota settings.
  161. //
  162. hResult = m_pUser->SetQuotaLimit(m_llLimit, TRUE);
  163. hResult = m_pUser->SetQuotaThreshold(m_llThreshold, TRUE);
  164. if (SUCCEEDED(hResult))
  165. {
  166. //
  167. // Add the entry back into the listview.
  168. //
  169. HWND hwndListView = m_pUndoList->GetListViewHwnd();
  170. PointerList *pUserList = m_pUndoList->GetUserList();
  171. LV_ITEM item;
  172. item.mask = LVIF_TEXT | LVIF_STATE | LVIF_IMAGE;
  173. item.state = 0;
  174. item.stateMask = 0;
  175. item.iSubItem = 0;
  176. item.pszText = LPSTR_TEXTCALLBACK;
  177. item.iImage = I_IMAGECALLBACK;
  178. item.iItem = 0;
  179. pUserList->Insert((LPVOID)m_pUser);
  180. if (-1 != ListView_InsertItem(hwndListView, &item))
  181. {
  182. m_pUser->AddRef();
  183. }
  184. else
  185. hResult = E_FAIL;
  186. }
  187. return hResult;
  188. }
  189. ///////////////////////////////////////////////////////////////////////////////
  190. /* Function: UndoAdd::Undo
  191. Description: Reverses the addition of a user quota record by marking it
  192. for deletion.
  193. Arguments: None.
  194. Returns: Nothing.
  195. Revision History:
  196. Date Description Programmer
  197. -------- --------------------------------------------------- ----------
  198. 05/27/97 Initial creation. BrianAu
  199. */
  200. ///////////////////////////////////////////////////////////////////////////////
  201. HRESULT
  202. UndoAdd::Undo(
  203. VOID
  204. )
  205. {
  206. DBGPRINT((DM_UNDO, DL_MID, TEXT("UNDO - Undoing addition")));
  207. DBGASSERT((NULL != m_pQuotaControl));
  208. DBGASSERT((NULL != m_pUser));
  209. HRESULT hResult = m_pQuotaControl->DeleteUser(m_pUser);
  210. if (SUCCEEDED(hResult))
  211. {
  212. INT iItem;
  213. LV_FINDINFO fi;
  214. HWND hwndListView = m_pUndoList->GetListViewHwnd();
  215. PointerList *pUserList = m_pUndoList->GetUserList();
  216. fi.flags = LVFI_PARAM;
  217. fi.lParam = (LPARAM)m_pUser;
  218. iItem = ListView_FindItem(hwndListView, -1, &fi);
  219. if (-1 != iItem)
  220. {
  221. PDISKQUOTA_USER pIUserToDelete = NULL;
  222. //
  223. // Delete the entry from the list view.
  224. //
  225. ListView_DeleteItem(hwndListView, iItem);
  226. //
  227. // Delete the entry from the user list.
  228. //
  229. pUserList->Remove((LPVOID *)&pIUserToDelete, iItem);
  230. pIUserToDelete->Release(); // Release from listview.
  231. }
  232. else
  233. {
  234. DBGERROR((TEXT("UndoAdd::Undo - Didn't find user in listview.")));
  235. }
  236. }
  237. else
  238. {
  239. DBGERROR((TEXT("UndoAdd::Undo - Error 0x%08X deleting user 0x%08X"),
  240. hResult, m_pUser));
  241. }
  242. return hResult;
  243. }
  244. ///////////////////////////////////////////////////////////////////////////////
  245. /* Function: UndoModify::Undo
  246. Description: Reverses the modification of a user quota record.
  247. Arguments: None.
  248. Returns: Nothing.
  249. Revision History:
  250. Date Description Programmer
  251. -------- --------------------------------------------------- ----------
  252. 09/30/96 Initial creation. BrianAu
  253. */
  254. ///////////////////////////////////////////////////////////////////////////////
  255. HRESULT
  256. UndoModify::Undo(
  257. VOID
  258. )
  259. {
  260. DBGPRINT((DM_UNDO, DL_MID, TEXT("UNDO - Undoing modification")));
  261. HRESULT hResult = NO_ERROR;
  262. //
  263. // Restore the user's quota settings.
  264. //
  265. hResult = m_pUser->SetQuotaLimit(m_llLimit, TRUE);
  266. hResult = m_pUser->SetQuotaThreshold(m_llThreshold, TRUE);
  267. if (SUCCEEDED(hResult))
  268. {
  269. //
  270. // Locate the corresponding listview item and update it.
  271. //
  272. HWND hwndListView = m_pUndoList->GetListViewHwnd();
  273. PointerList *pUserList = m_pUndoList->GetUserList();
  274. DBGASSERT((NULL != hwndListView));
  275. INT iItem = -1;
  276. if (pUserList->FindIndex((LPVOID)m_pUser, &iItem))
  277. ListView_Update(hwndListView, iItem);
  278. else
  279. hResult = E_FAIL;
  280. }
  281. return hResult;
  282. }