// File: /workspace/github_c_makefile_star2_O1/enzo1982[P]smooth/classes/gui/widgets/multi/list/listbox.cpp
// Function: smooth::GUI::ListBox::Paint(int)
S::Int S::GUI::ListBox::Paint(Int message)
{
	if (!IsRegistered()) return Error();
	if (!IsVisible())    return Success();

	Surface		*surface	   = GetDrawSurface();
	Rect		 frame		   = Rect(GetRealPosition(), GetRealSize());
	Rect		 entryRect	   = frame;

	String		 visibleEntries;
	Int		 visibleEntryCount = 0;

	ListEntry	*lastVisibleEntry  = NIL;

	if (GetNOfTabs() > 0 && !(flags & LF_HIDEHEADER)) header->Show();
	else						  header->Hide();

	Int		 entriesHeight	   = 0;
	Int		 headerHeight	   = (header->IsVisible()    ? header->GetHeight()   : 0);
	Int		 scrollbarWidth	   = (scrollbar->IsVisible() ? scrollbar->GetWidth() : 0);

	switch (message)
	{
		case SP_PAINT:
			surface->StartPaint(frame);

			/* Update scrollbar if necessary.
			 */
			entriesHeight = GetEntriesHeight();

			if (entriesHeight > GetHeight() - headerHeight - 4 && !(flags & LF_HIDESCROLLBAR))
			{
				scrollbar->SetMetrics(Point(18, 1 + headerHeight), Size(scrollbar->GetWidth(), GetHeight() - 2 - headerHeight));
				scrollbar->SetRange(0, entriesHeight - (GetHeight() - 4 - headerHeight));

				scrollbar->SetPageSize(GetHeight() - 4 - headerHeight);

				scrollbar->Show();

				scrollbarWidth = scrollbar->GetWidth();
			}
			else
			{
				scrollbar->Hide();

				scrollbarPos   = 0;
				scrollbarWidth = 0;
			}

			/* Set visibility of list entries first.
			 */
			entryRect.top	 = -scrollbarPos;
			entryRect.bottom = -scrollbarPos;

			for (Int i = 0; i < Length(); i++)
			{
				ListEntry	*entry = GetNthEntry(i);

				entry->SetVisibleDirect(False);

				if (entryRect.bottom + entry->GetHeight() >= 0 && entryRect.top <= GetHeight() - headerHeight - 4)
				{
					entry->SetMetrics(Point(2, entryRect.top + 2 + headerHeight), Size(GetWidth() - 4 - scrollbarWidth, entry->GetHeight()));
					entry->SetVisibleDirect(True);

					visibleEntries[visibleEntryCount++] = entry->GetHandle() % 32767 + 1;
				}

				entryRect.top	 += entry->GetHeight();
				entryRect.bottom += entry->GetHeight();
			}

			visibleEntriesString = visibleEntries;

			/* Now paint the listbox and all entries.
			 */
			if (IsActive())	surface->Box(frame + Point(0, headerHeight) - Size(scrollbarWidth, headerHeight), Setup::ClientColor, Rect::Filled);
			else		surface->Box(frame + Point(0, headerHeight) - Size(scrollbarWidth, headerHeight), Setup::BackgroundColor, Rect::Filled);

			surface->Frame(frame, FRAME_DOWN);

			Widget::Paint(message);

			surface->EndPaint();

			break;
		case SP_UPDATE:
			/* Update scrollbar if necessary.
			 */
			entriesHeight = GetEntriesHeight();

			if ((entriesHeight >  GetHeight() - headerHeight - 4 && !scrollbar->IsVisible() && !(flags & LF_HIDESCROLLBAR)) ||
			    (entriesHeight <= GetHeight() - headerHeight - 4 &&  scrollbar->IsVisible()				      )) return Paint(SP_PAINT);

			scrollbar->SetRange(0, entriesHeight - (GetHeight() - 4 - headerHeight));

			/* Find visible entries.
			 */
			entryRect.top	 = -scrollbarPos;
			entryRect.bottom = -scrollbarPos;

			for (Int i = 0; i < Length(); i++)
			{
				ListEntry	*entry = GetNthEntry(i);

				entry->SetVisibleDirect(False);

				if (entryRect.bottom + entry->GetHeight() >= 0 && entryRect.top <= GetHeight() - headerHeight - 4)
				{
					entry->SetMetrics(Point(2, entryRect.top + 2 + headerHeight), Size(GetWidth() - 4 - scrollbarWidth, entry->GetHeight()));
					entry->SetVisibleDirect(True);

					lastVisibleEntry = entry;

					visibleEntries[visibleEntryCount++] = entry->GetHandle() % 32767 + 1;
				}

				entryRect.top	 += entry->GetHeight();
				entryRect.bottom += entry->GetHeight();

				if (entryRect.top > GetHeight() - headerHeight - 4) break;
			}

			/* Check for changes.
			 */
			if (visibleEntriesString != visibleEntries)
			{
				/* Draw added entry only if it was added to the end.
				 */
				if	(visibleEntries.StartsWith(visibleEntriesString) && visibleEntries.Length() == visibleEntriesString.Length() + 1) lastVisibleEntry->Paint(SP_PAINT);

				/* Nothing needs to be done if last entry was removed.
				 */
				else if (visibleEntriesString.StartsWith(visibleEntries) && visibleEntriesString.Length() == visibleEntries.Length() + 1) ;

				/* Redraw the whole list if something else changed.
				 */
				else															  Paint(SP_PAINT);

				visibleEntriesString = visibleEntries;
			}

			break;
	}

	return Success();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %esi, %r15d
movq %rdi, %rbx
movq (%rdi), %rax
callq *0x88(%rax)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testb %al, %al
je 0x84aa8
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x90(%rax)
xorl %ebp, %ebp
testb %al, %al
je 0x84aa8
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x40(%rax)
movq %rax, %r13
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x48(%rax)
movq %rax, %r14
movq %rax, %r12
shrq $0x20, %r12
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x50(%rax)
leal (%rax,%r14), %ecx
shrq $0x20, %rax
movl %r14d, 0x18(%rsp)
movl %r12d, 0x1c(%rsp)
movl %ecx, 0x20(%rsp)
addl %r12d, %eax
movl %eax, 0x24(%rsp)
leaq 0x48(%rsp), %rdi
xorl %esi, %esi
callq 0x58e20
movq 0x6d8(%rbx), %rdi
callq 0x55530
testl %eax, %eax
jle 0x844d2
movl $0x58, %eax
testb $0x8, 0x30(%rbx)
je 0x844d7
movl $0x60, %eax
movq 0x6d8(%rbx), %rdi
movq (%rdi), %rcx
callq *(%rcx,%rax)
movq 0x6d8(%rbx), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
xorl %r14d, %r14d
testb %al, %al
je 0x84509
movq 0x6d8(%rbx), %rax
movl 0xb4(%rax), %r14d
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
movl $0xfffffffc, %r12d      # imm = 0xFFFFFFFC
testb %al, %al
je 0x84531
movq 0x6c8(%rbx), %rax
subl 0xb0(%rax), %r12d
testl %r15d, %r15d
movq %r14, 0x28(%rsp)
je 0x845b9
xorl %ebp, %ebp
cmpl $0x1, %r15d
jne 0x84a9e
movq %rbx, %rdi
callq 0x58e60
movl %eax, %ebp
movl 0xb4(%rbx), %eax
subl %r14d, %eax
addl $-0x4, %eax
cmpl %eax, %ebp
jle 0x8457b
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
testb %al, %al
jne 0x8457b
testb $0x1, 0x30(%rbx)
je 0x845a7
movl 0xb4(%rbx), %eax
subl %r14d, %eax
addl $-0x4, %eax
cmpl %eax, %ebp
jg 0x8482b
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
testb %al, %al
je 0x8482b
movq (%rbx), %rax
movq %rbx, %rdi
xorl %esi, %esi
callq *0x78(%rax)
movl %eax, %ebp
jmp 0x84a9e
leaq 0x18(%rsp), %rsi
movq %r13, %rdi
callq 0x55160
movq %rbx, %rdi
callq 0x58e60
movl %eax, %ebp
movl 0xb4(%rbx), %eax
subl %r14d, %eax
leal -0x4(%rax), %ecx
cmpl %ecx, %ebp
movq %r13, 0x60(%rsp)
jle 0x84676
testb $0x1, 0x30(%rbx)
jne 0x84676
movq 0x6c8(%rbx), %rdi
leal 0x1(%r14), %ecx
leaq 0x30(%rsp), %rsi
movl $0x12, (%rsi)
movl %ecx, 0x4(%rsi)
movl 0xb0(%rdi), %ecx
addl $-0x2, %eax
leaq 0x8(%rsp), %rdx
movl %ecx, (%rdx)
movl %eax, 0x4(%rdx)
movq (%rdi), %rax
callq *0x150(%rax)
movq 0x6c8(%rbx), %rdi
addl %r14d, %ebp
subl 0xb4(%rbx), %ebp
addl $0x4, %ebp
xorl %esi, %esi
movl %ebp, %edx
callq 0x557e0
movq 0x6c8(%rbx), %rdi
movl 0xb4(%rbx), %eax
subl %r14d, %eax
addl $-0x4, %eax
movl %eax, 0x654(%rdi)
movq (%rdi), %rax
callq *0x58(%rax)
movq 0x6c8(%rbx), %rax
movl 0xb0(%rax), %eax
movl %eax, 0x4(%rsp)
jmp 0x84695
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x60(%rax)
movl $0x0, 0x6d0(%rbx)
movl $0x0, 0x4(%rsp)
movl $0x0, 0x10(%rsp)
xorl %r12d, %r12d
subl 0x6d0(%rbx), %r12d
leal 0x2(%r14), %eax
movq %rax, 0x40(%rsp)
movl %r12d, %r13d
xorl %r14d, %r14d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x178(%rax)
cmpl %eax, %r14d
jge 0x847a4
movq (%rbx), %rax
movq %rbx, %rdi
movl %r14d, %esi
callq *0x180(%rax)
movq %rax, %r15
movb $0x0, 0xcb(%rax)
movl 0xb4(%rax), %eax
movl %eax, %ecx
addl %r13d, %ecx
js 0x8478f
movl 0xb4(%rbx), %ecx
subl 0x28(%rsp), %ecx
addl $-0x4, %ecx
cmpl %ecx, %r12d
jg 0x8478f
movq 0x40(%rsp), %rcx
addl %r12d, %ecx
movl $0x2, 0x30(%rsp)
movl %ecx, 0x34(%rsp)
movl 0xb0(%rbx), %ecx
subl 0x4(%rsp), %ecx
addl $-0x4, %ecx
movl %ecx, 0x8(%rsp)
movl %eax, 0xc(%rsp)
movq (%r15), %rax
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq *0x150(%rax)
movb $0x1, 0xcb(%r15)
movl 0x8(%r15), %ebp
leaq 0x48(%rsp), %rdi
movl 0x10(%rsp), %esi
callq 0x58990
incl 0x10(%rsp)
movslq %ebp, %rcx
imulq $-0x7ffefffd, %rcx, %rdx # imm = 0x80010003
shrq $0x20, %rdx
addl %ecx, %edx
movl %edx, %esi
shrl $0x1f, %esi
sarl $0xe, %edx
addl %esi, %edx
movl %edx, %esi
shll $0xf, %esi
subl %esi, %edx
addl %edx, %ecx
incl %ecx
movl %ecx, (%rax)
movl 0xb4(%r15), %eax
addl %eax, %r12d
addl %eax, %r13d
incl %r14d
jmp 0x846b6
leaq 0x6e0(%rbx), %rdi
leaq 0x48(%rsp), %rsi
callq 0x555f0
movq 0x28(%rsp), %r14
movq 0x60(%rsp), %r15
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x98(%rax)
testb %al, %al
je 0x849de
movl 0x18(%rsp), %eax
movl 0x20(%rsp), %ecx
addl 0x1c(%rsp), %r14d
shlq $0x20, %r14
orq %rax, %r14
subl 0x4(%rsp), %ecx
movl 0x24(%rsp), %eax
shlq $0x20, %rax
orq %rax, %rcx
leaq 0x30(%rsp), %rsi
movq %r14, (%rsi)
movq %rcx, 0x8(%rsi)
movq 0xe879f(%rip), %rax     # 0x16cfa8
movl (%rax), %ecx
leaq 0x8(%rsp), %r8
movq $0x0, (%r8)
movq 0xe7e52(%rip), %rdx     # 0x16c670
movq %r15, %rdi
callq 0x57930
jmp 0x84a31
movq 0x6c8(%rbx), %rdi
addl %r14d, %ebp
subl 0xb4(%rbx), %ebp
addl $0x4, %ebp
movq $0x0, 0x10(%rsp)
xorl %esi, %esi
movl %ebp, %edx
callq 0x557e0
movl %r12d, 0x4(%rsp)
xorl %ebp, %ebp
subl 0x6d0(%rbx), %ebp
leal 0x2(%r14), %eax
movq %rax, 0x40(%rsp)
movl %ebp, %r14d
xorl %r13d, %r13d
xorl %r12d, %r12d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x178(%rax)
cmpl %eax, %r12d
jge 0x8497a
movq (%rbx), %rax
movq %rbx, %rdi
movl %r12d, %esi
callq *0x180(%rax)
movq %rax, %r15
movb $0x0, 0xcb(%rax)
movl 0xb4(%rax), %eax
movl %eax, %ecx
addl %r14d, %ecx
js 0x84952
movl 0xb4(%rbx), %ecx
movq 0x28(%rsp), %rdx
subl %edx, %ecx
addl $-0x4, %ecx
cmpl %ecx, %ebp
jg 0x84957
movq 0x40(%rsp), %rcx
addl %ebp, %ecx
movl $0x2, 0x30(%rsp)
movl %ecx, 0x34(%rsp)
movl 0xb0(%rbx), %ecx
addl 0x4(%rsp), %ecx
movl %ecx, 0x8(%rsp)
movl %eax, 0xc(%rsp)
movq (%r15), %rax
movq %r15, %rdi
leaq 0x30(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq *0x150(%rax)
movb $0x1, 0xcb(%r15)
movl 0x8(%r15), %r13d
leaq 0x48(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x58990
movq 0x10(%rsp), %rcx
incl %ecx
movq %rcx, 0x10(%rsp)
movslq %r13d, %rcx
imulq $-0x7ffefffd, %rcx, %rdx # imm = 0x80010003
shrq $0x20, %rdx
addl %ecx, %edx
movl %edx, %esi
shrl $0x1f, %esi
sarl $0xe, %edx
addl %esi, %edx
movl %edx, %esi
shll $0xf, %esi
subl %esi, %edx
addl %edx, %ecx
incl %ecx
movl %ecx, (%rax)
movq %r15, %r13
movq 0x28(%rsp), %rdx
movl 0xb4(%r15), %eax
addl %eax, %ebp
movl 0xb4(%rbx), %ecx
subl %edx, %ecx
addl $-0x4, %ecx
cmpl %ecx, %ebp
jg 0x8497a
addl %eax, %r14d
incl %r12d
jmp 0x8486f
leaq 0x6e0(%rbx), %r14
leaq 0x48(%rsp), %rsi
movq %r14, %rdi
callq 0x56fa0
xorl %ebp, %ebp
testb %al, %al
je 0x84a9e
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0x577d0
testb %al, %al
je 0x84a59
leaq 0x48(%rsp), %rdi
callq 0x57180
movl %eax, %r15d
movq %r14, %rdi
callq 0x57180
incl %eax
cmpl %eax, %r15d
jne 0x84a59
movq (%r13), %rax
movq %r13, %rdi
xorl %esi, %esi
callq *0x78(%rax)
jmp 0x84a91
movl 0x18(%rsp), %eax
movl 0x20(%rsp), %ecx
addl 0x1c(%rsp), %r14d
shlq $0x20, %r14
orq %rax, %r14
subl 0x4(%rsp), %ecx
movl 0x24(%rsp), %eax
shlq $0x20, %rax
orq %rax, %rcx
leaq 0x30(%rsp), %rsi
movq %r14, (%rsi)
movq %rcx, 0x8(%rsi)
movq 0xe8594(%rip), %rax     # 0x16cfa8
movl (%rax), %ecx
leaq 0x8(%rsp), %r8
movq $0x0, (%r8)
movq 0xe7aa7(%rip), %rdx     # 0x16c4d0
movq %r15, %rdi
callq 0x57930
leaq 0x18(%rsp), %rsi
movq %r15, %rdi
movl $0x1, %edx
callq 0x57890
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %esi, %esi
callq 0x567d0
movq %r15, %rdi
callq 0x58780
jmp 0x84a9e
leaq 0x48(%rsp), %rsi
movq %r14, %rdi
callq 0x577d0
testb %al, %al
je 0x84a86
movq %r14, %rdi
callq 0x57180
movl %eax, %r15d
leaq 0x48(%rsp), %rdi
callq 0x57180
incl %eax
cmpl %eax, %r15d
je 0x84a91
movq (%rbx), %rax
movq %rbx, %rdi
xorl %esi, %esi
callq *0x78(%rax)
leaq 0x48(%rsp), %rsi
movq %r14, %rdi
callq 0x555f0
leaq 0x48(%rsp), %rdi
callq 0x59200
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x84acf
jmp 0x84acf
jmp 0x84acf
jmp 0x84acf
jmp 0x84acf
jmp 0x84acf
jmp 0x84acf
jmp 0x84acf
jmp 0x84acf
jmp 0x84acf
jmp 0x84acf
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x59200
movq %rbx, %rdi
callq 0x57090