wined3d: Move constant loading into target-specific files.
[wine.git] / dlls / user / class.c
bloba08d7b53267acee736378fc137f342476d5e954b
1 /*
2 * Window classes functions
4 * Copyright 1993, 1996, 2003 Alexandre Julliard
5 * Copyright 1998 Juergen Schmied (jsch)
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <stdlib.h>
28 #include <string.h>
30 #include "winerror.h"
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "wine/winuser16.h"
35 #include "wine/unicode.h"
36 #include "win.h"
37 #include "user_private.h"
38 #include "controls.h"
39 #include "winproc.h"
40 #include "wine/server.h"
41 #include "wine/list.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(class);
46 typedef struct tagCLASS
48 struct list entry; /* Entry in class list */
49 UINT style; /* Class style */
50 BOOL local; /* Local class? */
51 WNDPROC winproc; /* Window procedure */
52 INT cbClsExtra; /* Class extra bytes */
53 INT cbWndExtra; /* Window extra bytes */
54 LPWSTR menuName; /* Default menu name (Unicode followed by ASCII) */
55 HINSTANCE hInstance; /* Module that created the task */
56 HICON hIcon; /* Default icon */
57 HICON hIconSm; /* Default small icon */
58 HCURSOR hCursor; /* Default cursor */
59 HBRUSH hbrBackground; /* Default background */
60 ATOM atomName; /* Name of the class */
61 } CLASS;
63 static struct list class_list = LIST_INIT( class_list );
65 #define CLASS_OTHER_PROCESS ((CLASS *)1)
67 /***********************************************************************
68 * get_class_ptr
70 static CLASS *get_class_ptr( HWND hwnd, BOOL write_access )
72 WND *ptr = WIN_GetPtr( hwnd );
74 if (ptr)
76 if (ptr != WND_OTHER_PROCESS && ptr != WND_DESKTOP) return ptr->class;
77 if (!write_access) return CLASS_OTHER_PROCESS;
79 /* modifying classes in other processes is not allowed */
80 if (ptr == WND_DESKTOP || IsWindow( hwnd ))
82 SetLastError( ERROR_ACCESS_DENIED );
83 return NULL;
86 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
87 return NULL;
91 /***********************************************************************
92 * release_class_ptr
94 inline static void release_class_ptr( CLASS *ptr )
96 USER_Unlock();
100 /***********************************************************************
101 * set_server_info
103 * Set class info with the wine server.
105 static BOOL set_server_info( HWND hwnd, INT offset, LONG newval )
107 BOOL ret;
109 SERVER_START_REQ( set_class_info )
111 req->window = hwnd;
112 req->extra_offset = -1;
113 switch(offset)
115 case GCW_ATOM:
116 req->flags = SET_CLASS_ATOM;
117 req->atom = newval;
118 case GCL_STYLE:
119 req->flags = SET_CLASS_STYLE;
120 req->style = newval;
121 break;
122 case GCL_CBWNDEXTRA:
123 req->flags = SET_CLASS_WINEXTRA;
124 req->win_extra = newval;
125 break;
126 case GCLP_HMODULE:
127 req->flags = SET_CLASS_INSTANCE;
128 req->instance = (void *)newval;
129 break;
130 default:
131 assert( offset >= 0 );
132 req->flags = SET_CLASS_EXTRA;
133 req->extra_offset = offset;
134 req->extra_size = sizeof(newval);
135 memcpy( &req->extra_value, &newval, sizeof(newval) );
136 break;
138 ret = !wine_server_call_err( req );
140 SERVER_END_REQ;
141 return ret;
145 /***********************************************************************
146 * CLASS_GetMenuNameA
148 * Get the menu name as a ASCII string.
150 inline static LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
152 if (!HIWORD(classPtr->menuName)) return (LPSTR)classPtr->menuName;
153 return (LPSTR)(classPtr->menuName + strlenW(classPtr->menuName) + 1);
157 /***********************************************************************
158 * CLASS_GetMenuNameW
160 * Get the menu name as a Unicode string.
162 inline static LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
164 return classPtr->menuName;
168 /***********************************************************************
169 * CLASS_SetMenuNameA
171 * Set the menu name in a class structure by copying the string.
173 static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
175 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
176 if (HIWORD(name))
178 DWORD lenA = strlen(name) + 1;
179 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, name, lenA, NULL, 0 );
180 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
181 MultiByteToWideChar( CP_ACP, 0, name, lenA, classPtr->menuName, lenW );
182 memcpy( classPtr->menuName + lenW, name, lenA );
184 else classPtr->menuName = (LPWSTR)name;
188 /***********************************************************************
189 * CLASS_SetMenuNameW
191 * Set the menu name in a class structure by copying the string.
193 static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
195 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
196 if (HIWORD(name))
198 DWORD lenW = strlenW(name) + 1;
199 DWORD lenA = WideCharToMultiByte( CP_ACP, 0, name, lenW, NULL, 0, NULL, NULL );
200 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
201 memcpy( classPtr->menuName, name, lenW*sizeof(WCHAR) );
202 WideCharToMultiByte( CP_ACP, 0, name, lenW,
203 (char *)(classPtr->menuName + lenW), lenA, NULL, NULL );
205 else classPtr->menuName = (LPWSTR)name;
209 /***********************************************************************
210 * CLASS_FreeClass
212 * Free a class structure.
214 static void CLASS_FreeClass( CLASS *classPtr )
216 TRACE("%p\n", classPtr);
218 USER_Lock();
220 list_remove( &classPtr->entry );
221 if (classPtr->hbrBackground > (HBRUSH)(COLOR_GRADIENTINACTIVECAPTION + 1))
222 DeleteObject( classPtr->hbrBackground );
223 HeapFree( GetProcessHeap(), 0, classPtr->menuName );
224 HeapFree( GetProcessHeap(), 0, classPtr );
225 USER_Unlock();
229 /***********************************************************************
230 * CLASS_FreeModuleClasses
232 void CLASS_FreeModuleClasses( HMODULE16 hModule )
234 struct list *ptr, *next;
236 TRACE("0x%08x\n", hModule);
238 USER_Lock();
239 for (ptr = list_head( &class_list ); ptr; ptr = next)
241 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
242 next = list_next( &class_list, ptr );
243 if (class->hInstance == HINSTANCE_32(hModule))
245 BOOL ret;
247 SERVER_START_REQ( destroy_class )
249 req->atom = class->atomName;
250 req->instance = class->hInstance;
251 ret = !wine_server_call_err( req );
253 SERVER_END_REQ;
254 if (ret) CLASS_FreeClass( class );
257 USER_Unlock();
261 /***********************************************************************
262 * CLASS_FindClassByAtom
264 * Return a pointer to the class.
265 * hinstance has been normalized by the caller.
267 static CLASS *CLASS_FindClassByAtom( ATOM atom, HINSTANCE hinstance )
269 struct list *ptr;
271 USER_Lock();
273 LIST_FOR_EACH( ptr, &class_list )
275 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
276 if (class->atomName != atom) continue;
277 if (!hinstance || !class->local || class->hInstance == hinstance)
279 TRACE("0x%04x %p -> %p\n", atom, hinstance, class);
280 return class;
283 USER_Unlock();
284 TRACE("0x%04x %p -> not found\n", atom, hinstance);
285 return NULL;
289 /***********************************************************************
290 * CLASS_RegisterClass
292 * The real RegisterClass() functionality.
293 * The atom is deleted no matter what.
295 static CLASS *CLASS_RegisterClass( ATOM atom, HINSTANCE hInstance, BOOL local,
296 DWORD style, INT classExtra, INT winExtra )
298 CLASS *classPtr;
299 BOOL ret;
301 TRACE("atom=0x%x hinst=%p style=0x%lx clExtr=0x%x winExtr=0x%x\n",
302 atom, hInstance, style, classExtra, winExtra );
304 /* Fix the extra bytes value */
306 if (classExtra < 0 || winExtra < 0)
308 SetLastError( ERROR_INVALID_PARAMETER );
309 return NULL;
311 if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
312 WARN("Class extra bytes %d is > 40\n", classExtra);
313 if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
314 WARN("Win extra bytes %d is > 40\n", winExtra );
316 classPtr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLASS) + classExtra );
317 if (!classPtr)
319 GlobalDeleteAtom( atom );
320 return NULL;
323 SERVER_START_REQ( create_class )
325 req->local = local;
326 req->atom = atom;
327 req->style = style;
328 req->instance = hInstance;
329 req->extra = classExtra;
330 req->win_extra = winExtra;
331 req->client_ptr = classPtr;
332 ret = !wine_server_call_err( req );
334 SERVER_END_REQ;
335 GlobalDeleteAtom( atom ); /* the server increased the atom ref count */
336 if (!ret)
338 HeapFree( GetProcessHeap(), 0, classPtr );
339 return NULL;
342 classPtr->style = style;
343 classPtr->local = local;
344 classPtr->cbWndExtra = winExtra;
345 classPtr->cbClsExtra = classExtra;
346 classPtr->hInstance = hInstance;
347 classPtr->atomName = atom;
349 /* Other non-null values must be set by caller */
351 USER_Lock();
352 if (local) list_add_head( &class_list, &classPtr->entry );
353 else list_add_tail( &class_list, &classPtr->entry );
354 return classPtr;
358 /***********************************************************************
359 * register_builtin
361 * Register a builtin control class.
362 * This allows having both ASCII and Unicode winprocs for the same class.
364 static CLASS *register_builtin( const struct builtin_class_descr *descr )
366 ATOM atom;
367 CLASS *classPtr;
369 if (!(atom = GlobalAddAtomA( descr->name ))) return 0;
371 if (!(classPtr = CLASS_RegisterClass( atom, user32_module, FALSE,
372 descr->style, 0, descr->extra ))) return 0;
374 classPtr->hCursor = LoadCursorA( 0, (LPSTR)descr->cursor );
375 classPtr->hbrBackground = descr->brush;
376 classPtr->winproc = WINPROC_AllocProc( descr->procA, descr->procW );
377 release_class_ptr( classPtr );
378 return classPtr;
382 /***********************************************************************
383 * CLASS_RegisterBuiltinClasses
385 void CLASS_RegisterBuiltinClasses(void)
387 extern const struct builtin_class_descr BUTTON_builtin_class;
388 extern const struct builtin_class_descr COMBO_builtin_class;
389 extern const struct builtin_class_descr COMBOLBOX_builtin_class;
390 extern const struct builtin_class_descr DIALOG_builtin_class;
391 extern const struct builtin_class_descr DESKTOP_builtin_class;
392 extern const struct builtin_class_descr EDIT_builtin_class;
393 extern const struct builtin_class_descr ICONTITLE_builtin_class;
394 extern const struct builtin_class_descr LISTBOX_builtin_class;
395 extern const struct builtin_class_descr MDICLIENT_builtin_class;
396 extern const struct builtin_class_descr MENU_builtin_class;
397 extern const struct builtin_class_descr SCROLL_builtin_class;
398 extern const struct builtin_class_descr STATIC_builtin_class;
400 register_builtin( &DESKTOP_builtin_class );
401 register_builtin( &BUTTON_builtin_class );
402 register_builtin( &COMBO_builtin_class );
403 register_builtin( &COMBOLBOX_builtin_class );
404 register_builtin( &DIALOG_builtin_class );
405 register_builtin( &EDIT_builtin_class );
406 register_builtin( &ICONTITLE_builtin_class );
407 register_builtin( &LISTBOX_builtin_class );
408 register_builtin( &MDICLIENT_builtin_class );
409 register_builtin( &MENU_builtin_class );
410 register_builtin( &SCROLL_builtin_class );
411 register_builtin( &STATIC_builtin_class );
415 /***********************************************************************
416 * CLASS_AddWindow
418 * Add a new window using this class, and set the necessary
419 * information inside the window structure.
421 void CLASS_AddWindow( CLASS *class, WND *win, BOOL unicode )
423 win->class = class;
424 win->clsStyle = class->style;
425 win->winproc = class->winproc;
426 if (WINPROC_IsUnicode( win->winproc, unicode )) win->flags |= WIN_ISUNICODE;
430 /***********************************************************************
431 * RegisterClassA (USER32.@)
433 * Register a window class.
435 * RETURNS
436 * >0: Unique identifier
437 * 0: Failure
439 ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
441 WNDCLASSEXA wcex;
443 wcex.cbSize = sizeof(wcex);
444 wcex.style = wc->style;
445 wcex.lpfnWndProc = wc->lpfnWndProc;
446 wcex.cbClsExtra = wc->cbClsExtra;
447 wcex.cbWndExtra = wc->cbWndExtra;
448 wcex.hInstance = wc->hInstance;
449 wcex.hIcon = wc->hIcon;
450 wcex.hCursor = wc->hCursor;
451 wcex.hbrBackground = wc->hbrBackground;
452 wcex.lpszMenuName = wc->lpszMenuName;
453 wcex.lpszClassName = wc->lpszClassName;
454 wcex.hIconSm = 0;
455 return RegisterClassExA( &wcex );
459 /***********************************************************************
460 * RegisterClassW (USER32.@)
462 * See RegisterClassA.
464 ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
466 WNDCLASSEXW wcex;
468 wcex.cbSize = sizeof(wcex);
469 wcex.style = wc->style;
470 wcex.lpfnWndProc = wc->lpfnWndProc;
471 wcex.cbClsExtra = wc->cbClsExtra;
472 wcex.cbWndExtra = wc->cbWndExtra;
473 wcex.hInstance = wc->hInstance;
474 wcex.hIcon = wc->hIcon;
475 wcex.hCursor = wc->hCursor;
476 wcex.hbrBackground = wc->hbrBackground;
477 wcex.lpszMenuName = wc->lpszMenuName;
478 wcex.lpszClassName = wc->lpszClassName;
479 wcex.hIconSm = 0;
480 return RegisterClassExW( &wcex );
484 /***********************************************************************
485 * RegisterClassExA (USER32.@)
487 ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
489 ATOM atom;
490 CLASS *classPtr;
491 HINSTANCE instance;
493 if (wc->hInstance == user32_module)
495 /* we can't register a class for user32 */
496 SetLastError( ERROR_INVALID_PARAMETER );
497 return 0;
499 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
501 if (!(atom = GlobalAddAtomA( wc->lpszClassName ))) return 0;
503 if (!(classPtr = CLASS_RegisterClass( atom, instance, !(wc->style & CS_GLOBALCLASS),
504 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
505 return 0;
507 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
508 atom, wc->lpfnWndProc, instance, wc->hbrBackground,
509 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
511 classPtr->hIcon = wc->hIcon;
512 classPtr->hIconSm = wc->hIconSm;
513 classPtr->hCursor = wc->hCursor;
514 classPtr->hbrBackground = wc->hbrBackground;
515 classPtr->winproc = WINPROC_AllocProc( wc->lpfnWndProc, NULL );
516 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
517 release_class_ptr( classPtr );
518 return atom;
522 /***********************************************************************
523 * RegisterClassExW (USER32.@)
525 ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
527 ATOM atom;
528 CLASS *classPtr;
529 HINSTANCE instance;
531 if (wc->hInstance == user32_module)
533 /* we can't register a class for user32 */
534 SetLastError( ERROR_INVALID_PARAMETER );
535 return 0;
537 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
539 if (!(atom = GlobalAddAtomW( wc->lpszClassName ))) return 0;
541 if (!(classPtr = CLASS_RegisterClass( atom, instance, !(wc->style & CS_GLOBALCLASS),
542 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
543 return 0;
545 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
546 atom, wc->lpfnWndProc, instance, wc->hbrBackground,
547 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
549 classPtr->hIcon = wc->hIcon;
550 classPtr->hIconSm = wc->hIconSm;
551 classPtr->hCursor = wc->hCursor;
552 classPtr->hbrBackground = wc->hbrBackground;
553 classPtr->winproc = WINPROC_AllocProc( NULL, wc->lpfnWndProc );
554 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
555 release_class_ptr( classPtr );
556 return atom;
560 /***********************************************************************
561 * UnregisterClassA (USER32.@)
563 BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
565 ATOM atom = HIWORD(className) ? GlobalFindAtomA( className ) : LOWORD(className);
566 return UnregisterClassW( MAKEINTATOMW(atom), hInstance );
569 /***********************************************************************
570 * UnregisterClassW (USER32.@)
572 BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
574 CLASS *classPtr = NULL;
575 ATOM atom = HIWORD(className) ? GlobalFindAtomW( className ) : LOWORD(className);
577 TRACE("%s %p %x\n",debugstr_w(className), hInstance, atom);
579 if (!atom)
581 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
582 return FALSE;
585 SERVER_START_REQ( destroy_class )
587 req->atom = atom;
588 req->instance = hInstance;
589 if (!wine_server_call_err( req )) classPtr = reply->client_ptr;
591 SERVER_END_REQ;
593 if (classPtr) CLASS_FreeClass( classPtr );
594 return (classPtr != NULL);
598 /***********************************************************************
599 * GetClassWord (USER32.@)
601 WORD WINAPI GetClassWord( HWND hwnd, INT offset )
603 CLASS *class;
604 WORD retvalue = 0;
606 if (offset < 0) return GetClassLongA( hwnd, offset );
608 TRACE("%p %x\n",hwnd, offset);
610 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
612 if (class == CLASS_OTHER_PROCESS)
614 SERVER_START_REQ( set_class_info )
616 req->window = hwnd;
617 req->flags = 0;
618 req->extra_offset = offset;
619 req->extra_size = sizeof(retvalue);
620 if (!wine_server_call_err( req ))
621 memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
623 SERVER_END_REQ;
624 return retvalue;
627 if (offset <= class->cbClsExtra - sizeof(WORD))
628 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
629 else
630 SetLastError( ERROR_INVALID_INDEX );
631 release_class_ptr( class );
632 return retvalue;
636 /***********************************************************************
637 * GetClassLongW (USER32.@)
639 DWORD WINAPI GetClassLongW( HWND hwnd, INT offset )
641 CLASS *class;
642 DWORD retvalue = 0;
644 TRACE("%p %d\n", hwnd, offset);
646 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
648 if (class == CLASS_OTHER_PROCESS)
650 SERVER_START_REQ( set_class_info )
652 req->window = hwnd;
653 req->flags = 0;
654 req->extra_offset = (offset >= 0) ? offset : -1;
655 req->extra_size = (offset >= 0) ? sizeof(retvalue) : 0;
656 if (!wine_server_call_err( req ))
658 switch(offset)
660 case GCLP_HBRBACKGROUND:
661 case GCLP_HCURSOR:
662 case GCLP_HICON:
663 case GCLP_HICONSM:
664 case GCLP_WNDPROC:
665 case GCLP_MENUNAME:
666 FIXME( "offset %d not supported on other process window %p\n", offset, hwnd );
667 SetLastError( ERROR_INVALID_HANDLE );
668 break;
669 case GCL_STYLE:
670 retvalue = reply->old_style;
671 break;
672 case GCL_CBWNDEXTRA:
673 retvalue = reply->old_win_extra;
674 break;
675 case GCL_CBCLSEXTRA:
676 retvalue = reply->old_extra;
677 break;
678 case GCLP_HMODULE:
679 retvalue = (DWORD)reply->old_instance;
680 break;
681 case GCW_ATOM:
682 retvalue = reply->old_atom;
683 break;
684 default:
685 if (offset >= 0) memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
686 else SetLastError( ERROR_INVALID_INDEX );
687 break;
691 SERVER_END_REQ;
692 return retvalue;
695 if (offset >= 0)
697 if (offset <= class->cbClsExtra - sizeof(LONG))
698 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
699 else
700 SetLastError( ERROR_INVALID_INDEX );
701 release_class_ptr( class );
702 return retvalue;
705 switch(offset)
707 case GCLP_HBRBACKGROUND:
708 retvalue = (DWORD)class->hbrBackground;
709 break;
710 case GCLP_HCURSOR:
711 retvalue = (DWORD)class->hCursor;
712 break;
713 case GCLP_HICON:
714 retvalue = (DWORD)class->hIcon;
715 break;
716 case GCLP_HICONSM:
717 retvalue = (DWORD)class->hIconSm;
718 break;
719 case GCL_STYLE:
720 retvalue = (DWORD)class->style;
721 break;
722 case GCL_CBWNDEXTRA:
723 retvalue = (DWORD)class->cbWndExtra;
724 break;
725 case GCL_CBCLSEXTRA:
726 retvalue = (DWORD)class->cbClsExtra;
727 break;
728 case GCLP_HMODULE:
729 retvalue = (DWORD)class->hInstance;
730 break;
731 case GCLP_WNDPROC:
732 retvalue = (DWORD)WINPROC_GetProc( class->winproc, TRUE );
733 break;
734 case GCLP_MENUNAME:
735 retvalue = (DWORD)CLASS_GetMenuNameW( class );
736 break;
737 case GCW_ATOM:
738 retvalue = (DWORD)class->atomName;
739 break;
740 default:
741 SetLastError( ERROR_INVALID_INDEX );
742 break;
744 release_class_ptr( class );
745 return retvalue;
749 /***********************************************************************
750 * GetClassLongA (USER32.@)
752 DWORD WINAPI GetClassLongA( HWND hwnd, INT offset )
754 CLASS *class;
755 DWORD retvalue;
757 if (offset != GCLP_WNDPROC && offset != GCLP_MENUNAME)
758 return GetClassLongW( hwnd, offset );
760 TRACE("%p %d\n", hwnd, offset);
762 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
764 if (class == CLASS_OTHER_PROCESS)
766 FIXME( "offset %d not supported on other process window %p\n", offset, hwnd );
767 SetLastError( ERROR_INVALID_HANDLE );
768 return 0;
771 if (offset == GCLP_WNDPROC)
772 retvalue = (DWORD)WINPROC_GetProc( class->winproc, FALSE );
773 else /* GCL_MENUNAME */
774 retvalue = (DWORD)CLASS_GetMenuNameA( class );
776 release_class_ptr( class );
777 return retvalue;
781 /***********************************************************************
782 * SetClassWord (USER32.@)
784 WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
786 CLASS *class;
787 WORD retval = 0;
789 if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
791 TRACE("%p %d %x\n", hwnd, offset, newval);
793 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
795 SERVER_START_REQ( set_class_info )
797 req->window = hwnd;
798 req->flags = SET_CLASS_EXTRA;
799 req->extra_offset = offset;
800 req->extra_size = sizeof(newval);
801 memcpy( &req->extra_value, &newval, sizeof(newval) );
802 if (!wine_server_call_err( req ))
804 void *ptr = (char *)(class + 1) + offset;
805 memcpy( &retval, ptr, sizeof(retval) );
806 memcpy( ptr, &newval, sizeof(newval) );
809 SERVER_END_REQ;
810 release_class_ptr( class );
811 return retval;
815 /***********************************************************************
816 * SetClassLongW (USER32.@)
818 DWORD WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
820 CLASS *class;
821 DWORD retval = 0;
823 TRACE("%p %d %lx\n", hwnd, offset, newval);
825 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
827 if (offset >= 0)
829 if (set_server_info( hwnd, offset, newval ))
831 void *ptr = (char *)(class + 1) + offset;
832 memcpy( &retval, ptr, sizeof(retval) );
833 memcpy( ptr, &newval, sizeof(newval) );
836 else switch(offset)
838 case GCLP_MENUNAME:
839 CLASS_SetMenuNameW( class, (LPCWSTR)newval );
840 retval = 0; /* Old value is now meaningless anyway */
841 break;
842 case GCLP_WNDPROC:
843 retval = (DWORD)WINPROC_GetProc( class->winproc, TRUE );
844 class->winproc = WINPROC_AllocProc( NULL, (WNDPROC)newval );
845 break;
846 case GCLP_HBRBACKGROUND:
847 retval = (DWORD)class->hbrBackground;
848 class->hbrBackground = (HBRUSH)newval;
849 break;
850 case GCLP_HCURSOR:
851 retval = (DWORD)class->hCursor;
852 class->hCursor = (HCURSOR)newval;
853 break;
854 case GCLP_HICON:
855 retval = (DWORD)class->hIcon;
856 class->hIcon = (HICON)newval;
857 break;
858 case GCLP_HICONSM:
859 retval = (DWORD)class->hIconSm;
860 class->hIconSm = (HICON)newval;
861 break;
862 case GCL_STYLE:
863 if (!set_server_info( hwnd, offset, newval )) break;
864 retval = (DWORD)class->style;
865 class->style = newval;
866 break;
867 case GCL_CBWNDEXTRA:
868 if (!set_server_info( hwnd, offset, newval )) break;
869 retval = (DWORD)class->cbWndExtra;
870 class->cbWndExtra = newval;
871 break;
872 case GCLP_HMODULE:
873 if (!set_server_info( hwnd, offset, newval )) break;
874 retval = (DWORD)class->hInstance;
875 class->hInstance = (HINSTANCE)newval;
876 break;
877 case GCW_ATOM:
878 if (!set_server_info( hwnd, offset, newval )) break;
879 retval = (DWORD)class->atomName;
880 class->atomName = newval;
881 break;
882 case GCL_CBCLSEXTRA: /* cannot change this one */
883 SetLastError( ERROR_INVALID_PARAMETER );
884 break;
885 default:
886 SetLastError( ERROR_INVALID_INDEX );
887 break;
889 release_class_ptr( class );
890 return retval;
894 /***********************************************************************
895 * SetClassLongA (USER32.@)
897 DWORD WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
899 CLASS *class;
900 DWORD retval;
902 if (offset != GCLP_WNDPROC && offset != GCLP_MENUNAME)
903 return SetClassLongW( hwnd, offset, newval );
905 TRACE("%p %d %lx\n", hwnd, offset, newval);
907 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
909 if (offset == GCLP_WNDPROC)
911 retval = (DWORD)WINPROC_GetProc( class->winproc, FALSE );
912 class->winproc = WINPROC_AllocProc( (WNDPROC)newval, NULL );
914 else /* GCL_MENUNAME */
916 CLASS_SetMenuNameA( class, (LPCSTR)newval );
917 retval = 0; /* Old value is now meaningless anyway */
919 release_class_ptr( class );
920 return retval;
924 /***********************************************************************
925 * GetClassNameA (USER32.@)
927 INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
929 INT ret = GlobalGetAtomNameA( GetClassLongA( hwnd, GCW_ATOM ), buffer, count );
931 TRACE("%p %s %x\n",hwnd, debugstr_a(buffer), count);
932 return ret;
936 /***********************************************************************
937 * GetClassNameW (USER32.@)
939 INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
941 INT ret = GlobalGetAtomNameW( GetClassLongW( hwnd, GCW_ATOM ), buffer, count );
943 TRACE("%p %s %x\n",hwnd, debugstr_w(buffer), count);
944 return ret;
948 /***********************************************************************
949 * RealGetWindowClassA (USER32.@)
951 UINT WINAPI RealGetWindowClassA( HWND hwnd, LPSTR buffer, UINT count )
953 return GetClassNameA( hwnd, buffer, count );
957 /***********************************************************************
958 * RealGetWindowClassW (USER32.@)
960 UINT WINAPI RealGetWindowClassW( HWND hwnd, LPWSTR buffer, UINT count )
962 return GetClassNameW( hwnd, buffer, count );
966 /***********************************************************************
967 * GetClassInfoA (USER32.@)
969 BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name, WNDCLASSA *wc )
971 WNDCLASSEXA wcex;
972 UINT ret = GetClassInfoExA( hInstance, name, &wcex );
974 if (ret)
976 wc->style = wcex.style;
977 wc->lpfnWndProc = wcex.lpfnWndProc;
978 wc->cbClsExtra = wcex.cbClsExtra;
979 wc->cbWndExtra = wcex.cbWndExtra;
980 wc->hInstance = wcex.hInstance;
981 wc->hIcon = wcex.hIcon;
982 wc->hCursor = wcex.hCursor;
983 wc->hbrBackground = wcex.hbrBackground;
984 wc->lpszMenuName = wcex.lpszMenuName;
985 wc->lpszClassName = wcex.lpszClassName;
987 return ret;
991 /***********************************************************************
992 * GetClassInfoW (USER32.@)
994 BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSW *wc )
996 WNDCLASSEXW wcex;
997 UINT ret = GetClassInfoExW( hInstance, name, &wcex );
999 if (ret)
1001 wc->style = wcex.style;
1002 wc->lpfnWndProc = wcex.lpfnWndProc;
1003 wc->cbClsExtra = wcex.cbClsExtra;
1004 wc->cbWndExtra = wcex.cbWndExtra;
1005 wc->hInstance = wcex.hInstance;
1006 wc->hIcon = wcex.hIcon;
1007 wc->hCursor = wcex.hCursor;
1008 wc->hbrBackground = wcex.hbrBackground;
1009 wc->lpszMenuName = wcex.lpszMenuName;
1010 wc->lpszClassName = wcex.lpszClassName;
1012 return ret;
1016 /***********************************************************************
1017 * GetClassInfoExA (USER32.@)
1019 BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name, WNDCLASSEXA *wc )
1021 ATOM atom = HIWORD(name) ? GlobalFindAtomA( name ) : LOWORD(name);
1022 CLASS *classPtr;
1024 TRACE("%p %s %x %p\n", hInstance, debugstr_a(name), atom, wc);
1026 if (!hInstance) hInstance = user32_module;
1028 if (!atom || !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
1030 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1031 return FALSE;
1033 wc->style = classPtr->style;
1034 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, FALSE );
1035 wc->cbClsExtra = classPtr->cbClsExtra;
1036 wc->cbWndExtra = classPtr->cbWndExtra;
1037 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1038 wc->hIcon = (HICON)classPtr->hIcon;
1039 wc->hIconSm = (HICON)classPtr->hIconSm;
1040 wc->hCursor = (HCURSOR)classPtr->hCursor;
1041 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1042 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
1043 wc->lpszClassName = name;
1044 release_class_ptr( classPtr );
1046 /* We must return the atom of the class here instead of just TRUE. */
1047 return atom;
1051 /***********************************************************************
1052 * GetClassInfoExW (USER32.@)
1054 BOOL WINAPI GetClassInfoExW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSEXW *wc )
1056 ATOM atom = HIWORD(name) ? GlobalFindAtomW( name ) : LOWORD(name);
1057 CLASS *classPtr;
1059 TRACE("%p %s %x %p\n", hInstance, debugstr_w(name), atom, wc);
1061 if (!hInstance) hInstance = user32_module;
1063 if (!atom || !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
1065 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1066 return FALSE;
1068 wc->style = classPtr->style;
1069 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, TRUE );
1070 wc->cbClsExtra = classPtr->cbClsExtra;
1071 wc->cbWndExtra = classPtr->cbWndExtra;
1072 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1073 wc->hIcon = (HICON)classPtr->hIcon;
1074 wc->hIconSm = (HICON)classPtr->hIconSm;
1075 wc->hCursor = (HCURSOR)classPtr->hCursor;
1076 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1077 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1078 wc->lpszClassName = name;
1079 release_class_ptr( classPtr );
1081 /* We must return the atom of the class here instead of just TRUE. */
1082 return atom;
1086 #if 0 /* toolhelp is in kernel, so this cannot work */
1088 /***********************************************************************
1089 * ClassFirst (TOOLHELP.69)
1091 BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
1093 TRACE("%p\n",pClassEntry);
1094 pClassEntry->wNext = 1;
1095 return ClassNext16( pClassEntry );
1099 /***********************************************************************
1100 * ClassNext (TOOLHELP.70)
1102 BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
1104 int i;
1105 CLASS *class = firstClass;
1107 TRACE("%p\n",pClassEntry);
1109 if (!pClassEntry->wNext) return FALSE;
1110 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1111 if (!class)
1113 pClassEntry->wNext = 0;
1114 return FALSE;
1116 pClassEntry->hInst = class->hInstance;
1117 pClassEntry->wNext++;
1118 GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
1119 sizeof(pClassEntry->szClassName) );
1120 return TRUE;
1122 #endif
1124 /* 64bit versions */
1126 #ifdef GetClassLongPtrA
1127 #undef GetClassLongPtrA
1128 #endif
1130 #ifdef GetClassLongPtrW
1131 #undef GetClassLongPtrW
1132 #endif
1134 #ifdef SetClassLongPtrA
1135 #undef SetClassLongPtrA
1136 #endif
1138 #ifdef SetClassLongPtrW
1139 #undef SetClassLongPtrW
1140 #endif
1142 /***********************************************************************
1143 * GetClassLongPtrA (USER32.@)
1145 ULONG_PTR WINAPI GetClassLongPtrA( HWND hwnd, INT offset )
1147 FIXME("\n");
1148 return 0;
1151 /***********************************************************************
1152 * GetClassLongPtrW (USER32.@)
1154 ULONG_PTR WINAPI GetClassLongPtrW( HWND hwnd, INT offset )
1156 FIXME("\n");
1157 return 0;
1160 /***********************************************************************
1161 * SetClassLongPtrW (USER32.@)
1163 ULONG_PTR WINAPI SetClassLongPtrW( HWND hwnd, INT offset, LONG_PTR newval )
1165 FIXME("\n");
1166 return 0;
1169 /***********************************************************************
1170 * SetClassLongPtrA (USER32.@)
1172 ULONG_PTR WINAPI SetClassLongPtrA( HWND hwnd, INT offset, LONG_PTR newval )
1174 FIXME("\n");
1175 return 0;