📄 mmidictionary.c
字号:
/*******************************************************************************
CONDAT (UK)
********************************************************************************
This software product is the property of Condat (UK) Ltd and may not be
disclosed to any third party without the express permission of the owner.
********************************************************************************
$Project name: Basic MMI
$Project code: BMI
$Module: MMI
$File: Dixtionary.c
$Revision: 1.0
$Author: Condat(UK)
$Date:
********************************************************************************
Description: Predictive text dictionary functions.
Interfaces between the Lation text editor and the EziText API.
********************************************************************************
$History: Dictionary.c
$End
*******************************************************************************/
#include <stddefs.h>
#include <string.h>
//#include "MmiBookShared.h"
#include "MmiDictionary.h"
#include "..\..\..\ZI\Include\zi8api.h"
////#include "gsm.h"
#include "Mfw_kbd.h"
/************************************ MACROS****************************************/
#define MAX_NO_OF_ELEMENTS 12
#define CANDIDATES_PER_GROUP 1
/************************************* Data Type definitions ****************************/
typedef struct dict_data_
{
ZI8GETPARAM getParam; //global ezitext data structure
int no_of_candidates;
int candidate_cursor;
int more_count;
} dict_data;
/*************************************Global Variables***********************************/
ZI8WCHAR element_buffer[MAX_NO_OF_ELEMENTS];
ZI8WCHAR candidates_buffer[MAX_NO_OF_ELEMENTS*CANDIDATES_PER_GROUP];
static dict_data Dictionary;
/*******************************************************************************
$Function: Initialize_Dict
$Description: Initialises Predictive Text libs
$Returns: status int
$Arguments: language, text entry mode(may be used for chinese e.g. pinyin/stroke)
*******************************************************************************/
int Initialize_Dict(UBYTE language, UBYTE entry_mode)
{
Zi8Initialize();
//switch (language)
{
// case (ENGLISH):
{ Dictionary.getParam.Language = ZI8_LANG_EN;
Dictionary.getParam.GetMode = ZI8_GETMODE_DEFAULT;
Dictionary.getParam.SubLanguage = ZI8_SUBLANG_DEFAULT;
Dictionary.getParam.Context = ZI8_GETCONTEXT_DEFAULT;
Dictionary.getParam.GetOptions = ZI8_GETOPTION_STRINGS;
Dictionary.getParam.pElements = element_buffer;
Dictionary.getParam.pCandidates = candidates_buffer;
Dictionary.getParam.MaxCandidates = CANDIDATES_PER_GROUP + 1;
// TRACE_EVENT("English Dictionary");
}
// break;
//default: return 1;break;
}
Dictionary.getParam.ElementCount = 0;
Dictionary.more_count = 0;
Dictionary.no_of_candidates = 0;
Dictionary.candidate_cursor = 0;
return 0;
}
/*******************************************************************************
$Function: DictAlphaKeyPress
$Description: Passes keypress to pred text lib and puts first match into string param
$Returns: status int
$Arguments: keycode, string
*******************************************************************************/
int DictAlphaKeyPress(UBYTE keycode, char* first_candidate)
{
ZI8WCHAR new_keycode;
//convert keycode to Ezitext code
switch (keycode)
{
case KCD_1: new_keycode = ZI8_CODE_LATIN_PUNCT; break;
case KCD_2: new_keycode = ZI8_CODE_LATIN_ABC; break;
case KCD_3: new_keycode = ZI8_CODE_LATIN_DEF; break;
case KCD_4: new_keycode = ZI8_CODE_LATIN_GHI; break;
case KCD_5: new_keycode = ZI8_CODE_LATIN_JKL; break;
case KCD_6: new_keycode = ZI8_CODE_LATIN_MNO; break;
case KCD_7: new_keycode = ZI8_CODE_LATIN_PQRS; break;
case KCD_8: new_keycode = ZI8_CODE_LATIN_TUV; break;
case KCD_9: new_keycode = ZI8_CODE_LATIN_WXYZ; break;
default: break;
}
//place in array of elements
Dictionary.getParam.pElements[Dictionary.getParam.ElementCount++] = new_keycode;
Dictionary.more_count = 0;
Dictionary.getParam.FirstCandidate = 0; //start new word search
Dictionary.candidate_cursor = 0;
Dictionary.no_of_candidates = Zi8GetCandidates(&Dictionary.getParam);
if (Dictionary.no_of_candidates == 0)
return DictBackSpace(first_candidate);
Zi8Copy((PZI8UCHAR)first_candidate, (&Dictionary.getParam), Dictionary.candidate_cursor);
return 0;
}
/*******************************************************************************
$Function: ResetDictSearch
$Description: Resets dictionary search as match selected
$Returns: status int
$Arguments: none
*******************************************************************************/
int ResetDictSearch()
{
Dictionary.getParam.ElementCount = 0;
Dictionary.more_count = 0;
Dictionary.no_of_candidates = 0;
Dictionary.candidate_cursor = 0;
return 0;
}
/*******************************************************************************
$Function: MoreCandidates
$Description: gets next (set of) candidate(s)
$Returns: status int
$Arguments: string, pointer to int(not used ATM)
*******************************************************************************/
//get the next set of candidates
//At the moment we only get one candidate at a time, but this allows us to get more than one
int MoreCandidates(char* first_candidate, int* no_of_candidates)
{ ZI8UCHAR temp[MAX_NO_OF_ELEMENTS + 1];
//any more candidates to retrieve?
if (Dictionary.no_of_candidates > CANDIDATES_PER_GROUP)
{
Dictionary.more_count++;
Dictionary.getParam.FirstCandidate = Dictionary.more_count *CANDIDATES_PER_GROUP;
Dictionary.no_of_candidates = Zi8GetCandidates(&Dictionary.getParam);
Zi8Copy((PZI8UCHAR)first_candidate, &(Dictionary.getParam), Dictionary.candidate_cursor);
//return first candidate in group
}
else
{
Dictionary.more_count = 0;
Dictionary.getParam.FirstCandidate = 0;
Dictionary.no_of_candidates = Zi8GetCandidates(&Dictionary.getParam);
Zi8Copy((PZI8UCHAR)first_candidate, &(Dictionary.getParam), Dictionary.candidate_cursor);
}
;
return 0;
}
/*******************************************************************************
$Function: ConvertToKeyPresses
$Description: Takes a string and sends it as keypresses to dictionary to start new search
$Returns: status int
$Arguments: input string, output string(first match)
*******************************************************************************/
//takes in a string
int ConvertToKeyPresses(char* string, char* first_candidate)
{ int no_of_chars;
int i;
ResetDictSearch();
no_of_chars = strlen(string);
for (i=0; i < no_of_chars; i++)
{
switch (string[i])
{
case ('A'):
case ('a'):
case ('B'):
case ('b'):
case ('C'):
case ('c'):
DictAlphaKeyPress(KCD_2, first_candidate); break;
case ('D'):
case ('d'):
case ('E'):
case ('e'):
case ('F'):
case ('f'):
DictAlphaKeyPress(KCD_3, first_candidate); break;
case ('G'):
case ('g'):
case ('H'):
case ('h'):
case ('I'):
case ('i'):
DictAlphaKeyPress(KCD_4, first_candidate); break;
case ('J'):
case ('j'):
case ('K'):
case ('k'):
case ('L'):
case ('l'):
DictAlphaKeyPress(KCD_5, first_candidate); break;
case ('M'):
case ('m'):
case ('N'):
case ('n'):
case ('O'):
case ('o'):
DictAlphaKeyPress(KCD_6, first_candidate); break;
case ('P'):
case ('p'):
case ('Q'):
case ('q'):
case ('R'):
case ('r'):
case ('S'):
case ('s'):
DictAlphaKeyPress(KCD_7, first_candidate); break;
case ('T'):
case ('t'):
case ('U'):
case ('u'):
case ('V'):
case ('v'):
DictAlphaKeyPress(KCD_8, first_candidate); break;
case ('W'):
case ('w'):
case ('X'):
case ('x'):
case ('Y'):
case ('y'):
case ('Z'):
case ('z'):
DictAlphaKeyPress(KCD_9, first_candidate); break;
default: DictAlphaKeyPress(KCD_1, first_candidate); break;
}
}
Dictionary.no_of_candidates = Zi8GetCandidates(&Dictionary.getParam);
Zi8Copy((PZI8UCHAR)first_candidate, &Dictionary.getParam, Dictionary.candidate_cursor);
return 0;
}
/*******************************************************************************
$Function: DictBackSpace
$Description: Removes last char from list of elements in dictionary search
$Returns: status int
$Arguments: output string(first match)
*******************************************************************************/
int DictBackSpace(char* first_candidate)
{
if (Dictionary.more_count != 0)
{ Dictionary.more_count --;}
else
if (Dictionary.getParam.ElementCount != 0)
{
//replace last element with 0
Dictionary.getParam.pElements[--Dictionary.getParam.ElementCount] = 0;
}
Dictionary.more_count = 0;
Dictionary.getParam.FirstCandidate = 0; //start new word search
Dictionary.candidate_cursor = 0;
Dictionary.no_of_candidates = Zi8GetCandidates(&Dictionary.getParam);
Zi8Copy((PZI8UCHAR)first_candidate, &Dictionary.getParam, Dictionary.candidate_cursor);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -