Hi Octavian and Glenn

The thing with the '\par' was the point.
The RTF-format is documented here:
http://msdn.microsoft.com/en-us/library/aa140283(office.10).aspx 

i had to turn the '\r\n' into '\\par\r\n'.

So here is my solution to handle multiline-unicode-text with richedit-fields.

You need the pragmas:
use utf8; #  'sub GT_DEFAULT() {0};'
  #my $flags = $flags = GT_DEFAULT; # defined with a constant
   my $codepage = 1200;
   my $struct = pack("LLIpp", $maxlen, $flags, $codepage, undef, undef);
   my $address = pack("P20", $struct);
   my $wparam = unpack("L", $address);
   my $numTchar = $window -> $richedit -> SendMessage(1118, $wparam, $buffer); #
Alternatively You can define the message as constants WM_USER and EM_GETTEXTEX 
in
the header of the program --> 'sub WM_USER() {1024};' and 'sub EM_GETTEXTEX()
{+WM_USER+94};'
  # my $numTchar = $WIN -> re -> SendMessage(qw(EM_GETTEXTEX {+WM_USER()
{1024}+94}), $wparam, $buffer); # defined with constants
   my $octets = substr($buffer, 0, ($numTchar*2));
   my $text = decode("UCS-2LE", $octets);
   return($text); # Returns a unicode-string
}


And the Set-function:

sub SetText # prepares unicode-strings for the Text()-method of the richedit
{
my @input = @_;
my $rtf_prolog  = '{\rtf1'; # Minimal-RTF-Header. Define Your own RTF-Header
according the RTF-specs
    $input[0] =~ s/([^\x00-\x7F])/'\uc1\u'.((ord $1 < 32768)?ord $1 :
ord($1)-65536).'?'/eg; # Converting unicode into 'escaped' RTF-format 
    $input[0] =~ s/(\r\n)/\\par\r\n/g; # Converting common newlines (\r\n) into
RTF-newlines (\par\r\n)
    return $rtf_prolog . $input[0] . '}'; # Returns the string as RTF
}


So if you want so get the text of the field, use:
$SAVE = &GetText($window,'richedit_field');

And to set it back, use:
$window -> richdit_field -> Text(SetText($SAVE)); 

In this example, I made the function GetText variable, if you have more than one
window or richedit-field.
Honestly, I tested this not to much. Newlines, tabs and spaces works well. But i
don't know what happens, if there is something totally unexpected in the 
richedit.

Feel free to ask, if anyone needs examples or further information to the
functions above.
Again, thanks to all.

Regards,
Raphael



On Wed 05/11/08 22:49 , "Octavian Rasnita" [EMAIL PROTECTED] sent:
> If I remember well, you need to use
> \par
> in the RTF document for specifying a new line.
> 
> Find and read the RTF specifications. It will help you to do more other
> things.
> 
> Octavian
> 
> ----- Original Message ----- 
> From: "Raphael Stoeckli"  rabanti.ch>To: Sent: Wednesday,
November 05, 2008 10:05 PM
> Subject: [perl-win32-gui-users] Newlines disappearing in 
> richedit(unicode-content)
> 
> 
> > 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
> >
> >
> >
> -------------------------------------------------------------------------> 
> 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-use
> rs> http://perl-win32-gui.sourceforge.net/
> 
> 
> 
> 


-------------------------------------------------------------------------
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