win32: Add a public clutter_win32_handle_event function

This function handles a single windows message. The idea is that it
could be used by clutter-gtk to forward on events from a
GdkEventFilter. The function replaces the old message_translate()
function. That function didn't translate the event anymore anyway and
instead it could generate multiple events so
clutter_win32_handle_event seems like a more appropriate name. The
function returns TRUE or FALSE depending on whether the event was
completely handled instead of setting call_window_proc.
This commit is contained in:
Neil Roberts 2010-08-27 15:54:21 +01:00
parent 52744c0d9d
commit e66c679e84
3 changed files with 46 additions and 25 deletions

View File

@ -343,10 +343,27 @@ get_key_modifier_state (const BYTE *key_states)
return ret; return ret;
} }
static void /**
message_translate (ClutterBackend *backend, * clutter_win32_handle_event:
const MSG *msg, * @msg: A pointer to a structure describing a Win32 message.
gboolean *call_def_window_proc) *
* This function processes a single Win32 message. It can be used to
* hook into external windows message processing (for example, a GDK
* filter function).
*
* If clutter_win32_disable_event_retrieval() has been called, you must
* let this function process events to update Clutter's internal state.
*
* Return value: %TRUE if the message was handled entirely by Clutter
* and no further processing (such as calling the default window
* procedure) should take place. %FALSE is returned if is the message
* was not handled at all or if Clutter expects processing to take
* place.
*
* Since: 1.6
*/
gboolean
clutter_win32_handle_event (const MSG *msg)
{ {
ClutterBackendWin32 *backend_win32; ClutterBackendWin32 *backend_win32;
ClutterStageWin32 *stage_win32; ClutterStageWin32 *stage_win32;
@ -354,16 +371,17 @@ message_translate (ClutterBackend *backend,
ClutterInputDevice *core_pointer, *core_keyboard; ClutterInputDevice *core_pointer, *core_keyboard;
ClutterStage *stage; ClutterStage *stage;
ClutterStageWindow *impl; ClutterStageWindow *impl;
gboolean return_value = FALSE;
backend_win32 = CLUTTER_BACKEND_WIN32 (backend);
/* Do further processing only on events for the stage window */
stage = clutter_win32_get_stage_from_window (msg->hwnd); stage = clutter_win32_get_stage_from_window (msg->hwnd);
/* Ignore any messages for windows which we don't have a stage for */
if (stage == NULL) if (stage == NULL)
return; return FALSE;
impl = _clutter_stage_get_window (stage); impl = _clutter_stage_get_window (stage);
stage_win32 = CLUTTER_STAGE_WIN32 (impl); stage_win32 = CLUTTER_STAGE_WIN32 (impl);
backend_win32 = stage_win32->backend;
manager = clutter_device_manager_get_default (); manager = clutter_device_manager_get_default ();
core_pointer = core_pointer =
@ -460,8 +478,7 @@ message_translate (ClutterBackend *backend,
/* The default window proc will destroy the window so we want to /* The default window proc will destroy the window so we want to
prevent this to allow applications to optionally destroy the prevent this to allow applications to optionally destroy the
window themselves */ window themselves */
if (call_def_window_proc) return_value = TRUE;
*call_def_window_proc = FALSE;
} }
break; break;
@ -680,8 +697,7 @@ message_translate (ClutterBackend *backend,
{ {
MINMAXINFO *min_max_info = (MINMAXINFO *) msg->lParam; MINMAXINFO *min_max_info = (MINMAXINFO *) msg->lParam;
_clutter_stage_win32_get_min_max_info (stage_win32, min_max_info); _clutter_stage_win32_get_min_max_info (stage_win32, min_max_info);
if (call_def_window_proc) return_value = TRUE;
*call_def_window_proc = FALSE;
} }
break; break;
@ -691,30 +707,32 @@ message_translate (ClutterBackend *backend,
instead */ instead */
if (LOWORD (msg->lParam) == HTCLIENT && !stage_win32->is_cursor_visible) if (LOWORD (msg->lParam) == HTCLIENT && !stage_win32->is_cursor_visible)
{ {
if (call_def_window_proc) return_value = TRUE;
*call_def_window_proc = FALSE;
_clutter_stage_win32_update_cursor (stage_win32); _clutter_stage_win32_update_cursor (stage_win32);
} }
break; break;
} }
return return_value;
} }
LRESULT CALLBACK LRESULT CALLBACK
_clutter_stage_win32_window_proc (HWND hwnd, UINT umsg, _clutter_stage_win32_window_proc (HWND hwnd, UINT umsg,
WPARAM wparam, LPARAM lparam) WPARAM wparam, LPARAM lparam)
{ {
ClutterStageWin32 *stage_win32 gboolean message_handled = FALSE;
= (ClutterStageWin32 *) GetWindowLongPtrW (hwnd, 0);
gboolean call_def_window_proc = TRUE;
/* Ignore any messages before SetWindowLongPtr has been called to /* Windows sends some messages such as WM_GETMINMAXINFO and
set the stage */ WM_CREATE before returning from CreateWindow. The stage point
if (stage_win32 != NULL) will not yet be stored in the Window structure in this case so we
need to skip these messages because we can't know which stage the
window belongs to */
if (GetWindowLongPtrW (hwnd, 0))
{ {
ClutterBackendWin32 *backend_win32 = stage_win32->backend;
MSG msg; MSG msg;
DWORD message_pos = GetMessagePos (); DWORD message_pos = GetMessagePos ();
/* Convert the parameters to a MSG struct */
msg.hwnd = hwnd; msg.hwnd = hwnd;
msg.message = umsg; msg.message = umsg;
msg.wParam = wparam; msg.wParam = wparam;
@ -725,11 +743,11 @@ _clutter_stage_win32_window_proc (HWND hwnd, UINT umsg,
msg.pt.x = (SHORT) LOWORD (message_pos); msg.pt.x = (SHORT) LOWORD (message_pos);
msg.pt.y = (SHORT) HIWORD (message_pos); msg.pt.y = (SHORT) HIWORD (message_pos);
message_translate (CLUTTER_BACKEND (backend_win32), /* Process the message */
&msg, &call_def_window_proc); message_handled = clutter_win32_handle_event (&msg);
} }
if (call_def_window_proc) if (!message_handled)
return DefWindowProcW (hwnd, umsg, wparam, lparam); return DefWindowProcW (hwnd, umsg, wparam, lparam);
else else
return 0; return 0;

View File

@ -51,6 +51,8 @@ gboolean clutter_win32_set_stage_foreign (ClutterStage *stage,
void clutter_win32_disable_event_retrieval (void); void clutter_win32_disable_event_retrieval (void);
gboolean clutter_win32_handle_event (const MSG *msg);
G_END_DECLS G_END_DECLS
#endif /* __CLUTTER_WIN32_H__ */ #endif /* __CLUTTER_WIN32_H__ */

View File

@ -1256,6 +1256,7 @@ clutter_win32_disable_event_retrieval
clutter_win32_set_stage_foreign clutter_win32_set_stage_foreign
clutter_win32_get_stage_from_window clutter_win32_get_stage_from_window
clutter_win32_get_stage_window clutter_win32_get_stage_window
clutter_win32_handle_event
</SECTION> </SECTION>
<SECTION> <SECTION>