1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
|
/*
* Server-side window class management
*
* Copyright (C) 2002 Mike McCormack
* Copyright (C) 2003 Alexandre Julliard
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include "wine/port.h"
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "ntstatus.h"
#define WIN32_NO_STATUS
#include "wine/list.h"
#include "request.h"
#include "object.h"
#include "process.h"
#include "user.h"
#include "winuser.h"
#include "winternl.h"
struct window_class
{
struct list entry; /* entry in process list */
struct process *process; /* process owning the class */
int count; /* reference count */
int local; /* local class? */
atom_t atom; /* class atom */
void *instance; /* module instance */
unsigned int style; /* class style */
int win_extra; /* number of window extra bytes */
void *client_ptr; /* pointer to class in client address space */
int nb_extra_bytes; /* number of extra bytes */
char extra_bytes[1]; /* extra bytes storage */
};
static struct window_class *create_class( struct process *process, int extra_bytes, int local )
{
struct window_class *class;
if (!(class = mem_alloc( sizeof(*class) + extra_bytes - 1 ))) return NULL;
class->process = (struct process *)grab_object( process );
class->count = 0;
class->local = local;
class->nb_extra_bytes = extra_bytes;
memset( class->extra_bytes, 0, extra_bytes );
/* other fields are initialized by caller */
/* local classes have priority so we put them first in the list */
if (local) list_add_head( &process->classes, &class->entry );
else list_add_tail( &process->classes, &class->entry );
return class;
}
static void destroy_class( struct window_class *class )
{
list_remove( &class->entry );
release_object( class->process );
free( class );
}
void destroy_process_classes( struct process *process )
{
struct list *ptr;
while ((ptr = list_head( &process->classes )))
{
struct window_class *class = LIST_ENTRY( ptr, struct window_class, entry );
destroy_class( class );
}
}
static struct window_class *find_class( struct process *process, atom_t atom, void *instance )
{
struct list *ptr;
LIST_FOR_EACH( ptr, &process->classes )
{
struct window_class *class = LIST_ENTRY( ptr, struct window_class, entry );
if (class->atom != atom) continue;
if (!instance || !class->local || class->instance == instance) return class;
}
return NULL;
}
struct window_class *grab_class( struct process *process, atom_t atom,
void *instance, int *extra_bytes )
{
struct window_class *class = find_class( process, atom, instance );
if (class)
{
class->count++;
*extra_bytes = class->win_extra;
}
else set_error( STATUS_INVALID_HANDLE );
return class;
}
void release_class( struct window_class *class )
{
assert( class->count > 0 );
class->count--;
}
int is_desktop_class( struct window_class *class )
{
return (class->atom == DESKTOP_ATOM && !class->local);
}
atom_t get_class_atom( struct window_class *class )
{
return class->atom;
}
void *get_class_client_ptr( struct window_class *class )
{
return class->client_ptr;
}
/* create a window class */
DECL_HANDLER(create_class)
{
struct window_class *class;
atom_t atom;
if (get_req_data_size())
{
atom = add_global_atom( NULL, get_req_data(), get_req_data_size() / sizeof(WCHAR) );
if (!atom) return;
}
else
{
atom = req->atom;
if (!grab_global_atom( NULL, atom )) return;
}
class = find_class( current->process, atom, req->instance );
if (class && !class->local == !req->local)
{
set_win32_error( ERROR_CLASS_ALREADY_EXISTS );
release_global_atom( NULL, atom );
return;
}
if (req->extra < 0 || req->extra > 4096 || req->win_extra < 0 || req->win_extra > 4096)
{
/* don't allow stupid values here */
set_error( STATUS_INVALID_PARAMETER );
release_global_atom( NULL, atom );
return;
}
if (!(class = create_class( current->process, req->extra, req->local )))
{
release_global_atom( NULL, atom );
return;
}
class->atom = atom;
class->instance = req->instance;
class->style = req->style;
class->win_extra = req->win_extra;
class->client_ptr = req->client_ptr;
reply->atom = atom;
}
/* destroy a window class */
DECL_HANDLER(destroy_class)
{
struct window_class *class;
atom_t atom = req->atom;
if (get_req_data_size())
atom = find_global_atom( NULL, get_req_data(), get_req_data_size() / sizeof(WCHAR) );
if (!(class = find_class( current->process, atom, req->instance )))
set_win32_error( ERROR_CLASS_DOES_NOT_EXIST );
else if (class->count)
set_win32_error( ERROR_CLASS_HAS_WINDOWS );
else
{
reply->client_ptr = class->client_ptr;
destroy_class( class );
}
}
/* set some information in a class */
DECL_HANDLER(set_class_info)
{
struct window_class *class = get_window_class( req->window );
if (!class) return;
if (req->flags && class->process != current->process)
{
set_error( STATUS_ACCESS_DENIED );
return;
}
if (req->extra_size > sizeof(req->extra_value) ||
req->extra_offset < -1 ||
req->extra_offset > class->nb_extra_bytes - (int)req->extra_size)
{
set_win32_error( ERROR_INVALID_INDEX );
return;
}
if ((req->flags & SET_CLASS_WINEXTRA) && (req->win_extra < 0 || req->win_extra > 4096))
{
set_error( STATUS_INVALID_PARAMETER );
return;
}
if (req->extra_offset != -1)
{
memcpy( &reply->old_extra_value, class->extra_bytes + req->extra_offset, req->extra_size );
}
else if (req->flags & SET_CLASS_EXTRA)
{
set_win32_error( ERROR_INVALID_INDEX );
return;
}
reply->old_atom = class->atom;
reply->old_style = class->style;
reply->old_extra = class->nb_extra_bytes;
reply->old_win_extra = class->win_extra;
reply->old_instance = class->instance;
if (req->flags & SET_CLASS_ATOM)
{
if (!grab_global_atom( NULL, req->atom )) return;
release_global_atom( NULL, class->atom );
class->atom = req->atom;
}
if (req->flags & SET_CLASS_STYLE) class->style = req->style;
if (req->flags & SET_CLASS_WINEXTRA) class->win_extra = req->win_extra;
if (req->flags & SET_CLASS_INSTANCE) class->instance = req->instance;
if (req->flags & SET_CLASS_EXTRA) memcpy( class->extra_bytes + req->extra_offset,
&req->extra_value, req->extra_size );
}
|