2003-06-23 23:02:02 +00:00
|
|
|
/*
|
|
|
|
* Server-side clipboard management
|
|
|
|
*
|
2016-09-26 02:48:32 +00:00
|
|
|
* Copyright 2002 Ulrich Czekalla
|
|
|
|
* Copyright 2016 Alexandre Julliard
|
2003-06-23 23:02:02 +00: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 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2003-06-23 23:02:02 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
2005-11-28 16:32:54 +00:00
|
|
|
#include "ntstatus.h"
|
|
|
|
#define WIN32_NO_STATUS
|
2003-06-23 23:02:02 +00:00
|
|
|
#include "request.h"
|
|
|
|
#include "object.h"
|
2015-06-03 07:02:11 +00:00
|
|
|
#include "file.h"
|
2009-12-01 14:10:23 +00:00
|
|
|
#include "process.h"
|
2003-06-23 23:02:02 +00:00
|
|
|
#include "user.h"
|
2005-06-29 20:13:36 +00:00
|
|
|
#include "winuser.h"
|
2005-11-28 16:32:54 +00:00
|
|
|
#include "winternl.h"
|
2003-06-23 23:02:02 +00:00
|
|
|
|
2016-09-26 02:48:32 +00:00
|
|
|
struct clip_format
|
|
|
|
{
|
|
|
|
struct list entry; /* entry in format list */
|
|
|
|
unsigned int id; /* format id */
|
|
|
|
data_size_t size; /* size of the data block */
|
|
|
|
void *data; /* data contents, or NULL for delay-rendered */
|
|
|
|
};
|
|
|
|
|
2005-06-29 20:13:36 +00: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 */
|
|
|
|
struct thread *owner_thread; /* thread id that owns the clipboard */
|
|
|
|
user_handle_t owner_win; /* window that owns the clipboard data */
|
|
|
|
user_handle_t viewer; /* first window in clipboard viewer list */
|
|
|
|
unsigned int seqno; /* clipboard change sequence number */
|
2016-08-30 07:33:04 +00:00
|
|
|
unsigned int open_seqno; /* sequence number at open time */
|
2016-09-26 02:48:32 +00:00
|
|
|
struct list formats; /* list of data formats */
|
|
|
|
unsigned int format_count; /* count of data formats */
|
2016-08-29 11:55:52 +00: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 20:13:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void clipboard_dump( struct object *obj, int verbose );
|
2016-08-29 11:55:52 +00:00
|
|
|
static void clipboard_destroy( struct object *obj );
|
2005-06-29 20:13:36 +00:00
|
|
|
|
|
|
|
static const struct object_ops clipboard_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct clipboard), /* size */
|
|
|
|
clipboard_dump, /* dump */
|
2007-12-05 17:16:42 +00:00
|
|
|
no_get_type, /* get_type */
|
2005-06-29 20:13:36 +00:00
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
NULL, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
|
|
|
no_get_fd, /* get_fd */
|
2005-12-12 13:57:40 +00:00
|
|
|
no_map_access, /* map_access */
|
2007-10-03 12:10:37 +00:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
2005-11-22 14:55:42 +00:00
|
|
|
no_lookup_name, /* lookup_name */
|
2016-02-04 12:07:19 +00:00
|
|
|
no_link_name, /* link_name */
|
|
|
|
NULL, /* unlink_name */
|
2007-03-22 10:44:29 +00:00
|
|
|
no_open_file, /* open_file */
|
2005-06-29 20:13:36 +00:00
|
|
|
no_close_handle, /* close_handle */
|
2016-08-29 11:55:52 +00:00
|
|
|
clipboard_destroy /* destroy */
|
2005-06-29 20:13:36 +00:00
|
|
|
};
|
2003-06-23 23:02:02 +00:00
|
|
|
|
|
|
|
|
2016-09-26 02:48:32 +00: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;
|
|
|
|
format->size = 0;
|
|
|
|
format->data = NULL;
|
|
|
|
list_add_tail( &clipboard->formats, &format->entry );
|
|
|
|
clipboard->format_count++;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-06-29 20:13:36 +00:00
|
|
|
/* dump a clipboard object */
|
|
|
|
static void clipboard_dump( struct object *obj, int verbose )
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard = (struct clipboard *)obj;
|
|
|
|
|
2008-12-08 15:57:38 +00:00
|
|
|
fprintf( stderr, "Clipboard open_thread=%p open_win=%08x owner_thread=%p owner_win=%08x viewer=%08x seq=%u\n",
|
2005-06-29 20:13:36 +00:00
|
|
|
clipboard->open_thread, clipboard->open_win, clipboard->owner_thread,
|
|
|
|
clipboard->owner_win, clipboard->viewer, clipboard->seqno );
|
|
|
|
}
|
|
|
|
|
2016-08-29 11:55:52 +00:00
|
|
|
static void clipboard_destroy( struct object *obj )
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard = (struct clipboard *)obj;
|
|
|
|
|
|
|
|
free( clipboard->listeners );
|
2016-09-26 02:48:32 +00:00
|
|
|
free_clipboard_formats( clipboard );
|
2016-08-29 11:55:52 +00:00
|
|
|
}
|
|
|
|
|
2005-06-29 20:13:36 +00:00
|
|
|
/* retrieve the clipboard info for the current process, allocating it if needed */
|
|
|
|
static struct clipboard *get_process_clipboard(void)
|
2003-06-23 23:02:02 +00:00
|
|
|
{
|
2005-06-29 20:13:36 +00:00
|
|
|
struct clipboard *clipboard;
|
|
|
|
struct winstation *winstation = get_process_winstation( current->process, WINSTA_ACCESSCLIPBOARD );
|
|
|
|
|
|
|
|
if (!winstation) return NULL;
|
|
|
|
|
2005-07-11 10:55:53 +00:00
|
|
|
if (!(clipboard = winstation->clipboard))
|
2003-06-23 23:02:02 +00:00
|
|
|
{
|
2005-06-29 20:13:36 +00:00
|
|
|
if ((clipboard = alloc_object( &clipboard_ops )))
|
|
|
|
{
|
|
|
|
clipboard->open_thread = NULL;
|
|
|
|
clipboard->open_win = 0;
|
|
|
|
clipboard->owner_thread = NULL;
|
|
|
|
clipboard->owner_win = 0;
|
|
|
|
clipboard->viewer = 0;
|
|
|
|
clipboard->seqno = 0;
|
2016-09-26 02:48:32 +00:00
|
|
|
clipboard->format_count = 0;
|
2016-08-29 11:55:52 +00:00
|
|
|
clipboard->listen_size = 0;
|
|
|
|
clipboard->listen_count = 0;
|
|
|
|
clipboard->listeners = NULL;
|
2016-09-26 02:48:32 +00:00
|
|
|
list_init( &clipboard->formats );
|
2005-07-11 10:55:53 +00:00
|
|
|
winstation->clipboard = clipboard;
|
2005-06-29 20:13:36 +00:00
|
|
|
}
|
2003-06-23 23:02:02 +00:00
|
|
|
}
|
2005-06-29 20:13:36 +00:00
|
|
|
release_object( winstation );
|
|
|
|
return clipboard;
|
|
|
|
}
|
|
|
|
|
2016-08-29 11:55:52 +00: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 02:48:32 +00: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 07:33:04 +00: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 02:48:32 +00: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 */
|
|
|
|
return notify_listeners( clipboard );
|
|
|
|
}
|
|
|
|
|
2016-09-01 11:06:09 +00: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 02:48:32 +00:00
|
|
|
struct clip_format *format, *next;
|
|
|
|
int changed = 0;
|
|
|
|
|
2016-09-01 11:06:09 +00:00
|
|
|
clipboard->owner_win = 0;
|
|
|
|
clipboard->owner_thread = NULL;
|
2016-09-26 02:48:32 +00: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 )
|
|
|
|
{
|
|
|
|
if (format->data) continue;
|
|
|
|
list_remove( &format->entry );
|
|
|
|
clipboard->format_count--;
|
|
|
|
free( format );
|
|
|
|
changed = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!changed) return 0;
|
|
|
|
clipboard->seqno++;
|
|
|
|
return notify_listeners( clipboard );
|
2016-09-01 11:06:09 +00:00
|
|
|
}
|
|
|
|
|
2016-08-23 11:58:44 +00: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 07:33:04 +00:00
|
|
|
remove_listener( clipboard, window );
|
|
|
|
if (clipboard->viewer == window) clipboard->viewer = 0;
|
2016-09-01 11:06:09 +00:00
|
|
|
if (clipboard->owner_win == window) release_clipboard( clipboard );
|
2016-08-30 07:33:04 +00:00
|
|
|
if (clipboard->open_win == window)
|
|
|
|
{
|
|
|
|
user_handle_t viewer = close_clipboard( clipboard );
|
|
|
|
if (viewer) send_notify_message( viewer, WM_DRAWCLIPBOARD, clipboard->owner_win, 0 );
|
|
|
|
}
|
2016-08-23 11:58:44 +00:00
|
|
|
}
|
2005-06-29 20:13:36 +00:00
|
|
|
|
|
|
|
/* Called when thread terminates to allow release of clipboard */
|
|
|
|
void cleanup_clipboard_thread(struct thread *thread)
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard;
|
2009-12-01 14:10:23 +00:00
|
|
|
struct winstation *winstation;
|
2005-06-29 20:13:36 +00:00
|
|
|
|
2009-12-01 14:10:23 +00:00
|
|
|
if (!thread->process->winstation) return;
|
|
|
|
if (!(winstation = get_process_winstation( thread->process, WINSTA_ACCESSCLIPBOARD ))) return;
|
2005-06-29 20:13:36 +00:00
|
|
|
|
2005-07-11 10:55:53 +00:00
|
|
|
if ((clipboard = winstation->clipboard))
|
2003-06-23 23:02:02 +00:00
|
|
|
{
|
2016-09-01 13:13:53 +00:00
|
|
|
if (thread == clipboard->owner_thread) clipboard->owner_thread = NULL;
|
2016-08-30 07:33:04 +00:00
|
|
|
if (thread == clipboard->open_thread)
|
|
|
|
{
|
|
|
|
user_handle_t viewer = close_clipboard( clipboard );
|
|
|
|
if (viewer) send_notify_message( viewer, WM_DRAWCLIPBOARD, clipboard->owner_win, 0 );
|
|
|
|
}
|
2003-06-23 23:02:02 +00:00
|
|
|
}
|
2005-06-29 20:13:36 +00:00
|
|
|
release_object( winstation );
|
2003-06-23 23:02:02 +00:00
|
|
|
}
|
|
|
|
|
2015-06-03 09:46:01 +00:00
|
|
|
static int release_clipboard_owner( struct clipboard *clipboard, user_handle_t win )
|
2015-06-03 09:37:16 +00:00
|
|
|
{
|
2015-06-03 09:46:01 +00:00
|
|
|
if ((clipboard->open_thread && clipboard->open_thread->process != current->process) ||
|
|
|
|
(win && clipboard->owner_win != get_user_full_handle( win )))
|
2003-06-23 23:02:02 +00:00
|
|
|
{
|
2015-06-03 09:46:01 +00:00
|
|
|
set_win32_error( ERROR_CLIPBOARD_NOT_OPEN );
|
2015-06-03 09:37:16 +00:00
|
|
|
return 0;
|
2003-06-23 23:02:02 +00:00
|
|
|
}
|
2015-06-03 09:37:16 +00:00
|
|
|
clipboard->owner_win = 0;
|
|
|
|
clipboard->owner_thread = NULL;
|
2004-06-25 02:55:37 +00:00
|
|
|
return 1;
|
2003-06-23 23:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-22 06:31:21 +00:00
|
|
|
/* open the clipboard */
|
|
|
|
DECL_HANDLER(open_clipboard)
|
2003-06-23 23:02:02 +00:00
|
|
|
{
|
2005-06-29 20:13:36 +00:00
|
|
|
struct clipboard *clipboard = get_process_clipboard();
|
2016-08-30 09:08:36 +00:00
|
|
|
user_handle_t win = 0;
|
2005-06-29 20:13:36 +00:00
|
|
|
|
|
|
|
if (!clipboard) return;
|
2016-08-30 09:08:36 +00:00
|
|
|
if (req->window && !(win = get_valid_window_handle( req->window ))) return;
|
2005-06-29 20:13:36 +00:00
|
|
|
|
2016-08-22 06:31:21 +00:00
|
|
|
if (clipboard->open_thread && clipboard->open_win != win)
|
2003-06-23 23:02:02 +00:00
|
|
|
{
|
2016-08-29 11:33:22 +00:00
|
|
|
set_error( STATUS_INVALID_LOCK_SEQUENCE );
|
2016-08-22 06:31:21 +00:00
|
|
|
return;
|
2003-06-23 23:02:02 +00:00
|
|
|
}
|
2016-08-30 07:33:04 +00:00
|
|
|
|
|
|
|
if (!clipboard->open_thread) clipboard->open_seqno = clipboard->seqno; /* first open */
|
2016-08-22 06:31:21 +00:00
|
|
|
clipboard->open_win = win;
|
|
|
|
clipboard->open_thread = current;
|
|
|
|
|
|
|
|
reply->owner = (clipboard->owner_thread && clipboard->owner_thread->process == current->process);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* close the clipboard */
|
|
|
|
DECL_HANDLER(close_clipboard)
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard = get_process_clipboard();
|
|
|
|
|
|
|
|
if (!clipboard) return;
|
|
|
|
|
|
|
|
if (clipboard->open_thread != current)
|
2003-06-23 23:02:02 +00:00
|
|
|
{
|
2016-08-22 06:31:21 +00:00
|
|
|
set_win32_error( ERROR_CLIPBOARD_NOT_OPEN );
|
|
|
|
return;
|
2003-06-23 23:02:02 +00:00
|
|
|
}
|
2016-08-30 07:33:04 +00:00
|
|
|
reply->viewer = close_clipboard( clipboard );
|
2016-09-14 06:29:03 +00:00
|
|
|
reply->owner = clipboard->owner_win;
|
2016-08-22 06:31:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DECL_HANDLER(set_clipboard_info)
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard = get_process_clipboard();
|
|
|
|
|
|
|
|
if (!clipboard) return;
|
|
|
|
|
|
|
|
reply->old_clipboard = clipboard->open_win;
|
|
|
|
reply->old_owner = clipboard->owner_win;
|
|
|
|
reply->old_viewer = clipboard->viewer;
|
2003-06-23 23:02:02 +00:00
|
|
|
|
2015-06-09 07:53:30 +00:00
|
|
|
if (req->flags & SET_CB_RELOWNER)
|
2003-06-23 23:02:02 +00:00
|
|
|
{
|
2015-06-03 09:46:01 +00:00
|
|
|
if (!release_clipboard_owner( clipboard, req->owner )) return;
|
2003-06-23 23:02:02 +00:00
|
|
|
}
|
|
|
|
|
2005-06-29 20:13:36 +00:00
|
|
|
if (req->flags & SET_CB_SEQNO) clipboard->seqno++;
|
2003-06-23 23:02:02 +00:00
|
|
|
|
2016-09-23 05:16:56 +00:00
|
|
|
reply->seqno = clipboard->seqno;
|
2005-03-07 19:31:46 +00:00
|
|
|
|
2016-08-23 08:35:18 +00:00
|
|
|
if (clipboard->open_thread) reply->flags |= CB_OPEN_ANY;
|
2005-06-29 20:13:36 +00:00
|
|
|
if (clipboard->open_thread == current) reply->flags |= CB_OPEN;
|
|
|
|
if (clipboard->owner_thread == current) reply->flags |= CB_OWNER;
|
|
|
|
if (clipboard->owner_thread && clipboard->owner_thread->process == current->process)
|
2005-03-07 19:31:46 +00:00
|
|
|
reply->flags |= CB_PROCESS;
|
2003-06-23 23:02:02 +00:00
|
|
|
}
|
2015-06-09 07:53:30 +00:00
|
|
|
|
|
|
|
|
2016-09-26 02:48:32 +00: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
clipboard->seqno++;
|
|
|
|
format->size = get_req_data_size();
|
|
|
|
format->data = data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-26 04:55:09 +00: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 07:53:30 +00: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 02:48:32 +00:00
|
|
|
|
|
|
|
free_clipboard_formats( clipboard );
|
2015-06-09 07:53:30 +00:00
|
|
|
clipboard->owner_win = clipboard->open_win;
|
|
|
|
clipboard->owner_thread = clipboard->open_thread;
|
|
|
|
clipboard->seqno++;
|
|
|
|
}
|
2016-08-22 10:26:55 +00:00
|
|
|
|
|
|
|
|
2016-09-01 11:06:09 +00: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;
|
|
|
|
|
|
|
|
if (clipboard->owner_win == owner)
|
2016-09-14 06:20:54 +00:00
|
|
|
{
|
2016-09-01 11:06:09 +00:00
|
|
|
reply->viewer = release_clipboard( clipboard );
|
2016-09-14 06:20:54 +00:00
|
|
|
reply->owner = clipboard->owner_win;
|
|
|
|
}
|
|
|
|
else set_error( STATUS_INVALID_OWNER );
|
2016-09-01 11:06:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* get clipboard information */
|
2016-08-23 07:29:00 +00:00
|
|
|
DECL_HANDLER(get_clipboard_info)
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard = get_process_clipboard();
|
|
|
|
|
|
|
|
if (!clipboard) return;
|
|
|
|
|
|
|
|
reply->window = clipboard->open_win;
|
|
|
|
reply->owner = clipboard->owner_win;
|
|
|
|
reply->viewer = clipboard->viewer;
|
2016-09-23 05:16:56 +00:00
|
|
|
reply->seqno = clipboard->seqno;
|
2016-08-23 07:29:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-22 10:26:55 +00:00
|
|
|
/* set the clipboard viewer window */
|
|
|
|
DECL_HANDLER(set_clipboard_viewer)
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard = get_process_clipboard();
|
2016-08-30 09:08:36 +00:00
|
|
|
user_handle_t viewer = 0, previous = 0;
|
2016-08-22 10:26:55 +00:00
|
|
|
|
|
|
|
if (!clipboard) return;
|
2016-08-30 09:08:36 +00: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 11:33:22 +00:00
|
|
|
|
2016-08-22 10:26:55 +00:00
|
|
|
reply->old_viewer = clipboard->viewer;
|
|
|
|
reply->owner = clipboard->owner_win;
|
|
|
|
|
2016-08-29 11:33:22 +00:00
|
|
|
if (!previous || clipboard->viewer == previous)
|
|
|
|
clipboard->viewer = viewer;
|
2016-08-22 10:26:55 +00:00
|
|
|
else
|
|
|
|
set_error( STATUS_PENDING ); /* need to send message instead */
|
|
|
|
}
|
2016-08-29 11:55:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* add a clipboard listener window */
|
|
|
|
DECL_HANDLER(add_clipboard_listener)
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard = get_process_clipboard();
|
2016-08-30 09:08:36 +00:00
|
|
|
user_handle_t win;
|
2016-08-29 11:55:52 +00:00
|
|
|
|
|
|
|
if (!clipboard) return;
|
2016-08-30 09:08:36 +00:00
|
|
|
if (!(win = get_valid_window_handle( req->window ))) return;
|
2016-08-29 11:55:52 +00:00
|
|
|
|
|
|
|
add_listener( clipboard, win );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* remove a clipboard listener window */
|
|
|
|
DECL_HANDLER(remove_clipboard_listener)
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard = get_process_clipboard();
|
2016-08-30 09:08:36 +00:00
|
|
|
user_handle_t win;
|
2016-08-29 11:55:52 +00:00
|
|
|
|
|
|
|
if (!clipboard) return;
|
2016-08-30 09:08:36 +00:00
|
|
|
if (!(win = get_valid_window_handle( req->window ))) return;
|
2016-08-29 11:55:52 +00:00
|
|
|
|
|
|
|
if (!remove_listener( clipboard, win )) set_error( STATUS_INVALID_PARAMETER );
|
|
|
|
}
|