ProcessPaste.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #include "stdafx.h"
  2. #include "CP_Main.h"
  3. #include "ProcessPaste.h"
  4. #include "ClipIds.h"
  5. #ifdef _DEBUG
  6. #undef THIS_FILE
  7. static char THIS_FILE[]=__FILE__;
  8. #define new DEBUG_NEW
  9. #endif
  10. CProcessPaste::CProcessPaste()
  11. {
  12. m_pOle = new COleClipSource;
  13. m_bSendPaste = true;
  14. m_bActivateTarget = true;
  15. m_bOnlyPaste_CF_TEXT = false;
  16. m_bPasteHTMLFormatAs_CF_TEXT = false;
  17. }
  18. CProcessPaste::~CProcessPaste()
  19. {
  20. DELETE_PTR(m_pOle);
  21. }
  22. BOOL CProcessPaste::DoPaste()
  23. {
  24. Log(_T("Do Paste"));
  25. m_pOle->m_bOnlyPaste_CF_TEXT = m_bOnlyPaste_CF_TEXT;
  26. m_pOle->m_bPasteHTMLFormatAs_CF_TEXT = m_bPasteHTMLFormatAs_CF_TEXT;
  27. if(m_pOle->DoImmediateRender())
  28. {
  29. // MarkAsPasted() must be done first since it makes use of
  30. // m_pOle->m_ClipIDs and m_pOle is inaccessible after
  31. // SetClipboard is called.
  32. MarkAsPasted();
  33. // Ignore the clipboard change that we will cause IF:
  34. // 1) we are pasting a single element, since the element is already
  35. // in the db and its lDate was updated by MarkAsPasted().
  36. // OR
  37. // 2) we are pasting multiple, but g_Opt.m_bSaveMultiPaste is false
  38. if(GetClipIDs().GetSize() == 1 || !g_Opt.m_bSaveMultiPaste)
  39. {
  40. m_pOle->CacheGlobalData(theApp.m_cfIgnoreClipboard, NewGlobalP("Ignore", sizeof("Ignore")));
  41. }
  42. else
  43. {
  44. m_pOle->CacheGlobalData(theApp.m_cfDelaySavingData, NewGlobalP("Delay", sizeof("Delay")));
  45. }
  46. m_pOle->SetClipboard(); // m_pOle is now managed by the OLE clipboard
  47. // The Clipboard now owns the allocated memory
  48. // and will delete this data object
  49. // when new data is put on the Clipboard
  50. m_pOle = NULL; // m_pOle should not be accessed past this point
  51. #ifndef _DEBUG
  52. if(m_bSendPaste)
  53. {
  54. theApp.SendPaste(m_bActivateTarget);
  55. }
  56. #else
  57. if(m_bActivateTarget)
  58. {
  59. theApp.ActivateTarget();
  60. }
  61. #endif
  62. Log(_T("Do Paste RETURN TRUE"));
  63. return TRUE;
  64. }
  65. return FALSE;
  66. }
  67. BOOL CProcessPaste::DoDrag()
  68. {
  69. m_pOle->DoDelayRender();
  70. DROPEFFECT de = m_pOle->DoDragDrop(DROPEFFECT_COPY);
  71. if(de != DROPEFFECT_NONE)
  72. {
  73. MarkAsPasted();
  74. return TRUE;
  75. }
  76. return FALSE;
  77. }
  78. void CProcessPaste::MarkAsPasted()
  79. {
  80. CClipIDs& clips = GetClipIDs();
  81. if(clips.GetSize() == 1)
  82. MarkClipAsPasted(clips.ElementAt(0));
  83. }