1 /**
2  * @file lv_ime_pinyin.h
3  *
4  */
5 #ifndef LV_IME_PINYIN_H
6 #define LV_IME_PINYIN_H
7 
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11 
12 /*********************
13  *      INCLUDES
14  *********************/
15 #include "../../../lvgl.h"
16 
17 #if LV_USE_IME_PINYIN != 0
18 
19 /*********************
20  *      DEFINES
21  *********************/
22 #define LV_IME_PINYIN_K9_MAX_INPUT  7
23 
24 /**********************
25  *      TYPEDEFS
26  **********************/
27 
28 typedef enum {
29     LV_IME_PINYIN_MODE_K26,
30     LV_IME_PINYIN_MODE_K9,
31 } lv_ime_pinyin_mode_t;
32 
33 /*Data of pinyin_dict*/
34 typedef struct {
35     const char * const py;
36     const char * const py_mb;
37 } lv_pinyin_dict_t;
38 
39 /*Data of 9-key input(k9) mode*/
40 typedef struct {
41     char py_str[7];
42 } ime_pinyin_k9_py_str_t;
43 
44 /*Data of lv_ime_pinyin*/
45 typedef struct {
46     lv_obj_t obj;
47     lv_obj_t * kb;
48     lv_obj_t * cand_panel;
49     lv_pinyin_dict_t * dict;
50     lv_ll_t k9_legal_py_ll;
51     char * cand_str;            /* Candidate string */
52     char   input_char[16];      /* Input box character */
53 #if LV_IME_PINYIN_USE_K9_MODE
54     char   k9_input_str[LV_IME_PINYIN_K9_MAX_INPUT]; /* 9-key input(k9) mode input string */
55     uint16_t k9_py_ll_pos;      /* Current pinyin map pages(k9) */
56     uint16_t k9_legal_py_count; /* Count of legal Pinyin numbers(k9) */
57     uint16_t k9_input_str_len;  /* 9-key input(k9) mode input string max len */
58 #endif
59     uint16_t ta_count;          /* The number of characters entered in the text box this time */
60     uint16_t cand_num;          /* Number of candidates */
61     uint16_t py_page;           /* Current pinyin map pages(k26) */
62     uint16_t py_num[26];        /* Number and length of Pinyin */
63     uint16_t py_pos[26];        /* Pinyin position */
64     uint8_t  mode : 1;          /* Set mode, 1: 26-key input(k26), 0: 9-key input(k9). Default: 1. */
65 } lv_ime_pinyin_t;
66 
67 /***********************
68  * GLOBAL VARIABLES
69  ***********************/
70 
71 /**********************
72  * GLOBAL PROTOTYPES
73  **********************/
74 lv_obj_t * lv_ime_pinyin_create(lv_obj_t * parent);
75 
76 /*=====================
77  * Setter functions
78  *====================*/
79 
80 /**
81  * Set the keyboard of Pinyin input method.
82  * @param obj  pointer to a Pinyin input method object
83  * @param dict pointer to a Pinyin input method keyboard
84  */
85 void lv_ime_pinyin_set_keyboard(lv_obj_t * obj, lv_obj_t * kb);
86 
87 /**
88  * Set the dictionary of Pinyin input method.
89  * @param obj  pointer to a Pinyin input method object
90  * @param dict pointer to a Pinyin input method dictionary
91  */
92 void lv_ime_pinyin_set_dict(lv_obj_t * obj, lv_pinyin_dict_t * dict);
93 
94 /**
95  * Set mode, 26-key input(k26) or 9-key input(k9).
96  * @param obj  pointer to a Pinyin input method object
97  * @param mode   the mode from 'lv_ime_pinyin_mode_t'
98  */
99 void lv_ime_pinyin_set_mode(lv_obj_t * obj, lv_ime_pinyin_mode_t mode);
100 
101 /*=====================
102  * Getter functions
103  *====================*/
104 
105 /**
106  * Set the dictionary of Pinyin input method.
107  * @param obj  pointer to a Pinyin IME object
108  * @return     pointer to the Pinyin IME keyboard
109  */
110 lv_obj_t * lv_ime_pinyin_get_kb(lv_obj_t * obj);
111 
112 /**
113  * Set the dictionary of Pinyin input method.
114  * @param obj  pointer to a Pinyin input method object
115  * @return     pointer to the Pinyin input method candidate panel
116  */
117 lv_obj_t * lv_ime_pinyin_get_cand_panel(lv_obj_t * obj);
118 
119 /**
120  * Set the dictionary of Pinyin input method.
121  * @param obj  pointer to a Pinyin input method object
122  * @return     pointer to the Pinyin input method dictionary
123  */
124 lv_pinyin_dict_t * lv_ime_pinyin_get_dict(lv_obj_t * obj);
125 
126 /*=====================
127  * Other functions
128  *====================*/
129 
130 /**********************
131  *      MACROS
132  **********************/
133 
134 #endif  /*LV_IME_PINYIN*/
135 
136 #ifdef __cplusplus
137 } /*extern "C"*/
138 #endif
139 
140 #endif /*LV_USE_IME_PINYIN*/
141