1 /*
2 * Window classes functions
3 *
4 * Copyright 1993, 1996, 2003 Alexandre Julliard
5 * Copyright 1998 Juergen Schmied (jsch)
6 *
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.
11 *
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.
16 *
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
20 */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <stdlib.h>
28 #include <string.h>
29
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"
41
42 WINE_DEFAULT_DEBUG_CHANNEL(class);
43
44 #define MAX_ATOM_LEN 255 /* from dlls/kernel32/atom.c */
45
46 typedef struct tagCLASS
47 {
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 HCURSOR hCursor; /* Default cursor */
60 HBRUSH hbrBackground; /* Default background */
61 ATOM atomName; /* Name of the class */
62 WCHAR name[MAX_ATOM_LEN + 1];
63 } CLASS;
64
65 static struct list class_list = LIST_INIT( class_list );
66
67 #define CLASS_OTHER_PROCESS ((CLASS *)1)
68
69 /***********************************************************************
70 * get_class_ptr
71 */
72 static CLASS *get_class_ptr( HWND hwnd, BOOL write_access )
73 {
74 WND *ptr = WIN_GetPtr( hwnd );
75
76 if (ptr)
77 {
78 if (ptr != WND_OTHER_PROCESS && ptr != WND_DESKTOP) return ptr->class;
79 if (!write_access) return CLASS_OTHER_PROCESS;
80
81 /* modifying classes in other processes is not allowed */
82 if (ptr == WND_DESKTOP || IsWindow( hwnd ))
83 {
84 SetLastError( ERROR_ACCESS_DENIED );
85 return NULL;
86 }
87 }
88 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
89 return NULL;
90 }
91
92
93 /***********************************************************************
94 * release_class_ptr
95 */
96 static inline void release_class_ptr( CLASS *ptr )
97 {
98 USER_Unlock();
99 }
100
101
102 /***********************************************************************
103 * get_int_atom_value
104 */
105 ATOM get_int_atom_value( LPCWSTR name )
106 {
107 UINT ret = 0;
108
109 if (IS_INTRESOURCE(name)) return LOWORD(name);
110 if (*name++ != '#') return 0;
111 while (*name)
112 {
113 if (*name < '' || *name > '9') return 0;
114 ret = ret * 10 + *name++ - '';
115 if (ret > 0xffff) return 0;
116 }
117 return ret;
118 }
119
120
121 /***********************************************************************
122 * set_server_info
123 *
124 * Set class info with the wine server.
125 */
126 static BOOL set_server_info( HWND hwnd, INT offset, LONG_PTR newval, UINT size )
127 {
128 BOOL ret;
129
130 SERVER_START_REQ( set_class_info )
131 {
132 req->window = wine_server_user_handle( hwnd );
133 req->extra_offset = -1;
134 switch(offset)
135 {
136 case GCW_ATOM:
137 req->flags = SET_CLASS_ATOM;
138 req->atom = LOWORD(newval);
139 break;
140 case GCL_STYLE:
141 req->flags = SET_CLASS_STYLE;
142 req->style = newval;
143 break;
144 case GCL_CBWNDEXTRA:
145 req->flags = SET_CLASS_WINEXTRA;
146 req->win_extra = newval;
147 break;
148 case GCLP_HMODULE:
149 req->flags = SET_CLASS_INSTANCE;
150 req->instance = wine_server_client_ptr( (void *)newval );
151 break;
152 default:
153 assert( offset >= 0 );
154 req->flags = SET_CLASS_EXTRA;
155 req->extra_offset = offset;
156 req->extra_size = size;
157 if ( size == sizeof(LONG) )
158 {
159 LONG newlong = newval;
160 memcpy( &req->extra_value, &newlong, sizeof(LONG) );
161 }
162 else
163 memcpy( &req->extra_value, &newval, sizeof(LONG_PTR) );
164 break;
165 }
166 ret = !wine_server_call_err( req );
167 }
168 SERVER_END_REQ;
169 return ret;
170 }
171
172
173 /***********************************************************************
174 * CLASS_GetMenuNameA
175 *
176 * Get the menu name as a ASCII string.
177 */
178 static inline LPSTR CLASS_GetMenuNameA( CLASS *classPtr )
179 {
180 if (IS_INTRESOURCE(classPtr->menuName)) return (LPSTR)classPtr->menuName;
181 return (LPSTR)(classPtr->menuName + strlenW(classPtr->menuName) + 1);
182 }
183
184
185 /***********************************************************************
186 * CLASS_GetMenuNameW
187 *
188 * Get the menu name as a Unicode string.
189 */
190 static inline LPWSTR CLASS_GetMenuNameW( CLASS *classPtr )
191 {
192 return classPtr->menuName;
193 }
194
195
196 /***********************************************************************
197 * CLASS_SetMenuNameA
198 *
199 * Set the menu name in a class structure by copying the string.
200 */
201 static void CLASS_SetMenuNameA( CLASS *classPtr, LPCSTR name )
202 {
203 if (!IS_INTRESOURCE(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
204 if (!IS_INTRESOURCE(name))
205 {
206 DWORD lenA = strlen(name) + 1;
207 DWORD lenW = MultiByteToWideChar( CP_ACP, 0, name, lenA, NULL, 0 );
208 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
209 MultiByteToWideChar( CP_ACP, 0, name, lenA, classPtr->menuName, lenW );
210 memcpy( classPtr->menuName + lenW, name, lenA );
211 }
212 else classPtr->menuName = (LPWSTR)name;
213 }
214
215
216 /***********************************************************************
217 * CLASS_SetMenuNameW
218 *
219 * Set the menu name in a class structure by copying the string.
220 */
221 static void CLASS_SetMenuNameW( CLASS *classPtr, LPCWSTR name )
222 {
223 if (!IS_INTRESOURCE(classPtr->menuName)) HeapFree( GetProcessHeap(), 0, classPtr->menuName );
224 if (!IS_INTRESOURCE(name))
225 {
226 DWORD lenW = strlenW(name) + 1;
227 DWORD lenA = WideCharToMultiByte( CP_ACP, 0, name, lenW, NULL, 0, NULL, NULL );
228 classPtr->menuName = HeapAlloc( GetProcessHeap(), 0, lenA + lenW*sizeof(WCHAR) );
229 memcpy( classPtr->menuName, name, lenW*sizeof(WCHAR) );
230 WideCharToMultiByte( CP_ACP, 0, name, lenW,
231 (char *)(classPtr->menuName + lenW), lenA, NULL, NULL );
232 }
233 else classPtr->menuName = (LPWSTR)name;
234 }
235
236
237 /***********************************************************************
238 * CLASS_FreeClass
239 *
240 * Free a class structure.
241 */
242 static void CLASS_FreeClass( CLASS *classPtr )
243 {
244 TRACE("%p\n", classPtr);
245
246 USER_Lock();
247
248 if (classPtr->dce) free_dce( classPtr->dce, 0 );
249 list_remove( &classPtr->entry );
250 if (classPtr->hbrBackground > (HBRUSH)(COLOR_GRADIENTINACTIVECAPTION + 1))
251 DeleteObject( classPtr->hbrBackground );
252 HeapFree( GetProcessHeap(), 0, classPtr->menuName );
253 HeapFree( GetProcessHeap(), 0, classPtr );
254 USER_Unlock();
255 }
256
257
258 /***********************************************************************
259 * CLASS_FindClass
260 *
261 * Return a pointer to the class.
262 * hinstance has been normalized by the caller.
263 */
264 static CLASS *CLASS_FindClass( LPCWSTR name, HINSTANCE hinstance )
265 {
266 struct list *ptr;
267 ATOM atom = get_int_atom_value( name );
268
269 USER_Lock();
270
271 LIST_FOR_EACH( ptr, &class_list )
272 {
273 CLASS *class = LIST_ENTRY( ptr, CLASS, entry );
274 if (atom)
275 {
276 if (class->atomName != atom) continue;
277 }
278 else
279 {
280 if (!name || strcmpiW( class->name, name )) continue;
281 }
282 if (!hinstance || !class->local || class->hInstance == hinstance)
283 {
284 TRACE("%s %p -> %p\n", debugstr_w(name), hinstance, class);
285 return class;
286 }
287 }
288 USER_Unlock();
289 TRACE("%s %p -> not found\n", debugstr_w(name), hinstance);
290 return NULL;
291 }
292
293
294 /***********************************************************************
295 * CLASS_RegisterClass
296 *
297 * The real RegisterClass() functionality.
298 */
299 static CLASS *CLASS_RegisterClass( LPCWSTR name, HINSTANCE hInstance, BOOL local,
300 DWORD style, INT classExtra, INT winExtra )
301 {
302 CLASS *classPtr;
303 BOOL ret;
304
305 TRACE("name=%s hinst=%p style=0x%x clExtr=0x%x winExtr=0x%x\n",
306 debugstr_w(name), hInstance, style, classExtra, winExtra );
307
308 /* Fix the extra bytes value */
309
310 if (classExtra > 40) /* Extra bytes are limited to 40 in Win32 */
311 WARN("Class extra bytes %d is > 40\n", classExtra);
312 if (winExtra > 40) /* Extra bytes are limited to 40 in Win32 */
313 WARN("Win extra bytes %d is > 40\n", winExtra );
314
315 classPtr = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CLASS) + classExtra );
316 if (!classPtr) return NULL;
317
318 classPtr->atomName = get_int_atom_value( name );
319 if (!classPtr->atomName && name) strcpyW( classPtr->name, name );
320 else GlobalGetAtomNameW( classPtr->atomName, classPtr->name, sizeof(classPtr->name)/sizeof(WCHAR) );
321
322 SERVER_START_REQ( create_class )
323 {
324 req->local = local;
325 req->style = style;
326 req->instance = wine_server_client_ptr( hInstance );
327 req->extra = classExtra;
328 req->win_extra = winExtra;
329 req->client_ptr = wine_server_client_ptr( classPtr );
330 req->atom = classPtr->atomName;
331 if (!req->atom && name) wine_server_add_data( req, name, strlenW(name) * sizeof(WCHAR) );
332 ret = !wine_server_call_err( req );
333 classPtr->atomName = reply->atom;
334 }
335 SERVER_END_REQ;
336 if (!ret)
337 {
338 HeapFree( GetProcessHeap(), 0, classPtr );
339 return NULL;
340 }
341
342 classPtr->style = style;
343 classPtr->local = local;
344 classPtr->cbWndExtra = winExtra;
345 classPtr->cbClsExtra = classExtra;
346 classPtr->hInstance = hInstance;
347
348 /* Other non-null values must be set by caller */
349
350 USER_Lock();
351 if (local) list_add_head( &class_list, &classPtr->entry );
352 else list_add_tail( &class_list, &classPtr->entry );
353 return classPtr;
354 }
355
356
357 /***********************************************************************
358 * register_builtin
359 *
360 * Register a builtin control class.
361 * This allows having both ASCII and Unicode winprocs for the same class.
362 */
363 static void register_builtin( const struct builtin_class_descr *descr )
364 {
365 CLASS *classPtr;
366
367 if (!(classPtr = CLASS_RegisterClass( descr->name, user32_module, FALSE,
368 descr->style, 0, descr->extra ))) return;
369
370 classPtr->hCursor = LoadCursorA( 0, (LPSTR)descr->cursor );
371 classPtr->hbrBackground = descr->brush;
372 classPtr->winproc = BUILTIN_WINPROC( descr->proc );
373 release_class_ptr( classPtr );
374 }
375
376
377 /***********************************************************************
378 * CLASS_RegisterBuiltinClasses
379 */
380 void CLASS_RegisterBuiltinClasses(void)
381 {
382 register_builtin( &DESKTOP_builtin_class );
383 register_builtin( &BUTTON_builtin_class );
384 register_builtin( &COMBO_builtin_class );
385 register_builtin( &COMBOLBOX_builtin_class );
386 register_builtin( &DIALOG_builtin_class );
387 register_builtin( &EDIT_builtin_class );
388 register_builtin( &ICONTITLE_builtin_class );
389 register_builtin( &LISTBOX_builtin_class );
390 register_builtin( &MDICLIENT_builtin_class );
391 register_builtin( &MENU_builtin_class );
392 register_builtin( &MESSAGE_builtin_class );
393 register_builtin( &SCROLL_builtin_class );
394 register_builtin( &STATIC_builtin_class );
395 }
396
397
398 /***********************************************************************
399 * get_class_winproc
400 */
401 WNDPROC get_class_winproc( CLASS *class )
402 {
403 return class->winproc;
404 }
405
406
407 /***********************************************************************
408 * get_class_dce
409 */
410 struct dce *get_class_dce( CLASS *class )
411 {
412 return class->dce;
413 }
414
415
416 /***********************************************************************
417 * set_class_dce
418 */
419 struct dce *set_class_dce( CLASS *class, struct dce *dce )
420 {
421 if (class->dce) return class->dce; /* already set, don't change it */
422 class->dce = dce;
423 return dce;
424 }
425
426
427 /***********************************************************************
428 * RegisterClassA (USER32.@)
429 *
430 * Register a window class.
431 *
432 * RETURNS
433 * >0: Unique identifier
434 * 0: Failure
435 */
436 ATOM WINAPI RegisterClassA( const WNDCLASSA* wc ) /* [in] Address of structure with class data */
437 {
438 WNDCLASSEXA wcex;
439
440 wcex.cbSize = sizeof(wcex);
441 wcex.style = wc->style;
442 wcex.lpfnWndProc = wc->lpfnWndProc;
443 wcex.cbClsExtra = wc->cbClsExtra;
444 wcex.cbWndExtra = wc->cbWndExtra;
445 wcex.hInstance = wc->hInstance;
446 wcex.hIcon = wc->hIcon;
447 wcex.hCursor = wc->hCursor;
448 wcex.hbrBackground = wc->hbrBackground;
449 wcex.lpszMenuName = wc->lpszMenuName;
450 wcex.lpszClassName = wc->lpszClassName;
451 wcex.hIconSm = 0;
452 return RegisterClassExA( &wcex );
453 }
454
455
456 /***********************************************************************
457 * RegisterClassW (USER32.@)
458 *
459 * See RegisterClassA.
460 */
461 ATOM WINAPI RegisterClassW( const WNDCLASSW* wc )
462 {
463 WNDCLASSEXW wcex;
464
465 wcex.cbSize = sizeof(wcex);
466 wcex.style = wc->style;
467 wcex.lpfnWndProc = wc->lpfnWndProc;
468 wcex.cbClsExtra = wc->cbClsExtra;
469 wcex.cbWndExtra = wc->cbWndExtra;
470 wcex.hInstance = wc->hInstance;
471 wcex.hIcon = wc->hIcon;
472 wcex.hCursor = wc->hCursor;
473 wcex.hbrBackground = wc->hbrBackground;
474 wcex.lpszMenuName = wc->lpszMenuName;
475 wcex.lpszClassName = wc->lpszClassName;
476 wcex.hIconSm = 0;
477 return RegisterClassExW( &wcex );
478 }
479
480
481 /***********************************************************************
482 * RegisterClassExA (USER32.@)
483 */
484 ATOM WINAPI RegisterClassExA( const WNDCLASSEXA* wc )
485 {
486 ATOM atom;
487 CLASS *classPtr;
488 HINSTANCE instance;
489
490 if (wc->cbSize != sizeof(*wc) || wc->cbClsExtra < 0 || wc->cbWndExtra < 0 ||
491 wc->hInstance == user32_module) /* we can't register a class for user32 */
492 {
493 SetLastError( ERROR_INVALID_PARAMETER );
494 return 0;
495 }
496 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
497
498 if (!IS_INTRESOURCE(wc->lpszClassName))
499 {
500 WCHAR name[MAX_ATOM_LEN + 1];
501
502 if (!MultiByteToWideChar( CP_ACP, 0, wc->lpszClassName, -1, name, MAX_ATOM_LEN + 1 )) return 0;
503 classPtr = CLASS_RegisterClass( name, instance, !(wc->style & CS_GLOBALCLASS),
504 wc->style, wc->cbClsExtra, wc->cbWndExtra );
505 }
506 else
507 {
508 classPtr = CLASS_RegisterClass( (LPCWSTR)wc->lpszClassName, instance,
509 !(wc->style & CS_GLOBALCLASS), wc->style,
510 wc->cbClsExtra, wc->cbWndExtra );
511 }
512 if (!classPtr) return 0;
513 atom = classPtr->atomName;
514
515 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
516 debugstr_a(wc->lpszClassName), atom, wc->lpfnWndProc, instance, wc->hbrBackground,
517 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
518
519 classPtr->hIcon = wc->hIcon;
520 classPtr->hIconSm = wc->hIconSm;
521 classPtr->hCursor = wc->hCursor;
522 classPtr->hbrBackground = wc->hbrBackground;
523 classPtr->winproc = WINPROC_AllocProc( wc->lpfnWndProc, FALSE );
524 CLASS_SetMenuNameA( classPtr, wc->lpszMenuName );
525 release_class_ptr( classPtr );
526 return atom;
527 }
528
529
530 /***********************************************************************
531 * RegisterClassExW (USER32.@)
532 */
533 ATOM WINAPI RegisterClassExW( const WNDCLASSEXW* wc )
534 {
535 ATOM atom;
536 CLASS *classPtr;
537 HINSTANCE instance;
538
539 if (wc->cbSize != sizeof(*wc) || wc->cbClsExtra < 0 || wc->cbWndExtra < 0 ||
540 wc->hInstance == user32_module) /* we can't register a class for user32 */
541 {
542 SetLastError( ERROR_INVALID_PARAMETER );
543 return 0;
544 }
545 if (!(instance = wc->hInstance)) instance = GetModuleHandleW( NULL );
546
547 if (!(classPtr = CLASS_RegisterClass( wc->lpszClassName, instance, !(wc->style & CS_GLOBALCLASS),
548 wc->style, wc->cbClsExtra, wc->cbWndExtra )))
549 return 0;
550
551 atom = classPtr->atomName;
552
553 TRACE("name=%s atom=%04x wndproc=%p hinst=%p bg=%p style=%08x clsExt=%d winExt=%d class=%p\n",
554 debugstr_w(wc->lpszClassName), atom, wc->lpfnWndProc, instance, wc->hbrBackground,
555 wc->style, wc->cbClsExtra, wc->cbWndExtra, classPtr );
556
557 classPtr->hIcon = wc->hIcon;
558 classPtr->hIconSm = wc->hIconSm;
559 classPtr->hCursor = wc->hCursor;
560 classPtr->hbrBackground = wc->hbrBackground;
561 classPtr->winproc = WINPROC_AllocProc( wc->lpfnWndProc, TRUE );
562 CLASS_SetMenuNameW( classPtr, wc->lpszMenuName );
563 release_class_ptr( classPtr );
564 return atom;
565 }
566
567
568 /***********************************************************************
569 * UnregisterClassA (USER32.@)
570 */
571 BOOL WINAPI UnregisterClassA( LPCSTR className, HINSTANCE hInstance )
572 {
573 if (!IS_INTRESOURCE(className))
574 {
575 WCHAR name[MAX_ATOM_LEN + 1];
576
577 if (!MultiByteToWideChar( CP_ACP, 0, className, -1, name, MAX_ATOM_LEN + 1 ))
578 return FALSE;
579 return UnregisterClassW( name, hInstance );
580 }
581 return UnregisterClassW( (LPCWSTR)className, hInstance );
582 }
583
584 /***********************************************************************
585 * UnregisterClassW (USER32.@)
586 */
587 BOOL WINAPI UnregisterClassW( LPCWSTR className, HINSTANCE hInstance )
588 {
589 CLASS *classPtr = NULL;
590
591 SERVER_START_REQ( destroy_class )
592 {
593 req->instance = wine_server_client_ptr( hInstance );
594 if (!(req->atom = get_int_atom_value(className)) && className)
595 wine_server_add_data( req, className, strlenW(className) * sizeof(WCHAR) );
596 if (!wine_server_call_err( req )) classPtr = wine_server_get_ptr( reply->client_ptr );
597 }
598 SERVER_END_REQ;
599
600 if (classPtr) CLASS_FreeClass( classPtr );
601 return (classPtr != NULL);
602 }
603
604
605 /***********************************************************************
606 * GetClassWord (USER32.@)
607 */
608 WORD WINAPI GetClassWord( HWND hwnd, INT offset )
609 {
610 CLASS *class;
611 WORD retvalue = 0;
612
613 if (offset < 0) return GetClassLongA( hwnd, offset );
614
615 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
616
617 if (class == CLASS_OTHER_PROCESS)
618 {
619 SERVER_START_REQ( set_class_info )
620 {
621 req->window = wine_server_user_handle( hwnd );
622 req->flags = 0;
623 req->extra_offset = offset;
624 req->extra_size = sizeof(retvalue);
625 if (!wine_server_call_err( req ))
626 memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
627 }
628 SERVER_END_REQ;
629 return retvalue;
630 }
631
632 if (offset <= class->cbClsExtra - sizeof(WORD))
633 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(retvalue) );
634 else
635 SetLastError( ERROR_INVALID_INDEX );
636 release_class_ptr( class );
637 return retvalue;
638 }
639
640
641 /***********************************************************************
642 * CLASS_GetClassLong
643 *
644 * Implementation of GetClassLong(Ptr)A/W
645 */
646 static ULONG_PTR CLASS_GetClassLong( HWND hwnd, INT offset, UINT size,
647 BOOL unicode )
648 {
649 CLASS *class;
650 ULONG_PTR retvalue = 0;
651
652 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
653
654 if (class == CLASS_OTHER_PROCESS)
655 {
656 SERVER_START_REQ( set_class_info )
657 {
658 req->window = wine_server_user_handle( hwnd );
659 req->flags = 0;
660 req->extra_offset = (offset >= 0) ? offset : -1;
661 req->extra_size = (offset >= 0) ? size : 0;
662 if (!wine_server_call_err( req ))
663 {
664 switch(offset)
665 {
666 case GCLP_HBRBACKGROUND:
667 case GCLP_HCURSOR:
668 case GCLP_HICON:
669 case GCLP_HICONSM:
670 case GCLP_WNDPROC:
671 case GCLP_MENUNAME:
672 FIXME( "offset %d (%s) not supported on other process window %p\n",
673 offset, SPY_GetClassLongOffsetName(offset), hwnd );
674 SetLastError( ERROR_INVALID_HANDLE );
675 break;
676 case GCL_STYLE:
677 retvalue = reply->old_style;
678 break;
679 case GCL_CBWNDEXTRA:
680 retvalue = reply->old_win_extra;
681 break;
682 case GCL_CBCLSEXTRA:
683 retvalue = reply->old_extra;
684 break;
685 case GCLP_HMODULE:
686 retvalue = (ULONG_PTR)wine_server_get_ptr( reply->old_instance );
687 break;
688 case GCW_ATOM:
689 retvalue = reply->old_atom;
690 break;
691 default:
692 if (offset >= 0)
693 {
694 if (size == sizeof(DWORD))
695 {
696 DWORD retdword;
697 memcpy( &retdword, &reply->old_extra_value, sizeof(DWORD) );
698 retvalue = retdword;
699 }
700 else
701 memcpy( &retvalue, &reply->old_extra_value,
702 sizeof(ULONG_PTR) );
703 }
704 else SetLastError( ERROR_INVALID_INDEX );
705 break;
706 }
707 }
708 }
709 SERVER_END_REQ;
710 return retvalue;
711 }
712
713 if (offset >= 0)
714 {
715 if (offset <= class->cbClsExtra - size)
716 {
717 if (size == sizeof(DWORD))
718 {
719 DWORD retdword;
720 memcpy( &retdword, (char *)(class + 1) + offset, sizeof(DWORD) );
721 retvalue = retdword;
722 }
723 else
724 memcpy( &retvalue, (char *)(class + 1) + offset, sizeof(ULONG_PTR) );
725 }
726 else
727 SetLastError( ERROR_INVALID_INDEX );
728 release_class_ptr( class );
729 return retvalue;
730 }
731
732 switch(offset)
733 {
734 case GCLP_HBRBACKGROUND:
735 retvalue = (ULONG_PTR)class->hbrBackground;
736 break;
737 case GCLP_HCURSOR:
738 retvalue = (ULONG_PTR)class->hCursor;
739 break;
740 case GCLP_HICON:
741 retvalue = (ULONG_PTR)class->hIcon;
742 break;
743 case GCLP_HICONSM:
744 retvalue = (ULONG_PTR)class->hIconSm;
745 break;
746 case GCL_STYLE:
747 retvalue = class->style;
748 break;
749 case GCL_CBWNDEXTRA:
750 retvalue = class->cbWndExtra;
751 break;
752 case GCL_CBCLSEXTRA:
753 retvalue = class->cbClsExtra;
754 break;
755 case GCLP_HMODULE:
756 retvalue = (ULONG_PTR)class->hInstance;
757 break;
758 case GCLP_WNDPROC:
759 retvalue = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
760 break;
761 case GCLP_MENUNAME:
762 retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
763 if (unicode)
764 retvalue = (ULONG_PTR)CLASS_GetMenuNameW( class );
765 else
766 retvalue = (ULONG_PTR)CLASS_GetMenuNameA( class );
767 break;
768 case GCW_ATOM:
769 retvalue = class->atomName;
770 break;
771 default:
772 SetLastError( ERROR_INVALID_INDEX );
773 break;
774 }
775 release_class_ptr( class );
776 return retvalue;
777 }
778
779
780 /***********************************************************************
781 * GetClassLongW (USER32.@)
782 */
783 DWORD WINAPI GetClassLongW( HWND hwnd, INT offset )
784 {
785 return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), TRUE );
786 }
787
788
789
790 /***********************************************************************
791 * GetClassLongA (USER32.@)
792 */
793 DWORD WINAPI GetClassLongA( HWND hwnd, INT offset )
794 {
795 return CLASS_GetClassLong( hwnd, offset, sizeof(DWORD), FALSE );
796 }
797
798
799 /***********************************************************************
800 * SetClassWord (USER32.@)
801 */
802 WORD WINAPI SetClassWord( HWND hwnd, INT offset, WORD newval )
803 {
804 CLASS *class;
805 WORD retval = 0;
806
807 if (offset < 0) return SetClassLongA( hwnd, offset, (DWORD)newval );
808
809 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
810
811 SERVER_START_REQ( set_class_info )
812 {
813 req->window = wine_server_user_handle( hwnd );
814 req->flags = SET_CLASS_EXTRA;
815 req->extra_offset = offset;
816 req->extra_size = sizeof(newval);
817 memcpy( &req->extra_value, &newval, sizeof(newval) );
818 if (!wine_server_call_err( req ))
819 {
820 void *ptr = (char *)(class + 1) + offset;
821 memcpy( &retval, ptr, sizeof(retval) );
822 memcpy( ptr, &newval, sizeof(newval) );
823 }
824 }
825 SERVER_END_REQ;
826 release_class_ptr( class );
827 return retval;
828 }
829
830
831 /***********************************************************************
832 * CLASS_SetClassLong
833 *
834 * Implementation of SetClassLong(Ptr)A/W
835 */
836 static ULONG_PTR CLASS_SetClassLong( HWND hwnd, INT offset, LONG_PTR newval,
837 UINT size, BOOL unicode )
838 {
839 CLASS *class;
840 ULONG_PTR retval = 0;
841
842 if (!(class = get_class_ptr( hwnd, TRUE ))) return 0;
843
844 if (offset >= 0)
845 {
846 if (set_server_info( hwnd, offset, newval, size ))
847 {
848 void *ptr = (char *)(class + 1) + offset;
849 if ( size == sizeof(LONG) )
850 {
851 DWORD retdword;
852 LONG newlong = newval;
853 memcpy( &retdword, ptr, sizeof(DWORD) );
854 memcpy( ptr, &newlong, sizeof(LONG) );
855 retval = retdword;
856 }
857 else
858 {
859 memcpy( &retval, ptr, sizeof(ULONG_PTR) );
860 memcpy( ptr, &newval, sizeof(LONG_PTR) );
861 }
862 }
863 }
864 else switch(offset)
865 {
866 case GCLP_MENUNAME:
867 if ( unicode )
868 CLASS_SetMenuNameW( class, (LPCWSTR)newval );
869 else
870 CLASS_SetMenuNameA( class, (LPCSTR)newval );
871 retval = 0; /* Old value is now meaningless anyway */
872 break;
873 case GCLP_WNDPROC:
874 retval = (ULONG_PTR)WINPROC_GetProc( class->winproc, unicode );
875 class->winproc = WINPROC_AllocProc( (WNDPROC)newval, unicode );
876 break;
877 case GCLP_HBRBACKGROUND:
878 retval = (ULONG_PTR)class->hbrBackground;
879 class->hbrBackground = (HBRUSH)newval;
880 break;
881 case GCLP_HCURSOR:
882 retval = (ULONG_PTR)class->hCursor;
883 class->hCursor = (HCURSOR)newval;
884 break;
885 case GCLP_HICON:
886 retval = (ULONG_PTR)class->hIcon;
887 class->hIcon = (HICON)newval;
888 break;
889 case GCLP_HICONSM:
890 retval = (ULONG_PTR)class->hIconSm;
891 class->hIconSm = (HICON)newval;
892 break;
893 case GCL_STYLE:
894 if (!set_server_info( hwnd, offset, newval, size )) break;
895 retval = class->style;
896 class->style = newval;
897 break;
898 case GCL_CBWNDEXTRA:
899 if (!set_server_info( hwnd, offset, newval, size )) break;
900 retval = class->cbWndExtra;
901 class->cbWndExtra = newval;
902 break;
903 case GCLP_HMODULE:
904 if (!set_server_info( hwnd, offset, newval, size )) break;
905 retval = (ULONG_PTR)class->hInstance;
906 class->hInstance = (HINSTANCE)newval;
907 break;
908 case GCW_ATOM:
909 if (!set_server_info( hwnd, offset, newval, size )) break;
910 retval = class->atomName;
911 class->atomName = newval;
912 GlobalGetAtomNameW( newval, class->name, sizeof(class->name)/sizeof(WCHAR) );
913 break;
914 case GCL_CBCLSEXTRA: /* cannot change this one */
915 SetLastError( ERROR_INVALID_PARAMETER );
916 break;
917 default:
918 SetLastError( ERROR_INVALID_INDEX );
919 break;
920 }
921 release_class_ptr( class );
922 return retval;
923 }
924
925
926 /***********************************************************************
927 * SetClassLongW (USER32.@)
928 */
929 DWORD WINAPI SetClassLongW( HWND hwnd, INT offset, LONG newval )
930 {
931 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG), TRUE );
932 }
933
934
935 /***********************************************************************
936 * SetClassLongA (USER32.@)
937 */
938 DWORD WINAPI SetClassLongA( HWND hwnd, INT offset, LONG newval )
939 {
940 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG), FALSE );
941 }
942
943
944 /***********************************************************************
945 * GetClassNameA (USER32.@)
946 */
947 INT WINAPI GetClassNameA( HWND hwnd, LPSTR buffer, INT count )
948 {
949 WCHAR tmpbuf[MAX_ATOM_LEN + 1];
950 DWORD len;
951
952 if (count <= 0) return 0;
953 if (!GetClassNameW( hwnd, tmpbuf, sizeof(tmpbuf)/sizeof(WCHAR) )) return 0;
954 RtlUnicodeToMultiByteN( buffer, count - 1, &len, tmpbuf, strlenW(tmpbuf) * sizeof(WCHAR) );
955 buffer[len] = 0;
956 return len;
957 }
958
959
960 /***********************************************************************
961 * GetClassNameW (USER32.@)
962 */
963 INT WINAPI GetClassNameW( HWND hwnd, LPWSTR buffer, INT count )
964 {
965 CLASS *class;
966 INT ret;
967
968 TRACE("%p %p %d\n", hwnd, buffer, count);
969
970 if (count <= 0) return 0;
971
972 if (!(class = get_class_ptr( hwnd, FALSE ))) return 0;
973
974 if (class == CLASS_OTHER_PROCESS)
975 {
976 WCHAR tmpbuf[MAX_ATOM_LEN + 1];
977
978 ret = GlobalGetAtomNameW( GetClassLongW( hwnd, GCW_ATOM ), tmpbuf, MAX_ATOM_LEN + 1 );
979 if (ret)
980 {
981 ret = min(count - 1, ret);
982 memcpy(buffer, tmpbuf, ret * sizeof(WCHAR));
983 buffer[ret] = 0;
984 }
985 }
986 else
987 {
988 lstrcpynW( buffer, class->name, count );
989 release_class_ptr( class );
990 ret = strlenW( buffer );
991 }
992 return ret;
993 }
994
995
996 /***********************************************************************
997 * RealGetWindowClassA (USER32.@)
998 */
999 UINT WINAPI RealGetWindowClassA( HWND hwnd, LPSTR buffer, UINT count )
1000 {
1001 return GetClassNameA( hwnd, buffer, count );
1002 }
1003
1004
1005 /***********************************************************************
1006 * RealGetWindowClassW (USER32.@)
1007 */
1008 UINT WINAPI RealGetWindowClassW( HWND hwnd, LPWSTR buffer, UINT count )
1009 {
1010 return GetClassNameW( hwnd, buffer, count );
1011 }
1012
1013
1014 /***********************************************************************
1015 * GetClassInfoA (USER32.@)
1016 */
1017 BOOL WINAPI GetClassInfoA( HINSTANCE hInstance, LPCSTR name, WNDCLASSA *wc )
1018 {
1019 WNDCLASSEXA wcex;
1020 UINT ret = GetClassInfoExA( hInstance, name, &wcex );
1021
1022 if (ret)
1023 {
1024 wc->style = wcex.style;
1025 wc->lpfnWndProc = wcex.lpfnWndProc;
1026 wc->cbClsExtra = wcex.cbClsExtra;
1027 wc->cbWndExtra = wcex.cbWndExtra;
1028 wc->hInstance = wcex.hInstance;
1029 wc->hIcon = wcex.hIcon;
1030 wc->hCursor = wcex.hCursor;
1031 wc->hbrBackground = wcex.hbrBackground;
1032 wc->lpszMenuName = wcex.lpszMenuName;
1033 wc->lpszClassName = wcex.lpszClassName;
1034 }
1035 return ret;
1036 }
1037
1038
1039 /***********************************************************************
1040 * GetClassInfoW (USER32.@)
1041 */
1042 BOOL WINAPI GetClassInfoW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSW *wc )
1043 {
1044 WNDCLASSEXW wcex;
1045 UINT ret = GetClassInfoExW( hInstance, name, &wcex );
1046
1047 if (ret)
1048 {
1049 wc->style = wcex.style;
1050 wc->lpfnWndProc = wcex.lpfnWndProc;
1051 wc->cbClsExtra = wcex.cbClsExtra;
1052 wc->cbWndExtra = wcex.cbWndExtra;
1053 wc->hInstance = wcex.hInstance;
1054 wc->hIcon = wcex.hIcon;
1055 wc->hCursor = wcex.hCursor;
1056 wc->hbrBackground = wcex.hbrBackground;
1057 wc->lpszMenuName = wcex.lpszMenuName;
1058 wc->lpszClassName = wcex.lpszClassName;
1059 }
1060 return ret;
1061 }
1062
1063
1064 /***********************************************************************
1065 * GetClassInfoExA (USER32.@)
1066 */
1067 BOOL WINAPI GetClassInfoExA( HINSTANCE hInstance, LPCSTR name, WNDCLASSEXA *wc )
1068 {
1069 ATOM atom;
1070 CLASS *classPtr;
1071
1072 TRACE("%p %s %p\n", hInstance, debugstr_a(name), wc);
1073
1074 if (!wc)
1075 {
1076 SetLastError( ERROR_NOACCESS );
1077 return FALSE;
1078 }
1079
1080 if (!hInstance) hInstance = user32_module;
1081
1082 if (!IS_INTRESOURCE(name))
1083 {
1084 WCHAR nameW[MAX_ATOM_LEN + 1];
1085 if (!MultiByteToWideChar( CP_ACP, 0, name, -1, nameW, sizeof(nameW)/sizeof(WCHAR) ))
1086 return FALSE;
1087 classPtr = CLASS_FindClass( nameW, hInstance );
1088 }
1089 else classPtr = CLASS_FindClass( (LPCWSTR)name, hInstance );
1090
1091 if (!classPtr)
1092 {
1093 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1094 return FALSE;
1095 }
1096 wc->style = classPtr->style;
1097 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, FALSE );
1098 wc->cbClsExtra = classPtr->cbClsExtra;
1099 wc->cbWndExtra = classPtr->cbWndExtra;
1100 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1101 wc->hIcon = classPtr->hIcon;
1102 wc->hIconSm = classPtr->hIconSm;
1103 wc->hCursor = classPtr->hCursor;
1104 wc->hbrBackground = classPtr->hbrBackground;
1105 wc->lpszMenuName = CLASS_GetMenuNameA( classPtr );
1106 wc->lpszClassName = name;
1107 atom = classPtr->atomName;
1108 release_class_ptr( classPtr );
1109
1110 /* We must return the atom of the class here instead of just TRUE. */
1111 return atom;
1112 }
1113
1114
1115 /***********************************************************************
1116 * GetClassInfoExW (USER32.@)
1117 */
1118 BOOL WINAPI GetClassInfoExW( HINSTANCE hInstance, LPCWSTR name, WNDCLASSEXW *wc )
1119 {
1120 ATOM atom;
1121 CLASS *classPtr;
1122
1123 TRACE("%p %s %p\n", hInstance, debugstr_w(name), wc);
1124
1125 if (!wc)
1126 {
1127 SetLastError( ERROR_NOACCESS );
1128 return FALSE;
1129 }
1130
1131 if (!hInstance) hInstance = user32_module;
1132
1133 if (!(classPtr = CLASS_FindClass( name, hInstance )))
1134 {
1135 SetLastError( ERROR_CLASS_DOES_NOT_EXIST );
1136 return FALSE;
1137 }
1138 wc->style = classPtr->style;
1139 wc->lpfnWndProc = WINPROC_GetProc( classPtr->winproc, TRUE );
1140 wc->cbClsExtra = classPtr->cbClsExtra;
1141 wc->cbWndExtra = classPtr->cbWndExtra;
1142 wc->hInstance = (hInstance == user32_module) ? 0 : hInstance;
1143 wc->hIcon = classPtr->hIcon;
1144 wc->hIconSm = classPtr->hIconSm;
1145 wc->hCursor = classPtr->hCursor;
1146 wc->hbrBackground = classPtr->hbrBackground;
1147 wc->lpszMenuName = CLASS_GetMenuNameW( classPtr );
1148 wc->lpszClassName = name;
1149 atom = classPtr->atomName;
1150 release_class_ptr( classPtr );
1151
1152 /* We must return the atom of the class here instead of just TRUE. */
1153 return atom;
1154 }
1155
1156
1157 #if 0 /* toolhelp is in kernel, so this cannot work */
1158
1159 /***********************************************************************
1160 * ClassFirst (TOOLHELP.69)
1161 */
1162 BOOL16 WINAPI ClassFirst16( CLASSENTRY *pClassEntry )
1163 {
1164 TRACE("%p\n",pClassEntry);
1165 pClassEntry->wNext = 1;
1166 return ClassNext16( pClassEntry );
1167 }
1168
1169
1170 /***********************************************************************
1171 * ClassNext (TOOLHELP.70)
1172 */
1173 BOOL16 WINAPI ClassNext16( CLASSENTRY *pClassEntry )
1174 {
1175 int i;
1176 CLASS *class = firstClass;
1177
1178 TRACE("%p\n",pClassEntry);
1179
1180 if (!pClassEntry->wNext) return FALSE;
1181 for (i = 1; (i < pClassEntry->wNext) && class; i++) class = class->next;
1182 if (!class)
1183 {
1184 pClassEntry->wNext = 0;
1185 return FALSE;
1186 }
1187 pClassEntry->hInst = class->hInstance;
1188 pClassEntry->wNext++;
1189 GlobalGetAtomNameA( class->atomName, pClassEntry->szClassName,
1190 sizeof(pClassEntry->szClassName) );
1191 return TRUE;
1192 }
1193 #endif
1194
1195 /* 64bit versions */
1196
1197 #ifdef GetClassLongPtrA
1198 #undef GetClassLongPtrA
1199 #endif
1200
1201 #ifdef GetClassLongPtrW
1202 #undef GetClassLongPtrW
1203 #endif
1204
1205 #ifdef SetClassLongPtrA
1206 #undef SetClassLongPtrA
1207 #endif
1208
1209 #ifdef SetClassLongPtrW
1210 #undef SetClassLongPtrW
1211 #endif
1212
1213 /***********************************************************************
1214 * GetClassLongPtrA (USER32.@)
1215 */
1216 ULONG_PTR WINAPI GetClassLongPtrA( HWND hwnd, INT offset )
1217 {
1218 return CLASS_GetClassLong( hwnd, offset, sizeof(ULONG_PTR), FALSE );
1219 }
1220
1221 /***********************************************************************
1222 * GetClassLongPtrW (USER32.@)
1223 */
1224 ULONG_PTR WINAPI GetClassLongPtrW( HWND hwnd, INT offset )
1225 {
1226 return CLASS_GetClassLong( hwnd, offset, sizeof(ULONG_PTR), TRUE );
1227 }
1228
1229 /***********************************************************************
1230 * SetClassLongPtrW (USER32.@)
1231 */
1232 ULONG_PTR WINAPI SetClassLongPtrW( HWND hwnd, INT offset, LONG_PTR newval )
1233 {
1234 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG_PTR), TRUE );
1235 }
1236
1237 /***********************************************************************
1238 * SetClassLongPtrA (USER32.@)
1239 */
1240 ULONG_PTR WINAPI SetClassLongPtrA( HWND hwnd, INT offset, LONG_PTR newval )
1241 {
1242 return CLASS_SetClassLong( hwnd, offset, newval, sizeof(LONG_PTR), FALSE );
1243 }
1244
This page was automatically generated by the
LXR engine.
Visit the LXR main site for more
information.