Clip.cpp 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348
  1. // ProcessCopy.cpp: implementation of the CProcessCopy class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "CP_Main.h"
  6. #include "Clip.h"
  7. #include "DatabaseUtilities.h"
  8. #include "Crc32Dynamic.h"
  9. #include "sqlite\CppSQLite3.h"
  10. #include "shared/TextConvert.h"
  11. #include "zlib/zlib.h"
  12. #include "Misc.h"
  13. #include <Mmsystem.h>
  14. #include "Path.h"
  15. #ifdef _DEBUG
  16. #undef THIS_FILE
  17. static char THIS_FILE[]=__FILE__;
  18. #define new DEBUG_NEW
  19. #endif
  20. /*----------------------------------------------------------------------------*\
  21. COleDataObjectEx
  22. \*----------------------------------------------------------------------------*/
  23. HGLOBAL COleDataObjectEx::GetGlobalData(CLIPFORMAT cfFormat, LPFORMATETC lpFormatEtc)
  24. {
  25. HGLOBAL hGlobal = COleDataObject::GetGlobalData(cfFormat, lpFormatEtc);
  26. if(hGlobal)
  27. {
  28. if(!::IsValid(hGlobal))
  29. {
  30. Log( StrF(
  31. _T("COleDataObjectEx::GetGlobalData(\"%s\"): ERROR: Invalid (NULL) data returned."),
  32. GetFormatName(cfFormat) ) );
  33. ::GlobalFree( hGlobal );
  34. hGlobal = NULL;
  35. }
  36. return hGlobal;
  37. }
  38. // The data isn't in global memory, so try getting an IStream interface to it.
  39. STGMEDIUM stg;
  40. if(!GetData(cfFormat, &stg))
  41. {
  42. return 0;
  43. }
  44. switch(stg.tymed)
  45. {
  46. case TYMED_HGLOBAL:
  47. hGlobal = stg.hGlobal;
  48. break;
  49. case TYMED_ISTREAM:
  50. {
  51. UINT uDataSize;
  52. LARGE_INTEGER li;
  53. ULARGE_INTEGER uli;
  54. li.HighPart = li.LowPart = 0;
  55. if ( SUCCEEDED( stg.pstm->Seek ( li, STREAM_SEEK_END, &uli )))
  56. {
  57. hGlobal = GlobalAlloc(GMEM_MOVEABLE | GMEM_SHARE, uli.LowPart );
  58. void* pv = GlobalLock(hGlobal);
  59. stg.pstm->Seek(li, STREAM_SEEK_SET, NULL);
  60. HRESULT result = stg.pstm->Read(pv, uli.LowPart, (PULONG)&uDataSize);
  61. GlobalUnlock(hGlobal);
  62. if( FAILED(result) )
  63. hGlobal = GlobalFree(hGlobal);
  64. }
  65. break; // case TYMED_ISTREAM
  66. }
  67. } // end switch
  68. ReleaseStgMedium(&stg);
  69. if(hGlobal && !::IsValid(hGlobal))
  70. {
  71. Log( StrF(
  72. _T("COleDataObjectEx::GetGlobalData(\"%s\"): ERROR: Invalid (NULL) data returned."),
  73. GetFormatName(cfFormat)));
  74. ::GlobalFree(hGlobal);
  75. hGlobal = NULL;
  76. }
  77. return hGlobal;
  78. }
  79. /*----------------------------------------------------------------------------*\
  80. CClipFormat - holds the data of one clip format.
  81. \*----------------------------------------------------------------------------*/
  82. CClipFormat::CClipFormat(CLIPFORMAT cfType, HGLOBAL hgData, int parentId)
  83. {
  84. m_cfType = cfType;
  85. m_hgData = hgData;
  86. m_autoDeleteData = true;
  87. m_parentId = parentId;
  88. }
  89. CClipFormat::~CClipFormat()
  90. {
  91. Free();
  92. }
  93. void CClipFormat::Clear()
  94. {
  95. m_cfType = 0;
  96. m_hgData = 0;
  97. m_dataId = -1;
  98. m_parentId = -1;
  99. }
  100. void CClipFormat::Free()
  101. {
  102. if(m_autoDeleteData)
  103. {
  104. if(m_hgData)
  105. {
  106. m_hgData = ::GlobalFree( m_hgData );
  107. m_hgData = NULL;
  108. }
  109. }
  110. }
  111. /*----------------------------------------------------------------------------*\
  112. CClipFormats - holds an array of CClipFormat
  113. \*----------------------------------------------------------------------------*/
  114. // returns a pointer to the CClipFormat in this array which matches the given type
  115. // or NULL if that type doesn't exist in this array.
  116. CClipFormat* CClipFormats::FindFormat(UINT cfType)
  117. {
  118. CClipFormat* pCF;
  119. INT_PTR count = GetSize();
  120. for(int i=0; i < count; i++)
  121. {
  122. pCF = &ElementAt(i);
  123. if(pCF->m_cfType == cfType)
  124. return pCF;
  125. }
  126. return NULL;
  127. }
  128. /*----------------------------------------------------------------------------*\
  129. CClip - holds multiple CClipFormats and CopyClipboard() statistics
  130. \*----------------------------------------------------------------------------*/
  131. DWORD CClip::m_LastAddedCRC = 0;
  132. int CClip::m_lastAddedID = -1;
  133. CClip::CClip() :
  134. m_id(0),
  135. m_CRC(0),
  136. m_parentId(-1),
  137. m_dontAutoDelete(FALSE),
  138. m_shortCut(0),
  139. m_bIsGroup(FALSE),
  140. m_param1(0),
  141. m_clipOrder(0),
  142. m_stickyClipOrder(INVALID_STICKY),
  143. m_stickyClipGroupOrder(INVALID_STICKY),
  144. m_clipGroupOrder(0),
  145. m_globalShortCut(FALSE),
  146. m_moveToGroupShortCut(0),
  147. m_globalMoveToGroupShortCut(FALSE)
  148. {
  149. m_copyReason = CopyReasonEnum::COPY_TO_UNKOWN;
  150. }
  151. CClip::~CClip()
  152. {
  153. EmptyFormats();
  154. }
  155. void CClip::Clear()
  156. {
  157. m_id = -1;
  158. m_Time = 0;
  159. m_Desc = "";
  160. m_CRC = 0;
  161. m_parentId = -1;
  162. m_dontAutoDelete = FALSE;
  163. m_shortCut = 0;
  164. m_bIsGroup = FALSE;
  165. m_csQuickPaste = "";
  166. m_param1 = 0;
  167. m_globalShortCut = FALSE;
  168. m_moveToGroupShortCut = 0;
  169. m_globalMoveToGroupShortCut = 0;
  170. EmptyFormats();
  171. }
  172. const CClip& CClip::operator=(const CClip &clip)
  173. {
  174. const CClipFormat* pCF;
  175. m_id = clip.m_id;
  176. m_Time = clip.m_Time;
  177. m_lastPasteDate = clip.m_lastPasteDate;
  178. m_CRC = clip.m_CRC;
  179. m_parentId = clip.m_parentId;
  180. m_dontAutoDelete = clip.m_dontAutoDelete;
  181. m_shortCut = clip.m_shortCut;
  182. m_bIsGroup = clip.m_bIsGroup;
  183. m_csQuickPaste = clip.m_csQuickPaste;
  184. m_moveToGroupShortCut = clip.m_moveToGroupShortCut;
  185. m_globalMoveToGroupShortCut = clip.m_globalMoveToGroupShortCut;
  186. INT_PTR nCount = clip.m_Formats.GetSize();
  187. for(int i = 0; i < nCount; i++)
  188. {
  189. pCF = &clip.m_Formats.GetData()[i];
  190. LPVOID pvData = GlobalLock(pCF->m_hgData);
  191. if(pvData)
  192. {
  193. AddFormat(pCF->m_cfType, pvData, (UINT)GlobalSize(pCF->m_hgData));
  194. }
  195. GlobalUnlock(pCF->m_hgData);
  196. }
  197. //Set this after since in could get the wrong description in AddFormat
  198. m_Desc = clip.m_Desc;
  199. return *this;
  200. }
  201. void CClip::EmptyFormats()
  202. {
  203. // free global memory in m_Formats
  204. for(INT_PTR i = m_Formats.GetSize()-1; i >= 0; i--)
  205. {
  206. m_Formats[i].Free();
  207. m_Formats.RemoveAt(i);
  208. }
  209. }
  210. // Adds a new Format to this Clip by copying the given data.
  211. bool CClip::AddFormat(CLIPFORMAT cfType, void* pData, UINT nLen)
  212. {
  213. ASSERT(pData && nLen);
  214. HGLOBAL hGlobal = ::NewGlobalP(pData, nLen);
  215. ASSERT(hGlobal);
  216. // update the Clip statistics
  217. m_Time = m_Time.GetCurrentTime();
  218. if(!SetDescFromText(hGlobal, true))
  219. SetDescFromType();
  220. CClipFormat format(cfType,hGlobal);
  221. CClipFormat *pFormat;
  222. pFormat = m_Formats.FindFormat(cfType);
  223. // if the format type already exists as part of this clip, replace the data
  224. if(pFormat)
  225. {
  226. pFormat->Free();
  227. pFormat->m_hgData = format.m_hgData;
  228. }
  229. else
  230. {
  231. m_Formats.Add(format);
  232. }
  233. format.m_hgData = 0; // now owned by m_Formats
  234. return true;
  235. }
  236. // Fills this CClip with the contents of the clipboard.
  237. bool CClip::LoadFromClipboard(CClipTypes* pClipTypes, bool checkClipboardIgnore)
  238. {
  239. COleDataObjectEx oleData;
  240. CClipTypes defaultTypes;
  241. CClipTypes* pTypes = pClipTypes;
  242. // m_Formats should be empty when this is called.
  243. ASSERT(m_Formats.GetSize() == 0);
  244. // If the data is supposed to be private, then return
  245. if(::IsClipboardFormatAvailable(theApp.m_cfIgnoreClipboard))
  246. {
  247. Log(_T("Clipboard ignore type is on the clipboard, skipping this clipboard change"));
  248. return false;
  249. }
  250. //If we are saving a multi paste then delay us connecting to the clipboard
  251. //to allow the ctrl-v to do a paste
  252. if(::IsClipboardFormatAvailable(theApp.m_cfDelaySavingData))
  253. {
  254. Log(_T("Delay clipboard type is on the clipboard, delaying 1500 ms to allow ctrl-v to work"));
  255. Sleep(1500);
  256. }
  257. //Attach to the clipboard
  258. if(!oleData.AttachClipboard())
  259. {
  260. Log(_T("failed to attache to clipboard, skipping this clipboard change"));
  261. ASSERT(0); // does this ever happen?
  262. return false;
  263. }
  264. oleData.EnsureClipboardObject();
  265. // if no types were given, get only the first (most important) type.
  266. // (subsequent types could be synthetic due to automatic type conversions)
  267. if(pTypes == NULL || pTypes->GetSize() == 0)
  268. {
  269. ASSERT(0); // this feature is not currently used... it is an error if it is.
  270. FORMATETC formatEtc;
  271. oleData.BeginEnumFormats();
  272. oleData.GetNextFormat(&formatEtc);
  273. defaultTypes.Add(formatEtc.cfFormat);
  274. pTypes = &defaultTypes;
  275. }
  276. m_Desc = "[Ditto Error] BAD DESCRIPTION";
  277. // Get Description String
  278. // NOTE: We make sure that the description always corresponds to the
  279. // data saved by using the exact same globalmem instance as the source
  280. // for both... i.e. we only fetch the description format type once.
  281. CClipFormat cfDesc;
  282. bool bIsDescSet = false;
  283. cfDesc.m_cfType = CF_UNICODETEXT;
  284. if(oleData.IsDataAvailable(cfDesc.m_cfType))
  285. {
  286. cfDesc.m_hgData = oleData.GetGlobalData(cfDesc.m_cfType);
  287. bIsDescSet = SetDescFromText(cfDesc.m_hgData, true);
  288. Log(StrF(_T("Tried to set description from cf_unicode text, Set: %d, Desc: [%s]"), bIsDescSet, m_Desc.Left(30)));
  289. }
  290. if(bIsDescSet == false)
  291. {
  292. cfDesc.m_cfType = CF_TEXT;
  293. if(oleData.IsDataAvailable(cfDesc.m_cfType))
  294. {
  295. cfDesc.m_hgData = oleData.GetGlobalData(cfDesc.m_cfType);
  296. bIsDescSet = SetDescFromText(cfDesc.m_hgData, false);
  297. Log(StrF(_T("Tried to set description from cf_text text, Set: %d, Desc: [%s]"), bIsDescSet, m_Desc.Left(30)));
  298. }
  299. }
  300. INT_PTR nSize;
  301. CClipFormat cf;
  302. INT_PTR numTypes = pTypes->GetSize();
  303. Log(StrF(_T("Begin enumerating over supported types, Count: %d"), numTypes));
  304. for(int i = 0; i < numTypes; i++)
  305. {
  306. cf.m_cfType = pTypes->ElementAt(i);
  307. BOOL bSuccess = false;
  308. Log(StrF(_T("Begin try and load type %s"), GetFormatName(cf.m_cfType)));
  309. // is this the description we already fetched?
  310. if(cf.m_cfType == cfDesc.m_cfType)
  311. {
  312. cf = cfDesc;
  313. cfDesc.m_hgData = 0; // cf owns it now (to go into m_Formats)
  314. }
  315. else if(!oleData.IsDataAvailable(cf.m_cfType))
  316. {
  317. Log(StrF(_T("End of load - Data is not available for type %s"), GetFormatName(cf.m_cfType)));
  318. continue;
  319. }
  320. else
  321. {
  322. cf.m_hgData = oleData.GetGlobalData(cf.m_cfType);
  323. }
  324. if(cf.m_hgData)
  325. {
  326. nSize = GlobalSize(cf.m_hgData);
  327. if(nSize > 0)
  328. {
  329. if(g_Opt.m_lMaxClipSizeInBytes > 0 && (int)nSize > g_Opt.m_lMaxClipSizeInBytes)
  330. {
  331. CString cs;
  332. cs.Format(_T("Maximum clip size reached max size = %d, clip size = %d"), g_Opt.m_lMaxClipSizeInBytes, nSize);
  333. Log(cs);
  334. oleData.Release();
  335. return false;
  336. }
  337. ASSERT(::IsValid(cf.m_hgData));
  338. m_Formats.Add(cf);
  339. bSuccess = true;
  340. }
  341. else
  342. {
  343. ASSERT(FALSE); // a valid GlobalMem with 0 size is strange
  344. cf.Free();
  345. Log(StrF(_T("Data length is 0 for type %s"), GetFormatName(cf.m_cfType)));
  346. }
  347. cf.m_hgData = 0; // m_Formats owns it now
  348. }
  349. Log(StrF(_T("End of load - type %s, Success: %d"), GetFormatName(cf.m_cfType), bSuccess));
  350. }
  351. Log(StrF(_T("End enumerating over supported types, Count: %d"), numTypes));
  352. m_Time = CTime::GetCurrentTime();
  353. if(!bIsDescSet)
  354. {
  355. SetDescFromType();
  356. Log(StrF(_T("Setting description from type, Desc: [%s]"), m_Desc.Left(30)));
  357. }
  358. // if the description was in a type that is not supported,
  359. //we have to free it since it wasn't added to m_Formats
  360. if(cfDesc.m_hgData)
  361. {
  362. cfDesc.Free();
  363. }
  364. oleData.Release();
  365. if(m_Formats.GetSize() == 0)
  366. {
  367. Log(_T("No clip types were in supported types array"));
  368. return false;
  369. }
  370. return true;
  371. }
  372. bool CClip::SetDescFromText(HGLOBAL hgData, bool unicode)
  373. {
  374. if(hgData == 0)
  375. return false;
  376. bool bRet = false;
  377. INT_PTR bufLen = 0;
  378. if(unicode)
  379. {
  380. TCHAR* text = (TCHAR *) GlobalLock(hgData);
  381. bufLen = GlobalSize(hgData);
  382. m_Desc = text;
  383. bRet = true;
  384. }
  385. else
  386. {
  387. char* text = (char *) GlobalLock(hgData);
  388. bufLen = GlobalSize(hgData);
  389. m_Desc = text;
  390. bRet = true;
  391. }
  392. if(bufLen > g_Opt.m_bDescTextSize)
  393. {
  394. m_Desc = m_Desc.Left(g_Opt.m_bDescTextSize);
  395. }
  396. //Unlock the data
  397. GlobalUnlock(hgData);
  398. return bRet;
  399. }
  400. bool CClip::SetDescFromType()
  401. {
  402. INT_PTR size = m_Formats.GetSize();
  403. if(size <= 0)
  404. {
  405. return false;
  406. }
  407. int nCF_HDROPIndex = -1;
  408. for(int i = 0; i < size; i++)
  409. {
  410. if(m_Formats[i].m_cfType == CF_HDROP)
  411. {
  412. nCF_HDROPIndex = i;
  413. }
  414. }
  415. if(nCF_HDROPIndex >= 0)
  416. {
  417. using namespace nsPath;
  418. HDROP drop = (HDROP)GlobalLock(m_Formats[nCF_HDROPIndex].m_hgData);
  419. int nNumFiles = min(5, DragQueryFile(drop, -1, NULL, 0));
  420. if(nNumFiles > 1)
  421. m_Desc = "Copied Files - ";
  422. else
  423. m_Desc = "Copied File - ";
  424. TCHAR file[MAX_PATH];
  425. for(int nFile = 0; nFile < nNumFiles; nFile++)
  426. {
  427. if(DragQueryFile(drop, nFile, file, sizeof(file)) > 0)
  428. {
  429. CPath path(file);
  430. m_Desc += path.GetName();
  431. m_Desc += " - ";
  432. m_Desc += file;
  433. m_Desc += "\n";
  434. }
  435. }
  436. GlobalUnlock(m_Formats[nCF_HDROPIndex].m_hgData);
  437. }
  438. else
  439. {
  440. m_Desc = GetFormatName(m_Formats[0].m_cfType);
  441. }
  442. return m_Desc.GetLength() > 0;
  443. }
  444. bool CClip::AddToDB(bool bCheckForDuplicates)
  445. {
  446. bool bResult;
  447. try
  448. {
  449. m_CRC = GenerateCRC();
  450. if(bCheckForDuplicates &&
  451. m_parentId < 0)
  452. {
  453. int nID = FindDuplicate();
  454. if(nID >= 0)
  455. {
  456. MakeLatestOrder();
  457. MakeLatestGroupOrder();
  458. CString sql;
  459. sql.Format(_T("UPDATE Main SET clipOrder = %f, lastPasteDate = %d where lID = %d;"),
  460. m_clipOrder, (int)CTime::GetCurrentTime().GetTime(), nID);
  461. int ret = theApp.m_db.execDML(sql);
  462. int groupRet = -1;
  463. if(m_parentId > -1)
  464. {
  465. sql.Format(_T("UPDATE Main SET clipGroupOrder = %f where lID = %d;"),
  466. m_clipGroupOrder, nID);
  467. groupRet = theApp.m_db.execDML(sql);
  468. }
  469. m_id = nID;
  470. Log(StrF(_T("Found duplicate clip in db, Id: %d, ParentId: %d crc: %d, NewOrder: %f, GroupOrder %f, Ret: %d, GroupRet: %d, SQL: %s"),
  471. nID, m_parentId, m_CRC, m_clipOrder, m_clipGroupOrder, ret, groupRet, sql));
  472. return true;
  473. }
  474. }
  475. }
  476. CATCH_SQLITE_EXCEPTION_AND_RETURN(false)
  477. bResult = false;
  478. if(AddToMainTable())
  479. {
  480. bResult = AddToDataTable();
  481. }
  482. if(bResult)
  483. {
  484. if(g_Opt.m_csPlaySoundOnCopy.IsEmpty() == FALSE)
  485. PlaySound(g_Opt.m_csPlaySoundOnCopy, NULL, SND_FILENAME|SND_ASYNC);
  486. }
  487. // should be emptied by AddToDataTable
  488. //ASSERT(m_Formats.GetSize() == 0);
  489. return bResult;
  490. }
  491. // if a duplicate exists, set recset to the duplicate and return true
  492. int CClip::FindDuplicate()
  493. {
  494. try
  495. {
  496. //If they are allowing duplicates still check
  497. //the last copied item
  498. if(g_Opt.m_bAllowDuplicates)
  499. {
  500. if(m_CRC == m_LastAddedCRC)
  501. return m_lastAddedID;
  502. }
  503. else
  504. {
  505. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID FROM Main WHERE CRC = %d"), m_CRC);
  506. if(q.eof() == false)
  507. {
  508. return q.getIntField(_T("lID"));
  509. }
  510. }
  511. }
  512. CATCH_SQLITE_EXCEPTION
  513. return -1;
  514. }
  515. DWORD CClip::GenerateCRC()
  516. {
  517. CClipFormat* pCF;
  518. DWORD dwCRC = 0xFFFFFFFF;
  519. CCrc32Dynamic *pCrc32 = new CCrc32Dynamic;
  520. if(pCrc32)
  521. {
  522. //Generate a CRC value for all copied data
  523. INT_PTR size = m_Formats.GetSize();
  524. for(int i = 0; i < size ; i++)
  525. {
  526. pCF = & m_Formats.ElementAt(i);
  527. const unsigned char *Data = (const unsigned char *)GlobalLock(pCF->m_hgData);
  528. if(Data)
  529. {
  530. pCrc32->GenerateCrc32((const LPBYTE)Data, (DWORD)GlobalSize(pCF->m_hgData), dwCRC);
  531. }
  532. GlobalUnlock(pCF->m_hgData);
  533. }
  534. dwCRC = ~dwCRC;
  535. delete pCrc32;
  536. }
  537. return dwCRC;
  538. }
  539. // assigns m_ID
  540. bool CClip::AddToMainTable()
  541. {
  542. try
  543. {
  544. m_Desc.Replace(_T("'"), _T("''"));
  545. m_csQuickPaste.Replace(_T("'"), _T("''"));
  546. CString cs;
  547. cs.Format(_T("INSERT into Main (lDate, mText, lShortCut, lDontAutoDelete, CRC, bIsGroup, lParentID, QuickPasteText, clipOrder, clipGroupOrder, globalShortCut, lastPasteDate, stickyClipOrder, stickyClipGroupOrder, MoveToGroupShortCut, GlobalMoveToGroupShortCut) ")
  548. _T("values(%d, '%s', %d, %d, %d, %d, %d, '%s', %f, %f, %d, %d, %f, %f, %d, %d);"),
  549. (int)m_Time.GetTime(),
  550. m_Desc,
  551. m_shortCut,
  552. m_dontAutoDelete,
  553. m_CRC,
  554. m_bIsGroup,
  555. m_parentId,
  556. m_csQuickPaste,
  557. m_clipOrder,
  558. m_clipGroupOrder,
  559. m_globalShortCut,
  560. (int)CTime::GetCurrentTime().GetTime(),
  561. m_stickyClipOrder,
  562. m_stickyClipGroupOrder,
  563. m_moveToGroupShortCut,
  564. m_globalMoveToGroupShortCut);
  565. theApp.m_db.execDML(cs);
  566. m_id = (long)theApp.m_db.lastRowId();
  567. Log(StrF(_T("Added clip to main table, Id: %d, ParentId: %d Desc: %s, Order: %f, GroupOrder: %f"), m_id, m_parentId, m_Desc, m_clipOrder, m_clipGroupOrder));
  568. m_LastAddedCRC = m_CRC;
  569. m_lastAddedID = m_id;
  570. }
  571. CATCH_SQLITE_EXCEPTION_AND_RETURN(false)
  572. return true;
  573. }
  574. bool CClip::ModifyMainTable()
  575. {
  576. bool bRet = false;
  577. try
  578. {
  579. m_Desc.Replace(_T("'"), _T("''"));
  580. m_csQuickPaste.Replace(_T("'"), _T("''"));
  581. theApp.m_db.execDMLEx(_T("UPDATE Main SET lShortCut = %d, ")
  582. _T("mText = '%s', ")
  583. _T("lParentID = %d, ")
  584. _T("lDontAutoDelete = %d, ")
  585. _T("QuickPasteText = '%s', ")
  586. _T("clipOrder = %f, ")
  587. _T("clipGroupOrder = %f, ")
  588. _T("globalShortCut = %d, ")
  589. _T("stickyClipOrder = %f, ")
  590. _T("stickyClipGroupOrder = %f, ")
  591. _T("MoveToGroupShortCut = %d, ")
  592. _T("GlobalMoveToGroupShortCut = %d ")
  593. _T("WHERE lID = %d;"),
  594. m_shortCut,
  595. m_Desc,
  596. m_parentId,
  597. m_dontAutoDelete,
  598. m_csQuickPaste,
  599. m_clipOrder,
  600. m_clipGroupOrder,
  601. m_globalShortCut,
  602. m_stickyClipOrder,
  603. m_stickyClipGroupOrder,
  604. m_moveToGroupShortCut,
  605. m_globalMoveToGroupShortCut,
  606. m_id);
  607. bRet = true;
  608. }
  609. CATCH_SQLITE_EXCEPTION_AND_RETURN(false)
  610. return bRet;
  611. }
  612. // Empties m_Formats as it saves them to the Data Table.
  613. bool CClip::AddToDataTable()
  614. {
  615. CClipFormat* pCF;
  616. try
  617. {
  618. CppSQLite3Statement stmt = theApp.m_db.compileStatement(_T("insert into Data values (NULL, ?, ?, ?);"));
  619. for(INT_PTR i = m_Formats.GetSize()-1; i >= 0 ; i--)
  620. {
  621. pCF = &m_Formats.ElementAt(i);
  622. CString formatName = GetFormatName(pCF->m_cfType);
  623. int clipSize = 0;
  624. stmt.bind(1, m_id);
  625. stmt.bind(2, formatName);
  626. const unsigned char *Data = (const unsigned char *)GlobalLock(pCF->m_hgData);
  627. if(Data)
  628. {
  629. clipSize = (int)GlobalSize(pCF->m_hgData);
  630. stmt.bind(3, Data, clipSize);
  631. }
  632. GlobalUnlock(pCF->m_hgData);
  633. stmt.execDML();
  634. stmt.reset();
  635. pCF->m_dataId = (long)theApp.m_db.lastRowId();
  636. Log(StrF(_T("Added ClipData to DB, Id: %d, ParentId: %d Type: %s, size: %d"), pCF->m_dataId, m_id, formatName, clipSize));
  637. }
  638. }
  639. CATCH_SQLITE_EXCEPTION_AND_RETURN(false)
  640. return true;
  641. }
  642. void CClip::MoveUp()
  643. {
  644. if (m_stickyClipOrder == INVALID_STICKY)
  645. {
  646. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, clipOrder FROM Main Where clipOrder > %f ORDER BY clipOrder ASC LIMIT 1"), m_clipOrder);
  647. if (q.eof() == false)
  648. {
  649. int idAbove = q.getIntField(_T("lID"));
  650. double orderAbove = q.getFloatField(_T("clipOrder"));
  651. CppSQLite3Query q2 = theApp.m_db.execQueryEx(_T("SELECT lID, clipOrder FROM Main Where clipOrder > %f ORDER BY clipOrder ASC LIMIT 1"), orderAbove);
  652. if (q2.eof() == false)
  653. {
  654. int idTwoAbove = q2.getIntField(_T("lID"));
  655. double orderTwoAbove = q2.getFloatField(_T("clipOrder"));
  656. m_clipOrder = orderAbove + (orderTwoAbove - orderAbove) / 2.0;
  657. }
  658. else
  659. {
  660. m_clipOrder = orderAbove + 1;
  661. }
  662. }
  663. }
  664. else
  665. {
  666. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT lID, stickyClipOrder FROM Main Where stickyClipOrder > %f ORDER BY clipOrder ASC LIMIT 1"), m_stickyClipOrder);
  667. if (q.eof() == false)
  668. {
  669. int idAbove = q.getIntField(_T("lID"));
  670. double orderAbove = q.getFloatField(_T("stickyClipOrder"));
  671. CppSQLite3Query q2 = theApp.m_db.execQueryEx(_T("SELECT lID, stickyClipOrder FROM Main Where stickyClipOrder > %f ORDER BY clipOrder ASC LIMIT 1"), orderAbove);
  672. if (q2.eof() == false)
  673. {
  674. int idTwoAbove = q2.getIntField(_T("lID"));
  675. double orderTwoAbove = q2.getFloatField(_T("stickyClipOrder"));
  676. m_stickyClipOrder = orderAbove + (orderTwoAbove - orderAbove) / 2.0;
  677. }
  678. else
  679. {
  680. m_stickyClipOrder = orderAbove + 1;
  681. }
  682. }
  683. }
  684. }
  685. void CClip::MakeStickyTop(int parentId)
  686. {
  687. if (parentId < 0)
  688. {
  689. m_stickyClipOrder = GetNewTopSticky(parentId, m_id);
  690. }
  691. else
  692. {
  693. m_stickyClipGroupOrder = GetNewTopSticky(parentId, m_id);
  694. }
  695. }
  696. void CClip::MakeStickyLast(int parentId)
  697. {
  698. if (parentId < 0)
  699. {
  700. m_stickyClipOrder = GetNewLastSticky(parentId, m_id);
  701. }
  702. else
  703. {
  704. m_stickyClipGroupOrder = GetNewLastSticky(parentId, m_id);
  705. }
  706. }
  707. void CClip::RemoveStickySetting(int parentId)
  708. {
  709. if (parentId < 0)
  710. {
  711. m_stickyClipOrder = INVALID_STICKY;
  712. }
  713. else
  714. {
  715. m_stickyClipGroupOrder = INVALID_STICKY;
  716. }
  717. }
  718. double CClip::GetNewTopSticky(int parentId, int clipId)
  719. {
  720. double newOrder = 1;
  721. double existingMaxOrder = 0;
  722. CString existingDesc = _T("");
  723. try
  724. {
  725. if (parentId < 0)
  726. {
  727. CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT stickyClipOrder, mText FROM Main ORDER BY stickyClipOrder DESC LIMIT 1"));
  728. if (q.eof() == false)
  729. {
  730. existingMaxOrder = q.getFloatField(_T("stickyClipOrder"));
  731. existingDesc = q.getStringField(_T("mText"));
  732. newOrder = existingMaxOrder + 1;
  733. }
  734. }
  735. else
  736. {
  737. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT stickyClipGroupOrder, mText FROM Main WHERE lParentID = %d ORDER BY stickyClipGroupOrder DESC LIMIT 1"), parentId);
  738. if (q.eof() == false)
  739. {
  740. existingMaxOrder = q.getFloatField(_T("stickyClipGroupOrder"));
  741. newOrder = existingMaxOrder + 1;
  742. }
  743. }
  744. if (newOrder == 0.0)
  745. newOrder += 1;
  746. Log(StrF(_T("GetNewTopSticky, Id: %d, parentId: %d, CurrentMax: %f, CurrentDesc: %s, NewMax: %f"), clipId, parentId, existingMaxOrder, existingDesc, newOrder));
  747. }
  748. CATCH_SQLITE_EXCEPTION
  749. return newOrder;
  750. }
  751. double CClip::GetNewLastSticky(int parentId, int clipId)
  752. {
  753. double newOrder = 1;
  754. double existingMaxOrder = 0;
  755. CString existingDesc = _T("");
  756. try
  757. {
  758. if (parentId < 0)
  759. {
  760. CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT stickyClipOrder, mText FROM Main WHERE stickyClipOrder <> -10000000 ORDER BY stickyClipOrder LIMIT 1"));
  761. if (q.eof() == false)
  762. {
  763. existingMaxOrder = q.getFloatField(_T("stickyClipOrder"));
  764. existingDesc = q.getStringField(_T("mText"));
  765. newOrder = existingMaxOrder - 1;
  766. }
  767. }
  768. else
  769. {
  770. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT stickyClipGroupOrder, mText FROM Main WHERE lParentID = %d ORDER BY stickyClipGroupOrder LIMIT 1"), parentId);
  771. if (q.eof() == false)
  772. {
  773. existingMaxOrder = q.getFloatField(_T("stickyClipGroupOrder"));
  774. newOrder = existingMaxOrder - 1;
  775. }
  776. }
  777. if (newOrder == 0.0)
  778. newOrder -= 1;
  779. Log(StrF(_T("GetNewLastSticky, Id: %d, parentId: %d, CurrentMax: %f, CurrentDesc: %s, NewMax: %f"), clipId, parentId, existingMaxOrder, existingDesc, newOrder));
  780. }
  781. CATCH_SQLITE_EXCEPTION
  782. return newOrder;
  783. }
  784. void CClip::MakeLatestOrder()
  785. {
  786. m_clipOrder = GetNewOrder(-1, m_id);
  787. }
  788. void CClip::MakeLatestGroupOrder()
  789. {
  790. if(m_parentId > -1)
  791. {
  792. m_clipGroupOrder = GetNewOrder(m_parentId, m_id);
  793. }
  794. }
  795. double CClip::GetNewOrder(int parentId, int clipId)
  796. {
  797. double newOrder = 0;
  798. double existingMaxOrder = 0;
  799. CString existingDesc = _T("");
  800. try
  801. {
  802. if(parentId < 0)
  803. {
  804. CppSQLite3Query q = theApp.m_db.execQuery(_T("SELECT clipOrder, mText FROM Main ORDER BY clipOrder DESC LIMIT 1"));
  805. if(q.eof() == false)
  806. {
  807. existingMaxOrder = q.getFloatField(_T("clipOrder"));
  808. existingDesc = q.getStringField(_T("mText"));
  809. newOrder = existingMaxOrder + 1;
  810. }
  811. }
  812. else
  813. {
  814. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT clipGroupOrder, mText FROM Main WHERE lParentID = %d ORDER BY clipGroupOrder DESC LIMIT 1"), parentId);
  815. if(q.eof() == false)
  816. {
  817. existingMaxOrder = q.getFloatField(_T("clipGroupOrder"));
  818. newOrder = existingMaxOrder + 1;
  819. }
  820. }
  821. Log(StrF(_T("GetNewOrder, Id: %d, parentId: %d, CurrentMax: %f, CurrentDesc: %s, NewMax: %f"), clipId, parentId, existingMaxOrder, existingDesc, newOrder));
  822. }
  823. CATCH_SQLITE_EXCEPTION
  824. return newOrder;
  825. }
  826. BOOL CClip::LoadMainTable(int id)
  827. {
  828. bool bRet = false;
  829. try
  830. {
  831. CppSQLite3Query q = theApp.m_db.execQueryEx(_T("SELECT * FROM Main WHERE lID = %d"), id);
  832. if(q.eof() == false)
  833. {
  834. m_Time = q.getIntField(_T("lDate"));
  835. m_Desc = q.getStringField(_T("mText"));
  836. m_CRC = q.getIntField(_T("CRC"));
  837. m_parentId = q.getIntField(_T("lParentID"));
  838. m_dontAutoDelete = q.getIntField(_T("lDontAutoDelete"));
  839. m_shortCut = q.getIntField(_T("lShortCut"));
  840. m_bIsGroup = q.getIntField(_T("bIsGroup"));
  841. m_csQuickPaste = q.getStringField(_T("QuickPasteText"));
  842. m_clipOrder = q.getFloatField(_T("clipOrder"));
  843. m_clipGroupOrder = q.getFloatField(_T("clipGroupOrder"));
  844. m_globalShortCut = q.getIntField(_T("globalShortCut"));
  845. m_lastPasteDate = q.getIntField(_T("lastPasteDate"));
  846. m_stickyClipOrder = q.getFloatField(_T("stickyClipOrder"));
  847. m_stickyClipGroupOrder = q.getFloatField(_T("stickyClipGroupOrder"));
  848. m_moveToGroupShortCut = q.getIntField(_T("MoveToGroupShortCut"));
  849. m_globalMoveToGroupShortCut = q.getIntField(_T("GlobalMoveToGroupShortCut"));
  850. m_id = id;
  851. bRet = true;
  852. }
  853. }
  854. CATCH_SQLITE_EXCEPTION_AND_RETURN(FALSE)
  855. return bRet;
  856. }
  857. // STATICS
  858. // Allocates a Global containing the requested Clip Format Data
  859. HGLOBAL CClip::LoadFormat(int id, UINT cfType)
  860. {
  861. HGLOBAL hGlobal = 0;
  862. try
  863. {
  864. CString csSQL;
  865. csSQL.Format(
  866. _T("SELECT Data.ooData FROM Data ")
  867. _T("INNER JOIN Main ON Main.lID = Data.lParentID ")
  868. _T("WHERE Main.lID = %d ")
  869. _T("AND Data.strClipBoardFormat = \'%s\'"),
  870. id,
  871. GetFormatName(cfType));
  872. CppSQLite3Query q = theApp.m_db.execQuery(csSQL);
  873. if(q.eof() == false)
  874. {
  875. int nDataLen = 0;
  876. const unsigned char *cData = q.getBlobField(0, nDataLen);
  877. if(cData == NULL)
  878. {
  879. return false;
  880. }
  881. hGlobal = NewGlobalP((LPVOID)cData, nDataLen);
  882. }
  883. }
  884. CATCH_SQLITE_EXCEPTION
  885. return hGlobal;
  886. }
  887. bool CClip::LoadFormats(int id, bool bOnlyLoad_CF_TEXT)
  888. {
  889. DWORD startTick = GetTickCount();
  890. CClipFormat cf;
  891. HGLOBAL hGlobal = 0;
  892. m_Formats.RemoveAll();
  893. try
  894. {
  895. //Open the data table for all that have the parent id
  896. //Order by Data.lID so that when generating CRC it's always in the same order as the first time
  897. //we generated it
  898. CString csSQL;
  899. CString textFilter = _T("");
  900. if(bOnlyLoad_CF_TEXT)
  901. {
  902. textFilter = _T("(strClipBoardFormat = 'CF_TEXT' OR strClipBoardFormat = 'CF_UNICODETEXT') AND ");
  903. }
  904. csSQL.Format(
  905. _T("SELECT lID, lParentID, strClipBoardFormat, ooData FROM Data ")
  906. _T("WHERE %s lParentID = %d ORDER BY Data.lID desc"), textFilter, id);
  907. CppSQLite3Query q = theApp.m_db.execQuery(csSQL);
  908. while(q.eof() == false)
  909. {
  910. cf.m_dataId = q.getIntField(_T("lID"));
  911. cf.m_parentId = q.getIntField(_T("lParentID"));
  912. cf.m_cfType = GetFormatID(q.getStringField(_T("strClipBoardFormat")));
  913. if(bOnlyLoad_CF_TEXT)
  914. {
  915. if(cf.m_cfType != CF_TEXT && cf.m_cfType != CF_UNICODETEXT)
  916. {
  917. q.nextRow();
  918. continue;
  919. }
  920. }
  921. int nDataLen = 0;
  922. const unsigned char *cData = q.getBlobField(_T("ooData"), nDataLen);
  923. if(cData != NULL)
  924. {
  925. hGlobal = NewGlobalP((LPVOID)cData, nDataLen);
  926. }
  927. cf.m_hgData = hGlobal;
  928. m_Formats.Add(cf);
  929. q.nextRow();
  930. }
  931. // formats owns all the data
  932. cf.m_hgData = 0;
  933. }
  934. CATCH_SQLITE_EXCEPTION_AND_RETURN(false)
  935. DWORD endTick = GetTickCount();
  936. if((endTick-startTick) > 150)
  937. Log(StrF(_T("Paste Timing LoadFormats: %d, ClipId: %d"), endTick-startTick, id));
  938. return m_Formats.GetSize() > 0;
  939. }
  940. void CClip::LoadTypes(int id, CClipTypes& types)
  941. {
  942. types.RemoveAll();
  943. try
  944. {
  945. CString csSQL;
  946. // get formats for Clip "lID" (Main.lID) using the corresponding Main.lDataID
  947. //Order by Data.lID so that when generating CRC it's always in the same order as the first time
  948. //we generated it
  949. csSQL.Format(
  950. _T("SELECT strClipBoardFormat FROM Data ")
  951. _T("INNER JOIN Main ON Main.lID = Data.lParentID ")
  952. _T("WHERE Main.lID = %d ORDER BY Data.lID desc"), id);
  953. CppSQLite3Query q = theApp.m_db.execQuery(csSQL);
  954. while(q.eof() == false)
  955. {
  956. types.Add(GetFormatID(q.getStringField(0)));
  957. q.nextRow();
  958. }
  959. }
  960. CATCH_SQLITE_EXCEPTION
  961. }
  962. bool CClip::SaveFromEditWnd(BOOL bUpdateDesc)
  963. {
  964. bool bRet = false;
  965. try
  966. {
  967. theApp.m_db.execDMLEx(_T("DELETE FROM Data WHERE lParentID = %d;"), m_id);
  968. DWORD CRC = GenerateCRC();
  969. AddToDataTable();
  970. theApp.m_db.execDMLEx(_T("UPDATE Main SET CRC = %d WHERE lID = %d"), CRC, m_id);
  971. if(bUpdateDesc)
  972. {
  973. m_Desc.Replace(_T("'"), _T("''"));
  974. theApp.m_db.execDMLEx(_T("UPDATE Main SET mText = '%s' WHERE lID = %d"), m_Desc, m_id);
  975. }
  976. bRet = true;
  977. }
  978. CATCH_SQLITE_EXCEPTION
  979. return bRet;
  980. }
  981. CStringW CClip::GetUnicodeTextFormat()
  982. {
  983. IClipFormat *pFormat = this->Clips()->FindFormatEx(CF_UNICODETEXT);
  984. if(pFormat != NULL)
  985. {
  986. wchar_t *stringData = (wchar_t *)GlobalLock(pFormat->Data());
  987. if(stringData != NULL)
  988. {
  989. CStringW string(stringData);
  990. GlobalUnlock(pFormat->Data());
  991. return string;
  992. }
  993. }
  994. return _T("");
  995. }
  996. CStringA CClip::GetCFTextTextFormat()
  997. {
  998. IClipFormat *pFormat = this->Clips()->FindFormatEx(CF_TEXT);
  999. if(pFormat != NULL)
  1000. {
  1001. char *stringData = (char *)GlobalLock(pFormat->Data());
  1002. if(stringData != NULL)
  1003. {
  1004. CStringA string(stringData);
  1005. GlobalUnlock(pFormat->Data());
  1006. return string;
  1007. }
  1008. }
  1009. return _T("");
  1010. }
  1011. BOOL CClip::WriteTextToFile(CString path, BOOL unicode, BOOL asci, BOOL utf8)
  1012. {
  1013. BOOL ret = false;
  1014. CFile f;
  1015. if(f.Open(path, CFile::modeWrite|CFile::modeCreate))
  1016. {
  1017. CStringW w = GetUnicodeTextFormat();
  1018. CStringA a = GetCFTextTextFormat();
  1019. if(utf8 && w != _T(""))
  1020. {
  1021. CStringA convToUtf8;
  1022. CTextConvert::ConvertToUTF8(w, convToUtf8);
  1023. byte header[2];
  1024. header[0] = 0xEF;
  1025. header[1] = 0xBB;
  1026. f.Write(&header, 2);
  1027. f.Write(convToUtf8.GetBuffer(), convToUtf8.GetLength());
  1028. ret = true;
  1029. }
  1030. else if(unicode && w != _T(""))
  1031. {
  1032. byte header[2];
  1033. header[0] = 0xFF;
  1034. header[1] = 0xFE;
  1035. f.Write(&header, 2);
  1036. f.Write(w.GetBuffer(), w.GetLength() * sizeof(wchar_t));
  1037. ret = true;
  1038. }
  1039. else if(asci && a != _T(""))
  1040. {
  1041. f.Write(a.GetBuffer(), a.GetLength());
  1042. ret = true;
  1043. }
  1044. f.Close();
  1045. }
  1046. return ret;
  1047. }
  1048. /*----------------------------------------------------------------------------*\
  1049. CClipList
  1050. \*----------------------------------------------------------------------------*/
  1051. CClipList::~CClipList()
  1052. {
  1053. CClip* pClip;
  1054. while(GetCount())
  1055. {
  1056. pClip = RemoveHead();
  1057. delete pClip;
  1058. }
  1059. }
  1060. // returns the number of clips actually saved
  1061. // while this does empty the Format Data, it does not delete the Clips.
  1062. int CClipList::AddToDB(bool bLatestOrder)
  1063. {
  1064. Log(_T("AddToDB - Start"));
  1065. int savedCount = 0;
  1066. CClip* pClip;
  1067. POSITION pos;
  1068. bool bResult;
  1069. INT_PTR remaining = GetCount();
  1070. pos = GetHeadPosition();
  1071. while(pos)
  1072. {
  1073. Log(StrF(_T("AddToDB - while(pos), Start Remaining %d"), remaining));
  1074. remaining--;
  1075. pClip = GetNext(pos);
  1076. ASSERT(pClip);
  1077. if(bLatestOrder)
  1078. {
  1079. pClip->MakeLatestOrder();
  1080. pClip->MakeLatestGroupOrder();
  1081. }
  1082. pClip->m_Time = CTime::GetCurrentTime().GetTime();
  1083. bResult = pClip->AddToDB();
  1084. if(bResult)
  1085. {
  1086. savedCount++;
  1087. }
  1088. Log(StrF(_T("AddToDB - while(pos), End Remaining %d, save count: %d"), remaining, savedCount));
  1089. }
  1090. Log(StrF(_T("AddToDB - Start, count: %d"), savedCount));
  1091. return savedCount;
  1092. }
  1093. const CClipList& CClipList::operator=(const CClipList &cliplist)
  1094. {
  1095. POSITION pos;
  1096. CClip* pClip;
  1097. pos = cliplist.GetHeadPosition();
  1098. while(pos)
  1099. {
  1100. pClip = cliplist.GetNext(pos);
  1101. ASSERT(pClip);
  1102. CClip *pNewClip = new CClip;
  1103. if(pNewClip)
  1104. {
  1105. *pNewClip = *pClip;
  1106. AddTail(pNewClip);
  1107. }
  1108. }
  1109. return *this;
  1110. }