2003-12-09 21:08:06 -07:00
|
|
|
/*
|
|
|
|
* 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
|
2006-05-18 05:49:52 -07:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-12-09 21:08:06 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2005-11-28 09:32:54 -07:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
|
2003-12-09 21:08:06 -07:00
|
|
|
#include "wine/list.h"
|
|
|
|
|
|
|
|
#include "request.h"
|
|
|
|
#include "object.h"
|
|
|
|
#include "process.h"
|
|
|
|
#include "user.h"
|
2005-07-08 07:23:27 -07:00
|
|
|
#include "winuser.h"
|
2005-11-28 09:32:54 -07:00
|
|
|
#include "winternl.h"
|
2003-12-09 21:08:06 -07:00
|
|
|
|
|
|
|
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 */
|
2018-06-11 00:42:34 -07:00
|
|
|
atom_t base_atom; /* base class atom for versioned class */
|
2008-12-29 08:41:44 -07:00
|
|
|
mod_handle_t instance; /* module instance */
|
2003-12-09 21:08:06 -07:00
|
|
|
unsigned int style; /* class style */
|
|
|
|
int win_extra; /* number of window extra bytes */
|
2008-12-29 09:24:33 -07:00
|
|
|
client_ptr_t client_ptr; /* pointer to class in client address space */
|
2003-12-09 21:08:06 -07:00
|
|
|
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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-12-29 08:41:44 -07:00
|
|
|
static struct window_class *find_class( struct process *process, atom_t atom, mod_handle_t instance )
|
2003-12-09 21:08:06 -07:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2003-12-10 22:34:53 -07:00
|
|
|
struct window_class *grab_class( struct process *process, atom_t atom,
|
2008-12-29 08:41:44 -07:00
|
|
|
mod_handle_t instance, int *extra_bytes )
|
2003-12-09 21:08:06 -07:00
|
|
|
{
|
|
|
|
struct window_class *class = find_class( process, atom, instance );
|
2003-12-10 22:34:53 -07:00
|
|
|
if (class)
|
|
|
|
{
|
|
|
|
class->count++;
|
|
|
|
*extra_bytes = class->win_extra;
|
|
|
|
}
|
2003-12-09 21:08:06 -07:00
|
|
|
else set_error( STATUS_INVALID_HANDLE );
|
|
|
|
return class;
|
|
|
|
}
|
|
|
|
|
|
|
|
void release_class( struct window_class *class )
|
|
|
|
{
|
|
|
|
assert( class->count > 0 );
|
|
|
|
class->count--;
|
|
|
|
}
|
|
|
|
|
2006-03-06 12:37:52 -07:00
|
|
|
int is_desktop_class( struct window_class *class )
|
|
|
|
{
|
|
|
|
return (class->atom == DESKTOP_ATOM && !class->local);
|
|
|
|
}
|
|
|
|
|
2008-06-25 05:43:39 -07:00
|
|
|
int is_hwnd_message_class( struct window_class *class )
|
|
|
|
{
|
|
|
|
static const WCHAR messageW[] = {'M','e','s','s','a','g','e'};
|
|
|
|
static const struct unicode_str name = { messageW, sizeof(messageW) };
|
|
|
|
|
|
|
|
return (!class->local && class->atom == find_global_atom( NULL, &name ));
|
|
|
|
}
|
|
|
|
|
2003-12-09 21:08:06 -07:00
|
|
|
atom_t get_class_atom( struct window_class *class )
|
|
|
|
{
|
|
|
|
return class->atom;
|
|
|
|
}
|
|
|
|
|
2008-12-29 09:24:33 -07:00
|
|
|
client_ptr_t get_class_client_ptr( struct window_class *class )
|
2003-12-10 22:34:53 -07:00
|
|
|
{
|
|
|
|
return class->client_ptr;
|
|
|
|
}
|
|
|
|
|
2003-12-09 21:08:06 -07:00
|
|
|
/* create a window class */
|
|
|
|
DECL_HANDLER(create_class)
|
|
|
|
{
|
2003-12-10 22:34:53 -07:00
|
|
|
struct window_class *class;
|
2016-01-29 00:36:45 -07:00
|
|
|
struct unicode_str name = get_req_unicode_str();
|
2018-06-11 00:42:34 -07:00
|
|
|
atom_t atom, base_atom;
|
2003-12-09 21:08:06 -07:00
|
|
|
|
2008-06-25 05:03:08 -07:00
|
|
|
if (name.len)
|
2007-11-01 05:02:01 -07:00
|
|
|
{
|
2008-06-25 05:03:08 -07:00
|
|
|
atom = add_global_atom( NULL, &name );
|
2007-11-01 05:02:01 -07:00
|
|
|
if (!atom) return;
|
2018-06-11 00:42:34 -07:00
|
|
|
if (req->name_offset && req->name_offset < name.len / sizeof(WCHAR))
|
|
|
|
{
|
|
|
|
name.str += req->name_offset;
|
|
|
|
name.len -= req->name_offset * sizeof(WCHAR);
|
|
|
|
|
|
|
|
base_atom = add_global_atom( NULL, &name );
|
|
|
|
if (!base_atom)
|
|
|
|
{
|
|
|
|
release_global_atom( NULL, atom );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
base_atom = atom;
|
|
|
|
grab_global_atom( NULL, atom );
|
|
|
|
}
|
2007-11-01 05:02:01 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-11 00:42:34 -07:00
|
|
|
base_atom = atom = req->atom;
|
2007-11-01 05:02:01 -07:00
|
|
|
if (!grab_global_atom( NULL, atom )) return;
|
2018-06-11 00:42:34 -07:00
|
|
|
grab_global_atom( NULL, base_atom );
|
2007-11-01 05:02:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
class = find_class( current->process, atom, req->instance );
|
2003-12-09 21:08:06 -07:00
|
|
|
if (class && !class->local == !req->local)
|
|
|
|
{
|
|
|
|
set_win32_error( ERROR_CLASS_ALREADY_EXISTS );
|
2007-11-01 05:02:01 -07:00
|
|
|
release_global_atom( NULL, atom );
|
2018-06-11 00:42:34 -07:00
|
|
|
release_global_atom( NULL, base_atom );
|
2003-12-09 21:08:06 -07:00
|
|
|
return;
|
|
|
|
}
|
2003-12-10 22:34:53 -07:00
|
|
|
if (req->extra < 0 || req->extra > 4096 || req->win_extra < 0 || req->win_extra > 4096)
|
2003-12-09 21:08:06 -07:00
|
|
|
{
|
2003-12-10 22:34:53 -07:00
|
|
|
/* don't allow stupid values here */
|
2003-12-09 21:08:06 -07:00
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
2007-11-01 05:02:01 -07:00
|
|
|
release_global_atom( NULL, atom );
|
2018-06-11 00:42:34 -07:00
|
|
|
release_global_atom( NULL, base_atom );
|
2003-12-09 21:08:06 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(class = create_class( current->process, req->extra, req->local )))
|
|
|
|
{
|
2007-11-01 05:02:01 -07:00
|
|
|
release_global_atom( NULL, atom );
|
2018-06-11 00:42:34 -07:00
|
|
|
release_global_atom( NULL, base_atom );
|
2003-12-09 21:08:06 -07:00
|
|
|
return;
|
|
|
|
}
|
2007-11-01 05:02:01 -07:00
|
|
|
class->atom = atom;
|
2018-06-11 00:42:34 -07:00
|
|
|
class->base_atom = base_atom;
|
2003-12-10 22:34:53 -07:00
|
|
|
class->instance = req->instance;
|
|
|
|
class->style = req->style;
|
|
|
|
class->win_extra = req->win_extra;
|
|
|
|
class->client_ptr = req->client_ptr;
|
2007-11-01 05:02:01 -07:00
|
|
|
reply->atom = atom;
|
2003-12-09 21:08:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* destroy a window class */
|
|
|
|
DECL_HANDLER(destroy_class)
|
|
|
|
{
|
2007-11-01 07:28:30 -07:00
|
|
|
struct window_class *class;
|
2016-01-29 00:36:45 -07:00
|
|
|
struct unicode_str name = get_req_unicode_str();
|
2007-11-01 07:28:30 -07:00
|
|
|
atom_t atom = req->atom;
|
|
|
|
|
2008-06-25 05:03:08 -07:00
|
|
|
if (name.len) atom = find_global_atom( NULL, &name );
|
2003-12-09 21:08:06 -07:00
|
|
|
|
2007-11-01 07:28:30 -07:00
|
|
|
if (!(class = find_class( current->process, atom, req->instance )))
|
2003-12-10 22:34:53 -07:00
|
|
|
set_win32_error( ERROR_CLASS_DOES_NOT_EXIST );
|
2003-12-09 21:08:06 -07:00
|
|
|
else if (class->count)
|
|
|
|
set_win32_error( ERROR_CLASS_HAS_WINDOWS );
|
|
|
|
else
|
2003-12-10 22:34:53 -07:00
|
|
|
{
|
|
|
|
reply->client_ptr = class->client_ptr;
|
2006-03-06 12:37:52 -07:00
|
|
|
destroy_class( class );
|
2003-12-10 22:34:53 -07:00
|
|
|
}
|
2003-12-09 21:08:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* set some information in a class */
|
|
|
|
DECL_HANDLER(set_class_info)
|
|
|
|
{
|
|
|
|
struct window_class *class = get_window_class( req->window );
|
|
|
|
|
|
|
|
if (!class) return;
|
|
|
|
|
2003-12-10 22:34:53 -07:00
|
|
|
if (req->flags && class->process != current->process)
|
|
|
|
{
|
|
|
|
set_error( STATUS_ACCESS_DENIED );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-12-09 21:08:06 -07:00
|
|
|
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;
|
|
|
|
}
|
2003-12-10 22:34:53 -07:00
|
|
|
if ((req->flags & SET_CLASS_WINEXTRA) && (req->win_extra < 0 || req->win_extra > 4096))
|
|
|
|
{
|
|
|
|
set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
return;
|
|
|
|
}
|
2003-12-09 21:08:06 -07:00
|
|
|
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;
|
2018-06-13 03:47:41 -07:00
|
|
|
reply->base_atom = class->base_atom;
|
2003-12-09 21:08:06 -07:00
|
|
|
|
|
|
|
if (req->flags & SET_CLASS_ATOM)
|
|
|
|
{
|
2006-03-22 14:13:40 -07:00
|
|
|
if (!grab_global_atom( NULL, req->atom )) return;
|
|
|
|
release_global_atom( NULL, class->atom );
|
2003-12-09 21:08:06 -07:00
|
|
|
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 );
|
|
|
|
}
|