Clip.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 "tinyxml.h"
  12. #include "Shared\IClip.h"
  13. class CClip;
  14. class CCopyThread;
  15. typedef CArray<CLIPFORMAT, CLIPFORMAT> CClipTypes;
  16. /*----------------------------------------------------------------------------*\
  17. COleDataObjectEx
  18. \*----------------------------------------------------------------------------*/
  19. class COleDataObjectEx : public COleDataObject
  20. {
  21. public:
  22. // creates global from IStream if necessary
  23. HGLOBAL GetGlobalData(CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtc = NULL);
  24. };
  25. /*----------------------------------------------------------------------------*\
  26. CClipFormat - holds the data of one clip format.
  27. \*----------------------------------------------------------------------------*/
  28. class CClipFormat : public IClipFormat
  29. {
  30. public:
  31. CLIPFORMAT m_cfType;
  32. HGLOBAL m_hgData;
  33. bool bDeleteData;
  34. long m_lDBID;
  35. CClipFormat(CLIPFORMAT cfType = 0, HGLOBAL hgData = 0, long lDBID = -1);
  36. ~CClipFormat();
  37. void Clear();
  38. void Free();
  39. virtual CLIPFORMAT Type() { return m_cfType; }
  40. virtual HGLOBAL Data() { return m_hgData; }
  41. virtual void Type(CLIPFORMAT type) { m_cfType = type; }
  42. virtual void Data(HGLOBAL data) { m_hgData = data; }
  43. };
  44. /*----------------------------------------------------------------------------*\
  45. CClipFormats - holds an array of CClipFormat
  46. \*----------------------------------------------------------------------------*/
  47. class CClipFormats : public CArray<CClipFormat,CClipFormat&>, public IClipFormats
  48. {
  49. public:
  50. // returns a pointer to the CClipFormat in this array which matches the given type
  51. // or NULL if that type doesn't exist in this array.
  52. CClipFormat* FindFormat(UINT cfType);
  53. virtual int Size() { return this->GetCount(); }
  54. virtual IClipFormat *GetAt(int nPos) { return &this->ElementAt(nPos); }
  55. virtual void DeleteAt(int nPos) { this->RemoveAt(nPos); }
  56. virtual void DeleteAll() { this->RemoveAll(); }
  57. virtual int AddNew(CLIPFORMAT type, HGLOBAL data) {CClipFormat ft(type, data, -1); ft.bDeleteData = false; return this->Add(ft); }
  58. virtual IClipFormat *FindFormatEx(CLIPFORMAT type) { return FindFormat((UINT)type); }
  59. };
  60. /*----------------------------------------------------------------------------*\
  61. CClip - holds multiple CClipFormats and clip statistics
  62. - provides static functions for manipulating a Clip as a single unit.
  63. \*----------------------------------------------------------------------------*/
  64. class CClip : public IClip
  65. {
  66. public:
  67. CClip();
  68. ~CClip();
  69. const CClip& operator=(const CClip &clip);
  70. static DWORD m_LastAddedCRC;
  71. static long m_LastAddedID;
  72. long m_ID;
  73. CClipFormats m_Formats;
  74. CTime m_Time;
  75. CString m_Desc;
  76. ULONG m_lTotalCopySize;
  77. long m_lParent;
  78. long m_lDontAutoDelete;
  79. long m_lShortCut;
  80. BOOL m_bIsGroup;
  81. DWORD m_CRC;
  82. CString m_csQuickPaste;
  83. virtual CString Description() { return m_Desc; }
  84. virtual void Description(CString csValue) { m_Desc = csValue; }
  85. virtual CTime PasteTime() { return m_Time; }
  86. virtual int ID() { return m_ID; }
  87. virtual int Parent() { return m_lParent; }
  88. virtual void Parent(int nParent) { m_lParent = nParent; }
  89. virtual int DontAutoDelete() { return m_lDontAutoDelete; }
  90. virtual void DontAutoDelete(int Dont) { m_lDontAutoDelete = Dont; }
  91. virtual CString QuickPaste() { return m_csQuickPaste; }
  92. virtual void QuickPaste(CString csValue) { m_csQuickPaste = csValue; }
  93. virtual IClipFormats *Clips() { return (IClipFormats*)&m_Formats; }
  94. void Clear();
  95. void EmptyFormats();
  96. bool AddFormat(CLIPFORMAT cfType, void* pData, UINT nLen);
  97. bool LoadFromClipboard(CClipTypes* pClipTypes);
  98. bool SetDescFromText(HGLOBAL hgData);
  99. bool SetDescFromType();
  100. bool AddToDB(bool bCheckForDuplicates = true);
  101. bool ModifyMainTable();
  102. bool SaveFromEditWnd(BOOL bUpdateDesc);
  103. void MakeLatestTime();
  104. BOOL LoadMainTable(long lID);
  105. DWORD GenerateCRC();
  106. // Allocates a Global containing the requested Clip's Format Data
  107. static HGLOBAL LoadFormat(long lID, UINT cfType);
  108. // Fills "formats" with the Data of all Formats in the db for the given Clip ID
  109. bool LoadFormats(long lID, bool bOnlyLoad_CF_TEXT = false);
  110. // Fills "types" with all Types in the db for the given Clip ID
  111. static void LoadTypes(long lID, CClipTypes& types);
  112. protected:
  113. bool AddToMainTable();
  114. bool AddToDataTable();
  115. int FindDuplicate();
  116. };
  117. /*----------------------------------------------------------------------------*\
  118. CClipList
  119. \*----------------------------------------------------------------------------*/
  120. class CClipList : public CList<CClip*,CClip*>
  121. {
  122. public:
  123. ~CClipList();
  124. // returns the number of clips actually saved
  125. // while this does empty the Format Data, it does not delete the Clips.
  126. int AddToDB( bool bLatestTime = false, bool bShowStatus = true );
  127. const CClipList& operator=(const CClipList &cliplist);
  128. };
  129. #endif // !defined(AFX_PROCESSCOPY_H__185CBB6F_4B63_4397_8FF9_E18D777DA506__INCLUDED_)