2017-10-05 11:29:21 +02:00
|
|
|
|
2017-08-23 09:24:23 +02:00
|
|
|
/**
|
|
|
|
* @file lv_kb.c
|
2018-03-02 09:44:05 +08:00
|
|
|
*
|
2017-08-23 09:24:23 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*********************
|
|
|
|
* INCLUDES
|
|
|
|
*********************/
|
2018-07-07 11:53:22 +02:00
|
|
|
#include "lv_kb.h"
|
2019-03-07 00:05:16 +01:00
|
|
|
#if LV_USE_KB != 0
|
2017-08-23 09:24:23 +02:00
|
|
|
|
|
|
|
#include "lv_ta.h"
|
2017-11-16 15:32:33 +01:00
|
|
|
#include "../lv_themes/lv_theme.h"
|
2017-08-23 09:24:23 +02:00
|
|
|
|
|
|
|
/*********************
|
|
|
|
* DEFINES
|
|
|
|
*********************/
|
2017-11-05 00:48:57 +01:00
|
|
|
|
2017-08-23 09:24:23 +02:00
|
|
|
/**********************
|
|
|
|
* TYPEDEFS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC PROTOTYPES
|
|
|
|
**********************/
|
2017-11-10 15:01:40 +01:00
|
|
|
static lv_res_t lv_kb_signal(lv_obj_t * kb, lv_signal_t sign, void * param);
|
2019-03-12 06:20:45 +01:00
|
|
|
static void lv_kb_def_event_cb(lv_obj_t * kb);
|
2017-08-23 09:24:23 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC VARIABLES
|
|
|
|
**********************/
|
2019-02-26 09:25:46 +01:00
|
|
|
static lv_signal_cb_t ancestor_signal;
|
2017-11-10 15:01:40 +01:00
|
|
|
|
2017-08-23 09:24:23 +02:00
|
|
|
static const char * kb_map_lc[] = {
|
2019-03-12 06:20:45 +01:00
|
|
|
"#", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "Bksp", "\n",
|
|
|
|
"ABC", "a", "s", "d", "f", "g", "h", "j", "k", "l", "Enter", "\n",
|
2018-06-19 09:49:58 +02:00
|
|
|
"_", "-", "z", "x", "c", "v", "b", "n", "m", ".", ",", ":", "\n",
|
2019-03-12 06:20:45 +01:00
|
|
|
LV_SYMBOL_CLOSE, LV_SYMBOL_LEFT, " ", LV_SYMBOL_RIGHT, LV_SYMBOL_OK, ""
|
2017-08-23 09:24:23 +02:00
|
|
|
};
|
|
|
|
|
2019-02-27 06:17:37 +01:00
|
|
|
static const lv_btnm_ctrl_t kb_ctrl_lc_map[] = {
|
|
|
|
5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 7,
|
2019-03-11 06:18:44 +01:00
|
|
|
(6 | LV_BTNM_BTN_NO_REPEAT), 3, 3, 3, 3, 3, 3, 3, 3, 3, 7,
|
2019-02-27 06:17:37 +01:00
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
2, 2, 6, 2, 2
|
|
|
|
};
|
|
|
|
|
2017-08-23 09:24:23 +02:00
|
|
|
static const char * kb_map_uc[] = {
|
2019-03-12 06:20:45 +01:00
|
|
|
"#", "Q", "W", "E", "R", "T", "Y", "U", "I", "O", "P", "Bksp", "\n",
|
|
|
|
"abc", "A", "S", "D", "F", "G", "H", "J", "K", "L", "Enter", "\n",
|
2018-06-19 09:49:58 +02:00
|
|
|
"_", "-", "Z", "X", "C", "V", "B", "N", "M", ".", ",", ":", "\n",
|
2019-03-12 06:20:45 +01:00
|
|
|
LV_SYMBOL_CLOSE, LV_SYMBOL_LEFT, " ", LV_SYMBOL_RIGHT, LV_SYMBOL_OK, ""
|
2017-08-23 09:24:23 +02:00
|
|
|
};
|
|
|
|
|
2019-02-27 06:17:37 +01:00
|
|
|
static const lv_btnm_ctrl_t kb_ctrl_uc_map[] = {
|
|
|
|
5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 7,
|
2019-03-11 06:18:44 +01:00
|
|
|
(6 | LV_BTNM_BTN_NO_REPEAT), 3, 3, 3, 3, 3, 3, 3, 3, 3, 7,
|
2019-02-27 06:17:37 +01:00
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
2, 2, 6, 2, 2
|
|
|
|
};
|
|
|
|
|
2017-08-23 09:24:23 +02:00
|
|
|
static const char * kb_map_spec[] = {
|
2019-03-12 06:20:45 +01:00
|
|
|
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "Bksp", "\n",
|
|
|
|
"abc", "+", "-", "/", "*", "=", "%", "!", "?", "#", "<", ">", "\n",
|
2018-06-19 09:49:58 +02:00
|
|
|
"\\", "@", "$", "(", ")", "{", "}", "[", "]", ";", "\"", "'", "\n",
|
2019-03-12 06:20:45 +01:00
|
|
|
LV_SYMBOL_CLOSE, LV_SYMBOL_LEFT, " ", LV_SYMBOL_RIGHT, LV_SYMBOL_OK, ""
|
2017-08-23 09:24:23 +02:00
|
|
|
};
|
|
|
|
|
2019-02-27 06:17:37 +01:00
|
|
|
static const lv_btnm_ctrl_t kb_ctrl_spec_map[] = {
|
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,
|
2019-03-11 06:18:44 +01:00
|
|
|
(2 | LV_BTNM_BTN_NO_REPEAT), 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
2019-02-27 06:17:37 +01:00
|
|
|
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
|
|
2, 2, 6, 2, 2
|
|
|
|
};
|
|
|
|
|
2017-08-23 09:24:23 +02:00
|
|
|
static const char * kb_map_num[] = {
|
2019-03-07 00:05:16 +01:00
|
|
|
"1", "2", "3", "\202"LV_SYMBOL_CLOSE, "\n",
|
|
|
|
"4", "5", "6", "\202"LV_SYMBOL_OK, "\n",
|
2018-12-27 10:32:05 -05:00
|
|
|
"7", "8", "9", "\202Bksp", "\n",
|
2019-03-07 00:05:16 +01:00
|
|
|
"+/-", "0", ".", LV_SYMBOL_LEFT, LV_SYMBOL_RIGHT, ""
|
2017-08-23 09:24:23 +02:00
|
|
|
};
|
2019-02-27 06:17:37 +01:00
|
|
|
|
|
|
|
static const lv_btnm_ctrl_t kb_ctrl_num_map[] = {
|
2019-03-01 15:56:27 +08:00
|
|
|
1, 1, 1, 2,
|
2019-02-27 06:17:37 +01:00
|
|
|
1, 1, 1, 2,
|
|
|
|
1, 1, 1, 2,
|
|
|
|
1, 1, 1, 1, 1
|
|
|
|
};
|
2017-08-23 09:24:23 +02:00
|
|
|
/**********************
|
|
|
|
* MACROS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**********************
|
|
|
|
* GLOBAL FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a keyboard objects
|
|
|
|
* @param par pointer to an object, it will be the parent of the new keyboard
|
|
|
|
* @param copy pointer to a keyboard object, if not NULL then the new object will be copied from it
|
|
|
|
* @return pointer to the created keyboard
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_obj_t * lv_kb_create(lv_obj_t * par, const lv_obj_t * copy)
|
2017-08-23 09:24:23 +02:00
|
|
|
{
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_TRACE("keyboard create started");
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2017-08-23 09:24:23 +02:00
|
|
|
/*Create the ancestor of keyboard*/
|
|
|
|
lv_obj_t * new_kb = lv_btnm_create(par, copy);
|
2017-11-26 11:38:28 +01:00
|
|
|
lv_mem_assert(new_kb);
|
2018-07-25 13:33:53 +02:00
|
|
|
if(new_kb == NULL) return NULL;
|
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_func(new_kb);
|
2018-03-02 09:44:05 +08:00
|
|
|
|
2017-08-23 09:24:23 +02:00
|
|
|
/*Allocate the keyboard type specific extended data*/
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_kb_ext_t * ext = lv_obj_allocate_ext_attr(new_kb, sizeof(lv_kb_ext_t));
|
2017-11-26 11:38:28 +01:00
|
|
|
lv_mem_assert(ext);
|
2018-07-25 13:33:53 +02:00
|
|
|
if(ext == NULL) return NULL;
|
2017-08-23 09:24:23 +02:00
|
|
|
|
|
|
|
/*Initialize the allocated 'ext' */
|
|
|
|
|
|
|
|
ext->ta = NULL;
|
2017-10-30 17:11:56 +01:00
|
|
|
ext->mode = LV_KB_MODE_TEXT;
|
2017-11-18 00:18:19 +01:00
|
|
|
ext->cursor_mng = 0;
|
2017-08-23 09:24:23 +02:00
|
|
|
|
|
|
|
/*The signal and design functions are not copied so set them here*/
|
2019-02-26 09:25:46 +01:00
|
|
|
lv_obj_set_signal_cb(new_kb, lv_kb_signal);
|
2017-08-23 09:24:23 +02:00
|
|
|
|
|
|
|
/*Init the new keyboard keyboard*/
|
|
|
|
if(copy == NULL) {
|
2019-02-07 19:17:10 +01:00
|
|
|
lv_obj_set_size(new_kb, LV_DPI * 3, LV_DPI * 2);
|
2017-08-23 09:24:23 +02:00
|
|
|
lv_obj_align(new_kb, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
|
|
|
lv_btnm_set_map(new_kb, kb_map_lc);
|
2019-02-27 06:17:37 +01:00
|
|
|
lv_btnm_set_ctrl_map(new_kb, kb_ctrl_lc_map);
|
2017-11-16 15:32:33 +01:00
|
|
|
|
|
|
|
/*Set the default styles*/
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_theme_t * th = lv_theme_get_current();
|
2017-11-16 15:32:33 +01:00
|
|
|
if(th) {
|
2019-02-11 09:35:06 +01:00
|
|
|
lv_kb_set_style(new_kb, LV_KB_STYLE_BG, th->style.kb.bg);
|
|
|
|
lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_REL, th->style.kb.btn.rel);
|
|
|
|
lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_PR, th->style.kb.btn.pr);
|
|
|
|
lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_TGL_REL, th->style.kb.btn.tgl_rel);
|
|
|
|
lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_TGL_PR, th->style.kb.btn.tgl_pr);
|
|
|
|
lv_kb_set_style(new_kb, LV_KB_STYLE_BTN_INA, th->style.kb.btn.ina);
|
2017-11-16 15:32:33 +01:00
|
|
|
} else {
|
|
|
|
/*Let the button matrix's styles*/
|
|
|
|
}
|
2017-08-23 09:24:23 +02:00
|
|
|
}
|
|
|
|
/*Copy an existing keyboard*/
|
|
|
|
else {
|
2018-06-19 09:49:58 +02:00
|
|
|
lv_kb_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
|
|
|
|
ext->ta = NULL;
|
2017-08-23 09:24:23 +02:00
|
|
|
ext->ta = copy_ext->ta;
|
|
|
|
ext->mode = copy_ext->mode;
|
2017-11-18 00:18:19 +01:00
|
|
|
ext->cursor_mng = copy_ext->cursor_mng;
|
2017-08-23 09:24:23 +02:00
|
|
|
|
|
|
|
/*Refresh the style with new signal function*/
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_obj_refresh_style(new_kb);
|
2017-08-23 09:24:23 +02:00
|
|
|
}
|
2018-03-02 09:44:05 +08:00
|
|
|
|
2018-07-25 20:39:24 +02:00
|
|
|
|
2018-10-05 17:22:49 +02:00
|
|
|
LV_LOG_INFO("keyboard created");
|
2018-07-25 20:39:24 +02:00
|
|
|
|
2018-07-25 17:57:08 +02:00
|
|
|
|
2017-08-23 09:24:23 +02:00
|
|
|
return new_kb;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*=====================
|
|
|
|
* Setter functions
|
|
|
|
*====================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assign a Text Area to the Keyboard. The pressed characters will be put there.
|
|
|
|
* @param kb pointer to a Keyboard object
|
|
|
|
* @param ta pointer to a Text Area object to write there
|
|
|
|
*/
|
|
|
|
void lv_kb_set_ta(lv_obj_t * kb, lv_obj_t * ta)
|
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
|
2017-11-18 00:18:19 +01:00
|
|
|
lv_cursor_type_t cur_type;
|
|
|
|
|
2018-05-16 23:09:30 +02:00
|
|
|
/*Hide the cursor of the old Text area if cursor management is enabled*/
|
2017-11-18 00:18:19 +01:00
|
|
|
if(ext->ta && ext->cursor_mng) {
|
|
|
|
cur_type = lv_ta_get_cursor_type(ext->ta);
|
|
|
|
lv_ta_set_cursor_type(ext->ta, cur_type | LV_CURSOR_HIDDEN);
|
|
|
|
}
|
2017-08-23 09:24:23 +02:00
|
|
|
|
|
|
|
ext->ta = ta;
|
2017-11-18 00:18:19 +01:00
|
|
|
|
2018-05-16 23:09:30 +02:00
|
|
|
/*Show the cursor of the new Text area if cursor management is enabled*/
|
2017-12-19 22:00:32 +01:00
|
|
|
if(ext->ta && ext->cursor_mng) {
|
2017-11-18 00:18:19 +01:00
|
|
|
cur_type = lv_ta_get_cursor_type(ext->ta);
|
|
|
|
lv_ta_set_cursor_type(ext->ta, cur_type & (~LV_CURSOR_HIDDEN));
|
|
|
|
}
|
2017-08-23 09:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a new a mode (text or number map)
|
|
|
|
* @param kb pointer to a Keyboard object
|
|
|
|
* @param mode the mode from 'lv_kb_mode_t'
|
|
|
|
*/
|
|
|
|
void lv_kb_set_mode(lv_obj_t * kb, lv_kb_mode_t mode)
|
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
|
2018-05-16 23:09:30 +02:00
|
|
|
if(ext->mode == mode) return;
|
|
|
|
|
2017-08-23 09:24:23 +02:00
|
|
|
ext->mode = mode;
|
2019-02-27 06:17:37 +01:00
|
|
|
if(mode == LV_KB_MODE_TEXT) {
|
|
|
|
lv_btnm_set_map(kb, kb_map_lc);
|
|
|
|
lv_btnm_set_ctrl_map(kb, kb_ctrl_lc_map);
|
|
|
|
}
|
|
|
|
else if(mode == LV_KB_MODE_NUM) {
|
|
|
|
lv_btnm_set_map(kb, kb_map_num);
|
|
|
|
lv_btnm_set_ctrl_map(kb, kb_ctrl_num_map);
|
|
|
|
}
|
2017-08-23 09:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Automatically hide or show the cursor of Text Area
|
|
|
|
* @param kb pointer to a Keyboard object
|
|
|
|
* @param en true: show cursor on the current text area, false: hide cursor
|
|
|
|
*/
|
2017-11-05 00:48:57 +01:00
|
|
|
void lv_kb_set_cursor_manage(lv_obj_t * kb, bool en)
|
2017-08-23 09:24:23 +02:00
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
|
2018-05-16 23:09:30 +02:00
|
|
|
if(ext->cursor_mng == en) return;
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
ext->cursor_mng = en == false ? 0 : 1;
|
2017-08-23 09:24:23 +02:00
|
|
|
|
2017-11-18 00:18:19 +01:00
|
|
|
if(ext->ta) {
|
|
|
|
lv_cursor_type_t cur_type;
|
|
|
|
cur_type = lv_ta_get_cursor_type(ext->ta);
|
2018-03-02 09:44:05 +08:00
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
if(ext->cursor_mng) {
|
2018-03-02 09:44:05 +08:00
|
|
|
lv_ta_set_cursor_type(ext->ta, cur_type & (~LV_CURSOR_HIDDEN));
|
2018-06-19 09:49:58 +02:00
|
|
|
} else {
|
2018-03-02 09:44:05 +08:00
|
|
|
lv_ta_set_cursor_type(ext->ta, cur_type | LV_CURSOR_HIDDEN);
|
|
|
|
}
|
2017-11-18 00:18:19 +01:00
|
|
|
}
|
2017-08-23 09:24:23 +02:00
|
|
|
}
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/**
|
|
|
|
* Set a style of a keyboard
|
|
|
|
* @param kb pointer to a keyboard object
|
|
|
|
* @param type which style should be set
|
|
|
|
* @param style pointer to a style
|
|
|
|
*/
|
2018-06-19 09:49:58 +02:00
|
|
|
void lv_kb_set_style(lv_obj_t * kb, lv_kb_style_t type, lv_style_t * style)
|
2017-11-15 15:50:33 +01:00
|
|
|
{
|
2018-06-19 09:49:58 +02:00
|
|
|
switch(type) {
|
2017-11-15 15:50:33 +01:00
|
|
|
case LV_KB_STYLE_BG:
|
|
|
|
lv_btnm_set_style(kb, LV_BTNM_STYLE_BG, style);
|
|
|
|
break;
|
|
|
|
case LV_KB_STYLE_BTN_REL:
|
|
|
|
lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_REL, style);
|
|
|
|
break;
|
|
|
|
case LV_KB_STYLE_BTN_PR:
|
|
|
|
lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_PR, style);
|
|
|
|
break;
|
|
|
|
case LV_KB_STYLE_BTN_TGL_REL:
|
|
|
|
lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_TGL_REL, style);
|
|
|
|
break;
|
|
|
|
case LV_KB_STYLE_BTN_TGL_PR:
|
|
|
|
lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_TGL_PR, style);
|
|
|
|
break;
|
|
|
|
case LV_KB_STYLE_BTN_INA:
|
|
|
|
lv_btnm_set_style(kb, LV_BTNM_STYLE_BTN_INA, style);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-10-05 11:29:21 +02:00
|
|
|
|
2017-08-23 09:24:23 +02:00
|
|
|
/*=====================
|
|
|
|
* Getter functions
|
|
|
|
*====================*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assign a Text Area to the Keyboard. The pressed characters will be put there.
|
|
|
|
* @param kb pointer to a Keyboard object
|
|
|
|
* @return pointer to the assigned Text Area object
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_obj_t * lv_kb_get_ta(const lv_obj_t * kb)
|
2017-08-23 09:24:23 +02:00
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
|
2017-08-23 09:24:23 +02:00
|
|
|
return ext->ta;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a new a mode (text or number map)
|
|
|
|
* @param kb pointer to a Keyboard object
|
|
|
|
* @return the current mode from 'lv_kb_mode_t'
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_kb_mode_t lv_kb_get_mode(const lv_obj_t * kb)
|
2017-08-23 09:24:23 +02:00
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
|
2017-08-23 09:24:23 +02:00
|
|
|
return ext->mode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current cursor manage mode.
|
|
|
|
* @param kb pointer to a Keyboard object
|
|
|
|
* @return true: show cursor on the current text area, false: hide cursor
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
bool lv_kb_get_cursor_manage(const lv_obj_t * kb)
|
2017-08-23 09:24:23 +02:00
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
|
2017-11-18 00:18:19 +01:00
|
|
|
return ext->cursor_mng == 0 ? false : true;
|
2017-08-23 09:24:23 +02:00
|
|
|
}
|
|
|
|
|
2017-11-15 15:50:33 +01:00
|
|
|
/**
|
|
|
|
* Get a style of a keyboard
|
|
|
|
* @param kb pointer to a keyboard object
|
|
|
|
* @param type which style should be get
|
|
|
|
* @return style pointer to a style
|
|
|
|
*/
|
2018-07-30 06:52:29 +02:00
|
|
|
lv_style_t * lv_kb_get_style(const lv_obj_t * kb, lv_kb_style_t type)
|
2017-11-15 15:50:33 +01:00
|
|
|
{
|
2018-11-05 22:21:20 -06:00
|
|
|
lv_style_t * style = NULL;
|
|
|
|
|
2018-06-19 09:49:58 +02:00
|
|
|
switch(type) {
|
|
|
|
case LV_KB_STYLE_BG:
|
2018-11-05 22:21:20 -06:00
|
|
|
style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BG);
|
|
|
|
break;
|
2018-06-19 09:49:58 +02:00
|
|
|
case LV_KB_STYLE_BTN_REL:
|
2018-11-05 22:21:20 -06:00
|
|
|
style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_REL);
|
|
|
|
break;
|
2018-06-19 09:49:58 +02:00
|
|
|
case LV_KB_STYLE_BTN_PR:
|
2018-11-05 22:21:20 -06:00
|
|
|
style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_PR);
|
|
|
|
break;
|
2018-06-19 09:49:58 +02:00
|
|
|
case LV_KB_STYLE_BTN_TGL_REL:
|
2018-11-05 22:21:20 -06:00
|
|
|
style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_TGL_REL);
|
|
|
|
break;
|
2018-06-19 09:49:58 +02:00
|
|
|
case LV_KB_STYLE_BTN_TGL_PR:
|
2018-11-05 22:21:20 -06:00
|
|
|
style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_TGL_PR);
|
|
|
|
break;
|
2018-06-19 09:49:58 +02:00
|
|
|
case LV_KB_STYLE_BTN_INA:
|
2018-11-05 22:21:20 -06:00
|
|
|
style = lv_btnm_get_style(kb, LV_BTNM_STYLE_BTN_INA);
|
|
|
|
break;
|
2018-06-19 09:49:58 +02:00
|
|
|
default:
|
2018-11-05 22:21:20 -06:00
|
|
|
style = NULL;
|
|
|
|
break;
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
|
|
|
|
2018-11-05 22:21:20 -06:00
|
|
|
return style;
|
2017-11-15 15:50:33 +01:00
|
|
|
}
|
2017-08-23 09:24:23 +02:00
|
|
|
|
|
|
|
/**********************
|
|
|
|
* STATIC FUNCTIONS
|
|
|
|
**********************/
|
|
|
|
|
|
|
|
/**
|
2017-11-10 15:01:40 +01:00
|
|
|
* Signal function of the keyboard
|
|
|
|
* @param kb pointer to a keyboard object
|
|
|
|
* @param sign a signal type from lv_signal_t enum
|
|
|
|
* @param param pointer to a signal specific variable
|
|
|
|
* @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
|
2017-08-23 09:24:23 +02:00
|
|
|
*/
|
2017-11-10 15:01:40 +01:00
|
|
|
static lv_res_t lv_kb_signal(lv_obj_t * kb, lv_signal_t sign, void * param)
|
2017-08-23 09:24:23 +02:00
|
|
|
{
|
2017-11-10 15:01:40 +01:00
|
|
|
lv_res_t res;
|
2017-08-23 09:24:23 +02:00
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
/* Include the ancient signal function */
|
|
|
|
res = ancestor_signal(kb, sign, param);
|
|
|
|
if(res != LV_RES_OK) return res;
|
2017-08-23 09:24:23 +02:00
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
if(sign == LV_SIGNAL_CLEANUP) {
|
|
|
|
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
|
2019-03-12 06:20:45 +01:00
|
|
|
}
|
2019-03-12 14:29:37 +01:00
|
|
|
else if(sign == LV_SIGNAL_PRESSED) {
|
2019-03-12 06:20:45 +01:00
|
|
|
lv_kb_def_event_cb(kb);
|
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_LONG_PRESS_REP) {
|
|
|
|
bool no_rep = lv_btnm_get_btn_no_repeate(kb, lv_btnm_get_active_btn(kb));
|
|
|
|
if(no_rep == false) lv_kb_def_event_cb(kb);
|
|
|
|
}
|
2019-03-12 14:29:37 +01:00
|
|
|
else if(sign == LV_SIGNAL_FOCUS) {
|
|
|
|
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
|
|
|
|
/*Show the cursor of the new Text area if cursor management is enabled*/
|
|
|
|
if(ext->ta && ext->cursor_mng) {
|
|
|
|
lv_cursor_type_t cur_type = lv_ta_get_cursor_type(ext->ta);
|
|
|
|
lv_ta_set_cursor_type(ext->ta, cur_type & (~LV_CURSOR_HIDDEN));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(sign == LV_SIGNAL_DEFOCUS) {
|
|
|
|
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
|
|
|
|
/*Show the cursor of the new Text area if cursor management is enabled*/
|
|
|
|
if(ext->ta && ext->cursor_mng) {
|
|
|
|
lv_cursor_type_t cur_type = lv_ta_get_cursor_type(ext->ta);
|
|
|
|
lv_ta_set_cursor_type(ext->ta, cur_type | LV_CURSOR_HIDDEN);
|
|
|
|
}
|
|
|
|
}
|
2019-03-12 06:20:45 +01:00
|
|
|
else if(sign == LV_SIGNAL_GET_TYPE) {
|
2018-02-28 15:37:41 +01:00
|
|
|
lv_obj_type_t * buf = param;
|
|
|
|
uint8_t i;
|
|
|
|
for(i = 0; i < LV_MAX_ANCESTOR_NUM - 1; i++) { /*Find the last set data*/
|
|
|
|
if(buf->type[i] == NULL) break;
|
|
|
|
}
|
|
|
|
buf->type[i] = "lv_kb";
|
|
|
|
}
|
2017-08-23 09:24:23 +02:00
|
|
|
|
2017-11-10 15:01:40 +01:00
|
|
|
return res;
|
2017-08-23 09:24:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2019-03-12 06:20:45 +01:00
|
|
|
* Called when a button of the keyboard is released
|
|
|
|
* @param kb pointer to a keyboard
|
|
|
|
* @param event type of the event
|
2017-08-23 09:24:23 +02:00
|
|
|
*/
|
2019-03-12 06:20:45 +01:00
|
|
|
static void lv_kb_def_event_cb(lv_obj_t * kb)
|
2017-08-23 09:24:23 +02:00
|
|
|
{
|
2017-10-20 10:17:02 +02:00
|
|
|
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
|
2019-03-12 06:20:45 +01:00
|
|
|
|
|
|
|
uint16_t btn_id = lv_btnm_get_active_btn(kb);
|
|
|
|
if(btn_id == LV_BTNM_BTN_NONE) return;
|
|
|
|
if(lv_btnm_get_btn_hidden(kb, btn_id)) return;
|
|
|
|
if(lv_btnm_get_btn_inactive(kb, btn_id)) return;
|
|
|
|
|
|
|
|
const char * txt = lv_btnm_get_active_btn_text(kb);
|
|
|
|
if(txt == NULL) return;
|
2017-08-23 09:24:23 +02:00
|
|
|
|
|
|
|
/*Do the corresponding action according to the text of the button*/
|
2017-11-16 15:32:33 +01:00
|
|
|
if(strcmp(txt, "abc") == 0) {
|
|
|
|
lv_btnm_set_map(kb, kb_map_lc);
|
2019-02-27 06:17:37 +01:00
|
|
|
lv_btnm_set_ctrl_map(kb, kb_ctrl_lc_map);
|
2019-03-12 06:20:45 +01:00
|
|
|
return;
|
2018-06-19 09:49:58 +02:00
|
|
|
} else if(strcmp(txt, "ABC") == 0) {
|
2017-11-16 15:32:33 +01:00
|
|
|
lv_btnm_set_map(kb, kb_map_uc);
|
2019-02-27 06:17:37 +01:00
|
|
|
lv_btnm_set_ctrl_map(kb, kb_ctrl_uc_map);
|
2019-03-12 06:20:45 +01:00
|
|
|
return;
|
2018-06-19 09:49:58 +02:00
|
|
|
} else if(strcmp(txt, "1#") == 0) {
|
2017-11-16 15:32:33 +01:00
|
|
|
lv_btnm_set_map(kb, kb_map_spec);
|
2019-02-27 06:17:37 +01:00
|
|
|
lv_btnm_set_ctrl_map(kb, kb_ctrl_spec_map);
|
2019-03-12 06:20:45 +01:00
|
|
|
return;
|
2019-03-07 00:05:16 +01:00
|
|
|
} else if(strcmp(txt, LV_SYMBOL_CLOSE) == 0) {
|
2019-03-07 00:42:08 +01:00
|
|
|
if(kb->event_cb) {
|
2019-03-12 06:20:45 +01:00
|
|
|
lv_obj_send_event(kb, LV_EVENT_CANCEL);
|
2019-03-07 00:42:08 +01:00
|
|
|
}
|
2018-04-13 20:09:14 +02:00
|
|
|
else {
|
|
|
|
lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/
|
|
|
|
lv_obj_del(kb);
|
|
|
|
}
|
2019-03-12 06:20:45 +01:00
|
|
|
return;
|
2019-03-07 00:05:16 +01:00
|
|
|
} else if(strcmp(txt, LV_SYMBOL_OK) == 0) {
|
2019-03-12 06:20:45 +01:00
|
|
|
if(kb->event_cb) lv_obj_send_event(kb, LV_EVENT_APPLY);
|
|
|
|
else lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/
|
|
|
|
return;
|
2017-11-10 15:01:40 +01:00
|
|
|
}
|
|
|
|
|
2018-10-15 19:33:34 +02:00
|
|
|
/*Add the characters to the text area if set*/
|
2019-03-12 06:20:45 +01:00
|
|
|
if(ext->ta == NULL) return;
|
2017-11-10 15:01:40 +01:00
|
|
|
|
|
|
|
if(strcmp(txt, "Enter") == 0)lv_ta_add_char(ext->ta, '\n');
|
2019-03-07 00:05:16 +01:00
|
|
|
else if(strcmp(txt, LV_SYMBOL_LEFT) == 0) lv_ta_cursor_left(ext->ta);
|
|
|
|
else if(strcmp(txt, LV_SYMBOL_RIGHT) == 0) lv_ta_cursor_right(ext->ta);
|
2018-12-27 10:32:05 -05:00
|
|
|
else if(strcmp(txt, "Bksp") == 0) lv_ta_del_char(ext->ta);
|
2017-11-10 15:01:40 +01:00
|
|
|
else if(strcmp(txt, "+/-") == 0) {
|
2017-08-23 09:24:23 +02:00
|
|
|
uint16_t cur = lv_ta_get_cursor_pos(ext->ta);
|
2017-11-05 00:48:57 +01:00
|
|
|
const char * ta_txt = lv_ta_get_text(ext->ta);
|
2017-08-23 09:24:23 +02:00
|
|
|
if(ta_txt[0] == '-') {
|
|
|
|
lv_ta_set_cursor_pos(ext->ta, 1);
|
2017-11-15 15:50:33 +01:00
|
|
|
lv_ta_del_char(ext->ta);
|
2017-08-23 09:24:23 +02:00
|
|
|
lv_ta_add_char(ext->ta, '+');
|
|
|
|
lv_ta_set_cursor_pos(ext->ta, cur);
|
|
|
|
} else if(ta_txt[0] == '+') {
|
|
|
|
lv_ta_set_cursor_pos(ext->ta, 1);
|
2017-11-15 15:50:33 +01:00
|
|
|
lv_ta_del_char(ext->ta);
|
2017-08-23 09:24:23 +02:00
|
|
|
lv_ta_add_char(ext->ta, '-');
|
|
|
|
lv_ta_set_cursor_pos(ext->ta, cur);
|
|
|
|
} else {
|
|
|
|
lv_ta_set_cursor_pos(ext->ta, 0);
|
|
|
|
lv_ta_add_char(ext->ta, '-');
|
|
|
|
lv_ta_set_cursor_pos(ext->ta, cur + 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
lv_ta_add_text(ext->ta, txt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|