Clip.h 6.4 KB

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