2 * Server-side window class management
4 * Copyright (C) 2002 Mike McCormack
5 * Copyright (C) 2003 Alexandre Julliard
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
23 #include "wine/port.h"
31 #define WIN32_NO_STATUS
33 #include "wine/list.h"
44 struct list entry
; /* entry in process list */
45 struct process
*process
; /* process owning the class */
46 int count
; /* reference count */
47 int local
; /* local class? */
48 atom_t atom
; /* class atom */
49 void *instance
; /* module instance */
50 unsigned int style
; /* class style */
51 int win_extra
; /* number of window extra bytes */
52 void *client_ptr
; /* pointer to class in client address space */
53 int nb_extra_bytes
; /* number of extra bytes */
54 char extra_bytes
[1]; /* extra bytes storage */
57 static struct window_class
*create_class( struct process
*process
, int extra_bytes
, int local
)
59 struct window_class
*class;
61 if (!(class = mem_alloc( sizeof(*class) + extra_bytes
- 1 ))) return NULL
;
63 class->process
= (struct process
*)grab_object( process
);
66 class->nb_extra_bytes
= extra_bytes
;
67 memset( class->extra_bytes
, 0, extra_bytes
);
68 /* other fields are initialized by caller */
70 /* local classes have priority so we put them first in the list */
71 if (local
) list_add_head( &process
->classes
, &class->entry
);
72 else list_add_tail( &process
->classes
, &class->entry
);
76 static void destroy_class( struct window_class
*class )
78 list_remove( &class->entry
);
79 release_object( class->process
);
83 void destroy_process_classes( struct process
*process
)
87 while ((ptr
= list_head( &process
->classes
)))
89 struct window_class
*class = LIST_ENTRY( ptr
, struct window_class
, entry
);
90 destroy_class( class );
94 static struct window_class
*find_class( struct process
*process
, atom_t atom
, void *instance
)
98 LIST_FOR_EACH( ptr
, &process
->classes
)
100 struct window_class
*class = LIST_ENTRY( ptr
, struct window_class
, entry
);
101 if (class->atom
!= atom
) continue;
102 if (!instance
|| !class->local
|| class->instance
== instance
) return class;
107 struct window_class
*grab_class( struct process
*process
, atom_t atom
,
108 void *instance
, int *extra_bytes
)
110 struct window_class
*class = find_class( process
, atom
, instance
);
114 *extra_bytes
= class->win_extra
;
116 else set_error( STATUS_INVALID_HANDLE
);
120 void release_class( struct window_class
*class )
122 assert( class->count
> 0 );
126 int is_desktop_class( struct window_class
*class )
128 return (class->atom
== DESKTOP_ATOM
&& !class->local
);
131 atom_t
get_class_atom( struct window_class
*class )
136 void *get_class_client_ptr( struct window_class
*class )
138 return class->client_ptr
;
141 /* create a window class */
142 DECL_HANDLER(create_class
)
144 struct window_class
*class;
145 struct winstation
*winstation
;
147 class = find_class( current
->process
, req
->atom
, req
->instance
);
148 if (class && !class->local
== !req
->local
)
150 set_win32_error( ERROR_CLASS_ALREADY_EXISTS
);
153 if (req
->extra
< 0 || req
->extra
> 4096 || req
->win_extra
< 0 || req
->win_extra
> 4096)
155 /* don't allow stupid values here */
156 set_error( STATUS_INVALID_PARAMETER
);
160 if (!(winstation
= get_process_winstation( current
->process
, WINSTA_ACCESSGLOBALATOMS
)))
163 if (!grab_global_atom( winstation
, req
->atom
))
165 release_object( winstation
);
168 if (!(class = create_class( current
->process
, req
->extra
, req
->local
)))
170 release_global_atom( winstation
, req
->atom
);
171 release_object( winstation
);
174 class->atom
= req
->atom
;
175 class->instance
= req
->instance
;
176 class->style
= req
->style
;
177 class->win_extra
= req
->win_extra
;
178 class->client_ptr
= req
->client_ptr
;
179 release_object( winstation
);
182 /* destroy a window class */
183 DECL_HANDLER(destroy_class
)
185 struct window_class
*class = find_class( current
->process
, req
->atom
, req
->instance
);
188 set_win32_error( ERROR_CLASS_DOES_NOT_EXIST
);
189 else if (class->count
)
190 set_win32_error( ERROR_CLASS_HAS_WINDOWS
);
193 reply
->client_ptr
= class->client_ptr
;
194 destroy_class( class );
199 /* set some information in a class */
200 DECL_HANDLER(set_class_info
)
202 struct window_class
*class = get_window_class( req
->window
);
206 if (req
->flags
&& class->process
!= current
->process
)
208 set_error( STATUS_ACCESS_DENIED
);
212 if (req
->extra_size
> sizeof(req
->extra_value
) ||
213 req
->extra_offset
< -1 ||
214 req
->extra_offset
> class->nb_extra_bytes
- (int)req
->extra_size
)
216 set_win32_error( ERROR_INVALID_INDEX
);
219 if ((req
->flags
& SET_CLASS_WINEXTRA
) && (req
->win_extra
< 0 || req
->win_extra
> 4096))
221 set_error( STATUS_INVALID_PARAMETER
);
224 if (req
->extra_offset
!= -1)
226 memcpy( &reply
->old_extra_value
, class->extra_bytes
+ req
->extra_offset
, req
->extra_size
);
228 else if (req
->flags
& SET_CLASS_EXTRA
)
230 set_win32_error( ERROR_INVALID_INDEX
);
234 reply
->old_atom
= class->atom
;
235 reply
->old_style
= class->style
;
236 reply
->old_extra
= class->nb_extra_bytes
;
237 reply
->old_win_extra
= class->win_extra
;
238 reply
->old_instance
= class->instance
;
240 if (req
->flags
& SET_CLASS_ATOM
)
242 struct winstation
*winstation
= get_process_winstation( current
->process
,
243 WINSTA_ACCESSGLOBALATOMS
);
244 if (!grab_global_atom( winstation
, req
->atom
))
246 release_object( winstation
);
249 release_global_atom( winstation
, class->atom
);
250 class->atom
= req
->atom
;
251 release_object( winstation
);
253 if (req
->flags
& SET_CLASS_STYLE
) class->style
= req
->style
;
254 if (req
->flags
& SET_CLASS_WINEXTRA
) class->win_extra
= req
->win_extra
;
255 if (req
->flags
& SET_CLASS_INSTANCE
) class->instance
= req
->instance
;
256 if (req
->flags
& SET_CLASS_EXTRA
) memcpy( class->extra_bytes
+ req
->extra_offset
,
257 &req
->extra_value
, req
->extra_size
);