How to get size of wx wxHtmlWindow Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Nikolay
Experienced Solver
Experienced Solver
Posts: 72
Joined: Wed Oct 10, 2007 4:27 am

How to get size of wx wxHtmlWindow

Post by Nikolay »

Hi

I have dialog that contains only wxHtmlWindow. In a dialog constructor I load html page to this wxHtmlWindow, and I want that window have normal size when appear. So, wxHtmlWindow control should show all html page without scroll bars and blank field and winwow's size should be == size of wxHtmlWindow control.

Problem is I can't force wxHtmlWindow to get real size of loaded html. Any ideas?
Best regards, Nikolay
wxWidgets in russian
Small Notes Manager and Clipboard Manager with History written with wxWidgets
tan
wxWorld Domination!
wxWorld Domination!
Posts: 1471
Joined: Tue Nov 14, 2006 7:58 am
Location: Saint-Petersburg, Russia

Re: How to get size of wx wxHtmlWindow

Post by tan »

Hi,
Nikolay wrote:Hi

I have dialog that contains only wxHtmlWindow. In a dialog constructor I load html page to this wxHtmlWindow, and I want that window have normal size when appear. So, wxHtmlWindow control should show all html page without scroll bars and blank field and winwow's size should be == size of wxHtmlWindow control.

Problem is I can't force wxHtmlWindow to get real size of loaded html. Any ideas?
try this:

Code: Select all

wxSize vs = html_window->GetVirtualSize();
SetClientSize(vs);  // For the parent
OS: Windows XP Pro
Compiler: MSVC++ 7.1
wxWidgets: 2.8.10
Nikolay
Experienced Solver
Experienced Solver
Posts: 72
Joined: Wed Oct 10, 2007 4:27 am

Post by Nikolay »

This does not work in Create(). So, I have created timer and resize window after 10 ms... But there is still some problems with window visible and size - GetVirtualSize() returns correct width but incorect height. I'll try to fix it in few after week end.

Thanks for help.
Best regards, Nikolay
wxWidgets in russian
Small Notes Manager and Clipboard Manager with History written with wxWidgets
wxBen
Experienced Solver
Experienced Solver
Posts: 65
Joined: Wed Jun 06, 2012 4:44 pm
Location: Calgary, Canada

Re: How to get size of wx wxHtmlWindow

Post by wxBen »

I just faced a very similar problem. I am using an instance wxHtmlWindow to show a super tool tip (like Excel), and I want no scroll bars and for it to be just large enough to display the contents. There is no predetermined way of doing that :? , but this is how I got the result I wanted :idea: . Works perfectly!

Code: Select all

   //There is no way to get the perfect height for the window.
   //So we set it to something too small for starters:
   int ySize = 50;
   int xSize = 200;
   mywxHTML->SetSize(xSize, ySize);

   //Now if we got a vertical scroll bar, then make the window taller,
   //to get rid of the scroll bar:
   int vxSize=0;
   int vySize=0;
   mywxHTML->GetVirtualSize(&vxSize, &vySize);
   if (vySize > ySize)
      {
      mywxHTML->SetSize(xSize, vySize);
      }

   //Now reset the text to make it redo the layout and sizes:
   wxString wxEmpty;
   mywxHTML->SetPage(wxEmpty);
   mywxHTML->SetPage(html2);

   //Now get the final size, which may have reduced more since the scroll bar
   //is now gone.
   wxHtmlContainerCell* cell = mywxHTML->GetInternalRepresentation();
   if (cell)
      {
      int height = cell->GetHeight();
      mywxHTML->SetSize(xSize, height + oborder + oborder);
      }

   //Show it:
   mywxHTML->Show(true);

   //Make sure it is seen:
   mywxHTML->Raise();
To get a nice rectangle around the outer edges of the window, I also did this:

Code: Select all

mywxHTML->SetBorders(1);
And then my tip contents is wrapped around a matrix with a border but with the cell spacing set to zero.

Code: Select all

<body bgcolor="xxx background colour goes here xxx">
<table width="100%" border="1" cellspacing="0" cellpadding="8"><tr><td>
xxx tip text HTML goes here xxx
</td></tr></table>
</body>
The end result is you get an HTML window that is just big enough to show its contents, no scroll bars, and it has a nice border line around it. =D>
Post Reply