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

//
// flipsel.cpp
//
// "Flip Selection" menu item handler.
//
#include "globals.h"
#include "case.h"
#include "editsess.h"
class CFlipEditSession : public CEditSessionBase
{
public:
CFlipEditSession(ITfContext *pContext) : CEditSessionBase(pContext) {}
// ITfEditSession
STDMETHODIMP DoEditSession(TfEditCookie ec);
};
//+---------------------------------------------------------------------------
//
// _Menu_FlipSel
//
// Toggle the case of the selected text in the focus context.
//----------------------------------------------------------------------------
void CCaseTextService::_Menu_FlipSel(CCaseTextService *_this)
{
ITfDocumentMgr *pFocusDoc;
ITfContext *pContext;
CFlipEditSession *pFlipEditSession;
HRESULT hr;
// get the focus document
if (_this->_pThreadMgr->GetFocus(&pFocusDoc) != S_OK)
return;
// we want the topmost context, since the main doc context could be
// superceded by a modal tip context
if (pFocusDoc->GetTop(&pContext) != S_OK)
{
pContext = NULL;
goto Exit;
}
if (pFlipEditSession = new CFlipEditSession(pContext))
{
// we need a document write lock to insert text
// the CHelloEditSession will do all the work when the
// CFlipEditSession::DoEditSession method is called by the context
pContext->RequestEditSession(_this->_tfClientId, pFlipEditSession, TF_ES_READWRITE | TF_ES_ASYNCDONTCARE, &hr);
pFlipEditSession->Release();
}
Exit:
SafeRelease(pContext);
pFocusDoc->Release();
}
//+---------------------------------------------------------------------------
//
// DoEditSession
//
//----------------------------------------------------------------------------
STDAPI CFlipEditSession::DoEditSession(TfEditCookie ec)
{
TF_SELECTION tfSelection;
ULONG cFetched;
// get the selection
if (_pContext->GetSelection(ec, TF_DEFAULT_SELECTION, 1, &tfSelection, &cFetched) != S_OK ||
cFetched == 0)
{
// no selection
return S_OK;
}
// do the work
ToggleCase(ec, tfSelection.range, FALSE);
// release the range
tfSelection.range->Release();
return S_OK;
}