PasteAnyAsText.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "StdAfx.h"
  2. #include ".\pasteanyastext.h"
  3. #include "SelectPasteFormat.h"
  4. PasteAnyAsText::PasteAnyAsText(void)
  5. {
  6. }
  7. PasteAnyAsText::~PasteAnyAsText(void)
  8. {
  9. }
  10. bool PasteAnyAsText::SelectClipToPasteAsText(const CDittoInfo &DittoInfo, IClip *pClip)
  11. {
  12. bool ret = false;
  13. AFX_MANAGE_STATE(AfxGetStaticModuleState());
  14. IClipFormats *pFormats = pClip->Clips();
  15. CWnd* pWnd = CWnd::FromHandle(DittoInfo.m_hWndDitto);
  16. CSelectPasteFormat dlg(pWnd, pFormats);
  17. if(dlg.DoModal() == IDOK)
  18. {
  19. //Find the format that was selected, remove all then readd the data as type CF_TEXT
  20. CLIPFORMAT format = dlg.SelectedFormat();
  21. if(format > 0)
  22. {
  23. IClipFormat *pText = pFormats->FindFormatEx(format);
  24. if(pText != NULL)
  25. {
  26. //We own the data, when we call DeleteAll tell it to not free the data
  27. pText->AutoDeleteData(false);
  28. HGLOBAL data = pText->Data();
  29. if(dlg.PasteAsUnicode() == false)
  30. {
  31. char * stringData = (char *)GlobalLock(data);
  32. int size = (int)GlobalSize(data);
  33. for(int i = 0; i < size; i++)
  34. {
  35. if(stringData[i] == 0)
  36. {
  37. stringData[i] = ' ';
  38. }
  39. }
  40. GlobalUnlock(data);
  41. //Remove all over formats and add the selected date back as CF_TEXT
  42. pFormats->DeleteAll();
  43. pFormats->AddNew(CF_TEXT, data);
  44. IClipFormat *pText = pFormats->FindFormatEx(CF_TEXT);
  45. if(pText != NULL)
  46. {
  47. pText->AutoDeleteData(true);
  48. }
  49. }
  50. else
  51. {
  52. wchar_t * stringData = (wchar_t *)GlobalLock(data);
  53. int size = (int)GlobalSize(data);
  54. for(int i = 0; i < (int)(size/(sizeof(wchar_t))); i++)
  55. {
  56. if(stringData[i] == 0)
  57. {
  58. stringData[i] = ' ';
  59. }
  60. }
  61. GlobalUnlock(data);
  62. //Remove all over formats and add the selected date back as CF_TEXT
  63. pFormats->DeleteAll();
  64. pFormats->AddNew(CF_UNICODETEXT, data);
  65. IClipFormat *pText = pFormats->FindFormatEx(CF_UNICODETEXT);
  66. if(pText != NULL)
  67. {
  68. pText->AutoDeleteData(true);
  69. }
  70. }
  71. ret = true;
  72. }
  73. }
  74. }
  75. return ret;
  76. }