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.

87 lines
2.2 KiB

  1. //
  2. // flipsel.cpp
  3. //
  4. // "Flip Selection" menu item handler.
  5. //
  6. #include "globals.h"
  7. #include "case.h"
  8. #include "editsess.h"
  9. class CFlipEditSession : public CEditSessionBase
  10. {
  11. public:
  12. CFlipEditSession(ITfContext *pContext) : CEditSessionBase(pContext) {}
  13. // ITfEditSession
  14. STDMETHODIMP DoEditSession(TfEditCookie ec);
  15. };
  16. //+---------------------------------------------------------------------------
  17. //
  18. // _Menu_FlipSel
  19. //
  20. // Toggle the case of the selected text in the focus context.
  21. //----------------------------------------------------------------------------
  22. void CCaseTextService::_Menu_FlipSel(CCaseTextService *_this)
  23. {
  24. ITfDocumentMgr *pFocusDoc;
  25. ITfContext *pContext;
  26. CFlipEditSession *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 CFlipEditSession(pContext))
  39. {
  40. // we need a document write lock to insert text
  41. // the CHelloEditSession will do all the work when the
  42. // CFlipEditSession::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 CFlipEditSession::DoEditSession(TfEditCookie ec)
  56. {
  57. TF_SELECTION tfSelection;
  58. ULONG cFetched;
  59. // get the selection
  60. if (_pContext->GetSelection(ec, TF_DEFAULT_SELECTION, 1, &tfSelection, &cFetched) != S_OK ||
  61. cFetched == 0)
  62. {
  63. // no selection
  64. return S_OK;
  65. }
  66. // do the work
  67. ToggleCase(ec, tfSelection.range, FALSE);
  68. // release the range
  69. tfSelection.range->Release();
  70. return S_OK;
  71. }