// File: /workspace/github_c_makefile_star2_O3/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 *0x440d5(%rip)          # 0x603b8
movl %eax, %ebx
cmpb $0x1, %al
jne 0x1c4fc
movzbl %bpl, %r13d
movb $0x1, %bl
leal -0x7(%r13), %eax
cmpl $0xc, %eax
ja 0x1c4fc
leaq 0x23585(%rip), %rcx     # 0x3f88c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
callq 0x378a
movq %rax, %r12
movq %rax, %rdi
callq 0x3792
cmpb $0x2, %al
je 0x1c348
movzbl %al, %eax
cmpl $0x4, %eax
jne 0x1c4fc
movq %r14, %rdi
callq 0x4ed1
movq %rax, %rdi
callq 0x2b0b
testb %al, %al
je 0x1c4fc
movq %r14, %rdi
xorl %esi, %esi
callq 0x1cdad
testq %rax, %rax
je 0x1c37d
movq %rax, %r15
movq %r15, %rdi
callq 0x136d6
cmpb $0x1, %al
je 0x1c440
movq %r14, %rdi
movq %r15, %rsi
callq 0x1cdad
movq %rax, %r15
testq %rax, %rax
jne 0x1c35a
movq %r14, %rdi
callq 0x6af7
jmp 0x1c4fc
callq 0x378a
movq %rax, %rdi
callq 0x3792
movq %r14, %rdi
cmpb $0x4, %al
jne 0x1c470
callq 0x4ed1
movq %rax, %rdi
callq 0x2b0b
testb %al, %al
je 0x1c4cf
movq %r14, %rdi
callq 0x6af7
movq 0x88(%rax), %rsi
jmp 0x1c4dd
movq %r14, %rdi
xorl %esi, %esi
callq 0x1cc01
movq %r14, %rdi
callq 0x6af7
xorps %xmm0, %xmm0
movups %xmm0, 0x90(%rax)
jmp 0x1c4fc
movb $0x1, (%r15)
jmp 0x1c4fc
leaq 0x23524(%rip), %rsi     # 0x3f920
movq %r15, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6c02
movzbl (%r15), %eax
movl %eax, %ecx
andb $-0x2, %cl
cmpb $0x12, %cl
jne 0x1c499
movq %r14, %rdi
callq 0x6af7
movq 0x90(%rax), %rsi
movq %r14, %rdi
testq %rsi, %rsi
jne 0x1c4c3
jmp 0x1c4c1
movq %r14, %rdi
callq 0x6af7
addl $-0x8, %r13d
cmpl $0x5, %r13d
ja 0x1c4fc
leaq 0x23463(%rip), %rcx     # 0x3f8c0
movslq (%rcx,%r13,4), %rdx
addq %rcx, %rdx
jmpq *%rdx
movq %r15, %rdi
xorl %esi, %esi
jmp 0x1c57d
callq 0x6af7
movq %rax, %r15
movq 0x98(%rax), %rsi
testq %rsi, %rsi
je 0x1c4d6
movq %r14, %rdi
callq 0x1cc01
movq $0x0, 0x98(%r15)
jmp 0x1c4fc
cmpl $0x14, %eax
je 0x1c4a3
cmpl $0x11, %eax
jne 0x1c4fc
movq %r14, %rdi
callq 0x6af7
movq 0x90(%rax), %rsi
movq %r14, %rdi
testq %rsi, %rsi
je 0x1c4c1
callq 0x1cdad
jmp 0x1c4c8
xorl %esi, %esi
callq 0x1c66d
testq %rax, %rax
jne 0x1c4f1
jmp 0x1c4fc
movq %r14, %rdi
xorl %esi, %esi
jmp 0x1c4f7
movq 0x88(%r15), %rsi
testq %rsi, %rsi
je 0x1c4e7
movq %r14, %rdi
jmp 0x1c4f7
movq %r14, %rdi
xorl %esi, %esi
callq 0x1c66d
movq %r14, %rdi
movq %rax, %rsi
callq 0x1cc01
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, 0x88(%rax)
movb $0x1, %bl
testb $0x1, 0x78(%r12)
jne 0x1c52f
movq %r15, %rdi
movl $0x3, %esi
xorl %edx, %edx
callq 0x5018
movl %eax, %ebx
movq %r12, %rdi
callq 0x3869
cmpb $0x1, %bl
setne %cl
orb %al, %cl
jne 0x1c552
movq %r15, %rdi
movl $0x6, %esi
xorl %edx, %edx
callq 0x5018
movl %eax, %ebx
cmpb $0x1, %bl
jne 0x1c4fc
movq %r15, %rdi
movl $0x7, %esi
jmp 0x1c57d
movq %r15, %rdi
movl $0x1, %esi
jmp 0x1c57d
movq %r15, %rdi
movl $0x4, %esi
jmp 0x1c57d
movq %r15, %rdi
movl $0x5, %esi
xorl %edx, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x5018