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

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

remove wrong check for negative x & y coordinates during window creation

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