Release 950620
[wine] / misc / spy.c
1 /* SPY.C
2  *
3  * Copyright 1994, Bob Amstadt
4  */
5
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <X11/Xlib.h>
9 #include <X11/Xresource.h>
10 #include <string.h>
11 #include "wineopts.h"
12 #include "windows.h"
13 #include "wine.h"
14 #include "options.h"
15
16 #ifndef NOSPY
17
18 #define SPY_MAX_MSGNUM          0x0232
19
20 const char *MessageTypeNames[SPY_MAX_MSGNUM + 1] =
21 {
22     "WM_NULL",                  /* 0x00 */
23     "WM_CREATE",        
24     "WM_DESTROY",    
25     "WM_MOVE",
26     "WM_UNUSED0",
27     "WM_SIZE",
28     "WM_ACTIVATE",
29     "WM_SETFOCUS",
30     "WM_KILLFOCUS",
31     "WM_UNUSED1",
32     "WM_ENABLE",
33     "WM_SETREDRAW",
34     "WM_SETTEXT",
35     "WM_GETTEXT",
36     "WM_GETTEXTLENGTH",
37     "WM_PAINT",
38     "WM_CLOSE",                 /* 0x10 */
39     "WM_QUERYENDSESSION",
40     "WM_QUIT",
41     "WM_QUERYOPEN",
42     "WM_ERASEBKGND",
43     "WM_SYSCOLORCHANGE",
44     "WM_ENDSESSION",
45     "WM_UNUSED2",
46     "WM_SHOWWINDOW",
47     "WM_CTLCOLOR",
48     "WM_WININICHANGE",
49     "WM_DEVMODECHANGE",
50     "WM_ACTIVATEAPP",
51     "WM_FONTCHANGE",
52     "WM_TIMECHANGE",
53     "WM_CANCELMODE",
54     "WM_SETCURSOR",             /* 0x20 */
55     "WM_MOUSEACTIVATE",
56     "WM_CHILDACTIVATE",
57     "WM_QUEUESYNC",
58     "WM_GETMINMAXINFO",
59     "WM_UNUSED3",
60     "WM_PAINTICON",
61     "WM_ICONERASEBKGND",
62     "WM_NEXTDLGCTL",
63     "WM_UNUSED4",
64     "WM_SPOOLERSTATUS",
65     "WM_DRAWITEM",
66     "WM_MEASUREITEM",
67     "WM_DELETEITEM",
68     "WM_VKEYTOITEM",
69     "WM_CHARTOITEM",
70     "WM_SETFONT",               /* 0x30 */
71     "WM_GETFONT", NULL, NULL, NULL, NULL, NULL, NULL,
72     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
73
74     /* 0x40 */
75     NULL, NULL, NULL, NULL, NULL, NULL,
76     "WM_WINDOWPOSCHANGING",     /* 0x0046 */
77     "WM_WINDOWPOSCHANGED",      /* 0x0047 */
78     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
79
80     /* 0x0050 */
81     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
82     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
83
84     /* 0x0060 */
85     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
86     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
87
88     /* 0x0070 */
89     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
90     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
91
92     NULL,                       /* 0x0080 */
93     "WM_NCCREATE",              /* 0x0081 */
94     "WM_NCDESTROY",             /* 0x0082 */
95     "WM_NCCALCSIZE",            /* 0x0083 */
96     "WM_NCHITTEST",             /* 0x0084 */
97     "WM_NCPAINT",               /* 0x0085 */
98     "WM_NCACTIVATE",            /* 0x0086 */
99     "WM_GETDLGCODE",            /* 0x0087 */
100     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
101
102     /* 0x0090 */
103     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
104     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
105
106     /* 0x00A0 */
107     "WM_NCMOUSEMOVE",           /* 0x00A0 */
108     "WM_NCLBUTTONDOWN",         /* 0x00A1 */
109     "WM_NCLBUTTONUP",           /* 0x00A2 */
110     "WM_NCLBUTTONDBLCLK",       /* 0x00A3 */
111     "WM_NCRBUTTONDOWN",         /* 0x00A4 */
112     "WM_NCRBUTTONUP",           /* 0x00A5 */
113     "WM_NCRBUTTONDBLCLK",       /* 0x00A6 */
114     "WM_NCMBUTTONDOWN",         /* 0x00A7 */
115     "WM_NCMBUTTONUP",           /* 0x00A8 */
116     "WM_NCMBUTTONDBLCLK",       /* 0x00A9 */
117     NULL, NULL, NULL, NULL, NULL, NULL,
118
119     /* 0x00B0 */
120     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
121     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
122
123     /* 0x00C0 */
124     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
125     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
126
127     /* 0x00D0 */
128     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
129     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
130
131     /* 0x00E0 */
132     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
133     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
134
135     /* 0x00F0 */
136     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
137     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
138
139     "WM_KEYDOWN",               /* 0x0100 */
140     "WM_KEYUP",                 /* 0x0101 */
141     "WM_CHAR",                  /* 0x0102 */
142     "WM_DEADCHAR",              /* 0x0103 */
143     "WM_SYSKEYDOWN",            /* 0x0104 */
144     "WM_SYSKEYUP",              /* 0x0105 */
145     "WM_SYSCHAR",               /* 0x0106 */
146     "WM_SYSDEADCHAR",           /* 0x0107 */
147     "WM_KEYLAST",               /* 0x0108 */
148     NULL, NULL, NULL, NULL, NULL, NULL, NULL,
149
150     "WM_INITDIALOG",            /* 0x0110 */
151     "WM_COMMAND",               /* 0x0111 */
152     "WM_SYSCOMMAND",            /* 0x0112 */
153     "WM_TIMER",                 /* 0x0113 */
154     "WM_HSCROLL",               /* 0x0114 */
155     "WM_VSCROLL",               /* 0x0115 */
156     "WM_INITMENU",              /* 0x0116 */
157     "WM_INITMENUPOPUP",         /* 0x0117 */
158     "WM_SYSTIMER",              /* 0x0118 */
159     NULL, NULL, NULL, NULL, NULL, NULL,
160     "WM_MENUSELECT",            /* 0x011f */
161
162     "WM_MENUCHAR",              /* 0x0120 */
163     "WM_ENTERIDLE",             /* 0x0121 */
164     NULL, NULL, NULL, NULL, NULL, NULL,
165     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
166
167     /* 0x0130 */
168     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
169     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
170
171     /* 0x0140 */
172     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
173     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
174
175     /* 0x0150 */
176     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
177     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
178
179     /* 0x0160 */
180     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
181     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
182
183     /* 0x0170 */
184     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
185     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
186
187     /* 0x0180 */
188     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
189     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
190
191     /* 0x0190 */
192     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
193     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
194
195     /* 0x01A0 */
196     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
197     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
198
199     /* 0x01B0 */
200     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
201     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
202
203     /* 0x01C0 */
204     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
205     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
206
207     /* 0x01D0 */
208     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
209     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
210
211     /* 0x01E0 */
212     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
213     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
214
215     /* 0x01F0 */
216     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
217     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
218
219     "WM_MOUSEMOVE",             /* 0x0200 */
220     "WM_LBUTTONDOWN",           /* 0x0201 */
221     "WM_LBUTTONUP",             /* 0x0202 */
222     "WM_LBUTTONDBLCLK",         /* 0x0203 */
223     "WM_RBUTTONDOWN",           /* 0x0204 */
224     "WM_RBUTTONUP",             /* 0x0205 */
225     "WM_RBUTTONDBLCLK",         /* 0x0206 */
226     "WM_MBUTTONDOWN",           /* 0x0207 */
227     "WM_MBUTTONUP",             /* 0x0208 */
228     "WM_MBUTTONDBLCLK",         /* 0x0209 */
229     NULL, NULL, NULL, NULL, NULL, NULL,
230
231     "WM_PARENTNOTIFY",          /* 0x0210 */
232     "WM_ENTERMENULOOP",         /* 0x0211 */
233     "WM_EXITMENULOOP",          /* 0x0212 */
234     NULL, NULL, NULL, NULL, NULL,
235     NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
236
237     "WM_MDICREATE",             /* 0x0220 */
238     "WM_MDIDESTROY",            /* 0x0221 */
239     "WM_MDIACTIVATE",           /* 0x0222 */
240     "WM_MDIRESTORE",            /* 0x0223 */
241     "WM_MDINEXT",               /* 0x0224 */
242     "WM_MDIMAXIMIZE",           /* 0x0225 */
243     "WM_MDITILE",               /* 0x0226 */
244     "WM_MDICASCADE",            /* 0x0227 */
245     "WM_MDIICONARRANGE",        /* 0x0228 */
246     "WM_MDIGETACTIVE",          /* 0x0229 */
247
248     "WM_MDISETMENU",            /* 0x0230 */
249     "WM_ENTERSIZEMOVE",         /* 0x0231 */
250     "WM_EXITSIZEMOVE"           /* 0x0232 */
251 };
252
253 char SpyFilters[256+1];
254 char SpyIncludes[256+1];
255
256 #endif /* NOSPY */
257
258 /**********************************************************************
259  *                                      SpyMessage
260  */
261 void SpyMessage(HWND hwnd, WORD msg, WORD wParam, LONG lParam)
262 {
263 #ifndef NOSPY
264     char msg_name[80];
265     
266     if (SpyFp == NULL)
267         return;
268     
269     if (msg > SPY_MAX_MSGNUM || MessageTypeNames[msg] == NULL)
270         sprintf(msg_name, "%04x", msg);
271     else
272         strcpy(msg_name, MessageTypeNames[msg]);
273     
274     strcat(msg_name, ";");
275     
276     if ((strlen(SpyIncludes) == 0 || strstr(SpyIncludes, msg_name) != NULL) &&
277         strstr(SpyFilters, msg_name) == NULL)
278     {
279         msg_name[strlen(msg_name) - 1] = '\0';
280         fprintf(SpyFp, "%04x  %20.20s  %04x  %04x  %08lx\n",
281                 hwnd, msg_name, msg, wParam, lParam);
282     }
283 #endif
284 }
285
286 /**********************************************************************
287  *                                      SpyInit
288  */
289 void SpyInit(void)
290 {
291 #ifndef NOSPY
292     char filename[100];
293
294     if (SpyFp != NULL)
295         return;
296
297     if (Options.spyFilename == NULL)
298     {
299         GetPrivateProfileString("spy", "file", "", filename, sizeof(filename),
300                                 WINE_INI);
301     }
302     else
303         strncpy(filename, Options.spyFilename, 100);
304
305     if (strcasecmp(filename, "CON") == 0)
306         SpyFp = stdout;
307     else if (strlen(filename))
308         SpyFp = fopen(filename, "a");
309     else
310     {
311         SpyFp = NULL;
312         return;
313     }
314     
315     GetPrivateProfileString("spy", "exclude", "", SpyFilters, 
316                             sizeof(SpyFilters)-1, WINE_INI);
317     GetPrivateProfileString("spy", "include", "", SpyIncludes, 
318                             sizeof(SpyIncludes)-1, WINE_INI);
319
320     if (*SpyIncludes != 0) {
321       strcat(SpyIncludes, ";");
322     }
323     if (*SpyFilters != 0) {
324       strcat(SpyFilters, ";");
325     }
326 #endif
327 }