// File: /workspace/github_c_makefile_star2_O2/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 $0x78, %rsp
movl %esi, %r15d
movq %rdi, %rbx
movq (%rdi), %rax
callq *0x88(%rax)
testb %al, %al
je 0x81d3c
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x90(%rax)
xorl %ebp, %ebp
testb %al, %al
je 0x822f4
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, 0x58(%rsp)
movl %r12d, 0x5c(%rsp)
movl %ecx, 0x60(%rsp)
addl %r12d, %eax
movl %eax, 0x64(%rsp)
leaq 0x40(%rsp), %rdi
xorl %esi, %esi
callq 0x5a180
movq %rbx, %rdi
callq 0x56760
testl %eax, %eax
jle 0x81d44
testb $0x8, 0x30(%rbx)
jne 0x81d44
pushq $0x58
jmp 0x81d46
pushq $-0x1
popq %rbp
jmp 0x822f4
pushq $0x60
popq %rax
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 0x81d79
movq 0x6d8(%rbx), %rax
movl 0xb4(%rax), %r14d
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
testb %al, %al
je 0x81da3
movq 0x6c8(%rbx), %rax
pushq $-0x4
popq %rcx
subl 0xb0(%rax), %ecx
movl %ecx, 0xc(%rsp)
jmp 0x81daa
pushq $-0x4
popq %rax
movl %eax, 0xc(%rsp)
testl %r15d, %r15d
je 0x81e33
xorl %ebp, %ebp
cmpl $0x1, %r15d
jne 0x822ea
movq %rbx, %rdi
callq 0x5a1c0
movl %eax, %ebp
movl 0xb4(%rbx), %eax
subl %r14d, %eax
addl $-0x4, %eax
cmpl %eax, %ebp
jle 0x81df3
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
testb %al, %al
jne 0x81df3
testb $0x1, 0x30(%rbx)
je 0x81e21
movl 0xb4(%rbx), %eax
movl %eax, %ecx
subl %r14d, %ecx
addl $-0x4, %ecx
cmpl %ecx, %ebp
jg 0x82113
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
testb %al, %al
je 0x8210d
movq (%rbx), %rax
movq %rbx, %rdi
xorl %esi, %esi
callq *0x78(%rax)
movl %eax, %ebp
jmp 0x822ea
leaq 0x58(%rsp), %rsi
movq %r13, %rdi
callq 0x56160
movq %rbx, %rdi
callq 0x5a1c0
movl %eax, %ebp
movl 0xb4(%rbx), %eax
subl %r14d, %eax
leal -0x4(%rax), %ecx
cmpl %ecx, %ebp
movq %r13, 0x68(%rsp)
jle 0x81ef7
testb $0x1, 0x30(%rbx)
jne 0x81ef7
movq 0x6c8(%rbx), %rdi
leal 0x1(%r14), %ecx
leaq 0x28(%rsp), %rsi
movl $0x12, (%rsi)
movl %ecx, 0x4(%rsi)
movl 0xb0(%rdi), %ecx
addl $-0x2, %eax
leaq 0x10(%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 0x56840
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, 0xc(%rsp)
movl 0x6d0(%rbx), %r13d
jmp 0x81f16
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x60(%rax)
andl $0x0, 0x6d0(%rbx)
xorl %r13d, %r13d
movl $0x0, 0xc(%rsp)
negl %r13d
movq %r14, 0x20(%rsp)
leal 0x2(%r14), %eax
movq %rax, 0x38(%rsp)
movl $0x0, 0x18(%rsp)
movl %r13d, %ebp
xorl %r14d, %r14d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x178(%rax)
cmpl %eax, %r14d
jge 0x8200c
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 %ebp, %ecx
js 0x81fff
movl 0xb4(%rbx), %edx
subl 0x20(%rsp), %edx
addl $-0x4, %edx
cmpl %edx, %r13d
jg 0x81fff
movq 0x38(%rsp), %rcx
addl %r13d, %ecx
movl $0x2, 0x28(%rsp)
movl %ecx, 0x2c(%rsp)
movl 0xb0(%rbx), %ecx
subl 0xc(%rsp), %ecx
addl $-0x4, %ecx
movl %ecx, 0x10(%rsp)
movl %eax, 0x14(%rsp)
movq (%r15), %rax
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq *0x150(%rax)
movb $0x1, 0xcb(%r15)
movl 0x8(%r15), %r12d
leaq 0x40(%rsp), %rdi
movl 0x18(%rsp), %esi
callq 0x59cc0
movq %rax, %rcx
incl 0x18(%rsp)
movl %r12d, %eax
cltd
movl $0x7fff, %esi           # imm = 0x7FFF
idivl %esi
incl %edx
movl %edx, (%rcx)
movl 0xb4(%r15), %eax
addl %eax, %ebp
movl %ebp, %ecx
addl %eax, %r13d
incl %r14d
movl %ecx, %ebp
jmp 0x81f35
leaq 0x6e0(%rbx), %rdi
leaq 0x40(%rsp), %rsi
callq 0x56630
movq 0x20(%rsp), %r14
movq 0x68(%rsp), %r15
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x98(%rax)
leaq 0x10(%rsp), %rsi
testb %al, %al
je 0x82091
andl $0x0, (%rsi)
movl %r14d, 0x4(%rsi)
leaq 0x58(%rsp), %rdi
callq 0x58930
movq %rdx, %rcx
shrq $0x20, %rcx
subl 0xc(%rsp), %edx
subl %r14d, %ecx
shlq $0x20, %rcx
orq %rcx, %rdx
leaq 0x28(%rsp), %rsi
movq %rax, (%rsi)
movq %rdx, 0x8(%rsi)
movq 0xdff33(%rip), %rax     # 0x161fa8
movl (%rax), %ecx
leaq 0x70(%rsp), %r8
andq $0x0, (%r8)
movq 0xdf5e9(%rip), %rdx     # 0x161670
movq %r15, %rdi
callq 0x58b80
jmp 0x820e4
andl $0x0, (%rsi)
movl %r14d, 0x4(%rsi)
leaq 0x58(%rsp), %rdi
callq 0x58930
movq %rdx, %rcx
shrq $0x20, %rcx
subl 0xc(%rsp), %edx
subl %r14d, %ecx
shlq $0x20, %rcx
orq %rcx, %rdx
leaq 0x28(%rsp), %rsi
movq %rax, (%rsi)
movq %rdx, 0x8(%rsi)
movq 0xdfede(%rip), %rax     # 0x161fa8
movl (%rax), %ecx
leaq 0x70(%rsp), %r8
andq $0x0, (%r8)
movq 0xdf3f4(%rip), %rdx     # 0x1614d0
movq %r15, %rdi
callq 0x58b80
leaq 0x58(%rsp), %rsi
pushq $0x1
popq %rdx
movq %r15, %rdi
callq 0x58ad0
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %esi, %esi
callq 0x57910
movq %r15, %rdi
callq 0x59a80
jmp 0x822ea
movl 0xb4(%rbx), %eax
movq 0x6c8(%rbx), %rdi
addl %r14d, %ebp
subl %eax, %ebp
addl $0x4, %ebp
movq $0x0, 0x18(%rsp)
xorl %esi, %esi
movl %ebp, %edx
callq 0x56840
movq %r14, %rcx
xorl %r14d, %r14d
subl 0x6d0(%rbx), %r14d
movq %rcx, 0x20(%rsp)
leal 0x2(%rcx), %eax
movq %rax, 0x38(%rsp)
movl %r14d, %r13d
xorl %r12d, %r12d
xorl %ebp, %ebp
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x178(%rax)
cmpl %eax, %ebp
jge 0x8224c
movq (%rbx), %rax
movq %rbx, %rdi
movl %ebp, %esi
callq *0x180(%rax)
movq %rax, %r15
movb $0x0, 0xcb(%rax)
movl 0xb4(%rax), %eax
movl %eax, %ecx
addl %r13d, %ecx
movl 0xb4(%rbx), %ecx
js 0x821a3
movl %ecx, %edx
subl 0x20(%rsp), %edx
addl $-0x4, %edx
cmpl %edx, %r14d
jle 0x821ab
movq %r12, %r15
jmp 0x8222d
movq 0x38(%rsp), %rcx
addl %r14d, %ecx
movl $0x2, 0x28(%rsp)
movl %ecx, 0x2c(%rsp)
movl 0xb0(%rbx), %ecx
addl 0xc(%rsp), %ecx
movl %ecx, 0x10(%rsp)
movl %eax, 0x14(%rsp)
movq (%r15), %rax
movq %r15, %rdi
leaq 0x28(%rsp), %rsi
leaq 0x10(%rsp), %rdx
callq *0x150(%rax)
movb $0x1, 0xcb(%r15)
movl 0x8(%r15), %r12d
leaq 0x40(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x59cc0
movq %rax, %rcx
movq 0x18(%rsp), %rax
incl %eax
movq %rax, 0x18(%rsp)
movl %r12d, %eax
cltd
movl $0x7fff, %esi           # imm = 0x7FFF
idivl %esi
incl %edx
movl %edx, (%rcx)
movl 0xb4(%r15), %eax
movl 0xb4(%rbx), %ecx
addl %eax, %r14d
subl 0x20(%rsp), %ecx
addl $-0x4, %ecx
cmpl %ecx, %r14d
jg 0x82249
addl %eax, %r13d
incl %ebp
movq %r15, %r12
jmp 0x82156
movq %r15, %r12
leaq 0x6e0(%rbx), %r14
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
callq 0x58150
xorl %ebp, %ebp
testb %al, %al
je 0x822ea
leaq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0x58a10
testb %al, %al
je 0x822a5
leaq 0x40(%rsp), %rdi
callq 0x58370
movl %eax, %r15d
movq %r14, %rdi
callq 0x58370
incl %eax
cmpl %eax, %r15d
jne 0x822a5
movq (%r12), %rax
movq %r12, %rdi
xorl %esi, %esi
callq *0x78(%rax)
jmp 0x822dd
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
callq 0x58a10
testb %al, %al
je 0x822d2
movq %r14, %rdi
callq 0x58370
movl %eax, %r15d
leaq 0x40(%rsp), %rdi
callq 0x58370
incl %eax
cmpl %eax, %r15d
je 0x822dd
movq (%rbx), %rax
movq %rbx, %rdi
xorl %esi, %esi
callq *0x78(%rax)
leaq 0x40(%rsp), %rsi
movq %r14, %rdi
callq 0x56630
leaq 0x40(%rsp), %rdi
callq 0x5a588
movl %ebp, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x8231f
jmp 0x8231f
jmp 0x8231f
jmp 0x8231f
jmp 0x8231f
jmp 0x8231f
jmp 0x8231f
jmp 0x8231f
jmp 0x8231f
jmp 0x8231f
jmp 0x8231f
jmp 0x8231f
jmp 0x8231f
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x5a588
movq %rbx, %rdi
callq 0x58260