Blender  V2.93
blender_user_menu.c
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
23 #include <string.h>
24 
25 #include "MEM_guardedalloc.h"
26 
27 #include "BLI_listbase.h"
28 #include "BLI_string.h"
29 
30 #include "DNA_userdef_types.h"
31 
32 #include "BKE_blender_user_menu.h"
33 #include "BKE_idprop.h"
34 
35 /* -------------------------------------------------------------------- */
39 bUserMenu *BKE_blender_user_menu_find(ListBase *lb, char space_type, const char *context)
40 {
41  LISTBASE_FOREACH (bUserMenu *, um, lb) {
42  if ((space_type == um->space_type) && (STREQ(context, um->context))) {
43  return um;
44  }
45  }
46  return NULL;
47 }
48 
49 bUserMenu *BKE_blender_user_menu_ensure(ListBase *lb, char space_type, const char *context)
50 {
51  bUserMenu *um = BKE_blender_user_menu_find(lb, space_type, context);
52  if (um == NULL) {
53  um = MEM_callocN(sizeof(bUserMenu), __func__);
54  um->space_type = space_type;
55  STRNCPY(um->context, context);
56  BLI_addhead(lb, um);
57  }
58  return um;
59 }
60 
63 /* -------------------------------------------------------------------- */
68 {
69  uint size;
70 
71  if (type == USER_MENU_TYPE_SEP) {
72  size = sizeof(bUserMenuItem);
73  }
74  else if (type == USER_MENU_TYPE_OPERATOR) {
75  size = sizeof(bUserMenuItem_Op);
76  }
77  else if (type == USER_MENU_TYPE_MENU) {
78  size = sizeof(bUserMenuItem_Menu);
79  }
80  else if (type == USER_MENU_TYPE_PROP) {
81  size = sizeof(bUserMenuItem_Prop);
82  }
83  else {
84  size = sizeof(bUserMenuItem);
85  BLI_assert(0);
86  }
87 
88  bUserMenuItem *umi = MEM_callocN(size, __func__);
89  umi->type = type;
90  BLI_addtail(lb, umi);
91  return umi;
92 }
93 
95 {
96  if (umi->type == USER_MENU_TYPE_OPERATOR) {
97  bUserMenuItem_Op *umi_op = (bUserMenuItem_Op *)umi;
98  if (umi_op->prop) {
99  IDP_FreeProperty(umi_op->prop);
100  }
101  }
102  MEM_freeN(umi);
103 }
104 
106 {
107  for (bUserMenuItem *umi = lb->first, *umi_next; umi; umi = umi_next) {
108  umi_next = umi->next;
110  }
111  BLI_listbase_clear(lb);
112 }
void IDP_FreeProperty(struct IDProperty *prop)
Definition: idprop.c:1040
#define BLI_assert(a)
Definition: BLI_assert.h:58
void BLI_addhead(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:87
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
Definition: BLI_listbase.h:128
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
#define STRNCPY(dst, src)
Definition: BLI_string.h:163
unsigned int uint
Definition: BLI_sys_types.h:83
#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
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
Read Guarded memory(de)allocation.
bUserMenu * BKE_blender_user_menu_ensure(ListBase *lb, char space_type, const char *context)
void BKE_blender_user_menu_item_free(bUserMenuItem *umi)
bUserMenu * BKE_blender_user_menu_find(ListBase *lb, char space_type, const char *context)
void BKE_blender_user_menu_item_free_list(ListBase *lb)
bUserMenuItem * BKE_blender_user_menu_item_add(ListBase *lb, int type)
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition: btDbvt.cpp:52
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_callocN)(size_t len, const char *str)
Definition: mallocn.c:45
struct SELECTID_Context context
Definition: select_engine.c:47
void * first
Definition: DNA_listBase.h:47
struct IDProperty * prop
char context[64]