#include "CnInput.h" #define dfClr_PinyinSelBackGround clTeal const char ListPayload[10] = {0,0,3,3,3,3,3,4,3,4}; const char ListCaseUp[10][4] = { {' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' '}, {'A', 'B', 'C', ' '}, {'D', 'E', 'F', ' '}, {'G', 'H', 'I', ' '}, {'J', 'K', 'L', ' '}, {'M', 'N', 'O', ' '}, {'P', 'Q', 'R', 'S'}, {'T', 'U', 'V', ' '}, {'W', 'X', 'Y', 'Z'} }; const char ListCaseLow[10][4] = { {' ', ' ', ' ', ' '}, {' ', ' ', ' ', ' '}, {'A', 'B', 'C', ' '}, {'D', 'E', 'F', ' '}, {'G', 'H', 'I', ' '}, {'J', 'K', 'L', ' '}, {'M', 'N', 'O', ' '}, {'P', 'Q', 'R', 'S'}, {'T', 'U', 'V', ' '}, {'W', 'X', 'Y', 'Z'} }; const char ccEnList[10][12] = { {'0', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 1}, {'1', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', 2}, {'2', 'A', 'B', 'C', 'a', 'b', 'c', ' ', ' ', ' ', ' ', 7}, {'3', 'D', 'E', 'F', 'd', 'e', 'f', ' ', ' ', ' ', ' ', 7}, {'4', 'G', 'H', 'I', 'g', 'h', 'i', ' ', ' ', ' ', ' ', 7}, {'5', 'J', 'K', 'L', 'j', 'k', 'l', ' ', ' ', ' ', ' ', 7}, {'6', 'M', 'N', 'O', 'm', 'n', 'o', ' ', ' ', ' ', ' ', 7}, {'7', 'P', 'Q', 'R', 'S', 'p', 'q', 'r', 's', ' ', ' ', 9}, {'8', 'T', 'U', 'V', 't', 'u', 'v', ' ', ' ', ' ', ' ', 7}, {'9', 'W', 'X', 'Y', 'Z', 'w', 'x', 'y', 'z', ' ', ' ', 9} }; const char ccSymbolList[4][12] = { {'`', '~', '!', '@', '#', '$', '%', '^', ' ', ' ', ' ', 8}, {'&', '*', '(', ')', '-', '+', '_', '=', ' ', ' ', ' ', 8}, {'{', '}', '[', ']', '|', '\\', ':', ';', ' ', ' ', ' ', 8}, {'"', '\'', '<', '>', ',', '.', '?', '/', ' ', ' ', ' ', 8}, }; void TCnInput::Init(int aX, int aY, int aW, int aH, int OwnerX, int OwnerY, u32 aColor){ unsigned short Left,Right,Top,Bottom; Bound.SetBySize(aX+OwnerX, aY+OwnerY, aW, aH); Color = aColor; if(1){ Left = Bound.Left + 1; Right = Bound.Right - 2; Top = Bound.Top + 1; Bottom = Bound.Bottom - 2; }else{ Left = Bound.Left + 2; Right = Bound.Right - 2; Top = Bound.Top + 2; Bottom = Bound.Bottom - 2; } Content.Set(Left,Top,Right,Bottom); iEdit.Init(0,0,2,28,Content.Left, Content.Top, Color, clDeepGray); iEdit.Visible = 0; iEdit.Enable = 1; iEdit.SetMaxLen(8); iEdit.Str.Clear(); iEdit.IsShowCursor =0; sEdit.Init(0,0,90,28,Content.Left, Content.Top, Color, clDeepGray); sEdit.Visible = 1; sEdit.Enable = 1; sEdit.SetMaxLen(8); sEdit.Str.Clear(); sEdit.IsShowCursor =1; sEdit.Selected = 1; PySelIndex = 0; CnSelIndex = 0; PyCount =0; CnCount =0; IsShowing = 0; SelectedCn = 0; InputMode = CnInputModeEn; } void TCnInput::DrawSelf(void) { /*unsigned int r,g,b, h,l; h = Color & 0x00FFFFFF; r = h / 0x10000; g = (h / 256) % 256; b = h % 256; h = r * 3 / 2; if(h > 255)h=255; r = h; h = g * 3 / 2; if(h > 255)h=255; g = h; h = b * 3 / 2; if(h > 255)h=255; b = h; h = (r<<16) + (g<<8) + b; l = r * 2 / 3; r = l; l = g * 2 / 3; g = l; l = b * 2 / 3; b = l; l = (r<<16) + (g<<8) + b; //Draw Border g = Bound.Right; b = Bound.Bottom; //Draw Right & Bottom for(r=0; r3)SymbolSelIndex = 0; aInx = SymbolSelIndex; aLen = ccSymbolList[SymbolSelIndex][11]; for(i=0; i 3)aInx = 0; aLen = ccSymbolList[aInx][11]; x = Content.Left + 10; y = Content.Top + 59; for(i=0; i 9)break; if(x> (Content.Right-100))break; if(z == PySelIndex){ aClr = clNearWhite; bClr = dfClr_PinyinSelBackGround; }else{ aClr = clNearBlack; bClr = Color; } //gui_write_EN2412(x,y,aClr, bClr, '0' + (z+1) % 10); //x+=12; //RectFillRender(x, y, x+4, y+23, bClr); //x+=4; p = PinyinT9.GetPinyin(i); v =0; while(*p != '\0'){ gui_write_EN2412(x,y,aClr, bClr, *p); p++; v++; x+=12; if(v>=7)break; } x += 20; z++; } } void TCnInput::DrawCnList() { int i,g,v,x,y, aInx; unsigned int aClr, bClr, iClr; const char *p; x = Content.Left + 6; y = Content.Top + 57; if(SelectedCn == 1){ iClr = clBlue; aClr = clNearWhite; bClr = dfClr_PinyinSelBackGround; }else{ iClr = clNearBlack; aClr = clNearBlack; bClr = Color; } RectFillRender(x, y, Content.Right-2, Content.Bottom - 2, bClr); if(PinyinT9.CnResult.CnCount > 0){ y = Content.Top + 57 + 4; if(CnSelIndex > 0){ y = Content.Top + 57 + 4; for(v=0; v<2; v++){ aInx = 1; x = 620; for(i=0; i<8; i++){ HorizLineRender(x, y, aInx, clBlue); x--; aInx += 2; y++; } y += 3; } } y = Content.Top + 57 + 6; if( CnSelIndex < (PinyinT9.CnResult.CnPageCount -1) ){ for(v=0; v<2; v++){ aInx = 16; x = 640; for(i=0; i<8; i++){ HorizLineRender(x, y, aInx, clBlue); x++; aInx -= 2; y++; } y += 3; } } } x = Content.Left + 38; y = Content.Top + 57; for(i=0; i<10; i++){ if(x> (Content.Right-50))break; aInx = CnSelIndex * 10 + i ; if( aInx >= PinyinT9.CnResult.CnCount)break; gui_write_EN2412(x,y,iClr, bClr, '0' + i); x+=12; RectFillRender(x, y, x+4, y+23, bClr); x+=4; p = &PinyinT9.CnResult.pCn[aInx * 2]; TextRender_1CN24(x,y,aClr,p); x+=40; } } const char * TCnInput::TryGetCn(int cInx) { int PyIndex, CnIndex; PyIndex = PinyinT9.CnResult.Index[PySelIndex]; CnIndex = CnSelIndex * 10 + cInx; if(CnIndex < PinyinT9.CnResult.CnCount){ TheGotCn = PinyinT9.TryGetCn(PinyinT9.CnResult.Index[PySelIndex], CnIndex); if(TheGotCn != nullptr){ iEdit.Str.Clear(); iEdit.Pst = -1; iEdit.Show(); TMyString::sFromStr(iEdit.Str.Text, PinyinT9.InputStr.Num); PinyinT9.GetMatchedPinyinCode(); SelectedCn = 0; PySelIndex = 0; DrawPinyinList(); CnSelIndex = 0; PinyinT9.IdentifyCn(PySelIndex); DrawCnList(); GotChar[0] = *TheGotCn; GotChar[1] = TheGotCn[1]; GotChar[2] = '\0'; return TheGotCn; } } return nullptr; } void TCnInput::ClearCnResult() { PinyinT9.CnResult.Count = 0; PinyinT9.CnResult.CnCount =0; PinyinT9.CnResult.CnPageCount = 0; CnSelIndex = 0; iEdit.Str.Clear(); iEdit.Pst = -1; sEdit.Str.Clear(); sEdit.Pst = -1; sEdit.Show(); sEdit.ShowCursor(); } void TCnInput::ShowPinyinText() { int i,aLen; const char *p; aLen = iEdit.Str.GetEndPst() +1; if(aLen >6)aLen = 6; if(PinyinT9.CnResult.Count >0){ if(PySelIndex < PinyinT9.CnResult.Count){ p = PinyinT9.GetPinyin(PySelIndex); for(i=0; i 0){ SymbolSelIndex--; DrawSymbolList(); } break; case VK_RIGHT: if(SymbolSelIndex < 3){ SymbolSelIndex++; DrawSymbolList(); } break; case VK_UP: if(SymbolSelIndex > 0){ SymbolSelIndex--; DrawSymbolList(); } break; case VK_DOWN: if(SymbolSelIndex < 3){ SymbolSelIndex++; DrawSymbolList(); } break; case VK_TAB: break; case VK_EXECUTE: break; case VK_RETURN: break; } return nullptr; } const char * TCnInput::NumKeyIn(unsigned char aKey) { switch(aKey){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': GotChar[0] = aKey; GotChar[1] = 0; GotChar[2] = 0; return GotChar; break; } return nullptr; } const char * TCnInput::CnKeyIn(unsigned char aKey) { int i; switch(aKey){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case VK_DELETE: if( (SelectedCn == 0) || (aKey == VK_DELETE) ){ iEdit.KeyIn(aKey); TMyString::sFromStr(iEdit.Str.Text, PinyinT9.InputStr.Num); i = PinyinT9.GetMatchedPinyinCode(); if(0 == i){ iEdit.KeyIn(VK_DELETE); TMyString::sFromStr(iEdit.Str.Text, PinyinT9.InputStr.Num); i = PinyinT9.GetMatchedPinyinCode(); } if(i)CnShowTip(1); else CnShowTip(0); ShowPinyinText(); PySelIndex = 0; DrawPinyinList(); CnSelIndex = 0; PinyinT9.IdentifyCn(PySelIndex); SelectedCn = 0; DrawCnList(); } if(SelectedCn == 1){ if(aKey != VK_DELETE){ TheGotCn = PinyinT9.TryGetCn(PinyinT9.CnResult.Index[PySelIndex], CnSelIndex * 10 + (aKey - '0') ); TheGotCn = TryGetCn(aKey - '0'); iEdit.Str.Clear(); iEdit.Pst = -1; sEdit.Str.Clear(); sEdit.Pst = -1; sEdit.Show(); SelectedCn = 0; ClearCnResult(); CnShowTip(0); return TheGotCn; } } break; case VK_LEFT: if(PinyinT9.CnResult.Count){ if(PySelIndex > 0){ PySelIndex--; CnSelIndex = 0; ShowPinyinText(); DrawPinyinList(); CnSelIndex = 0; PinyinT9.IdentifyCn(PySelIndex); DrawCnList(); } } break; case VK_RIGHT: if(PinyinT9.CnResult.Count){ if(PySelIndex < (PinyinT9.CnResult.Count-1)){ PySelIndex++; ShowPinyinText(); DrawPinyinList(); CnSelIndex = 0; PinyinT9.IdentifyCn(PySelIndex); DrawCnList(); } } break; case VK_UP: if(CnSelIndex >0){ CnSelIndex--; DrawCnList(); } break; case VK_DOWN: if(CnSelIndex < (PinyinT9.CnResult.CnPageCount-1) ){ CnSelIndex++; DrawCnList(); } break; case VK_TAB: SelectedCn = 0; DrawCnList(); break; case dfKEY_ASTERISK: case dfKEY_SIG: case VK_EXECUTE: if(SelectedCn == 0){ SelectedCn = 1; CnShowTip(2); DrawCnList(); }else if(SelectedCn == 1){ SelectedCn = 0; CnShowTip(1); DrawCnList(); } break; case VK_RETURN: break; } return nullptr; } const char * TCnInput::KeyIn(unsigned char aKey) { if(aKey == dfKEY_ENCN){ switch(InputMode){ case CnInputModeEn: InputMode = CnInputModeSymbol; CnInputMode = CnInputModeSymbol; DrawInputType(); DrawSymbolList(); sEdit.Enable = 0; sEdit.Str.Clear(); sEdit.Pst = -1; sEdit.IsShowCursor = 0; sEdit.Show(); SymbolShowTip(0); break; case CnInputModeSymbol: InputMode = CnInputModeCn; CnInputMode = CnInputModeCn; DrawInputType(); ClearCnResult(); SelectedCn = 0; PySelIndex = 0; CnSelIndex = 0; ShowPinyinText(); DrawPinyinList(); DrawCnList(); CnShowTip(0); break; case CnInputModeCn: InputMode = CnInputModeNum; CnInputMode = CnInputModeNum; DrawInputType(); DrawEnList(); sEdit.Str.Clear(); sEdit.Enable = 0; sEdit.Str.Clear(); sEdit.Pst = -1; sEdit.IsShowCursor = 0; sEdit.Show(); NumShowTip(0); break; case CnInputModeNum: InputMode = CnInputModeEn; CnInputMode = CnInputModeEn; DrawInputType(); DrawEnList(); sEdit.Str.Clear(); sEdit.Enable = 1; sEdit.Str.Clear(); sEdit.Pst = -1; sEdit.IsShowCursor = 0; sEdit.Show(); EnShowTip(0); break; } }else{ switch(InputMode){ case CnInputModeEn: return EnKeyIn(aKey); break; case CnInputModeSymbol: return SymbolKeyIn(aKey); break; case CnInputModeCn: return CnKeyIn(aKey); break; case CnInputModeNum: return NumKeyIn(aKey); break; } } return nullptr; } void TCnInput::SetInputMode(TTextInputMode aInputMode) { switch(aInputMode){ case CnInputModeSymbol: InputMode = CnInputModeSymbol; CnInputMode = aInputMode; DrawInputType(); DrawSymbolList(); sEdit.Enable = 0; sEdit.Str.Clear(); sEdit.Pst = -1; sEdit.IsShowCursor = 0; sEdit.Show(); SymbolShowTip(0); break; case CnInputModeCn: InputMode = CnInputModeCn; CnInputMode = aInputMode; DrawInputType(); ClearCnResult(); SelectedCn = 0; PySelIndex = 0; CnSelIndex = 0; ShowPinyinText(); DrawPinyinList(); DrawCnList(); CnShowTip(0); break; case CnInputModeEn: InputMode = CnInputModeEn; CnInputMode = aInputMode; DrawInputType(); DrawEnList(); sEdit.Str.Clear(); sEdit.Enable = 1; sEdit.Str.Clear(); sEdit.Pst = -1; sEdit.IsShowCursor = 0; sEdit.Show(); EnShowTip(0); break; case CnInputModeNum: InputMode = CnInputModeNum; CnInputMode = aInputMode; DrawInputType(); DrawEnList(); sEdit.Str.Clear(); sEdit.Enable = 0; sEdit.Str.Clear(); sEdit.Pst = -1; sEdit.IsShowCursor = 0; sEdit.Show(); NumShowTip(0); break; default: InputMode = CnInputModeEn; CnInputMode = CnInputModeEn; DrawInputType(); DrawEnList(); sEdit.Str.Clear(); sEdit.Enable = 0; sEdit.Str.Clear(); sEdit.Pst = -1; sEdit.IsShowCursor = 0; sEdit.Show(); EnShowTip(0); break; } } int TCnInput::ExtRequst(unsigned char Prm) { IsShowing =0; return 0; }