FreeCalypso > hg > fc-magnetite
comparison src/ui3/bmi/MmiDictionary.c @ 420:e8ddbb0837ed
src/ui3: initial import of TCS3/LoCosto BMI & MFW code
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 21 Jan 2018 03:09:00 +0000 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 419:59143cd42ec7 | 420:e8ddbb0837ed |
|---|---|
| 1 /******************************************************************************* | |
| 2 | |
| 3 CONDAT (UK) | |
| 4 | |
| 5 ******************************************************************************** | |
| 6 | |
| 7 This software product is the property of Condat (UK) Ltd and may not be | |
| 8 disclosed to any third party without the express permission of the owner. | |
| 9 | |
| 10 ******************************************************************************** | |
| 11 | |
| 12 $Project name: Basic MMI | |
| 13 $Project code: BMI | |
| 14 $Module: MMI | |
| 15 $File: Dixtionary.c | |
| 16 $Revision: 1.0 | |
| 17 | |
| 18 $Author: Condat(UK) | |
| 19 $Date: | |
| 20 | |
| 21 ******************************************************************************** | |
| 22 | |
| 23 Description: Predictive text dictionary functions. | |
| 24 Interfaces between the Lation text editor and the EziText API. | |
| 25 | |
| 26 | |
| 27 | |
| 28 ******************************************************************************** | |
| 29 | |
| 30 $History: Dictionary.c | |
| 31 Aug 16, 2004 REF: CRR 24323 Deepa M.D | |
| 32 Bug:Clenup of sprintf used for tracing | |
| 33 Fix:Replace the char buf[]; sprintf (buf, "...", ...); TRACE_EVENT (buf); statements by TRACE_EVENT_PX | |
| 34 | |
| 35 03/10/02 Replaced most of the file with version on 3.3.3 line (MC, SPR 1242) | |
| 36 | |
| 37 $End | |
| 38 | |
| 39 *******************************************************************************/ | |
| 40 | |
| 41 #define ENTITY_MFW | |
| 42 | |
| 43 /* includes */ | |
| 44 #include <string.h> | |
| 45 #include <stdio.h> | |
| 46 #include <stdlib.h> | |
| 47 | |
| 48 #if defined (NEW_FRAME) | |
| 49 | |
| 50 #include "typedefs.h" | |
| 51 #include "vsi.h" | |
| 52 #include "pei.h" | |
| 53 #include "custom.h" | |
| 54 #include "gsm.h" | |
| 55 | |
| 56 #else | |
| 57 | |
| 58 #include "STDDEFS.H" | |
| 59 #include "custom.h" | |
| 60 #include "gsm.h" | |
| 61 #include "vsi.h" | |
| 62 | |
| 63 #endif | |
| 64 //#include "MmiBookShared.h" | |
| 65 #include "MmiBlkLangDB.h" | |
| 66 #include "MmiDictionary.h" | |
| 67 #include "zi8api.h" | |
| 68 #include "mfw_kbd.h" | |
| 69 | |
| 70 | |
| 71 | |
| 72 /************************************ MACROS****************************************/ | |
| 73 #define MAX_NO_OF_ELEMENTS 12 | |
| 74 #define CANDIDATES_PER_GROUP 1 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 /************************************* Data Type definitions ****************************/ | |
| 80 typedef struct dict_data_ | |
| 81 { | |
| 82 ZI8GETPARAM getParam; //global ezitext data structure | |
| 83 int no_of_candidates; | |
| 84 int candidate_cursor; | |
| 85 int more_count; | |
| 86 | |
| 87 } dict_data; | |
| 88 | |
| 89 /*MC, SPR 1150 - Added data structure definitions*/ | |
| 90 typedef struct | |
| 91 { | |
| 92 UBYTE condat_lang; /*Condat language code e.g. ENGLISH LANGAUGE*/ | |
| 93 UBYTE zi_lang; /*Zi library language code */ | |
| 94 UBYTE zi_sub_lang; /*Zi library sub-language code e.g. British English*/ | |
| 95 | |
| 96 }lang_code_table_entry; | |
| 97 | |
| 98 typedef struct | |
| 99 { | |
| 100 UBYTE no_of_entries; | |
| 101 lang_code_table_entry* entries; | |
| 102 | |
| 103 }lang_code_table; | |
| 104 /*MC end*/ | |
| 105 /*************************************Global Variables***********************************/ | |
| 106 | |
| 107 ZI8WCHAR element_buffer[MAX_NO_OF_ELEMENTS]; | |
| 108 ZI8WCHAR candidates_buffer[MAX_NO_OF_ELEMENTS*CANDIDATES_PER_GROUP]; | |
| 109 | |
| 110 | |
| 111 static dict_data Dictionary; | |
| 112 | |
| 113 /*MC SPR 1150- hardcoded Language table*/ | |
| 114 /*This is used to correlate the current language with the language settings needed for Ezitext*/ | |
| 115 /*If we add new lanaguages, we just need to amend this table*/ | |
| 116 lang_code_table_entry LangCodeTableEntries[] = | |
| 117 { | |
| 118 {ENGLISH_LANGUAGE, ZI8_LANG_EN, ZI8_SUBLANG_EN_UK}, | |
| 119 {GERMAN_LANGUAGE, ZI8_LANG_DE, ZI8_SUBLANG_DEFAULT} | |
| 120 }; | |
| 121 lang_code_table LangCodeTable = { 2, LangCodeTableEntries}; | |
| 122 /*************************************Prototypes***********************************/ | |
| 123 void convert_chars_to_ascii(char* string, UBYTE language);/*SPR 1508*/ | |
| 124 | |
| 125 /******************************************************************************* | |
| 126 | |
| 127 $Function: Initialize_Dict | |
| 128 | |
| 129 $Description: Initialises Predictive Text libs | |
| 130 | |
| 131 $Returns: status int | |
| 132 | |
| 133 $Arguments: language, text entry mode(may be used for chinese e.g. pinyin/stroke) | |
| 134 *******************************************************************************/ | |
| 135 int Initialize_Dict(UBYTE language, UBYTE entry_mode) | |
| 136 { int i; | |
| 137 | |
| 138 Zi8Initialize(); | |
| 139 /*MC, SPR 1150- more generic code for setting Zi library parameters*/ | |
| 140 | |
| 141 /* for each entry in language table*/ | |
| 142 for(i=0; i< LangCodeTable.no_of_entries; i++) | |
| 143 {/*if current language in table*/ | |
| 144 if (LangCodeTable.entries[i].condat_lang == language) | |
| 145 { /*use Zi language definitions*/ | |
| 146 Dictionary.getParam.Language = LangCodeTable.entries[i].zi_lang; | |
| 147 Dictionary.getParam.SubLanguage = LangCodeTable.entries[i].zi_sub_lang; | |
| 148 break; | |
| 149 } | |
| 150 } | |
| 151 /*if no entry found*/ | |
| 152 if (i>=LangCodeTable.no_of_entries) | |
| 153 return 1; /*exit with error code*/ | |
| 154 Dictionary.getParam.GetMode = ZI8_GETMODE_DEFAULT; | |
| 155 Dictionary.getParam.SubLanguage = ZI8_SUBLANG_EN_ALL; | |
| 156 Dictionary.getParam.Context = ZI8_GETCONTEXT_DEFAULT; | |
| 157 Dictionary.getParam.GetOptions = ZI8_GETOPTION_STRINGS; | |
| 158 Dictionary.getParam.pElements = element_buffer; | |
| 159 Dictionary.getParam.pCandidates = candidates_buffer; | |
| 160 Dictionary.getParam.MaxCandidates = CANDIDATES_PER_GROUP + 1; | |
| 161 Dictionary.getParam.pScratch = NULL; | |
| 162 Dictionary.getParam.FirstCandidate = 0; | |
| 163 | |
| 164 memset(element_buffer, 0, MAX_NO_OF_ELEMENTS*sizeof(ZI8WCHAR)); | |
| 165 memset(candidates_buffer, 0, MAX_NO_OF_ELEMENTS*CANDIDATES_PER_GROUP); | |
| 166 Dictionary.getParam.ElementCount = 0; | |
| 167 Dictionary.more_count = 0; | |
| 168 Dictionary.no_of_candidates = 0; | |
| 169 Dictionary.candidate_cursor = 0; | |
| 170 return 0; | |
| 171 } | |
| 172 | |
| 173 /******************************************************************************* | |
| 174 | |
| 175 $Function: DictAlphaKeyPress | |
| 176 | |
| 177 $Description: Passes keypress to pred text lib and puts first match into string param | |
| 178 | |
| 179 $Returns: status int | |
| 180 | |
| 181 $Arguments: keycode, string | |
| 182 *******************************************************************************/ | |
| 183 int DictAlphaKeyPress(UBYTE keycode, char* first_candidate) | |
| 184 { | |
| 185 ZI8WCHAR new_keycode=0; | |
| 186 //convert keycode to Ezitext code | |
| 187 | |
| 188 switch (keycode) | |
| 189 { | |
| 190 case KCD_1: new_keycode = ZI8_CODE_LATIN_PUNCT; break; | |
| 191 case KCD_2: new_keycode = ZI8_CODE_LATIN_ABC; break; | |
| 192 case KCD_3: new_keycode = ZI8_CODE_LATIN_DEF; break; | |
| 193 case KCD_4: new_keycode = ZI8_CODE_LATIN_GHI; break; | |
| 194 case KCD_5: new_keycode = ZI8_CODE_LATIN_JKL; break; | |
| 195 case KCD_6: new_keycode = ZI8_CODE_LATIN_MNO; break; | |
| 196 case KCD_7: new_keycode = ZI8_CODE_LATIN_PQRS; break; | |
| 197 case KCD_8: new_keycode = ZI8_CODE_LATIN_TUV; break; | |
| 198 case KCD_9: new_keycode = ZI8_CODE_LATIN_WXYZ; break; | |
| 199 default: break; | |
| 200 } | |
| 201 /*MC, SPR 1150 - removed any code for chinese Pinyin from this function*/ | |
| 202 | |
| 203 //place in array of elements | |
| 204 Dictionary.getParam.pElements[Dictionary.getParam.ElementCount++] = new_keycode; | |
| 205 Dictionary.more_count = 0; | |
| 206 Dictionary.getParam.FirstCandidate = 0; //start new word search | |
| 207 Dictionary.candidate_cursor = 0; | |
| 208 Dictionary.no_of_candidates = Zi8GetCandidates(&Dictionary.getParam); | |
| 209 | |
| 210 if (Dictionary.no_of_candidates == 0) | |
| 211 { TRACE_EVENT("NO candidates returned"); | |
| 212 return DictBackSpace(first_candidate); | |
| 213 } | |
| 214 else | |
| 215 { | |
| 216 /***************************Go-lite Optimization changes Start***********************/ | |
| 217 | |
| 218 //Aug 16, 2004 REF: CRR 24323 Deepa M.D | |
| 219 TRACE_EVENT_P1("No of candidates returned: %d", Dictionary.no_of_candidates); | |
| 220 /***************************Go-lite Optimization changes end***********************/ | |
| 221 | |
| 222 } | |
| 223 Zi8Copy((PZI8UCHAR)first_candidate, (&Dictionary.getParam), Dictionary.candidate_cursor); | |
| 224 /*MC, SPR 1150 - removed any code for chinese Pinyin from this function*/ | |
| 225 | |
| 226 /*SPR 1508*/ | |
| 227 if (Mmi_getCurrentLanguage() == GERMAN_LANGUAGE) | |
| 228 convert_chars_to_ascii(first_candidate, Mmi_getCurrentLanguage()); | |
| 229 /*return 0;*/ | |
| 230 /* SH - '1' will now be returned if the key is accepted, 0 otherwise */ | |
| 231 return 1; | |
| 232 | |
| 233 } | |
| 234 | |
| 235 /******************************************************************************* | |
| 236 | |
| 237 $Function: ResetDictSearch | |
| 238 | |
| 239 $Description: Resets dictionary search as match selected | |
| 240 | |
| 241 $Returns: status int | |
| 242 | |
| 243 $Arguments: none | |
| 244 *******************************************************************************/ | |
| 245 | |
| 246 int ResetDictSearch() | |
| 247 { | |
| 248 Dictionary.getParam.ElementCount = 0; | |
| 249 Dictionary.more_count = 0; | |
| 250 Dictionary.no_of_candidates = 0; | |
| 251 Dictionary.candidate_cursor = 0; | |
| 252 | |
| 253 return 0; | |
| 254 | |
| 255 } | |
| 256 | |
| 257 /******************************************************************************* | |
| 258 | |
| 259 $Function: MoreCandidates | |
| 260 | |
| 261 $Description: gets next (set of) candidate(s) | |
| 262 | |
| 263 $Returns: status int | |
| 264 | |
| 265 $Arguments: string, pointer to int(not used ATM) | |
| 266 *******************************************************************************/ | |
| 267 //get the next set of candidates | |
| 268 //At the moment we only get one candidate at a time, but this allows us to get more than one | |
| 269 int MoreCandidates(char* first_candidate, int* no_of_candidates) | |
| 270 { | |
| 271 | |
| 272 | |
| 273 //any more candidates to retrieve? | |
| 274 if (Dictionary.no_of_candidates > CANDIDATES_PER_GROUP) | |
| 275 { | |
| 276 Dictionary.more_count++; | |
| 277 Dictionary.getParam.FirstCandidate = Dictionary.more_count *CANDIDATES_PER_GROUP; | |
| 278 Dictionary.no_of_candidates = Zi8GetCandidates(&Dictionary.getParam); | |
| 279 | |
| 280 Zi8Copy((PZI8UCHAR)first_candidate, &(Dictionary.getParam), Dictionary.candidate_cursor); | |
| 281 | |
| 282 //return first candidate in group | |
| 283 } | |
| 284 | |
| 285 else | |
| 286 { | |
| 287 Dictionary.more_count = 0; | |
| 288 Dictionary.getParam.FirstCandidate = 0; | |
| 289 Dictionary.no_of_candidates = Zi8GetCandidates(&Dictionary.getParam); | |
| 290 | |
| 291 Zi8Copy((PZI8UCHAR)first_candidate, &(Dictionary.getParam), Dictionary.candidate_cursor); | |
| 292 } | |
| 293 /*SPR 1508*/ | |
| 294 if (Mmi_getCurrentLanguage() == GERMAN_LANGUAGE) | |
| 295 convert_chars_to_ascii(first_candidate, Mmi_getCurrentLanguage()); | |
| 296 | |
| 297 return 0; | |
| 298 } | |
| 299 | |
| 300 /******************************************************************************* | |
| 301 | |
| 302 $Function: ConvertToKeyPresses | |
| 303 | |
| 304 $Description: Takes a string and sends it as keypresses to dictionary to start new search | |
| 305 | |
| 306 $Returns: status int | |
| 307 | |
| 308 $Arguments: input string, output string(first match) | |
| 309 *******************************************************************************/ | |
| 310 //takes in a string | |
| 311 int ConvertToKeyPresses(char* string, char* first_candidate) | |
| 312 { int no_of_chars; | |
| 313 int i; | |
| 314 | |
| 315 ResetDictSearch(); | |
| 316 no_of_chars = strlen(string); | |
| 317 for (i=0; i < no_of_chars; i++) | |
| 318 { | |
| 319 switch (string[i]) | |
| 320 { | |
| 321 | |
| 322 case ('A'): | |
| 323 case ('a'): | |
| 324 case ('B'): | |
| 325 case ('b'): | |
| 326 case ('C'): | |
| 327 case ('c'): | |
| 328 DictAlphaKeyPress(KCD_2, first_candidate); break; | |
| 329 case ('D'): | |
| 330 case ('d'): | |
| 331 case ('E'): | |
| 332 case ('e'): | |
| 333 case ('F'): | |
| 334 case ('f'): | |
| 335 DictAlphaKeyPress(KCD_3, first_candidate); break; | |
| 336 case ('G'): | |
| 337 case ('g'): | |
| 338 case ('H'): | |
| 339 case ('h'): | |
| 340 case ('I'): | |
| 341 case ('i'): | |
| 342 DictAlphaKeyPress(KCD_4, first_candidate); break; | |
| 343 case ('J'): | |
| 344 case ('j'): | |
| 345 case ('K'): | |
| 346 case ('k'): | |
| 347 case ('L'): | |
| 348 case ('l'): | |
| 349 DictAlphaKeyPress(KCD_5, first_candidate); break; | |
| 350 case ('M'): | |
| 351 case ('m'): | |
| 352 case ('N'): | |
| 353 case ('n'): | |
| 354 case ('O'): | |
| 355 case ('o'): | |
| 356 DictAlphaKeyPress(KCD_6, first_candidate); break; | |
| 357 case ('P'): | |
| 358 case ('p'): | |
| 359 case ('Q'): | |
| 360 case ('q'): | |
| 361 case ('R'): | |
| 362 case ('r'): | |
| 363 case ('S'): | |
| 364 case ('s'): | |
| 365 DictAlphaKeyPress(KCD_7, first_candidate); break; | |
| 366 case ('T'): | |
| 367 case ('t'): | |
| 368 case ('U'): | |
| 369 case ('u'): | |
| 370 case ('V'): | |
| 371 case ('v'): | |
| 372 DictAlphaKeyPress(KCD_8, first_candidate); break; | |
| 373 case ('W'): | |
| 374 case ('w'): | |
| 375 case ('X'): | |
| 376 case ('x'): | |
| 377 case ('Y'): | |
| 378 case ('y'): | |
| 379 case ('Z'): | |
| 380 case ('z'): | |
| 381 DictAlphaKeyPress(KCD_9, first_candidate); break; | |
| 382 default: DictAlphaKeyPress(KCD_1, first_candidate); break; | |
| 383 } | |
| 384 } | |
| 385 Dictionary.no_of_candidates = Zi8GetCandidates(&Dictionary.getParam); | |
| 386 Zi8Copy((PZI8UCHAR)first_candidate, &Dictionary.getParam, Dictionary.candidate_cursor); | |
| 387 /*SPR1508*/ | |
| 388 if (Mmi_getCurrentLanguage() == GERMAN_LANGUAGE) | |
| 389 convert_chars_to_ascii(first_candidate, Mmi_getCurrentLanguage()); | |
| 390 return 0; | |
| 391 } | |
| 392 /******************************************************************************* | |
| 393 | |
| 394 $Function: DictBackSpace | |
| 395 $Description: Removes last char from list of elements in dictionary search | |
| 396 | |
| 397 $Returns: status int | |
| 398 | |
| 399 $Arguments: output string(first match) | |
| 400 *******************************************************************************/ | |
| 401 int DictBackSpace(char* first_candidate) | |
| 402 { | |
| 403 | |
| 404 if (Dictionary.more_count != 0) | |
| 405 { Dictionary.more_count --;} | |
| 406 else | |
| 407 if (Dictionary.getParam.ElementCount != 0) | |
| 408 { | |
| 409 //replace last element with 0 | |
| 410 Dictionary.getParam.pElements[--Dictionary.getParam.ElementCount] = 0; | |
| 411 } | |
| 412 Dictionary.more_count = 0; | |
| 413 Dictionary.getParam.FirstCandidate = 0; //start new word search | |
| 414 Dictionary.candidate_cursor = 0; | |
| 415 Dictionary.no_of_candidates = Zi8GetCandidates(&Dictionary.getParam); | |
| 416 Zi8Copy((PZI8UCHAR)first_candidate, &Dictionary.getParam, Dictionary.candidate_cursor); | |
| 417 /*SPR 1508*/ | |
| 418 if (Mmi_getCurrentLanguage() == GERMAN_LANGUAGE) | |
| 419 convert_chars_to_ascii(first_candidate, Mmi_getCurrentLanguage()); | |
| 420 return 0; | |
| 421 } | |
| 422 /******************************************************************************* | |
| 423 | |
| 424 $Function: convert_chars_to_ascii | |
| 425 $Description: Changes any language-specific chars from ezitext encoding to our ascii | |
| 426 encoding. Added for SPR 1508. | |
| 427 | |
| 428 $Returns: none | |
| 429 | |
| 430 $Arguments: input string, language | |
| 431 *******************************************************************************/ | |
| 432 void convert_chars_to_ascii(char* string, UBYTE language) | |
| 433 { | |
| 434 switch(language) | |
| 435 { | |
| 436 | |
| 437 case (GERMAN_LANGUAGE): | |
| 438 { unsigned int i; | |
| 439 | |
| 440 for (i=0; i< strlen(string);i++) | |
| 441 { | |
| 442 | |
| 443 switch (string[i]) | |
| 444 { case (0x1e):string[i] = (char)225;break; /*SS*/ | |
| 445 case (0x7B):string[i] = (char)132;break; /*a with umlaut*/ | |
| 446 case (0x7c):string[i] = (char)148;break; /*o with umlaut*/ | |
| 447 case (0x7e):string[i] = (char)154;break; /*u with umlaut*/ | |
| 448 } | |
| 449 | |
| 450 } | |
| 451 break; | |
| 452 } | |
| 453 } | |
| 454 | |
| 455 } |
