Small fixes.
[wine] / include / queue.h
1 /*
2  * Message queues definitions
3  *
4  * Copyright 1993 Alexandre Julliard
5  */
6
7 #ifndef __WINE_QUEUE_H
8 #define __WINE_QUEUE_H
9
10 #include "windef.h"
11 #include "winuser.h"
12 #include "thread.h"
13
14
15   /* Message as stored in the queue (contains the extraInfo field) */
16 typedef struct tagQMSG
17 {
18     int   type;
19     MSG   msg;
20     DWORD extraInfo;  /* Only in 3.1 */
21     
22     struct tagQMSG *nextMsg;
23     struct tagQMSG *prevMsg;
24 } QMSG;
25
26 #define QMSG_WIN16    0
27 #define QMSG_WIN32A   1
28 #define QMSG_WIN32W   2
29 #define QMSG_HARDWARE 3
30
31
32 typedef struct tagSMSG
33 {
34     struct tagSMSG *nextProcessing; /* next SMSG in the processing list */
35     struct tagSMSG *nextPending;    /* next SMSG in the pending list */
36     struct tagSMSG *nextWaiting;    /* next SMSG in the waiting list */
37     
38     HQUEUE16       hSrcQueue;       /* sending Queue, (NULL if it didn't wait) */
39     HQUEUE16       hDstQueue;       /* destination Queue */
40
41     HWND         hWnd;            /* destinantion window */
42     UINT         msg;             /* message sent */
43     WPARAM       wParam;          /* wParam of the sent message */
44     LPARAM         lParam;          /* lParam of the sent message */
45
46     LRESULT        lResult;         /* result of SendMessage */
47     WORD           flags;           /* see below SMSG_XXXX */
48 } SMSG;
49
50
51 /* SMSG -> flags values */
52 /* set when lResult contains a good value */
53 #define SMSG_HAVE_RESULT            0x0001
54 /* protection for multiple call to ReplyMessage16() */
55 #define SMSG_ALREADY_REPLIED        0x0002
56 /* use with EARLY_REPLY for forcing the receiver to clean SMSG */
57 #define SMSG_RECEIVER_CLEANS        0x0010
58 /* used with EARLY_REPLY to indicate to sender, receiver is done with SMSG */
59 #define SMSG_RECEIVED               0x0020
60 /* set in ReceiveMessage() to indicate it's not an early reply */
61 #define SMSG_SENDING_REPLY          0x0040
62 /* set when ReplyMessage16() is called by the application */
63 #define SMSG_EARLY_REPLY            0x0080
64 /* set when sender is Win32 thread */
65 #define SMSG_WIN32                  0x1000
66 /* set when sender is a unnicode thread */
67 #define SMSG_UNICODE                0x2000
68
69 /* Per-queue data for the message queue
70  * Note that we currently only store the current values for
71  * Active, Capture and Focus windows currently.
72  * It might be necessary to store a pointer to the system message queue
73  * as well since windows 9x maintains per thread system message queues
74  */
75 typedef struct tagPERQUEUEDATA      
76 {
77   HWND    hWndFocus;              /* Focus window */
78   HWND    hWndActive;             /* Active window */
79   HWND    hWndCapture;            /* Capture window */
80   INT16     nCaptureHT;             /* Capture info (hit-test) */
81   ULONG     ulRefCount;             /* Reference count */
82   CRITICAL_SECTION cSection;        /* Critical section for thread safe access */
83 } PERQUEUEDATA;
84
85 /* Message queue */
86 typedef struct tagMESSAGEQUEUE
87 {
88   HQUEUE16  next;                   /* Next queue */
89   HQUEUE16  self;                   /* Handle to self (was: reserved) */
90   TEB*      teb;                    /* Thread owning queue */
91   HANDLE  hEvent;                 /* Event handle */
92   CRITICAL_SECTION cSection;        /* Queue access critical section */
93
94   DWORD     magic;                  /* magic number should be QUEUE_MAGIC */
95   DWORD     lockCount;              /* reference counter */
96   WORD      wWinVersion;            /* Expected Windows version */
97   
98   WORD      msgCount;               /* Number of waiting messages */
99   QMSG*     firstMsg;               /* First message in linked list */
100   QMSG*     lastMsg;                /* Last message in linked list */
101   
102   WORD      wPostQMsg;              /* PostQuitMessage flag */
103   WORD      wExitCode;              /* PostQuitMessage exit code */
104   WORD      wPaintCount;            /* Number of WM_PAINT needed */
105   WORD      wTimerCount;            /* Number of timers for this task */
106
107   WORD      changeBits;             /* Changed wake-up bits */
108   WORD      wakeBits;               /* Queue wake-up bits */
109   WORD      wakeMask;               /* Queue wake-up mask */
110
111   DWORD     GetMessageTimeVal;      /* Value for GetMessageTime */
112   DWORD     GetMessagePosVal;       /* Value for GetMessagePos */
113   DWORD     GetMessageExtraInfoVal; /* Value for GetMessageExtraInfo */
114   
115   SMSG*     smWaiting;              /* SendMessage waiting for reply */
116   SMSG*     smProcessing;           /* SendMessage currently being processed */
117   SMSG*     smPending;              /* SendMessage waiting to be received */
118   
119   HANDLE16  hCurHook;               /* Current hook */
120   HANDLE16  hooks[WH_NB_HOOKS];     /* Task hooks list */
121
122   PERQUEUEDATA *pQData;             /* pointer to (shared) PERQUEUEDATA structure */
123   
124 } MESSAGEQUEUE;
125
126
127 /* Extra (undocumented) queue wake bits - see "Undoc. Windows" */
128 #define QS_SMRESULT      0x8000  /* Queue has a SendMessage() result */
129
130 /* Types of SMSG stack */
131 #define SM_PROCESSING_LIST    1  /* list of SM currently being processed */
132 #define SM_PENDING_LIST       2  /* list of SM wating to be received */
133 #define SM_WAITING_LIST       3  /* list of SM waiting for reply */
134
135 #define QUEUE_MAGIC        0xD46E80AF
136
137 /* Per queue data management methods */
138 PERQUEUEDATA* PERQDATA_CreateInstance( void );
139 ULONG PERQDATA_Addref( PERQUEUEDATA* pQData );
140 ULONG PERQDATA_Release( PERQUEUEDATA* pQData );
141 HWND PERQDATA_GetFocusWnd( PERQUEUEDATA *pQData );
142 HWND PERQDATA_SetFocusWnd( PERQUEUEDATA *pQData, HWND hWndFocus );
143 HWND PERQDATA_GetActiveWnd( PERQUEUEDATA *pQData );
144 HWND PERQDATA_SetActiveWnd( PERQUEUEDATA *pQData, HWND hWndActive );
145 HWND PERQDATA_GetCaptureWnd( PERQUEUEDATA *pQData );
146 HWND PERQDATA_SetCaptureWnd( PERQUEUEDATA *pQData, HWND hWndCapture );
147 INT16  PERQDATA_GetCaptureInfo( PERQUEUEDATA *pQData );
148 INT16 PERQDATA_SetCaptureInfo( PERQUEUEDATA *pQData, INT16 nCaptureHT );
149     
150 /* Message queue management methods */
151 extern MESSAGEQUEUE *QUEUE_Lock( HQUEUE16 hQueue );
152 extern void QUEUE_Unlock( MESSAGEQUEUE *queue );
153 extern void QUEUE_DumpQueue( HQUEUE16 hQueue );
154 extern void QUEUE_WalkQueues(void);
155 extern BOOL QUEUE_IsExitingQueue( HQUEUE16 hQueue );
156 extern void QUEUE_SetExitingQueue( HQUEUE16 hQueue );
157 extern MESSAGEQUEUE *QUEUE_GetSysQueue(void);
158 extern void QUEUE_SetWakeBit( MESSAGEQUEUE *queue, WORD bit );
159 extern void QUEUE_ClearWakeBit( MESSAGEQUEUE *queue, WORD bit );
160 extern void QUEUE_ReceiveMessage( MESSAGEQUEUE *queue );
161 extern int QUEUE_WaitBits( WORD bits, DWORD timeout );
162 extern void QUEUE_IncPaintCount( HQUEUE16 hQueue );
163 extern void QUEUE_DecPaintCount( HQUEUE16 hQueue );
164 extern void QUEUE_IncTimerCount( HQUEUE16 hQueue );
165 extern void QUEUE_DecTimerCount( HQUEUE16 hQueue );
166 extern BOOL QUEUE_CreateSysMsgQueue( int size );
167 extern BOOL QUEUE_DeleteMsgQueue( HQUEUE16 hQueue );
168 extern HTASK16 QUEUE_GetQueueTask( HQUEUE16 hQueue );
169 extern BOOL QUEUE_AddMsg( HQUEUE16 hQueue, int type, MSG * msg, DWORD extraInfo );
170 extern QMSG* QUEUE_FindMsg( MESSAGEQUEUE * msgQueue, HWND hwnd,
171                           int first, int last );
172 extern void QUEUE_RemoveMsg( MESSAGEQUEUE * msgQueue, QMSG *qmsg );
173 extern SMSG *QUEUE_RemoveSMSG( MESSAGEQUEUE *queue, int list, SMSG *smsg );
174 extern BOOL QUEUE_AddSMSG( MESSAGEQUEUE *queue, int list, SMSG *smsg );
175 extern void hardware_event( UINT message, WPARAM wParam, LPARAM lParam,
176                             int xPos, int yPos, DWORD time, DWORD extraInfo );
177
178 extern HQUEUE16 WINAPI InitThreadInput16( WORD unknown, WORD flags );
179
180 #endif  /* __WINE_QUEUE_H */