OleClipSource.cpp 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424
  1. #include "stdafx.h"
  2. #include "CP_Main.h"
  3. #include "OleClipSource.h"
  4. #include "shared/TextConvert.h"
  5. #include "CF_HDropAggregator.h"
  6. #include "CF_UnicodeTextAggregator.h"
  7. #include "CF_TextAggregator.h"
  8. #include "richtextaggregator.h"
  9. #include "htmlformataggregator.h"
  10. #include "Shared\Tokenizer.h"
  11. #include <random>
  12. #include "Client.h"
  13. #include "Path.h"
  14. #include "Md5.h"
  15. #include "DittoChaiScript.h"
  16. #include "ChaiScriptOnCopy.h"
  17. #include "Slugify.h"
  18. #include "ImageFormatAggregator.h"
  19. /*------------------------------------------------------------------*\
  20. COleClipSource
  21. \*------------------------------------------------------------------*/
  22. //IMPLEMENT_DYNAMIC(COleClipSource, COleDataSource)
  23. COleClipSource::COleClipSource()
  24. {
  25. m_bLoadedFormats = false;
  26. m_convertToHDROPOnDelayRender = false;
  27. }
  28. COleClipSource::~COleClipSource()
  29. {
  30. }
  31. BOOL COleClipSource::DoDelayRender()
  32. {
  33. CClipTypes types;
  34. m_ClipIDs.GetTypes(types);
  35. bool foundHDrop = false;
  36. INT_PTR count = types.GetSize();
  37. for(int i=0; i < count; i++)
  38. {
  39. if (m_pasteOptions.m_dragDropFilesOnly)
  40. {
  41. if (types[i] == CF_HDROP)
  42. {
  43. DelayRenderData(types[i]);
  44. }
  45. }
  46. else
  47. {
  48. DelayRenderData(types[i]);
  49. }
  50. if (types[i] == CF_HDROP)
  51. {
  52. foundHDrop = true;
  53. }
  54. }
  55. if (m_pasteOptions.m_placeCF_HDROP_OnDrag &&
  56. foundHDrop == false)
  57. {
  58. DelayRenderData(CF_HDROP);
  59. m_convertToHDROPOnDelayRender = true;
  60. }
  61. return count > 0;
  62. }
  63. BOOL COleClipSource::DoImmediateRender()
  64. {
  65. if(m_bLoadedFormats)
  66. return TRUE;
  67. m_bLoadedFormats = true;
  68. if(m_pasteOptions.m_pPasteFormats != NULL)
  69. {
  70. return PutFormatOnClipboard(m_pasteOptions.m_pPasteFormats) > 0;
  71. }
  72. INT_PTR count = m_ClipIDs.GetSize();
  73. if(count <= 0)
  74. return 0;
  75. CClip clip;
  76. if(count > 1)
  77. {
  78. if (m_pasteOptions.m_pasteImagesHorizontal ||
  79. m_pasteOptions.m_pasteImagesVertically)
  80. {
  81. CImageFormatAggregator bigImage(m_pasteOptions.m_pasteImagesHorizontal);
  82. if (m_ClipIDs.AggregateData(bigImage, CF_DIB, g_Opt.m_bMultiPasteReverse, m_pasteOptions.LimitFormatsToText()))
  83. {
  84. CClipFormat cf(CF_DIB, bigImage.GetHGlobal());
  85. clip.m_Formats.Add(cf);
  86. //clip.m_Formats now owns the global data
  87. cf.m_autoDeleteData = false;
  88. }
  89. }
  90. else
  91. {
  92. CStringA SepA = CTextConvert::UnicodeToAnsi(g_Opt.GetMultiPasteSeparator());
  93. CCF_TextAggregator CFText(SepA);
  94. if (m_ClipIDs.AggregateData(CFText, CF_TEXT, g_Opt.m_bMultiPasteReverse, m_pasteOptions.LimitFormatsToText()))
  95. {
  96. CClipFormat cf(CF_TEXT, CFText.GetHGlobal());
  97. clip.m_Formats.Add(cf);
  98. //clip.m_Formats now owns the global data
  99. cf.m_autoDeleteData = false;
  100. }
  101. CStringW SepW = g_Opt.GetMultiPasteSeparator();
  102. CCF_UnicodeTextAggregator CFUnicodeText(SepW);
  103. if (m_ClipIDs.AggregateData(CFUnicodeText, CF_UNICODETEXT, g_Opt.m_bMultiPasteReverse, m_pasteOptions.LimitFormatsToText()))
  104. {
  105. CClipFormat cf(CF_UNICODETEXT, CFUnicodeText.GetHGlobal());
  106. clip.m_Formats.Add(cf);
  107. //clip.m_Formats now owns the global data
  108. cf.m_autoDeleteData = false;
  109. }
  110. if (m_pasteOptions.LimitFormatsToText() == false)
  111. {
  112. CCF_HDropAggregator HDrop;
  113. if (m_ClipIDs.AggregateData(HDrop, CF_HDROP, g_Opt.m_bMultiPasteReverse, m_pasteOptions.LimitFormatsToText()))
  114. {
  115. CClipFormat cf(CF_HDROP, HDrop.GetHGlobal());
  116. clip.m_Formats.Add(cf);
  117. //clip.m_Formats now owns the global data
  118. cf.m_autoDeleteData = false;
  119. }
  120. CRichTextAggregator RichText(SepA);
  121. if (m_ClipIDs.AggregateData(RichText, theApp.m_RTFFormat, g_Opt.m_bMultiPasteReverse, m_pasteOptions.LimitFormatsToText()))
  122. {
  123. CClipFormat cf(theApp.m_RTFFormat, RichText.GetHGlobal());
  124. clip.m_Formats.Add(cf);
  125. //clip.m_Formats now owns the global data
  126. cf.m_autoDeleteData = false;
  127. }
  128. CHTMLFormatAggregator Html(SepA);
  129. if (m_ClipIDs.AggregateData(Html, theApp.m_HTML_Format, g_Opt.m_bMultiPasteReverse, m_pasteOptions.LimitFormatsToText()))
  130. {
  131. CClipFormat cf(theApp.m_HTML_Format, Html.GetHGlobal());
  132. clip.m_Formats.Add(cf);
  133. //clip.m_Formats now owns the global data
  134. cf.m_autoDeleteData = false;
  135. }
  136. }
  137. }
  138. }
  139. if (count >= 1 && clip.m_Formats.GetCount() == 0)
  140. {
  141. clip.LoadFormats(m_ClipIDs[0], m_pasteOptions.LimitFormatsToText(), m_pasteOptions.IncludeRTFForTextOnly());
  142. }
  143. if (m_pasteOptions.LimitFormatsToText())
  144. {
  145. PlainTextFilter(clip);
  146. }
  147. if(m_pasteOptions.m_pasteUpperCase ||
  148. m_pasteOptions.m_pasteLowerCase)
  149. {
  150. DoUpperLowerCase(clip, m_pasteOptions.m_pasteUpperCase);
  151. }
  152. else if(m_pasteOptions.m_pasteCapitalize)
  153. {
  154. Capitalize(clip);
  155. }
  156. else if(m_pasteOptions.m_pasteSentenceCase)
  157. {
  158. SentenceCase(clip);
  159. }
  160. else if(m_pasteOptions.m_pasteRemoveLineFeeds)
  161. {
  162. RemoveLineFeeds(clip);
  163. }
  164. else if(m_pasteOptions.m_pasteAddOneLineFeed)
  165. {
  166. AddLineFeeds(clip, 1);
  167. }
  168. else if (m_pasteOptions.m_pasteAddTwoLineFeeds)
  169. {
  170. AddLineFeeds(clip, 2);
  171. }
  172. else if (m_pasteOptions.m_pasteTypoglycemia)
  173. {
  174. Typoglycemia(clip);
  175. }
  176. else if (m_pasteOptions.m_pasteAddingDateTime)
  177. {
  178. AddDateTime(clip);
  179. }
  180. else if (m_pasteOptions.m_trimWhiteSpace)
  181. {
  182. TrimWhiteSpace(clip);
  183. }
  184. else if (m_pasteOptions.m_pasteSlugify)
  185. {
  186. Slugify(clip);
  187. }
  188. else if (m_pasteOptions.m_invertCase)
  189. {
  190. InvertCase(clip);
  191. }
  192. else if (m_pasteOptions.m_pasteCamelCase)
  193. {
  194. CamelCase(clip);
  195. }
  196. else if (m_pasteOptions.m_pasteAsciiOnly)
  197. {
  198. AsciiOnly(clip);
  199. }
  200. SaveDittoFileDataToFile(clip);
  201. if (m_pasteOptions.m_pasteScriptGuid != _T(""))
  202. {
  203. for (auto & element : g_Opt.m_pasteScripts.m_list)
  204. {
  205. if (element.m_guid == m_pasteOptions.m_pasteScriptGuid)
  206. {
  207. try
  208. {
  209. Log(StrF(_T("Start of paste script name: %s, script: %s"), element.m_name, element.m_script));
  210. ChaiScriptOnCopy onPaste;
  211. CDittoChaiScript clipData(&clip, "", "");
  212. if (onPaste.ProcessScript(clipData, (LPCSTR)CTextConvert::UnicodeToAnsi(element.m_script)) == false)
  213. {
  214. Log(StrF(_T("End of paste script name: %s, returned false, not saving this copy to Ditto, last Error: %s"), element.m_name, onPaste.m_lastError));
  215. return FALSE;
  216. }
  217. Log(StrF(_T("End of paste script name: %s, returned true, last Error: %s"), element.m_name, onPaste.m_lastError));
  218. }
  219. catch (CException *ex)
  220. {
  221. TCHAR szCause[255];
  222. ex->GetErrorMessage(szCause, 255);
  223. CString cs;
  224. cs.Format(_T("chai script paste exception: %s"), szCause);
  225. Log(cs);
  226. }
  227. catch (...)
  228. {
  229. Log(_T("chai script paste exception 2"));
  230. }
  231. break;
  232. }
  233. }
  234. }
  235. return PutFormatOnClipboard(&clip.m_Formats) > 0;
  236. }
  237. void COleClipSource::DoUpperLowerCase(CClip &clip, bool upper)
  238. {
  239. IClipFormat *unicodeTextFormat = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
  240. if (unicodeTextFormat != NULL)
  241. {
  242. CString cs = unicodeTextFormat->GetAsCString();
  243. //free the old text we are going to replace it below with an upper case version
  244. unicodeTextFormat->Free();
  245. CString val;
  246. if (upper)
  247. {
  248. val = theApp.m_icuString.ToUpperStringEx(cs);
  249. }
  250. else
  251. {
  252. val = theApp.m_icuString.ToLowerStringEx(cs);
  253. }
  254. long lLen = val.GetLength();
  255. HGLOBAL hGlobal = NewGlobalP(val.GetBuffer(lLen), ((lLen+1) * sizeof(wchar_t)));
  256. val.ReleaseBuffer();
  257. unicodeTextFormat->Data(hGlobal);
  258. }
  259. IClipFormat *asciiTextFormat = clip.m_Formats.FindFormatEx(CF_TEXT);
  260. if (asciiTextFormat != NULL)
  261. {
  262. CStringA cs(asciiTextFormat->GetAsCStringA());
  263. //free the old text we are going to replace it below with an upper case version
  264. asciiTextFormat->Free();
  265. CString val;
  266. if (upper)
  267. {
  268. val = cs.MakeUpper();
  269. }
  270. else
  271. {
  272. val = cs.MakeLower();
  273. }
  274. long lLen = val.GetLength();
  275. HGLOBAL hGlobal = NewGlobalP(val.GetBuffer(lLen), lLen + sizeof(char));
  276. val.ReleaseBuffer();
  277. asciiTextFormat->Data(hGlobal);
  278. }
  279. }
  280. void COleClipSource::InvertCase(CClip &clip)
  281. {
  282. IClipFormat *unicodeTextFormat = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
  283. if (unicodeTextFormat != NULL)
  284. {
  285. CString cs(unicodeTextFormat->GetAsCString());
  286. //free the old text we are going to replace it below with an upper case version
  287. unicodeTextFormat->Free();
  288. const int len = cs.GetLength();
  289. if (len > 0)
  290. {
  291. wchar_t* pText = cs.GetBuffer();
  292. for (int i = 0; i < len; i++)
  293. {
  294. wchar_t item = pText[i];
  295. if (theApp.m_icuString.IsUpperEx(item))
  296. {
  297. pText[i] = theApp.m_icuString.ToLowerEx(item);
  298. }
  299. else
  300. {
  301. pText[i] = theApp.m_icuString.ToUpperEx(item);
  302. }
  303. }
  304. }
  305. cs.ReleaseBuffer();
  306. HGLOBAL hGlobal = NewGlobalP(cs.GetBuffer(), ((len + 1) * sizeof(wchar_t)));
  307. unicodeTextFormat->Data(hGlobal);
  308. }
  309. IClipFormat *asciiTextFormat = clip.m_Formats.FindFormatEx(CF_TEXT);
  310. if (asciiTextFormat != NULL)
  311. {
  312. CStringA cs(asciiTextFormat->GetAsCStringA());
  313. //free the old text we are going to replace it below with an upper case version
  314. asciiTextFormat->Free();
  315. long len = cs.GetLength();
  316. if (len > 0)
  317. {
  318. char * pText = cs.GetBuffer();
  319. for (int i = 0; i < len; i++)
  320. {
  321. char item = pText[i];
  322. if (::isupper(item))
  323. {
  324. pText[i] = ::tolower(item);
  325. }
  326. else
  327. {
  328. pText[i] = ::toupper(item);
  329. }
  330. }
  331. }
  332. cs.ReleaseBuffer();
  333. HGLOBAL hGlobal = NewGlobalP(cs.GetBuffer(), (len + 1));
  334. asciiTextFormat->Data(hGlobal);
  335. }
  336. }
  337. void COleClipSource::CamelCase(CClip& clip)
  338. {
  339. IClipFormat* unicodeTextFormat = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
  340. if (unicodeTextFormat != NULL)
  341. {
  342. CString cs(unicodeTextFormat->GetAsCString());
  343. //free the old text we are going to replace it below with an upper case version
  344. unicodeTextFormat->Free();
  345. const int len = cs.GetLength();
  346. if (len > 0)
  347. {
  348. wchar_t* pText = cs.GetBuffer();
  349. bool setCapital = false;
  350. for (int i = 0; i < len; i++)
  351. {
  352. wchar_t item = pText[i];
  353. if (item == ' ')
  354. {
  355. setCapital = true;
  356. }
  357. else if (setCapital || i == 0)
  358. {
  359. if (theApp.m_icuString.IsUpperEx(item) == false)
  360. {
  361. pText[i] = theApp.m_icuString.ToUpperEx(item);
  362. }
  363. setCapital = false;
  364. }
  365. else if (theApp.m_icuString.IsUpperEx(item))
  366. {
  367. pText[i] = theApp.m_icuString.ToLowerEx(item);
  368. }
  369. }
  370. }
  371. cs.ReleaseBuffer();
  372. cs.Remove(' ');
  373. HGLOBAL hGlobal = NewGlobalP(cs.GetBuffer(), ((len + 1) * sizeof(wchar_t)));
  374. unicodeTextFormat->Data(hGlobal);
  375. }
  376. IClipFormat* asciiTextFormat = clip.m_Formats.FindFormatEx(CF_TEXT);
  377. if (asciiTextFormat != NULL)
  378. {
  379. CStringA cs(asciiTextFormat->GetAsCStringA());
  380. //free the old text we are going to replace it below with an upper case version
  381. asciiTextFormat->Free();
  382. long len = cs.GetLength();
  383. if (len > 0)
  384. {
  385. char* pText = cs.GetBuffer();
  386. bool setCapital = false;
  387. for (int i = 0; i < len; i++)
  388. {
  389. char item = pText[i];
  390. if (item == ' ')
  391. {
  392. setCapital = true;
  393. }
  394. else if (setCapital || i == 0)
  395. {
  396. if (::isupper(item) == false)
  397. {
  398. pText[i] = ::toupper(item);
  399. }
  400. setCapital = false;
  401. }
  402. else if(::isupper(item))
  403. {
  404. pText[i] = ::tolower(item);
  405. }
  406. }
  407. }
  408. cs.ReleaseBuffer();
  409. cs.Remove(' ');
  410. HGLOBAL hGlobal = NewGlobalP(cs.GetBuffer(), (len + 1));
  411. asciiTextFormat->Data(hGlobal);
  412. }
  413. }
  414. void COleClipSource::Capitalize(CClip &clip)
  415. {
  416. IClipFormat *unicodeTextFormat = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
  417. if (unicodeTextFormat != NULL)
  418. {
  419. CString cs(unicodeTextFormat->GetAsCString());
  420. //free the old text we are going to replace it below with an upper case version
  421. unicodeTextFormat->Free();
  422. CString val = theApp.m_icuString.ToLowerStringEx(cs);
  423. long len = val.GetLength();
  424. if (len > 0)
  425. {
  426. wchar_t * pText = val.GetBuffer();
  427. pText[0] = theApp.m_icuString.ToUpperEx(pText[0]);
  428. bool capitalize = false;
  429. for (int i = 1; i < len; i++)
  430. {
  431. wchar_t item = pText[i];
  432. if (item == ' ')
  433. {
  434. capitalize = true;
  435. }
  436. else if (capitalize)
  437. {
  438. pText[i] = theApp.m_icuString.ToUpperEx(item);
  439. capitalize = false;
  440. }
  441. }
  442. }
  443. val.ReleaseBuffer();
  444. HGLOBAL hGlobal = NewGlobalP(val.GetBuffer(), ((len + 1) * sizeof(wchar_t)));
  445. unicodeTextFormat->Data(hGlobal);
  446. }
  447. //my change
  448. //test
  449. //second test
  450. IClipFormat *asciiTextFormat = clip.m_Formats.FindFormatEx(CF_TEXT);
  451. if (asciiTextFormat != NULL)
  452. {
  453. CStringA cs(asciiTextFormat->GetAsCStringA());
  454. //free the old text we are going to replace it below with an upper case version
  455. asciiTextFormat->Free();
  456. CStringA val = cs.MakeLower();
  457. long len = val.GetLength();
  458. if (len > 0)
  459. {
  460. char * pText = val.GetBuffer();
  461. pText[0] = toupper(pText[0]);
  462. bool capitalize = false;
  463. for (int i = 1; i < len; i++)
  464. {
  465. char item = pText[i];
  466. if (item == ' ')
  467. {
  468. capitalize = true;
  469. }
  470. else if (capitalize)
  471. {
  472. pText[i] = toupper(item);
  473. capitalize = false;
  474. }
  475. }
  476. }
  477. val.ReleaseBuffer();
  478. HGLOBAL hGlobal = NewGlobalP(val.GetBuffer(), (len + 1));
  479. asciiTextFormat->Data(hGlobal);
  480. }
  481. }
  482. void COleClipSource::SentenceCase(CClip &clip)
  483. {
  484. IClipFormat *unicodeTextFormat = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
  485. if (unicodeTextFormat != NULL)
  486. {
  487. CString cs(unicodeTextFormat->GetAsCString());
  488. //free the old text we are going to replace it below with an upper case version
  489. unicodeTextFormat->Free();
  490. CString val = theApp.m_icuString.ToLowerStringEx(cs);;
  491. long len = val.GetLength();
  492. if (len > 0)
  493. {
  494. wchar_t * pText = val.GetBuffer();
  495. pText[0] = theApp.m_icuString.ToUpperEx(pText[0]);
  496. bool capitalize = false;
  497. for (int i = 1; i < len; i++)
  498. {
  499. wchar_t item = pText[i];
  500. if (item == '.' ||
  501. item == '!' ||
  502. item == '?')
  503. {
  504. capitalize = true;
  505. }
  506. else if (capitalize && item != ' ')
  507. {
  508. pText[i] = theApp.m_icuString.ToUpperEx(item);
  509. capitalize = false;
  510. }
  511. }
  512. }
  513. val.ReleaseBuffer();
  514. HGLOBAL hGlobal = NewGlobalP(val.GetBuffer(), ((len + 1) * sizeof(wchar_t)));
  515. unicodeTextFormat->Data(hGlobal);
  516. }
  517. IClipFormat *asciiTextFormat = clip.m_Formats.FindFormatEx(CF_TEXT);
  518. if (asciiTextFormat != NULL)
  519. {
  520. CStringA cs(asciiTextFormat->GetAsCStringA());
  521. //free the old text we are going to replace it below with an upper case version
  522. asciiTextFormat->Free();
  523. CStringA val = cs.MakeLower();
  524. long len = val.GetLength();
  525. if (len > 0)
  526. {
  527. char * pText = val.GetBuffer();
  528. pText[0] = toupper(pText[0]);
  529. bool capitalize = false;
  530. for (int i = 1; i < len; i++)
  531. {
  532. char item = pText[i];
  533. if (item == '.' ||
  534. item == '!' ||
  535. item == '?')
  536. {
  537. capitalize = true;
  538. }
  539. else if (capitalize && item != ' ')
  540. {
  541. pText[i] = toupper(item);
  542. capitalize = false;
  543. }
  544. }
  545. }
  546. val.ReleaseBuffer();
  547. HGLOBAL hGlobal = NewGlobalP(val.GetBuffer(), (len + 1));
  548. asciiTextFormat->Data(hGlobal);
  549. }
  550. }
  551. void COleClipSource::AsciiOnly(CClip& clip)
  552. {
  553. IClipFormat* unicodeTextFormat = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
  554. if (unicodeTextFormat != NULL)
  555. {
  556. CString cs(unicodeTextFormat->GetAsCString());
  557. CString newString;
  558. //free the old text we are going to replace it below with an upper case version
  559. unicodeTextFormat->Free();
  560. long len = cs.GetLength();
  561. if (len > 0)
  562. {
  563. for (int i = 0; i < len; i++)
  564. {
  565. wchar_t item = cs[i];
  566. if (item >= 0x00 && item <= 0x7F)
  567. {
  568. newString += item;
  569. }
  570. }
  571. }
  572. HGLOBAL hGlobal = NewGlobalP(newString.GetBuffer(), ((newString.GetLength() + 1) * sizeof(wchar_t)));
  573. unicodeTextFormat->Data(hGlobal);
  574. }
  575. IClipFormat* asciiTextFormat = clip.m_Formats.FindFormatEx(CF_TEXT);
  576. if (asciiTextFormat != NULL)
  577. {
  578. CStringA cs(asciiTextFormat->GetAsCStringA());
  579. CStringA newString;
  580. //free the old text we are going to replace it below with an upper case version
  581. asciiTextFormat->Free();
  582. long len = cs.GetLength();
  583. if (len > 0)
  584. {
  585. for (int i = 0; i < len; i++)
  586. {
  587. char item = cs[i];
  588. if (item >= 0x00 && item <= 0x7F)
  589. {
  590. newString += item;
  591. }
  592. }
  593. }
  594. HGLOBAL hGlobal = NewGlobalP(newString.GetBuffer(), (newString.GetLength() + 1));
  595. asciiTextFormat->Data(hGlobal);
  596. }
  597. }
  598. void COleClipSource::PlainTextFilter(CClip &clip)
  599. {
  600. bool foundText = false;
  601. INT_PTR hDropIndex = -1;
  602. INT_PTR count = clip.m_Formats.GetCount();
  603. for (INT_PTR i = 0; i < count; i++)
  604. {
  605. CClipFormat *pCF = &clip.m_Formats.ElementAt(i);
  606. if (pCF->m_cfType == CF_TEXT ||
  607. pCF->m_cfType == CF_UNICODETEXT)
  608. {
  609. foundText = true;
  610. }
  611. else if (pCF->m_cfType == CF_HDROP)
  612. {
  613. hDropIndex = i;
  614. }
  615. }
  616. if (foundText &&
  617. hDropIndex > -1)
  618. {
  619. clip.m_Formats.RemoveAt(hDropIndex);
  620. }
  621. else if (foundText == false &&
  622. hDropIndex > -1)
  623. {
  624. CCF_HDropAggregator HDrop;
  625. if (m_ClipIDs.AggregateData(HDrop, CF_HDROP, g_Opt.m_bMultiPasteReverse, m_pasteOptions.LimitFormatsToText()))
  626. {
  627. clip.m_Formats.RemoveAt(hDropIndex);
  628. CClipFormat format(CF_UNICODETEXT, HDrop.GetHGlobalAsString());
  629. clip.m_Formats.Add(format);
  630. format.m_autoDeleteData = false; //owned by m_DelayRenderedFormats
  631. }
  632. }
  633. }
  634. void COleClipSource::RemoveLineFeeds(CClip &clip)
  635. {
  636. IClipFormat *pUnicodeText = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
  637. if (pUnicodeText != NULL)
  638. {
  639. CStringW string(pUnicodeText->GetAsCString());
  640. pUnicodeText->Free();
  641. int count = string.Replace(_T("\r\n"), _T(" "));
  642. count = string.Replace(_T("\r"), _T(" "));
  643. count = string.Replace(_T("\n"), _T(" "));
  644. HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1) * sizeof(wchar_t)));
  645. pUnicodeText->Data(hGlobal);
  646. }
  647. IClipFormat *pAsciiText = clip.m_Formats.FindFormatEx(CF_TEXT);
  648. if (pAsciiText != NULL)
  649. {
  650. CStringA string(pAsciiText->GetAsCStringA());
  651. pAsciiText->Free();
  652. int count = string.Replace("\r\n", " ");
  653. count = string.Replace("\r", " ");
  654. count = string.Replace("\n", " ");
  655. HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
  656. pAsciiText->Data(hGlobal);
  657. }
  658. IClipFormat *pRTFFormat = clip.m_Formats.FindFormatEx(theApp.m_RTFFormat);
  659. if (pRTFFormat != NULL)
  660. {
  661. CStringA string(pRTFFormat->GetAsCStringA());
  662. pRTFFormat->Free();
  663. int count = string.Replace("\\par\r\n", " ");
  664. int count2 = string.Replace("\\par ", " ");
  665. int count3 = string.Replace("\\line ", " ");
  666. HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
  667. pRTFFormat->Data(hGlobal);
  668. }
  669. }
  670. void COleClipSource::AddLineFeeds(CClip &clip, int count)
  671. {
  672. IClipFormat *pUnicodeText = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
  673. if (pUnicodeText != NULL)
  674. {
  675. CStringW string(pUnicodeText->GetAsCString());
  676. pUnicodeText->Free();
  677. for(int i = 0; i < count; i++)
  678. {
  679. string += _T("\r\n");
  680. }
  681. HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1) * sizeof(wchar_t)));
  682. pUnicodeText->Data(hGlobal);
  683. }
  684. IClipFormat *pAsciiText = clip.m_Formats.FindFormatEx(CF_TEXT);
  685. if (pAsciiText != NULL)
  686. {
  687. CStringA string(pAsciiText->GetAsCStringA());
  688. pAsciiText->Free();
  689. for (int i = 0; i < count; i++)
  690. {
  691. string += "\r\n";
  692. }
  693. HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
  694. pAsciiText->Data(hGlobal);
  695. }
  696. IClipFormat *pRTFFormat = clip.m_Formats.FindFormatEx(theApp.m_RTFFormat);
  697. if (pRTFFormat != NULL)
  698. {
  699. CStringA string(pRTFFormat->GetAsCStringA());
  700. pRTFFormat->Free();
  701. for (int i = 0; i < count; i++)
  702. {
  703. int pos = string.ReverseFind('}');
  704. if (pos >= 0)
  705. {
  706. int count = string.Insert(pos, "\\par\r\n");
  707. }
  708. }
  709. HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
  710. pRTFFormat->Data(hGlobal);
  711. }
  712. }
  713. void COleClipSource::AddDateTime(CClip &clip)
  714. {
  715. IClipFormat *pUnicodeText = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
  716. if (pUnicodeText != NULL)
  717. {
  718. CStringW string(pUnicodeText->GetAsCString());
  719. pUnicodeText->Free();
  720. string += _T("\r\n");
  721. COleDateTime now(COleDateTime::GetCurrentTime());
  722. string += now.Format();
  723. HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1) * sizeof(wchar_t)));
  724. pUnicodeText->Data(hGlobal);
  725. }
  726. IClipFormat *pAsciiText = clip.m_Formats.FindFormatEx(CF_TEXT);
  727. if (pAsciiText != NULL)
  728. {
  729. CStringA string(pAsciiText->GetAsCStringA());
  730. pAsciiText->Free();
  731. string += "\r\n\r\n";
  732. COleDateTime now(COleDateTime::GetCurrentTime());
  733. string += CTextConvert::UnicodeToAnsi(now.Format());
  734. HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
  735. pAsciiText->Data(hGlobal);
  736. }
  737. IClipFormat *pRTFFormat = clip.m_Formats.FindFormatEx(theApp.m_RTFFormat);
  738. if (pRTFFormat != NULL)
  739. {
  740. CStringA string(pRTFFormat->GetAsCStringA());
  741. pRTFFormat->Free();
  742. int pos = string.ReverseFind('}');
  743. if (pos >= 0)
  744. {
  745. string += _T("\r\n\r\n");
  746. COleDateTime now(COleDateTime::GetCurrentTime());
  747. CStringA insert;
  748. insert.Format("\\par\r\n\\par\r\n%s", CTextConvert::UnicodeToAnsi(now.Format()));
  749. int count = string.Insert(pos, insert);
  750. }
  751. HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
  752. pRTFFormat->Data(hGlobal);
  753. }
  754. }
  755. void COleClipSource::TrimWhiteSpace(CClip &clip)
  756. {
  757. IClipFormat *pUnicodeText = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
  758. if (pUnicodeText != NULL)
  759. {
  760. CStringW string(pUnicodeText->GetAsCString());
  761. pUnicodeText->Free();
  762. string = string.Trim();
  763. string = string.Trim(_T("\t"));
  764. string = string.Trim(_T("\r"));
  765. string = string.Trim(_T("\n"));
  766. HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1) * sizeof(wchar_t)));
  767. pUnicodeText->Data(hGlobal);
  768. }
  769. IClipFormat *pAsciiText = clip.m_Formats.FindFormatEx(CF_TEXT);
  770. if (pAsciiText != NULL)
  771. {
  772. CStringA string(pAsciiText->GetAsCStringA());
  773. pAsciiText->Free();
  774. string = string.Trim();
  775. string = string.Trim("\t");
  776. string = string.Trim("\r");
  777. string = string.Trim("\n");
  778. HGLOBAL hGlobal = NewGlobalP(string.GetBuffer(), ((string.GetLength() + 1)));
  779. pAsciiText->Data(hGlobal);
  780. }
  781. }
  782. void COleClipSource::SaveDittoFileDataToFile(CClip &clip)
  783. {
  784. CFileRecieve hDrpData;
  785. CClipFormat* pCF;
  786. int hDropIndex = -1;
  787. bool savedFile = false;
  788. INT_PTR count = clip.m_Formats.GetSize();
  789. for (int i = 0; i < count; i++)
  790. {
  791. pCF = &clip.m_Formats.ElementAt(i);
  792. if (pCF->m_cfType == theApp.m_DittoFileData)
  793. {
  794. IClipFormat *dittoFileData = &clip.m_Formats.ElementAt(i);
  795. if (dittoFileData == NULL)
  796. continue;
  797. HGLOBAL data = dittoFileData->Data();
  798. char * stringData = (char *)GlobalLock(data);
  799. //original source is store in the first string ending in the null terminator
  800. CStringA src(stringData);
  801. stringData += src.GetLength() + 1;
  802. CStringA originalMd5(stringData);
  803. stringData += originalMd5.GetLength() + 1;
  804. int dataSize = (int)GlobalSize(data) - (src.GetLength() + 1) - (originalMd5.GetLength() + 1);
  805. CMd5 calcMd5;
  806. CStringA md5String = calcMd5.CalcMD5FromString(stringData, dataSize);
  807. CString unicodeFilePath = CTextConvert::Utf8ToUnicode(src);
  808. CString unicodeMd5 = CTextConvert::Utf8ToUnicode(md5String);
  809. Log(StrF(_T("Saving file contents from Ditto, original file: %s, size: %d, md5: %s"), unicodeFilePath, dataSize, unicodeMd5));
  810. if (md5String != originalMd5)
  811. {
  812. Log(StrF(_T("MD5 ERROR, file: %s, original md5: %s, calc md5: %s"), unicodeFilePath, originalMd5, md5String));
  813. continue;
  814. }
  815. using namespace nsPath;
  816. CPath path(unicodeFilePath);
  817. CString fileName = path.GetName();
  818. CString newFilePath = CGetSetOptions::GetPath(PATH_DRAG_FILES);
  819. newFilePath += fileName;
  820. CFile f;
  821. if (f.Open(newFilePath, CFile::modeWrite | CFile::modeCreate))
  822. {
  823. f.Write(stringData, dataSize);
  824. f.Close();
  825. savedFile = true;
  826. hDrpData.AddFile(newFilePath);
  827. }
  828. else
  829. {
  830. Log(StrF(_T("Error saving file: %s"), unicodeFilePath));
  831. }
  832. }
  833. else if (pCF->m_cfType == CF_HDROP)
  834. {
  835. hDropIndex = i;
  836. }
  837. }
  838. if (savedFile)
  839. {
  840. if (hDropIndex >= 0)
  841. {
  842. clip.m_Formats.RemoveAt(hDropIndex);
  843. }
  844. CClipFormat cf(CF_HDROP, hDrpData.CreateCF_HDROPBuffer());
  845. clip.m_Formats.Add(cf);
  846. //clip.m_Formats now owns the global data
  847. cf.m_autoDeleteData = false;
  848. }
  849. }
  850. void COleClipSource::Typoglycemia(CClip &clip)
  851. {
  852. IClipFormat *unicodeTextFormat = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
  853. if (unicodeTextFormat != NULL)
  854. {
  855. CString cs(unicodeTextFormat->GetAsCString());
  856. //free the old text we are going to replace it below with an upper case version
  857. unicodeTextFormat->Free();
  858. CString newString;
  859. CTokenizer token(cs, _T(' '));
  860. CString word;
  861. while (token.Next(word))
  862. {
  863. if(word.GetLength() > 3)
  864. {
  865. int end = word.GetLength();
  866. for (int i = end-1; i >= 0; i--)
  867. {
  868. if(word[i] == _T('.') ||
  869. word[i] == _T('!') ||
  870. word[i] == _T('?'))
  871. {
  872. end--;
  873. }
  874. else
  875. {
  876. break;
  877. }
  878. }
  879. if (end > 3)
  880. {
  881. std::uniform_int_distribution<int> dist(1, end - 2);
  882. std::random_device rd;
  883. for (int i = 1; i < end - 1; i++)
  884. {
  885. int newPos = dist(rd);
  886. CString cs;
  887. cs.Format(_T("pos: %d, rnd: %d\r\n"), i, newPos);
  888. OutputDebugString(cs);
  889. TCHAR temp = word.GetAt(i);
  890. word.SetAt(i, word.GetAt(newPos));
  891. word.SetAt(newPos, temp);
  892. }
  893. }
  894. newString += word;
  895. }
  896. else
  897. {
  898. newString += word;
  899. }
  900. newString += _T(' ');
  901. }
  902. long len = newString.GetLength();
  903. HGLOBAL hGlobal = NewGlobalP(newString.GetBuffer(), ((len + 1) * sizeof(wchar_t)));
  904. unicodeTextFormat->Data(hGlobal);
  905. }
  906. }
  907. INT_PTR COleClipSource::PutFormatOnClipboard(CClipFormats *pFormats)
  908. {
  909. Log(_T("Start of put format on clipboard"));
  910. CClipFormat* pCF;
  911. INT_PTR count = pFormats->GetSize();
  912. bool bDelayedRenderCF_HDROP = false;
  913. bool dittoFileData = false;
  914. INT_PTR i = 0;
  915. //see if the html format is in the list
  916. //if it is the list we will not paste CF_TEXT
  917. for(i = 0; i < count; i++)
  918. {
  919. pCF = &pFormats->ElementAt(i);
  920. if(pCF->m_cfType == theApp.m_RemoteCF_HDROP)
  921. {
  922. bDelayedRenderCF_HDROP = true;
  923. }
  924. if (pCF->m_cfType == theApp.m_DittoFileData)
  925. {
  926. dittoFileData = true;
  927. //save file data
  928. //adjust hdrop
  929. }
  930. }
  931. for(i = 0; i < count; i++)
  932. {
  933. pCF = &pFormats->ElementAt(i);
  934. if(bDelayedRenderCF_HDROP)
  935. {
  936. if(pCF->m_cfType == CF_HDROP)
  937. {
  938. LogSendRecieveInfo("Added delayed cf_hdrop to clipboard");
  939. DelayRenderData(pCF->m_cfType);
  940. }
  941. continue;
  942. }
  943. Log(StrF(_T("Setting clipboard type: %s to the clipboard"), GetFormatName(pCF->m_cfType)));
  944. CacheGlobalData(pCF->m_cfType, pCF->m_hgData);
  945. pCF->m_hgData = 0; // OLE owns it now
  946. }
  947. pFormats->RemoveAll();
  948. m_bLoadedFormats = true;
  949. Log(_T("End of put format on clipboard"));
  950. return count;
  951. }
  952. BOOL COleClipSource::OnRenderGlobalData(LPFORMATETC lpFormatEtc, HGLOBAL* phGlobal)
  953. {
  954. static bool bInHere = false;
  955. if(bInHere)
  956. {
  957. return FALSE;
  958. }
  959. bInHere = true;
  960. HGLOBAL hData = NULL;
  961. CClipFormat *pFind = m_DelayRenderedFormats.FindFormat(lpFormatEtc->cfFormat);
  962. if(pFind)
  963. {
  964. if(pFind->m_hgData)
  965. {
  966. hData = NewGlobalH(pFind->m_hgData, GlobalSize(pFind->m_hgData));
  967. }
  968. }
  969. else
  970. {
  971. if (m_pasteOptions.m_delayRenderLockout > 0 &&
  972. (GetTickCount() - m_pasteOptions.m_delayRenderLockout) < (DWORD)CGetSetOptions::GetDelayRenderLockout())
  973. {
  974. bInHere = false;
  975. return false;
  976. }
  977. LogSendRecieveInfo("Delayed Render, getting data from remote machine");
  978. CClip clip;
  979. if(m_ClipIDs.GetCount() > 0)
  980. {
  981. clip.LoadFormats(m_ClipIDs[0]);
  982. CClipFormat *pDittoDelayCF_HDROP = clip.m_Formats.FindFormat(theApp.m_RemoteCF_HDROP);
  983. CClipFormat *pCF_HDROP = clip.m_Formats.FindFormat(CF_HDROP);
  984. if(pDittoDelayCF_HDROP && pCF_HDROP)
  985. {
  986. CDittoCF_HDROP *pData = (CDittoCF_HDROP*)GlobalLock(pDittoDelayCF_HDROP->m_hgData);
  987. if(pData)
  988. {
  989. CString csComputerName;
  990. CString csIP;
  991. csIP = CTextConvert::Utf8ToUnicode(pData->m_cIP);
  992. csComputerName = CTextConvert::Utf8ToUnicode(pData->m_cComputerName);
  993. GlobalUnlock(pDittoDelayCF_HDROP->m_hgData);
  994. CString ipPort = csIP;
  995. if (pData->respondPort > 0)
  996. {
  997. ipPort.Format(_T("%s:%d"), csIP, pData->respondPort);
  998. }
  999. CString namePort = csComputerName;
  1000. if (pData->respondPort > 0)
  1001. {
  1002. namePort.Format(_T("%s:%d"), csComputerName, pData->respondPort);
  1003. }
  1004. CClient cl;
  1005. hData = cl.RequestCopiedFiles(*pCF_HDROP, ipPort, namePort);
  1006. }
  1007. }
  1008. else
  1009. {
  1010. hData = m_ClipIDs.Render(lpFormatEtc->cfFormat);
  1011. if (m_convertToHDROPOnDelayRender &&
  1012. hData == NULL &&
  1013. lpFormatEtc->cfFormat == CF_HDROP)
  1014. {
  1015. hData = ConvertToFileDrop();
  1016. }
  1017. }
  1018. }
  1019. //Add to a cache of already rendered data
  1020. //Windows seems to call this function multiple times
  1021. //so only the first time do we need to go get the data
  1022. HGLOBAL hCopy = NULL;
  1023. if(hData)
  1024. {
  1025. hCopy = NewGlobalH(hData, GlobalSize(hData));
  1026. }
  1027. CClipFormat format(lpFormatEtc->cfFormat, hCopy);
  1028. m_DelayRenderedFormats.Add(format);
  1029. format.m_autoDeleteData = false; //owned by m_DelayRenderedFormats
  1030. }
  1031. BOOL bRet = FALSE;
  1032. if(hData)
  1033. {
  1034. // if phGlobal is null, we can just give the allocated mem
  1035. // else, our data must fit within the GlobalSize(*phGlobal)
  1036. if(*phGlobal == 0)
  1037. {
  1038. *phGlobal = hData;
  1039. }
  1040. else
  1041. {
  1042. SIZE_T len = min(::GlobalSize(*phGlobal), ::GlobalSize(hData));
  1043. if(len)
  1044. {
  1045. CopyToGlobalHH(*phGlobal, hData, len);
  1046. }
  1047. ::GlobalFree(hData);
  1048. }
  1049. bRet = TRUE;
  1050. }
  1051. bInHere = false;
  1052. return bRet;
  1053. }
  1054. HGLOBAL COleClipSource::ConvertToFileDrop()
  1055. {
  1056. CString path = CGetSetOptions::GetPath(PATH_DRAG_FILES);
  1057. CreateDirectory(path, NULL);
  1058. CFileRecieve fileList;
  1059. int dragId = CGetSetOptions::GetDragId();
  1060. int origDragId = dragId;
  1061. auto customDragName = g_Opt.GetTempDragFileName();
  1062. if (customDragName != _T(""))
  1063. {
  1064. dragId = 1;
  1065. }
  1066. for (int i = 0; i < m_ClipIDs.GetCount(); i++)
  1067. {
  1068. CClip fileClip;
  1069. fileClip.LoadFormats(m_ClipIDs[i]);
  1070. CClipFormat *unicodeText = fileClip.m_Formats.FindFormat(CF_UNICODETEXT);
  1071. if (unicodeText)
  1072. {
  1073. CString name = _T("text");
  1074. CString file;
  1075. if (customDragName != _T(""))
  1076. {
  1077. name = customDragName;
  1078. file.Format(_T("%s%s.txt"), path, name);
  1079. }
  1080. else
  1081. {
  1082. file.Format(_T("%s%s_%d.txt"), path, name, dragId++);
  1083. }
  1084. fileClip.WriteTextToFile(file, TRUE, FALSE, FALSE);
  1085. fileList.AddFile(file);
  1086. continue;
  1087. }
  1088. CClipFormat *asciiText = fileClip.m_Formats.FindFormat(CF_TEXT);
  1089. if (asciiText)
  1090. {
  1091. CString name = _T("text");
  1092. CString file;
  1093. if (customDragName != _T(""))
  1094. {
  1095. name = customDragName;
  1096. file.Format(_T("%s%s.txt"), path, name);
  1097. }
  1098. else
  1099. {
  1100. file.Format(_T("%s%s_%d.txt"), path, name, dragId++);
  1101. }
  1102. fileClip.WriteTextToFile(file, FALSE, TRUE, FALSE);
  1103. fileList.AddFile(file);
  1104. continue;
  1105. }
  1106. CClipFormat *png = fileClip.m_Formats.FindFormat(theApp.m_PNG_Format);
  1107. CClipFormat *bitmap = fileClip.m_Formats.FindFormat(CF_DIB);
  1108. if (bitmap != NULL ||
  1109. png != NULL)
  1110. {
  1111. CString name = _T("image");
  1112. CString file;
  1113. if (customDragName != _T(""))
  1114. {
  1115. name = customDragName;
  1116. file.Format(_T("%s%s.png"), path, name);
  1117. }
  1118. else
  1119. {
  1120. file.Format(_T("%s%s_%d.png"), path, name, dragId++);
  1121. }
  1122. if (fileClip.WriteImageToFile(file))
  1123. {
  1124. fileList.AddFile(file);
  1125. }
  1126. }
  1127. }
  1128. if(customDragName == _T("") &&
  1129. dragId != origDragId)
  1130. {
  1131. CGetSetOptions::SetDragId(dragId);
  1132. }
  1133. HGLOBAL hData = fileList.CreateCF_HDROPBuffer();
  1134. return hData;
  1135. }
  1136. void COleClipSource::Slugify(CClip &clip)
  1137. {
  1138. IClipFormat *unicodeTextFormat = clip.m_Formats.FindFormatEx(CF_UNICODETEXT);
  1139. if (unicodeTextFormat != NULL)
  1140. {
  1141. CString cs(unicodeTextFormat->GetAsCString());
  1142. //free the old text we are going to replace it below with an upper case version
  1143. unicodeTextFormat->Free();
  1144. CString newString = slugify(cs.GetString(), CGetSetOptions::GetSlugifySeparator().GetString()).c_str();
  1145. long len = newString.GetLength();
  1146. HGLOBAL hGlobal = NewGlobalP(newString.GetBuffer(), ((len + 1) * sizeof(wchar_t)));
  1147. unicodeTextFormat->Data(hGlobal);
  1148. }
  1149. }