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#include <wx/textctrl.h>
15
16// MY: Class that inherits from the wxTextCtrl class.
17// We override AcceptsFocusFromKeyboard in order to add
18// the text controls to the Tab Order since wxTextCtrls
19// with the wxTE_READONLY style are normally skipped.
20class wxTextCtrlWrapper final : public wxTextCtrl
21{
22public:
23 wxTextCtrlWrapper(wxWindow * parent, wxWindowID id,
24 const wxString &value = {},
25 const wxPoint &pos = wxDefaultPosition,
26 const wxSize &size = wxDefaultSize,
27 long style = 0,
28 const wxValidator &validator = wxDefaultValidator,
29 const wxString &name = wxTextCtrlNameStr)
30 : wxTextCtrl(parent, id, value, pos, size, style, validator, name)
31 {
32 mReadOnly = false;
33
34 Bind(wxEVT_KEY_DOWN, [&](wxKeyEvent &event)
35 {
36 auto keyCode = event.GetKeyCode();
37 if (mReadOnly)
38 {
39 if (keyCode >= WXK_SPACE || keyCode == WXK_DELETE || keyCode == WXK_BACK)
40 {
41 event.Skip(false);
42 return;
43 }
44 }
45
46 event.Skip();
47 });
48 };
49
51 {
52 };
53
54 virtual bool AcceptsFocusFromKeyboard() const override
55 {
56 return true;
57 }
58
60 {
61 return mReadOnly;
62 }
63
64 void SetReadOnly(bool readonly = true)
65 {
66 mReadOnly = readonly;
67 }
68
69private:
71};
72
73#endif // __AUDACITY_WXTEXTCTRLWRAPPER__
wxString name
Definition: TagsEditor.cpp:166
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