RemoveLineFeeds.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #include "StdAfx.h"
  2. #include "RemoveLineFeeds.h"
  3. #include "../../Shared/Tokenizer.h"
  4. #include "../../Shared/TextConvert.h"
  5. CRemoveLineFeeds::CRemoveLineFeeds(void)
  6. {
  7. }
  8. CRemoveLineFeeds::~CRemoveLineFeeds(void)
  9. {
  10. }
  11. bool CRemoveLineFeeds::RemoveLineFeeds(const CDittoInfo &DittoInfo, IClip *pClip)
  12. {
  13. bool didSomething = false;
  14. IClipFormats *pFormats = pClip->Clips();
  15. if(pFormats)
  16. {
  17. didSomething = Handle_CF_TEXT(pFormats);
  18. didSomething |= Handle_CF_UNICODETEXT(pFormats);
  19. didSomething |= Handle_RichText(pFormats);
  20. }
  21. return didSomething;
  22. }
  23. bool CRemoveLineFeeds::Handle_CF_TEXT(IClipFormats *pFormats)
  24. {
  25. bool didSomething = false;
  26. IClipFormat *pFormat = pFormats->FindFormatEx(CF_TEXT);
  27. if(pFormat != NULL)
  28. {
  29. char *stringData = (char *)GlobalLock(pFormat->Data());
  30. if(stringData != NULL)
  31. {
  32. CStringA string(stringData);
  33. int count = string.Replace("\r\n", " ");
  34. //INT_PTR size = GlobalSize(pFormat->Data());
  35. strcpy_s(stringData, GlobalSize(pFormat->Data()), string);
  36. GlobalUnlock(pFormat->Data());
  37. didSomething = true;
  38. }
  39. }
  40. return didSomething;
  41. }
  42. bool CRemoveLineFeeds::Handle_CF_UNICODETEXT(IClipFormats *pFormats)
  43. {
  44. bool didSomething = false;
  45. IClipFormat *pFormat = pFormats->FindFormatEx(CF_UNICODETEXT);
  46. if(pFormat != NULL)
  47. {
  48. wchar_t *stringData = (wchar_t *)GlobalLock(pFormat->Data());
  49. if(stringData != NULL)
  50. {
  51. CStringW string(stringData);
  52. int count = string.Replace(_T("\r\n"), _T(" "));
  53. wcscpy_s(stringData, GlobalSize(pFormat->Data())/2, string);
  54. GlobalUnlock(pFormat->Data());
  55. didSomething = true;
  56. }
  57. }
  58. return didSomething;
  59. }
  60. bool CRemoveLineFeeds::Handle_RichText(IClipFormats *pFormats)
  61. {
  62. bool didSomething = false;
  63. CLIPFORMAT m_RTFFormat = ::RegisterClipboardFormat(_T("Rich Text Format"));
  64. IClipFormat *pFormat = pFormats->FindFormatEx(m_RTFFormat);
  65. if(pFormat != NULL)
  66. {
  67. char *stringData = (char *)GlobalLock(pFormat->Data());
  68. if(stringData != NULL)
  69. {
  70. CStringA string(stringData);
  71. int count = string.Replace("\\par\r\n", " ");
  72. int count2 = string.Replace("\\par ", " ");
  73. int count3 = string.Replace("\\line ", " ");
  74. strcpy_s(stringData, GlobalSize(pFormat->Data()), string);
  75. GlobalUnlock(pFormat->Data());
  76. didSomething = true;
  77. }
  78. }
  79. return didSomething;
  80. }