source: trunk/src/user32/wndclass.cpp@ 218

Last change on this file since 218 was 218, checked in by sandervl, 26 years ago

More message changes

File size: 33.9 KB
Line 
1/* $Id: wndclass.cpp,v 1.11 1999-06-26 14:09:58 sandervl Exp $ */
2
3/*
4 * Win32 Window Class Managment Code for OS/2
5 *
6 * 18-07-1998 SvL: Merged all class code into this file + bug fixes
7 * Register all system classes at dll init
8 * Rewrote incorrect callback code
9 *
10 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
11 *
12 *
13 * Project Odin Software License can be found in LICENSE.TXT
14 *
15 */
16#include <os2win.h>
17#include <stdarg.h>
18#include <stdio.h>
19#include <string.h>
20#include <stdlib.h>
21#include <assert.h>
22#include <misc.h>
23#include <wndproc.h>
24#include <wndclass.h>
25#include <nameid.h>
26#include <spy.h>
27#include "hooks.h"
28
29//default window handlers that are registered by RegisterClass are called
30//in this callback handler
31LRESULT EXPENTRY_O32 OS2ToWinCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam);
32//default window handlers that are queried by GetClassInfo/GetClassLong is really
33//this callback handler
34LRESULT WIN32API WinToOS2Callback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam);
35
36#ifdef DEBUG
37char *GetMsgText(int Msg);
38#endif
39
40DWORD MapOEMToRealKey(DWORD wParam, DWORD lParam);
41
42WNDPROC_O32 ButtonHandler = 0;
43WNDPROC_O32 ListboxHandler = 0;
44WNDPROC_O32 ComboboxHandler = 0;
45WNDPROC_O32 EditHandler = 0;
46WNDPROC_O32 MdiClientHandler = 0;
47WNDPROC_O32 ScrollbarHandler = 0;
48WNDPROC_O32 StaticHandler = 0;
49
50HWND hwndButton = 0;
51HWND hwndListbox = 0;
52HWND hwndEdit = 0;
53HWND hwndCombobox = 0;
54HWND hwndScrollbar = 0;
55HWND hwndMdiClient = 0;
56HWND hwndStatic = 0;
57
58Win32WindowClass *ButtonClass = 0;
59Win32WindowClass *ListboxClass = 0;
60Win32WindowClass *EditClass = 0;
61Win32WindowClass *ComboboxClass = 0;
62Win32WindowClass *MdiClientClass = 0;
63Win32WindowClass *ScrollbarClass = 0;
64Win32WindowClass *StaticClass = 0;
65//******************************************************************************
66//******************************************************************************
67LRESULT WIN32API ButtonCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
68{
69 DWORD dwStyle, dwExStyle;
70 LRESULT rc;
71
72 PostSpyMessage(hwnd, Msg, wParam, lParam);
73 switch(Msg)
74 {
75 case WM_LBUTTONDOWN:
76 rc = ButtonHandler(hwnd, Msg, wParam, lParam);
77
78 NotifyParent(hwnd, Msg, wParam, lParam);
79 dwStyle = GetWindowLongA(hwnd, GWL_STYLE);
80 dwExStyle = GetWindowLongA(hwnd, GWL_EXSTYLE);
81
82 if(dwStyle & WS_CHILD && !(dwExStyle & WS_EX_NOPARENTNOTIFY) )
83 {
84 HWND hwndParent = GetParent(hwnd);
85
86 //TODO: Mouse shouldn't be captured
87 Win32WindowProc *parentwnd = Win32WindowProc::FindProc(hwndParent);
88 if(parentwnd) {
89 //TODO: HTCLIENT isn't always accurate
90 parentwnd->SendMessageA(hwndParent, WM_SETCURSOR, hwnd, HTCLIENT | (WM_LBUTTONDOWN << 16));
91 }
92 }
93 return rc;
94 case WM_CREATE:
95 case WM_DESTROY:
96 case WM_MBUTTONDOWN:
97 case WM_RBUTTONDOWN:
98 NotifyParent(hwnd, Msg, wParam, lParam);
99 break;
100 }
101 return ButtonHandler(hwnd, Msg, wParam, lParam);
102}
103//******************************************************************************
104//******************************************************************************
105LRESULT WIN32API ListboxCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
106{
107 PostSpyMessage(hwnd, Msg, wParam, lParam);
108 return ListboxHandler(hwnd, Msg, wParam, lParam);
109}
110//******************************************************************************
111//******************************************************************************
112LRESULT WIN32API ComboboxCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
113{
114 PostSpyMessage(hwnd, Msg, wParam, lParam);
115 return ComboboxHandler(hwnd, Msg, wParam, lParam);
116}
117//******************************************************************************
118//******************************************************************************
119LRESULT WIN32API MdiClientCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
120{
121 PostSpyMessage(hwnd, Msg, wParam, lParam);
122 return MdiClientHandler(hwnd, Msg, wParam, lParam);
123}
124//******************************************************************************
125//******************************************************************************
126LRESULT WIN32API EditCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
127{
128 PostSpyMessage(hwnd, Msg, wParam, lParam);
129 return EditHandler(hwnd, Msg, wParam, lParam);
130}
131//******************************************************************************
132//******************************************************************************
133LRESULT WIN32API ScrollbarCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
134{
135 PostSpyMessage(hwnd, Msg, wParam, lParam);
136 return ScrollbarHandler(hwnd, Msg, wParam, lParam);
137}
138//******************************************************************************
139//******************************************************************************
140LRESULT WIN32API StaticCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
141{
142 PostSpyMessage(hwnd, Msg, wParam, lParam);
143 return StaticHandler(hwnd, Msg, wParam, lParam);
144}
145//******************************************************************************
146//SvL: 18-7-'98, Registers system window classes (button, listbox etc etc)
147//******************************************************************************
148void RegisterSystemClasses(ULONG hModule)
149{
150 WNDCLASSA wndclass;
151 HWND hwnd;
152
153 if(O32_GetClassInfo(NULL, "BUTTON", &wndclass)) {
154 dprintf(("Create BUTTON System class"));
155 ButtonClass = new Win32WindowClass(ButtonCallback, "BUTTON", hModule);
156 ButtonHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
157 hwndButton = O32_CreateWindow("BUTTON", "BUTTON", 0, 0, 0, 0, 0, 0, 0, 0, 0);
158 if(hwndButton == 0) {
159 dprintf(("RegisterSystemClasses failed!!"));
160 }
161 O32_SetClassLong(hwndButton, GCL_WNDPROC, (LONG)ButtonCallback);
162 }
163 if(O32_GetClassInfo(NULL, "LISTBOX", &wndclass)) {
164 dprintf(("Create LISTBOX System class"));
165 ListboxClass = new Win32WindowClass(ListboxCallback, "LISTBOX", hModule);
166 ListboxHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
167 hwndListbox = O32_CreateWindow("LISTBOX", "LISTBOX", 0, 0, 0, 0, 0, 0, 0, 0, 0);
168 if(hwndListbox == 0) {
169 dprintf(("RegisterSystemClasses failed!!"));
170 }
171 O32_SetClassLong(hwndListbox, GCL_WNDPROC, (LONG)ListboxCallback);
172 }
173 if(O32_GetClassInfo(NULL, "COMBOBOX", &wndclass)) {
174 dprintf(("Create COMBOBOX System class"));
175 ComboboxClass = new Win32WindowClass(ComboboxCallback, "COMBOBOX", hModule);
176 ComboboxHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
177 hwndCombobox = O32_CreateWindow("COMBOBOX", "COMBOBOX", 0, 0, 0, 0, 0, 0, 0, 0, 0);
178 if(hwndCombobox == 0) {
179 dprintf(("RegisterSystemClasses failed!!"));
180 }
181 O32_SetClassLong(hwndCombobox, GCL_WNDPROC, (LONG)ComboboxCallback);
182 }
183 if(O32_GetClassInfo(NULL, "EDIT", &wndclass)) {
184 dprintf(("Create EDIT System class"));
185 EditClass = new Win32WindowClass(EditCallback, "EDIT", hModule);
186 EditHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
187 hwndEdit = O32_CreateWindow("EDIT", "EDIT", 0, 0, 0, 0, 0, 0, 0, 0, 0);
188 if(hwndEdit == 0) {
189 dprintf(("RegisterSystemClasses failed!!"));
190 }
191 O32_SetClassLong(hwndEdit, GCL_WNDPROC, (LONG)EditCallback);
192 }
193 //TODO: This doens't work yet!! (need to create a normal window as parent)
194 if(O32_GetClassInfo(NULL, "MDICLIENT", &wndclass)) {
195 dprintf(("Create MDICLIENT System class"));
196 MdiClientClass = new Win32WindowClass(MdiClientCallback, "MDICLIENT", hModule);
197 MdiClientHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
198 hwndMdiClient = O32_CreateWindow("MDICLIENT", "MDICLIENT", WS_CHILD, 0, 0, 0, 0, hwndListbox, 0, 0, 0);
199 if(hwndMdiClient == 0) {
200 dprintf(("RegisterSystemClasses failed!!"));
201 }
202 O32_SetClassLong(hwndMdiClient, GCL_WNDPROC, (LONG)MdiClientCallback);
203 }
204 if(O32_GetClassInfo(NULL, "SCROLLBAR", &wndclass)) {
205 dprintf(("Create SCROLLBAR System class"));
206 ScrollbarClass = new Win32WindowClass(ScrollbarCallback, "SCROLLBAR", hModule);
207 ScrollbarHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
208 hwndScrollbar = O32_CreateWindow("SCROLLBAR", "SCROLLBAR", 0, 0, 0, 0, 0, 0, 0, 0, 0);
209 if(hwndScrollbar == 0) {
210 dprintf(("RegisterSystemClasses failed!!"));
211 }
212 O32_SetClassLong(hwndScrollbar, GCL_WNDPROC, (LONG)ScrollbarCallback);
213 }
214 if(O32_GetClassInfo(NULL, "STATIC", &wndclass)) {
215 dprintf(("Create STATIC System class"));
216 StaticClass = new Win32WindowClass(StaticCallback, "STATIC", hModule);
217 StaticHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
218 hwndStatic = O32_CreateWindow("STATIC", "STATIC", 0, 0, 0, 0, 0, 0, 0, 0, 0);
219 if(hwndStatic == 0) {
220 dprintf(("RegisterSystemClasses failed!!"));
221 }
222 O32_SetClassLong(hwndStatic, GCL_WNDPROC, (LONG)StaticCallback);
223 }
224//TODO: More standard classes in win95/NT4?
225}
226//******************************************************************************
227//******************************************************************************
228void UnregisterSystemClasses()
229{
230 dprintf(("KERNEL32: UnregisterSystemClasses"));
231 if(hwndButton) O32_DestroyWindow(hwndButton);
232 if(hwndListbox) O32_DestroyWindow(hwndListbox);
233 if(hwndCombobox) O32_DestroyWindow(hwndCombobox);
234 if(hwndMdiClient) O32_DestroyWindow(hwndMdiClient);
235 if(hwndEdit) O32_DestroyWindow(hwndEdit);
236 if(hwndScrollbar) O32_DestroyWindow(hwndScrollbar);
237 if(hwndStatic) O32_DestroyWindow(hwndStatic);
238 if(ButtonClass) delete ButtonClass;
239 if(ListboxClass) delete ListboxClass;
240 if(EditClass) delete EditClass;
241 if(ComboboxClass) delete ComboboxClass;
242 if(MdiClientClass) delete MdiClientClass;
243 if(ScrollbarClass) delete ScrollbarClass;
244 if(StaticClass) delete StaticClass;
245 ButtonClass = NULL;
246 EditClass = NULL;
247 ListboxClass = NULL;
248 ComboboxClass = NULL;
249 MdiClientClass = NULL;
250 ScrollbarClass = NULL;
251 StaticClass = NULL;
252}
253//******************************************************************************
254//SvL: 18-7-'98: Moved here from user32.cpp
255//******************************************************************************
256ATOM WIN32API RegisterClassA(const WNDCLASSA *lpWndClass)
257{
258 ATOM rc;
259 WNDCLASSA wc;
260
261#ifdef DEBUG
262 WriteLog("USER32: RegisterClassA\n");
263 WriteLog("USER32: lpWndClass->style %X\n", lpWndClass->style);
264 WriteLog("USER32: lpWndClass->lpfnWndProc %X\n", lpWndClass->lpfnWndProc);
265 WriteLog("USER32: lpWndClass->cbClsExtra %X\n", lpWndClass->cbClsExtra);
266 WriteLog("USER32: lpWndClass->cbWndExtra %X\n", lpWndClass->cbWndExtra);
267 WriteLog("USER32: lpWndClass->hInstance %X\n", lpWndClass->hInstance);
268 WriteLog("USER32: lpWndClass->hIcon %X\n", lpWndClass->hIcon);
269 WriteLog("USER32: lpWndClass->hCursor %X\n", lpWndClass->hCursor);
270 WriteLog("USER32: lpWndClass->hbrBackground %X\n", lpWndClass->hbrBackground);
271 WriteLog("USER32: lpWndClass->lpszMenuName %X\n", lpWndClass->lpszMenuName);
272 if((int)lpWndClass->lpszClassName >> 16 == 0)
273 WriteLog("USER32: lpWndClass->lpszClassName %X\n", lpWndClass->lpszClassName);
274 else WriteLog("USER32: lpWndClass->lpszClassName %s\n", lpWndClass->lpszClassName);
275#endif
276 memcpy(&wc, lpWndClass, sizeof(WNDCLASSA));
277
278 if((int)wc.lpszMenuName >> 16 != 0) {//convert string name identifier to numeric id
279 dprintf(("USER32: lpszMenuName %s\n", wc.lpszMenuName));
280 *(int *)&wc.lpszMenuName = ConvertNameId(0, (char *)wc.lpszMenuName);
281 dprintf(("USER32: Menu id = %d\n", (int)wc.lpszMenuName));
282 }
283#ifdef DEBUG
284 if(wc.style & (CS_PARENTDC | CS_CLASSDC)) {
285 dprintf(("USER32: Class uses an unsupported style!!!\n"));
286 }
287#endif
288 //These are not supported by Open32
289 wc.style &= ~(CS_PARENTDC | CS_CLASSDC);
290
291 wc.lpfnWndProc = (WNDPROC)Win32WindowClass::GetOS2ClassCallback();
292 rc = O32_RegisterClass(&wc);
293 if(rc) {
294 Win32WindowClass *wndclass = new Win32WindowClass((WNDPROC)lpWndClass->lpfnWndProc, (LPSTR)wc.lpszClassName, wc.hInstance);
295 }
296 dprintf(("USER32: RegisterClass returned %d (%d)\n", rc, GetLastError()));
297 return(rc);
298}
299//******************************************************************************
300//SvL: 18-7-'98: Moved here from user32.cpp
301//******************************************************************************
302ATOM WIN32API RegisterClassExA(const WNDCLASSEXA *lpWndClass)
303{
304 ATOM rc;
305 WNDCLASSEXA wc;
306
307#ifdef DEBUG
308 WriteLog("USER32: lpWndClass->cbSize %X\n", lpWndClass->cbSize);
309 WriteLog("USER32: lpWndClass->style %X\n", lpWndClass->style);
310 WriteLog("USER32: lpWndClass->lpfnWndProc %X\n", lpWndClass->lpfnWndProc);
311 WriteLog("USER32: lpWndClass->cbClsExtra %X\n", lpWndClass->cbClsExtra);
312 WriteLog("USER32: lpWndClass->cbWndExtra %X\n", lpWndClass->cbWndExtra);
313 WriteLog("USER32: lpWndClass->hInstance %X\n", lpWndClass->hInstance);
314 WriteLog("USER32: lpWndClass->hIcon %X\n", lpWndClass->hIcon);
315 WriteLog("USER32: lpWndClass->hCursor %X\n", lpWndClass->hCursor);
316 WriteLog("USER32: lpWndClass->hbrBackground %X\n", lpWndClass->hbrBackground);
317 WriteLog("USER32: lpWndClass->lpszMenuName %X\n", lpWndClass->lpszMenuName);
318 if((int)lpWndClass->lpszClassName >> 16 == 0)
319 WriteLog("USER32: lpWndClass->lpszClassName %X\n", lpWndClass->lpszClassName);
320 else WriteLog("USER32: lpWndClass->lpszClassName %s\n", lpWndClass->lpszClassName);
321#endif
322 memcpy(&wc, lpWndClass, sizeof(WNDCLASSEXA));
323
324 if((int)wc.lpszMenuName >> 16 != 0) {//convert string name identifier to numeric id
325 dprintf(("USER32: lpszMenuName %s\n", wc.lpszMenuName));
326 *(int *)&wc.lpszMenuName = ConvertNameId(0, (char *)wc.lpszMenuName);
327 dprintf(("USER32: Menu id = %d\n", (int)wc.lpszMenuName));
328 }
329 if(wc.cbSize != sizeof(WNDCLASSEXA))
330 return(0);
331
332#ifdef DEBUG
333 if(wc.style & (CS_PARENTDC | CS_CLASSDC)) {
334 dprintf(("USER32: Class uses an unsupported style!!!\n"));
335 }
336#endif
337 //These are not supported by Open32
338 wc.style &= ~(CS_PARENTDC | CS_CLASSDC);
339
340 wc.lpfnWndProc = (WNDPROC)Win32WindowClass::GetOS2ClassCallback();
341
342 rc = O32_RegisterClass((WNDCLASSA *)&wc.style);
343 if(rc) {
344 Win32WindowClass *wndclass = new Win32WindowClass((WNDPROC)lpWndClass->lpfnWndProc, (LPSTR)wc.lpszClassName, wc.hInstance);
345 }
346#ifdef DEBUG
347 WriteLog("USER32: RegisterClassExA, not completely supported, returned %d\n", rc);
348 if(rc == 0)
349 WriteLog("USER32: GetLastError returned %X\n", GetLastError());
350
351#endif
352 return(rc);
353}
354//******************************************************************************
355//******************************************************************************
356WORD WIN32API RegisterClassW(const WNDCLASSW *lpwc)
357{
358 ATOM rc;
359 WNDCLASSA wclass;
360
361 dprintf(("RegisterClassW\n"));
362 memcpy(&wclass, lpwc, sizeof(WNDCLASSA));
363 if(wclass.lpszMenuName && ((int)wclass.lpszMenuName >> 16 != 0)) {
364 wclass.lpszMenuName = UnicodeToAsciiString((LPWSTR)lpwc->lpszMenuName);
365 }
366 if(wclass.lpszClassName && ((int)wclass.lpszClassName >> 16 != 0)) {
367 wclass.lpszClassName = UnicodeToAsciiString((LPWSTR)lpwc->lpszClassName);
368 }
369
370 rc = RegisterClassA(&wclass);
371
372 //TODO: Assuming RegisterClass doesn't mess up our structure
373 if(lpwc->lpszMenuName && ((int)lpwc->lpszMenuName >> 16 != 0)) {
374 FreeAsciiString((char *)wclass.lpszMenuName);
375 }
376 if(lpwc->lpszClassName && ((int)lpwc->lpszClassName >> 16 != 0)) {
377 FreeAsciiString((char *)wclass.lpszClassName);
378 }
379 return(rc);
380}
381//******************************************************************************
382//******************************************************************************
383ATOM WIN32API RegisterClassExW(CONST WNDCLASSEXW *lpwc)
384{
385 ATOM rc;
386 WNDCLASSEXA wclass;
387
388 dprintf(("RegisterClassExW\n"));
389 memcpy(&wclass, lpwc, sizeof(WNDCLASSEXA));
390 if(wclass.lpszMenuName && ((int)wclass.lpszMenuName >> 16 != 0)) {
391 wclass.lpszMenuName = UnicodeToAsciiString((LPWSTR)lpwc->lpszMenuName);
392 }
393 if(wclass.lpszClassName && ((int)wclass.lpszClassName >> 16 != 0)) {
394 wclass.lpszClassName = UnicodeToAsciiString((LPWSTR)lpwc->lpszClassName);
395 }
396
397 rc = RegisterClassExA(&wclass);
398
399 //TODO: Assuming RegisterClassEx doesn't mess up our structure
400 if(lpwc->lpszMenuName && ((int)lpwc->lpszMenuName >> 16 != 0)) {
401 FreeAsciiString((char *)wclass.lpszMenuName);
402 }
403 if(lpwc->lpszClassName && ((int)lpwc->lpszClassName >> 16 != 0)) {
404 FreeAsciiString((char *)wclass.lpszClassName);
405 }
406 return(rc);
407}
408//******************************************************************************
409//******************************************************************************
410BOOL WIN32API UnregisterClassA(LPCSTR lpszClassName, HINSTANCE hinst)
411{
412 BOOL rc;
413
414 Win32WindowClass::UnregisterClass(hinst, (LPSTR)lpszClassName);
415 rc = O32_UnregisterClass(lpszClassName, hinst);
416 dprintf(("USER32: OS2UnregisterClassA returned %d\n", rc));
417
418 //Spintest returns FALSE in dll termination, so pretend it succeeded
419 return(TRUE);
420}
421//******************************************************************************
422//******************************************************************************
423BOOL WIN32API UnregisterClassW(LPCWSTR lpszClassName, HINSTANCE hinst)
424{
425 char *astring = NULL;
426 BOOL rc;
427
428 dprintf(("USER32: OS2UnregisterClassW\n"));
429 if((int)lpszClassName >> 16 != 0) {
430 astring = UnicodeToAsciiString((LPWSTR)lpszClassName);
431 }
432 else astring = (char *)lpszClassName;
433
434 Win32WindowClass::UnregisterClass(hinst, (LPSTR)astring);
435 rc = O32_UnregisterClass(astring, hinst);
436 if((int)astring >> 16 != 0) {
437 FreeAsciiString(astring);
438 }
439 //Spintest returns FALSE in dll termination, so pretend it succeeded
440 return(TRUE);
441}
442//******************************************************************************
443//******************************************************************************
444BOOL WIN32API GetClassInfoA(HINSTANCE arg1, LPCSTR arg2, WNDCLASSA * arg3)
445{
446 BOOL rc;
447
448 dprintf(("USER32: OS2GetClassInfoA\n"));
449 rc = O32_GetClassInfo(arg1, arg2, (WNDCLASSA *)arg3);
450 if(rc == TRUE) {
451 arg3->lpfnWndProc = (WNDPROC)Win32WindowClass::GetClassCallback((LPSTR)arg2);
452 }
453 return(rc);
454}
455//******************************************************************************
456//******************************************************************************
457BOOL WIN32API GetClassInfoW(HINSTANCE hinst,
458 LPCWSTR lpszClass,
459 WNDCLASSW *lpwc)
460{
461 WNDCLASSA wclass;
462 BOOL rc;
463 char *szClass = NULL;
464
465 dprintf(("USER32: OS2GetClassInfoW\n"));
466 if((int)lpszClass >> 16 != 0) {
467 szClass = UnicodeToAsciiString((LPWSTR)lpszClass);
468 dprintf(("USER32: OS2GetClassInfoW %s\n", szClass));
469 }
470 else szClass = (char *)lpszClass;
471
472 rc = GetClassInfoA(hinst, szClass, &wclass);
473 if(rc == TRUE) {
474 memcpy(lpwc, &wclass, sizeof(WNDCLASSA));
475 //TODO: Memory leak (create class object at RegisterClass and delete it at UnregisterClass)
476 if(lpwc->lpszMenuName && ((int)lpwc->lpszMenuName >> 16 != 0)) {
477 lpwc->lpszMenuName = (LPCWSTR)malloc(strlen(wclass.lpszMenuName)*sizeof(WCHAR)+2);
478 AsciiToUnicode((char *)wclass.lpszMenuName, (LPWSTR)lpwc->lpszMenuName);
479 }
480 if(lpwc->lpszClassName && ((int)lpwc->lpszClassName >> 16 != 0)) {
481 lpwc->lpszClassName = (LPCWSTR)malloc(strlen(wclass.lpszClassName)*sizeof(WCHAR)+2);
482 AsciiToUnicode((char *)wclass.lpszClassName, (LPWSTR)lpwc->lpszClassName);
483 }
484 }
485 dprintf(("USER32: OS2GetClassInfoW returned %d\n", rc));
486 return(rc);
487}
488/****************************************************************************
489 * Name : BOOL WIN32API GetClassInfoExA
490 * Purpose : The GetClassInfoEx function retrieves information about a window
491 * class, including the handle of the small icon associated with the
492 * window class. GetClassInfo does not retrieve the handle of the small icon.
493 * Parameters: HINSTANCE hinst handle of application instance
494 * LPCTSTR lpszClass address of class name string
495 * LPWNDCLASSEX lpwcx address of structure for class data
496 * Variables :
497 * Result : If the function finds a matching class and successfully copies
498 * the data, the return value is TRUE;
499 * otherwise, it is FALSE.
500 * To get extended error information, call GetLastError.
501 * Remark : PH: does not obtain handle of the small icon
502 * Status : UNTESTED STUB
503 *
504 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
505 *****************************************************************************/
506BOOL WIN32API GetClassInfoExA(HINSTANCE hInstance,
507 LPCTSTR lpszClass,
508 LPWNDCLASSEXA lpwcx)
509{
510 WNDCLASSA WndClass; /* structure for data transformation */
511 BOOL bResult; /* result of subsequent function calls */
512
513 dprintf(("USER32:GetClassInfoExA (%08xh,%s,%08x).\n",
514 hInstance,
515 lpszClass,
516 lpwcx));
517
518 /* convert the structures */
519 memcpy((PVOID)&WndClass,
520 (PVOID)&lpwcx->style,
521 sizeof(WndClass) );
522
523 bResult = GetClassInfoA(hInstance,
524 lpszClass,
525 (WNDCLASSA *)&WndClass);
526 if (bResult == TRUE)
527 {
528 /* convert data back to original structure */
529 memcpy((PVOID)&lpwcx->style,
530 (PVOID)&WndClass,
531 sizeof(WndClass) );
532 lpwcx->cbSize = sizeof(WNDCLASSEXA);
533 lpwcx->hIconSm = 0;
534 }
535
536 return (bResult);
537}
538/*****************************************************************************
539 * Name : BOOL WIN32API GetClassInfoExW
540 * Purpose : The GetClassInfoEx function retrieves information about a window
541 * class, including the handle of the small icon associated with the
542 * window class. GetClassInfo does not retrieve the handle of the small icon.
543 * Parameters: HINSTANCE hinst handle of application instance
544 * LPCWSTR lpszClass address of class name string
545 * LPWNDCLASSEX lpwcx address of structure for class data
546 * Variables :
547 * Result : If the function finds a matching class and successfully copies
548 * the data, the return value is TRUE;
549 * otherwise, it is FALSE.
550 * To get extended error information, call GetLastError.
551 * Remark : does not obtain handle of the small icon
552 * Status : UNTESTED STUB
553 *
554 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
555 *****************************************************************************/
556BOOL WIN32API GetClassInfoExW(HINSTANCE hInstance,
557 LPCWSTR lpszClass,
558 LPWNDCLASSEXW lpwcx)
559{
560 WNDCLASSW WndClass; /* structure for data transformation */
561 BOOL bResult; /* result of subsequent function calls */
562
563 dprintf(("USER32:GetClassInfoExW (%08xh,%s,%08x).\n",
564 hInstance,
565 lpszClass,
566 lpwcx));
567
568 /* convert the structures */
569 memcpy((PVOID)&WndClass,
570 (PVOID)&lpwcx->style,
571 sizeof(WndClass) );
572
573 bResult = GetClassInfoW(hInstance,
574 (LPWSTR)lpszClass,
575 (WNDCLASSW *)&WndClass);
576 if (bResult == TRUE)
577 {
578 /* convert data back to original structure */
579 memcpy((PVOID)&lpwcx->style,
580 (PVOID)&WndClass,
581 sizeof(WndClass) );
582 lpwcx->cbSize = sizeof(WNDCLASSEXW);
583 lpwcx->hIconSm = 0;
584 }
585
586 return (bResult);
587}
588//******************************************************************************
589//TODO: Not complete (unsupported extension in WNDCLASSEXA/W, unsupported styles etc)
590//******************************************************************************
591LONG WIN32API GetClassLongA(HWND hwnd, int nIndex)
592{
593 DWORD rc;
594
595 dprintf(("USER32: OS2GetClassLongA\n"));
596 rc = O32_GetClassLong(hwnd, nIndex);
597 if(nIndex == GCL_WNDPROC) {
598 char szClass[128];
599 Win32WindowClass *wclass;
600
601 if(GetClassNameA(hwnd, szClass, sizeof(szClass))) {
602 wclass = Win32WindowClass::FindClass(szClass);
603 if(wclass) {
604 return (LONG)wclass->GetWinCallback();
605 }
606 }
607 dprintf(("GetClassLongA, class of window %X not found\n", hwnd));
608 return 0; //TODO: set last error
609 }
610 return rc;
611}
612//******************************************************************************
613//******************************************************************************
614LONG WIN32API GetClassLongW(HWND hwnd, int nIndex)
615{
616 dprintf(("USER32: OS2GetClassLongW\n"));
617 if(nIndex == GCL_MENUNAME) { //TODO
618 dprintf(("USER32: Class Menu name not implemented yet\n"));
619 }
620 // NOTE: This will not work as is (needs UNICODE support)
621 return GetClassLongA(hwnd, nIndex);
622}
623//******************************************************************************
624//******************************************************************************
625int WIN32API GetClassNameA( HWND arg1, LPSTR arg2, int arg3)
626{
627 dprintf(("USER32: OS2GetClassNameA\n"));
628 return O32_GetClassName(arg1, arg2, arg3);
629}
630//******************************************************************************
631//******************************************************************************
632int WIN32API GetClassNameW(HWND hwnd, LPWSTR lpClassName, int nMaxCount)
633{
634 char *astring = (char *)malloc(nMaxCount);
635 int rc;
636
637 dprintf(("USER32: OS2GetClassNameW\n"));
638 rc = GetClassNameA(hwnd, astring, nMaxCount);
639 AsciiToUnicode(astring, lpClassName);
640 free(astring);
641 return(rc);
642}
643//******************************************************************************
644//******************************************************************************
645WORD WIN32API GetClassWord( HWND arg1, int arg2)
646{
647 dprintf(("USER32: OS2GetClassWord\n"));
648 return O32_GetClassWord(arg1, arg2);
649}
650//******************************************************************************
651//******************************************************************************
652LONG WIN32API SetClassLongA(HWND hwnd, int nIndex, LONG lNewVal)
653{
654 DWORD rc;
655
656 dprintf(("USER32: OS2SetClassLongA\n"));
657 if(nIndex == GCL_WNDPROC) {
658 char szClass[128];
659 Win32WindowClass *wclass;
660
661 if(GetClassNameA(hwnd, szClass, sizeof(szClass))) {
662 wclass = Win32WindowClass::FindClass(szClass);
663 if(wclass) {
664 rc = (DWORD)wclass->GetWinCallback();
665 wclass->SetWinCallback((WNDPROC)lNewVal);
666 return rc;
667 }
668 }
669 dprintf(("SetClassLongA, class of window %X not found\n", hwnd));
670 return 0; //TODO: set last error
671 }
672 return O32_SetClassLong(hwnd, nIndex, lNewVal);
673}
674//******************************************************************************
675//******************************************************************************
676LONG WIN32API SetClassLongW( HWND arg1, int arg2, LONG arg3)
677{
678 dprintf(("USER32: OS2SetClassLongW\n"));
679 // NOTE: This will not work as is (needs UNICODE support)
680 return O32_SetClassLong(arg1, arg2, arg3);
681}
682//******************************************************************************
683//******************************************************************************
684WORD WIN32API SetClassWord( HWND arg1, int arg2, WORD arg3)
685{
686 dprintf(("USER32: OS2SetClassWord\n"));
687 return O32_SetClassWord(arg1, arg2, arg3);
688}
689//******************************************************************************
690//Win32WindowClass methods:
691//******************************************************************************
692Win32WindowClass::Win32WindowClass(WNDPROC pUserCallback, LPSTR id, HINSTANCE hinst)
693{
694 //Insert it in front of the rest
695 next = wndclasses;
696 wndclasses = this;
697 if((int)id >> 16 != 0) {
698 strcpy(className, id);
699 classAtom = 0;
700 }
701 else {
702 className[0] = 0;
703 classAtom = (DWORD)id;
704 }
705 this->hinst = hinst;
706
707 pWinCallback = pUserCallback;
708 dprintf(("Win32WindowClass::Win32WindowClass %d\n", id));
709}
710//******************************************************************************
711//******************************************************************************
712Win32WindowClass::~Win32WindowClass()
713{
714 Win32WindowClass *wndclass = Win32WindowClass::wndclasses;
715
716 if(wndclass == this) {
717 wndclasses = next;
718 }
719 else {
720 while(wndclass->next != NULL) {
721 if(wndclass->next == this) {
722 wndclass->next = next;
723 break;
724 }
725 wndclass = wndclass->next;
726 }
727 }
728}
729//******************************************************************************
730//******************************************************************************
731Win32WindowClass *Win32WindowClass::FindClass(LPSTR id)
732{
733 Win32WindowClass *wndclass = wndclasses;
734
735 if(wndclass == NULL) return(NULL);
736
737 if((int)id >> 16 != 0) {
738 if(stricmp(wndclass->className, id) == 0) {
739 return(wndclass);
740 }
741 else {
742 wndclass = wndclass->next;
743 while(wndclass != NULL) {
744 if(stricmp(wndclass->className, id) == 0) {
745 return(wndclass);
746 }
747 wndclass = wndclass->next;
748 }
749 }
750 }
751 else {
752 if(wndclass->classAtom == (DWORD)id) {
753 return(wndclass);
754 }
755 else {
756 wndclass = wndclass->next;
757 while(wndclass != NULL) {
758 if(wndclass->classAtom == (DWORD)id) {
759 return(wndclass);
760 }
761 wndclass = wndclass->next;
762 }
763 }
764 }
765 return(NULL);
766}
767//******************************************************************************
768//******************************************************************************
769void Win32WindowClass::UnregisterClass(HINSTANCE hinst, LPSTR id)
770{
771 Win32WindowClass *wndclass;
772
773 dprintf(("::UnregisterClass, destroy class %X!!\n", id));
774 wndclass = FindClass(id);
775 if(wndclass && wndclass->hinst == hinst) {
776 delete wndclass;
777 return;
778 }
779 dprintf(("::UnregisterClass, couldn't find class %X!!\n", id));
780}
781//******************************************************************************
782//******************************************************************************
783WNDPROC Win32WindowClass::GetClassCallback(HINSTANCE hinst, LPSTR id)
784{
785 Win32WindowClass *wndclass;
786
787 wndclass = FindClass(id);
788 if(wndclass && wndclass->hinst == hinst) {
789 return wndclass->pWinCallback;
790 }
791 dprintf(("::GetClassCallback, couldn't find class %X!!\n", id));
792 return(NULL);
793}
794//******************************************************************************
795//******************************************************************************
796WNDPROC Win32WindowClass::GetClassCallback(LPSTR id)
797{
798 Win32WindowClass *wndclass;
799
800 wndclass = FindClass(id);
801 if(wndclass) {
802 return wndclass->pWinCallback;
803 }
804 dprintf(("::GetClassCallback2, couldn't find class %X!!\n", id));
805 return(NULL);
806}
807//******************************************************************************
808//******************************************************************************
809WNDPROC_O32 Win32WindowClass::GetOS2ClassCallback()
810{
811 return OS2ToWinCallback;
812}
813//******************************************************************************
814//******************************************************************************
815LRESULT EXPENTRY_O32 OS2ToWinCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
816{
817 char szClass[128];
818 Win32WindowClass *wclass;
819 LRESULT rc;
820 DWORD dwStyle, dwExStyle;
821 HWND parentHwnd;
822 Win32WindowProc *window;
823
824 if(Msg == WM_MOUSEACTIVATE)
825 {
826 //Open32 sends an OS/2 window message for a button click
827 if(HIWORD(lParam) == 0x71) //WM_BUTTONCLICKFIRST
828 {
829 lParam = (WM_LBUTTONDOWN << 16) | LOWORD(lParam);
830 }
831 }
832 if(PostSpyMessage(hwnd, Msg, wParam, lParam) == FALSE)
833 dprintf(("OS2ToWinCallback %s for %x %x %x", GetMsgText(Msg), hwnd, wParam, lParam));
834
835 if(HkCBT::OS2HkCBTProc(hwnd, Msg, wParam, lParam) == TRUE) {//hook swallowed msg
836 return(0);
837 }
838
839 if(O32_GetClassName(hwnd, szClass, sizeof(szClass))) {
840 wclass = Win32WindowClass::FindClass(szClass);
841 if(wclass) {
842 switch(Msg)
843 {
844 case WM_CREATE://Open32 isn't sending WM_NCCREATE messages!!
845 window = Win32WindowProc::FindProc(hwnd, GetCurrentThreadId());
846 if(window) {
847 dprintf(("OS2ToWinCallback (class): New window object!"));
848 window->SetWindowHandle(hwnd);
849 }
850
851 if(wclass->GetWinCallback()(hwnd, WM_NCCREATE, 0, lParam) == 0) {
852 dprintf(("WM_NCCREATE returned FALSE\n"));
853 return(-1); //don't create window
854 }
855 //Send WM_CREATE message before notifying parent
856 rc = wclass->GetWinCallback()(hwnd, Msg, wParam, lParam);
857
858 NotifyParent(hwnd, WM_CREATE, wParam, lParam);
859 return(rc);
860
861 case WM_DESTROY: //nofity parent
862 case WM_LBUTTONDOWN:
863 case WM_MBUTTONDOWN:
864 case WM_RBUTTONDOWN:
865 NotifyParent(hwnd, Msg, wParam, lParam);
866 break;
867
868 case WM_KEYDOWN:
869 case WM_KEYUP:
870 case WM_CHAR: //SvL: Correct Open32 key mapping bug
871 //TODO: Not good enough, look at Wine
872 lParam = MapOEMToRealKey(wParam, lParam);
873 break;
874
875 case WM_ACTIVATE:
876 if(LOWORD(wParam) != WA_INACTIVE)
877 {
878 //EB: I think the problem is not a missing wm_erasebkgnd.
879 //Maybe some wrong flags in open32 during async repainting.
880 RECT rect;
881 HRGN hrgn;
882 HDC hdc = GetDC(hwnd);
883
884 // erase the dirty rect
885 GetUpdateRect(hwnd, &rect, TRUE);
886 hrgn = CreateRectRgnIndirect(&rect);
887 SelectClipRgn (hdc, hrgn);
888 DeleteObject (hrgn);
889 wclass->GetWinCallback()(hwnd, WM_ERASEBKGND, hdc, (LPARAM)&rect);
890 SelectClipRgn (hdc, NULL);
891 ReleaseDC(hwnd, hdc);
892 }
893 break;
894 }
895 return wclass->GetWinCallback()(hwnd, Msg, wParam, lParam);
896 }
897 }
898 dprintf(("OS2ToWinCallback: couldn't find class procedure of window %X\n", hwnd));
899 return(0);
900}
901//******************************************************************************
902//******************************************************************************
903LRESULT WIN32API WinToOS2Callback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
904{
905 WNDPROC_O32 os2callback;
906
907 os2callback = (WNDPROC_O32)GetClassLongA(hwnd, GCL_WNDPROC);
908 if(os2callback) {
909 return os2callback(hwnd, Msg, wParam, lParam);
910 }
911 dprintf(("OS2ToWinCallback: window procedure == NULL!!\n"));
912 return(0);
913}
914//******************************************************************************
915//******************************************************************************
916Win32WindowClass *Win32WindowClass::wndclasses = NULL;
Note: See TracBrowser for help on using the repository browser.