Blender  V2.93
wm_menu_type.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 <stdio.h>
24 
25 #include "BLI_sys_types.h"
26 
28 #include "DNA_workspace_types.h"
29 
30 #include "MEM_guardedalloc.h"
31 
32 #include "BLI_ghash.h"
33 #include "BLI_utildefines.h"
34 
35 #include "BKE_context.h"
36 #include "BKE_screen.h"
37 #include "BKE_workspace.h"
38 
39 #include "WM_api.h"
40 #include "WM_types.h"
41 
43 
44 MenuType *WM_menutype_find(const char *idname, bool quiet)
45 {
46  if (idname[0]) {
48  if (mt) {
49  return mt;
50  }
51  }
52 
53  if (!quiet) {
54  printf("search for unknown menutype %s\n", idname);
55  }
56 
57  return NULL;
58 }
59 
61 {
63 }
64 
66 {
67  BLI_assert((mt->description == NULL) || (mt->description[0]));
69  return true;
70 }
71 
73 {
75 
76  BLI_assert(ok);
78 }
79 
80 /* called on initialize WM_init() */
81 void WM_menutype_init(void)
82 {
83  /* reserve size is set based on blender default setup */
84  menutypes_hash = BLI_ghash_str_new_ex("menutypes_hash gh", 512);
85 }
86 
87 void WM_menutype_free(void)
88 {
89  GHashIterator gh_iter;
90 
91  GHASH_ITER (gh_iter, menutypes_hash) {
92  MenuType *mt = BLI_ghashIterator_getValue(&gh_iter);
93  if (mt->rna_ext.free) {
94  mt->rna_ext.free(mt->rna_ext.data);
95  }
96  }
97 
100 }
101 
103 {
104  /* If we're tagged, only use compatible. */
105  if (mt->owner_id[0] != '\0') {
106  const WorkSpace *workspace = CTX_wm_workspace(C);
107  if (BKE_workspace_owner_id_check(workspace, mt->owner_id) == false) {
108  return false;
109  }
110  }
111 
112  if (mt->poll != NULL) {
113  return mt->poll(C, mt);
114  }
115  return true;
116 }
struct WorkSpace * CTX_wm_workspace(const bContext *C)
Definition: context.c:704
bool BKE_workspace_owner_id_check(const struct WorkSpace *workspace, const char *owner_id) ATTR_NONNULL()
#define BLI_assert(a)
Definition: BLI_assert.h:58
BLI_INLINE void * BLI_ghashIterator_getValue(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.h:150
#define GHASH_ITER(gh_iter_, ghash_)
Definition: BLI_ghash.h:169
GHash * BLI_ghash_str_new_ex(const char *info, const unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
bool BLI_ghash_remove(GHash *gh, const void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:900
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition: BLI_ghash.c:756
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition: BLI_ghash.c:1008
void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh)
Definition: BLI_ghash.c:1065
void * BLI_ghash_lookup(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition: BLI_ghash.c:803
#define UNUSED_VARS_NDEBUG(...)
Read Guarded memory(de)allocation.
#define C
Definition: RandGen.cpp:39
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void * data
Definition: RNA_types.h:680
StructFreeFunc free
Definition: RNA_types.h:683
const char * description
Definition: BKE_screen.h:379
char owner_id[BKE_ST_MAXNAME]
Definition: BKE_screen.h:378
ExtensionRNA rna_ext
Definition: BKE_screen.h:387
char idname[BKE_ST_MAXNAME]
Definition: BKE_screen.h:375
bool(* poll)(const struct bContext *C, struct MenuType *mt)
Definition: BKE_screen.h:382
void WM_menutype_iter(GHashIterator *ghi)
Definition: wm_menu_type.c:60
MenuType * WM_menutype_find(const char *idname, bool quiet)
Definition: wm_menu_type.c:44
void WM_menutype_free(void)
Definition: wm_menu_type.c:87
bool WM_menutype_add(MenuType *mt)
Definition: wm_menu_type.c:65
void WM_menutype_init(void)
Definition: wm_menu_type.c:81
bool WM_menutype_poll(bContext *C, MenuType *mt)
Definition: wm_menu_type.c:102
void WM_menutype_freelink(MenuType *mt)
Definition: wm_menu_type.c:72
static GHash * menutypes_hash
Definition: wm_menu_type.c:42