Audacity 3.2.0
Classes | Typedefs | Functions | Variables
Journal::Events::anonymous_namespace{JournalEvents.cpp} Namespace Reference

Classes

struct  RegisteredEventType
 
struct  Type
 
struct  Watcher
 Singleton object listens to global wxEvent stream. More...
 

Typedefs

using Types = std::vector< Type >
 
using Code = Identifier
 
using ByTypeMap = std::map< wxEventType, const Type & >
 
using ByCodeMap = std::unordered_map< Code, const Type & >
 

Functions

static const TypesTypeCatalog ()
 
static const ByTypeMapByType ()
 
static const ByCodeMapByCode ()
 
wxString WindowEventName (const wxEvent &event)
 
std::optional< wxArrayStringExWindowEventSerialization (const wxEvent &event)
 
template<typename Event = wxCommandEvent, typename EventType >
static Type NullaryCommandType (EventType type, const wxString &code)
 
template<typename Event = wxCommandEvent, typename EventType >
static Type BooleanCommandType (EventType type, const wxString &code)
 
template<typename Event = wxCommandEvent, typename EventType >
static Type NumericalCommandType (EventType type, const wxString &code)
 
template<typename Event = wxCommandEvent, typename EventType >
static Type TextualCommandType (EventType type, const wxString &code)
 
void Initialize ()
 
void Watch ()
 

Variables

static bool sWatching { true }
 Whether the event filter is still watching events. More...
 
RegisteredInitializer initializer
 

Typedef Documentation

◆ ByCodeMap

using Journal::Events::anonymous_namespace{JournalEvents.cpp}::ByCodeMap = typedef std::unordered_map< Code, const Type & >

Definition at line 60 of file JournalEvents.cpp.

◆ ByTypeMap

using Journal::Events::anonymous_namespace{JournalEvents.cpp}::ByTypeMap = typedef std::map< wxEventType, const Type& >

Definition at line 56 of file JournalEvents.cpp.

◆ Code

using Journal::Events::anonymous_namespace{JournalEvents.cpp}::Code = typedef Identifier

Definition at line 53 of file JournalEvents.cpp.

◆ Types

using Journal::Events::anonymous_namespace{JournalEvents.cpp}::Types = typedef std::vector< Type >

Definition at line 41 of file JournalEvents.cpp.

Function Documentation

◆ BooleanCommandType()

template<typename Event = wxCommandEvent, typename EventType >
static Type Journal::Events::anonymous_namespace{JournalEvents.cpp}::BooleanCommandType ( EventType  type,
const wxString &  code 
)
static

Definition at line 211 of file JournalEvents.cpp.

211 {
212 // Writes a window identifier to the journal and a bool
213 const auto serialize =
214 []( const Event &event ) {
215 auto result = WindowEventSerialization( event );
216 if ( result )
217 result->push_back(
218 wxString::Format( L"%d", event.GetInt() ? 1 : 0 ) );
219 return result;
220 };
221
222 const auto deserialize =
223 []( wxEventType type, const wxArrayStringEx &components ) {
224 std::unique_ptr< Event > result;
225 int value;
226 if ( components.size() == 2 ) {
227 if ( auto pWindow = WindowPaths::FindByPath( components[0] ) ) {
228 if ( long longValue; components[1].ToLong( &longValue ) ) {
229 bool value = (longValue != 0);
230 result = std::make_unique< Event >(
231 type, pWindow->GetId() );
232 result->SetEventObject( pWindow );
233 result->SetInt( value );
234 // Also change the state of the control before the event is
235 // processed. This class handles the most common control
236 // types.
237 wxGenericValidator validator( &value );
238 validator.SetWindow( pWindow );
239 validator.TransferToWindow();
240 }
241 }
242 }
243 return result;
244 };
245
246 return Type{ type, code, serialize, deserialize };
247}
Extend wxArrayString with move operations and construction and insertion fromstd::initializer_list.
std::optional< wxArrayStringEx > WindowEventSerialization(const wxEvent &event)
wxWindow * FindByPath(const Path &path)

References Journal::WindowPaths::FindByPath(), and WindowEventSerialization().

Referenced by TypeCatalog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ByCode()

static const ByCodeMap & Journal::Events::anonymous_namespace{JournalEvents.cpp}::ByCode ( )
static

Definition at line 368 of file JournalEvents.cpp.

369{
370 static std::once_flag flag;
371 static ByCodeMap result;
372 std::call_once( flag, []{
373 for ( const auto &type : TypeCatalog() )
374 result.emplace( type.code, type );
375 } );
376 return result;
377}
static std::once_flag flag
std::unordered_map< Code, const Type & > ByCodeMap

References flag, and TypeCatalog().

Referenced by Journal::Events::anonymous_namespace{JournalEvents.cpp}::RegisteredEventType::DispatchEvent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ByType()

static const ByTypeMap & Journal::Events::anonymous_namespace{JournalEvents.cpp}::ByType ( )
static

Definition at line 357 of file JournalEvents.cpp.

358{
359 static std::once_flag flag;
360 static ByTypeMap result;
361 std::call_once( flag, []{
362 for ( const auto &type : TypeCatalog() )
363 result.emplace( type.type, type );
364 } );
365 return result;
366}
std::map< wxEventType, const Type & > ByTypeMap

References flag, and TypeCatalog().

Referenced by Journal::Events::anonymous_namespace{JournalEvents.cpp}::Watcher::FilterEvent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Initialize()

void Journal::Events::anonymous_namespace{JournalEvents.cpp}::Initialize ( )

Definition at line 438 of file JournalEvents.cpp.

439{
440 (void) TypeCatalog();
441}

References TypeCatalog().

Here is the call graph for this function:

◆ NullaryCommandType()

template<typename Event = wxCommandEvent, typename EventType >
static Type Journal::Events::anonymous_namespace{JournalEvents.cpp}::NullaryCommandType ( EventType  type,
const wxString &  code 
)
static

Definition at line 193 of file JournalEvents.cpp.

193 {
194 const auto deserialize =
195 []( wxEventType evtType, const wxArrayStringEx &components) {
196 std::unique_ptr< wxCommandEvent > result;
197 if ( components.size() == 1 ) {
198 if ( auto pWindow = WindowPaths::FindByPath( components[0] ) ) {
199 result = std::make_unique< wxCommandEvent >(
200 evtType, pWindow->GetId() );
201 result->SetEventObject( pWindow );
202 }
203 }
204 return result;
205 };
206
207 return Type{ type, code, WindowEventSerialization, deserialize };
208}

References Journal::WindowPaths::FindByPath(), and WindowEventSerialization().

Referenced by TypeCatalog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ NumericalCommandType()

template<typename Event = wxCommandEvent, typename EventType >
static Type Journal::Events::anonymous_namespace{JournalEvents.cpp}::NumericalCommandType ( EventType  type,
const wxString &  code 
)
static

Definition at line 250 of file JournalEvents.cpp.

250 {
251 // Writes a window identifier to the journal and an int
252 const auto serialize =
253 []( const Event &event ) {
254 auto result = WindowEventSerialization( event );
255 if ( result )
256 result->push_back( wxString::Format( L"%d", event.GetInt() ) );
257 return result;
258 };
259
260 const auto deserialize =
261 []( wxEventType type, const wxArrayStringEx &components ) {
262 std::unique_ptr< Event > result;
263 int value;
264 if ( components.size() == 2 ) {
265 if ( auto pWindow = WindowPaths::FindByPath( components[0] ) ) {
266 if ( long longValue;
267 components[1].ToLong( &longValue ) &&
268 longValue == (value = static_cast<int>(longValue) )
269 ) {
270 result = std::make_unique< Event >(
271 type, pWindow->GetId() );
272 result->SetEventObject( pWindow );
273 result->SetInt( value );
274 // Also change the state of the control before the event is
275 // processed. This class handles the most common control
276 // types.
277 wxGenericValidator validator( &value );
278 validator.SetWindow( pWindow );
279 validator.TransferToWindow();
280 }
281 }
282 }
283 return result;
284 };
285
286 return Type{ type, code, serialize, deserialize };
287}

References Journal::WindowPaths::FindByPath(), and WindowEventSerialization().

Referenced by TypeCatalog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TextualCommandType()

template<typename Event = wxCommandEvent, typename EventType >
static Type Journal::Events::anonymous_namespace{JournalEvents.cpp}::TextualCommandType ( EventType  type,
const wxString &  code 
)
static

Definition at line 290 of file JournalEvents.cpp.

290 {
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}

References Journal::WindowPaths::FindByPath(), and WindowEventSerialization().

Referenced by TypeCatalog().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TypeCatalog()

const Types & Journal::Events::anonymous_namespace{JournalEvents.cpp}::TypeCatalog ( )
static

Definition at line 332 of file JournalEvents.cpp.

333{
334 static Types result {
335 NullaryCommandType( wxEVT_BUTTON, "Press" ),
336 NullaryCommandType( wxEVT_COMBOBOX_DROPDOWN, "DropDown" ),
337 NullaryCommandType( wxEVT_COMBOBOX_CLOSEUP, "CloseUp" ),
338
339 BooleanCommandType( wxEVT_CHECKBOX, "Check" ),
340 BooleanCommandType( wxEVT_RADIOBUTTON, "Radio" ),
341 BooleanCommandType( wxEVT_RADIOBOX, "RadioBox" ),
342 BooleanCommandType( wxEVT_TOGGLEBUTTON, "Toggle" ),
343
344 NumericalCommandType( wxEVT_CHOICE, "Choose" ),
345 NumericalCommandType( wxEVT_SLIDER, "Slide" ),
346 NumericalCommandType<wxSpinEvent>( wxEVT_SPINCTRL, "Spin" ),
347 NumericalCommandType<wxSpinEvent>( wxEVT_SPIN_DOWN, "SpinUp" ),
348 NumericalCommandType<wxSpinEvent>( wxEVT_SPIN_UP, "SpinDown" ),
349
350 TextualCommandType( wxEVT_COMBOBOX, "Combo" ),
351 TextualCommandType( wxEVT_TEXT, "Text" ),
352 TextualCommandType( wxEVT_TEXT_ENTER, "FullText" ),
353 };
354 return result;
355}
static Type BooleanCommandType(EventType type, const wxString &code)
static Type NumericalCommandType(EventType type, const wxString &code)
static Type NullaryCommandType(EventType type, const wxString &code)
static Type TextualCommandType(EventType type, const wxString &code)

References BooleanCommandType(), NullaryCommandType(), NumericalCommandType(), and TextualCommandType().

Referenced by ByCode(), ByType(), and Initialize().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Watch()

void Journal::Events::anonymous_namespace{JournalEvents.cpp}::Watch ( )

Definition at line 443 of file JournalEvents.cpp.

444{
445 static Watcher instance;
446}
Singleton object listens to global wxEvent stream.

◆ WindowEventName()

wxString Journal::Events::anonymous_namespace{JournalEvents.cpp}::WindowEventName ( const wxEvent &  event)

Definition at line 174 of file JournalEvents.cpp.

175{
176 wxString windowName;
177 if ( auto pWindow = dynamic_cast< wxWindow * >( event.GetEventObject() ) )
178 windowName = WindowPaths::FindPath( *pWindow ).GET();
179 return windowName;
180}
const wxString & GET() const
Explicit conversion to wxString, meant to be ugly-looking and demanding of a comment why it's correct...
Definition: Identifier.h:66
Path FindPath(const wxWindow &window)

References Journal::WindowPaths::FindPath(), and Identifier::GET().

Referenced by WindowEventSerialization().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WindowEventSerialization()

std::optional< wxArrayStringEx > Journal::Events::anonymous_namespace{JournalEvents.cpp}::WindowEventSerialization ( const wxEvent &  event)

Definition at line 182 of file JournalEvents.cpp.

183{
184 std::optional< wxArrayStringEx > result;
185 if ( auto windowName = WindowEventName( event ); !windowName.empty() )
186 result.emplace( wxArrayStringEx{ windowName } );
187 else
189 return result;
190}
void FailedEventSerialization()

References Journal::Events::FailedEventSerialization(), and WindowEventName().

Referenced by BooleanCommandType(), NullaryCommandType(), NumericalCommandType(), and TextualCommandType().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ initializer

RegisteredInitializer Journal::Events::anonymous_namespace{JournalEvents.cpp}::initializer

◆ sWatching

bool Journal::Events::anonymous_namespace{JournalEvents.cpp}::sWatching { true }
static

Whether the event filter is still watching events.

Definition at line 72 of file JournalEvents.cpp.

Referenced by Journal::Events::FailedEventSerialization(), and Journal::Events::IsWatching().