[edited response so as not to be top posted]
Sky Blueshoes wrote:
>> I have a RichEdit widget in which I use as a display to my program. I
>> created a sub in which I call whenever I want to display something:
>>
>> sub display {
>> my @input = @_;
>> for (0..$#input) {
>> $display->Select(1e9, 1e9);
better: $display->Select(-1,-1);
>> $display->ReplaceSel("$input[$_]\r\n");
>> }
>> }
>>
>> Ok, now I have two problems...
>>
>> First, I'll use $display->SetCharFormat( -bold => 1, -color =>
>> "#0000FF"); to change the color of the line I want to display, but it
>> immediately changes back after just one line. Do I have to set this
>> before every line I want Blue?
SetCharFormat() sets the format of the selected text. If there is no
selection it sets the format of the insertion point. In your case it
sets the format of the insertion point. ReplaceSel, similarly replaces
the selection, or inserts at the insertion point if there is no
selection. ReplaceSel effective creates a new insertion point, which
will take the underlying formatting. [Note that in the next Win32::GUI
release the -foreground option will allow you to set the 'default' text
colour]. It's difficult to help with what you should do, as you provide
no code that show where you are currently calling SetCharFormat(), but I
would call Select() once before the loop and SetCharFormat() each time
round the loop.
>> If you look at my sub I would like to
>> use it like this: &display('First line of text', 'second line...',
>> 'etc');
>> In this example only the first line would be blue
> To fix the color reset problem I changed the
> $display->ReplaceSel("$input[$_]\r\n"); to
> $display->ReplaceSel("\r\n$input[$_]"); and I also had to add the
> following line after the for loop:
>
> $display->SetCharFormat( -bold => 0, -color => "#000000");
I'd do this (complete code at end)
sub display
{
my @lines = @_;
$re->SetSel(-1,-1); # move to the end
$re->ScrollCaret(); # ensure caret is in view
for my $line (@lines) {
$re->SetCharFormat(-color => 0xFF0000); # set the color
$re->ReplaceSel("$line\r\n"); # insert the text
}
}
Although it might be quicker if you know that the amount of text in
@lines is 'small' to join('\r\n', @lines), and call ReplaceSel once with
the result.
>> The second problem I am having is with the scrolling...I have a
>> status bar widget underneath this RichEdit widget, instead of the
>> text scrolling up like I would like it to, it just pushes the
>> status bar down and never even shows a scroll bar. How do I fix this?
I don't understand how it 'pushes the status bar down', but to get a
vertical scroll bar in a RichEdit control add -vscroll => 1 to the
constructor.
To solve the scroll problem I had to add the -style option to the
What -style did you add? I suspect that you really want -vscroll instead.
creation of my RichEdit widget and I also had to include the following
line in my display sub:
$display->SendMessage(0x115, 1, 0);
#define WM_VSCROLL 227
You need to do this, as I expect by using the -style option you have
removed the default 'autovscroll' style. I assume you are not useing
warnings, as if you were you'd get a warning that using the -style
option is deprecated. It is exactly for this sort of reason that using
-style is dangerous.
I assume this tells the scrollbar to scroll down 1.
Yes. But it is not necessary if done correctly.
Regards,
Rob.
My (complete) example of doing this:
#!perl -w
use strict;
use warnings;
use Win32::GUI();
my $counter = 0;
my $mw = Win32::GUI::Window->new(
-title => "Blue Text in RichEdit",
-size => [400,300],
);
my $re = $mw->AddRichEdit(
-width => $mw->ScaleWidth(),
-height => 200,
-vscroll => 1,
);
$mw->AddButton(
-text => "Insert lines",
-left => $mw->ScaleWidth() - 100,
-top => $mw->ScaleHeight() - 30,
-onClick => \&insertText,
);
$mw->Show();
Win32::GUI::Dialog();
exit(0);
sub insertText
{
display('Inserted line '.++$counter,
'Inserted line '.++$counter,
'Inserted line '.++$counter,
);
return 1;
}
sub display
{
my @lines = @_;
$re->SetSel(-1,-1); # move to the end
$re->ScrollCaret(); # ensure caret is in view
for my $line (@lines) {
$re->SetCharFormat(-color => 0xFF0000); # set the color
$re->ReplaceSel("$line\r\n"); # insert the text
}
}
__END__