Clip.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. // Clip.h: classes for manage clips
  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 <memory>
  12. #include "tinyxml\tinyxml.h"
  13. #include "..\Shared\IClip.h"
  14. #include "Misc.h"
  15. class CClip;
  16. class CCopyThread;
  17. typedef CArray<CLIPFORMAT, CLIPFORMAT> CClipTypes;
  18. /*----------------------------------------------------------------------------*\
  19. COleDataObjectEx
  20. \*----------------------------------------------------------------------------*/
  21. class COleDataObjectEx : public COleDataObject
  22. {
  23. public:
  24. // creates global from IStream if necessary
  25. HGLOBAL GetGlobalData(CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtc = NULL);
  26. std::shared_ptr<CClipTypes> GetAvailableTypes();
  27. };
  28. /*----------------------------------------------------------------------------*\
  29. CClipFormat - holds the data of one clip format.
  30. \*----------------------------------------------------------------------------*/
  31. class CClipFormat : public IClipFormat
  32. {
  33. public:
  34. CLIPFORMAT m_cfType;
  35. HGLOBAL m_hgData;
  36. bool m_autoDeleteData;
  37. int m_dataId;
  38. int m_parentId;
  39. CClipFormat(CLIPFORMAT cfType = 0, HGLOBAL hgData = 0, int parentId = -1);
  40. ~CClipFormat();
  41. void Clear();
  42. virtual void Free();
  43. virtual CLIPFORMAT Type() { return m_cfType; }
  44. virtual HGLOBAL Data() { return m_hgData; }
  45. virtual void Type(CLIPFORMAT type) { m_cfType = type; }
  46. virtual void Data(HGLOBAL data) { m_hgData = data; }
  47. virtual void AutoDeleteData(bool autoDeleteData) { m_autoDeleteData = autoDeleteData; }
  48. virtual bool AutoDeleteData() { return m_autoDeleteData; }
  49. CStringA GetAsCStringA() {
  50. CStringA ret;
  51. if (m_hgData)
  52. {
  53. LPVOID data = GlobalLock(m_hgData);
  54. int size = (int)GlobalSize(m_hgData);
  55. if (data != NULL && size > 0)
  56. {
  57. ret = CStringA((char *)data, size-1);
  58. }
  59. GlobalUnlock(m_hgData);
  60. }
  61. return ret;
  62. }
  63. CString GetAsCString() {
  64. CString ret;
  65. if (m_hgData)
  66. {
  67. LPVOID data = GlobalLock(m_hgData);
  68. int size = (int)GlobalSize(m_hgData);
  69. if (data != NULL && size > 0)
  70. {
  71. ret = CString((wchar_t *)data, ((size / (sizeof(wchar_t))) - 1));
  72. }
  73. GlobalUnlock(m_hgData);
  74. }
  75. return ret;
  76. }
  77. Gdiplus::Bitmap *CreateGdiplusBitmap();
  78. };
  79. /*----------------------------------------------------------------------------*\
  80. CClipFormats - holds an array of CClipFormat
  81. \*----------------------------------------------------------------------------*/
  82. class CClipFormats : public CArray<CClipFormat,CClipFormat&>, public IClipFormats
  83. {
  84. public:
  85. // returns a pointer to the CClipFormat in this array which matches the given type
  86. // or NULL if that type doesn't exist in this array.
  87. CClipFormat* FindFormat(UINT cfType);
  88. virtual int Size() { return (int)this->GetCount(); }
  89. virtual IClipFormat *GetAt(int nPos) { return &this->ElementAt(nPos); }
  90. virtual void DeleteAt(int nPos) { this->RemoveAt(nPos); }
  91. virtual void DeleteAll() { this->RemoveAll(); }
  92. virtual INT_PTR AddNew(CLIPFORMAT type, HGLOBAL data) {CClipFormat ft(type, data, -1); ft.m_autoDeleteData = false; return this->Add(ft); }
  93. virtual IClipFormat *FindFormatEx(CLIPFORMAT type) { return FindFormat((UINT)type); }
  94. virtual bool RemoveFormat(CLIPFORMAT type);
  95. };
  96. /*----------------------------------------------------------------------------*\
  97. CClip - holds multiple CClipFormats and clip statistics
  98. - provides static functions for manipulating a Clip as a single unit.
  99. \*----------------------------------------------------------------------------*/
  100. class CClip : public IClip
  101. {
  102. public:
  103. CClip();
  104. ~CClip();
  105. const CClip& operator=(const CClip &clip);
  106. static DWORD m_LastAddedCRC;
  107. static int m_lastAddedID;
  108. int m_id;
  109. CClipFormats m_Formats;
  110. CTime m_Time;
  111. CString m_Desc;
  112. ULONG m_lTotalCopySize;
  113. int m_parentId;
  114. int m_dontAutoDelete;
  115. int m_shortCut;
  116. BOOL m_bIsGroup;
  117. DWORD m_CRC;
  118. CString m_csQuickPaste;
  119. int m_param1;
  120. double m_clipOrder;
  121. double m_clipGroupOrder;
  122. double m_stickyClipOrder;
  123. double m_stickyClipGroupOrder;
  124. BOOL m_globalShortCut;
  125. CTime m_lastPasteDate;
  126. int m_moveToGroupShortCut;
  127. BOOL m_globalMoveToGroupShortCut;
  128. CopyReasonEnum::CopyReason m_copyReason;
  129. virtual CString Description() { return m_Desc; }
  130. virtual void Description(CString csValue) { m_Desc = csValue; }
  131. virtual CTime PasteTime() { return m_Time; }
  132. virtual int ID() { return m_id; }
  133. virtual int Parent() { return m_parentId; }
  134. virtual void Parent(int nParent) { m_parentId = nParent; }
  135. virtual int DontAutoDelete() { return m_dontAutoDelete; }
  136. virtual void DontAutoDelete(int Dont) { m_dontAutoDelete = Dont; }
  137. virtual CString QuickPaste() { return m_csQuickPaste; }
  138. virtual void QuickPaste(CString csValue) { m_csQuickPaste = csValue; }
  139. virtual void SetSaveToDbSticky(AddToDbStickyEnum::AddToDbSticky option) { m_addToDbStickyEnum = option; }
  140. virtual IClipFormats *Clips() { return (IClipFormats*)&m_Formats; }
  141. void Clear();
  142. void EmptyFormats();
  143. bool AddFormat(CLIPFORMAT cfType, void* pData, UINT nLen, bool setDesc = false);
  144. int LoadFromClipboard(CClipTypes* pClipTypes, bool checkClipboardIgnore = true, CString activeApp = _T(""), CString activeAppTitle = _T(""));
  145. bool SetDescFromText(HGLOBAL hgData, bool unicode);
  146. bool SetDescFromType();
  147. bool AddToDB(bool bCheckForDuplicates = true);
  148. bool ModifyMainTable();
  149. bool ModifyDescription();
  150. void MakeLatestOrder();
  151. void MakeLatestGroupOrder();
  152. void MakeLastOrder();
  153. void MakeLastGroupOrder();
  154. void MakeStickyTop(int parentId);
  155. void MakeStickyLast(int parentId);
  156. bool RemoveStickySetting(int parentId);
  157. BOOL LoadMainTable(int id);
  158. DWORD GenerateCRC();
  159. void MoveUp(int parentId);
  160. void MoveDown(int parentId);
  161. bool SaveFromEditWnd(BOOL bUpdateDesc);
  162. CStringW GetUnicodeTextFormat();
  163. CStringA GetCFTextTextFormat();
  164. CStringA GetRTFTextFormat();
  165. BOOL ContainsClipFormat(CLIPFORMAT clipFormat);
  166. BOOL WriteTextToFile(CString path, BOOL unicode, BOOL asci, BOOL rtf, BOOL forceUnicode = FALSE, BOOL utf8 = FALSE);
  167. BOOL WriteImageToFile(CString path);
  168. BOOL WriteTextToHtmlFile(CString path);
  169. BOOL SaveFormats(CString* unicode, CStringA* asci, CStringA* rtf, BOOL updateDescription, std::vector<BYTE>* cf_dibBytes = nullptr, std::vector<BYTE>* pngBytes = nullptr);
  170. // Allocates a Global containing the requested Clip's Format Data
  171. static HGLOBAL LoadFormat(int id, UINT cfType);
  172. // Fills "formats" with the Data of all Formats in the db for the given Clip ID
  173. bool LoadFormats(int id, bool bOnlyLoad_CF_TEXT = false, bool includeRichTextForTextOnly = false, int dataId = -1);
  174. // Fills "types" with all Types in the db for the given Clip ID
  175. static void LoadTypes(int id, CClipTypes& types);
  176. static double GetNewOrder(int parentId, int clipId);
  177. double GetNewLastOrder(int parentId, int clipId);
  178. static double GetNewTopSticky(int parentId, int clipId);
  179. static double GetNewLastSticky(int parentId, int clipId);
  180. static int GetExistingTopStickyClipId(int parentId);
  181. static bool RemoveStickySetting(int clipId, int parentId);
  182. bool AddFileDataToData(CString &errorMessage);
  183. Gdiplus::Bitmap *CreateGdiplusBitmap();
  184. protected:
  185. bool AddToMainTable();
  186. bool AddToDataTable();
  187. int FindDuplicate();
  188. AddToDbStickyEnum::AddToDbSticky m_addToDbStickyEnum;
  189. };
  190. /*----------------------------------------------------------------------------*\
  191. CClipList
  192. \*----------------------------------------------------------------------------*/
  193. class CClipList : public CList<CClip*,CClip*>
  194. {
  195. public:
  196. ~CClipList();
  197. // returns the number of clips actually saved
  198. // while this does empty the Format Data, it does not delete the Clips.
  199. int AddToDB( bool bLatestOrder = false);
  200. const CClipList& operator=(const CClipList &cliplist);
  201. };
  202. #endif // !defined(AFX_PROCESSCOPY_H__185CBB6F_4B63_4397_8FF9_E18D777DA506__INCLUDED_)