]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't handle "Return" key as "TAB" even when the default button is disabled.
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 11 Jul 2011 22:25:24 +0000 (22:25 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 11 Jul 2011 22:25:24 +0000 (22:25 +0000)
wxMSW used to handle VK_RETURN in the same way as VK_TAB if it wasn't consumed
by the default push button but this didn't correspond to the native platform
behaviour which considers pressing Return when the OK button is disabled an
error and audibly notifies the user about it.

Fix this by passing VK_RETURN to IsDialogMessage() if we don't translate it to
a button click.

Also add a possibility to test what happens when the default (or all)
button(s) in the dialog are disabled to the dialogs sample.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68227 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/dialogs/dialogs.cpp
samples/dialogs/dialogs.h
src/msw/window.cpp

index 1c020573f544381590927e8bea5c7178b383e7ee..335cc16ca2151b83340cdcac554f3cc6b237c410 100644 (file)
@@ -1769,10 +1769,15 @@ void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent& WXUNUSED(event))
 
 #define ID_CATCH_LISTBOX_DCLICK 100
 #define ID_LISTBOX              101
+#define ID_DISABLE_OK           102
+#define ID_DISABLE_CANCEL       103
 
 BEGIN_EVENT_TABLE(TestDefaultActionDialog, wxDialog)
     EVT_CHECKBOX(ID_CATCH_LISTBOX_DCLICK,    TestDefaultActionDialog::OnCatchListBoxDClick)
+    EVT_CHECKBOX(ID_DISABLE_OK,              TestDefaultActionDialog::OnDisableOK)
+    EVT_CHECKBOX(ID_DISABLE_CANCEL,          TestDefaultActionDialog::OnDisableCancel)
     EVT_LISTBOX_DCLICK(ID_LISTBOX,           TestDefaultActionDialog::OnListBoxDClick)
+    EVT_TEXT_ENTER(wxID_ANY,                 TestDefaultActionDialog::OnTextEnter)
 END_EVENT_TABLE()
 
 TestDefaultActionDialog::TestDefaultActionDialog( wxWindow *parent ) :
@@ -1801,6 +1806,9 @@ TestDefaultActionDialog::TestDefaultActionDialog( wxWindow *parent ) :
     grid_sizer->Add( new wxTextCtrl( this, -1, "", wxDefaultPosition, wxSize(80,-1), wxTE_PROCESS_ENTER ), 0, wxALIGN_CENTRE_VERTICAL );
     grid_sizer->Add( new wxStaticText( this, -1, "wxTextCtrl with wxTE_PROCESS_ENTER" ), 0, wxALIGN_CENTRE_VERTICAL );
 
+    grid_sizer->Add( new wxCheckBox(this, ID_DISABLE_OK, "Disable \"OK\""), 0, wxALIGN_CENTRE_VERTICAL );
+    grid_sizer->Add( new wxCheckBox(this, ID_DISABLE_CANCEL, "Disable \"Cancel\""), 0, wxALIGN_CENTRE_VERTICAL );
+
     main_sizer->Add( grid_sizer, 0, wxALL, 10 );
 
     wxSizer *button_sizer = CreateSeparatedButtonSizer( wxOK|wxCANCEL );
@@ -1810,6 +1818,16 @@ TestDefaultActionDialog::TestDefaultActionDialog( wxWindow *parent ) :
     SetSizerAndFit( main_sizer );
 }
 
+void TestDefaultActionDialog::OnDisableOK(wxCommandEvent& event)
+{
+    FindWindow(wxID_OK)->Enable(!event.IsChecked());
+}
+
+void TestDefaultActionDialog::OnDisableCancel(wxCommandEvent& event)
+{
+    FindWindow(wxID_CANCEL)->Enable(!event.IsChecked());
+}
+
 void TestDefaultActionDialog::OnListBoxDClick(wxCommandEvent& event)
 {
     event.Skip( !m_catchListBoxDClick );
@@ -1820,6 +1838,11 @@ void TestDefaultActionDialog::OnCatchListBoxDClick(wxCommandEvent& WXUNUSED(even
     m_catchListBoxDClick = !m_catchListBoxDClick;
 }
 
+void TestDefaultActionDialog::OnTextEnter(wxCommandEvent& event)
+{
+    wxLogMessage("Text \"%s\" entered.", event.GetString());
+}
+
 void MyFrame::OnTestDefaultActionDialog(wxCommandEvent& WXUNUSED(event))
 {
     TestDefaultActionDialog dialog( this );
index f70e173606cd6f58d9777a26331e352fcc5d7e7b..fbad49919a3137d8ce9e32fa31e7527711e69f50 100644 (file)
@@ -293,7 +293,10 @@ public:
     TestDefaultActionDialog( wxWindow *parent );
 
     void OnListBoxDClick(wxCommandEvent& event);
+    void OnDisableOK(wxCommandEvent& event);
+    void OnDisableCancel(wxCommandEvent& event);
     void OnCatchListBoxDClick(wxCommandEvent& event);
+    void OnTextEnter(wxCommandEvent& event);
 
 private:
     bool   m_catchListBoxDClick;
index cd72c3c1e6142973e44af94d5e824619d820ba8f..eee4ca18ad676b821db3820fea3c8ac4704eb122 100644 (file)
@@ -2403,8 +2403,6 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
                                 // emulate the button click
                                 btn = wxFindWinFromHandle(msg->hwnd);
                             }
-
-                            bProcess = false;
                         }
                         else // not a button itself, do we have default button?
                         {
@@ -2464,6 +2462,13 @@ bool wxWindowMSW::MSWProcessMessage(WXMSG* pMsg)
                             return true;
                         }
 
+                        // This "Return" key press won't be actually used for
+                        // navigation so don't generate wxNavigationKeyEvent
+                        // for it but still pass it to IsDialogMessage() as it
+                        // may handle it in some other way (e.g. by playing the
+                        // default error sound).
+                        bProcess = false;
+
 #endif // wxUSE_BUTTON
 
 #ifdef __WXWINCE__