Loading ...
Sorry, an error occurred while loading the content.

Re: clipboard for win9x

Expand Messages
  • Glenn Maynard
    Could you please CC: vim-multibyte@vim.org on subjects related to Unicode? (I only check vim-dev very rarely, since most of the code I m involved in is
    Message 1 of 20 , Mar 5, 2003
    • 0 Attachment
      Could you please CC: vim-multibyte@... on subjects related to
      Unicode? (I only check vim-dev very rarely, since most of the code I'm
      involved in is multibyte and that list is much lower volume.)

      On Sun, Feb 23, 2003 at 06:23:22PM +0900, MURAOKA Taro wrote:
      > SetClipboardData(CF_UNICODETEXT, hMemW);
      > hMemW = 0;
      > }
      > - else
      > # endif
      > {
      > SetClipboardData(CF_TEXT, hMem);
      > hMem = 0;
      > --- 1231,1238 ----
      > SetClipboardData(CF_UNICODETEXT, hMemW);
      > hMemW = 0;
      > }
      > # endif
      > + if (hMem)
      > {
      > SetClipboardData(CF_TEXT, hMem);
      > hMem = 0;

      This will set *both* Unicode and ANSI text on systems with CF_UNICODETEXT.
      This is bad, because we often set CF_TEXT incorrectly, by putting data in
      it that isn't in the ANSI codepage.

      For example, if encoding=utf-8, and we copy "ú", UTF-8 will be put
      in CF_TEXT, and we get garbage when we paste. This problem happens even
      on Unicode systems, since many apps don't use the Unicode clipboard directly.

      The attached patch fixes this. After converting the selection to WCHAR,
      we then convert it to the ANSI codepage. This has an added bonus: if
      the conversion was clean, Unicode isn't needed and we can save some
      memory (a lot of memory in some cases).

      It also removes the str_len/metadata.txtlen alias (so they don't
      accidentally get out of sync and cause bugs).

      One thing I'm concerned about is that I havn't yet reproduced the
      reported OE problem, and this may obscure it--it might hide it for the
      person having it, but it probably won't actually fix the problem. I
      havn't been able to reproduce that report; have you (Bram)?

      --
      Glenn Maynard
    • Bram Moolenaar
      ... You mean that when CF_TEXT is set it will be used and the text from CF_UNICODETEXT will not be used? That is indeed not good at all. ... The idea looks
      Message 2 of 20 , Mar 6, 2003
      • 0 Attachment
        Glenn Maynard wrote:

        > On Sun, Feb 23, 2003 at 06:23:22PM +0900, MURAOKA Taro wrote:
        > > SetClipboardData(CF_UNICODETEXT, hMemW);
        > > hMemW = 0;
        > > }
        > > - else
        > > # endif
        > > {
        > > SetClipboardData(CF_TEXT, hMem);
        > > hMem = 0;
        > > --- 1231,1238 ----
        > > SetClipboardData(CF_UNICODETEXT, hMemW);
        > > hMemW = 0;
        > > }
        > > # endif
        > > + if (hMem)
        > > {
        > > SetClipboardData(CF_TEXT, hMem);
        > > hMem = 0;
        >
        > This will set *both* Unicode and ANSI text on systems with CF_UNICODETEXT.
        > This is bad, because we often set CF_TEXT incorrectly, by putting data in
        > it that isn't in the ANSI codepage.
        >
        > For example, if encoding=utf-8, and we copy "ú", UTF-8 will be put
        > in CF_TEXT, and we get garbage when we paste. This problem happens
        > even on Unicode systems, since many apps don't use the Unicode
        > clipboard directly.

        You mean that when CF_TEXT is set it will be used and the text from
        CF_UNICODETEXT will not be used? That is indeed not good at all.

        > The attached patch fixes this. After converting the selection to WCHAR,
        > we then convert it to the ANSI codepage. This has an added bonus: if
        > the conversion was clean, Unicode isn't needed and we can save some
        > memory (a lot of memory in some cases).
        >
        > It also removes the str_len/metadata.txtlen alias (so they don't
        > accidentally get out of sync and cause bugs).

        The idea looks good to me, but this really needs to be tested to make
        sure it works. Especially on Windows 95.

        > One thing I'm concerned about is that I havn't yet reproduced the
        > reported OE problem, and this may obscure it--it might hide it for the
        > person having it, but it probably won't actually fix the problem. I
        > havn't been able to reproduce that report; have you (Bram)?

        OE problem? Wasn't that the problem that was identified as a problem
        with OE itself?

        --
        Hacker: Someone skilled in computer programming (good guy).
        Cracker: A hacker that uses his skills to crack software (bad guy).

        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
        /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\
        \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
        \\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///
      • Glenn Maynard
        ... Some apps request CF_TEXT, and some request CF_UNICODETEXT. If the exact type requested is there, Windows uses it directly. Otherwise, it synthesizes
        Message 3 of 20 , Mar 6, 2003
        • 0 Attachment
          On Thu, Mar 06, 2003 at 11:18:08AM +0100, Bram Moolenaar wrote:
          > You mean that when CF_TEXT is set it will be used and the text from
          > CF_UNICODETEXT will not be used? That is indeed not good at all.

          Some apps request CF_TEXT, and some request CF_UNICODETEXT. If the
          exact type requested is there, Windows uses it directly. Otherwise,
          it "synthesizes" it from another convertable type.

          Also, we want CF_TEXT to be correct anyway for the case where
          CF_UNICODETEXT isn't supported (9x, apparently, despite MS's
          "documentation").

          > The idea looks good to me, but this really needs to be tested to make
          > sure it works. Especially on Windows 95.

          Right; I can't do that, so I post it to the list and hope someone else
          does. :)

          > OE problem? Wasn't that the problem that was identified as a problem
          > with OE itself?

          Even if it's an OE problem, if it's something we're triggering that we
          can fix, we should, at least if it occurs on more than one person's
          system and the fix isn't overly heinous (and there's no workaround
          available, such as upgrading OE).

          However, if nobody else can reproduce it, there's not much I can do, so
          I won't worry about it.

          --
          Glenn Maynard
        • Tony Mechelynck
          Glenn Maynard wrote: [...] ... Apparently the person who had it fixed it by setting his preferences to send in plaintext rather than HTML.
          Message 4 of 20 , Mar 6, 2003
          • 0 Attachment
            Glenn Maynard <glenn@...> wrote:
            [...]
            > Even if it's an OE problem, if it's something we're triggering that we
            > can fix, we should, at least if it occurs on more than one person's
            > system and the fix isn't overly heinous (and there's no workaround
            > available, such as upgrading OE).
            >
            > However, if nobody else can reproduce it, there's not much I can do,
            > so I won't worry about it.
            >
            > --
            > Glenn Maynard

            Apparently the person who had it "fixed" it by setting his preferences to
            send in plaintext rather than HTML. Dunno if that qualifies as a
            "workaround" in your eyes.

            Tony.
          • Glenn Maynard
            ... Vim got somebody to stop sending HTML mail? Now *that s* a feature! :) -- Glenn Maynard
            Message 5 of 20 , Mar 6, 2003
            • 0 Attachment
              On Thu, Mar 06, 2003 at 03:40:07PM +0100, Tony Mechelynck wrote:
              > Apparently the person who had it "fixed" it by setting his preferences to
              > send in plaintext rather than HTML. Dunno if that qualifies as a
              > "workaround" in your eyes.

              Vim got somebody to stop sending HTML mail? Now *that's* a feature! :)

              --
              Glenn Maynard
            • Glenn Maynard
              ... Substituting Japanese for Hebrew and/or Greek here, all of this worked for me already, with only CF_UNICODETEXT being set. The only apparent problem was
              Message 6 of 20 , Mar 6, 2003
              • 0 Attachment
                On Thu, Mar 06, 2003 at 08:35:02AM -0800, Ron Aaron wrote:
                > Highlight the text in Word and paste into vim ... do you see the text correctly? (yes)
                > Highlight the text in Notepad and paste into vim ... do you see the text correctly? (depends...)
                > yank again from vim to the clipboard and paste back into vim -- is the text correct? (it better be)

                Substituting Japanese for Hebrew and/or Greek here, all of this worked
                for me already, with only CF_UNICODETEXT being set. The only apparent
                problem was that (contrary to MS's docs) CF_U isn't actually supported
                in 9x (and apparently ME), so copying didn't work correctly there.

                > The correct thing to do is to make sure the CF_UNICODE is correct always, and the CF_TEXT is ANSI so Windows doesn't muck with it. When we have multiple languages in the text and try to ANSIfy it, we will have a problem ... but there is nothing to do about it.

                This is what my patch already does, except that it doesn't set
                CF_UNICODETEXT if CF_TEXT is lossless (which it would not be in
                the above cases). Have you tried it?

                I've found one bug related to transliteration (copy "ı" out of Vim and
                you'll always get "i"); I've fixed this, but I'm not going to send this
                out just yet, since I havn't been awake long enough. Once I have that
                tested more and posted, I'll put together a small test set for people to try.

                Also, the same conversion (ACP to wide char to p_enc) *may* need to be
                done when pasting into Vim, too. I'll include a test for this in the
                test set (so we don't waste time on it if it's not needed).

                > I suggest making the smallest possible change, and testing it on Me and XP (or equivalent systems) before sending out a patch.

                Feel free to donate such systems. :) A better (practical) approach is
                for me to write the code, test it as best I can, and then post it to the
                appropriate mailing list(s) so people on other systems can test it, which
                is what I do. (I only have 2k machines.)

                Have you tested the patch? You seem to be criticising something, but I don't
                know what; it's intended to do almost exactly what you're saying it should do.

                --
                Glenn Maynard
              • Glenn Maynard
                On Thu, Mar 06, 2003 at 02:19:00PM -0500, Glenn Maynard wrote: I ve found one bug related to transliteration (copy ı out of Vim and you ll always get
                Message 7 of 20 , Mar 6, 2003
                • 0 Attachment
                  On Thu, Mar 06, 2003 at 02:19:00PM -0500, Glenn Maynard wrote:
                  > I've found one bug related to transliteration (copy "ı" out of Vim and
                  > you'll always get "i"); I've fixed this, but I'm not going to send this
                  > out just yet, since I havn't been awake long enough. Once I have that
                  > tested more and posted, I'll put together a small test set for people to try.

                  Okay. I've just removed the code to elide the Unicode clipboard, since
                  I rather just want to get the current stuff working well. (It may be a
                  mostly futile gesture to memory conservation, anyway--we make several
                  copies of the clipboard data when copying anyway, so we'll hit swap
                  there if we'll hit it at all.)

                  Here's how people can test this patch:

                  Load Vim, Notepad and Word with a font that can display the characters in
                  this mail; Courier New works. Make sure Vim is using UTF-8 internally;
                  use ":set enc=utf-8".

                  Copy in these lines:
                  ASCII test
                  Latín tëst
                  בגדה

                  Copy them--one line at a time--from Vim into Notepad and Word.

                  The first is a sanity check. The second tests non-ASCII ANSI copying,
                  and assumes you're on a US system; substitute characters in your local
                  language if needed. The third tests Unicode and will probably not work
                  when pasting to Notepad in 9x or ME (but may work when pasting to Word).
                  (Note that the second test requires iconv until the enc_codepage patch
                  is in, and the third one inherently requires iconv.)

                  Try it in reverse; copy them (again one at a line) from Notepad and Word
                  back to Vim.

                  And, just to be paranoid, copy from one Vim to another.


                  --
                  Glenn Maynard
                • Bram Moolenaar
                  ... I m wondering if we can really omit CF_UNICODETEXT. It s unclear what encoding CF_TEXT should use. The active code page? Any 8-bit encoding that the
                  Message 8 of 20 , Mar 6, 2003
                  • 0 Attachment
                    Glenn Maynard wrote:

                    > > The correct thing to do is to make sure the CF_UNICODE is correct
                    > > always, and the CF_TEXT is ANSI so Windows doesn't muck with it.
                    > > When we have multiple languages in the text and try to ANSIfy it, we
                    > > will have a problem ... but there is nothing to do about it.
                    >
                    > This is what my patch already does, except that it doesn't set
                    > CF_UNICODETEXT if CF_TEXT is lossless (which it would not be in
                    > the above cases). Have you tried it?

                    I'm wondering if we can really omit CF_UNICODETEXT. It's unclear what
                    encoding CF_TEXT should use. The active code page? Any 8-bit encoding
                    that the file happens to contain? And even when MS specifies something,
                    do applications really implement it correctly?

                    Using CF_UNICODETEXT has the advantage that there can be no confusion
                    about the encoding, thus every application that uses it (like Vim) will
                    copy/paste correctly.

                    --
                    BEDEVERE: And that, my lord, is how we know the Earth to be banana-shaped.
                    "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

                    /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                    /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\
                    \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
                    \\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///
                  • Glenn Maynard
                    ... I m sure that CF_TEXT contains text in the ANSI codepage. Also, data sent to the normal *A Windows API functions is in the ANSI codepage, and most apps
                    Message 9 of 20 , Mar 6, 2003
                    • 0 Attachment
                      On Thu, Mar 06, 2003 at 10:41:24PM +0100, Bram Moolenaar wrote:
                      > I'm wondering if we can really omit CF_UNICODETEXT. It's unclear what
                      > encoding CF_TEXT should use. The active code page? Any 8-bit encoding
                      > that the file happens to contain? And even when MS specifies something,
                      > do applications really implement it correctly?

                      I'm sure that CF_TEXT contains text in the ANSI codepage. Also, data sent
                      to the normal *A Windows API functions is in the ANSI codepage, and most
                      apps simply take data from CF_TEXT and throw it at Windows API calls
                      unchanged--CF_TEXT being ANSI "just works" almost all of the time (and it
                      being anything else almost never works). I could find cases where it
                      doesn't work (by using old non-Unicode fonts), but in those cases,
                      CF_UNICODETEXT doesn't help.

                      However, I removed the code to omit CF_UNICODETEXT for simplicity, so
                      it's a moot issue.

                      --
                      Glenn Maynard
                    • Glenn Maynard
                      ... Here s one problem I ve found--not due to the patch, but related: if we ever get text from CF_TEXT, it ll be in the ANSI codepage, and we need to convert
                      Message 10 of 20 , Mar 12, 2003
                      • 0 Attachment
                        On Thu, Mar 06, 2003 at 04:16:53PM -0500, Glenn Maynard wrote:
                        > Try it in reverse; copy them (again one at a line) from Notepad and Word
                        > back to Vim.

                        Here's one problem I've found--not due to the patch, but related: if we
                        ever get text from CF_TEXT, it'll be in the ANSI codepage, and we need
                        to convert it to p_enc. On NT, we never use CF_TEXT, since it'll
                        synthesize CF_UNICODETEXT for us.

                        So, do we ever get CF_TEXT in 95? The recent Notepad problems seem to
                        indicate that we do. Can someone confirm this by copying "Latín tëxt"
                        into Vim on a 95 box with "encoding" set to UTF-8? I expect that
                        you'll see "Lat<ed>n t<eb>xt". (You don't need this patch to test this,
                        just CVS, though I'm still looking for someone to test it in 95.)

                        --
                        Glenn Maynard
                      • Tony Mechelynck
                        ... On W98SE 4.10.2222 with gvim 6.1.362 +ole as distributed in binary by Cream (see link at http://cream.sourceforge.net/vim.html ): writing Latín tèxt
                        Message 11 of 20 , Mar 12, 2003
                        • 0 Attachment
                          Glenn Maynard <glenn@...> wrote:
                          > On Thu, Mar 06, 2003 at 04:16:53PM -0500, Glenn Maynard wrote:
                          > > Try it in reverse; copy them (again one at a line) from Notepad and
                          > > Word back to Vim.
                          >
                          > Here's one problem I've found--not due to the patch, but related: if
                          > we ever get text from CF_TEXT, it'll be in the ANSI codepage, and we
                          > need
                          > to convert it to p_enc. On NT, we never use CF_TEXT, since it'll
                          > synthesize CF_UNICODETEXT for us.
                          >
                          > So, do we ever get CF_TEXT in 95? The recent Notepad problems seem to
                          > indicate that we do. Can someone confirm this by copying "Latín tëxt"
                          > into Vim on a 95 box with "encoding" set to UTF-8? I expect that
                          > you'll see "Lat<ed>n t<eb>xt". (You don't need this patch to test
                          > this, just CVS, though I'm still looking for someone to test it in
                          > 95.)
                          >
                          > --
                          > Glenn Maynard

                          On W98SE 4.10.2222 with gvim 6.1.362 +ole as distributed in binary by Cream
                          (see link at http://cream.sourceforge.net/vim.html ): writing "Latín tèxt"
                          in Notepad and pasting it in gvim [No File] buffer with 'enc'=utf-8 gives
                          indeed Lat<ed>n t<e8>xt, with the <> sequences in blue and the rest in
                          black. I don't know if your patch is included in my binary, but it shows
                          that non-unicode text is passed. This experiment may or may not be relevant
                          to your needs. Pasting done by clicking Edit -> Paste in the standard gvim
                          menu.

                          Tony.
                        • uribarri_u@tsm.es
                          I have detected two problems with UTF-8: 1. When I write a two byte character (í or ñ), I have press the spacebar twice to get it (the spaces aren t inserted
                          Message 12 of 20 , Mar 13, 2003
                          • 0 Attachment
                            I have detected two problems with UTF-8:
                            1. When I write a two byte character (í or ñ), I have press the spacebar
                            twice to get it (the spaces aren't inserted in the buffer).
                            2. If I copy "Cañá" on VIM and paste it in the notepad I get "Cañá"




                            13/03/2003 00:25
                            Glenn Maynard <glenn@...>


                            Destinatarios: vim-multibyte@..., vim-dev@...
                            CC:
                            Asunto: Re: clipboard for win9x


                            On Thu, Mar 06, 2003 at 04:16:53PM -0500, Glenn Maynard wrote:
                            > Try it in reverse; copy them (again one at a line) from Notepad and Word
                            > back to Vim.

                            Here's one problem I've found--not due to the patch, but related: if we
                            ever get text from CF_TEXT, it'll be in the ANSI codepage, and we need
                            to convert it to p_enc. On NT, we never use CF_TEXT, since it'll
                            synthesize CF_UNICODETEXT for us.

                            So, do we ever get CF_TEXT in 95? The recent Notepad problems seem to
                            indicate that we do. Can someone confirm this by copying "Latín tëxt"
                            into Vim on a 95 box with "encoding" set to UTF-8? I expect that
                            you'll see "Lat<ed>n t<eb>xt". (You don't need this patch to test this,
                            just CVS, though I'm still looking for someone to test it in 95.)

                            --
                            Glenn Maynard
                          • Glenn Maynard
                            ... This doesn t seem to be related to the clipboard, so I ll leave this to Bram ... ... Is this with or without the patch I attached to this thread? -- Glenn
                            Message 13 of 20 , Mar 13, 2003
                            • 0 Attachment
                              On Thu, Mar 13, 2003 at 10:12:57AM +0100, uribarri_u@... wrote:
                              > I have detected two problems with UTF-8:
                              > 1. When I write a two byte character (í or ñ), I have press the spacebar
                              > twice to get it (the spaces aren't inserted in the buffer).

                              This doesn't seem to be related to the clipboard, so I'll leave this to
                              Bram ...

                              > 2. If I copy "Cañá" on VIM and paste it in the notepad I get "Cañá"

                              Is this with or without the patch I attached to this thread?

                              --
                              Glenn Maynard
                            • Bram Moolenaar
                              ... Didn t we have this discussion before? The CF_TEXT text can theoretically be any encoding. But it s probably the currently active codepage. Thus
                              Message 14 of 20 , Mar 13, 2003
                              • 0 Attachment
                                Glenn Maynard wrote:

                                > On Thu, Mar 06, 2003 at 04:16:53PM -0500, Glenn Maynard wrote:
                                > > Try it in reverse; copy them (again one at a line) from Notepad and Word
                                > > back to Vim.
                                >
                                > Here's one problem I've found--not due to the patch, but related: if we
                                > ever get text from CF_TEXT, it'll be in the ANSI codepage, and we need
                                > to convert it to p_enc. On NT, we never use CF_TEXT, since it'll
                                > synthesize CF_UNICODETEXT for us.
                                >
                                > So, do we ever get CF_TEXT in 95? The recent Notepad problems seem to
                                > indicate that we do. Can someone confirm this by copying "Latín tëxt"
                                > into Vim on a 95 box with "encoding" set to UTF-8? I expect that
                                > you'll see "Lat<ed>n t<eb>xt". (You don't need this patch to test this,
                                > just CVS, though I'm still looking for someone to test it in 95.)

                                Didn't we have this discussion before? The CF_TEXT text can
                                theoretically be any encoding. But it's probably the currently active
                                codepage. Thus converting from that codepage to 'encoding' would work
                                in most situations.

                                Previously we didn't do the conversion, because it could break
                                copy/paste from one Vim to another when 'enc' is utf-8 and the codepage
                                is an 8-bit one. But we now use CF_UNICODETEXT between two Vims.

                                --
                                hundred-and-one symptoms of being an internet addict:
                                39. You move into a new house and decide to Netscape before you landscape.

                                /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                                /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\
                                \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
                                \\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///
                              • Glenn Maynard
                                ... Since somebody confirmed this problem, I have code written to handle the other end of the conversion (converting CF_TEXT properly when pasting). I ll post
                                Message 15 of 20 , Mar 13, 2003
                                • 0 Attachment
                                  On Thu, Mar 13, 2003 at 10:34:11AM +0100, Bram Moolenaar wrote:
                                  > > So, do we ever get CF_TEXT in 95? The recent Notepad problems seem to
                                  > > indicate that we do. Can someone confirm this by copying "Latín tëxt"
                                  > > into Vim on a 95 box with "encoding" set to UTF-8? I expect that
                                  > > you'll see "Lat<ed>n t<eb>xt". (You don't need this patch to test this,
                                  > > just CVS, though I'm still looking for someone to test it in 95.)

                                  Since somebody confirmed this problem, I have code written to handle the
                                  other end of the conversion (converting CF_TEXT properly when pasting).
                                  I'll post it (combined with the last patch, converting copying) once I
                                  test it some more.

                                  Unless you'd rather apply the current (more important) fix first. After
                                  all, this problem has existed for a long time, so we don't necessarily
                                  have to fix them together. Do you want to wait to finish the copying
                                  fix and let that sit in CVS for a while before bothering with pasting?

                                  > Didn't we have this discussion before? The CF_TEXT text can
                                  > theoretically be any encoding. But it's probably the currently active
                                  > codepage. Thus converting from that codepage to 'encoding' would work
                                  > in most situations.

                                  I don't recall. We might have settled on "maybe what we're doing is
                                  valid and maybe not, but UTF-8 pasting between Vims is more important
                                  anyway".

                                  Anyway, as you said, since the stumbling block of cross-Vim pasting is gone
                                  this doesn't matter now. We can deal with CF_TEXT in ANSI now without
                                  lossage.

                                  --
                                  Glenn Maynard
                                • Bram Moolenaar
                                  ... I would prefer fixing this with one patch. We have quite a few of them already anyway! -- hundred-and-one symptoms of being an internet addict: 40. You
                                  Message 16 of 20 , Mar 13, 2003
                                  • 0 Attachment
                                    Glenn Maynard wrote:

                                    > On Thu, Mar 13, 2003 at 10:34:11AM +0100, Bram Moolenaar wrote:
                                    > > > So, do we ever get CF_TEXT in 95? The recent Notepad problems seem to
                                    > > > indicate that we do. Can someone confirm this by copying "Latín tëxt"
                                    > > > into Vim on a 95 box with "encoding" set to UTF-8? I expect that
                                    > > > you'll see "Lat<ed>n t<eb>xt". (You don't need this patch to test this,
                                    > > > just CVS, though I'm still looking for someone to test it in 95.)
                                    >
                                    > Since somebody confirmed this problem, I have code written to handle the
                                    > other end of the conversion (converting CF_TEXT properly when pasting).
                                    > I'll post it (combined with the last patch, converting copying) once I
                                    > test it some more.
                                    >
                                    > Unless you'd rather apply the current (more important) fix first. After
                                    > all, this problem has existed for a long time, so we don't necessarily
                                    > have to fix them together. Do you want to wait to finish the copying
                                    > fix and let that sit in CVS for a while before bothering with pasting?

                                    I would prefer fixing this with one patch. We have quite a few of them
                                    already anyway!

                                    --
                                    hundred-and-one symptoms of being an internet addict:
                                    40. You tell the cab driver you live at
                                    http://123.elm.street/house/bluetrim.html
                                    41. You actually try that 123.elm.street address.

                                    /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                                    /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\
                                    \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
                                    \\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///
                                  • Valery Kondakoff
                                    Hello, Glenn! ... Yes. Garbage characters that I was describing in my latest mail are looking exactly like these. GM Is this with or without the patch I
                                    Message 17 of 20 , Mar 13, 2003
                                    • 0 Attachment
                                      Hello, Glenn!

                                      13 ìàðòà 2003 ã., you wrote to me:

                                      >> 2. If I copy "Cañá" on VIM and paste it in the notepad I get "Cañá"

                                      Yes. 'Garbage characters' that I was describing in my latest mail are
                                      looking exactly like these.

                                      GM> Is this with or without the patch I attached to this thread?

                                      Glenn, excuse me for asking: if there is a place, where I can download
                                      GVIM build with your patch applied? (I'm not sure that I can compile
                                      CVIM by myself, but I'll try if there are no other ways to 'catch' the
                                      problem...). :)


                                      --
                                      Best regards,
                                      Valery Kondakoff
                                      http://www.nbk.orc.ru (Ne Bey Kopytom)
                                      http://www.nbk.orc.ru/mtb (MTB riding in Moscow)

                                      PGP key: mailto:pgp-public-keys@...?subject=GET%20strauss@...
                                    • Bram Moolenaar
                                      ... Yes, this problem exists. After including your previous patch I can now properly copy text in gvim (using encoding set to utf-8 ) and paste in Notepad.
                                      Message 18 of 20 , Mar 16, 2003
                                      • 0 Attachment
                                        Glenn Maynard wrote:

                                        > On Thu, Mar 06, 2003 at 04:16:53PM -0500, Glenn Maynard wrote:
                                        > > Try it in reverse; copy them (again one at a line) from Notepad and Word
                                        > > back to Vim.
                                        >
                                        > Here's one problem I've found--not due to the patch, but related: if we
                                        > ever get text from CF_TEXT, it'll be in the ANSI codepage, and we need
                                        > to convert it to p_enc. On NT, we never use CF_TEXT, since it'll
                                        > synthesize CF_UNICODETEXT for us.
                                        >
                                        > So, do we ever get CF_TEXT in 95? The recent Notepad problems seem to
                                        > indicate that we do. Can someone confirm this by copying "Latín tëxt"
                                        > into Vim on a 95 box with "encoding" set to UTF-8? I expect that
                                        > you'll see "Lat<ed>n t<eb>xt". (You don't need this patch to test this,
                                        > just CVS, though I'm still looking for someone to test it in 95.)

                                        Yes, this problem exists. After including your previous patch I can now
                                        properly copy text in gvim (using 'encoding' set to "utf-8") and paste in
                                        Notepad. Thus setting the CF_TEXT entry to text converted from
                                        'encoding' to the active codepage appears to work.

                                        The other way around doesn't work. Obviously Notepad only sets CF_TEXT
                                        and it is in the active codepage. When pasting CF_TEXT in Vim this must
                                        be converted to 'encoding'.

                                        Should not be difficult.... Below is a patch that combines the two
                                        directions. I also fixed a memory leak when using CF_UNICODETEXT.
                                        Please give this a try.

                                        -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
                                        *** ../vim61.406/src/os_mswin.c Sat Mar 15 16:54:47 2003
                                        --- src/os_mswin.c Sun Mar 16 16:47:15 2003
                                        ***************
                                        *** 971,977 ****

                                        utf8_str = alloc((unsigned)length);
                                        if (utf8_str != NULL)
                                        ! WideCharToMultiByte(enc_dbcs, 0, str, *len, utf8_str, length, 0,0);
                                        *len = length;
                                        return utf8_str;
                                        }
                                        --- 971,977 ----

                                        utf8_str = alloc((unsigned)length);
                                        if (utf8_str != NULL)
                                        ! WideCharToMultiByte(enc_dbcs, 0, str, *len, utf8_str, length, 0, 0);
                                        *len = length;
                                        return utf8_str;
                                        }
                                        ***************
                                        *** 1022,1027 ****
                                        --- 1022,1028 ----
                                        VimClipType_t metadata = { -1, -1, -1 };
                                        HGLOBAL hMem = NULL;
                                        char_u *str = NULL;
                                        + char_u *to_free = NULL;
                                        char_u *hMemStr = NULL;
                                        int str_size = 0;
                                        int maxlen;
                                        ***************
                                        *** 1076,1082 ****
                                        if (hMemWstr[str_size] == NUL)
                                        break;
                                        }
                                        ! str = ucs2_to_enc(hMemWstr, &str_size);
                                        GlobalUnlock(hMemW);
                                        }
                                        }
                                        --- 1077,1083 ----
                                        if (hMemWstr[str_size] == NUL)
                                        break;
                                        }
                                        ! to_free = str = ucs2_to_enc(hMemWstr, &str_size);
                                        GlobalUnlock(hMemW);
                                        }
                                        }
                                        ***************
                                        *** 1105,1110 ****
                                        --- 1106,1128 ----
                                        if (str[str_size] == NUL)
                                        break;
                                        }
                                        +
                                        + /* The text is now in the active codepage. Convert to 'encoding',
                                        + * going through UCS-2. */
                                        + maxlen = MultiByteToWideChar(CP_ACP, 0, str, str_size, NULL, 0);
                                        + to_free = alloc((unsigned)(maxlen * sizeof(WCHAR)));
                                        + if (to_free != NULL)
                                        + {
                                        + MultiByteToWideChar(CP_ACP, 0, str, str_size,
                                        + (WCHAR *)to_free, maxlen);
                                        + str_size = maxlen;
                                        + str = ucs2_to_enc((WCHAR *)to_free, &str_size);
                                        + if (str != NULL)
                                        + {
                                        + vim_free(to_free);
                                        + to_free = str;
                                        + }
                                        + }
                                        }
                                        }

                                        ***************
                                        *** 1129,1134 ****
                                        --- 1147,1153 ----
                                        if (hMemStr != NULL)
                                        GlobalUnlock(hMem);
                                        CloseClipboard();
                                        + vim_free(to_free);
                                        }

                                        /*
                                        ***************
                                        *** 1138,1144 ****
                                        clip_mch_set_selection(VimClipboard *cbd)
                                        {
                                        char_u *str = NULL;
                                        - long_u str_len;
                                        VimClipType_t metadata;
                                        HGLOBAL hMem = NULL;
                                        HGLOBAL hMemVim = NULL;
                                        --- 1157,1162 ----
                                        ***************
                                        *** 1152,1167 ****
                                        cbd->owned = FALSE;

                                        /* Get the text to be put on the clipboard, with CR-LF. */
                                        ! metadata.type = clip_convert_selection(&str, &str_len, cbd);
                                        if (metadata.type < 0)
                                        return;
                                        - metadata.txtlen = str_len;
                                        metadata.ucslen = 0;

                                        # if defined(FEAT_MBYTE) && defined(WIN3264)
                                        {
                                        WCHAR *out;
                                        ! int len = str_len;

                                        /* Convert the text to UCS-2. This is put on the clipboard as
                                        * CF_UNICODETEXT. */
                                        --- 1170,1184 ----
                                        cbd->owned = FALSE;

                                        /* Get the text to be put on the clipboard, with CR-LF. */
                                        ! metadata.type = clip_convert_selection(&str, &metadata.txtlen, cbd);
                                        if (metadata.type < 0)
                                        return;
                                        metadata.ucslen = 0;

                                        # if defined(FEAT_MBYTE) && defined(WIN3264)
                                        {
                                        WCHAR *out;
                                        ! int len = metadata.txtlen;

                                        /* Convert the text to UCS-2. This is put on the clipboard as
                                        * CF_UNICODETEXT. */
                                        ***************
                                        *** 1170,1175 ****
                                        --- 1187,1206 ----
                                        {
                                        WCHAR *lpszMemW;

                                        + /* Convert the text for CF_TEXT to ANSI codepage. Otherwise it's
                                        + * p_enc, which has no relation to the ANSI codepage. */
                                        + metadata.txtlen = WideCharToMultiByte(CP_ACP, 0, out, len,
                                        + NULL, 0, 0, 0);
                                        + vim_free(str);
                                        + str = (char_u *)alloc((unsigned)metadata.txtlen);
                                        + if (str == NULL)
                                        + {
                                        + vim_free(out);
                                        + return; /* out of memory */
                                        + }
                                        + WideCharToMultiByte(CP_ACP, 0, out, len,
                                        + str, metadata.txtlen, 0, 0);
                                        +
                                        /* Allocate memory for the UCS-2 text, add one NUL word to
                                        * terminate the string. */
                                        hMemW = (LPSTR)GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE,
                                        ***************
                                        *** 1189,1202 ****

                                        /* Allocate memory for the text, add one NUL byte to terminate the string.
                                        */
                                        ! hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, str_len + 1);
                                        {
                                        LPSTR lpszMem = (LPSTR)GlobalLock(hMem);

                                        if (lpszMem)
                                        {
                                        ! STRNCPY(lpszMem, str, str_len);
                                        ! lpszMem[str_len] = NUL;
                                        GlobalUnlock(hMem);
                                        }
                                        }
                                        --- 1220,1233 ----

                                        /* Allocate memory for the text, add one NUL byte to terminate the string.
                                        */
                                        ! hMem = GlobalAlloc(GMEM_MOVEABLE | GMEM_DDESHARE, metadata.txtlen + 1);
                                        {
                                        LPSTR lpszMem = (LPSTR)GlobalLock(hMem);

                                        if (lpszMem)
                                        {
                                        ! STRNCPY(lpszMem, str, metadata.txtlen);
                                        ! lpszMem[metadata.txtlen] = NUL;
                                        GlobalUnlock(hMem);
                                        }
                                        }
                                        ***************
                                        *** 1230,1237 ****
                                        # if defined(FEAT_MBYTE) && defined(WIN3264)
                                        if (hMemW != NULL)
                                        {
                                        ! SetClipboardData(CF_UNICODETEXT, hMemW);
                                        ! hMemW = 0;
                                        }
                                        # endif
                                        /* Always use CF_TEXT. On Win98 Notepad won't obtain the
                                        --- 1261,1268 ----
                                        # if defined(FEAT_MBYTE) && defined(WIN3264)
                                        if (hMemW != NULL)
                                        {
                                        ! if (SetClipboardData(CF_UNICODETEXT, hMemW) != NULL)
                                        ! hMemW = NULL;
                                        }
                                        # endif
                                        /* Always use CF_TEXT. On Win98 Notepad won't obtain the


                                        --
                                        From "know your smileys":
                                        (X0||) Double hamburger with lettuce and tomato

                                        /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                                        /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\
                                        \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
                                        \\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///
                                      • Valery Kondakoff
                                        Hello, Bram! Sunday, March 16, 2003, you wrote to me: BM Should not be difficult.... Below is a patch that combines the two BM directions. I also fixed a
                                        Message 19 of 20 , Mar 25, 2003
                                        • 0 Attachment
                                          Hello, Bram!

                                          Sunday, March 16, 2003, you wrote to me:

                                          BM> Should not be difficult.... Below is a patch that combines the two
                                          BM> directions. I also fixed a memory leak when using CF_UNICODETEXT.
                                          BM> Please give this a try.

                                          BM> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
                                          BM> *** ../vim61.406/src/os_mswin.c Sat Mar 15 16:54:47 2003
                                          BM> --- src/os_mswin.c Sun Mar 16 16:47:15 2003

                                          Please, can you give me rather more details how to apply this patch?
                                          I'm a real newbie in "patching". With a little help of VIM-community I
                                          was able to apply 'official' patches. But I still can't understand
                                          what 'os_mswin.c' revision do I need to have to successfully apply
                                          your patch.

                                          When applying your patch on clean 'os_mswin.c' or 'os_mswin.c' with
                                          all official patches applyed, I receive an error:

                                          Patching file src/os_mswin.c using Plan A...
                                          Hunk #1 FAILED at 971.
                                          Hunk #2 FAILED at 1022.
                                          Hunk #3 FAILED at 1077.
                                          Hunk #4 FAILED at 1106.
                                          Hunk #5 succeeded at 1147 with fuzz 2.
                                          Hunk #6 FAILED at 1157.
                                          Hunk #7 FAILED at 1170.
                                          Hunk #8 FAILED at 1187.
                                          Hunk #9 FAILED at 1220.
                                          Hunk #10 FAILED at 1261.
                                          9 out of 10 hunks FAILED -- saving rejects to file src/os_mswin.c.rej

                                          Do I need to find a special 'os_mswin.c' version in CVS?

                                          Thank you in advance! (I think I need to try this patch and
                                          'strftime_encoding' one, because I'm working in multilangiage
                                          environment).

                                          --
                                          Best regards,
                                          Valery Kondakoff
                                          http://www.nbk.orc.ru (Ne Bey Kopytom)
                                          http://www.nbk.orc.ru/mtb (MTB riding in Moscow)

                                          PGP key: mailto:pgp-public-keys@...?subject=GET%20strauss@...

                                          np: Simon Raymonde - The Seventh Day (Blame Someone Else) [stopped]
                                        • Bram Moolenaar
                                          ... First make sure the patch file and the source file use the same line endings. Both dos and unix fileformats work, but they must match. I m not sure if
                                          Message 20 of 20 , Mar 26, 2003
                                          • 0 Attachment
                                            Valery Kondakoff wrote:

                                            > Please, can you give me rather more details how to apply this patch?
                                            > I'm a real newbie in "patching". With a little help of VIM-community I
                                            > was able to apply 'official' patches. But I still can't understand
                                            > what 'os_mswin.c' revision do I need to have to successfully apply
                                            > your patch.
                                            >
                                            > When applying your patch on clean 'os_mswin.c' or 'os_mswin.c' with
                                            > all official patches applyed, I receive an error:
                                            >
                                            > Patching file src/os_mswin.c using Plan A...
                                            > Hunk #1 FAILED at 971.
                                            > Hunk #2 FAILED at 1022.
                                            > Hunk #3 FAILED at 1077.
                                            > Hunk #4 FAILED at 1106.
                                            > Hunk #5 succeeded at 1147 with fuzz 2.
                                            > Hunk #6 FAILED at 1157.
                                            > Hunk #7 FAILED at 1170.
                                            > Hunk #8 FAILED at 1187.
                                            > Hunk #9 FAILED at 1220.
                                            > Hunk #10 FAILED at 1261.
                                            > 9 out of 10 hunks FAILED -- saving rejects to file src/os_mswin.c.rej
                                            >
                                            > Do I need to find a special 'os_mswin.c' version in CVS?

                                            First make sure the patch file and the source file use the same line
                                            endings. Both dos and unix fileformats work, but they must match.

                                            I'm not sure if this patch depends on previous patches. Simplest is to
                                            obtain the latest version through CVS. See the CVS page on
                                            www.vim.org for that.

                                            --
                                            hundred-and-one symptoms of being an internet addict:
                                            214. Your MCI "Circle of Friends" are all Hayes-compatible.

                                            /// Bram Moolenaar -- Bram@... -- http://www.Moolenaar.net \\\
                                            /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\
                                            \\\ Project leader for A-A-P -- http://www.A-A-P.org ///
                                            \\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///
                                          Your message has been successfully submitted and would be delivered to recipients shortly.