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.

189 lines
4.2 KiB

  1. //
  2. // view.cpp
  3. //
  4. #include "private.h"
  5. #include "view.h"
  6. #include "ic.h"
  7. #include "range.h"
  8. DBG_ID_INSTANCE(CContextView);
  9. //+---------------------------------------------------------------------------
  10. //
  11. // ctor
  12. //
  13. //----------------------------------------------------------------------------
  14. CContextView::CContextView(CInputContext *pic, TsViewCookie vcView)
  15. {
  16. Dbg_MemSetThisNameID(TEXT("CContextView"));
  17. _pic = pic;
  18. _pic->AddRef();
  19. _vcView = vcView;
  20. }
  21. //+---------------------------------------------------------------------------
  22. //
  23. // dtor
  24. //
  25. //----------------------------------------------------------------------------
  26. CContextView::~CContextView()
  27. {
  28. _pic->Release();
  29. }
  30. //+---------------------------------------------------------------------------
  31. //
  32. // GetRangeFromPoint
  33. //
  34. //----------------------------------------------------------------------------
  35. STDAPI CContextView::GetRangeFromPoint(TfEditCookie ec, const POINT *ppt, DWORD dwFlags, ITfRange **ppRange)
  36. {
  37. CRange *range;
  38. IAnchor *pa;
  39. HRESULT hr;
  40. if (ppRange == NULL)
  41. return E_INVALIDARG;
  42. *ppRange = NULL;
  43. if (ppt == NULL)
  44. return E_INVALIDARG;
  45. if (dwFlags & ~(GXFPF_ROUND_NEAREST | GXFPF_NEAREST))
  46. return E_INVALIDARG;
  47. if (!_pic->_IsValidEditCookie(ec, TF_ES_READ))
  48. {
  49. Assert(0);
  50. return TF_E_NOLOCK;
  51. }
  52. hr = _pic->_GetTSI()->GetAnchorFromPoint(_vcView, ppt, dwFlags, &pa);
  53. if (hr != S_OK)
  54. {
  55. // the only potentially bogus arg is the view, which could have gone away
  56. return (hr == E_INVALIDARG) ? TF_E_INVALIDVIEW : E_FAIL;
  57. }
  58. hr = E_FAIL;
  59. range = new CRange;
  60. if (range == NULL)
  61. goto Exit;
  62. if (!range->_InitWithDefaultGravity(_pic, COPY_ANCHORS, pa, pa))
  63. {
  64. range->Release();
  65. goto Exit;
  66. }
  67. *ppRange = (ITfRangeAnchor *)range;
  68. hr = S_OK;
  69. Exit:
  70. pa->Release();
  71. return hr;
  72. }
  73. //+---------------------------------------------------------------------------
  74. //
  75. // GetScreenExt
  76. //
  77. //----------------------------------------------------------------------------
  78. STDAPI CContextView::GetScreenExt(RECT *prc)
  79. {
  80. HRESULT hr;
  81. if (prc == NULL)
  82. return E_INVALIDARG;
  83. hr = _pic->_GetTSI()->GetScreenExt(_vcView, prc);
  84. if (hr != S_OK)
  85. {
  86. hr = (hr == E_INVALIDARG) ? TF_E_INVALIDVIEW : E_FAIL;
  87. }
  88. return hr;
  89. }
  90. //+---------------------------------------------------------------------------
  91. //
  92. // GetScreenExtent
  93. //
  94. //----------------------------------------------------------------------------
  95. STDAPI CContextView::GetTextExt(TfEditCookie ec, ITfRange *pRange, RECT *prc, BOOL *pfClipped)
  96. {
  97. CRange *range;
  98. HRESULT hr;
  99. if (prc != NULL)
  100. {
  101. memset(prc, 0, sizeof(*prc));
  102. }
  103. if (pfClipped != NULL)
  104. {
  105. *pfClipped = FALSE;
  106. }
  107. if (pRange == NULL || prc == NULL || pfClipped == NULL)
  108. return E_INVALIDARG;
  109. if ((range = GetCRange_NA(pRange)) == NULL)
  110. return E_INVALIDARG;
  111. if (!VerifySameContext(_pic, range))
  112. return E_INVALIDARG;
  113. if (!_pic->_IsValidEditCookie(ec, TF_ES_READ))
  114. {
  115. Assert(0);
  116. return TF_E_NOLOCK;
  117. }
  118. range->_QuickCheckCrossedAnchors();
  119. hr = _pic->_GetTSI()->GetTextExt(_vcView, range->_GetStart(), range->_GetEnd(), prc, pfClipped);
  120. if (hr != S_OK)
  121. {
  122. // the only potentially bogus arg is the view, which could have gone away
  123. hr = (hr == E_INVALIDARG) ? TF_E_INVALIDVIEW : E_FAIL;
  124. }
  125. return hr;
  126. }
  127. //+---------------------------------------------------------------------------
  128. //
  129. // GetWnd
  130. //
  131. //----------------------------------------------------------------------------
  132. STDAPI CContextView::GetWnd(HWND *phwnd)
  133. {
  134. HRESULT hr;
  135. if (phwnd == NULL)
  136. return E_INVALIDARG;
  137. hr = _pic->_GetTSI()->GetWnd(_vcView, phwnd);
  138. if (hr != S_OK)
  139. {
  140. // the only potentially bogus arg is the view, which could have gone away
  141. hr = (hr == E_INVALIDARG) ? TF_E_INVALIDVIEW : E_FAIL;
  142. }
  143. return hr;
  144. }