// File: /workspace/github_c_makefile_star2_O3/OnionIoT[P]lv_example/lvgl/src/lv_objx/lv_kb.c
// Function: lv_kb_def_event_cb
void lv_kb_def_event_cb(lv_obj_t * kb, lv_event_t event)
{
    LV_ASSERT_OBJ(kb, LV_OBJX_NAME);

    if(event != LV_EVENT_VALUE_CHANGED) return;

    lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
    uint16_t btn_id   = lv_btnm_get_active_btn(kb);
    if(btn_id == LV_BTNM_BTN_NONE) return;
    if(lv_btnm_get_btn_ctrl(kb, btn_id, LV_BTNM_CTRL_HIDDEN | LV_BTNM_CTRL_INACTIVE)) return;
    if(lv_btnm_get_btn_ctrl(kb, btn_id, LV_BTNM_CTRL_NO_REPEAT) && event == LV_EVENT_LONG_PRESSED_REPEAT) return;

    const char * txt = lv_btnm_get_active_btn_text(kb);
    if(txt == NULL) return;

    /*Do the corresponding action according to the text of the button*/
    if(strcmp(txt, "abc") == 0) {
        lv_btnm_set_map(kb, kb_map_lc);
        lv_btnm_set_ctrl_map(kb, kb_ctrl_lc_map);
        return;
    } else if(strcmp(txt, "ABC") == 0) {
        lv_btnm_set_map(kb, kb_map_uc);
        lv_btnm_set_ctrl_map(kb, kb_ctrl_uc_map);
        return;
    } else if(strcmp(txt, "1#") == 0) {
        lv_btnm_set_map(kb, kb_map_spec);
        lv_btnm_set_ctrl_map(kb, kb_ctrl_spec_map);
        return;
    } else if(strcmp(txt, LV_SYMBOL_CLOSE) == 0) {
        if(kb->event_cb != lv_kb_def_event_cb) {
            lv_res_t res = lv_event_send(kb, LV_EVENT_CANCEL, NULL);
            if(res != LV_RES_OK) return;
        } else {
            lv_kb_set_ta(kb, NULL); /*De-assign the text area  to hide it cursor if needed*/
            lv_obj_del(kb);
            return;
        }
        return;
    } else if(strcmp(txt, LV_SYMBOL_OK) == 0) {
        if(kb->event_cb != lv_kb_def_event_cb) {
            lv_res_t res = lv_event_send(kb, LV_EVENT_APPLY, NULL);
            if(res != LV_RES_OK) return;
        } else {
            lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/
        }
        return;
    }

    /*Add the characters to the text area if set*/
    if(ext->ta == NULL) return;

    if(strcmp(txt, "Enter") == 0 || strcmp(txt, LV_SYMBOL_NEW_LINE) == 0)
        lv_ta_add_char(ext->ta, '\n');
    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);
    else if(strcmp(txt, LV_SYMBOL_BACKSPACE) == 0)
        lv_ta_del_char(ext->ta);
    else if(strcmp(txt, "+/-") == 0) {
        uint16_t cur        = lv_ta_get_cursor_pos(ext->ta);
        const char * ta_txt = lv_ta_get_text(ext->ta);
        if(ta_txt[0] == '-') {
            lv_ta_set_cursor_pos(ext->ta, 1);
            lv_ta_del_char(ext->ta);
            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);
            lv_ta_del_char(ext->ta);
            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);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
callq 0x80e4
testb %al, %al
je 0xcc93
cmpb $0xe, %bl
jne 0xcca4
movq %r14, %rdi
callq 0x6af7
movq %rax, %rbx
movq %r14, %rdi
callq 0x228e6
cmpw $-0x1, %ax
je 0xcca4
movzwl %ax, %ebp
movq %r14, %rdi
movl %ebp, %esi
movl $0x28, %edx
callq 0x22a08
testb %al, %al
jne 0xcca4
movq %r14, %rdi
movl %ebp, %esi
movl $0x10, %edx
callq 0x22a08
movq %r14, %rdi
callq 0x22912
testq %rax, %rax
je 0xcca4
movq %rax, %r15
leaq 0x3280b(%rip), %rsi     # 0x3f385
movq %rax, %rdi
callq 0x20e0
testl %eax, %eax
je 0xccaf
leaq 0x327f8(%rip), %rsi     # 0x3f389
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xccc7
cmpb $0x31, (%r15)
jne 0xcbb9
cmpb $0x23, 0x1(%r15)
jne 0xcbb9
cmpb $0x0, 0x2(%r15)
je 0xcd5f
leaq 0x327d0(%rip), %rsi     # 0x3f390
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xccef
leaq 0x327bd(%rip), %rsi     # 0x3f394
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xcd06
movq 0x48(%rbx), %r14
testq %r14, %r14
je 0xcca4
leaq 0x3279d(%rip), %rsi     # 0x3f398
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xcd2c
leaq 0x3278c(%rip), %rsi     # 0x3f39e
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xcd2c
leaq 0x32779(%rip), %rsi     # 0x3f3a2
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xcd8e
leaq 0x32766(%rip), %rsi     # 0x3f3a6
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xcda0
leaq 0x32753(%rip), %rsi     # 0x3f3aa
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xcdb2
leaq 0x32740(%rip), %rsi     # 0x3f3ae
movq %r15, %rdi
callq 0x20e0
movq %r14, %rdi
testl %eax, %eax
je 0xcdc4
movq %r15, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1f336
leaq 0x3254a(%rip), %rdi     # 0x3f1e4
movq %r14, %rsi
callq 0x8294
jmp 0xcca2
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x463fa(%rip), %rsi     # 0x530b0
movq %r14, %rdi
callq 0x21f33
leaq 0x3276b(%rip), %rsi     # 0x3f430
jmp 0xccdd
leaq 0x465f2(%rip), %rsi     # 0x532c0
movq %r14, %rdi
callq 0x21f33
leaq 0x327d3(%rip), %rsi     # 0x3f4b0
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x22507
leaq -0x1ff(%rip), %rax      # 0xcaf7
cmpq %rax, 0x28(%r14)
je 0xcd43
movq %r14, %rdi
movl $0x12, %esi
jmp 0xcd1b
leaq -0x216(%rip), %rax      # 0xcaf7
cmpq %rax, 0x28(%r14)
je 0xcd7a
movq %r14, %rdi
movl $0x11, %esi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x5018
movq %r14, %rdi
movl $0xa, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1f08f
movq %r14, %rdi
xorl %esi, %esi
callq 0xce9b
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x4d59
leaq 0x466ba(%rip), %rsi     # 0x53420
movq %r14, %rdi
callq 0x21f33
leaq 0x3278b(%rip), %rsi     # 0x3f500
jmp 0xccdd
movq %r14, %rdi
xorl %esi, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xce9b
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x208ab
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x20877
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1f948
callq 0x1f823
movl %eax, %ebp
movq 0x48(%rbx), %rdi
callq 0x2069b
movzbl (%rax), %eax
movq 0x48(%rbx), %rdi
cmpl $0x2b, %eax
je 0xce03
cmpl $0x2d, %eax
jne 0xce2a
movl $0x1, %esi
callq 0x1f5c6
movq 0x48(%rbx), %rdi
callq 0x1f948
movq 0x48(%rbx), %rdi
movl $0x2b, %esi
jmp 0xce1f
movl $0x1, %esi
callq 0x1f5c6
movq 0x48(%rbx), %rdi
callq 0x1f948
movq 0x48(%rbx), %rdi
movl $0x2d, %esi
callq 0x1f08f
movq 0x48(%rbx), %rdi
jmp 0xce45
xorl %esi, %esi
callq 0x1f5c6
movq 0x48(%rbx), %rdi
movl $0x2d, %esi
callq 0x1f08f
movq 0x48(%rbx), %rdi
incl %ebp
movswl %bp, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1f5c6