~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/server/clipboard.c

Version: ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  1 /*
  2  * Server-side clipboard management
  3  *
  4  * Copyright (C) 2002 Ulrich Czekalla
  5  *
  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.
 10  *
 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.
 15  *
 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 19  */
 20 
 21 #include "config.h"
 22 #include "wine/port.h"
 23 
 24 #include <assert.h>
 25 #include <stdlib.h>
 26 #include <stdio.h>
 27 #include <string.h>
 28 
 29 #include "ntstatus.h"
 30 #define WIN32_NO_STATUS
 31 #include "request.h"
 32 #include "object.h"
 33 #include "user.h"
 34 #include "winuser.h"
 35 #include "winternl.h"
 36 
 37 struct clipboard
 38 {
 39     struct object  obj;              /* object header */
 40     struct thread *open_thread;      /* thread id that has clipboard open */
 41     user_handle_t  open_win;         /* window that has clipboard open */
 42     struct thread *owner_thread;     /* thread id that owns the clipboard */
 43     user_handle_t  owner_win;        /* window that owns the clipboard data */
 44     user_handle_t  viewer;           /* first window in clipboard viewer list */
 45     unsigned int   seqno;            /* clipboard change sequence number */
 46     time_t         seqno_timestamp;  /* time stamp of last seqno increment */
 47 };
 48 
 49 static void clipboard_dump( struct object *obj, int verbose );
 50 
 51 static const struct object_ops clipboard_ops =
 52 {
 53     sizeof(struct clipboard),     /* size */
 54     clipboard_dump,               /* dump */
 55     no_get_type,                  /* get_type */
 56     no_add_queue,                 /* add_queue */
 57     NULL,                         /* remove_queue */
 58     NULL,                         /* signaled */
 59     NULL,                         /* satisfied */
 60     no_signal,                    /* signal */
 61     no_get_fd,                    /* get_fd */
 62     no_map_access,                /* map_access */
 63     default_get_sd,               /* get_sd */
 64     default_set_sd,               /* set_sd */
 65     no_lookup_name,               /* lookup_name */
 66     no_open_file,                 /* open_file */
 67     no_close_handle,              /* close_handle */
 68     no_destroy                    /* destroy */
 69 };
 70 
 71 
 72 #define MINUPDATELAPSE 2
 73 
 74 /* dump a clipboard object */
 75 static void clipboard_dump( struct object *obj, int verbose )
 76 {
 77     struct clipboard *clipboard = (struct clipboard *)obj;
 78 
 79     fprintf( stderr, "Clipboard open_thread=%p open_win=%p owner_thread=%p owner_win=%p viewer=%p seq=%u\n",
 80              clipboard->open_thread, clipboard->open_win, clipboard->owner_thread,
 81              clipboard->owner_win, clipboard->viewer, clipboard->seqno );
 82 }
 83 
 84 /* retrieve the clipboard info for the current process, allocating it if needed */
 85 static struct clipboard *get_process_clipboard(void)
 86 {
 87     struct clipboard *clipboard;
 88     struct winstation *winstation = get_process_winstation( current->process, WINSTA_ACCESSCLIPBOARD );
 89 
 90     if (!winstation) return NULL;
 91 
 92     if (!(clipboard = winstation->clipboard))
 93     {
 94         if ((clipboard = alloc_object( &clipboard_ops )))
 95         {
 96             clipboard->open_thread = NULL;
 97             clipboard->open_win = 0;
 98             clipboard->owner_thread = NULL;
 99             clipboard->owner_win = 0;
100             clipboard->viewer = 0;
101             clipboard->seqno = 0;
102             clipboard->seqno_timestamp = 0;
103             winstation->clipboard = clipboard;
104         }
105     }
106     release_object( winstation );
107     return clipboard;
108 }
109 
110 
111 /* Called when thread terminates to allow release of clipboard */
112 void cleanup_clipboard_thread(struct thread *thread)
113 {
114     struct clipboard *clipboard;
115     struct winstation *winstation = get_process_winstation( thread->process, WINSTA_ACCESSCLIPBOARD );
116 
117     if (!winstation) return;
118 
119     if ((clipboard = winstation->clipboard))
120     {
121         if (thread == clipboard->open_thread)
122         {
123             clipboard->open_win = 0;
124             clipboard->open_thread = NULL;
125         }
126         if (thread == clipboard->owner_thread)
127         {
128             clipboard->owner_win = 0;
129             clipboard->owner_thread = NULL;
130         }
131     }
132     release_object( winstation );
133 }
134 
135 static int set_clipboard_window( struct clipboard *clipboard, user_handle_t win, int clear )
136 {
137     if (clipboard->open_thread && clipboard->open_thread != current)
138     {
139         set_error(STATUS_WAS_LOCKED);
140         return 0;
141     }
142     else if (!clear)
143     {
144         clipboard->open_win = win;
145         clipboard->open_thread = current;
146     }
147     else
148     {
149         clipboard->open_thread = NULL;
150         clipboard->open_win = 0;
151     }
152     return 1;
153 }
154 
155 
156 static int set_clipboard_owner( struct clipboard *clipboard, user_handle_t win, int clear )
157 {
158     if (clipboard->open_thread && clipboard->open_thread->process != current->process)
159     {
160         set_error(STATUS_WAS_LOCKED);
161         return 0;
162     }
163     else if (!clear)
164     {
165         clipboard->owner_win = win;
166         clipboard->owner_thread = current;
167     }
168     else
169     {
170         clipboard->owner_win = 0;
171         clipboard->owner_thread = NULL;
172     }
173     return 1;
174 }
175 
176 
177 static int get_seqno( struct clipboard *clipboard )
178 {
179     time_t tm = time(NULL);
180 
181     if (!clipboard->owner_thread && (tm > (clipboard->seqno_timestamp + MINUPDATELAPSE)))
182     {
183         clipboard->seqno_timestamp = tm;
184         clipboard->seqno++;
185     }
186     return clipboard->seqno;
187 }
188 
189 
190 DECL_HANDLER(set_clipboard_info)
191 {
192     struct clipboard *clipboard = get_process_clipboard();
193 
194     if (!clipboard) return;
195 
196     reply->old_clipboard = clipboard->open_win;
197     reply->old_owner     = clipboard->owner_win;
198     reply->old_viewer    = clipboard->viewer;
199 
200     if (req->flags & SET_CB_OPEN)
201     {
202         if (clipboard->open_thread)
203         {
204             /* clipboard already opened */
205             set_error(STATUS_WAS_LOCKED);
206             return;
207         }
208 
209         if (!set_clipboard_window( clipboard, req->clipboard, 0 )) return;
210     }
211     else if (req->flags & SET_CB_CLOSE)
212     {
213         if (clipboard->open_thread != current)
214         {
215             set_win32_error(ERROR_CLIPBOARD_NOT_OPEN);
216             return;
217         }
218 
219         if (!set_clipboard_window( clipboard, 0, 1 )) return;
220     }
221 
222     if (req->flags & SET_CB_OWNER)
223     {
224         if (!set_clipboard_owner( clipboard, req->owner, 0 )) return;
225     }
226     else if (req->flags & SET_CB_RELOWNER)
227     {
228         if (!set_clipboard_owner( clipboard, 0, 1 )) return;
229     }
230 
231     if (req->flags & SET_CB_VIEWER) clipboard->viewer = req->viewer;
232 
233     if (req->flags & SET_CB_SEQNO) clipboard->seqno++;
234 
235     reply->seqno = get_seqno( clipboard );
236 
237     if (clipboard->open_thread == current) reply->flags |= CB_OPEN;
238     if (clipboard->owner_thread == current) reply->flags |= CB_OWNER;
239     if (clipboard->owner_thread && clipboard->owner_thread->process == current->process)
240         reply->flags |= CB_PROCESS;
241 }
242 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.