2003-06-24 01:02:02 +02:00
|
|
|
/*
|
|
|
|
* Server-side clipboard management
|
|
|
|
*
|
2016-09-26 04:48:32 +02:00
|
|
|
* Copyright 2002 Ulrich Czekalla
|
|
|
|
* Copyright 2016 Alexandre Julliard
|
2003-06-24 01:02:02 +02:00
|
|
|
*
|
|
|
|
* 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 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-06-24 01:02:02 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2003-06-24 01:02:02 +02:00
|
|
|
#include "request.h"
|
|
|
|
#include "object.h"
|
2015-06-03 09:02:11 +02:00
|
|
|
#include "file.h"
|
2009-12-01 15:10:23 +01:00
|
|
|
#include "process.h"
|
2003-06-24 01:02:02 +02:00
|
|
|
#include "user.h"
|
2005-06-29 22:13:36 +02:00
|
|
|
#include "winuser.h"
|
2005-11-28 17:32:54 +01:00
|
|
|
#include "winternl.h"
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2016-09-26 04:48:32 +02:00
|
|
|
struct clip_format
|
|
|
|
{
|
|
|
|
struct list entry; /* entry in format list */
|
|
|
|
unsigned int id; /* format id */
|
2016-09-26 08:00:22 +02:00
|
|
|
unsigned int from; /* for synthesized data, format to generate it from */
|
2016-09-26 08:09:27 +02:00
|
|
|
unsigned int seqno; /* sequence number when the data was set */
|
2016-09-26 04:48:32 +02:00
|
|
|
data_size_t size; /* size of the data block */
|
|
|
|
void *data; /* data contents, or NULL for delay-rendered */
|
|
|
|
};
|
|
|
|
|
2005-06-29 22:13:36 +02:00
|
|
|
struct clipboard
|
|
|
|
{
|
|
|
|
struct object obj; /* object header */
|
|
|
|
struct thread *open_thread; /* thread id that has clipboard open */
|
|
|
|
user_handle_t open_win; /* window that has clipboard open */
|
2016-11-02 17:09:15 +01:00
|
|
|
user_handle_t owner; /* window that owns the clipboard */
|
2005-06-29 22:13:36 +02:00
|
|
|
user_handle_t viewer; /* first window in clipboard viewer list */
|
2016-09-26 08:00:22 +02:00
|
|
|
unsigned int lcid; /* locale id to use for synthesizing text formats */
|
2005-06-29 22:13:36 +02:00
|
|
|
unsigned int seqno; /* clipboard change sequence number */
|
2016-08-30 09:33:04 +02:00
|
|
|
unsigned int open_seqno; /* sequence number at open time */
|
2017-05-24 13:03:39 +02:00
|
|
|
unsigned int rendering; /* format rendering recursion counter */
|
2016-09-26 04:48:32 +02:00
|
|
|
struct list formats; /* list of data formats */
|
|
|
|
unsigned int format_count; /* count of data formats */
|
2016-09-26 08:00:22 +02:00
|
|
|
unsigned int format_map; /* existence bitmap for formats < CF_MAX */
|
2016-08-29 13:55:52 +02:00
|
|
|
unsigned int listen_size; /* size of listeners array */
|
|
|
|
unsigned int listen_count; /* count of listeners */
|
|
|
|
user_handle_t *listeners; /* array of listener windows */
|
2005-06-29 22:13:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void clipboard_dump( struct object *obj, int verbose );
|
2016-08-29 13:55:52 +02:00
|
|
|
static void clipboard_destroy( struct object *obj );
|
2005-06-29 22:13:36 +02:00
|
|
|
|
|
|
|
static const struct object_ops clipboard_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct clipboard), /* size */
|
2021-02-04 13:44:18 +01:00
|
|
|
&no_type, /* type */
|
2005-06-29 22:13:36 +02:00
|
|
|
clipboard_dump, /* dump */
|
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
NULL, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
|
|
|
no_get_fd, /* get_fd */
|
2021-02-05 12:10:44 +01:00
|
|
|
default_map_access, /* map_access */
|
2007-10-03 14:10:37 +02:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2020-09-22 16:52:31 +02:00
|
|
|
no_get_full_name, /* get_full_name */
|
2005-11-22 15:55:42 +01:00
|
|
|
no_lookup_name, /* lookup_name */
|
2016-02-04 13:07:19 +01:00
|
|
|
no_link_name, /* link_name */
|
|
|
|
NULL, /* unlink_name */
|
2007-03-22 11:44:29 +01:00
|
|
|
no_open_file, /* open_file */
|
2019-03-25 14:37:09 +01:00
|
|
|
no_kernel_obj_list, /* get_kernel_obj_list */
|
2005-06-29 22:13:36 +02:00
|
|
|
no_close_handle, /* close_handle */
|
2016-08-29 13:55:52 +02:00
|
|
|
clipboard_destroy /* destroy */
|
2005-06-29 22:13:36 +02:00
|
|
|
};
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
|
2016-09-26 08:00:22 +02:00
|
|
|
#define HAS_FORMAT(map,id) ((map) & (1 << (id))) /* only for formats < CF_MAX */
|
|
|
|
|
2016-09-26 04:48:32 +02:00
|
|
|
/* find a data format in the clipboard */
|
|
|
|
static struct clip_format *get_format( struct clipboard *clipboard, unsigned int id )
|
|
|
|
{
|
|
|
|
struct clip_format *format;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY( format, &clipboard->formats, struct clip_format, entry )
|
|
|
|
if (format->id == id) return format;
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* add a data format to the clipboard */
|
|
|
|
static struct clip_format *add_format( struct clipboard *clipboard, unsigned int id )
|
|
|
|
{
|
|
|
|
struct clip_format *format;
|
|
|
|
|
|
|
|
if (!(format = mem_alloc( sizeof(*format )))) return NULL;
|
|
|
|
format->id = id;
|
2016-09-26 08:00:22 +02:00
|
|
|
format->from = 0;
|
2016-09-26 04:48:32 +02:00
|
|
|
format->size = 0;
|
|
|
|
format->data = NULL;
|
|
|
|
list_add_tail( &clipboard->formats, &format->entry );
|
|
|
|
clipboard->format_count++;
|
2016-09-26 08:00:22 +02:00
|
|
|
if (id < CF_MAX) clipboard->format_map |= 1 << id;
|
2016-09-26 04:48:32 +02:00
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* free all clipboard formats */
|
|
|
|
static void free_clipboard_formats( struct clipboard *clipboard )
|
|
|
|
{
|
|
|
|
struct clip_format *format, *next;
|
|
|
|
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE( format, next, &clipboard->formats, struct clip_format, entry )
|
|
|
|
{
|
|
|
|
list_remove( &format->entry );
|
|
|
|
free( format->data );
|
|
|
|
free( format );
|
|
|
|
}
|
|
|
|
clipboard->format_count = 0;
|
2016-09-26 08:00:22 +02:00
|
|
|
clipboard->format_map = 0;
|
2016-09-26 04:48:32 +02:00
|
|
|
}
|
|
|
|
|
2005-06-29 22:13:36 +02:00
|
|
|
/* dump a clipboard object */
|
|
|
|
static void clipboard_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard = (struct clipboard *)obj;
|
|
|
|
|
2016-11-02 17:09:15 +01:00
|
|
|
fprintf( stderr, "Clipboard open_thread=%p open_win=%08x owner=%08x viewer=%08x seq=%u\n",
|
|
|
|
clipboard->open_thread, clipboard->open_win,
|
|
|
|
clipboard->owner, clipboard->viewer, clipboard->seqno );
|
2005-06-29 22:13:36 +02:00
|
|
|
}
|
|
|
|
|
2016-08-29 13:55:52 +02:00
|
|
|
static void clipboard_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard = (struct clipboard *)obj;
|
|
|
|
|
|
|
|
free( clipboard->listeners );
|
2016-09-26 04:48:32 +02:00
|
|
|
free_clipboard_formats( clipboard );
|
2016-08-29 13:55:52 +02:00
|
|
|
}
|
|
|
|
|
2005-06-29 22:13:36 +02:00
|
|
|
/* retrieve the clipboard info for the current process, allocating it if needed */
|
|
|
|
static struct clipboard *get_process_clipboard(void)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2005-06-29 22:13:36 +02:00
|
|
|
struct clipboard *clipboard;
|
|
|
|
struct winstation *winstation = get_process_winstation( current->process, WINSTA_ACCESSCLIPBOARD );
|
|
|
|
|
|
|
|
if (!winstation) return NULL;
|
|
|
|
|
2005-07-11 12:55:53 +02:00
|
|
|
if (!(clipboard = winstation->clipboard))
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2005-06-29 22:13:36 +02:00
|
|
|
if ((clipboard = alloc_object( &clipboard_ops )))
|
|
|
|
{
|
|
|
|
clipboard->open_thread = NULL;
|
|
|
|
clipboard->open_win = 0;
|
2016-11-02 17:09:15 +01:00
|
|
|
clipboard->owner = 0;
|
2005-06-29 22:13:36 +02:00
|
|
|
clipboard->viewer = 0;
|
|
|
|
clipboard->seqno = 0;
|
2016-09-26 04:48:32 +02:00
|
|
|
clipboard->format_count = 0;
|
2016-09-26 08:00:22 +02:00
|
|
|
clipboard->format_map = 0;
|
2016-08-29 13:55:52 +02:00
|
|
|
clipboard->listen_size = 0;
|
|
|
|
clipboard->listen_count = 0;
|
|
|
|
clipboard->listeners = NULL;
|
2016-09-26 04:48:32 +02:00
|
|
|
list_init( &clipboard->formats );
|
2005-07-11 12:55:53 +02:00
|
|
|
winstation->clipboard = clipboard;
|
2005-06-29 22:13:36 +02:00
|
|
|
}
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
2005-06-29 22:13:36 +02:00
|
|
|
release_object( winstation );
|
|
|
|
return clipboard;
|
|
|
|
}
|
|
|
|
|
2016-09-26 08:00:22 +02:00
|
|
|
/* add synthesized formats upon clipboard close */
|
|
|
|
static int synthesize_formats( struct clipboard *clipboard )
|
|
|
|
{
|
|
|
|
static const unsigned int formats[][3] =
|
|
|
|
{
|
|
|
|
{ CF_TEXT, CF_OEMTEXT, CF_UNICODETEXT },
|
|
|
|
{ CF_OEMTEXT, CF_UNICODETEXT, CF_TEXT },
|
|
|
|
{ CF_UNICODETEXT, CF_TEXT, CF_OEMTEXT },
|
|
|
|
{ CF_METAFILEPICT, CF_ENHMETAFILE },
|
|
|
|
{ CF_ENHMETAFILE, CF_METAFILEPICT },
|
|
|
|
{ CF_BITMAP, CF_DIB, CF_DIBV5 },
|
|
|
|
{ CF_DIB, CF_BITMAP, CF_DIBV5 },
|
|
|
|
{ CF_DIBV5, CF_BITMAP, CF_DIB }
|
|
|
|
};
|
|
|
|
unsigned int i, from, total = 0, map = clipboard->format_map;
|
|
|
|
struct clip_format *format;
|
|
|
|
|
|
|
|
if (!HAS_FORMAT( map, CF_LOCALE ) &&
|
|
|
|
(HAS_FORMAT( map, CF_TEXT ) || HAS_FORMAT( map, CF_OEMTEXT ) || HAS_FORMAT( map, CF_UNICODETEXT )))
|
|
|
|
{
|
|
|
|
void *data = memdup( &clipboard->lcid, sizeof(clipboard->lcid) );
|
2016-09-30 03:41:38 +02:00
|
|
|
if (data && (format = add_format( clipboard, CF_LOCALE )))
|
2016-09-26 08:00:22 +02:00
|
|
|
{
|
2016-09-26 08:09:27 +02:00
|
|
|
format->seqno = clipboard->seqno++;
|
2016-09-26 08:00:22 +02:00
|
|
|
format->data = data;
|
|
|
|
format->size = sizeof(clipboard->lcid);
|
|
|
|
}
|
|
|
|
else free( data );
|
|
|
|
}
|
|
|
|
|
2018-10-22 22:39:01 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE( formats ); i++)
|
2016-09-26 08:00:22 +02:00
|
|
|
{
|
|
|
|
if (HAS_FORMAT( map, formats[i][0] )) continue;
|
|
|
|
if (HAS_FORMAT( map, formats[i][1] )) from = formats[i][1];
|
|
|
|
else if (HAS_FORMAT( map, formats[i][2] )) from = formats[i][2];
|
|
|
|
else continue;
|
|
|
|
if (!(format = add_format( clipboard, formats[i][0] ))) continue;
|
|
|
|
format->from = from;
|
2016-09-26 08:09:27 +02:00
|
|
|
format->seqno = clipboard->seqno;
|
2016-09-26 08:00:22 +02:00
|
|
|
total++;
|
|
|
|
}
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
2016-08-29 13:55:52 +02:00
|
|
|
/* add a clipboard listener */
|
|
|
|
static void add_listener( struct clipboard *clipboard, user_handle_t window )
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < clipboard->listen_count; i++)
|
|
|
|
{
|
|
|
|
if (clipboard->listeners[i] != window) continue;
|
|
|
|
set_error( STATUS_INVALID_PARAMETER ); /* already set */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (clipboard->listen_size == clipboard->listen_count)
|
|
|
|
{
|
|
|
|
unsigned int new_size = max( 8, clipboard->listen_size * 2 );
|
|
|
|
user_handle_t *new = realloc( clipboard->listeners, new_size * sizeof(*new) );
|
|
|
|
if (!new)
|
|
|
|
{
|
|
|
|
set_error( STATUS_NO_MEMORY );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
clipboard->listeners = new;
|
|
|
|
clipboard->listen_size = new_size;
|
|
|
|
}
|
|
|
|
clipboard->listeners[clipboard->listen_count++] = window;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* remove a clipboard listener */
|
|
|
|
static int remove_listener( struct clipboard *clipboard, user_handle_t window )
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < clipboard->listen_count; i++)
|
|
|
|
{
|
|
|
|
if (clipboard->listeners[i] != window) continue;
|
|
|
|
memmove( clipboard->listeners + i, clipboard->listeners + i + 1,
|
|
|
|
(clipboard->listen_count - i - 1) * sizeof(*clipboard->listeners) );
|
|
|
|
clipboard->listen_count--;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-26 04:48:32 +02:00
|
|
|
/* notify all listeners, and return the viewer window that should be notified if any */
|
|
|
|
static user_handle_t notify_listeners( struct clipboard *clipboard )
|
2016-08-30 09:33:04 +02:00
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
for (i = 0; i < clipboard->listen_count; i++)
|
|
|
|
post_message( clipboard->listeners[i], WM_CLIPBOARDUPDATE, 0, 0 );
|
|
|
|
return clipboard->viewer;
|
|
|
|
}
|
|
|
|
|
2016-09-26 04:48:32 +02:00
|
|
|
/* close the clipboard, and return the viewer window that should be notified if any */
|
|
|
|
static user_handle_t close_clipboard( struct clipboard *clipboard )
|
|
|
|
{
|
|
|
|
clipboard->open_win = 0;
|
|
|
|
clipboard->open_thread = NULL;
|
|
|
|
if (clipboard->seqno == clipboard->open_seqno) return 0; /* unchanged */
|
2016-09-26 08:00:22 +02:00
|
|
|
if (synthesize_formats( clipboard )) clipboard->seqno++;
|
2016-09-26 04:48:32 +02:00
|
|
|
return notify_listeners( clipboard );
|
|
|
|
}
|
|
|
|
|
2016-09-01 13:06:09 +02:00
|
|
|
/* release the clipboard owner, and return the viewer window that should be notified if any */
|
|
|
|
static user_handle_t release_clipboard( struct clipboard *clipboard )
|
|
|
|
{
|
2016-09-26 04:48:32 +02:00
|
|
|
struct clip_format *format, *next;
|
|
|
|
int changed = 0;
|
|
|
|
|
2016-11-02 17:09:15 +01:00
|
|
|
clipboard->owner = 0;
|
2016-09-26 04:48:32 +02:00
|
|
|
|
|
|
|
/* free the delayed-rendered formats, since we no longer have an owner to render them */
|
|
|
|
LIST_FOR_EACH_ENTRY_SAFE( format, next, &clipboard->formats, struct clip_format, entry )
|
|
|
|
{
|
2016-09-26 08:00:22 +02:00
|
|
|
if (format->data || format->from) continue;
|
2016-09-26 04:48:32 +02:00
|
|
|
list_remove( &format->entry );
|
2016-09-26 08:00:22 +02:00
|
|
|
if (format->id < CF_MAX) clipboard->format_map &= ~(1 << format->id);
|
2016-09-26 04:48:32 +02:00
|
|
|
clipboard->format_count--;
|
|
|
|
free( format );
|
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!changed) return 0;
|
|
|
|
clipboard->seqno++;
|
|
|
|
return notify_listeners( clipboard );
|
2016-09-01 13:06:09 +02:00
|
|
|
}
|
|
|
|
|
2016-08-23 13:58:44 +02:00
|
|
|
/* cleanup clipboard information upon window destruction */
|
|
|
|
void cleanup_clipboard_window( struct desktop *desktop, user_handle_t window )
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard = desktop->winstation->clipboard;
|
|
|
|
|
|
|
|
if (!clipboard) return;
|
|
|
|
|
2016-08-30 09:33:04 +02:00
|
|
|
remove_listener( clipboard, window );
|
|
|
|
if (clipboard->viewer == window) clipboard->viewer = 0;
|
2016-11-02 17:09:15 +01:00
|
|
|
if (clipboard->owner == window) release_clipboard( clipboard );
|
2016-08-30 09:33:04 +02:00
|
|
|
if (clipboard->open_win == window)
|
|
|
|
{
|
|
|
|
user_handle_t viewer = close_clipboard( clipboard );
|
2016-11-02 17:09:15 +01:00
|
|
|
if (viewer) send_notify_message( viewer, WM_DRAWCLIPBOARD, clipboard->owner, 0 );
|
2016-08-30 09:33:04 +02:00
|
|
|
}
|
2016-08-23 13:58:44 +02:00
|
|
|
}
|
2005-06-29 22:13:36 +02:00
|
|
|
|
|
|
|
/* Called when thread terminates to allow release of clipboard */
|
|
|
|
void cleanup_clipboard_thread(struct thread *thread)
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard;
|
2009-12-01 15:10:23 +01:00
|
|
|
struct winstation *winstation;
|
2005-06-29 22:13:36 +02:00
|
|
|
|
2009-12-01 15:10:23 +01:00
|
|
|
if (!thread->process->winstation) return;
|
|
|
|
if (!(winstation = get_process_winstation( thread->process, WINSTA_ACCESSCLIPBOARD ))) return;
|
2005-06-29 22:13:36 +02:00
|
|
|
|
2005-07-11 12:55:53 +02:00
|
|
|
if ((clipboard = winstation->clipboard))
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2016-08-30 09:33:04 +02:00
|
|
|
if (thread == clipboard->open_thread)
|
|
|
|
{
|
|
|
|
user_handle_t viewer = close_clipboard( clipboard );
|
2016-11-02 17:09:15 +01:00
|
|
|
if (viewer) send_notify_message( viewer, WM_DRAWCLIPBOARD, clipboard->owner, 0 );
|
2016-08-30 09:33:04 +02:00
|
|
|
}
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
2005-06-29 22:13:36 +02:00
|
|
|
release_object( winstation );
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
2016-08-22 08:31:21 +02:00
|
|
|
/* open the clipboard */
|
|
|
|
DECL_HANDLER(open_clipboard)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2005-06-29 22:13:36 +02:00
|
|
|
struct clipboard *clipboard = get_process_clipboard();
|
2016-08-30 11:08:36 +02:00
|
|
|
user_handle_t win = 0;
|
2005-06-29 22:13:36 +02:00
|
|
|
|
|
|
|
if (!clipboard) return;
|
2016-08-30 11:08:36 +02:00
|
|
|
if (req->window && !(win = get_valid_window_handle( req->window ))) return;
|
2005-06-29 22:13:36 +02:00
|
|
|
|
2016-08-22 08:31:21 +02:00
|
|
|
if (clipboard->open_thread && clipboard->open_win != win)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2016-08-29 13:33:22 +02:00
|
|
|
set_error( STATUS_INVALID_LOCK_SEQUENCE );
|
2016-08-22 08:31:21 +02:00
|
|
|
return;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
2016-08-30 09:33:04 +02:00
|
|
|
|
|
|
|
if (!clipboard->open_thread) clipboard->open_seqno = clipboard->seqno; /* first open */
|
2017-05-24 13:03:39 +02:00
|
|
|
if (clipboard->open_thread != current) clipboard->rendering = 0;
|
2016-08-22 08:31:21 +02:00
|
|
|
clipboard->open_win = win;
|
|
|
|
clipboard->open_thread = current;
|
|
|
|
|
2016-11-02 17:09:15 +01:00
|
|
|
reply->owner = clipboard->owner;
|
2016-08-22 08:31:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* close the clipboard */
|
|
|
|
DECL_HANDLER(close_clipboard)
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard = get_process_clipboard();
|
|
|
|
|
|
|
|
if (!clipboard) return;
|
|
|
|
|
|
|
|
if (clipboard->open_thread != current)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2016-08-22 08:31:21 +02:00
|
|
|
set_win32_error( ERROR_CLIPBOARD_NOT_OPEN );
|
|
|
|
return;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
2016-08-30 09:33:04 +02:00
|
|
|
reply->viewer = close_clipboard( clipboard );
|
2016-11-02 17:09:15 +01:00
|
|
|
reply->owner = clipboard->owner;
|
2016-08-22 08:31:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-26 04:48:32 +02:00
|
|
|
/* add a data format to the clipboard */
|
|
|
|
DECL_HANDLER(set_clipboard_data)
|
|
|
|
{
|
|
|
|
struct clip_format *format;
|
|
|
|
struct clipboard *clipboard = get_process_clipboard();
|
|
|
|
void *data = NULL;
|
|
|
|
|
|
|
|
if (!clipboard) return;
|
|
|
|
|
|
|
|
if (!req->format || !clipboard->open_thread)
|
|
|
|
{
|
|
|
|
set_win32_error( ERROR_CLIPBOARD_NOT_OPEN );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (get_req_data_size() && !(data = memdup( get_req_data(), get_req_data_size() ))) return;
|
|
|
|
|
|
|
|
if (!(format = get_format( clipboard, req->format )))
|
|
|
|
{
|
|
|
|
if (!(format = add_format( clipboard, req->format )))
|
|
|
|
{
|
|
|
|
free( data );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-27 17:05:05 +02:00
|
|
|
free( format->data );
|
2016-09-26 08:00:22 +02:00
|
|
|
format->from = 0;
|
2017-05-24 13:03:39 +02:00
|
|
|
format->seqno = clipboard->seqno;
|
2016-09-26 04:48:32 +02:00
|
|
|
format->size = get_req_data_size();
|
|
|
|
format->data = data;
|
2017-05-24 13:03:39 +02:00
|
|
|
if (!clipboard->rendering) clipboard->seqno++;
|
2016-09-26 08:00:22 +02:00
|
|
|
|
|
|
|
if (req->format == CF_TEXT || req->format == CF_OEMTEXT || req->format == CF_UNICODETEXT)
|
|
|
|
clipboard->lcid = req->lcid;
|
2016-09-26 08:09:27 +02:00
|
|
|
|
|
|
|
reply->seqno = format->seqno;
|
2016-09-26 04:48:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-26 07:19:28 +02:00
|
|
|
/* fetch a data format from the clipboard */
|
|
|
|
DECL_HANDLER(get_clipboard_data)
|
|
|
|
{
|
|
|
|
struct clip_format *format;
|
|
|
|
struct clipboard *clipboard = get_process_clipboard();
|
|
|
|
|
|
|
|
if (!clipboard) return;
|
|
|
|
|
|
|
|
if (clipboard->open_thread != current)
|
|
|
|
{
|
|
|
|
set_win32_error( ERROR_CLIPBOARD_NOT_OPEN );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!(format = get_format( clipboard, req->format )))
|
|
|
|
{
|
|
|
|
set_error( STATUS_OBJECT_NAME_NOT_FOUND );
|
2017-05-24 13:03:39 +02:00
|
|
|
goto done;
|
2016-09-26 07:19:28 +02:00
|
|
|
}
|
2016-09-26 08:00:22 +02:00
|
|
|
reply->from = format->from;
|
2016-09-26 07:19:28 +02:00
|
|
|
reply->total = format->size;
|
2016-09-26 08:09:27 +02:00
|
|
|
reply->seqno = format->seqno;
|
2017-05-24 13:03:39 +02:00
|
|
|
reply->owner = clipboard->owner;
|
|
|
|
|
|
|
|
if (!format->data && req->render) /* try rendering it client-side */
|
|
|
|
{
|
|
|
|
if (format->from || clipboard->owner) clipboard->rendering++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (req->cached && req->seqno == format->seqno) goto done; /* client-side cache still valid */
|
|
|
|
|
|
|
|
if (format->size > get_reply_max_size())
|
|
|
|
{
|
|
|
|
set_error( STATUS_BUFFER_OVERFLOW );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
set_reply_data( format->data, format->size );
|
|
|
|
|
|
|
|
done:
|
|
|
|
if (!req->render) clipboard->rendering--;
|
2016-09-26 07:19:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-26 06:55:09 +02:00
|
|
|
/* retrieve a list of available formats */
|
|
|
|
DECL_HANDLER(get_clipboard_formats)
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard = get_process_clipboard();
|
|
|
|
|
|
|
|
if (!clipboard) return;
|
|
|
|
|
|
|
|
if (!req->format)
|
|
|
|
{
|
|
|
|
struct clip_format *format;
|
|
|
|
unsigned int i = 0, *ptr;
|
|
|
|
data_size_t size = clipboard->format_count * sizeof(unsigned int);
|
|
|
|
|
|
|
|
reply->count = clipboard->format_count;
|
|
|
|
if (size <= get_reply_max_size())
|
|
|
|
{
|
|
|
|
if ((ptr = mem_alloc( size )))
|
|
|
|
{
|
|
|
|
LIST_FOR_EACH_ENTRY( format, &clipboard->formats, struct clip_format, entry )
|
|
|
|
ptr[i++] = format->id;
|
|
|
|
assert( i == clipboard->format_count );
|
|
|
|
set_reply_data_ptr( ptr, size );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else set_error( STATUS_BUFFER_TOO_SMALL );
|
|
|
|
}
|
|
|
|
else reply->count = (get_format( clipboard, req->format ) != NULL); /* query a single format */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* retrieve the next available format */
|
|
|
|
DECL_HANDLER(enum_clipboard_formats)
|
|
|
|
{
|
|
|
|
struct list *ptr;
|
|
|
|
struct clipboard *clipboard = get_process_clipboard();
|
|
|
|
|
|
|
|
if (!clipboard) return;
|
|
|
|
|
|
|
|
if (clipboard->open_thread != current)
|
|
|
|
{
|
|
|
|
set_win32_error( ERROR_CLIPBOARD_NOT_OPEN );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ptr = list_head( &clipboard->formats );
|
|
|
|
if (req->previous)
|
|
|
|
{
|
|
|
|
while (ptr && LIST_ENTRY( ptr, struct clip_format, entry )->id != req->previous)
|
|
|
|
ptr = list_next( &clipboard->formats, ptr );
|
|
|
|
if (ptr) ptr = list_next( &clipboard->formats, ptr );
|
|
|
|
}
|
|
|
|
if (ptr) reply->format = LIST_ENTRY( ptr, struct clip_format, entry )->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-09 09:53:30 +02:00
|
|
|
/* empty the clipboard and grab ownership */
|
|
|
|
DECL_HANDLER(empty_clipboard)
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard = get_process_clipboard();
|
|
|
|
|
|
|
|
if (!clipboard) return;
|
|
|
|
|
|
|
|
if (clipboard->open_thread != current)
|
|
|
|
{
|
|
|
|
set_win32_error( ERROR_CLIPBOARD_NOT_OPEN );
|
|
|
|
return;
|
|
|
|
}
|
2016-09-26 04:48:32 +02:00
|
|
|
|
|
|
|
free_clipboard_formats( clipboard );
|
2016-11-02 17:09:15 +01:00
|
|
|
clipboard->owner = clipboard->open_win;
|
2015-06-09 09:53:30 +02:00
|
|
|
clipboard->seqno++;
|
|
|
|
}
|
2016-08-22 12:26:55 +02:00
|
|
|
|
|
|
|
|
2016-09-01 13:06:09 +02:00
|
|
|
/* release ownership of the clipboard */
|
|
|
|
DECL_HANDLER(release_clipboard)
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard = get_process_clipboard();
|
|
|
|
user_handle_t owner;
|
|
|
|
|
|
|
|
if (!clipboard) return;
|
|
|
|
|
|
|
|
if (!(owner = get_valid_window_handle( req->owner ))) return;
|
|
|
|
|
2016-11-02 17:09:15 +01:00
|
|
|
if (clipboard->owner == owner)
|
2016-09-14 08:20:54 +02:00
|
|
|
{
|
2016-09-01 13:06:09 +02:00
|
|
|
reply->viewer = release_clipboard( clipboard );
|
2016-11-02 17:09:15 +01:00
|
|
|
reply->owner = clipboard->owner;
|
2016-09-14 08:20:54 +02:00
|
|
|
}
|
|
|
|
else set_error( STATUS_INVALID_OWNER );
|
2016-09-01 13:06:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* get clipboard information */
|
2016-08-23 09:29:00 +02:00
|
|
|
DECL_HANDLER(get_clipboard_info)
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard = get_process_clipboard();
|
|
|
|
|
|
|
|
if (!clipboard) return;
|
|
|
|
|
|
|
|
reply->window = clipboard->open_win;
|
2016-11-02 17:09:15 +01:00
|
|
|
reply->owner = clipboard->owner;
|
2016-08-23 09:29:00 +02:00
|
|
|
reply->viewer = clipboard->viewer;
|
2016-09-23 07:16:56 +02:00
|
|
|
reply->seqno = clipboard->seqno;
|
2016-08-23 09:29:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-22 12:26:55 +02:00
|
|
|
/* set the clipboard viewer window */
|
|
|
|
DECL_HANDLER(set_clipboard_viewer)
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard = get_process_clipboard();
|
2016-08-30 11:08:36 +02:00
|
|
|
user_handle_t viewer = 0, previous = 0;
|
2016-08-22 12:26:55 +02:00
|
|
|
|
|
|
|
if (!clipboard) return;
|
2016-08-30 11:08:36 +02:00
|
|
|
if (req->viewer && !(viewer = get_valid_window_handle( req->viewer ))) return;
|
|
|
|
if (req->previous && !(previous = get_valid_window_handle( req->previous ))) return;
|
2016-08-29 13:33:22 +02:00
|
|
|
|
2016-08-22 12:26:55 +02:00
|
|
|
reply->old_viewer = clipboard->viewer;
|
2016-11-02 17:09:15 +01:00
|
|
|
reply->owner = clipboard->owner;
|
2016-08-22 12:26:55 +02:00
|
|
|
|
2016-08-29 13:33:22 +02:00
|
|
|
if (!previous || clipboard->viewer == previous)
|
|
|
|
clipboard->viewer = viewer;
|
2016-08-22 12:26:55 +02:00
|
|
|
else
|
|
|
|
set_error( STATUS_PENDING ); /* need to send message instead */
|
|
|
|
}
|
2016-08-29 13:55:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* add a clipboard listener window */
|
|
|
|
DECL_HANDLER(add_clipboard_listener)
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard = get_process_clipboard();
|
2016-08-30 11:08:36 +02:00
|
|
|
user_handle_t win;
|
2016-08-29 13:55:52 +02:00
|
|
|
|
|
|
|
if (!clipboard) return;
|
2016-08-30 11:08:36 +02:00
|
|
|
if (!(win = get_valid_window_handle( req->window ))) return;
|
2016-08-29 13:55:52 +02:00
|
|
|
|
|
|
|
add_listener( clipboard, win );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* remove a clipboard listener window */
|
|
|
|
DECL_HANDLER(remove_clipboard_listener)
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard = get_process_clipboard();
|
2016-08-30 11:08:36 +02:00
|
|
|
user_handle_t win;
|
2016-08-29 13:55:52 +02:00
|
|
|
|
|
|
|
if (!clipboard) return;
|
2016-08-30 11:08:36 +02:00
|
|
|
if (!(win = get_valid_window_handle( req->window ))) return;
|
2016-08-29 13:55:52 +02:00
|
|
|
|
|
|
|
if (!remove_listener( clipboard, win )) set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
}
|