4
* This file contains functions for managing the clipboard.
6
* Copyright (c) 1995 Sun Microsystems, Inc.
8
* See the file "license.terms" for information on usage and redistribution
9
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
11
* RCS: @(#) $Id: tkWinClipboard.c,v 1.2 1998/09/14 18:23:59 stanton Exp $
19
*----------------------------------------------------------------------
21
* TkSelGetSelection --
23
* Retrieve the specified selection from another process. For
24
* now, only fetching XA_STRING from CLIPBOARD is supported.
25
* Eventually other types should be allowed.
28
* The return value is a standard Tcl return value.
29
* If an error occurs (such as no selection exists)
30
* then an error message is left in interp->result.
35
*----------------------------------------------------------------------
39
TkSelGetSelection(interp, tkwin, selection, target, proc, clientData)
40
Tcl_Interp *interp; /* Interpreter to use for reporting
42
Tk_Window tkwin; /* Window on whose behalf to retrieve
43
* the selection (determines display
44
* from which to retrieve). */
45
Atom selection; /* Selection to retrieve. */
46
Atom target; /* Desired form in which selection
47
* is to be returned. */
48
Tk_GetSelProc *proc; /* Procedure to call to process the
49
* selection, once it has been retrieved. */
50
ClientData clientData; /* Arbitrary value to pass to proc. */
52
char *data, *buffer, *destPtr;
56
if ((selection == Tk_InternAtom(tkwin, "CLIPBOARD"))
57
&& (target == XA_STRING)) {
58
if (OpenClipboard(NULL)) {
59
handle = GetClipboardData(CF_TEXT);
61
data = GlobalLock(handle);
62
length = strlen(data);
63
buffer = ckalloc(length+1);
65
while (*data != '\0') {
75
result = (*proc)(clientData, interp, buffer);
83
Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection),
84
" selection doesn't exist or form \"", Tk_GetAtomName(tkwin, target),
85
"\" not defined", (char *) NULL);
90
*----------------------------------------------------------------------
92
* TkSetSelectionOwner --
94
* This function claims ownership of the specified selection.
95
* If the selection is CLIPBOARD, then we empty the system
102
* Empties the system clipboard, and claims ownership.
104
*----------------------------------------------------------------------
108
XSetSelectionOwner(display, selection, owner, time)
114
HWND hwnd = owner ? TkWinGetHWND(owner) : NULL;
118
* This is a gross hack because the Tk_InternAtom interface is broken.
119
* It expects a Tk_Window, even though it only needs a Tk_Display.
122
tkwin = (Tk_Window)tkMainWindowList->winPtr;
124
if (selection == Tk_InternAtom(tkwin, "CLIPBOARD")) {
127
* Only claim and empty the clipboard if we aren't already the
128
* owner of the clipboard.
131
if (GetClipboardOwner() != hwnd) {
134
SetClipboardData(CF_TEXT, NULL);
141
*----------------------------------------------------------------------
143
* TkWinClipboardRender --
145
* This function supplies the contents of the clipboard in
146
* response to a WM_RENDERFORMAT message.
152
* Sets the contents of the clipboard.
154
*----------------------------------------------------------------------
158
TkWinClipboardRender(dispPtr, format)
162
TkClipboardTarget *targetPtr;
163
TkClipboardBuffer *cbPtr;
165
char *buffer, *p, *endPtr;
168
for (targetPtr = dispPtr->clipTargetPtr; targetPtr != NULL;
169
targetPtr = targetPtr->nextPtr) {
170
if (targetPtr->type == XA_STRING)
174
if (targetPtr != NULL) {
175
for (cbPtr = targetPtr->firstBufferPtr; cbPtr != NULL;
176
cbPtr = cbPtr->nextPtr) {
177
length += cbPtr->length;
178
for (p = cbPtr->buffer, endPtr = p + cbPtr->length;
186
handle = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, length+1);
190
buffer = GlobalLock(handle);
191
if (targetPtr != NULL) {
192
for (cbPtr = targetPtr->firstBufferPtr; cbPtr != NULL;
193
cbPtr = cbPtr->nextPtr) {
194
for (p = cbPtr->buffer, endPtr = p + cbPtr->length;
204
GlobalUnlock(handle);
205
SetClipboardData(CF_TEXT, handle);
210
*----------------------------------------------------------------------
212
* TkSelUpdateClipboard --
214
* This function is called to force the clipboard to be updated
215
* after new data is added.
221
* Clears the current contents of the clipboard.
223
*----------------------------------------------------------------------
227
TkSelUpdateClipboard(winPtr, targetPtr)
229
TkClipboardTarget *targetPtr;
231
HWND hwnd = TkWinGetHWND(winPtr->window);
235
SetClipboardData(CF_TEXT, NULL);
240
*--------------------------------------------------------------
244
* This procedure is invoked whenever a selection-related
251
* Lots: depends on the type of event.
253
*--------------------------------------------------------------
257
TkSelEventProc(tkwin, eventPtr)
258
Tk_Window tkwin; /* Window for which event was
260
register XEvent *eventPtr; /* X event: either SelectionClear,
261
* SelectionRequest, or
262
* SelectionNotify. */
264
if (eventPtr->type == SelectionClear) {
265
TkSelClearSelection(tkwin, eventPtr);
270
*----------------------------------------------------------------------
274
* This procedure is invoked when property-change events
275
* occur on windows not known to the toolkit. This is a stub
276
* function under Windows.
284
*----------------------------------------------------------------------
288
TkSelPropProc(eventPtr)
289
register XEvent *eventPtr; /* X PropertyChange event. */