Authors: Martin Fuchs <martin-fuchs@gmx.net>, Ge van Geldorp <gvg@reactos.com>
[wine/multimedia.git] / windows / queue.c
blob6ac649ee5bb25f61ad251a7d69b06a2770309345
1 /*
2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "config.h"
22 #include "wine/port.h"
24 #include <stdarg.h>
25 #include <string.h>
26 #include <signal.h>
27 #include <assert.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winerror.h"
32 #include "wine/winbase16.h"
33 #include "wine/winuser16.h"
34 #include "message.h"
35 #include "win.h"
36 #include "user.h"
37 #include "thread.h"
38 #include "wine/debug.h"
39 #include "wine/server.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msg);
44 /***********************************************************************
45 * QUEUE_CreateMsgQueue
47 * Creates a message queue. Doesn't link it into queue list!
49 static HQUEUE16 QUEUE_CreateMsgQueue(void)
51 HQUEUE16 hQueue;
52 HANDLE handle;
53 MESSAGEQUEUE * msgQueue;
55 TRACE_(msg)("(): Creating message queue...\n");
57 if (!(hQueue = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT,
58 sizeof(MESSAGEQUEUE) )))
59 return 0;
61 msgQueue = (MESSAGEQUEUE *) GlobalLock16( hQueue );
62 if ( !msgQueue )
63 return 0;
65 SERVER_START_REQ( get_msg_queue )
67 wine_server_call_err( req );
68 handle = reply->handle;
70 SERVER_END_REQ;
71 if (!handle)
73 ERR_(msg)("Cannot get thread queue\n");
74 GlobalFree16( hQueue );
75 return 0;
77 msgQueue->server_queue = handle;
78 msgQueue->self = hQueue;
79 return hQueue;
83 /***********************************************************************
84 * QUEUE_Current
86 * Get the current thread queue, creating it if required.
87 * QUEUE_Unlock is not needed since the queue can only be deleted by
88 * the current thread anyway.
90 MESSAGEQUEUE *QUEUE_Current(void)
92 HQUEUE16 hQueue = NtCurrentTeb()->queue;
94 if (!hQueue)
96 if (!(hQueue = QUEUE_CreateMsgQueue())) return NULL;
97 SetThreadQueue16( 0, hQueue );
100 return GlobalLock16( hQueue );
105 /***********************************************************************
106 * QUEUE_DeleteMsgQueue
108 * Delete a message queue.
110 void QUEUE_DeleteMsgQueue(void)
112 HQUEUE16 hQueue = NtCurrentTeb()->queue;
113 MESSAGEQUEUE * msgQueue;
115 if (!hQueue) return; /* thread doesn't have a queue */
117 TRACE("(): Deleting message queue %04x\n", hQueue);
119 if (!(msgQueue = GlobalLock16( hQueue )))
121 ERR("invalid thread queue\n");
122 return;
125 SetThreadQueue16( 0, 0 );
126 CloseHandle( msgQueue->server_queue );
127 GlobalFree16( hQueue );
131 /***********************************************************************
132 * InitThreadInput (USER.409)
134 HQUEUE16 WINAPI InitThreadInput16( WORD unknown, WORD flags )
136 MESSAGEQUEUE *queue = QUEUE_Current();
137 return queue ? queue->self : 0;
140 /***********************************************************************
141 * GetQueueStatus (USER32.@)
143 DWORD WINAPI GetQueueStatus( UINT flags )
145 DWORD ret = 0;
147 /* check for pending X events */
148 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
149 USER_Driver.pMsgWaitForMultipleObjectsEx( 0, NULL, 0, 0, 0 );
151 SERVER_START_REQ( get_queue_status )
153 req->clear = 1;
154 wine_server_call( req );
155 ret = MAKELONG( reply->changed_bits & flags, reply->wake_bits & flags );
157 SERVER_END_REQ;
158 return ret;
162 /***********************************************************************
163 * GetInputState (USER32.@)
165 BOOL WINAPI GetInputState(void)
167 DWORD ret = 0;
169 /* check for pending X events */
170 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
171 USER_Driver.pMsgWaitForMultipleObjectsEx( 0, NULL, 0, 0, 0 );
173 SERVER_START_REQ( get_queue_status )
175 req->clear = 0;
176 wine_server_call( req );
177 ret = reply->wake_bits & (QS_KEY | QS_MOUSEBUTTON);
179 SERVER_END_REQ;
180 return ret;
183 /***********************************************************************
184 * GetMessagePos (USER.119)
185 * GetMessagePos (USER32.@)
187 * The GetMessagePos() function returns a long value representing a
188 * cursor position, in screen coordinates, when the last message
189 * retrieved by the GetMessage() function occurs. The x-coordinate is
190 * in the low-order word of the return value, the y-coordinate is in
191 * the high-order word. The application can use the MAKEPOINT()
192 * macro to obtain a POINT structure from the return value.
194 * For the current cursor position, use GetCursorPos().
196 * RETURNS
198 * Cursor position of last message on success, zero on failure.
200 * CONFORMANCE
202 * ECMA-234, Win32
205 DWORD WINAPI GetMessagePos(void)
207 MESSAGEQUEUE *queue;
209 if (!(queue = QUEUE_Current())) return 0;
210 return queue->GetMessagePosVal;
214 /***********************************************************************
215 * GetMessageTime (USER.120)
216 * GetMessageTime (USER32.@)
218 * GetMessageTime() returns the message time for the last message
219 * retrieved by the function. The time is measured in milliseconds with
220 * the same offset as GetTickCount().
222 * Since the tick count wraps, this is only useful for moderately short
223 * relative time comparisons.
225 * RETURNS
227 * Time of last message on success, zero on failure.
229 * CONFORMANCE
231 * ECMA-234, Win32
234 LONG WINAPI GetMessageTime(void)
236 MESSAGEQUEUE *queue;
238 if (!(queue = QUEUE_Current())) return 0;
239 return queue->GetMessageTimeVal;
243 /***********************************************************************
244 * GetMessageExtraInfo (USER.288)
245 * GetMessageExtraInfo (USER32.@)
247 LPARAM WINAPI GetMessageExtraInfo(void)
249 MESSAGEQUEUE *queue;
251 if (!(queue = QUEUE_Current())) return 0;
252 return queue->GetMessageExtraInfoVal;
256 /***********************************************************************
257 * SetMessageExtraInfo (USER32.@)
259 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
261 MESSAGEQUEUE *queue;
262 LONG old_value;
264 if (!(queue = QUEUE_Current())) return 0;
265 old_value = queue->GetMessageExtraInfoVal;
266 queue->GetMessageExtraInfoVal = lParam;
267 return old_value;