| 288 | |
| 289 | template<typename Event = wxCommandEvent, typename EventType > |
| 290 | static Type TextualCommandType( EventType type, const wxString &code ){ |
| 291 | // Writes a window identifier to the journal and a string |
| 292 | const auto serialize = |
| 293 | []( const Event &event ) { |
| 294 | auto result = WindowEventSerialization( event ); |
| 295 | if ( result ) |
| 296 | result->push_back( event.GetString() ); |
| 297 | return result; |
| 298 | }; |
| 299 | |
| 300 | const auto deserialize = |
| 301 | []( wxEventType type, const wxArrayStringEx &components ) { |
| 302 | std::unique_ptr< Event > result; |
| 303 | if ( components.size() == 2 ) { |
| 304 | if ( auto pWindow = WindowPaths::FindByPath( components[0] ) ) { |
| 305 | auto value = components[1]; |
| 306 | result = std::make_unique< Event >( |
| 307 | type, pWindow->GetId() ); |
| 308 | result->SetEventObject( pWindow ); |
| 309 | result->SetString( value ); |
| 310 | // Also change the state of the control before the event is |
| 311 | // processed. |
| 312 | if ( auto pCtrl = dynamic_cast<wxTextEntry*>( pWindow ) ) { |
| 313 | // Generic validator calls the SetValue() member function, |
| 314 | // which generates an event for this type of control, but we |
| 315 | // don't want that. So use ChangeValue() instead |
| 316 | pCtrl->ChangeValue( value ); |
| 317 | } |
| 318 | else { |
| 319 | // This class handles the most common control types. |
| 320 | wxGenericValidator validator( &value ); |
| 321 | validator.SetWindow( pWindow ); |
| 322 | validator.TransferToWindow(); |
| 323 | } |
| 324 | } |
| 325 | } |
| 326 | return result; |
| 327 | }; |
| 328 | |
| 329 | return Type{ type, code, serialize, deserialize }; |
| 330 | } |
| 331 | |
| 332 | const Types &TypeCatalog() |
| 333 | { |
no test coverage detected