📄 ppeditbox.cpp
字号:
w_nEN_TicksRemained = 3;
return 1;
}
else
{
//按下其他按键
if(w_nIME_Index == IME_ID_EN)
{
w_nIME_State = IME_ST_EN_IDLE;
}
else if(w_nIME_Index == IME_ID_CH)
{
w_nIME_State = IME_ST_CH_IDLE;
}
//注意这里我们并不退出,因为这个按键需要被新的状态得到并处理
}
break;
}
case IME_ST_punc:
//
// 标点输入选择状态:上下键选择标点,确定键输入,取消键返回
//
{
if(nKeyCode == IME_KEY_SELUP)
{
w_pCandidateBar->MoveCandidate(-1);
//RefreshAll();
return 1;
}
else if(nKeyCode == IME_KEY_SELDOWN){
w_pCandidateBar->MoveCandidate(1);
//RefreshAll();
return 1;
}
else if(nKeyCode == IME_KEY_OK)
{
w_pCandidateBar->GetSelectItem(strTextTemp);
Insert(strTextTemp);
w_pCandidateBar->CloseWindow();
//RefreshAll();
if(w_nIME_Index == IME_ID_EN)
{
w_nIME_State = IME_ST_EN_IDLE;
}
else if(w_nIME_Index == IME_ID_CH)
{
w_nIME_State = IME_ST_CH_IDLE;
}
return 1;
}
else if(nKeyCode == IME_KEY_ESC)
{
w_pCandidateBar->CloseWindow();
//RefreshAll();
if(w_nIME_Index == IME_ID_EN)
{
w_nIME_State = IME_ST_EN_IDLE;
}
else if(w_nIME_Index == IME_ID_CH)
{
w_nIME_State = IME_ST_CH_IDLE;
}
return 1;
}
break;
}
}
//
// 数字输入法
//
switch(w_nIME_State)
{
case IME_ST_digit:
//
// 数字键0-9输入数字,IME切换键切换输入法
//
if(nKeyCode >= IME_KEY_NUM0 && nKeyCode <= IME_KEY_NUM9)
{
strTextTemp[0] = nKeyCode - IME_KEY_NUM0 + '0';
strTextTemp[1] = 0;
Insert(strTextTemp);
// RefreshAll();
return 1;
}
else if(nKeyCode == IME_KEY_SWITCH_IME)
{
//转换到中文输入状态
w_nCH_PY_DCODE = 0;
w_nIME_State = IME_ST_CH_IDLE;
w_nIME_Index = IME_ID_CH;
//更新界面IME提示
SetUIDirty(1);
//RefreshAll();
return 1;
}
break;
}
//
//拼音汉字输入法
//
switch(w_nIME_State)
{
case IME_ST_CH_IDLE:
//
// 数字键2-9输入拼音码,数字键1转入到标点输入状态,IME切换键切换输入法
//
{
if(nKeyCode >= IME_KEY_NUM2 && nKeyCode <= IME_KEY_NUM9)
{
w_nCH_PY_DCODE = (nKeyCode - IME_KEY_NUM0);
w_nCH_PY_CurPYIndex = 0;
pIME_py_dcode = FindPY(w_nCH_PY_DCODE);
if(pIME_py_dcode)
{
//显示全部候选标点,转入标点输入状态
CRect rc;
GetWindowRect(&rc);
w_pCandidateBar->CreateWindow(GetParentWnd(),//候选窗显示在和EditBox同级别的窗体中
0,0, //候选窗的位置坐标在后面的代码中调整
200, //宽度
GetLineCNT(w_fontType)+8, //高度
w_fontType); //候选窗使用和editbox一样的字体]
//显示全部候选标点
w_pCandidateBar->SetCandidate(
pIME_py_dcode->pcode_arr[0].py,
pIME_py_dcode->pcode_arr[0].GBC_arr);
//弹出候选窗到editbox周围
w_pCandidateBar->Pop(&rc);
//RefreshAll();
w_nIME_State = IME_ST_CH_CHOOSE;
return 1;
}
}
else if(nKeyCode == IME_KEY_SWITCH_IME)
{
//转换到英文输入状态
w_nCH_PY_DCODE = 0;
w_nIME_State = IME_ST_EN_IDLE;
w_nIME_Index = IME_ID_EN;
//更新界面IME提示
SetUIDirty(1);
//RefreshAll();
return 1;
}
break;
}
case IME_ST_CH_CHOOSE:
//
// 数字键2-9输入拼音码,数字键1转入到标点输入状态,IME切换键切换输入法
//
if(nKeyCode >= IME_KEY_NUM2 && nKeyCode <= IME_KEY_NUM9)
{
pIME_py_dcode = FindPY(w_nCH_PY_DCODE*10 + (nKeyCode - IME_KEY_NUM0));
if(pIME_py_dcode)
{
//确定用户输入了一个合法的拼音组合
w_nCH_PY_DCODE = w_nCH_PY_DCODE*10 + (nKeyCode - IME_KEY_NUM0);
w_nCH_PY_CurPYIndex = 0;
w_pCandidateBar->SetCandidate(
pIME_py_dcode->pcode_arr[0].py,
pIME_py_dcode->pcode_arr[0].GBC_arr);
// RefreshAll();
return 1;
}
}
else if(nKeyCode == IME_KEY_SELUP)
{
w_pCandidateBar->MoveCandidate(-1);
// RefreshAll();
return 1;
}
else if(nKeyCode == IME_KEY_SELDOWN)
{
w_pCandidateBar->MoveCandidate(1);
// RefreshAll();
return 1;
}
else if(nKeyCode == IME_KEY_OK)
{
w_pCandidateBar->GetSelectItem(strTextTemp);
Insert(strTextTemp);
w_pCandidateBar->CloseWindow();
// RefreshAll();
w_nIME_State = IME_ST_CH_IDLE;
return 1;
}
else if(nKeyCode == IME_KEY_ESC)
{
w_nCH_PY_DCODE = w_nCH_PY_DCODE/10;
if(w_nCH_PY_DCODE == 0)
{
//删除拼音到空,代表1取消拼音选择状态
w_pCandidateBar->CloseWindow();
// RefreshAll();
w_nIME_State = IME_ST_CH_IDLE;
}
else
{
//删除拼音得到新的拼音组合
w_nCH_PY_CurPYIndex = 0;
pIME_py_dcode = FindPY(w_nCH_PY_DCODE);
w_pCandidateBar->SetCandidate(
pIME_py_dcode->pcode_arr[0].py,
pIME_py_dcode->pcode_arr[0].GBC_arr);
}
return 1;
}
else if(nKeyCode == IME_KEY_SELSPELL)
{
pIME_py_dcode = FindPY(w_nCH_PY_DCODE);
if(pIME_py_dcode)
{
//切换合法的拼音组合
w_nCH_PY_CurPYIndex ++;
if(w_nCH_PY_CurPYIndex >= pIME_py_dcode->pcode_cnt)
{
w_nCH_PY_CurPYIndex = 0;
}
w_pCandidateBar->SetCandidate(
pIME_py_dcode->pcode_arr[w_nCH_PY_CurPYIndex].py,
pIME_py_dcode->pcode_arr[w_nCH_PY_CurPYIndex].GBC_arr);
// RefreshAll();
return 1;
}
}
break;
}
//
//英文输入法
//
switch(w_nIME_State)
{
case IME_ST_EN_IDLE:
//
// 数字键2-9输入拼音码,数字键1转入到标点输入状态,IME切换键切换输入法
//
if(nKeyCode >= IME_KEY_NUM2 && nKeyCode <= IME_KEY_NUM9)
{
w_nEN_KeyNumber = nKeyCode;
w_nEN_CurCandidate = 0;
strTextTemp[0] = ppIME_EN_Table[w_nEN_KeyNumber - IME_KEY_NUM0][w_nEN_CurCandidate];
strTextTemp[1] =0 ;
Insert(strTextTemp);
// RefreshAll();
w_nIME_State = IME_ST_EN_CHOOSE;
w_nEN_TicksRemained = 3;
return 1;
}
else if(nKeyCode == IME_KEY_SWITCH_IME)
{
//转换到数字输入状态
w_nIME_State = IME_ST_digit;
w_nIME_Index = IME_ID_digit;
//更新界面IME提示
SetUIDirty(1);
// RefreshAll();
return 1;
}
break;
case IME_ST_EN_CHOOSE:
if(w_nEN_KeyNumber == nKeyCode)
{
//1 second内重复按键,更改当前输入字符为下一个候选
w_nEN_CurCandidate++;
if(ppIME_EN_Table[w_nEN_KeyNumber - IME_KEY_NUM0][w_nEN_CurCandidate] == 0)
{
w_nEN_CurCandidate = 0;
}
SetCurChar(ppIME_EN_Table[w_nEN_KeyNumber - IME_KEY_NUM0][w_nEN_CurCandidate]);
// RefreshAll();
w_nEN_TicksRemained = 3;
return 1;
}
else
{
if(nKeyCode >= IME_KEY_NUM2 && nKeyCode <= IME_KEY_NUM9)
{
//1 second内不重复按键:插入新字符并维持在英文选择状态
w_nEN_KeyNumber = nKeyCode;
w_nEN_CurCandidate = 0;
strTextTemp[0] = ppIME_EN_Table[w_nEN_KeyNumber - IME_KEY_NUM0][w_nEN_CurCandidate];
strTextTemp[1] =0 ;
Insert(strTextTemp);
// RefreshAll();
w_nEN_TicksRemained = 3;
return 1;
}
else if(nKeyCode == IME_KEY_SWITCH_IME)
{
//转换到数字输入状态
w_nIME_State = IME_ST_digit;
w_nIME_Index = IME_ID_digit;
//更新界面IME提示
SetUIDirty(1);
// RefreshAll();
return 1;
}
}
break;
}
return 0;
}
CCandidateBar CCandidateBar::s_CandidateBar;
CCandidateBar* CCandidateBar::Instance()
{
return &s_CandidateBar;
}
CCandidateBar::CCandidateBar()
{
w_strCodeString = NULL;
w_strCandidateString = NULL;
w_nCandidateCnt = 0;
w_nCurrentCandidate = 0;
w_nFirstCandidateOnScreen = 0;
w_nCodeStringStartPosX = 5;
w_nMaxCodeStringWidth = 0;
w_nCandidateStringStartPosX = 0;
w_nCandidateScreenWidth = 0;
w_nCandidatePerScreen = 0;
}
CCandidateBar::~CCandidateBar()
{
}
int CCandidateBar::CreateWindow(
CWnd * pParentWnd,
int nX1,
int nY1,
int nWidth,
int nHeight,
enum enFontType fontType)
{
w_strCodeString = NULL;
w_strCandidateString = NULL;
w_nCandidateCnt = 0;
w_nCurrentCandidate = 0;
w_fontType= fontType;
w_nFirstCandidateOnScreen = 0;
w_nCodeStringStartPosX = 5;
w_nMaxCodeStringWidth = GetTextWidth("zhuang", w_fontType, 6);
w_nCandidateStringStartPosX = w_nMaxCodeStringWidth + 10;
w_nCandidateScreenWidth = (nWidth - w_nMaxCodeStringWidth - 10 - 5);
w_nCandidatePerScreen = w_nCandidateScreenWidth / (GetLineCNT(w_fontType)+2);
//创建窗体
return CWnd::CreateWindow(pParentWnd, nX1, nY1, nWidth, nHeight);
}
void CCandidateBar::OnPaint()
{
enum enFontType fontType;
char strTextTemp[10];
CRect rc;
GetWindowRect(&rc);
//
// 绘制编码字符串和候选字符串,加亮选中字符
//
ButtonFrame(rc.w_nX1, rc.w_nY1, rc.w_nX2-rc.w_nX1, rc.w_nY2-rc.w_nY1, 0);
//输出CodeString和分割线
RectangleBlock(
rc.w_nX1+w_nCandidateStringStartPosX-4,
rc.w_nY1+1,
1,
rc.w_nY2-rc.w_nY1-3,
0);
TextOut((const unsigned char *)(w_strCodeString),
rc.w_nX1 + w_nCodeStringStartPosX, //水平靠左
rc.w_nY1 + (rc.w_nY2-rc.w_nY1-GetLineCNT(w_fontType))/2, //垂直居中
w_fontType,
0);
//输出CandidateString
int x = rc.w_nX1 + w_nCandidateStringStartPosX;
int y = rc.w_nY1 + (rc.w_nY2-rc.w_nY1-GetLineCNT(w_fontType))/2; //垂直居中
int j = 0;
for(int i = w_nFirstCandidateOnScreen;
((i < w_nFirstCandidateOnScreen + w_nCandidatePerScreen) && (i<w_nCandidateCnt));
i++)
{
//从中提取第i个候选字符
j = GetWordIndex(w_strCandidateString, i);
if(w_strCandidateString[j] & 0x80)
{
//wide char
strTextTemp[0] = w_strCandidateString[j];
strTextTemp[1] = w_strCandidateString[j+1];
strTextTemp[2] = 0;
}
else
{
strTextTemp[0] = w_strCandidateString[j];
strTextTemp[1] = 0;
}
if(i == w_nCurrentCandidate)
{
RectangleBlock(x-1, y-2, GetLineCNT(w_fontType)+3, GetLineCNT(w_fontType)+3, 0);
}
TextOut((const unsigned char *)(strTextTemp),
x+1,y,w_fontType,
(i == w_nCurrentCandidate) //反显选中项
);
x += GetLineCNT(w_fontType)+2;
}
}
void CCandidateBar::OnTimer(CTimer *pTimer)
{
}
//寻找一个可以附着的位置
void CCandidateBar::Pop(CRect* prc)
{
CRect rcCB;
GetWindowRect(&rcCB);
int nWidth = rcCB.GetWidth();
int nHeight = rcCB.GetHeight();
rcCB.w_nX1 = prc->w_nX1;
rcCB.w_nY1 = prc->w_nY2;
/////////////////
//保证候选窗不会超出屏幕边界
if((rcCB.w_nX1+ nWidth) >= SCR_MAX_COLUMNS)
{
rcCB.w_nX1 = SCR_MAX_COLUMNS-1 - nWidth;
}
if(rcCB.w_nX1 < 0)
{
rcCB.w_nX1 = 0;
}
if((rcCB.w_nY1 + nHeight) >= SCR_MAX_LINES)
{
//候选窗下边界超出屏幕,如果我们上移使其恢复到屏幕内部会造成
//对输入框的覆盖,因此这时我们选择向上弹出的方式
rcCB.w_nY1 = prc->w_nY1 - nHeight;
}
if(rcCB.w_nY1 < 0)
{
rcCB.w_nY1 = 0;
}
// wm_MoveTo(pCB->wnd,rc_cb.x1,rc_cb.y1);
// wm_SetWindowVisible(pCB->wnd,1);
// wm_MoveWindowForeground(pCB->wnd);
MoveTo(rcCB.w_nX1, rcCB.w_nY1);
SetWindowVisible(1);
MoveWindowForeground();
SetUIDirty(1);
// RefreshAll();
}
void CCandidateBar::SetCandidate(char *strCodeString, char *strCandidateString)
{
if(strCodeString != NULL)
{
w_strCodeString = strCodeString;
}
if(strCandidateString != NULL)
{
w_strCandidateString = strCandidateString;
w_nCandidateCnt = GetWordLen(w_strCandidateString);
w_nCurrentCandidate = 0;
w_nFirstCandidateOnScreen = 0;
}
SetUIDirty(1);
}
void CCandidateBar::MoveCandidate(int nStep)
{
int nNewCurCandidate = w_nCurrentCandidate + nStep;
if(nNewCurCandidate>=0 && nNewCurCandidate<w_nCandidateCnt)
{
w_nCurrentCandidate = nNewCurCandidate;
}
//调整当前屏幕显示的内容,使选择项始终可见
while(w_nCurrentCandidate < w_nFirstCandidateOnScreen)
{
w_nFirstCandidateOnScreen -= w_nCandidatePerScreen;
}
while(w_nCurrentCandidate >= w_nFirstCandidateOnScreen + w_nCandidatePerScreen)
{
w_nFirstCandidateOnScreen += w_nCandidatePerScreen;
}
SetUIDirty(1);
//RefreshAll();
}
void CCandidateBar::GetSelectItem(char *strSel)
{
int i;
i = GetWordIndex(w_strCandidateString, w_nCurrentCandidate);
if(w_strCandidateString[i] & 0x80)
{
strSel[0] = w_strCandidateString[i];
strSel[1] = w_strCandidateString[i+1];
strSel[2] = 0;
}
else
{
strSel[0] = w_strCandidateString[i];
strSel[1] = 0;
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -