1 /**
2 * @file lv_msgbox.c
3 *
4 */
5
6 /*********************
7 * INCLUDES
8 *********************/
9 #include "lv_msgbox.h"
10 #if LV_USE_MSGBOX != 0
11
12 #include "../lv_misc/lv_debug.h"
13 #include "../lv_core/lv_group.h"
14 #include "../lv_core/lv_disp.h"
15 #include "../lv_themes/lv_theme.h"
16 #include "../lv_misc/lv_anim.h"
17 #include "../lv_misc/lv_math.h"
18
19 /*********************
20 * DEFINES
21 *********************/
22 #define LV_OBJX_NAME "lv_msgbox"
23
24 #if LV_USE_ANIMATION
25 #ifndef LV_MSGBOX_CLOSE_ANIM_TIME
26 #define LV_MSGBOX_CLOSE_ANIM_TIME 200 /*List close animation time) */
27 #endif
28 #else
29 #undef LV_MSGBOX_CLOSE_ANIM_TIME
30 #define LV_MSGBOX_CLOSE_ANIM_TIME 0 /*No animations*/
31 #endif
32
33 /**********************
34 * TYPEDEFS
35 **********************/
36
37 /**********************
38 * STATIC PROTOTYPES
39 **********************/
40 static lv_res_t lv_msgbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param);
41 static void mbox_realign(lv_obj_t * mbox);
42 static lv_style_list_t * lv_msgbox_get_style(lv_obj_t * mbox, uint8_t part);
43 #if LV_USE_ANIMATION
44 static void lv_msgbox_close_ready_cb(lv_anim_t * a);
45 #endif
46 static void lv_msgbox_default_event_cb(lv_obj_t * mbox, lv_event_t event);
47 static void lv_msgbox_btnm_event_cb(lv_obj_t * btnm, lv_event_t event);
48
49 /**********************
50 * STATIC VARIABLES
51 **********************/
52 static lv_signal_cb_t ancestor_signal;
53
54 /**********************
55 * MACROS
56 **********************/
57
58 /**********************
59 * GLOBAL FUNCTIONS
60 **********************/
61
62 /**
63 * Create a message box objects
64 * @param par pointer to an object, it will be the parent of the new message box
65 * @param copy pointer to a message box object, if not NULL then the new object will be copied from
66 * it
67 * @return pointer to the created message box
68 */
lv_msgbox_create(lv_obj_t * par,const lv_obj_t * copy)69 lv_obj_t * lv_msgbox_create(lv_obj_t * par, const lv_obj_t * copy)
70 {
71 LV_LOG_TRACE("message box create started");
72
73 /*Create the ancestor message box*/
74 lv_obj_t * mbox = lv_cont_create(par, copy);
75 LV_ASSERT_MEM(mbox);
76 if(mbox == NULL) return NULL;
77
78 if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(mbox);
79
80 /*Allocate the message box type specific extended data*/
81 lv_msgbox_ext_t * ext = lv_obj_allocate_ext_attr(mbox, sizeof(lv_msgbox_ext_t));
82 LV_ASSERT_MEM(ext);
83 if(ext == NULL) {
84 lv_obj_del(mbox);
85 return NULL;
86 }
87
88 ext->text = NULL;
89 ext->btnm = NULL;
90 #if LV_USE_ANIMATION
91 ext->anim_time = LV_MSGBOX_CLOSE_ANIM_TIME;
92 #endif
93
94 /*The signal and design functions are not copied so set them here*/
95 lv_obj_set_signal_cb(mbox, lv_msgbox_signal);
96
97 /*Init the new message box message box*/
98 if(copy == NULL) {
99 ext->text = lv_label_create(mbox, NULL);
100 lv_label_set_align(ext->text, LV_LABEL_ALIGN_CENTER);
101 lv_label_set_long_mode(ext->text, LV_LABEL_LONG_BREAK);
102 lv_label_set_text(ext->text, "Message");
103
104 lv_cont_set_layout(mbox, LV_LAYOUT_COLUMN_MID);
105 lv_cont_set_fit2(mbox, LV_FIT_NONE, LV_FIT_TIGHT);
106 lv_coord_t fit_w = lv_obj_get_width_fit(par);
107 if(lv_disp_get_size_category(NULL) <= LV_DISP_SIZE_SMALL) {
108 lv_obj_set_width(mbox, fit_w);
109 }
110 else {
111 lv_obj_set_width(mbox, LV_MATH_MIN(fit_w, LV_DPX(400)));
112 }
113 lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0);
114 lv_obj_set_event_cb(mbox, lv_msgbox_default_event_cb);
115
116 /*Set the default styles*/
117 lv_theme_apply(mbox, LV_THEME_MSGBOX);
118
119 }
120 /*Copy an existing message box*/
121 else {
122 lv_msgbox_ext_t * copy_ext = lv_obj_get_ext_attr(copy);
123
124 ext->text = lv_label_create(mbox, copy_ext->text);
125
126 /*Copy the buttons and the label on them*/
127 if(copy_ext->btnm) ext->btnm = lv_btnmatrix_create(mbox, copy_ext->btnm);
128
129 /*Refresh the style with new signal function*/
130 lv_obj_refresh_style(mbox, LV_OBJ_PART_ALL, LV_STYLE_PROP_ALL);
131 }
132
133 LV_LOG_INFO("message box created");
134
135 return mbox;
136 }
137
138 /*======================
139 * Add/remove functions
140 *=====================*/
141
142 /**
143 * Add button to the message box
144 * @param mbox pointer to message box object
145 * @param btn_map button descriptor (button matrix map).
146 * E.g. a const char *txt[] = {"ok", "close", ""} (Can not be local variable)
147 */
lv_msgbox_add_btns(lv_obj_t * mbox,const char * btn_map[])148 void lv_msgbox_add_btns(lv_obj_t * mbox, const char * btn_map[])
149 {
150 LV_ASSERT_OBJ(mbox, LV_OBJX_NAME);
151 LV_ASSERT_NULL(btn_map);
152
153 lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
154
155 /*Create a button matrix if not exists yet*/
156 if(ext->btnm == NULL) {
157 ext->btnm = lv_btnmatrix_create(mbox, NULL);
158
159 lv_theme_apply(mbox, LV_THEME_MSGBOX_BTNS);
160 }
161
162 lv_btnmatrix_set_map(ext->btnm, btn_map);
163 lv_btnmatrix_set_btn_ctrl_all(ext->btnm, LV_BTNMATRIX_CTRL_CLICK_TRIG | LV_BTNMATRIX_CTRL_NO_REPEAT);
164 lv_obj_set_event_cb(ext->btnm, lv_msgbox_btnm_event_cb);
165
166 if(lv_obj_is_focused(mbox)) {
167 lv_state_t state = lv_obj_get_state(mbox, LV_MSGBOX_PART_BG);
168 if(state & LV_STATE_EDITED) {
169 lv_obj_set_state(ext->btnm, LV_STATE_FOCUSED | LV_STATE_EDITED);
170 }
171 else {
172 lv_obj_set_state(ext->btnm, LV_STATE_FOCUSED);
173 }
174
175 lv_btnmatrix_set_focused_btn(ext->btnm, 0);
176 }
177
178 mbox_realign(mbox);
179 }
180
181 /*=====================
182 * Setter functions
183 *====================*/
184
185 /**
186 * Set the text of the message box
187 * @param mbox pointer to a message box
188 * @param txt a '\0' terminated character string which will be the message box text
189 */
lv_msgbox_set_text(lv_obj_t * mbox,const char * txt)190 void lv_msgbox_set_text(lv_obj_t * mbox, const char * txt)
191 {
192 LV_ASSERT_OBJ(mbox, LV_OBJX_NAME);
193 LV_ASSERT_STR(txt);
194
195 lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
196 lv_label_set_text(ext->text, txt);
197
198 mbox_realign(mbox);
199 }
200
201 /**
202 * Set animation duration
203 * @param mbox pointer to a message box object
204 * @param anim_time animation length in milliseconds (0: no animation)
205 */
lv_msgbox_set_anim_time(lv_obj_t * mbox,uint16_t anim_time)206 void lv_msgbox_set_anim_time(lv_obj_t * mbox, uint16_t anim_time)
207 {
208 LV_ASSERT_OBJ(mbox, LV_OBJX_NAME);
209
210 #if LV_USE_ANIMATION
211 lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
212 anim_time = 0;
213 ext->anim_time = anim_time;
214 #else
215 (void)mbox;
216 (void)anim_time;
217 #endif
218 }
219
220 /**
221 * Automatically delete the message box after a given time
222 * @param mbox pointer to a message box object
223 * @param delay a time (in milliseconds) to wait before delete the message box
224 */
lv_msgbox_start_auto_close(lv_obj_t * mbox,uint16_t delay)225 void lv_msgbox_start_auto_close(lv_obj_t * mbox, uint16_t delay)
226 {
227 LV_ASSERT_OBJ(mbox, LV_OBJX_NAME);
228
229 #if LV_USE_ANIMATION
230 if(lv_msgbox_get_anim_time(mbox) != 0) {
231 /*Add shrinking animations*/
232 lv_anim_t a;
233 lv_anim_init(&a);
234 lv_anim_set_var(&a, mbox);
235 lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_height);
236 lv_anim_set_values(&a, lv_obj_get_height(mbox), 0);
237 lv_anim_set_time(&a, lv_msgbox_get_anim_time(mbox));
238 lv_anim_set_delay(&a, delay);
239 lv_anim_start(&a);
240
241 lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_obj_set_width);
242 lv_anim_set_values(&a, lv_obj_get_width(mbox), 0);
243 lv_anim_set_ready_cb(&a, lv_msgbox_close_ready_cb);
244 lv_anim_start(&a);
245
246 /*Disable fit to let shrinking work*/
247 lv_cont_set_fit(mbox, LV_FIT_NONE);
248 }
249 else {
250 /*Create an animation to delete the mbox `delay` ms later*/
251 lv_anim_t a;
252 lv_anim_init(&a);
253 lv_anim_set_var(&a, mbox);
254 lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)NULL);
255 lv_anim_set_values(&a, 0, 1);
256 lv_anim_set_ready_cb(&a, lv_msgbox_close_ready_cb);
257 lv_anim_set_time(&a, lv_msgbox_get_anim_time(mbox));
258 lv_anim_set_delay(&a, delay);
259 lv_anim_start(&a);
260 }
261 #else
262 (void)delay; /*Unused*/
263 lv_obj_del(mbox);
264 #endif
265 }
266
267 /**
268 * Stop the auto. closing of message box
269 * @param mbox pointer to a message box object
270 */
lv_msgbox_stop_auto_close(lv_obj_t * mbox)271 void lv_msgbox_stop_auto_close(lv_obj_t * mbox)
272 {
273 LV_ASSERT_OBJ(mbox, LV_OBJX_NAME);
274
275 #if LV_USE_ANIMATION
276 lv_anim_del(mbox, NULL);
277 #else
278 (void)mbox; /*Unused*/
279 #endif
280 }
281
282 /**
283 * Set whether recoloring is enabled
284 * @param mbox pointer to message box object
285 * @param en whether recoloring is enabled
286 */
lv_msgbox_set_recolor(lv_obj_t * mbox,bool en)287 void lv_msgbox_set_recolor(lv_obj_t * mbox, bool en)
288 {
289 LV_ASSERT_OBJ(mbox, LV_OBJX_NAME);
290
291 lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
292
293 if(ext->btnm) lv_btnmatrix_set_recolor(ext->btnm, en);
294 }
295
296 /*=====================
297 * Getter functions
298 *====================*/
299
300 /**
301 * Get the text of the message box
302 * @param mbox pointer to a message box object
303 * @return pointer to the text of the message box
304 */
lv_msgbox_get_text(const lv_obj_t * mbox)305 const char * lv_msgbox_get_text(const lv_obj_t * mbox)
306 {
307 LV_ASSERT_OBJ(mbox, LV_OBJX_NAME);
308
309 lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
310
311 return lv_label_get_text(ext->text);
312 }
313
314 /**
315 * Get the index of the lastly "activated" button by the user (pressed, released etc)
316 * Useful in the the `event_cb`.
317 * @param mbox pointer to message box object
318 * @return index of the last released button (LV_BTNMATRIX_BTN_NONE: if unset)
319 */
lv_msgbox_get_active_btn(lv_obj_t * mbox)320 uint16_t lv_msgbox_get_active_btn(lv_obj_t * mbox)
321 {
322 LV_ASSERT_OBJ(mbox, LV_OBJX_NAME);
323
324 lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
325 if(ext->btnm == NULL) return LV_BTNMATRIX_BTN_NONE;
326
327 uint16_t id = lv_btnmatrix_get_active_btn(ext->btnm);
328 if(id == LV_BTNMATRIX_BTN_NONE) {
329 id = lv_btnmatrix_get_focused_btn(ext->btnm);
330 }
331
332 return id;
333 }
334
335 /**
336 * Get the text of the lastly "activated" button by the user (pressed, released etc)
337 * Useful in the the `event_cb`.
338 * @param mbox pointer to message box object
339 * @return text of the last released button (NULL: if unset)
340 */
lv_msgbox_get_active_btn_text(lv_obj_t * mbox)341 const char * lv_msgbox_get_active_btn_text(lv_obj_t * mbox)
342 {
343 LV_ASSERT_OBJ(mbox, LV_OBJX_NAME);
344
345 lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
346 if(ext->btnm)
347 return lv_btnmatrix_get_active_btn_text(ext->btnm);
348 else
349 return NULL;
350 }
351
352 /**
353 * Get the animation duration (close animation time)
354 * @param mbox pointer to a message box object
355 * @return animation length in milliseconds (0: no animation)
356 */
lv_msgbox_get_anim_time(const lv_obj_t * mbox)357 uint16_t lv_msgbox_get_anim_time(const lv_obj_t * mbox)
358 {
359 LV_ASSERT_OBJ(mbox, LV_OBJX_NAME);
360
361 #if LV_USE_ANIMATION
362 lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
363 return ext->anim_time;
364 #else
365 (void)mbox;
366 return 0;
367 #endif
368 }
369
370 /**
371 * Get whether recoloring is enabled
372 * @param mbox pointer to a message box object
373 * @return whether recoloring is enabled
374 */
lv_msgbox_get_recolor(const lv_obj_t * mbox)375 bool lv_msgbox_get_recolor(const lv_obj_t * mbox)
376 {
377 LV_ASSERT_OBJ(mbox, LV_OBJX_NAME);
378
379 lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
380
381 if(!ext->btnm) return false;
382
383 return lv_btnmatrix_get_recolor(ext->btnm);
384 }
385
386 /**
387 * Get message box button matrix
388 * @param mbox pointer to a message box object
389 * @return pointer to button matrix object
390 * @remarks return value will be NULL unless `lv_msgbox_add_btns` has been already called
391 */
lv_msgbox_get_btnmatrix(lv_obj_t * mbox)392 lv_obj_t * lv_msgbox_get_btnmatrix(lv_obj_t * mbox)
393 {
394 LV_ASSERT_OBJ(mbox, LV_OBJX_NAME);
395
396 lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
397 return ext->btnm;
398 }
399
400 /**********************
401 * STATIC FUNCTIONS
402 **********************/
403
404 /**
405 * Signal function of the message box
406 * @param mbox pointer to a message box object
407 * @param sign a signal type from lv_signal_t enum
408 * @param param pointer to a signal specific variable
409 * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted
410 */
lv_msgbox_signal(lv_obj_t * mbox,lv_signal_t sign,void * param)411 static lv_res_t lv_msgbox_signal(lv_obj_t * mbox, lv_signal_t sign, void * param)
412 {
413 lv_res_t res;
414
415 #if LV_USE_GROUP
416 /*Translate LV_KEY_UP/DOWN to LV_KEY_LEFT/RIGHT */
417 char c_trans = 0;
418 if(sign == LV_SIGNAL_CONTROL) {
419 c_trans = *((char *)param);
420 if(c_trans == LV_KEY_DOWN) c_trans = LV_KEY_LEFT;
421 if(c_trans == LV_KEY_UP) c_trans = LV_KEY_RIGHT;
422
423 param = &c_trans;
424 }
425 #endif
426
427 if(sign == LV_SIGNAL_GET_STYLE) {
428 lv_get_style_info_t * info = param;
429 info->result = lv_msgbox_get_style(mbox, info->part);
430 if(info->result != NULL) return LV_RES_OK;
431 else return ancestor_signal(mbox, sign, param);
432 }
433 else if(sign == LV_SIGNAL_GET_STATE_DSC) {
434 lv_get_state_info_t * info = param;
435 lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
436 if(ext->btnm && info->part == LV_MSGBOX_PART_BTN_BG) {
437 info->result = lv_obj_get_state(ext->btnm, LV_BTNMATRIX_PART_BG);
438 }
439 else if(ext->btnm && info->part == LV_MSGBOX_PART_BTN) {
440 info->result = lv_obj_get_state(ext->btnm, LV_BTNMATRIX_PART_BTN);
441 }
442 return LV_RES_OK;
443 }
444
445 /* Include the ancient signal function */
446 res = ancestor_signal(mbox, sign, param);
447 if(res != LV_RES_OK) return res;
448 if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);
449
450 lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
451 if(sign == LV_SIGNAL_COORD_CHG) {
452 if(lv_obj_get_width(mbox) != lv_area_get_width(param)) {
453 mbox_realign(mbox);
454 }
455 }
456 else if(sign == LV_SIGNAL_STYLE_CHG) {
457 mbox_realign(mbox);
458 }
459 else if(sign == LV_SIGNAL_RELEASED) {
460 if(ext->btnm) {
461 uint32_t btn_id = lv_btnmatrix_get_focused_btn(ext->btnm);
462 if(btn_id != LV_BTNMATRIX_BTN_NONE) lv_event_send(mbox, LV_EVENT_VALUE_CHANGED, &btn_id);
463 }
464 }
465 else if(
466 #if LV_USE_GROUP
467 sign == LV_SIGNAL_CONTROL || sign == LV_SIGNAL_GET_EDITABLE ||
468 #endif
469 sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS) {
470 if(ext->btnm) {
471 ext->btnm->signal_cb(ext->btnm, sign, param);
472 }
473
474 /* The button matrix with ENCODER input supposes it's in a group but in this case it isn't
475 * (Only the message box's container) So so some actions here instead*/
476 #if LV_USE_GROUP
477 if(sign == LV_SIGNAL_FOCUS) {
478 lv_indev_t * indev = lv_indev_get_act();
479 lv_indev_type_t indev_type = lv_indev_get_type(indev);
480 if(indev_type == LV_INDEV_TYPE_ENCODER) {
481 /*In navigation mode don't select any button but in edit mode select the fist*/
482 if(lv_group_get_editing(lv_obj_get_group(mbox))) lv_btnmatrix_set_focused_btn(ext->btnm, 0);
483 else lv_btnmatrix_set_focused_btn(ext->btnm, LV_BTNMATRIX_BTN_NONE);
484 }
485 }
486
487 if(ext->btnm && (sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS)) {
488 lv_state_t state = lv_obj_get_state(mbox, LV_MSGBOX_PART_BG);
489 if(state & LV_STATE_FOCUSED) {
490 lv_obj_set_state(ext->btnm, LV_STATE_FOCUSED);
491 }
492 else {
493 lv_obj_clear_state(ext->btnm, LV_STATE_FOCUSED);
494
495 }
496 if(state & LV_STATE_EDITED) {
497 lv_obj_set_state(ext->btnm, LV_STATE_EDITED);
498 }
499 else {
500 lv_obj_clear_state(ext->btnm, LV_STATE_EDITED);
501
502 }
503 }
504 #endif
505 }
506
507 return res;
508 }
509
510 /**
511 * Get the style descriptor of a part of the object
512 * @param mbox pointer the object
513 * @param part the part from `lv_msgbox_part_t`. (LV_MSGBOX_PART_...)
514 * @return pointer to the style descriptor of the specified part
515 */
lv_msgbox_get_style(lv_obj_t * mbox,uint8_t part)516 static lv_style_list_t * lv_msgbox_get_style(lv_obj_t * mbox, uint8_t part)
517 {
518 LV_ASSERT_OBJ(mbox, LV_OBJX_NAME);
519
520 lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
521 lv_style_list_t * style_dsc_p;
522
523 switch(part) {
524 case LV_MSGBOX_PART_BG:
525 style_dsc_p = &mbox->style_list;
526 break;
527 case LV_MSGBOX_PART_BTN_BG:
528 style_dsc_p = ext->btnm ? lv_obj_get_style_list(ext->btnm, LV_BTNMATRIX_PART_BG) : NULL;
529 break;
530 case LV_MSGBOX_PART_BTN:
531 style_dsc_p = ext->btnm ? lv_obj_get_style_list(ext->btnm, LV_BTNMATRIX_PART_BTN) : NULL;
532 break;
533 default:
534 style_dsc_p = NULL;
535 }
536
537 return style_dsc_p;
538 }
539
540 /**
541 * Resize the button holder to fit
542 * @param mbox pointer to message box object
543 */
mbox_realign(lv_obj_t * mbox)544 static void mbox_realign(lv_obj_t * mbox)
545 {
546 lv_msgbox_ext_t * ext = lv_obj_get_ext_attr(mbox);
547
548 lv_coord_t w = lv_obj_get_width_fit(mbox);
549
550 if(ext->text) {
551 lv_obj_set_width(ext->text, w);
552 }
553
554 if(ext->btnm) {
555 lv_style_int_t bg_top = lv_obj_get_style_pad_top(mbox, LV_MSGBOX_PART_BTN_BG);
556 lv_style_int_t bg_bottom = lv_obj_get_style_pad_bottom(mbox, LV_MSGBOX_PART_BTN_BG);
557 lv_style_int_t bg_inner = lv_obj_get_style_pad_inner(mbox, LV_MSGBOX_PART_BTN_BG);
558 lv_style_int_t btn_top = lv_obj_get_style_pad_top(mbox, LV_MSGBOX_PART_BTN);
559 lv_style_int_t btn_bottom = lv_obj_get_style_pad_bottom(mbox, LV_MSGBOX_PART_BTN);
560 const lv_font_t * font = lv_obj_get_style_text_font(mbox, LV_MSGBOX_PART_BTN);
561
562 uint16_t btnm_lines = 1;
563 const char ** btnm_map = lv_btnmatrix_get_map_array(ext->btnm);
564 uint16_t i;
565 for(i = 0; btnm_map[i][0] != '\0'; i++) {
566 if(btnm_map[i][0] == '\n') btnm_lines++;
567 }
568
569 lv_coord_t font_h = lv_font_get_line_height(font);
570 lv_coord_t btn_h = font_h + btn_top + btn_bottom;
571 lv_obj_set_size(ext->btnm, w, btn_h * btnm_lines + bg_inner * (btnm_lines - 1) + bg_top + bg_bottom);
572 }
573 }
574
575 #if LV_USE_ANIMATION
lv_msgbox_close_ready_cb(lv_anim_t * a)576 static void lv_msgbox_close_ready_cb(lv_anim_t * a)
577 {
578 lv_obj_del(a->var);
579 }
580 #endif
581
lv_msgbox_default_event_cb(lv_obj_t * mbox,lv_event_t event)582 static void lv_msgbox_default_event_cb(lv_obj_t * mbox, lv_event_t event)
583 {
584 if(event != LV_EVENT_VALUE_CHANGED) return;
585
586 uint32_t btn_id = lv_msgbox_get_active_btn(mbox);
587 if(btn_id == LV_BTNMATRIX_BTN_NONE) return;
588
589 lv_msgbox_start_auto_close(mbox, 0);
590 }
591
lv_msgbox_btnm_event_cb(lv_obj_t * btnm,lv_event_t event)592 static void lv_msgbox_btnm_event_cb(lv_obj_t * btnm, lv_event_t event)
593 {
594 lv_obj_t * mbox = lv_obj_get_parent(btnm);
595
596 /*clang-format off*/
597 if(event == LV_EVENT_PRESSED || event == LV_EVENT_PRESSING || event == LV_EVENT_PRESS_LOST ||
598 event == LV_EVENT_RELEASED || event == LV_EVENT_SHORT_CLICKED || event == LV_EVENT_CLICKED ||
599 event == LV_EVENT_LONG_PRESSED || event == LV_EVENT_LONG_PRESSED_REPEAT ||
600 event == LV_EVENT_VALUE_CHANGED) {
601 lv_event_send(mbox, event, lv_event_get_data());
602 }
603 /*clang-format on*/
604 }
605
606 #endif
607