2 * Server-side clipboard management
4 * Copyright (C) 2002 Ulrich Czekalla
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
33 static struct thread
*cbthread
; /* thread id that has clipboard open */
34 static user_handle_t clipboard
; /* window that has clipboard open */
36 static struct thread
*cbowner
; /* thread id that owns the clipboard */
37 static user_handle_t owner
; /* window that owns the clipboard data */
39 static user_handle_t viewer
; /* first window in clipboard viewer list */
40 static unsigned int seqno
; /* clipboard change sequence number */
41 static time_t seqnots
; /* time stamp of last seqno increment */
43 #define MINUPDATELAPSE 2
45 /* Called when thread terminates to allow release of clipboard */
46 void cleanup_clipboard_thread(struct thread
*thread
)
48 if (thread
== cbthread
)
53 if (thread
== cbowner
)
60 static int set_clipboard_window(user_handle_t win
, int clear
)
62 if (cbthread
&& cbthread
!= current
)
64 set_error(STATUS_WAS_LOCKED
);
81 static int set_clipboard_owner(user_handle_t win
, int clear
)
83 if (cbowner
&& cbowner
!= current
)
85 set_error(STATUS_WAS_LOCKED
);
102 static int get_seqno(void)
104 time_t tm
= time(NULL
);
106 if (!cbowner
&& (tm
> (seqnots
+ MINUPDATELAPSE
)))
115 DECL_HANDLER(set_clipboard_info
)
117 reply
->old_clipboard
= clipboard
;
118 reply
->old_owner
= owner
;
119 reply
->old_viewer
= viewer
;
121 if (req
->flags
& SET_CB_OPEN
)
125 /* clipboard already opened */
126 set_error(STATUS_WAS_LOCKED
);
130 if (!set_clipboard_window(req
->clipboard
, 0))
133 else if (req
->flags
& SET_CB_CLOSE
)
135 if (cbthread
!= current
)
137 set_win32_error(ERROR_CLIPBOARD_NOT_OPEN
);
141 if (!set_clipboard_window(0, 1))
145 if (req
->flags
& SET_CB_OWNER
)
147 if (!set_clipboard_owner(req
->owner
, 0))
150 else if (req
->flags
& SET_CB_RELOWNER
)
152 if (!set_clipboard_owner(0, 1))
156 if (req
->flags
& SET_CB_VIEWER
)
157 viewer
= req
->viewer
;
159 if (req
->flags
& SET_CB_SEQNO
)
162 reply
->seqno
= get_seqno();
164 if (cbthread
== current
)
165 reply
->flags
|= CB_OPEN
;
167 if (cbowner
== current
)
168 reply
->flags
|= CB_OWNER
;