Jump to content
Sign in to follow this  
Rolf Fankhauser

TCppWebBrowser: Text of hint on multiple lines

Recommended Posts

Hi,

 

I generate in my application dynamically svg code using a javascript version of GraphViz (viz.js). The nodes are created as follows:

<g class="node" id="node1"><title>B Regen</title>
<polygon fill="none" stroke="black" points="63.9539,-396 0.0460627,-396 0.0460627,-360 63.9539,-360 63.9539,-396" />
<text font-family="Times,serif" font-size="14" text-anchor="middle" x="32" y="-373.8">B Regen</text>
</g>

Because I want to show some data of the objects (nodes) on MouseOver I changed the innerText of <title> (which is shown as hint by default by the browser) by the following C++ code:

// helpers for interface reference counting
  // could alternatively use TComInterface instead of DelphiInterface
  typedef DelphiInterface<IHTMLDocument3> _di_IHTMLDocument3;
  typedef DelphiInterface<IHTMLElement> _di_IHTMLElement;
  typedef DelphiInterface<IHTMLElementCollection> _di_IHTMLElementCollection;
  typedef DelphiInterface<IHTMLWindow2> _di_IHTMLWindow;

  // Get Data:
  _di_IHTMLDocument3 doc = CppWebBrowser1->Document;
  _di_IHTMLElement elem;
  _di_IHTMLElementCollection collection;
  _di_IHTMLWindow window;
  long len;
  TVariant value;
  // only for testing  
  OleCheck(doc->getElementById(WideString("svg"), &elem));
  if (elem) {
    elem->getAttribute(WideString("viewBox"), 2, &value);
    ShowMessage("viewBox: " + value);
  }
  
  // fill the title tags with data to show on Mouse over:  
  OleCheck(doc->getElementsByTagName(WideString("title"), &collection));
  collection->get_length(&len);
  //ShowMessage("Collection length: " + IntToStr(len));
  //ShowMessage(Commands->Text);  
  WideString tmp, tmp2;
  int line;
  for (long i = 0; i < len; ++i)
  {
    TVariant name = i;
    TVariant index = 0;
    DelphiInterface<IDispatch> disp;
    if(SUCCEEDED(collection->item(name, index, &disp)))
    {
      DelphiInterface<IHTMLElement> element;
      if( SUCCEEDED(disp->QueryInterface(IID_IHTMLElement, (LPVOID*)&element)))
      {
        element->get_innerText(&tmp); //reading element name
        line = FindElementInMemo(Commands, Trim(tmp)); //finding the element in a memo
        if (line != -1) {
          tmp2 = ExtractParameters(Commands->Strings[line]); //extracting the data to show
          //if (tmp != WideString("Output")) {
          if (tmp2 == WideString(""))
            tmp2 = WideString("a<br>b"); //test to format the data on two lines
          OleCheck(element->put_innerHTML(tmp2)); //replace the original text of the element name by the element data
        }
      }
    }
  }

All is working but the text is not shown on multiple lines. ExtractParameters returns one line, so I made a test by creating constant data of 2 lines by "a<br>b". I tried with put_innerText and put_innerHTML but without success.

 

Any idea why this doesn't work?

 

Could I define a separate event handler for onmouseover using doc->execScript ?

 

Thanks, Rolf

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×