📄 eqtapsmartenglish.cpp
字号:
// eQTapSmartEnglish.cpp: implementation of the CeQTapSmartEnglish class.
//
//////////////////////////////////////////////////////////////////////
#include "eQTapSmartEnglish.h"
#include "FepControl.h"
#include <stdio.h>
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CeQTapSmartEnglish::CeQTapSmartEnglish()
: m_pDictionaryEnglish(NULL),
m_pSentenceEnglish(NULL),
m_bSelectMode(FALSE),
m_bKeyMode(ENoMove),
m_bCurrentWordIsNull(CURRENT_WORD_NULL)
{
}
CeQTapSmartEnglish::~CeQTapSmartEnglish()
{
if(m_pDictionaryEnglish!=NULL)
{
PATTREE_FreeStaticDic(m_pDictionaryEnglish);
m_pDictionaryEnglish = NULL;
}
if(m_pSentenceEnglish!=NULL)
{
free(m_pSentenceEnglish);
m_pSentenceEnglish = NULL;
}
}
void CeQTapSmartEnglish::Active(TBool bActive)
{
m_bIsIMActive = bActive;
}
int CeQTapSmartEnglish::OnKeyEventProc(int nParameter1, int nParameter2)
{
int nReturn = KEY_RESULT_NOTPROCESSED;
TKeyResponse response = EKeyWasNotConsumed;
TKeyEvent* aKeyEvent = (TKeyEvent*)nParameter1;
TUint keyCode =0;
TEventCode aEventCode = (TEventCode)nParameter2;
if((aKeyEvent==NULL)||(m_bIsIMActive==FALSE)||(m_pSentenceEnglish==NULL)||(m_pDictionaryEnglish==NULL))
{
goto FuncExit;
}
keyCode = aKeyEvent->iCode;
switch (keyCode)
{
case '1':
if(m_pSentenceEnglish->szDigi[0]!=0)
{
m_bSelectMode=TRUE;
m_peQTapCtrl->FreshSEWindow();
response=EKeyWasConsumed;
}
else
{
response = EKeyWasConsumed;
}
break;
case '0':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
case '*':
case '#':
// printf( "Enter Key Proc\n" );
if (!m_peQTapCtrl->IsInlineEditTrans())
{
m_peQTapCtrl->StartInlineEdit(KNullDesC, 0, TRUE);
}
// printf( "StartInlineEdit \n" );
//先判断窗口是否打开
if(m_peQTapCtrl->GetWindowVisibleState()==FALSE)
{
ActiveSEWindow(TRUE);
}
// printf( "ActiveSEWindow \n" );
if (m_bSelectMode) //是选择模式,数字作为选择
{
OfferKeyEventInOKModeENL(keyCode);
}
else
{
if(m_pSentenceEnglish==NULL || m_pDictionaryEnglish==NULL)
{
return EKeyWasNotConsumed;
}
NEXTAP_AddDigi2SentenceEN(m_pSentenceEnglish,m_pDictionaryEnglish,keyCode);
// printf( "NEXTAP_AddDigi2SentenceEN \n" );
// CurrentChange ();
// printf( "CurrentChange \n" );
}
m_peQTapCtrl->FreshSEWindow();
// printf( "FreshSEWindow \n" );
response=EKeyWasConsumed;
break;
case EKeyBackspace:
if(m_bSelectMode==TRUE)
{
response = EKeyWasConsumed;
nReturn = response;
goto FuncExit;
}
if(m_pSentenceEnglish->szDigi[0]==0) //没有输入
{
response=EKeyWasNotConsumed;
}
else
{
NEXTAP_DelDigiFSentenceEN(m_pSentenceEnglish,m_pDictionaryEnglish);
if(m_pSentenceEnglish->szDigi[0]==0)
{
ResetValue();
m_peQTapCtrl->CommitInlineEdit(TRUE);
}
m_peQTapCtrl->FreshSEWindow();
m_bSelectMode=FALSE;
response=EKeyWasConsumed;
}
break;
case EKeyLeftArrow:
// response=OnKeyMoveLeft(aKeyEvent);// to be modify later
break;
case EKeyRightArrow:
// response=OnKeyMoveRight(aKeyEvent);// to be modify later
break;
case EKeyUpArrow:
response=OnKeyMoveUp(*aKeyEvent);
break;
case EKeyDownArrow:
response=OnKeyMoveDown(*aKeyEvent);
break;
case EKeyOK:
if(m_pSentenceEnglish->szDigi[0]!=0)
{
response=OfferKeyEventInOKModeENL('7');
response = EKeyWasConsumed;
ActiveSEWindow(TRUE);
m_peQTapCtrl->FreshSEWindow();
}
else
{
ActiveSEWindow(FALSE);
response = EKeyWasConsumed;
}
break;
}
nReturn =response;
FuncExit:
return nReturn;
}
int CeQTapSmartEnglish::OnDrawIMWindow()
{
int nReturn = 0;
return nReturn;
}
CeQTapSmartEnglish* CeQTapSmartEnglish::NewL(CeQTapControl* pControl)
{
CeQTapSmartEnglish* self = new(ELeave)CeQTapSmartEnglish(pControl);
CleanupStack::PushL(self);
self->ConstructL();
CleanupStack::Pop(); // self
return self;
}
CeQTapSmartEnglish::CeQTapSmartEnglish(CeQTapControl* pControl)
: m_pDictionaryEnglish(NULL),
m_pSentenceEnglish(NULL),
m_bSelectMode(FALSE),
m_bKeyMode(ENoMove)
{
m_peQTapCtrl = pControl;
m_bIsIMActive = FALSE;
}
void CeQTapSmartEnglish::ConstructL()
{
}
void CeQTapSmartEnglish::OpenDictionary()
{
int nSize =0;
if (NEXTAP_GetSentenceBufferSize()>NEXTAP_GetSentenceBufferSizeEN())
{
nSize=NEXTAP_GetSentenceBufferSize();
}
else
{
nSize=NEXTAP_GetSentenceBufferSizeEN();
}
m_pSentenceEnglish = (OUTBUFFER*)malloc(nSize);
if (m_pSentenceEnglish==NULL)
{
/*we should do something here*/
}
m_pSentenceEnglish->szDigi[0]=0;
m_pSentenceEnglish->nNextPredictCharNumber = 0;
m_pSentenceEnglish->szAllInput[0] = 0;
#ifdef __WINS__
m_pDictionaryEnglish= (int*)PATTREE_LoadStaticDic((const unsigned short *)L"z:\\system\\fep\\dic_en.bin",NULL);
#else
m_pDictionaryEnglish= (int*)PATTREE_LoadStaticDic((const unsigned short *)L"c:\\system\\fep\\dic_en.bin",NULL);
#endif
if (m_pDictionaryEnglish==NULL) //
{
/*we should do something here*/
}
}
TKeyResponse CeQTapSmartEnglish::OfferKeyEventInOKModeENL(TUint keyCode)
{
int Select;
TBuf<32> iWholeSentence;
TKeyResponse response = EKeyWasNotConsumed;
switch (keyCode)
{
case '7':
Select = 0;
break;
case '8':
Select = 1;
break;
case '9':
Select = 2;
break;
case '*':
Select = 3;
break;
case '0':
Select = 4;
break;
case '#':
Select = 5;
break;
default:
response = EKeyWasConsumed;
goto FuncExit;
break;
}
//提交选择
#ifdef ENGLISH_UNIFIED
iWholeSentence.Format(_L("%s "),m_pSentenceEnglish->pszUnifiedCand[Select]);
#else
iWholeSentence.Format(_L("%s "),m_pSentenceEnglish->pszCand[Select]);
#endif
m_peQTapCtrl->UpdateInlineEditL(iWholeSentence,iWholeSentence.Length());
m_peQTapCtrl->CommitInlineEdit(TRUE);
//调整词频
NEXTAP_ChooseCandPredictEN(m_pSentenceEnglish, m_pDictionaryEnglish,Select, TRUE ,0);
NEXTAP_ResetSentenceEN(m_pSentenceEnglish, m_pDictionaryEnglish, m_pSentenceEnglish->IMMethod, MAXCAND*2 , MAXCAND*2);
ResetValue();
m_bSelectMode = FALSE;
m_bKeyMode = ENoMove;
FuncExit:
return EKeyWasNotConsumed;
}
void CeQTapSmartEnglish::ResetValue()
{
if(m_pSentenceEnglish!=NULL)
{
m_pSentenceEnglish->szPinyin [0]=0;
m_pSentenceEnglish->szCurWordPinyin[0]=0;
}
}
void CeQTapSmartEnglish::ActiveSEWindow(TBool aActive)
{
TPoint fepControlPos;
RWindow& window = m_peQTapCtrl->GetRWindow();
/*
fepControlPos.iX=0;
fepControlPos.iY=162;
SetExtent(fepControlPos, TSize(176,45));
window.SetExtent(fepControlPos, TSize(176,45));
*/
fepControlPos.iX=0;
fepControlPos.iY=191;
SetExtent(fepControlPos, TSize(176,16));
window.SetExtent(fepControlPos, TSize(176,16));
if (aActive == TRUE) //打开输入法窗口
{
window.SetVisible(ETrue);
m_peQTapCtrl->SetWindowVisibleState(TRUE);
}
else //关闭输入法窗口
{
window.SetVisible(EFalse);
m_peQTapCtrl->SetWindowVisibleState(FALSE);
}
}
void CeQTapSmartEnglish::SwitchToSmartEnglish()
{
if(m_pSentenceEnglish==NULL)
{
OpenDictionary();
}
ResetValue();
NEXTAP_ResetSentenceEN(m_pSentenceEnglish, m_pDictionaryEnglish, PATTREE_EN_LOWERCASE,MAXCAND*2,MAXCAND*2);
ActiveSEWindow(EFalse);
m_bKeyMode = ENoMove;
m_bSelectMode = EFalse;
}
void CeQTapSmartEnglish::DrawSmartEnglish() const
{
CWindowGc& gc = SystemGc();
TRect rect = Rect();
TRect tmpRect;
TBuf<32> prompt;
TBuf<5> signalWord;
TBuf<64> sentenceWord;
TInt pos = 0;
TInt sentencePos = 0;
gc.Clear();
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.SetPenStyle(CGraphicsContext::ENullPen);
/*
//画上面的两个部分
tmpRect.SetRect(0,0,rect.Width(),29);
gc.SetBrushColor(DISPLAYBRUSHCOLOR);
gc.DrawRect(tmpRect);
*/
//画下面的被选
tmpRect=rect;
// tmpRect.SetRect(0,18,rect.Width(),rect.Height());
tmpRect.SetRect(0,0,rect.Width(),rect.Height());
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -