// File: /workspace/github_c_makefile_star2_O3/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 0x8459e
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x90(%rax)
xorl %ebp, %ebp
testb %al, %al
je 0x8459e
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x40(%rax)
movq %rax, 0x28(%rsp)
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 0x50(%rsp), %rdi
xorl %esi, %esi
callq 0x58e20
movq 0x6d8(%rbx), %rdi
callq 0x55530
testl %eax, %eax
jle 0x83fc0
movl $0x58, %eax
testb $0x8, 0x30(%rbx)
je 0x83fc5
movl $0x60, %eax
movq 0x6d8(%rbx), %rdi
movq (%rdi), %rcx
callq *(%rcx,%rax)
movq 0x6d8(%rbx), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
xorl %r13d, %r13d
testb %al, %al
je 0x83ff7
movq 0x6d8(%rbx), %rax
movl 0xb4(%rax), %r13d
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
movl $0xfffffffc, %r14d      # imm = 0xFFFFFFFC
testb %al, %al
je 0x8401f
movq 0x6c8(%rbx), %rax
subl 0xb0(%rax), %r14d
testl %r15d, %r15d
je 0x840a8
xorl %ebp, %ebp
cmpl $0x1, %r15d
jne 0x84594
movq %rbx, %rdi
callq 0x58e60
movl %eax, %ebp
movl 0xb4(%rbx), %eax
subl %r13d, %eax
addl $-0x4, %eax
cmpl %eax, %ebp
jle 0x84068
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
testb %al, %al
jne 0x84068
testb $0x1, 0x30(%rbx)
je 0x84096
movl 0xb4(%rbx), %eax
movl %eax, %ecx
subl %r13d, %ecx
addl $-0x4, %ecx
cmpl %ecx, %ebp
jg 0x843a5
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
testb %al, %al
je 0x8439f
movq (%rbx), %rax
movq %rbx, %rdi
xorl %esi, %esi
callq *0x78(%rax)
movl %eax, %ebp
jmp 0x84594
leaq 0x18(%rsp), %rsi
movq 0x28(%rsp), %rdi
callq 0x55160
movq %rbx, %rdi
callq 0x58e60
movl %eax, %ebp
movl 0xb4(%rbx), %eax
subl %r13d, %eax
leal -0x4(%rax), %ecx
cmpl %ecx, %ebp
jle 0x84169
testb $0x1, 0x30(%rbx)
jne 0x84169
movq 0x6c8(%rbx), %rdi
leal 0x1(%r13), %ecx
leaq 0x38(%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 %r13d, %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 %r13d, %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)
movl 0x6d0(%rbx), %r12d
jmp 0x8418b
movq 0x6c8(%rbx), %rdi
movq (%rdi), %rax
callq *0x60(%rax)
movl $0x0, 0x6d0(%rbx)
xorl %r12d, %r12d
movl $0x0, 0x4(%rsp)
negl %r12d
movq %r13, 0x30(%rsp)
leal 0x2(%r13), %eax
movq %rax, 0x48(%rsp)
movl $0x0, 0x10(%rsp)
movl %r12d, %r13d
xorl %r14d, %r14d
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x178(%rax)
cmpl %eax, %r14d
jge 0x8429e
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 0x84290
movl 0xb4(%rbx), %edx
subl 0x30(%rsp), %edx
addl $-0x4, %edx
cmpl %edx, %r12d
jg 0x84290
movq 0x48(%rsp), %rcx
addl %r12d, %ecx
movl $0x2, 0x38(%rsp)
movl %ecx, 0x3c(%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 0x38(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq *0x150(%rax)
movb $0x1, 0xcb(%r15)
movl 0x8(%r15), %ebp
leaq 0x50(%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, %r13d
movl %r13d, %ecx
addl %eax, %r12d
incl %r14d
movl %ecx, %r13d
jmp 0x841aa
leaq 0x6e0(%rbx), %rdi
leaq 0x50(%rsp), %rsi
callq 0x555f0
movq 0x30(%rsp), %r14
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x98(%rax)
testb %al, %al
je 0x8431b
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 0x38(%rsp), %rsi
movq %r14, (%rsi)
movq %rcx, 0x8(%rsi)
movq 0xe7cae(%rip), %rax     # 0x16bfa8
movl (%rax), %ecx
leaq 0x8(%rsp), %r8
movq $0x0, (%r8)
movq 0xe7361(%rip), %rdx     # 0x16b670
movq 0x28(%rsp), %rdi
callq 0x57930
jmp 0x84370
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 0x38(%rsp), %rsi
movq %r14, (%rsi)
movq %rcx, 0x8(%rsi)
movq 0xe7c57(%rip), %rax     # 0x16bfa8
movl (%rax), %ecx
leaq 0x8(%rsp), %r8
movq $0x0, (%r8)
movq 0xe716a(%rip), %rdx     # 0x16b4d0
movq 0x28(%rsp), %rdi
callq 0x57930
leaq 0x18(%rsp), %rsi
movq 0x28(%rsp), %rdi
movl $0x1, %edx
callq 0x57890
xorl %ebp, %ebp
movq %rbx, %rdi
xorl %esi, %esi
callq 0x567d0
movq 0x28(%rsp), %rdi
callq 0x58780
jmp 0x84594
movl 0xb4(%rbx), %eax
movq 0x6c8(%rbx), %rdi
addl %r13d, %ebp
subl %eax, %ebp
addl $0x4, %ebp
movq $0x0, 0x10(%rsp)
xorl %esi, %esi
movl %ebp, %edx
callq 0x557e0
movl %r14d, 0x4(%rsp)
xorl %r14d, %r14d
subl 0x6d0(%rbx), %r14d
movq %r13, 0x30(%rsp)
leal 0x2(%r13), %eax
movq %rax, 0x48(%rsp)
movl %r14d, %r13d
xorl %r12d, %r12d
xorl %ebp, %ebp
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x178(%rax)
cmpl %eax, %ebp
jge 0x844f6
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 0x84438
movl %ecx, %edx
subl 0x30(%rsp), %edx
addl $-0x4, %edx
cmpl %edx, %r14d
jle 0x84440
movq %r12, %r15
jmp 0x844d7
movq 0x48(%rsp), %rcx
addl %r14d, %ecx
movl $0x2, 0x38(%rsp)
movl %ecx, 0x3c(%rsp)
movl 0xb0(%rbx), %ecx
addl 0x4(%rsp), %ecx
movl %ecx, 0x8(%rsp)
movl %eax, 0xc(%rsp)
movq (%r15), %rax
movq %r15, %rdi
leaq 0x38(%rsp), %rsi
leaq 0x8(%rsp), %rdx
callq *0x150(%rax)
movb $0x1, 0xcb(%r15)
movl 0x8(%r15), %r12d
leaq 0x50(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x58990
movq 0x10(%rsp), %rcx
incl %ecx
movq %rcx, 0x10(%rsp)
movslq %r12d, %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
movl 0xb4(%rbx), %ecx
addl %eax, %r14d
subl 0x30(%rsp), %ecx
addl $-0x4, %ecx
cmpl %ecx, %r14d
jg 0x844f3
addl %eax, %r13d
incl %ebp
movq %r15, %r12
jmp 0x843eb
movq %r15, %r12
leaq 0x6e0(%rbx), %r14
leaq 0x50(%rsp), %rsi
movq %r14, %rdi
callq 0x56fa0
xorl %ebp, %ebp
testb %al, %al
je 0x84594
leaq 0x50(%rsp), %rdi
movq %r14, %rsi
callq 0x577d0
testb %al, %al
je 0x8454f
leaq 0x50(%rsp), %rdi
callq 0x57180
movl %eax, %r15d
movq %r14, %rdi
callq 0x57180
incl %eax
cmpl %eax, %r15d
jne 0x8454f
movq (%r12), %rax
movq %r12, %rdi
xorl %esi, %esi
callq *0x78(%rax)
jmp 0x84587
leaq 0x50(%rsp), %rsi
movq %r14, %rdi
callq 0x577d0
testb %al, %al
je 0x8457c
movq %r14, %rdi
callq 0x57180
movl %eax, %r15d
leaq 0x50(%rsp), %rdi
callq 0x57180
incl %eax
cmpl %eax, %r15d
je 0x84587
movq (%rbx), %rax
movq %rbx, %rdi
xorl %esi, %esi
callq *0x78(%rax)
leaq 0x50(%rsp), %rsi
movq %r14, %rdi
callq 0x555f0
leaq 0x50(%rsp), %rdi
callq 0x59200
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x845c5
jmp 0x845c5
jmp 0x845c5
jmp 0x845c5
jmp 0x845c5
jmp 0x845c5
jmp 0x845c5
jmp 0x845c5
jmp 0x845c5
jmp 0x845c5
jmp 0x845c5
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x59200
movq %rbx, %rdi
callq 0x57090