fixes if an object is deleted in its action

This commit is contained in:
Gabor Kiss-Vamosi
2018-10-15 19:33:34 +02:00
parent 603e9336d4
commit 7e4187e89a
8 changed files with 70 additions and 59 deletions

View File

@@ -690,6 +690,9 @@ static void indev_proc_release(lv_indev_proc_t * proc)
else { else {
proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_RELEASED, indev_act); proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_RELEASED, indev_act);
} }
if(proc->reset_query != 0) return;
/*Handle click focus*/ /*Handle click focus*/
#if USE_LV_GROUP #if USE_LV_GROUP
/*Edit mode is not used by POINTER devices. So leave edit mode if we are in it*/ /*Edit mode is not used by POINTER devices. So leave edit mode if we are in it*/

View File

@@ -541,7 +541,7 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
if(txt_i != LV_BTNM_PR_NONE) { if(txt_i != LV_BTNM_PR_NONE) {
if(button_is_repeat_disabled(ext->map_p[txt_i]) == false && if(button_is_repeat_disabled(ext->map_p[txt_i]) == false &&
button_is_inactive(ext->map_p[txt_i]) == false) { button_is_inactive(ext->map_p[txt_i]) == false) {
ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i])); res = ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i]));
} }
} }
} }
@@ -549,39 +549,41 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
if(ext->btn_id_pr != LV_BTNM_PR_NONE) { if(ext->btn_id_pr != LV_BTNM_PR_NONE) {
uint16_t txt_i = get_button_text(btnm, ext->btn_id_pr); uint16_t txt_i = get_button_text(btnm, ext->btn_id_pr);
if(button_is_inactive(ext->map_p[txt_i]) == false && txt_i != LV_BTNM_PR_NONE) { /*Ignore the inactive buttons anf click between the buttons*/ if(button_is_inactive(ext->map_p[txt_i]) == false && txt_i != LV_BTNM_PR_NONE) { /*Ignore the inactive buttons anf click between the buttons*/
if(ext->action)ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i])); if(ext->action) res = ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i]));
if(res == LV_RES_OK) {
/*Invalidate to old pressed area*/; /*Invalidate to old pressed area*/;
lv_obj_get_coords(btnm, &btnm_area); lv_obj_get_coords(btnm, &btnm_area);
lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_pr]); lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_pr]);
btn_area.x1 += btnm_area.x1; btn_area.x1 += btnm_area.x1;
btn_area.y1 += btnm_area.y1; btn_area.y1 += btnm_area.y1;
btn_area.x2 += btnm_area.x1; btn_area.x2 += btnm_area.x1;
btn_area.y2 += btnm_area.y1; btn_area.y2 += btnm_area.y1;
lv_inv_area(&btn_area); lv_inv_area(&btn_area);
if(ext->toggle != 0) { if(ext->toggle != 0) {
/*Invalidate to old toggled area*/; /*Invalidate to old toggled area*/;
lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_tgl]); lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_tgl]);
btn_area.x1 += btnm_area.x1; btn_area.x1 += btnm_area.x1;
btn_area.y1 += btnm_area.y1; btn_area.y1 += btnm_area.y1;
btn_area.x2 += btnm_area.x1; btn_area.x2 += btnm_area.x1;
btn_area.y2 += btnm_area.y1; btn_area.y2 += btnm_area.y1;
lv_inv_area(&btn_area); lv_inv_area(&btn_area);
ext->btn_id_tgl = ext->btn_id_pr; ext->btn_id_tgl = ext->btn_id_pr;
} }
#if USE_LV_GROUP #if USE_LV_GROUP
/*Leave the clicked button as pressed if this the focused object in a group*/ /*Leave the clicked button as pressed if this the focused object in a group*/
lv_group_t * g = lv_obj_get_group(btnm); lv_group_t * g = lv_obj_get_group(btnm);
if(lv_group_get_focused(g) != btnm) { if(lv_group_get_focused(g) != btnm) {
ext->btn_id_pr = LV_BTNM_PR_NONE; ext->btn_id_pr = LV_BTNM_PR_NONE;
} }
#else #else
ext->btn_id_pr = LV_BTNM_PR_NONE; ext->btn_id_pr = LV_BTNM_PR_NONE;
#endif #endif
}
} }
} }
} else if(sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_DEFOCUS) { } else if(sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_DEFOCUS) {
@@ -663,7 +665,7 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
if(ext->action != NULL) { if(ext->action != NULL) {
uint16_t txt_i = get_button_text(btnm, ext->btn_id_pr); uint16_t txt_i = get_button_text(btnm, ext->btn_id_pr);
if(txt_i != LV_BTNM_PR_NONE) { if(txt_i != LV_BTNM_PR_NONE) {
ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i])); res = ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i]));
} }
} }
} }

View File

@@ -598,7 +598,7 @@ static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * par
ext->opened = 1; ext->opened = 1;
} }
lv_ddlist_refr_size(ddlist, true); if(res == LV_RES_OK) lv_ddlist_refr_size(ddlist, true);
} else if(c == LV_GROUP_KEY_ESC) { } else if(c == LV_GROUP_KEY_ESC) {
if(ext->opened) { if(ext->opened) {
ext->opened = 0; ext->opened = 0;
@@ -658,6 +658,7 @@ static lv_res_t lv_ddlist_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void *
static lv_res_t lv_ddlist_release_action(lv_obj_t * ddlist) static lv_res_t lv_ddlist_release_action(lv_obj_t * ddlist)
{ {
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist); lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
lv_res_t res = LV_RES_OK;
if(ext->opened == 0) { /*Open the list*/ if(ext->opened == 0) { /*Open the list*/
ext->opened = 1; ext->opened = 1;
@@ -688,12 +689,13 @@ static lv_res_t lv_ddlist_release_action(lv_obj_t * ddlist)
ext->sel_opt_id = new_opt; ext->sel_opt_id = new_opt;
if(ext->action != NULL) { if(ext->action != NULL) {
ext->action(ddlist); res = ext->action(ddlist);
} }
} }
lv_ddlist_refr_size(ddlist, true);
return LV_RES_OK; if(res == LV_RES_OK) lv_ddlist_refr_size(ddlist, true);
return res;
} }

View File

@@ -25,7 +25,7 @@
* STATIC PROTOTYPES * STATIC PROTOTYPES
**********************/ **********************/
static lv_res_t lv_kb_signal(lv_obj_t * kb, lv_signal_t sign, void * param); static lv_res_t lv_kb_signal(lv_obj_t * kb, lv_signal_t sign, void * param);
static lv_res_t lv_app_kb_action(lv_obj_t * kb, const char * txt); static lv_res_t lv_kb_def_action(lv_obj_t * kb, const char * txt);
/********************** /**********************
* STATIC VARIABLES * STATIC VARIABLES
@@ -104,7 +104,7 @@ lv_obj_t * lv_kb_create(lv_obj_t * par, const lv_obj_t * copy)
if(copy == NULL) { if(copy == NULL) {
lv_obj_set_size(new_kb, LV_HOR_RES, LV_VER_RES / 2); lv_obj_set_size(new_kb, LV_HOR_RES, LV_VER_RES / 2);
lv_obj_align(new_kb, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0); lv_obj_align(new_kb, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
lv_btnm_set_action(new_kb, lv_app_kb_action); lv_btnm_set_action(new_kb, lv_kb_def_action);
lv_btnm_set_map(new_kb, kb_map_lc); lv_btnm_set_map(new_kb, kb_map_lc);
/*Set the default styles*/ /*Set the default styles*/
@@ -390,9 +390,10 @@ static lv_res_t lv_kb_signal(lv_obj_t * kb, lv_signal_t sign, void * param)
* @param i the index of the released button from the current btnm map * @param i the index of the released button from the current btnm map
* @return LV_ACTION_RES_INV if the btnm is deleted else LV_ACTION_RES_OK * @return LV_ACTION_RES_INV if the btnm is deleted else LV_ACTION_RES_OK
*/ */
static lv_res_t lv_app_kb_action(lv_obj_t * kb, const char * txt) static lv_res_t lv_kb_def_action(lv_obj_t * kb, const char * txt)
{ {
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb); lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
lv_res_t res = LV_RES_OK;
/*Do the corresponding action according to the text of the button*/ /*Do the corresponding action according to the text of the button*/
if(strcmp(txt, "abc") == 0) { if(strcmp(txt, "abc") == 0) {
@@ -405,22 +406,24 @@ static lv_res_t lv_app_kb_action(lv_obj_t * kb, const char * txt)
lv_btnm_set_map(kb, kb_map_spec); lv_btnm_set_map(kb, kb_map_spec);
return LV_RES_OK; return LV_RES_OK;
} else if(strcmp(txt, SYMBOL_CLOSE) == 0) { } else if(strcmp(txt, SYMBOL_CLOSE) == 0) {
if(ext->hide_action) ext->hide_action(kb); if(ext->hide_action) res = ext->hide_action(kb);
else { else {
lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/ lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/
lv_obj_del(kb); lv_obj_del(kb);
} }
return LV_RES_INV; return LV_RES_INV;
} else if(strcmp(txt, SYMBOL_OK) == 0) { } else if(strcmp(txt, SYMBOL_OK) == 0) {
if(ext->ok_action) ext->ok_action(kb); if(ext->ok_action) res = ext->ok_action(kb);
else { else {
lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/ lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/
lv_obj_del(kb); res = lv_obj_del(kb);
} }
return LV_RES_INV;
} }
if(ext->ta == NULL) return LV_RES_OK; if(res != LV_RES_OK) return res; /*The keyboard might be deleted in the actions*/
/*Add the characters to the text area if set*/
if(ext->ta == NULL) return res;
if(strcmp(txt, "Enter") == 0)lv_ta_add_char(ext->ta, '\n'); if(strcmp(txt, "Enter") == 0)lv_ta_add_char(ext->ta, '\n');
else if(strcmp(txt, SYMBOL_LEFT) == 0) lv_ta_cursor_left(ext->ta); else if(strcmp(txt, SYMBOL_LEFT) == 0) lv_ta_cursor_left(ext->ta);

View File

@@ -650,12 +650,12 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
} }
} else if(sign == LV_SIGNAL_PRESSED) { } else if(sign == LV_SIGNAL_PRESSED) {
if(ext->pr_action != NULL) { if(ext->pr_action != NULL) {
ext->pr_action(page); res = ext->pr_action(page);
} }
} else if(sign == LV_SIGNAL_RELEASED) { } else if(sign == LV_SIGNAL_RELEASED) {
if(lv_indev_is_dragging(lv_indev_get_act()) == false) { if(lv_indev_is_dragging(lv_indev_get_act()) == false) {
if(ext->rel_action != NULL) { if(ext->rel_action != NULL) {
ext->rel_action(page); res = ext->rel_action(page);
} }
} }
} else if(sign == LV_SIGNAL_REFR_EXT_SIZE) { } else if(sign == LV_SIGNAL_REFR_EXT_SIZE) {
@@ -794,12 +794,12 @@ static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, voi
} }
} else if(sign == LV_SIGNAL_PRESSED) { } else if(sign == LV_SIGNAL_PRESSED) {
if(page_ext->pr_action != NULL) { if(page_ext->pr_action != NULL) {
page_ext->pr_action(page); res = page_ext->pr_action(page);
} }
} else if(sign == LV_SIGNAL_RELEASED) { } else if(sign == LV_SIGNAL_RELEASED) {
if(lv_indev_is_dragging(lv_indev_get_act()) == false) { if(lv_indev_is_dragging(lv_indev_get_act()) == false) {
if(page_ext->rel_action != NULL) { if(page_ext->rel_action != NULL) {
page_ext->rel_action(page); res = page_ext->rel_action(page);
} }
} }
} }

View File

@@ -415,7 +415,7 @@ static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign,
if(id < 0) id = 0; if(id < 0) id = 0;
if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1; if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1;
ext->ddlist.sel_opt_id = id; ext->ddlist.sel_opt_id = id;
if(ext->ddlist.action) ext->ddlist.action(roller); if(ext->ddlist.action) res = ext->ddlist.action(roller);
} else if(sign == LV_SIGNAL_RELEASED) { } else if(sign == LV_SIGNAL_RELEASED) {
/*If picked an option by clicking then set it*/ /*If picked an option by clicking then set it*/
if(!lv_indev_is_dragging(indev)) { if(!lv_indev_is_dragging(indev)) {
@@ -426,12 +426,12 @@ static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign,
if(id < 0) id = 0; if(id < 0) id = 0;
if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1; if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1;
ext->ddlist.sel_opt_id = id; ext->ddlist.sel_opt_id = id;
if(ext->ddlist.action) ext->ddlist.action(roller); if(ext->ddlist.action) res = ext->ddlist.action(roller);
} }
} }
/*Position the scrollable according to the new selected option*/ /*Position the scrollable according to the new selected option*/
if(id != -1) { if(id != -1 && res == LV_RES_OK) {
refr_position(roller, true); refr_position(roller, true);
} }

View File

@@ -455,13 +455,13 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par
if(tmp != ext->drag_value) { if(tmp != ext->drag_value) {
ext->drag_value = tmp; ext->drag_value = tmp;
if(ext->action != NULL) ext->action(slider);
lv_obj_invalidate(slider); lv_obj_invalidate(slider);
if(ext->action != NULL) res = ext->action(slider);
} }
} else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) { } else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) {
lv_slider_set_value(slider, ext->drag_value); lv_slider_set_value(slider, ext->drag_value);
ext->drag_value = LV_SLIDER_NOT_PRESSED; ext->drag_value = LV_SLIDER_NOT_PRESSED;
if(ext->action != NULL) ext->action(slider); if(ext->action != NULL) res = ext->action(slider);
} else if(sign == LV_SIGNAL_CORD_CHG) { } else if(sign == LV_SIGNAL_CORD_CHG) {
/* The knob size depends on slider size. /* The knob size depends on slider size.
* During the drawing method the ext. size is used by the knob so refresh the ext. size.*/ * During the drawing method the ext. size is used by the knob so refresh the ext. size.*/
@@ -498,10 +498,10 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par
#endif #endif
if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP) { if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP) {
lv_slider_set_value(slider, lv_slider_get_value(slider) + 1); lv_slider_set_value(slider, lv_slider_get_value(slider) + 1);
if(ext->action != NULL) ext->action(slider); if(ext->action != NULL) res = ext->action(slider);
} else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) { } else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) {
lv_slider_set_value(slider, lv_slider_get_value(slider) - 1); lv_slider_set_value(slider, lv_slider_get_value(slider) - 1);
if(ext->action != NULL) ext->action(slider); if(ext->action != NULL) res = ext->action(slider);
} }
} else if(sign == LV_SIGNAL_GET_EDITABLE) { } else if(sign == LV_SIGNAL_GET_EDITABLE) {
bool * editable = (bool *)param; bool * editable = (bool *)param;

View File

@@ -243,9 +243,10 @@ static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param)
if(lv_sw_get_state(sw)) lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on); if(lv_sw_get_state(sw)) lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on);
else lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off); else lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off);
if(slider_action != NULL) slider_action(sw);
ext->changed = 0; ext->changed = 0;
if(slider_action != NULL) res = slider_action(sw);
} else if(sign == LV_SIGNAL_CONTROLL) { } else if(sign == LV_SIGNAL_CONTROLL) {
char c = *((char *)param); char c = *((char *)param);
@@ -253,13 +254,13 @@ static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param)
if(old_val) lv_sw_off(sw); if(old_val) lv_sw_off(sw);
else lv_sw_on(sw); else lv_sw_on(sw);
if(slider_action) slider_action(sw); if(slider_action) res = slider_action(sw);
} else if(c == LV_GROUP_KEY_UP || c == LV_GROUP_KEY_RIGHT) { } else if(c == LV_GROUP_KEY_UP || c == LV_GROUP_KEY_RIGHT) {
lv_sw_on(sw); lv_sw_on(sw);
if(slider_action) slider_action(sw); if(slider_action) res = slider_action(sw);
} else if(c == LV_GROUP_KEY_DOWN || c == LV_GROUP_KEY_LEFT) { } else if(c == LV_GROUP_KEY_DOWN || c == LV_GROUP_KEY_LEFT) {
lv_sw_off(sw); lv_sw_off(sw);
if(slider_action) slider_action(sw); if(slider_action) res = slider_action(sw);
} }
} else if(sign == LV_SIGNAL_GET_EDITABLE) { } else if(sign == LV_SIGNAL_GET_EDITABLE) {
bool * editable = (bool *)param; bool * editable = (bool *)param;
@@ -274,7 +275,7 @@ static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param)
} }
/*Restore the callback*/ /*Restore the callback*/
ext->slider.action = slider_action; if(res == LV_RES_OK) ext->slider.action = slider_action;
return res; return res;
} }