// File: /workspace/github_c_makefile_star2_O2/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 0x7994
testb %al, %al
je 0xc276
cmpb $0xe, %bl
jne 0xc287
movq %r14, %rdi
callq 0x6747
movq %rax, %rbx
movq %r14, %rdi
callq 0x207b0
cmpw $-0x1, %ax
je 0xc287
movzwl %ax, %ebp
pushq $0x28
popq %rdx
movq %r14, %rdi
movl %ebp, %esi
callq 0x208c5
testb %al, %al
jne 0xc287
pushq $0x10
popq %rdx
movq %r14, %rdi
movl %ebp, %esi
callq 0x208c5
movq %r14, %rdi
callq 0x207dc
testq %rax, %rax
je 0xc287
movq %rax, %r15
leaq 0x2f188(%rip), %rsi     # 0x3b2e5
movq %rax, %rdi
callq 0x20e0
testl %eax, %eax
je 0xc292
leaq 0x2f175(%rip), %rsi     # 0x3b2e9
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xc2aa
cmpb $0x31, (%r15)
jne 0xc19c
cmpb $0x23, 0x1(%r15)
jne 0xc19c
cmpb $0x0, 0x2(%r15)
je 0xc338
leaq 0x2f14d(%rip), %rsi     # 0x3b2f0
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xc2d2
leaq 0x2f13a(%rip), %rsi     # 0x3b2f4
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xc2e3
movq 0x48(%rbx), %r14
testq %r14, %r14
je 0xc287
leaq 0x2f11a(%rip), %rsi     # 0x3b2f8
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xc307
leaq 0x2f109(%rip), %rsi     # 0x3b2fe
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xc307
leaq 0x2f0f6(%rip), %rsi     # 0x3b302
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xc367
leaq 0x2f0e3(%rip), %rsi     # 0x3b306
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xc379
leaq 0x2f0d0(%rip), %rsi     # 0x3b30a
movq %r15, %rdi
callq 0x20e0
testl %eax, %eax
je 0xc38b
leaq 0x2f0bd(%rip), %rsi     # 0x3b30e
movq %r15, %rdi
callq 0x20e0
movq %r14, %rdi
testl %eax, %eax
je 0xc39d
movq %r15, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1d3f2
leaq 0x2eec7(%rip), %rdi     # 0x3b144
movq %r14, %rsi
callq 0x7b01
jmp 0xc285
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
leaq 0x44e17(%rip), %rsi     # 0x510b0
movq %r14, %rdi
callq 0x1fe53
leaq 0x2f0e8(%rip), %rsi     # 0x3b390
jmp 0xc2c0
leaq 0x4500f(%rip), %rsi     # 0x512c0
movq %r14, %rdi
callq 0x1fe53
leaq 0x2f150(%rip), %rsi     # 0x3b410
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x203e1
leaq -0x1fb(%rip), %rax      # 0xc0de
cmpq %rax, 0x28(%r14)
je 0xc31c
pushq $0x12
jmp 0xc2f2
leaq -0x20c(%rip), %rax      # 0xc0de
cmpq %rax, 0x28(%r14)
je 0xc353
pushq $0x11
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x4caf
pushq $0xa
popq %rsi
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1d175
movq %r14, %rdi
xorl %esi, %esi
callq 0xc469
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x4a42
leaq 0x450e1(%rip), %rsi     # 0x51420
movq %r14, %rdi
callq 0x1fe53
leaq 0x2f112(%rip), %rsi     # 0x3b460
jmp 0xc2c0
movq %r14, %rdi
xorl %esi, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0xc469
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1e890
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1e85c
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1d9f5
callq 0x1d8d0
movl %eax, %ebp
movq 0x48(%rbx), %rdi
callq 0x1e680
movzbl (%rax), %eax
movq 0x48(%rbx), %rdi
cmpl $0x2b, %eax
je 0xc3d7
cmpl $0x2d, %eax
jne 0xc3fa
pushq $0x1
popq %rsi
callq 0x1d679
movq 0x48(%rbx), %rdi
callq 0x1d9f5
movq 0x48(%rbx), %rdi
pushq $0x2b
jmp 0xc3ee
pushq $0x1
popq %rsi
callq 0x1d679
movq 0x48(%rbx), %rdi
callq 0x1d9f5
movq 0x48(%rbx), %rdi
pushq $0x2d
popq %rsi
callq 0x1d175
movq 0x48(%rbx), %rdi
jmp 0xc413
xorl %esi, %esi
callq 0x1d679
movq 0x48(%rbx), %rdi
pushq $0x2d
popq %rsi
callq 0x1d175
movq 0x48(%rbx), %rdi
incl %ebp
movswl %bp, %esi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1d679