This implements GetClassInfo
[reactos.git] / reactos / lib / user32 / windows / class.c
1 /* $Id: class.c,v 1.28 2003/08/09 07:09:57 jimtabor Exp $
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS user32.dll
5 * FILE: lib/user32/windows/class.c
6 * PURPOSE: Window classes
7 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
8 * UPDATE HISTORY:
9 * 09-05-2001 CSH Created
10 */
11 #include <windows.h>
12 #include <user32.h>
13 #include <string.h>
14 #include <stdlib.h>
15 #include <debug.h>
16 #include <window.h>
17 #include <strpool.h>
18
19 /*
20 * @implemented
21 */
22 WINBOOL
23 STDCALL
24 GetClassInfoExA(
25 HINSTANCE hinst,
26 LPCSTR lpszClass,
27 LPWNDCLASSEXA lpwcx)
28 {
29 LPWSTR str;
30 PUNICODE_STRING str2;
31 WNDCLASSEXW w;
32 BOOL retval;
33 NTSTATUS Status;
34 Status = HEAP_strdupAtoW (&str, lpszClass, NULL);
35 if ( !NT_SUCCESS (Status) )
36 {
37 SetLastError (RtlNtStatusToDosError(Status));
38 return 0;
39 }
40 retval = (BOOL)NtUserGetClassInfo(hinst,str,&w,TRUE,0);
41 if (str)
42 {
43 HEAP_free(str);
44 }
45 RtlCopyMemory (&w,lpwcx,sizeof(WNDCLASSEXW));
46 if (!IS_INTRESOURCE(w.lpszMenuName))
47 {
48 str = (LPWSTR)w.lpszMenuName;
49 str2 = (PUNICODE_STRING)str;
50 lpwcx->lpszMenuName = heap_string_poolA (str2->Buffer, str2->Length);
51 }
52 return retval;
53 }
54
55
56 /*
57 * @implemented
58 */
59 WINBOOL
60 STDCALL
61 GetClassInfoExW(
62 HINSTANCE hinst,
63 LPCWSTR lpszClass,
64 LPWNDCLASSEXW lpwcx)
65 {
66 LPWSTR str;
67 PUNICODE_STRING str2;
68 WNDCLASSEXW w;
69 WINBOOL retval;
70 str = HEAP_strdupW (lpszClass, wcslen(lpszClass) );
71 retval = (BOOL)NtUserGetClassInfo(hinst,lpszClass,&w,FALSE,0);
72 if (str)
73 {
74 HEAP_free(str);
75 }
76 RtlCopyMemory (&w,lpwcx,sizeof(WNDCLASSEXW));
77 if (!IS_INTRESOURCE(w.lpszMenuName) )
78 {
79 str = (LPWSTR)w.lpszMenuName;
80 str2 = (PUNICODE_STRING)str;
81 lpwcx->lpszMenuName = heap_string_poolW (str2->Buffer, str2->Length);
82 }
83 return retval;
84 }
85
86
87 /*
88 * @implemented
89 */
90 WINBOOL
91 STDCALL
92 GetClassInfoA(
93 HINSTANCE hInstance,
94 LPCSTR lpClassName,
95 LPWNDCLASSA lpWndClass)
96 {
97 WNDCLASSEXA w;
98 WINBOOL retval;
99 retval = GetClassInfoExA(hInstance,lpClassName,&w);
100 RtlCopyMemory (lpWndClass,&w.style,sizeof(WNDCLASSA));
101 return retval;
102 }
103
104 /*
105 * @implemented
106 */
107 WINBOOL
108 STDCALL
109 GetClassInfoW(
110 HINSTANCE hInstance,
111 LPCWSTR lpClassName,
112 LPWNDCLASSW lpWndClass)
113 {
114 WNDCLASSEXW w;
115 WINBOOL retval;
116 retval = GetClassInfoExW(hInstance,lpClassName,&w);
117 RtlCopyMemory (lpWndClass,&w.style,sizeof(WNDCLASSW));
118 return retval;
119 }
120
121
122 /*
123 * @implemented
124 */
125 DWORD STDCALL
126 GetClassLongA ( HWND hWnd, int nIndex )
127 {
128 PUNICODE_STRING str;
129
130 if ( nIndex != GCL_MENUNAME )
131 {
132 return NtUserGetClassLong ( hWnd, nIndex, TRUE );
133 }
134
135 str = (PUNICODE_STRING)NtUserGetClassLong ( hWnd, nIndex, TRUE );
136 if ( IS_INTRESOURCE(str) )
137 {
138 return (DWORD)str;
139 }
140 else
141 {
142 return (DWORD)heap_string_poolA ( str->Buffer, str->Length );
143 }
144 }
145
146 /*
147 * @implemented
148 */
149 DWORD STDCALL
150 GetClassLongW ( HWND hWnd, int nIndex )
151 {
152 PUNICODE_STRING str;
153
154 if ( nIndex != GCL_MENUNAME )
155 {
156 return NtUserGetClassLong ( hWnd, nIndex, FALSE );
157 }
158
159 str = (PUNICODE_STRING)NtUserGetClassLong(hWnd, nIndex, TRUE);
160 if ( IS_INTRESOURCE(str) )
161 {
162 return (DWORD)str;
163 }
164 else
165 {
166 return (DWORD)heap_string_poolW ( str->Buffer, str->Length );
167 }
168 }
169
170
171 /*
172 * @implemented
173 */
174 int STDCALL
175 GetClassNameA(
176 HWND hWnd,
177 LPSTR lpClassName,
178 int nMaxCount)
179 {
180 int result;
181 LPWSTR ClassNameW;
182 NTSTATUS Status;
183
184 ClassNameW = HEAP_alloc ( (nMaxCount+1)*sizeof(WCHAR) );
185
186 result = NtUserGetClassName ( hWnd, ClassNameW, nMaxCount );
187
188 Status = HEAP_strcpyWtoA ( lpClassName, ClassNameW, result );
189
190 HEAP_free ( ClassNameW );
191
192 if ( !NT_SUCCESS(Status) )
193 return 0;
194
195 return result;
196 }
197
198
199 /*
200 * @implemented
201 */
202 int
203 STDCALL
204 GetClassNameW(
205 HWND hWnd,
206 LPWSTR lpClassName,
207 int nMaxCount)
208 {
209 int result;
210 LPWSTR ClassNameW;
211
212 ClassNameW = HEAP_alloc ( (nMaxCount+1) * sizeof(WCHAR) );
213
214 result = NtUserGetClassName ( hWnd, ClassNameW, nMaxCount );
215
216 RtlCopyMemory ( lpClassName, ClassNameW, result );
217
218 HEAP_free ( ClassNameW );
219
220 return result;
221 }
222
223
224 /*
225 * @unimplemented
226 */
227 WORD
228 STDCALL
229 GetClassWord(
230 HWND hWnd,
231 int nIndex)
232 /*
233 * NOTE: Obsoleted in 32-bit windows
234 */
235 {
236 UNIMPLEMENTED;
237 return 0;
238 }
239
240
241 /*
242 * @implemented
243 */
244 LONG STDCALL
245 GetWindowLongA(HWND hWnd, int nIndex)
246 {
247 return NtUserGetWindowLong(hWnd, nIndex, TRUE);
248 }
249
250
251 /*
252 * @implemented
253 */
254 LONG STDCALL
255 GetWindowLongW(HWND hWnd, int nIndex)
256 {
257 return NtUserGetWindowLong(hWnd, nIndex, FALSE);
258 }
259
260 /*
261 * @implemented
262 */
263 WORD STDCALL
264 GetWindowWord(HWND hWnd, int nIndex)
265 {
266 return (WORD)NtUserGetWindowLong(hWnd, nIndex, TRUE);
267 }
268
269 /*
270 * @implemented
271 */
272 UINT
273 STDCALL
274 RealGetWindowClassW(
275 HWND hwnd,
276 LPWSTR pszType,
277 UINT cchType)
278 {
279 /* FIXME: Implement correct functionality of RealGetWindowClass */
280 return GetClassNameW(hwnd,pszType,cchType);
281 }
282
283
284 /*
285 * @implemented
286 */
287 UINT
288 STDCALL
289 RealGetWindowClassA(
290 HWND hwnd,
291 LPSTR pszType,
292 UINT cchType)
293 {
294 /* FIXME: Implement correct functionality of RealGetWindowClass */
295 return GetClassNameA(hwnd,pszType,cchType);
296 }
297
298 /*
299 * @implemented
300 */
301 ATOM STDCALL
302 RegisterClassA(CONST WNDCLASSA *lpWndClass)
303 {
304 WNDCLASSEXA Class;
305
306 if ( !lpWndClass )
307 return 0;
308
309 RtlCopyMemory ( &Class.style, lpWndClass, sizeof(WNDCLASSA) );
310
311 Class.cbSize = sizeof(WNDCLASSEXA);
312 Class.hIconSm = INVALID_HANDLE_VALUE;
313
314 return RegisterClassExA ( &Class );
315 }
316
317 /*
318 * @implemented
319 */
320 ATOM STDCALL
321 RegisterClassExA(CONST WNDCLASSEXA *lpwcx)
322 {
323 RTL_ATOM Atom;
324 WNDCLASSEXW wndclass;
325 NTSTATUS Status;
326 LPWSTR ClassName = NULL;
327 LPWSTR MenuName = NULL;
328
329 if ( !lpwcx || (lpwcx->cbSize != sizeof(WNDCLASSEXA)) )
330 return 0;
331
332 if ( !lpwcx->lpszClassName )
333 return 0;
334
335 RtlCopyMemory ( &wndclass, lpwcx, sizeof(WNDCLASSEXW) );
336
337 if ( !IS_ATOM(lpwcx->lpszClassName) )
338 {
339 Status = HEAP_strdupAtoW ( &ClassName, (LPCSTR)lpwcx->lpszClassName, NULL );
340 if ( !NT_SUCCESS (Status) )
341 {
342 SetLastError (RtlNtStatusToDosError(Status));
343 return 0;
344 }
345 wndclass.lpszClassName = ClassName;
346 }
347
348 if ( !IS_INTRESOURCE(lpwcx->lpszMenuName) )
349 {
350 Status = HEAP_strdupAtoW ( &MenuName, (LPCSTR)lpwcx->lpszMenuName, NULL );
351 if ( !NT_SUCCESS (Status) )
352 {
353 if ( ClassName )
354 HEAP_free ( ClassName );
355 SetLastError (RtlNtStatusToDosError(Status));
356 return 0;
357 }
358 wndclass.lpszMenuName = MenuName;
359 }
360
361 Atom = NtUserRegisterClassExWOW ( &wndclass, FALSE, 0, 0, 0 );
362
363 /* free strings if neccessary */
364 if ( MenuName ) HEAP_free ( MenuName );
365 if ( ClassName ) HEAP_free ( ClassName );
366
367 return (ATOM)Atom;
368 }
369
370
371
372 /*
373 * @implemented
374 */
375 ATOM STDCALL
376 RegisterClassExW(CONST WNDCLASSEXW *lpwcx)
377 {
378 RTL_ATOM Atom;
379 HANDLE hHeap;
380 WNDCLASSEXW wndclass;
381 LPWSTR ClassName = NULL;
382 LPWSTR MenuName = NULL;
383
384 if ( !lpwcx || (lpwcx->cbSize != sizeof(WNDCLASSEXA)) )
385 return 0;
386
387 if ( !lpwcx->lpszClassName )
388 return 0;
389
390 hHeap = RtlGetProcessHeap();
391 RtlCopyMemory ( &wndclass, lpwcx, sizeof(WNDCLASSEXW) );
392
393 /* copy strings if needed */
394
395 if ( !IS_ATOM(lpwcx->lpszClassName) )
396 {
397 ClassName = HEAP_strdupW ( lpwcx->lpszClassName, lstrlenW(lpwcx->lpszClassName) );
398 if ( !ClassName )
399 {
400 SetLastError(RtlNtStatusToDosError(STATUS_NO_MEMORY));
401 return 0;
402 }
403 wndclass.lpszClassName = ClassName;
404 }
405
406 if ( !IS_INTRESOURCE(lpwcx->lpszMenuName) )
407 {
408 MenuName = HEAP_strdupW ( lpwcx->lpszMenuName, lstrlenW(lpwcx->lpszMenuName) );
409 if ( !MenuName )
410 {
411 if ( ClassName )
412 HEAP_free ( MenuName );
413 SetLastError(RtlNtStatusToDosError(STATUS_NO_MEMORY));
414 return 0;
415 }
416 wndclass.lpszMenuName = MenuName;
417 }
418
419 Atom = NtUserRegisterClassExWOW ( &wndclass, TRUE, 0, 0, 0 );
420
421 /* free strings if neccessary */
422 if ( MenuName ) HEAP_free ( MenuName );
423 if ( ClassName ) HEAP_free ( ClassName );
424
425 return (ATOM)Atom;
426 }
427
428 /*
429 * @implemented
430 */
431 ATOM STDCALL
432 RegisterClassW(CONST WNDCLASSW *lpWndClass)
433 {
434 WNDCLASSEXW Class;
435
436 if ( !lpWndClass )
437 return 0;
438
439 RtlCopyMemory ( &Class.style, lpWndClass, sizeof(WNDCLASSW) );
440
441 Class.cbSize = sizeof(WNDCLASSEXW);
442 Class.hIconSm = INVALID_HANDLE_VALUE;
443
444 return RegisterClassExW ( &Class );
445 }
446
447 /*
448 * @implemented
449 */
450 DWORD
451 STDCALL
452 SetClassLongA (
453 HWND hWnd,
454 int nIndex,
455 LONG dwNewLong)
456 {
457 PUNICODE_STRING str;
458 PUNICODE_STRING str2;
459
460 if ( nIndex != GCL_MENUNAME )
461 {
462 return NtUserSetClassLong ( hWnd, nIndex, dwNewLong, TRUE );
463 }
464 if ( IS_INTRESOURCE(dwNewLong) )
465 {
466 str2 = (PUNICODE_STRING)dwNewLong;
467 }
468 else
469 {
470 RtlCreateUnicodeString ( str2, (LPWSTR)dwNewLong );
471 }
472
473 str = (PUNICODE_STRING)NtUserSetClassLong(hWnd, nIndex, (DWORD)str2, TRUE);
474
475 if ( !IS_INTRESOURCE(dwNewLong) )
476 {
477 RtlFreeUnicodeString ( str2 );
478 }
479 if ( IS_INTRESOURCE(str) )
480 {
481 return (DWORD)str;
482 }
483 else
484 {
485 return (DWORD)heap_string_poolA ( str->Buffer, str->Length );
486 }
487 }
488
489
490 /*
491 * @implemented
492 */
493 DWORD
494 STDCALL
495 SetClassLongW(
496 HWND hWnd,
497 int nIndex,
498 LONG dwNewLong)
499 {
500 PUNICODE_STRING str;
501 PUNICODE_STRING str2;
502
503 if (nIndex != GCL_MENUNAME )
504 {
505 return NtUserSetClassLong ( hWnd, nIndex, dwNewLong, FALSE );
506 }
507 if ( IS_INTRESOURCE(dwNewLong) )
508 {
509 str2 = (PUNICODE_STRING)dwNewLong;
510 }
511 else
512 {
513 RtlCreateUnicodeStringFromAsciiz ( str2,(LPSTR)dwNewLong );
514 }
515
516 str = (PUNICODE_STRING)NtUserSetClassLong(hWnd, nIndex, (DWORD)str2, TRUE);
517
518 if ( !IS_INTRESOURCE(dwNewLong) )
519 {
520 RtlFreeUnicodeString(str2);
521 }
522 if ( IS_INTRESOURCE(str) )
523 {
524 return (DWORD)str;
525 }
526 else
527 {
528 return (DWORD)heap_string_poolW ( str->Buffer, str->Length );
529 }
530 }
531
532
533 /*
534 * @unimplemented
535 */
536 WORD
537 STDCALL
538 SetClassWord(
539 HWND hWnd,
540 int nIndex,
541 WORD wNewWord)
542 /*
543 * NOTE: Obsoleted in 32-bit windows
544 */
545 {
546 UNIMPLEMENTED;
547 return 0;
548 }
549
550
551 /*
552 * @implemented
553 */
554 LONG
555 STDCALL
556 SetWindowLongA(
557 HWND hWnd,
558 int nIndex,
559 LONG dwNewLong)
560 {
561 return NtUserSetWindowLong(hWnd, nIndex, dwNewLong, TRUE);
562 }
563
564
565 /*
566 * @implemented
567 */
568 LONG
569 STDCALL
570 SetWindowLongW(
571 HWND hWnd,
572 int nIndex,
573 LONG dwNewLong)
574 {
575 return NtUserSetWindowLong(hWnd, nIndex, dwNewLong, FALSE);
576 }
577
578
579 /*
580 * @unimplemented
581 */
582 WINBOOL
583 STDCALL
584 UnregisterClassA(
585 LPCSTR lpClassName,
586 HINSTANCE hInstance)
587 {
588 UNIMPLEMENTED;
589 return FALSE;
590 }
591
592
593 /*
594 * @unimplemented
595 */
596 WINBOOL
597 STDCALL
598 UnregisterClassW(
599 LPCWSTR lpClassName,
600 HINSTANCE hInstance)
601 {
602 UNIMPLEMENTED;
603 return FALSE;
604 }
605
606 /* EOF */