Skip to content

Commit

Permalink
add array forceSP and notifySP funcitons
Browse files Browse the repository at this point in the history
  • Loading branch information
jrywu committed Aug 18, 2013
1 parent 1f3c457 commit 3bfe305
Show file tree
Hide file tree
Showing 16 changed files with 205 additions and 80 deletions.
40 changes: 30 additions & 10 deletions CandidateHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,16 @@ HRESULT CTSFTTS::_HandleCandidateWorker(TfEditCookie ec, _In_ ITfContext *pConte
}

const WCHAR* pCandidateString = nullptr;
DWORD_PTR candidateLen = 0;
DWORD_PTR candidateLen = 0;
BOOL arrayUsingSPCode =FALSE;

if (!_IsComposing())
_StartComposition(pContext);

if(Global::imeMode == IME_MODE_ARRAY)
{
candidateLen = _pCompositionProcessorEngine->CheckArraySpeicalCode(&pCandidateString);
if(candidateLen) arrayUsingSPCode = TRUE;
}
if(candidateLen == 0)
{
Expand Down Expand Up @@ -91,17 +93,35 @@ HRESULT CTSFTTS::_HandleCandidateWorker(TfEditCookie ec, _In_ ITfContext *pConte
StringCchCopyN(pwch, 2, pCandidateString, 1);
}
candidateString.Set(pwch, 1 );

hr = _AddComposingAndChar(ec, pContext, &commitString);
if (FAILED(hr)) return hr;

// Do not send _endcandidatelist here to avoid cand dissapear in win8
_TerminateComposition(ec, pContext);
_candidateMode = CANDIDATE_NONE;
_isCandidateWithWildcard = FALSE;
//-----------------do reverse lookup and array spcial code notify
BOOL ArraySPFound = FALSE;
if(Global::imeMode == IME_MODE_ARRAY && !arrayUsingSPCode && (CConfig::GetArrayForceSP() || CConfig::GetArrayNotifySP()) )
{
const WCHAR *specialCode = nullptr;
CStringRange notifyText;
ArraySPFound = _pCompositionProcessorEngine->LookupSpeicalCode(&commitString, &specialCode);
if(specialCode)
_pUIPresenter->ShowNotifyText(&notifyText.Set(specialCode,wcslen(specialCode)), -1);
}
//----------------- commit the selected string
if(Global::imeMode == IME_MODE_ARRAY && !arrayUsingSPCode && CConfig::GetArrayForceSP() && ArraySPFound )
{
_pCompositionProcessorEngine->DoBeep();
_HandleCancel(ec,pContext);
return hr;
}
else
{
hr = _AddComposingAndChar(ec, pContext, &commitString);
if (FAILED(hr)) return hr;
// Do not send _endcandidatelist here to avoid cand dissapear in win8
_TerminateComposition(ec, pContext);
_candidateMode = CANDIDATE_NONE;
_isCandidateWithWildcard = FALSE;
}



//-----------------do accociated phrase (make phrase)
if (CConfig::GetMakePhrase())
{
_pCompositionProcessorEngine->GetCandidateStringInConverted(candidateString, &candidatePhraseList);
Expand Down
50 changes: 47 additions & 3 deletions CompositionProcessorEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ void CCompositionProcessorEngine::GetReadingStrings(_Inout_ CTSFTTSArray<CString
{
if(Global::radicalMap.size() && !IsSymbol()) // if radicalMap is valid (size()>0), then convert the keystroke buffer
{
WCHAR* radicalChar = new (std::nothrow) WCHAR[2];
WCHAR radicalChar[2];
*radicalChar = towupper(*(_keystrokeBuffer.Get() + index));
WCHAR* radical = &Global::radicalMap[*radicalChar];
if(*radical == L'\0') *radical = *radicalChar;
Expand Down Expand Up @@ -558,7 +558,7 @@ BOOL CCompositionProcessorEngine::IsSymbol()
if(Global::imeMode==IME_MODE_DAYI)
return (_keystrokeBuffer.GetLength()<3 && *_keystrokeBuffer.Get()==L'=');
else if(Global::imeMode==IME_MODE_ARRAY)
return (_keystrokeBuffer.GetLength()<3 && _toupper(*_keystrokeBuffer.Get())==L'W');
return (_keystrokeBuffer.GetLength()<3 && towupper(*_keystrokeBuffer.Get())==L'W');
else
return FALSE;
}
Expand All @@ -582,7 +582,7 @@ BOOL CCompositionProcessorEngine::IsSymbolChar(WCHAR wch)
}

}
if((_keystrokeBuffer.GetLength() == 1) && (_toupper(*_keystrokeBuffer.Get()) == L'W') && Global::imeMode==IME_MODE_ARRAY)
if((_keystrokeBuffer.GetLength() == 1) && (towupper(*_keystrokeBuffer.Get()) == L'W') && Global::imeMode==IME_MODE_ARRAY)
{
for (int i = 0; i < 10; i++)
{
Expand Down Expand Up @@ -678,6 +678,50 @@ DWORD_PTR CCompositionProcessorEngine::CheckArraySpeicalCode(_Outptr_result_mayb



}
//+---------------------------------------------------------------------------
//
// checkArraySpeicalCode
//
//----------------------------------------------------------------------------
BOOL CCompositionProcessorEngine::LookupSpeicalCode(_In_ CStringRange *inword, _Outptr_result_maybenull_ const WCHAR **ppwchSpecialCodeResultString)
{
*ppwchSpecialCodeResultString = nullptr;
CTSFTTSArray<CCandidateListItem> candidateList;

if(Global::imeMode!= IME_MODE_ARRAY || _pArraySpecialCodeTableDictionaryEngine == nullptr || inword == nullptr ) return FALSE;
else
{
_pArraySpecialCodeTableDictionaryEngine->CollectWordFromConvertedString(inword, &candidateList);
if(candidateList.Count() == 1)
{

PWCHAR pwch;
pwch = new (std::nothrow) WCHAR[candidateList.GetAt(0)->_FindKeyCode.GetLength()+1];
*pwch=L'\0';
if(candidateList.GetAt(0)->_FindKeyCode.GetLength() && Global::radicalMap.size())
{
for(int i=0; i <candidateList.GetAt(0)->_FindKeyCode.GetLength(); i++)
{ // query keyname from keymap
WCHAR radicalChar[2];
*radicalChar = towupper(*(candidateList.GetAt(0)->_FindKeyCode.Get() + i));
WCHAR* radical = &Global::radicalMap[*radicalChar];
if(*radical == L'\0') *radical = *radicalChar;
StringCchCatN(pwch, candidateList.GetAt(0)->_FindKeyCode.GetLength()+1, radical,1);
}
*ppwchSpecialCodeResultString = pwch;
return TRUE;
}
else
{
delete pwch;
*ppwchSpecialCodeResultString = candidateList.GetAt(0)->_FindKeyCode.Get();
}
}
}
return FALSE;


}

//+---------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions CompositionProcessorEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class CCompositionProcessorEngine
//Array short code and special code
BOOL IsArrayShortCode();
DWORD_PTR CheckArraySpeicalCode(_Outptr_result_maybenull_ const WCHAR **ppwchSpecialCodeResultString);
BOOL LookupSpeicalCode(_In_ CStringRange *inword, _Outptr_result_maybenull_ const WCHAR **ppwchSpecialCodeResultString);

BOOL IsDoubleSingleByte(WCHAR wch);
BOOL IsWildcard() { return _isWildcard; }
Expand Down
28 changes: 23 additions & 5 deletions Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
//static configuration settings initilization
BOOL CConfig::_doBeep = TRUE;
BOOL CConfig::_autoCompose = FALSE;
BOOL CConfig::_threeCodeMode = FALSE;
BOOL CConfig::_threeCodeMode = TRUE;
BOOL CConfig::_arrayForceSP = FALSE;
BOOL CConfig::_arrayNotifySP = TRUE;
BOOL CConfig::_arrowKeySWPages = TRUE;
BOOL CConfig::_spaceAsPageDown = FALSE;
UINT CConfig::_fontSize = 14;
Expand Down Expand Up @@ -149,6 +151,8 @@ INT_PTR CALLBACK CConfig::CommonPropertyPageWndProc(HWND hDlg, UINT message, WPA
CheckDlgButton(hDlg, IDC_CHECKBOX_AUTOCOMPOSE, (_autoCompose)?BST_CHECKED:BST_UNCHECKED);
CheckDlgButton(hDlg, IDC_CHECKBOX_DOBEEP, (_doBeep)?BST_CHECKED:BST_UNCHECKED);
CheckDlgButton(hDlg, IDC_CHECKBOX_THREECODEMODE,(_threeCodeMode)?BST_CHECKED:BST_UNCHECKED);
CheckDlgButton(hDlg, IDC_CHECKBOX_ARRAY_FORCESP,(_arrayForceSP)?BST_CHECKED:BST_UNCHECKED);
CheckDlgButton(hDlg, IDC_CHECKBOX_ARRAY_NOTIFYSP,(_arrayNotifySP)?BST_CHECKED:BST_UNCHECKED);
CheckDlgButton(hDlg, IDC_CHECKBOX_PHRASE, (_makePhrase)?BST_CHECKED:BST_UNCHECKED);

CheckDlgButton(hDlg, IDC_RADIO_KEYBOARD_OPEN, (_activatedKeyboardMode)?BST_CHECKED:BST_UNCHECKED);
Expand All @@ -160,7 +164,7 @@ INT_PTR CALLBACK CConfig::CommonPropertyPageWndProc(HWND hDlg, UINT message, WPA
CheckDlgButton(hDlg, IDC_CHECKBOX_ARROWKEYSWPAGES, (_arrowKeySWPages)?BST_CHECKED:BST_UNCHECKED);
// hide autocompose and space as pagedown option in DAYI.

if(Global::imeMode==IME_MODE_DAYI)
if(Global::imeMode==IME_MODE_DAYI || Global::imeMode==IME_MODE_ARRAY)
{
ShowWindow(GetDlgItem(hDlg, IDC_CHECKBOX_AUTOCOMPOSE), SW_HIDE);
ShowWindow(GetDlgItem(hDlg, IDC_CHECKBOX_SPACEASPAGEDOWN), SW_HIDE);
Expand All @@ -169,7 +173,11 @@ INT_PTR CALLBACK CConfig::CommonPropertyPageWndProc(HWND hDlg, UINT message, WPA
{
ShowWindow(GetDlgItem(hDlg, IDC_CHECKBOX_THREECODEMODE), SW_HIDE);
}

if(Global::imeMode!=IME_MODE_ARRAY)
{
ShowWindow(GetDlgItem(hDlg, IDC_CHECKBOX_ARRAY_FORCESP), SW_HIDE);
ShowWindow(GetDlgItem(hDlg, IDC_CHECKBOX_ARRAY_NOTIFYSP), SW_HIDE);
}
ret = TRUE;
break;

Expand Down Expand Up @@ -238,6 +246,8 @@ INT_PTR CALLBACK CConfig::CommonPropertyPageWndProc(HWND hDlg, UINT message, WPA
case IDC_RADIO_KEYBOARD_OPEN:
case IDC_RADIO_KEYBOARD_CLOSE:
case IDC_CHECKBOX_THREECODEMODE:
case IDC_CHECKBOX_ARRAY_FORCESP:
case IDC_CHECKBOX_ARRAY_NOTIFYSP:
case IDC_CHECKBOX_PHRASE:
case IDC_CHECKBOX_ARROWKEYSWPAGES:
case IDC_CHECKBOX_SPACEASPAGEDOWN:
Expand Down Expand Up @@ -310,7 +320,8 @@ INT_PTR CALLBACK CConfig::CommonPropertyPageWndProc(HWND hDlg, UINT message, WPA
_showNotifyDesktop = IsDlgButtonChecked(hDlg, IDC_CHECKBOX_SHOWNOTIFY) == BST_CHECKED;
_spaceAsPageDown = IsDlgButtonChecked(hDlg, IDC_CHECKBOX_SPACEASPAGEDOWN) == BST_CHECKED;
_arrowKeySWPages = IsDlgButtonChecked(hDlg, IDC_CHECKBOX_ARROWKEYSWPAGES) == BST_CHECKED;

_arrayForceSP = IsDlgButtonChecked(hDlg, IDC_CHECKBOX_ARRAY_FORCESP) == BST_CHECKED;
_arrayNotifySP = IsDlgButtonChecked(hDlg, IDC_CHECKBOX_ARRAY_NOTIFYSP) == BST_CHECKED;


GetDlgItemText(hDlg, IDC_EDIT_MAXWIDTH, num, _countof(num));
Expand Down Expand Up @@ -406,7 +417,6 @@ VOID CConfig::WriteConfig()
{
fwprintf_s(fp, L"[Config]\n");
fwprintf_s(fp, L"AutoCompose = %d\n", _autoCompose?1:0);
fwprintf_s(fp, L"ThreeCodeMode = %d\n", _threeCodeMode?1:0);
fwprintf_s(fp, L"SpaceAsPageDown = %d\n", _spaceAsPageDown?1:0);
fwprintf_s(fp, L"ArrowKeySWPages = %d\n", _arrowKeySWPages?1:0);
fwprintf_s(fp, L"DoBeep = %d\n", _doBeep?1:0);
Expand All @@ -426,6 +436,14 @@ VOID CConfig::WriteConfig()
fwprintf_s(fp, L"SelectedBGItemColor = 0x%06X\n", _selectedBGColor);
if(Global::isWindows8)
fwprintf_s(fp, L"AppPermissionSet = %d\n", _appPermissionSet?1:0);
if(Global::imeMode == IME_MODE_DAYI)
fwprintf_s(fp, L"ThreeCodeMode = %d\n", _threeCodeMode?1:0);
if(Global::imeMode == IME_MODE_ARRAY)
{
fwprintf_s(fp, L"ArrayForceSP = %d\n", _arrayForceSP?1:0);
fwprintf_s(fp, L"ArrayNotifySP = %d\n", _arrayNotifySP?1:0);
}


fclose(fp);
}
Expand Down
8 changes: 8 additions & 0 deletions Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ class CConfig
static BOOL GetActivatedKeyboardMode() {return _activatedKeyboardMode;}
static void SetAppPermissionSet(BOOL appPermissionSet) { _appPermissionSet = appPermissionSet;}
static BOOL GetAppPermissionSet() {return _appPermissionSet;}
//array special code
static void SetArrayNotifySP(BOOL arrayNotifySP) { _arrayNotifySP = arrayNotifySP;}
static BOOL GetArrayNotifySP() {return _arrayNotifySP;}
static void SetArrayForceSP(BOOL arrayForceSP) { _arrayForceSP = arrayForceSP;}
static BOOL GetArrayForceSP() {return _arrayForceSP;}

static VOID WriteConfig();
static VOID LoadConfig();
Expand Down Expand Up @@ -86,6 +91,9 @@ class CConfig
static BOOL _spaceAsPageDown;
static BOOL _arrowKeySWPages;

static BOOL _arrayNotifySP;
static BOOL _arrayForceSP;

static struct _stat _initTimeStamp;


Expand Down
7 changes: 5 additions & 2 deletions DictionarySearch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ BOOL CDictionarySearch::FindWorker(BOOL isTextSearch, _Out_ CDictionaryResult **
CConfig::SetAutoCompose((CStringRange::Compare(_locale, valueStrings.GetAt(0), &value.Set(L"1", 1)) == CSTR_EQUAL));
else if (CStringRange::Compare(_locale, &keyword, &testKey.Set(L"ThreeCodeMode", 13)) == CSTR_EQUAL)
CConfig::SetThreeCodeMode((CStringRange::Compare(_locale, valueStrings.GetAt(0), &value.Set(L"1", 1)) == CSTR_EQUAL));
else if (CStringRange::Compare(_locale, &keyword, &testKey.Set(L"ArrayForceSP", 12)) == CSTR_EQUAL)
CConfig::SetArrayForceSP((CStringRange::Compare(_locale, valueStrings.GetAt(0), &value.Set(L"1", 1)) == CSTR_EQUAL));
else if (CStringRange::Compare(_locale, &keyword, &testKey.Set(L"ArrayNotifySP", 13)) == CSTR_EQUAL)
CConfig::SetArrayNotifySP((CStringRange::Compare(_locale, valueStrings.GetAt(0), &value.Set(L"1", 1)) == CSTR_EQUAL));
else if (CStringRange::Compare(_locale, &keyword, &testKey.Set(L"SpaceAsPageDown", 15)) == CSTR_EQUAL)
CConfig::SetSpaceAsPageDown((CStringRange::Compare(_locale, valueStrings.GetAt(0), &value.Set(L"1", 1)) == CSTR_EQUAL));
else if (CStringRange::Compare(_locale, &keyword, &testKey.Set(L"ArrowKeySWPages", 15)) == CSTR_EQUAL)
Expand Down Expand Up @@ -348,8 +352,7 @@ BOOL CDictionarySearch::FindWorker(BOOL isTextSearch, _Out_ CDictionaryResult **
else if (CStringRange::Compare(_locale, &keyword, &testKey.Set(L"SelectedItemColor", 18)) == CSTR_EQUAL)
CConfig::SetSelectedColor(wcstoul(valueStrings.GetAt(0)->Get(), NULL, 0));
else if (CStringRange::Compare(_locale, &keyword, &testKey.Set(L"SelectedBGItemColor", 20)) == CSTR_EQUAL)
CConfig::SetSelectedBGColor(wcstoul(valueStrings.GetAt(0)->Get(), NULL, 0));

CConfig::SetSelectedBGColor(wcstoul(valueStrings.GetAt(0)->Get(), NULL, 0));
else if (CStringRange::Compare(_locale, &keyword, &testKey.Set(L"FontFaceName", 12)) == CSTR_EQUAL)
{
WCHAR *pwszFontFaceName = new (std::nothrow) WCHAR[32];
Expand Down
2 changes: 1 addition & 1 deletion EndComposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void CTSFTTS::_EndComposition(_In_opt_ ITfContext *pContext)
CEndCompositionEditSession *pEditSession = new (std::nothrow) CEndCompositionEditSession(this, pContext);
HRESULT hr = S_OK;

if (nullptr != pEditSession)
if (pEditSession && pContext)
{
pContext->RequestEditSession(_tfClientId, pEditSession, TF_ES_ASYNCDONTCARE | TF_ES_READWRITE, &hr);
pEditSession->Release();
Expand Down
14 changes: 1 addition & 13 deletions Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,11 @@ HFONT defaultlFontHandle; // Global font object we use everywhere


//---------------------------------------------------------------------
// TSFDAYI CLSID
// TSFTTS CLSID
//---------------------------------------------------------------------
// {1DE68A87-FF3B-46A0-8F80-46730B2491B1}
extern const CLSID TSFTTSCLSID =
{ 0x1de68a87, 0xff3b, 0x46a0, { 0x8f, 0x80, 0x46, 0x73, 0xb, 0x24, 0x91, 0xb1 } };
//---------------------------------------------------------------------
// TSFARRAY CLSID
//---------------------------------------------------------------------
// {FD2D8F35-AF70-46DE-A08B-B76BDE8FED0F}
extern const CLSID TSFARRAYCLSID =
{ 0xfd2d8f35, 0xaf70, 0x46de, { 0xa0, 0x8b, 0xb7, 0x6b, 0xde, 0x8f, 0xed, 0xf } };
//---------------------------------------------------------------------
// TSFPHONETIC CLSID
//---------------------------------------------------------------------
// {9E6AC57A-BA61-4CD1-B582-0B4E7DA13C82}
extern const CLSID TSFPHONETICCLSID =
{ 0x9e6ac57a, 0xba61, 0x4cd1, { 0xb5, 0x82, 0xb, 0x4e, 0x7d, 0xa1, 0x3c, 0x82 } };



Expand Down
4 changes: 2 additions & 2 deletions Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ extern HFONT defaultlFontHandle; // Global font object we use everywhere


extern const CLSID TSFTTSCLSID;
extern const CLSID TSFARRAYCLSID;
extern const CLSID TSFPHONETICCLSID;


extern const GUID TSFDayiGuidProfile;
extern const GUID TSFArrayGuidProfile;
extern const GUID TSFPhoneticGuidProfile;
Expand Down
7 changes: 6 additions & 1 deletion KeyHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ HRESULT CTSFTTS::_HandleCompositionInput(TfEditCookie ec, _In_ ITfContext *pCont
CCompositionProcessorEngine* pCompositionProcessorEngine = nullptr;
pCompositionProcessorEngine = _pCompositionProcessorEngine;

if ((_pUIPresenter != nullptr)
if (_pUIPresenter && _pUIPresenter->IsNotifyShown())
{
_pUIPresenter->ClearNotify();
}

if (_pUIPresenter && _pUIPresenter->IsCandShown()
&& _candidateMode != CANDIDATE_INCREMENTAL &&_candidateMode != CANDIDATE_NONE )
{
_HandleCompositionFinalize(ec, pContext, TRUE);
Expand Down
22 changes: 17 additions & 5 deletions NotifyWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ CNotifyWindow::CNotifyWindow(_In_ NOTIFYWNDCALLBACK pfnCallback, _In_ void *pv)
_y =0;

_fontSize = 14;


_timeToHide = -1;
}

//+---------------------------------------------------------------------------
Expand Down Expand Up @@ -125,7 +126,7 @@ void CNotifyWindow::_ResizeWindow()
void CNotifyWindow::_Move(int x, int y)
{
_x = x;
_y = y + _cyTitle;
_y = y;
CBaseWindow::_Move(_x, _y);

}
Expand All @@ -135,13 +136,16 @@ void CNotifyWindow::_Move(int x, int y)
// _Show
//
//----------------------------------------------------------------------------

void CNotifyWindow::_Show(BOOL isShowWnd)
{
_Show(isShowWnd, _timeToHide);
}
void CNotifyWindow::_Show(BOOL isShowWnd, int timeToHide)
{
_timeToHide = timeToHide;
if (_pShadowWnd)
{
_pShadowWnd->_Show(isShowWnd);
}

CBaseWindow::_Show(isShowWnd);
if(isShowWnd && timeToHide > 0)
_StartTimer(timeToHide);//hide the window after timeToHide
Expand Down Expand Up @@ -516,6 +520,14 @@ void CNotifyWindow::_Clear()
_notifyText.Set(nullptr,0);
}

UINT CNotifyWindow::_GetWidth()
{
return _cxTitle;
}
UINT CNotifyWindow::_GetHeight()
{
return _cyTitle;
}


void CNotifyWindow::_FireMessageToLightDismiss(_In_ HWND wndHandle, _In_ WINDOWPOS *pWndPos)
Expand Down
Loading

0 comments on commit 3bfe305

Please sign in to comment.