1 /* -*- Mode: C; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // -------------------------------------------------------------------------*/
10 #include "lib/scritchui/win32/win32.h"
11 #include "lib/scritchui/win32/win32Intern.h"
13 sjme_errorCode
sjme_scritchui_win32_loopExecuteLater(
14 sjme_attrInNotNull sjme_scritchui inState
,
15 sjme_attrInNotNull sjme_thread_mainFunc callback
,
16 sjme_attrInNullable sjme_thread_parameter anything
)
19 if (inState
== NULL
|| callback
== NULL
)
20 return SJME_ERROR_NULL_ARGUMENTS
;
22 /* Send to the event thread. */
24 if ((result
= PostThreadMessage(
25 inState
->loopThreadId
,
27 (WPARAM
)callback
, (LPARAM
)anything
)) == 0)
28 return inState
->implIntern
->getLastError(inState
,
29 SJME_ERROR_LOOP_ENQUEUE_FAILED
);
32 return SJME_ERROR_NONE
;
35 sjme_errorCode
sjme_scritchui_win32_loopIterate(
36 sjme_attrInNotNull sjme_scritchui inState
,
37 sjme_attrInValue sjme_jboolean blocking
,
38 sjme_attrOutNullable sjme_jboolean
* outHasTerminated
)
44 return SJME_ERROR_NULL_ARGUMENTS
;
46 /* Read next message for the event thread. */
47 memset(&message
, 0, sizeof(message
));
50 /* Wait for the next message. */
51 messageResult
= GetMessage(&message
, NULL
,
55 if (messageResult
== 0)
57 if (outHasTerminated
!= NULL
)
58 *outHasTerminated
= SJME_JNI_TRUE
;
59 return SJME_ERROR_NONE
;
64 /* Grab the next message. */
65 messageResult
= PeekMessage(&message
, NULL
,
69 if (messageResult
== 0)
70 return SJME_ERROR_NONE
;
73 if (message
.message
== WM_QUIT
)
75 if (outHasTerminated
!= NULL
)
76 *outHasTerminated
= SJME_JNI_TRUE
;
77 return SJME_ERROR_NONE
;
81 /* If there is no window, we handle it ourselves. */
82 if (message
.hwnd
== NULL
&& !(message
.message
== WM_TIMER
))
83 return inState
->implIntern
->windowProc(inState
,
84 message
.hwnd
, message
.message
, message
.wParam
, message
.lParam
,
87 /* Otherwise dispatch to a window procedure handler. */
89 TranslateMessage(&message
);
90 DispatchMessage(&message
);
93 return inState
->implIntern
->getLastError(inState
, SJME_ERROR_NONE
);