Skip to content

Commit

Permalink
Implement ITfFnReconversion interface
Browse files Browse the repository at this point in the history
  • Loading branch information
nathancorvussolis committed Nov 7, 2016
1 parent 3439be1 commit f459d26
Show file tree
Hide file tree
Showing 12 changed files with 731 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Adobe Reader X 以降で使用するには、設定ファイル (config.xml) に

* 言語バーを右クリックし、メニューから「設定」を選択する。「テキストサービスと入力言語」ダイアログの「インストールされているサービス」からCorvusSKKを選択し、プロパティボタンを押す。
* 言語バーの入力モードアイコンを左クリックし、メニューから「設定」を選択する。
* 言語バーのヘルプボタンを左クリックし、メニューから「設定」を選択する。
* 言語バーのヘルプボタンを左クリックし、メニューから「CorvusSKK」を選択する。
* Windows 8 以降の通知領域の入力モードアイコンを右クリックし、メニューから「設定」を選択する。

設定ダイアログで保存した後は、IME OFF → ON で新しい設定が反映されます。
Expand Down Expand Up @@ -649,7 +649,7 @@ Visual Studio Community 2015 Update 3

WiX Toolset v3.10.3

pandoc 1.17.2
pandoc 1.18


### ビルド手順
Expand Down
171 changes: 171 additions & 0 deletions imcrvtip/FnCandidateList.h
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
102 changes: 102 additions & 0 deletions imcrvtip/FnCandidateString.h
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
Loading

0 comments on commit f459d26

Please sign in to comment.