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.

81 lines
2.1 KiB

  1. //
  2. // flipdoc.cpp
  3. //
  4. // "Flip Doc" menu item handler.
  5. //
  6. #include "globals.h"
  7. #include "case.h"
  8. #include "editsess.h"
  9. class CFlipDocEditSession : public CEditSessionBase
  10. {
  11. public:
  12. CFlipDocEditSession(ITfContext *pContext) : CEditSessionBase(pContext) {}
  13. // ITfEditSession
  14. STDMETHODIMP DoEditSession(TfEditCookie ec);
  15. };
  16. //+---------------------------------------------------------------------------
  17. //
  18. // _Menu_FlipDoc
  19. //
  20. // Toggle the case of the entire document.
  21. //----------------------------------------------------------------------------
  22. void CCaseTextService::_Menu_FlipDoc(CCaseTextService *_this)
  23. {
  24. ITfDocumentMgr *pFocusDoc;
  25. ITfContext *pContext;
  26. CFlipDocEditSession *pFlipEditSession;
  27. HRESULT hr;
  28. // get the focus document
  29. if (_this->_pThreadMgr->GetFocus(&pFocusDoc) != S_OK)
  30. return;
  31. // we want the topmost context, since the main doc context could be
  32. // superceded by a modal tip context
  33. if (pFocusDoc->GetTop(&pContext) != S_OK)
  34. {
  35. pContext = NULL;
  36. goto Exit;
  37. }
  38. if (pFlipEditSession = new CFlipDocEditSession(pContext))
  39. {
  40. // we need a document write lock to insert text
  41. // the CHelloEditSession will do all the work when the
  42. // CFlipDocEditSession::DoEditSession method is called by the context
  43. pContext->RequestEditSession(_this->_tfClientId, pFlipEditSession, TF_ES_READWRITE | TF_ES_ASYNCDONTCARE, &hr);
  44. pFlipEditSession->Release();
  45. }
  46. Exit:
  47. SafeRelease(pContext);
  48. pFocusDoc->Release();
  49. }
  50. //+---------------------------------------------------------------------------
  51. //
  52. // DoEditSession
  53. //
  54. //----------------------------------------------------------------------------
  55. STDAPI CFlipDocEditSession::DoEditSession(TfEditCookie ec)
  56. {
  57. ITfRange *pRangeStart;
  58. // get the head of the doc
  59. if (_pContext->GetStart(ec, &pRangeStart) != S_OK)
  60. return E_FAIL;
  61. // do the work
  62. ToggleCase(ec, pRangeStart, TRUE);
  63. pRangeStart->Release();
  64. return S_OK;
  65. }