Release 961023
[wine/multimedia.git] / misc / clipboard.c
blob32b89c618a80c8e9e2b60272f4ac009179bde864
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 HANDLE16 SetClipboardData(WORD wFormat, HANDLE16 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,
363 (WPARAM16)lpFormat->wFormatID,0L);
364 else
366 dprintf_clipboard(stddeb,"\thWndClipOwner (%04x) is lost!\n",
367 hWndClipOwner);
368 hWndClipOwner = 0; lpFormat->wDataPresent = 0;
369 return FALSE;
371 return (lpFormat->hData) ? TRUE : FALSE;
374 /**************************************************************************
375 * CLIPBOARD_RenderText
377 BOOL32 CLIPBOARD_RenderText(LPCLIPFORMAT lpTarget, LPCLIPFORMAT lpSource)
379 UINT size = GlobalSize16( lpSource->hData );
380 LPCSTR lpstrS = (LPSTR)GlobalLock16(lpSource->hData);
381 LPSTR lpstrT;
383 if( !lpstrS ) return FALSE;
384 dprintf_clipboard(stddeb,"\tconverting from '%s' to '%s', %i chars\n",
385 lpSource->Name, lpTarget->Name, size);
387 lpTarget->hData = GlobalAlloc16(GMEM_ZEROINIT, size);
388 lpstrT = (LPSTR)GlobalLock16(lpTarget->hData);
390 if( lpstrT )
392 if( lpSource->wFormatID == CF_TEXT )
393 AnsiToOemBuff(lpstrS, lpstrT, size);
394 else
395 OemToAnsiBuff(lpstrS, lpstrT, size);
396 dprintf_clipboard(stddeb,"\tgot %s\n", lpstrT);
397 return TRUE;
400 lpTarget->hData = 0;
401 return FALSE;
404 /**************************************************************************
405 * GetClipboardData [USER.142]
407 HANDLE16 GetClipboardData(WORD wFormat)
409 LPCLIPFORMAT lpRender = ClipFormats;
410 LPCLIPFORMAT lpUpdate = NULL;
412 if (!hWndClipWindow) return 0;
414 dprintf_clipboard(stddeb,"GetClipboardData(%04X)\n", wFormat);
416 if( wFormat == CF_TEXT && !lpRender[CF_TEXT-1].wDataPresent
417 && lpRender[CF_OEMTEXT-1].wDataPresent )
419 lpRender = &ClipFormats[CF_OEMTEXT-1];
420 lpUpdate = &ClipFormats[CF_TEXT-1];
422 dprintf_clipboard(stddeb,"\tOEMTEXT -> TEXT\n");
424 else if( wFormat == CF_OEMTEXT && !lpRender[CF_OEMTEXT-1].wDataPresent
425 && lpRender[CF_TEXT-1].wDataPresent )
427 lpRender = &ClipFormats[CF_TEXT-1];
428 lpUpdate = &ClipFormats[CF_OEMTEXT-1];
430 dprintf_clipboard(stddeb,"\tTEXT -> OEMTEXT\n");
432 else
434 while(TRUE)
436 if (lpRender == NULL) return 0;
437 if (lpRender->wFormatID == wFormat) break;
438 lpRender = lpRender->NextFormat;
440 lpUpdate = lpRender;
443 if( !CLIPBOARD_RenderFormat(lpRender) ) return 0;
444 if( lpUpdate != lpRender &&
445 !lpUpdate->hData ) CLIPBOARD_RenderText(lpUpdate, lpRender);
447 dprintf_clipboard(stddeb,"\treturning %04x (type %i)\n",
448 lpUpdate->hData, lpUpdate->wFormatID);
449 return lpUpdate->hData;
453 /**************************************************************************
454 * CountClipboardFormats [USER.143]
456 INT CountClipboardFormats()
458 int FormatCount = 0;
459 LPCLIPFORMAT lpFormat = ClipFormats;
461 dprintf_clipboard(stddeb,"CountClipboardFormats()\n");
463 if( !selectionAcquired ) CLIPBOARD_RequestXSelection();
465 FormatCount += abs(lpFormat[CF_TEXT-1].wDataPresent -
466 lpFormat[CF_OEMTEXT-1].wDataPresent);
468 while(TRUE) {
469 if (lpFormat == NULL) break;
470 if (lpFormat->wDataPresent)
472 dprintf_clipboard(stddeb, "\tdata found for format %i\n", lpFormat->wFormatID);
474 FormatCount++;
476 lpFormat = lpFormat->NextFormat;
479 dprintf_clipboard(stddeb,"\ttotal %d\n", FormatCount);
480 return FormatCount;
484 /**************************************************************************
485 * EnumClipboardFormats [USER.144]
487 UINT16 EnumClipboardFormats(UINT16 wFormat)
489 LPCLIPFORMAT lpFormat = ClipFormats;
491 dprintf_clipboard(stddeb,"EnumClipboardFormats(%04X)\n", wFormat);
493 if( !hWndClipWindow ) return 0;
495 if( (!wFormat || wFormat == CF_TEXT || wFormat == CF_OEMTEXT)
496 && !selectionAcquired) CLIPBOARD_RequestXSelection();
498 if (wFormat == 0)
499 if (lpFormat->wDataPresent || ClipFormats[CF_OEMTEXT-1].wDataPresent)
500 return lpFormat->wFormatID;
501 else
502 wFormat = lpFormat->wFormatID; /* and CF_TEXT is not available */
504 /* walk up to the specified format record */
506 while(TRUE) {
507 if (lpFormat == NULL) return 0;
508 if (lpFormat->wFormatID == wFormat) break;
509 lpFormat = lpFormat->NextFormat;
512 /* find next format with available data */
514 lpFormat = lpFormat->NextFormat;
515 while(TRUE) {
516 if (lpFormat == NULL) return 0;
517 if (lpFormat->wDataPresent ||
518 (lpFormat->wFormatID == CF_OEMTEXT &&
519 ClipFormats[CF_TEXT-1].wDataPresent)) break;
520 lpFormat = lpFormat->NextFormat;
523 return lpFormat->wFormatID;
527 /**************************************************************************
528 * RegisterClipboardFormat [USER.145]
530 WORD RegisterClipboardFormat(LPCSTR FormatName)
532 LPCLIPFORMAT lpNewFormat;
533 LPCLIPFORMAT lpFormat = ClipFormats;
535 if (FormatName == NULL) return 0;
537 dprintf_clipboard(stddeb,"RegisterClipboardFormat('%s') !\n", FormatName);
539 /* walk format chain to see if it's already registered */
541 while(TRUE) {
542 if ( !strcmp(lpFormat->Name,FormatName) )
544 lpFormat->wRefCount++;
545 return lpFormat->wFormatID;
548 if ( lpFormat->NextFormat == NULL ) break;
550 lpFormat = lpFormat->NextFormat;
553 /* allocate storage for new format entry */
555 lpNewFormat = (LPCLIPFORMAT)xmalloc(sizeof(CLIPFORMAT));
556 lpFormat->NextFormat = lpNewFormat;
557 lpNewFormat->wFormatID = LastRegFormat;
558 lpNewFormat->wRefCount = 1;
560 lpNewFormat->Name = (LPSTR)xmalloc(strlen(FormatName) + 1);
561 strcpy(lpNewFormat->Name, FormatName);
563 lpNewFormat->wDataPresent = 0;
564 lpNewFormat->hData = 0;
565 lpNewFormat->BufSize = 0;
566 lpNewFormat->PrevFormat = lpFormat;
567 lpNewFormat->NextFormat = NULL;
569 return LastRegFormat++;
573 /**************************************************************************
574 * GetClipboardFormatName [USER.146]
576 int GetClipboardFormatName(WORD wFormat, LPSTR retStr, short maxlen)
578 LPCLIPFORMAT lpFormat = ClipFormats;
580 dprintf_clipboard(stddeb,
581 "GetClipboardFormat(%04X, %p, %d) !\n", wFormat, retStr, maxlen);
583 while(TRUE) {
584 if (lpFormat == NULL) return 0;
585 if (lpFormat->wFormatID == wFormat) break;
586 lpFormat = lpFormat->NextFormat;
589 if (lpFormat->Name == NULL ||
590 lpFormat->wFormatID < CF_REGFORMATBASE) return 0;
592 dprintf_clipboard(stddeb,
593 "GetClipboardFormat // Name='%s' !\n", lpFormat->Name);
595 strncpy(retStr, lpFormat->Name, maxlen - 1);
596 retStr[maxlen] = 0;
598 return strlen(retStr);
602 /**************************************************************************
603 * SetClipboardViewer [USER.147]
605 HWND SetClipboardViewer(HWND hWnd)
607 HWND hwndPrev = hWndViewer;
609 dprintf_clipboard(stddeb,"SetClipboardViewer(%04x)\n", hWnd);
611 hWndViewer = hWnd;
612 return hwndPrev;
616 /**************************************************************************
617 * GetClipboardViewer [USER.148]
619 HWND GetClipboardViewer()
621 dprintf_clipboard(stddeb,"GetClipboardFormat() = %04x\n", hWndViewer);
623 return hWndViewer;
627 /**************************************************************************
628 * ChangeClipboardChain [USER.149]
630 BOOL ChangeClipboardChain(HWND hWnd, HWND hWndNext)
632 BOOL bRet = 0;
634 dprintf_clipboard(stdnimp, "ChangeClipboardChain(%04x, %04x)\n", hWnd, hWndNext);
636 if( hWndViewer )
637 bRet = !SendMessage16( hWndViewer, WM_CHANGECBCHAIN,
638 (WPARAM16)hWnd, (LPARAM)hWndNext);
639 else
640 dprintf_clipboard(stddeb,"ChangeClipboardChain: hWndViewer is lost\n");
642 if( hWnd == hWndViewer ) hWndViewer = hWndNext;
644 return 0;
648 /**************************************************************************
649 * IsClipboardFormatAvailable [USER.193]
651 BOOL IsClipboardFormatAvailable(WORD wFormat)
653 dprintf_clipboard(stddeb,"IsClipboardFormatAvailable(%04X) !\n", wFormat);
655 if( (wFormat == CF_TEXT || wFormat == CF_OEMTEXT) &&
656 !selectionAcquired ) CLIPBOARD_RequestXSelection();
658 return CLIPBOARD_IsPresent(wFormat);
662 /**************************************************************************
663 * GetOpenClipboardWindow [USER.248]
665 HWND GetOpenClipboardWindow()
667 dprintf_clipboard(stddeb,
668 "GetOpenClipboardWindow() = %04x\n", hWndClipWindow);
669 return hWndClipWindow;
673 /**************************************************************************
674 * GetPriorityClipboardFormat [USER.402]
676 int GetPriorityClipboardFormat(WORD *lpPriorityList, short nCount)
678 dprintf_clipboard(stdnimp,
679 "GetPriorityClipboardFormat(%p, %d) !\n", lpPriorityList, nCount);
681 return 0;
685 /**************************************************************************
686 * CLIPBOARD_ReadSelection
688 * Called from the SelectionNotify event handler.
690 void CLIPBOARD_ReadSelection(Window w,Atom prop)
692 HANDLE16 hText = 0;
693 LPCLIPFORMAT lpFormat = ClipFormats;
695 dprintf_clipboard(stddeb,"ReadSelection callback\n");
697 if(prop != None)
699 Atom atype=AnyPropertyType;
700 int aformat;
701 unsigned long nitems,remain;
702 unsigned char* val=NULL;
704 dprintf_clipboard(stddeb,"\tgot property %s\n",XGetAtomName(display,prop));
706 /* TODO: Properties longer than 64K */
708 if(XGetWindowProperty(display,w,prop,0,0x3FFF,True,XA_STRING,
709 &atype, &aformat, &nitems, &remain, &val) != Success)
710 dprintf_clipboard(stddeb,"\tcouldn't read property\n");
711 else
713 dprintf_clipboard(stddeb,"\tType %s,Format %d,nitems %ld,value %s\n",
714 XGetAtomName(display,atype),aformat,nitems,val);
716 if(atype == XA_STRING && aformat == 8)
718 int i,inlcount = 0;
719 char* lpstr;
721 dprintf_clipboard(stddeb,"\tselection is '%s'\n",val);
723 for(i=0; i <= nitems; i++)
724 if( val[i] == '\n' ) inlcount++;
726 if( nitems )
728 hText=GlobalAlloc16(GMEM_MOVEABLE, nitems + inlcount + 1);
729 if( (lpstr = (char*)GlobalLock16(hText)) )
730 for(i=0,inlcount=0; i <= nitems; i++)
732 if( val[i] == '\n' ) lpstr[inlcount++]='\r';
733 lpstr[inlcount++]=val[i];
735 else hText = 0;
738 XFree(val);
742 /* delete previous CF_TEXT and CF_OEMTEXT data */
744 if( hText )
746 lpFormat = &ClipFormats[CF_TEXT-1];
747 if (lpFormat->wDataPresent || lpFormat->hData)
748 CLIPBOARD_DeleteRecord(lpFormat);
749 lpFormat = &ClipFormats[CF_OEMTEXT-1];
750 if (lpFormat->wDataPresent || lpFormat->hData)
751 CLIPBOARD_DeleteRecord(lpFormat);
753 lpFormat->wDataPresent = 1;
754 lpFormat->hData = hText;
757 selectionWait=False;
760 /**************************************************************************
761 * CLIPBOARD_ReleaseSelection
763 * Wine might have lost XA_PRIMARY selection because of
764 * EmptyClipboard() or other client.
766 void CLIPBOARD_ReleaseSelection(Window w, HWND hwnd)
768 /* w is the window that lost selection,
770 * selectionPrevWindow is nonzero if CheckSelection() was called.
773 dprintf_clipboard(stddeb,"\tevent->window = %08x (sw = %08x, spw=%08x)\n",
774 (unsigned)w, (unsigned)selectionWindow, (unsigned)selectionPrevWindow );
776 if( selectionAcquired )
777 if( w == selectionWindow || selectionPrevWindow == None)
779 /* alright, we really lost it */
781 selectionAcquired = False;
782 selectionWindow = None;
784 /* but we'll keep existing data for internal use */
786 else if( w == selectionPrevWindow )
788 w = XGetSelectionOwner(display, XA_PRIMARY);
790 if( w == None )
791 XSetSelectionOwner(display, XA_PRIMARY, selectionWindow, CurrentTime);
794 selectionPrevWindow = None;