Audacity  3.0.3
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.
22 class wxTextCtrlWrapper final : public wxTextCtrl
23 {
24 public:
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 
61  bool IsReadOnly()
62  {
63  return mReadOnly;
64  }
65 
66  void SetReadOnly(bool readonly = true)
67  {
68  mReadOnly = readonly;
69  }
70 
71 private:
72  bool mReadOnly;
73 };
74 
75 #endif // __AUDACITY_WXTEXTCTRLWRAPPER__
wxTextCtrlWrapper::~wxTextCtrlWrapper
~wxTextCtrlWrapper()
Definition: wxTextCtrlWrapper.h:52
wxTextCtrlWrapper::wxTextCtrlWrapper
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)
Definition: wxTextCtrlWrapper.h:25
wxTextCtrlWrapper::mReadOnly
bool mReadOnly
Definition: wxTextCtrlWrapper.h:72
wxTextCtrlWrapper
Definition: wxTextCtrlWrapper.h:23
wxTextCtrlWrapper::AcceptsFocusFromKeyboard
virtual bool AcceptsFocusFromKeyboard() const override
Definition: wxTextCtrlWrapper.h:56
name
const TranslatableString name
Definition: Distortion.cpp:98
wxTextCtrlWrapper::SetReadOnly
void SetReadOnly(bool readonly=true)
Definition: wxTextCtrlWrapper.h:66
wxTextCtrlWrapper::IsReadOnly
bool IsReadOnly()
Definition: wxTextCtrlWrapper.h:61