Search code examples
c++wxwidgets

How to create one instance of a frame at a time


Im using wxWidgets with my c++ application.

I have a wxGrid setup in which users can double-click on a cell and that will create a new window with another grid.

Im having an issue with closing and reopening the new window with grid.

void FeatureList::mouseDClick(wxGridEvent& event)
{
int n_row, n_col;
n_row = event.GetRow();
n_col = 0;

m_sCellValue = grid->GetCellValue(n_row, n_col); 

if ( frame == NULL ) // If frame is closed
{
    CreateCrackBoxFrame(m_sCellValue);
}
else{
    frame->Raise();  // otherwise bring it to the front.
}
}

void FeatureList::CreateCrackBoxFrame(wxString m_sCellValue)
{
frame = new CrackBoxFrame(m_pvFeatures, m_sCellValue, m_bDisplayInMetric);
frame->Show(true);
}

CrackBoxFrame::CrackBoxFrame(vector<Feature> *pvFeatures, wxString CellValue, 
bool bDisplayInMetric)
: wxFrame(NULL, wxID_ANY, wxT("CrackBoxes"),wxDefaultPosition, wxSize(725, 
400))
{
 }

If i close the new window, and click on another cell my program crashes


Solution

  • For that you have couple of options:

    1. Keep the vector of lines and when the line in the grid is clicked, check if the appropriate line is clicked from the vector and allow the event to go only if it was not clicked.

    2. Disable the line after the click has been processed and don't let the second one go thru.

    3. Add the checkbox on every line in the grid and check it on the first click. On the subsequent ones - check if the value is not checked.

    You choose...

    Thank you.


    EDIT:

    void FeatureList::CreateCrackBoxFrame(wxString m_sCellValue)
    {
        frame = new CrackBoxFrame(m_pvFeatures, m_sCellValue, m_bDisplayInMetric);
        frame->Show(true);
        frame->Bind( wxEVT_CLOSE, &FeatureList::OnCrackBoxClose, this );
    }