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

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

logging updates

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