// File: /workspace/github_cpp_makefile_star2_O2/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, 0x30(%rsp)
movq 0x10(%rdi), %rax
testq %rax, %rax
je 0xd984
movl %edx, %ebp
movl %esi, %r15d
movq %rdi, %r14
movq %rax, %rsi
leaq 0xb12c(%rip), %rdx      # 0x18828
movzbl 0x101(%rdx), %eax
andl $0x1, %eax
xorl $0x5, %eax
movzbl 0x102(%rdx), %ecx
subl %ecx, %eax
cmpb $0x0, 0x8(%rdi)
pushq $0x5
popq %rcx
cmovnel %eax, %ecx
movl 0xc(%rdx), %eax
addl $-0x2, %eax
cltd
movl %ecx, 0x20(%rsp)
idivl %ecx
movl %eax, 0x24(%rdi)
movq 0x18(%rsi), %r12
addq $0x8, %rsi
movq %rsi, 0x28(%rsp)
movl $0x0, 0x4(%rsp)
movl $0x0, 0x10(%rsp)
xorl %ebx, %ebx
movq $0x0, 0x8(%rsp)
movl %ebp, 0x18(%rsp)
movl %r15d, 0x14(%rsp)
pushq $0x2
popq %r13
cmpq 0x28(%rsp), %r12
je 0xd90d
movl 0x20(%r14), %ecx
movl 0x24(%r14), %eax
subl %eax, %ecx
cmpl %ecx, %ebx
jle 0xd7be
cmpl %eax, 0x10(%rsp)
jge 0xd916
movq 0x28(%r12), %rsi
cmpb $0x1, 0x8(%r14)
jne 0xd7c9
leaq 0xb091(%rip), %rax      # 0x18828
movl 0x8(%rax), %r8d
movq 0x8(%rsp), %rax
addl $0x3, %eax
subq $0x8, %rsp
movl %r15d, %edx
movl %ebp, %ecx
pushq 0x38(%rsp)
pushq %rax
pushq $0x0
callq 0xd994
addq $0x20, %rsp
jmp 0xd7fc
movb $0x1, %al
movl %eax, 0x4(%rsp)
jmp 0xd8fb
cmpq $0x0, 0x230(%rsi)
je 0xd804
leaq 0xb04e(%rip), %rax      # 0x18828
movl 0x8(%rax), %r8d
addl $-0x2, %r8d
movq 0x8(%rsp), %rax
addl $0x2, %eax
movq %r14, %rdi
movl %r15d, %edx
movl %ebp, %ecx
pushq %rax
pushq $0x1
callq 0xda1a
popq %rcx
popq %rdx
testb %al, %al
jne 0xd984
movq 0x18(%r14), %r13
testq %r13, %r13
je 0xd851
movq 0x28(%r12), %rdi
movq (%rdi), %rax
callq *0x18(%rax)
movl %eax, 0x24(%rsp)
movq %r13, %rdi
leaq 0x24(%rsp), %rsi
callq 0x93a8
movq 0x18(%r14), %rcx
addq $0x8, %rcx
cmpq %rcx, %rax
je 0xd8e9
movq 0x28(%rax), %r13
leaq 0x10(%r13), %rdi
callq 0x62a0
testq %r13, %r13
jne 0xd879
jmp 0xd8e9
movq 0x28(%r12), %r13
movq 0x230(%r13), %rdi
testq %rdi, %rdi
je 0xd8e9
cmpb $0x1, 0x8(%r14)
jne 0xd8e9
addq $0x107, %rdi            # imm = 0x107
callq 0x62a0
movl %eax, %r9d
notl %r9d
leaq 0xafa2(%rip), %rcx      # 0x18828
addl 0x8(%rcx), %r9d
movl 0xc(%r14), %ebp
movl 0x20(%r14), %ecx
movl %ecx, 0x1c(%rsp)
movl 0x20(%r12), %ecx
movl %ecx, 0xc(%r14)
movl %ebx, 0x20(%r14)
movq 0x8(%rsp), %rcx
leal 0x1(%rcx), %r10d
movq %r14, %rdi
movq %r13, %rsi
movl 0x14(%rsp), %r15d
movl %r15d, %edx
movl 0x18(%rsp), %r13d
movl %r13d, %ecx
movl %eax, %r8d
pushq %r10
pushq %r9
callq 0xda1a
addq $0x10, %rsp
movl %ebp, 0xc(%r14)
movl %r13d, %ebp
movl 0x1c(%rsp), %ecx
movl %ecx, 0x20(%r14)
testb %al, %al
jne 0xd984
incl 0x10(%rsp)
movq 0x8(%rsp), %rax
addl 0x20(%rsp), %eax
movq %rax, 0x8(%rsp)
incl %ebx
movq %r12, %rdi
callq 0x6450
movq %rax, %r12
jmp 0xd75d
testb $0x1, 0x4(%rsp)
jne 0xd91d
jmp 0xd984
testb $0x1, 0x4(%rsp)
je 0xd952
leaq 0xaf04(%rip), %rax      # 0x18828
movl 0x8(%rax), %eax
cltd
idivl %r13d
leal -0x4(%rax), %r9d
subq $0x8, %rsp
pushq $0x4
popq %rcx
movq %r14, %rdi
movl %r15d, %esi
movl %ebp, %edx
pushq $0x0
callq 0xda5a
popq %rcx
popq %rdx
cmpq 0x28(%rsp), %r12
je 0xd984
testb %al, %al
jne 0xd984
leaq 0xaecf(%rip), %rcx      # 0x18828
movl 0x8(%rcx), %eax
movl 0xc(%rcx), %r8d
cltd
idivl %r13d
leal -0x4(%rax), %r9d
addl $-0x2, %r8d
subq $0x8, %rsp
pushq $0x4
popq %rcx
movq %r14, %rdi
movl %r15d, %esi
movl %ebp, %edx
pushq %r8
callq 0xda9a
popq %rcx
popq %rdx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop