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.

239 lines
5.4 KiB

  1. //
  2. // editrec.cpp
  3. //
  4. #include "private.h"
  5. #include "editrec.h"
  6. #include "ic.h"
  7. #include "enumss.h"
  8. DBG_ID_INSTANCE(CEditRecord);
  9. //+---------------------------------------------------------------------------
  10. //
  11. // ctor
  12. //
  13. //----------------------------------------------------------------------------
  14. CEditRecord::CEditRecord(CInputContext *pic)
  15. {
  16. Dbg_MemSetThisNameIDCounter(TEXT("CEditRecord"), PERF_EDITREC_COUNTER);
  17. Assert(_fSelChanged == FALSE);
  18. _pic = pic;
  19. _pic->AddRef();
  20. }
  21. //+---------------------------------------------------------------------------
  22. //
  23. // dtor
  24. //
  25. //----------------------------------------------------------------------------
  26. CEditRecord::~CEditRecord()
  27. {
  28. int i;
  29. PROPSPAN *pps;
  30. _pic->Release();
  31. for (i=0; i<_rgssProperties.Count(); i++)
  32. {
  33. pps = (PROPSPAN *)_rgssProperties.GetPtr(i);
  34. delete pps->pss;
  35. }
  36. }
  37. //+---------------------------------------------------------------------------
  38. //
  39. // GetSelectionStatus
  40. //
  41. //----------------------------------------------------------------------------
  42. STDAPI CEditRecord::GetSelectionStatus(BOOL *pfChanged)
  43. {
  44. if (pfChanged == NULL)
  45. return E_INVALIDARG;
  46. *pfChanged = _fSelChanged;
  47. return S_OK;
  48. }
  49. //+---------------------------------------------------------------------------
  50. //
  51. // GetTextAndPropertyUpdates
  52. //
  53. //----------------------------------------------------------------------------
  54. STDAPI CEditRecord::GetTextAndPropertyUpdates(DWORD dwFlags, const GUID **rgProperties, ULONG cProperties, IEnumTfRanges **ppEnumProp)
  55. {
  56. CEnumSpanSetRanges *pssAccumulate;
  57. CSpanSet *pssCurrent;
  58. ULONG i;
  59. if (ppEnumProp == NULL)
  60. return E_INVALIDARG;
  61. *ppEnumProp = NULL;
  62. if (dwFlags & ~TF_GTP_INCL_TEXT)
  63. return E_INVALIDARG;
  64. if (!(dwFlags & TF_GTP_INCL_TEXT) &&
  65. (rgProperties == NULL || cProperties < 1))
  66. {
  67. return E_INVALIDARG;
  68. }
  69. if ((pssAccumulate = new CEnumSpanSetRanges(_pic)) == NULL)
  70. return E_OUTOFMEMORY;
  71. if (dwFlags & TF_GTP_INCL_TEXT)
  72. {
  73. pssAccumulate->_Merge(&_ssText);
  74. }
  75. for (i=0; i<cProperties; i++)
  76. {
  77. if ((pssCurrent = _FindPropertySpanSet(*rgProperties[i])) == NULL)
  78. continue;
  79. pssAccumulate->_Merge(pssCurrent);
  80. }
  81. *ppEnumProp = pssAccumulate;
  82. return S_OK;
  83. }
  84. //+---------------------------------------------------------------------------
  85. //
  86. // _AddProperty
  87. //
  88. //----------------------------------------------------------------------------
  89. BOOL CEditRecord::_AddProperty(TfGuidAtom gaType, CSpanSet *pss)
  90. {
  91. int i;
  92. PROPSPAN *pps;
  93. pps = _FindProperty(gaType, &i);
  94. Assert(pps == NULL); // property should not already have been added
  95. return _InsertProperty(gaType, pss, i+1, FALSE);
  96. }
  97. //+---------------------------------------------------------------------------
  98. //
  99. // _FindCreateAppAttr
  100. //
  101. //----------------------------------------------------------------------------
  102. CSpanSet *CEditRecord::_FindCreateAppAttr(TfGuidAtom gaType)
  103. {
  104. int i;
  105. PROPSPAN *pps;
  106. CSpanSet *pss;
  107. pps = _FindProperty(gaType, &i);
  108. if (pps != NULL)
  109. {
  110. return pps->pss;
  111. }
  112. if ((pss = new CSpanSet) == NULL)
  113. return FALSE;
  114. if (!_InsertProperty(gaType, pss, i+1, TRUE))
  115. {
  116. delete pss;
  117. return NULL;
  118. }
  119. return pss;
  120. }
  121. //+---------------------------------------------------------------------------
  122. //
  123. // _InsertProperty
  124. //
  125. //----------------------------------------------------------------------------
  126. BOOL CEditRecord::_InsertProperty(TfGuidAtom gaType, CSpanSet *pss, int i, BOOL fAppProperty)
  127. {
  128. PROPSPAN *pps;
  129. if (!_rgssProperties.Insert(i, 1))
  130. return FALSE;
  131. pps = _rgssProperties.GetPtr(i);
  132. pps->gaType = gaType;
  133. pps->fAppProperty = fAppProperty;
  134. pps->pss = pss;
  135. return TRUE;
  136. }
  137. //+---------------------------------------------------------------------------
  138. //
  139. // _FindProperty
  140. //
  141. //----------------------------------------------------------------------------
  142. PROPSPAN *CEditRecord::_FindProperty(TfGuidAtom gaType, int *piOut)
  143. {
  144. PROPSPAN *ps;
  145. PROPSPAN *psMatch;
  146. int iMin;
  147. int iMax;
  148. int iMid;
  149. //
  150. // Issue: we should have a generic bsort function
  151. // instead of all this code dup!
  152. //
  153. psMatch = NULL;
  154. iMid = -1;
  155. iMin = 0;
  156. iMax = _rgssProperties.Count();
  157. while (iMin < iMax)
  158. {
  159. iMid = (iMin + iMax) / 2;
  160. ps = _rgssProperties.GetPtr(iMid);
  161. Assert(ps != NULL);
  162. if (gaType < ps->gaType)
  163. {
  164. iMax = iMid;
  165. }
  166. else if (gaType > ps->gaType)
  167. {
  168. iMin = iMid + 1;
  169. }
  170. else // match!
  171. {
  172. psMatch = ps;
  173. break;
  174. }
  175. }
  176. if (piOut != NULL)
  177. {
  178. if (psMatch == NULL && _rgssProperties.Count() > 0)
  179. {
  180. // couldn't find a match, return the next lowest span
  181. Assert(iMid == 0 || _rgssProperties.GetPtr(iMid-1)->gaType < gaType);
  182. if (_rgssProperties.GetPtr(iMid)->gaType > gaType)
  183. {
  184. iMid--;
  185. }
  186. }
  187. *piOut = iMid;
  188. }
  189. return psMatch;
  190. }