Clip.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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\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. int m_dataId;
  35. int m_parentId;
  36. CClipFormat(CLIPFORMAT cfType = 0, HGLOBAL hgData = 0, int parentId = -1);
  37. ~CClipFormat();
  38. void Clear();
  39. void Free();
  40. virtual CLIPFORMAT Type() { return m_cfType; }
  41. virtual HGLOBAL Data() { return m_hgData; }
  42. virtual void Type(CLIPFORMAT type) { m_cfType = type; }
  43. virtual void Data(HGLOBAL data) { m_hgData = data; }
  44. virtual void AutoDeleteData(bool autoDeleteData) { m_autoDeleteData = autoDeleteData; }
  45. virtual bool AutoDeleteData() { return m_autoDeleteData; }
  46. };
  47. /*----------------------------------------------------------------------------*\
  48. CClipFormats - holds an array of CClipFormat
  49. \*----------------------------------------------------------------------------*/
  50. class CClipFormats : public CArray<CClipFormat,CClipFormat&>, public IClipFormats
  51. {
  52. public:
  53. // returns a pointer to the CClipFormat in this array which matches the given type
  54. // or NULL if that type doesn't exist in this array.
  55. CClipFormat* FindFormat(UINT cfType);
  56. virtual int Size() { return (int)this->GetCount(); }
  57. virtual IClipFormat *GetAt(int nPos) { return &this->ElementAt(nPos); }
  58. virtual void DeleteAt(int nPos) { this->RemoveAt(nPos); }
  59. virtual void DeleteAll() { this->RemoveAll(); }
  60. virtual INT_PTR AddNew(CLIPFORMAT type, HGLOBAL data) {CClipFormat ft(type, data, -1); ft.m_autoDeleteData = false; return this->Add(ft); }
  61. virtual IClipFormat *FindFormatEx(CLIPFORMAT type) { return FindFormat((UINT)type); }
  62. };
  63. /*----------------------------------------------------------------------------*\
  64. CClip - holds multiple CClipFormats and clip statistics
  65. - provides static functions for manipulating a Clip as a single unit.
  66. \*----------------------------------------------------------------------------*/
  67. class CClip : public IClip
  68. {
  69. public:
  70. CClip();
  71. ~CClip();
  72. const CClip& operator=(const CClip &clip);
  73. static DWORD m_LastAddedCRC;
  74. static int m_lastAddedID;
  75. int m_id;
  76. CClipFormats m_Formats;
  77. CTime m_Time;
  78. CString m_Desc;
  79. ULONG m_lTotalCopySize;
  80. int m_parentId;
  81. int m_dontAutoDelete;
  82. int m_shortCut;
  83. BOOL m_bIsGroup;
  84. DWORD m_CRC;
  85. CString m_csQuickPaste;
  86. int m_param1;
  87. double m_clipOrder;
  88. double m_clipGroupOrder;
  89. double m_stickyClipOrder;
  90. double m_stickyClipGroupOrder;
  91. BOOL m_globalShortCut;
  92. CTime m_lastPasteDate;
  93. virtual CString Description() { return m_Desc; }
  94. virtual void Description(CString csValue) { m_Desc = csValue; }
  95. virtual CTime PasteTime() { return m_Time; }
  96. virtual int ID() { return m_id; }
  97. virtual int Parent() { return m_parentId; }
  98. virtual void Parent(int nParent) { m_parentId = nParent; }
  99. virtual int DontAutoDelete() { return m_dontAutoDelete; }
  100. virtual void DontAutoDelete(int Dont) { m_dontAutoDelete = Dont; }
  101. virtual CString QuickPaste() { return m_csQuickPaste; }
  102. virtual void QuickPaste(CString csValue) { m_csQuickPaste = csValue; }
  103. virtual IClipFormats *Clips() { return (IClipFormats*)&m_Formats; }
  104. void Clear();
  105. void EmptyFormats();
  106. bool AddFormat(CLIPFORMAT cfType, void* pData, UINT nLen);
  107. bool LoadFromClipboard(CClipTypes* pClipTypes, bool checkClipboardIgnore = true);
  108. bool SetDescFromText(HGLOBAL hgData, bool unicode);
  109. bool SetDescFromType();
  110. bool AddToDB(bool bCheckForDuplicates = true);
  111. bool ModifyMainTable();
  112. bool SaveFromEditWnd(BOOL bUpdateDesc);
  113. void MakeLatestOrder();
  114. void MakeLatestGroupOrder();
  115. void MakeStickyTop(int parentId);
  116. void MakeStickyLast(int parentId);
  117. void RemoveStickySetting(int parentId);
  118. BOOL LoadMainTable(int id);
  119. DWORD GenerateCRC();
  120. void MoveUp();
  121. CStringW GetUnicodeTextFormat();
  122. CStringA GetCFTextTextFormat();
  123. BOOL WriteTextToFile(CString path, BOOL unicode, BOOL asci, BOOL utf8);
  124. // Allocates a Global containing the requested Clip's Format Data
  125. static HGLOBAL LoadFormat(int id, UINT cfType);
  126. // Fills "formats" with the Data of all Formats in the db for the given Clip ID
  127. bool LoadFormats(int id, bool bOnlyLoad_CF_TEXT = false);
  128. // Fills "types" with all Types in the db for the given Clip ID
  129. static void LoadTypes(int id, CClipTypes& types);
  130. static double GetNewOrder(int parentId, int clipId);
  131. static double GetNewTopSticky(int parentId, int clipId);
  132. static double GetNewLastSticky(int parentId, int clipId);
  133. protected:
  134. bool AddToMainTable();
  135. bool AddToDataTable();
  136. int FindDuplicate();
  137. };
  138. /*----------------------------------------------------------------------------*\
  139. CClipList
  140. \*----------------------------------------------------------------------------*/
  141. class CClipList : public CList<CClip*,CClip*>
  142. {
  143. public:
  144. ~CClipList();
  145. // returns the number of clips actually saved
  146. // while this does empty the Format Data, it does not delete the Clips.
  147. int AddToDB( bool bLatestOrder = false);
  148. const CClipList& operator=(const CClipList &cliplist);
  149. };
  150. #endif // !defined(AFX_PROCESSCOPY_H__185CBB6F_4B63_4397_8FF9_E18D777DA506__INCLUDED_)