Forum > Lazarus Extra Components

TIpHTMLPanel

(1/2) > >>

CCRDude:
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: ---   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;
--- End code ---
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:
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:

--- Quote from: CCRDude on November 05, 2018, 10:21:57 pm ---(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.

--- End quote ---

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  window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function ColorToHTML(const AColor: TColor): String;begin  Result := '#' + HexStr(ColorToRGB(AColor), 6);end;

CCRDude:
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: ---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;
--- End code ---

And where the style change is applied:

--- Code: ---      FHTMLIP.EnumDocuments(@HtmlEnumerator);

--- End code ---

bobix:
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>

Navigation

[0] Message Index

[#] Next page

Go to full version