// File: /workspace/github_c_makefile_star2_O2/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
testb $0x10, 0x30(%rdi)
jne 0x823e0
pushq $-0x1
popq %rbp
jmp 0x82579
movl %esi, %ebp
movq %rdi, %rbx
callq 0x59dc0
movl %eax, %r14d
testb %bpl, %bpl
je 0x8241e
cmpl $0x2, %r14d
pushq $0x1
popq %r15
cmovgel %r14d, %r15d
decl %r15d
cmpl $0x3, %r14d
pushq $0x2
popq %rax
cmovgel %r14d, %eax
cmpl %r15d, %r14d
jne 0x8246b
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0x56ae0
jmp 0x82464
leal 0x1(%r14), %r15d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x178(%rax)
movl %eax, %r12d
decl %r12d
cmpl %r12d, %r15d
cmovgel %r12d, %r15d
leal 0x1(%r15), %r13d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x178(%rax)
decl %eax
cmpl %eax, %r13d
cmovll %r13d, %eax
cmpl %r14d, %r12d
jne 0x8246e
pushq $-0x1
popq %rsi
movq %rbx, %rdi
callq 0x57e50
xorl %ebp, %ebp
jmp 0x82579
addl $-0x2, %eax
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 0x824b2
movq (%r12), %rax
movq %r12, %rdi
callq *0x130(%rax)
shrq $0x20, %rdx
shrq $0x20, %rax
subl %eax, %edx
cmpl $0x2, %edx
jg 0x824cf
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 0x56160
movq (%rbx), %rax
xorl %ebp, %ebp
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 0x59a80
cmpl %r13d, 0x6d0(%rbx)
je 0x82579
pushq $0x64
popq %rdi
callq 0x58b10
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq