Audacity 3.2.0
wxTextCtrlWrapper.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 wxTextCtrlWrapper.h
6
7 (Extracted from TimerRecordDialog.h)
8
9**********************************************************************/
10
11#ifndef __AUDACITY_WXTEXTCTRLWRAPPER__
12#define __AUDACITY_WXTEXTCTRLWRAPPER__
13
14
15
16#include <wx/textctrl.h>
17
18// MY: Class that inherits from the wxTextCtrl class.
19// We override AcceptsFocusFromKeyboard in order to add
20// the text controls to the Tab Order since wxTextCtrls
21// with the wxTE_READONLY style are normally skipped.
22class wxTextCtrlWrapper final : public wxTextCtrl
23{
24public:
25 wxTextCtrlWrapper(wxWindow * parent, wxWindowID id,
26 const wxString &value = {},
27 const wxPoint &pos = wxDefaultPosition,
28 const wxSize &size = wxDefaultSize,
29 long style = 0,
30 const wxValidator &validator = wxDefaultValidator,
31 const wxString &name = wxTextCtrlNameStr)
32 : wxTextCtrl(parent, id, value, pos, size, style, validator, name)
33 {
34 mReadOnly = false;
35
36 Bind(wxEVT_KEY_DOWN, [&](wxKeyEvent &event)
37 {
38 auto keyCode = event.GetKeyCode();
39 if (mReadOnly)
40 {
41 if (keyCode >= WXK_SPACE || keyCode == WXK_DELETE || keyCode == WXK_BACK)
42 {
43 event.Skip(false);
44 return;
45 }
46 }
47
48 event.Skip();
49 });
50 };
51
53 {
54 };
55
56 virtual bool AcceptsFocusFromKeyboard() const override
57 {
58 return true;
59 }
60
62 {
63 return mReadOnly;
64 }
65
66 void SetReadOnly(bool readonly = true)
67 {
68 mReadOnly = readonly;
69 }
70
71private:
73};
74
75#endif // __AUDACITY_WXTEXTCTRLWRAPPER__
const TranslatableString name
Definition: Distortion.cpp:82
wxTextCtrlWrapper(wxWindow *parent, wxWindowID id, const wxString &value={}, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxTextCtrlNameStr)
void SetReadOnly(bool readonly=true)
virtual bool AcceptsFocusFromKeyboard() const override