RichTextAggregator.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #include "stdafx.h"
  2. #include ".\richtextaggregator.h"
  3. #include "Misc.h"
  4. CRichTextAggregator::CRichTextAggregator(CStringA csSeparator) :
  5. m_csSeparator(csSeparator)
  6. {
  7. //Remove the first line feed
  8. // if(m_csSeparator.GetLength() > 1 && m_csSeparator[0] == '\r' && m_csSeparator[1] == '\n')
  9. // {
  10. // m_csSeparator.Delete(0);
  11. // m_csSeparator.Delete(0);
  12. // }
  13. m_csSeparator.Replace("\r\n", "\\par");
  14. }
  15. CRichTextAggregator::~CRichTextAggregator(void)
  16. {
  17. }
  18. bool CRichTextAggregator::AddClip(LPVOID lpData, int nDataSize, int nPos, int nCount)
  19. {
  20. LPSTR pText = (LPSTR)lpData;
  21. if(pText == NULL)
  22. {
  23. return false;
  24. }
  25. //Ensure it's null terminated
  26. if(pText[nDataSize-1] != '\0')
  27. {
  28. int len = 0;
  29. for(len = 0; len < nDataSize && pText[len] != '\0'; len++ )
  30. {
  31. }
  32. // if it is not null terminated, skip this item
  33. if(len >= nDataSize)
  34. return false;
  35. }
  36. if(nPos != nCount-1)
  37. {
  38. //Remove the last } at the end of the rtf
  39. bool bBreak = false;
  40. for(int i = nDataSize-1; i >= 0; i--)
  41. {
  42. if(pText[i] == '}')
  43. bBreak = true;
  44. pText[i] = NULL;
  45. if(bBreak)
  46. break;
  47. }
  48. }
  49. else if(nPos >= 1)
  50. {
  51. //Remove the {\rtf1 at the start of the rtf
  52. for(int i = 0; i < 6; i++)
  53. {
  54. pText[0] = NULL;
  55. pText++;
  56. }
  57. }
  58. m_csNewText += pText;
  59. if(nPos != nCount-1)
  60. {
  61. m_csNewText += m_csSeparator;
  62. }
  63. return true;
  64. }
  65. HGLOBAL CRichTextAggregator::GetHGlobal()
  66. {
  67. long lLen = m_csNewText.GetLength();
  68. HGLOBAL hGlobal = NewGlobalP(m_csNewText.GetBuffer(lLen), lLen+sizeof(char));
  69. m_csNewText.ReleaseBuffer();
  70. return hGlobal;
  71. }