2 * 'Wine' Clipboard function handling
4 * Copyright 1994 Martin Ayotte
11 #include <sys/types.h>
17 #include <X11/Xatom.h>
21 #include "clipboard.h"
26 #define CF_REGFORMATBASE 0xC000
28 typedef struct tagCLIPFORMAT
{
35 struct tagCLIPFORMAT
*PrevFormat
;
36 struct tagCLIPFORMAT
*NextFormat
;
37 } CLIPFORMAT
, *LPCLIPFORMAT
;
39 /* *************************************************************************
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
;
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 /**************************************************************************
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 */
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
;
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;
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 */
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
;
198 if( wFormat
== CF_TEXT
|| wFormat
== CF_OEMTEXT
)
199 return lpFormat
[CF_TEXT
-1].wDataPresent
|
200 lpFormat
[CF_OEMTEXT
-1].wDataPresent
;
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
)
217 dprintf_clipboard(stddeb
,"OpenClipboard(%04x) = ", hWnd
);
221 hWndClipWindow
= hWnd
;
224 bClipChanged
= FALSE
;
226 dprintf_clipboard(stddeb
,"%i\n", bRet
);
231 /**************************************************************************
232 * CloseClipboard [USER.138]
234 BOOL
CloseClipboard()
236 dprintf_clipboard(stddeb
,"CloseClipboard(); !\n");
238 if (hWndClipWindow
== 0) return FALSE
;
241 if (bClipChanged
&& hWndViewer
) SendMessage16(hWndViewer
,WM_DRAWCLIPBOARD
,0,0L);
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 */
261 SendMessage16(hWndClipOwner
,WM_DESTROYCLIPBOARD
,0,0L);
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
);
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
;
307 dprintf_clipboard(stddeb
,
308 "SetClipboardData(%04X, %04x) !\n", wFormat
, hData
);
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",
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]);
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);
365 dprintf_clipboard(stddeb
,"\thWndClipOwner (%04x) is lost!\n",
367 hWndClipOwner
= 0; lpFormat
->wDataPresent
= 0;
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
);
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
);
391 if( lpSource
->wFormatID
== CF_TEXT
)
392 AnsiToOemBuff(lpstrS
, lpstrT
, size
);
394 OemToAnsiBuff(lpstrS
, lpstrT
, size
);
395 dprintf_clipboard(stddeb
,"\tgot %s\n", lpstrT
);
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");
435 if (lpRender
== NULL
) return 0;
436 if (lpRender
->wFormatID
== wFormat
) break;
437 lpRender
= lpRender
->NextFormat
;
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()
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
);
468 if (lpFormat
== NULL
) break;
469 if (lpFormat
->wDataPresent
)
471 dprintf_clipboard(stddeb
, "\tdata found for format %i\n", lpFormat
->wFormatID
);
475 lpFormat
= lpFormat
->NextFormat
;
478 dprintf_clipboard(stddeb
,"\ttotal %d\n", 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();
498 if (lpFormat
->wDataPresent
|| ClipFormats
[CF_OEMTEXT
-1].wDataPresent
)
499 return lpFormat
->wFormatID
;
501 wFormat
= lpFormat
->wFormatID
; /* and CF_TEXT is not available */
503 /* walk up to the specified format record */
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
;
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 */
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
);
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);
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
);
615 /**************************************************************************
616 * GetClipboardViewer [USER.148]
618 HWND
GetClipboardViewer()
620 dprintf_clipboard(stddeb
,"GetClipboardFormat() = %04x\n", hWndViewer
);
626 /**************************************************************************
627 * ChangeClipboardChain [USER.149]
629 BOOL
ChangeClipboardChain(HWND hWnd
, HWND hWndNext
)
633 dprintf_clipboard(stdnimp
, "ChangeClipboardChain(%04x, %04x)\n", hWnd
, hWndNext
);
636 bRet
= !SendMessage16( hWndViewer
, WM_CHANGECBCHAIN
, (WPARAM
)hWnd
, (LPARAM
)hWndNext
);
638 dprintf_clipboard(stddeb
,"ChangeClipboardChain: hWndViewer is lost\n");
640 if( hWnd
== hWndViewer
) hWndViewer
= hWndNext
;
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
);
683 /**************************************************************************
684 * CLIPBOARD_ReadSelection
686 * Called from the SelectionNotify event handler.
688 void CLIPBOARD_ReadSelection(Window w
,Atom prop
)
691 LPCLIPFORMAT lpFormat
= ClipFormats
;
693 dprintf_clipboard(stddeb
,"ReadSelection callback\n");
697 Atom atype
=AnyPropertyType
;
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");
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)
719 dprintf_clipboard(stddeb
,"\tselection is '%s'\n",val
);
721 for(i
=0; i
<= nitems
; i
++)
722 if( val
[i
] == '\n' ) inlcount
++;
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
];
740 /* delete previous CF_TEXT and CF_OEMTEXT data */
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
;
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
);
789 XSetSelectionOwner(display
, XA_PRIMARY
, selectionWindow
, CurrentTime
);
792 selectionPrevWindow
= None
;