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.

142 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 1985 - 1999, Microsoft Corporation
  3. Module Name:
  4. compstr.cpp
  5. Abstract:
  6. This file implements the CCompStrFactory Class.
  7. Author:
  8. Revision History:
  9. Notes:
  10. --*/
  11. #include "private.h"
  12. #include "compstr.h"
  13. #include "a_wrappers.h"
  14. HRESULT
  15. CCompStrFactory::CreateCompositionString(
  16. CWCompString* CompStr,
  17. CWCompAttribute* CompAttr,
  18. CWCompClause* CompClause,
  19. CWCompTfGuidAtom* CompGuid,
  20. CWCompString* CompReadStr,
  21. CWCompAttribute* CompReadAttr,
  22. CWCompClause* CompReadClause,
  23. CWCompString* ResultStr,
  24. CWCompClause* ResultClause,
  25. CWCompString* ResultReadStr,
  26. CWCompClause* ResultReadClause
  27. )
  28. {
  29. DWORD dwCompSize = (CompStr ? Align(CompStr->GetSize() * sizeof(WCHAR)) : 0) +
  30. (CompAttr ? Align(CompAttr->GetSize() * sizeof(BYTE)) : 0) +
  31. (CompClause ? Align(CompClause->GetSize() * sizeof(DWORD)) : 0) +
  32. (CompReadStr ? Align(CompReadStr->GetSize() * sizeof(WCHAR)) : 0) +
  33. (CompReadAttr ? Align(CompReadAttr->GetSize() * sizeof(BYTE)) : 0) +
  34. (CompReadClause ? Align(CompReadClause->GetSize() * sizeof(DWORD)) : 0) +
  35. (ResultStr ? Align(ResultStr->GetSize() * sizeof(WCHAR)) : 0) +
  36. (ResultClause ? Align(ResultClause->GetSize() * sizeof(DWORD)) : 0) +
  37. (ResultReadStr ? Align(ResultReadStr->GetSize() * sizeof(WCHAR)) : 0) +
  38. (ResultReadClause ? Align(ResultReadClause->GetSize() * sizeof(DWORD)) : 0) +
  39. (CompGuid ? Align(CompGuid->GetSize() * sizeof(TfGuidAtom)) : 0) + // COMPSTRING_AIMM12->dwTfGuidAtom
  40. (CompGuid && CompAttr
  41. ? Align(CompAttr->GetSize() * sizeof(BYTE)) : 0); // COMPSTRING_AIMM12->dwGuidMapAttr
  42. #ifdef CICERO_4678
  43. //
  44. // This is another workaround instead of dimm\imewnd.cpp.
  45. // Even subclass window hook off, AIMM won't resize hCompStr if dwCompSize is zero.
  46. //
  47. return (dwCompSize ? _CreateCompositionString(dwCompSize) : S_OK);
  48. #else
  49. return _CreateCompositionString(dwCompSize);
  50. #endif
  51. }
  52. HRESULT
  53. CCompStrFactory::CreateCompositionString(
  54. CWInterimString* InterimStr
  55. )
  56. {
  57. DWORD dwCompSize = (InterimStr ? Align(InterimStr->GetSize() * sizeof(WCHAR)) : 0) +
  58. Align(sizeof(WCHAR)) + // Interim char
  59. Align(sizeof(BYTE)); // Interim attr
  60. return _CreateCompositionString(dwCompSize);
  61. }
  62. HRESULT
  63. CCompStrFactory::_CreateCompositionString(
  64. DWORD dwCompSize
  65. )
  66. /*+++
  67. Return Value:
  68. Returns S_FALSE, dwCompSize is zero.
  69. Returns S_OK, dwCompSize is valid size.
  70. ---*/
  71. {
  72. IMTLS *ptls = IMTLS_GetOrAlloc();
  73. HRESULT hr = (dwCompSize != 0 ? S_OK : S_FALSE);
  74. dwCompSize += sizeof(COMPOSITIONSTRING_AIMM12);
  75. if (m_himcc == NULL) {
  76. //
  77. // First creation. Let's initialize it now
  78. //
  79. m_himcc = ImmCreateIMCC(ptls, dwCompSize);
  80. if (m_himcc != NULL) {
  81. m_hr = _LockIMCC(m_himcc, (void**)&m_pcomp);
  82. }
  83. }
  84. else if (ImmGetIMCCSize(ptls, m_himcc) != dwCompSize) {
  85. //
  86. // If already have m_himcc, then recreate it.
  87. //
  88. if (m_pcomp) {
  89. _UnlockIMCC(m_himcc);
  90. }
  91. HIMCC hMem;
  92. if ((hMem = ImmReSizeIMCC(ptls, m_himcc, dwCompSize)) != NULL) {
  93. m_himcc = hMem;
  94. }
  95. else {
  96. ImmDestroyIMCC(ptls, m_himcc);
  97. m_himcc = ImmCreateIMCC(ptls, dwCompSize);
  98. }
  99. if (m_himcc != NULL) {
  100. m_hr = _LockIMCC(m_himcc, (void**)&m_pcomp);
  101. }
  102. }
  103. if (FAILED(m_hr))
  104. return m_hr;
  105. if (m_himcc == NULL)
  106. return E_OUTOFMEMORY;
  107. memset(m_pcomp, 0, dwCompSize); // clear buffer with zero.
  108. m_pcomp->CompStr.dwSize = dwCompSize; // set buffer size.
  109. m_pEndOfData = (BYTE*)m_pcomp + sizeof(COMPOSITIONSTRING_AIMM12); // set end of the data pointer.
  110. return hr;
  111. }