sinfo.c
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 9k
Category:

Windows Kernel

Development Platform:

Visual C++

  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 _WIN2000_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.  
  118.     // Free any buffers held by PropVariants.
  119.     FreePropVariantArray (NUM_SI_PROPERTIES, GETSINFO(lpSIObj)->rgpropvar);
  120.     
  121. }    
  122.     
  123.     
  124.     
  125. ////////////////////////////////////////////////////////////////////////////////
  126. //
  127. // FSumInfoClear
  128. //
  129. // Purpose:
  130. //   Clear the data stored in the object, but do not destroy the object.
  131. //
  132. ////////////////////////////////////////////////////////////////////////////////
  133. BOOL FSumInfoClear (
  134.   LPSIOBJ lpSIObj)                     // Pointer to object
  135. {
  136.     BOOL fNoTimeTracking;
  137.     if ((lpDocObj == NULL) ||
  138.         (lpData == NULL))
  139.         return TRUE;
  140.     // Free data in the SINFO structure.
  141.     FreeData (lpDocObj);
  142.     // Invalidate any OLE Automation DocumentProperty objects we might have
  143.     InvalidateVBAObjects(lpSIObj, NULL, NULL);
  144.     // Clear the data, don't blt over the fn's stored at the end.
  145.     fNoTimeTracking = lpData->fNoTimeTracking;
  146.     FillBuf ((void *) lpData, (int) 0, (sizeof (SINFO) - ifnSIMax*(sizeof (void *))));
  147.     lpData->fNoTimeTracking = fNoTimeTracking;
  148.     OfficeDirtySIObj (lpSIObj, TRUE);
  149.     return TRUE;
  150. } // FSumInfoClear
  151. ////////////////////////////////////////////////////////////////////////////////
  152. //
  153. // FSumInfoDestroy
  154. //
  155. // Purpose:
  156. //   Destroy the object
  157. //
  158. ////////////////////////////////////////////////////////////////////////////////
  159. BOOL FSumInfoDestroy (LPSIOBJ *lplpSIObj)              // Pointer to pointer to object
  160. {
  161.     if ((lplpSIObj == NULL)    ||
  162.         (*lplpSIObj == NULL))
  163.         return TRUE;
  164.     if ((*lplpSIObj)->m_lpData != NULL)
  165.     {
  166.         // Free data held by the SINFO structure.
  167.         FreeData (*lplpSIObj);
  168.         // Invalidate any OLE Automation DocumentProperty objects we might have
  169.         InvalidateVBAObjects(*lplpSIObj, NULL, NULL);
  170.         // Free the SINFO structure itself.
  171.         VFreeMemP((*lplpSIObj)->m_lpData, sizeof(SINFO));
  172.     }
  173.     // Free the OFFICESUMINFO buffer.
  174.     VFreeMemP(*lplpSIObj, sizeof(OFFICESUMINFO));
  175.     *lplpSIObj=NULL;
  176.     return TRUE;
  177. } // FSumInfoDestroy
  178. ////////////////////////////////////////////////////////////////////////////////
  179. //
  180. // FSumInfoShouldSave
  181. //
  182. // Purpose:
  183. //  Indicates if the data has changed, meaning a write is needed.
  184. //
  185. ////////////////////////////////////////////////////////////////////////////////
  186. DLLEXPORT BOOL FSumInfoShouldSave (LPSIOBJ lpSIObj)                     // Pointer to object
  187. {
  188.     if (lpDocObj == NULL)
  189.         return FALSE;
  190.     return lpDocObj->m_fObjChanged;
  191. } // FSumInfoShouldSave
  192. //
  193. // VSumInfoSetPropBit
  194. //
  195. // Set the bit that indicates that a filetime has been set/loaded
  196. //
  197. VOID PASCAL VSumInfoSetPropBit(LONG pid, BYTE *pbPropSet)
  198. {
  199.     switch (pid)
  200.     {
  201.     case PID_EDITTIME:
  202.         *pbPropSet |= bEditTime;
  203.         break;
  204.     case PID_LASTPRINTED:
  205.         *pbPropSet |= bLastPrint;
  206.         break;
  207.     case PID_CREATE_DTM:
  208.         *pbPropSet |= bCreated;
  209.         break;
  210.     case PID_LASTSAVE_DTM:
  211.         *pbPropSet |= bLastSave;
  212.         break;
  213.     case PID_PAGECOUNT:
  214.         *pbPropSet |= bPageCount;
  215.         break;
  216.     case PID_WORDCOUNT:
  217.         *pbPropSet |= bWordCount;
  218.         break;
  219.     case PID_CHARCOUNT:
  220.         *pbPropSet |= bCharCount;
  221.         break;
  222.     case PID_DOC_SECURITY:
  223.         *pbPropSet |= bSecurity;
  224.         break;
  225. #ifdef DEBUG
  226.     default:
  227.         Assert(FALSE);
  228.         break;
  229. #endif
  230.     }
  231. }
  232. //
  233. // FSumInfoPropBitIsSet
  234. //
  235. // Check the bit that indicates that a filetime has been set/loaded
  236. //
  237. BOOL PASCAL FSumInfoPropBitIsSet(LONG pid, BYTE bPropSet)
  238. {
  239.     switch (pid)
  240.     {
  241.     case PID_EDITTIME:
  242.         return (bPropSet & bEditTime);
  243.         break;
  244.     case PID_LASTPRINTED:
  245.         return(bPropSet & bLastPrint);
  246.         break;
  247.     case PID_CREATE_DTM:
  248.         return(bPropSet & bCreated);
  249.         break;
  250.     case PID_LASTSAVE_DTM:
  251.         return(bPropSet & bLastSave);
  252.         break;
  253.     case PID_PAGECOUNT:
  254.         return(bPropSet & bPageCount);
  255.         break;
  256.     case PID_WORDCOUNT:
  257.         return(bPropSet & bWordCount);
  258.         break;
  259.     case PID_CHARCOUNT:
  260.         return(bPropSet & bCharCount);
  261.         break;
  262.     case PID_DOC_SECURITY:
  263.         return(bPropSet & bSecurity);
  264.         break;
  265.     default:
  266. #ifdef DEBUG
  267.         Assert(FALSE);
  268. #endif
  269.         return(FALSE);
  270.         break;
  271.     }
  272. }
  273. #endif // _WIN2000_DOCPROP_