// File: /workspace/github_c_makefile_star2_O2/OnionIoT[P]lv_example/lvgl/src/lv_objx/lv_list.c
// Function: lv_list_signal
static lv_res_t lv_list_signal(lv_obj_t * list, lv_signal_t sign, void * param)
{
    lv_res_t res;

    /* Include the ancient signal function */
    res = ancestor_page_signal(list, sign, param);
    if(res != LV_RES_OK) return res;
    if(sign == LV_SIGNAL_GET_TYPE) return lv_obj_handle_get_type_signal(param, LV_OBJX_NAME);

    if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESSED || sign == LV_SIGNAL_PRESSING ||
       sign == LV_SIGNAL_LONG_PRESS || sign == LV_SIGNAL_LONG_PRESS_REP) {
#if LV_USE_GROUP
        /*If pressed/released etc by a KEYPAD or ENCODER delegate signal to the button*/
        lv_indev_t * indev         = lv_indev_get_act();
        lv_indev_type_t indev_type = lv_indev_get_type(indev);
        if(indev_type == LV_INDEV_TYPE_KEYPAD ||
           (indev_type == LV_INDEV_TYPE_ENCODER && lv_group_get_editing(lv_obj_get_group(list)))) {
            /*Get the 'pressed' button*/
            lv_obj_t * btn = NULL;
            btn            = lv_list_get_prev_btn(list, btn);
            while(btn != NULL) {
                if(lv_btn_get_state(btn) == LV_BTN_STATE_PR) break;
                btn = lv_list_get_prev_btn(list, btn);
            }
            lv_list_ext_t * ext = lv_obj_get_ext_attr(list);

            /*The page receives the key presses so the events should be propagated to the selected
             * button*/
            if(btn) {
                if(sign == LV_SIGNAL_PRESSED) {
                    res = lv_event_send(btn, LV_EVENT_PRESSED, NULL);
                } else if(sign == LV_SIGNAL_PRESSING) {
                    res = lv_event_send(btn, LV_EVENT_PRESSING, NULL);
                } else if(sign == LV_SIGNAL_LONG_PRESS) {
                    res = lv_event_send(btn, LV_EVENT_LONG_PRESSED, NULL);
                } else if(sign == LV_SIGNAL_LONG_PRESS_REP) {
                    res = lv_event_send(btn, LV_EVENT_LONG_PRESSED_REPEAT, NULL);
                } else if(sign == LV_SIGNAL_RELEASED) {
#if LV_USE_GROUP
                    ext->last_sel = btn;
#endif
                    if(indev->proc.long_pr_sent == 0) {
                        res = lv_event_send(btn, LV_EVENT_SHORT_CLICKED, NULL);
                    }
                    if(lv_indev_is_dragging(indev) == false && res == LV_RES_OK) {
                        res = lv_event_send(btn, LV_EVENT_CLICKED, NULL);
                    }
                    if(res == LV_RES_OK) {
                        res = lv_event_send(btn, LV_EVENT_RELEASED, NULL);
                    }
                }
            }
        }
#endif
    } else if(sign == LV_SIGNAL_FOCUS) {

#if LV_USE_GROUP
        lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act());
        /*With ENCODER select the first button only in edit mode*/
        if(indev_type == LV_INDEV_TYPE_ENCODER) {
            lv_group_t * g = lv_obj_get_group(list);
            if(lv_group_get_editing(g)) {
                lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
                if(ext->last_sel) {
                    /* Select the    last used button */
                    lv_list_set_btn_selected(list, ext->last_sel);
                } else {
                    /*Get the first button and mark it as selected*/
                    lv_list_set_btn_selected(list, lv_list_get_next_btn(list, NULL));
                }
            } else {
                lv_list_set_btn_selected(list, NULL);
            }
        }
        /*Else select the clicked button*/
        else {
            /*Mark the last clicked button (if any) as selected because it triggered the focus*/
            lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
            if(ext->last_clicked_btn) {
                lv_list_set_btn_selected(list, ext->last_clicked_btn);
                ext->last_clicked_btn = NULL;

            } else {
                if(ext->last_sel) {
                    /* Select the last used button */
                    lv_list_set_btn_selected(list, ext->last_sel);
                } else {
                    /*Get the first button and mark it as selected*/
                    lv_list_set_btn_selected(list, lv_list_get_next_btn(list, NULL));
                }
            }
        }
#endif
    } else if(sign == LV_SIGNAL_DEFOCUS) {

#if LV_USE_GROUP
        /*De-select the selected btn*/
        lv_list_set_btn_selected(list, NULL);
        lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
        ext->last_clicked_btn    = NULL; /*button click will be set if click happens before focus*/
        ext->selected_btn   = NULL;
#endif
    } else if(sign == LV_SIGNAL_GET_EDITABLE) {
        bool * editable = (bool *)param;
        *editable       = true;
    } else if(sign == LV_SIGNAL_CONTROL) {

#if LV_USE_GROUP
        char c = *((char *)param);
        if(c == LV_KEY_RIGHT || c == LV_KEY_DOWN) {
            lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
            /*If there is a valid selected button the make the previous selected*/
            if(ext->selected_btn) {
                lv_obj_t * btn_prev = lv_list_get_next_btn(list, ext->selected_btn);
                if(btn_prev) lv_list_set_btn_selected(list, btn_prev);
            }
            /*If there is no selected button the make the first selected*/
            else {
                lv_obj_t * btn = lv_list_get_next_btn(list, NULL);
                if(btn)
                    lv_list_set_btn_selected(list,
                                             btn); /*If there are no buttons on the list then there is no first button*/
            }
        } else if(c == LV_KEY_LEFT || c == LV_KEY_UP) {
            lv_list_ext_t * ext = lv_obj_get_ext_attr(list);
            /*If there is a valid selected button the make the next selected*/
            if(ext->selected_btn != NULL) {
                lv_obj_t * btn_next = lv_list_get_prev_btn(list, ext->selected_btn);
                if(btn_next) lv_list_set_btn_selected(list, btn_next);
            }
            /*If there is no selected button the make the first selected*/
            else {
                lv_obj_t * btn = lv_list_get_next_btn(list, NULL);
                if(btn) lv_list_set_btn_selected(list, btn);
            }
        }
#endif
    }
    return res;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, %r14
callq *0x43e76(%rip)          # 0x5e3b8
movl %eax, %ebx
cmpb $0x1, %al
jne 0x1a7bd
movzbl %bpl, %r13d
movb $0x1, %bl
leal -0x7(%r13), %eax
cmpl $0xc, %eax
ja 0x1a7bd
leaq 0x2121a(%rip), %rcx     # 0x3b780
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
callq 0x35b3
movq %rax, %r12
movq %rax, %rdi
callq 0x35bb
cmpb $0x2, %al
je 0x1a5a7
movzbl %al, %eax
cmpl $0x4, %eax
jne 0x1a7bd
movq %r14, %rdi
callq 0x4b8e
movq %rax, %rdi
callq 0x2aaa
testb %al, %al
je 0x1a7bd
movq %r14, %rdi
xorl %esi, %esi
callq 0x1afa5
movq %rax, %r15
testq %rax, %rax
je 0x1a5cd
movq %r15, %rdi
callq 0x1289a
cmpb $0x1, %al
je 0x1a5cd
movq %r14, %rdi
movq %r15, %rsi
jmp 0x1a5ac
movq %r14, %rdi
callq 0x6747
testq %r15, %r15
je 0x1a7bd
addl $-0x8, %r13d
cmpl $0x5, %r13d
ja 0x1a7bd
leaq 0x211c1(%rip), %rcx     # 0x3b7b4
movslq (%rcx,%r13,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movq %r15, %rdi
xorl %esi, %esi
jmp 0x1a77b
callq 0x35b3
movq %rax, %rdi
callq 0x35bb
movq %r14, %rdi
cmpb $0x4, %al
jne 0x1a6b5
callq 0x4b8e
movq %rax, %rdi
callq 0x2aaa
testb %al, %al
je 0x1a790
movq %r14, %rdi
callq 0x6747
movq 0x88(%rax), %rsi
jmp 0x1a79e
movq %r14, %rdi
xorl %esi, %esi
callq 0x1ae15
movq %r14, %rdi
callq 0x6747
xorps %xmm0, %xmm0
movups %xmm0, 0x90(%rax)
jmp 0x1a7bd
movb $0x1, (%r15)
jmp 0x1a7bd
leaq 0x2119c(%rip), %rsi     # 0x3b814
movq %r15, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x684b
movzbl (%r15), %eax
movl %eax, %ecx
andb $-0x2, %cl
cmpb $0x12, %cl
jne 0x1a6e2
movq %r14, %rdi
callq 0x6747
movq 0x90(%rax), %rsi
movq %r14, %rdi
testq %rsi, %rsi
jne 0x1a710
jmp 0x1a70e
callq 0x6747
movq %rax, %r15
movq 0x98(%rax), %rsi
testq %rsi, %rsi
je 0x1a797
movq %r14, %rdi
callq 0x1ae15
andq $0x0, 0x98(%r15)
jmp 0x1a7bd
cmpl $0x14, %eax
je 0x1a6f0
cmpl $0x11, %eax
jne 0x1a7bd
movq %r14, %rdi
callq 0x6747
movq 0x90(%rax), %rsi
movq %r14, %rdi
testq %rsi, %rsi
je 0x1a70e
callq 0x1afa5
jmp 0x1a715
xorl %esi, %esi
callq 0x1a8ac
testq %rax, %rax
jne 0x1a7b2
jmp 0x1a7bd
movq %r15, 0x88(%rax)
movb $0x1, %bl
testb $0x1, 0x78(%r12)
jne 0x1a743
pushq $0x3
popq %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x4caf
movl %eax, %ebx
movq %r12, %rdi
callq 0x3691
cmpb $0x1, %bl
setne %cl
orb %al, %cl
jne 0x1a764
pushq $0x6
popq %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x4caf
movl %eax, %ebx
cmpb $0x1, %bl
jne 0x1a7bd
pushq $0x7
jmp 0x1a777
pushq $0x1
jmp 0x1a777
pushq $0x4
jmp 0x1a777
pushq $0x5
popq %rsi
movq %r15, %rdi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x4caf
movq %r14, %rdi
xorl %esi, %esi
jmp 0x1a7b8
movq 0x88(%r15), %rsi
testq %rsi, %rsi
je 0x1a7a8
movq %r14, %rdi
jmp 0x1a7b8
movq %r14, %rdi
xorl %esi, %esi
callq 0x1a8ac
movq %r14, %rdi
movq %rax, %rsi
callq 0x1ae15
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq