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.

125 lines
3.3 KiB

  1. /*++
  2. Copyright (c) 2001, Microsoft Corporation
  3. Module Name:
  4. compstr.h
  5. Abstract:
  6. This file defines the CCompStrFactory Class.
  7. Author:
  8. Revision History:
  9. Notes:
  10. --*/
  11. #ifndef _COMPSTR_H_
  12. #define _COMPSTR_H_
  13. #include "ime.h"
  14. #include "template.h"
  15. #include "ctxtcomp.h"
  16. class CCompStrFactory : public IMCCLock<COMPOSITIONSTRING>
  17. {
  18. public:
  19. CCompStrFactory(HIMCC hCompStr) : IMCCLock<COMPOSITIONSTRING>(hCompStr)
  20. {
  21. m_pEndOfData = NULL;
  22. }
  23. HIMCC GetHandle()
  24. {
  25. return m_himcc;
  26. }
  27. HRESULT CreateCompositionString(CWCompString* CompStr,
  28. CWCompAttribute* CompAttr,
  29. CWCompClause* CompClause,
  30. CWCompTfGuidAtom* CompGuid,
  31. CWCompString* CompReadStr,
  32. CWCompAttribute* CompReadAttr,
  33. CWCompClause* CompReadClause,
  34. CWCompString* ResultStr,
  35. CWCompClause* ResultClause,
  36. CWCompString* ResultReadStr,
  37. CWCompClause* ResultReadClause
  38. );
  39. HRESULT CreateCompositionString(CWInterimString* InterimStr);
  40. HRESULT ClearCompositionString();
  41. template<class CONTEXT_SRC, class ARG_TYPE>
  42. HRESULT WriteData(CONTEXT_SRC& context_src,
  43. DWORD* context_dest_len,
  44. DWORD* context_dest_off,
  45. DWORD context_baias = 0
  46. )
  47. {
  48. DWORD dwLen = (DWORD)context_src.GetSize();
  49. DWORD dwRemainBufferSize = GetRemainBufferSize();
  50. if (dwLen > dwRemainBufferSize)
  51. return E_OUTOFMEMORY;
  52. *context_dest_len = dwLen;
  53. *context_dest_off = (DWORD)(m_pEndOfData - (BYTE*)m_pcomp - context_baias);
  54. context_src.ReadCompData((ARG_TYPE*)m_pEndOfData, dwRemainBufferSize);
  55. m_pEndOfData += Align(dwLen * sizeof(ARG_TYPE));
  56. return S_OK;
  57. }
  58. template<class ARG_TYPE>
  59. HRESULT InitData(DWORD* context_dest_len,
  60. DWORD* context_dest_off
  61. )
  62. {
  63. DWORD dwRemainBufferSize = GetRemainBufferSize();
  64. if (sizeof(ARG_TYPE) > dwRemainBufferSize)
  65. return E_OUTOFMEMORY;
  66. m_pcomp->dwPrivateSize = sizeof(ARG_TYPE);
  67. m_pcomp->dwPrivateOffset = (DWORD)(m_pEndOfData - (BYTE*)m_pcomp);
  68. memset((BYTE*)m_pEndOfData, 0, dwRemainBufferSize);
  69. m_pEndOfData += Align(sizeof(ARG_TYPE));
  70. return S_OK;
  71. }
  72. HRESULT MakeGuidMapAttribute(CWCompTfGuidAtom* CompGuid, CWCompAttribute* CompAttr);
  73. private:
  74. HRESULT _CreateCompositionString(DWORD dwCompSize);
  75. DWORD GetRemainBufferSize()
  76. {
  77. if (m_pEndOfData == NULL)
  78. return 0;
  79. return m_pcomp->dwSize > (DWORD)(m_pEndOfData - (BYTE*)m_pcomp) ? (DWORD)(m_pcomp->dwSize - (m_pEndOfData - (BYTE*)m_pcomp)) : 0;
  80. }
  81. size_t Align(size_t a)
  82. {
  83. #ifndef _WIN64
  84. return (size_t) ((a + 3) & ~3);
  85. #else
  86. return (size_t) ((a + 7) & ~7);
  87. #endif
  88. }
  89. BYTE* m_pEndOfData;
  90. };
  91. #endif // _COMPSTR_H_