PB's SetClipboardText() works well with UTF8. However, if an EditorGadget contains RTF formated UTF8 text, how can that text be passed to the clipboard programmatically, retaining all formatting (Font, Size, Colour, Style)?
It works perfectly if the User performs the task manually (Select All,Ctrl-C,Ctrl-V).
I have read about RegisterClipboardFormat on MSDN, but to build a string replete with RTF formatting code is a huge task, since every individual UTF8 character has to be represented by an escape code (\uc1\unumber) and the range of character numbers is -32,768 to 32,768
There must be an easier way?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Might be worth it to build a one time Tool to do the UTF-8 conversion for you on the fly?
If you restrict yourself to English only, and then write a map for the characters (a=whatever, A=whatever etc) surely you won't need to cover the entire character range??
I'm really surprised there isn't any kind of universal database that programmers could use, to convert their strings between all these different formats.. Seems a rather trite thing to do on the part of the committees who come up with these standards, since they have to document the entire damn things in the first place.
It'd be real nice to have a DLL we could plugin to do this kind of thing..
I think you are on the wrong footing a little bit because it's difficult to explain - but I have had a full quota of coffee, so here is another attempt. It's not about converting a language (English) to another (the Rest of the World), or indeed a format (RTF) to a character set (UTF-8).
The English language doesn't need Unicode support on an English PC and the Chinese language (for example) does not need Unicode support on a Chinese PC.
What Unicode delivers, is the prospect of being able to write in any language on any PC. So, essentially your app may not need to 'know' what language your User is writing his/her text in. Mine doesn't.
RTF is a dark and murky place, and the official character range (-32,768 to 32,768) does not even cover all of the Unicode range, which is over 109,000 characters -yet somehow MS appears perfectly adept at supporting them for the clipboard. Also, not all fonts support all Unicode characters (surprise surprise), but your app should not need to know that either.......
So, it's about how to retain the text format (Font, Size, Colour, Style) that the User has already defined and can see in an EditorGadget (Edit Control supporting RTF), when passing said text to the clipboard. As I mentioned, if the User selects, copies and pastes manually, Windows handles that without any fuss, app to app (of course, both apps need to support RTF and many do).
The only difference in my case is that I need to copy to the clipboard programmatically.......
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Thank you once again for tackling the tricky stuff.
That code is essentially what I was experimenting with, using RegisterClipboardFormat_("Rich Text Format"), but concluded it is a no go
ANSI code page 1252 does not support all the characters that Unicode does, so you can't sandwich a text string in between formatting code unless that string's characters are all described by the code page. If they are not (= almost always true for Chinese etc), then you have to use an escape code for each individual character - that's difficult, but so is knowing what the character is in the first place, because the string in the Editor box is already input by the User - it's already formatted and using UTF-8.
However, you do have the right answer in there! Without imposing any RTF code, Send_Message~#EM_SETSEL and Send_Message~#WM_COPY is indeed what I needed Let Windows do the work - and works really well!
IdeasVacuum
If it sounds simple, you have not grasped the complexity.