1 #include "core/keymapper.hpp"
3 #include "plat-wxwidgets/common.hpp"
4 #include "plat-wxwidgets/keyentry.hpp"
6 #define S_DONT_CARE "Ignore"
7 #define S_RELEASED "Released"
8 #define S_PRESSED "Pressed"
10 wx_key_entry::wx_key_entry(wxWindow
* parent
)
11 : wxDialog(parent
, wxID_ANY
, wxT("Specify key"), wxDefaultPosition
, wxSize(-1, -1))
13 std::vector
<wxString
> keych
;
15 std::set
<std::string
> mods
= modifier::get_set();
16 std::set
<std::string
> keys
= keygroup::get_keys();
18 wxFlexGridSizer
* top_s
= new wxFlexGridSizer(2, 1, 0, 0);
21 wxFlexGridSizer
* t_s
= new wxFlexGridSizer(mods
.size() + 1, 3, 0, 0);
23 t_s
->Add(new wxStaticText(this, wxID_ANY
, towxstring(i
)), 0, wxGROW
);
25 t_s
->Add(m
.pressed
= new wxCheckBox(this, wxID_ANY
, wxT("Pressed")), 0, wxGROW
);
26 t_s
->Add(m
.unmasked
= new wxCheckBox(this, wxID_ANY
, wxT("Unmasked")), 0, wxGROW
);
29 m
.pressed
->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED
,
30 wxCommandEventHandler(wx_key_entry::on_change_setting
), NULL
, this);
31 m
.unmasked
->Connect(wxEVT_COMMAND_CHECKBOX_CLICKED
,
32 wxCommandEventHandler(wx_key_entry::on_change_setting
), NULL
, this);
35 keych
.push_back(towxstring(i
));
36 mainkey
= new labeledcombobox(t_s
, this, "Key", &keych
[0], keych
.size(), 0, true, this,
37 (wxObjectEventFunction
)(&wx_key_entry::on_change_setting
));
38 t_s
->Add(new wxStaticText(this, wxID_ANY
, wxT("")), 0, wxGROW
);
41 wxBoxSizer
* pbutton_s
= new wxBoxSizer(wxHORIZONTAL
);
42 pbutton_s
->AddStretchSpacer();
43 pbutton_s
->Add(ok
= new wxButton(this, wxID_OK
, wxT("OK")), 0, wxGROW
);
44 pbutton_s
->Add(cancel
= new wxButton(this, wxID_CANCEL
, wxT("Cancel")), 0, wxGROW
);
45 ok
->Connect(wxEVT_COMMAND_BUTTON_CLICKED
,
46 wxCommandEventHandler(wx_key_entry::on_ok
), NULL
, this);
47 cancel
->Connect(wxEVT_COMMAND_BUTTON_CLICKED
,
48 wxCommandEventHandler(wx_key_entry::on_cancel
), NULL
, this);
49 top_s
->Add(pbutton_s
, 0, wxGROW
);
51 t_s
->SetSizeHints(this);
52 top_s
->SetSizeHints(this);
56 #define TMPFLAG_UNMASKED 65
57 #define TMPFLAG_UNMASKED_LINK_CHILD 2
58 #define TMPFLAG_UNMASKED_LINK_PARENT 68
59 #define TMPFLAG_PRESSED 8
60 #define TMPFLAG_PRESSED_LINK_CHILD 16
61 #define TMPFLAG_PRESSED_LINK_PARENT 32
63 void wx_key_entry::on_change_setting(wxCommandEvent
& e
)
65 for(auto& i
: modifiers
)
66 i
.second
.tmpflags
= 0;
67 for(auto& i
: modifiers
) {
70 m
= &modifier::lookup(i
.first
);
72 i
.second
.pressed
->Disable();
73 i
.second
.unmasked
->Disable();
76 std::string j
= m
->linked_name();
77 if(i
.second
.unmasked
->GetValue())
78 i
.second
.tmpflags
|= TMPFLAG_UNMASKED
;
80 if(modifiers
[j
].unmasked
->GetValue())
81 i
.second
.tmpflags
|= TMPFLAG_UNMASKED_LINK_PARENT
;
82 if(i
.second
.unmasked
->GetValue())
83 modifiers
[j
].tmpflags
|= TMPFLAG_UNMASKED_LINK_CHILD
;
85 if(i
.second
.pressed
->GetValue())
86 i
.second
.tmpflags
|= TMPFLAG_PRESSED
;
88 if(modifiers
[j
].pressed
->GetValue())
89 i
.second
.tmpflags
|= TMPFLAG_PRESSED_LINK_PARENT
;
90 if(i
.second
.pressed
->GetValue())
91 modifiers
[j
].tmpflags
|= TMPFLAG_PRESSED_LINK_CHILD
;
94 for(auto& i
: modifiers
) {
95 //Unmasked is to be enabled if neither unmasked link flag is set.
96 if(i
.second
.tmpflags
& ((TMPFLAG_UNMASKED_LINK_CHILD
| TMPFLAG_UNMASKED_LINK_PARENT
) & ~64)) {
97 i
.second
.unmasked
->SetValue(false);
98 i
.second
.unmasked
->Disable();
100 i
.second
.unmasked
->Enable();
101 //Pressed is to be enabled if:
102 //- This modifier is unmasked or parent is unmasked.
103 //- Parent nor child is not pressed.
104 if(((i
.second
.tmpflags
& (TMPFLAG_UNMASKED
| TMPFLAG_UNMASKED_LINK_PARENT
| TMPFLAG_PRESSED_LINK_CHILD
|
105 TMPFLAG_PRESSED_LINK_PARENT
)) & 112) == 64)
106 i
.second
.pressed
->Enable();
108 i
.second
.pressed
->SetValue(false);
109 i
.second
.pressed
->Disable();
114 void wx_key_entry::on_ok(wxCommandEvent
& e
)
119 void wx_key_entry::on_cancel(wxCommandEvent
& e
)
121 EndModal(wxID_CANCEL
);
124 std::string
wx_key_entry::getkey()
129 for(auto i
: modifiers
) {
130 if(i
.second
.pressed
->GetValue()) {
139 for(auto i
: modifiers
) {
140 if(i
.second
.unmasked
->GetValue()) {
147 x
= x
+ "|" + mainkey
->get_choice();