2 * WINE clipboard function handling
4 * Copyright 1994 Martin Ayotte
11 #include <sys/types.h>
17 #include <X11/Xatom.h>
22 #include "clipboard.h"
27 #define CF_REGFORMATBASE 0xC000
29 typedef struct tagCLIPFORMAT
{
36 struct tagCLIPFORMAT
*PrevFormat
;
37 struct tagCLIPFORMAT
*NextFormat
;
38 } CLIPFORMAT
, *LPCLIPFORMAT
;
40 /* *************************************************************************
44 static HQUEUE16 hqClipLock
= 0;
45 static BOOL32 bCBHasChanged
= FALSE
;
47 static HWND32 hWndClipOwner
= 0; /* current clipboard owner */
48 static HWND32 hWndClipWindow
= 0; /* window that opened clipboard */
49 static HWND32 hWndViewer
= 0; /* start of viewers chain */
51 static WORD LastRegFormat
= CF_REGFORMATBASE
;
53 static Bool selectionWait
= False
;
54 static Bool selectionAcquired
= False
;
55 static Window selectionWindow
= None
;
56 static Window selectionPrevWindow
= None
;
58 static CLIPFORMAT ClipFormats
[16] = {
59 { 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
}
77 static LPCLIPFORMAT
__lookup_format( LPCLIPFORMAT lpFormat
, WORD wID
)
81 if (lpFormat
== NULL
||
82 lpFormat
->wFormatID
== wID
) break;
83 lpFormat
= lpFormat
->NextFormat
;
88 /**************************************************************************
89 * CLIPBOARD_CheckSelection
91 * Prevent X selection from being lost when a top level window is
94 static void CLIPBOARD_CheckSelection(WND
* pWnd
)
96 dprintf_clipboard(stddeb
,"\tchecking %08x\n", (unsigned)pWnd
->window
);
98 if( selectionAcquired
&& selectionWindow
!= None
&&
99 pWnd
->window
== selectionWindow
)
101 selectionPrevWindow
= selectionWindow
;
102 selectionWindow
= None
;
105 selectionWindow
= pWnd
->next
->window
;
106 else if( pWnd
->parent
)
107 if( pWnd
->parent
->child
!= pWnd
)
108 selectionWindow
= pWnd
->parent
->child
->window
;
110 dprintf_clipboard(stddeb
,"\tswitching selection from %08x to %08x\n",
111 (unsigned)selectionPrevWindow
, (unsigned)selectionWindow
);
113 if( selectionWindow
!= None
)
115 XSetSelectionOwner(display
, XA_PRIMARY
, selectionWindow
, CurrentTime
);
116 if( XGetSelectionOwner(display
, XA_PRIMARY
) != selectionWindow
)
117 selectionWindow
= None
;
122 /**************************************************************************
123 * CLIPBOARD_ResetLock
125 void CLIPBOARD_ResetLock( HQUEUE16 hqCurrent
, HQUEUE16 hqNew
)
127 if( hqClipLock
== hqCurrent
)
141 /**************************************************************************
142 * CLIPBOARD_ResetOwner
144 * Called from DestroyWindow().
146 void CLIPBOARD_ResetOwner(WND
* pWnd
)
148 LPCLIPFORMAT lpFormat
= ClipFormats
;
150 dprintf_clipboard(stddeb
,"DisOwn: clipboard owner = %04x, selection = %08x\n",
151 hWndClipOwner
, (unsigned)selectionWindow
);
153 if( pWnd
->hwndSelf
== hWndClipOwner
)
155 SendMessage16(hWndClipOwner
,WM_RENDERALLFORMATS
,0,0L);
157 /* check if all formats were rendered */
161 if( lpFormat
->wDataPresent
&& !lpFormat
->hData
)
163 dprintf_clipboard( stddeb
,"\tdata missing for clipboard format %i\n",
164 lpFormat
->wFormatID
);
165 lpFormat
->wDataPresent
= 0;
167 lpFormat
= lpFormat
->NextFormat
;
172 /* now try to salvage current selection from being destroyed by X */
174 if( pWnd
->window
) CLIPBOARD_CheckSelection(pWnd
);
177 /**************************************************************************
178 * CLIPBOARD_DeleteRecord
180 static void CLIPBOARD_DeleteRecord(LPCLIPFORMAT lpFormat
, BOOL32 bChange
)
182 if( lpFormat
->wFormatID
>= CF_GDIOBJFIRST
&&
183 lpFormat
->wFormatID
<= CF_GDIOBJLAST
)
184 DeleteObject32(lpFormat
->hData
);
185 else if( lpFormat
->hData
)
186 GlobalFree16(lpFormat
->hData
);
188 lpFormat
->wDataPresent
= 0;
191 if( bChange
) bCBHasChanged
= TRUE
;
194 /**************************************************************************
195 * CLIPBOARD_RequestXSelection
197 static BOOL32
CLIPBOARD_RequestXSelection()
199 HWND32 hWnd
= (hWndClipWindow
) ? hWndClipWindow
: GetActiveWindow32();
201 if( !hWnd
) return FALSE
;
203 dprintf_clipboard(stddeb
,"Requesting selection...\n");
205 /* request data type XA_STRING, later
206 * CLIPBOARD_ReadSelection() will be invoked
207 * from the SelectionNotify event handler */
209 XConvertSelection(display
,XA_PRIMARY
,XA_STRING
,
210 XInternAtom(display
,"PRIMARY_TEXT",False
),
211 WIN_GetXWindow(hWnd
),CurrentTime
);
213 /* wait until SelectionNotify is processed
215 * FIXME: Use XCheckTypedWindowEvent() instead ( same in the
216 * CLIPBOARD_CheckSelection() ).
220 while(selectionWait
) EVENT_WaitNetEvent( TRUE
, FALSE
);
222 /* we treat Unix text as CF_OEMTEXT */
223 dprintf_clipboard(stddeb
,"\tgot CF_OEMTEXT = %i\n",
224 ClipFormats
[CF_OEMTEXT
-1].wDataPresent
);
226 return (BOOL32
)ClipFormats
[CF_OEMTEXT
-1].wDataPresent
;
229 /**************************************************************************
230 * CLIPBOARD_IsPresent
232 BOOL32
CLIPBOARD_IsPresent(WORD wFormat
)
236 if( wFormat
== CF_TEXT
|| wFormat
== CF_OEMTEXT
)
237 return ClipFormats
[CF_TEXT
-1].wDataPresent
||
238 ClipFormats
[CF_OEMTEXT
-1].wDataPresent
;
241 LPCLIPFORMAT lpFormat
= __lookup_format( ClipFormats
, wFormat
);
242 if( lpFormat
) return (lpFormat
->wDataPresent
);
247 /**************************************************************************
248 * OpenClipboard16 (USER.137)
250 BOOL16 WINAPI
OpenClipboard16( HWND16 hWnd
)
252 return OpenClipboard32( hWnd
);
256 /**************************************************************************
257 * OpenClipboard32 (USER32.406)
259 * Note: Netscape uses NULL hWnd to open the clipboard.
261 BOOL32 WINAPI
OpenClipboard32( HWND32 hWnd
)
265 dprintf_clipboard(stddeb
,"OpenClipboard(%04x) = ", hWnd
);
269 hqClipLock
= GetTaskQueue(0);
270 hWndClipWindow
= hWnd
;
271 bCBHasChanged
= FALSE
;
276 dprintf_clipboard(stddeb
,"%i\n", bRet
);
281 /**************************************************************************
282 * CloseClipboard16 (USER.138)
284 BOOL16 WINAPI
CloseClipboard16(void)
286 return CloseClipboard32();
290 /**************************************************************************
291 * CloseClipboard32 (USER32.53)
293 BOOL32 WINAPI
CloseClipboard32(void)
295 dprintf_clipboard(stddeb
,"CloseClipboard(); !\n");
297 if (hqClipLock
== GetTaskQueue(0))
301 if (bCBHasChanged
&& hWndViewer
)
302 SendMessage16(hWndViewer
, WM_DRAWCLIPBOARD
, 0, 0L);
309 /**************************************************************************
310 * EmptyClipboard16 (USER.139)
312 BOOL16 WINAPI
EmptyClipboard16(void)
314 return EmptyClipboard32();
318 /**************************************************************************
319 * EmptyClipboard32 (USER32.168)
321 BOOL32 WINAPI
EmptyClipboard32(void)
323 LPCLIPFORMAT lpFormat
= ClipFormats
;
325 dprintf_clipboard(stddeb
,"EmptyClipboard()\n");
327 if (hqClipLock
!= GetTaskQueue(0)) return FALSE
;
329 /* destroy private objects */
332 SendMessage16(hWndClipOwner
, WM_DESTROYCLIPBOARD
, 0, 0L);
336 if ( lpFormat
->wDataPresent
|| lpFormat
->hData
)
337 CLIPBOARD_DeleteRecord( lpFormat
, TRUE
);
339 lpFormat
= lpFormat
->NextFormat
;
342 hWndClipOwner
= hWndClipWindow
;
344 if(selectionAcquired
)
346 selectionAcquired
= False
;
347 selectionPrevWindow
= selectionWindow
;
348 selectionWindow
= None
;
350 dprintf_clipboard(stddeb
, "\tgiving up selection (spw = %08x)\n",
351 (unsigned)selectionPrevWindow
);
353 XSetSelectionOwner(display
, XA_PRIMARY
, None
, CurrentTime
);
359 /**************************************************************************
360 * GetClipboardOwner16 (USER.140)
362 HWND16 WINAPI
GetClipboardOwner16(void)
364 return hWndClipOwner
;
368 /**************************************************************************
369 * GetClipboardOwner32 (USER32.224)
371 HWND32 WINAPI
GetClipboardOwner32(void)
373 return hWndClipOwner
;
377 /**************************************************************************
378 * SetClipboardData16 (USER.141)
380 HANDLE16 WINAPI
SetClipboardData16( UINT16 wFormat
, HANDLE16 hData
)
382 LPCLIPFORMAT lpFormat
= __lookup_format( ClipFormats
, wFormat
);
385 dprintf_clipboard(stddeb
,
386 "SetClipboardData(%04X, %04x) !\n", wFormat
, hData
);
388 /* 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
395 if( (hqClipLock
!= GetTaskQueue(0)) || !lpFormat
||
396 (!hData
&& (!hWndClipOwner
|| (hWndClipOwner
!= hWndClipWindow
))) ) return 0;
398 /* Acquire X selection if text format */
400 if( !selectionAcquired
&&
401 (wFormat
== CF_TEXT
|| wFormat
== CF_OEMTEXT
) )
403 owner
= WIN_GetXWindow( hWndClipWindow
? hWndClipWindow
: AnyPopup32() );
404 XSetSelectionOwner(display
,XA_PRIMARY
,owner
,CurrentTime
);
405 if( XGetSelectionOwner(display
,XA_PRIMARY
) == owner
)
407 selectionAcquired
= True
;
408 selectionWindow
= owner
;
410 dprintf_clipboard(stddeb
,"Grabbed X selection, owner=(%08x)\n",
415 if ( lpFormat
->wDataPresent
|| lpFormat
->hData
)
417 CLIPBOARD_DeleteRecord(lpFormat
, TRUE
);
419 /* delete existing CF_TEXT/CF_OEMTEXT aliases */
421 if( wFormat
== CF_TEXT
&& ClipFormats
[CF_OEMTEXT
-1].hData
422 && !ClipFormats
[CF_OEMTEXT
-1].wDataPresent
)
423 CLIPBOARD_DeleteRecord(&ClipFormats
[CF_OEMTEXT
-1], TRUE
);
424 if( wFormat
== CF_OEMTEXT
&& ClipFormats
[CF_TEXT
-1].hData
425 && !ClipFormats
[CF_TEXT
-1].wDataPresent
)
426 CLIPBOARD_DeleteRecord(&ClipFormats
[CF_TEXT
-1], TRUE
);
429 bCBHasChanged
= TRUE
;
430 lpFormat
->wDataPresent
= 1;
431 lpFormat
->hData
= hData
; /* 0 is legal, see WM_RENDERFORMAT */
433 return lpFormat
->hData
;
437 /**************************************************************************
438 * SetClipboardData32 (USER32.469)
440 HANDLE32 WINAPI
SetClipboardData32( UINT32 wFormat
, HANDLE32 hData
)
442 fprintf( stderr
, "SetClipboardData: empty stub\n" );
447 /**************************************************************************
448 * CLIPBOARD_RenderFormat
450 static BOOL32
CLIPBOARD_RenderFormat(LPCLIPFORMAT lpFormat
)
452 if( lpFormat
->wDataPresent
&& !lpFormat
->hData
)
453 if( IsWindow32(hWndClipOwner
) )
454 SendMessage16(hWndClipOwner
,WM_RENDERFORMAT
,
455 (WPARAM16
)lpFormat
->wFormatID
,0L);
458 dprintf_clipboard(stddeb
,"\thWndClipOwner (%04x) is lost!\n",
460 hWndClipOwner
= 0; lpFormat
->wDataPresent
= 0;
463 return (lpFormat
->hData
) ? TRUE
: FALSE
;
466 /**************************************************************************
467 * CLIPBOARD_RenderText
469 * Convert text between UNIX and DOS formats.
471 static BOOL32
CLIPBOARD_RenderText(LPCLIPFORMAT lpTarget
, LPCLIPFORMAT lpSource
)
473 UINT16 size
= GlobalSize16( lpSource
->hData
);
474 LPCSTR lpstrS
= (LPSTR
)GlobalLock16(lpSource
->hData
);
477 if( !lpstrS
) return FALSE
;
478 dprintf_clipboard(stddeb
,"\tconverting from '%s' to '%s', %i chars\n",
479 lpSource
->Name
, lpTarget
->Name
, size
);
481 lpTarget
->hData
= GlobalAlloc16(GMEM_ZEROINIT
, size
);
482 lpstrT
= (LPSTR
)GlobalLock16(lpTarget
->hData
);
486 if( lpSource
->wFormatID
== CF_TEXT
)
487 CharToOemBuff32A(lpstrS
, lpstrT
, size
);
489 OemToCharBuff32A(lpstrS
, lpstrT
, size
);
490 dprintf_clipboard(stddeb
,"\tgot %s\n", lpstrT
);
498 /**************************************************************************
499 * GetClipboardData16 (USER.142)
501 HANDLE16 WINAPI
GetClipboardData16( UINT16 wFormat
)
503 LPCLIPFORMAT lpRender
= ClipFormats
;
504 LPCLIPFORMAT lpUpdate
= NULL
;
506 if (hqClipLock
!= GetTaskQueue(0)) return 0;
508 dprintf_clipboard(stddeb
,"GetClipboardData(%04X)\n", wFormat
);
510 if( wFormat
== CF_TEXT
&& !lpRender
[CF_TEXT
-1].wDataPresent
511 && lpRender
[CF_OEMTEXT
-1].wDataPresent
)
513 lpRender
= &ClipFormats
[CF_OEMTEXT
-1];
514 lpUpdate
= &ClipFormats
[CF_TEXT
-1];
516 dprintf_clipboard(stddeb
,"\tOEMTEXT -> TEXT\n");
518 else if( wFormat
== CF_OEMTEXT
&& !lpRender
[CF_OEMTEXT
-1].wDataPresent
519 && lpRender
[CF_TEXT
-1].wDataPresent
)
521 lpRender
= &ClipFormats
[CF_TEXT
-1];
522 lpUpdate
= &ClipFormats
[CF_OEMTEXT
-1];
524 dprintf_clipboard(stddeb
,"\tTEXT -> OEMTEXT\n");
528 lpRender
= __lookup_format( ClipFormats
, wFormat
);
532 if( !lpRender
|| !CLIPBOARD_RenderFormat(lpRender
) ) return 0;
533 if( lpUpdate
!= lpRender
&& !lpUpdate
->hData
)
534 CLIPBOARD_RenderText(lpUpdate
, lpRender
);
536 dprintf_clipboard(stddeb
,"\treturning %04x (type %i)\n",
537 lpUpdate
->hData
, lpUpdate
->wFormatID
);
538 return lpUpdate
->hData
;
542 /**************************************************************************
543 * GetClipboardData32 (USER32.221)
545 HANDLE32 WINAPI
GetClipboardData32( UINT32 wFormat
)
547 fprintf( stderr
, "GetClipboardData32: empty stub\n" );
551 /**************************************************************************
552 * CountClipboardFormats16 (USER.143)
554 INT16 WINAPI
CountClipboardFormats16(void)
556 return CountClipboardFormats32();
560 /**************************************************************************
561 * CountClipboardFormats32 (USER32.62)
563 INT32 WINAPI
CountClipboardFormats32(void)
565 INT32 FormatCount
= 0;
566 LPCLIPFORMAT lpFormat
= ClipFormats
;
568 dprintf_clipboard(stddeb
,"CountClipboardFormats()\n");
570 if( !selectionAcquired
) CLIPBOARD_RequestXSelection();
572 FormatCount
+= abs(lpFormat
[CF_TEXT
-1].wDataPresent
-
573 lpFormat
[CF_OEMTEXT
-1].wDataPresent
);
577 if (lpFormat
== NULL
) break;
578 if (lpFormat
->wDataPresent
)
580 dprintf_clipboard(stddeb
, "\tdata found for format %i\n", lpFormat
->wFormatID
);
583 lpFormat
= lpFormat
->NextFormat
;
586 dprintf_clipboard(stddeb
,"\ttotal %d\n", FormatCount
);
591 /**************************************************************************
592 * EnumClipboardFormats16 (USER.144)
594 UINT16 WINAPI
EnumClipboardFormats16( UINT16 wFormat
)
596 return EnumClipboardFormats32( wFormat
);
600 /**************************************************************************
601 * EnumClipboardFormats32 (USER32.178)
603 UINT32 WINAPI
EnumClipboardFormats32( UINT32 wFormat
)
605 LPCLIPFORMAT lpFormat
= ClipFormats
;
607 dprintf_clipboard(stddeb
,"EnumClipboardFormats(%04X)\n", wFormat
);
609 if( hqClipLock
!= GetTaskQueue(0) ) return 0;
611 if( (!wFormat
|| wFormat
== CF_TEXT
|| wFormat
== CF_OEMTEXT
)
612 && !selectionAcquired
) CLIPBOARD_RequestXSelection();
615 if (lpFormat
->wDataPresent
|| ClipFormats
[CF_OEMTEXT
-1].wDataPresent
)
616 return lpFormat
->wFormatID
;
618 wFormat
= lpFormat
->wFormatID
; /* and CF_TEXT is not available */
620 /* walk up to the specified format record */
622 if( !(lpFormat
= __lookup_format( lpFormat
, wFormat
)) ) return 0;
624 /* find next format with available data */
626 lpFormat
= lpFormat
->NextFormat
;
629 if (lpFormat
== NULL
) return 0;
630 if (lpFormat
->wDataPresent
|| (lpFormat
->wFormatID
== CF_OEMTEXT
&&
631 ClipFormats
[CF_TEXT
-1].wDataPresent
))
633 lpFormat
= lpFormat
->NextFormat
;
636 return lpFormat
->wFormatID
;
640 /**************************************************************************
641 * RegisterClipboardFormat16 (USER.145)
643 UINT16 WINAPI
RegisterClipboardFormat16( LPCSTR FormatName
)
645 LPCLIPFORMAT lpNewFormat
;
646 LPCLIPFORMAT lpFormat
= ClipFormats
;
648 if (FormatName
== NULL
) return 0;
650 dprintf_clipboard(stddeb
,"RegisterClipboardFormat('%s') !\n", FormatName
);
652 /* walk format chain to see if it's already registered */
656 if ( !strcmp(lpFormat
->Name
,FormatName
) )
658 lpFormat
->wRefCount
++;
659 return lpFormat
->wFormatID
;
662 if ( lpFormat
->NextFormat
== NULL
) break;
664 lpFormat
= lpFormat
->NextFormat
;
667 /* allocate storage for new format entry */
669 lpNewFormat
= (LPCLIPFORMAT
)xmalloc(sizeof(CLIPFORMAT
));
670 lpFormat
->NextFormat
= lpNewFormat
;
671 lpNewFormat
->wFormatID
= LastRegFormat
;
672 lpNewFormat
->wRefCount
= 1;
674 lpNewFormat
->Name
= (LPSTR
)xmalloc(strlen(FormatName
) + 1);
675 strcpy(lpNewFormat
->Name
, FormatName
);
677 lpNewFormat
->wDataPresent
= 0;
678 lpNewFormat
->hData
= 0;
679 lpNewFormat
->BufSize
= 0;
680 lpNewFormat
->PrevFormat
= lpFormat
;
681 lpNewFormat
->NextFormat
= NULL
;
683 return LastRegFormat
++;
687 /**************************************************************************
688 * RegisterClipboardFormat32A (USER32.430)
690 UINT32 WINAPI
RegisterClipboardFormat32A( LPCSTR formatName
)
692 return RegisterClipboardFormat16( formatName
);
696 /**************************************************************************
697 * RegisterClipboardFormat32W (USER32.431)
699 UINT32 WINAPI
RegisterClipboardFormat32W( LPCWSTR formatName
)
701 LPSTR aFormat
= HEAP_strdupWtoA( GetProcessHeap(), 0, formatName
);
702 UINT32 ret
= RegisterClipboardFormat32A( aFormat
);
703 HeapFree( GetProcessHeap(), 0, aFormat
);
707 /**************************************************************************
708 * GetClipboardFormatName16 (USER.146)
710 INT16 WINAPI
GetClipboardFormatName16( UINT16 wFormat
, LPSTR retStr
, INT16 maxlen
)
712 return GetClipboardFormatName32A( wFormat
, retStr
, maxlen
);
716 /**************************************************************************
717 * GetClipboardFormatName32A (USER32.222)
719 INT32 WINAPI
GetClipboardFormatName32A( UINT32 wFormat
, LPSTR retStr
, INT32 maxlen
)
721 LPCLIPFORMAT lpFormat
= __lookup_format( ClipFormats
, wFormat
);
723 dprintf_clipboard(stddeb
,
724 "GetClipboardFormatName(%04X, %p, %d) !\n", wFormat
, retStr
, maxlen
);
726 if (lpFormat
== NULL
|| lpFormat
->Name
== NULL
||
727 lpFormat
->wFormatID
< CF_REGFORMATBASE
) return 0;
729 dprintf_clipboard(stddeb
,
730 "GetClipboardFormat // Name='%s' !\n", lpFormat
->Name
);
732 lstrcpyn32A( retStr
, lpFormat
->Name
, maxlen
);
733 return strlen(retStr
);
737 /**************************************************************************
738 * GetClipboardFormatName32W (USER32.223)
740 INT32 WINAPI
GetClipboardFormatName32W( UINT32 wFormat
, LPWSTR retStr
, INT32 maxlen
)
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
);
750 /**************************************************************************
751 * SetClipboardViewer16 (USER.147)
753 HWND16 WINAPI
SetClipboardViewer16( HWND16 hWnd
)
755 return SetClipboardViewer32( hWnd
);
759 /**************************************************************************
760 * SetClipboardViewer32 (USER32.470)
762 HWND32 WINAPI
SetClipboardViewer32( HWND32 hWnd
)
764 HWND32 hwndPrev
= hWndViewer
;
766 dprintf_clipboard(stddeb
,"SetClipboardViewer(%04x): returning %04x\n", hWnd
, hwndPrev
);
773 /**************************************************************************
774 * GetClipboardViewer16 (USER.148)
776 HWND16 WINAPI
GetClipboardViewer16(void)
782 /**************************************************************************
783 * GetClipboardViewer32 (USER32.225)
785 HWND32 WINAPI
GetClipboardViewer32(void)
791 /**************************************************************************
792 * ChangeClipboardChain16 (USER.149)
794 BOOL16 WINAPI
ChangeClipboardChain16(HWND16 hWnd
, HWND16 hWndNext
)
796 return ChangeClipboardChain32(hWnd
, hWndNext
);
799 /**************************************************************************
800 * ChangeClipboardChain32 (USER32.21)
802 BOOL32 WINAPI
ChangeClipboardChain32(HWND32 hWnd
, HWND32 hWndNext
)
806 dprintf_clipboard(stdnimp
, "ChangeClipboardChain(%04x, %04x)\n", hWnd
, hWndNext
);
809 bRet
= !SendMessage16( hWndViewer
, WM_CHANGECBCHAIN
,
810 (WPARAM16
)hWnd
, (LPARAM
)hWndNext
);
812 dprintf_clipboard(stddeb
,"ChangeClipboardChain: hWndViewer is lost\n");
814 if( hWnd
== hWndViewer
) hWndViewer
= hWndNext
;
821 /**************************************************************************
822 * IsClipboardFormatAvailable16 (USER.193)
824 BOOL16 WINAPI
IsClipboardFormatAvailable16( UINT16 wFormat
)
826 return IsClipboardFormatAvailable32( wFormat
);
830 /**************************************************************************
831 * IsClipboardFormatAvailable32 (USER32.339)
833 BOOL32 WINAPI
IsClipboardFormatAvailable32( UINT32 wFormat
)
835 dprintf_clipboard(stddeb
,"IsClipboardFormatAvailable(%04X) !\n", wFormat
);
837 if( (wFormat
== CF_TEXT
|| wFormat
== CF_OEMTEXT
) &&
838 !selectionAcquired
) CLIPBOARD_RequestXSelection();
840 return CLIPBOARD_IsPresent(wFormat
);
844 /**************************************************************************
845 * GetOpenClipboardWindow16 (USER.248)
847 HWND16 WINAPI
GetOpenClipboardWindow16(void)
849 return hWndClipWindow
;
853 /**************************************************************************
854 * GetOpenClipboardWindow32 (USER32.276)
856 HWND32 WINAPI
GetOpenClipboardWindow32(void)
858 return hWndClipWindow
;
862 /**************************************************************************
863 * GetPriorityClipboardFormat16 (USER.402)
865 INT16 WINAPI
GetPriorityClipboardFormat16( UINT16
*lpPriorityList
, INT16 nCount
)
867 fprintf( stderr
, "GetPriorityClipboardFormat16(%p, %d): stub\n",
868 lpPriorityList
, nCount
);
873 /**************************************************************************
874 * GetPriorityClipboardFormat32 (USER32.279)
876 INT32 WINAPI
GetPriorityClipboardFormat32( UINT32
*lpPriorityList
, INT32 nCount
)
880 if(CountClipboardFormats32() == 0)
885 for(Counter
= 0; Counter
<= nCount
; Counter
++)
887 if(IsClipboardFormatAvailable32(*(lpPriorityList
+sizeof(INT32
)*Counter
)))
888 return *(lpPriorityList
+sizeof(INT32
)*Counter
);
895 /**************************************************************************
896 * CLIPBOARD_ReadSelection
898 * Called from the SelectionNotify event handler.
900 void CLIPBOARD_ReadSelection(Window w
,Atom prop
)
903 LPCLIPFORMAT lpFormat
= ClipFormats
;
905 dprintf_clipboard(stddeb
,"ReadSelection callback\n");
909 Atom atype
=AnyPropertyType
;
911 unsigned long nitems
,remain
;
912 unsigned char* val
=NULL
;
914 dprintf_clipboard(stddeb
,"\tgot property %s\n",XGetAtomName(display
,prop
));
916 /* TODO: Properties longer than 64K */
918 if(XGetWindowProperty(display
,w
,prop
,0,0x3FFF,True
,XA_STRING
,
919 &atype
, &aformat
, &nitems
, &remain
, &val
) != Success
)
920 dprintf_clipboard(stddeb
,"\tcouldn't read property\n");
923 dprintf_clipboard(stddeb
,"\tType %s,Format %d,nitems %ld,value %s\n",
924 XGetAtomName(display
,atype
),aformat
,nitems
,val
);
926 if(atype
== XA_STRING
&& aformat
== 8)
931 dprintf_clipboard(stddeb
,"\tselection is '%s'\n",val
);
933 for(i
=0; i
<= nitems
; i
++)
934 if( val
[i
] == '\n' ) inlcount
++;
938 hText
=GlobalAlloc16(GMEM_MOVEABLE
, nitems
+ inlcount
+ 1);
939 if( (lpstr
= (char*)GlobalLock16(hText
)) )
940 for(i
=0,inlcount
=0; i
<= nitems
; i
++)
942 if( val
[i
] == '\n' ) lpstr
[inlcount
++]='\r';
943 lpstr
[inlcount
++]=val
[i
];
952 /* delete previous CF_TEXT and CF_OEMTEXT data */
956 lpFormat
= &ClipFormats
[CF_TEXT
-1];
957 if (lpFormat
->wDataPresent
|| lpFormat
->hData
)
958 CLIPBOARD_DeleteRecord(lpFormat
, !(hWndClipWindow
));
959 lpFormat
= &ClipFormats
[CF_OEMTEXT
-1];
960 if (lpFormat
->wDataPresent
|| lpFormat
->hData
)
961 CLIPBOARD_DeleteRecord(lpFormat
, !(hWndClipWindow
));
963 lpFormat
->wDataPresent
= 1;
964 lpFormat
->hData
= hText
;
970 /**************************************************************************
971 * CLIPBOARD_ReleaseSelection
973 * Wine might have lost XA_PRIMARY selection because of
974 * EmptyClipboard() or other client.
976 void CLIPBOARD_ReleaseSelection(Window w
, HWND32 hwnd
)
978 /* w is the window that lost selection,
980 * selectionPrevWindow is nonzero if CheckSelection() was called.
983 dprintf_clipboard(stddeb
,"\tevent->window = %08x (sw = %08x, spw=%08x)\n",
984 (unsigned)w
, (unsigned)selectionWindow
, (unsigned)selectionPrevWindow
);
986 if( selectionAcquired
)
987 if( w
== selectionWindow
|| selectionPrevWindow
== None
)
989 /* alright, we really lost it */
991 selectionAcquired
= False
;
992 selectionWindow
= None
;
994 /* but we'll keep existing data for internal use */
996 else if( w
== selectionPrevWindow
)
998 w
= XGetSelectionOwner(display
, XA_PRIMARY
);
1000 XSetSelectionOwner(display
, XA_PRIMARY
, selectionWindow
, CurrentTime
);
1003 selectionPrevWindow
= None
;