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.

265 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1990-1998, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. tlog.cpp
  5. Abstract:
  6. This module implements the travel log functionality for file open
  7. and save as dialogs.
  8. Revision History:
  9. 02-20-98 arulk created
  10. --*/
  11. // precompiled headers
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. #include "util.h"
  15. #include "d32tlog.h"
  16. //-------------------------------------------------------------------------
  17. // Travel Log Link implementation
  18. //-------------------------------------------------------------------------
  19. TLogLink::TLogLink()
  20. :_cRef(1), _pidl(NULL), _ptllNext(NULL), _ptllPrev(NULL)
  21. {
  22. }
  23. TLogLink::TLogLink(LPITEMIDLIST pidl)
  24. :_cRef(1), _pidl(NULL), _ptllNext(NULL), _ptllPrev(NULL)
  25. {
  26. _pidl = ILClone(pidl);
  27. }
  28. TLogLink::~TLogLink()
  29. {
  30. if (_pidl)
  31. {
  32. ILFree(_pidl);
  33. }
  34. if (_ptllNext)
  35. {
  36. _ptllNext->Release();
  37. }
  38. }
  39. UINT TLogLink::AddRef()
  40. {
  41. return ++_cRef;
  42. }
  43. UINT TLogLink::Release()
  44. {
  45. if (--_cRef > 0)
  46. {
  47. return _cRef;
  48. }
  49. delete this;
  50. return 0;
  51. }
  52. void TLogLink::SetNextLink(TLogLink* ptllNext)
  53. {
  54. //Do we already have Next Link ?
  55. if (_ptllNext)
  56. {
  57. // Release the next link
  58. _ptllNext->Release();
  59. }
  60. //Set the given pointer as our next pointer
  61. _ptllNext = ptllNext;
  62. if (_ptllNext)
  63. {
  64. //Since we are caching the pointer , Add reference to it
  65. _ptllNext->AddRef();
  66. //Also update the prev link of our new pointer to point to us
  67. _ptllNext->_ptllPrev = this;
  68. }
  69. }
  70. HRESULT TLogLink::GetPidl(LPITEMIDLIST* ppidl)
  71. {
  72. *ppidl = ILClone(_pidl);
  73. if (*ppidl)
  74. return NOERROR;
  75. else {
  76. return E_OUTOFMEMORY;
  77. }
  78. }
  79. HRESULT TLogLink::SetPidl(LPITEMIDLIST pidl)
  80. {
  81. if (_pidl)
  82. {
  83. ILFree(_pidl);
  84. }
  85. _pidl = ILClone(pidl);
  86. return NOERROR;
  87. }
  88. BOOL TLogLink::CanTravel(int iDir)
  89. {
  90. BOOL fRet = FALSE;
  91. switch ( iDir )
  92. {
  93. case ( TRAVEL_BACK ) :
  94. {
  95. if (_ptllPrev != NULL)
  96. {
  97. fRet = TRUE;
  98. }
  99. break;
  100. }
  101. case ( TRAVEL_FORWARD ) :
  102. {
  103. if (_ptllNext !=NULL)
  104. {
  105. fRet = TRUE;
  106. }
  107. break;
  108. }
  109. }
  110. return fRet;
  111. }
  112. //----------------------------------------------------------------------------------
  113. //Travel Log Class Implementation
  114. //----------------------------------------------------------------------------------
  115. TravelLog::TravelLog()
  116. :_cRef(1),_ptllCurrent(NULL), _ptllRoot(NULL)
  117. {
  118. }
  119. TravelLog::~TravelLog()
  120. {
  121. if (_ptllRoot)
  122. {
  123. _ptllRoot->Release();
  124. }
  125. }
  126. UINT TravelLog::AddRef()
  127. {
  128. return ++_cRef;
  129. }
  130. UINT TravelLog::Release()
  131. {
  132. if (--_cRef > 0 )
  133. return _cRef;
  134. delete this;
  135. return 0;
  136. }
  137. HRESULT TravelLog::AddEntry(LPITEMIDLIST pidl)
  138. {
  139. TLogLink *ptll = new TLogLink(pidl);
  140. if (!ptll)
  141. return E_FAIL;
  142. if (_ptllCurrent) {
  143. _ptllCurrent->SetNextLink(ptll);
  144. ptll->Release();
  145. }
  146. else
  147. {
  148. _ptllRoot = ptll;
  149. }
  150. _ptllCurrent = ptll;
  151. return NOERROR;
  152. }
  153. BOOL TravelLog::CanTravel(int iDir)
  154. {
  155. if (_ptllCurrent)
  156. {
  157. return _ptllCurrent->CanTravel(iDir);
  158. }
  159. return FALSE;
  160. }
  161. HRESULT TravelLog::Travel(int iDir)
  162. {
  163. HRESULT hres = E_FAIL;
  164. TLogLink *ptll;
  165. switch(iDir)
  166. {
  167. case ( TRAVEL_FORWARD ) :
  168. {
  169. if (CanTravel(iDir))
  170. {
  171. ptll = _ptllCurrent->GetNextLink();
  172. _ptllCurrent = ptll;
  173. hres = NOERROR;
  174. }
  175. break;
  176. }
  177. case ( TRAVEL_BACK ):
  178. {
  179. if (CanTravel(iDir))
  180. {
  181. ptll = _ptllCurrent->GetPrevLink();
  182. _ptllCurrent = ptll;
  183. hres = NOERROR;
  184. }
  185. break;
  186. }
  187. }
  188. return hres;
  189. }
  190. HRESULT TravelLog::GetCurrent(LPITEMIDLIST *ppidl)
  191. {
  192. //Set the return value. Just in case
  193. *ppidl = NULL;
  194. if (_ptllCurrent)
  195. {
  196. return _ptllCurrent->GetPidl(ppidl);
  197. }
  198. return E_FAIL;
  199. }
  200. HRESULT Create_TravelLog(TravelLog **pptlog)
  201. {
  202. HRESULT hres = E_FAIL;
  203. *pptlog = new TravelLog();
  204. if (*pptlog)
  205. {
  206. hres = S_OK;
  207. }
  208. return hres;
  209. }