-
Notifications
You must be signed in to change notification settings - Fork 0
/
OleClipSource.cpp
265 lines (215 loc) · 6.16 KB
/
OleClipSource.cpp
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
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
#include "stdafx.h"
#include "CP_Main.h"
#include "OleClipSource.h"
#include "TextConvert.h"
#include "CF_HDropAggregator.h"
#include "CF_UnicodeTextAggregator.h"
#include "CF_TextAggregator.h"
#include "richtextaggregator.h"
#include "htmlformataggregator.h"
/*------------------------------------------------------------------*\
COleClipSource
\*------------------------------------------------------------------*/
//IMPLEMENT_DYNAMIC(COleClipSource, COleDataSource)
//##ModelId=474D3058034C
COleClipSource::COleClipSource()
{
m_bLoadedFormats = false;
m_bOnlyPaste_CF_TEXT = false;
m_bPasteHTMLFormatAs_CF_TEXT = false;
}
//##ModelId=474D3058035C
COleClipSource::~COleClipSource()
{
}
//##ModelId=474D3058036D
BOOL COleClipSource::DoDelayRender()
{
CClipTypes types;
m_ClipIDs.GetTypes(types);
int count = types.GetSize();
for(int i=0; i < count; i++)
DelayRenderData(types[i]);
return count;
}
#include "Client.h"
//##ModelId=474D3058036E
BOOL COleClipSource::DoImmediateRender()
{
if(m_bLoadedFormats)
return TRUE;
m_bLoadedFormats = true;
int count = m_ClipIDs.GetSize();
if(count <= 0)
return 0;
BOOL bProcessedMult = FALSE;
if(count > 1)
{
CStringA SepA = CTextConvert::ConvertToChar(g_Opt.GetMultiPasteSeparator());
CCF_TextAggregator CFText(SepA);
if(m_ClipIDs.AggregateData(CFText, CF_TEXT, g_Opt.m_bMultiPasteReverse && g_Opt.m_bHistoryStartTop))
{
CacheGlobalData(CF_TEXT, CFText.GetHGlobal());
bProcessedMult = TRUE;
}
CStringW SepW = CTextConvert::ConvertToUnicode(g_Opt.GetMultiPasteSeparator());
CCF_UnicodeTextAggregator CFUnicodeText(SepW);
if(m_ClipIDs.AggregateData(CFUnicodeText, CF_UNICODETEXT, g_Opt.m_bMultiPasteReverse && g_Opt.m_bHistoryStartTop))
{
CacheGlobalData(CF_UNICODETEXT, CFUnicodeText.GetHGlobal());
bProcessedMult = TRUE;
}
if(m_bOnlyPaste_CF_TEXT == false)
{
CCF_HDropAggregator HDrop;
if(m_ClipIDs.AggregateData(HDrop, CF_HDROP, g_Opt.m_bMultiPasteReverse && g_Opt.m_bHistoryStartTop))
{
CacheGlobalData(CF_HDROP, HDrop.GetHGlobal());
bProcessedMult = TRUE;
}
CRichTextAggregator RichText(SepA);
if(m_ClipIDs.AggregateData(RichText, theApp.m_RTFFormat, g_Opt.m_bMultiPasteReverse && g_Opt.m_bHistoryStartTop))
{
CacheGlobalData(theApp.m_RTFFormat, RichText.GetHGlobal());
bProcessedMult = TRUE;
}
CHTMLFormatAggregator Html(SepA);
if(m_ClipIDs.AggregateData(Html, theApp.m_HTML_Format, g_Opt.m_bMultiPasteReverse && g_Opt.m_bHistoryStartTop))
{
CacheGlobalData(theApp.m_HTML_Format, Html.GetHGlobal());
bProcessedMult = TRUE;
}
}
}
if(count >= 1 && bProcessedMult == FALSE)
{
CClip clip;
CClipFormats formats;
clip.LoadFormats(m_ClipIDs[0], m_bOnlyPaste_CF_TEXT);
return PutFormatOnClipboard(&clip.m_Formats, m_bPasteHTMLFormatAs_CF_TEXT);
}
return bProcessedMult;
}
//##ModelId=474D3058038B
long COleClipSource::PutFormatOnClipboard(CClipFormats *pFormats, bool bPasteHTMLFormatAs_CF_TEXT)
{
CClipFormat* pCF;
bool bDelayedRenderCF_HDROP = false;
int count = pFormats->GetSize();
int i = 0;
//see if the html format is in the list
//if it is the list we will not paste CF_TEXT
for(i = 0; i < count; i++)
{
pCF = &pFormats->ElementAt(i);
if(bPasteHTMLFormatAs_CF_TEXT)
{
if(pCF->m_cfType == theApp.m_HTML_Format)
break;
}
if(pCF->m_cfType == theApp.m_RemoteCF_HDROP)
{
bDelayedRenderCF_HDROP = true;
}
}
//Didn't find html format
if(i == count)
bPasteHTMLFormatAs_CF_TEXT = false;
for(i = 0; i < count; i++)
{
pCF = &pFormats->ElementAt(i);
if(bDelayedRenderCF_HDROP)
{
if(pCF->m_cfType == CF_HDROP)
{
DelayRenderData(pCF->m_cfType);
}
continue;
}
if(bPasteHTMLFormatAs_CF_TEXT)
{
if(pCF->m_cfType == CF_TEXT)
continue;
if(pCF->m_cfType == theApp.m_HTML_Format)
pCF->m_cfType = CF_TEXT;
}
CacheGlobalData( pCF->m_cfType, pCF->m_hgData );
pCF->m_hgData = 0; // OLE owns it now
}
pFormats->RemoveAll();
m_bLoadedFormats = true;
return count;
}
//##ModelId=474D305803BB
BOOL COleClipSource::OnRenderGlobalData(LPFORMATETC lpFormatEtc, HGLOBAL* phGlobal)
{
static bool bInHere = false;
if(bInHere)
{
return FALSE;
}
bInHere = true;
HGLOBAL hData = NULL;
CClipFormat *pFind = m_DelayRenderedFormats.FindFormat(lpFormatEtc->cfFormat);
if(pFind)
{
if(pFind->m_hgData)
{
hData = NewGlobalH(pFind->m_hgData, GlobalSize(pFind->m_hgData));
}
}
else
{
CClip clip;
clip.LoadFormats(m_ClipIDs[0]);
CClipFormat *pDittoDelayCF_HDROP = clip.m_Formats.FindFormat(theApp.m_RemoteCF_HDROP);
CClipFormat *pCF_HDROP = clip.m_Formats.FindFormat(CF_HDROP);
if(pDittoDelayCF_HDROP && pCF_HDROP)
{
CDittoCF_HDROP *pData = (CDittoCF_HDROP*)GlobalLock(pDittoDelayCF_HDROP->m_hgData);
if(pData)
{
CString csComputerName;
CString csIP;
CTextConvert::ConvertFromUTF8(pData->m_cIP, csIP);
CTextConvert::ConvertFromUTF8(pData->m_cComputerName, csComputerName);
GlobalUnlock(pDittoDelayCF_HDROP->m_hgData);
CClient cl;
hData = cl.RequestCopiedFiles(*pCF_HDROP, csIP, csComputerName);
}
}
else
{
hData = m_ClipIDs.Render(lpFormatEtc->cfFormat);
}
//Add to a cache of already rendered data
//Windows seems to call this function multiple times
//so only the first time do we need to go get the data
HGLOBAL hCopy = NULL;
if(hData)
{
hCopy = NewGlobalH(hData, GlobalSize(hData));
}
CClipFormat format(lpFormatEtc->cfFormat, hCopy);
format.bDeleteData = false; //owned by m_DelayRenderedFormats
m_DelayRenderedFormats.Add(format);
}
BOOL bRet = FALSE;
if(hData)
{
// if phGlobal is null, we can just give the allocated mem
// else, our data must fit within the GlobalSize(*phGlobal)
if(*phGlobal == 0)
*phGlobal = hData;
else
{
UINT len = min(::GlobalSize(*phGlobal), ::GlobalSize(hData));
if(len)
CopyToGlobalHH(*phGlobal, hData, len);
::GlobalFree(hData);
}
bRet = TRUE;
}
bInHere = false;
return bRet;
}