Dan,

$re->Text() behind the scenes calls the win32api GetWindowText API, which in turn sends a WM_GETTEXT message to the richedit control. As far as I can see there is no Unicode version of GetWindowText.. You actually need to send a EM_GETTEXTEX message (see msdn for more information). This message can be set to get the text in unicode (UCS-2) and that then needs to be converted to perl characters.

As Win32::GUI does not support the EM_GETTEXTEX message, calling it is somewhat tricky, but the following seems to work here. If you'd like native support for EM_GETTEXTEX, then please raise a RFC.

Regards,
Rob.

#! perl -w
use strict;
use warnings;

use Win32::GUI;

# constants:
sub WM_USER() {1024};
sub EM_GETTEXTEX() {+WM_USER+94};
sub GT_DEFAULT() {0};

my $w = Win32::GUI::Window->new(
   -name => 'Main',
   -size => [800, 600],
);

my $re = $w->AddRichEdit(
   -size => [600, 400],
);

$w->AddButton(
   -name => 'btnChange',
   -pos => [600, 500],
   -text => '$re->Text($re->Text)',
);

my $rtf_prolog = '{\rtf1\ansi\deff0
{\fonttbl{\f0 \fcharset1\fnil Times New Roman;}}
{\stylesheet {\*\cs0 \additive Default Paragraph Font;}}';

$re->Text($rtf_prolog . 'This, \u305?, is not exactly the letter i' . '}');

$w->Show();
Win32::GUI::Dialog();
exit(0);

sub btnChange_Click {
   my $text1 = $re->Text();
   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 = $re->SendMessage(EM_GETTEXTEX, $wparam, $buffer);

   my $octets = substr($buffer, 0, ($numTchar*2));

   use Encode qw/decode/;
   my $text2 = decode("UCS-2LE", $octets);

   print "--$text1--\n";
   print "--$text2--\n";

   return 1;
}

__END__



Dan Dascalescu wrote:

I'm trying to get a useful Perl representation of the Unicode string
edited by the user in a RichEdit. It turned out that if I use
$RichEdit->Text, some Unicode characters are corrupted (transformed to
Latin equivalents). The same happens for GetSelText.

In other words, $RichEdit->Text($RichEdit->Text) corrupts the text!

I looked in RichEdit.xs, then at
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/richedit/richeditcontrols/richeditcontrolreference/richeditmessages/em_setoptions.asp
, but I couldn't figure out a fix.

So is there a way to retrieve the intact Unicode content of a RichEdit?
The code below demonstrates the problem (should I submit it as a bug?).

Or, is there a way to retrieve the RTF behind the RichEdit, other than
by doing a Save and reading the file?

Thanks,
Dan

#! perl -w
use strict;
use Win32::GUI;

my $w = Win32::GUI::Window->new(
   -name => 'Main',
   -size => [800, 600],
);

my $re = $w->AddRichEdit(
   -size => [600, 400],
);

$w->AddButton(
   -name => 'btnChange',
   -pos => [600, 500],
   -text => '$re->Text($re->Text)',
);

my $rtf_prolog = '{\rtf1\ansi\deff0
{\fonttbl{\f0 \fcharset1\fnil Times New Roman;}}
{\stylesheet {\*\cs0 \additive Default Paragraph Font;}}';

$re->Text($rtf_prolog . 'This, \u305?, is not exactly the letter i' . '}');

sub btnChange_Click {
   $re->Text($re->Text);
}


$w->Show;

Win32::GUI::Dialog();

sub Main_Terminate {
   -1;
}


-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_idt77&alloc_id492&opÌk
_______________________________________________
Perl-Win32-GUI-Users mailing list
Perl-Win32-GUI-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users


Reply via email to