// File: /workspace/github_c_makefile_star2_O1/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 0x80d4
testb %al, %al
je 0xcd54
cmpb $0xe, %bl
jne 0xcd65
movq %r14, %rdi
callq 0x6ad8
movq %rax, %rbx
movq %r14, %rdi
callq 0x22131
cmpw $-0x1, %ax
je 0xcd65
movzwl %ax, %ebp
movq %r14, %rdi
movl %ebp, %esi
movl $0x28, %edx
callq 0x22280
testb %al, %al
jne 0xcd65
movq %r14, %rdi
movl %ebp, %esi
movl $0x10, %edx
callq 0x22280
movq %r14, %rdi
callq 0x2215d
testq %rax, %rax
je 0xcd65
movq %rax, %r15
leaq 0x32699(%rip), %rsi     # 0x3f2d5
movq %rax, %rdi
callq 0x20e0
testl %eax, %eax
je 0xcd70
leaq 0x32686(%rip), %rsi     # 0x3f2d9
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xcd88
leaq 0x32673(%rip), %rsi     # 0x3f2dd
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xcda0
leaq 0x3265f(%rip), %rsi     # 0x3f2e0
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xcdc8
leaq 0x3264c(%rip), %rsi     # 0x3f2e4
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xcddf
movq 0x48(%rbx), %r14
testq %r14, %r14
je 0xcd65
leaq 0x3262c(%rip), %rsi     # 0x3f2e8
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xce05
leaq 0x3261b(%rip), %rsi     # 0x3f2ee
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xce05
leaq 0x32608(%rip), %rsi     # 0x3f2f2
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xce4c
leaq 0x325f5(%rip), %rsi     # 0x3f2f6
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xce5e
leaq 0x325e2(%rip), %rsi     # 0x3f2fa
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xce70
leaq 0x325cf(%rip), %rsi     # 0x3f2fe
movq %r15, %rdi
callq 0x20e0
movq %r14, %rdi
testl %eax, %eax
je 0xce82
movq %r15, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1eb68
leaq 0x323d9(%rip), %rdi     # 0x3f134
movq %r14, %rsi
callq 0x829e
jmp 0xcd63
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x46339(%rip), %rsi     # 0x530b0
movq %r14, %rdi
callq 0x21710
leaq 0x325fa(%rip), %rsi     # 0x3f380
jmp 0xcdb6
leaq 0x46531(%rip), %rsi     # 0x532c0
movq %r14, %rdi
callq 0x21710
leaq 0x32662(%rip), %rsi     # 0x3f400
jmp 0xcdb6
leaq 0x46679(%rip), %rsi     # 0x53420
movq %r14, %rdi
callq 0x21710
leaq 0x3269a(%rip), %rsi     # 0x3f450
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x21d48
leaq -0x216(%rip), %rax      # 0xcbb9
cmpq %rax, 0x28(%r14)
je 0xce1c
movq %r14, %rdi
movl $0x12, %esi
jmp 0xcdf4
leaq -0x22d(%rip), %rax      # 0xcbb9
cmpq %rax, 0x28(%r14)
je 0xce38
movq %r14, %rdi
movl $0x11, %esi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x4fea
movq %r14, %rdi
movl $0xa, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1e89b
movq %r14, %rdi
xorl %esi, %esi
callq 0xcf59
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x4d2b
movq %r14, %rdi
xorl %esi, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xcf59
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x200b7
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x20083
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1f16a
callq 0x1f045
movl %eax, %ebp
movq 0x48(%rbx), %rdi
callq 0x1fea7
movzbl (%rax), %eax
movq 0x48(%rbx), %rdi
cmpl $0x2b, %eax
je 0xcec1
cmpl $0x2d, %eax
jne 0xcee8
movl $0x1, %esi
callq 0x1edf8
movq 0x48(%rbx), %rdi
callq 0x1f16a
movq 0x48(%rbx), %rdi
movl $0x2b, %esi
jmp 0xcedd
movl $0x1, %esi
callq 0x1edf8
movq 0x48(%rbx), %rdi
callq 0x1f16a
movq 0x48(%rbx), %rdi
movl $0x2d, %esi
callq 0x1e89b
movq 0x48(%rbx), %rdi
jmp 0xcf03
xorl %esi, %esi
callq 0x1edf8
movq 0x48(%rbx), %rdi
movl $0x2d, %esi
callq 0x1e89b
movq 0x48(%rbx), %rdi
incl %ebp
movswl %bp, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1edf8