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

#ifdef __APPLE__
	if (orientation == OR_FREE)
	{
		if (menubarCocoa != NIL) menubarCocoa->Paint(message);

		return Success();
	}
#endif

	Window		*window	   = GetContainerWindow();
	Surface		*surface   = GetDrawSurface();
	Rect		 menubar   = Rect(GetRealPosition(), GetRealSize() - Size(1, 1));

#ifdef __WIN32__
	static Bool	 flatStyle = Backends::BackendWin32::IsWindowsVersionAtLeast(VER_PLATFORM_WIN32_NT, 6, 2);
#else
	static Bool	 flatStyle = True;
#endif

	if (orientation == OR_TOP || orientation == OR_BOTTOM)
	{
#ifdef __APPLE__
		Int	 leftWidth	= 0;
		Int	 rightWidth	= 0;

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

			if	(entry->GetOrientation() == OR_TOP    || entry->GetOrientation() == OR_LEFT)  leftWidth	 += entry->GetWidth() + 2;
			else if (entry->GetOrientation() == OR_BOTTOM || entry->GetOrientation() == OR_RIGHT) rightWidth += entry->GetWidth() + 2;
		}

		Int	 nextXPosLeft	= (GetSize().cx - leftWidth - rightWidth + 2) / 2;
		Int	 nextXPosRight	= nextXPosLeft + leftWidth + rightWidth - 2;
#else
		Int	 nextXPosLeft	= 7 + (window->GetIcon() != NIL ? 17 : 0);
		Int	 nextXPosRight	= GetSize().cx - 1;

		if (flatStyle) nextXPosLeft = 1;
#endif
		Int	 highestEntry	= 0;

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

			if (entry->GetOrientation() == OR_TOP) entry->SetOrientation(OR_LEFT);

			if (entry->GetOrientation() == OR_LEFT)
			{
				entry->SetPosition(Point(nextXPosLeft, 2));

				nextXPosLeft += entry->GetWidth() + 2;

				if (highestEntry < entry->GetHeight()) highestEntry = entry->GetHeight();
			}
		}

		for (Int i = Length() - 1; i >= 0; i--)
		{
			MenuEntry	*entry = GetNthEntry(i);

			if (entry->GetOrientation() == OR_BOTTOM) entry->SetOrientation(OR_RIGHT);

			if (entry->GetOrientation() == OR_RIGHT)
			{
				entry->SetPosition(Point(nextXPosRight - entry->GetWidth(), 2));

				nextXPosRight -= entry->GetWidth() + 2;

				if (highestEntry < entry->GetHeight()) highestEntry = entry->GetHeight();
			}
		}

		SetHeight(highestEntry + 2);

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

			if (entry->GetText() == NIL && entry->GetBitmap() == NIL) entry->SetHeight(GetHeight() - 3);
		}
	}
	else if (orientation == OR_LEFT || orientation == OR_RIGHT)
	{
		Int	 nextYPos	= 1;
		Int	 widestEntry	= 0;

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

			if (entry->GetOrientation() == OR_LEFT) entry->SetOrientation(OR_TOP);

			if (entry->GetOrientation() == OR_TOP)
			{
				entry->SetPosition(Point(1, nextYPos));

				nextYPos += entry->GetHeight() + 2;

				if (widestEntry < entry->GetWidth()) widestEntry = entry->GetWidth();
			}
		}

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

			if (entry->GetOrientation() == OR_RIGHT) entry->SetOrientation(OR_BOTTOM);

			if (entry->GetOrientation() == OR_BOTTOM)
			{
				entry->SetPosition(Point(1, nextYPos));

				nextYPos += entry->GetHeight() + 2;

				if (widestEntry < entry->GetWidth()) widestEntry = entry->GetWidth();
			}
		}

		SetWidth(widestEntry + 3);

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

			if (entry->GetText() == NIL && entry->GetBitmap() == NIL) entry->SetWidth(GetWidth() - 3);
		}
	}

	/* Draw handles of non-flat style menubars.
	 */
	switch (message)
	{
		case SP_PAINT:
			if (flatStyle) break;

			if (orientation == OR_TOP || orientation == OR_BOTTOM)
			{
				if (orientation == OR_BOTTOM) { menubar.top--; menubar.bottom--; }

				Point	 p1 = Point(menubar.left + 1, menubar.top + 2);
				Point	 p2 = Point(p1.x, menubar.bottom);

				if (window->GetIcon() != NIL && orientation == OR_TOP)
				{
					p1.x += Math::Round(18 * surface->GetSurfaceDPI() / 96.0) - 1;
					p2.x += Math::Round(18 * surface->GetSurfaceDPI() / 96.0) - 1;
				}

				surface->Bar(p1, p2, OR_VERT);

				p1.x += 2;
				p2.x += 2;

				surface->Bar(p1, p2, OR_VERT);
			}

			break;
	}

	return Widget::Paint(message);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x130(%rbp)
movq (%rdi), %rax
callq *0x88(%rax)
testb $0x1, %al
jne 0xba914
leaq -0x28(%rbp), %rdi
movq %rdi, -0x140(%rbp)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
callq 0x5a9c0
movq -0x140(%rbp), %rdi
callq 0x59680
movl %eax, -0x134(%rbp)
jmp 0xba8e3
movl -0x134(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x5b5b0
jmp 0xbb31e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x5b5b0
jmp 0xbb32a
movq -0x130(%rbp), %rdi
movq (%rdi), %rax
callq *0x90(%rax)
testb $0x1, %al
jne 0xba97d
leaq -0x48(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x5ca80
movq -0x150(%rbp), %rdi
callq 0x59680
movl %eax, -0x144(%rbp)
jmp 0xba94c
movl -0x144(%rbp), %eax
movl %eax, -0x4(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x5a410
jmp 0xbb31e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x30(%rbp)
movl %eax, -0x34(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x5a410
jmp 0xbb32a
movq -0x130(%rbp), %rdi
callq 0x59bc0
movq -0x130(%rbp), %rdi
movq %rax, -0x50(%rbp)
movq (%rdi), %rax
callq *0x40(%rax)
movq -0x130(%rbp), %rdi
movq %rax, -0x58(%rbp)
movq (%rdi), %rax
callq *0x48(%rax)
movq -0x130(%rbp), %rdi
movq %rax, -0x70(%rbp)
movq (%rdi), %rax
callq *0x50(%rax)
movq %rax, -0x80(%rbp)
leaq -0x88(%rbp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x59260
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x5db90
movq %rax, -0x78(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x59ff0
movq -0x130(%rbp), %rax
movswl 0xd0(%rax), %eax
cmpl $0x4, %eax
je 0xbaa22
movq -0x130(%rbp), %rax
movswl 0xd0(%rax), %eax
cmpl $0x8, %eax
jne 0xbade7
movq -0x50(%rbp), %rdi
callq 0x5a310
movq %rax, %rdi
xorl %esi, %esi
callq 0x5a830
movq -0x130(%rbp), %rdi
movb %al, %dl
xorl %eax, %eax
movl $0x11, %ecx
testb $0x1, %dl
cmovnel %ecx, %eax
addl $0x7, %eax
movl %eax, -0x8c(%rbp)
callq 0x5bf70
movl (%rax), %eax
subl $0x1, %eax
movl %eax, -0x90(%rbp)
testb $0x1, 0x150d55(%rip)    # 0x20b7c0
je 0xbaa77
movl $0x1, -0x8c(%rbp)
movl $0x0, -0x94(%rbp)
movl $0x0, -0x98(%rbp)
movq -0x130(%rbp), %rdi
movl -0x98(%rbp), %eax
movl %eax, -0x154(%rbp)
movq (%rdi), %rax
callq *0x178(%rax)
movl %eax, %ecx
movl -0x154(%rbp), %eax
cmpl %ecx, %eax
jge 0xbabb8
movq -0x130(%rbp), %rdi
movl -0x98(%rbp), %esi
movq (%rdi), %rax
callq *0x180(%rax)
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rdi
movq (%rdi), %rax
callq *0x128(%rax)
cmpl $0x4, %eax
jne 0xbaafe
movq -0xa0(%rbp), %rdi
movq (%rdi), %rax
movl $0x10, %esi
callq *0x120(%rax)
movq -0xa0(%rbp), %rdi
movq (%rdi), %rax
callq *0x128(%rax)
cmpl $0x10, %eax
jne 0xbaba2
movq -0xa0(%rbp), %rax
movq %rax, -0x160(%rbp)
movl -0x8c(%rbp), %esi
leaq -0xa8(%rbp), %rdi
movl $0x2, %edx
callq 0x5c2c0
movq -0x160(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x5d8c0
movq -0xa0(%rbp), %rdi
callq 0x5a210
addl $0x2, %eax
addl -0x8c(%rbp), %eax
movl %eax, -0x8c(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0x158(%rbp)
movq -0xa0(%rbp), %rdi
callq 0x5b860
movl %eax, %ecx
movl -0x158(%rbp), %eax
cmpl %ecx, %eax
jge 0xbaba0
movq -0xa0(%rbp), %rdi
callq 0x5b860
movl %eax, -0x94(%rbp)
jmp 0xbaba2
jmp 0xbaba4
movl -0x98(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x98(%rbp)
jmp 0xbaa8b
movq -0x130(%rbp), %rdi
movq (%rdi), %rax
callq *0x178(%rax)
subl $0x1, %eax
movl %eax, -0xac(%rbp)
cmpl $0x0, -0xac(%rbp)
jl 0xbacfd
movq -0x130(%rbp), %rdi
movl -0xac(%rbp), %esi
movq (%rdi), %rax
callq *0x180(%rax)
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rdi
movq (%rdi), %rax
callq *0x128(%rax)
cmpl $0x8, %eax
jne 0xbac25
movq -0xb8(%rbp), %rdi
movq (%rdi), %rax
movl $0x20, %esi
callq *0x120(%rax)
movq -0xb8(%rbp), %rdi
movq (%rdi), %rax
callq *0x128(%rax)
cmpl $0x20, %eax
jne 0xbace7
movq -0xb8(%rbp), %rax
movq %rax, -0x170(%rbp)
movl -0x90(%rbp), %eax
movl %eax, -0x174(%rbp)
movq -0xb8(%rbp), %rdi
callq 0x5a210
movl -0x174(%rbp), %esi
subl %eax, %esi
leaq -0xc0(%rbp), %rdi
movl $0x2, %edx
callq 0x5c2c0
movq -0x170(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x5d8c0
movq -0xb8(%rbp), %rdi
callq 0x5a210
movl %eax, %ecx
addl $0x2, %ecx
movl -0x90(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x90(%rbp)
movl -0x94(%rbp), %eax
movl %eax, -0x164(%rbp)
movq -0xb8(%rbp), %rdi
callq 0x5b860
movl %eax, %ecx
movl -0x164(%rbp), %eax
cmpl %ecx, %eax
jge 0xbace5
movq -0xb8(%rbp), %rdi
callq 0x5b860
movl %eax, -0x94(%rbp)
jmp 0xbace7
jmp 0xbace9
movl -0xac(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0xac(%rbp)
jmp 0xbabd1
movq -0x130(%rbp), %rdi
movl -0x94(%rbp), %esi
addl $0x2, %esi
callq 0x5bed0
movl $0x0, -0xc4(%rbp)
movq -0x130(%rbp), %rdi
movl -0xc4(%rbp), %eax
movl %eax, -0x178(%rbp)
movq (%rdi), %rax
callq *0x178(%rax)
movl %eax, %ecx
movl -0x178(%rbp), %eax
cmpl %ecx, %eax
jge 0xbade2
movq -0x130(%rbp), %rdi
movl -0xc4(%rbp), %esi
movq (%rdi), %rax
callq *0x180(%rax)
movq %rax, -0xd0(%rbp)
movq -0xd0(%rbp), %rdi
movq (%rdi), %rax
callq *0xa8(%rax)
movq %rax, %rdi
xorl %esi, %esi
callq 0x59320
testb $0x1, %al
jne 0xbad85
jmp 0xbadcc
movq -0xd0(%rbp), %rdi
callq 0x5a440
movq %rax, %rdi
xorl %esi, %esi
callq 0x5c730
testb $0x1, %al
jne 0xbada1
jmp 0xbadcc
movq -0x130(%rbp), %rdi
movq -0xd0(%rbp), %rax
movq %rax, -0x180(%rbp)
callq 0x5b860
movq -0x180(%rbp), %rdi
movl %eax, %esi
subl $0x3, %esi
callq 0x5bed0
jmp 0xbadce
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0xbad1c
jmp 0xbb17c
movq -0x130(%rbp), %rax
movswl 0xd0(%rax), %eax
cmpl $0x10, %eax
je 0xbae11
movq -0x130(%rbp), %rax
movswl 0xd0(%rax), %eax
cmpl $0x20, %eax
jne 0xbb17a
movl $0x1, -0xd4(%rbp)
movl $0x0, -0xd8(%rbp)
movl $0x0, -0xdc(%rbp)
movq -0x130(%rbp), %rdi
movl -0xdc(%rbp), %eax
movl %eax, -0x184(%rbp)
movq (%rdi), %rax
callq *0x178(%rax)
movl %eax, %ecx
movl -0x184(%rbp), %eax
cmpl %ecx, %eax
jge 0xbaf5c
movq -0x130(%rbp), %rdi
movl -0xdc(%rbp), %esi
movq (%rdi), %rax
callq *0x180(%rax)
movq %rax, -0xe8(%rbp)
movq -0xe8(%rbp), %rdi
movq (%rdi), %rax
callq *0x128(%rax)
cmpl $0x10, %eax
jne 0xbaea2
movq -0xe8(%rbp), %rdi
movq (%rdi), %rax
movl $0x4, %esi
callq *0x120(%rax)
movq -0xe8(%rbp), %rdi
movq (%rdi), %rax
callq *0x128(%rax)
cmpl $0x4, %eax
jne 0xbaf46
movq -0xe8(%rbp), %rax
movq %rax, -0x190(%rbp)
movl -0xd4(%rbp), %edx
leaq -0xf0(%rbp), %rdi
movl $0x1, %esi
callq 0x5c2c0
movq -0x190(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x5d8c0
movq -0xe8(%rbp), %rdi
callq 0x5b860
addl $0x2, %eax
addl -0xd4(%rbp), %eax
movl %eax, -0xd4(%rbp)
movl -0xd8(%rbp), %eax
movl %eax, -0x188(%rbp)
movq -0xe8(%rbp), %rdi
callq 0x5a210
movl %eax, %ecx
movl -0x188(%rbp), %eax
cmpl %ecx, %eax
jge 0xbaf44
movq -0xe8(%rbp), %rdi
callq 0x5a210
movl %eax, -0xd8(%rbp)
jmp 0xbaf46
jmp 0xbaf48
movl -0xdc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xdc(%rbp)
jmp 0xbae2f
movl $0x0, -0xf4(%rbp)
movq -0x130(%rbp), %rdi
movl -0xf4(%rbp), %eax
movl %eax, -0x194(%rbp)
movq (%rdi), %rax
callq *0x178(%rax)
movl %eax, %ecx
movl -0x194(%rbp), %eax
cmpl %ecx, %eax
jge 0xbb093
movq -0x130(%rbp), %rdi
movl -0xf4(%rbp), %esi
movq (%rdi), %rax
callq *0x180(%rax)
movq %rax, -0x100(%rbp)
movq -0x100(%rbp), %rdi
movq (%rdi), %rax
callq *0x128(%rax)
cmpl $0x20, %eax
jne 0xbafd9
movq -0x100(%rbp), %rdi
movq (%rdi), %rax
movl $0x8, %esi
callq *0x120(%rax)
movq -0x100(%rbp), %rdi
movq (%rdi), %rax
callq *0x128(%rax)
cmpl $0x8, %eax
jne 0xbb07d
movq -0x100(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movl -0xd4(%rbp), %edx
leaq -0x108(%rbp), %rdi
movl $0x1, %esi
callq 0x5c2c0
movq -0x1a0(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x5d8c0
movq -0x100(%rbp), %rdi
callq 0x5b860
addl $0x2, %eax
addl -0xd4(%rbp), %eax
movl %eax, -0xd4(%rbp)
movl -0xd8(%rbp), %eax
movl %eax, -0x198(%rbp)
movq -0x100(%rbp), %rdi
callq 0x5a210
movl %eax, %ecx
movl -0x198(%rbp), %eax
cmpl %ecx, %eax
jge 0xbb07b
movq -0x100(%rbp), %rdi
callq 0x5a210
movl %eax, -0xd8(%rbp)
jmp 0xbb07d
jmp 0xbb07f
movl -0xf4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4(%rbp)
jmp 0xbaf66
movq -0x130(%rbp), %rdi
movl -0xd8(%rbp), %esi
addl $0x3, %esi
callq 0x5db30
movl $0x0, -0x10c(%rbp)
movq -0x130(%rbp), %rdi
movl -0x10c(%rbp), %eax
movl %eax, -0x1a4(%rbp)
movq (%rdi), %rax
callq *0x178(%rax)
movl %eax, %ecx
movl -0x1a4(%rbp), %eax
cmpl %ecx, %eax
jge 0xbb178
movq -0x130(%rbp), %rdi
movl -0x10c(%rbp), %esi
movq (%rdi), %rax
callq *0x180(%rax)
movq %rax, -0x118(%rbp)
movq -0x118(%rbp), %rdi
movq (%rdi), %rax
callq *0xa8(%rax)
movq %rax, %rdi
xorl %esi, %esi
callq 0x59320
testb $0x1, %al
jne 0xbb11b
jmp 0xbb162
movq -0x118(%rbp), %rdi
callq 0x5a440
movq %rax, %rdi
xorl %esi, %esi
callq 0x5c730
testb $0x1, %al
jne 0xbb137
jmp 0xbb162
movq -0x130(%rbp), %rdi
movq -0x118(%rbp), %rax
movq %rax, -0x1b0(%rbp)
callq 0x5a210
movq -0x1b0(%rbp), %rdi
movl %eax, %esi
subl $0x3, %esi
callq 0x5db30
jmp 0xbb164
movl -0x10c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10c(%rbp)
jmp 0xbb0b2
jmp 0xbb17a
jmp 0xbb17c
movl -0x14(%rbp), %eax
testl %eax, %eax
jne 0xbb30c
jmp 0xbb189
testb $0x1, 0x150630(%rip)    # 0x20b7c0
je 0xbb197
jmp 0xbb30c
movq -0x130(%rbp), %rax
movswl 0xd0(%rax), %eax
cmpl $0x4, %eax
je 0xbb1c1
movq -0x130(%rbp), %rax
movswl 0xd0(%rax), %eax
cmpl $0x8, %eax
jne 0xbb30a
movq -0x130(%rbp), %rax
movswl 0xd0(%rax), %eax
cmpl $0x8, %eax
jne 0xbb1e6
movl -0x64(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x64(%rbp)
movl -0x5c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x5c(%rbp)
movl -0x68(%rbp), %esi
addl $0x1, %esi
movl -0x64(%rbp), %edx
addl $0x2, %edx
leaq -0x120(%rbp), %rdi
callq 0x5c2c0
movl -0x120(%rbp), %esi
movl -0x5c(%rbp), %edx
leaq -0x128(%rbp), %rdi
callq 0x5c2c0
movq -0x50(%rbp), %rdi
callq 0x5a310
movq %rax, %rdi
xorl %esi, %esi
callq 0x5a830
testb $0x1, %al
jne 0xbb22f
jmp 0xbb2b4
movq -0x130(%rbp), %rax
movswl 0xd0(%rax), %eax
cmpl $0x4, %eax
jne 0xbb2b4
movq -0x58(%rbp), %rdi
callq 0x5d470
cwtl
imull $0x12, %eax, %eax
cvtsi2sd %eax, %xmm0
movsd 0xcc265(%rip), %xmm1    # 0x1874c0
divsd %xmm1, %xmm0
callq 0x5a970
movq %rax, %rcx
subq $0x1, %rcx
movslq -0x120(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x120(%rbp)
movq -0x58(%rbp), %rdi
callq 0x5d470
cwtl
imull $0x12, %eax, %eax
cvtsi2sd %eax, %xmm0
movsd 0xcc22c(%rip), %xmm1    # 0x1874c0
divsd %xmm1, %xmm0
callq 0x5a970
movq %rax, %rcx
subq $0x1, %rcx
movslq -0x128(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x128(%rbp)
movq -0x58(%rbp), %rdi
leaq -0x120(%rbp), %rsi
leaq -0x128(%rbp), %rdx
movl $0x2, %ecx
callq 0x5dc90
movl -0x120(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x120(%rbp)
movl -0x128(%rbp), %eax
addl $0x2, %eax
movl %eax, -0x128(%rbp)
movq -0x58(%rbp), %rdi
leaq -0x120(%rbp), %rsi
leaq -0x128(%rbp), %rdx
movl $0x2, %ecx
callq 0x5dc90
jmp 0xbb30c
movq -0x130(%rbp), %rdi
movl -0x14(%rbp), %esi
callq 0x5acb0
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
movq -0x30(%rbp), %rdi
callq 0x5b6b0
nopw %cs:(%rax,%rax)