2 * WINE clipboard function handling
4 * Copyright 1994 Martin Ayotte
11 #include <sys/types.h>
17 #include <X11/Xatom.h>
22 #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 HQUEUE16 hqClipLock
= 0;
44 static BOOL32 bCBHasChanged
= FALSE
;
46 static HWND32 hWndClipOwner
= 0; /* current clipboard owner */
47 static HWND32 hWndClipWindow
= 0; /* window that opened clipboard */
48 static HWND32 hWndViewer
= 0; /* start of viewers chain */
50 static WORD LastRegFormat
= CF_REGFORMATBASE
;
52 static Bool selectionWait
= False
;
53 static Bool selectionAcquired
= False
;
54 static Window selectionWindow
= None
;
55 static Window selectionPrevWindow
= None
;
57 static CLIPFORMAT ClipFormats
[16] = {
58 { CF_TEXT
, 1, 0, "Text", (HANDLE16
)NULL
, 0, NULL
, &ClipFormats
[1] },
59 { CF_BITMAP
, 1, 0, "Bitmap", (HANDLE16
)NULL
, 0, &ClipFormats
[0], &ClipFormats
[2] },
60 { CF_METAFILEPICT
, 1, 0, "MetaFile Picture", (HANDLE16
)NULL
, 0, &ClipFormats
[1], &ClipFormats
[3] },
61 { CF_SYLK
, 1, 0, "Sylk", (HANDLE16
)NULL
, 0, &ClipFormats
[2], &ClipFormats
[4] },
62 { CF_DIF
, 1, 0, "DIF", (HANDLE16
)NULL
, 0, &ClipFormats
[3], &ClipFormats
[5] },
63 { CF_TIFF
, 1, 0, "TIFF", (HANDLE16
)NULL
, 0, &ClipFormats
[4], &ClipFormats
[6] },
64 { CF_OEMTEXT
, 1, 0, "OEM Text", (HANDLE16
)NULL
, 0, &ClipFormats
[5], &ClipFormats
[7] },
65 { CF_DIB
, 1, 0, "DIB", (HANDLE16
)NULL
, 0, &ClipFormats
[6], &ClipFormats
[8] },
66 { CF_PALETTE
, 1, 0, "Palette", (HANDLE16
)NULL
, 0, &ClipFormats
[7], &ClipFormats
[9] },
67 { CF_PENDATA
, 1, 0, "PenData", (HANDLE16
)NULL
, 0, &ClipFormats
[8], &ClipFormats
[10] },
68 { CF_RIFF
, 1, 0, "RIFF", (HANDLE16
)NULL
, 0, &ClipFormats
[9], &ClipFormats
[11] },
69 { CF_WAVE
, 1, 0, "Wave", (HANDLE16
)NULL
, 0, &ClipFormats
[10], &ClipFormats
[12] },
70 { CF_OWNERDISPLAY
, 1, 0, "Owner Display", (HANDLE16
)NULL
, 0, &ClipFormats
[11], &ClipFormats
[13] },
71 { CF_DSPTEXT
, 1, 0, "DSPText", (HANDLE16
)NULL
, 0, &ClipFormats
[12], &ClipFormats
[14] },
72 { CF_DSPMETAFILEPICT
, 1, 0, "DSPMetaFile Picture", (HANDLE16
)NULL
, 0, &ClipFormats
[13], &ClipFormats
[15] },
73 { CF_DSPBITMAP
, 1, 0, "DSPBitmap", (HANDLE16
)NULL
, 0, &ClipFormats
[14], NULL
}
76 static LPCLIPFORMAT
__lookup_format( LPCLIPFORMAT lpFormat
, WORD wID
)
80 if (lpFormat
== NULL
||
81 lpFormat
->wFormatID
== wID
) break;
82 lpFormat
= lpFormat
->NextFormat
;
87 /**************************************************************************
88 * CLIPBOARD_CheckSelection
90 * Prevent X selection from being lost when a top level window is
93 static void CLIPBOARD_CheckSelection(WND
* pWnd
)
95 dprintf_info(clipboard
,"\tchecking %08x\n", (unsigned)pWnd
->window
);
97 if( selectionAcquired
&& selectionWindow
!= None
&&
98 pWnd
->window
== selectionWindow
)
100 selectionPrevWindow
= selectionWindow
;
101 selectionWindow
= None
;
104 selectionWindow
= pWnd
->next
->window
;
105 else if( pWnd
->parent
)
106 if( pWnd
->parent
->child
!= pWnd
)
107 selectionWindow
= pWnd
->parent
->child
->window
;
109 dprintf_info(clipboard
,"\tswitching selection from %08x to %08x\n",
110 (unsigned)selectionPrevWindow
, (unsigned)selectionWindow
);
112 if( selectionWindow
!= None
)
114 TSXSetSelectionOwner(display
, XA_PRIMARY
, selectionWindow
, CurrentTime
);
115 if( TSXGetSelectionOwner(display
, XA_PRIMARY
) != selectionWindow
)
116 selectionWindow
= None
;
121 /**************************************************************************
122 * CLIPBOARD_ResetLock
124 void CLIPBOARD_ResetLock( HQUEUE16 hqCurrent
, HQUEUE16 hqNew
)
126 if( hqClipLock
== hqCurrent
)
140 /**************************************************************************
141 * CLIPBOARD_ResetOwner
143 * Called from DestroyWindow().
145 void CLIPBOARD_ResetOwner(WND
* pWnd
)
147 LPCLIPFORMAT lpFormat
= ClipFormats
;
149 dprintf_info(clipboard
,"DisOwn: clipboard owner = %04x, selection = %08x\n",
150 hWndClipOwner
, (unsigned)selectionWindow
);
152 if( pWnd
->hwndSelf
== hWndClipOwner
)
154 SendMessage16(hWndClipOwner
,WM_RENDERALLFORMATS
,0,0L);
156 /* check if all formats were rendered */
160 if( lpFormat
->wDataPresent
&& !lpFormat
->hData
)
162 dprintf_info(clipboard
,"\tdata missing for clipboard format %i\n",
163 lpFormat
->wFormatID
);
164 lpFormat
->wDataPresent
= 0;
166 lpFormat
= lpFormat
->NextFormat
;
171 /* now try to salvage current selection from being destroyed by X */
173 if( pWnd
->window
) CLIPBOARD_CheckSelection(pWnd
);
176 /**************************************************************************
177 * CLIPBOARD_DeleteRecord
179 static void CLIPBOARD_DeleteRecord(LPCLIPFORMAT lpFormat
, BOOL32 bChange
)
181 if( (lpFormat
->wFormatID
>= CF_GDIOBJFIRST
&&
182 lpFormat
->wFormatID
<= CF_GDIOBJLAST
) || lpFormat
->wFormatID
== CF_BITMAP
)
183 DeleteObject32(lpFormat
->hData
);
184 else if( lpFormat
->wFormatID
== CF_METAFILEPICT
&& lpFormat
->hData
)
186 DeleteMetaFile16( ((METAFILEPICT16
*)GlobalLock16( lpFormat
->hData
))->hMF
);
187 GlobalFree16(lpFormat
->hData
);
189 else if( lpFormat
->hData
)
190 GlobalFree16(lpFormat
->hData
);
192 lpFormat
->wDataPresent
= 0;
195 if( bChange
) bCBHasChanged
= TRUE
;
198 /**************************************************************************
199 * CLIPBOARD_RequestXSelection
201 static BOOL32
CLIPBOARD_RequestXSelection()
203 HWND32 hWnd
= (hWndClipWindow
) ? hWndClipWindow
: GetActiveWindow32();
205 if( !hWnd
) return FALSE
;
207 dprintf_info(clipboard
,"Requesting selection...\n");
209 /* request data type XA_STRING, later
210 * CLIPBOARD_ReadSelection() will be invoked
211 * from the SelectionNotify event handler */
213 TSXConvertSelection(display
,XA_PRIMARY
,XA_STRING
,
214 TSXInternAtom(display
,"PRIMARY_TEXT",False
),
215 WIN_GetXWindow(hWnd
),CurrentTime
);
217 /* wait until SelectionNotify is processed
219 * FIXME: Use TSXCheckTypedWindowEvent() instead ( same in the
220 * CLIPBOARD_CheckSelection() ).
224 while(selectionWait
) EVENT_WaitNetEvent( TRUE
, FALSE
);
226 /* we treat Unix text as CF_OEMTEXT */
227 dprintf_info(clipboard
,"\tgot CF_OEMTEXT = %i\n",
228 ClipFormats
[CF_OEMTEXT
-1].wDataPresent
);
230 return (BOOL32
)ClipFormats
[CF_OEMTEXT
-1].wDataPresent
;
233 /**************************************************************************
234 * CLIPBOARD_IsPresent
236 BOOL32
CLIPBOARD_IsPresent(WORD wFormat
)
240 if( wFormat
== CF_TEXT
|| wFormat
== CF_OEMTEXT
)
241 return ClipFormats
[CF_TEXT
-1].wDataPresent
||
242 ClipFormats
[CF_OEMTEXT
-1].wDataPresent
;
245 LPCLIPFORMAT lpFormat
= __lookup_format( ClipFormats
, wFormat
);
246 if( lpFormat
) return (lpFormat
->wDataPresent
);
251 /**************************************************************************
252 * OpenClipboard16 (USER.137)
254 BOOL16 WINAPI
OpenClipboard16( HWND16 hWnd
)
256 return OpenClipboard32( hWnd
);
260 /**************************************************************************
261 * OpenClipboard32 (USER32.406)
263 * Note: Netscape uses NULL hWnd to open the clipboard.
265 BOOL32 WINAPI
OpenClipboard32( HWND32 hWnd
)
269 dprintf_info(clipboard
,"OpenClipboard(%04x)...\n", hWnd
);
273 hqClipLock
= GetTaskQueue(0);
274 hWndClipWindow
= hWnd
;
275 bCBHasChanged
= FALSE
;
280 dprintf_info(clipboard
," returning %i\n", bRet
);
285 /**************************************************************************
286 * CloseClipboard16 (USER.138)
288 BOOL16 WINAPI
CloseClipboard16(void)
290 return CloseClipboard32();
294 /**************************************************************************
295 * CloseClipboard32 (USER32.53)
297 BOOL32 WINAPI
CloseClipboard32(void)
299 dprintf_info(clipboard
,"CloseClipboard(); !\n");
301 if (hqClipLock
== GetTaskQueue(0))
305 if (bCBHasChanged
&& hWndViewer
)
306 SendMessage16(hWndViewer
, WM_DRAWCLIPBOARD
, 0, 0L);
313 /**************************************************************************
314 * EmptyClipboard16 (USER.139)
316 BOOL16 WINAPI
EmptyClipboard16(void)
318 return EmptyClipboard32();
322 /**************************************************************************
323 * EmptyClipboard32 (USER32.168)
325 BOOL32 WINAPI
EmptyClipboard32(void)
327 LPCLIPFORMAT lpFormat
= ClipFormats
;
329 dprintf_info(clipboard
,"EmptyClipboard()\n");
331 if (hqClipLock
!= GetTaskQueue(0)) return FALSE
;
333 /* destroy private objects */
336 SendMessage16(hWndClipOwner
, WM_DESTROYCLIPBOARD
, 0, 0L);
340 if ( lpFormat
->wDataPresent
|| lpFormat
->hData
)
341 CLIPBOARD_DeleteRecord( lpFormat
, TRUE
);
343 lpFormat
= lpFormat
->NextFormat
;
346 hWndClipOwner
= hWndClipWindow
;
348 if(selectionAcquired
)
350 selectionAcquired
= False
;
351 selectionPrevWindow
= selectionWindow
;
352 selectionWindow
= None
;
354 dprintf_info(clipboard
, "\tgiving up selection (spw = %08x)\n",
355 (unsigned)selectionPrevWindow
);
357 TSXSetSelectionOwner(display
, XA_PRIMARY
, None
, CurrentTime
);
363 /**************************************************************************
364 * GetClipboardOwner16 (USER.140)
366 HWND16 WINAPI
GetClipboardOwner16(void)
368 return hWndClipOwner
;
372 /**************************************************************************
373 * GetClipboardOwner32 (USER32.224)
375 HWND32 WINAPI
GetClipboardOwner32(void)
377 return hWndClipOwner
;
381 /**************************************************************************
382 * SetClipboardData16 (USER.141)
384 HANDLE16 WINAPI
SetClipboardData16( UINT16 wFormat
, HANDLE16 hData
)
386 LPCLIPFORMAT lpFormat
= __lookup_format( ClipFormats
, wFormat
);
389 dprintf_info(clipboard
,
390 "SetClipboardData(%04X, %04x) !\n", wFormat
, hData
);
392 /* NOTE: If the hData is zero and current owner doesn't match
393 * the window that opened the clipboard then this application
394 * is screwed because WM_RENDERFORMAT will go to the owner
395 * (to become the owner it must call EmptyClipboard() before
399 if( (hqClipLock
!= GetTaskQueue(0)) || !lpFormat
||
400 (!hData
&& (!hWndClipOwner
|| (hWndClipOwner
!= hWndClipWindow
))) ) return 0;
402 /* Acquire X selection if text format */
404 if( !selectionAcquired
&&
405 (wFormat
== CF_TEXT
|| wFormat
== CF_OEMTEXT
) )
407 owner
= WIN_GetXWindow( hWndClipWindow
? hWndClipWindow
: AnyPopup32() );
408 TSXSetSelectionOwner(display
,XA_PRIMARY
,owner
,CurrentTime
);
409 if( TSXGetSelectionOwner(display
,XA_PRIMARY
) == owner
)
411 selectionAcquired
= True
;
412 selectionWindow
= owner
;
414 dprintf_info(clipboard
,"Grabbed X selection, owner=(%08x)\n",
419 if ( lpFormat
->wDataPresent
|| lpFormat
->hData
)
421 CLIPBOARD_DeleteRecord(lpFormat
, TRUE
);
423 /* delete existing CF_TEXT/CF_OEMTEXT aliases */
425 if( wFormat
== CF_TEXT
&& ClipFormats
[CF_OEMTEXT
-1].hData
426 && !ClipFormats
[CF_OEMTEXT
-1].wDataPresent
)
427 CLIPBOARD_DeleteRecord(&ClipFormats
[CF_OEMTEXT
-1], TRUE
);
428 if( wFormat
== CF_OEMTEXT
&& ClipFormats
[CF_TEXT
-1].hData
429 && !ClipFormats
[CF_TEXT
-1].wDataPresent
)
430 CLIPBOARD_DeleteRecord(&ClipFormats
[CF_TEXT
-1], TRUE
);
433 bCBHasChanged
= TRUE
;
434 lpFormat
->wDataPresent
= 1;
435 lpFormat
->hData
= hData
; /* 0 is legal, see WM_RENDERFORMAT */
437 return lpFormat
->hData
;
441 /**************************************************************************
442 * SetClipboardData32 (USER32.469)
444 HANDLE32 WINAPI
SetClipboardData32( UINT32 wFormat
, HANDLE32 hData
)
446 fprintf( stderr
, "SetClipboardData: empty stub\n" );
451 /**************************************************************************
452 * CLIPBOARD_RenderFormat
454 static BOOL32
CLIPBOARD_RenderFormat(LPCLIPFORMAT lpFormat
)
456 if( lpFormat
->wDataPresent
&& !lpFormat
->hData
)
457 if( IsWindow32(hWndClipOwner
) )
458 SendMessage16(hWndClipOwner
,WM_RENDERFORMAT
,
459 (WPARAM16
)lpFormat
->wFormatID
,0L);
462 dprintf_warn(clipboard
, "\thWndClipOwner (%04x) is lost!\n",
464 hWndClipOwner
= 0; lpFormat
->wDataPresent
= 0;
467 return (lpFormat
->hData
) ? TRUE
: FALSE
;
470 /**************************************************************************
471 * CLIPBOARD_RenderText
473 * Convert text between UNIX and DOS formats.
475 static BOOL32
CLIPBOARD_RenderText(LPCLIPFORMAT lpTarget
, LPCLIPFORMAT lpSource
)
477 UINT16 size
= GlobalSize16( lpSource
->hData
);
478 LPCSTR lpstrS
= (LPSTR
)GlobalLock16(lpSource
->hData
);
481 if( !lpstrS
) return FALSE
;
482 dprintf_info(clipboard
,"\tconverting from '%s' to '%s', %i chars\n",
483 lpSource
->Name
, lpTarget
->Name
, size
);
485 lpTarget
->hData
= GlobalAlloc16(GMEM_ZEROINIT
, size
);
486 lpstrT
= (LPSTR
)GlobalLock16(lpTarget
->hData
);
490 if( lpSource
->wFormatID
== CF_TEXT
)
491 CharToOemBuff32A(lpstrS
, lpstrT
, size
);
493 OemToCharBuff32A(lpstrS
, lpstrT
, size
);
494 dprintf_info(clipboard
,"\tgot %s\n", lpstrT
);
502 /**************************************************************************
503 * GetClipboardData16 (USER.142)
505 HANDLE16 WINAPI
GetClipboardData16( UINT16 wFormat
)
507 LPCLIPFORMAT lpRender
= ClipFormats
;
508 LPCLIPFORMAT lpUpdate
= NULL
;
510 if (hqClipLock
!= GetTaskQueue(0)) return 0;
512 dprintf_info(clipboard
,"GetClipboardData(%04X)\n", wFormat
);
514 if( wFormat
== CF_TEXT
&& !lpRender
[CF_TEXT
-1].wDataPresent
515 && lpRender
[CF_OEMTEXT
-1].wDataPresent
)
517 lpRender
= &ClipFormats
[CF_OEMTEXT
-1];
518 lpUpdate
= &ClipFormats
[CF_TEXT
-1];
520 dprintf_info(clipboard
,"\tOEMTEXT -> TEXT\n");
522 else if( wFormat
== CF_OEMTEXT
&& !lpRender
[CF_OEMTEXT
-1].wDataPresent
523 && lpRender
[CF_TEXT
-1].wDataPresent
)
525 lpRender
= &ClipFormats
[CF_TEXT
-1];
526 lpUpdate
= &ClipFormats
[CF_OEMTEXT
-1];
528 dprintf_info(clipboard
,"\tTEXT -> OEMTEXT\n");
532 lpRender
= __lookup_format( ClipFormats
, wFormat
);
536 if( !lpRender
|| !CLIPBOARD_RenderFormat(lpRender
) ) return 0;
537 if( lpUpdate
!= lpRender
&& !lpUpdate
->hData
)
538 CLIPBOARD_RenderText(lpUpdate
, lpRender
);
540 dprintf_info(clipboard
,"\treturning %04x (type %i)\n",
541 lpUpdate
->hData
, lpUpdate
->wFormatID
);
542 return lpUpdate
->hData
;
546 /**************************************************************************
547 * GetClipboardData32 (USER32.221)
549 HANDLE32 WINAPI
GetClipboardData32( UINT32 wFormat
)
551 fprintf( stderr
, "GetClipboardData32: empty stub\n" );
555 /**************************************************************************
556 * CountClipboardFormats16 (USER.143)
558 INT16 WINAPI
CountClipboardFormats16(void)
560 return CountClipboardFormats32();
564 /**************************************************************************
565 * CountClipboardFormats32 (USER32.62)
567 INT32 WINAPI
CountClipboardFormats32(void)
569 INT32 FormatCount
= 0;
570 LPCLIPFORMAT lpFormat
= ClipFormats
;
572 dprintf_info(clipboard
,"CountClipboardFormats()\n");
574 if( !selectionAcquired
) CLIPBOARD_RequestXSelection();
576 FormatCount
+= abs(lpFormat
[CF_TEXT
-1].wDataPresent
-
577 lpFormat
[CF_OEMTEXT
-1].wDataPresent
);
581 if (lpFormat
== NULL
) break;
582 if (lpFormat
->wDataPresent
)
584 dprintf_info(clipboard
, "\tdata found for format %i\n", lpFormat
->wFormatID
);
587 lpFormat
= lpFormat
->NextFormat
;
590 dprintf_info(clipboard
,"\ttotal %d\n", FormatCount
);
595 /**************************************************************************
596 * EnumClipboardFormats16 (USER.144)
598 UINT16 WINAPI
EnumClipboardFormats16( UINT16 wFormat
)
600 return EnumClipboardFormats32( wFormat
);
604 /**************************************************************************
605 * EnumClipboardFormats32 (USER32.178)
607 UINT32 WINAPI
EnumClipboardFormats32( UINT32 wFormat
)
609 LPCLIPFORMAT lpFormat
= ClipFormats
;
611 dprintf_info(clipboard
,"EnumClipboardFormats(%04X)\n", wFormat
);
613 if( hqClipLock
!= GetTaskQueue(0) ) return 0;
615 if( (!wFormat
|| wFormat
== CF_TEXT
|| wFormat
== CF_OEMTEXT
)
616 && !selectionAcquired
) CLIPBOARD_RequestXSelection();
619 if (lpFormat
->wDataPresent
|| ClipFormats
[CF_OEMTEXT
-1].wDataPresent
)
620 return lpFormat
->wFormatID
;
622 wFormat
= lpFormat
->wFormatID
; /* and CF_TEXT is not available */
624 /* walk up to the specified format record */
626 if( !(lpFormat
= __lookup_format( lpFormat
, wFormat
)) ) return 0;
628 /* find next format with available data */
630 lpFormat
= lpFormat
->NextFormat
;
633 if (lpFormat
== NULL
) return 0;
634 if (lpFormat
->wDataPresent
|| (lpFormat
->wFormatID
== CF_OEMTEXT
&&
635 ClipFormats
[CF_TEXT
-1].wDataPresent
))
637 lpFormat
= lpFormat
->NextFormat
;
640 return lpFormat
->wFormatID
;
644 /**************************************************************************
645 * RegisterClipboardFormat16 (USER.145)
647 UINT16 WINAPI
RegisterClipboardFormat16( LPCSTR FormatName
)
649 LPCLIPFORMAT lpNewFormat
;
650 LPCLIPFORMAT lpFormat
= ClipFormats
;
652 if (FormatName
== NULL
) return 0;
654 dprintf_info(clipboard
,"RegisterClipboardFormat('%s') !\n", FormatName
);
656 /* walk format chain to see if it's already registered */
660 if ( !strcmp(lpFormat
->Name
,FormatName
) )
662 lpFormat
->wRefCount
++;
663 return lpFormat
->wFormatID
;
666 if ( lpFormat
->NextFormat
== NULL
) break;
668 lpFormat
= lpFormat
->NextFormat
;
671 /* allocate storage for new format entry */
673 lpNewFormat
= (LPCLIPFORMAT
)xmalloc(sizeof(CLIPFORMAT
));
674 lpFormat
->NextFormat
= lpNewFormat
;
675 lpNewFormat
->wFormatID
= LastRegFormat
;
676 lpNewFormat
->wRefCount
= 1;
678 lpNewFormat
->Name
= (LPSTR
)xmalloc(strlen(FormatName
) + 1);
679 strcpy(lpNewFormat
->Name
, FormatName
);
681 lpNewFormat
->wDataPresent
= 0;
682 lpNewFormat
->hData
= 0;
683 lpNewFormat
->BufSize
= 0;
684 lpNewFormat
->PrevFormat
= lpFormat
;
685 lpNewFormat
->NextFormat
= NULL
;
687 return LastRegFormat
++;
691 /**************************************************************************
692 * RegisterClipboardFormat32A (USER32.430)
694 UINT32 WINAPI
RegisterClipboardFormat32A( LPCSTR formatName
)
696 return RegisterClipboardFormat16( formatName
);
700 /**************************************************************************
701 * RegisterClipboardFormat32W (USER32.431)
703 UINT32 WINAPI
RegisterClipboardFormat32W( LPCWSTR formatName
)
705 LPSTR aFormat
= HEAP_strdupWtoA( GetProcessHeap(), 0, formatName
);
706 UINT32 ret
= RegisterClipboardFormat32A( aFormat
);
707 HeapFree( GetProcessHeap(), 0, aFormat
);
711 /**************************************************************************
712 * GetClipboardFormatName16 (USER.146)
714 INT16 WINAPI
GetClipboardFormatName16( UINT16 wFormat
, LPSTR retStr
, INT16 maxlen
)
716 return GetClipboardFormatName32A( wFormat
, retStr
, maxlen
);
720 /**************************************************************************
721 * GetClipboardFormatName32A (USER32.222)
723 INT32 WINAPI
GetClipboardFormatName32A( UINT32 wFormat
, LPSTR retStr
, INT32 maxlen
)
725 LPCLIPFORMAT lpFormat
= __lookup_format( ClipFormats
, wFormat
);
727 dprintf_info(clipboard
,
728 "GetClipboardFormatName(%04X, %p, %d) !\n", wFormat
, retStr
, maxlen
);
730 if (lpFormat
== NULL
|| lpFormat
->Name
== NULL
||
731 lpFormat
->wFormatID
< CF_REGFORMATBASE
) return 0;
733 dprintf_info(clipboard
,
734 "GetClipboardFormat // Name='%s' !\n", lpFormat
->Name
);
736 lstrcpyn32A( retStr
, lpFormat
->Name
, maxlen
);
737 return strlen(retStr
);
741 /**************************************************************************
742 * GetClipboardFormatName32W (USER32.223)
744 INT32 WINAPI
GetClipboardFormatName32W( UINT32 wFormat
, LPWSTR retStr
, INT32 maxlen
)
746 LPSTR p
= HEAP_xalloc( GetProcessHeap(), 0, maxlen
);
747 INT32 ret
= GetClipboardFormatName32A( wFormat
, p
, maxlen
);
748 lstrcpynAtoW( retStr
, p
, maxlen
);
749 HeapFree( GetProcessHeap(), 0, p
);
754 /**************************************************************************
755 * SetClipboardViewer16 (USER.147)
757 HWND16 WINAPI
SetClipboardViewer16( HWND16 hWnd
)
759 return SetClipboardViewer32( hWnd
);
763 /**************************************************************************
764 * SetClipboardViewer32 (USER32.470)
766 HWND32 WINAPI
SetClipboardViewer32( HWND32 hWnd
)
768 HWND32 hwndPrev
= hWndViewer
;
770 dprintf_info(clipboard
,"SetClipboardViewer(%04x): returning %04x\n", hWnd
, hwndPrev
);
777 /**************************************************************************
778 * GetClipboardViewer16 (USER.148)
780 HWND16 WINAPI
GetClipboardViewer16(void)
786 /**************************************************************************
787 * GetClipboardViewer32 (USER32.225)
789 HWND32 WINAPI
GetClipboardViewer32(void)
795 /**************************************************************************
796 * ChangeClipboardChain16 (USER.149)
798 BOOL16 WINAPI
ChangeClipboardChain16(HWND16 hWnd
, HWND16 hWndNext
)
800 return ChangeClipboardChain32(hWnd
, hWndNext
);
803 /**************************************************************************
804 * ChangeClipboardChain32 (USER32.21)
806 BOOL32 WINAPI
ChangeClipboardChain32(HWND32 hWnd
, HWND32 hWndNext
)
810 dprintf_fixme(clipboard
, "ChangeClipboardChain(%04x, %04x) - stub?\n",
814 bRet
= !SendMessage16( hWndViewer
, WM_CHANGECBCHAIN
,
815 (WPARAM16
)hWnd
, (LPARAM
)hWndNext
);
817 dprintf_warn(clipboard
, "ChangeClipboardChain: hWndViewer is lost\n");
819 if( hWnd
== hWndViewer
) hWndViewer
= hWndNext
;
826 /**************************************************************************
827 * IsClipboardFormatAvailable16 (USER.193)
829 BOOL16 WINAPI
IsClipboardFormatAvailable16( UINT16 wFormat
)
831 return IsClipboardFormatAvailable32( wFormat
);
835 /**************************************************************************
836 * IsClipboardFormatAvailable32 (USER32.339)
838 BOOL32 WINAPI
IsClipboardFormatAvailable32( UINT32 wFormat
)
840 dprintf_info(clipboard
,"IsClipboardFormatAvailable(%04X) !\n", wFormat
);
842 if( (wFormat
== CF_TEXT
|| wFormat
== CF_OEMTEXT
) &&
843 !selectionAcquired
) CLIPBOARD_RequestXSelection();
845 return CLIPBOARD_IsPresent(wFormat
);
849 /**************************************************************************
850 * GetOpenClipboardWindow16 (USER.248)
852 HWND16 WINAPI
GetOpenClipboardWindow16(void)
854 return hWndClipWindow
;
858 /**************************************************************************
859 * GetOpenClipboardWindow32 (USER32.276)
861 HWND32 WINAPI
GetOpenClipboardWindow32(void)
863 return hWndClipWindow
;
867 /**************************************************************************
868 * GetPriorityClipboardFormat16 (USER.402)
870 INT16 WINAPI
GetPriorityClipboardFormat16( UINT16
*lpPriorityList
, INT16 nCount
)
872 fprintf( stderr
, "GetPriorityClipboardFormat16(%p, %d): stub\n",
873 lpPriorityList
, nCount
);
878 /**************************************************************************
879 * GetPriorityClipboardFormat32 (USER32.279)
881 INT32 WINAPI
GetPriorityClipboardFormat32( UINT32
*lpPriorityList
, INT32 nCount
)
885 if(CountClipboardFormats32() == 0)
890 for(Counter
= 0; Counter
<= nCount
; Counter
++)
892 if(IsClipboardFormatAvailable32(*(lpPriorityList
+sizeof(INT32
)*Counter
)))
893 return *(lpPriorityList
+sizeof(INT32
)*Counter
);
900 /**************************************************************************
901 * CLIPBOARD_ReadSelection
903 * Called from the SelectionNotify event handler.
905 void CLIPBOARD_ReadSelection(Window w
,Atom prop
)
908 LPCLIPFORMAT lpFormat
= ClipFormats
;
910 dprintf_info(clipboard
,"ReadSelection callback\n");
914 Atom atype
=AnyPropertyType
;
916 unsigned long nitems
,remain
;
917 unsigned char* val
=NULL
;
919 dprintf_info(clipboard
,"\tgot property %s\n",TSXGetAtomName(display
,prop
));
921 /* TODO: Properties longer than 64K */
923 if(TSXGetWindowProperty(display
,w
,prop
,0,0x3FFF,True
,XA_STRING
,
924 &atype
, &aformat
, &nitems
, &remain
, &val
) != Success
)
925 dprintf_warn(clipboard
, "\tcouldn't read property\n");
928 dprintf_info(clipboard
,"\tType %s,Format %d,nitems %ld,value %s\n",
929 TSXGetAtomName(display
,atype
),aformat
,nitems
,val
);
931 if(atype
== XA_STRING
&& aformat
== 8)
936 dprintf_info(clipboard
,"\tselection is '%s'\n",val
);
938 for(i
=0; i
<= nitems
; i
++)
939 if( val
[i
] == '\n' ) inlcount
++;
943 hText
=GlobalAlloc16(GMEM_MOVEABLE
, nitems
+ inlcount
+ 1);
944 if( (lpstr
= (char*)GlobalLock16(hText
)) )
945 for(i
=0,inlcount
=0; i
<= nitems
; i
++)
947 if( val
[i
] == '\n' ) lpstr
[inlcount
++]='\r';
948 lpstr
[inlcount
++]=val
[i
];
957 /* delete previous CF_TEXT and CF_OEMTEXT data */
961 lpFormat
= &ClipFormats
[CF_TEXT
-1];
962 if (lpFormat
->wDataPresent
|| lpFormat
->hData
)
963 CLIPBOARD_DeleteRecord(lpFormat
, !(hWndClipWindow
));
964 lpFormat
= &ClipFormats
[CF_OEMTEXT
-1];
965 if (lpFormat
->wDataPresent
|| lpFormat
->hData
)
966 CLIPBOARD_DeleteRecord(lpFormat
, !(hWndClipWindow
));
968 lpFormat
->wDataPresent
= 1;
969 lpFormat
->hData
= hText
;
975 /**************************************************************************
976 * CLIPBOARD_ReleaseSelection
978 * Wine might have lost XA_PRIMARY selection because of
979 * EmptyClipboard() or other client.
981 void CLIPBOARD_ReleaseSelection(Window w
, HWND32 hwnd
)
983 /* w is the window that lost selection,
985 * selectionPrevWindow is nonzero if CheckSelection() was called.
988 dprintf_info(clipboard
,"\tevent->window = %08x (sw = %08x, spw=%08x)\n",
989 (unsigned)w
, (unsigned)selectionWindow
, (unsigned)selectionPrevWindow
);
991 if( selectionAcquired
)
992 if( w
== selectionWindow
|| selectionPrevWindow
== None
)
994 /* alright, we really lost it */
996 selectionAcquired
= False
;
997 selectionWindow
= None
;
999 /* but we'll keep existing data for internal use */
1001 else if( w
== selectionPrevWindow
)
1003 w
= TSXGetSelectionOwner(display
, XA_PRIMARY
);
1005 TSXSetSelectionOwner(display
, XA_PRIMARY
, selectionWindow
, CurrentTime
);
1008 selectionPrevWindow
= None
;