// File: /workspace/github_c_makefile_star2_O1/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 $0x18, %rsp
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
cmpb $0x1, 0x5ca(%rdi)
jne 0x99329
movl %ecx, %ebp
movl %edx, %r12d
movl %esi, %r13d
movq %rdi, %r14
leaq 0x1c(%rdi), %r15
movq %r15, %rdi
callq 0x578f0
leaq 0x668(%r14), %rdi
movl %r13d, %esi
movl %r12d, %edx
movl %ebp, %ecx
callq 0x9a028
leal -0x780d(%r13), %eax
cmpl $0x6, %eax
ja 0x9915b
leaq 0x5ef7a(%rip), %rcx     # 0xf7f6c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %ebx, %ebx
cmpl $-0x1, 0x5ec(%r14)
jne 0x99026
cmpl $-0x1, 0x5f0(%r14)
jne 0x99026
cmpl $-0x1, 0x5f4(%r14)
jne 0x99026
cmpl $-0x1, 0x5f8(%r14)
sete %bl
testb %bl, %bl
je 0x992c5
movq (%r14), %rax
movq %r14, %rdi
callq *0x50(%rax)
movq $0x0, 0x5ec(%r14)
movl %eax, 0x5f4(%r14)
shrq $0x20, %rax
movl %eax, 0x5f8(%r14)
jmp 0x992e7
cmpb $0x0, 0xcd(%r14)
jne 0x9915b
movb $0x1, 0xcd(%r14)
movl $0x4d8, %edi            # imm = 0x4D8
jmp 0x99153
movq %r15, 0x8(%rsp)
movl %r12d, %r15d
shrl $0x10, %r15d
movl $0xffff8000, %eax       # imm = 0xFFFF8000
addl %eax, %r15d
movl $0xffff, %ecx           # imm = 0xFFFF
andl %ecx, %r12d
addl %eax, %r12d
movl %ebp, %ebx
shrl $0x10, %ebx
addl %eax, %ebx
andl %ecx, %ebp
addl %eax, %ebp
movl 0xa8(%r14), %eax
xorl %r15d, %eax
movl 0xac(%r14), %ecx
xorl %r12d, %ecx
movl 0xb0(%r14), %edx
xorl %ebx, %edx
movl 0xb4(%r14), %esi
movq %rbp, 0x10(%rsp)
xorl %ebp, %esi
orl %edx, %esi
setne %bpl
orl %eax, %ecx
setne %r13b
jne 0x99228
testb %bpl, %bpl
jne 0x99228
movq 0x8(%rsp), %r15
jmp 0x9931c
cmpb $0x1, 0xcd(%r14)
jne 0x9915b
movq 0xd3724(%rip), %rax     # 0x16c828
movswl (%rax), %esi
movl %r12d, %edi
callq 0x57710
testq %rax, %rax
je 0x99146
movq %rax, %rbx
leaq 0x20(%rax), %rdi
movq 0xd3bb6(%rip), %rax     # 0x16ccd8
movswl (%rax), %esi
callq 0x57520
testb %al, %al
je 0x99146
movl 0x5b8(%rbx), %eax
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl 0x5b8(%r14), %eax
jge 0x99321
movb $0x0, 0xcd(%r14)
movl $0x518, %edi            # imm = 0x518
addq %r14, %rdi
callq 0x70488
movq 0x620(%r14), %rdi
movq (%rdi), %rax
movl %r13d, %esi
movl %r12d, %edx
movl %ebp, %ecx
callq *0x80(%rax)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
cmpl $-0x1, %eax
je 0x99321
movq %rbp, 0x10(%rsp)
movl 0x40(%r14), %ebp
testl %ebp, %ebp
jle 0x99207
movq %r15, 0x8(%rsp)
leaq 0x38(%r14), %rbx
incl %ebp
movl $0xfffffffe, %r15d      # imm = 0xFFFFFFFE
leal -0x2(%rbp), %esi
movq %rbx, %rdi
callq 0x5b0a4
movq (%rax), %rdi
movl $0x5, %ecx
testq %rdi, %rdi
je 0x991e3
cmpq 0x620(%r14), %rdi
je 0x991e3
movq (%rdi), %rax
movl %r13d, %esi
movl %r12d, %edx
movq 0x10(%rsp), %rcx
callq *0x80(%rax)
xorl %ecx, %ecx
cmpl $-0x1, %eax
sete %cl
leal (%rcx,%rcx,2), %ecx
cmovel %eax, %r15d
cmpl $0x5, %ecx
je 0x991ec
testl %ecx, %ecx
jne 0x991f3
decl %ebp
cmpl $0x1, %ebp
jg 0x9919f
cmpl $-0x2, %r15d
movq 0x8(%rsp), %r15
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
jne 0x99321
addq $0x6b0, %r14            # imm = 0x6B0
movq %r14, %rdi
movl %r13d, %esi
movl %r12d, %edx
movq 0x10(%rsp), %rcx
callq 0x9a86a
movl %eax, %ebx
jmp 0x99321
movq %r14, %rdi
callq 0x59208
movq %r14, %rdi
callq 0x58740
testb %r13b, %r13b
je 0x99261
leaq 0xa8(%r14), %rsi
shlq $0x20, %r12
movl %r15d, %eax
orq %r12, %rax
movq %rax, 0xa8(%r14)
leaq 0x278(%r14), %rdi
callq 0x70676
testb %bpl, %bpl
je 0x9928e
leaq 0xb0(%r14), %rsi
movq 0x10(%rsp), %rcx
shlq $0x20, %rcx
movl %ebx, %eax
orq %rcx, %rax
movq %rax, 0xb0(%r14)
leaq 0x298(%r14), %rdi
callq 0x7094c
movb 0xcb(%r14), %bl
movb $0x0, 0xcb(%r14)
testb %bpl, %bpl
movq 0x8(%rsp), %r15
je 0x992bc
movq %r14, %rdi
callq 0x55ef0
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0x5ec(%r14)
movb %bl, 0xcb(%r14)
jmp 0x9931c
movq %r15, %r12
leaq 0x5ec(%r14), %r15
movq 0x5c0(%r14), %rdi
callq 0x9acee
movdqu (%rax), %xmm0
movdqu %xmm0, (%r15)
movq %r12, %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)
movq $0x0, 0x5ec(%r14)
movl %eax, 0x5f4(%r14)
shrq $0x20, %rax
movl %eax, 0x5f8(%r14)
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq %r15, %rdi
callq 0x55cc0
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq