Ace128 has asked for the wisdom of the Perl Monks concerning the following question:

Hey,

Im working on some tray thing here but I really hate that the docs for this API is so nonexisting! 'TBD' everywhere!

Anyway, I had a coupld of questions about this:
1. Exactly how can I append to this richedit without having to do something like this:
$richEdit->Text($richEdit->Text() . " Appended text\n");
How about inserting? I can also use an array, append to that and use that for the Text function, but still feels rather crappy because the whole text is rewritten to the widget...

2. Can I save the changed style on the text somehow. Like say I do:
$richEdit->Select (0, 20); $richEdit->SetCharFormat(-color => "#0000FF");
Now, if I do the code mentioned in #1, everything gets the same attribute throughout the text (all text is blue).
This is rather a combined problem with #1. The thing is, I wanna be able of adding text with a special font/color/size etc, and keep it that way, even if I add more text (with different font/color etc). That is, I wanna add text to this richedit with different styles and keep them that way. Or I have to add all text, and change afterwards? (this seems so dumb).
Like this would be ideal:
my $font = new Win32::GUI::Font( -name => "Courier New", #-height => 16, -bold => 1, ); $richEdit->Append(-text => " Appended text", -font => $font);

I would also like to have some nice tutorial/API for this kind of stuff. All I could find (which is good, but not complete is http://jeb.ca/perl/win32-gui-docs ). With a more complete API, things would be hell of alot easier!

Replies are listed 'Best First'.
Re: Questions about Win32::GUI::RichEdit
by jplindstrom (Monsignor) on Jul 06, 2005 at 21:45 UTC
    You're so close :)

    This is how you append to a RichEdit control (with a certain font and styles etc. Only set the options you want to change):

    $rePOD->Select(999999,999999); $rePOD->SetCharFormat( -color => 0x000000, -bold => 1, @aFont -height => $self->rhConfig()->{podFontSize}, -name => $self->rhConfig()->{podFontName}, ); $rePOD->ReplaceSel("$line\n", 1);

    The docs are a bit spotty, yes, but the simple demo programs clarify a whole lot. Unfortunately it's not in the current PPM distro, but I think they will be bundled with the new version due Real Soon Now(tm).

    Until then, get the source distro which has the demo programs.

    /J

      Alright! Thanks! But, care to explain the:
      -height => $self->rhConfig()->{podFontSize}, -name => $self->rhConfig()->{podFontName},
      part?
        I copied my example from an actual program.

        That's for setting the size and face of the font to values from a config file.

        /J

Re: Questions about Win32::GUI::RichEdit
by ikegami (Patriarch) on Jul 06, 2005 at 20:44 UTC
    I think the way to go is to replace the control's selected text instead of replacing the control's text. Select the end of the text first if you wish to append. I'm not sure how to do that.