2003-06-23 23:02:02 +00: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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "request.h"
|
|
|
|
#include "object.h"
|
|
|
|
#include "user.h"
|
2005-06-29 20:13:36 +00:00
|
|
|
#include "winuser.h"
|
2003-06-23 23:02:02 +00:00
|
|
|
|
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 */
|
|
|
|
time_t seqno_timestamp; /* time stamp of last seqno increment */
|
|
|
|
};
|
|
|
|
|
|
|
|
static void clipboard_dump( struct object *obj, int verbose );
|
|
|
|
|
|
|
|
static const struct object_ops clipboard_ops =
|
|
|
|
{
|
|
|
|
sizeof(struct clipboard), /* size */
|
|
|
|
clipboard_dump, /* dump */
|
|
|
|
no_add_queue, /* add_queue */
|
|
|
|
NULL, /* remove_queue */
|
|
|
|
NULL, /* signaled */
|
|
|
|
NULL, /* satisfied */
|
|
|
|
no_signal, /* signal */
|
|
|
|
no_get_fd, /* get_fd */
|
|
|
|
no_close_handle, /* close_handle */
|
|
|
|
no_destroy /* destroy */
|
|
|
|
};
|
2003-06-23 23:02:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
#define MINUPDATELAPSE 2
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
fprintf( stderr, "Clipboard open_thread=%p open_win=%p owner_thread=%p owner_win=%p viewer=%p seq=%u\n",
|
|
|
|
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-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;
|
|
|
|
clipboard->seqno_timestamp = 0;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Called when thread terminates to allow release of clipboard */
|
|
|
|
void cleanup_clipboard_thread(struct thread *thread)
|
|
|
|
{
|
|
|
|
struct clipboard *clipboard;
|
|
|
|
struct winstation *winstation = get_process_winstation( thread->process, WINSTA_ACCESSCLIPBOARD );
|
|
|
|
|
|
|
|
if (!winstation) return;
|
|
|
|
|
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 (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-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
|
|
|
}
|
|
|
|
|
2005-06-29 20:13:36 +00:00
|
|
|
static int set_clipboard_window( struct clipboard *clipboard, user_handle_t win, int clear )
|
2003-06-23 23:02:02 +00:00
|
|
|
{
|
2005-06-29 20:13:36 +00:00
|
|
|
if (clipboard->open_thread && clipboard->open_thread != current)
|
2003-06-23 23:02:02 +00:00
|
|
|
{
|
|
|
|
set_error(STATUS_WAS_LOCKED);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (!clear)
|
|
|
|
{
|
2005-06-29 20:13:36 +00:00
|
|
|
clipboard->open_win = win;
|
|
|
|
clipboard->open_thread = current;
|
2003-06-23 23:02:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-29 20:13:36 +00:00
|
|
|
clipboard->open_thread = NULL;
|
|
|
|
clipboard->open_win = 0;
|
2003-06-23 23:02:02 +00:00
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-29 20:13:36 +00:00
|
|
|
static int set_clipboard_owner( struct clipboard *clipboard, user_handle_t win, int clear )
|
2003-06-23 23:02:02 +00:00
|
|
|
{
|
2005-06-29 20:13:36 +00:00
|
|
|
if (clipboard->open_thread && clipboard->open_thread->process != current->process)
|
2003-06-23 23:02:02 +00:00
|
|
|
{
|
2004-06-25 02:55:37 +00:00
|
|
|
set_error(STATUS_WAS_LOCKED);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
else if (!clear)
|
|
|
|
{
|
2005-06-29 20:13:36 +00:00
|
|
|
clipboard->owner_win = win;
|
|
|
|
clipboard->owner_thread = current;
|
2003-06-23 23:02:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-06-29 20:13:36 +00:00
|
|
|
clipboard->owner_win = 0;
|
|
|
|
clipboard->owner_thread = NULL;
|
2003-06-23 23:02:02 +00:00
|
|
|
}
|
2004-06-25 02:55:37 +00:00
|
|
|
return 1;
|
2003-06-23 23:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-06-29 20:13:36 +00:00
|
|
|
static int get_seqno( struct clipboard *clipboard )
|
2003-06-23 23:02:02 +00:00
|
|
|
{
|
|
|
|
time_t tm = time(NULL);
|
|
|
|
|
2005-06-29 20:13:36 +00:00
|
|
|
if (!clipboard->owner_thread && (tm > (clipboard->seqno_timestamp + MINUPDATELAPSE)))
|
2003-06-23 23:02:02 +00:00
|
|
|
{
|
2005-06-29 20:13:36 +00:00
|
|
|
clipboard->seqno_timestamp = tm;
|
|
|
|
clipboard->seqno++;
|
2003-06-23 23:02:02 +00:00
|
|
|
}
|
2005-06-29 20:13:36 +00:00
|
|
|
return clipboard->seqno;
|
2003-06-23 23:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DECL_HANDLER(set_clipboard_info)
|
|
|
|
{
|
2005-06-29 20:13:36 +00:00
|
|
|
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
|
|
|
|
|
|
|
if (req->flags & SET_CB_OPEN)
|
|
|
|
{
|
2005-06-29 20:13:36 +00:00
|
|
|
if (clipboard->open_thread)
|
2004-06-25 02:55:37 +00:00
|
|
|
{
|
|
|
|
/* clipboard already opened */
|
|
|
|
set_error(STATUS_WAS_LOCKED);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-06-29 20:13:36 +00:00
|
|
|
if (!set_clipboard_window( clipboard, req->clipboard, 0 )) return;
|
2003-06-23 23:02:02 +00:00
|
|
|
}
|
|
|
|
else if (req->flags & SET_CB_CLOSE)
|
|
|
|
{
|
2005-06-29 20:13:36 +00:00
|
|
|
if (clipboard->open_thread != current)
|
2004-06-25 02:55:37 +00:00
|
|
|
{
|
|
|
|
set_win32_error(ERROR_CLIPBOARD_NOT_OPEN);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-06-29 20:13:36 +00:00
|
|
|
if (!set_clipboard_window( clipboard, 0, 1 )) return;
|
2003-06-23 23:02:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (req->flags & SET_CB_OWNER)
|
|
|
|
{
|
2005-06-29 20:13:36 +00:00
|
|
|
if (!set_clipboard_owner( clipboard, req->owner, 0 )) return;
|
2003-06-23 23:02:02 +00:00
|
|
|
}
|
|
|
|
else if (req->flags & SET_CB_RELOWNER)
|
|
|
|
{
|
2005-06-29 20:13:36 +00:00
|
|
|
if (!set_clipboard_owner( clipboard, 0, 1 )) return;
|
2003-06-23 23:02:02 +00:00
|
|
|
}
|
|
|
|
|
2005-06-29 20:13:36 +00:00
|
|
|
if (req->flags & SET_CB_VIEWER) clipboard->viewer = req->viewer;
|
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
|
|
|
|
2005-06-29 20:13:36 +00:00
|
|
|
reply->seqno = get_seqno( clipboard );
|
2005-03-07 19:31:46 +00:00
|
|
|
|
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
|
|
|
}
|