I have an instance of a wxScrolledWindow, which contains several wxBoxSizer instances.
Each wxBoxSizer contains a wxCollapsiblePane and a wxHyperlinkCtrl ("Remove" link). Please refer to attachment. That is how it looks like.
When the "Remove" hyper-link is clicked, the wxCollapsiblePane associated with it (and it's child controls) needs to be removed and also the "Remove" link itself.
For this, I have the following code, which works fine on Windows, but crashes on Mac. If i comment out the line "removeLink->Destroy();", it does not crash, but the link remains, which i obviously do not want.
The wxHyperlinkCtrl is actually customized in order to store the ID of the associated wxCollapsiblePane.
The "m_metaDataControlsbox" is the outermost sizer, which contains all the other wxBoxSizer instances.
What is it that I am doing wrong here? Please help!
Code: Select all
void PropertiesDialog::OnRemoveMetadataControls(wxHyperlinkEvent& event)
{
bool bRemoved = false;
int id = event.GetId();
customHyperLinkCtrl* removeLink = (customHyperLinkCtrl*)FindWindow(id);
int siblingCollPaneID = 0;
siblingCollPaneID = removeLink->getSiblingCollPaneID();
metadataSetCollapsiblePane* cpWindow = (metadataSetCollapsiblePane*)FindWindow(siblingCollPaneID);
if (cpWindow != NULL)
{
wxWindow* cpPane = cpWindow->GetPane();
wxWindowList cpChildren = cpPane->GetChildren();
for (int i = 0; i < cpChildren.GetCount(); i++)
{
wxWindow* w = cpChildren[i];
if (w != NULL)
w->Destroy();
}
cpWindow->Destroy();
removeLink->Destroy();
wxSizer* cpContainer = cpWindow->GetContainingSizer();
m_metaDataControlsbox->Remove(cpContainer);
}
}