blob: a6a072e2f363d185badd33880d03a932bc318359 [file] [log] [blame]
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00001/*
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00002 * WINE clipboard function handling
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00003 *
4 * Copyright 1994 Martin Ayotte
Alexandre Julliard1e9ac791996-06-06 18:38:27 +00005 * 1996 Alex Korobka
6 *
7 */
Alexandre Julliardfb9a9191994-03-01 19:48:04 +00008
Alexandre Julliard8d24ae61994-04-05 21:42:43 +00009#include <stdlib.h>
10#include <stdio.h>
Alexandre Julliardfb9a9191994-03-01 19:48:04 +000011#include <sys/types.h>
12#include <sys/stat.h>
13#include <fcntl.h>
14#include <unistd.h>
Alexandre Julliard1e9ac791996-06-06 18:38:27 +000015#include <string.h>
Alexandre Julliard3a405ba1994-10-30 16:25:19 +000016#include <X11/Xlib.h>
17#include <X11/Xatom.h>
Alexandre Julliard1e9ac791996-06-06 18:38:27 +000018#include "windows.h"
Alexandre Julliardfb9a9191994-03-01 19:48:04 +000019#include "win.h"
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +000020#include "heap.h"
Alexandre Julliard7cbe6571995-01-09 18:21:16 +000021#include "message.h"
Alexandre Julliard234bc241994-12-10 13:02:28 +000022#include "clipboard.h"
Alexandre Julliard1e9ac791996-06-06 18:38:27 +000023#include "xmalloc.h"
Alexandre Julliardaca05781994-10-17 18:12:41 +000024#include "stddebug.h"
Alexandre Julliardaca05781994-10-17 18:12:41 +000025#include "debug.h"
Alexandre Julliardfb9a9191994-03-01 19:48:04 +000026
Alexandre Julliard1e9ac791996-06-06 18:38:27 +000027#define CF_REGFORMATBASE 0xC000
28
Alexandre Julliardfb9a9191994-03-01 19:48:04 +000029typedef struct tagCLIPFORMAT {
30 WORD wFormatID;
31 WORD wRefCount;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +000032 WORD wDataPresent;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +000033 LPSTR Name;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +000034 HANDLE16 hData;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +000035 DWORD BufSize;
Alexandre Julliardd90840e1996-06-11 16:02:08 +000036 struct tagCLIPFORMAT *PrevFormat;
37 struct tagCLIPFORMAT *NextFormat;
Alexandre Julliard1285c2f1996-05-06 16:06:24 +000038} CLIPFORMAT, *LPCLIPFORMAT;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +000039
Alexandre Julliard1e9ac791996-06-06 18:38:27 +000040/* *************************************************************************
41 * internal variables
42 */
43
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +000044static HQUEUE16 hqClipLock = 0;
45static BOOL32 bCBHasChanged = FALSE;
46
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +000047static HWND32 hWndClipOwner = 0; /* current clipboard owner */
48static HWND32 hWndClipWindow = 0; /* window that opened clipboard */
49static HWND32 hWndViewer = 0; /* start of viewers chain */
Alexandre Julliard1e9ac791996-06-06 18:38:27 +000050
Alexandre Julliard1e9ac791996-06-06 18:38:27 +000051static WORD LastRegFormat = CF_REGFORMATBASE;
52
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +000053static Bool selectionWait = False;
54static Bool selectionAcquired = False;
55static Window selectionWindow = None;
56static Window selectionPrevWindow = None;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +000057
Alexandre Julliardd90840e1996-06-11 16:02:08 +000058static CLIPFORMAT ClipFormats[16] = {
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +000059 { CF_TEXT, 1, 0, "Text", (HANDLE16)NULL, 0, NULL, &ClipFormats[1] },
60 { CF_BITMAP, 1, 0, "Bitmap", (HANDLE16)NULL, 0, &ClipFormats[0], &ClipFormats[2] },
61 { CF_METAFILEPICT, 1, 0, "MetaFile Picture", (HANDLE16)NULL, 0, &ClipFormats[1], &ClipFormats[3] },
62 { CF_SYLK, 1, 0, "Sylk", (HANDLE16)NULL, 0, &ClipFormats[2], &ClipFormats[4] },
63 { CF_DIF, 1, 0, "DIF", (HANDLE16)NULL, 0, &ClipFormats[3], &ClipFormats[5] },
64 { CF_TIFF, 1, 0, "TIFF", (HANDLE16)NULL, 0, &ClipFormats[4], &ClipFormats[6] },
65 { CF_OEMTEXT, 1, 0, "OEM Text", (HANDLE16)NULL, 0, &ClipFormats[5], &ClipFormats[7] },
66 { CF_DIB, 1, 0, "DIB", (HANDLE16)NULL, 0, &ClipFormats[6], &ClipFormats[8] },
67 { CF_PALETTE, 1, 0, "Palette", (HANDLE16)NULL, 0, &ClipFormats[7], &ClipFormats[9] },
68 { CF_PENDATA, 1, 0, "PenData", (HANDLE16)NULL, 0, &ClipFormats[8], &ClipFormats[10] },
69 { CF_RIFF, 1, 0, "RIFF", (HANDLE16)NULL, 0, &ClipFormats[9], &ClipFormats[11] },
70 { CF_WAVE, 1, 0, "Wave", (HANDLE16)NULL, 0, &ClipFormats[10], &ClipFormats[12] },
71 { CF_OWNERDISPLAY, 1, 0, "Owner Display", (HANDLE16)NULL, 0, &ClipFormats[11], &ClipFormats[13] },
72 { CF_DSPTEXT, 1, 0, "DSPText", (HANDLE16)NULL, 0, &ClipFormats[12], &ClipFormats[14] },
73 { CF_DSPMETAFILEPICT, 1, 0, "DSPMetaFile Picture", (HANDLE16)NULL, 0, &ClipFormats[13], &ClipFormats[15] },
74 { CF_DSPBITMAP, 1, 0, "DSPBitmap", (HANDLE16)NULL, 0, &ClipFormats[14], NULL }
Alexandre Julliardfb9a9191994-03-01 19:48:04 +000075 };
76
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +000077static LPCLIPFORMAT __lookup_format( LPCLIPFORMAT lpFormat, WORD wID )
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +000078{
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +000079 while(TRUE)
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +000080 {
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +000081 if (lpFormat == NULL ||
82 lpFormat->wFormatID == wID) break;
83 lpFormat = lpFormat->NextFormat;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +000084 }
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +000085 return lpFormat;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +000086}
87
88/**************************************************************************
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +000089 * CLIPBOARD_CheckSelection
90 *
91 * Prevent X selection from being lost when a top level window is
92 * destroyed.
93 */
94static void CLIPBOARD_CheckSelection(WND* pWnd)
95{
96 dprintf_clipboard(stddeb,"\tchecking %08x\n", (unsigned)pWnd->window);
97
98 if( selectionAcquired && selectionWindow != None &&
99 pWnd->window == selectionWindow )
100 {
101 selectionPrevWindow = selectionWindow;
102 selectionWindow = None;
103
104 if( pWnd->next )
105 selectionWindow = pWnd->next->window;
106 else if( pWnd->parent )
107 if( pWnd->parent->child != pWnd )
108 selectionWindow = pWnd->parent->child->window;
109
110 dprintf_clipboard(stddeb,"\tswitching selection from %08x to %08x\n",
111 (unsigned)selectionPrevWindow, (unsigned)selectionWindow);
112
113 if( selectionWindow != None )
114 {
115 XSetSelectionOwner(display, XA_PRIMARY, selectionWindow, CurrentTime);
116 if( XGetSelectionOwner(display, XA_PRIMARY) != selectionWindow )
117 selectionWindow = None;
118 }
119 }
120}
121
122/**************************************************************************
123 * CLIPBOARD_ResetLock
124 */
125void CLIPBOARD_ResetLock( HQUEUE16 hqCurrent, HQUEUE16 hqNew )
126{
127 if( hqClipLock == hqCurrent )
128 {
129 if( hqNew )
130 hqClipLock = hqNew;
131 else
132 {
133 hWndClipOwner = 0;
134 hWndClipWindow = 0;
135 EmptyClipboard32();
136 hqClipLock = 0;
137 }
138 }
139}
140
141/**************************************************************************
142 * CLIPBOARD_ResetOwner
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000143 *
144 * Called from DestroyWindow().
145 */
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000146void CLIPBOARD_ResetOwner(WND* pWnd)
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000147{
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000148 LPCLIPFORMAT lpFormat = ClipFormats;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000149
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000150 dprintf_clipboard(stddeb,"DisOwn: clipboard owner = %04x, selection = %08x\n",
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000151 hWndClipOwner, (unsigned)selectionWindow);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000152
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000153 if( pWnd->hwndSelf == hWndClipOwner)
154 {
155 SendMessage16(hWndClipOwner,WM_RENDERALLFORMATS,0,0L);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000156
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000157 /* check if all formats were rendered */
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000158
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000159 while(lpFormat)
160 {
161 if( lpFormat->wDataPresent && !lpFormat->hData )
162 {
163 dprintf_clipboard( stddeb,"\tdata missing for clipboard format %i\n",
164 lpFormat->wFormatID);
165 lpFormat->wDataPresent = 0;
166 }
167 lpFormat = lpFormat->NextFormat;
168 }
169 hWndClipOwner = 0;
170 }
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000171
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000172 /* now try to salvage current selection from being destroyed by X */
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000173
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000174 if( pWnd->window ) CLIPBOARD_CheckSelection(pWnd);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000175}
176
177/**************************************************************************
178 * CLIPBOARD_DeleteRecord
179 */
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000180static void CLIPBOARD_DeleteRecord(LPCLIPFORMAT lpFormat, BOOL32 bChange)
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000181{
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000182 if( lpFormat->wFormatID >= CF_GDIOBJFIRST &&
183 lpFormat->wFormatID <= CF_GDIOBJLAST )
184 DeleteObject32(lpFormat->hData);
185 else if( lpFormat->hData )
186 GlobalFree16(lpFormat->hData);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000187
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000188 lpFormat->wDataPresent = 0;
189 lpFormat->hData = 0;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000190
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000191 if( bChange ) bCBHasChanged = TRUE;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000192}
193
194/**************************************************************************
195 * CLIPBOARD_RequestXSelection
196 */
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000197static BOOL32 CLIPBOARD_RequestXSelection()
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000198{
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000199 HWND32 hWnd = (hWndClipWindow) ? hWndClipWindow : GetActiveWindow32();
Alexandre Julliardd90840e1996-06-11 16:02:08 +0000200
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000201 if( !hWnd ) return FALSE;
Alexandre Julliardd90840e1996-06-11 16:02:08 +0000202
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000203 dprintf_clipboard(stddeb,"Requesting selection...\n");
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000204
205 /* request data type XA_STRING, later
206 * CLIPBOARD_ReadSelection() will be invoked
207 * from the SelectionNotify event handler */
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000208
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000209 XConvertSelection(display,XA_PRIMARY,XA_STRING,
210 XInternAtom(display,"PRIMARY_TEXT",False),
211 WIN_GetXWindow(hWnd),CurrentTime);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000212
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000213 /* wait until SelectionNotify is processed
214 *
215 * FIXME: Use XCheckTypedWindowEvent() instead ( same in the
216 * CLIPBOARD_CheckSelection() ).
217 */
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000218
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000219 selectionWait=True;
220 while(selectionWait) EVENT_WaitNetEvent( TRUE, FALSE );
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000221
222 /* we treat Unix text as CF_OEMTEXT */
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000223 dprintf_clipboard(stddeb,"\tgot CF_OEMTEXT = %i\n",
224 ClipFormats[CF_OEMTEXT-1].wDataPresent);
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000225
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000226 return (BOOL32)ClipFormats[CF_OEMTEXT-1].wDataPresent;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000227}
228
229/**************************************************************************
230 * CLIPBOARD_IsPresent
231 */
Alexandre Julliard21979011997-03-05 08:22:35 +0000232BOOL32 CLIPBOARD_IsPresent(WORD wFormat)
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000233{
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000234 /* special case */
235
236 if( wFormat == CF_TEXT || wFormat == CF_OEMTEXT )
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000237 return ClipFormats[CF_TEXT-1].wDataPresent ||
238 ClipFormats[CF_OEMTEXT-1].wDataPresent;
239 else
240 {
241 LPCLIPFORMAT lpFormat = __lookup_format( ClipFormats, wFormat );
242 if( lpFormat ) return (lpFormat->wDataPresent);
243 }
244 return FALSE;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000245}
246
247/**************************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000248 * OpenClipboard16 (USER.137)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000249 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000250BOOL16 WINAPI OpenClipboard16( HWND16 hWnd )
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000251{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000252 return OpenClipboard32( hWnd );
253}
254
255
256/**************************************************************************
257 * OpenClipboard32 (USER32.406)
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000258 *
259 * Note: Netscape uses NULL hWnd to open the clipboard.
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000260 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000261BOOL32 WINAPI OpenClipboard32( HWND32 hWnd )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000262{
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000263 BOOL32 bRet;
264
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000265 dprintf_clipboard(stddeb,"OpenClipboard(%04x) = ", hWnd);
266
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000267 if (!hqClipLock)
268 {
269 hqClipLock = GetTaskQueue(0);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000270 hWndClipWindow = hWnd;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000271 bCBHasChanged = FALSE;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000272 bRet = TRUE;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000273 }
274 else bRet = FALSE;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000275
276 dprintf_clipboard(stddeb,"%i\n", bRet);
277 return bRet;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000278}
279
280
281/**************************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000282 * CloseClipboard16 (USER.138)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000283 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000284BOOL16 WINAPI CloseClipboard16(void)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000285{
286 return CloseClipboard32();
287}
288
289
290/**************************************************************************
291 * CloseClipboard32 (USER32.53)
292 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000293BOOL32 WINAPI CloseClipboard32(void)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000294{
Alexandre Julliardaca05781994-10-17 18:12:41 +0000295 dprintf_clipboard(stddeb,"CloseClipboard(); !\n");
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000296
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000297 if (hqClipLock == GetTaskQueue(0))
298 {
299 hWndClipWindow = 0;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000300
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000301 if (bCBHasChanged && hWndViewer)
302 SendMessage16(hWndViewer, WM_DRAWCLIPBOARD, 0, 0L);
303 hqClipLock = 0;
304 }
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000305 return TRUE;
306}
307
308
309/**************************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000310 * EmptyClipboard16 (USER.139)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000311 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000312BOOL16 WINAPI EmptyClipboard16(void)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000313{
314 return EmptyClipboard32();
315}
316
317
318/**************************************************************************
319 * EmptyClipboard32 (USER32.168)
320 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000321BOOL32 WINAPI EmptyClipboard32(void)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000322{
323 LPCLIPFORMAT lpFormat = ClipFormats;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000324
325 dprintf_clipboard(stddeb,"EmptyClipboard()\n");
326
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000327 if (hqClipLock != GetTaskQueue(0)) return FALSE;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000328
329 /* destroy private objects */
330
331 if (hWndClipOwner)
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000332 SendMessage16(hWndClipOwner, WM_DESTROYCLIPBOARD, 0, 0L);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000333
334 while(lpFormat)
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000335 {
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000336 if ( lpFormat->wDataPresent || lpFormat->hData )
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000337 CLIPBOARD_DeleteRecord( lpFormat, TRUE );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000338
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000339 lpFormat = lpFormat->NextFormat;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000340 }
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000341
342 hWndClipOwner = hWndClipWindow;
343
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000344 if(selectionAcquired)
345 {
346 selectionAcquired = False;
347 selectionPrevWindow = selectionWindow;
348 selectionWindow = None;
349
350 dprintf_clipboard(stddeb, "\tgiving up selection (spw = %08x)\n",
351 (unsigned)selectionPrevWindow);
352
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000353 XSetSelectionOwner(display, XA_PRIMARY, None, CurrentTime);
Alexandre Julliard3a405ba1994-10-30 16:25:19 +0000354 }
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000355 return TRUE;
356}
357
358
359/**************************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000360 * GetClipboardOwner16 (USER.140)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000361 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000362HWND16 WINAPI GetClipboardOwner16(void)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000363{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000364 return hWndClipOwner;
365}
366
367
368/**************************************************************************
369 * GetClipboardOwner32 (USER32.224)
370 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000371HWND32 WINAPI GetClipboardOwner32(void)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000372{
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000373 return hWndClipOwner;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000374}
375
376
377/**************************************************************************
Alexandre Julliard21979011997-03-05 08:22:35 +0000378 * SetClipboardData16 (USER.141)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000379 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000380HANDLE16 WINAPI SetClipboardData16( UINT16 wFormat, HANDLE16 hData )
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000381{
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000382 LPCLIPFORMAT lpFormat = __lookup_format( ClipFormats, wFormat );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000383 Window owner;
384
Alexandre Julliardaca05781994-10-17 18:12:41 +0000385 dprintf_clipboard(stddeb,
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000386 "SetClipboardData(%04X, %04x) !\n", wFormat, hData);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000387
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000388 /* NOTE: If the hData is zero and current owner doesn't match
389 * the window that opened the clipboard then this application
390 * is screwed because WM_RENDERFORMAT will go to the owner
391 * (to become the owner it must call EmptyClipboard() before
392 * adding new data).
393 */
394
395 if( (hqClipLock != GetTaskQueue(0)) || !lpFormat ||
396 (!hData && (!hWndClipOwner || (hWndClipOwner != hWndClipWindow))) ) return 0;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000397
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000398 /* Acquire X selection if text format */
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000399
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000400 if( !selectionAcquired &&
401 (wFormat == CF_TEXT || wFormat == CF_OEMTEXT) )
402 {
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000403 owner = WIN_GetXWindow( hWndClipWindow ? hWndClipWindow : AnyPopup32() );
404 XSetSelectionOwner(display,XA_PRIMARY,owner,CurrentTime);
405 if( XGetSelectionOwner(display,XA_PRIMARY) == owner )
406 {
407 selectionAcquired = True;
408 selectionWindow = owner;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000409
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000410 dprintf_clipboard(stddeb,"Grabbed X selection, owner=(%08x)\n",
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000411 (unsigned) owner);
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000412 }
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000413 }
414
415 if ( lpFormat->wDataPresent || lpFormat->hData )
416 {
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000417 CLIPBOARD_DeleteRecord(lpFormat, TRUE);
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000418
419 /* delete existing CF_TEXT/CF_OEMTEXT aliases */
420
421 if( wFormat == CF_TEXT && ClipFormats[CF_OEMTEXT-1].hData
422 && !ClipFormats[CF_OEMTEXT-1].wDataPresent )
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000423 CLIPBOARD_DeleteRecord(&ClipFormats[CF_OEMTEXT-1], TRUE);
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000424 if( wFormat == CF_OEMTEXT && ClipFormats[CF_TEXT-1].hData
425 && !ClipFormats[CF_TEXT-1].wDataPresent )
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000426 CLIPBOARD_DeleteRecord(&ClipFormats[CF_TEXT-1], TRUE);
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000427 }
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000428
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000429 bCBHasChanged = TRUE;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000430 lpFormat->wDataPresent = 1;
431 lpFormat->hData = hData; /* 0 is legal, see WM_RENDERFORMAT */
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000432
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000433 return lpFormat->hData;
434}
435
Alexandre Julliard21979011997-03-05 08:22:35 +0000436
437/**************************************************************************
438 * SetClipboardData32 (USER32.469)
439 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000440HANDLE32 WINAPI SetClipboardData32( UINT32 wFormat, HANDLE32 hData )
Alexandre Julliard21979011997-03-05 08:22:35 +0000441{
442 fprintf( stderr, "SetClipboardData: empty stub\n" );
443 return 0;
444}
445
446
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000447/**************************************************************************
448 * CLIPBOARD_RenderFormat
449 */
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000450static BOOL32 CLIPBOARD_RenderFormat(LPCLIPFORMAT lpFormat)
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000451{
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000452 if( lpFormat->wDataPresent && !lpFormat->hData )
Alexandre Julliard21979011997-03-05 08:22:35 +0000453 if( IsWindow32(hWndClipOwner) )
Alexandre Julliard530ee841996-10-23 16:59:13 +0000454 SendMessage16(hWndClipOwner,WM_RENDERFORMAT,
455 (WPARAM16)lpFormat->wFormatID,0L);
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000456 else
457 {
458 dprintf_clipboard(stddeb,"\thWndClipOwner (%04x) is lost!\n",
459 hWndClipOwner);
460 hWndClipOwner = 0; lpFormat->wDataPresent = 0;
461 return FALSE;
462 }
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000463 return (lpFormat->hData) ? TRUE : FALSE;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000464}
465
466/**************************************************************************
467 * CLIPBOARD_RenderText
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000468 *
469 * Convert text between UNIX and DOS formats.
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000470 */
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000471static BOOL32 CLIPBOARD_RenderText(LPCLIPFORMAT lpTarget, LPCLIPFORMAT lpSource)
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000472{
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000473 UINT16 size = GlobalSize16( lpSource->hData );
474 LPCSTR lpstrS = (LPSTR)GlobalLock16(lpSource->hData);
475 LPSTR lpstrT;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000476
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000477 if( !lpstrS ) return FALSE;
478 dprintf_clipboard(stddeb,"\tconverting from '%s' to '%s', %i chars\n",
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000479 lpSource->Name, lpTarget->Name, size);
480
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000481 lpTarget->hData = GlobalAlloc16(GMEM_ZEROINIT, size);
482 lpstrT = (LPSTR)GlobalLock16(lpTarget->hData);
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000483
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000484 if( lpstrT )
485 {
486 if( lpSource->wFormatID == CF_TEXT )
487 CharToOemBuff32A(lpstrS, lpstrT, size);
488 else
489 OemToCharBuff32A(lpstrS, lpstrT, size);
490 dprintf_clipboard(stddeb,"\tgot %s\n", lpstrT);
491 return TRUE;
492 }
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000493
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000494 lpTarget->hData = 0;
495 return FALSE;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000496}
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000497
498/**************************************************************************
Alexandre Julliard21979011997-03-05 08:22:35 +0000499 * GetClipboardData16 (USER.142)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000500 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000501HANDLE16 WINAPI GetClipboardData16( UINT16 wFormat )
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000502{
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000503 LPCLIPFORMAT lpRender = ClipFormats;
504 LPCLIPFORMAT lpUpdate = NULL;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000505
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000506 if (hqClipLock != GetTaskQueue(0)) return 0;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000507
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000508 dprintf_clipboard(stddeb,"GetClipboardData(%04X)\n", wFormat);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000509
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000510 if( wFormat == CF_TEXT && !lpRender[CF_TEXT-1].wDataPresent
511 && lpRender[CF_OEMTEXT-1].wDataPresent )
512 {
513 lpRender = &ClipFormats[CF_OEMTEXT-1];
514 lpUpdate = &ClipFormats[CF_TEXT-1];
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000515
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000516 dprintf_clipboard(stddeb,"\tOEMTEXT -> TEXT\n");
517 }
518 else if( wFormat == CF_OEMTEXT && !lpRender[CF_OEMTEXT-1].wDataPresent
519 && lpRender[CF_TEXT-1].wDataPresent )
520 {
521 lpRender = &ClipFormats[CF_TEXT-1];
522 lpUpdate = &ClipFormats[CF_OEMTEXT-1];
523
524 dprintf_clipboard(stddeb,"\tTEXT -> OEMTEXT\n");
525 }
526 else
527 {
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000528 lpRender = __lookup_format( ClipFormats, wFormat );
529 lpUpdate = lpRender;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000530 }
531
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000532 if( !lpRender || !CLIPBOARD_RenderFormat(lpRender) ) return 0;
533 if( lpUpdate != lpRender && !lpUpdate->hData )
534 CLIPBOARD_RenderText(lpUpdate, lpRender);
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000535
536 dprintf_clipboard(stddeb,"\treturning %04x (type %i)\n",
537 lpUpdate->hData, lpUpdate->wFormatID);
538 return lpUpdate->hData;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000539}
540
541
542/**************************************************************************
Alexandre Julliard21979011997-03-05 08:22:35 +0000543 * GetClipboardData32 (USER32.221)
544 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000545HANDLE32 WINAPI GetClipboardData32( UINT32 wFormat )
Alexandre Julliard21979011997-03-05 08:22:35 +0000546{
547 fprintf( stderr, "GetClipboardData32: empty stub\n" );
548 return 0;
549}
550
551/**************************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000552 * CountClipboardFormats16 (USER.143)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000553 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000554INT16 WINAPI CountClipboardFormats16(void)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000555{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000556 return CountClipboardFormats32();
557}
558
559
560/**************************************************************************
561 * CountClipboardFormats32 (USER32.62)
562 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000563INT32 WINAPI CountClipboardFormats32(void)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000564{
565 INT32 FormatCount = 0;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000566 LPCLIPFORMAT lpFormat = ClipFormats;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000567
568 dprintf_clipboard(stddeb,"CountClipboardFormats()\n");
569
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000570 if( !selectionAcquired ) CLIPBOARD_RequestXSelection();
571
572 FormatCount += abs(lpFormat[CF_TEXT-1].wDataPresent -
573 lpFormat[CF_OEMTEXT-1].wDataPresent);
574
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000575 while(TRUE)
576 {
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000577 if (lpFormat == NULL) break;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000578 if (lpFormat->wDataPresent)
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000579 {
580 dprintf_clipboard(stddeb, "\tdata found for format %i\n", lpFormat->wFormatID);
581 FormatCount++;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000582 }
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000583 lpFormat = lpFormat->NextFormat;
584 }
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000585
586 dprintf_clipboard(stddeb,"\ttotal %d\n", FormatCount);
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000587 return FormatCount;
588}
589
590
591/**************************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000592 * EnumClipboardFormats16 (USER.144)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000593 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000594UINT16 WINAPI EnumClipboardFormats16( UINT16 wFormat )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000595{
596 return EnumClipboardFormats32( wFormat );
597}
598
599
600/**************************************************************************
601 * EnumClipboardFormats32 (USER32.178)
602 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000603UINT32 WINAPI EnumClipboardFormats32( UINT32 wFormat )
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000604{
605 LPCLIPFORMAT lpFormat = ClipFormats;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000606
607 dprintf_clipboard(stddeb,"EnumClipboardFormats(%04X)\n", wFormat);
608
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000609 if( hqClipLock != GetTaskQueue(0) ) return 0;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000610
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000611 if( (!wFormat || wFormat == CF_TEXT || wFormat == CF_OEMTEXT)
612 && !selectionAcquired) CLIPBOARD_RequestXSelection();
613
614 if (wFormat == 0)
615 if (lpFormat->wDataPresent || ClipFormats[CF_OEMTEXT-1].wDataPresent)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000616 return lpFormat->wFormatID;
617 else
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000618 wFormat = lpFormat->wFormatID; /* and CF_TEXT is not available */
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000619
620 /* walk up to the specified format record */
621
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000622 if( !(lpFormat = __lookup_format( lpFormat, wFormat )) ) return 0;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000623
624 /* find next format with available data */
625
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000626 lpFormat = lpFormat->NextFormat;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000627 while(TRUE)
628 {
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000629 if (lpFormat == NULL) return 0;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000630 if (lpFormat->wDataPresent || (lpFormat->wFormatID == CF_OEMTEXT &&
631 ClipFormats[CF_TEXT-1].wDataPresent))
632 break;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000633 lpFormat = lpFormat->NextFormat;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000634 }
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000635
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000636 return lpFormat->wFormatID;
637}
638
639
640/**************************************************************************
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000641 * RegisterClipboardFormat16 (USER.145)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000642 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000643UINT16 WINAPI RegisterClipboardFormat16( LPCSTR FormatName )
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000644{
645 LPCLIPFORMAT lpNewFormat;
646 LPCLIPFORMAT lpFormat = ClipFormats;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000647
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000648 if (FormatName == NULL) return 0;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000649
650 dprintf_clipboard(stddeb,"RegisterClipboardFormat('%s') !\n", FormatName);
651
652 /* walk format chain to see if it's already registered */
653
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000654 while(TRUE)
655 {
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000656 if ( !strcmp(lpFormat->Name,FormatName) )
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000657 {
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000658 lpFormat->wRefCount++;
659 return lpFormat->wFormatID;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000660 }
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000661
662 if ( lpFormat->NextFormat == NULL ) break;
663
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000664 lpFormat = lpFormat->NextFormat;
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000665 }
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000666
667 /* allocate storage for new format entry */
668
669 lpNewFormat = (LPCLIPFORMAT)xmalloc(sizeof(CLIPFORMAT));
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000670 lpFormat->NextFormat = lpNewFormat;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000671 lpNewFormat->wFormatID = LastRegFormat;
672 lpNewFormat->wRefCount = 1;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000673
674 lpNewFormat->Name = (LPSTR)xmalloc(strlen(FormatName) + 1);
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000675 strcpy(lpNewFormat->Name, FormatName);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000676
677 lpNewFormat->wDataPresent = 0;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000678 lpNewFormat->hData = 0;
679 lpNewFormat->BufSize = 0;
680 lpNewFormat->PrevFormat = lpFormat;
681 lpNewFormat->NextFormat = NULL;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000682
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000683 return LastRegFormat++;
684}
685
686
687/**************************************************************************
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000688 * RegisterClipboardFormat32A (USER32.430)
689 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000690UINT32 WINAPI RegisterClipboardFormat32A( LPCSTR formatName )
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000691{
692 return RegisterClipboardFormat16( formatName );
693}
694
695
696/**************************************************************************
697 * RegisterClipboardFormat32W (USER32.431)
698 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000699UINT32 WINAPI RegisterClipboardFormat32W( LPCWSTR formatName )
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000700{
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +0000701 LPSTR aFormat = HEAP_strdupWtoA( GetProcessHeap(), 0, formatName );
702 UINT32 ret = RegisterClipboardFormat32A( aFormat );
703 HeapFree( GetProcessHeap(), 0, aFormat );
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000704 return ret;
705}
706
707/**************************************************************************
Alexandre Julliard21979011997-03-05 08:22:35 +0000708 * GetClipboardFormatName16 (USER.146)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000709 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000710INT16 WINAPI GetClipboardFormatName16( UINT16 wFormat, LPSTR retStr, INT16 maxlen )
Alexandre Julliard21979011997-03-05 08:22:35 +0000711{
712 return GetClipboardFormatName32A( wFormat, retStr, maxlen );
713}
714
715
716/**************************************************************************
717 * GetClipboardFormatName32A (USER32.222)
718 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000719INT32 WINAPI GetClipboardFormatName32A( UINT32 wFormat, LPSTR retStr, INT32 maxlen )
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000720{
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000721 LPCLIPFORMAT lpFormat = __lookup_format( ClipFormats, wFormat );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000722
Alexandre Julliardaca05781994-10-17 18:12:41 +0000723 dprintf_clipboard(stddeb,
Alexandre Julliard21979011997-03-05 08:22:35 +0000724 "GetClipboardFormatName(%04X, %p, %d) !\n", wFormat, retStr, maxlen);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000725
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000726 if (lpFormat == NULL || lpFormat->Name == NULL ||
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000727 lpFormat->wFormatID < CF_REGFORMATBASE) return 0;
728
Alexandre Julliardaca05781994-10-17 18:12:41 +0000729 dprintf_clipboard(stddeb,
730 "GetClipboardFormat // Name='%s' !\n", lpFormat->Name);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000731
Alexandre Julliard21979011997-03-05 08:22:35 +0000732 lstrcpyn32A( retStr, lpFormat->Name, maxlen );
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000733 return strlen(retStr);
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000734}
735
736
737/**************************************************************************
Alexandre Julliard21979011997-03-05 08:22:35 +0000738 * GetClipboardFormatName32W (USER32.223)
739 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000740INT32 WINAPI GetClipboardFormatName32W( UINT32 wFormat, LPWSTR retStr, INT32 maxlen )
Alexandre Julliard21979011997-03-05 08:22:35 +0000741{
742 LPSTR p = HEAP_xalloc( GetProcessHeap(), 0, maxlen );
743 INT32 ret = GetClipboardFormatName32A( wFormat, p, maxlen );
744 lstrcpynAtoW( retStr, p, maxlen );
745 HeapFree( GetProcessHeap(), 0, p );
746 return ret;
747}
748
749
750/**************************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000751 * SetClipboardViewer16 (USER.147)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000752 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000753HWND16 WINAPI SetClipboardViewer16( HWND16 hWnd )
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000754{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000755 return SetClipboardViewer32( hWnd );
756}
757
758
759/**************************************************************************
760 * SetClipboardViewer32 (USER32.470)
761 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000762HWND32 WINAPI SetClipboardViewer32( HWND32 hWnd )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000763{
764 HWND32 hwndPrev = hWndViewer;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000765
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000766 dprintf_clipboard(stddeb,"SetClipboardViewer(%04x): returning %04x\n", hWnd, hwndPrev);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000767
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000768 hWndViewer = hWnd;
Alexandre Julliardecc37121994-11-22 16:31:29 +0000769 return hwndPrev;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000770}
771
772
773/**************************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000774 * GetClipboardViewer16 (USER.148)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000775 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000776HWND16 WINAPI GetClipboardViewer16(void)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000777{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000778 return hWndViewer;
779}
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000780
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000781
782/**************************************************************************
783 * GetClipboardViewer32 (USER32.225)
784 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000785HWND32 WINAPI GetClipboardViewer32(void)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000786{
Alexandre Julliardaca05781994-10-17 18:12:41 +0000787 return hWndViewer;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000788}
789
790
791/**************************************************************************
Alexandre Julliard21979011997-03-05 08:22:35 +0000792 * ChangeClipboardChain16 (USER.149)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000793 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000794BOOL16 WINAPI ChangeClipboardChain16(HWND16 hWnd, HWND16 hWndNext)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000795{
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000796 return ChangeClipboardChain32(hWnd, hWndNext);
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000797}
798
799/**************************************************************************
Alexandre Julliard21979011997-03-05 08:22:35 +0000800 * ChangeClipboardChain32 (USER32.21)
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000801 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000802BOOL32 WINAPI ChangeClipboardChain32(HWND32 hWnd, HWND32 hWndNext)
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000803{
804 BOOL32 bRet = 0;
Alexandre Julliard234bc241994-12-10 13:02:28 +0000805
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000806 dprintf_clipboard(stdnimp, "ChangeClipboardChain(%04x, %04x)\n", hWnd, hWndNext);
807
808 if( hWndViewer )
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000809 bRet = !SendMessage16( hWndViewer, WM_CHANGECBCHAIN,
Alexandre Julliard530ee841996-10-23 16:59:13 +0000810 (WPARAM16)hWnd, (LPARAM)hWndNext);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000811 else
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000812 dprintf_clipboard(stddeb,"ChangeClipboardChain: hWndViewer is lost\n");
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000813
814 if( hWnd == hWndViewer ) hWndViewer = hWndNext;
815
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000816 return bRet;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000817}
818
819
Alexandre Julliardc6c09441997-01-12 18:32:19 +0000820
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000821/**************************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000822 * IsClipboardFormatAvailable16 (USER.193)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000823 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000824BOOL16 WINAPI IsClipboardFormatAvailable16( UINT16 wFormat )
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000825{
826 return IsClipboardFormatAvailable32( wFormat );
827}
828
829
830/**************************************************************************
831 * IsClipboardFormatAvailable32 (USER32.339)
832 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000833BOOL32 WINAPI IsClipboardFormatAvailable32( UINT32 wFormat )
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000834{
Alexandre Julliardaca05781994-10-17 18:12:41 +0000835 dprintf_clipboard(stddeb,"IsClipboardFormatAvailable(%04X) !\n", wFormat);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000836
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000837 if( (wFormat == CF_TEXT || wFormat == CF_OEMTEXT) &&
838 !selectionAcquired ) CLIPBOARD_RequestXSelection();
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000839
840 return CLIPBOARD_IsPresent(wFormat);
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000841}
842
843
844/**************************************************************************
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000845 * GetOpenClipboardWindow16 (USER.248)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000846 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000847HWND16 WINAPI GetOpenClipboardWindow16(void)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000848{
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000849 return hWndClipWindow;
850}
851
852
853/**************************************************************************
854 * GetOpenClipboardWindow32 (USER32.276)
855 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000856HWND32 WINAPI GetOpenClipboardWindow32(void)
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000857{
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000858 return hWndClipWindow;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000859}
860
861
862/**************************************************************************
Alexandre Julliard21979011997-03-05 08:22:35 +0000863 * GetPriorityClipboardFormat16 (USER.402)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000864 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000865INT16 WINAPI GetPriorityClipboardFormat16( UINT16 *lpPriorityList, INT16 nCount)
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000866{
Alexandre Julliard21979011997-03-05 08:22:35 +0000867 fprintf( stderr, "GetPriorityClipboardFormat16(%p, %d): stub\n",
868 lpPriorityList, nCount );
869 return 0;
870}
Alexandre Julliard234bc241994-12-10 13:02:28 +0000871
Alexandre Julliard21979011997-03-05 08:22:35 +0000872
873/**************************************************************************
Alexandre Julliard0623a6f1998-01-18 18:01:49 +0000874 * GetPriorityClipboardFormat32 (USER32.279)
Alexandre Julliard21979011997-03-05 08:22:35 +0000875 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000876INT32 WINAPI GetPriorityClipboardFormat32( UINT32 *lpPriorityList, INT32 nCount )
Alexandre Julliard21979011997-03-05 08:22:35 +0000877{
Alexandre Julliard0623a6f1998-01-18 18:01:49 +0000878 int Counter;
879
880 if(CountClipboardFormats32() == 0)
881 {
882 return 0;
883 }
884
885 for(Counter = 0; Counter <= nCount; Counter++)
886 {
887 if(IsClipboardFormatAvailable32(*(lpPriorityList+sizeof(INT32)*Counter)))
888 return *(lpPriorityList+sizeof(INT32)*Counter);
889 }
890
891 return -1;
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000892}
893
894
Alexandre Julliard3a405ba1994-10-30 16:25:19 +0000895/**************************************************************************
896 * CLIPBOARD_ReadSelection
897 *
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000898 * Called from the SelectionNotify event handler.
Alexandre Julliard3a405ba1994-10-30 16:25:19 +0000899 */
900void CLIPBOARD_ReadSelection(Window w,Atom prop)
901{
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000902 HANDLE16 hText = 0;
Alexandre Julliard3a405ba1994-10-30 16:25:19 +0000903 LPCLIPFORMAT lpFormat = ClipFormats;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000904
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000905 dprintf_clipboard(stddeb,"ReadSelection callback\n");
906
907 if(prop != None)
908 {
909 Atom atype=AnyPropertyType;
910 int aformat;
911 unsigned long nitems,remain;
912 unsigned char* val=NULL;
913
914 dprintf_clipboard(stddeb,"\tgot property %s\n",XGetAtomName(display,prop));
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000915
Alexandre Julliard3a405ba1994-10-30 16:25:19 +0000916 /* TODO: Properties longer than 64K */
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000917
Alexandre Julliard3a405ba1994-10-30 16:25:19 +0000918 if(XGetWindowProperty(display,w,prop,0,0x3FFF,True,XA_STRING,
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000919 &atype, &aformat, &nitems, &remain, &val) != Success)
920 dprintf_clipboard(stddeb,"\tcouldn't read property\n");
921 else
922 {
923 dprintf_clipboard(stddeb,"\tType %s,Format %d,nitems %ld,value %s\n",
924 XGetAtomName(display,atype),aformat,nitems,val);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000925
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000926 if(atype == XA_STRING && aformat == 8)
927 {
928 int i,inlcount = 0;
929 char* lpstr;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000930
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000931 dprintf_clipboard(stddeb,"\tselection is '%s'\n",val);
932
933 for(i=0; i <= nitems; i++)
934 if( val[i] == '\n' ) inlcount++;
935
936 if( nitems )
937 {
938 hText=GlobalAlloc16(GMEM_MOVEABLE, nitems + inlcount + 1);
939 if( (lpstr = (char*)GlobalLock16(hText)) )
940 for(i=0,inlcount=0; i <= nitems; i++)
941 {
942 if( val[i] == '\n' ) lpstr[inlcount++]='\r';
943 lpstr[inlcount++]=val[i];
944 }
945 else hText = 0;
946 }
947 }
948 XFree(val);
Alexandre Julliard3a405ba1994-10-30 16:25:19 +0000949 }
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000950 }
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000951
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000952 /* delete previous CF_TEXT and CF_OEMTEXT data */
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000953
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000954 if( hText )
955 {
956 lpFormat = &ClipFormats[CF_TEXT-1];
957 if (lpFormat->wDataPresent || lpFormat->hData)
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000958 CLIPBOARD_DeleteRecord(lpFormat, !(hWndClipWindow));
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000959 lpFormat = &ClipFormats[CF_OEMTEXT-1];
960 if (lpFormat->wDataPresent || lpFormat->hData)
Alexandre Julliarddf2673b1997-03-29 17:20:20 +0000961 CLIPBOARD_DeleteRecord(lpFormat, !(hWndClipWindow));
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000962
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000963 lpFormat->wDataPresent = 1;
964 lpFormat->hData = hText;
965 }
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000966
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000967 selectionWait=False;
Alexandre Julliard3a405ba1994-10-30 16:25:19 +0000968}
Alexandre Julliardfb9a9191994-03-01 19:48:04 +0000969
Alexandre Julliard3a405ba1994-10-30 16:25:19 +0000970/**************************************************************************
971 * CLIPBOARD_ReleaseSelection
972 *
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000973 * Wine might have lost XA_PRIMARY selection because of
974 * EmptyClipboard() or other client.
Alexandre Julliard3a405ba1994-10-30 16:25:19 +0000975 */
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000976void CLIPBOARD_ReleaseSelection(Window w, HWND32 hwnd)
Alexandre Julliard3a405ba1994-10-30 16:25:19 +0000977{
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000978 /* w is the window that lost selection,
979 *
980 * selectionPrevWindow is nonzero if CheckSelection() was called.
981 */
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000982
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000983 dprintf_clipboard(stddeb,"\tevent->window = %08x (sw = %08x, spw=%08x)\n",
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000984 (unsigned)w, (unsigned)selectionWindow, (unsigned)selectionPrevWindow );
985
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000986 if( selectionAcquired )
987 if( w == selectionWindow || selectionPrevWindow == None)
988 {
989 /* alright, we really lost it */
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000990
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000991 selectionAcquired = False;
992 selectionWindow = None;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000993
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +0000994 /* but we'll keep existing data for internal use */
995 }
996 else if( w == selectionPrevWindow )
997 {
998 w = XGetSelectionOwner(display, XA_PRIMARY);
999 if( w == None )
1000 XSetSelectionOwner(display, XA_PRIMARY, selectionWindow, CurrentTime);
1001 }
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +00001002
Alexandre Julliarda0b2b1d1997-11-16 17:38:29 +00001003 selectionPrevWindow = None;
Alexandre Julliard3a405ba1994-10-30 16:25:19 +00001004}
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +00001005