-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement ITfFnReconversion interface
- Loading branch information
1 parent
3439be1
commit f459d26
Showing
12 changed files
with
731 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
|
||
#ifndef FNCANDIDATELIST_H | ||
#define FNCANDIDATELIST_H | ||
|
||
#include "TextService.h" | ||
#include "EditSession.h" | ||
#include "FnCandidateString.h" | ||
#include "FnEnumCandidates.h" | ||
|
||
class CSetResultEditSession : public CEditSessionBase | ||
{ | ||
public: | ||
CSetResultEditSession(CTextService *pTextService, ITfContext *pContext) : CEditSessionBase(pTextService, pContext) | ||
{ | ||
} | ||
|
||
~CSetResultEditSession() | ||
{ | ||
} | ||
|
||
// ITfEditSession | ||
STDMETHODIMP DoEditSession(TfEditCookie ec) | ||
{ | ||
return _pTextService->_HandleCharReturn(ec, _pContext); | ||
} | ||
}; | ||
|
||
class CFnCandidateList : public ITfCandidateList | ||
{ | ||
public: | ||
CFnCandidateList(CTextService *pTextService, const std::wstring &searchkey, const CANDIDATES &candidates) | ||
{ | ||
DllAddRef(); | ||
|
||
_cRef = 1; | ||
|
||
_pTextService = pTextService; | ||
_pTextService->AddRef(); | ||
|
||
_searchkey = searchkey; | ||
_candidates = candidates; | ||
} | ||
|
||
~CFnCandidateList() | ||
{ | ||
SafeRelease(&_pTextService); | ||
|
||
DllRelease(); | ||
} | ||
|
||
STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj) | ||
{ | ||
if(ppvObj == nullptr) | ||
{ | ||
return E_INVALIDARG; | ||
} | ||
|
||
*ppvObj = nullptr; | ||
|
||
if(IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_ITfCandidateList)) | ||
{ | ||
*ppvObj = (ITfCandidateList *)this; | ||
} | ||
|
||
if(*ppvObj) | ||
{ | ||
AddRef(); | ||
return S_OK; | ||
} | ||
|
||
return E_NOINTERFACE; | ||
} | ||
|
||
STDMETHODIMP_(ULONG) AddRef(void) | ||
{ | ||
return ++_cRef; | ||
} | ||
|
||
STDMETHODIMP_(ULONG) Release(void) | ||
{ | ||
if(--_cRef == 0) | ||
{ | ||
delete this; | ||
return 0; | ||
} | ||
|
||
return _cRef; | ||
} | ||
|
||
STDMETHODIMP EnumCandidates(IEnumTfCandidates **ppEnum) | ||
{ | ||
CFnEnumCandidates *pCandidateEnum; | ||
|
||
if(ppEnum == nullptr) | ||
{ | ||
return E_INVALIDARG; | ||
} | ||
|
||
*ppEnum = nullptr; | ||
|
||
try | ||
{ | ||
pCandidateEnum = new CFnEnumCandidates(_candidates); | ||
} | ||
catch(...) | ||
{ | ||
return E_OUTOFMEMORY; | ||
} | ||
|
||
*ppEnum = pCandidateEnum; | ||
|
||
return S_OK; | ||
} | ||
|
||
STDMETHODIMP GetCandidate(ULONG nIndex, ITfCandidateString **ppCand) | ||
{ | ||
if(ppCand == nullptr) | ||
{ | ||
return E_INVALIDARG; | ||
} | ||
|
||
*ppCand = nullptr; | ||
|
||
if(nIndex >= (ULONG)_candidates.size()) | ||
{ | ||
return E_FAIL; | ||
} | ||
|
||
try | ||
{ | ||
*ppCand = new CFnCandidateString(nIndex, _candidates[nIndex].first.first); | ||
} | ||
catch(...) | ||
{ | ||
return E_OUTOFMEMORY; | ||
} | ||
|
||
return S_OK; | ||
} | ||
|
||
STDMETHODIMP GetCandidateNum(ULONG *pnCnt) | ||
{ | ||
if(pnCnt == nullptr) | ||
{ | ||
return E_INVALIDARG; | ||
} | ||
|
||
*pnCnt = (ULONG)_candidates.size(); | ||
|
||
return S_OK; | ||
} | ||
|
||
STDMETHODIMP SetResult(ULONG nIndex, TfCandidateResult imcr) | ||
{ | ||
HRESULT hr = S_OK; | ||
if(imcr == CAND_FINALIZED) | ||
{ | ||
hr = _pTextService->_SetReconvertResult(_searchkey, _candidates, nIndex); | ||
} | ||
|
||
return hr; | ||
} | ||
|
||
private: | ||
LONG _cRef; | ||
CTextService *_pTextService; | ||
std::wstring _searchkey; | ||
CANDIDATES _candidates; | ||
}; | ||
|
||
#endif //FNCANDIDATELIST_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
|
||
#ifndef FNCANDIDATESTRING_H | ||
#define FNCANDIDATESTRING_H | ||
|
||
class CFnCandidateString : public ITfCandidateString | ||
{ | ||
public: | ||
CFnCandidateString(ULONG index, const std::wstring &candidate) | ||
{ | ||
DllAddRef(); | ||
|
||
_cRef = 1; | ||
_iIndex = index; | ||
_candidate = candidate; | ||
} | ||
|
||
~CFnCandidateString() | ||
{ | ||
DllRelease(); | ||
} | ||
|
||
STDMETHODIMP QueryInterface(REFIID riid, void **ppvObj) | ||
{ | ||
if(ppvObj == nullptr) | ||
{ | ||
return E_INVALIDARG; | ||
} | ||
|
||
*ppvObj = nullptr; | ||
|
||
if(IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_ITfCandidateString)) | ||
{ | ||
*ppvObj = (ITfCandidateString *)this; | ||
} | ||
|
||
if(*ppvObj) | ||
{ | ||
AddRef(); | ||
return S_OK; | ||
} | ||
|
||
return E_NOINTERFACE; | ||
} | ||
|
||
STDMETHODIMP_(ULONG) AddRef(void) | ||
{ | ||
return ++_cRef; | ||
} | ||
|
||
STDMETHODIMP_(ULONG) Release(void) | ||
{ | ||
if(--_cRef == 0) | ||
{ | ||
delete this; | ||
return 0; | ||
} | ||
|
||
return _cRef; | ||
} | ||
|
||
STDMETHODIMP GetString(BSTR *pbstr) | ||
{ | ||
BSTR bstr; | ||
|
||
if(pbstr == nullptr) | ||
{ | ||
return E_INVALIDARG; | ||
} | ||
|
||
*pbstr = nullptr; | ||
|
||
bstr = SysAllocString(_candidate.c_str()); | ||
|
||
if(bstr == nullptr) | ||
{ | ||
return E_OUTOFMEMORY; | ||
} | ||
|
||
*pbstr = bstr; | ||
|
||
return S_OK; | ||
} | ||
|
||
STDMETHODIMP GetIndex(ULONG *pnIndex) | ||
{ | ||
if(pnIndex == nullptr) | ||
{ | ||
return E_INVALIDARG; | ||
} | ||
|
||
*pnIndex = _iIndex; | ||
|
||
return S_OK; | ||
} | ||
|
||
private: | ||
LONG _cRef; | ||
LONG _iIndex; | ||
std::wstring _candidate; | ||
}; | ||
|
||
#endif //FNCANDIDATESTRING_H |
Oops, something went wrong.