X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/52a07708c402e7b60a73abb6bae42838cf92c9f7..a06066343d670807825adcafebfa4fb8cfff5521:/src/msw/dialog.cpp diff --git a/src/msw/dialog.cpp b/src/msw/dialog.cpp index 658003fe30..4a0102db14 100644 --- a/src/msw/dialog.cpp +++ b/src/msw/dialog.cpp @@ -235,24 +235,26 @@ wxDialog::~wxDialog() // By default, pressing escape cancels the dialog void wxDialog::OnCharHook(wxKeyEvent& event) { - if (GetHWND()) - { - if (event.m_keyCode == WXK_ESCAPE) + if (GetHWND()) { - // Behaviour changed in 2.0: we'll send a Cancel message - // to the dialog instead of Close. - wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); - cancelEvent.SetEventObject( this ); - GetEventHandler()->ProcessEvent(cancelEvent); - - // ensure that there is another message for this window so the - // ShowModal loop will exit and won't get stuck in GetMessage(). - ::PostMessage(GetHwnd(), WM_NULL, 0, 0); - return; + // "Esc" works as an accelerator for the "Cancel" button, but it + // shouldn't close the dialog which doesn't have any cancel button + if ( (event.m_keyCode == WXK_ESCAPE) && FindWindow(wxID_CANCEL) ) + { + wxCommandEvent cancelEvent(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL); + cancelEvent.SetEventObject( this ); + GetEventHandler()->ProcessEvent(cancelEvent); + + // ensure that there is another message for this window so the + // ShowModal loop will exit and won't get stuck in GetMessage(). + ::PostMessage(GetHwnd(), WM_NULL, 0, 0); + + return; + } } - } - // We didn't process this event. - event.Skip(); + + // We didn't process this event. + event.Skip(); } // ---------------------------------------------------------------------------- @@ -419,8 +421,29 @@ bool wxDialog::Show(bool show) // Replacement for Show(TRUE) for modal dialogs - returns return code int wxDialog::ShowModal() { + // modal dialog needs a parent window, so try to find one + if ( !GetParent() ) + { + wxWindow *parent = wxTheApp->GetTopWindow(); + if ( parent && parent != this ) + { + // use it + m_parent = parent; + } + } + + wxWindowDisabler *wd = (wxWindowDisabler *)NULL; + if ( !GetParent() ) + { + // still no parent? make the dialog app modal by disabling all windows + wd = new wxWindowDisabler(this); + } + m_windowStyle |= wxDIALOG_MODAL; Show(TRUE); + + delete wd; + return GetReturnCode(); } @@ -521,6 +544,33 @@ long wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) switch ( message ) { + case WM_ACTIVATE: + switch ( LOWORD(wParam) ) + { + case WA_ACTIVE: + case WA_CLICKACTIVE: + if ( IsModalShowing() && GetParent() ) + { + // bring the owner window to top as the standard dialog + // boxes do + if ( !::SetWindowPos + ( + GetHwndOf(GetParent()), + GetHwnd(), + 0, 0, + 0, 0, + SWP_NOACTIVATE | + SWP_NOMOVE | + SWP_NOSIZE + ) ) + { + wxLogLastError("SetWindowPos(SWP_NOACTIVATE)"); + } + } + // fall through to process it normally as well + } + break; + case WM_CLOSE: // if we can't close, tell the system that we processed the // message - otherwise it would close us @@ -530,13 +580,28 @@ long wxDialog::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) case WM_SETCURSOR: // we want to override the busy cursor for modal dialogs: // typically, wxBeginBusyCursor() is called and then a modal dialog - // is shown, but the modal dialog shouldn't have this cursor - if ( wxIsBusy() ) + // is shown, but the modal dialog shouldn't have hourglass cursor + if ( IsModalShowing() && wxIsBusy() ) { - rc = TRUE; + // set our cursor for all windows (but see below) + wxCursor cursor = m_cursor; + if ( !cursor.Ok() ) + cursor = wxCURSOR_ARROW; + ::SetCursor(GetHcursorOf(cursor)); + + // in any case, stop here and don't let wxWindow process this + // message (it would set the busy cursor) processed = TRUE; + + // but return FALSE to tell the child window (if the event + // comes from one of them and not from ourselves) that it can + // set its own cursor if it has one: thus, standard controls + // (e.g. text ctrl) still have correct cursors in a dialog + // invoked while wxIsBusy() + rc = FALSE; } + break; } if ( !processed )