-void wxDialog::DoShowModal()
-{
- wxCHECK_RET( !IsModalShowing(), _T("DoShowModal() called twice") );
- wxCHECK_RET( IsModal(), _T("can't DoShowModal() modeless dialog") );
-
- wxWindow *parent = GetParent();
-
- wxWindow* oldFocus = m_oldFocus;
-
- // We have to remember the HWND because we need to check
- // the HWND still exists (oldFocus can be garbage when the dialog
- // exits, if it has been destroyed)
- HWND hwndOldFocus = 0;
- if (oldFocus)
- hwndOldFocus = (HWND) oldFocus->GetHWND();
-
- // remember where the focus was
- if ( !oldFocus )
- {
- oldFocus = parent;
- if ( parent )
- hwndOldFocus = GetHwndOf(parent);
- }
-
- // enter the modal loop
- {
- wxDialogModalDataTiedPtr modalData(&m_modalData,
- new wxDialogModalData(this));
- modalData->RunLoop();
- }
-
- // and restore focus
- // Note that this code MUST NOT access the dialog object's data
- // in case the object has been deleted (which will be the case
- // for a modal dialog that has been destroyed before calling EndModal).
- if ( oldFocus && (oldFocus != this) && ::IsWindow(hwndOldFocus))
- {
- // This is likely to prove that the object still exists
- if (wxFindWinFromHandle((WXHWND) hwndOldFocus) == oldFocus)
- oldFocus->SetFocus();
- }
-}
-