wxhtmlwindow catch when closed 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
Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 174
Joined: Mon Jan 28, 2019 8:22 am

wxhtmlwindow catch when closed

Post by Wolfgang » Tue Dec 17, 2019 3:43 pm

Hello
I made a derived class MyHtmlwindow from wxhtmlwindo, but now I need to call some code when this window is closed.
Tried with EVT_CLOSE but that is not working inside the event table declaration.

Code: Select all

EVT_CLOSE(MyHtmlWindow::Onclosewindow)

Code: Select all

C++ #define EVT_CLOSE(func) wx__DECLARE_EVT0(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(func))

Code: Select all

wxEVT_CLOSE_WINDOW(MyHtmlWindow::Onclosewindow)

Code: Select all

C++ (<error-type>)<error>(&MyHtmlWindow::Onclosewindow)
Other try I had making a destructor for MyHtmlwindow, but this was not called.

I consturct it with htmlwindow on a panel with mainframe as parent, and then show ith with Addpane wihtin the wxAuimanager.
must I create an extra frame first, and then make it?

User avatar
doublemax
Moderator
Moderator
Posts: 15065
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxhtmlwindow catch when closed

Post by doublemax » Tue Dec 17, 2019 3:46 pm

Tried with EVT_CLOSE but that is not working inside the event table declaration.
That should work. Please show the whole event table and the full event handler. And what error do you get?
Use the source, Luke!

Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 174
Joined: Mon Jan 28, 2019 8:22 am

Re: wxhtmlwindow catch when closed

Post by Wolfgang » Tue Dec 17, 2019 4:04 pm

Code: Select all

wxBEGIN_EVENT_TABLE(MyHtmlWindow, wxHtmlWindow)
EVT_MOTION(MyHtmlWindow::OnMouseMotion)
EVT_LEFT_DOWN(MyHtmlWindow::OnActivm)
EVT_CLOSE(MyHtmlWindow::Onclosewindow)
wxEND_EVENT_TABLE()

Code: Select all

EVT_CLOSE(MyHtmlWindow::Onclosewindow)
In Visual Studio EVT_CLOSE is marked red invalid typ converting


Code: Select all

void MyHtmlWindow::Onclosewindow(wxMouseEvent& event)
{
	wxInt16 countm = 1;
	while (!bibwinid[countm] == GetId())
	{
		countm++;
	};
	bibwin[countm] = NULL;
	bibwinid[countm] = NULL;
}

Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 174
Joined: Mon Jan 28, 2019 8:22 am

Re: wxhtmlwindow catch when closed

Post by Wolfgang » Tue Dec 17, 2019 4:06 pm

found now the mistake, just have to find the right thing for it.
is of course not a mouse event

User avatar
doublemax
Moderator
Moderator
Posts: 15065
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxhtmlwindow catch when closed

Post by doublemax » Tue Dec 17, 2019 4:07 pm

Code: Select all

void MyHtmlWindow::Onclosewindow(wxMouseEvent& event)
This needs a wxCloseEvent as parameter.
Use the source, Luke!

Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 174
Joined: Mon Jan 28, 2019 8:22 am

Re: wxhtmlwindow catch when closed

Post by Wolfgang » Tue Dec 17, 2019 4:08 pm

wxCloseEvent

Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 174
Joined: Mon Jan 28, 2019 8:22 am

Re: wxhtmlwindow catch when closed

Post by Wolfgang » Tue Dec 17, 2019 4:09 pm

You were a bit quicker :)

Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 174
Joined: Mon Jan 28, 2019 8:22 am

Re: wxhtmlwindow catch when closed

Post by Wolfgang » Tue Dec 17, 2019 4:28 pm

it compiles like that, but the onclosewindow never gets called.

The htmlwindow can only get closed with the x from the pane, must I make the eventtable for the auimanager?

User avatar
doublemax
Moderator
Moderator
Posts: 15065
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxhtmlwindow catch when closed

Post by doublemax » Tue Dec 17, 2019 5:24 pm

I think only toplevel windows receive an EVT_CLOSE event. So the destructor would be the best place to put your code. But it i understand you correctly, it doesn't get destroyed, just hidden? Or the toplevel parent gets closed? In the latter case, you need to put the code in the EVT_CLOSE handler of the containing toplevel window.
Use the source, Luke!

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4357
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxhtmlwindow catch when closed

Post by ONEEYEMAN » Tue Dec 17, 2019 6:05 pm

doublemax,
You are correct - only TLW receives EVT_CLOSE.
There is a ticket about sending it for wxDialog (its old).

So if this HtmlWindow is not a TLW - its better to put you code in the destructor or use the parent window (or TLW) EVT_CLOSE event to process it.

Thank you.

Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 174
Joined: Mon Jan 28, 2019 8:22 am

Re: wxhtmlwindow catch when closed

Post by Wolfgang » Tue Dec 17, 2019 6:16 pm

Code: Select all

		m_bibf[count]->SetPage(page1);

		m_mgr.AddPane(m_bibf[count], wxAuiPaneInfo().Resizable().Dockable(false).Float());

Code: Select all

MyHtmlWindow* m_bibf[1024];
wxAuiManager m_mgr;
So it gets created. It has a close button on it, and if I press this close button the close event does not get called,I tried to make a destructor, but if I define a destructor for MyHTMLWindow it also does not get called.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 4357
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wxhtmlwindow catch when closed

Post by ONEEYEMAN » Tue Dec 17, 2019 6:20 pm

Hi,
You need to define the EVT_CLOSE for the AUI panel.

Thank you.

User avatar
doublemax
Moderator
Moderator
Posts: 15065
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxhtmlwindow catch when closed

Post by doublemax » Tue Dec 17, 2019 6:40 pm

EVT_AUI_PANE_CLOSE(func):
Triggered when a docked or floating pane is closed.

Code: Select all

void handlerFuncName(wxAuiManagerEvent& event)
But i still think it's strange that the destructor of the MyHtmlWindow is not executed when the AUI pane gets closed. I've never used AUI, but i don't think you can get a closed AUI pane back, so it must be destroyed.
Use the source, Luke!

Wolfgang
I live to help wx-kind
I live to help wx-kind
Posts: 174
Joined: Mon Jan 28, 2019 8:22 am

Re: wxhtmlwindow catch when closed

Post by Wolfgang » Tue Dec 17, 2019 6:46 pm

Aui Pane close works perfectly.

Thanks

Post Reply