Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.1 KiB

  1. // Copyright (C) 2001 Microsoft Corporation
  2. //
  3. // Rich Edit streaming helper for strings.
  4. //
  5. // 28 Sep 2001 sburns
  6. #ifndef RICHEDITSTRINGSTREAMER_HPP_INCLUDED
  7. #define RICHEDITSTRINGSTREAMER_HPP_INCLUDED
  8. #include "RichEditStreamer.hpp"
  9. // An implelemtation of RichEditStreamer for classes derived from
  10. // std::basic_string, which includes Burnslib::AnsiString and Burnslib::String.
  11. //
  12. // example use:
  13. //
  14. // HWND richEdit = your rich edit control
  15. // String streamMe(L"hello world.");
  16. //
  17. // RichEditStringStreamer<String> streamer(richEdit, streamMe);
  18. // streamer.StreamIn();
  19. // ASSERT(SUCCEEDED(streamer.ErrorResult()));
  20. template <class StringType>
  21. class RichEditStringStreamer
  22. :
  23. public RichEditStreamer
  24. {
  25. public:
  26. RichEditStringStreamer(HWND richEdit, const StringType& str)
  27. :
  28. RichEditStreamer(richEdit),
  29. textBuffer(str)
  30. {
  31. }
  32. virtual
  33. ~RichEditStringStreamer()
  34. {
  35. }
  36. protected:
  37. // RichEditStreamer overrides
  38. virtual
  39. HRESULT
  40. StreamCallback(
  41. PBYTE buffer,
  42. LONG bytesToTransfer,
  43. LONG* bytesTransferred)
  44. {
  45. HRESULT hr = S_OK;
  46. if (direction == StreamDirection::TO_CONTROL)
  47. {
  48. // we're stuffing textBuffer into the control
  49. LONG bytesRemaining =
  50. (textBuffer.length() * sizeof(StringType::value_type))
  51. - bytesCopiedSoFar;
  52. *bytesTransferred = min(bytesToTransfer, bytesRemaining);
  53. if (bytesRemaining)
  54. {
  55. PBYTE source =
  56. reinterpret_cast<BYTE*>(
  57. const_cast<StringType::value_type*>(textBuffer.c_str()))
  58. + bytesCopiedSoFar;
  59. memcpy(buffer, source, *bytesTransferred);
  60. }
  61. }
  62. else
  63. {
  64. ASSERT(direction == StreamDirection::FROM_CONTROL);
  65. *bytesTransferred = 0;
  66. hr = E_NOTIMPL;
  67. }
  68. return hr;
  69. }
  70. private:
  71. StringType textBuffer;
  72. };
  73. #endif // RICHEDITSTRINGSTREAMER_HPP_INCLUDED