head	1.14;
access;
symbols
	core-8-5-9:1.9
	core-8-5-8:1.9
	macosx-cocoa-merge:1.10
	macosx-cocoa-premerge:1.10
	macosx-carbon-freeze:1.10
	core-8-5-7:1.9
	core-8-5-6:1.9
	core-8-6-b1:1.10
	core-8-6-a3:1.9
	core-8-5-5:1.9
	core-8-6-a2:1.9
	core-8-5-4:1.9
	core-8-5-3:1.9
	core-8-6-a1:1.9
	core-8-4-19:1.7
	core-8-5-branch:1.9.0.4
	core-8-5-2:1.9
	core-8-4-18:1.7
	core-8-5-1:1.9
	core-8-4-17:1.7
	core-8-5-0:1.9
	core-8-5-b3:1.9
	core-8-5-b2:1.9
	core-8-4-16:1.7
	core-8-5-b1:1.9
	core-stablilizer-merge:1.9
	core-stabilizer-branch:1.9.0.2
	core-stabilizer-merge:1.9
	core-8-4-15:1.7
	core-8-5-a6:1.9
	core-8-5-a5:1.8
	core-8-4-14:1.7
	core-8-5-a4:1.8
	core-8-4-13:1.7
	core-8-4-12:1.7
	core-8-4-11:1.7
	core-8-5-a3:1.7
	core-8-4-10:1.7
	core-8-4-9-branch:1.7.0.14
	core-8-5-a2:1.7
	core-8-4-9:1.7
	core-8-4-8:1.7
	core-8-4-7:1.7
	core-8-5-a1:1.7
	core-8-4-6:1.7
	core-8-4-5:1.7
	mistachkin-dev-branch:1.7.0.12
	core-8-4-4:1.7
	core-8-4-3:1.7
	core-8-4-branch:1.7.0.10
	core-8-4-2:1.7
	core-8-4-1:1.7
	core-8-3-5:1.7
	core-8-4-0:1.7
	macosx-8-4-merge-2002-08-31-trunk:1.7
	macosx-8-4-premerge-2002-08-31-branch:1.7
	macosx-8-4-premerge-2002-08-31-trunk:1.7
	macosx-8-4-merge-2002-08-30-branch:1.7
	macosx-8-4-merge-2002-08-30-trunk:1.7
	macosx-8-4-merge-2002-08-20-branch:1.7
	macosx-8-4-merge-2002-08-20-trunk:1.7
	core-8-4-b2:1.7
	core-8-4-b1:1.7
	macosx-premerge-6-9-02:1.7
	core-8-4-a4:1.7
	core-8-3-4:1.7
	macosx-8-4-branch:1.7.0.8
	macosx-8-4-branchpoint:1.7
	core-8-4-a3:1.7
	core-8-3-3:1.7
	dgp-privates-into-namespace:1.7.0.6
	tclpro-1-5-0:1.7
	core-8-4-win-speedup:1.7.0.4
	core-8-4-a2:1.7
	tclpro-1-4-1:1.7
	tclpro-1-4-0:1.7
	core-8-3-2:1.7
	ajuba-ajuba2-2-1-base:1.7
	ajuba-ajuba2-2-0:1.7
	core-8-4-a1:1.7
	core-8-3-1-branch:1.7.0.2
	core-8-3-1:1.7
	scriptics-sc-2-0-b5:1.6
	scriptics-sc-2-0-fixed:1.6
	scriptics-sc-2-0-b2:1.6
	scriptics-sc-2-0-b1:1.6
	core-8-3-0:1.6
	core-8-3-b2:1.6
	core-8-3-b1:1.6
	scriptics-sc-1-1:1.5
	scriptics-sc-1-1-b1:1.5
	core-8-2-3:1.5
	scriptics-sc-1-1-branch:1.5.0.8
	scriptics-sc-1-1-base:1.5
	scriptics-sc-1-0:1.5
	scriptics-sc-1-0-branch:1.5.0.6
	scriptics-sc-1-0-base:1.5
	core-8-2-2:1.5
	core-8-2-1:1.5
	scriptics-bc-1-0-b1:1.5
	core-8-2-1-branch:1.5.0.4
	scriptics-tclpro-1-3-0:1.5
	core-8-2-0:1.5
	core-8-2-b3-branch:1.5.0.2
	core-8-2-b3-base:1.5
	scriptics-tclpro-1-3-b4:1.5
	core-8-2-b2:1.5
	scriptics-tclpro-1-3-b3:1.5
	core-8-2-b1:1.5
	scriptics-tclpro-1-3-b2:1.3.2.1
	merge-to-mainline-5/21/99:1.3.2.1
	scriptics-tclpro-1-3-b2-branch:1.3.0.2
	core-8-1-1:1.3.2.1
	scriptics-tclpro-1-3-b1:1.3
	core-8-1-1-base:1.3
	core-8-1-0:1.3
	merge-to-mainline-4-29-99:1.3
	merge-to-mainline-4-23-99:1.3
	core-8-1-branch-old:1.1.0.4
	core-8-0-6-branch:1.2.0.6
	core-8-0-6-base:1.2
	core-8-0-5:1.2
	core-8-1-b3:1.1.4.4
	core-8-1-b2:1.1.4.4
	dev-8-1-stubs-branch:1.1.4.4.0.2
	dev-stubs-branch:1.2.0.4
	scriptics-tclpro-1-2:1.2
	scriptics-tclpro-1-2-b2:1.2
	core-8-1-merge-2/10/99:1.2
	core-8-0-5-branch:1.2.0.2
	core-8-0-5-base:1.2
	scriptics-tclpro-1-2-b1:1.2
	scriptics-tclpro-1-2-a1:1.2
	core-8-1-b1:1.1.4.3
	core-8-0-4:1.2
	core-8-1-a2:1.1.4.1
	core-8-0-2:1.1
	core-8-0-3:1.2;
locks; strict;
comment	@ * @;


1.14
date	2010.11.03.12.11.44;	author nijtmans;	state Exp;
branches;
next	1.13;

1.13
date	2010.10.06.14.33.29;	author nijtmans;	state Exp;
branches;
next	1.12;

1.12
date	2010.09.10.08.59.25;	author nijtmans;	state Exp;
branches;
next	1.11;

1.11
date	2009.08.02.21.40.17;	author nijtmans;	state Exp;
branches;
next	1.10;

1.10
date	2008.11.08.18.44.40;	author dkf;	state Exp;
branches;
next	1.9;

1.9
date	2007.01.11.15.35.40;	author dkf;	state Exp;
branches;
next	1.8;

1.8
date	2005.12.02.00.19.04;	author dkf;	state Exp;
branches;
next	1.7;

1.7
date	2000.04.12.18.51.11;	author hobbs;	state Exp;
branches;
next	1.6;

1.6
date	99.09.21.06.43.06;	author hobbs;	state Exp;
branches;
next	1.5;

1.5
date	99.05.22.02.05.31;	author stanton;	state Exp;
branches;
next	1.4;

1.4
date	99.05.22.01.59.22;	author stanton;	state Exp;
branches;
next	1.3;

1.3
date	99.04.16.01.51.49;	author stanton;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	98.09.14.18.23.59;	author stanton;	state Exp;
branches;
next	1.1;

1.1
date	98.04.01.10.00.28;	author rjohnson;	state Exp;
branches
	1.1.4.1;
next	;

1.1.4.1
date	98.09.29.00.26.05;	author stanton;	state Exp;
branches;
next	1.1.4.2;

1.1.4.2
date	98.09.30.02.19.29;	author stanton;	state Exp;
branches;
next	1.1.4.3;

1.1.4.3
date	98.12.08.23.28.52;	author stanton;	state Exp;
branches;
next	1.1.4.4;

1.1.4.4
date	98.12.13.08.16.16;	author lfb;	state Exp;
branches;
next	;

1.3.2.1
date	99.05.18.22.27.34;	author stanton;	state Exp;
branches;
next	;


desc
@@


1.14
log
@[FRQ 2965056]: Windows build with -DUNICODE
@
text
@/*
 * tkWinClipboard.c --
 *
 *	This file contains functions for managing the clipboard.
 *
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
 * Copyright (c) 1998-2000 by Scriptics Corporation.
 *
 * See the file "license.terms" for information on usage and redistribution of
 * this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * RCS: @@(#) $Id: tkWinClipboard.c,v 1.13 2010/10/06 14:33:29 nijtmans Exp $
 */

#include "tkWinInt.h"
#include "tkSelect.h"

static void		UpdateClipboard(HWND hwnd);

/*
 *----------------------------------------------------------------------
 *
 * TkSelGetSelection --
 *
 *	Retrieve the specified selection from another process. For now, only
 *	fetching XA_STRING from CLIPBOARD is supported. Eventually other types
 *	should be allowed.
 *
 * Results:
 *	The return value is a standard Tcl return value. If an error occurs
 *	(such as no selection exists) then an error message is left in the
 *	interp's result.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

int
TkSelGetSelection(
    Tcl_Interp *interp,		/* Interpreter to use for reporting errors. */
    Tk_Window tkwin,		/* Window on whose behalf to retrieve the
				 * selection (determines display from which to
				 * retrieve). */
    Atom selection,		/* Selection to retrieve. */
    Atom target,		/* Desired form in which selection is to be
				 * returned. */
    Tk_GetSelProc *proc,	/* Procedure to call to process the selection,
				 * once it has been retrieved. */
    ClientData clientData)	/* Arbitrary value to pass to proc. */
{
    char *data, *destPtr;
    Tcl_DString ds;
    HGLOBAL handle;
    Tcl_Encoding encoding;
    int result, locale;

    if ((selection != Tk_InternAtom(tkwin, "CLIPBOARD"))
	    || (target != XA_STRING)
	    || !OpenClipboard(NULL)) {
	goto error;
    }

    /*
     * Attempt to get the data in Unicode form if available as this is less
     * work that CF_TEXT.
     */

    result = TCL_ERROR;
    if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
	handle = GetClipboardData(CF_UNICODETEXT);
	if (!handle) {
	    CloseClipboard();
	    goto error;
	}
	data = GlobalLock(handle);
	Tcl_DStringInit(&ds);
	Tcl_UniCharToUtfDString((Tcl_UniChar *)data,
		Tcl_UniCharLen((Tcl_UniChar *)data), &ds);
	GlobalUnlock(handle);
    } else if (IsClipboardFormatAvailable(CF_TEXT)) {
	/*
	 * Determine the encoding to use to convert this text.
	 */

	if (IsClipboardFormatAvailable(CF_LOCALE)) {
	    handle = GetClipboardData(CF_LOCALE);
	    if (!handle) {
		CloseClipboard();
		goto error;
	    }

	    /*
	     * Get the locale identifier, determine the proper code page to
	     * use, and find the corresponding encoding.
	     */

	    Tcl_DStringInit(&ds);
	    Tcl_DStringAppend(&ds, "cp######", -1);
	    data = GlobalLock(handle);

	    /*
	     * Even though the documentation claims that GetLocaleInfo expects
	     * an LCID, on Windows 9x it really seems to expect a LanguageID.
	     */

	    locale = LANGIDFROMLCID(*((int*)data));
	    GetLocaleInfoA(locale, LOCALE_IDEFAULTANSICODEPAGE,
		    Tcl_DStringValue(&ds)+2, Tcl_DStringLength(&ds)-2);
	    GlobalUnlock(handle);

	    encoding = Tcl_GetEncoding(NULL, Tcl_DStringValue(&ds));
	    Tcl_DStringFree(&ds);
	} else {
	    encoding = NULL;
	}

	/*
	 * Fetch the text and convert it to UTF.
	 */

	handle = GetClipboardData(CF_TEXT);
	if (!handle) {
	    if (encoding) {
		Tcl_FreeEncoding(encoding);
	    }
	    CloseClipboard();
	    goto error;
	}
	data = GlobalLock(handle);
	Tcl_ExternalToUtfDString(encoding, data, -1, &ds);
	GlobalUnlock(handle);
	if (encoding) {
	    Tcl_FreeEncoding(encoding);
	}

    } else {
	CloseClipboard();
	goto error;
    }

    /*
     * Translate CR/LF to LF.
     */

    data = destPtr = Tcl_DStringValue(&ds);
    while (*data) {
	if (data[0] == '\r' && data[1] == '\n') {
	    data++;
	} else {
	    *destPtr++ = *data++;
	}
    }
    *destPtr = '\0';

    /*
     * Pass the data off to the selection procedure.
     */

    result = proc(clientData, interp, Tcl_DStringValue(&ds));
    Tcl_DStringFree(&ds);
    CloseClipboard();
    return result;

  error:
    Tcl_AppendResult(interp, Tk_GetAtomName(tkwin, selection),
	    " selection doesn't exist or form \"",
	    Tk_GetAtomName(tkwin, target), "\" not defined", NULL);
    return TCL_ERROR;
}

/*
 *----------------------------------------------------------------------
 *
 * TkSetSelectionOwner --
 *
 *	This function claims ownership of the specified selection. If the
 *	selection is CLIPBOARD, then we empty the system clipboard.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Empties the system clipboard, and claims ownership.
 *
 *----------------------------------------------------------------------
 */

void
XSetSelectionOwner(
    Display *display,
    Atom selection,
    Window owner,
    Time time)
{
    HWND hwnd = owner ? TkWinGetHWND(owner) : NULL;
    Tk_Window tkwin;

    /*
     * This is a gross hack because the Tk_InternAtom interface is broken. It
     * expects a Tk_Window, even though it only needs a Tk_Display.
     */

    tkwin = (Tk_Window) TkGetMainInfoList()->winPtr;

    if (selection == Tk_InternAtom(tkwin, "CLIPBOARD")) {
	/*
	 * Only claim and empty the clipboard if we aren't already the owner
	 * of the clipboard.
	 */

	if (GetClipboardOwner() != hwnd) {
	    UpdateClipboard(hwnd);
	}
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkWinClipboardRender --
 *
 *	This function supplies the contents of the clipboard in response to a
 *	WM_RENDERFORMAT message.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Sets the contents of the clipboard.
 *
 *----------------------------------------------------------------------
 */

void
TkWinClipboardRender(
    TkDisplay *dispPtr,
    UINT format)
{
    TkClipboardTarget *targetPtr;
    TkClipboardBuffer *cbPtr;
    HGLOBAL handle;
    char *buffer, *p, *rawText, *endPtr;
    int length;
    Tcl_DString ds;

    for (targetPtr = dispPtr->clipTargetPtr; targetPtr != NULL;
	    targetPtr = targetPtr->nextPtr) {
	if (targetPtr->type == XA_STRING) {
	    break;
	}
    }

    /*
     * Count the number of newlines so we can add space for them in the
     * resulting string.
     */

    length = 0;
    if (targetPtr != NULL) {
	for (cbPtr = targetPtr->firstBufferPtr; cbPtr != NULL;
		cbPtr = cbPtr->nextPtr) {
	    length += cbPtr->length;
	    for (p = cbPtr->buffer, endPtr = p + cbPtr->length;
		    p < endPtr; p++) {
		if (*p == '\n') {
		    length++;
		}
	    }
	}
    }

    /*
     * Copy the data and change EOL characters.
     */

    buffer = rawText = ckalloc((unsigned)length + 1);
    if (targetPtr != NULL) {
	for (cbPtr = targetPtr->firstBufferPtr; cbPtr != NULL;
		cbPtr = cbPtr->nextPtr) {
	    for (p = cbPtr->buffer, endPtr = p + cbPtr->length;
		    p < endPtr; p++) {
		if (*p == '\n') {
		    *buffer++ = '\r';
		}
		*buffer++ = *p;
	    }
	}
    }
    *buffer = '\0';

    /*
     * Depending on the platform, turn the data into Unicode or the system
     * encoding before placing it on the clipboard.
     */

#ifdef UNICODE
	Tcl_DStringInit(&ds);
	Tcl_UtfToUniCharDString(rawText, -1, &ds);
	ckfree(rawText);
	handle = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE,
		(unsigned) Tcl_DStringLength(&ds) + 2);
	if (!handle) {
	    Tcl_DStringFree(&ds);
	    return;
	}
	buffer = GlobalLock(handle);
	memcpy(buffer, Tcl_DStringValue(&ds),
		(unsigned) Tcl_DStringLength(&ds) + 2);
	GlobalUnlock(handle);
	Tcl_DStringFree(&ds);
	SetClipboardData(CF_UNICODETEXT, handle);
#else
	Tcl_UtfToExternalDString(NULL, rawText, -1, &ds);
	ckfree(rawText);
	handle = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE,
		(unsigned) Tcl_DStringLength(&ds) + 1);
	if (!handle) {
	    Tcl_DStringFree(&ds);
	    return;
	}
	buffer = GlobalLock(handle);
	memcpy(buffer, Tcl_DStringValue(&ds),
		(unsigned) Tcl_DStringLength(&ds) + 1);
	GlobalUnlock(handle);
	Tcl_DStringFree(&ds);
	SetClipboardData(CF_TEXT, handle);
#endif
}

/*
 *----------------------------------------------------------------------
 *
 * TkSelUpdateClipboard --
 *
 *	This function is called to force the clipboard to be updated after new
 *	data is added.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Clears the current contents of the clipboard.
 *
 *----------------------------------------------------------------------
 */

void
TkSelUpdateClipboard(
    TkWindow *winPtr,
    TkClipboardTarget *targetPtr)
{
    HWND hwnd = TkWinGetHWND(winPtr->window);
    UpdateClipboard(hwnd);
}

/*
 *----------------------------------------------------------------------
 *
 * UpdateClipboard --
 *
 *	Take ownership of the clipboard, clear it, and indicate to the system
 *	the supported formats.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

static void
UpdateClipboard(
    HWND hwnd)
{
    TkWinUpdatingClipboard(TRUE);
    OpenClipboard(hwnd);
    EmptyClipboard();

    /*
     * CF_UNICODETEXT is only supported on NT, but it it is prefered when
     * possible.
     */

    if (TkWinGetPlatformId() != VER_PLATFORM_WIN32_WINDOWS) {
	SetClipboardData(CF_UNICODETEXT, NULL);
    } else {
	SetClipboardData(CF_TEXT, NULL);
    }
    CloseClipboard();
    TkWinUpdatingClipboard(FALSE);
}

/*
 *--------------------------------------------------------------
 *
 * TkSelEventProc --
 *
 *	This procedure is invoked whenever a selection-related event occurs.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Lots: depends on the type of event.
 *
 *--------------------------------------------------------------
 */

void
TkSelEventProc(
    Tk_Window tkwin,		/* Window for which event was targeted. */
    register XEvent *eventPtr)	/* X event: either SelectionClear,
				 * SelectionRequest, or SelectionNotify. */
{
    if (eventPtr->type == SelectionClear) {
	TkSelClearSelection(tkwin, eventPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * TkSelPropProc --
 *
 *	This procedure is invoked when property-change events occur on windows
 *	not known to the toolkit. This is a stub function under Windows.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */

void
TkSelPropProc(
    register XEvent *eventPtr)	/* X PropertyChange event. */
{
}

/*
 * Local Variables:
 * mode: c
 * c-basic-offset: 4
 * fill-column: 78
 * End:
 */
@


1.13
log
@ [FRQ 2965056]: Windows build with -DUNICODE
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinClipboard.c,v 1.12 2010/09/10 08:59:25 nijtmans Exp $
d298 1
a298 1
    if (TkWinGetPlatformId() != VER_PLATFORM_WIN32_WINDOWS) {
d314 1
a314 1
    } else {
d329 1
a329 1
    }
@


1.12
log
@Make compilable with -DUNICODE, or mark files with a TODO which are not done yet.
tkWinPort.h:  mingw/cygwin fixes: <tchar.h> should always be included here.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinClipboard.c,v 1.11 2009/08/02 21:40:17 nijtmans Exp $
a14 6
/* TODO: This file does not compile in UNICODE mode.
 * See [Freq 2965056]: Windows build with -DUNICODE
 */
#undef UNICODE
#undef _UNICODE

d109 1
a109 1
	    GetLocaleInfo(locale, LOCALE_IDEFAULTANSICODEPAGE,
@


1.11
log
@eliminate various gcc and msvc compiler warnings
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinClipboard.c,v 1.10 2008/11/08 18:44:40 dkf Exp $
d15 6
@


1.10
log
@Lots of small changes to make code more pretty and C89-like.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinClipboard.c,v 1.9 2007/01/11 15:35:40 dkf Exp $
d298 1
a298 1
    if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
d388 1
a388 1
    if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
@


1.9
log
@Many minute fixes to reduce number of minor warnings from GCC.
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinClipboard.c,v 1.8 2005/12/02 00:19:04 dkf Exp $
d161 1
a161 1
    result = (*proc)(clientData, interp, Tcl_DStringValue(&ds));
@


1.8
log
@ANSIfication
@
text
@d12 1
a12 1
 * RCS: @@(#) $Id: tkWinClipboard.c,v 1.7 2000/04/12 18:51:11 hobbs Exp $
d278 1
a278 1
    buffer = rawText = ckalloc(length + 1);
d303 1
a303 1
		Tcl_DStringLength(&ds)+2);
d309 2
a310 1
	memcpy(buffer, Tcl_DStringValue(&ds), Tcl_DStringLength(&ds) + 2);
d318 1
a318 1
		Tcl_DStringLength(&ds)+1);
d324 2
a325 1
	memcpy(buffer, Tcl_DStringValue(&ds), Tcl_DStringLength(&ds) + 1);
@


1.7
log
@	* test/winClipboard.test:
	* win/tkWinInt.h:
	* win/tkWinClipboard.c (UpdateClipboard):
	* win/tkWinX.c (GenerateXEvent): added updatingClipboard tsd and
	TkWinUpdatingClipboard accessor function to allow us to flag
	ourselves when we are the ones updating the clipboard.  This
	corrected inability to create our own clipboard types within a Tk
	application.  [Bug: 2338 4318]
	* win/tkWinTest.c (TestclipboardCmd): improved TestclipboardCmd
	with better error handling and obj'ification
@
text
@d1 1
a1 1
/* 
d9 2
a10 2
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
d12 1
a12 1
 * RCS: @@(#) $Id: tkWinClipboard.c,v 1.6 1999/09/21 06:43:06 hobbs Exp $
d18 1
a18 1
static void	UpdateClipboard _ANSI_ARGS_((HWND hwnd));
d25 4
a28 4
 *	Retrieve the specified selection from another process.  For
 *	now, only fetching XA_STRING from CLIPBOARD is supported.
 *	Eventually other types should be allowed.
 * 
d30 3
a32 3
 *	The return value is a standard Tcl return value.
 *	If an error occurs (such as no selection exists)
 *	then an error message is left in the interp's result.
d41 11
a51 12
TkSelGetSelection(interp, tkwin, selection, target, proc, clientData)
    Tcl_Interp *interp;		/* Interpreter to use for reporting
				 * errors. */
    Tk_Window tkwin;		/* Window on whose behalf to retrieve
				 * the selection (determines display
				 * from which to retrieve). */
    Atom selection;		/* Selection to retrieve. */
    Atom target;		/* Desired form in which selection
				 * is to be returned. */
    Tk_GetSelProc *proc;	/* Procedure to call to process the
				 * selection, once it has been retrieved. */
    ClientData clientData;	/* Arbitrary value to pass to proc. */
d66 2
a67 2
     * Attempt to get the data in Unicode form if available as this is
     * less work that CF_TEXT.
d95 2
a96 2
	     * Get the locale identifier, determine the proper code page
	     * to use, and find the corresponding encoding.
a101 1
	    
d104 2
a105 3
	     * Even though the documentation claims that GetLocaleInfo 
	     * expects an LCID, on Windows 9x it really seems to expect
	     * a LanguageID.
d146 1
a146 1
	
d165 2
a166 2
     
error:
d169 1
a169 2
	    Tk_GetAtomName(tkwin, target),
	    "\" not defined", (char *) NULL);
d178 2
a179 3
 *	This function claims ownership of the specified selection.
 *	If the selection is CLIPBOARD, then we empty the system
 *	clipboard.
d191 5
a195 5
XSetSelectionOwner(display, selection, owner, time)
    Display* display;
    Atom selection;
    Window owner;
    Time time;
d201 2
a202 2
     * This is a gross hack because the Tk_InternAtom interface is broken.
     * It expects a Tk_Window, even though it only needs a Tk_Display.
a207 1

d209 2
a210 2
	 * Only claim and empty the clipboard if we aren't already the
	 * owner of the clipboard.
d224 2
a225 2
 *	This function supplies the contents of the clipboard in
 *	response to a WM_RENDERFORMAT message.
d237 3
a239 3
TkWinClipboardRender(dispPtr, format)
    TkDisplay *dispPtr;
    UINT format;
d250 1
a250 1
	if (targetPtr->type == XA_STRING)
d252 1
d256 2
a257 2
     * Count the number of newlines so we can add space for them in
     * the resulting string.
d294 2
a295 2
     * Depending on the platform, turn the data into Unicode or the
     * system encoding before placing it on the clipboard.
a327 2

    return;
d335 2
a336 2
 *	This function is called to force the clipboard to be updated
 *	after new data is added.
d348 3
a350 3
TkSelUpdateClipboard(winPtr, targetPtr)
    TkWindow *winPtr;
    TkClipboardTarget *targetPtr;
d361 2
a362 2
 *	Take ownership of the clipboard, clear it, and indicate to the
 *	system the supported formats.
d374 2
a375 2
UpdateClipboard(hwnd)
    HWND hwnd;
d382 2
a383 2
     * CF_UNICODETEXT is only supported on NT, but it it is prefered
     * when possible.
d400 1
a400 2
 *	This procedure is invoked whenever a selection-related
 *	event occurs. 
d406 1
a406 1
 *	Lots:  depends on the type of event.
d412 4
a415 6
TkSelEventProc(tkwin, eventPtr)
    Tk_Window tkwin;		/* Window for which event was
				 * targeted. */
    register XEvent *eventPtr;	/* X event:  either SelectionClear,
				 * SelectionRequest, or
				 * SelectionNotify. */
d427 2
a428 3
 *	This procedure is invoked when property-change events
 *	occur on windows not known to the toolkit.  This is a stub
 *	function under Windows.
d440 2
a441 2
TkSelPropProc(eventPtr)
    register XEvent *eventPtr;		/* X PropertyChange event. */
d444 8
@


1.6
log
@1999-09-16  Jeff Hobbs  <hobbs@@scriptics.com>

	* generic/tkFont.c: fixed processing of font options and error
	returned [Bug: 2075]

	* win/tkWinWm.c: fixed bug in 'wm deiconify' that raised the
	wrong toplevel, and changed it to not set focus on overridden
	toplevels

1999-09-15  Jeff Hobbs  <hobbs@@scriptics.com>

	* unix/aclocal.m4: added fix for FreeBSD-[1-2] recognition [Bug: 2070]
	and fix to AIX-* to get ldAix right [Bug: 2624], fixed AIX
	version check (readjust from 8-21 fix) and several other config
	fixes for AIX
	* mac/tkMacMenubutton.c:
	* unix/tkUnixMenubu.c: fixed permanently stippled menubutton image
	* win/tkWinButton.c: fixed possible pointer smash [Bug: 2733]

1999-09-14  Jeff Hobbs  <hobbs@@scriptics.com>

	* win/tkWinMenu.c: fix for stack overrun in GetTextFace [Bug: 909]
@
text
@d7 1
d12 1
a12 1
 * RCS: @@(#) $Id: tkWinClipboard.c,v 1.5 1999/05/22 02:05:31 stanton Exp $
d384 1
d399 1
@


1.5
log
@Fixed bug in Windows clipboard code when dealing with selections that don't contain locale information.
@
text
@d11 1
a11 1
 * RCS: @@(#) $Id: tkWinClipboard.c,v 1.4 1999/05/22 01:59:22 stanton Exp $
d387 1
a387 1
     * CF_UNICODETEXT is only supported on NT, but it it is preffered
@


1.4
log
@Merged changes from scriptics-tclpro-1-3-b2 branch
@
text
@d11 1
a11 1
 * RCS: @@(#) $Id: tkWinClipboard.c,v 1.3 1999/04/16 01:51:49 stanton Exp $
d82 1
a82 2
    } else if (IsClipboardFormatAvailable(CF_TEXT)
	    && IsClipboardFormatAvailable(CF_LOCALE)) {
d87 32
a118 32
	handle = GetClipboardData(CF_LOCALE);
	if (!handle) {
	    CloseClipboard();
	    goto error;
	}

	/*
	 * Get the locale identifier, determine the proper code page to use,
	 * and find the corresponding encoding.
	 */

	Tcl_DStringInit(&ds);
	Tcl_DStringAppend(&ds, "cp######", -1);
	data = GlobalLock(handle);
	

	/*
	 * Even though the documentation claims that GetLocaleInfo expects an
	 * LCID, on Windows 9x it really seems to expect a LanguageID.
	 */

	locale = LANGIDFROMLCID(*((int*)data));
	GetLocaleInfo(locale, LOCALE_IDEFAULTANSICODEPAGE,
		Tcl_DStringValue(&ds)+2, Tcl_DStringLength(&ds)-2);
	GlobalUnlock(handle);

	encoding = Tcl_GetEncoding(NULL, Tcl_DStringValue(&ds));
	Tcl_DStringFree(&ds);

	if (!encoding) {
	    CloseClipboard();
	    goto error;
d127 3
a129 1
	    Tcl_FreeEncoding(encoding);
d136 3
a138 1
	Tcl_FreeEncoding(encoding);
@


1.3
log
@* Merged 8.1 branch into the main trunk
@
text
@d11 1
a11 1
 * RCS: @@(#) $Id$
d17 1
d53 1
a53 1
    char *data, *buffer, *destPtr;
d56 2
a57 1
    int result, length;
d59 70
a128 25
    if ((selection == Tk_InternAtom(tkwin, "CLIPBOARD"))
	    && (target == XA_STRING)) {
	if (OpenClipboard(NULL)) {
	    handle = GetClipboardData(CF_TEXT);
	    if (handle != NULL) {
		data = GlobalLock(handle);
		length = strlen(data);
		buffer = ckalloc(length+1);
		destPtr = buffer;
		while (*data != '\0') {
		    if (*data != '\r') {
			*destPtr = *data;
			destPtr++;
		    }
		    data++;
		}
		*destPtr = '\0';
		GlobalUnlock(handle);
		CloseClipboard();
		Tcl_ExternalToUtfDString(NULL, buffer, -1, &ds);
		ckfree(buffer);
		result = (*proc)(clientData, interp, Tcl_DStringValue(&ds));
		Tcl_DStringFree(&ds);
		return result;
	    }
d130 22
d154 1
d156 10
d167 3
a169 2
	" selection doesn't exist or form \"", Tk_GetAtomName(tkwin, target),
	"\" not defined", (char *) NULL);
d216 1
a216 4
	    OpenClipboard(hwnd);
	    EmptyClipboard();
	    SetClipboardData(CF_TEXT, NULL);
	    CloseClipboard();
d255 6
d274 5
d293 33
a325 5
    Tcl_UtfToExternalDString(NULL, rawText, -1, &ds);
    ckfree(rawText);
    handle = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE,
	    Tcl_DStringLength(&ds)+1);
    if (!handle) {
d327 1
a327 1
	return;
d329 1
a329 5
    buffer = GlobalLock(handle);
    memcpy(buffer, Tcl_DStringValue(&ds), Tcl_DStringLength(&ds) + 1);
    GlobalUnlock(handle);
    Tcl_DStringFree(&ds);
    SetClipboardData(CF_TEXT, handle);
d356 19
d376 4
d382 11
a392 1
    SetClipboardData(CF_TEXT, NULL);
@


1.3.2.1
log
@* tests/winClipboard.test:
* win/tkWinClipboard.c: Fixed clipboard code so it handles Unicode
data properly on Windows NT and 95. [Bug: 1791]
@
text
@d11 1
a11 1
 * RCS: @@(#) $Id: tkWinClipboard.c,v 1.3 1999/04/16 01:51:49 stanton Exp $
a16 1
static void	UpdateClipboard _ANSI_ARGS_((HWND hwnd));
d52 1
a52 1
    char *data, *destPtr;
d55 1
a55 2
    Tcl_Encoding encoding;
    int result, locale;
d57 25
a81 70
    if ((selection != Tk_InternAtom(tkwin, "CLIPBOARD"))
	    || (target != XA_STRING)
	    || !OpenClipboard(NULL)) {
	goto error;
    }

    /*
     * Attempt to get the data in Unicode form if available as this is
     * less work that CF_TEXT.
     */

    result = TCL_ERROR;
    if (IsClipboardFormatAvailable(CF_UNICODETEXT)) {
	handle = GetClipboardData(CF_UNICODETEXT);
	if (!handle) {
	    CloseClipboard();
	    goto error;
	}
	data = GlobalLock(handle);
	Tcl_DStringInit(&ds);
	Tcl_UniCharToUtfDString((Tcl_UniChar *)data,
		Tcl_UniCharLen((Tcl_UniChar *)data), &ds);
	GlobalUnlock(handle);
    } else if (IsClipboardFormatAvailable(CF_TEXT)
	    && IsClipboardFormatAvailable(CF_LOCALE)) {
	/*
	 * Determine the encoding to use to convert this text.
	 */

	handle = GetClipboardData(CF_LOCALE);
	if (!handle) {
	    CloseClipboard();
	    goto error;
	}

	/*
	 * Get the locale identifier, determine the proper code page to use,
	 * and find the corresponding encoding.
	 */

	Tcl_DStringInit(&ds);
	Tcl_DStringAppend(&ds, "cp######", -1);
	data = GlobalLock(handle);
	

	/*
	 * Even though the documentation claims that GetLocaleInfo expects an
	 * LCID, on Windows 9x it really seems to expect a LanguageID.
	 */

	locale = LANGIDFROMLCID(*((int*)data));
	GetLocaleInfo(locale, LOCALE_IDEFAULTANSICODEPAGE,
		Tcl_DStringValue(&ds)+2, Tcl_DStringLength(&ds)-2);
	GlobalUnlock(handle);

	encoding = Tcl_GetEncoding(NULL, Tcl_DStringValue(&ds));
	Tcl_DStringFree(&ds);

	if (!encoding) {
	    CloseClipboard();
	    goto error;
	}

	/*
	 * Fetch the text and convert it to UTF.
	 */

	handle = GetClipboardData(CF_TEXT);
	if (!handle) {
	    Tcl_FreeEncoding(encoding);
a82 22
	    goto error;
	}
	data = GlobalLock(handle);
	Tcl_ExternalToUtfDString(encoding, data, -1, &ds);
	GlobalUnlock(handle);
	Tcl_FreeEncoding(encoding);

    } else {
	CloseClipboard();
	goto error;
    }

    /*
     * Translate CR/LF to LF.
     */
	
    data = destPtr = Tcl_DStringValue(&ds);
    while (*data) {
	if (data[0] == '\r' && data[1] == '\n') {
	    data++;
	} else {
	    *destPtr++ = *data++;
a84 1
    *destPtr = '\0';
a85 10
    /*
     * Pass the data off to the selection procedure.
     */

    result = (*proc)(clientData, interp, Tcl_DStringValue(&ds));
    Tcl_DStringFree(&ds);
    CloseClipboard();
    return result;
     
error:
d87 2
a88 3
	    " selection doesn't exist or form \"",
	    Tk_GetAtomName(tkwin, target),
	    "\" not defined", (char *) NULL);
d135 4
a138 1
	    UpdateClipboard(hwnd);
a176 6

    /*
     * Count the number of newlines so we can add space for them in
     * the resulting string.
     */

a189 5

    /*
     * Copy the data and change EOL characters.
     */

d204 5
a208 33

    /*
     * Depending on the platform, turn the data into Unicode or the
     * system encoding before placing it on the clipboard.
     */

    if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
	Tcl_DStringInit(&ds);
	Tcl_UtfToUniCharDString(rawText, -1, &ds);
	ckfree(rawText);
	handle = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE,
		Tcl_DStringLength(&ds)+2);
	if (!handle) {
	    Tcl_DStringFree(&ds);
	    return;
	}
	buffer = GlobalLock(handle);
	memcpy(buffer, Tcl_DStringValue(&ds), Tcl_DStringLength(&ds) + 2);
	GlobalUnlock(handle);
	Tcl_DStringFree(&ds);
	SetClipboardData(CF_UNICODETEXT, handle);
    } else {
	Tcl_UtfToExternalDString(NULL, rawText, -1, &ds);
	ckfree(rawText);
	handle = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE,
		Tcl_DStringLength(&ds)+1);
	if (!handle) {
	    Tcl_DStringFree(&ds);
	    return;
	}
	buffer = GlobalLock(handle);
	memcpy(buffer, Tcl_DStringValue(&ds), Tcl_DStringLength(&ds) + 1);
	GlobalUnlock(handle);
d210 1
a210 1
	SetClipboardData(CF_TEXT, handle);
d212 5
a216 1

a242 19
    UpdateClipboard(hwnd);
}

/*
 *----------------------------------------------------------------------
 *
 * UpdateClipboard --
 *
 *	Take ownership of the clipboard, clear it, and indicate to the
 *	system the supported formats.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	None.
 *
 *----------------------------------------------------------------------
 */
a243 4
static void
UpdateClipboard(hwnd)
    HWND hwnd;
{
d246 1
a246 11

    /*
     * CF_UNICODETEXT is only supported on NT, but it it is preffered
     * when possible.
     */

    if (TkWinGetPlatformId() == VER_PLATFORM_WIN32_NT) {
	SetClipboardData(CF_UNICODETEXT, NULL);
    } else {
	SetClipboardData(CF_TEXT, NULL);
    }
@


1.2
log
@Replaced SCCS strings, fixed binary files
@
text
@d6 1
a6 1
 * Copyright (c) 1995 Sun Microsystems, Inc.
d30 1
a30 1
 *	then an error message is left in interp->result.
d53 1
d76 1
a76 1
		result = (*proc)(clientData, interp, buffer);
d78 2
d125 1
a125 1
    tkwin = (Tk_Window)tkMainWindowList->winPtr;
d168 1
a168 1
    char *buffer, *p, *endPtr;
d170 1
d190 1
a190 5
    handle = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE, length+1);
    if (!handle) {
	return;
    }
    buffer = GlobalLock(handle);
d204 10
d215 1
@


1.1
log
@Initial revision
@
text
@d11 1
a11 1
 * SCCS: @@(#) tkWinClipboard.c 1.8 97/05/20 17:01:13
@


1.1.4.1
log
@initial tk8.1a2 version
@
text
@d6 1
a6 1
 * Copyright (c) 1995-1997 Sun Microsystems, Inc.
d11 1
a11 1
 * SCCS: @@(#) tkWinClipboard.c 1.9 97/11/07 21:25:49
d30 1
a30 1
 *	then an error message is left in the interp's result.
@


1.1.4.2
log
@Merged 8.0.3 changes into 8.1
@
text
@d11 1
a11 1
 * RCS: @@(#) $Id: tkWinClipboard.c,v 1.2 1998/09/14 18:23:59 stanton Exp $
@


1.1.4.3
log
@* win/tkWinClipboard.c (TkSelGetSelection, TkWinClipboardRender):
Changed to handle multibyte characters properly. [Bug: 935]
@
text
@d11 1
a11 1
 * RCS: @@(#) $Id$
a52 1
    Tcl_DString ds;
d75 1
a75 1
		Tcl_ExternalToUtfDString(NULL, buffer, -1, &ds);
a76 2
		result = (*proc)(clientData, interp, Tcl_DStringValue(&ds));
		Tcl_DStringFree(&ds);
d165 1
a165 1
    char *buffer, *p, *rawText, *endPtr;
a166 1
    Tcl_DString ds;
d186 5
a190 1
    buffer = rawText = ckalloc(length + 1);
a203 10
    Tcl_UtfToExternalDString(NULL, rawText, -1, &ds);
    ckfree(rawText);
    handle = GlobalAlloc(GMEM_MOVEABLE|GMEM_DDESHARE,
	    Tcl_DStringLength(&ds)+1);
    if (!handle) {
	Tcl_DStringFree(&ds);
	return;
    }
    buffer = GlobalLock(handle);
    memcpy(buffer, Tcl_DStringValue(&ds), Tcl_DStringLength(&ds) + 1);
a204 1
    Tcl_DStringFree(&ds);
@


1.1.4.4
log
@
Tk 8.1 Muti-threading changes.

Moved static and global data elements into thread-local storage,
or introduced locks where not possible, as first stage of adding
thread safety to Tk.
@
text
@d11 1
a11 1
 * RCS: @@(#) $Id: tkWinClipboard.c,v 1.1.4.3 1998/12/08 23:28:52 stanton Exp $
d125 1
a125 1
    tkwin = (Tk_Window) TkGetMainInfoList()->winPtr;
@


