diff --git a/image/SampleIme.ico b/image/SampleIme.ico deleted file mode 100644 index 21845ba8..00000000 Binary files a/image/SampleIme.ico and /dev/null differ diff --git a/scripts/config_files/CMakeLists.txt b/scripts/config_files/CMakeLists.txt index fc39141e..70510b74 100644 --- a/scripts/config_files/CMakeLists.txt +++ b/scripts/config_files/CMakeLists.txt @@ -1,168 +1,168 @@ -cmake_minimum_required(VERSION 3.25.0) -set(PROJECT_NAME FanImeTsf) -project(${PROJECT_NAME} LANGUAGES CXX C) - -set(CMAKE_CXX_STANDARD 17) -set(CMAKE_CXX_STANDARD_REQUIRED ON) - -add_definitions( - /D_UNICODE=1 - /DUNICODE=1 -) - -# For utf8cpp, make it use C++11 and later -add_compile_options(/Zc:__cplusplus) - -# add_definitions( -# /DFANY_DEBUG=1 -# ) - -# fmt -find_package(fmt CONFIG REQUIRED) - -# For pure-header libs installed by vcpkg like utf8cpp -include_directories("./build/vcpkg_installed/x64-windows/include") - -include_directories("./src") -include_directories("./src/Candidate") -include_directories("./src/Compartment") -include_directories("./src/Composition") -include_directories("./src/DictEngine") -include_directories("./src/DisplayAttribute") -include_directories("./src/Drawing") -include_directories("./src/Edit") -include_directories("./src/FanyLog") -include_directories("./src/File") -include_directories("./src/Global") -include_directories("./src/Header") -include_directories("./src/IME") -include_directories("./src/IPC") -include_directories("./src/Key") -include_directories("./src/LanguageBar") -include_directories("./src/Register") -include_directories("./src/Tf") -include_directories("./src/Thread") -include_directories("./src/UI") -include_directories("./src/Utils") -include_directories("./src/Window") - -add_library(${PROJECT_NAME} SHARED - # Candidate - "./src/Candidate/EnumTfCandidates.cpp" - "./src/Candidate/EnumTfCandidates.h" - "./src/Candidate/SearchCandidateProvider.cpp" - "./src/Candidate/SearchCandidateProvider.h" - "./src/Candidate/TipCandidateList.cpp" - "./src/Candidate/TipCandidateList.h" - "./src/Candidate/TipCandidateString.cpp" - "./src/Candidate/TipCandidateString.h" - # Compartment - "./src/Compartment/Compartment.cpp" - "./src/Compartment/Compartment.h" - # Composition - "./src/Composition/Composition.cpp" - "./src/Composition/CompositionProcessorEngine.cpp" - "./src/Composition/CompositionProcessorEngine.cpp" - "./src/Composition/CompositionProcessorEngine.h" - "./src/Composition/EndComposition.cpp" - "./src/Composition/StartComposition.cpp" - # DictEngine - "./src/DictEngine/BaseDictionaryEngine.cpp" - "./src/DictEngine/BaseDictionaryEngine.h" - "./src/DictEngine/DictionaryParser.cpp" - "./src/DictEngine/DictionaryParser.h" - "./src/DictEngine/DictionarySearch.cpp" - "./src/DictEngine/DictionarySearch.h" - "./src/DictEngine/TableDictionaryEngine.cpp" - "./src/DictEngine/TableDictionaryEngine.h" - # DisplayAttribute - "./src/DisplayAttribute/DisplayAttribute.cpp" - "./src/DisplayAttribute/DisplayAttributeInfo.cpp" - "./src/DisplayAttribute/DisplayAttributeInfo.h" - "./src/DisplayAttribute/DisplayAttributeProvider.cpp" - "./src/DisplayAttribute/DisplayString.h" - "./src/DisplayAttribute/EnumDisplayAttributeInfo.cpp" - "./src/DisplayAttribute/EnumDisplayAttributeInfo.h" - # Drawing - "./src/Drawing/D2DSource.cpp" - "./src/Drawing/D2DSource.h" - # Edit - "./src/Edit/EditSession.cpp" - "./src/Edit/EditSession.h" - "./src/Edit/GetTextExtentEditSession.cpp" - "./src/Edit/GetTextExtentEditSession.h" - "./src/Edit/TextEditSink.cpp" - # File - "./src/File/File.cpp" - "./src/File/File.h" - "./src/File/FileMapping.cpp" - "./src/File/FileMapping.h" - # Global - "./src/Global/FanyDefines.h" - "./src/Global/Globals.cpp" - "./src/Global/Globals.h" - # Header - "./src/Header/Define.h" - "./src/Header/Private.h" - "./src/Header/resource.h" - "./src/Header/stdafx.h" - # IME - "./src/IME/ActiveLanguageProfileNotifySink.cpp" - "./src/IME/FunctionProviderSink.cpp" - "./src/IME/SampleIME.cpp" - "./src/IME/SampleIME.def" - "./src/IME/SampleIME.h" - "./src/IME/SampleIME.rc" - "./src/IME/SampleIMEBaseStructure.cpp" - "./src/IME/SampleIMEBaseStructure.h" - "./src/IME/SampleIMEStructureArray.h" - # IPC - "./src/IPC/Ipc.cpp" - "./src/IPC/Ipc.h" - # Key - "./src/Key/KeyEventSink.cpp" - "./src/Key/KeyHandler.cpp" - "./src/Key/KeyHandlerEditSession.cpp" - "./src/Key/KeyHandlerEditSession.h" - "./src/Key/KeyStateCategory.cpp" - "./src/Key/KeyStateCategory.h" - # LanguageBar - "./src/LanguageBar/LanguageBar.cpp" - "./src/LanguageBar/LanguageBar.h" - # Register - "./src/Register/Register.cpp" - "./src/Register/RegKey.cpp" - "./src/Register/RegKey.h" - # Tf - "./src/Tf/TfInputProcessorProfile.cpp" - "./src/Tf/TfInputProcessorProfile.h" - "./src/Tf/TfTextLayoutSink.cpp" - "./src/Tf/TfTextLayoutSink.h" - # Thread - "./src/Thread/ThreadFocusSink.cpp" - "./src/Thread/ThreadMgrEventSink.cpp" - # UI - "./src/UI/CandidateListUIPresenter.cpp" - "./src/UI/CandidateListUIPresenter.h" - # Utils - "./src/Utils/CommonUtils.cpp" - "./src/Utils/CommonUtils.h" - "./src/Utils/FanyUtils.cpp" - "./src/Utils/FanyUtils.h" - # Window - "./src/Window/BaseWindow.cpp" - "./src/Window/BaseWindow.h" - "./src/Window/ButtonWindow.cpp" - "./src/Window/ButtonWindow.h" - "./src/Window/CandidateWindow.cpp" - "./src/Window/CandidateWindow.h" - "./src/Window/ScrollBarWindow.cpp" - "./src/Window/ScrollBarWindow.h" - "./src/Window/ShadowWindow.cpp" - "./src/Window/ShadowWindow.h" - # Main - "./src/DllMain.cpp" - "./src/Server.cpp" -) - +cmake_minimum_required(VERSION 3.25.0) +set(PROJECT_NAME FanImeTsf) +project(${PROJECT_NAME} LANGUAGES CXX C) + +set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD_REQUIRED ON) + +add_definitions( + /D_UNICODE=1 + /DUNICODE=1 +) + +# For utf8cpp, make it use C++11 and later +add_compile_options(/Zc:__cplusplus) + +# add_definitions( +# /DFANY_DEBUG=1 +# ) + +# fmt +find_package(fmt CONFIG REQUIRED) + +# For pure-header libs installed by vcpkg like utf8cpp +include_directories("./build/vcpkg_installed/x64-windows/include") + +include_directories("./src") +include_directories("./src/Candidate") +include_directories("./src/Compartment") +include_directories("./src/Composition") +include_directories("./src/DictEngine") +include_directories("./src/DisplayAttribute") +include_directories("./src/Drawing") +include_directories("./src/Edit") +include_directories("./src/FanyLog") +include_directories("./src/File") +include_directories("./src/Global") +include_directories("./src/Header") +include_directories("./src/IME") +include_directories("./src/IPC") +include_directories("./src/Key") +include_directories("./src/LanguageBar") +include_directories("./src/Register") +include_directories("./src/Tf") +include_directories("./src/Thread") +include_directories("./src/UI") +include_directories("./src/Utils") +include_directories("./src/Window") + +add_library(${PROJECT_NAME} SHARED + # Candidate + "./src/Candidate/EnumTfCandidates.cpp" + "./src/Candidate/EnumTfCandidates.h" + "./src/Candidate/SearchCandidateProvider.cpp" + "./src/Candidate/SearchCandidateProvider.h" + "./src/Candidate/TipCandidateList.cpp" + "./src/Candidate/TipCandidateList.h" + "./src/Candidate/TipCandidateString.cpp" + "./src/Candidate/TipCandidateString.h" + # Compartment + "./src/Compartment/Compartment.cpp" + "./src/Compartment/Compartment.h" + # Composition + "./src/Composition/Composition.cpp" + "./src/Composition/CompositionProcessorEngine.cpp" + "./src/Composition/CompositionProcessorEngine.cpp" + "./src/Composition/CompositionProcessorEngine.h" + "./src/Composition/EndComposition.cpp" + "./src/Composition/StartComposition.cpp" + # DictEngine + "./src/DictEngine/BaseDictionaryEngine.cpp" + "./src/DictEngine/BaseDictionaryEngine.h" + "./src/DictEngine/DictionaryParser.cpp" + "./src/DictEngine/DictionaryParser.h" + "./src/DictEngine/DictionarySearch.cpp" + "./src/DictEngine/DictionarySearch.h" + "./src/DictEngine/TableDictionaryEngine.cpp" + "./src/DictEngine/TableDictionaryEngine.h" + # DisplayAttribute + "./src/DisplayAttribute/DisplayAttribute.cpp" + "./src/DisplayAttribute/DisplayAttributeInfo.cpp" + "./src/DisplayAttribute/DisplayAttributeInfo.h" + "./src/DisplayAttribute/DisplayAttributeProvider.cpp" + "./src/DisplayAttribute/DisplayString.h" + "./src/DisplayAttribute/EnumDisplayAttributeInfo.cpp" + "./src/DisplayAttribute/EnumDisplayAttributeInfo.h" + # Drawing + "./src/Drawing/D2DSource.cpp" + "./src/Drawing/D2DSource.h" + # Edit + "./src/Edit/EditSession.cpp" + "./src/Edit/EditSession.h" + "./src/Edit/GetTextExtentEditSession.cpp" + "./src/Edit/GetTextExtentEditSession.h" + "./src/Edit/TextEditSink.cpp" + # File + "./src/File/File.cpp" + "./src/File/File.h" + "./src/File/FileMapping.cpp" + "./src/File/FileMapping.h" + # Global + "./src/Global/FanyDefines.h" + "./src/Global/Globals.cpp" + "./src/Global/Globals.h" + # Header + "./src/Header/Define.h" + "./src/Header/Private.h" + "./src/Header/resource.h" + "./src/Header/stdafx.h" + # IME + "./src/IME/ActiveLanguageProfileNotifySink.cpp" + "./src/IME/FunctionProviderSink.cpp" + "./src/IME/MetasequoiaIME.cpp" + "./src/IME/MetasequoiaIME.def" + "./src/IME/MetasequoiaIME.h" + "./src/IME/MetasequoiaIME.rc" + "./src/IME/MetasequoiaIMEBaseStructure.cpp" + "./src/IME/MetasequoiaIMEBaseStructure.h" + "./src/IME/MetasequoiaIMEStructureArray.h" + # IPC + "./src/IPC/Ipc.cpp" + "./src/IPC/Ipc.h" + # Key + "./src/Key/KeyEventSink.cpp" + "./src/Key/KeyHandler.cpp" + "./src/Key/KeyHandlerEditSession.cpp" + "./src/Key/KeyHandlerEditSession.h" + "./src/Key/KeyStateCategory.cpp" + "./src/Key/KeyStateCategory.h" + # LanguageBar + "./src/LanguageBar/LanguageBar.cpp" + "./src/LanguageBar/LanguageBar.h" + # Register + "./src/Register/Register.cpp" + "./src/Register/RegKey.cpp" + "./src/Register/RegKey.h" + # Tf + "./src/Tf/TfInputProcessorProfile.cpp" + "./src/Tf/TfInputProcessorProfile.h" + "./src/Tf/TfTextLayoutSink.cpp" + "./src/Tf/TfTextLayoutSink.h" + # Thread + "./src/Thread/ThreadFocusSink.cpp" + "./src/Thread/ThreadMgrEventSink.cpp" + # UI + "./src/UI/CandidateListUIPresenter.cpp" + "./src/UI/CandidateListUIPresenter.h" + # Utils + "./src/Utils/CommonUtils.cpp" + "./src/Utils/CommonUtils.h" + "./src/Utils/FanyUtils.cpp" + "./src/Utils/FanyUtils.h" + # Window + "./src/Window/BaseWindow.cpp" + "./src/Window/BaseWindow.h" + "./src/Window/ButtonWindow.cpp" + "./src/Window/ButtonWindow.h" + "./src/Window/CandidateWindow.cpp" + "./src/Window/CandidateWindow.h" + "./src/Window/ScrollBarWindow.cpp" + "./src/Window/ScrollBarWindow.h" + "./src/Window/ShadowWindow.cpp" + "./src/Window/ShadowWindow.h" + # Main + "./src/DllMain.cpp" + "./src/Server.cpp" +) + target_link_libraries(${PROJECT_NAME} PRIVATE fmt::fmt-header-only) \ No newline at end of file diff --git a/src/Candidate/EnumTfCandidates.cpp b/src/Candidate/EnumTfCandidates.cpp index cf19bde2..12a80eea 100644 --- a/src/Candidate/EnumTfCandidates.cpp +++ b/src/Candidate/EnumTfCandidates.cpp @@ -9,7 +9,7 @@ #include "EnumTfCandidates.h" HRESULT CEnumTfCandidates::CreateInstance(_Out_ CEnumTfCandidates **ppobj, - _In_ const CSampleImeArray &rgelm, UINT currentNum) + _In_ const CMetasequoiaImeArray &rgelm, UINT currentNum) { if (ppobj == nullptr) { @@ -27,7 +27,7 @@ HRESULT CEnumTfCandidates::CreateInstance(_Out_ CEnumTfCandidates **ppobj, } HRESULT CEnumTfCandidates::CreateInstance(REFIID riid, _Out_ void **ppvObj, - _In_ const CSampleImeArray &rgelm, UINT currentNum) + _In_ const CMetasequoiaImeArray &rgelm, UINT currentNum) { if (ppvObj == nullptr) { @@ -44,7 +44,7 @@ HRESULT CEnumTfCandidates::CreateInstance(REFIID riid, _Out_ void **ppvObj, return ((CEnumTfCandidates *)(*ppvObj))->QueryInterface(riid, ppvObj); } -CEnumTfCandidates::CEnumTfCandidates(_In_ const CSampleImeArray &rgelm, UINT currentNum) +CEnumTfCandidates::CEnumTfCandidates(_In_ const CMetasequoiaImeArray &rgelm, UINT currentNum) { _refCount = 0; _rgelm = rgelm; diff --git a/src/Candidate/EnumTfCandidates.h b/src/Candidate/EnumTfCandidates.h index aefbb9ff..00506a09 100644 --- a/src/Candidate/EnumTfCandidates.h +++ b/src/Candidate/EnumTfCandidates.h @@ -13,16 +13,16 @@ class CEnumTfCandidates : public IEnumTfCandidates { protected: // constructor/destructor - CEnumTfCandidates(_In_ const CSampleImeArray &rgelm, UINT currentNum); + CEnumTfCandidates(_In_ const CMetasequoiaImeArray &rgelm, UINT currentNum); virtual ~CEnumTfCandidates(void); public: // create instance static HRESULT CreateInstance(_Out_ CEnumTfCandidates **ppobj, - _In_ const CSampleImeArray &rgelm, UINT currentNum = 0); + _In_ const CMetasequoiaImeArray &rgelm, UINT currentNum = 0); static HRESULT CreateInstance(REFIID riid, _Out_ void **ppvObj, - _In_ const CSampleImeArray &rgelm, UINT currentNum = 0); + _In_ const CMetasequoiaImeArray &rgelm, UINT currentNum = 0); // IUnknown methods virtual STDMETHODIMP QueryInterface(REFIID riid, _Outptr_ void **ppvObj); @@ -37,6 +37,6 @@ class CEnumTfCandidates : public IEnumTfCandidates protected: LONG _refCount; - CSampleImeArray _rgelm; + CMetasequoiaImeArray _rgelm; UINT _currentCandidateStrIndex; }; diff --git a/src/Candidate/SearchCandidateProvider.cpp b/src/Candidate/SearchCandidateProvider.cpp index 15251dfd..4d457e8b 100644 --- a/src/Candidate/SearchCandidateProvider.cpp +++ b/src/Candidate/SearchCandidateProvider.cpp @@ -8,7 +8,7 @@ #include "Private.h" #include "SearchCandidateProvider.h" #include -#include "SampleIME.h" +#include "MetasequoiaIME.h" #include "CompositionProcessorEngine.h" #include "TipCandidateList.h" #include "TipCandidateString.h" @@ -166,13 +166,13 @@ STDMETHODIMP CSearchCandidateProvider::GetSearchCandidates(BSTR bstrQuery, BSTR return hr; } - CCompositionProcessorEngine *pCompositionProcessorEngine = ((CSampleIME *)_pTip)->GetCompositionProcessorEngine(); + CCompositionProcessorEngine *pCompositionProcessorEngine = ((CMetasequoiaIME *)_pTip)->GetCompositionProcessorEngine(); if (nullptr == pCompositionProcessorEngine) { return hr; } - CSampleImeArray candidateList; + CMetasequoiaImeArray candidateList; pCompositionProcessorEngine->GetCandidateList(&candidateList, TRUE, FALSE); int cCand = min(candidateList.Count(), FAKECANDIDATENUMBER); diff --git a/src/Candidate/TipCandidateList.h b/src/Candidate/TipCandidateList.h index 322ad9b3..d6649c7f 100644 --- a/src/Candidate/TipCandidateList.h +++ b/src/Candidate/TipCandidateList.h @@ -8,7 +8,7 @@ #pragma once #include "Private.h" -#include "SampleIMEBaseStructure.h" +#include "MetasequoiaIMEBaseStructure.h" // // CTipCandidateList @@ -39,5 +39,5 @@ class CTipCandidateList : public ITfCandidateList protected: long _refCount; - CSampleImeArray _tfCandStrList; + CMetasequoiaImeArray _tfCandStrList; }; diff --git a/src/Composition/Composition.cpp b/src/Composition/Composition.cpp index 1846f509..12fda99b 100644 --- a/src/Composition/Composition.cpp +++ b/src/Composition/Composition.cpp @@ -7,7 +7,7 @@ #include "Private.h" #include "Globals.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" #include "CompositionProcessorEngine.h" #include #include @@ -22,7 +22,7 @@ // someone other than this service ends a composition. //---------------------------------------------------------------------------- -STDAPI CSampleIME::OnCompositionTerminated(TfEditCookie ecWrite, _In_ ITfComposition *pComposition) +STDAPI CMetasequoiaIME::OnCompositionTerminated(TfEditCookie ecWrite, _In_ ITfComposition *pComposition) { // Clear dummy composition _RemoveDummyCompositionForComposing(ecWrite, pComposition); @@ -53,7 +53,7 @@ STDAPI CSampleIME::OnCompositionTerminated(TfEditCookie ecWrite, _In_ ITfComposi // //---------------------------------------------------------------------------- -BOOL CSampleIME::_IsComposing() +BOOL CMetasequoiaIME::_IsComposing() { return _pComposition != nullptr; } @@ -64,7 +64,7 @@ BOOL CSampleIME::_IsComposing() // //---------------------------------------------------------------------------- -void CSampleIME::_SetComposition(_In_ ITfComposition *pComposition) +void CMetasequoiaIME::_SetComposition(_In_ ITfComposition *pComposition) { _pComposition = pComposition; } @@ -75,7 +75,7 @@ void CSampleIME::_SetComposition(_In_ ITfComposition *pComposition) // //---------------------------------------------------------------------------- -HRESULT CSampleIME::_AddComposingAndChar(TfEditCookie ec, _In_ ITfContext *pContext, _In_ CStringRange *pstrAddString) +HRESULT CMetasequoiaIME::_AddComposingAndChar(TfEditCookie ec, _In_ ITfContext *pContext, _In_ CStringRange *pstrAddString) { #ifdef FANY_DEBUG OutputDebugString(fmt::format(L"You entered _AddComposingAndChar{}\n", pstrAddString->Get()).c_str()); @@ -144,7 +144,7 @@ HRESULT CSampleIME::_AddComposingAndChar(TfEditCookie ec, _In_ ITfContext *pCont // //---------------------------------------------------------------------------- -HRESULT CSampleIME::_AddCharAndFinalize(TfEditCookie ec, _In_ ITfContext *pContext, _In_ CStringRange *pstrAddString) +HRESULT CMetasequoiaIME::_AddCharAndFinalize(TfEditCookie ec, _In_ ITfContext *pContext, _In_ CStringRange *pstrAddString) { HRESULT hr = E_FAIL; @@ -176,7 +176,7 @@ HRESULT CSampleIME::_AddCharAndFinalize(TfEditCookie ec, _In_ ITfContext *pConte // //---------------------------------------------------------------------------- -BOOL CSampleIME::_FindComposingRange(TfEditCookie ec, _In_ ITfContext *pContext, _In_ ITfRange *pSelection, +BOOL CMetasequoiaIME::_FindComposingRange(TfEditCookie ec, _In_ ITfContext *pContext, _In_ ITfRange *pSelection, _Outptr_result_maybenull_ ITfRange **ppRange) { if (ppRange == nullptr) @@ -234,7 +234,7 @@ BOOL CSampleIME::_FindComposingRange(TfEditCookie ec, _In_ ITfContext *pContext, // //---------------------------------------------------------------------------- -HRESULT CSampleIME::_SetInputString(TfEditCookie ec, _In_ ITfContext *pContext, _Out_opt_ ITfRange *pRange, +HRESULT CMetasequoiaIME::_SetInputString(TfEditCookie ec, _In_ ITfContext *pContext, _Out_opt_ ITfRange *pRange, _In_ CStringRange *pstrAddString, BOOL exist_composing) { ITfRange *pRangeInsert = nullptr; @@ -286,7 +286,7 @@ HRESULT CSampleIME::_SetInputString(TfEditCookie ec, _In_ ITfContext *pContext, // //---------------------------------------------------------------------------- -HRESULT CSampleIME::_InsertAtSelection(TfEditCookie ec, _In_ ITfContext *pContext, _In_ CStringRange *pstrAddString, +HRESULT CMetasequoiaIME::_InsertAtSelection(TfEditCookie ec, _In_ ITfContext *pContext, _In_ CStringRange *pstrAddString, _Outptr_ ITfRange **ppCompRange) { ITfRange *rangeInsert = nullptr; @@ -331,7 +331,7 @@ Exit: // //---------------------------------------------------------------------------- -HRESULT CSampleIME::_RemoveDummyCompositionForComposing(TfEditCookie ec, _In_ ITfComposition *pComposition) +HRESULT CMetasequoiaIME::_RemoveDummyCompositionForComposing(TfEditCookie ec, _In_ ITfComposition *pComposition) { HRESULT hr = S_OK; @@ -356,7 +356,7 @@ HRESULT CSampleIME::_RemoveDummyCompositionForComposing(TfEditCookie ec, _In_ IT // //---------------------------------------------------------------------------- -BOOL CSampleIME::_SetCompositionLanguage(TfEditCookie ec, _In_ ITfContext *pContext) +BOOL CMetasequoiaIME::_SetCompositionLanguage(TfEditCookie ec, _In_ ITfContext *pContext) { HRESULT hr = S_OK; BOOL ret = TRUE; diff --git a/src/Composition/CompositionProcessorEngine.cpp b/src/Composition/CompositionProcessorEngine.cpp index 830383a1..83e2750f 100644 --- a/src/Composition/CompositionProcessorEngine.cpp +++ b/src/Composition/CompositionProcessorEngine.cpp @@ -3,7 +3,7 @@ #endif #include "Private.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" #include "CompositionProcessorEngine.h" #include "TableDictionaryEngine.h" #include "TfInputProcessorProfile.h" @@ -19,7 +19,7 @@ ////////////////////////////////////////////////////////////////////// // -// CSampleIME implementation. +// CMetasequoiaIME implementation. // ////////////////////////////////////////////////////////////////////// @@ -29,7 +29,7 @@ // //---------------------------------------------------------------------------- -BOOL CSampleIME::_AddTextProcessorEngine() +BOOL CMetasequoiaIME::_AddTextProcessorEngine() { LANGID langid = 0; CLSID clsid = GUID_NULL; @@ -234,7 +234,7 @@ BOOL CCompositionProcessorEngine::SetupLanguageProfile(LANGID langid, REFGUID gu _tfClientId = tfClientId; SetupPreserved(pThreadMgr, tfClientId); - InitializeSampleIMECompartment(pThreadMgr, tfClientId); + InitializeMetasequoiaIMECompartment(pThreadMgr, tfClientId); SetupPunctuationPair(); SetupLanguageBar(pThreadMgr, tfClientId, isSecureMode); SetupKeystroke(); @@ -351,7 +351,7 @@ WCHAR CCompositionProcessorEngine::GetVirtualKey(DWORD_PTR dwIndex) // //---------------------------------------------------------------------------- -void CCompositionProcessorEngine::GetReadingStrings(_Inout_ CSampleImeArray *pReadingStrings, +void CCompositionProcessorEngine::GetReadingStrings(_Inout_ CMetasequoiaImeArray *pReadingStrings, _Out_ BOOL *pIsWildcardIncluded) { CStringRange oneKeystroke; @@ -388,7 +388,7 @@ void CCompositionProcessorEngine::GetReadingStrings(_Inout_ CSampleImeArray *pCandidateList, +void CCompositionProcessorEngine::GetCandidateList(_Inout_ CMetasequoiaImeArray *pCandidateList, BOOL isIncrementalWordSearch, BOOL isWildcardSearch) { // @@ -529,7 +529,7 @@ void CCompositionProcessorEngine::GetCandidateList(_Inout_ CSampleImeArray *pCandidateList) + CStringRange &searchString, _In_ CMetasequoiaImeArray *pCandidateList) { if (!IsDictionaryAvailable()) { @@ -707,7 +707,7 @@ void CCompositionProcessorEngine::SetupKeystroke() // //---------------------------------------------------------------------------- -void CCompositionProcessorEngine::SetKeystrokeTable(_Inout_ CSampleImeArray<_KEYSTROKE> *pKeystroke) +void CCompositionProcessorEngine::SetKeystrokeTable(_Inout_ CMetasequoiaImeArray<_KEYSTROKE> *pKeystroke) { for (int i = 0; i < 26; i++) { @@ -734,19 +734,19 @@ void CCompositionProcessorEngine::SetupPreserved(_In_ ITfThreadMgr *pThreadMgr, TF_PRESERVEDKEY preservedKeyImeMode; preservedKeyImeMode.uVKey = VK_SHIFT; preservedKeyImeMode.uModifiers = _TF_MOD_ON_KEYUP_SHIFT_ONLY; - SetPreservedKey(Global::SampleIMEGuidImeModePreserveKey, preservedKeyImeMode, Global::ImeModeDescription, + SetPreservedKey(Global::MetasequoiaIMEGuidImeModePreserveKey, preservedKeyImeMode, Global::ImeModeDescription, &_PreservedKey_IMEMode); TF_PRESERVEDKEY preservedKeyDoubleSingleByte; preservedKeyDoubleSingleByte.uVKey = VK_SPACE; preservedKeyDoubleSingleByte.uModifiers = TF_MOD_SHIFT | TF_MOD_CONTROL; - SetPreservedKey(Global::SampleIMEGuidDoubleSingleBytePreserveKey, preservedKeyDoubleSingleByte, + SetPreservedKey(Global::MetasequoiaIMEGuidDoubleSingleBytePreserveKey, preservedKeyDoubleSingleByte, Global::DoubleSingleByteDescription, &_PreservedKey_DoubleSingleByte); TF_PRESERVEDKEY preservedKeyPunctuation; preservedKeyPunctuation.uVKey = VK_OEM_PERIOD; preservedKeyPunctuation.uModifiers = TF_MOD_CONTROL; - SetPreservedKey(Global::SampleIMEGuidPunctuationPreserveKey, preservedKeyPunctuation, + SetPreservedKey(Global::MetasequoiaIMEGuidPunctuationPreserveKey, preservedKeyPunctuation, Global::PunctuationDescription, &_PreservedKey_Punctuation); InitPreservedKey(&_PreservedKey_IMEMode, pThreadMgr, tfClientId); @@ -837,7 +837,7 @@ BOOL CCompositionProcessorEngine::InitPreservedKey(_In_ XPreservedKey *pXPreserv // //---------------------------------------------------------------------------- -BOOL CCompositionProcessorEngine::CheckShiftKeyOnly(_In_ CSampleImeArray *pTSFPreservedKeyTable) +BOOL CCompositionProcessorEngine::CheckShiftKeyOnly(_In_ CMetasequoiaImeArray *pTSFPreservedKeyTable) { for (UINT i = 0; i < pTSFPreservedKeyTable->Count(); i++) { @@ -878,7 +878,7 @@ void CCompositionProcessorEngine::OnPreservedKey(ITfContext *pContext, REFGUID r // Also toggle punctuation mode BOOL isPunctuation = FALSE; - CCompartment CompartmentPunctuation(pThreadMgr, tfClientId, Global::SampleIMEGuidCompartmentPunctuation); + CCompartment CompartmentPunctuation(pThreadMgr, tfClientId, Global::MetasequoiaIMEGuidCompartmentPunctuation); CompartmentPunctuation._GetCompartmentBOOL(isPunctuation); CompartmentPunctuation._SetCompartmentBOOL(isPunctuation ? FALSE : TRUE); @@ -894,7 +894,7 @@ void CCompositionProcessorEngine::OnPreservedKey(ITfContext *pContext, REFGUID r } BOOL isDouble = FALSE; CCompartment CompartmentDoubleSingleByte(pThreadMgr, tfClientId, - Global::SampleIMEGuidCompartmentDoubleSingleByte); + Global::MetasequoiaIMEGuidCompartmentDoubleSingleByte); CompartmentDoubleSingleByte._GetCompartmentBOOL(isDouble); CompartmentDoubleSingleByte._SetCompartmentBOOL(isDouble ? FALSE : TRUE); *pIsEaten = TRUE; @@ -908,7 +908,7 @@ void CCompositionProcessorEngine::OnPreservedKey(ITfContext *pContext, REFGUID r } // Ctrl + .: toggle Chinese/English punctuation BOOL isPunctuation = FALSE; - CCompartment CompartmentPunctuation(pThreadMgr, tfClientId, Global::SampleIMEGuidCompartmentPunctuation); + CCompartment CompartmentPunctuation(pThreadMgr, tfClientId, Global::MetasequoiaIMEGuidCompartmentPunctuation); CompartmentPunctuation._GetCompartmentBOOL(isPunctuation); CompartmentPunctuation._SetCompartmentBOOL(isPunctuation ? FALSE : TRUE); *pIsEaten = TRUE; @@ -934,7 +934,7 @@ void CCompositionProcessorEngine::ToggleIMEMode(_In_ ITfThreadMgr *pThreadMgr, T // Also toggle punctuation mode BOOL isPunctuation = FALSE; - CCompartment CompartmentPunctuation(pThreadMgr, tfClientId, Global::SampleIMEGuidCompartmentPunctuation); + CCompartment CompartmentPunctuation(pThreadMgr, tfClientId, Global::MetasequoiaIMEGuidCompartmentPunctuation); CompartmentPunctuation._GetCompartmentBOOL(isPunctuation); CompartmentPunctuation._SetCompartmentBOOL(isPunctuation ? FALSE : TRUE); } @@ -973,18 +973,18 @@ void CCompositionProcessorEngine::SetupLanguageBar(_In_ ITfThreadMgr *pThreadMgr CreateLanguageBarButton(dwEnable, GUID_LBI_INPUTMODE, Global::LangbarImeModeDescription, Global::ImeModeDescription, Global::ImeModeOnIcoIndex, Global::ImeModeOffIcoIndex, &_pLanguageBar_IMEMode, isSecureMode); - CreateLanguageBarButton(dwEnable, Global::SampleIMEGuidLangBarDoubleSingleByte, + CreateLanguageBarButton(dwEnable, Global::MetasequoiaIMEGuidLangBarDoubleSingleByte, Global::LangbarDoubleSingleByteDescription, Global::DoubleSingleByteDescription, Global::DoubleSingleByteOnIcoIndex, Global::DoubleSingleByteOffIcoIndex, &_pLanguageBar_DoubleSingleByte, isSecureMode); - CreateLanguageBarButton(dwEnable, Global::SampleIMEGuidLangBarPunctuation, Global::LangbarPunctuationDescription, + CreateLanguageBarButton(dwEnable, Global::MetasequoiaIMEGuidLangBarPunctuation, Global::LangbarPunctuationDescription, Global::PunctuationDescription, Global::PunctuationOnIcoIndex, Global::PunctuationOffIcoIndex, &_pLanguageBar_Punctuation, isSecureMode); InitLanguageBar(_pLanguageBar_IMEMode, pThreadMgr, tfClientId, GUID_COMPARTMENT_KEYBOARD_OPENCLOSE); InitLanguageBar(_pLanguageBar_DoubleSingleByte, pThreadMgr, tfClientId, - Global::SampleIMEGuidCompartmentDoubleSingleByte); - InitLanguageBar(_pLanguageBar_Punctuation, pThreadMgr, tfClientId, Global::SampleIMEGuidCompartmentPunctuation); + Global::MetasequoiaIMEGuidCompartmentDoubleSingleByte); + InitLanguageBar(_pLanguageBar_Punctuation, pThreadMgr, tfClientId, Global::MetasequoiaIMEGuidCompartmentPunctuation); _pCompartmentConversion = new (std::nothrow) CCompartment(pThreadMgr, tfClientId, GUID_COMPARTMENT_KEYBOARD_INPUTMODE_CONVERSION); @@ -1003,11 +1003,11 @@ void CCompositionProcessorEngine::SetupLanguageBar(_In_ ITfThreadMgr *pThreadMgr } if (_pCompartmentDoubleSingleByteEventSink) { - _pCompartmentDoubleSingleByteEventSink->_Advise(pThreadMgr, Global::SampleIMEGuidCompartmentDoubleSingleByte); + _pCompartmentDoubleSingleByteEventSink->_Advise(pThreadMgr, Global::MetasequoiaIMEGuidCompartmentDoubleSingleByte); } if (_pCompartmentPunctuationEventSink) { - _pCompartmentPunctuationEventSink->_Advise(pThreadMgr, Global::SampleIMEGuidCompartmentPunctuation); + _pCompartmentPunctuationEventSink->_Advise(pThreadMgr, Global::MetasequoiaIMEGuidCompartmentPunctuation); } return; @@ -1178,16 +1178,16 @@ void CCompositionProcessorEngine::SetupPunctuationPair() *pPuncNestPair = punc_angle_bracket; } -void CCompositionProcessorEngine::InitializeSampleIMECompartment(_In_ ITfThreadMgr *pThreadMgr, TfClientId tfClientId) +void CCompositionProcessorEngine::InitializeMetasequoiaIMECompartment(_In_ ITfThreadMgr *pThreadMgr, TfClientId tfClientId) { // set initial mode CCompartment CompartmentKeyboardOpen(pThreadMgr, tfClientId, GUID_COMPARTMENT_KEYBOARD_OPENCLOSE); CompartmentKeyboardOpen._SetCompartmentBOOL(TRUE); - CCompartment CompartmentDoubleSingleByte(pThreadMgr, tfClientId, Global::SampleIMEGuidCompartmentDoubleSingleByte); + CCompartment CompartmentDoubleSingleByte(pThreadMgr, tfClientId, Global::MetasequoiaIMEGuidCompartmentDoubleSingleByte); CompartmentDoubleSingleByte._SetCompartmentBOOL(FALSE); - CCompartment CompartmentPunctuation(pThreadMgr, tfClientId, Global::SampleIMEGuidCompartmentPunctuation); + CCompartment CompartmentPunctuation(pThreadMgr, tfClientId, Global::MetasequoiaIMEGuidCompartmentPunctuation); CompartmentPunctuation._SetCompartmentBOOL(TRUE); PrivateCompartmentsUpdated(pThreadMgr); @@ -1215,8 +1215,8 @@ HRESULT CCompositionProcessorEngine::CompartmentCallback(_In_ void *pv, REFGUID return E_FAIL; } - if (IsEqualGUID(guidCompartment, Global::SampleIMEGuidCompartmentDoubleSingleByte) || - IsEqualGUID(guidCompartment, Global::SampleIMEGuidCompartmentPunctuation)) + if (IsEqualGUID(guidCompartment, Global::MetasequoiaIMEGuidCompartmentDoubleSingleByte) || + IsEqualGUID(guidCompartment, Global::MetasequoiaIMEGuidCompartmentPunctuation)) { fakeThis->PrivateCompartmentsUpdated(pThreadMgr); } @@ -1256,7 +1256,7 @@ void CCompositionProcessorEngine::ConversionModeCompartmentUpdated(_In_ ITfThrea } BOOL isDouble = FALSE; - CCompartment CompartmentDoubleSingleByte(pThreadMgr, _tfClientId, Global::SampleIMEGuidCompartmentDoubleSingleByte); + CCompartment CompartmentDoubleSingleByte(pThreadMgr, _tfClientId, Global::MetasequoiaIMEGuidCompartmentDoubleSingleByte); if (SUCCEEDED(CompartmentDoubleSingleByte._GetCompartmentBOOL(isDouble))) { if (!isDouble && (conversionMode & TF_CONVERSIONMODE_FULLSHAPE)) @@ -1269,7 +1269,7 @@ void CCompositionProcessorEngine::ConversionModeCompartmentUpdated(_In_ ITfThrea } } BOOL isPunctuation = FALSE; - CCompartment CompartmentPunctuation(pThreadMgr, _tfClientId, Global::SampleIMEGuidCompartmentPunctuation); + CCompartment CompartmentPunctuation(pThreadMgr, _tfClientId, Global::MetasequoiaIMEGuidCompartmentPunctuation); if (SUCCEEDED(CompartmentPunctuation._GetCompartmentBOOL(isPunctuation))) { if (!isPunctuation && (conversionMode & TF_CONVERSIONMODE_SYMBOL)) @@ -1320,7 +1320,7 @@ void CCompositionProcessorEngine::PrivateCompartmentsUpdated(_In_ ITfThreadMgr * conversionModePrev = conversionMode; BOOL isDouble = FALSE; - CCompartment CompartmentDoubleSingleByte(pThreadMgr, _tfClientId, Global::SampleIMEGuidCompartmentDoubleSingleByte); + CCompartment CompartmentDoubleSingleByte(pThreadMgr, _tfClientId, Global::MetasequoiaIMEGuidCompartmentDoubleSingleByte); if (SUCCEEDED(CompartmentDoubleSingleByte._GetCompartmentBOOL(isDouble))) { if (!isDouble && (conversionMode & TF_CONVERSIONMODE_FULLSHAPE)) @@ -1334,7 +1334,7 @@ void CCompositionProcessorEngine::PrivateCompartmentsUpdated(_In_ ITfThreadMgr * } BOOL isPunctuation = FALSE; - CCompartment CompartmentPunctuation(pThreadMgr, _tfClientId, Global::SampleIMEGuidCompartmentPunctuation); + CCompartment CompartmentPunctuation(pThreadMgr, _tfClientId, Global::MetasequoiaIMEGuidCompartmentPunctuation); if (SUCCEEDED(CompartmentPunctuation._GetCompartmentBOOL(isPunctuation))) { if (!isPunctuation && (conversionMode & TF_CONVERSIONMODE_SYMBOL)) @@ -1460,11 +1460,11 @@ CCompositionProcessorEngine::XPreservedKey::~XPreservedKey() } //+--------------------------------------------------------------------------- // -// CSampleIME::CreateInstance +// CMetasequoiaIME::CreateInstance // //---------------------------------------------------------------------------- -HRESULT CSampleIME::CreateInstance(REFCLSID rclsid, REFIID riid, _Outptr_result_maybenull_ LPVOID *ppv, +HRESULT CMetasequoiaIME::CreateInstance(REFCLSID rclsid, REFIID riid, _Outptr_result_maybenull_ LPVOID *ppv, _Out_opt_ HINSTANCE *phInst, BOOL isComLessMode) { HRESULT hr = S_OK; @@ -1481,7 +1481,7 @@ HRESULT CSampleIME::CreateInstance(REFCLSID rclsid, REFIID riid, _Outptr_result_ } else { - hr = CSampleIME::ComLessCreateInstance(rclsid, riid, ppv, phInst); + hr = CMetasequoiaIME::ComLessCreateInstance(rclsid, riid, ppv, phInst); } return hr; @@ -1489,15 +1489,15 @@ HRESULT CSampleIME::CreateInstance(REFCLSID rclsid, REFIID riid, _Outptr_result_ //+--------------------------------------------------------------------------- // -// CSampleIME::ComLessCreateInstance +// CMetasequoiaIME::ComLessCreateInstance // //---------------------------------------------------------------------------- -HRESULT CSampleIME::ComLessCreateInstance(REFGUID rclsid, REFIID riid, _Outptr_result_maybenull_ void **ppv, +HRESULT CMetasequoiaIME::ComLessCreateInstance(REFGUID rclsid, REFIID riid, _Outptr_result_maybenull_ void **ppv, _Out_opt_ HINSTANCE *phInst) { HRESULT hr = S_OK; - HINSTANCE sampleIMEDllHandle = nullptr; + HINSTANCE metasequoiaIMEDllHandle = nullptr; WCHAR wchPath[MAX_PATH] = {'\0'}; WCHAR szExpandedPath[MAX_PATH] = {'\0'}; DWORD dwCnt = 0; @@ -1507,19 +1507,19 @@ HRESULT CSampleIME::ComLessCreateInstance(REFGUID rclsid, REFIID riid, _Outptr_r if (SUCCEEDED(hr)) { *phInst = nullptr; - hr = CSampleIME::GetComModuleName(rclsid, wchPath, ARRAYSIZE(wchPath)); + hr = CMetasequoiaIME::GetComModuleName(rclsid, wchPath, ARRAYSIZE(wchPath)); if (SUCCEEDED(hr)) { dwCnt = ExpandEnvironmentStringsW(wchPath, szExpandedPath, ARRAYSIZE(szExpandedPath)); hr = (0 < dwCnt && dwCnt <= ARRAYSIZE(szExpandedPath)) ? S_OK : E_FAIL; if (SUCCEEDED(hr)) { - sampleIMEDllHandle = LoadLibraryEx(szExpandedPath, NULL, 0); - hr = sampleIMEDllHandle ? S_OK : E_FAIL; + metasequoiaIMEDllHandle = LoadLibraryEx(szExpandedPath, NULL, 0); + hr = metasequoiaIMEDllHandle ? S_OK : E_FAIL; if (SUCCEEDED(hr)) { - *phInst = sampleIMEDllHandle; - FARPROC pfn = GetProcAddress(sampleIMEDllHandle, "DllGetClassObject"); + *phInst = metasequoiaIMEDllHandle; + FARPROC pfn = GetProcAddress(metasequoiaIMEDllHandle, "DllGetClassObject"); hr = pfn ? S_OK : E_FAIL; if (SUCCEEDED(hr)) { @@ -1547,11 +1547,11 @@ HRESULT CSampleIME::ComLessCreateInstance(REFGUID rclsid, REFIID riid, _Outptr_r //+--------------------------------------------------------------------------- // -// CSampleIME::GetComModuleName +// CMetasequoiaIME::GetComModuleName // //---------------------------------------------------------------------------- -HRESULT CSampleIME::GetComModuleName(REFGUID rclsid, _Out_writes_(cchPath) WCHAR *wchPath, DWORD cchPath) +HRESULT CMetasequoiaIME::GetComModuleName(REFGUID rclsid, _Out_writes_(cchPath) WCHAR *wchPath, DWORD cchPath) { HRESULT hr = S_OK; @@ -2361,7 +2361,7 @@ BOOL CCompositionProcessorEngine::IsVirtualKeyKeystrokeComposition(UINT uCode, _ BOOL CCompositionProcessorEngine::IsVirtualKeyKeystrokeCandidate(UINT uCode, _In_ _KEYSTROKE_STATE *pKeyState, CANDIDATE_MODE candidateMode, _Out_ BOOL *pfRetCode, - _In_ CSampleImeArray<_KEYSTROKE> *pKeystrokeMetric) + _In_ CMetasequoiaImeArray<_KEYSTROKE> *pKeystrokeMetric) { if (pfRetCode == nullptr) { diff --git a/src/Composition/CompositionProcessorEngine.h b/src/Composition/CompositionProcessorEngine.h index 6aa80a0c..a9a8a911 100644 --- a/src/Composition/CompositionProcessorEngine.h +++ b/src/Composition/CompositionProcessorEngine.h @@ -1,17 +1,17 @@ #pragma once -#include "SampleIME.h" +#include "MetasequoiaIME.h" #include "sal.h" #include "TableDictionaryEngine.h" #include "KeyHandlerEditSession.h" -#include "SampleIMEBaseStructure.h" +#include "MetasequoiaIMEBaseStructure.h" #include "FileMapping.h" #include "Compartment.h" #include "define.h" class CCompositionProcessorEngine { - friend class CSampleIME; + friend class CMetasequoiaIME; public: CCompositionProcessorEngine(void); @@ -49,11 +49,11 @@ class CCompositionProcessorEngine }; WCHAR GetVirtualKey(DWORD_PTR dwIndex); - void GetReadingStrings(_Inout_ CSampleImeArray *pReadingStrings, _Out_ BOOL *pIsWildcardIncluded); - void GetCandidateList(_Inout_ CSampleImeArray *pCandidateList, BOOL isIncrementalWordSearch, + void GetReadingStrings(_Inout_ CMetasequoiaImeArray *pReadingStrings, _Out_ BOOL *pIsWildcardIncluded); + void GetCandidateList(_Inout_ CMetasequoiaImeArray *pCandidateList, BOOL isIncrementalWordSearch, BOOL isWildcardSearch); void GetCandidateStringInConverted(CStringRange &searchString, - _In_ CSampleImeArray *pCandidateList); + _In_ CMetasequoiaImeArray *pCandidateList); // Preserved key handler void OnPreservedKey(ITfContext *pContext, REFGUID rguid, _Out_ BOOL *pIsEaten, _In_ ITfThreadMgr *pThreadMgr, @@ -133,27 +133,27 @@ class CCompositionProcessorEngine BOOL IsVirtualKeyKeystrokeComposition(UINT uCode, _Out_opt_ _KEYSTROKE_STATE *pKeyState, KEYSTROKE_FUNCTION function); BOOL IsVirtualKeyKeystrokeCandidate(UINT uCode, _In_ _KEYSTROKE_STATE *pKeyState, CANDIDATE_MODE candidateMode, - _Out_ BOOL *pfRetCode, _In_ CSampleImeArray<_KEYSTROKE> *pKeystrokeMetric); + _Out_ BOOL *pfRetCode, _In_ CMetasequoiaImeArray<_KEYSTROKE> *pKeystrokeMetric); BOOL IsKeystrokeRange(UINT uCode, _Out_ _KEYSTROKE_STATE *pKeyState, CANDIDATE_MODE candidateMode); void SetupKeystroke(); void SetupPreserved(_In_ ITfThreadMgr *pThreadMgr, TfClientId tfClientId); void SetupConfiguration(); void SetupLanguageBar(_In_ ITfThreadMgr *pThreadMgr, TfClientId tfClientId, BOOL isSecureMode); - void SetKeystrokeTable(_Inout_ CSampleImeArray<_KEYSTROKE> *pKeystroke); + void SetKeystrokeTable(_Inout_ CMetasequoiaImeArray<_KEYSTROKE> *pKeystroke); void SetupPunctuationPair(); void CreateLanguageBarButton(DWORD dwEnable, GUID guidLangBar, _In_z_ LPCWSTR pwszDescriptionValue, _In_z_ LPCWSTR pwszTooltipValue, DWORD dwOnIconIndex, DWORD dwOffIconIndex, _Outptr_result_maybenull_ CLangBarItemButton **ppLangBarItemButton, BOOL isSecureMode); void SetInitialCandidateListRange(); void SetDefaultCandidateTextFont(); - void InitializeSampleIMECompartment(_In_ ITfThreadMgr *pThreadMgr, TfClientId tfClientId); + void InitializeMetasequoiaIMECompartment(_In_ ITfThreadMgr *pThreadMgr, TfClientId tfClientId); class XPreservedKey; void SetPreservedKey(const CLSID clsid, TF_PRESERVEDKEY &tfPreservedKey, _In_z_ LPCWSTR pwszDescription, _Out_ XPreservedKey *pXPreservedKey); BOOL InitPreservedKey(_In_ XPreservedKey *pXPreservedKey, _In_ ITfThreadMgr *pThreadMgr, TfClientId tfClientId); - BOOL CheckShiftKeyOnly(_In_ CSampleImeArray *pTSFPreservedKeyTable); + BOOL CheckShiftKeyOnly(_In_ CMetasequoiaImeArray *pTSFPreservedKeyTable); static HRESULT CompartmentCallback(_In_ void *pv, REFGUID guidCompartment); void PrivateCompartmentsUpdated(_In_ ITfThreadMgr *pThreadMgr); @@ -187,11 +187,11 @@ class CCompositionProcessorEngine GUID _guidProfile; TfClientId _tfClientId; - CSampleImeArray<_KEYSTROKE> _KeystrokeComposition; - CSampleImeArray<_KEYSTROKE> _KeystrokeCandidate; - CSampleImeArray<_KEYSTROKE> _KeystrokeCandidateWildcard; - CSampleImeArray<_KEYSTROKE> _KeystrokeCandidateSymbol; - CSampleImeArray<_KEYSTROKE> _KeystrokeSymbol; + CMetasequoiaImeArray<_KEYSTROKE> _KeystrokeComposition; + CMetasequoiaImeArray<_KEYSTROKE> _KeystrokeCandidate; + CMetasequoiaImeArray<_KEYSTROKE> _KeystrokeCandidateWildcard; + CMetasequoiaImeArray<_KEYSTROKE> _KeystrokeCandidateSymbol; + CMetasequoiaImeArray<_KEYSTROKE> _KeystrokeSymbol; // Preserved key data class XPreservedKey @@ -202,7 +202,7 @@ class CCompositionProcessorEngine BOOL UninitPreservedKey(_In_ ITfThreadMgr *pThreadMgr); public: - CSampleImeArray TSFPreservedKeyTable; + CMetasequoiaImeArray TSFPreservedKeyTable; GUID Guid; LPCWSTR Description; }; @@ -212,8 +212,8 @@ class CCompositionProcessorEngine XPreservedKey _PreservedKey_Punctuation; // Punctuation data - CSampleImeArray _PunctuationPair; - CSampleImeArray _PunctuationNestPair; + CMetasequoiaImeArray _PunctuationPair; + CMetasequoiaImeArray _PunctuationNestPair; // Language bar data CLangBarItemButton *_pLanguageBar_IMEMode; diff --git a/src/Composition/EndComposition.cpp b/src/Composition/EndComposition.cpp index 83b9cd40..0267853a 100644 --- a/src/Composition/EndComposition.cpp +++ b/src/Composition/EndComposition.cpp @@ -8,7 +8,7 @@ #include "Private.h" #include "Globals.h" #include "EditSession.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" ////////////////////////////////////////////////////////////////////// // @@ -27,7 +27,7 @@ class CEndCompositionEditSession : public CEditSessionBase { public: - CEndCompositionEditSession(_In_ CSampleIME *pTextService, _In_ ITfContext *pContext) + CEndCompositionEditSession(_In_ CMetasequoiaIME *pTextService, _In_ ITfContext *pContext) : CEditSessionBase(pTextService, pContext) { } @@ -42,7 +42,7 @@ class CEndCompositionEditSession : public CEditSessionBase ////////////////////////////////////////////////////////////////////// // -// CSampleIME class +// CMetasequoiaIME class // ////////////////////////////////////////////////////////////////////// @@ -52,7 +52,7 @@ class CEndCompositionEditSession : public CEditSessionBase // //---------------------------------------------------------------------------- -void CSampleIME::_TerminateComposition(TfEditCookie ec, _In_ ITfContext *pContext, BOOL isCalledFromDeactivate) +void CMetasequoiaIME::_TerminateComposition(TfEditCookie ec, _In_ ITfContext *pContext, BOOL isCalledFromDeactivate) { isCalledFromDeactivate; @@ -84,7 +84,7 @@ void CSampleIME::_TerminateComposition(TfEditCookie ec, _In_ ITfContext *pContex // //---------------------------------------------------------------------------- -void CSampleIME::_EndComposition(_In_opt_ ITfContext *pContext) +void CMetasequoiaIME::_EndComposition(_In_opt_ ITfContext *pContext) { CEndCompositionEditSession *pEditSession = new (std::nothrow) CEndCompositionEditSession(this, pContext); HRESULT hr = S_OK; diff --git a/src/Composition/StartComposition.cpp b/src/Composition/StartComposition.cpp index 32fb597e..639142d6 100644 --- a/src/Composition/StartComposition.cpp +++ b/src/Composition/StartComposition.cpp @@ -8,7 +8,7 @@ #include "Private.h" #include "Globals.h" #include "EditSession.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" //+--------------------------------------------------------------------------- // @@ -19,7 +19,7 @@ class CStartCompositionEditSession : public CEditSessionBase { public: - CStartCompositionEditSession(_In_ CSampleIME *pTextService, _In_ ITfContext *pContext) + CStartCompositionEditSession(_In_ CMetasequoiaIME *pTextService, _In_ ITfContext *pContext) : CEditSessionBase(pTextService, pContext) { } @@ -92,7 +92,7 @@ Exit: ////////////////////////////////////////////////////////////////////// // -// CSampleIME class +// CMetasequoiaIME class // ////////////////////////////////////////////////////////////////////// @@ -104,7 +104,7 @@ Exit: // focus context. //---------------------------------------------------------------------------- -void CSampleIME::_StartComposition(_In_ ITfContext *pContext) +void CMetasequoiaIME::_StartComposition(_In_ ITfContext *pContext) { CStartCompositionEditSession *pStartCompositionEditSession = new (std::nothrow) CStartCompositionEditSession(this, pContext); @@ -127,7 +127,7 @@ void CSampleIME::_StartComposition(_In_ ITfContext *pContext) // deactivation //---------------------------------------------------------------------------- -void CSampleIME::_SaveCompositionContext(_In_ ITfContext *pContext) +void CMetasequoiaIME::_SaveCompositionContext(_In_ ITfContext *pContext) { assert(_pContext == nullptr); diff --git a/src/DictEngine/BaseDictionaryEngine.cpp b/src/DictEngine/BaseDictionaryEngine.cpp index 83e265fb..bfdf93c3 100644 --- a/src/DictEngine/BaseDictionaryEngine.cpp +++ b/src/DictEngine/BaseDictionaryEngine.cpp @@ -31,7 +31,7 @@ CBaseDictionaryEngine::~CBaseDictionaryEngine() // SortListItemByFindKeyCode //---------------------------------------------------------------------------- -VOID CBaseDictionaryEngine::SortListItemByFindKeyCode(_Inout_ CSampleImeArray *pItemList) +VOID CBaseDictionaryEngine::SortListItemByFindKeyCode(_Inout_ CMetasequoiaImeArray *pItemList) { MergeSortByFindKeyCode(pItemList, 0, pItemList->Count() - 1); } @@ -43,7 +43,7 @@ VOID CBaseDictionaryEngine::SortListItemByFindKeyCode(_Inout_ CSampleImeArray *pItemList, +VOID CBaseDictionaryEngine::MergeSortByFindKeyCode(_Inout_ CMetasequoiaImeArray *pItemList, int leftRange, int rightRange) { int candidateCount = CalculateCandidateCount(leftRange, rightRange); @@ -55,7 +55,7 @@ VOID CBaseDictionaryEngine::MergeSortByFindKeyCode(_Inout_ CSampleImeArray ListItemTemp; + CMetasequoiaImeArray ListItemTemp; int leftRangeTemp = 0; int midTemp = 0; diff --git a/src/DictEngine/BaseDictionaryEngine.h b/src/DictEngine/BaseDictionaryEngine.h index 9c3b4652..5a028f98 100644 --- a/src/DictEngine/BaseDictionaryEngine.h +++ b/src/DictEngine/BaseDictionaryEngine.h @@ -8,7 +8,7 @@ #pragma once #include "File.h" -#include "SampleIMEBaseStructure.h" +#include "MetasequoiaIMEBaseStructure.h" class CBaseDictionaryEngine { @@ -16,25 +16,25 @@ class CBaseDictionaryEngine CBaseDictionaryEngine(LCID locale, _In_ CFile *pDictionaryFile); virtual ~CBaseDictionaryEngine(); - virtual VOID CollectWord(_In_ CStringRange *psrgKeyCode, _Out_ CSampleImeArray *pasrgWordString) + virtual VOID CollectWord(_In_ CStringRange *psrgKeyCode, _Out_ CMetasequoiaImeArray *pasrgWordString) { psrgKeyCode; pasrgWordString = nullptr; } - virtual VOID CollectWord(_In_ CStringRange *psrgKeyCode, _Out_ CSampleImeArray *pItemList) + virtual VOID CollectWord(_In_ CStringRange *psrgKeyCode, _Out_ CMetasequoiaImeArray *pItemList) { psrgKeyCode; pItemList = nullptr; } - virtual VOID SortListItemByFindKeyCode(_Inout_ CSampleImeArray *pItemList); + virtual VOID SortListItemByFindKeyCode(_Inout_ CMetasequoiaImeArray *pItemList); protected: CFile *_pDictionaryFile; LCID _locale; private: - VOID MergeSortByFindKeyCode(_Inout_ CSampleImeArray *pItemList, int leftRange, int rightRange); + VOID MergeSortByFindKeyCode(_Inout_ CMetasequoiaImeArray *pItemList, int leftRange, int rightRange); int CalculateCandidateCount(int leftRange, int rightRange); }; diff --git a/src/DictEngine/DictionaryParser.cpp b/src/DictEngine/DictionaryParser.cpp index 870bfe9b..63ac0b89 100644 --- a/src/DictEngine/DictionaryParser.cpp +++ b/src/DictEngine/DictionaryParser.cpp @@ -7,7 +7,7 @@ #include "Private.h" #include "DictionaryParser.h" -#include "SampleIMEBaseStructure.h" +#include "MetasequoiaIMEBaseStructure.h" //--------------------------------------------------------------------- // @@ -40,7 +40,7 @@ CDictionaryParser::~CDictionaryParser() BOOL CDictionaryParser::ParseLine(_In_reads_(dwBufLen) LPCWSTR pwszBuffer, DWORD_PTR dwBufLen, _Out_ CParserStringRange *psrgKeyword, - _Inout_opt_ CSampleImeArray *pValue) + _Inout_opt_ CMetasequoiaImeArray *pValue) { LPCWSTR pwszKeyWordDelimiter = nullptr; pwszKeyWordDelimiter = GetToken(pwszBuffer, dwBufLen, Global::KeywordDelimiter, psrgKeyword); diff --git a/src/DictEngine/DictionaryParser.h b/src/DictEngine/DictionaryParser.h index 771a30ef..2ece92e4 100644 --- a/src/DictEngine/DictionaryParser.h +++ b/src/DictEngine/DictionaryParser.h @@ -33,7 +33,7 @@ class CDictionaryParser virtual ~CDictionaryParser(); BOOL ParseLine(_In_reads_(dwBufLen) LPCWSTR pwszBuffer, DWORD_PTR dwBufLen, _Out_ CParserStringRange *psrgKeyword, - _Inout_opt_ CSampleImeArray *pValue = nullptr); + _Inout_opt_ CMetasequoiaImeArray *pValue = nullptr); // dwBufLen - in character count _Ret_maybenull_ LPCWSTR GetToken(_In_reads_(dwBufLen) LPCWSTR pwszBuffer, DWORD_PTR dwBufLen, diff --git a/src/DictEngine/DictionarySearch.cpp b/src/DictEngine/DictionarySearch.cpp index 739b41e3..55b85348 100644 --- a/src/DictEngine/DictionarySearch.cpp +++ b/src/DictEngine/DictionarySearch.cpp @@ -7,7 +7,7 @@ #include "Private.h" #include "DictionarySearch.h" -#include "SampleIMEBaseStructure.h" +#include "MetasequoiaIMEBaseStructure.h" //+--------------------------------------------------------------------------- // @@ -133,7 +133,7 @@ TryAgain: else { // Compare Dictionary converted string and input string - CSampleImeArray convertedStrings; + CMetasequoiaImeArray convertedStrings; if (!ParseLine(&pwch[indexTrace], bufLenOneLine, &keyword, &convertedStrings)) { if (bufLen) @@ -192,7 +192,7 @@ TryAgain: return FALSE; } - CSampleImeArray valueStrings; + CMetasequoiaImeArray valueStrings; if (!ParseLine(&pwch[indexTrace], bufLenOneLine, &keyword, &valueStrings)) { if (*ppdret) diff --git a/src/DictEngine/DictionarySearch.h b/src/DictEngine/DictionarySearch.h index b5e35b66..1bde7eab 100644 --- a/src/DictEngine/DictionarySearch.h +++ b/src/DictEngine/DictionarySearch.h @@ -9,7 +9,7 @@ #include "File.h" #include "DictionaryParser.h" -#include "SampleIMEBaseStructure.h" +#include "MetasequoiaIMEBaseStructure.h" class CDictionaryResult; @@ -75,5 +75,5 @@ class CDictionaryResult CStringRange _SearchKeyCode; CStringRange _FindKeyCode; - CSampleImeArray _FindPhraseList; + CMetasequoiaImeArray _FindPhraseList; }; diff --git a/src/DictEngine/TableDictionaryEngine.cpp b/src/DictEngine/TableDictionaryEngine.cpp index 1364abfc..775721bb 100644 --- a/src/DictEngine/TableDictionaryEngine.cpp +++ b/src/DictEngine/TableDictionaryEngine.cpp @@ -18,7 +18,7 @@ //---------------------------------------------------------------------------- VOID CTableDictionaryEngine::CollectWord(_In_ CStringRange *pKeyCode, - _Inout_ CSampleImeArray *pWordStrings) + _Inout_ CMetasequoiaImeArray *pWordStrings) { CDictionaryResult *pdret = nullptr; CDictionarySearch dshSearch(_locale, _pDictionaryFile, pKeyCode); @@ -41,7 +41,7 @@ VOID CTableDictionaryEngine::CollectWord(_In_ CStringRange *pKeyCode, } VOID CTableDictionaryEngine::CollectWord(_In_ CStringRange *pKeyCode, - _Inout_ CSampleImeArray *pItemList) + _Inout_ CMetasequoiaImeArray *pItemList) { std::wstring keyCodeWString = L""; keyCodeWString.append(pKeyCode->Get(), pKeyCode->GetLength()); // Append the key code to the string @@ -83,7 +83,7 @@ VOID CTableDictionaryEngine::CollectWord(_In_ CStringRange *pKeyCode, //---------------------------------------------------------------------------- VOID CTableDictionaryEngine::CollectWordForWildcard(_In_ CStringRange *pKeyCode, - _Inout_ CSampleImeArray *pItemList) + _Inout_ CMetasequoiaImeArray *pItemList) { CDictionaryResult *pdret = nullptr; CDictionarySearch dshSearch(_locale, _pDictionaryFile, pKeyCode); @@ -124,7 +124,7 @@ VOID CTableDictionaryEngine::CollectWordForWildcard(_In_ CStringRange *pKeyCode, //---------------------------------------------------------------------------- VOID CTableDictionaryEngine::CollectWordFromConvertedStringForWildcard( - _In_ CStringRange *pString, _Inout_ CSampleImeArray *pItemList) + _In_ CStringRange *pString, _Inout_ CMetasequoiaImeArray *pItemList) { CDictionaryResult *pdret = nullptr; CDictionarySearch dshSearch(_locale, _pDictionaryFile, pString); diff --git a/src/DictEngine/TableDictionaryEngine.h b/src/DictEngine/TableDictionaryEngine.h index 1743bf08..e7b51cee 100644 --- a/src/DictEngine/TableDictionaryEngine.h +++ b/src/DictEngine/TableDictionaryEngine.h @@ -26,11 +26,11 @@ class CTableDictionaryEngine : public CBaseDictionaryEngine // [out] pasrgWordString - Specified returns pointer of word as CStringRange. // returns // none. - VOID CollectWord(_In_ CStringRange *pKeyCode, _Inout_ CSampleImeArray *pWordStrings); - VOID CollectWord(_In_ CStringRange *pKeyCode, _Inout_ CSampleImeArray *pItemList); + VOID CollectWord(_In_ CStringRange *pKeyCode, _Inout_ CMetasequoiaImeArray *pWordStrings); + VOID CollectWord(_In_ CStringRange *pKeyCode, _Inout_ CMetasequoiaImeArray *pItemList); - VOID CollectWordForWildcard(_In_ CStringRange *psrgKeyCode, _Inout_ CSampleImeArray *pItemList); + VOID CollectWordForWildcard(_In_ CStringRange *psrgKeyCode, _Inout_ CMetasequoiaImeArray *pItemList); VOID CollectWordFromConvertedStringForWildcard(_In_ CStringRange *pString, - _Inout_ CSampleImeArray *pItemList); + _Inout_ CMetasequoiaImeArray *pItemList); }; diff --git a/src/DisplayAttribute/DisplayAttribute.cpp b/src/DisplayAttribute/DisplayAttribute.cpp index 61fae778..643c7aac 100644 --- a/src/DisplayAttribute/DisplayAttribute.cpp +++ b/src/DisplayAttribute/DisplayAttribute.cpp @@ -7,7 +7,7 @@ #include "Private.h" #include "Globals.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" //+--------------------------------------------------------------------------- // @@ -15,7 +15,7 @@ // //---------------------------------------------------------------------------- -void CSampleIME::_ClearCompositionDisplayAttributes(TfEditCookie ec, _In_ ITfContext *pContext) +void CMetasequoiaIME::_ClearCompositionDisplayAttributes(TfEditCookie ec, _In_ ITfContext *pContext) { ITfRange *pRangeComposition = nullptr; ITfProperty *pDisplayAttributeProperty = nullptr; @@ -44,7 +44,7 @@ void CSampleIME::_ClearCompositionDisplayAttributes(TfEditCookie ec, _In_ ITfCon // //---------------------------------------------------------------------------- -BOOL CSampleIME::_SetCompositionDisplayAttributes(TfEditCookie ec, _In_ ITfContext *pContext, +BOOL CMetasequoiaIME::_SetCompositionDisplayAttributes(TfEditCookie ec, _In_ ITfContext *pContext, TfGuidAtom gaDisplayAttribute) { ITfRange *pRangeComposition = nullptr; @@ -86,7 +86,7 @@ BOOL CSampleIME::_SetCompositionDisplayAttributes(TfEditCookie ec, _In_ ITfConte // TfGuidAtom, we do it once when Activate is called. //---------------------------------------------------------------------------- -BOOL CSampleIME::_InitDisplayAttributeGuidAtom() +BOOL CMetasequoiaIME::_InitDisplayAttributeGuidAtom() { ITfCategoryMgr *pCategoryMgr = nullptr; HRESULT hr = CoCreateInstance(CLSID_TF_CategoryMgr, nullptr, CLSCTX_INPROC_SERVER, IID_ITfCategoryMgr, @@ -98,13 +98,13 @@ BOOL CSampleIME::_InitDisplayAttributeGuidAtom() } // register the display attribute for input text. - hr = pCategoryMgr->RegisterGUID(Global::SampleIMEGuidDisplayAttributeInput, &_gaDisplayAttributeInput); + hr = pCategoryMgr->RegisterGUID(Global::MetasequoiaIMEGuidDisplayAttributeInput, &_gaDisplayAttributeInput); if (FAILED(hr)) { goto Exit; } // register the display attribute for the converted text. - hr = pCategoryMgr->RegisterGUID(Global::SampleIMEGuidDisplayAttributeConverted, &_gaDisplayAttributeConverted); + hr = pCategoryMgr->RegisterGUID(Global::MetasequoiaIMEGuidDisplayAttributeConverted, &_gaDisplayAttributeConverted); if (FAILED(hr)) { goto Exit; diff --git a/src/DisplayAttribute/DisplayAttributeInfo.cpp b/src/DisplayAttribute/DisplayAttributeInfo.cpp index 0a59ded7..ba75c855 100644 --- a/src/DisplayAttribute/DisplayAttributeInfo.cpp +++ b/src/DisplayAttribute/DisplayAttributeInfo.cpp @@ -21,8 +21,8 @@ const WCHAR CDisplayAttributeInfoInput::_s_szValueName[] = L"DisplayAttributeInp const WCHAR CDisplayAttributeInfoConverted::_s_szValueName[] = L"DisplayAttributeConverted"; // The descriptions -const WCHAR CDisplayAttributeInfoInput::_s_szDescription[] = L"Sample IME Text Service Display Attribute Input"; -const WCHAR CDisplayAttributeInfoConverted::_s_szDescription[] = L"Sample IME Text Service Display Attribute Converted"; +const WCHAR CDisplayAttributeInfoInput::_s_szDescription[] = L"Metasequoia IME Text Service Display Attribute Input"; +const WCHAR CDisplayAttributeInfoConverted::_s_szDescription[] = L"Metasequoia IME Text Service Display Attribute Converted"; //+--------------------------------------------------------------------------- // diff --git a/src/DisplayAttribute/DisplayAttributeInfo.h b/src/DisplayAttribute/DisplayAttributeInfo.h index b4443e5f..c2dcdb67 100644 --- a/src/DisplayAttribute/DisplayAttributeInfo.h +++ b/src/DisplayAttribute/DisplayAttributeInfo.h @@ -55,7 +55,7 @@ class CDisplayAttributeInfoInput : public CDisplayAttributeInfo public: CDisplayAttributeInfoInput() { - _pguid = &Global::SampleIMEGuidDisplayAttributeInput; + _pguid = &Global::MetasequoiaIMEGuidDisplayAttributeInput; _pDisplayAttribute = &_s_DisplayAttribute; _pDescription = _s_szDescription; _pValueName = _s_szValueName; @@ -77,7 +77,7 @@ class CDisplayAttributeInfoConverted : public CDisplayAttributeInfo public: CDisplayAttributeInfoConverted() { - _pguid = &Global::SampleIMEGuidDisplayAttributeConverted; + _pguid = &Global::MetasequoiaIMEGuidDisplayAttributeConverted; _pDisplayAttribute = &_s_DisplayAttribute; _pDescription = _s_szDescription; _pValueName = _s_szValueName; diff --git a/src/DisplayAttribute/DisplayAttributeProvider.cpp b/src/DisplayAttribute/DisplayAttributeProvider.cpp index 3681366d..78f5cbbd 100644 --- a/src/DisplayAttribute/DisplayAttributeProvider.cpp +++ b/src/DisplayAttribute/DisplayAttributeProvider.cpp @@ -7,7 +7,7 @@ #include "Private.h" #include "Globals.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" #include "DisplayAttributeInfo.h" #include "EnumDisplayAttributeInfo.h" @@ -17,7 +17,7 @@ // //---------------------------------------------------------------------------- -STDAPI CSampleIME::EnumDisplayAttributeInfo(__RPC__deref_out_opt IEnumTfDisplayAttributeInfo **ppEnum) +STDAPI CMetasequoiaIME::EnumDisplayAttributeInfo(__RPC__deref_out_opt IEnumTfDisplayAttributeInfo **ppEnum) { CEnumDisplayAttributeInfo *pAttributeEnum = nullptr; @@ -45,7 +45,7 @@ STDAPI CSampleIME::EnumDisplayAttributeInfo(__RPC__deref_out_opt IEnumTfDisplayA // //---------------------------------------------------------------------------- -STDAPI CSampleIME::GetDisplayAttributeInfo(__RPC__in REFGUID guidInfo, +STDAPI CMetasequoiaIME::GetDisplayAttributeInfo(__RPC__in REFGUID guidInfo, __RPC__deref_out_opt ITfDisplayAttributeInfo **ppInfo) { if (ppInfo == nullptr) @@ -56,7 +56,7 @@ STDAPI CSampleIME::GetDisplayAttributeInfo(__RPC__in REFGUID guidInfo, *ppInfo = nullptr; // Which display attribute GUID? - if (IsEqualGUID(guidInfo, Global::SampleIMEGuidDisplayAttributeInput)) + if (IsEqualGUID(guidInfo, Global::MetasequoiaIMEGuidDisplayAttributeInput)) { *ppInfo = new (std::nothrow) CDisplayAttributeInfoInput(); if ((*ppInfo) == nullptr) @@ -64,7 +64,7 @@ STDAPI CSampleIME::GetDisplayAttributeInfo(__RPC__in REFGUID guidInfo, return E_OUTOFMEMORY; } } - else if (IsEqualGUID(guidInfo, Global::SampleIMEGuidDisplayAttributeConverted)) + else if (IsEqualGUID(guidInfo, Global::MetasequoiaIMEGuidDisplayAttributeConverted)) { *ppInfo = new (std::nothrow) CDisplayAttributeInfoConverted(); if ((*ppInfo) == nullptr) diff --git a/src/DisplayAttribute/DisplayString.h b/src/DisplayAttribute/DisplayString.h index c9415417..7d661906 100644 --- a/src/DisplayAttribute/DisplayString.h +++ b/src/DisplayAttribute/DisplayString.h @@ -12,7 +12,7 @@ #include "Private.h" #include "Globals.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" #include "EnumDisplayAttributeInfo.h" // #include "StringRange.h" diff --git a/src/DisplayAttribute/EnumDisplayAttributeInfo.cpp b/src/DisplayAttribute/EnumDisplayAttributeInfo.cpp index 8f50cf22..7c7fb63d 100644 --- a/src/DisplayAttribute/EnumDisplayAttributeInfo.cpp +++ b/src/DisplayAttribute/EnumDisplayAttributeInfo.cpp @@ -7,7 +7,7 @@ #include "Private.h" #include "Globals.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" #include "DisplayAttributeInfo.h" #include "EnumDisplayAttributeInfo.h" diff --git a/src/Drawing/D2DSource.cpp b/src/Drawing/D2DSource.cpp index 8b9d1b21..c22bf970 100644 --- a/src/Drawing/D2DSource.cpp +++ b/src/Drawing/D2DSource.cpp @@ -17,9 +17,9 @@ void Direct2DSource::CreateGlobalD2DResources() if (!pTextFormat) { - pDWriteFactory->CreateTextFormat(SAMPLEIME_FONT_DEFAULT, nullptr, DWRITE_FONT_WEIGHT_NORMAL, + pDWriteFactory->CreateTextFormat(METASEQUOIAIME_FONT_DEFAULT, nullptr, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, 16.0f, - SAMPLEIME_LOCALE_DEFAULT, &pTextFormat); + METASEQUOIAIME_LOCALE_DEFAULT, &pTextFormat); } } diff --git a/src/Edit/EditSession.cpp b/src/Edit/EditSession.cpp index d4ed4fce..28e04229 100644 --- a/src/Edit/EditSession.cpp +++ b/src/Edit/EditSession.cpp @@ -7,7 +7,7 @@ #include "Private.h" #include "EditSession.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" //+--------------------------------------------------------------------------- // @@ -15,7 +15,7 @@ // //---------------------------------------------------------------------------- -CEditSessionBase::CEditSessionBase(_In_ CSampleIME *pTextService, _In_ ITfContext *pContext) +CEditSessionBase::CEditSessionBase(_In_ CMetasequoiaIME *pTextService, _In_ ITfContext *pContext) { _refCount = 1; _pContext = pContext; diff --git a/src/Edit/EditSession.h b/src/Edit/EditSession.h index 450467a9..a516a16b 100644 --- a/src/Edit/EditSession.h +++ b/src/Edit/EditSession.h @@ -9,12 +9,12 @@ #include "Private.h" -class CSampleIME; +class CMetasequoiaIME; class CEditSessionBase : public ITfEditSession { public: - CEditSessionBase(_In_ CSampleIME *pTextService, _In_ ITfContext *pContext); + CEditSessionBase(_In_ CMetasequoiaIME *pTextService, _In_ ITfContext *pContext); virtual ~CEditSessionBase(); // IUnknown @@ -27,7 +27,7 @@ class CEditSessionBase : public ITfEditSession protected: ITfContext *_pContext; - CSampleIME *_pTextService; + CMetasequoiaIME *_pTextService; private: LONG _refCount; // COM ref count diff --git a/src/Edit/GetTextExtentEditSession.cpp b/src/Edit/GetTextExtentEditSession.cpp index adc0d1cc..411b2799 100644 --- a/src/Edit/GetTextExtentEditSession.cpp +++ b/src/Edit/GetTextExtentEditSession.cpp @@ -18,7 +18,7 @@ // //---------------------------------------------------------------------------- -CGetTextExtentEditSession::CGetTextExtentEditSession(_In_ CSampleIME *pTextService, _In_ ITfContext *pContext, +CGetTextExtentEditSession::CGetTextExtentEditSession(_In_ CMetasequoiaIME *pTextService, _In_ ITfContext *pContext, _In_ ITfContextView *pContextView, _In_ ITfRange *pRangeComposition, _In_ CTfTextLayoutSink *pTfTextLayoutSink) diff --git a/src/Edit/GetTextExtentEditSession.h b/src/Edit/GetTextExtentEditSession.h index d86644a5..4b9dc4b8 100644 --- a/src/Edit/GetTextExtentEditSession.h +++ b/src/Edit/GetTextExtentEditSession.h @@ -9,7 +9,7 @@ #include "EditSession.h" -class CSampleIME; +class CMetasequoiaIME; class CTfTextLayoutSink; ////////////////////////////////////////////////////////////////////// @@ -29,7 +29,7 @@ class CTfTextLayoutSink; class CGetTextExtentEditSession : public CEditSessionBase { public: - CGetTextExtentEditSession(_In_ CSampleIME *pTextService, _In_ ITfContext *pContext, + CGetTextExtentEditSession(_In_ CMetasequoiaIME *pTextService, _In_ ITfContext *pContext, _In_ ITfContextView *pContextView, _In_ ITfRange *pRangeComposition, _In_ CTfTextLayoutSink *pTextLayoutSink); diff --git a/src/Edit/TextEditSink.cpp b/src/Edit/TextEditSink.cpp index e133b58d..1794808e 100644 --- a/src/Edit/TextEditSink.cpp +++ b/src/Edit/TextEditSink.cpp @@ -7,7 +7,7 @@ #include "Private.h" #include "Globals.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" //+--------------------------------------------------------------------------- // @@ -16,7 +16,7 @@ // Called by the system whenever anyone releases a write-access document lock. //---------------------------------------------------------------------------- -STDAPI CSampleIME::OnEndEdit(__RPC__in_opt ITfContext *pContext, TfEditCookie ecReadOnly, +STDAPI CMetasequoiaIME::OnEndEdit(__RPC__in_opt ITfContext *pContext, TfEditCookie ecReadOnly, __RPC__in_opt ITfEditRecord *pEditRecord) { BOOL isSelectionChanged; @@ -77,7 +77,7 @@ STDAPI CSampleIME::OnEndEdit(__RPC__in_opt ITfContext *pContext, TfEditCookie ec // Always release any previous sink. //---------------------------------------------------------------------------- -BOOL CSampleIME::_InitTextEditSink(_In_ ITfDocumentMgr *pDocMgr) +BOOL CMetasequoiaIME::_InitTextEditSink(_In_ ITfDocumentMgr *pDocMgr) { ITfSource *pSource = nullptr; BOOL ret = TRUE; diff --git a/src/File/File.cpp b/src/File/File.cpp index 59f1d137..095b4183 100644 --- a/src/File/File.cpp +++ b/src/File/File.cpp @@ -15,7 +15,7 @@ #include "Private.h" #include "File.h" -#include "SampleIMEBaseStructure.h" +#include "MetasequoiaIMEBaseStructure.h" //--------------------------------------------------------------------- // diff --git a/src/Global/Globals.cpp b/src/Global/Globals.cpp index 479eb932..48c65c57 100644 --- a/src/Global/Globals.cpp +++ b/src/Global/Globals.cpp @@ -3,7 +3,7 @@ #include "resource.h" #include "BaseWindow.h" #include "define.h" -#include "SampleIMEBaseStructure.h" +#include "MetasequoiaIMEBaseStructure.h" #include #include #include @@ -20,41 +20,41 @@ CRITICAL_SECTION CS; HFONT defaultlFontHandle; // Global font object we use everywhere //--------------------------------------------------------------------- -// SampleIME CLSID +// MetasequoiaIME CLSID //--------------------------------------------------------------------- // {D2291A80-84D8-4641-9AB2-BDD1472C846B} -extern const CLSID SampleIMECLSID = {0xd2291a80, 0x84d8, 0x4641, {0x9a, 0xb2, 0xbd, 0xd1, 0x47, 0x2c, 0x84, 0x6b}}; +extern const CLSID MetasequoiaIMECLSID = {0xd2291a80, 0x84d8, 0x4641, {0x9a, 0xb2, 0xbd, 0xd1, 0x47, 0x2c, 0x84, 0x6b}}; //--------------------------------------------------------------------- // Profile GUID //--------------------------------------------------------------------- // {83955C0E-2C09-47a5-BCF3-F2B98E11EE8B} -extern const GUID SampleIMEGuidProfile = {0x83955c0e, 0x2c09, 0x47a5, {0xbc, 0xf3, 0xf2, 0xb9, 0x8e, 0x11, 0xee, 0x8b}}; +extern const GUID MetasequoiaIMEGuidProfile = {0x83955c0e, 0x2c09, 0x47a5, {0xbc, 0xf3, 0xf2, 0xb9, 0x8e, 0x11, 0xee, 0x8b}}; //--------------------------------------------------------------------- // PreserveKey GUID //--------------------------------------------------------------------- // {4B62B54B-F828-43B5-9095-A96DF9CBDF38} -extern const GUID SampleIMEGuidImeModePreserveKey = { +extern const GUID MetasequoiaIMEGuidImeModePreserveKey = { 0x4b62b54b, 0xf828, 0x43b5, {0x90, 0x95, 0xa9, 0x6d, 0xf9, 0xcb, 0xdf, 0x38}}; // {5A08D6C4-4563-4E46-8DDB-65E75C4E73A3} -extern const GUID SampleIMEGuidDoubleSingleBytePreserveKey = { +extern const GUID MetasequoiaIMEGuidDoubleSingleBytePreserveKey = { 0x5a08d6c4, 0x4563, 0x4e46, {0x8d, 0xdb, 0x65, 0xe7, 0x5c, 0x4e, 0x73, 0xa3}}; // {175F062E-B961-4AED-A3DF-59F78A02862D} -extern const GUID SampleIMEGuidPunctuationPreserveKey = { +extern const GUID MetasequoiaIMEGuidPunctuationPreserveKey = { 0x175f062e, 0xb961, 0x4aed, {0xa3, 0xdf, 0x59, 0xf7, 0x8a, 0x2, 0x86, 0x2d}}; //--------------------------------------------------------------------- // Compartments //--------------------------------------------------------------------- // {101011C5-CF72-4F0C-A515-153019593F10} -extern const GUID SampleIMEGuidCompartmentDoubleSingleByte = { +extern const GUID MetasequoiaIMEGuidCompartmentDoubleSingleByte = { 0x101011c5, 0xcf72, 0x4f0c, {0xa5, 0x15, 0x15, 0x30, 0x19, 0x59, 0x3f, 0x10}}; // {DD321BCC-A7F8-4561-9B61-9B3508C9BA97} -extern const GUID SampleIMEGuidCompartmentPunctuation = { +extern const GUID MetasequoiaIMEGuidCompartmentPunctuation = { 0xdd321bcc, 0xa7f8, 0x4561, {0x9b, 0x61, 0x9b, 0x35, 0x8, 0xc9, 0xba, 0x97}}; //--------------------------------------------------------------------- @@ -62,23 +62,23 @@ extern const GUID SampleIMEGuidCompartmentPunctuation = { //--------------------------------------------------------------------- // {89BE500C-9462-4070-9DB0-B467BB051327} -extern const GUID SampleIMEGuidLangBarIMEMode = { +extern const GUID MetasequoiaIMEGuidLangBarIMEMode = { 0x89be500c, 0x9462, 0x4070, {0x9d, 0xb0, 0xb4, 0x67, 0xbb, 0x5, 0x13, 0x27}}; // {6A11D9DE-46DB-455B-A257-2EB615746BF4} -extern const GUID SampleIMEGuidLangBarDoubleSingleByte = { +extern const GUID MetasequoiaIMEGuidLangBarDoubleSingleByte = { 0x6a11d9de, 0x46db, 0x455b, {0xa2, 0x57, 0x2e, 0xb6, 0x15, 0x74, 0x6b, 0xf4}}; // {F29C731A-A51E-49FB-8A3C-EE51752912E2} -extern const GUID SampleIMEGuidLangBarPunctuation = { +extern const GUID MetasequoiaIMEGuidLangBarPunctuation = { 0xf29c731a, 0xa51e, 0x49fb, {0x8a, 0x3c, 0xee, 0x51, 0x75, 0x29, 0x12, 0xe2}}; // {4C802E2C-8140-4436-A5E5-F7C544EBC9CD} -extern const GUID SampleIMEGuidDisplayAttributeInput = { +extern const GUID MetasequoiaIMEGuidDisplayAttributeInput = { 0x4c802e2c, 0x8140, 0x4436, {0xa5, 0xe5, 0xf7, 0xc5, 0x44, 0xeb, 0xc9, 0xcd}}; // {9A1CC683-F2A7-4701-9C6E-2DA69A5CD474} -extern const GUID SampleIMEGuidDisplayAttributeConverted = { +extern const GUID MetasequoiaIMEGuidDisplayAttributeConverted = { 0x9a1cc683, 0xf2a7, 0x4701, {0x9c, 0x6e, 0x2d, 0xa6, 0x9a, 0x5c, 0xd4, 0x74}}; //--------------------------------------------------------------------- @@ -86,7 +86,7 @@ extern const GUID SampleIMEGuidDisplayAttributeConverted = { //--------------------------------------------------------------------- // {84B0749F-8DE7-4732-907A-3BCB150A01A8} -extern const GUID SampleIMEGuidCandUIElement = { +extern const GUID MetasequoiaIMEGuidCandUIElement = { 0x84b0749f, 0x8de7, 0x4732, {0x90, 0x7a, 0x3b, 0xcb, 0x15, 0xa, 0x1, 0xa8}}; //--------------------------------------------------------------------- @@ -125,13 +125,13 @@ extern const WCHAR LangbarPunctuationDescription[] = L"Punctuation"; //--------------------------------------------------------------------- // windows class / titile / atom //--------------------------------------------------------------------- -extern const WCHAR CandidateClassName[] = L"SampleIME.CandidateWindow"; +extern const WCHAR CandidateClassName[] = L"MetasequoiaIME.CandidateWindow"; ATOM AtomCandidateWindow; -extern const WCHAR ShadowClassName[] = L"SampleIME.ShadowWindow"; +extern const WCHAR ShadowClassName[] = L"MetasequoiaIME.ShadowWindow"; ATOM AtomShadowWindow; -extern const WCHAR ScrollBarClassName[] = L"SampleIME.ScrollBarWindow"; +extern const WCHAR ScrollBarClassName[] = L"MetasequoiaIME.ScrollBarWindow"; ATOM AtomScrollBarWindow; BOOL RegisterWindowClass() diff --git a/src/Global/Globals.h b/src/Global/Globals.h index 35c51bb9..427216eb 100644 --- a/src/Global/Globals.h +++ b/src/Global/Globals.h @@ -6,7 +6,7 @@ #include "Private.h" #include "define.h" -#include "SampleIMEBaseStructure.h" +#include "MetasequoiaIMEBaseStructure.h" #include #include #include @@ -112,11 +112,11 @@ extern LONG dllRefCount; extern CRITICAL_SECTION CS; extern HFONT defaultlFontHandle; // Global font object we use everywhere -extern const CLSID SampleIMECLSID; -extern const CLSID SampleIMEGuidProfile; -extern const CLSID SampleIMEGuidImeModePreserveKey; -extern const CLSID SampleIMEGuidDoubleSingleBytePreserveKey; -extern const CLSID SampleIMEGuidPunctuationPreserveKey; +extern const CLSID MetasequoiaIMECLSID; +extern const CLSID MetasequoiaIMEGuidProfile; +extern const CLSID MetasequoiaIMEGuidImeModePreserveKey; +extern const CLSID MetasequoiaIMEGuidDoubleSingleBytePreserveKey; +extern const CLSID MetasequoiaIMEGuidPunctuationPreserveKey; LRESULT CALLBACK ThreadKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam); BOOL CheckModifiers(UINT uModCurrent, UINT uMod); @@ -129,20 +129,20 @@ extern BOOL IsAltKeyDownOnly; extern BOOL PureShiftKeyDown; extern BOOL PureShiftKeyUp; -extern const GUID SampleIMEGuidCompartmentDoubleSingleByte; -extern const GUID SampleIMEGuidCompartmentPunctuation; +extern const GUID MetasequoiaIMEGuidCompartmentDoubleSingleByte; +extern const GUID MetasequoiaIMEGuidCompartmentPunctuation; extern const WCHAR FullWidthCharTable[]; extern const struct _PUNCTUATION PunctuationTable[19]; -extern const GUID SampleIMEGuidLangBarIMEMode; -extern const GUID SampleIMEGuidLangBarDoubleSingleByte; -extern const GUID SampleIMEGuidLangBarPunctuation; +extern const GUID MetasequoiaIMEGuidLangBarIMEMode; +extern const GUID MetasequoiaIMEGuidLangBarDoubleSingleByte; +extern const GUID MetasequoiaIMEGuidLangBarPunctuation; -extern const GUID SampleIMEGuidDisplayAttributeInput; -extern const GUID SampleIMEGuidDisplayAttributeConverted; +extern const GUID MetasequoiaIMEGuidDisplayAttributeInput; +extern const GUID MetasequoiaIMEGuidDisplayAttributeConverted; -extern const GUID SampleIMEGuidCandUIElement; +extern const GUID MetasequoiaIMEGuidCandUIElement; extern const WCHAR UnicodeByteOrderMark; extern const WCHAR KeywordDelimiter; diff --git a/src/Header/Define.h b/src/Header/Define.h index 40c356d0..ac4b0b94 100644 --- a/src/Header/Define.h +++ b/src/Header/Define.h @@ -12,8 +12,8 @@ #define TEXTSERVICE_MODEL L"Apartment" #define TEXTSERVICE_LANGID MAKELANGID(LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED) -#define TEXTSERVICE_ICON_INDEX -IDIS_SAMPLEIME -#define TEXTSERVICE_DIC L"SampleIMESimplifiedQuanPin.txt" +#define TEXTSERVICE_ICON_INDEX -IDIS_METASEQUOIAIME +#define TEXTSERVICE_DIC L"MetasequoiaIMESimplifiedQuanPin.txt" #define TEXTSERVICE_DIC_DB L"cutted_flyciku_with_jp.db" #define FANYLOGFILE_ "fanydebug.log" #define FANYLOGFILE L"fanydebug_w.log" @@ -25,8 +25,8 @@ #define IME_PUNCTUATION_ON_INDEX IDI_PUNCTUATION_ON #define IME_PUNCTUATION_OFF_INDEX IDI_PUNCTUATION_OFF -#define SAMPLEIME_FONT_DEFAULT L"Microsoft YaHei UI" -#define SAMPLEIME_LOCALE_DEFAULT L"zh-CN" +#define METASEQUOIAIME_FONT_DEFAULT L"Microsoft YaHei UI" +#define METASEQUOIAIME_LOCALE_DEFAULT L"zh-CN" //--------------------------------------------------------------------- // defined Candidated Window diff --git a/src/Header/resource.h b/src/Header/resource.h index bd7f7ff1..aa9fbd89 100644 --- a/src/Header/resource.h +++ b/src/Header/resource.h @@ -1,10 +1,10 @@ //{{NO_DEPENDENCIES}} // Microsoft Visual C++ generated include file. -// Used by SampleIME.rc +// Used by MetasequoiaIME.rc // #define SUBLANG_ENGLISH_US 0x01 #define LANG_ENGLISH 0x09 -#define IDIS_SAMPLEIME 12 +#define IDIS_METASEQUOIAIME 12 #define IDS_DEFAULT_FONT 13 #define IDS_IME_MODE 20 #define IDI_IME_MODE_ON 21 diff --git a/src/IME/ActiveLanguageProfileNotifySink.cpp b/src/IME/ActiveLanguageProfileNotifySink.cpp index 97174bcf..bad5c0fa 100644 --- a/src/IME/ActiveLanguageProfileNotifySink.cpp +++ b/src/IME/ActiveLanguageProfileNotifySink.cpp @@ -7,12 +7,12 @@ #include "Private.h" #include "Globals.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" #include "CompositionProcessorEngine.h" -BOOL CSampleIME::VerifySampleIMECLSID(_In_ REFCLSID clsid) +BOOL CMetasequoiaIME::VerifyMetasequoiaIMECLSID(_In_ REFCLSID clsid) { - if (IsEqualCLSID(clsid, Global::SampleIMECLSID)) + if (IsEqualCLSID(clsid, Global::MetasequoiaIMECLSID)) { return TRUE; } @@ -26,11 +26,11 @@ BOOL CSampleIME::VerifySampleIMECLSID(_In_ REFCLSID clsid) // Sink called by the framework when changes activate language profile. //---------------------------------------------------------------------------- -STDAPI CSampleIME::OnActivated(_In_ REFCLSID clsid, _In_ REFGUID guidProfile, _In_ BOOL isActivated) +STDAPI CMetasequoiaIME::OnActivated(_In_ REFCLSID clsid, _In_ REFGUID guidProfile, _In_ BOOL isActivated) { guidProfile; - if (FALSE == VerifySampleIMECLSID(clsid)) + if (FALSE == VerifyMetasequoiaIMECLSID(clsid)) { return S_OK; } @@ -68,7 +68,7 @@ STDAPI CSampleIME::OnActivated(_In_ REFCLSID clsid, _In_ REFGUID guidProfile, _I // Advise a active language profile notify sink. //---------------------------------------------------------------------------- -BOOL CSampleIME::_InitActiveLanguageProfileNotifySink() +BOOL CMetasequoiaIME::_InitActiveLanguageProfileNotifySink() { ITfSource *pSource = nullptr; BOOL ret = FALSE; @@ -99,7 +99,7 @@ Exit: // Unadvise a active language profile notify sink. Assumes we have advised one already. //---------------------------------------------------------------------------- -void CSampleIME::_UninitActiveLanguageProfileNotifySink() +void CMetasequoiaIME::_UninitActiveLanguageProfileNotifySink() { ITfSource *pSource = nullptr; diff --git a/src/IME/FunctionProviderSink.cpp b/src/IME/FunctionProviderSink.cpp index 9d03f3f9..eaf1635a 100644 --- a/src/IME/FunctionProviderSink.cpp +++ b/src/IME/FunctionProviderSink.cpp @@ -6,7 +6,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved #include "Private.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" #include "SearchCandidateProvider.h" //+--------------------------------------------------------------------------- @@ -15,7 +15,7 @@ // //---------------------------------------------------------------------------- -BOOL CSampleIME::_InitFunctionProviderSink() +BOOL CMetasequoiaIME::_InitFunctionProviderSink() { ITfSourceSingle *pSourceSingle = nullptr; BOOL ret = FALSE; @@ -45,7 +45,7 @@ BOOL CSampleIME::_InitFunctionProviderSink() // //---------------------------------------------------------------------------- -void CSampleIME::_UninitFunctionProviderSink() +void CMetasequoiaIME::_UninitFunctionProviderSink() { ITfSourceSingle *pSourceSingle = nullptr; if (SUCCEEDED(_pThreadMgr->QueryInterface(IID_ITfSourceSingle, (void **)&pSourceSingle))) diff --git a/src/IME/SampleIME.cpp b/src/IME/MetasequoiaIME.cpp similarity index 82% rename from src/IME/SampleIME.cpp rename to src/IME/MetasequoiaIME.cpp index f850e263..e57d88dd 100644 --- a/src/IME/SampleIME.cpp +++ b/src/IME/MetasequoiaIME.cpp @@ -1,465 +1,465 @@ -// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF -// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A -// PARTICULAR PURPOSE. -// -// Copyright (c) Microsoft Corporation. All rights reserved - -#include "Private.h" -#include "Globals.h" -#include "SampleIME.h" -#include "CandidateListUIPresenter.h" -#include "CompositionProcessorEngine.h" -#include "Compartment.h" -#include "define.h" -#include -#include -#include -#include -#include "FanyLog.h" -#include "Ipc.h" -#include "CommonUtils.h" -#include "Global/FanyDefines.h" -#include "Utils/FanyUtils.h" - -//+--------------------------------------------------------------------------- -// -// CreateInstance -// -//---------------------------------------------------------------------------- - -/* static */ -HRESULT CSampleIME::CreateInstance(_In_ IUnknown *pUnkOuter, REFIID riid, _Outptr_ void **ppvObj) -{ - CSampleIME *pSampleIME = nullptr; - HRESULT hr = S_OK; - - if (ppvObj == nullptr) - { - return E_INVALIDARG; - } - - *ppvObj = nullptr; - - if (nullptr != pUnkOuter) - { - return CLASS_E_NOAGGREGATION; - } - - pSampleIME = new (std::nothrow) CSampleIME(); - if (pSampleIME == nullptr) - { - return E_OUTOFMEMORY; - } - - hr = pSampleIME->QueryInterface(riid, ppvObj); - - pSampleIME->Release(); - - return hr; -} - -//+--------------------------------------------------------------------------- -// -// ctor -// -//---------------------------------------------------------------------------- - -CSampleIME::CSampleIME() -{ - DllAddRef(); - - _pThreadMgr = nullptr; - - _threadMgrEventSinkCookie = TF_INVALID_COOKIE; - - _pTextEditSinkContext = nullptr; - _textEditSinkCookie = TF_INVALID_COOKIE; - - _activeLanguageProfileNotifySinkCookie = TF_INVALID_COOKIE; - - _dwThreadFocusSinkCookie = TF_INVALID_COOKIE; - - _pComposition = nullptr; - - _pCompositionProcessorEngine = nullptr; - - _candidateMode = CANDIDATE_NONE; - _pCandidateListUIPresenter = nullptr; - _isCandidateWithWildcard = FALSE; - - _pDocMgrLastFocused = nullptr; - - _pSIPIMEOnOffCompartment = nullptr; - _dwSIPIMEOnOffCompartmentSinkCookie = 0; - _msgWndHandle = nullptr; - - _pContext = nullptr; - - _refCount = 1; -} - -//+--------------------------------------------------------------------------- -// -// dtor -// -//---------------------------------------------------------------------------- - -CSampleIME::~CSampleIME() -{ - if (_pCandidateListUIPresenter) - { - delete _pCandidateListUIPresenter; - _pCandidateListUIPresenter = nullptr; - } - DllRelease(); -} - -//+--------------------------------------------------------------------------- -// -// QueryInterface -// -//---------------------------------------------------------------------------- - -STDAPI CSampleIME::QueryInterface(REFIID riid, _Outptr_ void **ppvObj) -{ - if (ppvObj == nullptr) - { - return E_INVALIDARG; - } - - *ppvObj = nullptr; - - if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_ITfTextInputProcessor)) - { - *ppvObj = (ITfTextInputProcessor *)this; - } - else if (IsEqualIID(riid, IID_ITfTextInputProcessorEx)) - { - *ppvObj = (ITfTextInputProcessorEx *)this; - } - else if (IsEqualIID(riid, IID_ITfThreadMgrEventSink)) - { - *ppvObj = (ITfThreadMgrEventSink *)this; - } - else if (IsEqualIID(riid, IID_ITfTextEditSink)) - { - *ppvObj = (ITfTextEditSink *)this; - } - else if (IsEqualIID(riid, IID_ITfKeyEventSink)) - { - *ppvObj = (ITfKeyEventSink *)this; - } - else if (IsEqualIID(riid, IID_ITfActiveLanguageProfileNotifySink)) - { - *ppvObj = (ITfActiveLanguageProfileNotifySink *)this; - } - else if (IsEqualIID(riid, IID_ITfCompositionSink)) - { - *ppvObj = (ITfCompositionSink *)this; - } - else if (IsEqualIID(riid, IID_ITfDisplayAttributeProvider)) - { - *ppvObj = (ITfDisplayAttributeProvider *)this; - } - else if (IsEqualIID(riid, IID_ITfThreadFocusSink)) - { - *ppvObj = (ITfThreadFocusSink *)this; - } - else if (IsEqualIID(riid, IID_ITfFunctionProvider)) - { - *ppvObj = (ITfFunctionProvider *)this; - } - else if (IsEqualIID(riid, IID_ITfFunction)) - { - *ppvObj = (ITfFunction *)this; - } - else if (IsEqualIID(riid, IID_ITfFnGetPreferredTouchKeyboardLayout)) - { - *ppvObj = (ITfFnGetPreferredTouchKeyboardLayout *)this; - } - - if (*ppvObj) - { - AddRef(); - return S_OK; - } - - return E_NOINTERFACE; -} - -//+--------------------------------------------------------------------------- -// -// AddRef -// -//---------------------------------------------------------------------------- - -STDAPI_(ULONG) CSampleIME::AddRef() -{ - return ++_refCount; -} - -//+--------------------------------------------------------------------------- -// -// Release -// -//---------------------------------------------------------------------------- - -STDAPI_(ULONG) CSampleIME::Release() -{ - LONG cr = --_refCount; - - assert(_refCount >= 0); - - if (_refCount == 0) - { - delete this; - } - - return cr; -} - -//+--------------------------------------------------------------------------- -// -// ITfTextInputProcessorEx::ActivateEx -// -//---------------------------------------------------------------------------- - -STDAPI CSampleIME::ActivateEx(ITfThreadMgr *pThreadMgr, TfClientId tfClientId, DWORD dwFlags) -{ - _pThreadMgr = pThreadMgr; - _pThreadMgr->AddRef(); - - _tfClientId = tfClientId; - _dwActivateFlags = dwFlags; - - OutputDebugString(L"CSampleIME::ActivateEx\n"); - std::wstring processName = FanyUtils::GetCurrentProcessName(); - if (Global::VSCodeSeries.find(processName) != Global::VSCodeSeries.end()) - { - Global::IsVSCodeLike = true; - } - // Set up IPC(named pipe) - InitIpc(); - - Global::current_process_name = GetCurrentProcessName(); - - if (!_InitThreadMgrEventSink()) - { - goto ExitError; - } - - ITfDocumentMgr *pDocMgrFocus = nullptr; - if (SUCCEEDED(_pThreadMgr->GetFocus(&pDocMgrFocus)) && (pDocMgrFocus != nullptr)) - { - _InitTextEditSink(pDocMgrFocus); - pDocMgrFocus->Release(); - } - - if (!_InitKeyEventSink()) - { - goto ExitError; - } - - if (!_InitActiveLanguageProfileNotifySink()) - { - goto ExitError; - } - - if (!_InitThreadFocusSink()) - { - goto ExitError; - } - - if (!_InitDisplayAttributeGuidAtom()) - { - goto ExitError; - } - - if (!_InitFunctionProviderSink()) - { - goto ExitError; - } - - if (!_AddTextProcessorEngine()) - { - goto ExitError; - } - - // Reset to Chinese mode whenever switch back to this IME - _pCompositionProcessorEngine->InitializeSampleIMECompartment(pThreadMgr, tfClientId); - - SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); - -#ifdef FANY_DEBUG - OutputDebugString(L"CSampleIME::ActivateEx\n"); -#endif - - return S_OK; - -ExitError: - Deactivate(); - return E_FAIL; -} - -//+--------------------------------------------------------------------------- -// -// ITfTextInputProcessorEx::Deactivate -// -//---------------------------------------------------------------------------- - -STDAPI CSampleIME::Deactivate() -{ - // Clean IPC - CloseIpc(); - - OutputDebugString(L"CSampleIME::Deactivate\n"); - - if (_pCompositionProcessorEngine) - { - delete _pCompositionProcessorEngine; - _pCompositionProcessorEngine = nullptr; - } - - ITfContext *pContext = _pContext; - if (_pContext) - { - pContext->AddRef(); - _EndComposition(_pContext); - } - - if (_pCandidateListUIPresenter) - { - delete _pCandidateListUIPresenter; - _pCandidateListUIPresenter = nullptr; - - if (pContext) - { - pContext->Release(); - } - - _candidateMode = CANDIDATE_NONE; - _isCandidateWithWildcard = FALSE; - } - - _UninitFunctionProviderSink(); - - _UninitThreadFocusSink(); - - _UninitActiveLanguageProfileNotifySink(); - - _UninitKeyEventSink(); - - _UninitThreadMgrEventSink(); - - CCompartment CompartmentKeyboardOpen(_pThreadMgr, _tfClientId, GUID_COMPARTMENT_KEYBOARD_OPENCLOSE); - CompartmentKeyboardOpen._ClearCompartment(); - - CCompartment CompartmentDoubleSingleByte(_pThreadMgr, _tfClientId, - Global::SampleIMEGuidCompartmentDoubleSingleByte); - CompartmentDoubleSingleByte._ClearCompartment(); - - CCompartment CompartmentPunctuation(_pThreadMgr, _tfClientId, Global::SampleIMEGuidCompartmentPunctuation); - CompartmentDoubleSingleByte._ClearCompartment(); - - if (_pThreadMgr != nullptr) - { - _pThreadMgr->Release(); - } - - _tfClientId = TF_CLIENTID_NULL; - - if (_pDocMgrLastFocused) - { - _pDocMgrLastFocused->Release(); - _pDocMgrLastFocused = nullptr; - } - - return S_OK; -} - -//+--------------------------------------------------------------------------- -// -// ITfFunctionProvider::GetType -// -//---------------------------------------------------------------------------- -HRESULT CSampleIME::GetType(__RPC__out GUID *pguid) -{ - HRESULT hr = E_INVALIDARG; - if (pguid) - { - *pguid = Global::SampleIMECLSID; - hr = S_OK; - } - return hr; -} - -//+--------------------------------------------------------------------------- -// -// ITfFunctionProvider::::GetDescription -// -//---------------------------------------------------------------------------- -HRESULT CSampleIME::GetDescription(__RPC__deref_out_opt BSTR *pbstrDesc) -{ - HRESULT hr = E_INVALIDARG; - if (pbstrDesc != nullptr) - { - *pbstrDesc = nullptr; - hr = E_NOTIMPL; - } - return hr; -} - -//+--------------------------------------------------------------------------- -// -// ITfFunctionProvider::::GetFunction -// -//---------------------------------------------------------------------------- -HRESULT CSampleIME::GetFunction(__RPC__in REFGUID rguid, __RPC__in REFIID riid, __RPC__deref_out_opt IUnknown **ppunk) -{ - HRESULT hr = E_NOINTERFACE; - - if ((IsEqualGUID(rguid, GUID_NULL)) && (IsEqualGUID(riid, __uuidof(ITfFnSearchCandidateProvider)))) - { - hr = _pITfFnSearchCandidateProvider->QueryInterface(riid, (void **)ppunk); - } - else if (IsEqualGUID(rguid, GUID_NULL)) - { - hr = QueryInterface(riid, (void **)ppunk); - } - - return hr; -} - -//+--------------------------------------------------------------------------- -// -// ITfFunction::GetDisplayName -// -//---------------------------------------------------------------------------- -HRESULT CSampleIME::GetDisplayName(_Out_ BSTR *pbstrDisplayName) -{ - HRESULT hr = E_INVALIDARG; - if (pbstrDisplayName != nullptr) - { - *pbstrDisplayName = nullptr; - hr = E_NOTIMPL; - } - return hr; -} - -//+--------------------------------------------------------------------------- -// -// ITfFnGetPreferredTouchKeyboardLayout::GetLayout -// The tkblayout will be Optimized layout. -//---------------------------------------------------------------------------- -HRESULT CSampleIME::GetLayout(_Out_ TKBLayoutType *ptkblayoutType, _Out_ WORD *pwPreferredLayoutId) -{ - HRESULT hr = E_INVALIDARG; - if ((ptkblayoutType != nullptr) && (pwPreferredLayoutId != nullptr)) - { - *ptkblayoutType = TKBLT_OPTIMIZED; - *pwPreferredLayoutId = TKBL_OPT_SIMPLIFIED_CHINESE_PINYIN; - hr = S_OK; - } - return hr; -} +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A +// PARTICULAR PURPOSE. +// +// Copyright (c) Microsoft Corporation. All rights reserved + +#include "Private.h" +#include "Globals.h" +#include "MetasequoiaIME.h" +#include "CandidateListUIPresenter.h" +#include "CompositionProcessorEngine.h" +#include "Compartment.h" +#include "define.h" +#include +#include +#include +#include +#include "FanyLog.h" +#include "Ipc.h" +#include "CommonUtils.h" +#include "Global/FanyDefines.h" +#include "Utils/FanyUtils.h" + +//+--------------------------------------------------------------------------- +// +// CreateInstance +// +//---------------------------------------------------------------------------- + +/* static */ +HRESULT CMetasequoiaIME::CreateInstance(_In_ IUnknown *pUnkOuter, REFIID riid, _Outptr_ void **ppvObj) +{ + CMetasequoiaIME *pMetasequoiaIME = nullptr; + HRESULT hr = S_OK; + + if (ppvObj == nullptr) + { + return E_INVALIDARG; + } + + *ppvObj = nullptr; + + if (nullptr != pUnkOuter) + { + return CLASS_E_NOAGGREGATION; + } + + pMetasequoiaIME = new (std::nothrow) CMetasequoiaIME(); + if (pMetasequoiaIME == nullptr) + { + return E_OUTOFMEMORY; + } + + hr = pMetasequoiaIME->QueryInterface(riid, ppvObj); + + pMetasequoiaIME->Release(); + + return hr; +} + +//+--------------------------------------------------------------------------- +// +// ctor +// +//---------------------------------------------------------------------------- + +CMetasequoiaIME::CMetasequoiaIME() +{ + DllAddRef(); + + _pThreadMgr = nullptr; + + _threadMgrEventSinkCookie = TF_INVALID_COOKIE; + + _pTextEditSinkContext = nullptr; + _textEditSinkCookie = TF_INVALID_COOKIE; + + _activeLanguageProfileNotifySinkCookie = TF_INVALID_COOKIE; + + _dwThreadFocusSinkCookie = TF_INVALID_COOKIE; + + _pComposition = nullptr; + + _pCompositionProcessorEngine = nullptr; + + _candidateMode = CANDIDATE_NONE; + _pCandidateListUIPresenter = nullptr; + _isCandidateWithWildcard = FALSE; + + _pDocMgrLastFocused = nullptr; + + _pSIPIMEOnOffCompartment = nullptr; + _dwSIPIMEOnOffCompartmentSinkCookie = 0; + _msgWndHandle = nullptr; + + _pContext = nullptr; + + _refCount = 1; +} + +//+--------------------------------------------------------------------------- +// +// dtor +// +//---------------------------------------------------------------------------- + +CMetasequoiaIME::~CMetasequoiaIME() +{ + if (_pCandidateListUIPresenter) + { + delete _pCandidateListUIPresenter; + _pCandidateListUIPresenter = nullptr; + } + DllRelease(); +} + +//+--------------------------------------------------------------------------- +// +// QueryInterface +// +//---------------------------------------------------------------------------- + +STDAPI CMetasequoiaIME::QueryInterface(REFIID riid, _Outptr_ void **ppvObj) +{ + if (ppvObj == nullptr) + { + return E_INVALIDARG; + } + + *ppvObj = nullptr; + + if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_ITfTextInputProcessor)) + { + *ppvObj = (ITfTextInputProcessor *)this; + } + else if (IsEqualIID(riid, IID_ITfTextInputProcessorEx)) + { + *ppvObj = (ITfTextInputProcessorEx *)this; + } + else if (IsEqualIID(riid, IID_ITfThreadMgrEventSink)) + { + *ppvObj = (ITfThreadMgrEventSink *)this; + } + else if (IsEqualIID(riid, IID_ITfTextEditSink)) + { + *ppvObj = (ITfTextEditSink *)this; + } + else if (IsEqualIID(riid, IID_ITfKeyEventSink)) + { + *ppvObj = (ITfKeyEventSink *)this; + } + else if (IsEqualIID(riid, IID_ITfActiveLanguageProfileNotifySink)) + { + *ppvObj = (ITfActiveLanguageProfileNotifySink *)this; + } + else if (IsEqualIID(riid, IID_ITfCompositionSink)) + { + *ppvObj = (ITfCompositionSink *)this; + } + else if (IsEqualIID(riid, IID_ITfDisplayAttributeProvider)) + { + *ppvObj = (ITfDisplayAttributeProvider *)this; + } + else if (IsEqualIID(riid, IID_ITfThreadFocusSink)) + { + *ppvObj = (ITfThreadFocusSink *)this; + } + else if (IsEqualIID(riid, IID_ITfFunctionProvider)) + { + *ppvObj = (ITfFunctionProvider *)this; + } + else if (IsEqualIID(riid, IID_ITfFunction)) + { + *ppvObj = (ITfFunction *)this; + } + else if (IsEqualIID(riid, IID_ITfFnGetPreferredTouchKeyboardLayout)) + { + *ppvObj = (ITfFnGetPreferredTouchKeyboardLayout *)this; + } + + if (*ppvObj) + { + AddRef(); + return S_OK; + } + + return E_NOINTERFACE; +} + +//+--------------------------------------------------------------------------- +// +// AddRef +// +//---------------------------------------------------------------------------- + +STDAPI_(ULONG) CMetasequoiaIME::AddRef() +{ + return ++_refCount; +} + +//+--------------------------------------------------------------------------- +// +// Release +// +//---------------------------------------------------------------------------- + +STDAPI_(ULONG) CMetasequoiaIME::Release() +{ + LONG cr = --_refCount; + + assert(_refCount >= 0); + + if (_refCount == 0) + { + delete this; + } + + return cr; +} + +//+--------------------------------------------------------------------------- +// +// ITfTextInputProcessorEx::ActivateEx +// +//---------------------------------------------------------------------------- + +STDAPI CMetasequoiaIME::ActivateEx(ITfThreadMgr *pThreadMgr, TfClientId tfClientId, DWORD dwFlags) +{ + _pThreadMgr = pThreadMgr; + _pThreadMgr->AddRef(); + + _tfClientId = tfClientId; + _dwActivateFlags = dwFlags; + + OutputDebugString(L"CMetasequoiaIME::ActivateEx\n"); + std::wstring processName = FanyUtils::GetCurrentProcessName(); + if (Global::VSCodeSeries.find(processName) != Global::VSCodeSeries.end()) + { + Global::IsVSCodeLike = true; + } + // Set up IPC(named pipe) + InitIpc(); + + Global::current_process_name = GetCurrentProcessName(); + + if (!_InitThreadMgrEventSink()) + { + goto ExitError; + } + + ITfDocumentMgr *pDocMgrFocus = nullptr; + if (SUCCEEDED(_pThreadMgr->GetFocus(&pDocMgrFocus)) && (pDocMgrFocus != nullptr)) + { + _InitTextEditSink(pDocMgrFocus); + pDocMgrFocus->Release(); + } + + if (!_InitKeyEventSink()) + { + goto ExitError; + } + + if (!_InitActiveLanguageProfileNotifySink()) + { + goto ExitError; + } + + if (!_InitThreadFocusSink()) + { + goto ExitError; + } + + if (!_InitDisplayAttributeGuidAtom()) + { + goto ExitError; + } + + if (!_InitFunctionProviderSink()) + { + goto ExitError; + } + + if (!_AddTextProcessorEngine()) + { + goto ExitError; + } + + // Reset to Chinese mode whenever switch back to this IME + _pCompositionProcessorEngine->InitializeMetasequoiaIMECompartment(pThreadMgr, tfClientId); + + SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2); + +#ifdef FANY_DEBUG + OutputDebugString(L"CMetasequoiaIME::ActivateEx\n"); +#endif + + return S_OK; + +ExitError: + Deactivate(); + return E_FAIL; +} + +//+--------------------------------------------------------------------------- +// +// ITfTextInputProcessorEx::Deactivate +// +//---------------------------------------------------------------------------- + +STDAPI CMetasequoiaIME::Deactivate() +{ + // Clean IPC + CloseIpc(); + + OutputDebugString(L"CMetasequoiaIME::Deactivate\n"); + + if (_pCompositionProcessorEngine) + { + delete _pCompositionProcessorEngine; + _pCompositionProcessorEngine = nullptr; + } + + ITfContext *pContext = _pContext; + if (_pContext) + { + pContext->AddRef(); + _EndComposition(_pContext); + } + + if (_pCandidateListUIPresenter) + { + delete _pCandidateListUIPresenter; + _pCandidateListUIPresenter = nullptr; + + if (pContext) + { + pContext->Release(); + } + + _candidateMode = CANDIDATE_NONE; + _isCandidateWithWildcard = FALSE; + } + + _UninitFunctionProviderSink(); + + _UninitThreadFocusSink(); + + _UninitActiveLanguageProfileNotifySink(); + + _UninitKeyEventSink(); + + _UninitThreadMgrEventSink(); + + CCompartment CompartmentKeyboardOpen(_pThreadMgr, _tfClientId, GUID_COMPARTMENT_KEYBOARD_OPENCLOSE); + CompartmentKeyboardOpen._ClearCompartment(); + + CCompartment CompartmentDoubleSingleByte(_pThreadMgr, _tfClientId, + Global::MetasequoiaIMEGuidCompartmentDoubleSingleByte); + CompartmentDoubleSingleByte._ClearCompartment(); + + CCompartment CompartmentPunctuation(_pThreadMgr, _tfClientId, Global::MetasequoiaIMEGuidCompartmentPunctuation); + CompartmentDoubleSingleByte._ClearCompartment(); + + if (_pThreadMgr != nullptr) + { + _pThreadMgr->Release(); + } + + _tfClientId = TF_CLIENTID_NULL; + + if (_pDocMgrLastFocused) + { + _pDocMgrLastFocused->Release(); + _pDocMgrLastFocused = nullptr; + } + + return S_OK; +} + +//+--------------------------------------------------------------------------- +// +// ITfFunctionProvider::GetType +// +//---------------------------------------------------------------------------- +HRESULT CMetasequoiaIME::GetType(__RPC__out GUID *pguid) +{ + HRESULT hr = E_INVALIDARG; + if (pguid) + { + *pguid = Global::MetasequoiaIMECLSID; + hr = S_OK; + } + return hr; +} + +//+--------------------------------------------------------------------------- +// +// ITfFunctionProvider::::GetDescription +// +//---------------------------------------------------------------------------- +HRESULT CMetasequoiaIME::GetDescription(__RPC__deref_out_opt BSTR *pbstrDesc) +{ + HRESULT hr = E_INVALIDARG; + if (pbstrDesc != nullptr) + { + *pbstrDesc = nullptr; + hr = E_NOTIMPL; + } + return hr; +} + +//+--------------------------------------------------------------------------- +// +// ITfFunctionProvider::::GetFunction +// +//---------------------------------------------------------------------------- +HRESULT CMetasequoiaIME::GetFunction(__RPC__in REFGUID rguid, __RPC__in REFIID riid, __RPC__deref_out_opt IUnknown **ppunk) +{ + HRESULT hr = E_NOINTERFACE; + + if ((IsEqualGUID(rguid, GUID_NULL)) && (IsEqualGUID(riid, __uuidof(ITfFnSearchCandidateProvider)))) + { + hr = _pITfFnSearchCandidateProvider->QueryInterface(riid, (void **)ppunk); + } + else if (IsEqualGUID(rguid, GUID_NULL)) + { + hr = QueryInterface(riid, (void **)ppunk); + } + + return hr; +} + +//+--------------------------------------------------------------------------- +// +// ITfFunction::GetDisplayName +// +//---------------------------------------------------------------------------- +HRESULT CMetasequoiaIME::GetDisplayName(_Out_ BSTR *pbstrDisplayName) +{ + HRESULT hr = E_INVALIDARG; + if (pbstrDisplayName != nullptr) + { + *pbstrDisplayName = nullptr; + hr = E_NOTIMPL; + } + return hr; +} + +//+--------------------------------------------------------------------------- +// +// ITfFnGetPreferredTouchKeyboardLayout::GetLayout +// The tkblayout will be Optimized layout. +//---------------------------------------------------------------------------- +HRESULT CMetasequoiaIME::GetLayout(_Out_ TKBLayoutType *ptkblayoutType, _Out_ WORD *pwPreferredLayoutId) +{ + HRESULT hr = E_INVALIDARG; + if ((ptkblayoutType != nullptr) && (pwPreferredLayoutId != nullptr)) + { + *ptkblayoutType = TKBLT_OPTIMIZED; + *pwPreferredLayoutId = TKBL_OPT_SIMPLIFIED_CHINESE_PINYIN; + hr = S_OK; + } + return hr; +} diff --git a/src/IME/SampleIME.def b/src/IME/MetasequoiaIME.def similarity index 100% rename from src/IME/SampleIME.def rename to src/IME/MetasequoiaIME.def diff --git a/src/IME/SampleIME.h b/src/IME/MetasequoiaIME.h similarity index 91% rename from src/IME/SampleIME.h rename to src/IME/MetasequoiaIME.h index 185eb143..b59226f3 100644 --- a/src/IME/SampleIME.h +++ b/src/IME/MetasequoiaIME.h @@ -1,16 +1,16 @@ #pragma once #include "KeyHandlerEditSession.h" -#include "SampleIMEBaseStructure.h" +#include "MetasequoiaIMEBaseStructure.h" class CLangBarItemButton; class CCandidateListUIPresenter; class CCompositionProcessorEngine; const DWORD WM_CheckGlobalCompartment = WM_USER; -LRESULT CALLBACK CSampleIME_WindowProc(HWND wndHandle, UINT uMsg, WPARAM wParam, LPARAM lParam); +LRESULT CALLBACK CMetasequoiaIME_WindowProc(HWND wndHandle, UINT uMsg, WPARAM wParam, LPARAM lParam); -class CSampleIME : public ITfTextInputProcessorEx, +class CMetasequoiaIME : public ITfTextInputProcessorEx, public ITfThreadMgrEventSink, public ITfTextEditSink, public ITfKeyEventSink, @@ -22,8 +22,8 @@ class CSampleIME : public ITfTextInputProcessorEx, public ITfFnGetPreferredTouchKeyboardLayout { public: - CSampleIME(); - ~CSampleIME(); + CMetasequoiaIME(); + ~CMetasequoiaIME(); // IUnknown STDMETHODIMP QueryInterface(REFIID riid, _Outptr_ void **ppvObj); @@ -147,11 +147,11 @@ class CSampleIME : public ITfTextInputProcessorEx, }; // comless helpers - static HRESULT CSampleIME::CreateInstance(REFCLSID rclsid, REFIID riid, _Outptr_result_maybenull_ LPVOID *ppv, + static HRESULT CMetasequoiaIME::CreateInstance(REFCLSID rclsid, REFIID riid, _Outptr_result_maybenull_ LPVOID *ppv, _Out_opt_ HINSTANCE *phInst, BOOL isComLessMode); - static HRESULT CSampleIME::ComLessCreateInstance(REFGUID rclsid, REFIID riid, _Outptr_result_maybenull_ void **ppv, + static HRESULT CMetasequoiaIME::ComLessCreateInstance(REFGUID rclsid, REFIID riid, _Outptr_result_maybenull_ void **ppv, _Out_opt_ HINSTANCE *phInst); - static HRESULT CSampleIME::GetComModuleName(REFGUID rclsid, _Out_writes_(cchPath) WCHAR *wchPath, DWORD cchPath); + static HRESULT CMetasequoiaIME::GetComModuleName(REFGUID rclsid, _Out_writes_(cchPath) WCHAR *wchPath, DWORD cchPath); private: // functions for the composition object. @@ -218,9 +218,9 @@ class CSampleIME : public ITfTextInputProcessorEx, BOOL _AddTextProcessorEngine(); - BOOL VerifySampleIMECLSID(_In_ REFCLSID clsid); + BOOL VerifyMetasequoiaIMECLSID(_In_ REFCLSID clsid); - friend LRESULT CALLBACK CSampleIME_WindowProc(HWND wndHandle, UINT uMsg, WPARAM wParam, LPARAM lParam); + friend LRESULT CALLBACK CMetasequoiaIME_WindowProc(HWND wndHandle, UINT uMsg, WPARAM wParam, LPARAM lParam); private: ITfThreadMgr *_pThreadMgr; diff --git a/src/IME/SampleIME.rc b/src/IME/MetasequoiaIME.rc similarity index 84% rename from src/IME/SampleIME.rc rename to src/IME/MetasequoiaIME.rc index 838b497a..3dd48c86 100644 --- a/src/IME/SampleIME.rc +++ b/src/IME/MetasequoiaIME.rc @@ -15,7 +15,7 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US // Icon with lowest ID value placed first to ensure application icon // remains consistent on all systems. -IDIS_SAMPLEIME ICON "..\\..\\image\\FeatherIME.ico" +IDIS_METASEQUOIAIME ICON "..\\..\\image\\FeatherIME.ico" IDI_IME_MODE_ON ICON "..\\..\\image\\ImeModeOn.ico" IDI_IME_MODE_OFF ICON "..\\..\\image\\ImeModeOff.ico" IDI_DOUBLE_SINGLE_BYTE_ON ICON "..\\..\\image\\DoubleSingleByteOn.ico" @@ -46,12 +46,12 @@ BEGIN BLOCK "040904b0" BEGIN VALUE "CompanyName", "MSFT" - VALUE "FileDescription", "The Sample code of Windows 8 IME" + VALUE "FileDescription", "The Metasequoia code of Windows 8 IME" VALUE "FileVersion", "1.0.0.1" - VALUE "InternalName", "SampleIM.dll" + VALUE "InternalName", "MetasequoiaIM.dll" VALUE "LegalCopyright", "Copyright (C)" - VALUE "OriginalFilename", "SampleIM.dll" - VALUE "ProductName", "SampleIME" + VALUE "OriginalFilename", "MetasequoiaIM.dll" + VALUE "ProductName", "MetasequoiaIME" VALUE "ProductVersion", "1.0.0.1" END END @@ -94,7 +94,7 @@ END STRINGTABLE BEGIN - IDIS_SAMPLEIME "Chinese Simplified QuanPin (version 6.0)" + IDIS_METASEQUOIAIME "Chinese Simplified QuanPin (version 6.0)" IDS_DEFAULT_FONT "Microsoft YaHei UI" END diff --git a/src/IME/SampleIMEBaseStructure.cpp b/src/IME/MetasequoiaIMEBaseStructure.cpp similarity index 100% rename from src/IME/SampleIMEBaseStructure.cpp rename to src/IME/MetasequoiaIMEBaseStructure.cpp diff --git a/src/IME/SampleIMEBaseStructure.h b/src/IME/MetasequoiaIMEBaseStructure.h similarity index 88% rename from src/IME/SampleIMEBaseStructure.h rename to src/IME/MetasequoiaIMEBaseStructure.h index 21120fab..c5045bbd 100644 --- a/src/IME/SampleIMEBaseStructure.h +++ b/src/IME/MetasequoiaIMEBaseStructure.h @@ -96,21 +96,21 @@ HRESULT FindChar(WCHAR wch, _In_ LPCWSTR pwszBuffer, DWORD_PTR dwBufLen, _Out_ D BOOL IsSpace(LCID locale, WCHAR wch); -template class CSampleImeArray +template class CMetasequoiaImeArray { - typedef typename std::vector CSampleImeInnerArray; - typedef typename std::vector::iterator CSampleImeInnerIter; + typedef typename std::vector CMetasequoiaImeInnerArray; + typedef typename std::vector::iterator CMetasequoiaImeInnerIter; public: - CSampleImeArray() : _innerVect() + CMetasequoiaImeArray() : _innerVect() { } - explicit CSampleImeArray(size_t count) : _innerVect(count) + explicit CMetasequoiaImeArray(size_t count) : _innerVect(count) { } - virtual ~CSampleImeArray() + virtual ~CMetasequoiaImeArray() { } @@ -139,7 +139,7 @@ template class CSampleImeArray assert(index >= 0); assert(index < _innerVect.size()); - CSampleImeInnerIter iter = _innerVect.begin(); + CMetasequoiaImeInnerIter iter = _innerVect.begin(); _innerVect.erase(iter + index); } @@ -168,7 +168,7 @@ template class CSampleImeArray } private: - CSampleImeInnerArray _innerVect; + CMetasequoiaImeInnerArray _innerVect; }; class CCandidateRange @@ -194,7 +194,7 @@ class CCandidateRange } private: - CSampleImeArray _CandidateListIndexRange; + CMetasequoiaImeArray _CandidateListIndexRange; }; class CStringRange diff --git a/src/IME/SampleIMEStructureArray.h b/src/IME/MetasequoiaIMEStructureArray.h similarity index 57% rename from src/IME/SampleIMEStructureArray.h rename to src/IME/MetasequoiaIMEStructureArray.h index 35b29a52..ac61de8d 100644 --- a/src/IME/SampleIMEStructureArray.h +++ b/src/IME/MetasequoiaIMEStructureArray.h @@ -2,9 +2,9 @@ // // Copyright (C) Microsoft Corporation. All rights reserved. // -// CSampleIMESampleIMEStructureArray.h +// CMetasequoiaIMEMetasequoiaIMEStructureArray.h // -// CSampleIMEStructureArray declaration. +// CMetasequoiaIMEStructureArray declaration. // ////////////////////////////////////////////////////////////////////// @@ -12,27 +12,27 @@ #include -template class CSampleIMEStructureArray +template class CMetasequoiaIMEStructureArray { typedef typename std::vector value_type; typedef const T &CONST_REF; - typedef typename value_type CSampleIMEArray; - typedef typename value_type::iterator CSampleIMEIter; + typedef typename value_type CMetasequoiaIMEArray; + typedef typename value_type::iterator CMetasequoiaIMEIter; public: - CSampleIMEStructureArray() : _imeVector() + CMetasequoiaIMEStructureArray() : _imeVector() { } - explicit CSampleIMEStructureArray(size_t iCount) : _imeVector(iCount) + explicit CMetasequoiaIMEStructureArray(size_t iCount) : _imeVector(iCount) { } - CSampleIMEStructureArray(size_t iCount, CONST_REF tVal) : _imeVector(iCount, tVal) + CMetasequoiaIMEStructureArray(size_t iCount, CONST_REF tVal) : _imeVector(iCount, tVal) { } - virtual ~CSampleIMEStructureArray() + virtual ~CMetasequoiaIMEStructureArray() { } @@ -57,8 +57,8 @@ template class CSampleIMEStructureArray assert(iIndex <= _imeVector.size()); assert(_imeVector.size() > 0); - CSampleIMEIter beginIter = _imeVector.begin() + iIndex; - CSampleIMEIter lastIter = beginIter + iElements - 1; + CMetasequoiaIMEIter beginIter = _imeVector.begin() + iIndex; + CMetasequoiaIMEIter lastIter = beginIter + iElements - 1; _imeVector.erase(beginIter, lastIter); } @@ -79,6 +79,6 @@ template class CSampleIMEStructureArray } private: - CSampleIMEArray _imeVector; // the actual array of data - CSampleIMEIter _imeIter; + CMetasequoiaIMEArray _imeVector; // the actual array of data + CMetasequoiaIMEIter _imeIter; }; diff --git a/src/Key/KeyEventSink.cpp b/src/Key/KeyEventSink.cpp index 43ecd80e..9bb4a91d 100644 --- a/src/Key/KeyEventSink.cpp +++ b/src/Key/KeyEventSink.cpp @@ -1,11 +1,11 @@ #include "Private.h" #include "Globals.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" #include "CandidateListUIPresenter.h" #include "CompositionProcessorEngine.h" #include "KeyHandlerEditSession.h" #include "Compartment.h" -#include "SampleIMEBaseStructure.h" +#include "MetasequoiaIMEBaseStructure.h" #include "fmt/xchar.h" #include #include @@ -57,7 +57,7 @@ __inline UINT VKeyFromVKPacketAndWchar(UINT vk, WCHAR wch) // //---------------------------------------------------------------------------- -BOOL CSampleIME::_IsKeyEaten(_In_ ITfContext *pContext, UINT codeIn, _Out_ UINT *pCodeOut, _Out_writes_(1) WCHAR *pwch, +BOOL CMetasequoiaIME::_IsKeyEaten(_In_ ITfContext *pContext, UINT codeIn, _Out_ UINT *pCodeOut, _Out_writes_(1) WCHAR *pwch, _Out_opt_ _KEYSTROKE_STATE *pKeyState) { pContext; @@ -70,11 +70,11 @@ BOOL CSampleIME::_IsKeyEaten(_In_ ITfContext *pContext, UINT codeIn, _Out_ UINT BOOL isDoubleSingleByte = FALSE; CCompartment CompartmentDoubleSingleByte(_pThreadMgr, _tfClientId, - Global::SampleIMEGuidCompartmentDoubleSingleByte); + Global::MetasequoiaIMEGuidCompartmentDoubleSingleByte); CompartmentDoubleSingleByte._GetCompartmentBOOL(isDoubleSingleByte); BOOL isPunctuation = FALSE; - CCompartment CompartmentPunctuation(_pThreadMgr, _tfClientId, Global::SampleIMEGuidCompartmentPunctuation); + CCompartment CompartmentPunctuation(_pThreadMgr, _tfClientId, Global::MetasequoiaIMEGuidCompartmentPunctuation); CompartmentPunctuation._GetCompartmentBOOL(isPunctuation); if (pKeyState) @@ -185,7 +185,7 @@ BOOL CSampleIME::_IsKeyEaten(_In_ ITfContext *pContext, UINT codeIn, _Out_ UINT // //---------------------------------------------------------------------------- -WCHAR CSampleIME::ConvertVKey(UINT code) +WCHAR CMetasequoiaIME::ConvertVKey(UINT code) { // // Map virtual key to scan code @@ -220,7 +220,7 @@ WCHAR CSampleIME::ConvertVKey(UINT code) // //---------------------------------------------------------------------------- -BOOL CSampleIME::_IsKeyboardDisabled() +BOOL CMetasequoiaIME::_IsKeyboardDisabled() { ITfDocumentMgr *pDocMgrFocus = nullptr; ITfContext *pContext = nullptr; @@ -266,7 +266,7 @@ BOOL CSampleIME::_IsKeyboardDisabled() // Called by the system whenever this service gets the keystroke device focus. //---------------------------------------------------------------------------- -STDAPI CSampleIME::OnSetFocus(BOOL fForeground) +STDAPI CMetasequoiaIME::OnSetFocus(BOOL fForeground) { fForeground; @@ -280,7 +280,7 @@ STDAPI CSampleIME::OnSetFocus(BOOL fForeground) // Called by the system to query this service wants a potential keystroke. //---------------------------------------------------------------------------- -STDAPI CSampleIME::OnTestKeyDown(ITfContext *pContext, WPARAM wParam, LPARAM lParam, BOOL *pIsEaten) +STDAPI CMetasequoiaIME::OnTestKeyDown(ITfContext *pContext, WPARAM wParam, LPARAM lParam, BOOL *pIsEaten) { Global::UpdateModifiers(wParam, lParam); @@ -310,7 +310,7 @@ STDAPI CSampleIME::OnTestKeyDown(ITfContext *pContext, WPARAM wParam, LPARAM lPa // on exit, the application will not handle the keystroke. //---------------------------------------------------------------------------- -STDAPI CSampleIME::OnKeyDown(ITfContext *pContext, WPARAM wParam, LPARAM lParam, BOOL *pIsEaten) +STDAPI CMetasequoiaIME::OnKeyDown(ITfContext *pContext, WPARAM wParam, LPARAM lParam, BOOL *pIsEaten) { Global::UpdateModifiers(wParam, lParam); @@ -405,7 +405,7 @@ STDAPI CSampleIME::OnKeyDown(ITfContext *pContext, WPARAM wParam, LPARAM lParam, // Called by the system to query this service wants a potential keystroke. //---------------------------------------------------------------------------- -STDAPI CSampleIME::OnTestKeyUp(ITfContext *pContext, WPARAM wParam, LPARAM lParam, BOOL *pIsEaten) +STDAPI CMetasequoiaIME::OnTestKeyUp(ITfContext *pContext, WPARAM wParam, LPARAM lParam, BOOL *pIsEaten) { if (pIsEaten == nullptr) { @@ -430,7 +430,7 @@ STDAPI CSampleIME::OnTestKeyUp(ITfContext *pContext, WPARAM wParam, LPARAM lPara // on exit, the application will not handle the keystroke. //---------------------------------------------------------------------------- -STDAPI CSampleIME::OnKeyUp(ITfContext *pContext, WPARAM wParam, LPARAM lParam, BOOL *pIsEaten) +STDAPI CMetasequoiaIME::OnKeyUp(ITfContext *pContext, WPARAM wParam, LPARAM lParam, BOOL *pIsEaten) { Global::UpdateModifiers(wParam, lParam); @@ -464,7 +464,7 @@ STDAPI CSampleIME::OnKeyUp(ITfContext *pContext, WPARAM wParam, LPARAM lParam, B // Called when a hotkey (registered by us, or by the system) is typed. //---------------------------------------------------------------------------- -STDAPI CSampleIME::OnPreservedKey(ITfContext *pContext, REFGUID rguid, BOOL *pIsEaten) +STDAPI CMetasequoiaIME::OnPreservedKey(ITfContext *pContext, REFGUID rguid, BOOL *pIsEaten) { pContext; @@ -496,7 +496,7 @@ STDAPI CSampleIME::OnPreservedKey(ITfContext *pContext, REFGUID rguid, BOOL *pIs // Advise a keystroke sink. //---------------------------------------------------------------------------- -BOOL CSampleIME::_InitKeyEventSink() +BOOL CMetasequoiaIME::_InitKeyEventSink() { ITfKeystrokeMgr *pKeystrokeMgr = nullptr; HRESULT hr = S_OK; @@ -520,7 +520,7 @@ BOOL CSampleIME::_InitKeyEventSink() // Unadvise a keystroke sink. Assumes we have advised one already. //---------------------------------------------------------------------------- -void CSampleIME::_UninitKeyEventSink() +void CMetasequoiaIME::_UninitKeyEventSink() { ITfKeystrokeMgr *pKeystrokeMgr = nullptr; diff --git a/src/Key/KeyHandler.cpp b/src/Key/KeyHandler.cpp index 829d3903..9f6fe789 100644 --- a/src/Key/KeyHandler.cpp +++ b/src/Key/KeyHandler.cpp @@ -1,10 +1,10 @@ #include "Private.h" #include "Globals.h" #include "EditSession.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" #include "CandidateListUIPresenter.h" #include "CompositionProcessorEngine.h" -#include "SampleIMEBaseStructure.h" +#include "MetasequoiaIMEBaseStructure.h" #include #include #include @@ -13,7 +13,7 @@ ////////////////////////////////////////////////////////////////////// // -// CSampleIME class +// CMetasequoiaIME class // ////////////////////////////////////////////////////////////////////// @@ -25,7 +25,7 @@ // //---------------------------------------------------------------------------- -BOOL CSampleIME::_IsRangeCovered(TfEditCookie ec, _In_ ITfRange *pRangeTest, _In_ ITfRange *pRangeCover) +BOOL CMetasequoiaIME::_IsRangeCovered(TfEditCookie ec, _In_ ITfRange *pRangeTest, _In_ ITfRange *pRangeCover) { LONG lResult = 0; ; @@ -49,7 +49,7 @@ BOOL CSampleIME::_IsRangeCovered(TfEditCookie ec, _In_ ITfRange *pRangeTest, _In // //---------------------------------------------------------------------------- -VOID CSampleIME::_DeleteCandidateList(BOOL isForce, _In_opt_ ITfContext *pContext) +VOID CMetasequoiaIME::_DeleteCandidateList(BOOL isForce, _In_opt_ ITfContext *pContext) { isForce; pContext; @@ -73,7 +73,7 @@ VOID CSampleIME::_DeleteCandidateList(BOOL isForce, _In_opt_ ITfContext *pContex // //---------------------------------------------------------------------------- -HRESULT CSampleIME::_HandleComplete(TfEditCookie ec, _In_ ITfContext *pContext) +HRESULT CMetasequoiaIME::_HandleComplete(TfEditCookie ec, _In_ ITfContext *pContext) { _DeleteCandidateList(FALSE, pContext); @@ -89,7 +89,7 @@ HRESULT CSampleIME::_HandleComplete(TfEditCookie ec, _In_ ITfContext *pContext) // //---------------------------------------------------------------------------- -HRESULT CSampleIME::_HandleCancel(TfEditCookie ec, _In_ ITfContext *pContext) +HRESULT CMetasequoiaIME::_HandleCancel(TfEditCookie ec, _In_ ITfContext *pContext) { _RemoveDummyCompositionForComposing(ec, _pComposition); @@ -100,7 +100,7 @@ HRESULT CSampleIME::_HandleCancel(TfEditCookie ec, _In_ ITfContext *pContext) return S_OK; } -HRESULT CSampleIME::_HandleToogleIMEMode(TfEditCookie ec, _In_ ITfContext *pContext) +HRESULT CMetasequoiaIME::_HandleToogleIMEMode(TfEditCookie ec, _In_ ITfContext *pContext) { CStringRange keyStrokebuffer = _pCompositionProcessorEngine->GetKeystrokeBuffer(); if (keyStrokebuffer.GetLength()) @@ -130,7 +130,7 @@ HRESULT CSampleIME::_HandleToogleIMEMode(TfEditCookie ec, _In_ ITfContext *pCont // //---------------------------------------------------------------------------- -HRESULT CSampleIME::_HandleCompositionInput(TfEditCookie ec, _In_ ITfContext *pContext, WCHAR wch) +HRESULT CMetasequoiaIME::_HandleCompositionInput(TfEditCookie ec, _In_ ITfContext *pContext, WCHAR wch) { ITfRange *pRangeComposition = nullptr; TF_SELECTION tfSelection; @@ -191,11 +191,11 @@ Exit: // //---------------------------------------------------------------------------- -HRESULT CSampleIME::_HandleCompositionInputWorker(_In_ CCompositionProcessorEngine *pCompositionProcessorEngine, +HRESULT CMetasequoiaIME::_HandleCompositionInputWorker(_In_ CCompositionProcessorEngine *pCompositionProcessorEngine, TfEditCookie ec, _In_ ITfContext *pContext) { HRESULT hr = S_OK; - CSampleImeArray readingStrings; + CMetasequoiaImeArray readingStrings; BOOL isWildcardIncluded = FALSE; // @@ -222,7 +222,7 @@ HRESULT CSampleIME::_HandleCompositionInputWorker(_In_ CCompositionProcessorEngi // // Get candidate string from composition processor engine // - CSampleImeArray candidateList; + CMetasequoiaImeArray candidateList; // // Important: Generate candidate list here @@ -259,7 +259,7 @@ HRESULT CSampleIME::_HandleCompositionInputWorker(_In_ CCompositionProcessorEngi // //---------------------------------------------------------------------------- -HRESULT CSampleIME::_CreateAndStartCandidate(_In_ CCompositionProcessorEngine *pCompositionProcessorEngine, +HRESULT CMetasequoiaIME::_CreateAndStartCandidate(_In_ CCompositionProcessorEngine *pCompositionProcessorEngine, TfEditCookie ec, _In_ ITfContext *pContext) { HRESULT hr = S_OK; @@ -315,7 +315,7 @@ HRESULT CSampleIME::_CreateAndStartCandidate(_In_ CCompositionProcessorEngine *p // //---------------------------------------------------------------------------- -HRESULT CSampleIME::_HandleCompositionFinalize(TfEditCookie ec, _In_ ITfContext *pContext, BOOL isCandidateList) +HRESULT CMetasequoiaIME::_HandleCompositionFinalize(TfEditCookie ec, _In_ ITfContext *pContext, BOOL isCandidateList) { HRESULT hr = S_OK; @@ -379,11 +379,11 @@ HRESULT CSampleIME::_HandleCompositionFinalize(TfEditCookie ec, _In_ ITfContext // //---------------------------------------------------------------------------- -HRESULT CSampleIME::_HandleCompositionConvert(TfEditCookie ec, _In_ ITfContext *pContext, BOOL isWildcardSearch) +HRESULT CMetasequoiaIME::_HandleCompositionConvert(TfEditCookie ec, _In_ ITfContext *pContext, BOOL isWildcardSearch) { HRESULT hr = S_OK; - CSampleImeArray candidateList; + CMetasequoiaImeArray candidateList; // // Get candidate string from composition processor engine @@ -455,7 +455,7 @@ HRESULT CSampleIME::_HandleCompositionConvert(TfEditCookie ec, _In_ ITfContext * // //---------------------------------------------------------------------------- -HRESULT CSampleIME::_HandleCompositionBackspace(TfEditCookie ec, _In_ ITfContext *pContext) +HRESULT CMetasequoiaIME::_HandleCompositionBackspace(TfEditCookie ec, _In_ ITfContext *pContext) { ITfRange *pRangeComposition = nullptr; TF_SELECTION tfSelection; @@ -522,7 +522,7 @@ Exit: // //---------------------------------------------------------------------------- -HRESULT CSampleIME::_HandleCompositionArrowKey(TfEditCookie ec, _In_ ITfContext *pContext, +HRESULT CMetasequoiaIME::_HandleCompositionArrowKey(TfEditCookie ec, _In_ ITfContext *pContext, KEYSTROKE_FUNCTION keyFunction) { ITfRange *pRangeComposition = nullptr; @@ -563,7 +563,7 @@ Exit: // //---------------------------------------------------------------------------- -HRESULT CSampleIME::_HandleCompositionPunctuation(TfEditCookie ec, _In_ ITfContext *pContext, WCHAR wch) +HRESULT CMetasequoiaIME::_HandleCompositionPunctuation(TfEditCookie ec, _In_ ITfContext *pContext, WCHAR wch) { HRESULT hr = S_OK; #ifdef FANY_DEBUG @@ -626,7 +626,7 @@ HRESULT CSampleIME::_HandleCompositionPunctuation(TfEditCookie ec, _In_ ITfConte // //---------------------------------------------------------------------------- -HRESULT CSampleIME::_HandleCompositionDoubleSingleByte(TfEditCookie ec, _In_ ITfContext *pContext, WCHAR wch) +HRESULT CMetasequoiaIME::_HandleCompositionDoubleSingleByte(TfEditCookie ec, _In_ ITfContext *pContext, WCHAR wch) { HRESULT hr = S_OK; @@ -661,7 +661,7 @@ HRESULT CSampleIME::_HandleCompositionDoubleSingleByte(TfEditCookie ec, _In_ ITf // [in] dwKeyFunction - Function regarding virtual key //---------------------------------------------------------------------------- -HRESULT CSampleIME::_InvokeKeyHandler(_In_ ITfContext *pContext, UINT code, WCHAR wch, DWORD flags, +HRESULT CMetasequoiaIME::_InvokeKeyHandler(_In_ ITfContext *pContext, UINT code, WCHAR wch, DWORD flags, _KEYSTROKE_STATE keyState) { flags; diff --git a/src/Key/KeyHandlerEditSession.cpp b/src/Key/KeyHandlerEditSession.cpp index 4adfb9d5..54b2e92d 100644 --- a/src/Key/KeyHandlerEditSession.cpp +++ b/src/Key/KeyHandlerEditSession.cpp @@ -8,7 +8,7 @@ #include "Private.h" #include "KeyHandlerEditSession.h" #include "EditSession.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" #include "CompositionProcessorEngine.h" #include "KeyStateCategory.h" diff --git a/src/Key/KeyHandlerEditSession.h b/src/Key/KeyHandlerEditSession.h index 57d46147..56045906 100644 --- a/src/Key/KeyHandlerEditSession.h +++ b/src/Key/KeyHandlerEditSession.h @@ -13,7 +13,7 @@ class CKeyHandlerEditSession : public CEditSessionBase { public: - CKeyHandlerEditSession(CSampleIME *pTextService, ITfContext *pContext, UINT uCode, WCHAR wch, + CKeyHandlerEditSession(CMetasequoiaIME *pTextService, ITfContext *pContext, UINT uCode, WCHAR wch, _KEYSTROKE_STATE keyState) : CEditSessionBase(pTextService, pContext) { diff --git a/src/Key/KeyStateCategory.cpp b/src/Key/KeyStateCategory.cpp index 4b7fbfdd..0320c2b2 100644 --- a/src/Key/KeyStateCategory.cpp +++ b/src/Key/KeyStateCategory.cpp @@ -1,7 +1,7 @@ #include "KeyStateCategory.h" #include "Globals.h" #include "Ipc.h" -#include "SampleIMEBaseStructure.h" +#include "MetasequoiaIMEBaseStructure.h" #include CKeyStateCategoryFactory *CKeyStateCategoryFactory::_instance; @@ -22,7 +22,7 @@ CKeyStateCategoryFactory *CKeyStateCategoryFactory::Instance() } CKeyStateCategory *CKeyStateCategoryFactory::MakeKeyStateCategory(KEYSTROKE_CATEGORY keyCategory, - _In_ CSampleIME *pTextService) + _In_ CMetasequoiaIME *pTextService) { CKeyStateCategory *pKeyState = nullptr; @@ -63,7 +63,7 @@ void CKeyStateCategoryFactory::Release() /* class CKeyStateCategory */ -CKeyStateCategory::CKeyStateCategory(_In_ CSampleIME *pTextService) +CKeyStateCategory::CKeyStateCategory(_In_ CMetasequoiaIME *pTextService) { _pTextService = pTextService; } @@ -249,7 +249,7 @@ HRESULT CKeyStateCategory::HandleKeySelectByNumber(KeyHandlerEditSessionDTO dto) /* class CKeyStateComposing */ -CKeyStateComposing::CKeyStateComposing(_In_ CSampleIME *pTextService) : CKeyStateCategory(pTextService) +CKeyStateComposing::CKeyStateComposing(_In_ CMetasequoiaIME *pTextService) : CKeyStateCategory(pTextService) { } @@ -331,7 +331,7 @@ HRESULT CKeyStateComposing::HandleKeyPunctuation(KeyHandlerEditSessionDTO dto) /* class CKeyStateCandidate */ -CKeyStateCandidate::CKeyStateCandidate(_In_ CSampleIME *pTextService) : CKeyStateCategory(pTextService) +CKeyStateCandidate::CKeyStateCandidate(_In_ CMetasequoiaIME *pTextService) : CKeyStateCategory(pTextService) { } @@ -397,7 +397,7 @@ HRESULT CKeyStateCandidate::HandleKeySelectByNumber(KeyHandlerEditSessionDTO dto class CKeyStatePhrase */ -CKeyStatePhrase::CKeyStatePhrase(_In_ CSampleIME *pTextService) : CKeyStateCategory(pTextService) +CKeyStatePhrase::CKeyStatePhrase(_In_ CMetasequoiaIME *pTextService) : CKeyStateCategory(pTextService) { } diff --git a/src/Key/KeyStateCategory.h b/src/Key/KeyStateCategory.h index ccece770..37cebec4 100644 --- a/src/Key/KeyStateCategory.h +++ b/src/Key/KeyStateCategory.h @@ -1,7 +1,7 @@ #pragma once #include "Globals.h" #include "Private.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" class CKeyStateCategory; @@ -9,7 +9,7 @@ class CKeyStateCategoryFactory { public: static CKeyStateCategoryFactory *Instance(); - CKeyStateCategory *MakeKeyStateCategory(KEYSTROKE_CATEGORY keyCategory, _In_ CSampleIME *pTextService); + CKeyStateCategory *MakeKeyStateCategory(KEYSTROKE_CATEGORY keyCategory, _In_ CMetasequoiaIME *pTextService); void Release(); protected: @@ -41,7 +41,7 @@ typedef struct KeyHandlerEditSessionDTO class CKeyStateCategory { public: - CKeyStateCategory(_In_ CSampleIME *pTextService); + CKeyStateCategory(_In_ CMetasequoiaIME *pTextService); protected: ~CKeyStateCategory(void); @@ -97,13 +97,13 @@ class CKeyStateCategory virtual HRESULT HandleKeySelectByNumber(KeyHandlerEditSessionDTO dto); protected: - CSampleIME *_pTextService; + CMetasequoiaIME *_pTextService; }; class CKeyStateComposing : public CKeyStateCategory { public: - CKeyStateComposing(_In_ CSampleIME *pTextService); + CKeyStateComposing(_In_ CMetasequoiaIME *pTextService); protected: // _HandleCompositionInput @@ -149,7 +149,7 @@ class CKeyStateComposing : public CKeyStateCategory class CKeyStateCandidate : public CKeyStateCategory { public: - CKeyStateCandidate(_In_ CSampleIME *pTextService); + CKeyStateCandidate(_In_ CMetasequoiaIME *pTextService); protected: // HandleKeyFinalizeCandidatelist @@ -176,7 +176,7 @@ class CKeyStateCandidate : public CKeyStateCategory class CKeyStatePhrase : public CKeyStateCategory { public: - CKeyStatePhrase(_In_ CSampleIME *pTextService); + CKeyStatePhrase(_In_ CMetasequoiaIME *pTextService); protected: //_HandleCancel @@ -196,7 +196,7 @@ class CKeyStatePhrase : public CKeyStateCategory class CKeyStateNull : public CKeyStateCategory { public: - CKeyStateNull(_In_ CSampleIME *pTextService) : CKeyStateCategory(pTextService) {}; + CKeyStateNull(_In_ CMetasequoiaIME *pTextService) : CKeyStateCategory(pTextService) {}; protected: // _HandleNullInput diff --git a/src/LanguageBar/LanguageBar.cpp b/src/LanguageBar/LanguageBar.cpp index eb590cfc..eaa2cd37 100644 --- a/src/LanguageBar/LanguageBar.cpp +++ b/src/LanguageBar/LanguageBar.cpp @@ -14,7 +14,7 @@ #endif // !UNICODE #include "Private.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" #include "CompositionProcessorEngine.h" #include "LanguageBar.h" #include "Globals.h" @@ -22,11 +22,11 @@ //+--------------------------------------------------------------------------- // -// CSampleIME::_UpdateLanguageBarOnSetFocus +// CMetasequoiaIME::_UpdateLanguageBarOnSetFocus // //---------------------------------------------------------------------------- -void CSampleIME::_UpdateLanguageBarOnSetFocus(_In_ ITfDocumentMgr *pDocMgrFocus) +void CMetasequoiaIME::_UpdateLanguageBarOnSetFocus(_In_ ITfDocumentMgr *pDocMgrFocus) { BOOL needDisableButtons = FALSE; @@ -111,7 +111,7 @@ CLangBarItemButton::CLangBarItemButton(REFGUID guidLangBar, LPCWSTR description, DllAddRef(); // initialize TF_LANGBARITEMINFO structure. - _tfLangBarItemInfo.clsidService = Global::SampleIMECLSID; // This LangBarItem belongs to this TextService. + _tfLangBarItemInfo.clsidService = Global::MetasequoiaIMECLSID; // This LangBarItem belongs to this TextService. _tfLangBarItemInfo.guidItem = guidLangBar; // GUID of this LangBarItem. _tfLangBarItemInfo.dwStyle = (TF_LBI_STYLE_BTN_BUTTON | TF_LBI_STYLE_SHOWNINTRAY); // This LangBar is a button type. _tfLangBarItemInfo.ulSort = 0; // The position of this LangBar Item is not specified. diff --git a/src/LanguageBar/LanguageBar.h b/src/LanguageBar/LanguageBar.h index bc35321d..69a3f317 100644 --- a/src/LanguageBar/LanguageBar.h +++ b/src/LanguageBar/LanguageBar.h @@ -8,7 +8,7 @@ #pragma once #include "Private.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" #include "CompositionProcessorEngine.h" #include "Globals.h" #include "Compartment.h" diff --git a/src/Register/Register.cpp b/src/Register/Register.cpp index ce31fc04..d9020e23 100644 --- a/src/Register/Register.cpp +++ b/src/Register/Register.cpp @@ -64,7 +64,7 @@ BOOL RegisterProfiles() goto Exit; } hr = pITfInputProcessorProfileMgr->RegisterProfile( - Global::SampleIMECLSID, TEXTSERVICE_LANGID, Global::SampleIMEGuidProfile, TEXTSERVICE_DESC, + Global::MetasequoiaIMECLSID, TEXTSERVICE_LANGID, Global::MetasequoiaIMEGuidProfile, TEXTSERVICE_DESC, static_cast(lenOfDesc), achIconFile, cchA, (UINT)TEXTSERVICE_ICON_INDEX, NULL, 0, TRUE, 0); if (FAILED(hr)) @@ -99,8 +99,8 @@ void UnregisterProfiles() goto Exit; } - hr = pITfInputProcessorProfileMgr->UnregisterProfile(Global::SampleIMECLSID, TEXTSERVICE_LANGID, - Global::SampleIMEGuidProfile, 0); + hr = pITfInputProcessorProfileMgr->UnregisterProfile(Global::MetasequoiaIMECLSID, TEXTSERVICE_LANGID, + Global::MetasequoiaIMEGuidProfile, 0); if (FAILED(hr)) { goto Exit; @@ -135,7 +135,7 @@ BOOL RegisterCategories() // for each (GUID guid in SupportCategories) for (const auto &guid : SupportCategories) { - hr = pCategoryMgr->RegisterCategory(Global::SampleIMECLSID, guid, Global::SampleIMECLSID); + hr = pCategoryMgr->RegisterCategory(Global::MetasequoiaIMECLSID, guid, Global::MetasequoiaIMECLSID); } pCategoryMgr->Release(); @@ -163,7 +163,7 @@ void UnregisterCategories() // for each (GUID guid in SupportCategories) for (const auto &guid : SupportCategories) { - pCategoryMgr->UnregisterCategory(Global::SampleIMECLSID, guid, Global::SampleIMECLSID); + pCategoryMgr->UnregisterCategory(Global::MetasequoiaIMECLSID, guid, Global::MetasequoiaIMECLSID); } pCategoryMgr->Release(); @@ -223,7 +223,7 @@ BOOL RegisterServer() WCHAR achIMEKey[ARRAYSIZE(RegInfo_Prefix_CLSID) + CLSID_STRLEN] = {'\0'}; WCHAR achFileName[MAX_PATH] = {'\0'}; - if (!CLSIDToString(Global::SampleIMECLSID, achIMEKey + ARRAYSIZE(RegInfo_Prefix_CLSID) - 1)) + if (!CLSIDToString(Global::MetasequoiaIMECLSID, achIMEKey + ARRAYSIZE(RegInfo_Prefix_CLSID) - 1)) { return FALSE; } @@ -284,7 +284,7 @@ void UnregisterServer() { WCHAR achIMEKey[ARRAYSIZE(RegInfo_Prefix_CLSID) + CLSID_STRLEN] = {'\0'}; - if (!CLSIDToString(Global::SampleIMECLSID, achIMEKey + ARRAYSIZE(RegInfo_Prefix_CLSID) - 1)) + if (!CLSIDToString(Global::MetasequoiaIMECLSID, achIMEKey + ARRAYSIZE(RegInfo_Prefix_CLSID) - 1)) { return; } diff --git a/src/Server.cpp b/src/Server.cpp index 1c613b7a..b5e1b48b 100644 --- a/src/Server.cpp +++ b/src/Server.cpp @@ -7,7 +7,7 @@ #include "Private.h" #include "Globals.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" // from Register.cpp BOOL RegisterProfiles(); @@ -173,7 +173,7 @@ STDAPI CClassFactory::LockServer(BOOL fLock) void BuildGlobalObjects(void) { - classFactoryObjects[0] = new (std::nothrow) CClassFactory(Global::SampleIMECLSID, CSampleIME::CreateInstance); + classFactoryObjects[0] = new (std::nothrow) CClassFactory(Global::MetasequoiaIMECLSID, CMetasequoiaIME::CreateInstance); } //+--------------------------------------------------------------------------- diff --git a/src/Tf/TfTextLayoutSink.cpp b/src/Tf/TfTextLayoutSink.cpp index 0a1002ae..55f15329 100644 --- a/src/Tf/TfTextLayoutSink.cpp +++ b/src/Tf/TfTextLayoutSink.cpp @@ -7,10 +7,10 @@ #include "Private.h" #include "TfTextLayoutSink.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" #include "GetTextExtentEditSession.h" -CTfTextLayoutSink::CTfTextLayoutSink(_In_ CSampleIME *pTextService) +CTfTextLayoutSink::CTfTextLayoutSink(_In_ CMetasequoiaIME *pTextService) { _pTextService = pTextService; _pTextService->AddRef(); diff --git a/src/Tf/TfTextLayoutSink.h b/src/Tf/TfTextLayoutSink.h index 7d8d3065..ffea580c 100644 --- a/src/Tf/TfTextLayoutSink.h +++ b/src/Tf/TfTextLayoutSink.h @@ -9,12 +9,12 @@ #include "Private.h" -class CSampleIME; +class CMetasequoiaIME; class CTfTextLayoutSink : public ITfTextLayoutSink { public: - CTfTextLayoutSink(_In_ CSampleIME *pTextService); + CTfTextLayoutSink(_In_ CMetasequoiaIME *pTextService); virtual ~CTfTextLayoutSink(); // IUnknown methods @@ -45,7 +45,7 @@ class CTfTextLayoutSink : public ITfTextLayoutSink ITfRange *_pRangeComposition; ITfContext *_pContextDocument; TfEditCookie _tfEditCookie; - CSampleIME *_pTextService; + CMetasequoiaIME *_pTextService; DWORD _dwCookieTextLayoutSink; LONG _refCount; }; diff --git a/src/Thread/ThreadFocusSink.cpp b/src/Thread/ThreadFocusSink.cpp index 44b1b9ae..fee6c367 100644 --- a/src/Thread/ThreadFocusSink.cpp +++ b/src/Thread/ThreadFocusSink.cpp @@ -7,7 +7,7 @@ #include "Ipc.h" #include "Private.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" #include "CandidateListUIPresenter.h" #include @@ -17,7 +17,7 @@ // //---------------------------------------------------------------------------- -STDAPI CSampleIME::OnSetThreadFocus() +STDAPI CMetasequoiaIME::OnSetThreadFocus() { // Connect to namedpipe InitNamedpipe(); @@ -45,7 +45,7 @@ STDAPI CSampleIME::OnSetThreadFocus() // //---------------------------------------------------------------------------- -STDAPI CSampleIME::OnKillThreadFocus() +STDAPI CMetasequoiaIME::OnKillThreadFocus() { // Disconnect from namedpipe CloseNamedpipe(); @@ -72,7 +72,7 @@ STDAPI CSampleIME::OnKillThreadFocus() return S_OK; } -BOOL CSampleIME::_InitThreadFocusSink() +BOOL CMetasequoiaIME::_InitThreadFocusSink() { ITfSource *pSource = nullptr; @@ -92,7 +92,7 @@ BOOL CSampleIME::_InitThreadFocusSink() return TRUE; } -void CSampleIME::_UninitThreadFocusSink() +void CMetasequoiaIME::_UninitThreadFocusSink() { ITfSource *pSource = nullptr; diff --git a/src/Thread/ThreadMgrEventSink.cpp b/src/Thread/ThreadMgrEventSink.cpp index 2a185e55..f91d0ed6 100644 --- a/src/Thread/ThreadMgrEventSink.cpp +++ b/src/Thread/ThreadMgrEventSink.cpp @@ -7,7 +7,7 @@ #include "Private.h" #include "Globals.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" #include "CandidateListUIPresenter.h" //+--------------------------------------------------------------------------- @@ -18,7 +18,7 @@ // a document. //---------------------------------------------------------------------------- -STDAPI CSampleIME::OnInitDocumentMgr(_In_ ITfDocumentMgr *pDocMgr) +STDAPI CMetasequoiaIME::OnInitDocumentMgr(_In_ ITfDocumentMgr *pDocMgr) { pDocMgr; return E_NOTIMPL; @@ -32,7 +32,7 @@ STDAPI CSampleIME::OnInitDocumentMgr(_In_ ITfDocumentMgr *pDocMgr) // document. //---------------------------------------------------------------------------- -STDAPI CSampleIME::OnUninitDocumentMgr(_In_ ITfDocumentMgr *pDocMgr) +STDAPI CMetasequoiaIME::OnUninitDocumentMgr(_In_ ITfDocumentMgr *pDocMgr) { pDocMgr; return E_NOTIMPL; @@ -47,7 +47,7 @@ STDAPI CSampleIME::OnUninitDocumentMgr(_In_ ITfDocumentMgr *pDocMgr) // focus document, or now no document holds the input focus. //---------------------------------------------------------------------------- -STDAPI CSampleIME::OnSetFocus(_In_ ITfDocumentMgr *pDocMgrFocus, _In_ ITfDocumentMgr *pDocMgrPrevFocus) +STDAPI CMetasequoiaIME::OnSetFocus(_In_ ITfDocumentMgr *pDocMgrFocus, _In_ ITfDocumentMgr *pDocMgrPrevFocus) { pDocMgrPrevFocus; @@ -101,7 +101,7 @@ STDAPI CSampleIME::OnSetFocus(_In_ ITfDocumentMgr *pDocMgrFocus, _In_ ITfDocumen // Sink called by the framework when a context is pushed. //---------------------------------------------------------------------------- -STDAPI CSampleIME::OnPushContext(_In_ ITfContext *pContext) +STDAPI CMetasequoiaIME::OnPushContext(_In_ ITfContext *pContext) { pContext; @@ -115,7 +115,7 @@ STDAPI CSampleIME::OnPushContext(_In_ ITfContext *pContext) // Sink called by the framework when a context is popped. //---------------------------------------------------------------------------- -STDAPI CSampleIME::OnPopContext(_In_ ITfContext *pContext) +STDAPI CMetasequoiaIME::OnPopContext(_In_ ITfContext *pContext) { pContext; @@ -129,7 +129,7 @@ STDAPI CSampleIME::OnPopContext(_In_ ITfContext *pContext) // Advise our sink. //---------------------------------------------------------------------------- -BOOL CSampleIME::_InitThreadMgrEventSink() +BOOL CMetasequoiaIME::_InitThreadMgrEventSink() { ITfSource *pSource = nullptr; BOOL ret = FALSE; @@ -160,7 +160,7 @@ Exit: // Unadvise our sink. //---------------------------------------------------------------------------- -void CSampleIME::_UninitThreadMgrEventSink() +void CMetasequoiaIME::_UninitThreadMgrEventSink() { ITfSource *pSource = nullptr; diff --git a/src/UI/CandidateListUIPresenter.cpp b/src/UI/CandidateListUIPresenter.cpp index ef2fd29e..15ef5049 100644 --- a/src/UI/CandidateListUIPresenter.cpp +++ b/src/UI/CandidateListUIPresenter.cpp @@ -1,1412 +1,1412 @@ -#include "Globals.h" -#include "Private.h" -#include "SampleIME.h" -#include "CandidateWindow.h" -#include "CandidateListUIPresenter.h" -#include "CompositionProcessorEngine.h" -#include "SampleIMEBaseStructure.h" -#include "define.h" -#include -#include -#include -#include -#include "Ipc.h" -#include "fmt/xchar.h" - -////////////////////////////////////////////////////////////////////// -// -// CSampleIME candidate key handler methods -// -////////////////////////////////////////////////////////////////////// - -const int MOVEUP_ONE = -1; -const int MOVEDOWN_ONE = 1; -const int MOVETO_TOP = 0; -const int MOVETO_BOTTOM = -1; - -//+--------------------------------------------------------------------------- -// -// _HandleCandidateFinalize -// -//---------------------------------------------------------------------------- - -HRESULT CSampleIME::_HandleCandidateFinalize(TfEditCookie ec, _In_ ITfContext *pContext) -{ - HRESULT hr = S_OK; - - CStringRange keyStrokebuffer = _pCompositionProcessorEngine->GetKeystrokeBuffer(); - DWORD_PTR keystrokeBufLen = keyStrokebuffer.GetLength(); - DWORD_PTR candidateLen = keystrokeBufLen; - CStringRange candidateString(keyStrokebuffer); - - // _pCandidateListUIPresenter would be null in uwp/metro apps - if (nullptr == _pCandidateListUIPresenter) - { - // goto NoPresenter; - } - - if (candidateLen) - { - if (Global::Keycode == VK_SPACE || (Global::Keycode > '0' && Global::Keycode < '9')) - { - WriteDataToSharedMemory(Global::Keycode, 0, nullptr, 0, L"", 0b00001); - // SendKeyEventToUIProcess(); - } - std::wstring receivedData = ReadDataFromServerViaNamedPipe(); - candidateString.Set(receivedData.c_str(), receivedData.length()); - hr = _AddComposingAndChar(ec, pContext, &candidateString); - if (FAILED(hr)) - { - return hr; - } - } - -NoPresenter: - - _HandleComplete(ec, pContext); - - return hr; -} - -//+--------------------------------------------------------------------------- -// -// _HandleCandidateFinalizeForVKReturn -// -//---------------------------------------------------------------------------- - -HRESULT CSampleIME::_HandleCandidateFinalizeForVKReturn(TfEditCookie ec, _In_ ITfContext *pContext) -{ - HRESULT hr = S_OK; - - CStringRange keyStrokebuffer = _pCompositionProcessorEngine->GetKeystrokeBuffer(); - DWORD_PTR keystrokeBufLen = keyStrokebuffer.GetLength(); - DWORD_PTR candidateLen = keystrokeBufLen; - CStringRange candidateString(keyStrokebuffer); - - if (nullptr == _pCandidateListUIPresenter) - { - // goto NoPresenter; - } - -#ifdef FANY_DEBUG - std::wstring msg(candidateString.Get(), candidateLen); - OutputDebugString(msg.c_str()); -#endif - - if (candidateLen) - { - hr = _AddComposingAndChar(ec, pContext, &candidateString); - - if (FAILED(hr)) - { - return hr; - } - } - -NoPresenter: - - _HandleComplete(ec, pContext); - - return hr; -} - -//+--------------------------------------------------------------------------- -// -// _HandleCandidateConvert -// -//---------------------------------------------------------------------------- - -HRESULT CSampleIME::_HandleCandidateConvert(TfEditCookie ec, _In_ ITfContext *pContext) -{ - return _HandleCandidateWorker(ec, pContext); -} - -//+--------------------------------------------------------------------------- -// -// _HandleCandidateWorker -// -//---------------------------------------------------------------------------- - -HRESULT CSampleIME::_HandleCandidateWorker(TfEditCookie ec, _In_ ITfContext *pContext) -{ - HRESULT hrReturn = E_FAIL; - DWORD_PTR candidateLen = 0; - const WCHAR *pCandidateString = nullptr; - BSTR pbstr = nullptr; - CStringRange candidateString; - CSampleImeArray candidatePhraseList; - - if (nullptr == _pCandidateListUIPresenter) - { - hrReturn = S_OK; - goto Exit; - } - - candidateLen = _pCandidateListUIPresenter->_GetSelectedCandidateString(&pCandidateString); - if (0 == candidateLen) - { - hrReturn = S_FALSE; - goto Exit; - } - - candidateString.Set(pCandidateString, candidateLen); - - BOOL fMakePhraseFromText = _pCompositionProcessorEngine->IsMakePhraseFromText(); - if (fMakePhraseFromText) // NOTICE: always no - { - _pCompositionProcessorEngine->GetCandidateStringInConverted(candidateString, &candidatePhraseList); - LCID locale = _pCompositionProcessorEngine->GetLocale(); - - _pCandidateListUIPresenter->RemoveSpecificCandidateFromList(locale, candidatePhraseList, candidateString); - } - - // We have a candidate list if candidatePhraseList.Cnt is not 0 - // If we are showing reverse conversion, use CCandidateListUIPresenter - CANDIDATE_MODE tempCandMode = CANDIDATE_NONE; - CCandidateListUIPresenter *pTempCandListUIPresenter = nullptr; - if (candidatePhraseList.Count()) // NOTICE: always 0 - { - tempCandMode = CANDIDATE_WITH_NEXT_COMPOSITION; - - pTempCandListUIPresenter = new (std::nothrow) - CCandidateListUIPresenter(this, Global::AtomCandidateWindow, CATEGORY_CANDIDATE, - _pCompositionProcessorEngine->GetCandidateListIndexRange(), FALSE); - if (nullptr == pTempCandListUIPresenter) - { - hrReturn = E_OUTOFMEMORY; - goto Exit; - } - } - - // call _Start*Line for CCandidateListUIPresenter or CReadingLine - // we don't cache the document manager object so get it from pContext. - ITfDocumentMgr *pDocumentMgr = nullptr; - HRESULT hrStartCandidateList = E_FAIL; - if (pContext->GetDocumentMgr(&pDocumentMgr) == S_OK) - { - ITfRange *pRange = nullptr; - if (_pComposition->GetRange(&pRange) == S_OK) - { - if (pTempCandListUIPresenter) - { - hrStartCandidateList = pTempCandListUIPresenter->_StartCandidateList( - _tfClientId, pDocumentMgr, pContext, ec, pRange, - _pCompositionProcessorEngine->GetCandidateWindowWidth()); - } - - pRange->Release(); - } - pDocumentMgr->Release(); - } - - // set up candidate list if it is being shown - if (SUCCEEDED(hrStartCandidateList)) - { - pTempCandListUIPresenter->_SetTextColor(RGB(0, 0x80, 0), GetSysColor(COLOR_WINDOW)); // Text color is green - pTempCandListUIPresenter->_SetFillColor((HBRUSH)(COLOR_WINDOW + 1)); // Background color is window - pTempCandListUIPresenter->_SetText(&candidatePhraseList, FALSE); - -#ifdef FANY_DEBUG - OutputDebugString(fmt::format(L"Fany here candidateString = {}", candidateString.Get()).c_str()); -#endif - // Add composing character - hrReturn = _AddComposingAndChar(ec, pContext, &candidateString); - - // close candidate list - if (_pCandidateListUIPresenter) - { - _pCandidateListUIPresenter->_EndCandidateList(); - delete _pCandidateListUIPresenter; - _pCandidateListUIPresenter = nullptr; - - _candidateMode = CANDIDATE_NONE; - _isCandidateWithWildcard = FALSE; - } - - if (hrReturn == S_OK) - { - // copy temp candidate - _pCandidateListUIPresenter = pTempCandListUIPresenter; - - _candidateMode = tempCandMode; - _isCandidateWithWildcard = FALSE; - } - } - else - { - // When VK_SPACE, number(for selecting candidate) comes here - hrReturn = _HandleCandidateFinalize(ec, pContext); - } - - if (pbstr) - { - SysFreeString(pbstr); - } - -Exit: - return hrReturn; -} - -//+--------------------------------------------------------------------------- -// -// _HandleCandidateArrowKey -// -//---------------------------------------------------------------------------- - -HRESULT CSampleIME::_HandleCandidateArrowKey(TfEditCookie ec, _In_ ITfContext *pContext, - _In_ KEYSTROKE_FUNCTION keyFunction) -{ - ec; - pContext; - - _pCandidateListUIPresenter->AdviseUIChangedByArrowKey(keyFunction); - - return S_OK; -} - -//+--------------------------------------------------------------------------- -// -// _HandleCandidateSelectByNumber -// -//---------------------------------------------------------------------------- - -HRESULT CSampleIME::_HandleCandidateSelectByNumber(TfEditCookie ec, _In_ ITfContext *pContext, _In_ UINT uCode) -{ - int iSelectAsNumber = _pCompositionProcessorEngine->GetCandidateListIndexRange()->GetIndex(uCode); - if (iSelectAsNumber == -1) - { - return S_FALSE; - } - - if (_pCandidateListUIPresenter) - { - if (_pCandidateListUIPresenter->_SetSelectionInPage(iSelectAsNumber)) - { - return _HandleCandidateConvert(ec, pContext); - } - } - - return S_FALSE; -} - -//+--------------------------------------------------------------------------- -// -// _HandlePhraseFinalize -// -//---------------------------------------------------------------------------- - -HRESULT CSampleIME::_HandlePhraseFinalize(TfEditCookie ec, _In_ ITfContext *pContext) -{ - HRESULT hr = S_OK; - - DWORD phraseLen = 0; - const WCHAR *pPhraseString = nullptr; - - phraseLen = (DWORD)_pCandidateListUIPresenter->_GetSelectedCandidateString(&pPhraseString); - - CStringRange phraseString; - phraseString.Set(pPhraseString, phraseLen); - - if (phraseLen) - { - if ((hr = _AddCharAndFinalize(ec, pContext, &phraseString)) != S_OK) - { - return hr; - } - } - - _HandleComplete(ec, pContext); - - return S_OK; -} - -//+--------------------------------------------------------------------------- -// -// _HandlePhraseArrowKey -// -//---------------------------------------------------------------------------- - -HRESULT CSampleIME::_HandlePhraseArrowKey(TfEditCookie ec, _In_ ITfContext *pContext, - _In_ KEYSTROKE_FUNCTION keyFunction) -{ - ec; - pContext; - - _pCandidateListUIPresenter->AdviseUIChangedByArrowKey(keyFunction); - - return S_OK; -} - -//+--------------------------------------------------------------------------- -// -// _HandlePhraseSelectByNumber -// -//---------------------------------------------------------------------------- - -HRESULT CSampleIME::_HandlePhraseSelectByNumber(TfEditCookie ec, _In_ ITfContext *pContext, _In_ UINT uCode) -{ - // isSelectAsNumber starts from 0 - int iSelectAsNumber = _pCompositionProcessorEngine->GetCandidateListIndexRange()->GetIndex(uCode); - if (iSelectAsNumber == -1) - { - return S_FALSE; - } - - if (_pCandidateListUIPresenter) - { - if (_pCandidateListUIPresenter->_SetSelectionInPage(iSelectAsNumber)) - { - return _HandlePhraseFinalize(ec, pContext); - } - } - - return S_FALSE; -} - -////////////////////////////////////////////////////////////////////// -// -// CCandidateListUIPresenter class -// -////////////////////////////////////////////////////////////////////// - -//+--------------------------------------------------------------------------- -// -// ctor -// -//---------------------------------------------------------------------------- - -CCandidateListUIPresenter::CCandidateListUIPresenter(_In_ CSampleIME *pTextService, ATOM atom, - KEYSTROKE_CATEGORY Category, _In_ CCandidateRange *pIndexRange, - BOOL hideWindow) - : CTfTextLayoutSink(pTextService) -{ - _atom = atom; - - _pIndexRange = pIndexRange; - - _parentWndHandle = nullptr; - _pCandidateWnd = nullptr; - - _Category = Category; - - _updatedFlags = 0; - - _uiElementId = (DWORD)-1; - _isShowMode = TRUE; // store return value from BeginUIElement - _hideWindow = hideWindow; // Hide window flag from [Configuration] CandidateList.Phrase.HideWindow - - _pTextService = pTextService; - _pTextService->AddRef(); - - _refCount = 1; -} - -//+--------------------------------------------------------------------------- -// -// dtor -// -//---------------------------------------------------------------------------- - -CCandidateListUIPresenter::~CCandidateListUIPresenter() -{ - _EndCandidateList(); - _pTextService->Release(); -} - -//+--------------------------------------------------------------------------- -// -// ITfCandidateListUIElement::IUnknown::QueryInterface -// -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::QueryInterface(REFIID riid, _Outptr_ void **ppvObj) -{ - if (CTfTextLayoutSink::QueryInterface(riid, ppvObj) == S_OK) - { - return S_OK; - } - - if (ppvObj == nullptr) - { - return E_INVALIDARG; - } - - *ppvObj = nullptr; - - if (IsEqualIID(riid, IID_ITfUIElement) || IsEqualIID(riid, IID_ITfCandidateListUIElement)) - { - *ppvObj = (ITfCandidateListUIElement *)this; - } - else if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_ITfCandidateListUIElementBehavior)) - { - *ppvObj = (ITfCandidateListUIElementBehavior *)this; - } - else if (IsEqualIID(riid, __uuidof(ITfIntegratableCandidateListUIElement))) - { - *ppvObj = (ITfIntegratableCandidateListUIElement *)this; - } - - if (*ppvObj) - { - AddRef(); - return S_OK; - } - - return E_NOINTERFACE; -} - -//+--------------------------------------------------------------------------- -// -// ITfCandidateListUIElement::IUnknown::AddRef -// -//---------------------------------------------------------------------------- - -STDAPI_(ULONG) CCandidateListUIPresenter::AddRef() -{ - CTfTextLayoutSink::AddRef(); - return ++_refCount; -} - -//+--------------------------------------------------------------------------- -// -// ITfCandidateListUIElement::IUnknown::Release -// -//---------------------------------------------------------------------------- - -STDAPI_(ULONG) CCandidateListUIPresenter::Release() -{ - CTfTextLayoutSink::Release(); - - LONG cr = --_refCount; - - assert(_refCount >= 0); - - if (_refCount == 0) - { - delete this; - } - - return cr; -} - -//+--------------------------------------------------------------------------- -// -// ITfCandidateListUIElement::ITfUIElement::GetDescription -// -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::GetDescription(BSTR *pbstr) -{ - if (pbstr) - { - *pbstr = SysAllocString(L"Cand"); - } - return S_OK; -} - -//+--------------------------------------------------------------------------- -// -// ITfCandidateListUIElement::ITfUIElement::GetGUID -// -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::GetGUID(GUID *pguid) -{ - *pguid = Global::SampleIMEGuidCandUIElement; - return S_OK; -} - -//+--------------------------------------------------------------------------- -// -// ITfCandidateListUIElement::ITfUIElement::Show -// -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::Show(BOOL showCandidateWindow) -{ - if (showCandidateWindow) - { - ToShowCandidateWindow(); - } - else - { - ToHideCandidateWindow(); - } - return S_OK; -} - -HRESULT CCandidateListUIPresenter::ToShowCandidateWindow() -{ - if (_hideWindow) - { - _pCandidateWnd->_Show(FALSE); - } - else - { - _MoveWindowToTextExt(); - - _pCandidateWnd->_Show(TRUE); - } - - return S_OK; -} - -HRESULT CCandidateListUIPresenter::ToHideCandidateWindow() -{ - if (_pCandidateWnd) - { - _pCandidateWnd->_Show(FALSE); - } - - _updatedFlags = TF_CLUIE_SELECTION | TF_CLUIE_CURRENTPAGE; - _UpdateUIElement(); - - return S_OK; -} - -//+--------------------------------------------------------------------------- -// -// ITfCandidateListUIElement::ITfUIElement::IsShown -// -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::IsShown(BOOL *pIsShow) -{ - *pIsShow = _pCandidateWnd->_IsWindowVisible(); - return S_OK; -} - -//+--------------------------------------------------------------------------- -// -// ITfCandidateListUIElement::GetUpdatedFlags -// -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::GetUpdatedFlags(DWORD *pdwFlags) -{ - *pdwFlags = _updatedFlags; - return S_OK; -} - -//+--------------------------------------------------------------------------- -// -// ITfCandidateListUIElement::GetDocumentMgr -// -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::GetDocumentMgr(ITfDocumentMgr **ppdim) -{ - *ppdim = nullptr; - - return E_NOTIMPL; -} - -//+--------------------------------------------------------------------------- -// -// ITfCandidateListUIElement::GetCount -// -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::GetCount(UINT *pCandidateCount) -{ - if (_pCandidateWnd) - { - *pCandidateCount = _pCandidateWnd->_GetCount(); - } - else - { - *pCandidateCount = 0; - } - return S_OK; -} - -//+--------------------------------------------------------------------------- -// -// ITfCandidateListUIElement::GetSelection -// -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::GetSelection(UINT *pSelectedCandidateIndex) -{ - if (_pCandidateWnd) - { - *pSelectedCandidateIndex = _pCandidateWnd->_GetSelection(); - } - else - { - *pSelectedCandidateIndex = 0; - } - return S_OK; -} - -//+--------------------------------------------------------------------------- -// -// ITfCandidateListUIElement::GetString -// -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::GetString(UINT uIndex, BSTR *pbstr) -{ - if (!_pCandidateWnd || (uIndex > _pCandidateWnd->_GetCount())) - { - return E_FAIL; - } - - DWORD candidateLen = 0; - const WCHAR *pCandidateString = nullptr; - - candidateLen = _pCandidateWnd->_GetCandidateString(uIndex, &pCandidateString); - - *pbstr = (candidateLen == 0) ? nullptr : SysAllocStringLen(pCandidateString, candidateLen); - - return S_OK; -} - -//+--------------------------------------------------------------------------- -// -// ITfCandidateListUIElement::GetPageIndex -// -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::GetPageIndex(UINT *pIndex, UINT uSize, UINT *puPageCnt) -{ - if (!_pCandidateWnd) - { - if (pIndex) - { - *pIndex = 0; - } - *puPageCnt = 0; - return S_OK; - } - return _pCandidateWnd->_GetPageIndex(pIndex, uSize, puPageCnt); -} - -//+--------------------------------------------------------------------------- -// -// ITfCandidateListUIElement::SetPageIndex -// -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::SetPageIndex(UINT *pIndex, UINT uPageCnt) -{ - if (!_pCandidateWnd) - { - return E_FAIL; - } - return _pCandidateWnd->_SetPageIndex(pIndex, uPageCnt); -} - -//+--------------------------------------------------------------------------- -// -// ITfCandidateListUIElement::GetCurrentPage -// -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::GetCurrentPage(UINT *puPage) -{ - if (!_pCandidateWnd) - { - *puPage = 0; - return S_OK; - } - return _pCandidateWnd->_GetCurrentPage(puPage); -} - -//+--------------------------------------------------------------------------- -// -// ITfCandidateListUIElementBehavior::SetSelection -// It is related of the mouse clicking behavior upon the suggestion window -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::SetSelection(UINT nIndex) -{ - if (_pCandidateWnd) - { - _pCandidateWnd->_SetSelection(nIndex); - } - - return S_OK; -} - -//+--------------------------------------------------------------------------- -// -// ITfCandidateListUIElementBehavior::Finalize -// It is related of the mouse clicking behavior upon the suggestion window -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::Finalize(void) -{ - _CandidateChangeNotification(CAND_ITEM_SELECT); - return S_OK; -} - -//+--------------------------------------------------------------------------- -// -// ITfCandidateListUIElementBehavior::Abort -// -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::Abort(void) -{ - return E_NOTIMPL; -} - -//+--------------------------------------------------------------------------- -// -// ITfIntegratableCandidateListUIElement::SetIntegrationStyle -// To show candidateNumbers on the suggestion window -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::SetIntegrationStyle(GUID guidIntegrationStyle) -{ - return (guidIntegrationStyle == GUID_INTEGRATIONSTYLE_SEARCHBOX) ? S_OK : E_NOTIMPL; -} - -//+--------------------------------------------------------------------------- -// -// ITfIntegratableCandidateListUIElement::GetSelectionStyle -// -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::GetSelectionStyle(_Out_ TfIntegratableCandidateListSelectionStyle *ptfSelectionStyle) -{ - *ptfSelectionStyle = STYLE_ACTIVE_SELECTION; - return S_OK; -} - -//+--------------------------------------------------------------------------- -// -// ITfIntegratableCandidateListUIElement::OnKeyDown -// -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::OnKeyDown(_In_ WPARAM wParam, _In_ LPARAM lParam, _Out_ BOOL *pIsEaten) -{ - wParam; - lParam; - - *pIsEaten = TRUE; - return S_OK; -} - -//+--------------------------------------------------------------------------- -// -// ITfIntegratableCandidateListUIElement::ShowCandidateNumbers -// -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::ShowCandidateNumbers(_Out_ BOOL *pIsShow) -{ - *pIsShow = TRUE; - return S_OK; -} - -//+--------------------------------------------------------------------------- -// -// ITfIntegratableCandidateListUIElement::FinalizeExactCompositionString -// -//---------------------------------------------------------------------------- - -STDAPI CCandidateListUIPresenter::FinalizeExactCompositionString() -{ - return E_NOTIMPL; -} - -//+--------------------------------------------------------------------------- -// -// _StartCandidateList -// -//---------------------------------------------------------------------------- - -HRESULT CCandidateListUIPresenter::_StartCandidateList(TfClientId tfClientId, _In_ ITfDocumentMgr *pDocumentMgr, - _In_ ITfContext *pContextDocument, TfEditCookie ec, - _In_ ITfRange *pRangeComposition, UINT wndWidth) -{ - pDocumentMgr; - tfClientId; - - HRESULT hr = E_FAIL; - - if (FAILED(_StartLayout(pContextDocument, ec, pRangeComposition))) - { - goto Exit; - } - - BeginUIElement(); - - hr = MakeCandidateWindow(pContextDocument, wndWidth); - if (FAILED(hr)) - { - OutputDebugString(L"MakeCandidateWindow failed\n"); - // goto Exit; - } - - // Show(_isShowMode); - - RECT rcTextExt; - if (SUCCEEDED(_GetTextExt(&rcTextExt))) - { - Global::Point[0] = rcTextExt.left; - Global::Point[1] = rcTextExt.bottom; - _LayoutChangeNotification(&rcTextExt); - } - -Exit: - if (FAILED(hr)) - { - _EndCandidateList(); - } - return hr; -} - -//+--------------------------------------------------------------------------- -// -// _EndCandidateList -// -//---------------------------------------------------------------------------- - -void CCandidateListUIPresenter::_EndCandidateList() -{ - EndUIElement(); - - DisposeCandidateWindow(); - - _EndLayout(); -} - -void CCandidateListUIPresenter::_NotifyUI() -{ - CStringRange keyStringBuffer = _pTextService->GetCompositionProcessorEngine()->GetKeystrokeBuffer(); - std::wstring pinyinString(keyStringBuffer.Get(), keyStringBuffer.GetLength()); - Global::PinyinLength = pinyinString.length(); - WriteDataToSharedMemory( // - Global::Keycode, // - Global::ModifiersDown, // - Global::Point, // - Global::PinyinLength, // - Global::PinyinString, // - 0b11111 // - ); - SendShowCandidateWndEventToUIProcess(); - // SendKeyEventToUIProcess(); -} - -//+--------------------------------------------------------------------------- -// -// _SetText -// -//---------------------------------------------------------------------------- - -void CCandidateListUIPresenter::_SetText(_In_ CSampleImeArray *pCandidateList, - BOOL isAddFindKeyCode) -{ - AddCandidateToCandidateListUI(pCandidateList, isAddFindKeyCode); - - SetPageIndexWithScrollInfo(pCandidateList); - - if (_isShowMode) - { - // _pCandidateWnd->_InvalidateRect(); - _NotifyUI(); - } - else - { - _updatedFlags = - TF_CLUIE_COUNT | TF_CLUIE_SELECTION | TF_CLUIE_STRING | TF_CLUIE_PAGEINDEX | TF_CLUIE_CURRENTPAGE; - _UpdateUIElement(); - } -} - -void CCandidateListUIPresenter::AddCandidateToCandidateListUI(_In_ CSampleImeArray *pCandidateList, - BOOL isAddFindKeyCode) -{ - for (UINT index = 0; index < pCandidateList->Count(); index++) - { - _pCandidateWnd->_AddString(pCandidateList->GetAt(index), isAddFindKeyCode); - } -} - -void CCandidateListUIPresenter::SetPageIndexWithScrollInfo(_In_ CSampleImeArray *pCandidateList) -{ - UINT candCntInPage = _pIndexRange->Count(); - UINT bufferSize = pCandidateList->Count() / candCntInPage + 1; - UINT *puPageIndex = new (std::nothrow) UINT[bufferSize]; - if (puPageIndex != nullptr) - { - for (UINT i = 0; i < bufferSize; i++) - { - puPageIndex[i] = i * candCntInPage; - } - - _pCandidateWnd->_SetPageIndex(puPageIndex, bufferSize); - delete[] puPageIndex; - } - _pCandidateWnd->_SetScrollInfo(pCandidateList->Count(), - candCntInPage); // nMax:range of max, nPage:number of items in page -} -//+--------------------------------------------------------------------------- -// -// _ClearList -// -//---------------------------------------------------------------------------- - -void CCandidateListUIPresenter::_ClearList() -{ - _pCandidateWnd->_ClearList(); -} - -//+--------------------------------------------------------------------------- -// -// _SetTextColor -// _SetFillColor -// -//---------------------------------------------------------------------------- - -void CCandidateListUIPresenter::_SetTextColor(COLORREF crColor, COLORREF crBkColor) -{ - _pCandidateWnd->_SetTextColor(crColor, crBkColor); -} - -void CCandidateListUIPresenter::_SetFillColor(HBRUSH hBrush) -{ - _pCandidateWnd->_SetFillColor(hBrush); -} - -//+--------------------------------------------------------------------------- -// -// _GetSelectedCandidateString -// -//---------------------------------------------------------------------------- - -DWORD_PTR CCandidateListUIPresenter::_GetSelectedCandidateString( - _Outptr_result_maybenull_ const WCHAR **ppwchCandidateString) -{ - return _pCandidateWnd->_GetSelectedCandidateString(ppwchCandidateString); -} - -//+--------------------------------------------------------------------------- -// -// _MoveSelection -// -//---------------------------------------------------------------------------- - -BOOL CCandidateListUIPresenter::_MoveSelection(_In_ int offSet) -{ - BOOL ret = _pCandidateWnd->_MoveSelection(offSet, TRUE); - if (ret) - { - if (_isShowMode) - { - // _pCandidateWnd->_InvalidateRect(); - _NotifyUI(); - } - else - { - _updatedFlags = TF_CLUIE_SELECTION; - _UpdateUIElement(); - } - } - return ret; -} - -//+--------------------------------------------------------------------------- -// -// _SetSelection -// -//---------------------------------------------------------------------------- - -BOOL CCandidateListUIPresenter::_SetSelection(_In_ int selectedIndex) -{ - BOOL ret = _pCandidateWnd->_SetSelection(selectedIndex, TRUE); - if (ret) - { - if (_isShowMode) - { - } - else - { - _updatedFlags = TF_CLUIE_SELECTION | TF_CLUIE_CURRENTPAGE; - _UpdateUIElement(); - } - } - return ret; -} - -//+--------------------------------------------------------------------------- -// -// _MovePage -// -//---------------------------------------------------------------------------- - -BOOL CCandidateListUIPresenter::_MovePage(_In_ int offSet) -{ - BOOL ret = _pCandidateWnd->_MovePage(offSet, TRUE); - if (ret) - { - if (_isShowMode) - { - // _pCandidateWnd->_InvalidateRect(); - _NotifyUI(); - } - else - { - _updatedFlags = TF_CLUIE_SELECTION | TF_CLUIE_CURRENTPAGE; - _UpdateUIElement(); - } - } - return ret; -} - -//+--------------------------------------------------------------------------- -// -// _MoveWindowToTextExt -// -//---------------------------------------------------------------------------- - -void CCandidateListUIPresenter::_MoveWindowToTextExt() -{ - RECT rc; - - if (FAILED(_GetTextExt(&rc))) - { - return; - } - - _pCandidateWnd->_Move(rc.left, rc.bottom); -} -//+--------------------------------------------------------------------------- -// -// _LayoutChangeNotification -// -//---------------------------------------------------------------------------- - -VOID CCandidateListUIPresenter::_LayoutChangeNotification(_In_ RECT *lpRect) -{ - // OutputDebugString(L"LayoutChangeNotification\n"); -#ifdef FANY_DEBUG - // TODO: Log _LayoutChangeNotification firefox cnt: Global::firefox_like_cnt -#endif - WriteDataToSharedMemory(Global::Keycode, 0, Global::Point, Global::PinyinLength, Global::PinyinString, 0b00100); - SendMoveCandidateWndEventToUIProcess(); -} - -//+--------------------------------------------------------------------------- -// -// _LayoutDestroyNotification -// -//---------------------------------------------------------------------------- - -VOID CCandidateListUIPresenter::_LayoutDestroyNotification() -{ - _EndCandidateList(); -} - -//+--------------------------------------------------------------------------- -// -// _CandidateChangeNotifiction -// -//---------------------------------------------------------------------------- - -HRESULT CCandidateListUIPresenter::_CandidateChangeNotification(_In_ enum CANDWND_ACTION action) -{ - HRESULT hr = E_FAIL; - - TfClientId tfClientId = _pTextService->_GetClientId(); - ITfThreadMgr *pThreadMgr = nullptr; - ITfDocumentMgr *pDocumentMgr = nullptr; - ITfContext *pContext = nullptr; - - _KEYSTROKE_STATE KeyState; - KeyState.Category = _Category; - KeyState.Function = FUNCTION_FINALIZE_CANDIDATELIST; - - if (CAND_ITEM_SELECT != action) - { - goto Exit; - } - - pThreadMgr = _pTextService->_GetThreadMgr(); - if (nullptr == pThreadMgr) - { - goto Exit; - } - - hr = pThreadMgr->GetFocus(&pDocumentMgr); - if (FAILED(hr)) - { - goto Exit; - } - - hr = pDocumentMgr->GetTop(&pContext); - if (FAILED(hr)) - { - pDocumentMgr->Release(); - goto Exit; - } - - CKeyHandlerEditSession *pEditSession = - new (std::nothrow) CKeyHandlerEditSession(_pTextService, pContext, 0, 0, KeyState); - if (nullptr != pEditSession) - { - HRESULT hrSession = S_OK; - hr = pContext->RequestEditSession(tfClientId, pEditSession, TF_ES_SYNC | TF_ES_READWRITE, &hrSession); - if (hrSession == TF_E_SYNCHRONOUS || hrSession == TS_E_READONLY) - { - hr = pContext->RequestEditSession(tfClientId, pEditSession, TF_ES_ASYNC | TF_ES_READWRITE, &hrSession); - } - pEditSession->Release(); - } - - pContext->Release(); - pDocumentMgr->Release(); - -Exit: - return hr; -} - -//+--------------------------------------------------------------------------- -// -// _CandWndCallback -// -//---------------------------------------------------------------------------- - -// static -HRESULT CCandidateListUIPresenter::_CandWndCallback(_In_ void *pv, _In_ enum CANDWND_ACTION action) -{ - CCandidateListUIPresenter *fakeThis = (CCandidateListUIPresenter *)pv; - - return fakeThis->_CandidateChangeNotification(action); -} - -//+--------------------------------------------------------------------------- -// -// _UpdateUIElement -// -//---------------------------------------------------------------------------- - -HRESULT CCandidateListUIPresenter::_UpdateUIElement() -{ - HRESULT hr = S_OK; - - ITfThreadMgr *pThreadMgr = _pTextService->_GetThreadMgr(); - if (nullptr == pThreadMgr) - { - return S_OK; - } - - ITfUIElementMgr *pUIElementMgr = nullptr; - - hr = pThreadMgr->QueryInterface(IID_ITfUIElementMgr, (void **)&pUIElementMgr); - if (hr == S_OK) - { - pUIElementMgr->UpdateUIElement(_uiElementId); - pUIElementMgr->Release(); - } - - return S_OK; -} - -//+--------------------------------------------------------------------------- -// -// OnSetThreadFocus -// -//---------------------------------------------------------------------------- - -HRESULT CCandidateListUIPresenter::OnSetThreadFocus() -{ - if (_isShowMode) - { - Show(TRUE); - } - return S_OK; -} - -//+--------------------------------------------------------------------------- -// -// OnKillThreadFocus -// -//---------------------------------------------------------------------------- - -HRESULT CCandidateListUIPresenter::OnKillThreadFocus() -{ - if (_isShowMode) - { - Show(FALSE); - } - return S_OK; -} - -void CCandidateListUIPresenter::RemoveSpecificCandidateFromList( - _In_ LCID Locale, _Inout_ CSampleImeArray &candidateList, _In_ CStringRange &candidateString) -{ - for (UINT index = 0; index < candidateList.Count();) - { - CCandidateListItem *pLI = candidateList.GetAt(index); - - if (CStringRange::Compare(Locale, &candidateString, &pLI->_ItemString) == CSTR_EQUAL) - { - candidateList.RemoveAt(index); - continue; - } - - index++; - } -} - -void CCandidateListUIPresenter::AdviseUIChangedByArrowKey(_In_ KEYSTROKE_FUNCTION arrowKey) -{ - switch (arrowKey) - { - case FUNCTION_MOVE_UP: { - _MoveSelection(MOVEUP_ONE); - break; - } - case FUNCTION_MOVE_DOWN: { - _MoveSelection(MOVEDOWN_ONE); - break; - } - case FUNCTION_MOVE_PAGE_UP: { - // Page prev - WriteDataToSharedMemory(Global::Keycode, Global::ModifiersDown, nullptr, 0, L"", 0b00011); - // SendKeyEventToUIProcess(); -#ifdef FANY_DEBUG - OutputDebugString(fmt::format(L"Page up, prev, modifiers: {}", Global::ModifiersDown).c_str()); -#endif - _MovePage(MOVEUP_ONE); - break; - } - case FUNCTION_MOVE_PAGE_DOWN: { - // Page next - WriteDataToSharedMemory(Global::Keycode, 0, nullptr, 0, L"", 0b00001); - // SendKeyEventToUIProcess(); -#ifdef FANY_DEBUG - OutputDebugString(L"Page down, next\n"); -#endif - _MovePage(MOVEDOWN_ONE); - break; - } - case FUNCTION_MOVE_PAGE_TOP: { - _SetSelection(MOVETO_TOP); - break; - } - case FUNCTION_MOVE_PAGE_BOTTOM: { - _SetSelection(MOVETO_BOTTOM); - break; - } - default: - break; - } -} - -HRESULT CCandidateListUIPresenter::BeginUIElement() -{ - HRESULT hr = S_OK; - - ITfThreadMgr *pThreadMgr = _pTextService->_GetThreadMgr(); - if (nullptr == pThreadMgr) - { - hr = E_FAIL; - goto Exit; - } - - ITfUIElementMgr *pUIElementMgr = nullptr; - hr = pThreadMgr->QueryInterface(IID_ITfUIElementMgr, (void **)&pUIElementMgr); - if (hr == S_OK) - { - pUIElementMgr->BeginUIElement(this, &_isShowMode, &_uiElementId); - pUIElementMgr->Release(); - } - -Exit: - return hr; -} - -HRESULT CCandidateListUIPresenter::EndUIElement() -{ - HRESULT hr = S_OK; - - ITfThreadMgr *pThreadMgr = _pTextService->_GetThreadMgr(); - if ((nullptr == pThreadMgr) || (-1 == _uiElementId)) - { - hr = E_FAIL; - goto Exit; - } - - ITfUIElementMgr *pUIElementMgr = nullptr; - hr = pThreadMgr->QueryInterface(IID_ITfUIElementMgr, (void **)&pUIElementMgr); - if (hr == S_OK) - { - pUIElementMgr->EndUIElement(_uiElementId); - pUIElementMgr->Release(); - } - -Exit: - return hr; -} - -//+--------------------------------------------------------------------------- -// MakeCandidateWindow -// -// Create the candidate window -//---------------------------------------------------------------------------- - -HRESULT CCandidateListUIPresenter::MakeCandidateWindow(_In_ ITfContext *pContextDocument, _In_ UINT wndWidth) -{ - HRESULT hr = S_OK; - - if (nullptr != _pCandidateWnd) - { - return hr; - } - - _pCandidateWnd = new (std::nothrow) - CCandidateWindow(_CandWndCallback, this, _pIndexRange, _pTextService->_IsStoreAppMode(), _pTextService); - - if (_pCandidateWnd == nullptr) - { - hr = E_OUTOFMEMORY; - goto Exit; - } - - HWND parentWndHandle = nullptr; - ITfContextView *pView = nullptr; - if (SUCCEEDED(pContextDocument->GetActiveView(&pView))) - { - // pView->GetWnd(&parentWndHandle); - if (FAILED(pView->GetWnd(&parentWndHandle)) || (parentWndHandle == nullptr)) - { - parentWndHandle = GetFocus(); - } - } - - if (!_pCandidateWnd->_Create(_atom, wndWidth, parentWndHandle)) - { - hr = E_OUTOFMEMORY; - goto Exit; - } - -Exit: - return hr; -} - -void CCandidateListUIPresenter::DisposeCandidateWindow() -{ - if (nullptr == _pCandidateWnd) - { - return; - } - - // - // Hide the global candidate window - // - // ShowWindow(Global::MainWindowHandle, SW_HIDE); - // HWND UIHwnd = FindWindow(L"global_candidate_window", NULL); - // UINT WM_HIDE_MAIN_WINDOW = RegisterWindowMessage(L"WM_HIDE_MAIN_WINDOW"); - SendHideCandidateWndEventToUIProcess(); - - _pCandidateWnd->_Destroy(); - - delete _pCandidateWnd; - _pCandidateWnd = nullptr; -} +#include "Globals.h" +#include "Private.h" +#include "MetasequoiaIME.h" +#include "CandidateWindow.h" +#include "CandidateListUIPresenter.h" +#include "CompositionProcessorEngine.h" +#include "MetasequoiaIMEBaseStructure.h" +#include "define.h" +#include +#include +#include +#include +#include "Ipc.h" +#include "fmt/xchar.h" + +////////////////////////////////////////////////////////////////////// +// +// CMetasequoiaIME candidate key handler methods +// +////////////////////////////////////////////////////////////////////// + +const int MOVEUP_ONE = -1; +const int MOVEDOWN_ONE = 1; +const int MOVETO_TOP = 0; +const int MOVETO_BOTTOM = -1; + +//+--------------------------------------------------------------------------- +// +// _HandleCandidateFinalize +// +//---------------------------------------------------------------------------- + +HRESULT CMetasequoiaIME::_HandleCandidateFinalize(TfEditCookie ec, _In_ ITfContext *pContext) +{ + HRESULT hr = S_OK; + + CStringRange keyStrokebuffer = _pCompositionProcessorEngine->GetKeystrokeBuffer(); + DWORD_PTR keystrokeBufLen = keyStrokebuffer.GetLength(); + DWORD_PTR candidateLen = keystrokeBufLen; + CStringRange candidateString(keyStrokebuffer); + + // _pCandidateListUIPresenter would be null in uwp/metro apps + if (nullptr == _pCandidateListUIPresenter) + { + // goto NoPresenter; + } + + if (candidateLen) + { + if (Global::Keycode == VK_SPACE || (Global::Keycode > '0' && Global::Keycode < '9')) + { + WriteDataToSharedMemory(Global::Keycode, 0, nullptr, 0, L"", 0b00001); + // SendKeyEventToUIProcess(); + } + std::wstring receivedData = ReadDataFromServerViaNamedPipe(); + candidateString.Set(receivedData.c_str(), receivedData.length()); + hr = _AddComposingAndChar(ec, pContext, &candidateString); + if (FAILED(hr)) + { + return hr; + } + } + +NoPresenter: + + _HandleComplete(ec, pContext); + + return hr; +} + +//+--------------------------------------------------------------------------- +// +// _HandleCandidateFinalizeForVKReturn +// +//---------------------------------------------------------------------------- + +HRESULT CMetasequoiaIME::_HandleCandidateFinalizeForVKReturn(TfEditCookie ec, _In_ ITfContext *pContext) +{ + HRESULT hr = S_OK; + + CStringRange keyStrokebuffer = _pCompositionProcessorEngine->GetKeystrokeBuffer(); + DWORD_PTR keystrokeBufLen = keyStrokebuffer.GetLength(); + DWORD_PTR candidateLen = keystrokeBufLen; + CStringRange candidateString(keyStrokebuffer); + + if (nullptr == _pCandidateListUIPresenter) + { + // goto NoPresenter; + } + +#ifdef FANY_DEBUG + std::wstring msg(candidateString.Get(), candidateLen); + OutputDebugString(msg.c_str()); +#endif + + if (candidateLen) + { + hr = _AddComposingAndChar(ec, pContext, &candidateString); + + if (FAILED(hr)) + { + return hr; + } + } + +NoPresenter: + + _HandleComplete(ec, pContext); + + return hr; +} + +//+--------------------------------------------------------------------------- +// +// _HandleCandidateConvert +// +//---------------------------------------------------------------------------- + +HRESULT CMetasequoiaIME::_HandleCandidateConvert(TfEditCookie ec, _In_ ITfContext *pContext) +{ + return _HandleCandidateWorker(ec, pContext); +} + +//+--------------------------------------------------------------------------- +// +// _HandleCandidateWorker +// +//---------------------------------------------------------------------------- + +HRESULT CMetasequoiaIME::_HandleCandidateWorker(TfEditCookie ec, _In_ ITfContext *pContext) +{ + HRESULT hrReturn = E_FAIL; + DWORD_PTR candidateLen = 0; + const WCHAR *pCandidateString = nullptr; + BSTR pbstr = nullptr; + CStringRange candidateString; + CMetasequoiaImeArray candidatePhraseList; + + if (nullptr == _pCandidateListUIPresenter) + { + hrReturn = S_OK; + goto Exit; + } + + candidateLen = _pCandidateListUIPresenter->_GetSelectedCandidateString(&pCandidateString); + if (0 == candidateLen) + { + hrReturn = S_FALSE; + goto Exit; + } + + candidateString.Set(pCandidateString, candidateLen); + + BOOL fMakePhraseFromText = _pCompositionProcessorEngine->IsMakePhraseFromText(); + if (fMakePhraseFromText) // NOTICE: always no + { + _pCompositionProcessorEngine->GetCandidateStringInConverted(candidateString, &candidatePhraseList); + LCID locale = _pCompositionProcessorEngine->GetLocale(); + + _pCandidateListUIPresenter->RemoveSpecificCandidateFromList(locale, candidatePhraseList, candidateString); + } + + // We have a candidate list if candidatePhraseList.Cnt is not 0 + // If we are showing reverse conversion, use CCandidateListUIPresenter + CANDIDATE_MODE tempCandMode = CANDIDATE_NONE; + CCandidateListUIPresenter *pTempCandListUIPresenter = nullptr; + if (candidatePhraseList.Count()) // NOTICE: always 0 + { + tempCandMode = CANDIDATE_WITH_NEXT_COMPOSITION; + + pTempCandListUIPresenter = new (std::nothrow) + CCandidateListUIPresenter(this, Global::AtomCandidateWindow, CATEGORY_CANDIDATE, + _pCompositionProcessorEngine->GetCandidateListIndexRange(), FALSE); + if (nullptr == pTempCandListUIPresenter) + { + hrReturn = E_OUTOFMEMORY; + goto Exit; + } + } + + // call _Start*Line for CCandidateListUIPresenter or CReadingLine + // we don't cache the document manager object so get it from pContext. + ITfDocumentMgr *pDocumentMgr = nullptr; + HRESULT hrStartCandidateList = E_FAIL; + if (pContext->GetDocumentMgr(&pDocumentMgr) == S_OK) + { + ITfRange *pRange = nullptr; + if (_pComposition->GetRange(&pRange) == S_OK) + { + if (pTempCandListUIPresenter) + { + hrStartCandidateList = pTempCandListUIPresenter->_StartCandidateList( + _tfClientId, pDocumentMgr, pContext, ec, pRange, + _pCompositionProcessorEngine->GetCandidateWindowWidth()); + } + + pRange->Release(); + } + pDocumentMgr->Release(); + } + + // set up candidate list if it is being shown + if (SUCCEEDED(hrStartCandidateList)) + { + pTempCandListUIPresenter->_SetTextColor(RGB(0, 0x80, 0), GetSysColor(COLOR_WINDOW)); // Text color is green + pTempCandListUIPresenter->_SetFillColor((HBRUSH)(COLOR_WINDOW + 1)); // Background color is window + pTempCandListUIPresenter->_SetText(&candidatePhraseList, FALSE); + +#ifdef FANY_DEBUG + OutputDebugString(fmt::format(L"Fany here candidateString = {}", candidateString.Get()).c_str()); +#endif + // Add composing character + hrReturn = _AddComposingAndChar(ec, pContext, &candidateString); + + // close candidate list + if (_pCandidateListUIPresenter) + { + _pCandidateListUIPresenter->_EndCandidateList(); + delete _pCandidateListUIPresenter; + _pCandidateListUIPresenter = nullptr; + + _candidateMode = CANDIDATE_NONE; + _isCandidateWithWildcard = FALSE; + } + + if (hrReturn == S_OK) + { + // copy temp candidate + _pCandidateListUIPresenter = pTempCandListUIPresenter; + + _candidateMode = tempCandMode; + _isCandidateWithWildcard = FALSE; + } + } + else + { + // When VK_SPACE, number(for selecting candidate) comes here + hrReturn = _HandleCandidateFinalize(ec, pContext); + } + + if (pbstr) + { + SysFreeString(pbstr); + } + +Exit: + return hrReturn; +} + +//+--------------------------------------------------------------------------- +// +// _HandleCandidateArrowKey +// +//---------------------------------------------------------------------------- + +HRESULT CMetasequoiaIME::_HandleCandidateArrowKey(TfEditCookie ec, _In_ ITfContext *pContext, + _In_ KEYSTROKE_FUNCTION keyFunction) +{ + ec; + pContext; + + _pCandidateListUIPresenter->AdviseUIChangedByArrowKey(keyFunction); + + return S_OK; +} + +//+--------------------------------------------------------------------------- +// +// _HandleCandidateSelectByNumber +// +//---------------------------------------------------------------------------- + +HRESULT CMetasequoiaIME::_HandleCandidateSelectByNumber(TfEditCookie ec, _In_ ITfContext *pContext, _In_ UINT uCode) +{ + int iSelectAsNumber = _pCompositionProcessorEngine->GetCandidateListIndexRange()->GetIndex(uCode); + if (iSelectAsNumber == -1) + { + return S_FALSE; + } + + if (_pCandidateListUIPresenter) + { + if (_pCandidateListUIPresenter->_SetSelectionInPage(iSelectAsNumber)) + { + return _HandleCandidateConvert(ec, pContext); + } + } + + return S_FALSE; +} + +//+--------------------------------------------------------------------------- +// +// _HandlePhraseFinalize +// +//---------------------------------------------------------------------------- + +HRESULT CMetasequoiaIME::_HandlePhraseFinalize(TfEditCookie ec, _In_ ITfContext *pContext) +{ + HRESULT hr = S_OK; + + DWORD phraseLen = 0; + const WCHAR *pPhraseString = nullptr; + + phraseLen = (DWORD)_pCandidateListUIPresenter->_GetSelectedCandidateString(&pPhraseString); + + CStringRange phraseString; + phraseString.Set(pPhraseString, phraseLen); + + if (phraseLen) + { + if ((hr = _AddCharAndFinalize(ec, pContext, &phraseString)) != S_OK) + { + return hr; + } + } + + _HandleComplete(ec, pContext); + + return S_OK; +} + +//+--------------------------------------------------------------------------- +// +// _HandlePhraseArrowKey +// +//---------------------------------------------------------------------------- + +HRESULT CMetasequoiaIME::_HandlePhraseArrowKey(TfEditCookie ec, _In_ ITfContext *pContext, + _In_ KEYSTROKE_FUNCTION keyFunction) +{ + ec; + pContext; + + _pCandidateListUIPresenter->AdviseUIChangedByArrowKey(keyFunction); + + return S_OK; +} + +//+--------------------------------------------------------------------------- +// +// _HandlePhraseSelectByNumber +// +//---------------------------------------------------------------------------- + +HRESULT CMetasequoiaIME::_HandlePhraseSelectByNumber(TfEditCookie ec, _In_ ITfContext *pContext, _In_ UINT uCode) +{ + // isSelectAsNumber starts from 0 + int iSelectAsNumber = _pCompositionProcessorEngine->GetCandidateListIndexRange()->GetIndex(uCode); + if (iSelectAsNumber == -1) + { + return S_FALSE; + } + + if (_pCandidateListUIPresenter) + { + if (_pCandidateListUIPresenter->_SetSelectionInPage(iSelectAsNumber)) + { + return _HandlePhraseFinalize(ec, pContext); + } + } + + return S_FALSE; +} + +////////////////////////////////////////////////////////////////////// +// +// CCandidateListUIPresenter class +// +////////////////////////////////////////////////////////////////////// + +//+--------------------------------------------------------------------------- +// +// ctor +// +//---------------------------------------------------------------------------- + +CCandidateListUIPresenter::CCandidateListUIPresenter(_In_ CMetasequoiaIME *pTextService, ATOM atom, + KEYSTROKE_CATEGORY Category, _In_ CCandidateRange *pIndexRange, + BOOL hideWindow) + : CTfTextLayoutSink(pTextService) +{ + _atom = atom; + + _pIndexRange = pIndexRange; + + _parentWndHandle = nullptr; + _pCandidateWnd = nullptr; + + _Category = Category; + + _updatedFlags = 0; + + _uiElementId = (DWORD)-1; + _isShowMode = TRUE; // store return value from BeginUIElement + _hideWindow = hideWindow; // Hide window flag from [Configuration] CandidateList.Phrase.HideWindow + + _pTextService = pTextService; + _pTextService->AddRef(); + + _refCount = 1; +} + +//+--------------------------------------------------------------------------- +// +// dtor +// +//---------------------------------------------------------------------------- + +CCandidateListUIPresenter::~CCandidateListUIPresenter() +{ + _EndCandidateList(); + _pTextService->Release(); +} + +//+--------------------------------------------------------------------------- +// +// ITfCandidateListUIElement::IUnknown::QueryInterface +// +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::QueryInterface(REFIID riid, _Outptr_ void **ppvObj) +{ + if (CTfTextLayoutSink::QueryInterface(riid, ppvObj) == S_OK) + { + return S_OK; + } + + if (ppvObj == nullptr) + { + return E_INVALIDARG; + } + + *ppvObj = nullptr; + + if (IsEqualIID(riid, IID_ITfUIElement) || IsEqualIID(riid, IID_ITfCandidateListUIElement)) + { + *ppvObj = (ITfCandidateListUIElement *)this; + } + else if (IsEqualIID(riid, IID_IUnknown) || IsEqualIID(riid, IID_ITfCandidateListUIElementBehavior)) + { + *ppvObj = (ITfCandidateListUIElementBehavior *)this; + } + else if (IsEqualIID(riid, __uuidof(ITfIntegratableCandidateListUIElement))) + { + *ppvObj = (ITfIntegratableCandidateListUIElement *)this; + } + + if (*ppvObj) + { + AddRef(); + return S_OK; + } + + return E_NOINTERFACE; +} + +//+--------------------------------------------------------------------------- +// +// ITfCandidateListUIElement::IUnknown::AddRef +// +//---------------------------------------------------------------------------- + +STDAPI_(ULONG) CCandidateListUIPresenter::AddRef() +{ + CTfTextLayoutSink::AddRef(); + return ++_refCount; +} + +//+--------------------------------------------------------------------------- +// +// ITfCandidateListUIElement::IUnknown::Release +// +//---------------------------------------------------------------------------- + +STDAPI_(ULONG) CCandidateListUIPresenter::Release() +{ + CTfTextLayoutSink::Release(); + + LONG cr = --_refCount; + + assert(_refCount >= 0); + + if (_refCount == 0) + { + delete this; + } + + return cr; +} + +//+--------------------------------------------------------------------------- +// +// ITfCandidateListUIElement::ITfUIElement::GetDescription +// +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::GetDescription(BSTR *pbstr) +{ + if (pbstr) + { + *pbstr = SysAllocString(L"Cand"); + } + return S_OK; +} + +//+--------------------------------------------------------------------------- +// +// ITfCandidateListUIElement::ITfUIElement::GetGUID +// +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::GetGUID(GUID *pguid) +{ + *pguid = Global::MetasequoiaIMEGuidCandUIElement; + return S_OK; +} + +//+--------------------------------------------------------------------------- +// +// ITfCandidateListUIElement::ITfUIElement::Show +// +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::Show(BOOL showCandidateWindow) +{ + if (showCandidateWindow) + { + ToShowCandidateWindow(); + } + else + { + ToHideCandidateWindow(); + } + return S_OK; +} + +HRESULT CCandidateListUIPresenter::ToShowCandidateWindow() +{ + if (_hideWindow) + { + _pCandidateWnd->_Show(FALSE); + } + else + { + _MoveWindowToTextExt(); + + _pCandidateWnd->_Show(TRUE); + } + + return S_OK; +} + +HRESULT CCandidateListUIPresenter::ToHideCandidateWindow() +{ + if (_pCandidateWnd) + { + _pCandidateWnd->_Show(FALSE); + } + + _updatedFlags = TF_CLUIE_SELECTION | TF_CLUIE_CURRENTPAGE; + _UpdateUIElement(); + + return S_OK; +} + +//+--------------------------------------------------------------------------- +// +// ITfCandidateListUIElement::ITfUIElement::IsShown +// +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::IsShown(BOOL *pIsShow) +{ + *pIsShow = _pCandidateWnd->_IsWindowVisible(); + return S_OK; +} + +//+--------------------------------------------------------------------------- +// +// ITfCandidateListUIElement::GetUpdatedFlags +// +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::GetUpdatedFlags(DWORD *pdwFlags) +{ + *pdwFlags = _updatedFlags; + return S_OK; +} + +//+--------------------------------------------------------------------------- +// +// ITfCandidateListUIElement::GetDocumentMgr +// +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::GetDocumentMgr(ITfDocumentMgr **ppdim) +{ + *ppdim = nullptr; + + return E_NOTIMPL; +} + +//+--------------------------------------------------------------------------- +// +// ITfCandidateListUIElement::GetCount +// +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::GetCount(UINT *pCandidateCount) +{ + if (_pCandidateWnd) + { + *pCandidateCount = _pCandidateWnd->_GetCount(); + } + else + { + *pCandidateCount = 0; + } + return S_OK; +} + +//+--------------------------------------------------------------------------- +// +// ITfCandidateListUIElement::GetSelection +// +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::GetSelection(UINT *pSelectedCandidateIndex) +{ + if (_pCandidateWnd) + { + *pSelectedCandidateIndex = _pCandidateWnd->_GetSelection(); + } + else + { + *pSelectedCandidateIndex = 0; + } + return S_OK; +} + +//+--------------------------------------------------------------------------- +// +// ITfCandidateListUIElement::GetString +// +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::GetString(UINT uIndex, BSTR *pbstr) +{ + if (!_pCandidateWnd || (uIndex > _pCandidateWnd->_GetCount())) + { + return E_FAIL; + } + + DWORD candidateLen = 0; + const WCHAR *pCandidateString = nullptr; + + candidateLen = _pCandidateWnd->_GetCandidateString(uIndex, &pCandidateString); + + *pbstr = (candidateLen == 0) ? nullptr : SysAllocStringLen(pCandidateString, candidateLen); + + return S_OK; +} + +//+--------------------------------------------------------------------------- +// +// ITfCandidateListUIElement::GetPageIndex +// +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::GetPageIndex(UINT *pIndex, UINT uSize, UINT *puPageCnt) +{ + if (!_pCandidateWnd) + { + if (pIndex) + { + *pIndex = 0; + } + *puPageCnt = 0; + return S_OK; + } + return _pCandidateWnd->_GetPageIndex(pIndex, uSize, puPageCnt); +} + +//+--------------------------------------------------------------------------- +// +// ITfCandidateListUIElement::SetPageIndex +// +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::SetPageIndex(UINT *pIndex, UINT uPageCnt) +{ + if (!_pCandidateWnd) + { + return E_FAIL; + } + return _pCandidateWnd->_SetPageIndex(pIndex, uPageCnt); +} + +//+--------------------------------------------------------------------------- +// +// ITfCandidateListUIElement::GetCurrentPage +// +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::GetCurrentPage(UINT *puPage) +{ + if (!_pCandidateWnd) + { + *puPage = 0; + return S_OK; + } + return _pCandidateWnd->_GetCurrentPage(puPage); +} + +//+--------------------------------------------------------------------------- +// +// ITfCandidateListUIElementBehavior::SetSelection +// It is related of the mouse clicking behavior upon the suggestion window +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::SetSelection(UINT nIndex) +{ + if (_pCandidateWnd) + { + _pCandidateWnd->_SetSelection(nIndex); + } + + return S_OK; +} + +//+--------------------------------------------------------------------------- +// +// ITfCandidateListUIElementBehavior::Finalize +// It is related of the mouse clicking behavior upon the suggestion window +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::Finalize(void) +{ + _CandidateChangeNotification(CAND_ITEM_SELECT); + return S_OK; +} + +//+--------------------------------------------------------------------------- +// +// ITfCandidateListUIElementBehavior::Abort +// +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::Abort(void) +{ + return E_NOTIMPL; +} + +//+--------------------------------------------------------------------------- +// +// ITfIntegratableCandidateListUIElement::SetIntegrationStyle +// To show candidateNumbers on the suggestion window +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::SetIntegrationStyle(GUID guidIntegrationStyle) +{ + return (guidIntegrationStyle == GUID_INTEGRATIONSTYLE_SEARCHBOX) ? S_OK : E_NOTIMPL; +} + +//+--------------------------------------------------------------------------- +// +// ITfIntegratableCandidateListUIElement::GetSelectionStyle +// +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::GetSelectionStyle(_Out_ TfIntegratableCandidateListSelectionStyle *ptfSelectionStyle) +{ + *ptfSelectionStyle = STYLE_ACTIVE_SELECTION; + return S_OK; +} + +//+--------------------------------------------------------------------------- +// +// ITfIntegratableCandidateListUIElement::OnKeyDown +// +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::OnKeyDown(_In_ WPARAM wParam, _In_ LPARAM lParam, _Out_ BOOL *pIsEaten) +{ + wParam; + lParam; + + *pIsEaten = TRUE; + return S_OK; +} + +//+--------------------------------------------------------------------------- +// +// ITfIntegratableCandidateListUIElement::ShowCandidateNumbers +// +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::ShowCandidateNumbers(_Out_ BOOL *pIsShow) +{ + *pIsShow = TRUE; + return S_OK; +} + +//+--------------------------------------------------------------------------- +// +// ITfIntegratableCandidateListUIElement::FinalizeExactCompositionString +// +//---------------------------------------------------------------------------- + +STDAPI CCandidateListUIPresenter::FinalizeExactCompositionString() +{ + return E_NOTIMPL; +} + +//+--------------------------------------------------------------------------- +// +// _StartCandidateList +// +//---------------------------------------------------------------------------- + +HRESULT CCandidateListUIPresenter::_StartCandidateList(TfClientId tfClientId, _In_ ITfDocumentMgr *pDocumentMgr, + _In_ ITfContext *pContextDocument, TfEditCookie ec, + _In_ ITfRange *pRangeComposition, UINT wndWidth) +{ + pDocumentMgr; + tfClientId; + + HRESULT hr = E_FAIL; + + if (FAILED(_StartLayout(pContextDocument, ec, pRangeComposition))) + { + goto Exit; + } + + BeginUIElement(); + + hr = MakeCandidateWindow(pContextDocument, wndWidth); + if (FAILED(hr)) + { + OutputDebugString(L"MakeCandidateWindow failed\n"); + // goto Exit; + } + + // Show(_isShowMode); + + RECT rcTextExt; + if (SUCCEEDED(_GetTextExt(&rcTextExt))) + { + Global::Point[0] = rcTextExt.left; + Global::Point[1] = rcTextExt.bottom; + _LayoutChangeNotification(&rcTextExt); + } + +Exit: + if (FAILED(hr)) + { + _EndCandidateList(); + } + return hr; +} + +//+--------------------------------------------------------------------------- +// +// _EndCandidateList +// +//---------------------------------------------------------------------------- + +void CCandidateListUIPresenter::_EndCandidateList() +{ + EndUIElement(); + + DisposeCandidateWindow(); + + _EndLayout(); +} + +void CCandidateListUIPresenter::_NotifyUI() +{ + CStringRange keyStringBuffer = _pTextService->GetCompositionProcessorEngine()->GetKeystrokeBuffer(); + std::wstring pinyinString(keyStringBuffer.Get(), keyStringBuffer.GetLength()); + Global::PinyinLength = pinyinString.length(); + WriteDataToSharedMemory( // + Global::Keycode, // + Global::ModifiersDown, // + Global::Point, // + Global::PinyinLength, // + Global::PinyinString, // + 0b11111 // + ); + SendShowCandidateWndEventToUIProcess(); + // SendKeyEventToUIProcess(); +} + +//+--------------------------------------------------------------------------- +// +// _SetText +// +//---------------------------------------------------------------------------- + +void CCandidateListUIPresenter::_SetText(_In_ CMetasequoiaImeArray *pCandidateList, + BOOL isAddFindKeyCode) +{ + AddCandidateToCandidateListUI(pCandidateList, isAddFindKeyCode); + + SetPageIndexWithScrollInfo(pCandidateList); + + if (_isShowMode) + { + // _pCandidateWnd->_InvalidateRect(); + _NotifyUI(); + } + else + { + _updatedFlags = + TF_CLUIE_COUNT | TF_CLUIE_SELECTION | TF_CLUIE_STRING | TF_CLUIE_PAGEINDEX | TF_CLUIE_CURRENTPAGE; + _UpdateUIElement(); + } +} + +void CCandidateListUIPresenter::AddCandidateToCandidateListUI(_In_ CMetasequoiaImeArray *pCandidateList, + BOOL isAddFindKeyCode) +{ + for (UINT index = 0; index < pCandidateList->Count(); index++) + { + _pCandidateWnd->_AddString(pCandidateList->GetAt(index), isAddFindKeyCode); + } +} + +void CCandidateListUIPresenter::SetPageIndexWithScrollInfo(_In_ CMetasequoiaImeArray *pCandidateList) +{ + UINT candCntInPage = _pIndexRange->Count(); + UINT bufferSize = pCandidateList->Count() / candCntInPage + 1; + UINT *puPageIndex = new (std::nothrow) UINT[bufferSize]; + if (puPageIndex != nullptr) + { + for (UINT i = 0; i < bufferSize; i++) + { + puPageIndex[i] = i * candCntInPage; + } + + _pCandidateWnd->_SetPageIndex(puPageIndex, bufferSize); + delete[] puPageIndex; + } + _pCandidateWnd->_SetScrollInfo(pCandidateList->Count(), + candCntInPage); // nMax:range of max, nPage:number of items in page +} +//+--------------------------------------------------------------------------- +// +// _ClearList +// +//---------------------------------------------------------------------------- + +void CCandidateListUIPresenter::_ClearList() +{ + _pCandidateWnd->_ClearList(); +} + +//+--------------------------------------------------------------------------- +// +// _SetTextColor +// _SetFillColor +// +//---------------------------------------------------------------------------- + +void CCandidateListUIPresenter::_SetTextColor(COLORREF crColor, COLORREF crBkColor) +{ + _pCandidateWnd->_SetTextColor(crColor, crBkColor); +} + +void CCandidateListUIPresenter::_SetFillColor(HBRUSH hBrush) +{ + _pCandidateWnd->_SetFillColor(hBrush); +} + +//+--------------------------------------------------------------------------- +// +// _GetSelectedCandidateString +// +//---------------------------------------------------------------------------- + +DWORD_PTR CCandidateListUIPresenter::_GetSelectedCandidateString( + _Outptr_result_maybenull_ const WCHAR **ppwchCandidateString) +{ + return _pCandidateWnd->_GetSelectedCandidateString(ppwchCandidateString); +} + +//+--------------------------------------------------------------------------- +// +// _MoveSelection +// +//---------------------------------------------------------------------------- + +BOOL CCandidateListUIPresenter::_MoveSelection(_In_ int offSet) +{ + BOOL ret = _pCandidateWnd->_MoveSelection(offSet, TRUE); + if (ret) + { + if (_isShowMode) + { + // _pCandidateWnd->_InvalidateRect(); + _NotifyUI(); + } + else + { + _updatedFlags = TF_CLUIE_SELECTION; + _UpdateUIElement(); + } + } + return ret; +} + +//+--------------------------------------------------------------------------- +// +// _SetSelection +// +//---------------------------------------------------------------------------- + +BOOL CCandidateListUIPresenter::_SetSelection(_In_ int selectedIndex) +{ + BOOL ret = _pCandidateWnd->_SetSelection(selectedIndex, TRUE); + if (ret) + { + if (_isShowMode) + { + } + else + { + _updatedFlags = TF_CLUIE_SELECTION | TF_CLUIE_CURRENTPAGE; + _UpdateUIElement(); + } + } + return ret; +} + +//+--------------------------------------------------------------------------- +// +// _MovePage +// +//---------------------------------------------------------------------------- + +BOOL CCandidateListUIPresenter::_MovePage(_In_ int offSet) +{ + BOOL ret = _pCandidateWnd->_MovePage(offSet, TRUE); + if (ret) + { + if (_isShowMode) + { + // _pCandidateWnd->_InvalidateRect(); + _NotifyUI(); + } + else + { + _updatedFlags = TF_CLUIE_SELECTION | TF_CLUIE_CURRENTPAGE; + _UpdateUIElement(); + } + } + return ret; +} + +//+--------------------------------------------------------------------------- +// +// _MoveWindowToTextExt +// +//---------------------------------------------------------------------------- + +void CCandidateListUIPresenter::_MoveWindowToTextExt() +{ + RECT rc; + + if (FAILED(_GetTextExt(&rc))) + { + return; + } + + _pCandidateWnd->_Move(rc.left, rc.bottom); +} +//+--------------------------------------------------------------------------- +// +// _LayoutChangeNotification +// +//---------------------------------------------------------------------------- + +VOID CCandidateListUIPresenter::_LayoutChangeNotification(_In_ RECT *lpRect) +{ + // OutputDebugString(L"LayoutChangeNotification\n"); +#ifdef FANY_DEBUG + // TODO: Log _LayoutChangeNotification firefox cnt: Global::firefox_like_cnt +#endif + WriteDataToSharedMemory(Global::Keycode, 0, Global::Point, Global::PinyinLength, Global::PinyinString, 0b00100); + SendMoveCandidateWndEventToUIProcess(); +} + +//+--------------------------------------------------------------------------- +// +// _LayoutDestroyNotification +// +//---------------------------------------------------------------------------- + +VOID CCandidateListUIPresenter::_LayoutDestroyNotification() +{ + _EndCandidateList(); +} + +//+--------------------------------------------------------------------------- +// +// _CandidateChangeNotifiction +// +//---------------------------------------------------------------------------- + +HRESULT CCandidateListUIPresenter::_CandidateChangeNotification(_In_ enum CANDWND_ACTION action) +{ + HRESULT hr = E_FAIL; + + TfClientId tfClientId = _pTextService->_GetClientId(); + ITfThreadMgr *pThreadMgr = nullptr; + ITfDocumentMgr *pDocumentMgr = nullptr; + ITfContext *pContext = nullptr; + + _KEYSTROKE_STATE KeyState; + KeyState.Category = _Category; + KeyState.Function = FUNCTION_FINALIZE_CANDIDATELIST; + + if (CAND_ITEM_SELECT != action) + { + goto Exit; + } + + pThreadMgr = _pTextService->_GetThreadMgr(); + if (nullptr == pThreadMgr) + { + goto Exit; + } + + hr = pThreadMgr->GetFocus(&pDocumentMgr); + if (FAILED(hr)) + { + goto Exit; + } + + hr = pDocumentMgr->GetTop(&pContext); + if (FAILED(hr)) + { + pDocumentMgr->Release(); + goto Exit; + } + + CKeyHandlerEditSession *pEditSession = + new (std::nothrow) CKeyHandlerEditSession(_pTextService, pContext, 0, 0, KeyState); + if (nullptr != pEditSession) + { + HRESULT hrSession = S_OK; + hr = pContext->RequestEditSession(tfClientId, pEditSession, TF_ES_SYNC | TF_ES_READWRITE, &hrSession); + if (hrSession == TF_E_SYNCHRONOUS || hrSession == TS_E_READONLY) + { + hr = pContext->RequestEditSession(tfClientId, pEditSession, TF_ES_ASYNC | TF_ES_READWRITE, &hrSession); + } + pEditSession->Release(); + } + + pContext->Release(); + pDocumentMgr->Release(); + +Exit: + return hr; +} + +//+--------------------------------------------------------------------------- +// +// _CandWndCallback +// +//---------------------------------------------------------------------------- + +// static +HRESULT CCandidateListUIPresenter::_CandWndCallback(_In_ void *pv, _In_ enum CANDWND_ACTION action) +{ + CCandidateListUIPresenter *fakeThis = (CCandidateListUIPresenter *)pv; + + return fakeThis->_CandidateChangeNotification(action); +} + +//+--------------------------------------------------------------------------- +// +// _UpdateUIElement +// +//---------------------------------------------------------------------------- + +HRESULT CCandidateListUIPresenter::_UpdateUIElement() +{ + HRESULT hr = S_OK; + + ITfThreadMgr *pThreadMgr = _pTextService->_GetThreadMgr(); + if (nullptr == pThreadMgr) + { + return S_OK; + } + + ITfUIElementMgr *pUIElementMgr = nullptr; + + hr = pThreadMgr->QueryInterface(IID_ITfUIElementMgr, (void **)&pUIElementMgr); + if (hr == S_OK) + { + pUIElementMgr->UpdateUIElement(_uiElementId); + pUIElementMgr->Release(); + } + + return S_OK; +} + +//+--------------------------------------------------------------------------- +// +// OnSetThreadFocus +// +//---------------------------------------------------------------------------- + +HRESULT CCandidateListUIPresenter::OnSetThreadFocus() +{ + if (_isShowMode) + { + Show(TRUE); + } + return S_OK; +} + +//+--------------------------------------------------------------------------- +// +// OnKillThreadFocus +// +//---------------------------------------------------------------------------- + +HRESULT CCandidateListUIPresenter::OnKillThreadFocus() +{ + if (_isShowMode) + { + Show(FALSE); + } + return S_OK; +} + +void CCandidateListUIPresenter::RemoveSpecificCandidateFromList( + _In_ LCID Locale, _Inout_ CMetasequoiaImeArray &candidateList, _In_ CStringRange &candidateString) +{ + for (UINT index = 0; index < candidateList.Count();) + { + CCandidateListItem *pLI = candidateList.GetAt(index); + + if (CStringRange::Compare(Locale, &candidateString, &pLI->_ItemString) == CSTR_EQUAL) + { + candidateList.RemoveAt(index); + continue; + } + + index++; + } +} + +void CCandidateListUIPresenter::AdviseUIChangedByArrowKey(_In_ KEYSTROKE_FUNCTION arrowKey) +{ + switch (arrowKey) + { + case FUNCTION_MOVE_UP: { + _MoveSelection(MOVEUP_ONE); + break; + } + case FUNCTION_MOVE_DOWN: { + _MoveSelection(MOVEDOWN_ONE); + break; + } + case FUNCTION_MOVE_PAGE_UP: { + // Page prev + WriteDataToSharedMemory(Global::Keycode, Global::ModifiersDown, nullptr, 0, L"", 0b00011); + // SendKeyEventToUIProcess(); +#ifdef FANY_DEBUG + OutputDebugString(fmt::format(L"Page up, prev, modifiers: {}", Global::ModifiersDown).c_str()); +#endif + _MovePage(MOVEUP_ONE); + break; + } + case FUNCTION_MOVE_PAGE_DOWN: { + // Page next + WriteDataToSharedMemory(Global::Keycode, 0, nullptr, 0, L"", 0b00001); + // SendKeyEventToUIProcess(); +#ifdef FANY_DEBUG + OutputDebugString(L"Page down, next\n"); +#endif + _MovePage(MOVEDOWN_ONE); + break; + } + case FUNCTION_MOVE_PAGE_TOP: { + _SetSelection(MOVETO_TOP); + break; + } + case FUNCTION_MOVE_PAGE_BOTTOM: { + _SetSelection(MOVETO_BOTTOM); + break; + } + default: + break; + } +} + +HRESULT CCandidateListUIPresenter::BeginUIElement() +{ + HRESULT hr = S_OK; + + ITfThreadMgr *pThreadMgr = _pTextService->_GetThreadMgr(); + if (nullptr == pThreadMgr) + { + hr = E_FAIL; + goto Exit; + } + + ITfUIElementMgr *pUIElementMgr = nullptr; + hr = pThreadMgr->QueryInterface(IID_ITfUIElementMgr, (void **)&pUIElementMgr); + if (hr == S_OK) + { + pUIElementMgr->BeginUIElement(this, &_isShowMode, &_uiElementId); + pUIElementMgr->Release(); + } + +Exit: + return hr; +} + +HRESULT CCandidateListUIPresenter::EndUIElement() +{ + HRESULT hr = S_OK; + + ITfThreadMgr *pThreadMgr = _pTextService->_GetThreadMgr(); + if ((nullptr == pThreadMgr) || (-1 == _uiElementId)) + { + hr = E_FAIL; + goto Exit; + } + + ITfUIElementMgr *pUIElementMgr = nullptr; + hr = pThreadMgr->QueryInterface(IID_ITfUIElementMgr, (void **)&pUIElementMgr); + if (hr == S_OK) + { + pUIElementMgr->EndUIElement(_uiElementId); + pUIElementMgr->Release(); + } + +Exit: + return hr; +} + +//+--------------------------------------------------------------------------- +// MakeCandidateWindow +// +// Create the candidate window +//---------------------------------------------------------------------------- + +HRESULT CCandidateListUIPresenter::MakeCandidateWindow(_In_ ITfContext *pContextDocument, _In_ UINT wndWidth) +{ + HRESULT hr = S_OK; + + if (nullptr != _pCandidateWnd) + { + return hr; + } + + _pCandidateWnd = new (std::nothrow) + CCandidateWindow(_CandWndCallback, this, _pIndexRange, _pTextService->_IsStoreAppMode(), _pTextService); + + if (_pCandidateWnd == nullptr) + { + hr = E_OUTOFMEMORY; + goto Exit; + } + + HWND parentWndHandle = nullptr; + ITfContextView *pView = nullptr; + if (SUCCEEDED(pContextDocument->GetActiveView(&pView))) + { + // pView->GetWnd(&parentWndHandle); + if (FAILED(pView->GetWnd(&parentWndHandle)) || (parentWndHandle == nullptr)) + { + parentWndHandle = GetFocus(); + } + } + + if (!_pCandidateWnd->_Create(_atom, wndWidth, parentWndHandle)) + { + hr = E_OUTOFMEMORY; + goto Exit; + } + +Exit: + return hr; +} + +void CCandidateListUIPresenter::DisposeCandidateWindow() +{ + if (nullptr == _pCandidateWnd) + { + return; + } + + // + // Hide the global candidate window + // + // ShowWindow(Global::MainWindowHandle, SW_HIDE); + // HWND UIHwnd = FindWindow(L"global_candidate_window", NULL); + // UINT WM_HIDE_MAIN_WINDOW = RegisterWindowMessage(L"WM_HIDE_MAIN_WINDOW"); + SendHideCandidateWndEventToUIProcess(); + + _pCandidateWnd->_Destroy(); + + delete _pCandidateWnd; + _pCandidateWnd = nullptr; +} diff --git a/src/UI/CandidateListUIPresenter.h b/src/UI/CandidateListUIPresenter.h index eabe0407..b4025940 100644 --- a/src/UI/CandidateListUIPresenter.h +++ b/src/UI/CandidateListUIPresenter.h @@ -1,144 +1,144 @@ -// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF -// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO -// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A -// PARTICULAR PURPOSE. -// -// Copyright (c) Microsoft Corporation. All rights reserved - -#pragma once - -#include "Private.h" -#include "SampleIME.h" -#include "CandidateWindow.h" -#include "CompositionProcessorEngine.h" -#include "SampleIMEBaseStructure.h" -#include "KeyHandlerEditSession.h" -#include "TfTextLayoutSink.h" - -class CReadingLine; - -//+--------------------------------------------------------------------------- -// -// CCandidateListUIPresenter -// -// ITfCandidateListUIElement / ITfIntegratableCandidateListUIElement is used for -// UILess mode support -// ITfCandidateListUIElementBehavior sends the Selection behavior message to -// 3rd party IME. -//---------------------------------------------------------------------------- - -class CCandidateListUIPresenter : public CTfTextLayoutSink, - public ITfCandidateListUIElementBehavior, - public ITfIntegratableCandidateListUIElement -{ - public: - CCandidateListUIPresenter(_In_ CSampleIME *pTextService, ATOM atom, KEYSTROKE_CATEGORY Category, - _In_ CCandidateRange *pIndexRange, BOOL hideWindow); - virtual ~CCandidateListUIPresenter(); - - // IUnknown - STDMETHODIMP QueryInterface(REFIID riid, _Outptr_ void **ppvObj); - STDMETHODIMP_(ULONG) AddRef(void); - STDMETHODIMP_(ULONG) Release(void); - - // ITfUIElement - STDMETHODIMP GetDescription(BSTR *pbstr); - STDMETHODIMP GetGUID(GUID *pguid); - STDMETHODIMP Show(BOOL showCandidateWindow); - STDMETHODIMP IsShown(BOOL *pIsShow); - - // ITfCandidateListUIElement - STDMETHODIMP GetUpdatedFlags(DWORD *pdwFlags); - STDMETHODIMP GetDocumentMgr(ITfDocumentMgr **ppdim); - STDMETHODIMP GetCount(UINT *pCandidateCount); - STDMETHODIMP GetSelection(UINT *pSelectedCandidateIndex); - STDMETHODIMP GetString(UINT uIndex, BSTR *pbstr); - STDMETHODIMP GetPageIndex(UINT *pIndex, UINT uSize, UINT *puPageCnt); - STDMETHODIMP SetPageIndex(UINT *pIndex, UINT uPageCnt); - STDMETHODIMP GetCurrentPage(UINT *puPage); - - // ITfCandidateListUIElementBehavior methods - STDMETHODIMP SetSelection(UINT nIndex); - STDMETHODIMP Finalize(void); - STDMETHODIMP Abort(void); - - // ITfIntegratableCandidateListUIElement - STDMETHODIMP SetIntegrationStyle(GUID guidIntegrationStyle); - STDMETHODIMP GetSelectionStyle(_Out_ TfIntegratableCandidateListSelectionStyle *ptfSelectionStyle); - STDMETHODIMP OnKeyDown(_In_ WPARAM wParam, _In_ LPARAM lParam, _Out_ BOOL *pIsEaten); - STDMETHODIMP ShowCandidateNumbers(_Out_ BOOL *pIsShow); - STDMETHODIMP FinalizeExactCompositionString(); - - virtual HRESULT _StartCandidateList(TfClientId tfClientId, _In_ ITfDocumentMgr *pDocumentMgr, - _In_ ITfContext *pContextDocument, TfEditCookie ec, - _In_ ITfRange *pRangeComposition, UINT wndWidth); - void _EndCandidateList(); - - void _NotifyUI(); - void _SetText(_In_ CSampleImeArray *pCandidateList, BOOL isAddFindKeyCode); - void _ClearList(); - VOID _SetTextColor(COLORREF crColor, COLORREF crBkColor); - VOID _SetFillColor(HBRUSH hBrush); - - DWORD_PTR _GetSelectedCandidateString(_Outptr_result_maybenull_ const WCHAR **ppwchCandidateString); - BOOL _SetSelectionInPage(int nPos) - { - return _pCandidateWnd->_SetSelectionInPage(nPos); - } - - BOOL _MoveSelection(_In_ int offSet); - BOOL _SetSelection(_In_ int selectedIndex); - BOOL _MovePage(_In_ int offSet); - - void _MoveWindowToTextExt(); - - // CTfTextLayoutSink - virtual VOID _LayoutChangeNotification(_In_ RECT *lpRect); - virtual VOID _LayoutDestroyNotification(); - - // Event for ITfThreadFocusSink - virtual HRESULT OnSetThreadFocus(); - virtual HRESULT OnKillThreadFocus(); - - void RemoveSpecificCandidateFromList(_In_ LCID Locale, _Inout_ CSampleImeArray &candidateList, - _In_ CStringRange &srgCandidateString); - void AdviseUIChangedByArrowKey(_In_ KEYSTROKE_FUNCTION arrowKey); - - private: - virtual HRESULT CALLBACK _CandidateChangeNotification(_In_ enum CANDWND_ACTION action); - - static HRESULT _CandWndCallback(_In_ void *pv, _In_ enum CANDWND_ACTION action); - - friend COLORREF _AdjustTextColor(_In_ COLORREF crColor, _In_ COLORREF crBkColor); - - HRESULT _UpdateUIElement(); - - HRESULT ToShowCandidateWindow(); - - HRESULT ToHideCandidateWindow(); - - HRESULT BeginUIElement(); - HRESULT EndUIElement(); - - HRESULT MakeCandidateWindow(_In_ ITfContext *pContextDocument, _In_ UINT wndWidth); - void DisposeCandidateWindow(); - - void AddCandidateToCandidateListUI(_In_ CSampleImeArray *pCandidateList, BOOL isAddFindKeyCode); - - void SetPageIndexWithScrollInfo(_In_ CSampleImeArray *pCandidateList); - - protected: - CCandidateWindow *_pCandidateWnd; - BOOL _isShowMode; - BOOL _hideWindow; - - private: - HWND _parentWndHandle; - ATOM _atom; - CCandidateRange *_pIndexRange; - KEYSTROKE_CATEGORY _Category; - DWORD _updatedFlags; - DWORD _uiElementId; - CSampleIME *_pTextService; - LONG _refCount; -}; +// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF +// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO +// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A +// PARTICULAR PURPOSE. +// +// Copyright (c) Microsoft Corporation. All rights reserved + +#pragma once + +#include "Private.h" +#include "MetasequoiaIME.h" +#include "CandidateWindow.h" +#include "CompositionProcessorEngine.h" +#include "MetasequoiaIMEBaseStructure.h" +#include "KeyHandlerEditSession.h" +#include "TfTextLayoutSink.h" + +class CReadingLine; + +//+--------------------------------------------------------------------------- +// +// CCandidateListUIPresenter +// +// ITfCandidateListUIElement / ITfIntegratableCandidateListUIElement is used for +// UILess mode support +// ITfCandidateListUIElementBehavior sends the Selection behavior message to +// 3rd party IME. +//---------------------------------------------------------------------------- + +class CCandidateListUIPresenter : public CTfTextLayoutSink, + public ITfCandidateListUIElementBehavior, + public ITfIntegratableCandidateListUIElement +{ + public: + CCandidateListUIPresenter(_In_ CMetasequoiaIME *pTextService, ATOM atom, KEYSTROKE_CATEGORY Category, + _In_ CCandidateRange *pIndexRange, BOOL hideWindow); + virtual ~CCandidateListUIPresenter(); + + // IUnknown + STDMETHODIMP QueryInterface(REFIID riid, _Outptr_ void **ppvObj); + STDMETHODIMP_(ULONG) AddRef(void); + STDMETHODIMP_(ULONG) Release(void); + + // ITfUIElement + STDMETHODIMP GetDescription(BSTR *pbstr); + STDMETHODIMP GetGUID(GUID *pguid); + STDMETHODIMP Show(BOOL showCandidateWindow); + STDMETHODIMP IsShown(BOOL *pIsShow); + + // ITfCandidateListUIElement + STDMETHODIMP GetUpdatedFlags(DWORD *pdwFlags); + STDMETHODIMP GetDocumentMgr(ITfDocumentMgr **ppdim); + STDMETHODIMP GetCount(UINT *pCandidateCount); + STDMETHODIMP GetSelection(UINT *pSelectedCandidateIndex); + STDMETHODIMP GetString(UINT uIndex, BSTR *pbstr); + STDMETHODIMP GetPageIndex(UINT *pIndex, UINT uSize, UINT *puPageCnt); + STDMETHODIMP SetPageIndex(UINT *pIndex, UINT uPageCnt); + STDMETHODIMP GetCurrentPage(UINT *puPage); + + // ITfCandidateListUIElementBehavior methods + STDMETHODIMP SetSelection(UINT nIndex); + STDMETHODIMP Finalize(void); + STDMETHODIMP Abort(void); + + // ITfIntegratableCandidateListUIElement + STDMETHODIMP SetIntegrationStyle(GUID guidIntegrationStyle); + STDMETHODIMP GetSelectionStyle(_Out_ TfIntegratableCandidateListSelectionStyle *ptfSelectionStyle); + STDMETHODIMP OnKeyDown(_In_ WPARAM wParam, _In_ LPARAM lParam, _Out_ BOOL *pIsEaten); + STDMETHODIMP ShowCandidateNumbers(_Out_ BOOL *pIsShow); + STDMETHODIMP FinalizeExactCompositionString(); + + virtual HRESULT _StartCandidateList(TfClientId tfClientId, _In_ ITfDocumentMgr *pDocumentMgr, + _In_ ITfContext *pContextDocument, TfEditCookie ec, + _In_ ITfRange *pRangeComposition, UINT wndWidth); + void _EndCandidateList(); + + void _NotifyUI(); + void _SetText(_In_ CMetasequoiaImeArray *pCandidateList, BOOL isAddFindKeyCode); + void _ClearList(); + VOID _SetTextColor(COLORREF crColor, COLORREF crBkColor); + VOID _SetFillColor(HBRUSH hBrush); + + DWORD_PTR _GetSelectedCandidateString(_Outptr_result_maybenull_ const WCHAR **ppwchCandidateString); + BOOL _SetSelectionInPage(int nPos) + { + return _pCandidateWnd->_SetSelectionInPage(nPos); + } + + BOOL _MoveSelection(_In_ int offSet); + BOOL _SetSelection(_In_ int selectedIndex); + BOOL _MovePage(_In_ int offSet); + + void _MoveWindowToTextExt(); + + // CTfTextLayoutSink + virtual VOID _LayoutChangeNotification(_In_ RECT *lpRect); + virtual VOID _LayoutDestroyNotification(); + + // Event for ITfThreadFocusSink + virtual HRESULT OnSetThreadFocus(); + virtual HRESULT OnKillThreadFocus(); + + void RemoveSpecificCandidateFromList(_In_ LCID Locale, _Inout_ CMetasequoiaImeArray &candidateList, + _In_ CStringRange &srgCandidateString); + void AdviseUIChangedByArrowKey(_In_ KEYSTROKE_FUNCTION arrowKey); + + private: + virtual HRESULT CALLBACK _CandidateChangeNotification(_In_ enum CANDWND_ACTION action); + + static HRESULT _CandWndCallback(_In_ void *pv, _In_ enum CANDWND_ACTION action); + + friend COLORREF _AdjustTextColor(_In_ COLORREF crColor, _In_ COLORREF crBkColor); + + HRESULT _UpdateUIElement(); + + HRESULT ToShowCandidateWindow(); + + HRESULT ToHideCandidateWindow(); + + HRESULT BeginUIElement(); + HRESULT EndUIElement(); + + HRESULT MakeCandidateWindow(_In_ ITfContext *pContextDocument, _In_ UINT wndWidth); + void DisposeCandidateWindow(); + + void AddCandidateToCandidateListUI(_In_ CMetasequoiaImeArray *pCandidateList, BOOL isAddFindKeyCode); + + void SetPageIndexWithScrollInfo(_In_ CMetasequoiaImeArray *pCandidateList); + + protected: + CCandidateWindow *_pCandidateWnd; + BOOL _isShowMode; + BOOL _hideWindow; + + private: + HWND _parentWndHandle; + ATOM _atom; + CCandidateRange *_pIndexRange; + KEYSTROKE_CATEGORY _Category; + DWORD _updatedFlags; + DWORD _uiElementId; + CMetasequoiaIME *_pTextService; + LONG _refCount; +}; diff --git a/src/Window/CandidateWindow.cpp b/src/Window/CandidateWindow.cpp index bcd830f0..9f8df101 100644 --- a/src/Window/CandidateWindow.cpp +++ b/src/Window/CandidateWindow.cpp @@ -23,7 +23,7 @@ COLORREF _AdjustTextColor(_In_ COLORREF crColor, _In_ COLORREF crBkColor); //---------------------------------------------------------------------------- CCandidateWindow::CCandidateWindow(_In_ CANDWNDCALLBACK pfnCallback, _In_ void *pv, _In_ CCandidateRange *pIndexRange, - _In_ BOOL isStoreAppMode, _In_ CSampleIME *pTextService) + _In_ BOOL isStoreAppMode, _In_ CMetasequoiaIME *pTextService) { _currentSelection = 0; @@ -468,7 +468,7 @@ void CCandidateWindow::_DrawList(_In_ HDC dcHandle, _In_ UINT iIndex, _In_ RECT { // 创建并选择字体 HFONT hFont = CreateFont(-22, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET, OUT_OUTLINE_PRECIS, - CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, SAMPLEIME_FONT_DEFAULT); + CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, VARIABLE_PITCH, METASEQUOIAIME_FONT_DEFAULT); HFONT hOldFont = (HFONT)SelectObject(dcHandle, hFont); int pageCount = 0; diff --git a/src/Window/CandidateWindow.h b/src/Window/CandidateWindow.h index 7e9b12c3..0180c552 100644 --- a/src/Window/CandidateWindow.h +++ b/src/Window/CandidateWindow.h @@ -9,10 +9,10 @@ #include "Private.h" #include "BaseWindow.h" -#include "SampleIME.h" +#include "MetasequoiaIME.h" #include "ShadowWindow.h" #include "ScrollBarWindow.h" -#include "SampleIMEBaseStructure.h" +#include "MetasequoiaIMEBaseStructure.h" enum CANDWND_ACTION { @@ -25,7 +25,7 @@ class CCandidateWindow : public CBaseWindow { public: CCandidateWindow(_In_ CANDWNDCALLBACK pfnCallback, _In_ void *pv, _In_ CCandidateRange *pIndexRange, - _In_ BOOL isStoreAppMode, _In_ CSampleIME *pTextService); + _In_ BOOL isStoreAppMode, _In_ CMetasequoiaIME *pTextService); virtual ~CCandidateWindow(); BOOL _Create(ATOM atom, _In_ UINT wndWidth, _In_opt_ HWND parentWndHandle); @@ -93,9 +93,9 @@ class CCandidateWindow : public CBaseWindow private: UINT _currentSelection; - CSampleImeArray _candidateList; - CSampleImeArray _PageIndex; - CSampleIME *_pTextService; + CMetasequoiaImeArray _candidateList; + CMetasequoiaImeArray _PageIndex; + CMetasequoiaIME *_pTextService; COLORREF _crTextColor; COLORREF _crBkColor;