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

Last change on this file since 5935 was 5935, checked in by sandervl, 24 years ago

reference count (window + class objects) rewrite

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