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.

318 lines
8.6 KiB

  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // SInfo.c
  4. //
  5. // Summary Information API implementation
  6. //
  7. // Notes:
  8. // To make this file useful for OLE objects, define OLE_PROPS.
  9. //
  10. // The macro lpDocObj must be used for all methods to access the
  11. // object data to ensure that this will compile with OLE_PROPS defined.
  12. // The macro lpData must also be used for all access to the m_lpData
  13. // member of the object. These macros only work when the LPSIOBJ
  14. // parameter is named lpSIObj!
  15. //
  16. // All strings stored in objects are in the format described in proptype.h
  17. //
  18. // Change history:
  19. //
  20. // Date Who What
  21. // --------------------------------------------------------------------------
  22. // 06/03/94 B. Wentz Created file
  23. // 06/08/94 B. Wentz Updated to new string format
  24. // 06/25/94 B. Wentz Updated to lean & mean API
  25. // 07/20/94 M. Jansson Updated include statemes, due to changes in PDK
  26. //
  27. ////////////////////////////////////////////////////////////////////////////////
  28. #include "priv.h"
  29. #pragma hdrstop
  30. #include "reg.h"
  31. #ifndef _ABBREVIATED_DOCPROP_
  32. // Internal prototypes
  33. void PASCAL FreeData (LPSIOBJ lpSIObj);
  34. // Do nothing for non-OLE code....
  35. #define lpDocObj lpSIObj
  36. #define lpData ((LPSINFO) lpSIObj->m_lpData)
  37. ////////////////////////////////////////////////////////////////////////////////
  38. //
  39. // OfficeDirtySIObj
  40. //
  41. // Purpose:
  42. // Sets object state to dirty or clean.
  43. //
  44. ////////////////////////////////////////////////////////////////////////////////
  45. DLLEXPORT VOID OfficeDirtySIObj (
  46. LPSIOBJ lpSIObj, // The object
  47. BOOL fDirty) // Flag indicating if the object is dirty.
  48. {
  49. Assert(lpSIObj != NULL);
  50. lpDocObj->m_fObjChanged = fDirty;
  51. } // OfficeDirtySIObj
  52. ////////////////////////////////////////////////////////////////////////////////
  53. //
  54. // FSumInfoCreate
  55. //
  56. // Purpose:
  57. // Create the object and return it. Caller responsible for destruction.
  58. //
  59. ////////////////////////////////////////////////////////////////////////////////
  60. BOOL FSumInfoCreate (
  61. LPSIOBJ FAR *lplpSIObj, // Pointer to object
  62. const void *prglpfn[]) // Pointer to functions
  63. {
  64. LPSIOBJ lpSIObj; // Hack - a temp, must call it "lpSIObj" for macros to work!
  65. DWORD cb;
  66. TCHAR szValue[10];
  67. if (lplpSIObj == NULL)
  68. return(TRUE);
  69. // Make sure we get valid args before we start alloc'ing
  70. if ((prglpfn == NULL) || (prglpfn[ifnCPConvert] == NULL) ||
  71. ((prglpfn[ifnFSzToNum] == NULL) && (prglpfn[ifnFNumToSz] != NULL)) ||
  72. ((prglpfn[ifnFSzToNum] != NULL) && (prglpfn[ifnFNumToSz] == NULL)))
  73. return FALSE;
  74. if ((*lplpSIObj = (LPSIOBJ) PvMemAlloc(sizeof (OFFICESUMINFO))) == NULL)
  75. {
  76. // REVIEW: Add alert
  77. return FALSE;
  78. }
  79. lpSIObj = *lplpSIObj; // Save us some indirecting & let us use the "LP" macros
  80. // If alloc fails, free the original object too.
  81. if ((lpData = (LPSINFO) PvMemAlloc(sizeof (SINFO))) == NULL)
  82. {
  83. // REVIEW: Add alert
  84. VFreeMemP(*lplpSIObj, sizeof(OFFICESUMINFO));
  85. return FALSE;
  86. }
  87. FillBuf ((void *) lpData, (int) 0, (sizeof (SINFO) - ifnSIMax*(sizeof (void *))));
  88. // Save the fnc for code page conversion, SzToNum, NumToSz
  89. lpData->lpfnFCPConvert = (BOOL (*)(LPTSTR, DWORD, DWORD, BOOL)) prglpfn[ifnCPConvert];
  90. lpData->lpfnFSzToNum = (BOOL (*)(NUM *, LPTSTR)) prglpfn[ifnFSzToNum];
  91. lpData->lpfnFNumToSz = (BOOL (*)(NUM *, LPTSTR, DWORD)) prglpfn[ifnFNumToSz];
  92. lpData->lpfnFUpdateStats = (BOOL (*)(HWND, LPSIOBJ, LPDSIOBJ)) prglpfn[ifnFUpdateStats];
  93. // Check the registry to see if we should disable Total Editing tracking
  94. cb = sizeof(szValue);
  95. if (RegQueryValue(HKEY_CURRENT_USER, vcszNoTracking,
  96. (LPTSTR)&szValue, &cb) == ERROR_SUCCESS
  97. && cb < sizeof(szValue))
  98. lpData->fNoTimeTracking = (lstrcmpi(szValue,TEXT("0")) != 0); // lstrcmpi returns 0 if equal
  99. OfficeDirtySIObj (*lplpSIObj, FALSE);
  100. (*lplpSIObj)->m_hPage = NULL;
  101. return TRUE;
  102. } // FSumInfoCreate
  103. //////////////////////////////////////////////////////////////////////////////
  104. //
  105. // FreeData
  106. //
  107. // Purpose:
  108. // Deallocates all the member data for the object
  109. //
  110. // Note:
  111. // Assumes object is valid.
  112. //
  113. //////////////////////////////////////////////////////////////////////////////
  114. void PASCAL FreeData (
  115. LPSIOBJ lpSIObj) // Pointer to valid object
  116. {
  117. // Free any buffers held by PropVariants.
  118. FreePropVariantArray (NUM_SI_PROPERTIES, GETSINFO(lpSIObj)->rgpropvar);
  119. }
  120. ////////////////////////////////////////////////////////////////////////////////
  121. //
  122. // FSumInfoClear
  123. //
  124. // Purpose:
  125. // Clear the data stored in the object, but do not destroy the object.
  126. //
  127. ////////////////////////////////////////////////////////////////////////////////
  128. BOOL FSumInfoClear (
  129. LPSIOBJ lpSIObj) // Pointer to object
  130. {
  131. BOOL fNoTimeTracking;
  132. if ((lpDocObj == NULL) ||
  133. (lpData == NULL))
  134. return TRUE;
  135. // Free data in the SINFO structure.
  136. FreeData (lpDocObj);
  137. // Invalidate any OLE Automation DocumentProperty objects we might have
  138. InvalidateVBAObjects(lpSIObj, NULL, NULL);
  139. // Clear the data, don't blt over the fn's stored at the end.
  140. fNoTimeTracking = lpData->fNoTimeTracking;
  141. FillBuf ((void *) lpData, (int) 0, (sizeof (SINFO) - ifnSIMax*(sizeof (void *))));
  142. lpData->fNoTimeTracking = fNoTimeTracking;
  143. OfficeDirtySIObj (lpSIObj, TRUE);
  144. return TRUE;
  145. } // FSumInfoClear
  146. ////////////////////////////////////////////////////////////////////////////////
  147. //
  148. // FSumInfoDestroy
  149. //
  150. // Purpose:
  151. // Destroy the object
  152. //
  153. ////////////////////////////////////////////////////////////////////////////////
  154. BOOL FSumInfoDestroy (LPSIOBJ *lplpSIObj) // Pointer to pointer to object
  155. {
  156. if ((lplpSIObj == NULL) ||
  157. (*lplpSIObj == NULL))
  158. return TRUE;
  159. if ((*lplpSIObj)->m_lpData != NULL)
  160. {
  161. // Free data held by the SINFO structure.
  162. FreeData (*lplpSIObj);
  163. // Invalidate any OLE Automation DocumentProperty objects we might have
  164. InvalidateVBAObjects(*lplpSIObj, NULL, NULL);
  165. // Free the SINFO structure itself.
  166. VFreeMemP((*lplpSIObj)->m_lpData, sizeof(SINFO));
  167. }
  168. // Free the OFFICESUMINFO buffer.
  169. VFreeMemP(*lplpSIObj, sizeof(OFFICESUMINFO));
  170. *lplpSIObj=NULL;
  171. return TRUE;
  172. } // FSumInfoDestroy
  173. ////////////////////////////////////////////////////////////////////////////////
  174. //
  175. // FSumInfoShouldSave
  176. //
  177. // Purpose:
  178. // Indicates if the data has changed, meaning a write is needed.
  179. //
  180. ////////////////////////////////////////////////////////////////////////////////
  181. DLLEXPORT BOOL FSumInfoShouldSave (LPSIOBJ lpSIObj) // Pointer to object
  182. {
  183. if (lpDocObj == NULL)
  184. return FALSE;
  185. return lpDocObj->m_fObjChanged;
  186. } // FSumInfoShouldSave
  187. //
  188. // VSumInfoSetPropBit
  189. //
  190. // Set the bit that indicates that a filetime has been set/loaded
  191. //
  192. VOID PASCAL VSumInfoSetPropBit(LONG pid, BYTE *pbPropSet)
  193. {
  194. switch (pid)
  195. {
  196. case PID_EDITTIME:
  197. *pbPropSet |= bEditTime;
  198. break;
  199. case PID_LASTPRINTED:
  200. *pbPropSet |= bLastPrint;
  201. break;
  202. case PID_CREATE_DTM:
  203. *pbPropSet |= bCreated;
  204. break;
  205. case PID_LASTSAVE_DTM:
  206. *pbPropSet |= bLastSave;
  207. break;
  208. case PID_PAGECOUNT:
  209. *pbPropSet |= bPageCount;
  210. break;
  211. case PID_WORDCOUNT:
  212. *pbPropSet |= bWordCount;
  213. break;
  214. case PID_CHARCOUNT:
  215. *pbPropSet |= bCharCount;
  216. break;
  217. case PID_DOC_SECURITY:
  218. *pbPropSet |= bSecurity;
  219. break;
  220. #ifdef DEBUG
  221. default:
  222. Assert(FALSE);
  223. break;
  224. #endif
  225. }
  226. }
  227. //
  228. // FSumInfoPropBitIsSet
  229. //
  230. // Check the bit that indicates that a filetime has been set/loaded
  231. //
  232. BOOL PASCAL FSumInfoPropBitIsSet(LONG pid, BYTE bPropSet)
  233. {
  234. switch (pid)
  235. {
  236. case PID_EDITTIME:
  237. return (bPropSet & bEditTime);
  238. break;
  239. case PID_LASTPRINTED:
  240. return(bPropSet & bLastPrint);
  241. break;
  242. case PID_CREATE_DTM:
  243. return(bPropSet & bCreated);
  244. break;
  245. case PID_LASTSAVE_DTM:
  246. return(bPropSet & bLastSave);
  247. break;
  248. case PID_PAGECOUNT:
  249. return(bPropSet & bPageCount);
  250. break;
  251. case PID_WORDCOUNT:
  252. return(bPropSet & bWordCount);
  253. break;
  254. case PID_CHARCOUNT:
  255. return(bPropSet & bCharCount);
  256. break;
  257. case PID_DOC_SECURITY:
  258. return(bPropSet & bSecurity);
  259. break;
  260. default:
  261. #ifdef DEBUG
  262. Assert(FALSE);
  263. #endif
  264. return(FALSE);
  265. break;
  266. }
  267. }
  268. #endif // _ABBREVIATED_DOCPROP_