fixes for programmatically deleting the find/replace dialog
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@12481 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
		@@ -165,8 +165,8 @@ bool MyApp::OnInit()
 | 
				
			|||||||
  file_menu->Append(DIALOGS_BUSYINFO, "&Busy info dialog\tCtrl-B");
 | 
					  file_menu->Append(DIALOGS_BUSYINFO, "&Busy info dialog\tCtrl-B");
 | 
				
			||||||
#endif // wxUSE_BUSYINFO
 | 
					#endif // wxUSE_BUSYINFO
 | 
				
			||||||
#if wxUSE_FINDREPLDLG
 | 
					#if wxUSE_FINDREPLDLG
 | 
				
			||||||
  file_menu->Append(DIALOGS_FIND, "&Find dialog\tCtrl-F");
 | 
					  file_menu->Append(DIALOGS_FIND, "&Find dialog\tCtrl-F", "", TRUE);
 | 
				
			||||||
  file_menu->Append(DIALOGS_REPLACE, "Find and &replace dialog\tShift-Ctrl-F");
 | 
					  file_menu->Append(DIALOGS_REPLACE, "Find and &replace dialog\tShift-Ctrl-F", "", TRUE);
 | 
				
			||||||
#endif // wxUSE_FINDREPLDLG
 | 
					#endif // wxUSE_FINDREPLDLG
 | 
				
			||||||
  file_menu->AppendSeparator();
 | 
					  file_menu->AppendSeparator();
 | 
				
			||||||
  file_menu->Append(DIALOGS_MODAL, "Mo&dal dialog\tCtrl-D");
 | 
					  file_menu->Append(DIALOGS_MODAL, "Mo&dal dialog\tCtrl-D");
 | 
				
			||||||
@@ -199,6 +199,9 @@ MyFrame::MyFrame(wxWindow *parent,
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    m_dialog = (MyModelessDialog *)NULL;
 | 
					    m_dialog = (MyModelessDialog *)NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    m_dlgFind =
 | 
				
			||||||
 | 
					    m_dlgReplace = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    CreateStatusBar();
 | 
					    CreateStatusBar();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -658,27 +661,45 @@ void MyFrame::ShowBusyInfo(wxCommandEvent& WXUNUSED(event))
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) )
 | 
					void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    wxFindReplaceDialog *dialog = new wxFindReplaceDialog
 | 
					    if ( m_dlgReplace )
 | 
				
			||||||
                                      (
 | 
					    {
 | 
				
			||||||
                                        this,
 | 
					        delete m_dlgReplace;
 | 
				
			||||||
                                        &m_findData,
 | 
					        m_dlgReplace = NULL;
 | 
				
			||||||
                                        "Find and replace dialog",
 | 
					    }
 | 
				
			||||||
                                        wxFR_REPLACEDIALOG
 | 
					    else
 | 
				
			||||||
                                      );
 | 
					    {
 | 
				
			||||||
    dialog->Show(TRUE);
 | 
					        m_dlgReplace = new wxFindReplaceDialog
 | 
				
			||||||
 | 
					                           (
 | 
				
			||||||
 | 
					                            this,
 | 
				
			||||||
 | 
					                            &m_findData,
 | 
				
			||||||
 | 
					                            "Find and replace dialog",
 | 
				
			||||||
 | 
					                            wxFR_REPLACEDIALOG
 | 
				
			||||||
 | 
					                           );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        m_dlgReplace->Show(TRUE);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) )
 | 
					void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    wxFindReplaceDialog *dialog = new wxFindReplaceDialog
 | 
					    if ( m_dlgFind )
 | 
				
			||||||
                                      (
 | 
					    {
 | 
				
			||||||
                                        this,
 | 
					        delete m_dlgFind;
 | 
				
			||||||
                                        &m_findData,
 | 
					        m_dlgFind = NULL;
 | 
				
			||||||
                                        "Find dialog",
 | 
					    }
 | 
				
			||||||
                                        // just for testing
 | 
					    else
 | 
				
			||||||
                                        wxFR_NOWHOLEWORD
 | 
					    {
 | 
				
			||||||
                                      );
 | 
					        m_dlgFind = new wxFindReplaceDialog
 | 
				
			||||||
    dialog->Show(TRUE);
 | 
					                        (
 | 
				
			||||||
 | 
					                            this,
 | 
				
			||||||
 | 
					                            &m_findData,
 | 
				
			||||||
 | 
					                            "Find dialog",
 | 
				
			||||||
 | 
					                            // just for testing
 | 
				
			||||||
 | 
					                            wxFR_NOWHOLEWORD
 | 
				
			||||||
 | 
					                        );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        m_dlgFind->Show(TRUE);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static wxString DecodeFindDialogEventFlags(int flags)
 | 
					static wxString DecodeFindDialogEventFlags(int flags)
 | 
				
			||||||
@@ -714,9 +735,29 @@ void MyFrame::OnFindDialog(wxFindDialogEvent& event)
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
    else if ( type == wxEVT_COMMAND_FIND_CLOSE )
 | 
					    else if ( type == wxEVT_COMMAND_FIND_CLOSE )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        wxLogMessage(wxT("Find dialog is being closed."));
 | 
					        wxFindReplaceDialog *dlg = event.GetDialog();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        event.GetDialog()->Destroy();
 | 
					        const wxChar *txt;
 | 
				
			||||||
 | 
					        if ( dlg == m_dlgFind )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            txt = _T("Find");
 | 
				
			||||||
 | 
					            m_dlgFind = NULL;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else if ( dlg == m_dlgReplace )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            txt = _T("Replace");
 | 
				
			||||||
 | 
					            m_dlgReplace = NULL;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            txt = _T("Unknown");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            wxFAIL_MSG( _T("unexecpted event") );
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        wxLogMessage(wxT("%s dialog is being closed."), txt),
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        dlg->Destroy();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -100,6 +100,9 @@ private:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#if wxUSE_FINDREPLDLG
 | 
					#if wxUSE_FINDREPLDLG
 | 
				
			||||||
    wxFindReplaceData m_findData;
 | 
					    wxFindReplaceData m_findData;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    wxFindReplaceDialog *m_dlgFind,
 | 
				
			||||||
 | 
					                        *m_dlgReplace;
 | 
				
			||||||
#endif // wxUSE_FINDREPLDLG
 | 
					#endif // wxUSE_FINDREPLDLG
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    DECLARE_EVENT_TABLE()
 | 
					    DECLARE_EVENT_TABLE()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -81,6 +81,10 @@ public:
 | 
				
			|||||||
    // only for passing to ::FindText or ::ReplaceText
 | 
					    // only for passing to ::FindText or ::ReplaceText
 | 
				
			||||||
    FINDREPLACE *GetPtrFindReplace() { return &m_findReplace; }
 | 
					    FINDREPLACE *GetPtrFindReplace() { return &m_findReplace; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // set/query the "closed by user" flag
 | 
				
			||||||
 | 
					    void SetClosedByUser() { m_wasClosedByUser = TRUE; }
 | 
				
			||||||
 | 
					    bool WasClosedByUser() const { return m_wasClosedByUser; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
private:
 | 
					private:
 | 
				
			||||||
    void InitString(const wxString& str, LPTSTR *ppStr, WORD *pLen);
 | 
					    void InitString(const wxString& str, LPTSTR *ppStr, WORD *pLen);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -93,6 +97,9 @@ private:
 | 
				
			|||||||
    // the find replace data used by the dialog
 | 
					    // the find replace data used by the dialog
 | 
				
			||||||
    FINDREPLACE m_findReplace;
 | 
					    FINDREPLACE m_findReplace;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // TRUE if the user closed us, FALSE otherwise
 | 
				
			||||||
 | 
					    bool m_wasClosedByUser;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // registered Message for Dialog
 | 
					    // registered Message for Dialog
 | 
				
			||||||
    static UINT ms_msgFindDialog;
 | 
					    static UINT ms_msgFindDialog;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
@@ -124,6 +131,8 @@ wxFindReplaceDialogImpl::wxFindReplaceDialogImpl(wxFindReplaceDialog *dialog,
 | 
				
			|||||||
    m_hwndOwner = NULL;
 | 
					    m_hwndOwner = NULL;
 | 
				
			||||||
    m_oldParentWndProc = NULL;
 | 
					    m_oldParentWndProc = NULL;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    m_wasClosedByUser = FALSE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    wxZeroMemory(m_findReplace);
 | 
					    wxZeroMemory(m_findReplace);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // translate the flags: first the dialog creation flags
 | 
					    // translate the flags: first the dialog creation flags
 | 
				
			||||||
@@ -231,6 +240,11 @@ LRESULT APIENTRY wxFindReplaceWindowProc(HWND hwnd, WXUINT nMsg,
 | 
				
			|||||||
        bool replace = FALSE;
 | 
					        bool replace = FALSE;
 | 
				
			||||||
        if ( pFR->Flags & FR_DIALOGTERM )
 | 
					        if ( pFR->Flags & FR_DIALOGTERM )
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 | 
					            // we have to notify the dialog that it's being closed by user and
 | 
				
			||||||
 | 
					            // not deleted programmatically as it behaves differently in these
 | 
				
			||||||
 | 
					            // 2 cases
 | 
				
			||||||
 | 
					            dialog->GetImpl()->SetClosedByUser();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            evtType = wxEVT_COMMAND_FIND_CLOSE;
 | 
					            evtType = wxEVT_COMMAND_FIND_CLOSE;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        else if ( pFR->Flags & FR_FINDNEXT )
 | 
					        else if ( pFR->Flags & FR_FINDNEXT )
 | 
				
			||||||
@@ -338,13 +352,25 @@ wxFindReplaceDialog::wxFindReplaceDialog(wxWindow *parent,
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
wxFindReplaceDialog::~wxFindReplaceDialog()
 | 
					wxFindReplaceDialog::~wxFindReplaceDialog()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
 | 
					    // the dialog might have been already deleted if the user closed it
 | 
				
			||||||
 | 
					    // manually but in this case we should have got a notification about it and
 | 
				
			||||||
 | 
					    // the flagmust have been set
 | 
				
			||||||
 | 
					    if ( !m_impl->WasClosedByUser() )
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        // if it wasn't, delete the dialog ourselves
 | 
				
			||||||
 | 
					        if ( !::DestroyWindow(GetHwnd()) )
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            wxLogLastError(_T("DestroyWindow(find dialog)"));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // unsubclass the parent
 | 
					    // unsubclass the parent
 | 
				
			||||||
    delete m_impl;
 | 
					    delete m_impl;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // prevent the base class dtor from trying to hide us!
 | 
					    // prevent the base class dtor from trying to hide us!
 | 
				
			||||||
    m_isShown = FALSE;
 | 
					    m_isShown = FALSE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // and from destroying our window
 | 
					    // and from destroying our window [again]
 | 
				
			||||||
    m_hWnd = (WXHWND)NULL;
 | 
					    m_hWnd = (WXHWND)NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user