2003-06-24 01:02:02 +02:00
|
|
|
/*
|
|
|
|
* Server-side clipboard management
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Ulrich Czekalla
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
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 */
|
|
|
|
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 */
|
2015-06-03 09:02:11 +02:00
|
|
|
timeout_t seqno_timestamp; /* time stamp of last seqno increment */
|
2005-06-29 22:13:36 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static void clipboard_dump( struct object *obj, int verbose );
|
|
|
|
|
|
|
|
static const struct object_ops clipboard_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct clipboard), /* size */
|
|
|
|
clipboard_dump, /* dump */
|
2007-12-05 18:16:42 +01:00
|
|
|
no_get_type, /* get_type */
|
2005-06-29 22:13:36 +02:00
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
NULL, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
|
|
|
no_get_fd, /* get_fd */
|
2005-12-12 14:57:40 +01:00
|
|
|
no_map_access, /* map_access */
|
2007-10-03 14:10:37 +02:00
|
|
|
default_get_sd, /* get_sd */
|
|
|
|
default_set_sd, /* set_sd */
|
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 */
|
2005-06-29 22:13:36 +02:00
|
|
|
no_close_handle, /* close_handle */
|
|
|
|
no_destroy /* destroy */
|
|
|
|
};
|
2003-06-24 01:02:02 +02:00
|
|
|
|
|
|
|
|
2015-06-03 09:02:11 +02:00
|
|
|
#define MINUPDATELAPSE (2 * TICKS_PER_SEC)
|
2003-06-24 01:02:02 +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;
|
|
|
|
|
2008-12-08 16:57:38 +01:00
|
|
|
fprintf( stderr, "Clipboard open_thread=%p open_win=%08x owner_thread=%p owner_win=%08x viewer=%08x seq=%u\n",
|
2005-06-29 22:13:36 +02:00
|
|
|
clipboard->open_thread, clipboard->open_win, clipboard->owner_thread,
|
|
|
|
clipboard->owner_win, clipboard->viewer, clipboard->seqno );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
|
|
|
clipboard->owner_thread = NULL;
|
|
|
|
clipboard->owner_win = 0;
|
|
|
|
clipboard->viewer = 0;
|
|
|
|
clipboard->seqno = 0;
|
|
|
|
clipboard->seqno_timestamp = 0;
|
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-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;
|
|
|
|
|
|
|
|
if (clipboard->open_win == window)
|
|
|
|
{
|
|
|
|
clipboard->open_win = 0;
|
|
|
|
clipboard->open_thread = NULL;
|
|
|
|
}
|
|
|
|
if (clipboard->owner_win == window)
|
|
|
|
{
|
|
|
|
clipboard->owner_win = 0;
|
|
|
|
clipboard->owner_thread = NULL;
|
|
|
|
}
|
|
|
|
if (clipboard->viewer == window) clipboard->viewer = 0;
|
|
|
|
}
|
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
|
|
|
{
|
2005-06-29 22:13:36 +02:00
|
|
|
if (thread == clipboard->open_thread)
|
|
|
|
{
|
|
|
|
clipboard->open_win = 0;
|
|
|
|
clipboard->open_thread = NULL;
|
|
|
|
}
|
|
|
|
if (thread == clipboard->owner_thread)
|
|
|
|
{
|
|
|
|
clipboard->owner_win = 0;
|
|
|
|
clipboard->owner_thread = NULL;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2015-06-03 11:46:01 +02:00
|
|
|
static int release_clipboard_owner( struct clipboard *clipboard, user_handle_t win )
|
2015-06-03 11:37:16 +02:00
|
|
|
{
|
2015-06-03 11:46:01 +02:00
|
|
|
if ((clipboard->open_thread && clipboard->open_thread->process != current->process) ||
|
|
|
|
(win && clipboard->owner_win != get_user_full_handle( win )))
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2015-06-03 11:46:01 +02:00
|
|
|
set_win32_error( ERROR_CLIPBOARD_NOT_OPEN );
|
2015-06-03 11:37:16 +02:00
|
|
|
return 0;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
2015-06-03 11:37:16 +02:00
|
|
|
clipboard->owner_win = 0;
|
|
|
|
clipboard->owner_thread = NULL;
|
2004-06-25 04:55:37 +02:00
|
|
|
return 1;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-29 22:13:36 +02:00
|
|
|
static int get_seqno( struct clipboard *clipboard )
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2015-06-03 09:02:11 +02:00
|
|
|
if (!clipboard->owner_thread && (current_time - clipboard->seqno_timestamp > MINUPDATELAPSE))
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2015-06-03 09:02:11 +02:00
|
|
|
clipboard->seqno_timestamp = current_time;
|
2005-06-29 22:13:36 +02:00
|
|
|
clipboard->seqno++;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
2005-06-29 22:13:36 +02:00
|
|
|
return clipboard->seqno;
|
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-22 08:31:21 +02:00
|
|
|
user_handle_t win;
|
2005-06-29 22:13:36 +02:00
|
|
|
|
|
|
|
if (!clipboard) return;
|
2016-08-22 08:31:21 +02:00
|
|
|
win = get_user_full_handle( req->window );
|
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-22 08:31:21 +02:00
|
|
|
set_error( STATUS_WAS_LOCKED );
|
|
|
|
return;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
2016-08-22 08:31:21 +02: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-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-22 08:31:21 +02:00
|
|
|
if (req->changed) clipboard->seqno++;
|
|
|
|
clipboard->open_thread = NULL;
|
|
|
|
clipboard->open_win = 0;
|
|
|
|
|
|
|
|
reply->viewer = clipboard->viewer;
|
|
|
|
reply->owner = (clipboard->owner_thread && clipboard->owner_thread->process == current->process);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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-24 01:02:02 +02:00
|
|
|
|
2015-06-09 09:53:30 +02:00
|
|
|
if (req->flags & SET_CB_RELOWNER)
|
2003-06-24 01:02:02 +02:00
|
|
|
{
|
2015-06-03 11:46:01 +02:00
|
|
|
if (!release_clipboard_owner( clipboard, req->owner )) return;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
|
|
|
|
2005-06-29 22:13:36 +02:00
|
|
|
if (req->flags & SET_CB_SEQNO) clipboard->seqno++;
|
2003-06-24 01:02:02 +02:00
|
|
|
|
2005-06-29 22:13:36 +02:00
|
|
|
reply->seqno = get_seqno( clipboard );
|
2005-03-07 20:31:46 +01:00
|
|
|
|
2016-08-23 10:35:18 +02:00
|
|
|
if (clipboard->open_thread) reply->flags |= CB_OPEN_ANY;
|
2005-06-29 22:13:36 +02: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 20:31:46 +01:00
|
|
|
reply->flags |= CB_PROCESS;
|
2003-06-24 01:02:02 +02:00
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
clipboard->owner_win = clipboard->open_win;
|
|
|
|
clipboard->owner_thread = clipboard->open_thread;
|
|
|
|
clipboard->seqno++;
|
|
|
|
}
|
2016-08-22 12:26:55 +02:00
|
|
|
|
|
|
|
|
2016-08-23 09:29:00 +02:00
|
|
|
/* Get clipboard information */
|
|
|
|
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;
|
|
|
|
reply->seqno = get_seqno( clipboard );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-22 12:26:55 +02:00
|
|
|
/* set the clipboard viewer window */
|
|
|
|
DECL_HANDLER(set_clipboard_viewer)
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard = get_process_clipboard();
|
|
|
|
|
|
|
|
if (!clipboard) return;
|
|
|
|
|
|
|
|
reply->old_viewer = clipboard->viewer;
|
|
|
|
reply->owner = clipboard->owner_win;
|
|
|
|
|
|
|
|
if (!req->previous || clipboard->viewer == get_user_full_handle( req->previous ))
|
|
|
|
clipboard->viewer = get_user_full_handle( req->viewer );
|
|
|
|
else
|
|
|
|
set_error( STATUS_PENDING ); /* need to send message instead */
|
|
|
|
}
|