Blender V4.3
blender_user_menu.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11#include <cstring>
12
13#include "MEM_guardedalloc.h"
14
15#include "BLI_listbase.h"
16#include "BLI_string.h"
17
18#include "DNA_userdef_types.h"
19
21#include "BKE_idprop.hh"
22
23/* -------------------------------------------------------------------- */
27bUserMenu *BKE_blender_user_menu_find(ListBase *lb, char space_type, const char *context)
28{
29 LISTBASE_FOREACH (bUserMenu *, um, lb) {
30 if ((space_type == um->space_type) && STREQ(context, um->context)) {
31 return um;
32 }
33 }
34 return nullptr;
35}
36
37bUserMenu *BKE_blender_user_menu_ensure(ListBase *lb, char space_type, const char *context)
38{
39 bUserMenu *um = BKE_blender_user_menu_find(lb, space_type, context);
40 if (um == nullptr) {
41 um = static_cast<bUserMenu *>(MEM_callocN(sizeof(bUserMenu), __func__));
42 um->space_type = space_type;
43 STRNCPY(um->context, context);
44 BLI_addhead(lb, um);
45 }
46 return um;
47}
48
51/* -------------------------------------------------------------------- */
56{
57 uint size;
58
59 if (type == USER_MENU_TYPE_SEP) {
60 size = sizeof(bUserMenuItem);
61 }
62 else if (type == USER_MENU_TYPE_OPERATOR) {
63 size = sizeof(bUserMenuItem_Op);
64 }
65 else if (type == USER_MENU_TYPE_MENU) {
66 size = sizeof(bUserMenuItem_Menu);
67 }
68 else if (type == USER_MENU_TYPE_PROP) {
69 size = sizeof(bUserMenuItem_Prop);
70 }
71 else {
72 size = sizeof(bUserMenuItem);
73 BLI_assert(0);
74 }
75
76 bUserMenuItem *umi = static_cast<bUserMenuItem *>(MEM_callocN(size, __func__));
77 umi->type = type;
78 BLI_addtail(lb, umi);
79 return umi;
80}
81
83{
84 if (umi->type == USER_MENU_TYPE_OPERATOR) {
85 bUserMenuItem_Op *umi_op = (bUserMenuItem_Op *)umi;
86 if (umi_op->prop) {
87 IDP_FreeProperty(umi_op->prop);
88 }
89 }
90 MEM_freeN(umi);
91}
92
94{
95 for (bUserMenuItem *umi = static_cast<bUserMenuItem *>(lb->first), *umi_next; umi;
96 umi = umi_next)
97 {
98 umi_next = umi->next;
100 }
102}
103
void IDP_FreeProperty(IDProperty *prop)
Definition idprop.cc:1227
#define BLI_assert(a)
Definition BLI_assert.h:50
void BLI_addhead(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:90
#define LISTBASE_FOREACH(type, var, list)
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:110
#define STRNCPY(dst, src)
Definition BLI_string.h:593
unsigned int uint
#define STREQ(a, b)
struct bUserMenuItem_Op bUserMenuItem_Op
struct bUserMenuItem_Prop bUserMenuItem_Prop
struct bUserMenuItem_Menu bUserMenuItem_Menu
@ USER_MENU_TYPE_OPERATOR
@ USER_MENU_TYPE_SEP
@ USER_MENU_TYPE_PROP
@ USER_MENU_TYPE_MENU
struct bUserMenuItem bUserMenuItem
Read Guarded memory(de)allocation.
bUserMenu * BKE_blender_user_menu_find(ListBase *lb, char space_type, const char *context)
bUserMenu * BKE_blender_user_menu_ensure(ListBase *lb, char space_type, const char *context)
void BKE_blender_user_menu_item_free(bUserMenuItem *umi)
bUserMenuItem * BKE_blender_user_menu_item_add(ListBase *lb, int type)
void BKE_blender_user_menu_item_free_list(ListBase *lb)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
void MEM_freeN(void *vmemh)
Definition mallocn.cc:105
void *(* MEM_callocN)(size_t len, const char *str)
Definition mallocn.cc:42
void * first
struct IDProperty * prop