Clip.h 6.7 KB

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