// File: /workspace/github_c_makefile_star2_O2/enzo1982[P]smooth/classes/gui/window/window.cpp
// Function: smooth::GUI::Window::Process(int, int, int)
S::Int S::GUI::Window::Process(Int message, Int wParam, Int lParam)
{
	if (!created) return MessageUnknown;

	EnterProtectedRegion();

	/* Forward event to subscribers.
	 */
	onEvent.Emit(message, wParam, lParam);

	/* Process events we are interested in.
	 */
	Int	 rVal = MessageUnknown;

	switch (message)
	{
		case SM_GETFOCUS:
			if (!focussed)
			{
				focussed = True;

				onGetFocus.Emit();
			}

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

				if (focusWnd != NIL)
				{
					if (focusWnd->GetObjectType() == ToolWindow::classID && focusWnd->GetOrder() >= GetOrder())
					{
						LeaveProtectedRegion();

						return MessageProcessed;
					}
				}

				focussed = False;

				onLoseFocus.Emit();
			}

			break;
		case SM_WINDOWMETRICS:
			{
				Point	 nPos((unsigned(wParam) >> 16) - 32768, (unsigned(wParam) & 65535) - 32768);
				Size	 nSize((unsigned(lParam) >> 16) - 32768, (unsigned(lParam) & 65535) - 32768);

				Bool	 moved	 = (GetPosition() != nPos);
				Bool	 resized = (GetSize()	  != nSize);

				if (moved || resized)
				{
					DeactivateTooltip();
					InvalidateMetrics();

					if (moved)   { pos  = nPos;  onChangePosition.Emit(pos); }
					if (resized) { size = nSize; onChangeSize.Emit(size);    }

					Bool	 prevVisible = visible;

					visible = False;

					if (resized) { CalculateOffsets(); updateRect = Rect(Point(-1, -1), Size(0, 0)); }

					visible = prevVisible;
				}
			}

			rVal = MessageProcessed;

			break;
		case SM_PAINT:
			{
				Bool	 resized = (updateRect == Rect(Point(-1, -1), Size(0, 0)));

				if (resized) updateRect = Rect(Point(0, 0), GetRealSize());
				else	     updateRect = backend->GetUpdateRect();

				Paint(resized ? SP_PAINT : SP_UPDATE);

				updateRect = Rect(Point(0, 0), GetRealSize());
			}

			rVal = MessageProcessed;

			break;
	}

	if (rVal != MessageUnknown)
	{
		LeaveProtectedRegion();

		return rVal;
	}

	/* Delegate event to main layer.
	 */
	if (mainLayer->Process(message, wParam, lParam) == MessageProcessed)
	{
		LeaveProtectedRegion();

		return MessageProcessed;
	}

	/* Delegate event to other widgets.
	 */
	for (Int i = GetNOfObjects() - 1; i >= 0; i--)
	{
		Widget	*object = GetNthObject(i);

		if (object == NIL || object == mainLayer) continue;

		if (object->Process(message, wParam, lParam) == MessageProcessed)
		{
			rVal = MessageProcessed;

			break;
		}
	}

	/* Invoke callback for application message handling.
	 */
	if (rVal == MessageUnknown) rVal = handleSystemMessage.Call(message, wParam, lParam);

	LeaveProtectedRegion();

	return rVal;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
cmpb $0x1, 0x5ca(%rdi)
jne 0x94b9d
movl %ecx, %r15d
movl %edx, %r12d
movl %esi, %r13d
movq %rdi, %r14
leaq 0x1c(%rdi), %rbp
movq %rbp, %rdi
callq 0x58b40
leaq 0x668(%r14), %rdi
movl %r13d, %esi
movl %r12d, %edx
movl %r15d, %ecx
callq 0x95af8
leal -0x780d(%r13), %eax
cmpl $0x6, %eax
ja 0x94d2a
leaq 0x524cf(%rip), %rcx     # 0xe7010
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x5ec(%r14), %r15
pcmpeqd %xmm0, %xmm0
leaq 0x10(%rsp), %rsi
movdqa %xmm0, (%rsi)
movq %r15, %rdi
callq 0x58d60
movl %eax, %ebx
testb %al, %al
movq %rbp, 0x8(%rsp)
je 0x94dba
movq (%r14), %rax
movq %r14, %rdi
callq *0x50(%rax)
andq $0x0, 0x5ec(%r14)
movl %eax, 0x5f4(%r14)
shrq $0x20, %rax
movl %eax, 0x5f8(%r14)
jmp 0x94dcf
pushq $-0x2
jmp 0x94e20
cmpb $0x0, 0xcd(%r14)
jne 0x94d2a
movb $0x1, 0xcd(%r14)
movl $0x4d8, %edi            # imm = 0x4D8
jmp 0x94d22
movq %rbp, 0x8(%rsp)
movl %r12d, %ebp
shrl $0x10, %ebp
movl $0xffff8000, %eax       # imm = 0xFFFF8000
addl %eax, %ebp
movl $0xffff, %ecx           # imm = 0xFFFF
andl %ecx, %r12d
addl %eax, %r12d
movl %r15d, %ebx
shrl $0x10, %ebx
addl %eax, %ebx
andl %ecx, %r15d
addl %eax, %r15d
movl 0xa8(%r14), %eax
xorl %ebp, %eax
movl 0xac(%r14), %ecx
xorl %r12d, %ecx
movl 0xb0(%r14), %edx
xorl %ebx, %edx
movl 0xb4(%r14), %esi
xorl %r15d, %esi
orl %edx, %esi
setne %dl
orl %eax, %ecx
setne %r13b
jne 0x94c2a
testb %dl, %dl
je 0x94e14
movb %dl, 0x7(%rsp)
movq %r14, %rdi
callq 0x5a590
movq %r14, %rdi
callq 0x59a30
testb %r13b, %r13b
je 0x94c66
leaq 0xa8(%r14), %rsi
shlq $0x20, %r12
movl %ebp, %eax
orq %r12, %rax
movq %rax, 0xa8(%r14)
leaq 0x278(%r14), %rdi
callq 0x70356
cmpb $0x0, 0x7(%rsp)
je 0x94e03
leaq 0xb0(%r14), %rsi
shlq $0x20, %r15
movl %ebx, %eax
orq %r15, %rax
movq %rax, 0xb0(%r14)
leaq 0x298(%r14), %rdi
callq 0x705b8
leaq 0xcb(%r14), %r15
movb 0xcb(%r14), %bl
movb $0x0, 0xcb(%r14)
movq %r14, %rdi
callq 0x56fc0
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0x5ec(%r14)
movq %r15, %r14
jmp 0x94e11
cmpb $0x1, 0xcd(%r14)
jne 0x94d2a
movq 0xccb50(%rip), %rax     # 0x161828
movswl (%rax), %esi
movl %r12d, %edi
callq 0x58940
testq %rax, %rax
je 0x94d15
movq %rax, %rbx
leaq 0x20(%rax), %rdi
movq 0xccfe2(%rip), %rax     # 0x161cd8
movswl (%rax), %esi
callq 0x58720
testb %al, %al
je 0x94d15
movl 0x5b8(%rbx), %eax
cmpl 0x5b8(%r14), %eax
jge 0x94db5
movb $0x0, 0xcd(%r14)
movl $0x518, %edi            # imm = 0x518
addq %r14, %rdi
callq 0x70196
movq 0x620(%r14), %rdi
movq (%rdi), %rax
movl %r13d, %esi
movl %r12d, %edx
movl %r15d, %ecx
callq *0x80(%rax)
cmpl $-0x1, %eax
je 0x94db5
movq %rbp, 0x8(%rsp)
movl 0x40(%r14), %ebx
pushq $-0x1
popq %rbp
testl %ebx, %ebx
jle 0x94d8f
decl %ebx
movq %r14, %rdi
movl %ebx, %esi
callq 0x58c90
testq %rax, %rax
je 0x94d54
cmpq 0x620(%r14), %rax
je 0x94d54
movq (%rax), %r8
movq %rax, %rdi
movl %r13d, %esi
movl %r12d, %edx
movl %r15d, %ecx
callq *0x80(%r8)
cmpl $-0x1, %eax
jne 0x94d54
jmp 0x94da9
addq $0x6b0, %r14            # imm = 0x6B0
movq %r14, %rdi
movl %r13d, %esi
movl %r12d, %edx
movl %r15d, %ecx
callq 0x961b8
movl %eax, %ebp
movq 0x8(%rsp), %rdi
callq 0x56d60
jmp 0x94e21
movq %rbp, %rdi
jmp 0x94e19
movq 0x5c0(%r14), %rdi
callq 0x96566
movdqu (%rax), %xmm0
movdqu %xmm0, (%r15)
xorb $0x1, %bl
movzbl %bl, %esi
movq (%r14), %rax
movq %r14, %rdi
callq *0x78(%rax)
movq (%r14), %rax
movq %r14, %rdi
callq *0x50(%rax)
andq $0x0, 0x5ec(%r14)
movl %eax, 0x5f4(%r14)
shrq $0x20, %rax
movl %eax, 0x5f8(%r14)
jmp 0x94e14
movb 0xcb(%r14), %bl
addq $0xcb, %r14
movb %bl, (%r14)
movq 0x8(%rsp), %rdi
callq 0x56d60
pushq $-0x1
popq %rbp
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq