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