Fixed more -DSTRICT issues.
[wine] / windows / queue.c
1 /*
2  * Message queues related functions
3  *
4  * Copyright 1993, 1994 Alexandre Julliard
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <string.h>
22 #include <signal.h>
23 #include <assert.h>
24 #include "windef.h"
25 #include "wingdi.h"
26 #include "winerror.h"
27 #include "wine/winbase16.h"
28 #include "wine/winuser16.h"
29 #include "queue.h"
30 #include "win.h"
31 #include "user.h"
32 #include "thread.h"
33 #include "wine/debug.h"
34 #include "wine/server.h"
35 #include "spy.h"
36
37 WINE_DEFAULT_DEBUG_CHANNEL(msg);
38
39
40 /***********************************************************************
41  *           QUEUE_CreateMsgQueue
42  *
43  * Creates a message queue. Doesn't link it into queue list!
44  */
45 static HQUEUE16 QUEUE_CreateMsgQueue(void)
46 {
47     HQUEUE16 hQueue;
48     HANDLE handle;
49     MESSAGEQUEUE * msgQueue;
50
51     TRACE_(msg)("(): Creating message queue...\n");
52
53     if (!(hQueue = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT,
54                                   sizeof(MESSAGEQUEUE) )))
55         return 0;
56
57     msgQueue = (MESSAGEQUEUE *) GlobalLock16( hQueue );
58     if ( !msgQueue )
59         return 0;
60
61     SERVER_START_REQ( get_msg_queue )
62     {
63         wine_server_call_err( req );
64         handle = reply->handle;
65     }
66     SERVER_END_REQ;
67     if (!handle)
68     {
69         ERR_(msg)("Cannot get thread queue");
70         GlobalFree16( hQueue );
71         return 0;
72     }
73     msgQueue->server_queue = handle;
74     msgQueue->self = hQueue;
75     return hQueue;
76 }
77
78
79 /***********************************************************************
80  *           QUEUE_Current
81  *
82  * Get the current thread queue, creating it if required.
83  * QUEUE_Unlock is not needed since the queue can only be deleted by
84  * the current thread anyway.
85  */
86 MESSAGEQUEUE *QUEUE_Current(void)
87 {
88     HQUEUE16 hQueue = NtCurrentTeb()->queue;
89
90     if (!hQueue)
91     {
92         if (!(hQueue = QUEUE_CreateMsgQueue())) return NULL;
93         SetThreadQueue16( 0, hQueue );
94     }
95
96     return GlobalLock16( hQueue );
97 }
98
99
100
101 /***********************************************************************
102  *           QUEUE_DeleteMsgQueue
103  *
104  * Delete a message queue.
105  */
106 void QUEUE_DeleteMsgQueue(void)
107 {
108     HQUEUE16 hQueue = NtCurrentTeb()->queue;
109     MESSAGEQUEUE * msgQueue;
110
111     if (!hQueue) return;  /* thread doesn't have a queue */
112
113     TRACE("(): Deleting message queue %04x\n", hQueue);
114
115     if (!(msgQueue = GlobalLock16( hQueue )))
116     {
117         ERR("invalid thread queue\n");
118         return;
119     }
120
121     SetThreadQueue16( 0, 0 );
122     CloseHandle( msgQueue->server_queue );
123     GlobalFree16( hQueue );
124 }
125
126
127 /***********************************************************************
128  *              InitThreadInput   (USER.409)
129  */
130 HQUEUE16 WINAPI InitThreadInput16( WORD unknown, WORD flags )
131 {
132     MESSAGEQUEUE *queue = QUEUE_Current();
133     return queue ? queue->self : 0;
134 }
135
136 /***********************************************************************
137  *              GetQueueStatus (USER32.@)
138  */
139 DWORD WINAPI GetQueueStatus( UINT flags )
140 {
141     DWORD ret = 0;
142
143     SERVER_START_REQ( get_queue_status )
144     {
145         req->clear = 1;
146         wine_server_call( req );
147         ret = MAKELONG( reply->changed_bits & flags, reply->wake_bits & flags );
148     }
149     SERVER_END_REQ;
150     return ret;
151 }
152
153
154 /***********************************************************************
155  *              GetInputState   (USER32.@)
156  */
157 BOOL WINAPI GetInputState(void)
158 {
159     DWORD ret = 0;
160
161     SERVER_START_REQ( get_queue_status )
162     {
163         req->clear = 0;
164         wine_server_call( req );
165         ret = reply->wake_bits & (QS_KEY | QS_MOUSEBUTTON);
166     }
167     SERVER_END_REQ;
168     return ret;
169 }
170
171 /***********************************************************************
172  *              GetMessagePos (USER.119)
173  *              GetMessagePos (USER32.@)
174  *
175  * The GetMessagePos() function returns a long value representing a
176  * cursor position, in screen coordinates, when the last message
177  * retrieved by the GetMessage() function occurs. The x-coordinate is
178  * in the low-order word of the return value, the y-coordinate is in
179  * the high-order word. The application can use the MAKEPOINT()
180  * macro to obtain a POINT structure from the return value.
181  *
182  * For the current cursor position, use GetCursorPos().
183  *
184  * RETURNS
185  *
186  * Cursor position of last message on success, zero on failure.
187  *
188  * CONFORMANCE
189  *
190  * ECMA-234, Win32
191  *
192  */
193 DWORD WINAPI GetMessagePos(void)
194 {
195     MESSAGEQUEUE *queue;
196
197     if (!(queue = QUEUE_Current())) return 0;
198     return queue->GetMessagePosVal;
199 }
200
201
202 /***********************************************************************
203  *              GetMessageTime (USER.120)
204  *              GetMessageTime (USER32.@)
205  *
206  * GetMessageTime() returns the message time for the last message
207  * retrieved by the function. The time is measured in milliseconds with
208  * the same offset as GetTickCount().
209  *
210  * Since the tick count wraps, this is only useful for moderately short
211  * relative time comparisons.
212  *
213  * RETURNS
214  *
215  * Time of last message on success, zero on failure.
216  *
217  * CONFORMANCE
218  *
219  * ECMA-234, Win32
220  *
221  */
222 LONG WINAPI GetMessageTime(void)
223 {
224     MESSAGEQUEUE *queue;
225
226     if (!(queue = QUEUE_Current())) return 0;
227     return queue->GetMessageTimeVal;
228 }
229
230
231 /***********************************************************************
232  *              GetMessageExtraInfo (USER.288)
233  *              GetMessageExtraInfo (USER32.@)
234  */
235 LONG WINAPI GetMessageExtraInfo(void)
236 {
237     MESSAGEQUEUE *queue;
238
239     if (!(queue = QUEUE_Current())) return 0;
240     return queue->GetMessageExtraInfoVal;
241 }