//------------------------------------------------------------------------------ // void OnClose(wxCloseEvent &event) //------------------------------------------------------------------------------ void GmatMdiChildFrame::OnClose(wxCloseEvent &event) { #ifdef DEBUG_CLOSE MessageInterface::ShowMessage ("GmatMdiChildFrame::OnClose() entered, mDirty=%d, mOverrideDirty=%d\n", mDirty, mOverrideDirty); #endif SetFocus(); mCanClose = true; // We don't want to show duplicate save message, so check for override dirty flag if (mOverrideDirty) { #ifdef __USE_STC_EDITOR__ if (theEditor) { if (theEditor->IsModified()) mDirty = true; else mDirty = false; } #else if (theScriptTextCtrl) { if (theScriptTextCtrl->IsModified()) mDirty = true; else mDirty = false; } #endif } // check if window is dirty? if (mDirty) { #ifdef DEBUG_CLOSE MessageInterface::ShowMessage (" Panel has been changed, show exit confirm message\n"); #endif if ( wxMessageBox(_T("There were changes made to \"" + GetTitle() + "\" panel" " which will be lost on Close. \nDo you want to close anyway?"), _T("Please Confirm Close"), wxICON_QUESTION | wxYES_NO) != wxYES ) { event.Veto(); mCanClose = false; #ifdef DEBUG_CLOSE MessageInterface::ShowMessage ("GmatMdiChildFrame::OnClose() exiting, close event was vetoed\n"); #endif return; } } else { #ifdef DEBUG_CLOSE MessageInterface::ShowMessage(" No changes made to panel\n"); #endif } #ifdef DEBUG_CLOSE MessageInterface::ShowMessage("GmatMdiChildFrame::OnClose() Saving position and size\n"); #endif SaveChildPositionAndSize(); GmatSavePanel* panel = ((GmatSavePanel*) GetAssociatedWindow()); #ifdef DEBUG_CLOSE MessageInterface::ShowMessage(" Associated window = <%p>\n", panel); #endif if (panel != NULL) { if (!panel->UpdateStatusOnClose()) { event.Veto(); mCanClose = false; #ifdef DEBUG_CLOSE MessageInterface::ShowMessage ("GmatMdiChildFrame::OnClose() leaving, window cannot be closed\n"); #endif return; } } // Remove from the list of mdi children, but do not delete output child in the // GmatMainFrame::RemoveChild() (2012.01.17 LOJ: This fixes crash when file->exit) #ifdef DEBUG_CLOSE MessageInterface::ShowMessage ("GmatMdiChildFrame::OnClose() calling GetMainFrame::RemoveChild()\n"); #endif GmatAppData::Instance()->GetMainFrame()->RemoveChild(GetName(), mItemType, mCanBeDeleted); // Removed wxSafeYield() : The window should not be deleted, instead ->Destroy() should be called // which adds the window delete to an idle queue. Calling safe yield here causes the idle queue to run // too early. I believe the yield was added here previously to work around a bug that was caused by calling delete on the window. // wxSafeYield(); // This causes crash on exit with Red X/button on XP and Mac - wcs 2013.03.20 // event.Skip(); #ifdef DEBUG_CLOSE MessageInterface::ShowMessage("GmatMdiChildFrame::OnClose() leaving\n"); #endif }
//------------------------------------------------------------------------------ // void OnClose(wxCloseEvent &event) //------------------------------------------------------------------------------ void GmatMdiChildFrame::OnClose(wxCloseEvent &event) { #ifdef DEBUG_CLOSE MessageInterface::ShowMessage (wxT("GmatMdiChildFrame::OnClose() entered, mDirty=%d, mOverrideDirty=%d\n"), mDirty, mOverrideDirty); #endif mCanClose = true; // We don't want to show duplicate save message, so check for override dirty flag if (mOverrideDirty) { #ifdef __USE_STC_EDITOR__ if (theEditor) { if (theEditor->IsModified()) mDirty = true; else mDirty = false; } #else if (theScriptTextCtrl) { if (theScriptTextCtrl->IsModified()) mDirty = true; else mDirty = false; } #endif } // check if window is dirty? if (mDirty) { #ifdef DEBUG_CLOSE MessageInterface::ShowMessage (wxT(" Panel has been changed, show exit confirm message\n")); #endif if ( wxMessageBox(wxT("There were changes made to \"" + GetTitle() + "\" panel") wxT(" which will be lost on Close. \nDo you want to close anyway?"), wxT("Please Confirm Close"), wxICON_QUESTION | wxYES_NO) != wxYES ) { event.Veto(); mCanClose = false; #ifdef DEBUG_CLOSE MessageInterface::ShowMessage (wxT("GmatMdiChildFrame::OnClose() exiting, close event was vetoed\n")); #endif return; } } else { #ifdef DEBUG_CLOSE MessageInterface::ShowMessage(wxT(" No changes made to panel\n")); #endif } #ifdef DEBUG_CLOSE MessageInterface::ShowMessage (wxT("GmatMdiChildFrame::OnClose() will call GmatMainFrame to remove child and exit\n")); #endif SaveChildPositionAndSize(); // remove from list of frames GmatAppData::Instance()->GetMainFrame()->RemoveChild(GetName(), mItemType); wxSafeYield(); }