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

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

* empty log message *

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