Clip.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // ProcessCopy.h: classes for saving the clipboard to db
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_PROCESSCOPY_H__185CBB6F_4B63_4397_8FF9_E18D777DA506__INCLUDED_)
  5. #define AFX_PROCESSCOPY_H__185CBB6F_4B63_4397_8FF9_E18D777DA506__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. #include <afxole.h>
  10. #include <afxtempl.h>
  11. #include "MainTable.h"
  12. class CClip;
  13. class CCopyThread;
  14. typedef CArray<CLIPFORMAT, CLIPFORMAT> CClipTypes;
  15. /*----------------------------------------------------------------------------*\
  16. COleDataObjectEx
  17. \*----------------------------------------------------------------------------*/
  18. class COleDataObjectEx : public COleDataObject
  19. {
  20. public:
  21. // creates global from IStream if necessary
  22. HGLOBAL GetGlobalData(CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtc = NULL);
  23. };
  24. /*----------------------------------------------------------------------------*\
  25. CClipFormat - holds the data of one clip format.
  26. \*----------------------------------------------------------------------------*/
  27. class CClipFormat
  28. {
  29. public:
  30. CLIPFORMAT m_cfType;
  31. HGLOBAL m_hgData;
  32. bool bDeleteData;
  33. CClipFormat(CLIPFORMAT cfType = 0, HGLOBAL hgData = 0);
  34. ~CClipFormat();
  35. void Clear();
  36. void Free();
  37. };
  38. /*----------------------------------------------------------------------------*\
  39. CClipFormats - holds an array of CClipFormat
  40. \*----------------------------------------------------------------------------*/
  41. class CClipFormats : public CArray<CClipFormat,CClipFormat&>
  42. {
  43. public:
  44. // returns a pointer to the CClipFormat in this array which matches the given type
  45. // or NULL if that type doesn't exist in this array.
  46. CClipFormat* FindFormat(UINT cfType);
  47. };
  48. /*----------------------------------------------------------------------------*\
  49. CClip - holds multiple CClipFormats and clip statistics
  50. - provides static functions for manipulating a Clip as a single unit.
  51. \*----------------------------------------------------------------------------*/
  52. class CClip
  53. {
  54. public:
  55. long m_ID; // 0 if it hasn't yet been saved or is unknown
  56. long m_DataID;
  57. CClipFormats m_Formats; // actual format data
  58. const CClip& operator=(const CClip &clip);
  59. // statistics assigned by LoadFromClipboard
  60. CTime m_Time; // time copied from clipboard
  61. CString m_Desc;
  62. ULONG m_lTotalCopySize;
  63. CClip();
  64. ~CClip();
  65. void Clear();
  66. void EmptyFormats();
  67. // Adds a new Format to this Clip by copying the given data.
  68. bool AddFormat(CLIPFORMAT cfType, void* pData, UINT nLen);
  69. // Fills this CClip with the contents of the clipboard.
  70. bool LoadFromClipboard(CClipTypes* pClipTypes);
  71. bool SetDescFromText(HGLOBAL hgData);
  72. bool SetDescFromType();
  73. // Immediately save this clip to the db (empties m_Formats due to AddToDataTable).
  74. bool AddToDB(bool bCheckForDuplicates = true);
  75. bool AddToMainTable();
  76. bool AddToDataTable();
  77. // if a duplicate exists, set recset to the duplicate and return true
  78. bool FindDuplicate(CMainTable& recset, BOOL bCheckLastOnly = FALSE);
  79. int CompareFormatDataTo(long lDataID);
  80. // changes m_Time to be later than the latest clip entry in the db
  81. void MakeLatestTime();
  82. // STATICS
  83. // Allocates a Global containing the requested Clip's Format Data
  84. static HGLOBAL LoadFormat(long lID, UINT cfType);
  85. // Fills "formats" with the Data of all Formats in the db for the given Clip ID
  86. static bool LoadFormats(long lID, CClipFormats& formats, bool bOnlyLoad_CF_TEXT = false);
  87. // Fills "types" with all Types in the db for the given Clip ID
  88. static void LoadTypes(long lID, CClipTypes& types);
  89. };
  90. /*----------------------------------------------------------------------------*\
  91. CClipList
  92. \*----------------------------------------------------------------------------*/
  93. class CClipList : public CList<CClip*,CClip*>
  94. {
  95. public:
  96. ~CClipList();
  97. // returns the number of clips actually saved
  98. // while this does empty the Format Data, it does not delete the Clips.
  99. int AddToDB( bool bLatestTime = false, bool bShowStatus = true );
  100. const CClipList& operator=(const CClipList &cliplist);
  101. };
  102. #endif // !defined(AFX_PROCESSCOPY_H__185CBB6F_4B63_4397_8FF9_E18D777DA506__INCLUDED_)