// File: /workspace/github_c_makefile_star2_O3/enzo1982[P]smooth/classes/gui/widgets/widget.cpp
// Function: smooth::GUI::Widget::Process(int, int, int)
S::Int S::GUI::Widget::Process(Int message, Int wParam, Int lParam)
{
	if (!IsRegistered()) return Error();
	if (!IsVisible())    return Success();

	Window	*window	= container->GetContainerWindow();

	if (window == NIL)   return Success();

	widgets.LockForWrite();

	foreach (Widget *widget, widgets)
	{
		if (widget->Process(message, wParam, lParam) == MessageProcessed) { widgets.Unlock(); return MessageProcessed; }
	}

	widgets.Unlock();

	if (!IsVisible())    return Success();
	if (!IsActive())     return Success();

	EnterProtectedRegion();

	Int	 returnValue = Success();
	Point	 mousePos    = window->GetMousePosition();

	switch (message)
	{
		case SM_MOUSEMOVE:
			{
				Point	 realPosition = GetRealPosition();
				Rect	 visibleArea  = GetVisibleArea();

				if (!mouseOver && window->IsMouseOn(visibleArea) && hitTest.Call(mousePos - realPosition))
				{
					mouseOver = True;

					if (statusText != NIL) window->SetStatusText(statusText);

					if ((tooltipText != NIL || tooltipLayer != NIL) && window->IsFocussed())
					{
						Application::Lock	 lock;

						tipPos	 = mousePos;
						tipTimer = new System::Timer();

						tipTimer->onInterval.Connect(&Widget::ActivateTooltip, this);
						tipTimer->Start(Setup::HoverTime);
					}

					Paint(SP_MOUSEIN);

					onMouseOver.Emit();
				}
				else if (mouseOver && !(window->IsMouseOn(visibleArea) && hitTest.Call(mousePos - realPosition)))
				{
					mouseOver = False;

					leftButtonDown	= False;
					rightButtonDown	= False;

					if (statusText != NIL && window->GetStatusText() == statusText) window->RestoreDefaultStatusText();

					DeactivateTooltip();

					Paint(SP_MOUSEOUT);

					onMouseOut.Emit();
				}
				else if (mouseOver && window->IsMouseOn(visibleArea) && hitTest.Call(mousePos - realPosition))
				{
					Application::Lock	 lock;

					if (tipTimer != NIL && wParam == 0 && (Math::Abs(tipPos.x - mousePos.x) > Setup::HoverWidth / 2 || Math::Abs(tipPos.y - mousePos.y) > Setup::HoverHeight / 2))
					{
						tipPos = mousePos;

						tipTimer->Stop();
						tipTimer->Start(Setup::HoverTime);
					}
				}
			}

			if (mouseDragging)
			{
				onMouseDrag.Emit(mousePos);
			}

			break;
		case SM_LBUTTONDOWN:
			if (mouseOver)
			{
				leftButtonDown = True;

				DeactivateTooltip();

				Paint(SP_MOUSEDOWN);

				if (!focussed)
				{
					focussed = True;

					onGetFocus.Emit();
				}
				else
				{
					onClickInFocus.Emit();
				}

				onLeftButtonDown.Emit(mousePos);

				if (!mouseDragging)
				{
					mouseDragging = True;

					onMouseDragStart.Emit(mousePos);
				}
			}
			else
			{
				if (focussed)
				{
					focussed = False;

					onLoseFocus.Emit();
				}
			}

			break;
		case SM_LBUTTONDBLCLK:
			if (mouseOver)
			{
				leftButtonDown = True;

				Paint(SP_MOUSEDOWN);

				onLeftButtonDown.Emit(mousePos);
				onLeftButtonDoubleClick.Emit(mousePos);
			}

			break;
		case SM_LBUTTONUP:
			if (mouseOver)
			{
				Paint(SP_MOUSEUP);

				onLeftButtonUp.Emit(mousePos);

				if (leftButtonDown)
				{
					leftButtonDown = False;

					onLeftButtonClick.Emit(mousePos);
				}
			}

			if (mouseDragging)
			{
				mouseDragging = False;

				onMouseDragEnd.Emit(mousePos);
			}

			break;
		case SM_RBUTTONDOWN:
		case SM_RBUTTONDBLCLK:
			if (mouseOver)
			{
				OpenContextMenu();

				/* Force mouseOut event.
				 */
				window->Process(SM_MOUSEMOVE, 0, 0);
			}

			break;
		case SM_MOUSEWHEEL:
			{
				UnsignedInt	 scrollLines = 0;

#ifdef __WIN32__
				SystemParametersInfo(104, NIL, &scrollLines, NIL);
#endif

				if (scrollLines <= 0) scrollLines = 3;

				onMouseWheel.Emit(Float(wParam) / 120.0 * scrollLines);
			}

			break;
		case SM_KEYDOWN:
			if (!focussed || !tabstopCapable) break;

			if (wParam == Input::Keyboard::KeyTab)
			{
				Widget	*widget = NIL;

				if (Input::Keyboard::GetKeyState(Input::Keyboard::KeyShift)) widget = container->GetPreviousTabstopWidget(GetHandle());
				else							     widget = container->GetNextTabstopWidget(GetHandle());

				if (widget != NIL)
				{
					focussed = False;

					onLoseFocus.Emit();

					widget->SetFocusByKeyboard();
				}

				returnValue = MessageProcessed;
			}

			break;
		case SM_LOSEFOCUS:
			if (focussed)
			{
				Window	*focusWnd = (Window *) Object::GetObject(wParam, Window::classID);

				if (focusWnd != NIL)
				{
					if ((focusWnd->GetObjectType() == ToolWindow::classID && focusWnd->GetOrder() >= window->GetOrder()) || focusWnd == window) break;
				}

				focussed = False;

				onLoseFocus.Emit();
			}

			break;
	}

	LeaveProtectedRegion();

	return returnValue;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, %ebx
movl %edx, 0x14(%rsp)
movl %esi, %r13d
movq %rdi, %r14
movq (%rdi), %rax
callq *0x88(%rax)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testb %al, %al
je 0x6f50b
movq (%r14), %rax
movq %r14, %rdi
callq *0x90(%rax)
xorl %ebp, %ebp
testb %al, %al
je 0x6f50b
movq 0x190(%r14), %r12
movq 0xfca7a(%rip), %rax     # 0x16b828
movswl (%rax), %r15d
leaq 0x20(%r12), %rdi
movl %r15d, %esi
callq 0x57520
testb %al, %al
jne 0x6edd5
movq 0x190(%r12), %r12
testq %r12, %r12
jne 0x6edb2
jmp 0x6f50b
testq %r12, %r12
je 0x6f50b
cmpb $0x1, 0x68(%r14)
jne 0x6edee
movq 0x70(%r14), %rdi
callq 0x551d0
movq %r14, 0x18(%rsp)
cmpl $0x0, 0x40(%r14)
jle 0x6ee44
movq 0x18(%rsp), %rax
leaq 0x38(%rax), %rbp
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
incl %r14d
movq %rbp, %rdi
movl %r14d, %esi
callq 0x60a9a
movq (%rax), %rdi
movq (%rdi), %rax
movl %r13d, %esi
movl 0x14(%rsp), %edx
movl %ebx, %ecx
callq *0x80(%rax)
cmpl $-0x1, %eax
je 0x6eef5
movq 0x18(%rsp), %rax
movl 0x40(%rax), %eax
decl %eax
cmpl %eax, %r14d
jl 0x6ee09
movq 0x18(%rsp), %r14
cmpb $0x1, 0x68(%r14)
jne 0x6ee59
movq 0x70(%r14), %rdi
callq 0x55910
movq (%r14), %rax
movq %r14, %rdi
callq *0x90(%rax)
testb %al, %al
movl $0x0, %ebp
je 0x6f50b
movq (%r14), %rax
movq %r14, %rdi
callq *0x98(%rax)
testb %al, %al
je 0x6f50b
leaq 0x1c(%r14), %rbx
movq %rbx, %rdi
callq 0x578f0
movq %r12, %rdi
callq 0x56b50
movq %rax, 0x8(%rsp)
xorl %ebp, %ebp
addl $0xffff8800, %r13d      # imm = 0xFFFF8800
cmpl $0x13, %r13d
ja 0x6f503
leaq 0x86937(%rip), %rax     # 0xf57f0
movslq (%rax,%r13,4), %rcx
addq %rax, %rcx
jmpq *%rcx
cmpb $0x1, 0xd4(%r14)
jne 0x6f503
movq %r14, %rdi
callq 0x56b90
movq (%r12), %rax
xorl %ebp, %ebp
movq %r12, %rdi
movl $0x7800, %esi           # imm = 0x7800
xorl %edx, %edx
xorl %ecx, %ecx
callq *0x80(%rax)
jmp 0x6f503
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq 0x18(%rsp), %rax
cmpb $0x1, 0x68(%rax)
jne 0x6f50b
movq 0x70(%rax), %rdi
callq 0x55910
jmp 0x6f50b
cmpb $0x1, 0xd4(%r14)
jne 0x6ef63
movq (%r14), %rax
movq %r14, %rdi
movl $0x5, %esi
callq *0x78(%rax)
leaq 0x318(%r14), %rdi
leaq 0x8(%rsp), %rsi
callq 0x703b0
cmpb $0x1, 0xd5(%r14)
jne 0x6ef63
movb $0x0, 0xd5(%r14)
leaq 0x338(%r14), %rdi
leaq 0x8(%rsp), %rsi
callq 0x703b0
cmpb $0x1, 0xd7(%r14)
jne 0x6f503
movb $0x0, 0xd7(%r14)
addq $0x438, %r14            # imm = 0x438
jmp 0x6f49f
addq $0x458, %r14            # imm = 0x458
cvtsi2sdl 0x14(%rsp), %xmm0
divsd 0x86846(%rip), %xmm0    # 0xf57e0
mulsd 0x84616(%rip), %xmm0    # 0xf35b8
movq %r14, %rdi
callq 0x70454
jmp 0x6f503
cmpb $0x1, 0xcd(%r14)
jne 0x6f503
cmpl $0x9, 0x14(%rsp)
jne 0x6f503
cmpb $0x0, 0xd2(%r14)
je 0x6f503
movq %rbx, %r15
movl $0x10, %edi
callq 0x57510
movq 0x190(%r14), %rdi
movl 0x8(%r14), %esi
testb %al, %al
je 0x6f4cf
callq 0x57d00
jmp 0x6f4d4
movq %rbx, %r13
movq (%r14), %rax
movq %r14, %rdi
callq *0x48(%rax)
movq %rax, %r15
movq %rax, %rbx
shrq $0x20, %rbx
movq (%r14), %rax
movq %r14, %rdi
callq *0x130(%rax)
movq %rax, 0x28(%rsp)
movq %rdx, 0x30(%rsp)
cmpb $0x0, 0xd4(%r14)
jne 0x6f293
leaq 0x28(%rsp), %rsi
movq %r12, %rdi
callq 0x578a0
testb %al, %al
je 0x6f293
leaq 0x1a8(%r14), %rdi
movl 0x8(%rsp), %eax
movl 0xc(%rsp), %ecx
subl %r15d, %eax
subl %ebx, %ecx
shlq $0x20, %rcx
orq %rcx, %rax
leaq 0x20(%rsp), %rsi
movq %rax, (%rsi)
callq 0x7119c
testb %al, %al
je 0x6f293
movb $0x1, 0xd4(%r14)
leaq 0x108(%r14), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x56bd0
testb %al, %al
je 0x6f0ac
movq (%r12), %rax
movq %r12, %rdi
movq %rbx, %rsi
callq *0xd0(%rax)
leaq 0x120(%r14), %rdi
xorl %esi, %esi
callq 0x56bd0
testb %al, %al
jne 0x6f0c8
cmpq $0x0, 0x138(%r14)
je 0x6f140
cmpb $0x1, 0xcd(%r12)
jne 0x6f140
callq 0x55420
movq 0x8(%rsp), %rax
movq %rax, 0x98(%r14)
movl $0x68, %edi
callq 0x556b0
movq %rax, %r14
movq %rax, %rdi
callq 0x55b80
movq 0x18(%rsp), %rcx
movq %r14, 0xa0(%rcx)
addq $0x48, %r14
movq 0xfc728(%rip), %rsi     # 0x16b838
movq %r14, %rdi
xorl %edx, %edx
callq 0x702f0
movq 0x18(%rsp), %rax
movq 0xa0(%rax), %rdi
movq 0xfcb43(%rip), %rax     # 0x16bc70
movl (%rax), %esi
callq 0x55100
callq 0x56e90
xorl %ebp, %ebp
movq 0x18(%rsp), %r14
movq (%r14), %rax
movq %r14, %rdi
movl $0x2, %esi
callq *0x78(%rax)
leaq 0x2b8(%r14), %rdi
jmp 0x6f486
cmpb $0x1, 0xd4(%r14)
jne 0x6f3f4
movb $0x1, 0xd5(%r14)
movq %r14, %rdi
callq 0x59208
movq (%r14), %rax
movq %r14, %rdi
movl $0x4, %esi
callq *0x78(%rax)
movl $0x538, %edi            # imm = 0x538
cmpb $0x0, 0xcd(%r14)
jne 0x6f1a2
movb $0x1, 0xcd(%r14)
movl $0x4d8, %edi            # imm = 0x4D8
addq %r14, %rdi
callq 0x701aa
leaq 0x2f8(%r14), %rdi
leaq 0x8(%rsp), %rsi
callq 0x703b0
cmpb $0x0, 0xd7(%r14)
jne 0x6f503
movb $0x1, 0xd7(%r14)
addq $0x3f8, %r14            # imm = 0x3F8
jmp 0x6f49f
cmpb $0x1, 0xcd(%r14)
jne 0x6f503
movq %rbx, %r13
movl 0x14(%rsp), %edi
movl %r15d, %esi
callq 0x57710
testq %rax, %rax
je 0x6f4b3
movq %rax, %rbx
leaq 0x20(%rax), %rdi
movq 0xfcac7(%rip), %rax     # 0x16bcd8
movswl (%rax), %esi
callq 0x57520
testb %al, %al
je 0x6f4ae
cmpq %r12, %rbx
je 0x6f4ca
movl 0x5b8(%r12), %eax
cmpl %eax, 0x5b8(%rbx)
jl 0x6f4b3
jmp 0x6f4ca
cmpb $0x1, 0xd4(%r14)
jne 0x6f503
movb $0x1, 0xd5(%r14)
movq (%r14), %rax
movq %r14, %rdi
movl $0x4, %esi
callq *0x78(%rax)
leaq 0x2f8(%r14), %rdi
movq %rbx, %r15
leaq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x703b0
addq $0x358, %r14            # imm = 0x358
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rbx
jmp 0x6f4a7
movb 0xd4(%r14), %al
cmpb $0x1, %al
jne 0x6f2ea
leaq 0x28(%rsp), %rsi
movq %r12, %rdi
callq 0x578a0
testb %al, %al
je 0x6f41e
leaq 0x1a8(%r14), %rdi
movl 0x8(%rsp), %eax
movl 0xc(%rsp), %ecx
subl %r15d, %eax
subl %ebx, %ecx
shlq $0x20, %rcx
orq %rcx, %rax
leaq 0x20(%rsp), %rsi
movq %rax, (%rsi)
callq 0x7119c
testb %al, %al
je 0x6f41e
movb 0xd4(%r14), %al
testb $0x1, %al
je 0x6f48b
leaq 0x28(%rsp), %rsi
movq %r12, %rdi
callq 0x578a0
testb %al, %al
je 0x6f48b
leaq 0x1a8(%r14), %rdi
movl 0x8(%rsp), %eax
movl 0xc(%rsp), %ecx
subl %r15d, %eax
subl %ebx, %ecx
shlq $0x20, %rcx
orq %rcx, %rax
leaq 0x20(%rsp), %rsi
movq %rax, (%rsi)
callq 0x7119c
testb %al, %al
movq %r13, %rbx
je 0x6f48e
callq 0x55420
movq 0xa0(%r14), %rdi
testq %rdi, %rdi
sete %al
cmpl $0x0, 0x14(%rsp)
setne %cl
orb %al, %cl
jne 0x6f3ea
movl 0x98(%r14), %ecx
movl 0x8(%rsp), %edx
movl %ecx, %esi
subl %edx, %esi
sarl $0x1f, %esi
orl $0x1, %esi
xorl %eax, %eax
subl %edx, %ecx
cmovel %eax, %esi
imull %ecx, %esi
movq 0xfc696(%rip), %rcx     # 0x16ba18
movl (%rcx), %ecx
movl %ecx, %edx
shrl $0x1f, %edx
addl %ecx, %edx
sarl %edx
cmpl %edx, %esi
jg 0x6f3c4
movl 0x9c(%r14), %ecx
movl 0xc(%rsp), %edx
movl %ecx, %esi
subl %edx, %esi
sarl $0x1f, %esi
orl $0x1, %esi
subl %edx, %ecx
cmovel %eax, %esi
imull %ecx, %esi
movq 0xfcb43(%rip), %rax     # 0x16bef8
movl (%rax), %eax
movl %eax, %ecx
shrl $0x1f, %ecx
addl %eax, %ecx
sarl %ecx
cmpl %ecx, %esi
jle 0x6f3ea
movq 0x8(%rsp), %rax
movq %rax, 0x98(%r14)
callq 0x59190
movq 0xa0(%r14), %rdi
movq 0xfc88d(%rip), %rax     # 0x16bc70
movl (%rax), %esi
callq 0x55100
callq 0x56e90
jmp 0x6f48e
cmpb $0x1, 0xcd(%r14)
jne 0x6f503
movb $0x0, 0xcd(%r14)
addq $0x518, %r14            # imm = 0x518
movq %r14, %rdi
callq 0x701aa
jmp 0x6f503
movw $0x0, 0xd4(%r14)
movb $0x0, 0xd6(%r14)
leaq 0x108(%r14), %rbx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x56bd0
testb %al, %al
je 0x6f469
movq (%r12), %rax
movq %r12, %rdi
callq *0xd8(%rax)
movq %rax, %rdi
movq %rbx, %rsi
callq 0x55900
testb %al, %al
je 0x6f469
movq %r12, %rdi
callq 0x55de0
movq %r14, %rdi
callq 0x59208
movq (%r14), %rax
movq %r14, %rdi
movl $0x3, %esi
callq *0x78(%rax)
leaq 0x2d8(%r14), %rdi
callq 0x701aa
movq %r13, %rbx
cmpb $0x1, 0xd7(%r14)
jne 0x6f503
addq $0x418, %r14            # imm = 0x418
leaq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x703b0
jmp 0x6f503
cmpq %r12, %rbx
je 0x6f4ca
movb $0x0, 0xcd(%r14)
addq $0x518, %r14            # imm = 0x518
movq %r14, %rdi
callq 0x701aa
movq %r13, %rbx
jmp 0x6f503
callq 0x55fe0
movq %rax, %rbx
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x6f500
movb $0x0, 0xcd(%r14)
addq $0x518, %r14            # imm = 0x518
movq %r14, %rdi
callq 0x701aa
movq %rbx, %rdi
callq 0x56210
movq %r15, %rbx
movq %rbx, %rdi
callq 0x55cc0
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6f54e
movq %rax, %rbx
movl $0x68, %esi
movq %r14, %rdi
callq 0x55480
jmp 0x6f541
movq %rax, %rbx
callq 0x56e90
jmp 0x6f546
jmp 0x6f54e
jmp 0x6f54e
movq %rax, %rbx
callq 0x56e90
movq %rbx, %rdi
callq 0x57090
movq %rax, %rdi
callq 0x5aeae