Recent

Author Topic: TIpHTMLPanel  (Read 7132 times)

CCRDude

  • Hero Member
  • *****
  • Posts: 596
TIpHTMLPanel
« on: November 05, 2018, 10:21:57 pm »
While making my project cross-platform, my last hurdle today was HTML display (used for displaying update notice and the integrated help).

I've been using TFrameViewer09 for many years, but it displays a blank page on Cocoa. To use RichMemo, my first alternative, I would have needed a HTML to RTF converter.

I then found TIpHTMLPanel. TurboPower is a name that rings a bell, I used libraries from a company by that name like 25 years ago for creating GUIs on Turbo Pascal 5.5.

Works fine - except for the background color. The background is always white for me.

I do set the default colors this way:
Code: [Select]
   if Assigned(FHTMLIP) then begin
      FHTMLIP.Color := AStyle.Window.BackgroundColor;
      FHTMLIP.DefaultTypeFace := AStyle.Window.FontName;
      FHTMLIP.LinkColor := AStyle.Table.Header.ActionFont.FontHoveredColor;
      FHTMLIP.BgColor := AStyle.Window.BackgroundColor;
      FHTMLIP.ALinkColor := AStyle.Table.Header.ActionFont.FontHoveredColor;
   end;
This is called in SetParent before the HTML is loaded from the files resources. Settng the type face and link color works correctly.

What can I do to get the background correct?

(adding it as css is not an option, since due to support for Dark Mode in Windows and MacOS I need to toggle background & font colors.

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: TIpHTMLPanel
« Reply #1 on: November 05, 2018, 11:31:26 pm »
Using the BgColor property, I did not get it to work either. But setting the background color with a style works. So why don't you replace the text "<body" of your html by "<body style="background-color:yellow" to force a yellow background?

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: TIpHTMLPanel
« Reply #2 on: November 06, 2018, 12:35:35 am »
(adding it as css is not an option, since due to support for Dark Mode in Windows and MacOS I need to toggle background & font colors.

If nothing else works and you must add CSS--as suggested by wp--you could try using something like this to convert any TColor to a CSS-color string:

Code: Pascal  [Select][+][-]
  1. function ColorToHTML(const AColor: TColor): String;
  2. begin
  3.   Result := '#' + HexStr(ColorToRGB(AColor), 6);
  4. end;
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

CCRDude

  • Hero Member
  • *****
  • Posts: 596
Re: TIpHTMLPanel
« Reply #3 on: November 06, 2018, 09:15:02 am »
Many thanks for the confirmation that BgColor does not seem to work.

Changing the HTML content would mean that I would have to cache/reload the content. I looked into TipHTML to see how it handles CSS, and found another way:

Code: [Select]
procedure TCustomSpybot3DocumentFrame.HtmlEnumerator(Document: TIpHtml);
var
   n: TIpHtmlNode;
   nb: TIpHtmlNodeBODY;
begin
   if not Assigned(Document.HtmlNode) then begin
      Exit;
   end;
   if Document.HtmlNode.ChildCount < 1 then begin
      Exit;
   end;
   n := Document.HtmlNode.ChildNode[0];
   if not (n is TIpHtmlNodeBODY) then begin
      Exit;
   end;
   TIpHtmlNodeBODY(n).BgColor := FHTMLIP.BgColor;
end;

And where the style change is applied:
Code: [Select]
      FHTMLIP.EnumDocuments(@HtmlEnumerator);

bobix

  • Jr. Member
  • **
  • Posts: 71
    • http://rechnik-bg.com
Re: TIpHTMLPanel
« Reply #4 on: November 06, 2018, 10:18:50 am »
I dont think that TIpHTMLPanel has css support, but this maight be supported:

 <html>
<body bgcolor="#E6E6FA">
<h1>Hello world!</h1>
<p>Hello world!</p>
</body>
</html>
Lazarus 1.8.4 r57972 FPC 3.0.4 i386-win32-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: TIpHTMLPanel
« Reply #5 on: November 06, 2018, 10:30:53 am »
I fixed BgColor in the current trunk version, and it is a published property now. It is used unless a background color or background image is defined inside the html string.

Not sure about backporting to v2.0RC3 as the new version will soon be released. If you don't use trunk you can fix your version with these changes:
  • Open the file iphtml.pas in the folder components/turbopower_ipro. Make a backup copy first.
  • Find procedure TIpHtmlFrame.InitHtml and add the line: "FHtmlBgColor := FViewer.BgColor;", maybe after "FHtml.VLinkColor := ..."
  • Find procedure TIpHtmlNodeBODY.Render. In the "else" branch of "if ScaleBitmaps" there is a "Owner.Target.Brush.Color := clWhite;". Replace the "clWhite" by "Owner.BgColor". You probably can replace also the two other "clWhite"s in this procedure in the same way.
  • Find the "published" declaration section of TIpHtmlPanel. Add a "property BgColor;".
  • Reinstall the component.
« Last Edit: November 06, 2018, 10:43:38 am by wp »

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: TIpHTMLPanel
« Reply #6 on: November 06, 2018, 10:32:10 am »
I dont think that TIpHTMLPanel has css support
Wrong, it does have css support, but not for all fancy features. "background-color" is supported.
« Last Edit: November 06, 2018, 10:33:41 am by wp »

CCRDude

  • Hero Member
  • *****
  • Posts: 596
Re: TIpHTMLPanel
« Reply #7 on: November 06, 2018, 12:50:04 pm »
Thank you very much @wp!
Glad to hear this is still in development and gets improved so quickly!
Good to have a fix instead of having to use a workaround :)

 

TinyPortal © 2005-2018