Kirix Support Forums

adding functions to the close event

Please post all general questions, comments, bug reports, and any other wxAUI feedback here.

adding functions to the close event

Postby stevee on Thu Apr 20, 2006 4:07 pm

Hi,
I have a problem with the close event, that means I don't know how to 'catch' this close event in order to add some functions. Thus, what happens when I click the close button, which function is called and how can I add some code to this close function. I tried to use a wxWidgets EVT_CLOSE macro in the EVENT_TABLE, but it is not working.

Following I try to specify what I intend to do again in other words.
I derived a class from wxPanel and added it with m_mgr.AddPane to a wxMDIParentFrame. When I am closing the panel with the automatically generated close button the panel is closing - every thing is fine so far.
But I would like to add a function when closing the panel that checks a menu item, for instance. How can I do this?

Hope that was not to confusing and thanks for answers.
Stevee
stevee
Registered User
 
Posts: 2
Joined: Thu Apr 20, 2006 3:49 pm

Re: adding functions to the close event

Postby abligh on Thu Apr 20, 2006 6:08 pm

stevee wrote:Hi,
I have a problem with the close event, that means I don't know how to 'catch' this close event in order to add some functions. Thus, what happens when I click the close button, which function is called and how can I add some code to this close function. I tried to use a wxWidgets EVT_CLOSE macro in the EVENT_TABLE, but it is not working.

Following I try to specify what I intend to do again in other words.
I derived a class from wxPanel and added it with m_mgr.AddPane to a wxMDIParentFrame. When I am closing the panel with the automatically generated close button the panel is closing - every thing is fine so far.
But I would like to add a function when closing the panel that checks a menu item, for instance. How can I do this?

Hope that was not to confusing and thanks for answers.
Stevee


If you are trying to get this to work from a floating pane, you might want to make wxFloatingPane::OnClose do something like the following. If you have a docked panel with a closebox, you will need to make a similar adjustment.

Note that (in my opinion) we need to do a lot more work to get close events handled properly. For instance we need the standard veto behaviour captured.

Code: Select all
    void OnClose(wxCloseEvent& event)
    {
        static wxList s_closing;

        EnsureSizeRecorded();

        if (!s_closing.Member(this))
        {
            s_closing.Append(this);

            wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
            cancelEvent.SetEventObject( m_pane_window );
            m_pane_window->GetEventHandler()->ProcessEvent(cancelEvent);
            s_closing.DeleteObject(this);
            // we should really return here without doing anything if the close was vetoed
        }

        m_owner_mgr->OnFloatingPaneClosed(m_pane_window);
        Destroy();
    }
abligh
Registered User
 
Posts: 59
Joined: Sun Jan 01, 2006 2:31 pm

Postby stevee on Fri Apr 21, 2006 3:19 am

Thanks so far, but I encounter still some compiler errors.

I added the (modified) code you posted in my wxMDIParentFrame and linked it with EVT_CLOSE in the event table.

The first compiler error:
'EnsureSizeRecorded': identifier not found
What does the 'EnsureSizeRecorded()' command mean?

The second problem occurs when I try to use the wxFrameManager from the wxMDIParentFrame. In my case it is m_mgr.
m_mgr->OnFloatingPaneClosed(pcp_frame);
// pcp_frame is an instance of my wxPanel. It is a docked panel with a closebox.
Compiler error: left of -> OnFloatingPaneClosed must point to class/struct/union
stevee
Registered User
 
Posts: 2
Joined: Thu Apr 20, 2006 3:49 pm

Return to wxAUI Questions, Thoughts & Feedback