Balloon Hint using WPRichText?

  • I am looking to have a balloon hint for my application that displays WPRichText. I currently use the standard TBalloonHint and display the WPRichText in plain text, but if the text is long, the TBalloonHint is pretty bad and can go off the screen.

    Just wondering if anyone has already put something like TBallonHint together but uses a nice presentation using a WPRichText control.

    Thanks,

    Eric

    • Offizieller Beitrag

    A TWPRichText would cause too much overhead, this can be done easily with the TWPPaintEngine. But it is necessary to override the TBalloonHint.

    The code is also a good example how to use this non-visual class TWPPaintEngine.

    Usage:

    in Form.OnCreate

    aHint := TWPRTFBalloonHint.Create(Self);

    when you need it:

    aHint .Text := '<html><div style="text-align:center">Hello <b>World</b><br>Second Line</div></html>';

    aHint .ShowHint(Mouse.CursorPos);


    (The TWPRTFBalloonHint will officially be part of the next release of WPTools 9.1.)

  • Very nice! Exactly what I was looking for. Thank you!

    Couple of things to point out... the hint title shows up in the middle (vertically) of the hint box. Pretty much behind the RTF text. I don't really need a title, so no big deal.

    The other thing is I'd like to change the background color. If I use a dark VCL style, the black text is against a dark background.

    What I got to work for the most part is to use this in the class Create constructor:

    FRTFText.Memo.PaperColor := clInfoBk;


    This produces the hint window with the clInfoBk colored rectangle, but draws the clInfoBk rectangle slightly lower within the hint window by a few pixels. You can see the VCL style background color behind the clInofBk rectangle, and the hint window outline and stem is covered by the clInfoBk rectangle at the bottom due to the offset. If I don't use that PaperColor setting, this does not happen.

    So, is this probably not the right way to set the background color?

    FWIW, if I change your Draw statement to this, it lines up correctly whether using the PaperColor or not:

    Code
      FRTFText.Draw(TCustomHintWindowHelper(HintWindow).Canvas,
        2, FOffRTF-10, HintWindow.Height-14,
        WPScreenPixelsPerInch, WPScreenPixelsPerInch, 0
        );

    4 Mal editiert, zuletzt von ehimmer (21. März 2020 um 00:54)

  • Maybe have a SetTextFromStream method, or Stream property for the official release? I load RTF from a database into a TMemoryStream which I usually load into a WPRichText using LoadFromStream.

    So, using this is not as pretty as using aHint.Text assignment. Just saying.

    aHint.RTF.RTFData.LoadFromStream(vRR.Remark);

  • No problem on the Title stuff, but one last question I think. Is there a way to support linked images? Currently they show up as white space even though I loop through each of the TextObjects (RTF.RTFData.TextObjects) and load the linked image before it invokes the Draw method via the ShowHint method.

  • The images are referenced by name only. I parse out the name and pull it in as a stream from our database. Here is the code I am trying to use when popping up a hint of what we call a RapidRemark. RapidRemarks are a list of saved comments users can quickly add to a report comment. They can click on a node in a tree view to see a view of the RapidRemark in a hint window before applying it to the report. Sometimes these saved comments include images or frequently used diagrams. This is the same basic code logic I use elsewhere to resolve linked images but tailored here for this hint stuff.

    • Offizieller Beitrag

    Usually the event TWPRichText.OnRequestHTTPImage is used to load an image which is referenced by a name or id.

    That event is also available in the TWPRTFDataCollection which is accessible through Painter.RTFData. (I renamed "RTF" to "Painter")

    To use the event you need to create an event handler like this:

    Procedure TForm.DoLoadImage(

    RTFData: TWPRTFDataCollectionBase;

    Reader: TWPCustomTextReader;

    const LoadPath, url: string; TextObject: TWPTextObj; var Ok: Boolean) ;

    And assign it to Hint.Painter.OnRequestHTTPImage in code.

  • Yes, I always use the OnRequestHTTPImage event, except in one place where I can't (which I won't get into). I tried to find that event in the hint stuff earlier, but for some reason could not find it. With your instruction I easily found it this time and set up the event but it still does not work. Debugging shows that the event is invoked and the image is loaded into the TextObject, but it is not showing up in the hint. Below is the same code I use in my RapidRemark manager which works for a WPRichText.

    It is invoked this way:

    Code
      fRapidRemarkHintID := pRapidRemark.ID;
      fRapidRemarkHint.Painter.RTFData.OnRequestHTTPImage := RRHintRequestHTTPImage;
      fRapidRemarkHint.Painter.RTFData.LoadFromStream(pRapidRemark.Remark);
      fRapidRemarkHint.ShowHint(pRect);