Release 960928
[wine/multimedia.git] / misc / clipboard.c
blob03d80ca70b3886a6ebe8dd06e580cd54b5787f81
1 /*
2 * 'Wine' Clipboard function handling
4 * Copyright 1994 Martin Ayotte
5 * 1996 Alex Korobka
7 */
9 #include <stdlib.h>
10 #include <stdio.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <fcntl.h>
14 #include <unistd.h>
15 #include <string.h>
16 #include <X11/Xlib.h>
17 #include <X11/Xatom.h>
18 #include "windows.h"
19 #include "win.h"
20 #include "message.h"
21 #include "clipboard.h"
22 #include "xmalloc.h"
23 #include "stddebug.h"
24 #include "debug.h"
26 #define CF_REGFORMATBASE 0xC000
28 typedef struct tagCLIPFORMAT {
29 WORD wFormatID;
30 WORD wRefCount;
31 WORD wDataPresent;
32 LPSTR Name;
33 HANDLE16 hData;
34 DWORD BufSize;
35 struct tagCLIPFORMAT *PrevFormat;
36 struct tagCLIPFORMAT *NextFormat;
37 } CLIPFORMAT, *LPCLIPFORMAT;
39 /* *************************************************************************
40 * internal variables
43 static HWND hWndClipOwner = 0; /* current clipboard owner */
44 static HWND hWndClipWindow = 0; /* window that opened clipboard */
45 static HWND hWndViewer = 0; /* start of viewers chain */
47 static BOOL bClipChanged = FALSE;
48 static WORD LastRegFormat = CF_REGFORMATBASE;
50 static Bool selectionWait = False;
51 static Bool selectionAcquired = False;
52 static Window selectionWindow = None;
53 static Window selectionPrevWindow = None;
55 static CLIPFORMAT ClipFormats[16] = {
56 { CF_TEXT, 1, 0, "Text", (HANDLE16)NULL, 0, NULL, &ClipFormats[1] },
57 { CF_BITMAP, 1, 0, "Bitmap", (HANDLE16)NULL, 0, &ClipFormats[0], &ClipFormats[2] },
58 { CF_METAFILEPICT, 1, 0, "MetaFile Picture", (HANDLE16)NULL, 0, &ClipFormats[1], &ClipFormats[3] },
59 { CF_SYLK, 1, 0, "Sylk", (HANDLE16)NULL, 0, &ClipFormats[2], &ClipFormats[4] },
60 { CF_DIF, 1, 0, "DIF", (HANDLE16)NULL, 0, &ClipFormats[3], &ClipFormats[5] },
61 { CF_TIFF, 1, 0, "TIFF", (HANDLE16)NULL, 0, &ClipFormats[4], &ClipFormats[6] },
62 { CF_OEMTEXT, 1, 0, "OEM Text", (HANDLE16)NULL, 0, &ClipFormats[5], &ClipFormats[7] },
63 { CF_DIB, 1, 0, "DIB", (HANDLE16)NULL, 0, &ClipFormats[6], &ClipFormats[8] },
64 { CF_PALETTE, 1, 0, "Palette", (HANDLE16)NULL, 0, &ClipFormats[7], &ClipFormats[9] },
65 { CF_PENDATA, 1, 0, "PenData", (HANDLE16)NULL, 0, &ClipFormats[8], &ClipFormats[10] },
66 { CF_RIFF, 1, 0, "RIFF", (HANDLE16)NULL, 0, &ClipFormats[9], &ClipFormats[11] },
67 { CF_WAVE, 1, 0, "Wave", (HANDLE16)NULL, 0, &ClipFormats[10], &ClipFormats[12] },
68 { CF_OWNERDISPLAY, 1, 0, "Owner Display", (HANDLE16)NULL, 0, &ClipFormats[11], &ClipFormats[13] },
69 { CF_DSPTEXT, 1, 0, "DSPText", (HANDLE16)NULL, 0, &ClipFormats[12], &ClipFormats[14] },
70 { CF_DSPMETAFILEPICT, 1, 0, "DSPMetaFile Picture", (HANDLE16)NULL, 0, &ClipFormats[13], &ClipFormats[15] },
71 { CF_DSPBITMAP, 1, 0, "DSPBitmap", (HANDLE16)NULL, 0, &ClipFormats[14], NULL }
74 /**************************************************************************
75 * CLIPBOARD_CheckSelection
77 void CLIPBOARD_CheckSelection(WND* pWnd)
79 dprintf_clipboard(stddeb,"\tchecking %08x\n", (unsigned)pWnd->window);
81 if( selectionAcquired && selectionWindow != None &&
82 pWnd->window == selectionWindow )
84 selectionPrevWindow = selectionWindow;
85 selectionWindow = None;
87 if( pWnd->next )
88 selectionWindow = pWnd->next->window;
89 else if( pWnd->parent )
90 if( pWnd->parent->child != pWnd )
91 selectionWindow = pWnd->parent->child->window;
93 dprintf_clipboard(stddeb,"\tswitching selection from %08x to %08x\n",
94 (unsigned)selectionPrevWindow, (unsigned)selectionWindow);
96 if( selectionWindow != None )
98 XSetSelectionOwner(display, XA_PRIMARY, selectionWindow, CurrentTime);
99 if( XGetSelectionOwner(display, XA_PRIMARY) != selectionWindow )
100 selectionWindow = None;
105 /**************************************************************************
106 * CLIPBOARD_DisOwn
108 * Called from DestroyWindow().
110 void CLIPBOARD_DisOwn(WND* pWnd)
112 LPCLIPFORMAT lpFormat = ClipFormats;
114 dprintf_clipboard(stddeb,"DisOwn: clipboard owner = %04x, sw = %08x\n",
115 hWndClipOwner, (unsigned)selectionWindow);
117 if( pWnd->hwndSelf == hWndClipOwner)
119 SendMessage16(hWndClipOwner,WM_RENDERALLFORMATS,0,0L);
121 /* check if all formats were rendered */
123 while(lpFormat)
125 if( lpFormat->wDataPresent && !lpFormat->hData )
127 dprintf_clipboard(stddeb,"\tdata missing for clipboard format %i\n", lpFormat->wFormatID);
128 lpFormat->wDataPresent = 0;
130 lpFormat = lpFormat->NextFormat;
132 hWndClipOwner = 0;
135 /* now try to salvage current selection from being destroyed by X */
137 CLIPBOARD_CheckSelection(pWnd);
140 /**************************************************************************
141 * CLIPBOARD_DeleteRecord
143 void CLIPBOARD_DeleteRecord(LPCLIPFORMAT lpFormat)
145 if( lpFormat->wFormatID >= CF_GDIOBJFIRST &&
146 lpFormat->wFormatID <= CF_GDIOBJLAST )
147 DeleteObject(lpFormat->hData);
148 else if( lpFormat->hData )
149 GlobalFree16(lpFormat->hData);
151 lpFormat->wDataPresent = 0;
152 lpFormat->hData = 0;
154 bClipChanged = TRUE;
157 /**************************************************************************
158 * CLIPBOARD_RequestXSelection
160 BOOL CLIPBOARD_RequestXSelection()
162 HWND hWnd = (hWndClipWindow) ? hWndClipWindow : GetActiveWindow();
164 if( !hWnd ) return FALSE;
166 dprintf_clipboard(stddeb,"Requesting selection...\n");
168 /* request data type XA_STRING, later
169 * CLIPBOARD_ReadSelection() will be invoked
170 * from the SelectionNotify event handler */
172 XConvertSelection(display,XA_PRIMARY,XA_STRING,
173 XInternAtom(display,"PRIMARY_TEXT",False),
174 WIN_GetXWindow(hWnd),CurrentTime);
176 /* wait until SelectionNotify is processed */
178 selectionWait=True;
179 while(selectionWait)
180 EVENT_WaitXEvent( TRUE, FALSE );
182 /* we treat Unix text as CF_OEMTEXT */
183 dprintf_clipboard(stddeb,"\tgot CF_OEMTEXT = %i\n",
184 ClipFormats[CF_OEMTEXT-1].wDataPresent);
186 return (BOOL)ClipFormats[CF_OEMTEXT-1].wDataPresent;
189 /**************************************************************************
190 * CLIPBOARD_IsPresent
192 BOOL CLIPBOARD_IsPresent(WORD wFormat)
194 LPCLIPFORMAT lpFormat = ClipFormats;
196 /* special case */
198 if( wFormat == CF_TEXT || wFormat == CF_OEMTEXT )
199 return lpFormat[CF_TEXT-1].wDataPresent |
200 lpFormat[CF_OEMTEXT-1].wDataPresent;
202 while(TRUE) {
203 if (lpFormat == NULL) return FALSE;
204 if (lpFormat->wFormatID == wFormat) break;
205 lpFormat = lpFormat->NextFormat;
208 return (lpFormat->wDataPresent);
211 /**************************************************************************
212 * OpenClipboard [USER.137]
214 BOOL OpenClipboard(HWND hWnd)
216 BOOL bRet = FALSE;
217 dprintf_clipboard(stddeb,"OpenClipboard(%04x) = ", hWnd);
219 if (!hWndClipWindow)
221 hWndClipWindow = hWnd;
222 bRet = TRUE;
224 bClipChanged = FALSE;
226 dprintf_clipboard(stddeb,"%i\n", bRet);
227 return bRet;
231 /**************************************************************************
232 * CloseClipboard [USER.138]
234 BOOL CloseClipboard()
236 dprintf_clipboard(stddeb,"CloseClipboard(); !\n");
238 if (hWndClipWindow == 0) return FALSE;
239 hWndClipWindow = 0;
241 if (bClipChanged && hWndViewer) SendMessage16(hWndViewer,WM_DRAWCLIPBOARD,0,0L);
243 return TRUE;
247 /**************************************************************************
248 * EmptyClipboard [USER.139]
250 BOOL EmptyClipboard()
252 LPCLIPFORMAT lpFormat = ClipFormats;
254 dprintf_clipboard(stddeb,"EmptyClipboard()\n");
256 if (hWndClipWindow == 0) return FALSE;
258 /* destroy private objects */
260 if (hWndClipOwner)
261 SendMessage16(hWndClipOwner,WM_DESTROYCLIPBOARD,0,0L);
263 while(lpFormat)
265 if ( lpFormat->wDataPresent || lpFormat->hData )
266 CLIPBOARD_DeleteRecord( lpFormat );
268 lpFormat = lpFormat->NextFormat;
271 hWndClipOwner = hWndClipWindow;
273 if(selectionAcquired)
275 selectionAcquired = False;
276 selectionPrevWindow = selectionWindow;
277 selectionWindow = None;
279 dprintf_clipboard(stddeb, "\tgiving up selection (spw = %08x)\n",
280 (unsigned)selectionPrevWindow);
282 XSetSelectionOwner(display,XA_PRIMARY,None,CurrentTime);
284 return TRUE;
288 /**************************************************************************
289 * GetClipboardOwner [USER.140]
291 HWND GetClipboardOwner()
293 dprintf_clipboard(stddeb,
294 "GetClipboardOwner() = %04x !\n", hWndClipOwner);
295 return hWndClipOwner;
299 /**************************************************************************
300 * SetClipboardData [USER.141]
302 HANDLE SetClipboardData(WORD wFormat, HANDLE hData)
304 LPCLIPFORMAT lpFormat = ClipFormats;
305 Window owner;
307 dprintf_clipboard(stddeb,
308 "SetClipboardData(%04X, %04x) !\n", wFormat, hData);
310 while(TRUE)
312 if (lpFormat == NULL) return 0;
313 if (lpFormat->wFormatID == wFormat) break;
314 lpFormat = lpFormat->NextFormat;
317 /* Acquire X selection if text format */
319 if( !selectionAcquired &&
320 (wFormat == CF_TEXT || wFormat == CF_OEMTEXT) )
322 owner = WIN_GetXWindow(hWndClipWindow);
323 XSetSelectionOwner(display,XA_PRIMARY,owner,CurrentTime);
324 if( XGetSelectionOwner(display,XA_PRIMARY) == owner )
326 selectionAcquired = True;
327 selectionWindow = owner;
329 dprintf_clipboard(stddeb,"Grabbed X selection, owner=(%08x)\n",
330 (unsigned) owner);
334 if ( lpFormat->wDataPresent || lpFormat->hData )
336 CLIPBOARD_DeleteRecord(lpFormat);
338 /* delete existing CF_TEXT/CF_OEMTEXT aliases */
340 if( wFormat == CF_TEXT && ClipFormats[CF_OEMTEXT-1].hData
341 && !ClipFormats[CF_OEMTEXT-1].wDataPresent )
342 CLIPBOARD_DeleteRecord(&ClipFormats[CF_OEMTEXT-1]);
343 if( wFormat == CF_OEMTEXT && ClipFormats[CF_TEXT-1].hData
344 && !ClipFormats[CF_TEXT-1].wDataPresent )
345 CLIPBOARD_DeleteRecord(&ClipFormats[CF_TEXT-1]);
348 bClipChanged = TRUE;
349 lpFormat->wDataPresent = 1;
350 lpFormat->hData = hData; /* 0 is legal, see WM_RENDERFORMAT */
352 return lpFormat->hData;
355 /**************************************************************************
356 * CLIPBOARD_RenderFormat
358 BOOL32 CLIPBOARD_RenderFormat(LPCLIPFORMAT lpFormat)
360 if( lpFormat->wDataPresent && !lpFormat->hData )
361 if( IsWindow(hWndClipOwner) )
362 SendMessage16(hWndClipOwner,WM_RENDERFORMAT,(WPARAM)lpFormat->wFormatID,0L);
363 else
365 dprintf_clipboard(stddeb,"\thWndClipOwner (%04x) is lost!\n",
366 hWndClipOwner);
367 hWndClipOwner = 0; lpFormat->wDataPresent = 0;
368 return FALSE;
370 return (lpFormat->hData) ? TRUE : FALSE;
373 /**************************************************************************
374 * CLIPBOARD_RenderText
376 BOOL32 CLIPBOARD_RenderText(LPCLIPFORMAT lpTarget, LPCLIPFORMAT lpSource)
378 UINT size = GlobalSize16( lpSource->hData );
379 LPCSTR lpstrS = (LPSTR)GlobalLock16(lpSource->hData);
380 LPSTR lpstrT;
382 if( !lpstrS ) return FALSE;
383 dprintf_clipboard(stddeb,"\tconverting from '%s' to '%s', %i chars\n",
384 lpSource->Name, lpTarget->Name, size);
386 lpTarget->hData = GlobalAlloc16(GMEM_ZEROINIT, size);
387 lpstrT = (LPSTR)GlobalLock16(lpTarget->hData);
389 if( lpstrT )
391 if( lpSource->wFormatID == CF_TEXT )
392 AnsiToOemBuff(lpstrS, lpstrT, size);
393 else
394 OemToAnsiBuff(lpstrS, lpstrT, size);
395 dprintf_clipboard(stddeb,"\tgot %s\n", lpstrT);
396 return TRUE;
399 lpTarget->hData = 0;
400 return FALSE;
403 /**************************************************************************
404 * GetClipboardData [USER.142]
406 HANDLE GetClipboardData(WORD wFormat)
408 LPCLIPFORMAT lpRender = ClipFormats;
409 LPCLIPFORMAT lpUpdate = NULL;
411 if (!hWndClipWindow) return 0;
413 dprintf_clipboard(stddeb,"GetClipboardData(%04X)\n", wFormat);
415 if( wFormat == CF_TEXT && !lpRender[CF_TEXT-1].wDataPresent
416 && lpRender[CF_OEMTEXT-1].wDataPresent )
418 lpRender = &ClipFormats[CF_OEMTEXT-1];
419 lpUpdate = &ClipFormats[CF_TEXT-1];
421 dprintf_clipboard(stddeb,"\tOEMTEXT -> TEXT\n");
423 else if( wFormat == CF_OEMTEXT && !lpRender[CF_OEMTEXT-1].wDataPresent
424 && lpRender[CF_TEXT-1].wDataPresent )
426 lpRender = &ClipFormats[CF_TEXT-1];
427 lpUpdate = &ClipFormats[CF_OEMTEXT-1];
429 dprintf_clipboard(stddeb,"\tTEXT -> OEMTEXT\n");
431 else
433 while(TRUE)
435 if (lpRender == NULL) return 0;
436 if (lpRender->wFormatID == wFormat) break;
437 lpRender = lpRender->NextFormat;
439 lpUpdate = lpRender;
442 if( !CLIPBOARD_RenderFormat(lpRender) ) return 0;
443 if( lpUpdate != lpRender &&
444 !lpUpdate->hData ) CLIPBOARD_RenderText(lpUpdate, lpRender);
446 dprintf_clipboard(stddeb,"\treturning %04x (type %i)\n",
447 lpUpdate->hData, lpUpdate->wFormatID);
448 return lpUpdate->hData;
452 /**************************************************************************
453 * CountClipboardFormats [USER.143]
455 INT CountClipboardFormats()
457 int FormatCount = 0;
458 LPCLIPFORMAT lpFormat = ClipFormats;
460 dprintf_clipboard(stddeb,"CountClipboardFormats()\n");
462 if( !selectionAcquired ) CLIPBOARD_RequestXSelection();
464 FormatCount += abs(lpFormat[CF_TEXT-1].wDataPresent -
465 lpFormat[CF_OEMTEXT-1].wDataPresent);
467 while(TRUE) {
468 if (lpFormat == NULL) break;
469 if (lpFormat->wDataPresent)
471 dprintf_clipboard(stddeb, "\tdata found for format %i\n", lpFormat->wFormatID);
473 FormatCount++;
475 lpFormat = lpFormat->NextFormat;
478 dprintf_clipboard(stddeb,"\ttotal %d\n", FormatCount);
479 return FormatCount;
483 /**************************************************************************
484 * EnumClipboardFormats [USER.144]
486 UINT16 EnumClipboardFormats(UINT16 wFormat)
488 LPCLIPFORMAT lpFormat = ClipFormats;
490 dprintf_clipboard(stddeb,"EnumClipboardFormats(%04X)\n", wFormat);
492 if( !hWndClipWindow ) return 0;
494 if( (!wFormat || wFormat == CF_TEXT || wFormat == CF_OEMTEXT)
495 && !selectionAcquired) CLIPBOARD_RequestXSelection();
497 if (wFormat == 0)
498 if (lpFormat->wDataPresent || ClipFormats[CF_OEMTEXT-1].wDataPresent)
499 return lpFormat->wFormatID;
500 else
501 wFormat = lpFormat->wFormatID; /* and CF_TEXT is not available */
503 /* walk up to the specified format record */
505 while(TRUE) {
506 if (lpFormat == NULL) return 0;
507 if (lpFormat->wFormatID == wFormat) break;
508 lpFormat = lpFormat->NextFormat;
511 /* find next format with available data */
513 lpFormat = lpFormat->NextFormat;
514 while(TRUE) {
515 if (lpFormat == NULL) return 0;
516 if (lpFormat->wDataPresent ||
517 (lpFormat->wFormatID == CF_OEMTEXT &&
518 ClipFormats[CF_TEXT-1].wDataPresent)) break;
519 lpFormat = lpFormat->NextFormat;
522 return lpFormat->wFormatID;
526 /**************************************************************************
527 * RegisterClipboardFormat [USER.145]
529 WORD RegisterClipboardFormat(LPCSTR FormatName)
531 LPCLIPFORMAT lpNewFormat;
532 LPCLIPFORMAT lpFormat = ClipFormats;
534 if (FormatName == NULL) return 0;
536 dprintf_clipboard(stddeb,"RegisterClipboardFormat('%s') !\n", FormatName);
538 /* walk format chain to see if it's already registered */
540 while(TRUE) {
541 if ( !strcmp(lpFormat->Name,FormatName) )
543 lpFormat->wRefCount++;
544 return lpFormat->wFormatID;
547 if ( lpFormat->NextFormat == NULL ) break;
549 lpFormat = lpFormat->NextFormat;
552 /* allocate storage for new format entry */
554 lpNewFormat = (LPCLIPFORMAT)xmalloc(sizeof(CLIPFORMAT));
555 lpFormat->NextFormat = lpNewFormat;
556 lpNewFormat->wFormatID = LastRegFormat;
557 lpNewFormat->wRefCount = 1;
559 lpNewFormat->Name = (LPSTR)xmalloc(strlen(FormatName) + 1);
560 strcpy(lpNewFormat->Name, FormatName);
562 lpNewFormat->wDataPresent = 0;
563 lpNewFormat->hData = 0;
564 lpNewFormat->BufSize = 0;
565 lpNewFormat->PrevFormat = lpFormat;
566 lpNewFormat->NextFormat = NULL;
568 return LastRegFormat++;
572 /**************************************************************************
573 * GetClipboardFormatName [USER.146]
575 int GetClipboardFormatName(WORD wFormat, LPSTR retStr, short maxlen)
577 LPCLIPFORMAT lpFormat = ClipFormats;
579 dprintf_clipboard(stddeb,
580 "GetClipboardFormat(%04X, %p, %d) !\n", wFormat, retStr, maxlen);
582 while(TRUE) {
583 if (lpFormat == NULL) return 0;
584 if (lpFormat->wFormatID == wFormat) break;
585 lpFormat = lpFormat->NextFormat;
588 if (lpFormat->Name == NULL ||
589 lpFormat->wFormatID < CF_REGFORMATBASE) return 0;
591 dprintf_clipboard(stddeb,
592 "GetClipboardFormat // Name='%s' !\n", lpFormat->Name);
594 strncpy(retStr, lpFormat->Name, maxlen - 1);
595 retStr[maxlen] = 0;
597 return strlen(retStr);
601 /**************************************************************************
602 * SetClipboardViewer [USER.147]
604 HWND SetClipboardViewer(HWND hWnd)
606 HWND hwndPrev = hWndViewer;
608 dprintf_clipboard(stddeb,"SetClipboardViewer(%04x)\n", hWnd);
610 hWndViewer = hWnd;
611 return hwndPrev;
615 /**************************************************************************
616 * GetClipboardViewer [USER.148]
618 HWND GetClipboardViewer()
620 dprintf_clipboard(stddeb,"GetClipboardFormat() = %04x\n", hWndViewer);
622 return hWndViewer;
626 /**************************************************************************
627 * ChangeClipboardChain [USER.149]
629 BOOL ChangeClipboardChain(HWND hWnd, HWND hWndNext)
631 BOOL bRet = 0;
633 dprintf_clipboard(stdnimp, "ChangeClipboardChain(%04x, %04x)\n", hWnd, hWndNext);
635 if( hWndViewer )
636 bRet = !SendMessage16( hWndViewer, WM_CHANGECBCHAIN, (WPARAM)hWnd, (LPARAM)hWndNext);
637 else
638 dprintf_clipboard(stddeb,"ChangeClipboardChain: hWndViewer is lost\n");
640 if( hWnd == hWndViewer ) hWndViewer = hWndNext;
642 return 0;
646 /**************************************************************************
647 * IsClipboardFormatAvailable [USER.193]
649 BOOL IsClipboardFormatAvailable(WORD wFormat)
651 dprintf_clipboard(stddeb,"IsClipboardFormatAvailable(%04X) !\n", wFormat);
653 if( (wFormat == CF_TEXT || wFormat == CF_OEMTEXT) &&
654 !selectionAcquired ) CLIPBOARD_RequestXSelection();
656 return CLIPBOARD_IsPresent(wFormat);
660 /**************************************************************************
661 * GetOpenClipboardWindow [USER.248]
663 HWND GetOpenClipboardWindow()
665 dprintf_clipboard(stddeb,
666 "GetOpenClipboardWindow() = %04x\n", hWndClipWindow);
667 return hWndClipWindow;
671 /**************************************************************************
672 * GetPriorityClipboardFormat [USER.402]
674 int GetPriorityClipboardFormat(WORD *lpPriorityList, short nCount)
676 dprintf_clipboard(stdnimp,
677 "GetPriorityClipboardFormat(%p, %d) !\n", lpPriorityList, nCount);
679 return 0;
683 /**************************************************************************
684 * CLIPBOARD_ReadSelection
686 * Called from the SelectionNotify event handler.
688 void CLIPBOARD_ReadSelection(Window w,Atom prop)
690 HANDLE16 hText = 0;
691 LPCLIPFORMAT lpFormat = ClipFormats;
693 dprintf_clipboard(stddeb,"ReadSelection callback\n");
695 if(prop != None)
697 Atom atype=AnyPropertyType;
698 int aformat;
699 unsigned long nitems,remain;
700 unsigned char* val=NULL;
702 dprintf_clipboard(stddeb,"\tgot property %s\n",XGetAtomName(display,prop));
704 /* TODO: Properties longer than 64K */
706 if(XGetWindowProperty(display,w,prop,0,0x3FFF,True,XA_STRING,
707 &atype, &aformat, &nitems, &remain, &val) != Success)
708 dprintf_clipboard(stddeb,"\tcouldn't read property\n");
709 else
711 dprintf_clipboard(stddeb,"\tType %s,Format %d,nitems %ld,value %s\n",
712 XGetAtomName(display,atype),aformat,nitems,val);
714 if(atype == XA_STRING && aformat == 8)
716 int i,inlcount = 0;
717 char* lpstr;
719 dprintf_clipboard(stddeb,"\tselection is '%s'\n",val);
721 for(i=0; i <= nitems; i++)
722 if( val[i] == '\n' ) inlcount++;
724 if( nitems )
726 hText=GlobalAlloc16(GMEM_MOVEABLE, nitems + inlcount + 1);
727 if( (lpstr = (char*)GlobalLock16(hText)) )
728 for(i=0,inlcount=0; i <= nitems; i++)
730 if( val[i] == '\n' ) lpstr[inlcount++]='\r';
731 lpstr[inlcount++]=val[i];
733 else hText = 0;
736 XFree(val);
740 /* delete previous CF_TEXT and CF_OEMTEXT data */
742 if( hText )
744 lpFormat = &ClipFormats[CF_TEXT-1];
745 if (lpFormat->wDataPresent || lpFormat->hData)
746 CLIPBOARD_DeleteRecord(lpFormat);
747 lpFormat = &ClipFormats[CF_OEMTEXT-1];
748 if (lpFormat->wDataPresent || lpFormat->hData)
749 CLIPBOARD_DeleteRecord(lpFormat);
751 lpFormat->wDataPresent = 1;
752 lpFormat->hData = hText;
755 selectionWait=False;
758 /**************************************************************************
759 * CLIPBOARD_ReleaseSelection
761 * Wine might have lost XA_PRIMARY selection because of
762 * EmptyClipboard() or other client.
764 void CLIPBOARD_ReleaseSelection(Window w, HWND hwnd)
766 /* w is the window that lost selection,
768 * selectionPrevWindow is nonzero if CheckSelection() was called.
771 dprintf_clipboard(stddeb,"\tevent->window = %08x (sw = %08x, spw=%08x)\n",
772 (unsigned)w, (unsigned)selectionWindow, (unsigned)selectionPrevWindow );
774 if( selectionAcquired )
775 if( w == selectionWindow || selectionPrevWindow == None)
777 /* alright, we really lost it */
779 selectionAcquired = False;
780 selectionWindow = None;
782 /* but we'll keep existing data for internal use */
784 else if( w == selectionPrevWindow )
786 w = XGetSelectionOwner(display, XA_PRIMARY);
788 if( w == None )
789 XSetSelectionOwner(display, XA_PRIMARY, selectionWindow, CurrentTime);
792 selectionPrevWindow = None;