source: trunk/src/user32/windowclass.cpp@ 9523

Last change on this file since 9523 was 9523, checked in by sandervl, 23 years ago

removed obsolete files

File size: 19.6 KB
Line 
1/* $Id: windowclass.cpp,v 1.26 2002-12-18 12:28:08 sandervl Exp $ */
2/*
3 * Win32 Window Class Code for OS/2
4 *
5 *
6 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12#include <os2win.h>
13#include <stdio.h>
14#include <stdlib.h>
15#include <string.h>
16#include <stdarg.h>
17#include <assert.h>
18#include <misc.h>
19#include <unicode.h>
20#include <win32class.h>
21#include <win32wbase.h>
22#include <controls.h>
23
24#define DBG_LOCALLOG DBG_windowclass
25#include "dbglocal.h"
26
27
28#include <odin.h>
29#include <odinwrap.h>
30#include <os2sel.h>
31
32ODINDEBUGCHANNEL(USER32-CLASS)
33
34
35//******************************************************************************
36//******************************************************************************
37void RegisterSystemClasses(ULONG hModule)
38{
39 dprintf(("RegisterSystemClasses\n"));
40 CONTROLS_Register();
41}
42//******************************************************************************
43//******************************************************************************
44void UnregisterSystemClasses()
45{
46 dprintf(("UnregisterSystemClasses\n"));
47 CONTROLS_Unregister();
48}
49//******************************************************************************
50//Note: RegisterClassA does NOT change the last error if successful! (verified in NT 4, SP6)
51//******************************************************************************
52ATOM WIN32API RegisterClassA(CONST WNDCLASSA *lpWndClass)
53{
54 WNDCLASSEXA wc;
55 Win32WndClass *wclass;
56
57 //CB: size new in ex structure
58 wc.cbSize = sizeof(wc);
59 memcpy(&wc.style, lpWndClass, sizeof(WNDCLASSA));
60 wc.hIconSm = 0;
61
62 wclass = Win32WndClass::FindClass(wc.hInstance, (LPSTR)wc.lpszClassName);
63 if(wclass) {
64 RELEASE_CLASSOBJ(wclass);
65 if(HIWORD(wc.lpszClassName)) {
66 dprintf(("RegisterClassA %x %s already exists", wc.hInstance, wc.lpszClassName));
67 }
68 else dprintf(("RegisterClassA %x %x already exists", wc.hInstance, wc.lpszClassName));
69 SetLastError(ERROR_CLASS_ALREADY_EXISTS);
70 return 0;
71 }
72
73 //TODO: not destroyed when class is unregistered (neither does Wine, but that might be a bug)
74 dprintf(("RegisterClassA"));
75 int iSmIconWidth = GetSystemMetrics(SM_CXSMICON);
76 int iSmIconHeight = GetSystemMetrics(SM_CYSMICON);
77
78 if(wc.hIcon)
79 wc.hIconSm = CopyImage(wc.hIcon, IMAGE_ICON, iSmIconWidth, iSmIconHeight,
80 LR_COPYFROMRESOURCE);
81
82 wclass = new Win32WndClass(&wc, WNDCLASS_ASCII);
83 if(wclass == NULL) {
84 dprintf(("ERROR: RegisterClassA winclass == NULL!"));
85 DebugInt3();
86 return(0);
87 }
88 ATOM atom = wclass->getAtom();
89 RELEASE_CLASSOBJ(wclass);
90 return atom;
91}
92//******************************************************************************
93//Note: RegisterClassA does NOT change the last error if successful! (verified in NT 4, SP6)
94//******************************************************************************
95ATOM WIN32API RegisterClassExA(CONST WNDCLASSEXA *lpWndClass)
96{
97 Win32WndClass *wclass;
98
99 wclass = Win32WndClass::FindClass(lpWndClass->hInstance, (LPSTR)lpWndClass->lpszClassName);
100 if(wclass) {
101 RELEASE_CLASSOBJ(wclass);
102 if(HIWORD(lpWndClass->lpszClassName)) {
103 dprintf(("RegisterClassExA %x %s already exists", lpWndClass->hInstance, lpWndClass->lpszClassName));
104 }
105 else dprintf(("RegisterClassExA %x %x already exists", lpWndClass->hInstance, lpWndClass->lpszClassName));
106 SetLastError(ERROR_CLASS_ALREADY_EXISTS);
107 return 0;
108 }
109
110 dprintf(("RegisterClassExA"));
111 wclass = new Win32WndClass((WNDCLASSEXA *)lpWndClass, WNDCLASS_ASCII);
112 if(wclass == NULL) {
113 dprintf(("ERROR: RegisterClassExA winclass == NULL!"));
114 DebugInt3();
115 return(0);
116 }
117 ATOM atom = wclass->getAtom();
118 RELEASE_CLASSOBJ(wclass);
119 return atom;
120}
121//******************************************************************************
122//Used for user32 control class registration only
123//******************************************************************************
124ATOM WIN32API InternalRegisterClass(LPSTR lpszClassName, DWORD dwStyle,
125 WNDPROC pfnClassA, WNDPROC pfnClassW,
126 UINT cbExtraWindowWords, LPCSTR lpszCursor,
127 HBRUSH hBrush)
128{
129 WNDCLASSEXA wc;
130 Win32WndClass *wclass;
131
132 wclass = Win32WndClass::FindClass(0, lpszClassName);
133 if(wclass) {
134 RELEASE_CLASSOBJ(wclass);
135 DebugInt3(); //this must never happen
136 dprintf(("ERROR: InternalRegisterClass %s already exists", lpszClassName));
137 SetLastError(ERROR_CLASS_ALREADY_EXISTS);
138 return 0;
139 }
140
141 dprintf(("InternalRegisterClass %s %x %x %x %d %x %x", lpszClassName, dwStyle, pfnClassA, pfnClassW, cbExtraWindowWords, lpszCursor, hBrush));
142 wc.cbSize = sizeof(wc);
143 wc.style = dwStyle;
144 wc.lpfnWndProc = pfnClassA;
145 wc.cbClsExtra = 0;
146 wc.cbWndExtra = cbExtraWindowWords;
147 wc.hInstance = NULL;
148 wc.hIcon = 0;
149 wc.hCursor = LoadCursorA(0, lpszCursor);
150 wc.hbrBackground = hBrush;
151 wc.lpszMenuName = NULL;
152 wc.lpszClassName = lpszClassName;
153 wc.hIconSm = 0;
154
155 wclass = new Win32WndClass(&wc, WNDCLASS_ASCII);
156 if(wclass == NULL) {
157 dprintf(("ERROR: InternalRegisterClass winclass == NULL!"));
158 DebugInt3();
159 return(0);
160 }
161 wclass->setWindowProc(pfnClassW, WNDPROC_UNICODE);
162 ATOM atom = wclass->getAtom();
163 RELEASE_CLASSOBJ(wclass);
164 return atom;
165}
166//******************************************************************************
167//Note: RegisterClassA does NOT change the last error if successful! (verified in NT 4, SP6)
168//******************************************************************************
169ATOM WIN32API RegisterClassW(CONST WNDCLASSW * lpwc)
170{
171 ATOM rc;
172 WNDCLASSEXA wc;
173 Win32WndClass *winclass;
174
175 //CB: size new in ex structure
176 wc.cbSize = sizeof(wc);
177 memcpy(&wc.style, lpwc, sizeof(WNDCLASSA));
178 wc.hIconSm = 0;
179
180 winclass = Win32WndClass::FindClass(wc.hInstance, (LPWSTR)wc.lpszClassName);
181 if(winclass)
182 {
183 RELEASE_CLASSOBJ(winclass);
184 if(HIWORD(wc.lpszClassName)) {
185 dprintf(("RegisterClassW %x %ls already exists", wc.hInstance, wc.lpszClassName));
186 }
187 else dprintf(("RegisterClassW %x %x already exists", wc.hInstance, wc.lpszClassName));
188 SetLastError(ERROR_CLASS_ALREADY_EXISTS);
189 return 0;
190 }
191
192 //TODO: not destroyed when class is unregistered (neither does Wine, but that might be a bug)
193 int iSmIconWidth = GetSystemMetrics(SM_CXSMICON);
194 int iSmIconHeight = GetSystemMetrics(SM_CYSMICON);
195
196 if(wc.hIcon)
197 wc.hIconSm = CopyImage(wc.hIcon, IMAGE_ICON, iSmIconWidth, iSmIconHeight,
198 LR_COPYFROMRESOURCE);
199
200 dprintf(("RegisterClassW"));
201 winclass = new Win32WndClass((WNDCLASSEXA *)&wc, WNDCLASS_UNICODE);
202 if(winclass == NULL) {
203 dprintf(("ERROR: RegisterClassW winclass == NULL!"));
204 DebugInt3();
205 return 0;
206 }
207 rc = winclass->getAtom();
208 RELEASE_CLASSOBJ(winclass);
209 return(rc);
210}
211//******************************************************************************
212//Note: RegisterClassA does NOT change the last error if successful! (verified in NT 4, SP6)
213//******************************************************************************
214ATOM WIN32API RegisterClassExW(CONST WNDCLASSEXW *lpwc)
215{
216 ATOM rc;
217 WNDCLASSEXA wc;
218 Win32WndClass *winclass;
219
220 memcpy(&wc, lpwc, sizeof(WNDCLASSEXA));
221
222 winclass = Win32WndClass::FindClass(wc.hInstance, (LPWSTR)wc.lpszClassName);
223 if(winclass) {
224 RELEASE_CLASSOBJ(winclass);
225 if(HIWORD(wc.lpszClassName)) {
226 dprintf(("RegisterClassExW %x %ls already exists", wc.hInstance, wc.lpszClassName));
227 }
228 else dprintf(("RegisterClassExW %x %x already exists", wc.hInstance, wc.lpszClassName));
229 SetLastError(ERROR_CLASS_ALREADY_EXISTS);
230 return 0;
231 }
232
233 dprintf(("RegisterClassExW"));
234 winclass = new Win32WndClass((WNDCLASSEXA *)&wc, WNDCLASS_UNICODE);
235 if(winclass == NULL) {
236 dprintf(("ERROR: RegisterClassExW winclass == NULL!"));
237 DebugInt3();
238 return(0);
239 }
240 rc = winclass->getAtom();
241 RELEASE_CLASSOBJ(winclass);
242
243 return(rc);
244}
245//******************************************************************************
246//******************************************************************************
247BOOL WIN32API UnregisterClassA(LPCSTR lpszClassName, HINSTANCE hinst)
248{
249 BOOL ret;
250
251 ret = Win32WndClass::UnregisterClassA(hinst, (LPSTR)lpszClassName);
252 return ret;
253}
254//******************************************************************************
255//******************************************************************************
256BOOL WIN32API UnregisterClassW(LPCWSTR lpszClassName, HINSTANCE hinst)
257{
258 char *astring = NULL;
259 BOOL ret;
260
261 dprintf(("USER32: UnregisterClassW\n"));
262 if(HIWORD(lpszClassName) != 0) {
263 astring = UnicodeToAsciiString((LPWSTR)lpszClassName);
264 }
265 else astring = (char *)lpszClassName;
266
267 ret = Win32WndClass::UnregisterClassA(hinst, (LPSTR)astring);
268 if(HIWORD(astring) != 0)
269 FreeAsciiString((char *)astring);
270
271 return ret;
272}
273//******************************************************************************
274//******************************************************************************
275BOOL WIN32API GetClassInfoA(HINSTANCE hInstance, LPCSTR lpszClass,
276 WNDCLASSA *lpwc)
277{
278 WNDCLASSEXA wc;
279 BOOL rc;
280 Win32WndClass *wndclass;
281
282 if(HIWORD(lpszClass) != 0) {
283 dprintf(("USER32: GetClassInfoA %x %s %x", hInstance, lpszClass, lpwc));
284 }
285 else dprintf(("USER32: GetClassInfoA %x %x %x", hInstance, lpszClass, lpwc));
286
287 wndclass = Win32WndClass::FindClass(hInstance, (LPSTR)lpszClass);
288 if(wndclass) {
289 wndclass->getClassInfo(&wc);
290 RELEASE_CLASSOBJ(wndclass);
291 memcpy(lpwc, &wc.style, sizeof(WNDCLASSA));
292 SetLastError(ERROR_SUCCESS);
293 return(TRUE);
294 }
295 SetLastError(ERROR_CLASS_DOES_NOT_EXIST);
296 return(FALSE);
297}
298//******************************************************************************
299//******************************************************************************
300BOOL WIN32API GetClassInfoW(HINSTANCE hinst, LPCWSTR lpszClass, WNDCLASSW *lpwc)
301{
302 WNDCLASSEXW wc;
303 BOOL rc;
304 Win32WndClass *wndclass;
305 char *astring = NULL;
306
307 dprintf(("USER32: GetClassInfoW\n"));
308
309 if(HIWORD(lpszClass) != 0) {
310 astring = UnicodeToAsciiString((LPWSTR)lpszClass);
311 }
312 else astring = (char *)lpszClass;
313
314 wndclass = Win32WndClass::FindClass(hinst, astring);
315 if(HIWORD(astring) != 0)
316 FreeAsciiString((char *)astring);
317
318 if(wndclass) {
319 wndclass->getClassInfo(&wc);
320 RELEASE_CLASSOBJ(wndclass);
321 memcpy(lpwc, &wc.style, sizeof(WNDCLASSW));
322 SetLastError(ERROR_SUCCESS);
323 return(TRUE);
324 }
325 SetLastError(ERROR_CLASS_DOES_NOT_EXIST);
326 return(FALSE);
327}
328/****************************************************************************
329 * Name : BOOL WIN32API GetClassInfoExA
330 * Purpose : The GetClassInfoEx function retrieves information about a window
331 * class, including the handle of the small icon associated with the
332 * window class. GetClassInfo does not retrieve the handle of the small icon.
333 * Parameters: HINSTANCE hinst handle of application instance
334 * LPCTSTR lpszClass address of class name string
335 * LPWNDCLASSEX lpwcx address of structure for class data
336 * Variables :
337 * Result : If the function finds a matching class and successfully copies
338 * the data, the return value is TRUE;
339 * otherwise, it is FALSE.
340 * To get extended error information, call GetLastError.
341 * Remark : PH: does not obtain handle of the small icon
342 *****************************************************************************/
343BOOL WIN32API GetClassInfoExA(HINSTANCE hInstance, LPCTSTR lpszClass,
344 LPWNDCLASSEXA lpwcx)
345{
346 BOOL rc;
347 Win32WndClass *wndclass;
348
349 if(HIWORD(lpszClass)) {
350 dprintf(("USER32:GetClassInfoExA (%08xh,%s,%08x)",
351 hInstance, lpszClass, lpwcx));
352 }
353 else dprintf(("USER32:GetClassInfoExA (%08xh,%x,%08x)",
354 hInstance, lpszClass, lpwcx));
355
356 wndclass = Win32WndClass::FindClass(hInstance, (LPSTR)lpszClass);
357 if(wndclass) {
358 wndclass->getClassInfo(lpwcx);
359 RELEASE_CLASSOBJ(wndclass);
360 lpwcx->cbSize = sizeof(WNDCLASSEXA);
361 SetLastError(ERROR_SUCCESS);
362 return(TRUE);
363 }
364 SetLastError(ERROR_CLASS_DOES_NOT_EXIST);
365 return(FALSE);
366}
367
368
369/*****************************************************************************
370 * Name : BOOL WIN32API GetClassInfoExW
371 * Purpose : The GetClassInfoEx function retrieves information about a window
372 * class, including the handle of the small icon associated with the
373 * window class. GetClassInfo does not retrieve the handle of the small icon.
374 * Parameters: HINSTANCE hinst handle of application instance
375 * LPCWSTR lpszClass address of class name string
376 * LPWNDCLASSEX lpwcx address of structure for class data
377 * Variables :
378 * Result : If the function finds a matching class and successfully copies
379 * the data, the return value is TRUE;
380 * otherwise, it is FALSE.
381 * To get extended error information, call GetLastError.
382 * Remark : does not obtain handle of the small icon
383 *
384 *****************************************************************************/
385BOOL WIN32API GetClassInfoExW(HINSTANCE hInstance, LPCWSTR lpszClass,
386 LPWNDCLASSEXW lpwcx)
387{
388 BOOL rc;
389 Win32WndClass *wndclass;
390 char *astring = NULL;
391
392 if(HIWORD(lpszClass)) {
393 dprintf(("USER32:GetClassInfoExW (%08xh,%ls,%08x)",
394 hInstance, lpszClass, lpwcx));
395 }
396 else dprintf(("USER32:GetClassInfoExW (%08xh,%x,%08x)",
397 hInstance, lpszClass, lpwcx));
398
399 if(HIWORD(lpszClass) != 0) {
400 astring = UnicodeToAsciiString((LPWSTR)lpszClass);
401 }
402 else astring = (char *)lpszClass;
403
404 wndclass = Win32WndClass::FindClass(hInstance, astring);
405 if(HIWORD(astring) != 0)
406 FreeAsciiString((char *)astring);
407
408 if(wndclass) {
409 wndclass->getClassInfo(lpwcx);
410 RELEASE_CLASSOBJ(wndclass);
411 lpwcx->cbSize = sizeof(WNDCLASSEXW);
412 SetLastError(ERROR_SUCCESS);
413 return(TRUE);
414 }
415 SetLastError(ERROR_CLASS_DOES_NOT_EXIST);
416 return(FALSE);
417}
418//******************************************************************************
419//******************************************************************************
420int WIN32API GetClassNameA(HWND hwnd, LPSTR lpszClassName, int cchClassName)
421{
422 Win32BaseWindow *wnd;
423 int rc;
424
425 wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
426 if(!wnd) {
427 dprintf(("GetClassNameA wnd == NULL"));
428 return(0);
429 }
430 *lpszClassName = 0;
431 rc = (wnd->getClass())->getClassName(lpszClassName, cchClassName);
432 RELEASE_WNDOBJ(wnd);
433 if(HIWORD(lpszClassName)) {
434 dprintf(("USER32: GetClassNameA %x %s", hwnd, lpszClassName));
435 }
436 else dprintf(("USER32: GetClassNameA %x %x", hwnd, lpszClassName));
437 return rc;
438}
439//******************************************************************************
440//******************************************************************************
441int WIN32API GetClassNameW(HWND hwnd, LPWSTR lpszClassName, int cchClassName)
442{
443 Win32BaseWindow *wnd;
444 int ret;
445
446 wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
447 if(!wnd) {
448 dprintf(("GetClassNameA wnd == NULL"));
449 return(0);
450 }
451 ret = (wnd->getClass())->getClassName(lpszClassName, cchClassName);
452 RELEASE_WNDOBJ(wnd);
453 if(HIWORD(lpszClassName)) {
454 dprintf(("USER32: GetClassNameW %x %ls", hwnd, lpszClassName));
455 }
456 else dprintf(("USER32: GetClassNameW %x %x", hwnd, lpszClassName));
457 return ret;
458}
459//******************************************************************************
460//******************************************************************************
461LONG WIN32API SetClassLongA(HWND hwnd, int nIndex, LONG lNewVal)
462{
463 Win32BaseWindow *wnd;
464 LONG ret;
465
466 wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
467 if(!wnd) {
468 dprintf(("SetClassLongA %x %d %x wnd == NULL", hwnd, nIndex, lNewVal));
469 return(0);
470 }
471 ret = (wnd->getClass())->setClassLongA(nIndex, lNewVal);
472 RELEASE_WNDOBJ(wnd);
473 return ret;
474}
475//******************************************************************************
476//******************************************************************************
477LONG WIN32API SetClassLongW(HWND hwnd, int nIndex, LONG lNewVal)
478{
479 Win32BaseWindow *wnd;
480 LONG ret;
481
482 wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
483 if(!wnd) {
484 dprintf(("SetClassLongW %x %d %x wnd == NULL", hwnd, nIndex, lNewVal));
485 return(0);
486 }
487 ret = (wnd->getClass())->setClassLongW(nIndex, lNewVal);
488 RELEASE_WNDOBJ(wnd);
489 return ret;
490}
491//******************************************************************************
492//******************************************************************************
493WORD WIN32API SetClassWord(HWND hwnd, int nIndex, WORD wNewVal)
494{
495 Win32BaseWindow *wnd;
496 LONG ret;
497
498 dprintf(("USER32: SetClassWord %x %d %x", hwnd, nIndex, (ULONG)wNewVal));
499 wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
500 if(!wnd) {
501 dprintf(("SetClassWordA %x %d %x wnd == NULL", hwnd, nIndex, wNewVal));
502 return(0);
503 }
504 ret = (wnd->getClass())->setClassWord(nIndex, wNewVal);
505 RELEASE_WNDOBJ(wnd);
506 return ret;
507}
508//******************************************************************************
509//******************************************************************************
510WORD WIN32API GetClassWord(HWND hwnd, int nIndex)
511{
512 Win32BaseWindow *wnd;
513 WORD ret;
514
515 wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
516 if(!wnd) {
517 dprintf(("GetClassWordA %x %d wnd == NULL", hwnd, nIndex));
518 return(0);
519 }
520 ret = (wnd->getClass())->getClassWord(nIndex);
521 RELEASE_WNDOBJ(wnd);
522 dprintf(("USER32: GetClassWord %x %d returned %x", hwnd, nIndex, (ULONG)ret));
523 return ret;
524}
525//******************************************************************************
526//******************************************************************************
527LONG WIN32API GetClassLongA(HWND hwnd, int nIndex)
528{
529 Win32BaseWindow *wnd;
530 LONG ret;
531
532 wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
533 if(!wnd) {
534 dprintf(("GetClassLongA %x %d wnd == NULL", hwnd, nIndex));
535 return(0);
536 }
537 ret = (wnd->getClass())->getClassLongA(nIndex);
538 RELEASE_WNDOBJ(wnd);
539 dprintf(("USER32: GetClassLongA %x %d returned %x", hwnd, nIndex, ret));
540 return ret;
541}
542//******************************************************************************
543//******************************************************************************
544LONG WIN32API GetClassLongW(HWND hwnd, int nIndex)
545{
546 Win32BaseWindow *wnd;
547 LONG ret;
548
549 wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
550 if(!wnd) {
551 dprintf(("GetClassLongW %x %d wnd == NULL", hwnd, nIndex));
552 return(0);
553 }
554 ret = (wnd->getClass())->getClassLongW(nIndex);
555 RELEASE_WNDOBJ(wnd);
556 dprintf(("USER32: GetClassLongW %x %d returned %x", hwnd, nIndex, ret));
557 return ret;
558}
559//******************************************************************************
560//******************************************************************************
Note: See TracBrowser for help on using the repository browser.