From a5c35fb27f090bb716a3bb49a69a56be80dff6d3 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Tue, 28 Jan 2014 03:52:21 +1100 Subject: Code cleanup: use booleans where appropriate --- source/blender/windowmanager/WM_api.h | 6 ++-- source/blender/windowmanager/WM_keymap.h | 10 ++++-- source/blender/windowmanager/intern/wm.c | 20 +++++++++--- .../blender/windowmanager/intern/wm_event_system.c | 16 +++++----- source/blender/windowmanager/intern/wm_keymap.c | 36 +++++++++++----------- 5 files changed, 51 insertions(+), 37 deletions(-) (limited to 'source/blender/windowmanager') diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 1690a1a8641..ed86cc01a16 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -232,7 +232,7 @@ int WM_operator_call_notest(struct bContext *C, struct wmOperator *op); int WM_operator_repeat (struct bContext *C, struct wmOperator *op); int WM_operator_repeat_check(const struct bContext *C, struct wmOperator *op); int WM_operator_name_call (struct bContext *C, const char *opstring, short context, struct PointerRNA *properties); -int WM_operator_call_py(struct bContext *C, struct wmOperatorType *ot, short context, struct PointerRNA *properties, struct ReportList *reports, short is_undo); +int WM_operator_call_py(struct bContext *C, struct wmOperatorType *ot, short context, struct PointerRNA *properties, struct ReportList *reports, const bool is_undo); void WM_operator_properties_alloc(struct PointerRNA **ptr, struct IDProperty **properties, const char *opstring); /* used for keymap and macro items */ void WM_operator_properties_sanitize(struct PointerRNA *ptr, const bool no_context); /* make props context sensitive or not */ @@ -288,14 +288,14 @@ void WM_operator_py_idname(char *to, const char *from); /* *************** uilist types ******************** */ void WM_uilisttype_init(void); struct uiListType *WM_uilisttype_find(const char *idname, bool quiet); -int WM_uilisttype_add(struct uiListType *ult); +bool WM_uilisttype_add(struct uiListType *ult); void WM_uilisttype_freelink(struct uiListType *ult); void WM_uilisttype_free(void); /* *************** menu types ******************** */ void WM_menutype_init(void); struct MenuType *WM_menutype_find(const char *idname, bool quiet); -int WM_menutype_add(struct MenuType *mt); +bool WM_menutype_add(struct MenuType *mt); void WM_menutype_freelink(struct MenuType *mt); void WM_menutype_free(void); diff --git a/source/blender/windowmanager/WM_keymap.h b/source/blender/windowmanager/WM_keymap.h index f5488cbbe59..9645c95f62b 100644 --- a/source/blender/windowmanager/WM_keymap.h +++ b/source/blender/windowmanager/WM_keymap.h @@ -96,9 +96,13 @@ int WM_keymap_map_type_get(struct wmKeyMapItem *kmi); /* Key Event */ -const char *WM_key_event_string(short type); -int WM_key_event_operator_id(const struct bContext *C, const char *opname, int opcontext, struct IDProperty *properties, int hotkey, struct wmKeyMap **keymap_r); -char *WM_key_event_operator_string(const struct bContext *C, const char *opname, int opcontext, struct IDProperty *properties, const bool strict, char *str, int len); +const char *WM_key_event_string(short type); +int WM_key_event_operator_id( + const struct bContext *C, const char *opname, int opcontext, + struct IDProperty *properties, const bool is_hotkey, struct wmKeyMap **keymap_r); +char *WM_key_event_operator_string( + const struct bContext *C, const char *opname, int opcontext, + struct IDProperty *properties, const bool is_strict, char *str, int len); const char *WM_bool_as_string(bool test); diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c index 6a91eca2c7f..4460a1167ff 100644 --- a/source/blender/windowmanager/intern/wm.c +++ b/source/blender/windowmanager/intern/wm.c @@ -230,7 +230,7 @@ uiListType *WM_uilisttype_find(const char *idname, bool quiet) return NULL; } -int WM_uilisttype_add(uiListType *ult) +bool WM_uilisttype_add(uiListType *ult) { BLI_ghash_insert(uilisttypes_hash, (void *)ult->idname, ult); return 1; @@ -238,7 +238,12 @@ int WM_uilisttype_add(uiListType *ult) void WM_uilisttype_freelink(uiListType *ult) { - BLI_ghash_remove(uilisttypes_hash, ult->idname, NULL, MEM_freeN); + bool ok; + + ok = BLI_ghash_remove(uilisttypes_hash, ult->idname, NULL, MEM_freeN); + + BLI_assert(ok); + (void)ok; } /* called on initialize WM_init() */ @@ -283,15 +288,20 @@ MenuType *WM_menutype_find(const char *idname, bool quiet) return NULL; } -int WM_menutype_add(MenuType *mt) +bool WM_menutype_add(MenuType *mt) { BLI_ghash_insert(menutypes_hash, (void *)mt->idname, mt); - return 1; + return true; } void WM_menutype_freelink(MenuType *mt) { - BLI_ghash_remove(menutypes_hash, mt->idname, NULL, MEM_freeN); + bool ok; + + ok = BLI_ghash_remove(menutypes_hash, mt->idname, NULL, MEM_freeN); + + BLI_assert(ok); + (void)ok; } /* called on initialize WM_init() */ diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c index 01086fad305..1256fcf70a2 100644 --- a/source/blender/windowmanager/intern/wm_event_system.c +++ b/source/blender/windowmanager/intern/wm_event_system.c @@ -394,8 +394,8 @@ static int wm_handler_ui_call(bContext *C, wmEventHandler *handler, wmEvent *eve ScrArea *area = CTX_wm_area(C); ARegion *region = CTX_wm_region(C); ARegion *menu = CTX_wm_menu(C); - static int do_wheel_ui = TRUE; - int is_wheel = ELEM3(event->type, WHEELUPMOUSE, WHEELDOWNMOUSE, MOUSEPAN); + static bool do_wheel_ui = true; + const bool is_wheel = ELEM3(event->type, WHEELUPMOUSE, WHEELDOWNMOUSE, MOUSEPAN); int retval; /* UI code doesn't handle return values - it just always returns break. @@ -405,11 +405,11 @@ static int wm_handler_ui_call(bContext *C, wmEventHandler *handler, wmEvent *eve /* UI is quite aggressive with swallowing events, like scrollwheel */ /* I realize this is not extremely nice code... when UI gets keymaps it can be maybe smarter */ - if (do_wheel_ui == FALSE) { + if (do_wheel_ui == false) { if (is_wheel) return WM_HANDLER_CONTINUE; else if (wm_event_always_pass(event) == 0) - do_wheel_ui = TRUE; + do_wheel_ui = true; } /* we set context to where ui handler came from */ @@ -437,7 +437,7 @@ static int wm_handler_ui_call(bContext *C, wmEventHandler *handler, wmEvent *eve /* event not handled in UI, if wheel then we temporarily disable it */ if (is_wheel) - do_wheel_ui = FALSE; + do_wheel_ui = false; return WM_HANDLER_CONTINUE; } @@ -985,7 +985,7 @@ static int wm_operator_invoke(bContext *C, wmOperatorType *ot, wmEvent *event, if (WM_operator_poll(C, ot)) { wmWindowManager *wm = CTX_wm_manager(C); wmOperator *op = wm_operator_create(wm, ot, properties, reports); /* if reports == NULL, they'll be initialized */ - const short is_nested_call = (wm->op_undo_depth != 0); + const bool is_nested_call = (wm->op_undo_depth != 0); op->flag |= OP_IS_INVOKE; @@ -1254,7 +1254,7 @@ int WM_operator_name_call(bContext *C, const char *opstring, short context, Poin * - reports can be passed to this function (so python can report them as exceptions) */ int WM_operator_call_py(bContext *C, wmOperatorType *ot, short context, - PointerRNA *properties, ReportList *reports, short is_undo) + PointerRNA *properties, ReportList *reports, const bool is_undo) { int retval = OPERATOR_CANCELLED; @@ -2148,7 +2148,7 @@ void wm_event_do_handlers(bContext *C) int is_playing_sound = sound_scene_playing(win->screen->scene); if (is_playing_sound != -1) { - int is_playing_screen; + bool is_playing_screen; CTX_wm_window_set(C, win); CTX_wm_screen_set(C, win->screen); CTX_data_scene_set(C, scene); diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c index 10837178f35..7caa5b31df4 100644 --- a/source/blender/windowmanager/intern/wm_keymap.c +++ b/source/blender/windowmanager/intern/wm_keymap.c @@ -928,7 +928,7 @@ int WM_keymap_item_to_string(wmKeyMapItem *kmi, char *str, const int len) static wmKeyMapItem *wm_keymap_item_find_handlers( const bContext *C, ListBase *handlers, const char *opname, int UNUSED(opcontext), - IDProperty *properties, int is_strict, int hotkey, wmKeyMap **keymap_r) + IDProperty *properties, const bool is_strict, const bool is_hotkey, wmKeyMap **keymap_r) { wmWindowManager *wm = CTX_wm_manager(C); wmEventHandler *handler; @@ -943,7 +943,7 @@ static wmKeyMapItem *wm_keymap_item_find_handlers( for (kmi = keymap->items.first; kmi; kmi = kmi->next) { if (strcmp(kmi->idname, opname) == 0 && WM_key_event_string(kmi->type)[0]) { - if (hotkey) + if (is_hotkey) if (!ISHOTKEY(kmi->type)) continue; @@ -982,7 +982,7 @@ static wmKeyMapItem *wm_keymap_item_find_handlers( static wmKeyMapItem *wm_keymap_item_find_props( const bContext *C, const char *opname, int opcontext, - IDProperty *properties, int is_strict, int hotkey, wmKeyMap **keymap_r) + IDProperty *properties, const bool is_strict, const bool is_hotkey, wmKeyMap **keymap_r) { wmWindow *win = CTX_wm_window(C); ScrArea *sa = CTX_wm_area(C); @@ -991,10 +991,10 @@ static wmKeyMapItem *wm_keymap_item_find_props( /* look into multiple handler lists to find the item */ if (win) - found = wm_keymap_item_find_handlers(C, &win->handlers, opname, opcontext, properties, is_strict, hotkey, keymap_r); + found = wm_keymap_item_find_handlers(C, &win->handlers, opname, opcontext, properties, is_strict, is_hotkey, keymap_r); if (sa && found == NULL) - found = wm_keymap_item_find_handlers(C, &sa->handlers, opname, opcontext, properties, is_strict, hotkey, keymap_r); + found = wm_keymap_item_find_handlers(C, &sa->handlers, opname, opcontext, properties, is_strict, is_hotkey, keymap_r); if (found == NULL) { if (ELEM(opcontext, WM_OP_EXEC_REGION_WIN, WM_OP_INVOKE_REGION_WIN)) { @@ -1003,7 +1003,7 @@ static wmKeyMapItem *wm_keymap_item_find_props( ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW); if (ar) - found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, is_strict, hotkey, keymap_r); + found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, is_strict, is_hotkey, keymap_r); } } else if (ELEM(opcontext, WM_OP_EXEC_REGION_CHANNELS, WM_OP_INVOKE_REGION_CHANNELS)) { @@ -1011,18 +1011,18 @@ static wmKeyMapItem *wm_keymap_item_find_props( ar = BKE_area_find_region_type(sa, RGN_TYPE_CHANNELS); if (ar) - found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, is_strict, hotkey, keymap_r); + found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, is_strict, is_hotkey, keymap_r); } else if (ELEM(opcontext, WM_OP_EXEC_REGION_PREVIEW, WM_OP_INVOKE_REGION_PREVIEW)) { if (!(ar && ar->regiontype == RGN_TYPE_PREVIEW)) ar = BKE_area_find_region_type(sa, RGN_TYPE_PREVIEW); if (ar) - found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, is_strict, hotkey, keymap_r); + found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, is_strict, is_hotkey, keymap_r); } else { if (ar) - found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, is_strict, hotkey, keymap_r); + found = wm_keymap_item_find_handlers(C, &ar->handlers, opname, opcontext, properties, is_strict, is_hotkey, keymap_r); } } @@ -1031,9 +1031,9 @@ static wmKeyMapItem *wm_keymap_item_find_props( static wmKeyMapItem *wm_keymap_item_find( const bContext *C, const char *opname, int opcontext, - IDProperty *properties, const short hotkey, const bool strict, wmKeyMap **keymap_r) + IDProperty *properties, const bool is_hotkey, const bool is_strict, wmKeyMap **keymap_r) { - wmKeyMapItem *found = wm_keymap_item_find_props(C, opname, opcontext, properties, strict, hotkey, keymap_r); + wmKeyMapItem *found = wm_keymap_item_find_props(C, opname, opcontext, properties, is_strict, is_hotkey, keymap_r); if (!found && properties) { wmOperatorType *ot = WM_operatortype_find(opname, TRUE); @@ -1046,14 +1046,14 @@ static wmKeyMapItem *wm_keymap_item_find( RNA_pointer_create(NULL, ot->srna, properties_default, &opptr); if (WM_operator_properties_default(&opptr, true) || - (!strict && ot->prop && RNA_property_is_set(&opptr, ot->prop))) + (!is_strict && ot->prop && RNA_property_is_set(&opptr, ot->prop))) { /* for operator that has enum menu, unset it so it always matches */ - if (!strict && ot->prop) { + if (!is_strict && ot->prop) { RNA_property_unset(&opptr, ot->prop); } - found = wm_keymap_item_find_props(C, opname, opcontext, properties_default, false, hotkey, keymap_r); + found = wm_keymap_item_find_props(C, opname, opcontext, properties_default, false, is_hotkey, keymap_r); } IDP_FreeProperty(properties_default); @@ -1066,9 +1066,9 @@ static wmKeyMapItem *wm_keymap_item_find( char *WM_key_event_operator_string( const bContext *C, const char *opname, int opcontext, - IDProperty *properties, const bool strict, char *str, int len) + IDProperty *properties, const bool is_strict, char *str, int len) { - wmKeyMapItem *kmi = wm_keymap_item_find(C, opname, opcontext, properties, 0, strict, NULL); + wmKeyMapItem *kmi = wm_keymap_item_find(C, opname, opcontext, properties, false, is_strict, NULL); if (kmi) { WM_keymap_item_to_string(kmi, str, len); @@ -1080,9 +1080,9 @@ char *WM_key_event_operator_string( int WM_key_event_operator_id( const bContext *C, const char *opname, int opcontext, - IDProperty *properties, int hotkey, wmKeyMap **keymap_r) + IDProperty *properties, const bool is_hotkey, wmKeyMap **keymap_r) { - wmKeyMapItem *kmi = wm_keymap_item_find(C, opname, opcontext, properties, hotkey, true, keymap_r); + wmKeyMapItem *kmi = wm_keymap_item_find(C, opname, opcontext, properties, is_hotkey, true, keymap_r); if (kmi) return kmi->id; -- cgit v1.2.3