push ad05fa8ea86b4a1581adad6c24ad723042d385d2
[wine/hacks.git] / dlls / user32 / class.c
blob9a1dd2f0fd164fb7e5b1a4333f2260460b74fdf8
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/unicode.h"
35 #include "win.h"
36 #include "user_private.h"
37 #include "controls.h"
38 #include "wine/server.h"
39 #include "wine/list.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(class);
44 #define MAX_ATOM_LEN 255 /* from dlls/kernel32/atom.c */
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 WCHAR name[MAX_ATOM_LEN + 1];
62 } CLASS;
64 static struct list class_list = LIST_INIT( class_list );
66 #define CLASS_OTHER_PROCESS ((CLASS *)1)
68 /***********************************************************************
69 * get_class_ptr
71 static CLASS *get_class_ptr( HWND hwnd, BOOL write_access )
73 WND *ptr = WIN_GetPtr( hwnd );
75 if (ptr)
77 if (ptr != WND_OTHER_PROCESS && ptr != WND_DESKTOP) return ptr->class;
78 if (!write_access) return CLASS_OTHER_PROCESS;
80 /* modifying classes in other processes is not allowed */
81 if (ptr == WND_DESKTOP || IsWindow( hwnd ))
83 SetLastError( ERROR_ACCESS_DENIED );
84 return NULL;
87 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
88 return NULL;
92 /***********************************************************************
93 * release_class_ptr
95 static inline void release_class_ptr( CLASS *ptr )
97 USER_Unlock();
101 /***********************************************************************
102 * get_int_atom_value
104 static ATOM get_int_atom_value( LPCWSTR name )
106 UINT ret = 0;
108 if (IS_INTRESOURCE(name)) return LOWORD(name);
109 if (*name++ != '#') return 0;
110 while (*name)
112 if (*name < '0' || *name > '9') return 0;
113 ret = ret * 10 + *name++ - '0';
114 if (ret > 0xffff) return 0;
116 return ret;
120 /***********************************************************************
121 * set_server_info
123 * Set class info with the wine server.
125 static BOOL set_server_info( HWND hwnd, INT offset, LONG_PTR newval, UINT size )
127 BOOL ret;
129 SERVER_START_REQ( set_class_info )
131 req->window = hwnd;
132 req->extra_offset = -1;
133 switch(offset)
135 case GCW_ATOM:
136 req->flags = SET_CLASS_ATOM;
137 req->atom = newval;
138 case GCL_STYLE:
139 req->flags = SET_CLASS_STYLE;
140 req->style = newval;
141 break;
142 case GCL_CBWNDEXTRA:
143 req->flags = SET_CLASS_WINEXTRA;
144 req->win_extra = newval;
145 break;
146 case GCLP_HMODULE:
147 req->flags = SET_CLASS_INSTANCE;
148 req->instance = (void *)newval;
149 break;
150 default:
151 assert( offset >= 0 );
152 req->flags = SET_CLASS_EXTRA;
153 req->extra_offset = offset;
154 req->extra_size = size;
155 if ( size == sizeof(LONG) )
157 LONG newlong = newval;
158 memcpy( &req->extra_value, &newlong, sizeof(LONG) );
160 else
161 memcpy( &req->extra_value, &newval, sizeof(LONG_PTR) );
162 break;
164 ret = !wine_server_call_err( req );
166 SERVER_END_REQ;
167 return ret;
171 /***********************************************************************
172 * CLASS_GetMenuNameA
174 * Get the menu name as a ASCII string.
176 static inline LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
178 if (!HIWORD(classPtr->menuName)) return (LPSTR)classPtr->menuName;
179 return (LPSTR)(classPtr->menuName + strlenW(classPtr->menuName) + 1);
183 /***********************************************************************
184 * CLASS_GetMenuNameW
186 * Get the menu name as a Unicode string.
188 static inline LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
190 return classPtr->menuName;
194 /***********************************************************************
195 * CLASS_SetMenuNameA
197 * Set the menu name in a class structure by copying the string.
199 static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
201 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
202 if (HIWORD(name))
204 DWORD lenA = strlen(name) + 1;
205 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, name, lenA, NULL, 0 );
206 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
207 MultiByteToWideChar( CP_ACP, 0, name, lenA, classPtr->menuName, lenW );
208 memcpy( classPtr->menuName + lenW, name, lenA );
210 else classPtr->menuName = (LPWSTR)name;
214 /***********************************************************************
215 * CLASS_SetMenuNameW
217 * Set the menu name in a class structure by copying the string.
219 static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
221 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
222 if (HIWORD(name))
224 DWORD lenW = strlenW(name) + 1;
225 DWORD lenA = WideCharToMultiByte( CP_ACP, 0, name, lenW, NULL, 0, NULL, NULL );
226 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
227 memcpy( classPtr->menuName, name, lenW*sizeof(WCHAR) );
228 WideCharToMultiByte( CP_ACP, 0, name, lenW,
229 (char *)(classPtr->menuName + lenW), lenA, NULL, NULL );
231 else classPtr->menuName = (LPWSTR)name;
235 /***********************************************************************
236 * CLASS_FreeClass
238 * Free a class structure.
240 static void CLASS_FreeClass( CLASS *classPtr )
242 TRACE("%p\n", classPtr);
244 USER_Lock();
246 list_remove( &classPtr->entry );
247 if (classPtr->hbrBackground > (HBRUSH)(COLOR_GRADIENTINACTIVECAPTION + 1))
248 DeleteObject( classPtr->hbrBackground );
249 HeapFree( GetProcessHeap(), 0, classPtr->menuName );
250 HeapFree( GetProcessHeap(), 0, classPtr );
251 USER_Unlock();
255 /***********************************************************************
256 * CLASS_FreeModuleClasses
258 void CLASS_FreeModuleClasses( HMODULE16 hModule )
260 struct list *ptr, *next;
262 TRACE("0x%08x\n", hModule);
264 USER_Lock();
265 for (ptr = list_head( &class_list ); ptr; ptr = next)
267 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
268 next = list_next( &class_list, ptr );
269 if (class->hInstance == HINSTANCE_32(hModule))
271 BOOL ret;
273 SERVER_START_REQ( destroy_class )
275 req->atom = class->atomName;
276 req->instance = class->hInstance;
277 ret = !wine_server_call_err( req );
279 SERVER_END_REQ;
280 if (ret) CLASS_FreeClass( class );
283 USER_Unlock();
287 /***********************************************************************
288 * CLASS_FindClass
290 * Return a pointer to the class.
291 * hinstance has been normalized by the caller.
293 static CLASS *CLASS_FindClass( LPCWSTR name, HINSTANCE hinstance )
295 struct list *ptr;
296 ATOM atom = get_int_atom_value( name );
298 USER_Lock();
300 LIST_FOR_EACH( ptr, &class_list )
302 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
303 if (atom)
305 if (class->atomName != atom) continue;
307 else
309 if (!name || strcmpiW( class->name, name )) continue;
311 if (!hinstance || !class->local || class->hInstance == hinstance)
313 TRACE("%s %p -> %p\n", debugstr_w(name), hinstance, class);
314 return class;
317 USER_Unlock();
318 TRACE("%s %p -> not found\n", debugstr_w(name), hinstance);
319 return NULL;
323 /***********************************************************************
324 * CLASS_RegisterClass
326 * The real RegisterClass() functionality.
328 static CLASS *CLASS_RegisterClass( LPCWSTR name, HINSTANCE hInstance, BOOL local,
329 DWORD style, INT classExtra, INT winExtra )
331 CLASS *classPtr;
332 BOOL ret;
334 TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
335 debugstr_w(name), hInstance, style, classExtra, winExtra );
337 /* Fix the extra bytes value */
339 if (classExtra < 0 || winExtra < 0)
341 SetLastError( ERROR_INVALID_PARAMETER );
342 return NULL;
344 if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
345 WARN("Class extra bytes %d is > 40\n", classExtra);
346 if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
347 WARN("Win extra bytes %d is > 40\n", winExtra );
349 classPtr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLASS) + classExtra );
350 if (!classPtr) return NULL;
352 classPtr->atomName = get_int_atom_value( name );
353 if (!classPtr->atomName && name) strcpyW( classPtr->name, name );
354 else GlobalGetAtomNameW( classPtr->atomName, classPtr->name, sizeof(classPtr->name)/sizeof(WCHAR) );
356 SERVER_START_REQ( create_class )
358 req->local = local;
359 req->style = style;
360 req->instance = hInstance;
361 req->extra = classExtra;
362 req->win_extra = winExtra;
363 req->client_ptr = classPtr;
364 req->atom = classPtr->atomName;
365 if (!req->atom && name) wine_server_add_data( req, name, strlenW(name) * sizeof(WCHAR) );
366 ret = !wine_server_call_err( req );
367 classPtr->atomName = reply->atom;
369 SERVER_END_REQ;
370 if (!ret)
372 HeapFree( GetProcessHeap(), 0, classPtr );
373 return NULL;
376 classPtr->style = style;
377 classPtr->local = local;
378 classPtr->cbWndExtra = winExtra;
379 classPtr->cbClsExtra = classExtra;
380 classPtr->hInstance = hInstance;
382 /* Other non-null values must be set by caller */
384 USER_Lock();
385 if (local) list_add_head( &class_list, &classPtr->entry );
386 else list_add_tail( &class_list, &classPtr->entry );
387 return classPtr;
391 /***********************************************************************
392 * register_builtin
394 * Register a builtin control class.
395 * This allows having both ASCII and Unicode winprocs for the same class.
397 static WNDPROC register_builtin( const struct builtin_class_descr *descr )
399 CLASS *classPtr;
401 if (!(classPtr = CLASS_RegisterClass( descr->name, user32_module, FALSE,
402 descr->style, 0, descr->extra ))) return 0;
404 classPtr->hCursor = LoadCursorA( 0, (LPSTR)descr->cursor );
405 classPtr->hbrBackground = descr->brush;
406 classPtr->winproc = WINPROC_AllocProc( descr->procA, descr->procW );
407 release_class_ptr( classPtr );
408 return classPtr->winproc;
412 /***********************************************************************
413 * CLASS_RegisterBuiltinClasses
415 void CLASS_RegisterBuiltinClasses(void)
417 extern const struct builtin_class_descr BUTTON_builtin_class;
418 extern const struct builtin_class_descr COMBO_builtin_class;
419 extern const struct builtin_class_descr COMBOLBOX_builtin_class;
420 extern const struct builtin_class_descr DIALOG_builtin_class;
421 extern const struct builtin_class_descr DESKTOP_builtin_class;
422 extern const struct builtin_class_descr EDIT_builtin_class;
423 extern const struct builtin_class_descr ICONTITLE_builtin_class;
424 extern const struct builtin_class_descr LISTBOX_builtin_class;
425 extern const struct builtin_class_descr MDICLIENT_builtin_class;
426 extern const struct builtin_class_descr MENU_builtin_class;
427 extern const struct builtin_class_descr SCROLL_builtin_class;
428 extern const struct builtin_class_descr STATIC_builtin_class;
430 register_builtin( &DESKTOP_builtin_class );
431 register_builtin( &BUTTON_builtin_class );
432 register_builtin( &COMBO_builtin_class );
433 register_builtin( &COMBOLBOX_builtin_class );
434 register_builtin( &DIALOG_builtin_class );
435 EDIT_winproc_handle = register_builtin( &EDIT_builtin_class );
436 register_builtin( &ICONTITLE_builtin_class );
437 register_builtin( &LISTBOX_builtin_class );
438 register_builtin( &MDICLIENT_builtin_class );
439 register_builtin( &MENU_builtin_class );
440 register_builtin( &SCROLL_builtin_class );
441 register_builtin( &STATIC_builtin_class );
443 /* the DefWindowProc winprocs are magic too */
444 WINPROC_AllocProc( DefWindowProcA, DefWindowProcW );
448 /***********************************************************************
449 * CLASS_AddWindow
451 * Add a new window using this class, and set the necessary
452 * information inside the window structure.
454 void CLASS_AddWindow( CLASS *class, WND *win, BOOL unicode )
456 win->class = class;
457 win->clsStyle = class->style;
458 win->winproc = class->winproc;
459 if (WINPROC_IsUnicode( win->winproc, unicode )) win->flags |= WIN_ISUNICODE;
463 /***********************************************************************
464 * RegisterClassA (USER32.@)
466 * Register a window class.
468 * RETURNS
469 * >0: Unique identifier
470 * 0: Failure
472 ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
474 WNDCLASSEXA wcex;
476 wcex.cbSize = sizeof(wcex);
477 wcex.style = wc->style;
478 wcex.lpfnWndProc = wc->lpfnWndProc;
479 wcex.cbClsExtra = wc->cbClsExtra;
480 wcex.cbWndExtra = wc->cbWndExtra;
481 wcex.hInstance = wc->hInstance;
482 wcex.hIcon = wc->hIcon;
483 wcex.hCursor = wc->hCursor;
484 wcex.hbrBackground = wc->hbrBackground;
485 wcex.lpszMenuName = wc->lpszMenuName;
486 wcex.lpszClassName = wc->lpszClassName;
487 wcex.hIconSm = 0;
488 return RegisterClassExA( &wcex );
492 /***********************************************************************
493 * RegisterClassW (USER32.@)
495 * See RegisterClassA.
497 ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
499 WNDCLASSEXW wcex;
501 wcex.cbSize = sizeof(wcex);
502 wcex.style = wc->style;
503 wcex.lpfnWndProc = wc->lpfnWndProc;
504 wcex.cbClsExtra = wc->cbClsExtra;
505 wcex.cbWndExtra = wc->cbWndExtra;
506 wcex.hInstance = wc->hInstance;
507 wcex.hIcon = wc->hIcon;
508 wcex.hCursor = wc->hCursor;
509 wcex.hbrBackground = wc->hbrBackground;
510 wcex.lpszMenuName = wc->lpszMenuName;
511 wcex.lpszClassName = wc->lpszClassName;
512 wcex.hIconSm = 0;
513 return RegisterClassExW( &wcex );
517 /***********************************************************************
518 * RegisterClassExA (USER32.@)
520 ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
522 ATOM atom;
523 CLASS *classPtr;
524 HINSTANCE instance;
526 if (wc->hInstance == user32_module)
528 /* we can't register a class for user32 */
529 SetLastError( ERROR_INVALID_PARAMETER );
530 return 0;
532 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
534 if (!IS_INTRESOURCE(wc->lpszClassName))
536 WCHAR name[MAX_ATOM_LEN + 1];
538 if (!MultiByteToWideChar( CP_ACP, 0, wc->lpszClassName, -1, name, MAX_ATOM_LEN + 1 )) return 0;
539 classPtr = CLASS_RegisterClass( name, instance, !(wc->style & CS_GLOBALCLASS),
540 wc->style, wc->cbClsExtra, wc->cbWndExtra );
542 else
544 classPtr = CLASS_RegisterClass( (LPCWSTR)wc->lpszClassName, instance,
545 !(wc->style & CS_GLOBALCLASS), wc->style,
546 wc->cbClsExtra, wc->cbWndExtra );
548 if (!classPtr) return 0;
549 atom = classPtr->atomName;
551 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
552 debugstr_a(wc->lpszClassName), atom, wc->lpfnWndProc, instance, wc->hbrBackground,
553 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
555 classPtr->hIcon = wc->hIcon;
556 classPtr->hIconSm = wc->hIconSm;
557 classPtr->hCursor = wc->hCursor;
558 classPtr->hbrBackground = wc->hbrBackground;
559 classPtr->winproc = WINPROC_AllocProc( wc->lpfnWndProc, NULL );
560 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
561 release_class_ptr( classPtr );
562 return atom;
566 /***********************************************************************
567 * RegisterClassExW (USER32.@)
569 ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
571 ATOM atom;
572 CLASS *classPtr;
573 HINSTANCE instance;
575 if (wc->hInstance == user32_module)
577 /* we can't register a class for user32 */
578 SetLastError( ERROR_INVALID_PARAMETER );
579 return 0;
581 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
583 if (!(classPtr = CLASS_RegisterClass( wc->lpszClassName, instance, !(wc->style & CS_GLOBALCLASS),
584 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
585 return 0;
587 atom = classPtr->atomName;
589 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
590 debugstr_w(wc->lpszClassName), atom, wc->lpfnWndProc, instance, wc->hbrBackground,
591 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
593 classPtr->hIcon = wc->hIcon;
594 classPtr->hIconSm = wc->hIconSm;
595 classPtr->hCursor = wc->hCursor;
596 classPtr->hbrBackground = wc->hbrBackground;
597 classPtr->winproc = WINPROC_AllocProc( NULL, wc->lpfnWndProc );
598 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
599 release_class_ptr( classPtr );
600 return atom;
604 /***********************************************************************
605 * UnregisterClassA (USER32.@)
607 BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
609 if (!IS_INTRESOURCE(className))
611 WCHAR name[MAX_ATOM_LEN + 1];
613 if (!MultiByteToWideChar( CP_ACP, 0, className, -1, name, MAX_ATOM_LEN + 1 ))
614 return FALSE;
615 return UnregisterClassW( name, hInstance );
617 return UnregisterClassW( (LPCWSTR)className, hInstance );
620 /***********************************************************************
621 * UnregisterClassW (USER32.@)
623 BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
625 CLASS *classPtr = NULL;
627 TRACE("%s %p\n",debugstr_w(className), hInstance);
629 SERVER_START_REQ( destroy_class )
631 req->instance = hInstance;
632 if (!(req->atom = get_int_atom_value(className)) && className)
633 wine_server_add_data( req, className, strlenW(className) * sizeof(WCHAR) );
634 if (!wine_server_call_err( req )) classPtr = reply->client_ptr;
636 SERVER_END_REQ;
638 if (classPtr) CLASS_FreeClass( classPtr );
639 return (classPtr != NULL);
643 /***********************************************************************
644 * GetClassWord (USER32.@)
646 WORD WINAPI GetClassWord( HWND hwnd, INT offset )
648 CLASS *class;
649 WORD retvalue = 0;
651 if (offset < 0) return GetClassLongA( hwnd, offset );
653 TRACE("%p %x\n",hwnd, offset);
655 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
657 if (class == CLASS_OTHER_PROCESS)
659 SERVER_START_REQ( set_class_info )
661 req->window = hwnd;
662 req->flags = 0;
663 req->extra_offset = offset;
664 req->extra_size = sizeof(retvalue);
665 if (!wine_server_call_err( req ))
666 memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
668 SERVER_END_REQ;
669 return retvalue;
672 if (offset <= class->cbClsExtra - sizeof(WORD))
673 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
674 else
675 SetLastError( ERROR_INVALID_INDEX );
676 release_class_ptr( class );
677 return retvalue;
681 /***********************************************************************
682 * CLASS_GetClassLong
684 * Implementation of GetClassLong(Ptr)A/W
686 static ULONG_PTR CLASS_GetClassLong( HWND hwnd, INT offset, UINT size,
687 BOOL unicode )
689 CLASS *class;
690 ULONG_PTR retvalue = 0;
692 TRACE("%p %d\n", hwnd, offset);
694 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
696 if (class == CLASS_OTHER_PROCESS)
698 SERVER_START_REQ( set_class_info )
700 req->window = hwnd;
701 req->flags = 0;
702 req->extra_offset = (offset >= 0) ? offset : -1;
703 req->extra_size = (offset >= 0) ? size : 0;
704 if (!wine_server_call_err( req ))
706 switch(offset)
708 case GCLP_HBRBACKGROUND:
709 case GCLP_HCURSOR:
710 case GCLP_HICON:
711 case GCLP_HICONSM:
712 case GCLP_WNDPROC:
713 case GCLP_MENUNAME:
714 FIXME( "offset %d (%s) not supported on other process window %p\n",
715 offset, SPY_GetClassLongOffsetName(offset), hwnd );
716 SetLastError( ERROR_INVALID_HANDLE );
717 break;
718 case GCL_STYLE:
719 retvalue = reply->old_style;
720 break;
721 case GCL_CBWNDEXTRA:
722 retvalue = reply->old_win_extra;
723 break;
724 case GCL_CBCLSEXTRA:
725 retvalue = reply->old_extra;
726 break;
727 case GCLP_HMODULE:
728 retvalue = (ULONG_PTR)reply->old_instance;
729 break;
730 case GCW_ATOM:
731 retvalue = reply->old_atom;
732 break;
733 default:
734 if (offset >= 0)
736 if (size == sizeof(DWORD))
738 DWORD retdword;
739 memcpy( &retdword, &reply->old_extra_value, sizeof(DWORD) );
740 retvalue = retdword;
742 else
743 memcpy( &retvalue, &reply->old_extra_value,
744 sizeof(ULONG_PTR) );
746 else SetLastError( ERROR_INVALID_INDEX );
747 break;
751 SERVER_END_REQ;
752 return retvalue;
755 if (offset >= 0)
757 if (offset <= class->cbClsExtra - size)
759 if (size == sizeof(DWORD))
761 DWORD retdword;
762 memcpy( &retdword, (char *)(class + 1) + offset, sizeof(DWORD) );
763 retvalue = retdword;
765 else
766 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(ULONG_PTR) );
768 else
769 SetLastError( ERROR_INVALID_INDEX );
770 release_class_ptr( class );
771 return retvalue;
774 switch(offset)
776 case GCLP_HBRBACKGROUND:
777 retvalue = (ULONG_PTR)class->hbrBackground;
778 break;
779 case GCLP_HCURSOR:
780 retvalue = (ULONG_PTR)class->hCursor;
781 break;
782 case GCLP_HICON:
783 retvalue = (ULONG_PTR)class->hIcon;
784 break;
785 case GCLP_HICONSM:
786 retvalue = (ULONG_PTR)class->hIconSm;
787 break;
788 case GCL_STYLE:
789 retvalue = class->style;
790 break;
791 case GCL_CBWNDEXTRA:
792 retvalue = class->cbWndExtra;
793 break;
794 case GCL_CBCLSEXTRA:
795 retvalue = class->cbClsExtra;
796 break;
797 case GCLP_HMODULE:
798 retvalue = (ULONG_PTR)class->hInstance;
799 break;
800 case GCLP_WNDPROC:
801 retvalue = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
802 break;
803 case GCLP_MENUNAME:
804 retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
805 if (unicode)
806 retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
807 else
808 retvalue = (ULONG_PTR)CLASS_GetMenuNameA( class );
809 break;
810 case GCW_ATOM:
811 retvalue = class->atomName;
812 break;
813 default:
814 SetLastError( ERROR_INVALID_INDEX );
815 break;
817 release_class_ptr( class );
818 return retvalue;
822 /***********************************************************************
823 * GetClassLongW (USER32.@)
825 DWORD WINAPI GetClassLongW( HWND hwnd, INT offset )
827 return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), TRUE );
832 /***********************************************************************
833 * GetClassLongA (USER32.@)
835 DWORD WINAPI GetClassLongA( HWND hwnd, INT offset )
837 return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), FALSE );
841 /***********************************************************************
842 * SetClassWord (USER32.@)
844 WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
846 CLASS *class;
847 WORD retval = 0;
849 if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
851 TRACE("%p %d %x\n", hwnd, offset, newval);
853 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
855 SERVER_START_REQ( set_class_info )
857 req->window = hwnd;
858 req->flags = SET_CLASS_EXTRA;
859 req->extra_offset = offset;
860 req->extra_size = sizeof(newval);
861 memcpy( &req->extra_value, &newval, sizeof(newval) );
862 if (!wine_server_call_err( req ))
864 void *ptr = (char *)(class + 1) + offset;
865 memcpy( &retval, ptr, sizeof(retval) );
866 memcpy( ptr, &newval, sizeof(newval) );
869 SERVER_END_REQ;
870 release_class_ptr( class );
871 return retval;
875 /***********************************************************************
876 * CLASS_SetClassLong
878 * Implementation of SetClassLong(Ptr)A/W
880 static ULONG_PTR CLASS_SetClassLong( HWND hwnd, INT offset, LONG_PTR newval,
881 UINT size, BOOL unicode )
883 CLASS *class;
884 ULONG_PTR retval = 0;
886 TRACE("%p %d %lx\n", hwnd, offset, newval);
888 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
890 if (offset >= 0)
892 if (set_server_info( hwnd, offset, newval, size ))
894 void *ptr = (char *)(class + 1) + offset;
895 if ( size == sizeof(LONG) )
897 DWORD retdword;
898 LONG newlong = newval;
899 memcpy( &retdword, ptr, sizeof(DWORD) );
900 memcpy( ptr, &newlong, sizeof(LONG) );
901 retval = retdword;
903 else
905 memcpy( &retval, ptr, sizeof(ULONG_PTR) );
906 memcpy( ptr, &newval, sizeof(LONG_PTR) );
910 else switch(offset)
912 case GCLP_MENUNAME:
913 if ( unicode )
914 CLASS_SetMenuNameW( class, (LPCWSTR)newval );
915 else
916 CLASS_SetMenuNameA( class, (LPCSTR)newval );
917 retval = 0; /* Old value is now meaningless anyway */
918 break;
919 case GCLP_WNDPROC:
920 retval = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
921 class->winproc = WINPROC_AllocProc( unicode ? NULL : (WNDPROC)newval,
922 unicode ? (WNDPROC)newval : NULL );
923 break;
924 case GCLP_HBRBACKGROUND:
925 retval = (ULONG_PTR)class->hbrBackground;
926 class->hbrBackground = (HBRUSH)newval;
927 break;
928 case GCLP_HCURSOR:
929 retval = (ULONG_PTR)class->hCursor;
930 class->hCursor = (HCURSOR)newval;
931 break;
932 case GCLP_HICON:
933 retval = (ULONG_PTR)class->hIcon;
934 class->hIcon = (HICON)newval;
935 break;
936 case GCLP_HICONSM:
937 retval = (ULONG_PTR)class->hIconSm;
938 class->hIconSm = (HICON)newval;
939 break;
940 case GCL_STYLE:
941 if (!set_server_info( hwnd, offset, newval, size )) break;
942 retval = class->style;
943 class->style = newval;
944 break;
945 case GCL_CBWNDEXTRA:
946 if (!set_server_info( hwnd, offset, newval, size )) break;
947 retval = class->cbWndExtra;
948 class->cbWndExtra = newval;
949 break;
950 case GCLP_HMODULE:
951 if (!set_server_info( hwnd, offset, newval, size )) break;
952 retval = (ULONG_PTR)class->hInstance;
953 class->hInstance = (HINSTANCE)newval;
954 break;
955 case GCW_ATOM:
956 if (!set_server_info( hwnd, offset, newval, size )) break;
957 retval = class->atomName;
958 class->atomName = newval;
959 GlobalGetAtomNameW( newval, class->name, sizeof(class->name)/sizeof(WCHAR) );
960 break;
961 case GCL_CBCLSEXTRA: /* cannot change this one */
962 SetLastError( ERROR_INVALID_PARAMETER );
963 break;
964 default:
965 SetLastError( ERROR_INVALID_INDEX );
966 break;
968 release_class_ptr( class );
969 return retval;
973 /***********************************************************************
974 * SetClassLongW (USER32.@)
976 DWORD WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
978 TRACE("%p %d %x\n", hwnd, offset, newval);
980 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG), TRUE );
984 /***********************************************************************
985 * SetClassLongA (USER32.@)
987 DWORD WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
989 TRACE("%p %d %x\n", hwnd, offset, newval);
991 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG), FALSE );
995 /***********************************************************************
996 * GetClassNameA (USER32.@)
998 INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
1000 WCHAR tmpbuf[MAX_ATOM_LEN + 1];
1001 DWORD len;
1003 if (count <= 0) return 0;
1004 if (!GetClassNameW( hwnd, tmpbuf, sizeof(tmpbuf)/sizeof(WCHAR) )) return 0;
1005 RtlUnicodeToMultiByteN( buffer, count - 1, &len, tmpbuf, strlenW(tmpbuf) * sizeof(WCHAR) );
1006 buffer[len] = 0;
1007 return len;
1011 /***********************************************************************
1012 * GetClassNameW (USER32.@)
1014 INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
1016 CLASS *class;
1017 INT ret;
1019 TRACE("%p %p %d\n", hwnd, buffer, count);
1021 if (count <= 0) return 0;
1023 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
1025 if (class == CLASS_OTHER_PROCESS)
1027 WCHAR tmpbuf[MAX_ATOM_LEN + 1];
1029 ret = GlobalGetAtomNameW( GetClassLongW( hwnd, GCW_ATOM ), tmpbuf, MAX_ATOM_LEN + 1 );
1030 if (ret)
1032 ret = min(count - 1, ret);
1033 memcpy(buffer, tmpbuf, ret * sizeof(WCHAR));
1034 buffer[ret] = 0;
1037 else
1039 lstrcpynW( buffer, class->name, count );
1040 release_class_ptr( class );
1041 ret = strlenW( buffer );
1043 return ret;
1047 /***********************************************************************
1048 * RealGetWindowClassA (USER32.@)
1050 UINT WINAPI RealGetWindowClassA( HWND hwnd, LPSTR buffer, UINT count )
1052 return GetClassNameA( hwnd, buffer, count );
1056 /***********************************************************************
1057 * RealGetWindowClassW (USER32.@)
1059 UINT WINAPI RealGetWindowClassW( HWND hwnd, LPWSTR buffer, UINT count )
1061 return GetClassNameW( hwnd, buffer, count );
1065 /***********************************************************************
1066 * GetClassInfoA (USER32.@)
1068 BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name, WNDCLASSA *wc )
1070 WNDCLASSEXA wcex;
1071 UINT ret = GetClassInfoExA( hInstance, name, &wcex );
1073 if (ret)
1075 wc->style = wcex.style;
1076 wc->lpfnWndProc = wcex.lpfnWndProc;
1077 wc->cbClsExtra = wcex.cbClsExtra;
1078 wc->cbWndExtra = wcex.cbWndExtra;
1079 wc->hInstance = wcex.hInstance;
1080 wc->hIcon = wcex.hIcon;
1081 wc->hCursor = wcex.hCursor;
1082 wc->hbrBackground = wcex.hbrBackground;
1083 wc->lpszMenuName = wcex.lpszMenuName;
1084 wc->lpszClassName = wcex.lpszClassName;
1086 return ret;
1090 /***********************************************************************
1091 * GetClassInfoW (USER32.@)
1093 BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSW *wc )
1095 WNDCLASSEXW wcex;
1096 UINT ret = GetClassInfoExW( hInstance, name, &wcex );
1098 if (ret)
1100 wc->style = wcex.style;
1101 wc->lpfnWndProc = wcex.lpfnWndProc;
1102 wc->cbClsExtra = wcex.cbClsExtra;
1103 wc->cbWndExtra = wcex.cbWndExtra;
1104 wc->hInstance = wcex.hInstance;
1105 wc->hIcon = wcex.hIcon;
1106 wc->hCursor = wcex.hCursor;
1107 wc->hbrBackground = wcex.hbrBackground;
1108 wc->lpszMenuName = wcex.lpszMenuName;
1109 wc->lpszClassName = wcex.lpszClassName;
1111 return ret;
1115 /***********************************************************************
1116 * GetClassInfoExA (USER32.@)
1118 BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name, WNDCLASSEXA *wc )
1120 ATOM atom;
1121 CLASS *classPtr;
1123 TRACE("%p %s %p\n", hInstance, debugstr_a(name), wc);
1125 if (!hInstance) hInstance = user32_module;
1127 if (!IS_INTRESOURCE(name))
1129 WCHAR nameW[MAX_ATOM_LEN + 1];
1130 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, sizeof(nameW)/sizeof(WCHAR) ))
1131 return FALSE;
1132 classPtr = CLASS_FindClass( nameW, hInstance );
1134 else classPtr = CLASS_FindClass( (LPCWSTR)name, hInstance );
1136 if (!classPtr)
1138 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1139 return FALSE;
1141 wc->style = classPtr->style;
1142 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, FALSE );
1143 wc->cbClsExtra = classPtr->cbClsExtra;
1144 wc->cbWndExtra = classPtr->cbWndExtra;
1145 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1146 wc->hIcon = (HICON)classPtr->hIcon;
1147 wc->hIconSm = (HICON)classPtr->hIconSm;
1148 wc->hCursor = (HCURSOR)classPtr->hCursor;
1149 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1150 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
1151 wc->lpszClassName = name;
1152 atom = classPtr->atomName;
1153 release_class_ptr( classPtr );
1155 /* We must return the atom of the class here instead of just TRUE. */
1156 return atom;
1160 /***********************************************************************
1161 * GetClassInfoExW (USER32.@)
1163 BOOL WINAPI GetClassInfoExW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSEXW *wc )
1165 ATOM atom;
1166 CLASS *classPtr;
1168 TRACE("%p %s %p\n", hInstance, debugstr_w(name), wc);
1170 if (!hInstance) hInstance = user32_module;
1172 if (!(classPtr = CLASS_FindClass( name, hInstance )))
1174 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1175 return FALSE;
1177 wc->style = classPtr->style;
1178 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, TRUE );
1179 wc->cbClsExtra = classPtr->cbClsExtra;
1180 wc->cbWndExtra = classPtr->cbWndExtra;
1181 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1182 wc->hIcon = (HICON)classPtr->hIcon;
1183 wc->hIconSm = (HICON)classPtr->hIconSm;
1184 wc->hCursor = (HCURSOR)classPtr->hCursor;
1185 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1186 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1187 wc->lpszClassName = name;
1188 atom = classPtr->atomName;
1189 release_class_ptr( classPtr );
1191 /* We must return the atom of the class here instead of just TRUE. */
1192 return atom;
1196 #if 0 /* toolhelp is in kernel, so this cannot work */
1198 /***********************************************************************
1199 * ClassFirst (TOOLHELP.69)
1201 BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
1203 TRACE("%p\n",pClassEntry);
1204 pClassEntry->wNext = 1;
1205 return ClassNext16( pClassEntry );
1209 /***********************************************************************
1210 * ClassNext (TOOLHELP.70)
1212 BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
1214 int i;
1215 CLASS *class = firstClass;
1217 TRACE("%p\n",pClassEntry);
1219 if (!pClassEntry->wNext) return FALSE;
1220 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1221 if (!class)
1223 pClassEntry->wNext = 0;
1224 return FALSE;
1226 pClassEntry->hInst = class->hInstance;
1227 pClassEntry->wNext++;
1228 GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
1229 sizeof(pClassEntry->szClassName) );
1230 return TRUE;
1232 #endif
1234 /* 64bit versions */
1236 #ifdef GetClassLongPtrA
1237 #undef GetClassLongPtrA
1238 #endif
1240 #ifdef GetClassLongPtrW
1241 #undef GetClassLongPtrW
1242 #endif
1244 #ifdef SetClassLongPtrA
1245 #undef SetClassLongPtrA
1246 #endif
1248 #ifdef SetClassLongPtrW
1249 #undef SetClassLongPtrW
1250 #endif
1252 /***********************************************************************
1253 * GetClassLongPtrA (USER32.@)
1255 ULONG_PTR WINAPI GetClassLongPtrA( HWND hwnd, INT offset )
1257 return CLASS_GetClassLong( hwnd, offset, sizeof(ULONG_PTR), FALSE );
1260 /***********************************************************************
1261 * GetClassLongPtrW (USER32.@)
1263 ULONG_PTR WINAPI GetClassLongPtrW( HWND hwnd, INT offset )
1265 return CLASS_GetClassLong( hwnd, offset, sizeof(ULONG_PTR), TRUE );
1268 /***********************************************************************
1269 * SetClassLongPtrW (USER32.@)
1271 ULONG_PTR WINAPI SetClassLongPtrW( HWND hwnd, INT offset, LONG_PTR newval )
1273 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG_PTR), TRUE );
1276 /***********************************************************************
1277 * SetClassLongPtrA (USER32.@)
1279 ULONG_PTR WINAPI SetClassLongPtrA( HWND hwnd, INT offset, LONG_PTR newval )
1281 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG_PTR), FALSE );