file_menu->Append(DIALOGS_BUSYINFO, "&Busy info dialog\tCtrl-B");
#endif // wxUSE_BUSYINFO
#if wxUSE_FINDREPLDLG
- file_menu->Append(DIALOGS_FIND, "&Find dialog\tCtrl-F");
- file_menu->Append(DIALOGS_REPLACE, "Find and &replace dialog\tShift-Ctrl-F");
+ file_menu->Append(DIALOGS_FIND, "&Find dialog\tCtrl-F", "", TRUE);
+ file_menu->Append(DIALOGS_REPLACE, "Find and &replace dialog\tShift-Ctrl-F", "", TRUE);
#endif // wxUSE_FINDREPLDLG
file_menu->AppendSeparator();
file_menu->Append(DIALOGS_MODAL, "Mo&dal dialog\tCtrl-D");
{
m_dialog = (MyModelessDialog *)NULL;
+ m_dlgFind =
+ m_dlgReplace = NULL;
+
CreateStatusBar();
}
void MyFrame::ShowReplaceDialog( wxCommandEvent& WXUNUSED(event) )
{
- wxFindReplaceDialog *dialog = new wxFindReplaceDialog
- (
- this,
- &m_findData,
- "Find and replace dialog",
- wxFR_REPLACEDIALOG
- );
- dialog->Show(TRUE);
+ if ( m_dlgReplace )
+ {
+ delete m_dlgReplace;
+ m_dlgReplace = NULL;
+ }
+ else
+ {
+ m_dlgReplace = new wxFindReplaceDialog
+ (
+ this,
+ &m_findData,
+ "Find and replace dialog",
+ wxFR_REPLACEDIALOG
+ );
+
+ m_dlgReplace->Show(TRUE);
+ }
}
void MyFrame::ShowFindDialog( wxCommandEvent& WXUNUSED(event) )
{
- wxFindReplaceDialog *dialog = new wxFindReplaceDialog
- (
- this,
- &m_findData,
- "Find dialog",
- // just for testing
- wxFR_NOWHOLEWORD
- );
- dialog->Show(TRUE);
+ if ( m_dlgFind )
+ {
+ delete m_dlgFind;
+ m_dlgFind = NULL;
+ }
+ else
+ {
+ m_dlgFind = new wxFindReplaceDialog
+ (
+ this,
+ &m_findData,
+ "Find dialog",
+ // just for testing
+ wxFR_NOWHOLEWORD
+ );
+
+ m_dlgFind->Show(TRUE);
+ }
}
static wxString DecodeFindDialogEventFlags(int flags)
}
else if ( type == wxEVT_COMMAND_FIND_CLOSE )
{
- wxLogMessage(wxT("Find dialog is being closed."));
+ wxFindReplaceDialog *dlg = event.GetDialog();
+
+ 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),
- event.GetDialog()->Destroy();
+ dlg->Destroy();
}
else
{
#if wxUSE_FINDREPLDLG
wxFindReplaceData m_findData;
+
+ wxFindReplaceDialog *m_dlgFind,
+ *m_dlgReplace;
#endif // wxUSE_FINDREPLDLG
DECLARE_EVENT_TABLE()
// only for passing to ::FindText or ::ReplaceText
FINDREPLACE *GetPtrFindReplace() { return &m_findReplace; }
+ // set/query the "closed by user" flag
+ void SetClosedByUser() { m_wasClosedByUser = TRUE; }
+ bool WasClosedByUser() const { return m_wasClosedByUser; }
+
private:
void InitString(const wxString& str, LPTSTR *ppStr, WORD *pLen);
// the find replace data used by the dialog
FINDREPLACE m_findReplace;
+ // TRUE if the user closed us, FALSE otherwise
+ bool m_wasClosedByUser;
+
// registered Message for Dialog
static UINT ms_msgFindDialog;
};
m_hwndOwner = NULL;
m_oldParentWndProc = NULL;
+ m_wasClosedByUser = FALSE;
+
wxZeroMemory(m_findReplace);
// translate the flags: first the dialog creation flags
bool replace = FALSE;
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;
}
else if ( pFR->Flags & FR_FINDNEXT )
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
delete m_impl;
// prevent the base class dtor from trying to hide us!
m_isShown = FALSE;
- // and from destroying our window
+ // and from destroying our window [again]
m_hWnd = (WXHWND)NULL;
}