workaround wX 3.1+ key accel string parsing bug
In wX 3.1+ the behavior of wxAcceleratorEntry::ToString() and wxAcceleratorEntry::FromString() has changed and the resulting string can no longer round-trip through these methods. Use a lookup table based on an internal data structure from the wX source code to translate the "display name" of some keys to the regular "name" as a workaround for now. This allows at least the default keybindings to work and not throw an error on startup. TODO: standalone modifiers as game keys are still broken.
This commit is contained in:
parent
d5020b905c
commit
a60d24e91a
|
@ -100,6 +100,11 @@ wxString wxKeyTextCtrl::ToString(int mod, int key)
|
||||||
s.append(_("CTRL"));
|
s.append(_("CTRL"));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// this is the cmd key on macs
|
||||||
|
case WXK_RAW_CONTROL:
|
||||||
|
s.append(_("RAWCTRL"));
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
s.append((wxChar)key);
|
s.append((wxChar)key);
|
||||||
}
|
}
|
||||||
|
@ -119,6 +124,21 @@ wxString wxKeyTextCtrl::ToString(int mod, int key)
|
||||||
// bad key combo; probably also generates an assertion in wx
|
// bad key combo; probably also generates an assertion in wx
|
||||||
return wxEmptyString;
|
return wxEmptyString;
|
||||||
|
|
||||||
|
// hacky workaround for bug in wx 3.1+ not parsing key display names, or
|
||||||
|
// parsing modifiers that aren't a combo correctly
|
||||||
|
s.MakeUpper();
|
||||||
|
|
||||||
|
int keys_el_size = sizeof(keys_with_display_names)/sizeof(keys_with_display_names[0]);
|
||||||
|
|
||||||
|
for (int i = 0; i < keys_el_size; i++) {
|
||||||
|
wxString name(keys_with_display_names[i].name);
|
||||||
|
wxString display_name(keys_with_display_names[i].display_name);
|
||||||
|
name.MakeUpper();
|
||||||
|
display_name.MakeUpper();
|
||||||
|
|
||||||
|
s.Replace(display_name, name, true);
|
||||||
|
}
|
||||||
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,10 +213,18 @@ bool wxKeyTextCtrl::ParseString(const wxChar* s, int len, int& mod, int& key)
|
||||||
chk_str(wxT("SHIFT"), WXK_SHIFT);
|
chk_str(wxT("SHIFT"), WXK_SHIFT);
|
||||||
chk_str(wxT("CTRL"), WXK_CONTROL);
|
chk_str(wxT("CTRL"), WXK_CONTROL);
|
||||||
chk_str(wxT("CONTROL"), WXK_CONTROL);
|
chk_str(wxT("CONTROL"), WXK_CONTROL);
|
||||||
|
chk_str(wxT("RAWCTRL"), WXK_CONTROL);
|
||||||
|
chk_str(wxT("RAW_CTRL"), WXK_RAW_CONTROL);
|
||||||
|
chk_str(wxT("RAWCONTROL"), WXK_RAW_CONTROL);
|
||||||
|
chk_str(wxT("RAW_CONTROL"), WXK_RAW_CONTROL);
|
||||||
chk_str(_("ALT"), WXK_ALT);
|
chk_str(_("ALT"), WXK_ALT);
|
||||||
chk_str(_("SHIFT"), WXK_SHIFT);
|
chk_str(_("SHIFT"), WXK_SHIFT);
|
||||||
chk_str(_("CTRL"), WXK_CONTROL);
|
chk_str(_("CTRL"), WXK_CONTROL);
|
||||||
chk_str(_("CONTROL"), WXK_CONTROL);
|
chk_str(_("CONTROL"), WXK_CONTROL);
|
||||||
|
chk_str(_("RAWCTRL"), WXK_RAW_CONTROL);
|
||||||
|
chk_str(_("RAW_CTRL"), WXK_RAW_CONTROL);
|
||||||
|
chk_str(_("RAWCONTROL"), WXK_RAW_CONTROL);
|
||||||
|
chk_str(_("RAW_CONTROL"), WXK_RAW_CONTROL);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -108,4 +108,42 @@ protected:
|
||||||
DECLARE_CLASS(wxKeyValidator)
|
DECLARE_CLASS(wxKeyValidator)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const struct {
|
||||||
|
wxKeyCode code;
|
||||||
|
const char *name;
|
||||||
|
const char *display_name;
|
||||||
|
} keys_with_display_names[] = {
|
||||||
|
{ WXK_BACK, wxTRANSLATE("Back"), wxTRANSLATE("Backspace") },
|
||||||
|
{ WXK_PAGEUP, wxTRANSLATE("PageUp"), wxTRANSLATE("Page Up") },
|
||||||
|
{ WXK_PAGEDOWN, wxTRANSLATE("PageDown"), wxTRANSLATE("Page Down") },
|
||||||
|
{ WXK_NUMLOCK, wxTRANSLATE("Num_lock"), wxTRANSLATE("Num Lock") },
|
||||||
|
{ WXK_SCROLL, wxTRANSLATE("Scroll_lock"), wxTRANSLATE("Scroll Lock") },
|
||||||
|
{ WXK_NUMPAD_SPACE, wxTRANSLATE("KP_Space"), wxTRANSLATE("Num Space") },
|
||||||
|
{ WXK_NUMPAD_TAB, wxTRANSLATE("KP_Tab"), wxTRANSLATE("Num Tab") },
|
||||||
|
{ WXK_NUMPAD_ENTER, wxTRANSLATE("KP_Enter"), wxTRANSLATE("Num Enter") },
|
||||||
|
{ WXK_NUMPAD_HOME, wxTRANSLATE("KP_Home"), wxTRANSLATE("Num Home") },
|
||||||
|
{ WXK_NUMPAD_LEFT, wxTRANSLATE("KP_Left"), wxTRANSLATE("Num left") },
|
||||||
|
{ WXK_NUMPAD_UP, wxTRANSLATE("KP_Up"), wxTRANSLATE("Num Up") },
|
||||||
|
{ WXK_NUMPAD_RIGHT, wxTRANSLATE("KP_Right"), wxTRANSLATE("Num Right") },
|
||||||
|
{ WXK_NUMPAD_DOWN, wxTRANSLATE("KP_Down"), wxTRANSLATE("Num Down") },
|
||||||
|
|
||||||
|
// these two are in some 3.1+ builds for whatever reason
|
||||||
|
{ WXK_NUMPAD_PAGEUP, wxTRANSLATE("KP_PageUp"), wxTRANSLATE("Num PageUp") },
|
||||||
|
{ WXK_NUMPAD_PAGEDOWN, wxTRANSLATE("KP_PageDown"), wxTRANSLATE("Num PageDown") },
|
||||||
|
|
||||||
|
{ WXK_NUMPAD_PAGEUP, wxTRANSLATE("KP_PageUp"), wxTRANSLATE("Num Page Up") },
|
||||||
|
{ WXK_NUMPAD_PAGEDOWN, wxTRANSLATE("KP_PageDown"), wxTRANSLATE("Num Page Down") },
|
||||||
|
{ WXK_NUMPAD_END, wxTRANSLATE("KP_End"), wxTRANSLATE("Num End") },
|
||||||
|
{ WXK_NUMPAD_BEGIN, wxTRANSLATE("KP_Begin"), wxTRANSLATE("Num Begin") },
|
||||||
|
{ WXK_NUMPAD_INSERT, wxTRANSLATE("KP_Insert"), wxTRANSLATE("Num Insert") },
|
||||||
|
{ WXK_NUMPAD_DELETE, wxTRANSLATE("KP_Delete"), wxTRANSLATE("Num Delete") },
|
||||||
|
{ WXK_NUMPAD_EQUAL, wxTRANSLATE("KP_Equal"), wxTRANSLATE("Num =") },
|
||||||
|
{ WXK_NUMPAD_MULTIPLY, wxTRANSLATE("KP_Multiply"), wxTRANSLATE("Num *") },
|
||||||
|
{ WXK_NUMPAD_ADD, wxTRANSLATE("KP_Add"), wxTRANSLATE("Num +") },
|
||||||
|
{ WXK_NUMPAD_SEPARATOR, wxTRANSLATE("KP_Separator"), wxTRANSLATE("Num ,") },
|
||||||
|
{ WXK_NUMPAD_SUBTRACT, wxTRANSLATE("KP_Subtract"), wxTRANSLATE("Num -") },
|
||||||
|
{ WXK_NUMPAD_DECIMAL, wxTRANSLATE("KP_Decimal"), wxTRANSLATE("Num .") },
|
||||||
|
{ WXK_NUMPAD_DIVIDE, wxTRANSLATE("KP_Divide"), wxTRANSLATE("Num /") },
|
||||||
|
};
|
||||||
|
|
||||||
#endif /* WX_KEYTEXT_H */
|
#endif /* WX_KEYTEXT_H */
|
||||||
|
|
Loading…
Reference in New Issue