From 36f3e6e9af15906c7d459a8c80ee9f4e995b59f6 Mon Sep 17 00:00:00 2001 From: stanton Date: Sat, 22 May 1999 02:05:31 +0000 Subject: Fixed bug in Windows clipboard code when dealing with selections that don't contain locale information. --- ChangeLog | 5 ++++ win/tkWinClipboard.c | 67 +++++++++++++++++++++++++++------------------------- 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 257d937..612e9ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +1999-05-21 + + * win/tkWinClipboard.c: Fixed clipboard code to handle lack of + CF_LOCALE information (e.g. from command.com). + 1999-05-20 * library/console.tcl: Changed copyright string to read 1999 diff --git a/win/tkWinClipboard.c b/win/tkWinClipboard.c index cb7d1a8..18fb1f1 100644 --- a/win/tkWinClipboard.c +++ b/win/tkWinClipboard.c @@ -8,7 +8,7 @@ * 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.4 1999/05/22 01:59:22 stanton Exp $ + * RCS: @(#) $Id: tkWinClipboard.c,v 1.5 1999/05/22 02:05:31 stanton Exp $ */ #include "tkWinInt.h" @@ -79,44 +79,43 @@ TkSelGetSelection(interp, tkwin, selection, target, proc, clientData) Tcl_UniCharToUtfDString((Tcl_UniChar *)data, Tcl_UniCharLen((Tcl_UniChar *)data), &ds); GlobalUnlock(handle); - } else if (IsClipboardFormatAvailable(CF_TEXT) - && IsClipboardFormatAvailable(CF_LOCALE)) { + } else if (IsClipboardFormatAvailable(CF_TEXT)) { /* * Determine the encoding to use to convert this text. */ - handle = GetClipboardData(CF_LOCALE); - if (!handle) { - CloseClipboard(); - goto error; - } + 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. - */ + /* + * 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); - + 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. - */ + /* + * 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); + locale = LANGIDFROMLCID(*((int*)data)); + GetLocaleInfo(locale, LOCALE_IDEFAULTANSICODEPAGE, + Tcl_DStringValue(&ds)+2, Tcl_DStringLength(&ds)-2); + GlobalUnlock(handle); - if (!encoding) { - CloseClipboard(); - goto error; + encoding = Tcl_GetEncoding(NULL, Tcl_DStringValue(&ds)); + Tcl_DStringFree(&ds); + } else { + encoding = NULL; } /* @@ -125,14 +124,18 @@ TkSelGetSelection(interp, tkwin, selection, target, proc, clientData) handle = GetClipboardData(CF_TEXT); if (!handle) { - Tcl_FreeEncoding(encoding); + if (encoding) { + Tcl_FreeEncoding(encoding); + } CloseClipboard(); goto error; } data = GlobalLock(handle); Tcl_ExternalToUtfDString(encoding, data, -1, &ds); GlobalUnlock(handle); - Tcl_FreeEncoding(encoding); + if (encoding) { + Tcl_FreeEncoding(encoding); + } } else { CloseClipboard(); -- cgit v0.12