-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 7b83802
Showing
103 changed files
with
19,016 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
BasedOnStyle: Microsoft | ||
IndentWidth: 4 | ||
|
||
# 不要给头文件排序 | ||
SortIncludes: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CompileFlags: | ||
Add: [-Wno-microsoft-goto, -Wno-unused-value] # 忽略某些警告 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// 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 "CompositionProcessorEngine.h" | ||
|
||
BOOL CSampleIME::VerifySampleIMECLSID(_In_ REFCLSID clsid) | ||
{ | ||
if (IsEqualCLSID(clsid, Global::SampleIMECLSID)) | ||
{ | ||
return TRUE; | ||
} | ||
return FALSE; | ||
} | ||
|
||
//+--------------------------------------------------------------------------- | ||
// | ||
// ITfActiveLanguageProfileNotifySink::OnActivated | ||
// | ||
// Sink called by the framework when changes activate language profile. | ||
//---------------------------------------------------------------------------- | ||
|
||
STDAPI CSampleIME::OnActivated(_In_ REFCLSID clsid, _In_ REFGUID guidProfile, _In_ BOOL isActivated) | ||
{ | ||
guidProfile; | ||
|
||
if (FALSE == VerifySampleIMECLSID(clsid)) | ||
{ | ||
return S_OK; | ||
} | ||
|
||
if (isActivated) | ||
{ | ||
_AddTextProcessorEngine(); | ||
} | ||
|
||
if (nullptr == _pCompositionProcessorEngine) | ||
{ | ||
return S_OK; | ||
} | ||
|
||
if (isActivated) | ||
{ | ||
_pCompositionProcessorEngine->ShowAllLanguageBarIcons(); | ||
|
||
_pCompositionProcessorEngine->ConversionModeCompartmentUpdated(_pThreadMgr); | ||
} | ||
else | ||
{ | ||
_DeleteCandidateList(FALSE, nullptr); | ||
|
||
_pCompositionProcessorEngine->HideAllLanguageBarIcons(); | ||
} | ||
|
||
return S_OK; | ||
} | ||
|
||
//+--------------------------------------------------------------------------- | ||
// | ||
// _InitActiveLanguageProfileNotifySink | ||
// | ||
// Advise a active language profile notify sink. | ||
//---------------------------------------------------------------------------- | ||
|
||
BOOL CSampleIME::_InitActiveLanguageProfileNotifySink() | ||
{ | ||
ITfSource *pSource = nullptr; | ||
BOOL ret = FALSE; | ||
|
||
if (_pThreadMgr->QueryInterface(IID_ITfSource, (void **)&pSource) != S_OK) | ||
{ | ||
return ret; | ||
} | ||
|
||
if (pSource->AdviseSink(IID_ITfActiveLanguageProfileNotifySink, (ITfActiveLanguageProfileNotifySink *)this, | ||
&_activeLanguageProfileNotifySinkCookie) != S_OK) | ||
{ | ||
_activeLanguageProfileNotifySinkCookie = TF_INVALID_COOKIE; | ||
goto Exit; | ||
} | ||
|
||
ret = TRUE; | ||
|
||
Exit: | ||
pSource->Release(); | ||
return ret; | ||
} | ||
|
||
//+--------------------------------------------------------------------------- | ||
// | ||
// _UninitActiveLanguageProfileNotifySink | ||
// | ||
// Unadvise a active language profile notify sink. Assumes we have advised one already. | ||
//---------------------------------------------------------------------------- | ||
|
||
void CSampleIME::_UninitActiveLanguageProfileNotifySink() | ||
{ | ||
ITfSource *pSource = nullptr; | ||
|
||
if (_activeLanguageProfileNotifySinkCookie == TF_INVALID_COOKIE) | ||
{ | ||
return; // never Advised | ||
} | ||
|
||
if (_pThreadMgr->QueryInterface(IID_ITfSource, (void **)&pSource) == S_OK) | ||
{ | ||
pSource->UnadviseSink(_activeLanguageProfileNotifySinkCookie); | ||
pSource->Release(); | ||
} | ||
|
||
_activeLanguageProfileNotifySinkCookie = TF_INVALID_COOKIE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// 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 "BaseDictionaryEngine.h" | ||
#include "Globals.h" | ||
|
||
//+--------------------------------------------------------------------------- | ||
// ctor | ||
//---------------------------------------------------------------------------- | ||
|
||
CBaseDictionaryEngine::CBaseDictionaryEngine(LCID locale, _In_ CFile *pDictionaryFile) | ||
{ | ||
_locale = locale; | ||
_pDictionaryFile = pDictionaryFile; | ||
} | ||
|
||
//+--------------------------------------------------------------------------- | ||
// dtor | ||
//---------------------------------------------------------------------------- | ||
|
||
CBaseDictionaryEngine::~CBaseDictionaryEngine() | ||
{ | ||
} | ||
|
||
//+--------------------------------------------------------------------------- | ||
// SortListItemByFindKeyCode | ||
//---------------------------------------------------------------------------- | ||
|
||
VOID CBaseDictionaryEngine::SortListItemByFindKeyCode(_Inout_ CSampleImeArray<CCandidateListItem> *pItemList) | ||
{ | ||
MergeSortByFindKeyCode(pItemList, 0, pItemList->Count() - 1); | ||
} | ||
|
||
//+--------------------------------------------------------------------------- | ||
// MergeSortByFindKeyCode | ||
// | ||
// Mergesort the array of element in CCandidateListItem::_FindKeyCode | ||
// | ||
//---------------------------------------------------------------------------- | ||
|
||
VOID CBaseDictionaryEngine::MergeSortByFindKeyCode(_Inout_ CSampleImeArray<CCandidateListItem> *pItemList, int leftRange, int rightRange) | ||
{ | ||
int candidateCount = CalculateCandidateCount(leftRange, rightRange); | ||
|
||
if (candidateCount > 2) | ||
{ | ||
int mid = leftRange + (candidateCount / 2); | ||
|
||
MergeSortByFindKeyCode(pItemList, leftRange, mid); | ||
MergeSortByFindKeyCode(pItemList, mid, rightRange); | ||
|
||
CSampleImeArray<CCandidateListItem> ListItemTemp; | ||
|
||
int leftRangeTemp = 0; | ||
int midTemp = 0; | ||
for (leftRangeTemp = leftRange, midTemp = mid; leftRangeTemp != mid || midTemp != rightRange;) | ||
{ | ||
CStringRange* psrgLeftTemp = nullptr; | ||
CStringRange* psrgMidTemp = nullptr; | ||
|
||
psrgLeftTemp = &pItemList->GetAt(leftRangeTemp)->_FindKeyCode; | ||
psrgMidTemp = &pItemList->GetAt(midTemp)->_FindKeyCode; | ||
|
||
CCandidateListItem* pLI = nullptr; | ||
pLI = ListItemTemp.Append(); | ||
if (pLI) | ||
{ | ||
if (leftRangeTemp == mid) | ||
{ | ||
*pLI = *pItemList->GetAt(midTemp++); | ||
} | ||
else if (midTemp == rightRange || CStringRange::Compare(_locale, psrgLeftTemp, psrgMidTemp) != CSTR_GREATER_THAN) | ||
{ | ||
*pLI = *pItemList->GetAt(leftRangeTemp++); | ||
} | ||
else | ||
{ | ||
*pLI = *pItemList->GetAt(midTemp++); | ||
} | ||
} | ||
} | ||
|
||
leftRangeTemp = leftRange; | ||
for (UINT count = 0; count < ListItemTemp.Count(); count++) | ||
{ | ||
*pItemList->GetAt(leftRangeTemp++) = *ListItemTemp.GetAt(count); | ||
} | ||
} | ||
else if (candidateCount == 2) | ||
{ | ||
CStringRange *psrgLeft = nullptr; | ||
CStringRange *psrgLeftNext = nullptr; | ||
|
||
psrgLeft = &pItemList->GetAt(leftRange )->_FindKeyCode; | ||
psrgLeftNext = &pItemList->GetAt(leftRange+1)->_FindKeyCode; | ||
|
||
if (CStringRange::Compare(_locale, psrgLeft, psrgLeftNext) == CSTR_GREATER_THAN) | ||
{ | ||
CCandidateListItem ListItem; | ||
ListItem = *pItemList->GetAt(leftRange); | ||
*pItemList->GetAt(leftRange ) = *pItemList->GetAt(leftRange+1); | ||
*pItemList->GetAt(leftRange+1) = ListItem; | ||
} | ||
} | ||
} | ||
|
||
int CBaseDictionaryEngine::CalculateCandidateCount(int leftRange, int rightRange) | ||
{ | ||
assert(leftRange >= 0); | ||
assert(rightRange >= 0); | ||
|
||
return (rightRange - leftRange + 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// 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 "File.h" | ||
#include "SampleIMEBaseStructure.h" | ||
|
||
class CBaseDictionaryEngine | ||
{ | ||
public: | ||
CBaseDictionaryEngine(LCID locale, _In_ CFile *pDictionaryFile); | ||
virtual ~CBaseDictionaryEngine(); | ||
|
||
virtual VOID CollectWord(_In_ CStringRange *psrgKeyCode, _Out_ CSampleImeArray<CStringRange> *pasrgWordString) | ||
{ | ||
psrgKeyCode; | ||
pasrgWordString = nullptr; | ||
} | ||
|
||
virtual VOID CollectWord(_In_ CStringRange *psrgKeyCode, _Out_ CSampleImeArray<CCandidateListItem> *pItemList) | ||
{ | ||
psrgKeyCode; | ||
pItemList = nullptr; | ||
} | ||
|
||
virtual VOID SortListItemByFindKeyCode(_Inout_ CSampleImeArray<CCandidateListItem> *pItemList); | ||
|
||
protected: | ||
CFile* _pDictionaryFile; | ||
LCID _locale; | ||
|
||
private: | ||
VOID MergeSortByFindKeyCode(_Inout_ CSampleImeArray<CCandidateListItem> *pItemList, int leftRange, int rightRange); | ||
int CalculateCandidateCount(int leftRange, int rightRange); | ||
}; |
Oops, something went wrong.