Treat already preprocessed code just like normal #include'ed code.
[wine.git] / windows / class.c
blob608f2ed292e431609748bd4b9a64fc8ab99655b8
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 "dce.h"
40 #include "winproc.h"
41 #include "wine/server.h"
42 #include "wine/list.h"
43 #include "wine/debug.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(class);
47 typedef struct tagCLASS
49 struct list entry; /* Entry in class list */
50 UINT style; /* Class style */
51 BOOL local; /* Local class? */
52 WNDPROC winprocA; /* Window procedure (ASCII) */
53 WNDPROC winprocW; /* Window procedure (Unicode) */
54 INT cbClsExtra; /* Class extra bytes */
55 INT cbWndExtra; /* Window extra bytes */
56 LPWSTR menuName; /* Default menu name (Unicode followed by ASCII) */
57 SEGPTR segMenuName; /* Default menu name as SEGPTR */
58 struct tagDCE *dce; /* Class DCE (if CS_CLASSDC) */
59 HINSTANCE hInstance; /* Module that created the task */
60 HICON hIcon; /* Default icon */
61 HICON hIconSm; /* Default small icon */
62 HCURSOR hCursor; /* Default cursor */
63 HBRUSH hbrBackground; /* Default background */
64 ATOM atomName; /* Name of the class */
65 } CLASS;
67 static struct list class_list = LIST_INIT( class_list );
68 static CLASS *desktop_class;
70 #define CLASS_OTHER_PROCESS ((CLASS *)1)
72 /***********************************************************************
73 * get_class_ptr
75 static CLASS *get_class_ptr( HWND hwnd, BOOL write_access )
77 WND *ptr = WIN_GetPtr( hwnd );
79 if (ptr)
81 if (ptr != WND_OTHER_PROCESS) return ptr->class;
82 if (write_access && IsWindow( hwnd )) /* check other processes */
84 /* modifying classes in other processes is not allowed */
85 SetLastError( ERROR_ACCESS_DENIED );
86 return NULL;
88 return CLASS_OTHER_PROCESS;
90 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
91 return NULL;
95 /***********************************************************************
96 * release_class_ptr
98 inline static void release_class_ptr( CLASS *ptr )
100 USER_Unlock();
104 /***********************************************************************
105 * set_server_info
107 * Set class info with the wine server.
109 static BOOL set_server_info( HWND hwnd, INT offset, LONG newval )
111 BOOL ret;
113 SERVER_START_REQ( set_class_info )
115 req->window = hwnd;
116 req->extra_offset = -1;
117 switch(offset)
119 case GCW_ATOM:
120 req->flags = SET_CLASS_ATOM;
121 req->atom = newval;
122 case GCL_STYLE:
123 req->flags = SET_CLASS_STYLE;
124 req->style = newval;
125 break;
126 case GCL_CBWNDEXTRA:
127 req->flags = SET_CLASS_WINEXTRA;
128 req->win_extra = newval;
129 break;
130 case GCLP_HMODULE:
131 req->flags = SET_CLASS_INSTANCE;
132 req->instance = (void *)newval;
133 break;
134 default:
135 assert( offset >= 0 );
136 req->flags = SET_CLASS_EXTRA;
137 req->extra_offset = offset;
138 req->extra_size = sizeof(newval);
139 memcpy( &req->extra_value, &newval, sizeof(newval) );
140 break;
142 ret = !wine_server_call_err( req );
144 SERVER_END_REQ;
145 return ret;
149 /***********************************************************************
150 * CLASS_GetProc
152 * Get the class winproc for a given proc type
154 static WNDPROC16 CLASS_GetProc( CLASS *classPtr, WINDOWPROCTYPE type )
156 WNDPROC proc = classPtr->winprocA;
158 if (classPtr->winprocW)
160 /* if we have a Unicode proc, use it if we have no ASCII proc
161 * or if we have both and Unicode was requested
163 if (!proc || type == WIN_PROC_32W) proc = classPtr->winprocW;
165 return WINPROC_GetProc( proc, type );
169 /***********************************************************************
170 * CLASS_SetProc
172 * Set the class winproc for a given proc type.
173 * Returns the previous window proc.
175 static WNDPROC16 CLASS_SetProc( CLASS *classPtr, WNDPROC newproc, WINDOWPROCTYPE type )
177 WNDPROC *proc = &classPtr->winprocA;
178 WNDPROC16 ret;
180 if (classPtr->winprocW)
182 /* if we have a Unicode proc, use it if we have no ASCII proc
183 * or if we have both and Unicode was requested
185 if (!*proc || type == WIN_PROC_32W) proc = &classPtr->winprocW;
187 ret = WINPROC_GetProc( *proc, type );
188 *proc = WINPROC_AllocProc( newproc, type );
189 /* now clear the one that we didn't set */
190 if (classPtr->winprocA && classPtr->winprocW)
192 if (proc == &classPtr->winprocA)
193 classPtr->winprocW = 0;
194 else
195 classPtr->winprocA = 0;
197 return ret;
201 /***********************************************************************
202 * CLASS_GetMenuNameA
204 * Get the menu name as a ASCII string.
206 inline static LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
208 if (!HIWORD(classPtr->menuName)) return (LPSTR)classPtr->menuName;
209 return (LPSTR)(classPtr->menuName + strlenW(classPtr->menuName) + 1);
213 /***********************************************************************
214 * CLASS_GetMenuName16
216 * Get the menu name as a SEGPTR.
218 inline static SEGPTR CLASS_GetMenuName16( CLASS *classPtr )
220 if (!HIWORD(classPtr->menuName)) return (SEGPTR)classPtr->menuName;
221 if (!classPtr->segMenuName)
222 classPtr->segMenuName = MapLS( CLASS_GetMenuNameA(classPtr) );
223 return classPtr->segMenuName;
227 /***********************************************************************
228 * CLASS_GetMenuNameW
230 * Get the menu name as a Unicode string.
232 inline static LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
234 return classPtr->menuName;
238 /***********************************************************************
239 * CLASS_SetMenuNameA
241 * Set the menu name in a class structure by copying the string.
243 static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
245 UnMapLS( classPtr->segMenuName );
246 classPtr->segMenuName = 0;
247 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
248 if (HIWORD(name))
250 DWORD lenA = strlen(name) + 1;
251 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, name, lenA, NULL, 0 );
252 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
253 MultiByteToWideChar( CP_ACP, 0, name, lenA, classPtr->menuName, lenW );
254 memcpy( classPtr->menuName + lenW, name, lenA );
256 else classPtr->menuName = (LPWSTR)name;
260 /***********************************************************************
261 * CLASS_SetMenuNameW
263 * Set the menu name in a class structure by copying the string.
265 static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
267 UnMapLS( classPtr->segMenuName );
268 classPtr->segMenuName = 0;
269 if (HIWORD(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
270 if (HIWORD(name))
272 DWORD lenW = strlenW(name) + 1;
273 DWORD lenA = WideCharToMultiByte( CP_ACP, 0, name, lenW, NULL, 0, NULL, NULL );
274 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
275 memcpy( classPtr->menuName, name, lenW*sizeof(WCHAR) );
276 WideCharToMultiByte( CP_ACP, 0, name, lenW,
277 (char *)(classPtr->menuName + lenW), lenA, NULL, NULL );
279 else classPtr->menuName = (LPWSTR)name;
283 /***********************************************************************
284 * CLASS_FreeClass
286 * Free a class structure.
288 static void CLASS_FreeClass( CLASS *classPtr )
290 TRACE("%p\n", classPtr);
292 USER_Lock();
294 list_remove( &classPtr->entry );
295 if (classPtr->dce) DCE_FreeDCE( classPtr->dce );
296 if (classPtr->hbrBackground > (HBRUSH)(COLOR_GRADIENTINACTIVECAPTION + 1))
297 DeleteObject( classPtr->hbrBackground );
298 UnMapLS( classPtr->segMenuName );
299 HeapFree( GetProcessHeap(), 0, classPtr->menuName );
300 HeapFree( GetProcessHeap(), 0, classPtr );
301 USER_Unlock();
305 /***********************************************************************
306 * CLASS_FreeModuleClasses
308 void CLASS_FreeModuleClasses( HMODULE16 hModule )
310 struct list *ptr, *next;
312 TRACE("0x%08x\n", hModule);
314 USER_Lock();
315 for (ptr = list_head( &class_list ); ptr; ptr = next)
317 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
318 next = list_next( &class_list, ptr );
319 if (class->hInstance == HINSTANCE_32(hModule))
321 BOOL ret;
323 SERVER_START_REQ( destroy_class )
325 req->atom = class->atomName;
326 req->instance = class->hInstance;
327 ret = !wine_server_call_err( req );
329 SERVER_END_REQ;
330 if (ret) CLASS_FreeClass( class );
333 USER_Unlock();
337 /***********************************************************************
338 * CLASS_FindClassByAtom
340 * Return a pointer to the class.
341 * hinstance has been normalized by the caller.
343 static CLASS *CLASS_FindClassByAtom( ATOM atom, HINSTANCE hinstance )
345 struct list *ptr;
347 USER_Lock();
349 LIST_FOR_EACH( ptr, &class_list )
351 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
352 if (class->atomName != atom) continue;
353 if (!hinstance || !class->local || class->hInstance == hinstance)
355 TRACE("0x%04x %p -> %p\n", atom, hinstance, class);
356 return class;
359 USER_Unlock();
360 TRACE("0x%04x %p -> not found\n", atom, hinstance);
361 return NULL;
365 /***********************************************************************
366 * CLASS_RegisterClass
368 * The real RegisterClass() functionality.
369 * The atom is deleted no matter what.
371 static CLASS *CLASS_RegisterClass( ATOM atom, HINSTANCE hInstance, BOOL local,
372 DWORD style, INT classExtra, INT winExtra )
374 CLASS *classPtr;
375 BOOL ret;
377 TRACE("atom=0x%x hinst=%p style=0x%lx clExtr=0x%x winExtr=0x%x\n",
378 atom, hInstance, style, classExtra, winExtra );
380 /* Fix the extra bytes value */
382 if (classExtra < 0 || winExtra < 0)
384 SetLastError( ERROR_INVALID_PARAMETER );
385 return NULL;
387 if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
388 WARN("Class extra bytes %d is > 40\n", classExtra);
389 if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
390 WARN("Win extra bytes %d is > 40\n", winExtra );
392 classPtr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLASS) + classExtra );
393 if (!classPtr)
395 GlobalDeleteAtom( atom );
396 return NULL;
399 SERVER_START_REQ( create_class )
401 req->local = local;
402 req->atom = atom;
403 req->style = style;
404 req->instance = hInstance;
405 req->extra = classExtra;
406 req->win_extra = winExtra;
407 req->client_ptr = classPtr;
408 ret = !wine_server_call_err( req );
410 SERVER_END_REQ;
411 GlobalDeleteAtom( atom ); /* the server increased the atom ref count */
412 if (!ret)
414 HeapFree( GetProcessHeap(), 0, classPtr );
415 return NULL;
418 classPtr->style = style;
419 classPtr->local = local;
420 classPtr->cbWndExtra = winExtra;
421 classPtr->cbClsExtra = classExtra;
422 classPtr->hInstance = hInstance;
423 classPtr->atomName = atom;
424 classPtr->dce = (style & CS_CLASSDC) ? DCE_AllocDCE( 0, DCE_CLASS_DC ) : NULL;
426 /* Other non-null values must be set by caller */
428 USER_Lock();
429 if (local) list_add_head( &class_list, &classPtr->entry );
430 else list_add_tail( &class_list, &classPtr->entry );
431 return classPtr;
435 /***********************************************************************
436 * register_builtin
438 * Register a builtin control class.
439 * This allows having both ASCII and Unicode winprocs for the same class.
441 static CLASS *register_builtin( const struct builtin_class_descr *descr )
443 ATOM atom;
444 CLASS *classPtr;
446 if (!(atom = GlobalAddAtomA( descr->name ))) return 0;
448 if (!(classPtr = CLASS_RegisterClass( atom, user32_module, FALSE,
449 descr->style, 0, descr->extra ))) return 0;
451 classPtr->hCursor = LoadCursorA( 0, (LPSTR)descr->cursor );
452 classPtr->hbrBackground = descr->brush;
454 if (descr->procA) classPtr->winprocA = WINPROC_AllocProc( descr->procA, WIN_PROC_32A );
455 if (descr->procW) classPtr->winprocW = WINPROC_AllocProc( descr->procW, WIN_PROC_32W );
456 release_class_ptr( classPtr );
457 return classPtr;
461 /***********************************************************************
462 * CLASS_RegisterBuiltinClasses
464 void CLASS_RegisterBuiltinClasses(void)
466 extern const struct builtin_class_descr BUTTON_builtin_class;
467 extern const struct builtin_class_descr COMBO_builtin_class;
468 extern const struct builtin_class_descr COMBOLBOX_builtin_class;
469 extern const struct builtin_class_descr DIALOG_builtin_class;
470 extern const struct builtin_class_descr DESKTOP_builtin_class;
471 extern const struct builtin_class_descr EDIT_builtin_class;
472 extern const struct builtin_class_descr ICONTITLE_builtin_class;
473 extern const struct builtin_class_descr LISTBOX_builtin_class;
474 extern const struct builtin_class_descr MDICLIENT_builtin_class;
475 extern const struct builtin_class_descr MENU_builtin_class;
476 extern const struct builtin_class_descr SCROLL_builtin_class;
477 extern const struct builtin_class_descr STATIC_builtin_class;
479 desktop_class = register_builtin( &DESKTOP_builtin_class );
480 register_builtin( &BUTTON_builtin_class );
481 register_builtin( &COMBO_builtin_class );
482 register_builtin( &COMBOLBOX_builtin_class );
483 register_builtin( &DIALOG_builtin_class );
484 register_builtin( &EDIT_builtin_class );
485 register_builtin( &ICONTITLE_builtin_class );
486 register_builtin( &LISTBOX_builtin_class );
487 register_builtin( &MDICLIENT_builtin_class );
488 register_builtin( &MENU_builtin_class );
489 register_builtin( &SCROLL_builtin_class );
490 register_builtin( &STATIC_builtin_class );
494 /***********************************************************************
495 * CLASS_AddWindow
497 * Add a new window using this class, and set the necessary
498 * information inside the window structure.
500 void CLASS_AddWindow( CLASS *class, WND *win, WINDOWPROCTYPE type )
502 if (!class) class = desktop_class;
504 if (type == WIN_PROC_32W)
506 if (!(win->winproc = class->winprocW)) win->winproc = class->winprocA;
508 else
510 if (!(win->winproc = class->winprocA)) win->winproc = class->winprocW;
512 win->class = class;
513 win->clsStyle = class->style;
514 win->dce = class->dce;
518 /***********************************************************************
519 * RegisterClassA (USER32.@)
520 * RETURNS
521 * >0: Unique identifier
522 * 0: Failure
524 ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
526 WNDCLASSEXA wcex;
528 wcex.cbSize = sizeof(wcex);
529 wcex.style = wc->style;
530 wcex.lpfnWndProc = wc->lpfnWndProc;
531 wcex.cbClsExtra = wc->cbClsExtra;
532 wcex.cbWndExtra = wc->cbWndExtra;
533 wcex.hInstance = wc->hInstance;
534 wcex.hIcon = wc->hIcon;
535 wcex.hCursor = wc->hCursor;
536 wcex.hbrBackground = wc->hbrBackground;
537 wcex.lpszMenuName = wc->lpszMenuName;
538 wcex.lpszClassName = wc->lpszClassName;
539 wcex.hIconSm = 0;
540 return RegisterClassExA( &wcex );
544 /***********************************************************************
545 * RegisterClassW (USER32.@)
547 ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
549 WNDCLASSEXW wcex;
551 wcex.cbSize = sizeof(wcex);
552 wcex.style = wc->style;
553 wcex.lpfnWndProc = wc->lpfnWndProc;
554 wcex.cbClsExtra = wc->cbClsExtra;
555 wcex.cbWndExtra = wc->cbWndExtra;
556 wcex.hInstance = wc->hInstance;
557 wcex.hIcon = wc->hIcon;
558 wcex.hCursor = wc->hCursor;
559 wcex.hbrBackground = wc->hbrBackground;
560 wcex.lpszMenuName = wc->lpszMenuName;
561 wcex.lpszClassName = wc->lpszClassName;
562 wcex.hIconSm = 0;
563 return RegisterClassExW( &wcex );
567 /***********************************************************************
568 * RegisterClassExA (USER32.@)
570 ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
572 ATOM atom;
573 CLASS *classPtr;
574 HINSTANCE instance;
576 if (wc->hInstance == user32_module)
578 /* we can't register a class for user32 */
579 SetLastError( ERROR_INVALID_PARAMETER );
580 return 0;
582 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
584 if (!(atom = GlobalAddAtomA( wc->lpszClassName ))) return 0;
586 if (!(classPtr = CLASS_RegisterClass( atom, instance, !(wc->style & CS_GLOBALCLASS),
587 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
588 return 0;
590 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
591 atom, wc->lpfnWndProc, instance, wc->hbrBackground,
592 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
594 classPtr->hIcon = wc->hIcon;
595 classPtr->hIconSm = wc->hIconSm;
596 classPtr->hCursor = wc->hCursor;
597 classPtr->hbrBackground = wc->hbrBackground;
598 classPtr->winprocA = WINPROC_AllocProc( wc->lpfnWndProc, WIN_PROC_32A );
599 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
600 release_class_ptr( classPtr );
601 return atom;
605 /***********************************************************************
606 * RegisterClassExW (USER32.@)
608 ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
610 ATOM atom;
611 CLASS *classPtr;
612 HINSTANCE instance;
614 if (wc->hInstance == user32_module)
616 /* we can't register a class for user32 */
617 SetLastError( ERROR_INVALID_PARAMETER );
618 return 0;
620 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
622 if (!(atom = GlobalAddAtomW( wc->lpszClassName ))) return 0;
624 if (!(classPtr = CLASS_RegisterClass( atom, instance, !(wc->style & CS_GLOBALCLASS),
625 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
626 return 0;
628 TRACE("atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
629 atom, wc->lpfnWndProc, instance, wc->hbrBackground,
630 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
632 classPtr->hIcon = wc->hIcon;
633 classPtr->hIconSm = wc->hIconSm;
634 classPtr->hCursor = wc->hCursor;
635 classPtr->hbrBackground = wc->hbrBackground;
636 classPtr->winprocW = WINPROC_AllocProc( wc->lpfnWndProc, WIN_PROC_32W );
637 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
638 release_class_ptr( classPtr );
639 return atom;
643 /***********************************************************************
644 * UnregisterClassA (USER32.@)
646 BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
648 ATOM atom = HIWORD(className) ? GlobalFindAtomA( className ) : LOWORD(className);
649 return UnregisterClassW( MAKEINTATOMW(atom), hInstance );
652 /***********************************************************************
653 * UnregisterClassW (USER32.@)
655 BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
657 CLASS *classPtr = NULL;
658 ATOM atom = HIWORD(className) ? GlobalFindAtomW( className ) : LOWORD(className);
660 TRACE("%s %p %x\n",debugstr_w(className), hInstance, atom);
662 if (!atom)
664 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
665 return FALSE;
668 SERVER_START_REQ( destroy_class )
670 req->atom = atom;
671 req->instance = hInstance;
672 if (!wine_server_call_err( req )) classPtr = reply->client_ptr;
674 SERVER_END_REQ;
676 if (classPtr) CLASS_FreeClass( classPtr );
677 return (classPtr != NULL);
681 /***********************************************************************
682 * GetClassWord (USER32.@)
684 WORD WINAPI GetClassWord( HWND hwnd, INT offset )
686 CLASS *class;
687 WORD retvalue = 0;
689 if (offset < 0) return GetClassLongA( hwnd, offset );
691 TRACE("%p %x\n",hwnd, offset);
693 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
695 if (class == CLASS_OTHER_PROCESS)
697 SERVER_START_REQ( set_class_info )
699 req->window = hwnd;
700 req->flags = 0;
701 req->extra_offset = offset;
702 req->extra_size = sizeof(retvalue);
703 if (!wine_server_call_err( req ))
704 memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
706 SERVER_END_REQ;
707 return retvalue;
710 if (offset <= class->cbClsExtra - sizeof(WORD))
711 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
712 else
713 SetLastError( ERROR_INVALID_INDEX );
714 release_class_ptr( class );
715 return retvalue;
719 /***********************************************************************
720 * GetClassLong (USER.131)
722 LONG WINAPI GetClassLong16( HWND16 hwnd16, INT16 offset )
724 CLASS *class;
725 LONG ret;
726 HWND hwnd = (HWND)(ULONG_PTR)hwnd16; /* no need for full handle */
728 TRACE("%p %d\n",hwnd, offset);
730 switch( offset )
732 case GCLP_WNDPROC:
733 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
734 if (class == CLASS_OTHER_PROCESS) break;
735 ret = (LONG)CLASS_GetProc( class, WIN_PROC_16 );
736 release_class_ptr( class );
737 return ret;
738 case GCLP_MENUNAME:
739 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
740 if (class == CLASS_OTHER_PROCESS) break;
741 ret = (LONG)CLASS_GetMenuName16( class );
742 release_class_ptr( class );
743 return ret;
744 default:
745 return GetClassLongA( hwnd, offset );
747 FIXME( "offset %d not supported on other process window %p\n", offset, hwnd );
748 SetLastError( ERROR_INVALID_HANDLE );
749 return 0;
753 /***********************************************************************
754 * GetClassLongW (USER32.@)
756 DWORD WINAPI GetClassLongW( HWND hwnd, INT offset )
758 CLASS *class;
759 DWORD retvalue = 0;
761 TRACE("%p %d\n", hwnd, offset);
763 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
765 if (class == CLASS_OTHER_PROCESS)
767 SERVER_START_REQ( set_class_info )
769 req->window = hwnd;
770 req->flags = 0;
771 req->extra_offset = (offset >= 0) ? offset : -1;
772 req->extra_size = (offset >= 0) ? sizeof(retvalue) : 0;
773 if (!wine_server_call_err( req ))
775 switch(offset)
777 case GCLP_HBRBACKGROUND:
778 case GCLP_HCURSOR:
779 case GCLP_HICON:
780 case GCLP_HICONSM:
781 case GCLP_WNDPROC:
782 case GCLP_MENUNAME:
783 FIXME( "offset %d not supported on other process window %p\n", offset, hwnd );
784 SetLastError( ERROR_INVALID_HANDLE );
785 break;
786 case GCL_STYLE:
787 retvalue = reply->old_style;
788 break;
789 case GCL_CBWNDEXTRA:
790 retvalue = reply->old_win_extra;
791 break;
792 case GCL_CBCLSEXTRA:
793 retvalue = reply->old_extra;
794 break;
795 case GCLP_HMODULE:
796 retvalue = (DWORD)reply->old_instance;
797 break;
798 case GCW_ATOM:
799 retvalue = reply->old_atom;
800 break;
801 default:
802 if (offset >= 0) memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
803 else SetLastError( ERROR_INVALID_INDEX );
804 break;
808 SERVER_END_REQ;
809 return retvalue;
812 if (offset >= 0)
814 if (offset <= class->cbClsExtra - sizeof(LONG))
815 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
816 else
817 SetLastError( ERROR_INVALID_INDEX );
818 release_class_ptr( class );
819 return retvalue;
822 switch(offset)
824 case GCLP_HBRBACKGROUND:
825 retvalue = (DWORD)class->hbrBackground;
826 break;
827 case GCLP_HCURSOR:
828 retvalue = (DWORD)class->hCursor;
829 break;
830 case GCLP_HICON:
831 retvalue = (DWORD)class->hIcon;
832 break;
833 case GCLP_HICONSM:
834 retvalue = (DWORD)class->hIconSm;
835 break;
836 case GCL_STYLE:
837 retvalue = (DWORD)class->style;
838 break;
839 case GCL_CBWNDEXTRA:
840 retvalue = (DWORD)class->cbWndExtra;
841 break;
842 case GCL_CBCLSEXTRA:
843 retvalue = (DWORD)class->cbClsExtra;
844 break;
845 case GCLP_HMODULE:
846 retvalue = (DWORD)class->hInstance;
847 break;
848 case GCLP_WNDPROC:
849 retvalue = (DWORD)CLASS_GetProc( class, WIN_PROC_32W );
850 break;
851 case GCLP_MENUNAME:
852 retvalue = (DWORD)CLASS_GetMenuNameW( class );
853 break;
854 case GCW_ATOM:
855 retvalue = (DWORD)class->atomName;
856 break;
857 default:
858 SetLastError( ERROR_INVALID_INDEX );
859 break;
861 release_class_ptr( class );
862 return retvalue;
866 /***********************************************************************
867 * GetClassLongA (USER32.@)
869 DWORD WINAPI GetClassLongA( HWND hwnd, INT offset )
871 CLASS *class;
872 DWORD retvalue;
874 if (offset != GCLP_WNDPROC && offset != GCLP_MENUNAME)
875 return GetClassLongW( hwnd, offset );
877 TRACE("%p %d\n", hwnd, offset);
879 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
881 if (class == CLASS_OTHER_PROCESS)
883 FIXME( "offset %d not supported on other process window %p\n", offset, hwnd );
884 SetLastError( ERROR_INVALID_HANDLE );
885 return 0;
888 if (offset == GCLP_WNDPROC)
889 retvalue = (DWORD)CLASS_GetProc( class, WIN_PROC_32A );
890 else /* GCL_MENUNAME */
891 retvalue = (DWORD)CLASS_GetMenuNameA( class );
893 release_class_ptr( class );
894 return retvalue;
898 /***********************************************************************
899 * SetClassWord (USER32.@)
901 WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
903 CLASS *class;
904 WORD retval = 0;
906 if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
908 TRACE("%p %d %x\n", hwnd, offset, newval);
910 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
912 SERVER_START_REQ( set_class_info )
914 req->window = hwnd;
915 req->flags = SET_CLASS_EXTRA;
916 req->extra_offset = offset;
917 req->extra_size = sizeof(newval);
918 memcpy( &req->extra_value, &newval, sizeof(newval) );
919 if (!wine_server_call_err( req ))
921 void *ptr = (char *)(class + 1) + offset;
922 memcpy( &retval, ptr, sizeof(retval) );
923 memcpy( ptr, &newval, sizeof(newval) );
926 SERVER_END_REQ;
927 release_class_ptr( class );
928 return retval;
932 /***********************************************************************
933 * SetClassLong (USER.132)
935 LONG WINAPI SetClassLong16( HWND16 hwnd16, INT16 offset, LONG newval )
937 CLASS *class;
938 LONG retval;
939 HWND hwnd = (HWND)(ULONG_PTR)hwnd16; /* no need for full handle */
941 TRACE("%p %d %lx\n", hwnd, offset, newval);
943 switch(offset)
945 case GCLP_WNDPROC:
946 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
947 retval = (LONG)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_16 );
948 release_class_ptr( class );
949 return retval;
950 case GCLP_MENUNAME:
951 newval = (LONG)MapSL( newval );
952 /* fall through */
953 default:
954 return SetClassLongA( hwnd, offset, newval );
959 /***********************************************************************
960 * SetClassLongW (USER32.@)
962 DWORD WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
964 CLASS *class;
965 DWORD retval = 0;
967 TRACE("%p %d %lx\n", hwnd, offset, newval);
969 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
971 if (offset >= 0)
973 if (set_server_info( hwnd, offset, newval ))
975 void *ptr = (char *)(class + 1) + offset;
976 memcpy( &retval, ptr, sizeof(retval) );
977 memcpy( ptr, &newval, sizeof(newval) );
980 else switch(offset)
982 case GCLP_MENUNAME:
983 CLASS_SetMenuNameW( class, (LPCWSTR)newval );
984 retval = 0; /* Old value is now meaningless anyway */
985 break;
986 case GCLP_WNDPROC:
987 retval = (DWORD)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_32W );
988 break;
989 case GCLP_HBRBACKGROUND:
990 retval = (DWORD)class->hbrBackground;
991 class->hbrBackground = (HBRUSH)newval;
992 break;
993 case GCLP_HCURSOR:
994 retval = (DWORD)class->hCursor;
995 class->hCursor = (HCURSOR)newval;
996 break;
997 case GCLP_HICON:
998 retval = (DWORD)class->hIcon;
999 class->hIcon = (HICON)newval;
1000 break;
1001 case GCLP_HICONSM:
1002 retval = (DWORD)class->hIconSm;
1003 class->hIconSm = (HICON)newval;
1004 break;
1005 case GCL_STYLE:
1006 if (!set_server_info( hwnd, offset, newval )) break;
1007 retval = (DWORD)class->style;
1008 class->style = newval;
1009 break;
1010 case GCL_CBWNDEXTRA:
1011 if (!set_server_info( hwnd, offset, newval )) break;
1012 retval = (DWORD)class->cbWndExtra;
1013 class->cbWndExtra = newval;
1014 break;
1015 case GCLP_HMODULE:
1016 if (!set_server_info( hwnd, offset, newval )) break;
1017 retval = (DWORD)class->hInstance;
1018 class->hInstance = (HINSTANCE)newval;
1019 break;
1020 case GCW_ATOM:
1021 if (!set_server_info( hwnd, offset, newval )) break;
1022 retval = (DWORD)class->atomName;
1023 class->atomName = newval;
1024 break;
1025 case GCL_CBCLSEXTRA: /* cannot change this one */
1026 SetLastError( ERROR_INVALID_PARAMETER );
1027 break;
1028 default:
1029 SetLastError( ERROR_INVALID_INDEX );
1030 break;
1032 release_class_ptr( class );
1033 return retval;
1037 /***********************************************************************
1038 * SetClassLongA (USER32.@)
1040 DWORD WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
1042 CLASS *class;
1043 DWORD retval;
1045 if (offset != GCLP_WNDPROC && offset != GCLP_MENUNAME)
1046 return SetClassLongW( hwnd, offset, newval );
1048 TRACE("%p %d %lx\n", hwnd, offset, newval);
1050 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
1052 if (offset == GCLP_WNDPROC)
1053 retval = (DWORD)CLASS_SetProc( class, (WNDPROC)newval, WIN_PROC_32A );
1054 else /* GCL_MENUNAME */
1056 CLASS_SetMenuNameA( class, (LPCSTR)newval );
1057 retval = 0; /* Old value is now meaningless anyway */
1059 release_class_ptr( class );
1060 return retval;
1064 /***********************************************************************
1065 * GetClassNameA (USER32.@)
1067 INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
1069 INT ret = GlobalGetAtomNameA( GetClassLongA( hwnd, GCW_ATOM ), buffer, count );
1071 TRACE("%p %s %x\n",hwnd, debugstr_a(buffer), count);
1072 return ret;
1076 /***********************************************************************
1077 * GetClassNameW (USER32.@)
1079 INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
1081 INT ret = GlobalGetAtomNameW( GetClassLongW( hwnd, GCW_ATOM ), buffer, count );
1083 TRACE("%p %s %x\n",hwnd, debugstr_w(buffer), count);
1084 return ret;
1088 /***********************************************************************
1089 * RealGetWindowClassA (USER32.@)
1091 UINT WINAPI RealGetWindowClassA( HWND hwnd, LPSTR buffer, UINT count )
1093 return GetClassNameA( hwnd, buffer, count );
1097 /***********************************************************************
1098 * RealGetWindowClassW (USER32.@)
1100 UINT WINAPI RealGetWindowClassW( HWND hwnd, LPWSTR buffer, UINT count )
1102 return GetClassNameW( hwnd, buffer, count );
1106 /***********************************************************************
1107 * GetClassInfoA (USER32.@)
1109 BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name, WNDCLASSA *wc )
1111 WNDCLASSEXA wcex;
1112 UINT ret = GetClassInfoExA( hInstance, name, &wcex );
1114 if (ret)
1116 wc->style = wcex.style;
1117 wc->lpfnWndProc = wcex.lpfnWndProc;
1118 wc->cbClsExtra = wcex.cbClsExtra;
1119 wc->cbWndExtra = wcex.cbWndExtra;
1120 wc->hInstance = wcex.hInstance;
1121 wc->hIcon = wcex.hIcon;
1122 wc->hCursor = wcex.hCursor;
1123 wc->hbrBackground = wcex.hbrBackground;
1124 wc->lpszMenuName = wcex.lpszMenuName;
1125 wc->lpszClassName = wcex.lpszClassName;
1127 return ret;
1131 /***********************************************************************
1132 * GetClassInfoW (USER32.@)
1134 BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSW *wc )
1136 WNDCLASSEXW wcex;
1137 UINT ret = GetClassInfoExW( hInstance, name, &wcex );
1139 if (ret)
1141 wc->style = wcex.style;
1142 wc->lpfnWndProc = wcex.lpfnWndProc;
1143 wc->cbClsExtra = wcex.cbClsExtra;
1144 wc->cbWndExtra = wcex.cbWndExtra;
1145 wc->hInstance = wcex.hInstance;
1146 wc->hIcon = wcex.hIcon;
1147 wc->hCursor = wcex.hCursor;
1148 wc->hbrBackground = wcex.hbrBackground;
1149 wc->lpszMenuName = wcex.lpszMenuName;
1150 wc->lpszClassName = wcex.lpszClassName;
1152 return ret;
1156 /***********************************************************************
1157 * GetClassInfoExA (USER32.@)
1159 BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name, WNDCLASSEXA *wc )
1161 ATOM atom = HIWORD(name) ? GlobalFindAtomA( name ) : LOWORD(name);
1162 CLASS *classPtr;
1164 TRACE("%p %s %x %p\n", hInstance, debugstr_a(name), atom, wc);
1166 if (!hInstance) hInstance = user32_module;
1168 if (!atom || !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
1170 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1171 return FALSE;
1173 wc->style = classPtr->style;
1174 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32A );
1175 wc->cbClsExtra = classPtr->cbClsExtra;
1176 wc->cbWndExtra = classPtr->cbWndExtra;
1177 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1178 wc->hIcon = (HICON)classPtr->hIcon;
1179 wc->hIconSm = (HICON)classPtr->hIconSm;
1180 wc->hCursor = (HCURSOR)classPtr->hCursor;
1181 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1182 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
1183 wc->lpszClassName = name;
1184 release_class_ptr( classPtr );
1186 /* We must return the atom of the class here instead of just TRUE. */
1187 return atom;
1191 /***********************************************************************
1192 * GetClassInfoExW (USER32.@)
1194 BOOL WINAPI GetClassInfoExW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSEXW *wc )
1196 ATOM atom = HIWORD(name) ? GlobalFindAtomW( name ) : LOWORD(name);
1197 CLASS *classPtr;
1199 TRACE("%p %s %x %p\n", hInstance, debugstr_w(name), atom, wc);
1201 if (!hInstance) hInstance = user32_module;
1203 if (!atom || !(classPtr = CLASS_FindClassByAtom( atom, hInstance )))
1205 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1206 return FALSE;
1208 wc->style = classPtr->style;
1209 wc->lpfnWndProc = (WNDPROC)CLASS_GetProc( classPtr, WIN_PROC_32W );
1210 wc->cbClsExtra = classPtr->cbClsExtra;
1211 wc->cbWndExtra = classPtr->cbWndExtra;
1212 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1213 wc->hIcon = (HICON)classPtr->hIcon;
1214 wc->hIconSm = (HICON)classPtr->hIconSm;
1215 wc->hCursor = (HCURSOR)classPtr->hCursor;
1216 wc->hbrBackground = (HBRUSH)classPtr->hbrBackground;
1217 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1218 wc->lpszClassName = name;
1219 release_class_ptr( classPtr );
1221 /* We must return the atom of the class here instead of just TRUE. */
1222 return atom;
1226 #if 0 /* toolhelp is in kernel, so this cannot work */
1228 /***********************************************************************
1229 * ClassFirst (TOOLHELP.69)
1231 BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
1233 TRACE("%p\n",pClassEntry);
1234 pClassEntry->wNext = 1;
1235 return ClassNext16( pClassEntry );
1239 /***********************************************************************
1240 * ClassNext (TOOLHELP.70)
1242 BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
1244 int i;
1245 CLASS *class = firstClass;
1247 TRACE("%p\n",pClassEntry);
1249 if (!pClassEntry->wNext) return FALSE;
1250 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1251 if (!class)
1253 pClassEntry->wNext = 0;
1254 return FALSE;
1256 pClassEntry->hInst = class->hInstance;
1257 pClassEntry->wNext++;
1258 GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
1259 sizeof(pClassEntry->szClassName) );
1260 return TRUE;
1262 #endif