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.

176 lines
5.5 KiB

  1. /*++
  2. Copyright (c) 2001, 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. HRESULT
  14. CCompStrFactory::CreateCompositionString(
  15. CWCompString* CompStr,
  16. CWCompAttribute* CompAttr,
  17. CWCompClause* CompClause,
  18. CWCompTfGuidAtom* CompGuid,
  19. CWCompString* CompReadStr,
  20. CWCompAttribute* CompReadAttr,
  21. CWCompClause* CompReadClause,
  22. CWCompString* ResultStr,
  23. CWCompClause* ResultClause,
  24. CWCompString* ResultReadStr,
  25. CWCompClause* ResultReadClause
  26. )
  27. {
  28. DWORD dwCompSize = (CompStr ? Align(CompStr->GetSize() * sizeof(WCHAR)) : 0) +
  29. (CompAttr ? Align(CompAttr->GetSize() * sizeof(BYTE)) : 0) +
  30. (CompClause ? Align(CompClause->GetSize() * sizeof(DWORD)) : 0) +
  31. (CompReadStr ? Align(CompReadStr->GetSize() * sizeof(WCHAR)) : 0) +
  32. (CompReadAttr ? Align(CompReadAttr->GetSize() * sizeof(BYTE)) : 0) +
  33. (CompReadClause ? Align(CompReadClause->GetSize() * sizeof(DWORD)) : 0) +
  34. (ResultStr ? Align(ResultStr->GetSize() * sizeof(WCHAR)) : 0) +
  35. (ResultClause ? Align(ResultClause->GetSize() * sizeof(DWORD)) : 0) +
  36. (ResultReadStr ? Align(ResultReadStr->GetSize() * sizeof(WCHAR)) : 0) +
  37. (ResultReadClause ? Align(ResultReadClause->GetSize() * sizeof(DWORD)) : 0) +
  38. (CompGuid ? Align(CompGuid->GetSize() * sizeof(TfGuidAtom)) : 0) + // COMPSTRING_AIMM12->dwTfGuidAtom
  39. (CompGuid && CompAttr
  40. ? Align(CompAttr->GetSize() * sizeof(BYTE)) : 0); // COMPSTRING_AIMM12->dwGuidMapAttr
  41. #ifdef CICERO_4678
  42. //
  43. // This is another workaround instead of dimm\imewnd.cpp.
  44. // Even subclass window hook off, AIMM won't resize hCompStr if dwCompSize is zero.
  45. //
  46. return (dwCompSize ? _CreateCompositionString(dwCompSize) : S_OK);
  47. #else
  48. return _CreateCompositionString(dwCompSize);
  49. #endif
  50. }
  51. HRESULT
  52. CCompStrFactory::CreateCompositionString(
  53. CWInterimString* InterimStr
  54. )
  55. {
  56. DWORD dwCompSize = (InterimStr ? Align(InterimStr->GetSize() * sizeof(WCHAR)) : 0) +
  57. Align(sizeof(WCHAR)) + // Interim char
  58. Align(sizeof(BYTE)); // Interim attr
  59. return _CreateCompositionString(dwCompSize);
  60. }
  61. HRESULT
  62. CCompStrFactory::ClearCompositionString()
  63. {
  64. return _CreateCompositionString(0);
  65. }
  66. HRESULT
  67. CCompStrFactory::_CreateCompositionString(
  68. DWORD dwCompSize
  69. )
  70. /*+++
  71. Return Value:
  72. Returns S_FALSE, dwCompSize is zero.
  73. Returns S_OK, dwCompSize is valid size.
  74. ---*/
  75. {
  76. HRESULT hr = (dwCompSize != 0 ? S_OK : S_FALSE);
  77. dwCompSize += sizeof(COMPOSITIONSTRING) + sizeof(GUIDMAPATTRIBUTE);
  78. if (m_himcc == NULL) {
  79. //
  80. // First creation. Let's initialize it now
  81. //
  82. m_himcc = ImmCreateIMCC(dwCompSize);
  83. if (m_himcc != NULL) {
  84. m_hr = _LockIMCC(m_himcc, (void**)&m_pcomp);
  85. }
  86. }
  87. else if (ImmGetIMCCSize(m_himcc) != dwCompSize) {
  88. //
  89. // If already have m_himcc, then recreate it.
  90. //
  91. if (m_pcomp) {
  92. _UnlockIMCC(m_himcc);
  93. }
  94. HIMCC hMem;
  95. if ((hMem = ImmReSizeIMCC(m_himcc, dwCompSize)) != NULL) {
  96. m_himcc = hMem;
  97. }
  98. else {
  99. ImmDestroyIMCC(m_himcc);
  100. m_himcc = ImmCreateIMCC(dwCompSize);
  101. }
  102. if (m_himcc != NULL) {
  103. m_hr = _LockIMCC(m_himcc, (void**)&m_pcomp);
  104. }
  105. }
  106. if (FAILED(m_hr))
  107. return m_hr;
  108. if (m_himcc == NULL)
  109. return E_OUTOFMEMORY;
  110. memset(m_pcomp, 0, dwCompSize); // clear buffer with zero.
  111. m_pcomp->dwSize = dwCompSize; // set buffer size.
  112. m_pEndOfData = (BYTE*)m_pcomp + sizeof(COMPOSITIONSTRING); // set end of the data pointer.
  113. return hr;
  114. }
  115. HRESULT
  116. CCompStrFactory::MakeGuidMapAttribute(
  117. CWCompTfGuidAtom* CompGuid,
  118. CWCompAttribute* CompAttr)
  119. {
  120. HRESULT hr;
  121. GUIDMAPATTRIBUTE* guid_map;
  122. hr = InitData<GUIDMAPATTRIBUTE>(&GetBuffer()->dwPrivateSize,
  123. &GetBuffer()->dwPrivateOffset);
  124. if (SUCCEEDED(hr) &&
  125. (guid_map = (GUIDMAPATTRIBUTE*)GetOffsetPointer(GetBuffer()->dwPrivateOffset)) != NULL)
  126. {
  127. hr = WriteData<CWCompTfGuidAtom, TfGuidAtom>(*CompGuid,
  128. &guid_map->dwTfGuidAtomLen,
  129. &guid_map->dwTfGuidAtomOffset,
  130. GetBuffer()->dwPrivateOffset);
  131. if (SUCCEEDED(hr))
  132. {
  133. // temporary make a buffer of dwGuidMapAttr
  134. if (CompAttr && CompAttr->GetSize()) {
  135. hr = WriteData<CWCompAttribute, BYTE>(*CompAttr,
  136. &guid_map->dwGuidMapAttrLen,
  137. &guid_map->dwGuidMapAttrOffset,
  138. GetBuffer()->dwPrivateOffset);
  139. }
  140. }
  141. }
  142. return hr;
  143. }