⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eqtapsmartchinese.cpp

📁 Symbian平台 数字键盘手机输入法源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// eQTapSmartChinese.cpp: implementation of the CeQTapSmartChinese class.
//
//////////////////////////////////////////////////////////////////////

#include "eQTapSmartChinese.h"
#include "FepControl.h"

#include "String.h"
#include <stdio.h>

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CeQTapSmartChinese::CeQTapSmartChinese()
:	m_pDictionaryChinese(NULL),
	m_pSentenceChinese(NULL),
	m_bSelectMode(FALSE),
	m_bKeyMode(ENoMove),
	m_bCurrentWordIsNull(CURRENT_WORD_NOT_NULL)
{

}

CeQTapSmartChinese::~CeQTapSmartChinese()
{
	if(m_peQTapCtrl->GetChineseDictionary()!=NULL)
	{
		NEXTAP_WriteStaticDic((const unsigned short *)L"c:\\udic.bin",m_peQTapCtrl->GetChineseDictionary());
		PATTREE_FreeStaticDic(m_peQTapCtrl->GetChineseDictionary());
		m_peQTapCtrl->SetChineseDictionary(NULL);
	}
	if(m_peQTapCtrl->GetChineseSentence()!=NULL)
	{
		free(m_peQTapCtrl->GetChineseSentence());
		m_peQTapCtrl->SetChineseSentence ( NULL);
	}
}
int CeQTapSmartChinese::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))
	{
		goto FuncExit;
	}
#ifndef SMARTCHINESE_OPENDIC_ATKEYPRESS
	if((m_pSentenceChinese==NULL)||(m_pDictionaryChinese==NULL))
	{
		goto FuncExit;
	}
#endif //SMARTCHINESE_OPENDIC_ATKEYPRESS

	keyCode = aKeyEvent->iCode;

	switch (keyCode)
	{
	case '1':
#ifdef SMARTCHINESE_OPENDIC_ATKEYPRESS
		if(m_pSentenceChinese==NULL)
		{
			OpenDictionary();
			if((m_pSentenceChinese==NULL)||(m_pDictionaryChinese==NULL))
			{
				printf( "Open Chinese Dictionary Error!\n" );
				goto FuncExit;
			}
			ResetValue();
			NEXTAP_ResetSentence(m_pSentenceChinese, m_pDictionaryChinese, PATTREE_CHS_PINYIN,MAXCAND,MAXCAND);
			ActiveSCWindow(EFalse);
			m_bKeyMode     = ENoMove;
			m_bSelectMode  = EFalse;
		}
#endif
		if(m_peQTapCtrl->GetWindowVisibleState()==FALSE)
		{
			ActiveSCWindow(TRUE);
		}
//		if(m_pSentenceChinese->szDigi[0]!=0)
		{
			m_bSelectMode=TRUE;
			m_peQTapCtrl->FreshSCWindow();
			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 '#':
#ifdef SMARTCHINESE_OPENDIC_ATKEYPRESS
		if(m_pSentenceChinese==NULL)
		{
			OpenDictionary();
			if((m_pSentenceChinese==NULL)||(m_pDictionaryChinese==NULL))
			{
				printf( "Open Chinese Dictionary Error!\n" );
				goto FuncExit;
			}
			ResetValue();
			NEXTAP_ResetSentence(m_pSentenceChinese, m_pDictionaryChinese, PATTREE_CHS_PINYIN,MAXCAND,MAXCAND);
			ActiveSCWindow(EFalse);
			m_bKeyMode     = ENoMove;
			m_bSelectMode  = EFalse;
		}
#endif
 		if (!m_peQTapCtrl->IsInlineEditTrans())
		{ 
			m_peQTapCtrl->StartInlineEdit(KNullDesC, 0, TRUE);
		}
		//先判断窗口是否打开
		if(m_peQTapCtrl->GetWindowVisibleState()==FALSE)
		{
			ActiveSCWindow(TRUE);
		}

		if (m_bSelectMode)       //是选择模式,数字作为选择
		{
 			OfferKeyEventInOKModeL(keyCode);// to be modify later
		}
		else
		{
			if(m_pSentenceChinese==NULL || m_pDictionaryChinese==NULL)
			{
				return EKeyWasNotConsumed;
			}
			NEXTAP_AddDigi2Sentence(m_pSentenceChinese,m_pDictionaryChinese,keyCode);
			CurrentChange ();	
		}
		m_peQTapCtrl->FreshSCWindow();
		response=EKeyWasConsumed;
		break;
	case EKeyBackspace:
#ifdef SMARTCHINESE_OPENDIC_ATKEYPRESS
		if((m_pSentenceChinese==NULL)||(m_pDictionaryChinese==NULL))
		{
			goto FuncExit;
		}
#endif //SMARTCHINESE_OPENDIC_ATKEYPRESS
		if (m_bKeyMode == EMoveLRUD)
		{
			response = EKeyWasConsumed;
			nReturn = response;
			goto FuncExit;
		}
		if(m_pSentenceChinese->szDigi[0]==0)        //没有输入
		{
			response=EKeyWasNotConsumed;
		}
		else
		{

			NEXTAP_DelDigiFSentence(m_pSentenceChinese,m_pDictionaryChinese);
			if(m_pSentenceChinese->szDigi[0]==0)
			{
				NEXTAP_ResetSentence(m_pSentenceChinese, m_pDictionaryChinese, m_pSentenceChinese->IMMethod, MAXCAND , MAXCAND  );
				ResetValue();
				m_peQTapCtrl->CommitInlineEdit(TRUE);
			}
			m_peQTapCtrl->FreshSCWindow();
			m_bSelectMode=FALSE;
			response=EKeyWasConsumed;
		}
		break;
	case EKeyLeftArrow:
#ifdef SMARTCHINESE_OPENDIC_ATKEYPRESS
		if((m_pSentenceChinese==NULL)||(m_pDictionaryChinese==NULL))
		{
			goto FuncExit;
		}
#endif //SMARTCHINESE_OPENDIC_ATKEYPRESS
		response=OnKeyMoveLeft(*aKeyEvent);// to be modify later
		break;
	case EKeyRightArrow:		
#ifdef SMARTCHINESE_OPENDIC_ATKEYPRESS
		if((m_pSentenceChinese==NULL)||(m_pDictionaryChinese==NULL))
		{
			goto FuncExit;
		}
#endif //SMARTCHINESE_OPENDIC_ATKEYPRESS
		response=OnKeyMoveRight(*aKeyEvent);// to be modify later
		break;
	case EKeyUpArrow:
#ifdef SMARTCHINESE_OPENDIC_ATKEYPRESS
		if((m_pSentenceChinese==NULL)||(m_pDictionaryChinese==NULL))
		{
			goto FuncExit;
		}
#endif //SMARTCHINESE_OPENDIC_ATKEYPRESS
		response=OnKeyMoveUp(*aKeyEvent);
		break;			
	case EKeyDownArrow:
#ifdef SMARTCHINESE_OPENDIC_ATKEYPRESS
		if((m_pSentenceChinese==NULL)||(m_pDictionaryChinese==NULL))
		{
			goto FuncExit;
		}
#endif //SMARTCHINESE_OPENDIC_ATKEYPRESS
		response=OnKeyMoveDown(*aKeyEvent);
		break;
	case EKeyOK:
#ifdef SMARTCHINESE_OPENDIC_ATKEYPRESS
		if((m_pSentenceChinese==NULL)||(m_pDictionaryChinese==NULL))
		{
			goto FuncExit;
		}
#endif //SMARTCHINESE_OPENDIC_ATKEYPRESS
		if(m_pSentenceChinese->szDigi[0]!=0)
		{
			response=OfferKeyEventInOKModeL(-1);
			m_peQTapCtrl->FreshSCWindow();
			m_bSelectMode=FALSE;
		}
		else
		{
			ActiveSCWindow(FALSE);
			response = EKeyWasConsumed;
		}
		break;
	}
	nReturn =response;
FuncExit:
	return nReturn;
}
int CeQTapSmartChinese::OnDrawSCWindow()
{
	int nReturn = KEY_RESULT_NOTPROCESSED;
	return nReturn;
}

CeQTapSmartChinese* CeQTapSmartChinese::NewL(CeQTapControl* pControl)
{
	CeQTapSmartChinese* self = new(ELeave)CeQTapSmartChinese(pControl);
	CleanupStack::PushL(self);
	self->ConstructL();
	CleanupStack::Pop();	// self
	return self;
}

CeQTapSmartChinese::CeQTapSmartChinese(CeQTapControl* pControl)
:	m_pDictionaryChinese(NULL),
	m_pSentenceChinese(NULL),
	m_bSelectMode(FALSE),
	m_bKeyMode(ENoMove),
	m_bCurrentWordIsNull(CURRENT_WORD_NOT_NULL)
{
	m_peQTapCtrl = pControl;
	m_bIsIMActive = FALSE;
}

void CeQTapSmartChinese::ConstructL()
{
}

void CeQTapSmartChinese::SwitchToSmartChinese()
{
#ifndef SMARTCHINESE_OPENDIC_ATKEYPRESS
	if(m_pSentenceChinese==NULL)
	{
		OpenDictionary();
	}
	if((m_pSentenceChinese==NULL)||(m_pDictionaryChinese==NULL))
	{
		printf( "Open Chinese Dictionary Error!\n" );
		return;
	}
#else //SMARTCHINESE_OPENDIC_ATKEYPRESS
	if((m_pSentenceChinese==NULL)||(m_pDictionaryChinese==NULL))
	{
		ActiveSCWindow(EFalse);
		m_bKeyMode     = ENoMove;
		m_bSelectMode  = EFalse;
		return;
	}
#endif //SMARTCHINESE_OPENDIC_ATKEYPRESS
	ResetValue();
	NEXTAP_ResetSentence(m_pSentenceChinese, m_pDictionaryChinese, PATTREE_CHS_PINYIN,MAXCAND,MAXCAND);
	ActiveSCWindow(EFalse);
	m_bKeyMode     = ENoMove;
	m_bSelectMode  = EFalse;
}

void CeQTapSmartChinese::ActiveSCWindow(TBool bActive)
{
	TPoint fepControlPos;
	RWindow& window = m_peQTapCtrl->GetRWindow();

	fepControlPos.iX=0;
	fepControlPos.iY=162;
	SetExtent(fepControlPos, TSize(176,45));
	window.SetExtent(fepControlPos, TSize(176,45));

  if (bActive == TRUE)  //打开输入法窗口	
	{
		window.SetVisible(ETrue);
		m_peQTapCtrl->SetWindowVisibleState(TRUE);
	}
	else                 //关闭输入法窗口
	{
		window.SetVisible(EFalse);
		m_peQTapCtrl->SetWindowVisibleState(FALSE);
	}
}
TBool CeQTapSmartChinese::CurrentChange()
{
	int pnCharBegin, pnCharEnd, pnDigiBegin, pnDigiEnd;
	

    NEXTAP_GetActiveWordInfo(m_pSentenceChinese, m_pDictionaryChinese, &pnCharBegin, &pnCharEnd, &pnDigiBegin, &pnDigiEnd);
	if(pnDigiBegin==0) 
	{
		m_bCurrentWordIsNull=CURRENT_WORD_NOT_NULL;
		return FALSE;
	}
	else
	{
		m_bCurrentWordIsNull=CURRENT_WORD_NULL;
		return TRUE;
	}
}
void CeQTapSmartChinese::ResetValue()
{
	if(m_pSentenceChinese!=NULL)
	{
		m_pSentenceChinese->szPinyin [0]=0;
		m_pSentenceChinese->szCurWordPinyin[0]=0;
		m_pSentenceChinese->szAllInput[0] = 0;
		m_pSentenceChinese->nNextPredictCharNumber = 0;
	}
}
void CeQTapSmartChinese::OpenDictionary()
{
	int nSize =0;
	if (NEXTAP_GetSentenceBufferSize()>NEXTAP_GetSentenceBufferSizeEN())
	{
			nSize=NEXTAP_GetSentenceBufferSize();
	}
	else
	{
			nSize=NEXTAP_GetSentenceBufferSizeEN();
	}
	
	if(m_peQTapCtrl->GetChineseSentence()==NULL)
	{
		m_pSentenceChinese = (OUTBUFFER*)malloc(nSize);
		if (m_pSentenceChinese==NULL)
		{
			/*we should do something here*/
		}
		m_pSentenceChinese->szDigi[0]=0;

		m_pSentenceChinese->nNextPredictCharNumber = 0;
		m_pSentenceChinese->szAllInput[0] = 0;	
		m_peQTapCtrl->SetChineseSentence(m_pSentenceChinese);
	}
	else
	{
		m_pSentenceChinese= m_peQTapCtrl->GetChineseSentence();
	}


	if(m_peQTapCtrl->GetChineseDictionary()==NULL)
	{
#ifdef __WINS__
		m_pDictionaryChinese= (int*)PATTREE_LoadStaticDic((const unsigned short *)L"z:\\system\\fep\\dic.bin",(const unsigned short *)L"c:\\udic.bin");
#else
		m_pDictionaryChinese= (int*)PATTREE_LoadStaticDic((const unsigned short *)L"c:\\system\\fep\\dic.bin",(const unsigned short *)L"c:\\udic.bin");
#endif
		if (m_pDictionaryChinese==NULL)   //
		{
			/*we should do something here*/
		}
		m_peQTapCtrl->SetChineseDictionary(m_pDictionaryChinese);
	}
	else
	{
		m_pDictionaryChinese = m_peQTapCtrl->GetChineseDictionary();
	}
}
void CeQTapSmartChinese::DrawSmartChinese() 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,30,rect.Width(),rect.Height());
	tmpRect.SetHeight(16);
	gc.SetBrushColor(CANDBRUSHCOLOR);
	gc.DrawRect(tmpRect);
	


	//画分割线
	gc.SetPenStyle(CGraphicsContext::ESolidPen);
	gc.SetPenColor(LINECOLOR);
	gc.DrawLine(TPoint(0,0),TPoint(rect.Width(),0));
	gc.DrawLine(TPoint(0,15),TPoint(rect.Width(),15));	
	gc.DrawLine(TPoint(0,29),TPoint(rect.Width(),29));		

	
	if((m_pSentenceChinese==NULL)||(m_pDictionaryChinese==NULL))
	{
		return;
	}
	//画三角
	DrawUpDownArrow();

	//写字符
	
	DrawSentence(DISABLETEXT);
	if (m_bSelectMode==TRUE)     //选择模式
	{
		DrawCandWithNumber();
	}
	else
	{
		DrawCand();
	}
	
	
	DrawPinYin();


}

void CeQTapSmartChinese::DrawArrow(int Style) const
{
	
	CWindowGc& aGc = SystemGc();
	
	TRect  rect			= Rect();
	TInt   temp			= rect.Width()-3;


	TPoint upTriangle[3] = {TPoint(temp-8,36),TPoint(temp,36),TPoint(temp-4,32)};
	TPoint downTriangle[3] = {TPoint(temp-8,38),TPoint(temp,38),TPoint(temp-4,42)};
	

	switch (Style)
	{
		case DOWN_DISABLE:
			aGc.SetBrushColor(ARROWCOLOR);
			aGc.SetPenColor(ARROWCOLOR);
			aGc.DrawPolygon(downTriangle,3);		
			break;
		case DOWN_ENABLE:
			aGc.SetBrushColor(TEXTCOLOR);
			aGc.SetPenColor(TEXTCOLOR);
			aGc.DrawPolygon(downTriangle,3);					
			break;
		case UP_DISABLE:
			aGc.SetBrushColor(ARROWCOLOR);
			aGc.SetPenColor(ARROWCOLOR);
			aGc.DrawPolygon(upTriangle,3);
			break;
		case UP_ENABLE:
			aGc.SetBrushColor(TEXTCOLOR);
			aGc.SetPenColor(TEXTCOLOR);
			aGc.DrawPolygon(upTriangle,3);					
			break;
	}

	
   
}
void CeQTapSmartChinese::DrawUpDownArrow() const
{
	if(UpisActive() ==TRUE)
	{
		DrawArrow(UP_ENABLE);
	}
	else
	{
		DrawArrow(UP_DISABLE);
	}
	
				

	if(DownisActive()  ==TRUE)
	{
		DrawArrow(DOWN_ENABLE);
	}
	else
	{
		DrawArrow(DOWN_DISABLE);
	}

}
TBool CeQTapSmartChinese::UpisActive(void) const
{
	
	if (m_pSentenceChinese==NULL)
	{
		return EFalse;
	}
	if(m_pSentenceChinese->nUnifiedCandTotal==0)
	{
		return EFalse;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -