Clip.h 5.3 KB

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