wrc: Remove non-bison compatibility code.
[wine.git] / dlls / user32 / class.c
bloba66f0dba72d831bfaf402f8ca155a41ce75de2ac
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 struct dce *dce; /* Opaque pointer to class DCE */
56 HINSTANCE hInstance; /* Module that created the task */
57 HICON hIcon; /* Default icon */
58 HICON hIconSm; /* Default small icon */
59 HICON hIconSmIntern; /* Internal small icon, derived from hIcon */
60 HCURSOR hCursor; /* Default cursor */
61 HBRUSH hbrBackground; /* Default background */
62 ATOM atomName; /* Name of the class */
63 WCHAR name[MAX_ATOM_LEN + 1];
64 } CLASS;
66 static struct list class_list = LIST_INIT( class_list );
68 #define CLASS_OTHER_PROCESS ((CLASS *)1)
70 /***********************************************************************
71 * get_class_ptr
73 static CLASS *get_class_ptr( HWND hwnd, BOOL write_access )
75 WND *ptr = WIN_GetPtr( hwnd );
77 if (ptr)
79 if (ptr != WND_OTHER_PROCESS && ptr != WND_DESKTOP) return ptr->class;
80 if (!write_access) return CLASS_OTHER_PROCESS;
82 /* modifying classes in other processes is not allowed */
83 if (ptr == WND_DESKTOP || IsWindow( hwnd ))
85 SetLastError( ERROR_ACCESS_DENIED );
86 return NULL;
89 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
90 return NULL;
94 /***********************************************************************
95 * release_class_ptr
97 static inline void release_class_ptr( CLASS *ptr )
99 USER_Unlock();
103 /***********************************************************************
104 * get_int_atom_value
106 ATOM get_int_atom_value( LPCWSTR name )
108 UINT ret = 0;
110 if (IS_INTRESOURCE(name)) return LOWORD(name);
111 if (*name++ != '#') return 0;
112 while (*name)
114 if (*name < '0' || *name > '9') return 0;
115 ret = ret * 10 + *name++ - '0';
116 if (ret > 0xffff) return 0;
118 return ret;
122 /***********************************************************************
123 * set_server_info
125 * Set class info with the wine server.
127 static BOOL set_server_info( HWND hwnd, INT offset, LONG_PTR newval, UINT size )
129 BOOL ret;
131 SERVER_START_REQ( set_class_info )
133 req->window = wine_server_user_handle( hwnd );
134 req->extra_offset = -1;
135 switch(offset)
137 case GCW_ATOM:
138 req->flags = SET_CLASS_ATOM;
139 req->atom = LOWORD(newval);
140 break;
141 case GCL_STYLE:
142 req->flags = SET_CLASS_STYLE;
143 req->style = newval;
144 break;
145 case GCL_CBWNDEXTRA:
146 req->flags = SET_CLASS_WINEXTRA;
147 req->win_extra = newval;
148 break;
149 case GCLP_HMODULE:
150 req->flags = SET_CLASS_INSTANCE;
151 req->instance = wine_server_client_ptr( (void *)newval );
152 break;
153 default:
154 assert( offset >= 0 );
155 req->flags = SET_CLASS_EXTRA;
156 req->extra_offset = offset;
157 req->extra_size = size;
158 if ( size == sizeof(LONG) )
160 LONG newlong = newval;
161 memcpy( &req->extra_value, &newlong, sizeof(LONG) );
163 else
164 memcpy( &req->extra_value, &newval, sizeof(LONG_PTR) );
165 break;
167 ret = !wine_server_call_err( req );
169 SERVER_END_REQ;
170 return ret;
174 /***********************************************************************
175 * CLASS_GetMenuNameA
177 * Get the menu name as a ASCII string.
179 static inline LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
181 if (IS_INTRESOURCE(classPtr->menuName)) return (LPSTR)classPtr->menuName;
182 return (LPSTR)(classPtr->menuName + strlenW(classPtr->menuName) + 1);
186 /***********************************************************************
187 * CLASS_GetMenuNameW
189 * Get the menu name as a Unicode string.
191 static inline LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
193 return classPtr->menuName;
197 /***********************************************************************
198 * CLASS_SetMenuNameA
200 * Set the menu name in a class structure by copying the string.
202 static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
204 if (!IS_INTRESOURCE(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
205 if (!IS_INTRESOURCE(name))
207 DWORD lenA = strlen(name) + 1;
208 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, name, lenA, NULL, 0 );
209 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
210 MultiByteToWideChar( CP_ACP, 0, name, lenA, classPtr->menuName, lenW );
211 memcpy( classPtr->menuName + lenW, name, lenA );
213 else classPtr->menuName = (LPWSTR)name;
217 /***********************************************************************
218 * CLASS_SetMenuNameW
220 * Set the menu name in a class structure by copying the string.
222 static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
224 if (!IS_INTRESOURCE(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
225 if (!IS_INTRESOURCE(name))
227 DWORD lenW = strlenW(name) + 1;
228 DWORD lenA = WideCharToMultiByte( CP_ACP, 0, name, lenW, NULL, 0, NULL, NULL );
229 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
230 memcpy( classPtr->menuName, name, lenW*sizeof(WCHAR) );
231 WideCharToMultiByte( CP_ACP, 0, name, lenW,
232 (char *)(classPtr->menuName + lenW), lenA, NULL, NULL );
234 else classPtr->menuName = (LPWSTR)name;
238 /***********************************************************************
239 * CLASS_FreeClass
241 * Free a class structure.
243 static void CLASS_FreeClass( CLASS *classPtr )
245 TRACE("%p\n", classPtr);
247 USER_Lock();
249 if (classPtr->dce) free_dce( classPtr->dce, 0 );
250 list_remove( &classPtr->entry );
251 if (classPtr->hbrBackground > (HBRUSH)(COLOR_GRADIENTINACTIVECAPTION + 1))
252 DeleteObject( classPtr->hbrBackground );
253 HeapFree( GetProcessHeap(), 0, classPtr->menuName );
254 HeapFree( GetProcessHeap(), 0, classPtr );
255 USER_Unlock();
259 /***********************************************************************
260 * CLASS_FindClass
262 * Return a pointer to the class.
263 * hinstance has been normalized by the caller.
265 static CLASS *CLASS_FindClass( LPCWSTR name, HINSTANCE hinstance )
267 struct list *ptr;
268 ATOM atom = get_int_atom_value( name );
270 USER_Lock();
272 LIST_FOR_EACH( ptr, &class_list )
274 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
275 if (atom)
277 if (class->atomName != atom) continue;
279 else
281 if (!name || strcmpiW( class->name, name )) continue;
283 if (!hinstance || !class->local || class->hInstance == hinstance)
285 TRACE("%s %p -> %p\n", debugstr_w(name), hinstance, class);
286 return class;
289 USER_Unlock();
290 TRACE("%s %p -> not found\n", debugstr_w(name), hinstance);
291 return NULL;
295 /***********************************************************************
296 * CLASS_RegisterClass
298 * The real RegisterClass() functionality.
300 static CLASS *CLASS_RegisterClass( LPCWSTR name, HINSTANCE hInstance, BOOL local,
301 DWORD style, INT classExtra, INT winExtra )
303 CLASS *classPtr;
304 BOOL ret;
306 TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
307 debugstr_w(name), hInstance, style, classExtra, winExtra );
309 /* Fix the extra bytes value */
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) return NULL;
319 classPtr->atomName = get_int_atom_value( name );
320 if (!classPtr->atomName && name) strcpyW( classPtr->name, name );
321 else GlobalGetAtomNameW( classPtr->atomName, classPtr->name, sizeof(classPtr->name)/sizeof(WCHAR) );
323 SERVER_START_REQ( create_class )
325 req->local = local;
326 req->style = style;
327 req->instance = wine_server_client_ptr( hInstance );
328 req->extra = classExtra;
329 req->win_extra = winExtra;
330 req->client_ptr = wine_server_client_ptr( classPtr );
331 req->atom = classPtr->atomName;
332 if (!req->atom && name) wine_server_add_data( req, name, strlenW(name) * sizeof(WCHAR) );
333 ret = !wine_server_call_err( req );
334 classPtr->atomName = reply->atom;
336 SERVER_END_REQ;
337 if (!ret)
339 HeapFree( GetProcessHeap(), 0, classPtr );
340 return NULL;
343 classPtr->style = style;
344 classPtr->local = local;
345 classPtr->cbWndExtra = winExtra;
346 classPtr->cbClsExtra = classExtra;
347 classPtr->hInstance = hInstance;
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 void register_builtin( const struct builtin_class_descr *descr )
366 CLASS *classPtr;
368 if (!(classPtr = CLASS_RegisterClass( descr->name, user32_module, FALSE,
369 descr->style, 0, descr->extra ))) return;
371 classPtr->hCursor = LoadCursorA( 0, (LPSTR)descr->cursor );
372 classPtr->hbrBackground = descr->brush;
373 classPtr->winproc = BUILTIN_WINPROC( descr->proc );
374 release_class_ptr( classPtr );
378 /***********************************************************************
379 * CLASS_RegisterBuiltinClasses
381 void CLASS_RegisterBuiltinClasses(void)
383 register_builtin( &DESKTOP_builtin_class );
384 register_builtin( &BUTTON_builtin_class );
385 register_builtin( &COMBO_builtin_class );
386 register_builtin( &COMBOLBOX_builtin_class );
387 register_builtin( &DIALOG_builtin_class );
388 register_builtin( &EDIT_builtin_class );
389 register_builtin( &ICONTITLE_builtin_class );
390 register_builtin( &LISTBOX_builtin_class );
391 register_builtin( &MDICLIENT_builtin_class );
392 register_builtin( &MENU_builtin_class );
393 register_builtin( &MESSAGE_builtin_class );
394 register_builtin( &SCROLL_builtin_class );
395 register_builtin( &STATIC_builtin_class );
399 /***********************************************************************
400 * get_class_winproc
402 WNDPROC get_class_winproc( CLASS *class )
404 return class->winproc;
408 /***********************************************************************
409 * get_class_dce
411 struct dce *get_class_dce( CLASS *class )
413 return class->dce;
417 /***********************************************************************
418 * set_class_dce
420 struct dce *set_class_dce( CLASS *class, struct dce *dce )
422 if (class->dce) return class->dce; /* already set, don't change it */
423 class->dce = dce;
424 return dce;
428 /***********************************************************************
429 * RegisterClassA (USER32.@)
431 * Register a window class.
433 * RETURNS
434 * >0: Unique identifier
435 * 0: Failure
437 ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
439 WNDCLASSEXA wcex;
441 wcex.cbSize = sizeof(wcex);
442 wcex.style = wc->style;
443 wcex.lpfnWndProc = wc->lpfnWndProc;
444 wcex.cbClsExtra = wc->cbClsExtra;
445 wcex.cbWndExtra = wc->cbWndExtra;
446 wcex.hInstance = wc->hInstance;
447 wcex.hIcon = wc->hIcon;
448 wcex.hCursor = wc->hCursor;
449 wcex.hbrBackground = wc->hbrBackground;
450 wcex.lpszMenuName = wc->lpszMenuName;
451 wcex.lpszClassName = wc->lpszClassName;
452 wcex.hIconSm = 0;
453 return RegisterClassExA( &wcex );
457 /***********************************************************************
458 * RegisterClassW (USER32.@)
460 * See RegisterClassA.
462 ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
464 WNDCLASSEXW wcex;
466 wcex.cbSize = sizeof(wcex);
467 wcex.style = wc->style;
468 wcex.lpfnWndProc = wc->lpfnWndProc;
469 wcex.cbClsExtra = wc->cbClsExtra;
470 wcex.cbWndExtra = wc->cbWndExtra;
471 wcex.hInstance = wc->hInstance;
472 wcex.hIcon = wc->hIcon;
473 wcex.hCursor = wc->hCursor;
474 wcex.hbrBackground = wc->hbrBackground;
475 wcex.lpszMenuName = wc->lpszMenuName;
476 wcex.lpszClassName = wc->lpszClassName;
477 wcex.hIconSm = 0;
478 return RegisterClassExW( &wcex );
482 /***********************************************************************
483 * RegisterClassExA (USER32.@)
485 ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
487 ATOM atom;
488 CLASS *classPtr;
489 HINSTANCE instance;
491 if (wc->cbSize != sizeof(*wc) || wc->cbClsExtra < 0 || wc->cbWndExtra < 0 ||
492 wc->hInstance == user32_module) /* we can't register a class for user32 */
494 SetLastError( ERROR_INVALID_PARAMETER );
495 return 0;
497 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
499 if (!IS_INTRESOURCE(wc->lpszClassName))
501 WCHAR name[MAX_ATOM_LEN + 1];
503 if (!MultiByteToWideChar( CP_ACP, 0, wc->lpszClassName, -1, name, MAX_ATOM_LEN + 1 )) return 0;
504 classPtr = CLASS_RegisterClass( name, instance, !(wc->style & CS_GLOBALCLASS),
505 wc->style, wc->cbClsExtra, wc->cbWndExtra );
507 else
509 classPtr = CLASS_RegisterClass( (LPCWSTR)wc->lpszClassName, instance,
510 !(wc->style & CS_GLOBALCLASS), wc->style,
511 wc->cbClsExtra, wc->cbWndExtra );
513 if (!classPtr) return 0;
514 atom = classPtr->atomName;
516 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
517 debugstr_a(wc->lpszClassName), atom, wc->lpfnWndProc, instance, wc->hbrBackground,
518 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
520 classPtr->hIcon = wc->hIcon;
521 classPtr->hIconSm = wc->hIconSm;
522 classPtr->hIconSmIntern = wc->hIcon && !wc->hIconSm ?
523 CopyImage( wc->hIcon, IMAGE_ICON,
524 GetSystemMetrics( SM_CXSMICON ),
525 GetSystemMetrics( SM_CYSMICON ), 0 ) : NULL;
526 classPtr->hCursor = wc->hCursor;
527 classPtr->hbrBackground = wc->hbrBackground;
528 classPtr->winproc = WINPROC_AllocProc( wc->lpfnWndProc, FALSE );
529 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
530 release_class_ptr( classPtr );
531 return atom;
535 /***********************************************************************
536 * RegisterClassExW (USER32.@)
538 ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
540 ATOM atom;
541 CLASS *classPtr;
542 HINSTANCE instance;
544 if (wc->cbSize != sizeof(*wc) || wc->cbClsExtra < 0 || wc->cbWndExtra < 0 ||
545 wc->hInstance == user32_module) /* we can't register a class for user32 */
547 SetLastError( ERROR_INVALID_PARAMETER );
548 return 0;
550 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
552 if (!(classPtr = CLASS_RegisterClass( wc->lpszClassName, instance, !(wc->style & CS_GLOBALCLASS),
553 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
554 return 0;
556 atom = classPtr->atomName;
558 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
559 debugstr_w(wc->lpszClassName), atom, wc->lpfnWndProc, instance, wc->hbrBackground,
560 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
562 classPtr->hIcon = wc->hIcon;
563 classPtr->hIconSm = wc->hIconSm;
564 classPtr->hIconSmIntern = wc->hIcon && !wc->hIconSm ?
565 CopyImage( wc->hIcon, IMAGE_ICON,
566 GetSystemMetrics( SM_CXSMICON ),
567 GetSystemMetrics( SM_CYSMICON ), 0 ) : NULL;
568 classPtr->hCursor = wc->hCursor;
569 classPtr->hbrBackground = wc->hbrBackground;
570 classPtr->winproc = WINPROC_AllocProc( wc->lpfnWndProc, TRUE );
571 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
572 release_class_ptr( classPtr );
573 return atom;
577 /***********************************************************************
578 * UnregisterClassA (USER32.@)
580 BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
582 if (!IS_INTRESOURCE(className))
584 WCHAR name[MAX_ATOM_LEN + 1];
586 if (!MultiByteToWideChar( CP_ACP, 0, className, -1, name, MAX_ATOM_LEN + 1 ))
587 return FALSE;
588 return UnregisterClassW( name, hInstance );
590 return UnregisterClassW( (LPCWSTR)className, hInstance );
593 /***********************************************************************
594 * UnregisterClassW (USER32.@)
596 BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
598 CLASS *classPtr = NULL;
600 SERVER_START_REQ( destroy_class )
602 req->instance = wine_server_client_ptr( hInstance );
603 if (!(req->atom = get_int_atom_value(className)) && className)
604 wine_server_add_data( req, className, strlenW(className) * sizeof(WCHAR) );
605 if (!wine_server_call_err( req )) classPtr = wine_server_get_ptr( reply->client_ptr );
607 SERVER_END_REQ;
609 if (classPtr) CLASS_FreeClass( classPtr );
610 return (classPtr != NULL);
614 /***********************************************************************
615 * GetClassWord (USER32.@)
617 WORD WINAPI GetClassWord( HWND hwnd, INT offset )
619 CLASS *class;
620 WORD retvalue = 0;
622 if (offset < 0) return GetClassLongA( hwnd, offset );
624 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
626 if (class == CLASS_OTHER_PROCESS)
628 SERVER_START_REQ( set_class_info )
630 req->window = wine_server_user_handle( hwnd );
631 req->flags = 0;
632 req->extra_offset = offset;
633 req->extra_size = sizeof(retvalue);
634 if (!wine_server_call_err( req ))
635 memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
637 SERVER_END_REQ;
638 return retvalue;
641 if (offset <= class->cbClsExtra - sizeof(WORD))
642 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
643 else
644 SetLastError( ERROR_INVALID_INDEX );
645 release_class_ptr( class );
646 return retvalue;
650 /***********************************************************************
651 * CLASS_GetClassLong
653 * Implementation of GetClassLong(Ptr)A/W
655 static ULONG_PTR CLASS_GetClassLong( HWND hwnd, INT offset, UINT size,
656 BOOL unicode )
658 CLASS *class;
659 ULONG_PTR retvalue = 0;
661 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
663 if (class == CLASS_OTHER_PROCESS)
665 SERVER_START_REQ( set_class_info )
667 req->window = wine_server_user_handle( hwnd );
668 req->flags = 0;
669 req->extra_offset = (offset >= 0) ? offset : -1;
670 req->extra_size = (offset >= 0) ? size : 0;
671 if (!wine_server_call_err( req ))
673 switch(offset)
675 case GCLP_HBRBACKGROUND:
676 case GCLP_HCURSOR:
677 case GCLP_HICON:
678 case GCLP_HICONSM:
679 case GCLP_WNDPROC:
680 case GCLP_MENUNAME:
681 FIXME( "offset %d (%s) not supported on other process window %p\n",
682 offset, SPY_GetClassLongOffsetName(offset), hwnd );
683 SetLastError( ERROR_INVALID_HANDLE );
684 break;
685 case GCL_STYLE:
686 retvalue = reply->old_style;
687 break;
688 case GCL_CBWNDEXTRA:
689 retvalue = reply->old_win_extra;
690 break;
691 case GCL_CBCLSEXTRA:
692 retvalue = reply->old_extra;
693 break;
694 case GCLP_HMODULE:
695 retvalue = (ULONG_PTR)wine_server_get_ptr( reply->old_instance );
696 break;
697 case GCW_ATOM:
698 retvalue = reply->old_atom;
699 break;
700 default:
701 if (offset >= 0)
703 if (size == sizeof(DWORD))
705 DWORD retdword;
706 memcpy( &retdword, &reply->old_extra_value, sizeof(DWORD) );
707 retvalue = retdword;
709 else
710 memcpy( &retvalue, &reply->old_extra_value,
711 sizeof(ULONG_PTR) );
713 else SetLastError( ERROR_INVALID_INDEX );
714 break;
718 SERVER_END_REQ;
719 return retvalue;
722 if (offset >= 0)
724 if (offset <= class->cbClsExtra - size)
726 if (size == sizeof(DWORD))
728 DWORD retdword;
729 memcpy( &retdword, (char *)(class + 1) + offset, sizeof(DWORD) );
730 retvalue = retdword;
732 else
733 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(ULONG_PTR) );
735 else
736 SetLastError( ERROR_INVALID_INDEX );
737 release_class_ptr( class );
738 return retvalue;
741 switch(offset)
743 case GCLP_HBRBACKGROUND:
744 retvalue = (ULONG_PTR)class->hbrBackground;
745 break;
746 case GCLP_HCURSOR:
747 retvalue = (ULONG_PTR)class->hCursor;
748 break;
749 case GCLP_HICON:
750 retvalue = (ULONG_PTR)class->hIcon;
751 break;
752 case GCLP_HICONSM:
753 retvalue = (ULONG_PTR)(class->hIconSm ? class->hIconSm : class->hIconSmIntern);
754 break;
755 case GCL_STYLE:
756 retvalue = class->style;
757 break;
758 case GCL_CBWNDEXTRA:
759 retvalue = class->cbWndExtra;
760 break;
761 case GCL_CBCLSEXTRA:
762 retvalue = class->cbClsExtra;
763 break;
764 case GCLP_HMODULE:
765 retvalue = (ULONG_PTR)class->hInstance;
766 break;
767 case GCLP_WNDPROC:
768 retvalue = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
769 break;
770 case GCLP_MENUNAME:
771 retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
772 if (unicode)
773 retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
774 else
775 retvalue = (ULONG_PTR)CLASS_GetMenuNameA( class );
776 break;
777 case GCW_ATOM:
778 retvalue = class->atomName;
779 break;
780 default:
781 SetLastError( ERROR_INVALID_INDEX );
782 break;
784 release_class_ptr( class );
785 return retvalue;
789 /***********************************************************************
790 * GetClassLongW (USER32.@)
792 DWORD WINAPI GetClassLongW( HWND hwnd, INT offset )
794 return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), TRUE );
799 /***********************************************************************
800 * GetClassLongA (USER32.@)
802 DWORD WINAPI GetClassLongA( HWND hwnd, INT offset )
804 return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), FALSE );
808 /***********************************************************************
809 * SetClassWord (USER32.@)
811 WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
813 CLASS *class;
814 WORD retval = 0;
816 if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
818 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
820 SERVER_START_REQ( set_class_info )
822 req->window = wine_server_user_handle( hwnd );
823 req->flags = SET_CLASS_EXTRA;
824 req->extra_offset = offset;
825 req->extra_size = sizeof(newval);
826 memcpy( &req->extra_value, &newval, sizeof(newval) );
827 if (!wine_server_call_err( req ))
829 void *ptr = (char *)(class + 1) + offset;
830 memcpy( &retval, ptr, sizeof(retval) );
831 memcpy( ptr, &newval, sizeof(newval) );
834 SERVER_END_REQ;
835 release_class_ptr( class );
836 return retval;
840 /***********************************************************************
841 * CLASS_SetClassLong
843 * Implementation of SetClassLong(Ptr)A/W
845 static ULONG_PTR CLASS_SetClassLong( HWND hwnd, INT offset, LONG_PTR newval,
846 UINT size, BOOL unicode )
848 CLASS *class;
849 ULONG_PTR retval = 0;
851 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
853 if (offset >= 0)
855 if (set_server_info( hwnd, offset, newval, size ))
857 void *ptr = (char *)(class + 1) + offset;
858 if ( size == sizeof(LONG) )
860 DWORD retdword;
861 LONG newlong = newval;
862 memcpy( &retdword, ptr, sizeof(DWORD) );
863 memcpy( ptr, &newlong, sizeof(LONG) );
864 retval = retdword;
866 else
868 memcpy( &retval, ptr, sizeof(ULONG_PTR) );
869 memcpy( ptr, &newval, sizeof(LONG_PTR) );
873 else switch(offset)
875 case GCLP_MENUNAME:
876 if ( unicode )
877 CLASS_SetMenuNameW( class, (LPCWSTR)newval );
878 else
879 CLASS_SetMenuNameA( class, (LPCSTR)newval );
880 retval = 0; /* Old value is now meaningless anyway */
881 break;
882 case GCLP_WNDPROC:
883 retval = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
884 class->winproc = WINPROC_AllocProc( (WNDPROC)newval, unicode );
885 break;
886 case GCLP_HBRBACKGROUND:
887 retval = (ULONG_PTR)class->hbrBackground;
888 class->hbrBackground = (HBRUSH)newval;
889 break;
890 case GCLP_HCURSOR:
891 retval = (ULONG_PTR)class->hCursor;
892 class->hCursor = (HCURSOR)newval;
893 break;
894 case GCLP_HICON:
895 retval = (ULONG_PTR)class->hIcon;
896 if (retval && class->hIconSmIntern)
898 DestroyIcon(class->hIconSmIntern);
899 class->hIconSmIntern = NULL;
901 if (newval && !class->hIconSm)
902 class->hIconSmIntern = CopyImage( (HICON)newval, IMAGE_ICON,
903 GetSystemMetrics( SM_CXSMICON ), GetSystemMetrics( SM_CYSMICON ), 0 );
904 class->hIcon = (HICON)newval;
905 break;
906 case GCLP_HICONSM:
907 retval = (ULONG_PTR)class->hIconSm;
908 if (retval && !newval)
909 class->hIconSmIntern = class->hIcon ? CopyImage( class->hIcon, IMAGE_ICON,
910 GetSystemMetrics( SM_CXSMICON ),
911 GetSystemMetrics( SM_CYSMICON ), 0 ) : NULL;
912 else if (!retval && newval && class->hIconSmIntern)
914 DestroyIcon(class->hIconSmIntern);
915 class->hIconSmIntern = NULL;
917 class->hIconSm = (HICON)newval;
918 break;
919 case GCL_STYLE:
920 if (!set_server_info( hwnd, offset, newval, size )) break;
921 retval = class->style;
922 class->style = newval;
923 break;
924 case GCL_CBWNDEXTRA:
925 if (!set_server_info( hwnd, offset, newval, size )) break;
926 retval = class->cbWndExtra;
927 class->cbWndExtra = newval;
928 break;
929 case GCLP_HMODULE:
930 if (!set_server_info( hwnd, offset, newval, size )) break;
931 retval = (ULONG_PTR)class->hInstance;
932 class->hInstance = (HINSTANCE)newval;
933 break;
934 case GCW_ATOM:
935 if (!set_server_info( hwnd, offset, newval, size )) break;
936 retval = class->atomName;
937 class->atomName = newval;
938 GlobalGetAtomNameW( newval, class->name, sizeof(class->name)/sizeof(WCHAR) );
939 break;
940 case GCL_CBCLSEXTRA: /* cannot change this one */
941 SetLastError( ERROR_INVALID_PARAMETER );
942 break;
943 default:
944 SetLastError( ERROR_INVALID_INDEX );
945 break;
947 release_class_ptr( class );
948 return retval;
952 /***********************************************************************
953 * SetClassLongW (USER32.@)
955 DWORD WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
957 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG), TRUE );
961 /***********************************************************************
962 * SetClassLongA (USER32.@)
964 DWORD WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
966 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG), FALSE );
970 /***********************************************************************
971 * GetClassNameA (USER32.@)
973 INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
975 WCHAR tmpbuf[MAX_ATOM_LEN + 1];
976 DWORD len;
978 if (count <= 0) return 0;
979 if (!GetClassNameW( hwnd, tmpbuf, sizeof(tmpbuf)/sizeof(WCHAR) )) return 0;
980 RtlUnicodeToMultiByteN( buffer, count - 1, &len, tmpbuf, strlenW(tmpbuf) * sizeof(WCHAR) );
981 buffer[len] = 0;
982 return len;
986 /***********************************************************************
987 * GetClassNameW (USER32.@)
989 INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
991 CLASS *class;
992 INT ret;
994 TRACE("%p %p %d\n", hwnd, buffer, count);
996 if (count <= 0) return 0;
998 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
1000 if (class == CLASS_OTHER_PROCESS)
1002 WCHAR tmpbuf[MAX_ATOM_LEN + 1];
1004 ret = GlobalGetAtomNameW( GetClassLongW( hwnd, GCW_ATOM ), tmpbuf, MAX_ATOM_LEN + 1 );
1005 if (ret)
1007 ret = min(count - 1, ret);
1008 memcpy(buffer, tmpbuf, ret * sizeof(WCHAR));
1009 buffer[ret] = 0;
1012 else
1014 lstrcpynW( buffer, class->name, count );
1015 release_class_ptr( class );
1016 ret = strlenW( buffer );
1018 return ret;
1022 /***********************************************************************
1023 * RealGetWindowClassA (USER32.@)
1025 UINT WINAPI RealGetWindowClassA( HWND hwnd, LPSTR buffer, UINT count )
1027 return GetClassNameA( hwnd, buffer, count );
1031 /***********************************************************************
1032 * RealGetWindowClassW (USER32.@)
1034 UINT WINAPI RealGetWindowClassW( HWND hwnd, LPWSTR buffer, UINT count )
1036 return GetClassNameW( hwnd, buffer, count );
1040 /***********************************************************************
1041 * GetClassInfoA (USER32.@)
1043 BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name, WNDCLASSA *wc )
1045 WNDCLASSEXA wcex;
1046 UINT ret = GetClassInfoExA( hInstance, name, &wcex );
1048 if (ret)
1050 wc->style = wcex.style;
1051 wc->lpfnWndProc = wcex.lpfnWndProc;
1052 wc->cbClsExtra = wcex.cbClsExtra;
1053 wc->cbWndExtra = wcex.cbWndExtra;
1054 wc->hInstance = wcex.hInstance;
1055 wc->hIcon = wcex.hIcon;
1056 wc->hCursor = wcex.hCursor;
1057 wc->hbrBackground = wcex.hbrBackground;
1058 wc->lpszMenuName = wcex.lpszMenuName;
1059 wc->lpszClassName = wcex.lpszClassName;
1061 return ret;
1065 /***********************************************************************
1066 * GetClassInfoW (USER32.@)
1068 BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSW *wc )
1070 WNDCLASSEXW wcex;
1071 UINT ret = GetClassInfoExW( 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 * GetClassInfoExA (USER32.@)
1093 BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name, WNDCLASSEXA *wc )
1095 ATOM atom;
1096 CLASS *classPtr;
1098 TRACE("%p %s %p\n", hInstance, debugstr_a(name), wc);
1100 if (!wc)
1102 SetLastError( ERROR_NOACCESS );
1103 return FALSE;
1106 if (!hInstance) hInstance = user32_module;
1108 if (!IS_INTRESOURCE(name))
1110 WCHAR nameW[MAX_ATOM_LEN + 1];
1111 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, sizeof(nameW)/sizeof(WCHAR) ))
1112 return FALSE;
1113 classPtr = CLASS_FindClass( nameW, hInstance );
1115 else classPtr = CLASS_FindClass( (LPCWSTR)name, hInstance );
1117 if (!classPtr)
1119 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1120 return FALSE;
1122 wc->style = classPtr->style;
1123 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, FALSE );
1124 wc->cbClsExtra = classPtr->cbClsExtra;
1125 wc->cbWndExtra = classPtr->cbWndExtra;
1126 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1127 wc->hIcon = classPtr->hIcon;
1128 wc->hIconSm = classPtr->hIconSm ? classPtr->hIconSm : classPtr->hIconSmIntern;
1129 wc->hCursor = classPtr->hCursor;
1130 wc->hbrBackground = classPtr->hbrBackground;
1131 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
1132 wc->lpszClassName = name;
1133 atom = classPtr->atomName;
1134 release_class_ptr( classPtr );
1136 /* We must return the atom of the class here instead of just TRUE. */
1137 return atom;
1141 /***********************************************************************
1142 * GetClassInfoExW (USER32.@)
1144 BOOL WINAPI GetClassInfoExW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSEXW *wc )
1146 ATOM atom;
1147 CLASS *classPtr;
1149 TRACE("%p %s %p\n", hInstance, debugstr_w(name), wc);
1151 if (!wc)
1153 SetLastError( ERROR_NOACCESS );
1154 return FALSE;
1157 if (!hInstance) hInstance = user32_module;
1159 if (!(classPtr = CLASS_FindClass( name, hInstance )))
1161 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1162 return FALSE;
1164 wc->style = classPtr->style;
1165 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, TRUE );
1166 wc->cbClsExtra = classPtr->cbClsExtra;
1167 wc->cbWndExtra = classPtr->cbWndExtra;
1168 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1169 wc->hIcon = classPtr->hIcon;
1170 wc->hIconSm = classPtr->hIconSm ? classPtr->hIconSm : classPtr->hIconSmIntern;
1171 wc->hCursor = classPtr->hCursor;
1172 wc->hbrBackground = classPtr->hbrBackground;
1173 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1174 wc->lpszClassName = name;
1175 atom = classPtr->atomName;
1176 release_class_ptr( classPtr );
1178 /* We must return the atom of the class here instead of just TRUE. */
1179 return atom;
1183 #if 0 /* toolhelp is in kernel, so this cannot work */
1185 /***********************************************************************
1186 * ClassFirst (TOOLHELP.69)
1188 BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
1190 TRACE("%p\n",pClassEntry);
1191 pClassEntry->wNext = 1;
1192 return ClassNext16( pClassEntry );
1196 /***********************************************************************
1197 * ClassNext (TOOLHELP.70)
1199 BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
1201 int i;
1202 CLASS *class = firstClass;
1204 TRACE("%p\n",pClassEntry);
1206 if (!pClassEntry->wNext) return FALSE;
1207 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1208 if (!class)
1210 pClassEntry->wNext = 0;
1211 return FALSE;
1213 pClassEntry->hInst = class->hInstance;
1214 pClassEntry->wNext++;
1215 GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
1216 sizeof(pClassEntry->szClassName) );
1217 return TRUE;
1219 #endif
1221 /* 64bit versions */
1223 #ifdef GetClassLongPtrA
1224 #undef GetClassLongPtrA
1225 #endif
1227 #ifdef GetClassLongPtrW
1228 #undef GetClassLongPtrW
1229 #endif
1231 #ifdef SetClassLongPtrA
1232 #undef SetClassLongPtrA
1233 #endif
1235 #ifdef SetClassLongPtrW
1236 #undef SetClassLongPtrW
1237 #endif
1239 /***********************************************************************
1240 * GetClassLongPtrA (USER32.@)
1242 ULONG_PTR WINAPI GetClassLongPtrA( HWND hwnd, INT offset )
1244 return CLASS_GetClassLong( hwnd, offset, sizeof(ULONG_PTR), FALSE );
1247 /***********************************************************************
1248 * GetClassLongPtrW (USER32.@)
1250 ULONG_PTR WINAPI GetClassLongPtrW( HWND hwnd, INT offset )
1252 return CLASS_GetClassLong( hwnd, offset, sizeof(ULONG_PTR), TRUE );
1255 /***********************************************************************
1256 * SetClassLongPtrW (USER32.@)
1258 ULONG_PTR WINAPI SetClassLongPtrW( HWND hwnd, INT offset, LONG_PTR newval )
1260 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG_PTR), TRUE );
1263 /***********************************************************************
1264 * SetClassLongPtrA (USER32.@)
1266 ULONG_PTR WINAPI SetClassLongPtrA( HWND hwnd, INT offset, LONG_PTR newval )
1268 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG_PTR), FALSE );