- // find the top level window which had focus before - we will restore
- // focus to it later
- m_hwndOldFocus = 0;
- for ( HWND hwnd = ::GetFocus(); hwnd; hwnd = ::GetParent(hwnd) )
- {
- m_hwndOldFocus = (WXHWND)hwnd;
- }
-
- if (m_modalShowing)
- {
- BringWindowToTop((HWND) GetHWND());
- return TRUE;
- }
-
- m_modalShowing = TRUE;
- wxNode *node = wxModalDialogs.First();
- while (node)
- {
- wxDialog *box = (wxDialog *)node->Data();
- if (box != this)
- ::EnableWindow((HWND) box->GetHWND(), FALSE);
- node = node->Next();
- }
-
- // if we don't do it, some window might be deleted while we have pointers
- // to them in our disabledWindows list and the program will crash when it
- // will try to reenable them after the modal dialog end
- wxTheApp->DeletePendingObjects();
- wxList disabledWindows;
-
- node = wxModelessWindows.First();
- while (node)
- {
- wxWindow *win = (wxWindow *)node->Data();
- if (::IsWindowEnabled((HWND) win->GetHWND()))
- {
- ::EnableWindow((HWND) win->GetHWND(), FALSE);
- disabledWindows.Append(win);
- }
- node = node->Next();
- }
-
- ShowWindow((HWND) GetHWND(), SW_SHOW);
- EnableWindow((HWND) GetHWND(), TRUE);
- BringWindowToTop((HWND) GetHWND());
-
- if ( !wxModalDialogs.Find(this) )
- wxModalDialogs.Append(this);
-
- MSG msg;
- // Must test whether this dialog still exists: we may not process
- // a message before the deletion.
- while (wxModalDialogs.Find(this) && m_modalShowing && GetMessage(&msg, NULL, 0, 0))
- {
- if ( m_acceleratorTable.Ok() &&
- ::TranslateAccelerator((HWND)GetHWND(),
- (HACCEL)m_acceleratorTable.GetHACCEL(),
- &msg) )
+ // if we had disabled other app windows, reenable them back now because
+ // if they stay disabled Windows will activate another window (one
+ // which is enabled, anyhow) and we will lose activation
+ if ( m_windowDisabler )