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

Last change on this file since 96 was 96, checked in by phaller, 26 years ago

Add: added cvs variable $Id$ to source files.

File size: 28.4 KB
Line 
1/* $Id: wndclass.cpp,v 1.3 1999-06-10 16:50:37 phaller 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 <assert.h>
19#include "misc.h"
20#include "user32.h"
21#include "wndproc.h"
22#include "wndclass.h"
23#include "hooks.h"
24
25//default window handlers that are registered by RegisterClass are called
26//in this callback handler
27LRESULT EXPENTRY_O32 OS2ToWinCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam);
28//default window handlers that are queried by GetClassInfo/GetClassLong is really
29//this callback handler
30LRESULT WIN32API WinToOS2Callback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam);
31
32#ifdef DEBUG
33char *GetMsgText(int Msg);
34#endif
35
36DWORD MapOEMToRealKey(DWORD wParam, DWORD lParam);
37
38WNDPROC_O32 ButtonHandler = 0;
39WNDPROC_O32 ListboxHandler = 0;
40WNDPROC_O32 ComboboxHandler = 0;
41WNDPROC_O32 EditHandler = 0;
42WNDPROC_O32 MdiClientHandler = 0;
43WNDPROC_O32 ScrollbarHandler = 0;
44WNDPROC_O32 StaticHandler = 0;
45//******************************************************************************
46//******************************************************************************
47LRESULT WIN32API ButtonCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
48{
49 return ButtonHandler(hwnd, Msg, wParam, lParam);
50}
51//******************************************************************************
52//******************************************************************************
53LRESULT WIN32API ListboxCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
54{
55 return ListboxHandler(hwnd, Msg, wParam, lParam);
56}
57//******************************************************************************
58//******************************************************************************
59LRESULT WIN32API ComboboxCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
60{
61 return ComboboxHandler(hwnd, Msg, wParam, lParam);
62}
63//******************************************************************************
64//******************************************************************************
65LRESULT WIN32API MdiClientCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
66{
67 return MdiClientHandler(hwnd, Msg, wParam, lParam);
68}
69//******************************************************************************
70//******************************************************************************
71LRESULT WIN32API EditCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
72{
73 return EditHandler(hwnd, Msg, wParam, lParam);
74}
75//******************************************************************************
76//******************************************************************************
77LRESULT WIN32API ScrollbarCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
78{
79 return ScrollbarHandler(hwnd, Msg, wParam, lParam);
80}
81//******************************************************************************
82//******************************************************************************
83LRESULT WIN32API StaticCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
84{
85 return StaticHandler(hwnd, Msg, wParam, lParam);
86}
87//******************************************************************************
88//SvL: 18-7-'98, Registers system window classes (button, listbox etc etc)
89//******************************************************************************
90void RegisterSystemClasses(ULONG hModule)
91{
92 WNDCLASSA wndclass;
93
94 if(O32_GetClassInfo(NULL, "BUTTON", &wndclass)) {
95 new Win32WindowClass(ButtonCallback, "BUTTON", hModule);
96 ButtonHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
97 }
98 if(O32_GetClassInfo(NULL, "LISTBOX", &wndclass)) {
99 new Win32WindowClass(ListboxCallback, "LISTBOX", hModule);
100 ListboxHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
101 }
102 if(O32_GetClassInfo(NULL, "COMBOBOX", &wndclass)) {
103 new Win32WindowClass(ComboboxCallback, "COMBOBOX", hModule);
104 ComboboxHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
105 }
106 if(O32_GetClassInfo(NULL, "EDIT", &wndclass)) {
107 new Win32WindowClass(EditCallback, "EDIT", hModule);
108 EditHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
109 }
110 if(O32_GetClassInfo(NULL, "MDICLIENT", &wndclass)) {
111 new Win32WindowClass(MdiClientCallback, "MDICLIENT", hModule);
112 MdiClientHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
113 }
114 if(O32_GetClassInfo(NULL, "SCROLLBAR", &wndclass)) {
115 new Win32WindowClass(ScrollbarCallback, "SCROLLBAR", hModule);
116 ScrollbarHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
117 }
118 if(O32_GetClassInfo(NULL, "STATIC", &wndclass)) {
119 new Win32WindowClass(StaticCallback, "STATIC", hModule);
120 StaticHandler = (WNDPROC_O32)wndclass.lpfnWndProc;
121 }
122//TODO: More standard classes in win95/NT4?
123}
124//******************************************************************************
125//SvL: 18-7-'98: Moved here from user32.cpp
126//******************************************************************************
127ATOM WIN32API RegisterClassA(const WNDCLASSA *lpWndClass)
128{
129 ATOM rc;
130 WNDCLASSA wc;
131
132#ifdef DEBUG
133 WriteLog("USER32: RegisterClassA\n");
134 WriteLog("USER32: lpWndClass->style %X\n", lpWndClass->style);
135 WriteLog("USER32: lpWndClass->lpfnWndProc %X\n", lpWndClass->lpfnWndProc);
136 WriteLog("USER32: lpWndClass->cbClsExtra %X\n", lpWndClass->cbClsExtra);
137 WriteLog("USER32: lpWndClass->cbWndExtra %X\n", lpWndClass->cbWndExtra);
138 WriteLog("USER32: lpWndClass->hInstance %X\n", lpWndClass->hInstance);
139 WriteLog("USER32: lpWndClass->hIcon %X\n", lpWndClass->hIcon);
140 WriteLog("USER32: lpWndClass->hCursor %X\n", lpWndClass->hCursor);
141 WriteLog("USER32: lpWndClass->hbrBackground %X\n", lpWndClass->hbrBackground);
142 WriteLog("USER32: lpWndClass->lpszMenuName %X\n", lpWndClass->lpszMenuName);
143 if((int)lpWndClass->lpszClassName >> 16 == 0)
144 WriteLog("USER32: lpWndClass->lpszClassName %X\n", lpWndClass->lpszClassName);
145 else WriteLog("USER32: lpWndClass->lpszClassName %s\n", lpWndClass->lpszClassName);
146#endif
147 memcpy(&wc, lpWndClass, sizeof(WNDCLASSA));
148
149 if((int)wc.lpszMenuName >> 16 != 0) {//convert string name identifier to numeric id
150 dprintf(("USER32: lpszMenuName %s\n", wc.lpszMenuName));
151 *(int *)&wc.lpszMenuName = ConvertNameId(0, (char *)wc.lpszMenuName);
152 dprintf(("USER32: Menu id = %d\n", (int)wc.lpszMenuName));
153 }
154#ifdef DEBUG
155 if(wc.style & (CS_PARENTDC | CS_CLASSDC)) {
156 dprintf(("USER32: Class uses an unsupported style!!!\n"));
157 }
158#endif
159 //These are not supported by Open32
160 wc.style &= ~(CS_PARENTDC | CS_CLASSDC);
161
162//SvL: 18-7-'98 Breaks apps (solitaire, rasmol..)
163#if 0
164 /* @@@PH 98/06/21 experimental fix for WInhlp32 */
165#ifndef CS_SYNCPAINT
166 #define CS_SYNCPAINT 0x02000000L
167#endif
168
169 wc.style |= CS_SYNCPAINT;
170#endif
171
172 wc.lpfnWndProc = (WNDPROC)Win32WindowClass::GetOS2ClassCallback();
173 rc = O32_RegisterClass(&wc);
174 if(rc) {
175 Win32WindowClass *wndclass = new Win32WindowClass((WNDPROC)lpWndClass->lpfnWndProc, (LPSTR)wc.lpszClassName, wc.hInstance);
176 }
177 dprintf(("USER32: RegisterClass returned %d (%d)\n", rc, GetLastError()));
178 return(rc);
179}
180//******************************************************************************
181//SvL: 18-7-'98: Moved here from user32.cpp
182//******************************************************************************
183ATOM WIN32API RegisterClassExA(const WNDCLASSEXA *lpWndClass)
184{
185 ATOM rc;
186 WNDCLASSEXA wc;
187
188#ifdef DEBUG
189 WriteLog("USER32: lpWndClass->cbSize %X\n", lpWndClass->cbSize);
190 WriteLog("USER32: lpWndClass->style %X\n", lpWndClass->style);
191 WriteLog("USER32: lpWndClass->lpfnWndProc %X\n", lpWndClass->lpfnWndProc);
192 WriteLog("USER32: lpWndClass->cbClsExtra %X\n", lpWndClass->cbClsExtra);
193 WriteLog("USER32: lpWndClass->cbWndExtra %X\n", lpWndClass->cbWndExtra);
194 WriteLog("USER32: lpWndClass->hInstance %X\n", lpWndClass->hInstance);
195 WriteLog("USER32: lpWndClass->hIcon %X\n", lpWndClass->hIcon);
196 WriteLog("USER32: lpWndClass->hCursor %X\n", lpWndClass->hCursor);
197 WriteLog("USER32: lpWndClass->hbrBackground %X\n", lpWndClass->hbrBackground);
198 WriteLog("USER32: lpWndClass->lpszMenuName %X\n", lpWndClass->lpszMenuName);
199 if((int)lpWndClass->lpszClassName >> 16 == 0)
200 WriteLog("USER32: lpWndClass->lpszClassName %X\n", lpWndClass->lpszClassName);
201 else WriteLog("USER32: lpWndClass->lpszClassName %s\n", lpWndClass->lpszClassName);
202#endif
203 memcpy(&wc, lpWndClass, sizeof(WNDCLASSEXA));
204
205 if((int)wc.lpszMenuName >> 16 != 0) {//convert string name identifier to numeric id
206 dprintf(("USER32: lpszMenuName %s\n", wc.lpszMenuName));
207 *(int *)&wc.lpszMenuName = ConvertNameId(0, (char *)wc.lpszMenuName);
208 dprintf(("USER32: Menu id = %d\n", (int)wc.lpszMenuName));
209 }
210 if(wc.cbSize != sizeof(WNDCLASSEXA))
211 return(0);
212
213#ifdef DEBUG
214 if(wc.style & (CS_PARENTDC | CS_CLASSDC)) {
215 dprintf(("USER32: Class uses an unsupported style!!!\n"));
216 }
217#endif
218 //These are not supported by Open32
219 wc.style &= ~(CS_PARENTDC | CS_CLASSDC);
220
221//SvL: 18-7-'98 Breaks apps (solitaire, rasmol..)
222#if 0
223 /* @@@PH 98/06/21 experimental fix for WInhlp32 */
224#ifndef CS_SYNCPAINT
225 #define CS_SYNCPAINT 0x02000000L
226#endif
227
228 wc.style |= CS_SYNCPAINT;
229#endif
230
231 wc.lpfnWndProc = (WNDPROC)Win32WindowClass::GetOS2ClassCallback();
232
233 rc = O32_RegisterClass((WNDCLASSA *)&wc.style);
234 if(rc) {
235 Win32WindowClass *wndclass = new Win32WindowClass((WNDPROC)lpWndClass->lpfnWndProc, (LPSTR)wc.lpszClassName, wc.hInstance);
236 }
237#ifdef DEBUG
238 WriteLog("USER32: RegisterClassExA, not completely supported, returned %d\n", rc);
239 if(rc == 0)
240 WriteLog("USER32: GetLastError returned %X\n", GetLastError());
241
242#endif
243 return(rc);
244}
245//******************************************************************************
246//******************************************************************************
247WORD WIN32API RegisterClassW(const WNDCLASSW *lpwc)
248{
249 ATOM rc;
250 WNDCLASSA wclass;
251
252 dprintf(("RegisterClassW\n"));
253 memcpy(&wclass, lpwc, sizeof(WNDCLASSA));
254 if(wclass.lpszMenuName && ((int)wclass.lpszMenuName >> 16 != 0)) {
255 wclass.lpszMenuName = UnicodeToAsciiString((LPWSTR)lpwc->lpszMenuName);
256 }
257 if(wclass.lpszClassName && ((int)wclass.lpszClassName >> 16 != 0)) {
258 wclass.lpszClassName = UnicodeToAsciiString((LPWSTR)lpwc->lpszClassName);
259 }
260
261 rc = RegisterClassA(&wclass);
262
263 //TODO: Assuming RegisterClass doesn't mess up our structure
264 if(lpwc->lpszMenuName && ((int)lpwc->lpszMenuName >> 16 != 0)) {
265 FreeAsciiString((char *)wclass.lpszMenuName);
266 }
267 if(lpwc->lpszClassName && ((int)lpwc->lpszClassName >> 16 != 0)) {
268 FreeAsciiString((char *)wclass.lpszClassName);
269 }
270 return(rc);
271}
272//******************************************************************************
273//******************************************************************************
274ATOM WIN32API RegisterClassExW(CONST WNDCLASSEXW *lpwc)
275{
276 ATOM rc;
277 WNDCLASSEXA wclass;
278
279 dprintf(("RegisterClassExW\n"));
280 memcpy(&wclass, lpwc, sizeof(WNDCLASSEXA));
281 if(wclass.lpszMenuName && ((int)wclass.lpszMenuName >> 16 != 0)) {
282 wclass.lpszMenuName = UnicodeToAsciiString((LPWSTR)lpwc->lpszMenuName);
283 }
284 if(wclass.lpszClassName && ((int)wclass.lpszClassName >> 16 != 0)) {
285 wclass.lpszClassName = UnicodeToAsciiString((LPWSTR)lpwc->lpszClassName);
286 }
287
288 rc = RegisterClassExA(&wclass);
289
290 //TODO: Assuming RegisterClassEx doesn't mess up our structure
291 if(lpwc->lpszMenuName && ((int)lpwc->lpszMenuName >> 16 != 0)) {
292 FreeAsciiString((char *)wclass.lpszMenuName);
293 }
294 if(lpwc->lpszClassName && ((int)lpwc->lpszClassName >> 16 != 0)) {
295 FreeAsciiString((char *)wclass.lpszClassName);
296 }
297 return(rc);
298}
299//******************************************************************************
300//******************************************************************************
301BOOL WIN32API UnregisterClassA(LPCSTR lpszClassName, HINSTANCE hinst)
302{
303 BOOL rc;
304
305 Win32WindowClass::UnregisterClass(hinst, (LPSTR)lpszClassName);
306 rc = O32_UnregisterClass(lpszClassName, hinst);
307 dprintf(("USER32: OS2UnregisterClassA returned %d\n", rc));
308
309 //Spintest returns FALSE in dll termination, so pretend it succeeded
310 return(TRUE);
311}
312//******************************************************************************
313//******************************************************************************
314BOOL WIN32API UnregisterClassW(LPCWSTR lpszClassName, HINSTANCE hinst)
315{
316 char *astring = NULL;
317 BOOL rc;
318
319 dprintf(("USER32: OS2UnregisterClassW\n"));
320 if((int)lpszClassName >> 16 != 0) {
321 astring = UnicodeToAsciiString((LPWSTR)lpszClassName);
322 }
323 else astring = (char *)lpszClassName;
324
325 Win32WindowClass::UnregisterClass(hinst, (LPSTR)astring);
326 rc = O32_UnregisterClass(astring, hinst);
327 if((int)astring >> 16 != 0) {
328 FreeAsciiString(astring);
329 }
330 //Spintest returns FALSE in dll termination, so pretend it succeeded
331 return(TRUE);
332}
333//******************************************************************************
334//******************************************************************************
335BOOL WIN32API GetClassInfoA(HINSTANCE arg1, LPCSTR arg2, WNDCLASSA * arg3)
336{
337 BOOL rc;
338
339 dprintf(("USER32: OS2GetClassInfoA\n"));
340 rc = O32_GetClassInfo(arg1, arg2, (WNDCLASSA *)arg3);
341 if(rc == TRUE) {
342 arg3->lpfnWndProc = (WNDPROC)Win32WindowClass::GetClassCallback((LPSTR)arg2);
343 }
344 return(rc);
345}
346//******************************************************************************
347//******************************************************************************
348BOOL WIN32API GetClassInfoW(HINSTANCE hinst,
349 LPCWSTR lpszClass,
350 WNDCLASSW *lpwc)
351{
352 WNDCLASSA wclass;
353 BOOL rc;
354 char *szClass = NULL;
355
356 dprintf(("USER32: OS2GetClassInfoW\n"));
357 if((int)lpszClass >> 16 != 0) {
358 szClass = UnicodeToAsciiString((LPWSTR)lpszClass);
359 dprintf(("USER32: OS2GetClassInfoW %s\n", szClass));
360 }
361 else szClass = (char *)lpszClass;
362
363 rc = GetClassInfoA(hinst, szClass, &wclass);
364 if(rc == TRUE) {
365 memcpy(lpwc, &wclass, sizeof(WNDCLASSA));
366 //TODO: Memory leak (create class object at RegisterClass and delete it at UnregisterClass)
367 if(lpwc->lpszMenuName && ((int)lpwc->lpszMenuName >> 16 != 0)) {
368 lpwc->lpszMenuName = (LPCWSTR)malloc(strlen(wclass.lpszMenuName)*sizeof(WCHAR)+2);
369 AsciiToUnicode((char *)wclass.lpszMenuName, (LPWSTR)lpwc->lpszMenuName);
370 }
371 if(lpwc->lpszClassName && ((int)lpwc->lpszClassName >> 16 != 0)) {
372 lpwc->lpszClassName = (LPCWSTR)malloc(strlen(wclass.lpszClassName)*sizeof(WCHAR)+2);
373 AsciiToUnicode((char *)wclass.lpszClassName, (LPWSTR)lpwc->lpszClassName);
374 }
375 }
376 dprintf(("USER32: OS2GetClassInfoW returned %d\n", rc));
377 return(rc);
378}
379/****************************************************************************
380 * Name : BOOL WIN32API GetClassInfoExA
381 * Purpose : The GetClassInfoEx function retrieves information about a window
382 * class, including the handle of the small icon associated with the
383 * window class. GetClassInfo does not retrieve the handle of the small icon.
384 * Parameters: HINSTANCE hinst handle of application instance
385 * LPCTSTR lpszClass address of class name string
386 * LPWNDCLASSEX lpwcx address of structure for class data
387 * Variables :
388 * Result : If the function finds a matching class and successfully copies
389 * the data, the return value is TRUE;
390 * otherwise, it is FALSE.
391 * To get extended error information, call GetLastError.
392 * Remark : PH: does not obtain handle of the small icon
393 * Status : UNTESTED STUB
394 *
395 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
396 *****************************************************************************/
397BOOL WIN32API GetClassInfoExA(HINSTANCE hInstance,
398 LPCTSTR lpszClass,
399 LPWNDCLASSEXA lpwcx)
400{
401 WNDCLASSA WndClass; /* structure for data transformation */
402 BOOL bResult; /* result of subsequent function calls */
403
404 dprintf(("USER32:GetClassInfoExA (%08xh,%s,%08x).\n",
405 hInstance,
406 lpszClass,
407 lpwcx));
408
409 /* convert the structures */
410 memcpy((PVOID)&WndClass,
411 (PVOID)&lpwcx->style,
412 sizeof(WndClass) );
413
414 bResult = GetClassInfoA(hInstance,
415 lpszClass,
416 (WNDCLASSA *)&WndClass);
417 if (bResult == TRUE)
418 {
419 /* convert data back to original structure */
420 memcpy((PVOID)&lpwcx->style,
421 (PVOID)&WndClass,
422 sizeof(WndClass) );
423 lpwcx->cbSize = sizeof(WNDCLASSEXA);
424 lpwcx->hIconSm = 0;
425 }
426
427 return (bResult);
428}
429/*****************************************************************************
430 * Name : BOOL WIN32API GetClassInfoExW
431 * Purpose : The GetClassInfoEx function retrieves information about a window
432 * class, including the handle of the small icon associated with the
433 * window class. GetClassInfo does not retrieve the handle of the small icon.
434 * Parameters: HINSTANCE hinst handle of application instance
435 * LPCWSTR lpszClass address of class name string
436 * LPWNDCLASSEX lpwcx address of structure for class data
437 * Variables :
438 * Result : If the function finds a matching class and successfully copies
439 * the data, the return value is TRUE;
440 * otherwise, it is FALSE.
441 * To get extended error information, call GetLastError.
442 * Remark : does not obtain handle of the small icon
443 * Status : UNTESTED STUB
444 *
445 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
446 *****************************************************************************/
447BOOL WIN32API GetClassInfoExW(HINSTANCE hInstance,
448 LPCWSTR lpszClass,
449 LPWNDCLASSEXW lpwcx)
450{
451 WNDCLASSW WndClass; /* structure for data transformation */
452 BOOL bResult; /* result of subsequent function calls */
453
454 dprintf(("USER32:GetClassInfoExW (%08xh,%s,%08x).\n",
455 hInstance,
456 lpszClass,
457 lpwcx));
458
459 /* convert the structures */
460 memcpy((PVOID)&WndClass,
461 (PVOID)&lpwcx->style,
462 sizeof(WndClass) );
463
464 bResult = GetClassInfoW(hInstance,
465 (LPWSTR)lpszClass,
466 (WNDCLASSW *)&WndClass);
467 if (bResult == TRUE)
468 {
469 /* convert data back to original structure */
470 memcpy((PVOID)&lpwcx->style,
471 (PVOID)&WndClass,
472 sizeof(WndClass) );
473 lpwcx->cbSize = sizeof(WNDCLASSEXW);
474 lpwcx->hIconSm = 0;
475 }
476
477 return (bResult);
478}
479//******************************************************************************
480//TODO: Not complete (unsupported extension in WNDCLASSEXA/W, unsupported styles etc)
481//******************************************************************************
482LONG WIN32API GetClassLongA(HWND hwnd, int nIndex)
483{
484 DWORD rc;
485
486 dprintf(("USER32: OS2GetClassLongA\n"));
487 rc = O32_GetClassLong(hwnd, nIndex);
488 if(nIndex == GCL_WNDPROC) {
489 char szClass[128];
490 Win32WindowClass *wclass;
491
492 if(GetClassNameA(hwnd, szClass, sizeof(szClass))) {
493 wclass = Win32WindowClass::FindClass(szClass);
494 if(wclass) {
495 return (LONG)wclass->GetWinCallback();
496 }
497 }
498 dprintf(("GetClassLongA, class of window %X not found\n", hwnd));
499 return 0; //TODO: set last error
500 }
501 return rc;
502}
503//******************************************************************************
504//******************************************************************************
505LONG WIN32API GetClassLongW(HWND hwnd, int nIndex)
506{
507 dprintf(("USER32: OS2GetClassLongW\n"));
508 if(nIndex == GCL_MENUNAME) { //TODO
509 dprintf(("USER32: Class Menu name not implemented yet\n"));
510 }
511 // NOTE: This will not work as is (needs UNICODE support)
512 return GetClassLongA(hwnd, nIndex);
513}
514//******************************************************************************
515//******************************************************************************
516int WIN32API GetClassNameA( HWND arg1, LPSTR arg2, int arg3)
517{
518 dprintf(("USER32: OS2GetClassNameA\n"));
519 return O32_GetClassName(arg1, arg2, arg3);
520}
521//******************************************************************************
522//******************************************************************************
523int WIN32API GetClassNameW(HWND hwnd, LPWSTR lpClassName, int nMaxCount)
524{
525 char *astring = (char *)malloc(nMaxCount);
526 int rc;
527
528 dprintf(("USER32: OS2GetClassNameW\n"));
529 rc = GetClassNameA(hwnd, astring, nMaxCount);
530 AsciiToUnicode(astring, lpClassName);
531 free(astring);
532 return(rc);
533}
534//******************************************************************************
535//******************************************************************************
536WORD WIN32API GetClassWord( HWND arg1, int arg2)
537{
538 dprintf(("USER32: OS2GetClassWord\n"));
539 return O32_GetClassWord(arg1, arg2);
540}
541//******************************************************************************
542//******************************************************************************
543LONG WIN32API SetClassLongA(HWND hwnd, int nIndex, LONG lNewVal)
544{
545 DWORD rc;
546
547 dprintf(("USER32: OS2SetClassLongA\n"));
548 if(nIndex == GCL_WNDPROC) {
549 char szClass[128];
550 Win32WindowClass *wclass;
551
552 if(GetClassNameA(hwnd, szClass, sizeof(szClass))) {
553 wclass = Win32WindowClass::FindClass(szClass);
554 if(wclass) {
555 rc = (DWORD)wclass->GetWinCallback();
556 wclass->SetWinCallback((WNDPROC)lNewVal);
557 return rc;
558 }
559 }
560 dprintf(("SetClassLongA, class of window %X not found\n", hwnd));
561 return 0; //TODO: set last error
562 }
563 return O32_SetClassLong(hwnd, nIndex, lNewVal);
564}
565//******************************************************************************
566//******************************************************************************
567LONG WIN32API SetClassLongW( HWND arg1, int arg2, LONG arg3)
568{
569 dprintf(("USER32: OS2SetClassLongW\n"));
570 // NOTE: This will not work as is (needs UNICODE support)
571 return O32_SetClassLong(arg1, arg2, arg3);
572}
573//******************************************************************************
574//******************************************************************************
575WORD WIN32API SetClassWord( HWND arg1, int arg2, WORD arg3)
576{
577 dprintf(("USER32: OS2SetClassWord\n"));
578 return O32_SetClassWord(arg1, arg2, arg3);
579}
580//******************************************************************************
581//Win32WindowClass methods:
582//******************************************************************************
583Win32WindowClass::Win32WindowClass(WNDPROC pUserCallback, LPSTR id, HINSTANCE hinst)
584{
585 //Insert it in front of the rest
586 next = wndclasses;
587 wndclasses = this;
588 if((int)id >> 16 != 0) {
589 strcpy(className, id);
590 classAtom = 0;
591 }
592 else {
593 className[0] = 0;
594 classAtom = (DWORD)id;
595 }
596 this->hinst = hinst;
597
598 pWinCallback = pUserCallback;
599 dprintf(("Win32WindowClass::Win32WindowClass %d\n", id));
600}
601//******************************************************************************
602//******************************************************************************
603Win32WindowClass::~Win32WindowClass()
604{
605 Win32WindowClass *wndclass = Win32WindowClass::wndclasses;
606
607 if(wndclass == this) {
608 wndclasses = next;
609 }
610 else {
611 while(wndclass->next != NULL) {
612 if(wndclass->next == this) {
613 wndclass->next = next;
614 break;
615 }
616 wndclass = wndclass->next;
617 }
618 }
619}
620//******************************************************************************
621//******************************************************************************
622Win32WindowClass *Win32WindowClass::FindClass(LPSTR id)
623{
624 Win32WindowClass *wndclass = wndclasses;
625
626 if(wndclass == NULL) return(NULL);
627
628 if((int)id >> 16 != 0) {
629 if(stricmp(wndclass->className, id) == 0) {
630 return(wndclass);
631 }
632 else {
633 wndclass = wndclass->next;
634 while(wndclass != NULL) {
635 if(stricmp(wndclass->className, id) == 0) {
636 return(wndclass);
637 }
638 wndclass = wndclass->next;
639 }
640 }
641 }
642 else {
643 if(wndclass->classAtom == (DWORD)id) {
644 return(wndclass);
645 }
646 else {
647 wndclass = wndclass->next;
648 while(wndclass != NULL) {
649 if(wndclass->classAtom == (DWORD)id) {
650 return(wndclass);
651 }
652 wndclass = wndclass->next;
653 }
654 }
655 }
656 return(NULL);
657}
658//******************************************************************************
659//******************************************************************************
660void Win32WindowClass::UnregisterClass(HINSTANCE hinst, LPSTR id)
661{
662 Win32WindowClass *wndclass;
663
664 dprintf(("::UnregisterClass, destroy class %X!!\n", id));
665 wndclass = FindClass(id);
666 if(wndclass && wndclass->hinst == hinst) {
667 delete wndclass;
668 return;
669 }
670 dprintf(("::UnregisterClass, couldn't find class %X!!\n", id));
671}
672//******************************************************************************
673//******************************************************************************
674WNDPROC Win32WindowClass::GetClassCallback(HINSTANCE hinst, LPSTR id)
675{
676 Win32WindowClass *wndclass;
677
678 wndclass = FindClass(id);
679 if(wndclass && wndclass->hinst == hinst) {
680 return wndclass->pWinCallback;
681 }
682 dprintf(("::GetClassCallback, couldn't find class %X!!\n", id));
683 return(NULL);
684}
685//******************************************************************************
686//******************************************************************************
687WNDPROC Win32WindowClass::GetClassCallback(LPSTR id)
688{
689 Win32WindowClass *wndclass;
690
691 wndclass = FindClass(id);
692 if(wndclass) {
693 return wndclass->pWinCallback;
694 }
695 dprintf(("::GetClassCallback2, couldn't find class %X!!\n", id));
696 return(NULL);
697}
698//******************************************************************************
699//******************************************************************************
700WNDPROC_O32 Win32WindowClass::GetOS2ClassCallback()
701{
702 return OS2ToWinCallback;
703}
704//******************************************************************************
705//******************************************************************************
706LRESULT EXPENTRY_O32 OS2ToWinCallback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
707{
708 char szClass[128];
709 Win32WindowClass *wclass;
710
711#ifdef DEBUG1
712 dprintf(("OS2ToWinCallback for message %s", GetMsgText(Msg)));
713#endif
714
715 if(HkCBT::OS2HkCBTProc(hwnd, Msg, wParam, lParam) == TRUE) {//hook swallowed msg
716 return(0);
717 }
718
719 if(O32_GetClassName(hwnd, szClass, sizeof(szClass))) {
720 wclass = Win32WindowClass::FindClass(szClass);
721 if(wclass) {
722 //SvL: Correct Open32 key mapping bug
723 if(Msg == WM_KEYDOWN || Msg == WM_KEYUP || Msg == WM_CHAR) {
724// dprintf(("WM_KEYDOWN %X %08X\n", wParam, lParam));
725 lParam = MapOEMToRealKey(wParam, lParam);
726 }
727
728 if(Msg == WM_CREATE) {//Open32 isn't sending WM_NCCREATE messages!!
729 if(wclass->GetWinCallback()(hwnd, WM_NCCREATE, 0, lParam) == 0) {
730 dprintf(("WM_NCCREATE returned FALSE\n"));
731 return(-1); //don't create window
732 }
733 }
734 if(Msg == WM_ACTIVATE && LOWORD(wParam) != WA_INACTIVE)
735 {//SvL: Bugfix, Open32 is NOT sending this to the window (messes up Solitaire)
736 HDC hdc = GetDC(hwnd);
737
738 wclass->GetWinCallback()(hwnd, WM_ERASEBKGND, hdc, 0);
739 ReleaseDC(hwnd, hdc);
740 }
741 return wclass->GetWinCallback()(hwnd, Msg, wParam, lParam);
742 }
743 }
744 dprintf(("OS2ToWinCallback: couldn't find class procedure of window %X\n", hwnd));
745 return(0);
746}
747//******************************************************************************
748//******************************************************************************
749LRESULT WIN32API WinToOS2Callback(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam)
750{
751 WNDPROC_O32 os2callback;
752
753 os2callback = (WNDPROC_O32)GetClassLongA(hwnd, GCL_WNDPROC);
754 if(os2callback) {
755 return os2callback(hwnd, Msg, wParam, lParam);
756 }
757 dprintf(("OS2ToWinCallback: window procedure == NULL!!\n"));
758 return(0);
759}
760//******************************************************************************
761//******************************************************************************
762Win32WindowClass *Win32WindowClass::wndclasses = NULL;
Note: See TracBrowser for help on using the repository browser.