Cleanup: pass keymap items as const where possible

This commit is contained in:
Campbell Barton 2021-02-04 21:53:58 +11:00
parent dff51d418a
commit 3be5859b21
6 changed files with 33 additions and 24 deletions

View File

@ -49,7 +49,7 @@
static eRedrawFlag seq_slide_handleEvent(struct TransInfo *t, const wmEvent *event)
{
BLI_assert(t->mode == TFM_SEQ_SLIDE);
wmKeyMapItem *kmi = t->custom.mode.data;
const wmKeyMapItem *kmi = t->custom.mode.data;
if (kmi && event->type == kmi->type && event->val == kmi->val) {
/* Allows the 'Expand to fit' effect to be enabled as a toogle. */
t->flag ^= T_ALT_TRANSFORM;
@ -73,7 +73,7 @@ static void headerSeqSlide(TransInfo *t, const float val[2], char str[UI_MAX_DRA
ofs += BLI_snprintf(
str + ofs, UI_MAX_DRAW_STR - ofs, TIP_("Sequence Slide: %s%s, ("), &tvec[0], t->con.text);
wmKeyMapItem *kmi = t->custom.mode.data;
const wmKeyMapItem *kmi = t->custom.mode.data;
if (kmi) {
ofs += WM_keymap_item_to_string(kmi, false, str + ofs, UI_MAX_DRAW_STR - ofs);
}
@ -158,7 +158,7 @@ void initSeqSlide(TransInfo *t)
if (t->keymap) {
/* Workaround to use the same key as the modal keymap. */
t->custom.mode.data = WM_modalkeymap_find_propvalue(t->keymap, TFM_MODAL_TRANSLATE);
t->custom.mode.data = (void *)WM_modalkeymap_find_propvalue(t->keymap, TFM_MODAL_TRANSLATE);
}
}
/** \} */

View File

@ -49,7 +49,7 @@
static eRedrawFlag shrinkfatten_handleEvent(struct TransInfo *t, const wmEvent *event)
{
BLI_assert(t->mode == TFM_SHRINKFATTEN);
wmKeyMapItem *kmi = t->custom.mode.data;
const wmKeyMapItem *kmi = t->custom.mode.data;
if (kmi && event->type == kmi->type && event->val == kmi->val) {
/* Allows the 'Even Thickness' effect to be enabled as a toogle. */
t->flag ^= T_ALT_TRANSFORM;
@ -90,7 +90,7 @@ static void applyShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
}
ofs += BLI_strncpy_rlen(str + ofs, ", (", sizeof(str) - ofs);
wmKeyMapItem *kmi = t->custom.mode.data;
const wmKeyMapItem *kmi = t->custom.mode.data;
if (kmi) {
ofs += WM_keymap_item_to_string(kmi, false, str + ofs, sizeof(str) - ofs);
}
@ -150,7 +150,7 @@ void initShrinkFatten(TransInfo *t)
if (t->keymap) {
/* Workaround to use the same key as the modal keymap. */
t->custom.mode.data = WM_modalkeymap_find_propvalue(t->keymap, TFM_MODAL_RESIZE);
t->custom.mode.data = (void *)WM_modalkeymap_find_propvalue(t->keymap, TFM_MODAL_RESIZE);
}
}
}

View File

@ -72,6 +72,12 @@ const EnumPropertyItem rna_enum_window_cursor_items[] = {
# include "WM_types.h"
/* Needed since RNA doesn't use `const` in function signatures. */
static bool rna_KeyMapItem_compare(struct wmKeyMapItem *k1, struct wmKeyMapItem *k2)
{
return WM_keymap_item_compare(k1, k2);
}
static void rna_KeyMapItem_to_string(wmKeyMapItem *kmi, bool compact, char *result)
{
WM_keymap_item_to_string(kmi, compact, result, UI_MAX_SHORTCUT_STR);
@ -1103,7 +1109,7 @@ void RNA_api_keymapitem(StructRNA *srna)
FunctionRNA *func;
PropertyRNA *parm;
func = RNA_def_function(srna, "compare", "WM_keymap_item_compare");
func = RNA_def_function(srna, "compare", "rna_KeyMapItem_compare");
parm = RNA_def_pointer(func, "item", "KeyMapItem", "Item", "");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
parm = RNA_def_boolean(func, "result", 0, "Comparison result", "");

View File

@ -59,7 +59,7 @@ wmKeyMapItem *WM_keymap_add_item(
wmKeyMapItem *WM_keymap_add_item_copy(struct wmKeyMap *keymap, wmKeyMapItem *kmi_src);
bool WM_keymap_remove_item(struct wmKeyMap *keymap, struct wmKeyMapItem *kmi);
int WM_keymap_item_to_string(wmKeyMapItem *kmi,
int WM_keymap_item_to_string(const wmKeyMapItem *kmi,
const bool compact,
char *result,
const int result_len);
@ -86,7 +86,7 @@ bool WM_keymap_remove(struct wmKeyConfig *keyconfig, struct wmKeyMap *keymap);
bool WM_keymap_poll(struct bContext *C, struct wmKeyMap *keymap);
wmKeyMapItem *WM_keymap_item_find_id(struct wmKeyMap *keymap, int id);
bool WM_keymap_item_compare(struct wmKeyMapItem *k1, struct wmKeyMapItem *k2);
bool WM_keymap_item_compare(const struct wmKeyMapItem *k1, const struct wmKeyMapItem *k2);
/* keymap_utils.c */
@ -111,13 +111,13 @@ void WM_keymap_add_context_enum_set_items(wmKeyMap *keymap,
wmKeyMap *WM_keymap_guess_from_context(const struct bContext *C);
wmKeyMap *WM_keymap_guess_opname(const struct bContext *C, const char *opname);
bool WM_keymap_uses_event_modifier(wmKeyMap *keymap, const int event_modifier);
bool WM_keymap_uses_event_modifier(const wmKeyMap *keymap, const int event_modifier);
void WM_keymap_fix_linking(void);
/* Modal Keymap */
int WM_modalkeymap_items_to_string(struct wmKeyMap *km,
int WM_modalkeymap_items_to_string(const struct wmKeyMap *km,
const int propvalue,
const bool compact,
char *result,
@ -142,7 +142,7 @@ wmKeyMapItem *WM_modalkeymap_add_item(
struct wmKeyMap *km, int type, int val, int modifier, int keymodifier, int value);
wmKeyMapItem *WM_modalkeymap_add_item_str(
struct wmKeyMap *km, int type, int val, int modifier, int keymodifier, const char *value);
wmKeyMapItem *WM_modalkeymap_find_propvalue(wmKeyMap *km, const int propvalue);
const wmKeyMapItem *WM_modalkeymap_find_propvalue(const wmKeyMap *km, const int propvalue);
void WM_modalkeymap_assign(struct wmKeyMap *km, const char *opname);
/* Keymap Editor */

View File

@ -949,9 +949,9 @@ wmKeyMapItem *WM_modalkeymap_add_item_str(
return kmi;
}
static wmKeyMapItem *wm_modalkeymap_find_propvalue_iter(wmKeyMap *km,
wmKeyMapItem *kmi,
const int propvalue)
static const wmKeyMapItem *wm_modalkeymap_find_propvalue_iter(const wmKeyMap *km,
const wmKeyMapItem *kmi,
const int propvalue)
{
if (km->flag & KEYMAP_MODAL) {
kmi = kmi ? kmi->next : km->items.first;
@ -968,7 +968,7 @@ static wmKeyMapItem *wm_modalkeymap_find_propvalue_iter(wmKeyMap *km,
return NULL;
}
wmKeyMapItem *WM_modalkeymap_find_propvalue(wmKeyMap *km, const int propvalue)
const wmKeyMapItem *WM_modalkeymap_find_propvalue(const wmKeyMap *km, const int propvalue)
{
return wm_modalkeymap_find_propvalue_iter(km, NULL, propvalue);
}
@ -1201,7 +1201,7 @@ int WM_keymap_item_raw_to_string(const short shift,
#undef ADD_SEP
}
int WM_keymap_item_to_string(wmKeyMapItem *kmi,
int WM_keymap_item_to_string(const wmKeyMapItem *kmi,
const bool compact,
char *result,
const int result_len)
@ -1218,14 +1218,17 @@ int WM_keymap_item_to_string(wmKeyMapItem *kmi,
result_len);
}
int WM_modalkeymap_items_to_string(
wmKeyMap *km, const int propvalue, const bool compact, char *result, const int result_len)
int WM_modalkeymap_items_to_string(const wmKeyMap *km,
const int propvalue,
const bool compact,
char *result,
const int result_len)
{
int totlen = 0;
bool add_sep = false;
if (km) {
wmKeyMapItem *kmi;
const wmKeyMapItem *kmi;
/* Find all shortcuts related to that propvalue! */
for (kmi = WM_modalkeymap_find_propvalue(km, propvalue); kmi && totlen < (result_len - 2);
@ -1654,7 +1657,7 @@ wmKeyMapItem *WM_key_event_operator_from_keymap(wmKeyMap *keymap,
});
}
bool WM_keymap_item_compare(wmKeyMapItem *k1, wmKeyMapItem *k2)
bool WM_keymap_item_compare(const wmKeyMapItem *k1, const wmKeyMapItem *k2)
{
if (k1->flag & KMI_INACTIVE || k2->flag & KMI_INACTIVE) {
return 0;

View File

@ -477,7 +477,7 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname)
return km;
}
static bool wm_keymap_item_uses_modifier(wmKeyMapItem *kmi, const int event_modifier)
static bool wm_keymap_item_uses_modifier(const wmKeyMapItem *kmi, const int event_modifier)
{
if (kmi->ctrl != KM_ANY) {
if ((kmi->ctrl == KM_NOTHING) != ((event_modifier & KM_CTRL) == 0)) {
@ -505,9 +505,9 @@ static bool wm_keymap_item_uses_modifier(wmKeyMapItem *kmi, const int event_modi
return true;
}
bool WM_keymap_uses_event_modifier(wmKeyMap *keymap, const int event_modifier)
bool WM_keymap_uses_event_modifier(const wmKeyMap *keymap, const int event_modifier)
{
LISTBASE_FOREACH (wmKeyMapItem *, kmi, &keymap->items) {
LISTBASE_FOREACH (const wmKeyMapItem *, kmi, &keymap->items) {
if ((kmi->flag & KMI_INACTIVE) == 0) {
if (wm_keymap_item_uses_modifier(kmi, event_modifier)) {
return true;