| 156 | } |
| 157 | |
| 158 | int FilterEvent(wxEvent& event) override |
| 159 | { |
| 160 | // Unguarded exception propagation may crash the program, at least |
| 161 | // on Mac while in the objective-C closure above |
| 162 | return GuardedCall< int > ( [&] { |
| 163 | // Quickly bail if this isn't something we want. |
| 164 | wxEventType type = event.GetEventType(); |
| 165 | if (type != wxEVT_CHAR_HOOK && type != wxEVT_KEY_UP) |
| 166 | { |
| 167 | return Event_Skip; |
| 168 | } |
| 169 | |
| 170 | wxKeyEvent key = static_cast<wxKeyEvent &>( event ); |
| 171 | |
| 172 | if ( !( KeyboardCapture::PreFilter::Call(key) ) ) |
| 173 | return Event_Skip; |
| 174 | |
| 175 | #ifdef __WXMAC__ |
| 176 | // Bugs 1329 and 2107 (Mac only) |
| 177 | // wxButton::SetDefault() alone doesn't cause correct event routing |
| 178 | // of key-down to the button when a text entry or combo has focus, |
| 179 | // but we can intercept wxEVT_CHAR_HOOK here and do it |
| 180 | if ( type == wxEVT_CHAR_HOOK && |
| 181 | key.GetKeyCode() == WXK_RETURN ) { |
| 182 | const auto focus = wxWindow::FindFocus(); |
| 183 | // Bug 2267 (Mac only): don't apply fix for 2107 when a text entry |
| 184 | // needs to allow multiple line input |
| 185 | const auto text = dynamic_cast<wxTextCtrl*>(focus); |
| 186 | if ( !(text && text->IsMultiLine()) ) { |
| 187 | if (auto top = |
| 188 | dynamic_cast< wxTopLevelWindow* >( |
| 189 | wxGetTopLevelParent( focus ) ) ) { |
| 190 | if ( auto button = |
| 191 | dynamic_cast<wxButton*>( top->GetDefaultItem() ) ) { |
| 192 | wxCommandEvent newEvent{ wxEVT_BUTTON, button->GetId() }; |
| 193 | newEvent.SetEventObject( button ); |
| 194 | button->GetEventHandler()->AddPendingEvent( newEvent ); |
| 195 | return Event_Processed; |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | #endif |
| 201 | |
| 202 | // Make a copy of the event and (possibly) make it look like a key down |
| 203 | // event. |
| 204 | if (type == wxEVT_CHAR_HOOK) |
| 205 | { |
| 206 | key.SetEventType(wxEVT_KEY_DOWN); |
| 207 | } |
| 208 | |
| 209 | // Give the capture handler first dibs at the event. |
| 210 | wxWindow *handler = KeyboardCapture::GetHandler(); |
| 211 | if (handler && HandleCapture(handler, key)) |
| 212 | { |
| 213 | return Event_Processed; |
| 214 | } |
| 215 |
nothing calls this directly
no test coverage detected