// File: /workspace/github_c_makefile_star2_O1/enzo1982[P]smooth/classes/gui/widgets/multi/list/listbox.cpp
// Function: smooth::GUI::ListBox::DragSelectedEntry(bool)
S::Int S::GUI::ListBox::DragSelectedEntry(Bool upDown)
{
	if (!(flags & LF_ALLOWREORDER)) return Error();

	/* Get entry numbers to switch and check.
	 */
	Int	 selectedEntryNumber = GetSelectedEntryNumber();
	Int	 newEntryNumber	     = selectedEntryNumber;
	Int	 checkEntryNumber    = selectedEntryNumber;

	if (upDown)
	{
		newEntryNumber	 = Math::Max(0, selectedEntryNumber - 1);
		checkEntryNumber = Math::Max(0, newEntryNumber	    - 1);
	}
	else
	{
		newEntryNumber	 = Math::Min(selectedEntryNumber + 1, Length() - 1);
		checkEntryNumber = Math::Min(newEntryNumber	 + 1, Length() - 1);
	}

	/* Check whether entry should be moved.
	 */
	if (selectedEntryNumber != newEntryNumber)
	{
		Int	 oldScrollbarPos = scrollbarPos;

		/* Check whether to scroll the whole list.
		 */
		ListEntry	*checkEntry = GetNthEntry(checkEntryNumber);

		if (!checkEntry->IsVisible() || checkEntry->GetVisibleArea().GetHeight() <= 2)
		{
			if (upDown) scrollbarPos -= scrollbar->GetStepSize();
			else	    scrollbarPos += scrollbar->GetStepSize();
		}

		/* Move entry to new position.
		 */
		MoveEntry(selectedEntryNumber, newEntryNumber);

		/* Redraw the list.
		 */
		Surface		*surface  = GetDrawSurface();
		ListEntry	*oldEntry = GetNthEntry(selectedEntryNumber);

		surface->StartPaint(Rect(GetRealPosition(), GetRealSize()));

		Paint(SP_PAINT);

		oldEntry->Process(SM_MOUSEMOVE, 0, 0);

		surface->EndPaint();

		/* If list was scrolled, delay next action by 100ms.
		 */
		if (scrollbarPos != oldScrollbarPos) System::System::Sleep(100);
	}
	else
	{
		if (upDown) ScrollUp(ScrollToTop);
		else	    ScrollDown(ScrollToBottom);
	}

	return Success();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
testb $0x10, 0x30(%rdi)
jne 0x84bb4
movl %r12d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %esi, %ebp
movq %rdi, %rbx
callq 0x58a80
movl %eax, %r14d
testb %bpl, %bpl
je 0x84be9
cmpl $0x2, %r14d
movl $0x1, %r15d
cmovgel %r14d, %r15d
decl %r15d
cmpl $0x3, %r14d
movl $0x2, %eax
cmovgel %r14d, %eax
addl $-0x2, %eax
jmp 0x84c1f
leal 0x1(%r14), %r12d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x178(%rax)
movl %eax, %r15d
decl %r15d
cmpl %r15d, %r12d
cmovll %r12d, %r15d
leal 0x1(%r15), %r12d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x178(%rax)
decl %eax
cmpl %eax, %r12d
cmovll %r12d, %eax
cmpl %r15d, %r14d
jne 0x84c43
movq 0x6c8(%rbx), %rdi
testb %bpl, %bpl
je 0x84d5a
xorl %r12d, %r12d
xorl %esi, %esi
callq 0x56f80
jmp 0x84ba2
movl 0x6d0(%rbx), %r13d
movq (%rbx), %rcx
movq %rbx, %rdi
movl %eax, %esi
callq *0x180(%rcx)
movq %rax, %r12
movq (%rax), %rax
movq %r12, %rdi
callq *0x90(%rax)
testb %al, %al
je 0x84c87
movq (%r12), %rax
movq %r12, %rdi
callq *0x130(%rax)
shrq $0x20, %rdx
shrq $0x20, %rax
subl %eax, %edx
cmpl $0x2, %edx
jg 0x84ca4
movq 0x6c8(%rbx), %rax
movl 0x5e0(%rax), %eax
movl %eax, %ecx
negl %ecx
testb %bpl, %bpl
cmovel %eax, %ecx
addl %ecx, 0x6d0(%rbx)
movq (%rbx), %rax
movq %rbx, %rdi
movl %r14d, %esi
movl %r15d, %edx
callq *0x170(%rax)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x40(%rax)
movq %rax, %r15
movq (%rbx), %rax
movq %rbx, %rdi
movl %r14d, %esi
callq *0x180(%rax)
movq %rax, %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x48(%rax)
movq %rax, %r12
movq %rax, %rbp
shrq $0x20, %rbp
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x50(%rax)
leal (%rax,%r12), %ecx
shrq $0x20, %rax
leaq 0x8(%rsp), %rsi
movl %r12d, (%rsi)
movl %ebp, 0x4(%rsi)
movl %ecx, 0x8(%rsi)
addl %ebp, %eax
movl %eax, 0xc(%rsi)
movq %r15, %rdi
callq 0x55160
movq (%rbx), %rax
xorl %r12d, %r12d
movq %rbx, %rdi
xorl %esi, %esi
callq *0x78(%rax)
movq (%r14), %rax
movq %r14, %rdi
movl $0x7800, %esi           # imm = 0x7800
xorl %edx, %edx
xorl %ecx, %ecx
callq *0x80(%rax)
movq %r15, %rdi
callq 0x58780
cmpl %r13d, 0x6d0(%rbx)
je 0x84ba2
movl $0x64, %edi
callq 0x578c0
jmp 0x84ba2
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
callq 0x56f80
xorl %r12d, %r12d
jmp 0x84ba2