1 #include "keyentry.hpp"
3 #include "keymapper.hpp"
5 #define S_DONT_CARE "Ignore"
6 #define S_RELEASED "Released"
7 #define S_PRESSED "Pressed"
9 wx_key_entry::wx_key_entry(wxWindow
* parent
)
10 : wxDialog(parent
, wxID_ANY
, wxT("Specify key"), wxDefaultPosition
, wxSize(-1, -1))
12 std::vector
<wxString
> keych
;
14 std::set
<std::string
> mods
= modifier::get_set();
15 std::set
<std::string
> keys
= keygroup::get_keys();
17 wxFlexGridSizer
* top_s
= new wxFlexGridSizer(2, 1, 0, 0);
20 wxFlexGridSizer
* t_s
= new wxFlexGridSizer(mods
.size() + 1, 3, 0, 0);
22 t_s
->Add(new wxStaticText(this, wxID_ANY
, towxstring(i
)), 0, wxGROW
);
24 t_s
->Add(m
.pressed
= new wxCheckBox(this, wxID_ANY
, wxT("Pressed")), 0, wxGROW
);
25 t_s
->Add(m
.unmasked
= new wxCheckBox(this, wxID_ANY
, wxT("Unmasked")), 0, wxGROW
);
28 m
.pressed
->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED
,
29 wxCommandEventHandler(wx_key_entry::on_change_setting
), NULL
, this);
30 m
.unmasked
->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED
,
31 wxCommandEventHandler(wx_key_entry::on_change_setting
), NULL
, this);
34 keych
.push_back(towxstring(i
));
35 mainkey
= new labeledcombobox(t_s
, this, "Key", &keych
[0], keych
.size(), 0, true, this,
36 (wxObjectEventFunction
)(&wx_key_entry::on_change_setting
));
37 t_s
->Add(new wxStaticText(this, wxID_ANY
, wxT("")), 0, wxGROW
);
40 wxBoxSizer
* pbutton_s
= new wxBoxSizer(wxHORIZONTAL
);
41 pbutton_s
->AddStretchSpacer();
42 pbutton_s
->Add(ok
= new wxButton(this, wxID_OK
, wxT("OK")), 0, wxGROW
);
43 pbutton_s
->Add(cancel
= new wxButton(this, wxID_CANCEL
, wxT("Cancel")), 0, wxGROW
);
44 ok
->Connect(wxEVT_COMMAND_BUTTON_CLICKED
,
45 wxCommandEventHandler(wx_key_entry::on_ok
), NULL
, this);
46 cancel
->Connect(wxEVT_COMMAND_BUTTON_CLICKED
,
47 wxCommandEventHandler(wx_key_entry::on_cancel
), NULL
, this);
48 top_s
->Add(pbutton_s
, 0, wxGROW
);
50 t_s
->SetSizeHints(this);
51 top_s
->SetSizeHints(this);
55 #define TMPFLAG_UNMASKED 65
56 #define TMPFLAG_UNMASKED_LINK_CHILD 2
57 #define TMPFLAG_UNMASKED_LINK_PARENT 68
58 #define TMPFLAG_PRESSED 8
59 #define TMPFLAG_PRESSED_LINK_CHILD 16
60 #define TMPFLAG_PRESSED_LINK_PARENT 32
62 void wx_key_entry::on_change_setting(wxCommandEvent
& e
)
64 for(auto& i
: modifiers
)
65 i
.second
.tmpflags
= 0;
66 for(auto& i
: modifiers
) {
69 m
= &modifier::lookup(i
.first
);
71 i
.second
.pressed
->Disable();
72 i
.second
.unmasked
->Disable();
75 std::string j
= m
->linked_name();
76 if(i
.second
.unmasked
->GetValue())
77 i
.second
.tmpflags
|= TMPFLAG_UNMASKED
;
79 if(modifiers
[j
].unmasked
->GetValue())
80 i
.second
.tmpflags
|= TMPFLAG_UNMASKED_LINK_PARENT
;
81 if(i
.second
.unmasked
->GetValue())
82 modifiers
[j
].tmpflags
|= TMPFLAG_UNMASKED_LINK_CHILD
;
84 if(i
.second
.pressed
->GetValue())
85 i
.second
.tmpflags
|= TMPFLAG_PRESSED
;
87 if(modifiers
[j
].pressed
->GetValue())
88 i
.second
.tmpflags
|= TMPFLAG_PRESSED_LINK_PARENT
;
89 if(i
.second
.pressed
->GetValue())
90 modifiers
[j
].tmpflags
|= TMPFLAG_PRESSED_LINK_CHILD
;
93 for(auto& i
: modifiers
) {
94 //Unmasked is to be enabled if neither unmasked link flag is set.
95 if(i
.second
.tmpflags
& ((TMPFLAG_UNMASKED_LINK_CHILD
| TMPFLAG_UNMASKED_LINK_PARENT
) & ~64)) {
96 i
.second
.unmasked
->SetValue(false);
97 i
.second
.unmasked
->Disable();
99 i
.second
.unmasked
->Enable();
100 //Pressed is to be enabled if:
101 //- This modifier is unmasked or parent is unmasked.
102 //- Parent nor child is not pressed.
103 if(((i
.second
.tmpflags
& (TMPFLAG_UNMASKED
| TMPFLAG_UNMASKED_LINK_PARENT
| TMPFLAG_PRESSED_LINK_CHILD
|
104 TMPFLAG_PRESSED_LINK_PARENT
)) & 112) == 64)
105 i
.second
.pressed
->Enable();
107 i
.second
.pressed
->SetValue(false);
108 i
.second
.pressed
->Disable();
113 void wx_key_entry::on_ok(wxCommandEvent
& e
)
118 void wx_key_entry::on_cancel(wxCommandEvent
& e
)
120 EndModal(wxID_CANCEL
);
123 std::string
wx_key_entry::getkey()
128 for(auto i
: modifiers
) {
129 if(i
.second
.pressed
->GetValue()) {
138 for(auto i
: modifiers
) {
139 if(i
.second
.unmasked
->GetValue()) {
146 x
= x
+ "|" + mainkey
->get_choice();