// File: /workspace/github_cpp_makefile_star2_O1/fulhax[P]ncpamixer/src/ui/tab.cpp
// Function: Tab::handleMouse(int, int, int)
void Tab::handleMouse(int x, int y, int button)
{
    if (object == nullptr) {
        return;
    }

    int baseY = 0;
    int current_block = 0;
    int BLOCK_SIZE = getBlockSize();

    total_blocks = (ui.height - 2) / BLOCK_SIZE;
    int blocks_drawn = 0;

    bool more_up = false;
    bool more_down = false;

    for (auto &i : *object) {
        auto item = i.second;
        if (current_block <= selected_block - total_blocks) {
            current_block++;
            more_up = true;
            continue;
        }

        if (blocks_drawn >= total_blocks) {
            more_down = true;
            break;
        }

        blocks_drawn++;

        if (has_volume) {
            if (handleMouseVolumeBar(item, x, y, ui.width, ui.height, 0, baseY + 3, button)) {
                return;
            }
        } else { // Configuration
            if (item->active_attribute != nullptr) {
                if (handleMouseDropDown(item, x, y, ui.width - 2, 2, 1, baseY + 2)) {
                    return;
                }
            }
        }

        unsigned int len = 0;
        unsigned int sink_pos = 0;
        PaObject* toggle_item = nullptr;

        if (toggle != nullptr) {
            auto rel = toggle->find(i.second->getRelation());

            if (rel != toggle->end()) {
                char *name = rel->second->name;

                if (name != nullptr) {
                    len = strlen(name);
                    sink_pos = ui.width - 1 - len;
                    toggle_item = rel->second;
                }
            }
        } else {
            if (i.second->active_attribute != nullptr && has_volume) {
                len = strlen(i.second->active_attribute->description);
                sink_pos = ui.width - 1 - len;
                toggle_item = i.second;
            }
        }

        if (toggle_item != nullptr) {
            auto save_selected_index = selected_index;
            auto save_selected_block = selected_block;

            selected_index = i.first;
            selected_block = current_block;

            bool done = handleMouseDropDown(toggle_item, x, y, len, 1, sink_pos, baseY + 1);

            selected_index = save_selected_index;
            selected_block = save_selected_block;

            if (done) {
                return;
            }
        }

        baseY += BLOCK_SIZE;
        current_block++;
    }

    if (more_up) {
        if (handleMouseMoreUp(x, y, 4, 1, (ui.width / 2) - 4, 0)) {
            return;
        }
    }

    if (more_down) {
        if (handleMouseMoreDown(x, y, 4, 1, (ui.width / 2) - 4, ui.height - 2)) {
            return;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, 0x28(%rsp)
movl %edx, 0x4(%rsp)
movl %esi, (%rsp)
movq 0x10(%rdi), %r15
testq %r15, %r15
je 0xecb5
movq %rdi, %rbx
leaq 0x9e63(%rip), %rdx      # 0x187f8
movzbl 0x101(%rdx), %eax
andl $0x1, %eax
xorl $0x5, %eax
movzbl 0x102(%rdx), %ecx
subl %ecx, %eax
cmpb $0x0, 0x8(%rdi)
movl $0x5, %ecx
cmovnel %eax, %ecx
movl 0xc(%rdx), %eax
addl $-0x2, %eax
cltd
movl %ecx, 0x14(%rsp)
idivl %ecx
movl %eax, 0x24(%rdi)
movq 0x18(%r15), %r12
addq $0x8, %r15
movq $0x0, 0x8(%rsp)
cmpq %r15, %r12
je 0xec1f
xorl %ebp, %ebp
movl $0x0, 0x10(%rsp)
xorl %r13d, %r13d
xorl %r14d, %r14d
movl 0x20(%rbx), %ecx
movl 0x24(%rbx), %eax
subl %eax, %ecx
cmpl %ecx, %ebp
jle 0xea53
movl 0x10(%rsp), %ecx
cmpl %eax, %ecx
jge 0xea62
movq 0x28(%r12), %rsi
incl %ecx
movl %ecx, 0x10(%rsp)
cmpb $0x1, 0x8(%rbx)
jne 0xea6f
leaq 0x9ddb(%rip), %rax      # 0x187f8
movl 0x8(%rax), %r8d
movq 0x8(%rsp), %rax
addl $0x3, %eax
subq $0x8, %rsp
movl 0x8(%rsp), %edx
movl 0xc(%rsp), %ecx
pushq 0x30(%rsp)
pushq %rax
pushq $0x0
callq 0xecc4
addq $0x20, %rsp
movl $0x1, %ecx
testb %al, %al
je 0xeac9
jmp 0xebf5
incl %ebp
movb $0x1, %r13b
movl $0x3, %ecx
jmp 0xebf5
movb $0x1, %r14b
movl $0x2, %ecx
jmp 0xebf5
cmpq $0x0, 0x230(%rsi)
je 0xeac9
movl (%rsp), %edi
testl %edi, %edi
setg %al
leaq 0x9d70(%rip), %rcx      # 0x187f8
movl 0x8(%rcx), %ecx
movq 0x8(%rsp), %r8
leal 0x2(%r8), %edx
decl %ecx
cmpl %edi, %ecx
setg %cl
movl 0x4(%rsp), %edi
cmpl %edi, %edx
setle %dl
andb %al, %dl
leal 0x5(%r8), %eax
cmpl %edi, %eax
setg %al
andb %dl, %al
andb %cl, %al
cmpb $0x1, %al
jne 0xeac9
movq %rbx, %rdi
callq 0xe7da
movl $0x1, %ecx
jmp 0xebf5
movq %r13, 0x18(%rsp)
movq %r14, 0x20(%rsp)
movq 0x18(%rbx), %r14
movq 0x28(%r12), %r13
testq %r14, %r14
je 0xeb38
movq (%r13), %rax
movq %r13, %rdi
callq *0x18(%rax)
movq 0x10(%r14), %rdx
addq $0x8, %r14
movq %r14, %rcx
testq %rdx, %rdx
je 0xeb15
movq %r14, %rcx
xorl %esi, %esi
cmpl %eax, 0x20(%rdx)
setb %sil
cmovaeq %rdx, %rcx
movq 0x10(%rdx,%rsi,8), %rdx
testq %rdx, %rdx
jne 0xeafe
cmpq %r14, %rcx
je 0xeb21
cmpl 0x20(%rcx), %eax
cmovaeq %rcx, %r14
movq 0x18(%rbx), %rax
addq $0x8, %rax
cmpq %rax, %r14
je 0xeb66
movq 0x28(%r14), %r13
leaq 0x10(%r13), %rdi
jmp 0xeb51
movq 0x230(%r13), %rdi
testq %rdi, %rdi
je 0xeb66
cmpb $0x1, 0x8(%rbx)
jne 0xeb66
addq $0x107, %rdi            # imm = 0x107
callq 0x62b0
movl %eax, %ecx
notl %ecx
leaq 0x9c97(%rip), %rdx      # 0x187f8
addl 0x8(%rdx), %ecx
jmp 0xeb6d
xorl %eax, %eax
xorl %ecx, %ecx
xorl %r13d, %r13d
testq %r13, %r13
je 0xebd9
movl 0xc(%rbx), %r14d
movl 0x20(%rbx), %r8d
movl 0x20(%r12), %edx
movl %edx, 0xc(%rbx)
movl %ebp, 0x20(%rbx)
movl (%rsp), %esi
cmpl %esi, %ecx
setle %dl
addl %ecx, %eax
cmpl %esi, %eax
setg %al
movl 0x4(%rsp), %esi
movq 0x8(%rsp), %rdi
cmpl %esi, %edi
setl %cl
andb %dl, %cl
andb %al, %cl
leal 0x4(%rdi), %eax
cmpl %esi, %eax
setg %al
andb %cl, %al
cmpb $0x1, %al
jne 0xebd1
movq %rbx, %rdi
movq %r13, %rsi
movl %r8d, %r13d
callq 0xe7da
movl %r14d, 0xc(%rbx)
movl %r13d, 0x20(%rbx)
movl $0x1, %ecx
jmp 0xebeb
movl %r14d, 0xc(%rbx)
movl %r8d, 0x20(%rbx)
movq 0x8(%rsp), %rax
addl 0x14(%rsp), %eax
movq %rax, 0x8(%rsp)
incl %ebp
xorl %ecx, %ecx
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %r13
cmpl $0x3, %ecx
je 0xebfe
testl %ecx, %ecx
jne 0xec17
movq %r12, %rdi
callq 0x6440
movq %rax, %r12
cmpq %r15, %rax
jne 0xe9f1
movl $0x2, %ecx
cmpl $0x2, %ecx
sete %al
jmp 0xec27
movb $0x1, %al
xorl %r14d, %r14d
xorl %r13d, %r13d
testb %al, %al
je 0xecb5
testb $0x1, %r13b
je 0xec65
cmpl $0x0, 0x4(%rsp)
jne 0xec65
leaq 0x9bb5(%rip), %rax      # 0x187f8
movl 0x8(%rax), %ecx
movl %ecx, %eax
shrl $0x1f, %eax
addl %ecx, %eax
sarl %eax
cmpl (%rsp), %eax
jle 0xec65
addl $-0x4, %eax
cmpl (%rsp), %eax
jg 0xec65
leaq 0x3d22(%rip), %rax      # 0x12985
jmp 0xeca5
testb $0x1, %r14b
je 0xecb5
leaq 0x9b86(%rip), %rax      # 0x187f8
movl 0xc(%rax), %eax
addl $-0x2, %eax
cmpl 0x4(%rsp), %eax
jne 0xecb5
leaq 0x9b73(%rip), %rax      # 0x187f8
movl 0x8(%rax), %ecx
movl %ecx, %eax
shrl $0x1f, %eax
addl %ecx, %eax
sarl %eax
cmpl (%rsp), %eax
jle 0xecb5
addl $-0x4, %eax
cmpl (%rsp), %eax
jg 0xecb5
leaq 0x3ce8(%rip), %rax      # 0x1298d
leaq 0x30(%rsp), %rsi
movq %rax, (%rsi)
movq %rbx, %rdi
callq 0xe1e4
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq