Skip to content

Commit

Permalink
1. bug fixed on phrase candidate select by number not working properly
Browse files Browse the repository at this point in the history
2. CNotifyWindow updated (not finished).
  • Loading branch information
jrywu committed Aug 1, 2013
1 parent cb4a009 commit 935000c
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 48 deletions.
67 changes: 46 additions & 21 deletions CompositionProcessorEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,45 @@ BOOL CCompositionProcessorEngine::IsSymbolChar(WCHAR wch)
return FALSE;
}

//+---------------------------------------------------------------------------
//
// IsAddressChar
//
//----------------------------------------------------------------------------
BOOL CCompositionProcessorEngine::IsAddressChar(WCHAR wch)
{
if(_keystrokeBuffer.Get() == nullptr || (_keystrokeBuffer.Get() && (_keystrokeBuffer.GetLength() == 0)))
{
for (int i = 0; i < ARRAYSIZE(Global::addressCharTable); i++)
{
if (Global::addressCharTable[i]._Code == wch)
{
return TRUE;
}
}

}
return FALSE;
}

//+---------------------------------------------------------------------------
//
// GetAddressChar
//
//----------------------------------------------------------------------------

WCHAR CCompositionProcessorEngine::GetAddressChar(WCHAR wch)
{
for (int i = 0; i < ARRAYSIZE(Global::addressCharTable); i++)
{
if (Global::addressCharTable[i]._Code == wch)
{
return Global::addressCharTable[i]._AddressChar;
}
}
return 0;
}



//+---------------------------------------------------------------------------
Expand Down Expand Up @@ -1987,24 +2026,7 @@ BOOL CCompositionProcessorEngine::IsVirtualKeyNeed(UINT uCode, _In_reads_(1) WCH
}
}
}
/*
if (candidateMode == CANDIDATE_PHRASE) //never seen here.
{
switch (uCode)
{
case VK_UP: if (pKeyState) { pKeyState->Category = CATEGORY_PHRASE; pKeyState->Function = FUNCTION_MOVE_UP; } return TRUE;
case VK_DOWN: if (pKeyState) { pKeyState->Category = CATEGORY_PHRASE; pKeyState->Function = FUNCTION_MOVE_DOWN; } return TRUE;
case VK_PRIOR: if (pKeyState) { pKeyState->Category = CATEGORY_PHRASE; pKeyState->Function = FUNCTION_MOVE_PAGE_UP; } return TRUE;
case VK_NEXT: if (pKeyState) { pKeyState->Category = CATEGORY_PHRASE; pKeyState->Function = FUNCTION_MOVE_PAGE_DOWN; } return TRUE;
case VK_HOME: if (pKeyState) { pKeyState->Category = CATEGORY_PHRASE; pKeyState->Function = FUNCTION_MOVE_PAGE_TOP; } return TRUE;
case VK_END: if (pKeyState) { pKeyState->Category = CATEGORY_PHRASE; pKeyState->Function = FUNCTION_MOVE_PAGE_BOTTOM; } return TRUE;
case VK_RETURN: if (pKeyState) { pKeyState->Category = CATEGORY_PHRASE; pKeyState->Function = FUNCTION_FINALIZE_CANDIDATELIST; } return TRUE;
case VK_SPACE: if (pKeyState) { pKeyState->Category = CATEGORY_PHRASE; pKeyState->Function = FUNCTION_CONVERT; } return TRUE;
case VK_ESCAPE: if (pKeyState) { pKeyState->Category = CATEGORY_PHRASE; pKeyState->Function = FUNCTION_CANCEL; } return TRUE;
case VK_BACK: if (pKeyState) { pKeyState->Category = CATEGORY_CANDIDATE; pKeyState->Function = FUNCTION_CANCEL; } return TRUE;
}
}
*/

if (IsKeystrokeRange(uCode, pKeyState, candidateMode))
{
return TRUE;
Expand Down Expand Up @@ -2077,6 +2099,7 @@ BOOL CCompositionProcessorEngine::IsVirtualKeyKeystrokeComposition(UINT uCode, _

BOOL CCompositionProcessorEngine::IsVirtualKeyKeystrokeCandidate(UINT uCode, _In_ _KEYSTROKE_STATE *pKeyState, CANDIDATE_MODE candidateMode, _Out_ BOOL *pfRetCode, _In_ CTSFDayiArray<_KEYSTROKE> *pKeystrokeMetric)
{
candidateMode;
if (pfRetCode == nullptr)
{
return FALSE;
Expand All @@ -2094,8 +2117,9 @@ BOOL CCompositionProcessorEngine::IsVirtualKeyKeystrokeCandidate(UINT uCode, _In
*pfRetCode = TRUE;
if (pKeyState)
{
pKeyState->Category = (candidateMode == CANDIDATE_ORIGINAL ? CATEGORY_CANDIDATE :
candidateMode == CANDIDATE_PHRASE ? CATEGORY_PHRASE : CATEGORY_CANDIDATE);
pKeyState->Category = CATEGORY_CANDIDATE;
//(candidateMode == CANDIDATE_ORIGINAL ? CATEGORY_CANDIDATE :
//candidateMode == CANDIDATE_PHRASE ? CATEGORY_PHRASE : CATEGORY_CANDIDATE);

pKeyState->Function = pKeystroke->Function;
}
Expand Down Expand Up @@ -2130,7 +2154,8 @@ BOOL CCompositionProcessorEngine::IsKeystrokeRange(UINT uCode, _Out_ _KEYSTROKE_
if ((GetCandidateListPhraseModifier() == 0 && (Global::ModifiersValue & (TF_MOD_LSHIFT | TF_MOD_SHIFT) )!= 0) || //shift + 123...
(GetCandidateListPhraseModifier() != 0 && Global::CheckModifiers(Global::ModifiersValue, GetCandidateListPhraseModifier())))
{
pKeyState->Category = CATEGORY_PHRASE; pKeyState->Function = FUNCTION_SELECT_BY_NUMBER;
pKeyState->Category = CATEGORY_CANDIDATE;//CATEGORY_PHRASE;
pKeyState->Function = FUNCTION_SELECT_BY_NUMBER;
return TRUE;
}
else
Expand Down
4 changes: 4 additions & 0 deletions CompositionProcessorEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ class CCompositionProcessorEngine
BOOL IsSymbolChar(WCHAR wch);
BOOL IsSymbol();

//Address characters direct input
BOOL IsAddressChar(WCHAR wch);
WCHAR GetAddressChar(WCHAR wch);

BOOL IsDoubleSingleByte(WCHAR wch);
BOOL IsWildcard() { return _isWildcard; }
BOOL IsDisableWildcardAtFirst() { return _isDisableWildcardAtFirst; }
Expand Down
4 changes: 2 additions & 2 deletions Define.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
#define NOTIFYWND_ROW_WIDTH (30)
#define NOTIFYWND_BORDER_COLOR (RGB(0x00, 0x00, 0x00))
#define NOTIFYWND_BORDER_WIDTH (2)
#define NOTIFYWND_TEXT_COLOR (RGB(0xFF, 0xFF, 0xFF))
#define NOTIFYWND_TEXT_BK_COLOR (RGB(0xA6, 0xA6, 0x00))
#define NOTIFYWND_TEXT_COLOR (RGB(0x00, 0x00, 0x00))
#define NOTIFYWND_TEXT_BK_COLOR (RGB(0xFF, 0xFF, 0xFF))

//---------------------------------------------------------------------
// defined modifier
Expand Down
11 changes: 11 additions & 0 deletions Globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,17 @@ extern const WCHAR FullWidthCharTable[] = {
extern const WCHAR symbolCharTable[25] = {
L' ', L'!', L'@', L'\\', L'\"', L'#', L'$', L'%', L'&', L'\'', L'(', L')', L'+', L':', L'<', L'>', L'[', L']', L'^', L'_', L'`', L'{', L'}', L'|', L'~'
};
//---------------------------------------------------------------------
// defined directly input address characters
//---------------------------------------------------------------------
extern const _AddressDirectInput addressCharTable[5] = {
{L'\'', L'¸¹'},
{L'[', L'¸ô'},
{L']', L'µó'},
{L'-', L'¶m'},
{L'\\', L'Âí'}
};


//+---------------------------------------------------------------------------
//
Expand Down
1 change: 1 addition & 0 deletions Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ extern const GUID TSFDayiGuidCompartmentPunctuation;

extern const WCHAR FullWidthCharTable[];
extern const WCHAR symbolCharTable[25];
extern const _AddressDirectInput addressCharTable[5];

extern const GUID TSFDayiGuidLangBarIMEMode;
extern const GUID TSFDayiGuidLangBarDoubleSingleByte;
Expand Down
16 changes: 15 additions & 1 deletion KeyEventSink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,24 @@ BOOL CTSFDayi::_IsKeyEaten(_In_ ITfContext *pContext, UINT codeIn, _Out_ UINT *p
CCompositionProcessorEngine *pCompositionProcessorEngine;
pCompositionProcessorEngine = _pCompositionProcessorEngine;


//
// Address characters direct input mode '[]-\
//
if (isOpen && _candidateMode == CANDIDATE_NONE && pCompositionProcessorEngine->IsAddressChar(wch))
{
if (pKeyState)
{
pKeyState->Category = CATEGORY_COMPOSING;
pKeyState->Function = FUNCTION_ADDRESS_DIRECT_INPUT;
}
return TRUE;
}

//
// Symbol mode start with L'='
//
if (pCompositionProcessorEngine->IsSymbolChar(wch))
if (isOpen && pCompositionProcessorEngine->IsSymbolChar(wch))
{
if (pKeyState)
{
Expand Down
36 changes: 33 additions & 3 deletions KeyHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,6 @@ HRESULT CTSFDayi::_HandleCompositionInputWorker(_In_ CCompositionProcessorEngine
_pTSFDayiUIPresenter->Show(TRUE);
}

if(candidateList.Count() ==1)
_HandleCandidateFinalize(ec, pContext);

}
else if (_pTSFDayiUIPresenter)
Expand Down Expand Up @@ -423,7 +421,7 @@ HRESULT CTSFDayi::_HandleCompositionConvert(TfEditCookie ec, _In_ ITfContext *pC
_pTSFDayiUIPresenter->_SetText(&candidateList, FALSE);
}
}
if(nCount==1) //finalized with the only candidate without showing cand.
if(nCount==1 ) //finalized with the only candidate without showing cand.
{
_HandleCandidateFinalize(ec, pContext);
}
Expand Down Expand Up @@ -568,6 +566,38 @@ HRESULT CTSFDayi::_HandleCompositionDoubleSingleByte(TfEditCookie ec, _In_ ITfCo
}


//+---------------------------------------------------------------------------
//
// _HandleAddressChar
//
//----------------------------------------------------------------------------

HRESULT CTSFDayi::_HandleCompositionAddressChar(TfEditCookie ec, _In_ ITfContext *pContext, WCHAR wch)
{
HRESULT hr = S_OK;

//
// Get punctuation char from composition processor engine
//
CCompositionProcessorEngine* pCompositionProcessorEngine = nullptr;
pCompositionProcessorEngine = _pCompositionProcessorEngine;

WCHAR addressChar = pCompositionProcessorEngine->GetAddressChar(wch);

CStringRange addressCharString;
addressCharString.Set(&addressChar, 1);

// Finalize character
hr = _AddCharAndFinalize(ec, pContext, &addressCharString);
if (FAILED(hr))
{
return hr;
}

_HandleCancel(ec, pContext);

return S_OK;
}

//+---------------------------------------------------------------------------
//
Expand Down
16 changes: 14 additions & 2 deletions KeyStateCategory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ HRESULT CKeyStateCategory::KeyStateHandler(KEYSTROKE_FUNCTION function, KeyHandl
case FUNCTION_DOUBLE_SINGLE_BYTE:
return HandleKeyDoubleSingleByte(dto);

//case FUNCTION_PUNCTUATION:
// return HandleKeyPunctuation(dto);
case FUNCTION_ADDRESS_DIRECT_INPUT:
return HandleKeyAddressChar(dto);

case FUNCTION_SELECT_BY_NUMBER:
return HandleKeySelectByNumber(dto);
Expand Down Expand Up @@ -224,6 +224,14 @@ HRESULT CKeyStateCategory::HandleKeySelectByNumber(KeyHandlerEditSessionDTO dto)
return E_NOTIMPL;
}

HRESULT CKeyStateCategory::HandleKeyAddressChar(KeyHandlerEditSessionDTO dto)
{
dto;
return E_NOTIMPL;
}



/*
class CKeyStateComposing
*/
Expand Down Expand Up @@ -288,6 +296,10 @@ HRESULT CKeyStateComposing::HandleKeyDoubleSingleByte(KeyHandlerEditSessionDTO d
return _pTextService->_HandleCompositionDoubleSingleByte(dto.ec, dto.pContext, dto.wch);
}

HRESULT CKeyStateComposing::HandleKeyAddressChar(KeyHandlerEditSessionDTO dto)
{
return _pTextService->_HandleCompositionAddressChar(dto.ec, dto.pContext, dto.wch);
}


/*
Expand Down
8 changes: 8 additions & 0 deletions KeyStateCategory.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ class CKeyStateCategory
// HandleKeySelectByNumber
virtual HRESULT HandleKeySelectByNumber(KeyHandlerEditSessionDTO dto);

// HandleKeyAddressChar
virtual HRESULT HandleKeyAddressChar(KeyHandlerEditSessionDTO dto);


protected:
CTSFDayi* _pTextService;
};
Expand Down Expand Up @@ -140,6 +144,10 @@ class CKeyStateComposing : public CKeyStateCategory
// HandleKeyDoubleSingleByte
HRESULT HandleKeyDoubleSingleByte(KeyHandlerEditSessionDTO dto);

// HandleKeyAddressChar
HRESULT HandleKeyAddressChar(KeyHandlerEditSessionDTO dto);


};

class CKeyStateCandidate : public CKeyStateCategory
Expand Down
21 changes: 8 additions & 13 deletions NotifyWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@

CNotifyWindow::CNotifyWindow(_In_ NOTIFYWNDCALLBACK pfnCallback, _In_ void *pv)
{

_SetTextColor(CANDWND_ITEM_COLOR, GetSysColor(COLOR_WINDOW)); // text color is black
_SetFillColor((HBRUSH)(COLOR_WINDOW+1));



_pfnCallback = pfnCallback;
_pObj = pv;

_pShadowWnd = nullptr;
_cxTitle = 0;
_wndWidth = 0;
_cxTitle = 50;
_wndWidth = 50;


}
Expand All @@ -51,10 +47,9 @@ CNotifyWindow::~CNotifyWindow()
// CandidateWinow is the top window
//----------------------------------------------------------------------------

BOOL CNotifyWindow::_Create(ATOM atom, _In_ UINT wndWidth, _In_opt_ HWND parentWndHandle)
BOOL CNotifyWindow::_Create(ATOM atom, _In_opt_ HWND parentWndHandle)
{
BOOL ret = FALSE;
_wndWidth = wndWidth;

ret = _CreateMainWindow(atom, parentWndHandle);
if (FALSE == ret)
Expand Down Expand Up @@ -115,7 +110,7 @@ void CNotifyWindow::_ResizeWindow()
{
SIZE size = {0, 0};

_cxTitle = max(_cxTitle, size.cx + 2 * GetSystemMetrics(SM_CXFRAME));
//_cxTitle = max(_cxTitle, size.cx + 2 * GetSystemMetrics(SM_CXFRAME));


CBaseWindow::_Resize(0, 0, _cxTitle, _wndWidth); //x, y, cx, cy
Expand Down Expand Up @@ -189,7 +184,7 @@ LRESULT CALLBACK CNotifyWindow::_WindowProcCallback(_In_ HWND wndHandle, UINT uM
HFONT hFontOld = (HFONT)SelectObject(dcHandle, Global::defaultlFontHandle);
GetTextMetrics(dcHandle, &_TextMetric);

_cxTitle = _TextMetric.tmMaxCharWidth * _wndWidth;
//_cxTitle = _TextMetric.tmMaxCharWidth * _wndWidth;
SelectObject(dcHandle, hFontOld);
ReleaseDC(wndHandle, dcHandle);
}
Expand Down Expand Up @@ -347,7 +342,6 @@ void CNotifyWindow::_OnPaint(_In_ HDC dcHandle, _In_ PAINTSTRUCT *pPaintStruct)

FillRect(dcHandle, &pPaintStruct->rcPaint, _brshBkColor);


_DrawText(dcHandle, &pPaintStruct->rcPaint);

//cleanup:
Expand Down Expand Up @@ -492,7 +486,8 @@ void CNotifyWindow::_SetString(_Inout_ const WCHAR *pNotifyText)
{
return;
}
memcpy((void*)pwchString, notifyText.Get(), notifyTextLen * sizeof(WCHAR)+1);
StringCchCopyN(pwchString, notifyTextLen + 1, pNotifyText, notifyTextLen);
notifyText.Set(pwchString, notifyTextLen);
}


Expand Down
4 changes: 2 additions & 2 deletions NotifyWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ enum NOTIFYWND_ACTION
CLICK_TO_DISMISS
};

typedef HRESULT (*NOTIFYWNDCALLBACK)(void *pv, enum NOTIFYWND_ACTION action);
typedef HRESULT (*NOTIFYWNDCALLBACK)(void *pv);

class CNotifyWindow : public CBaseWindow
{
public:
CNotifyWindow(_In_ NOTIFYWNDCALLBACK pfnCallback, _In_ void *pv);
virtual ~CNotifyWindow();

BOOL _Create(ATOM atom, _In_ UINT notifyWidth, _In_opt_ HWND parentWndHandle);
BOOL _Create(ATOM atom, _In_opt_ HWND parentWndHandle);

void _Move(int x, int y);
void _Show(BOOL isShowWnd);
Expand Down
1 change: 1 addition & 0 deletions TSFDayi.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class CTSFDayi : public ITfTextInputProcessorEx,
HRESULT _HandleCompositionBackspace(TfEditCookie ec, _In_ ITfContext *pContext);
HRESULT _HandleCompositionArrowKey(TfEditCookie ec, _In_ ITfContext *pContext, KEYSTROKE_FUNCTION keyFunction);
HRESULT _HandleCompositionDoubleSingleByte(TfEditCookie ec, _In_ ITfContext *pContext, WCHAR wch);
HRESULT _HandleCompositionAddressChar(TfEditCookie ec, _In_ ITfContext *pContext, WCHAR wch);
// function for textlayoutchange.
HRESULT _HandlTextLayoutChange(TfEditCookie ec, _In_ ITfContext *pContext, _In_ ITfRange *pRangeComposition);

Expand Down
Loading

0 comments on commit 935000c

Please sign in to comment.