Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/context.c
| Show First 20 Lines • Show All 288 Lines • ▼ Show 20 Lines | #endif | ||||
| /* don't allow UI context access from non-main threads */ | /* don't allow UI context access from non-main threads */ | ||||
| if (!BLI_thread_is_main()) { | if (!BLI_thread_is_main()) { | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| return fall_through; | return fall_through; | ||||
| } | } | ||||
| static int ctx_data_get(bContext *C, const char *member, bContextDataResult *result) | static eContextResult ctx_data_get(bContext *C, const char *member, bContextDataResult *result) | ||||
| { | { | ||||
| bScreen *screen; | bScreen *screen; | ||||
| ScrArea *area; | ScrArea *area; | ||||
| ARegion *region; | ARegion *region; | ||||
| int done = 0, recursion = C->data.recursion; | int done = 0, recursion = C->data.recursion; | ||||
| int ret = 0; | int ret = 0; | ||||
| memset(result, 0, sizeof(bContextDataResult)); | memset(result, 0, sizeof(bContextDataResult)); | ||||
| ▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | #endif | ||||
| return done; | return done; | ||||
| } | } | ||||
| static void *ctx_data_pointer_get(const bContext *C, const char *member) | static void *ctx_data_pointer_get(const bContext *C, const char *member) | ||||
| { | { | ||||
| bContextDataResult result; | bContextDataResult result; | ||||
| if (C && ctx_data_get((bContext *)C, member, &result) == 1) { | if (C && ctx_data_get((bContext *)C, member, &result) == CTX_RESULT_OK) { | ||||
| BLI_assert(result.type == CTX_DATA_TYPE_POINTER); | BLI_assert(result.type == CTX_DATA_TYPE_POINTER); | ||||
| return result.ptr.data; | return result.ptr.data; | ||||
| } | } | ||||
| return NULL; | return NULL; | ||||
| } | } | ||||
| static int ctx_data_pointer_verify(const bContext *C, const char *member, void **pointer) | static int ctx_data_pointer_verify(const bContext *C, const char *member, void **pointer) | ||||
| { | { | ||||
| bContextDataResult result; | bContextDataResult result; | ||||
| /* if context is NULL, pointer must be NULL too and that is a valid return */ | /* if context is NULL, pointer must be NULL too and that is a valid return */ | ||||
| if (C == NULL) { | if (C == NULL) { | ||||
| *pointer = NULL; | *pointer = NULL; | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| if (ctx_data_get((bContext *)C, member, &result) == 1) { | if (ctx_data_get((bContext *)C, member, &result) == CTX_RESULT_OK) { | ||||
| BLI_assert(result.type == CTX_DATA_TYPE_POINTER); | BLI_assert(result.type == CTX_DATA_TYPE_POINTER); | ||||
| *pointer = result.ptr.data; | *pointer = result.ptr.data; | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| *pointer = NULL; | *pointer = NULL; | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| static int ctx_data_collection_get(const bContext *C, const char *member, ListBase *list) | static int ctx_data_collection_get(const bContext *C, const char *member, ListBase *list) | ||||
| { | { | ||||
| bContextDataResult result; | bContextDataResult result; | ||||
| if (ctx_data_get((bContext *)C, member, &result) == 1) { | if (ctx_data_get((bContext *)C, member, &result) == CTX_RESULT_OK) { | ||||
| BLI_assert(result.type == CTX_DATA_TYPE_COLLECTION); | BLI_assert(result.type == CTX_DATA_TYPE_COLLECTION); | ||||
| *list = result.list; | *list = result.list; | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| BLI_listbase_clear(list); | BLI_listbase_clear(list); | ||||
| return 0; | return 0; | ||||
| Show All 31 Lines | static int ctx_data_base_collection_get(const bContext *C, const char *member, ListBase *list) | ||||
| *list = result.list; | *list = result.list; | ||||
| return ok; | return ok; | ||||
| } | } | ||||
| PointerRNA CTX_data_pointer_get(const bContext *C, const char *member) | PointerRNA CTX_data_pointer_get(const bContext *C, const char *member) | ||||
| { | { | ||||
| bContextDataResult result; | bContextDataResult result; | ||||
| if (ctx_data_get((bContext *)C, member, &result) == 1) { | if (ctx_data_get((bContext *)C, member, &result) == CTX_RESULT_OK) { | ||||
| BLI_assert(result.type == CTX_DATA_TYPE_POINTER); | BLI_assert(result.type == CTX_DATA_TYPE_POINTER); | ||||
| return result.ptr; | return result.ptr; | ||||
| } | } | ||||
| return PointerRNA_NULL; | return PointerRNA_NULL; | ||||
| } | } | ||||
| PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type) | PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type) | ||||
| Show All 25 Lines | PointerRNA CTX_data_pointer_get_type_silent(const bContext *C, const char *member, StructRNA *type) | ||||
| return PointerRNA_NULL; | return PointerRNA_NULL; | ||||
| } | } | ||||
| ListBase CTX_data_collection_get(const bContext *C, const char *member) | ListBase CTX_data_collection_get(const bContext *C, const char *member) | ||||
| { | { | ||||
| bContextDataResult result; | bContextDataResult result; | ||||
| if (ctx_data_get((bContext *)C, member, &result) == 1) { | if (ctx_data_get((bContext *)C, member, &result) == CTX_RESULT_OK) { | ||||
| BLI_assert(result.type == CTX_DATA_TYPE_COLLECTION); | BLI_assert(result.type == CTX_DATA_TYPE_COLLECTION); | ||||
| return result.list; | return result.list; | ||||
| } | } | ||||
| ListBase list = {NULL, NULL}; | ListBase list = {NULL, NULL}; | ||||
| return list; | return list; | ||||
| } | } | ||||
| /* 1:found, -1:found but not set, 0:not found */ | int /*eContextResult*/ CTX_data_get( | ||||
| int CTX_data_get( | |||||
| const bContext *C, const char *member, PointerRNA *r_ptr, ListBase *r_lb, short *r_type) | const bContext *C, const char *member, PointerRNA *r_ptr, ListBase *r_lb, short *r_type) | ||||
| { | { | ||||
| bContextDataResult result; | bContextDataResult result; | ||||
| int ret = ctx_data_get((bContext *)C, member, &result); | eContextResult ret = ctx_data_get((bContext *)C, member, &result); | ||||
| if (ret == 1) { | if (ret == CTX_RESULT_OK) { | ||||
| *r_ptr = result.ptr; | *r_ptr = result.ptr; | ||||
| *r_lb = result.list; | *r_lb = result.list; | ||||
| *r_type = result.type; | *r_type = result.type; | ||||
| } | } | ||||
| else { | else { | ||||
| memset(r_ptr, 0, sizeof(*r_ptr)); | memset(r_ptr, 0, sizeof(*r_ptr)); | ||||
| memset(r_lb, 0, sizeof(*r_lb)); | memset(r_lb, 0, sizeof(*r_lb)); | ||||
| *r_type = 0; | *r_type = 0; | ||||
| ▲ Show 20 Lines • Show All 917 Lines • Show Last 20 Lines | |||||