On approximately 11/5/2008 12:05 PM, came the following characters from 
the keyboard of Raphael Stoeckli:
>  Hi @ all
> 
> I’m working on an program, that can handle Unicode-text in richedit-fields.
> The fields sets and gets the text using some modifications of the 
> richedit-field. These mods are also from this mailinglist.
> 
> The problem is, that Newlines (\r\n) in strings (whether if it’s ASCII or 
> Unicode) seems to be wiped, when I put the string into the modified 
> richedit-field.
> 
> I wrote a demo/test-program to show this behavior. You can get it here: 
> http://www.rabanti.ch/storage/rtf_utf_test.pl or 
> http://www.rabanti.ch/storage/rtf_utf_test.zip (if there is a problem with 
> the encoding, while downloading)
> Anyhow I try to describe it abbreviated in this post. 
> 
> For saving Unicode-content into a string, I use these functions:
> -------------------------------------
> sub WM_USER() {1024};
> sub EM_GETTEXTEX() {+WM_USER+94};
> sub GT_DEFAULT() {0};
> 
> sub get_unicode # takes the text out of the richedit-field
> {
>    my $maxlen = 1024;
>    my $buffer = " " x $maxlen;
>    my $flags = GT_DEFAULT;
>    my $codepage = 1200;
>    my $struct = pack("LLIpp", $maxlen, $flags, $codepage, undef, undef);
>    my $address = pack("P20", $struct);
>    my $wparam = unpack("L", $address);
>    my $numTchar = $WIN -> re -> SendMessage(EM_GETTEXTEX, $wparam, $buffer); 
> # re is the richedit-field, $WIN the window-object
>    my $octets = substr($buffer, 0, ($numTchar*2));
>    my $text = decode("UCS-2LE", $octets);
>    return($text);
> }
> -------------------------------------
> 
> This is the richedit-field (simplified):
> 
> $RE = $WIN -> AddRichEdit(
>     -name => 're',
>     -size => [240, 80],
>     -pushstyle        => WS_CHILD | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | 
> ES_LEFT | ES_MULTILINE,
> );
> 
> -------------------------------------
> 
> I get the text out of the field like that:
> $SAVE = &get_unicode;
> 
> When I try to write the string back into the field, I use this function and 
> definition:
> -------------------------------------
> our $RTF_PROLOG = '{\rtf1';
> 
> sub string2rtf # string-converter for RTF-handling
> {
> my @input = @_;
>     $input[0] =~ s/([^\x00-\x7F])/'\uc1\u'.((ord $1 < 32768)?ord $1 : 
> ord($1)-65536).'?'/eg;
>     return $input[0];
> }
> -------------------------------------
> 
> I try to set the text like that:
> $WIN -> re -> Text($RTF_PROLOG . string2rtf($SAVE) . '}');
> 
> The result is that all stored lines (in the string) appear on one single 
> line, without newlines.
> The operation >> $input[0] =~ s/([^\x00-\x7F])/'\uc1\u'.((ord $1 < 32768)?ord 
> $1 : ord($1)-65536).'?'/eg; << seems to wipe the newlines. I checked the 
> converted strings. The newlines (\r\n) are still there, nonetheless the 
> richedit-field do not recognize them. If I use $WIN -> re -> Text($SAVE), the 
> Newlines are appearing, but the unicode is broken.
> 
> I think it's something about a sent (respectively not sent) system-signal. 
> But I have at this time no plan about these things.
> I tested it on a Win2K (SP4)- System and a XP (SP3)-System with win32::GUI 
> v1.06 and Activestate Perl v5.8.6.811 
> 
> Can someone explain me this behavior, and get me a hint, how to correct this?
> 
> Many thanks in advance!... and much sorry for the bad English.
> 
> Regards,
> Raphael 


Using Unicode in Perl Win32-GUI is somewhat limited at present.  The 
rich edit control seems to be one of the few things that can handle it.

I have a rich edit control in one of my Win32-GUI programs.  It has a 
limited purpose, but does achieve its goal of inputting Unicode data to 
the program.  I do the following in converting to rtf which is the way 
that seems possible to input Unicode to the rich edit control.  I see 
you are doing something with RTF also.  My rtf prolog is as follows.

$rtf_prolog = <<'E_O_RTF';
{\rtf1\ansi\deff0{\fonttbl
{\f0 \fcharset1\fnil Lucida Console;}
{\f1 \fcharset1\fnil Lucida Sans Unicode;}}\fs16
E_O_RTF

#####################################
sub conv_to_uni_rtf
{ my ( $out, $allunicode ) = @_;
   $out =~ [EMAIL PROTECTED]@[EMAIL PROTECTED];
   $out =~ [EMAIL PROTECTED]@[EMAIL PROTECTED];
   $out =~ [EMAIL PROTECTED]@[EMAIL PROTECTED];
   $out =~ [EMAIL PROTECTED]@[EMAIL PROTECTED];
   $out =~ [EMAIL PROTECTED]@[EMAIL PROTECTED];
   $out =~ [EMAIL PROTECTED]> @=> \\f1 @g;
   $out =~ s@ <[EMAIL PROTECTED]  <[EMAIL PROTECTED];
   $out = '\\f1 ' . $out . '\\f0 '  if $allunicode;
   $out = $rtf_prolog . $out . '}';
   return $out;
}

It appears that I later pass this string to the rich edit control's 
Text() function directly.

I've long since forgotten the exact details of how this works, but 
perhaps you can merge it with some of your ideas, and figure out a solution.

Let us know if you come up with something more general purpose than 
mine, or if mine helped you achieve your goals!  Good luck!

-- 
Glenn -- http://nevcal.com/
===========================
A protocol is complete when there is nothing left to remove.
-- Stuart Cheshire, Apple Computer, regarding Zero Configuration Networking

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
http://perl-win32-gui.sourceforge.net/

Reply via email to