Blender
V2.93
source
blender
windowmanager
intern
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
27
#include "
DNA_windowmanager_types.h
"
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
42
static
GHash
*
menutypes_hash
=
NULL
;
43
44
MenuType
*
WM_menutype_find
(
const
char
*idname,
bool
quiet)
45
{
46
if
(idname[0]) {
47
MenuType
*mt =
BLI_ghash_lookup
(
menutypes_hash
, idname);
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
60
void
WM_menutype_iter
(
GHashIterator
*ghi)
61
{
62
BLI_ghashIterator_init
(ghi,
menutypes_hash
);
63
}
64
65
bool
WM_menutype_add
(
MenuType
*mt)
66
{
67
BLI_assert
((mt->
description
==
NULL
) || (mt->
description
[0]));
68
BLI_ghash_insert
(
menutypes_hash
, mt->
idname
, mt);
69
return
true
;
70
}
71
72
void
WM_menutype_freelink
(
MenuType
*mt)
73
{
74
bool
ok =
BLI_ghash_remove
(
menutypes_hash
, mt->
idname
,
NULL
,
MEM_freeN
);
75
76
BLI_assert
(ok);
77
UNUSED_VARS_NDEBUG
(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
98
BLI_ghash_free
(
menutypes_hash
,
NULL
,
MEM_freeN
);
99
menutypes_hash
=
NULL
;
100
}
101
102
bool
WM_menutype_poll
(
bContext
*
C
,
MenuType
*mt)
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
}
BKE_context.h
CTX_wm_workspace
struct WorkSpace * CTX_wm_workspace(const bContext *C)
Definition:
context.c:704
BKE_screen.h
BKE_workspace.h
BKE_workspace_owner_id_check
bool BKE_workspace_owner_id_check(const struct WorkSpace *workspace, const char *owner_id) ATTR_NONNULL()
BLI_assert
#define BLI_assert(a)
Definition:
BLI_assert.h:58
BLI_ghash.h
BLI_ghashIterator_getValue
BLI_INLINE void * BLI_ghashIterator_getValue(GHashIterator *ghi) ATTR_WARN_UNUSED_RESULT
Definition:
BLI_ghash.h:150
GHASH_ITER
#define GHASH_ITER(gh_iter_, ghash_)
Definition:
BLI_ghash.h:169
BLI_ghash_str_new_ex
GHash * BLI_ghash_str_new_ex(const char *info, const unsigned int nentries_reserve) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT
Definition:
BLI_ghash_utils.c:222
BLI_ghash_remove
bool BLI_ghash_remove(GHash *gh, const void *key, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition:
BLI_ghash.c:900
BLI_ghash_insert
void BLI_ghash_insert(GHash *gh, void *key, void *val)
Definition:
BLI_ghash.c:756
BLI_ghash_free
void BLI_ghash_free(GHash *gh, GHashKeyFreeFP keyfreefp, GHashValFreeFP valfreefp)
Definition:
BLI_ghash.c:1008
BLI_ghashIterator_init
void BLI_ghashIterator_init(GHashIterator *ghi, GHash *gh)
Definition:
BLI_ghash.c:1065
BLI_ghash_lookup
void * BLI_ghash_lookup(GHash *gh, const void *key) ATTR_WARN_UNUSED_RESULT
Definition:
BLI_ghash.c:803
BLI_sys_types.h
BLI_utildefines.h
UNUSED_VARS_NDEBUG
#define UNUSED_VARS_NDEBUG(...)
Definition:
BLI_utildefines.h:738
DNA_windowmanager_types.h
DNA_workspace_types.h
MEM_guardedalloc.h
Read Guarded memory(de)allocation.
C
#define C
Definition:
RandGen.cpp:39
WM_api.h
WM_types.h
NULL
return NULL
Definition:
bmesh_operator_api_inline.h:224
MEM_freeN
void(* MEM_freeN)(void *vmemh)
Definition:
mallocn.c:41
ExtensionRNA::data
void * data
Definition:
RNA_types.h:680
ExtensionRNA::free
StructFreeFunc free
Definition:
RNA_types.h:683
GHashIterator
Definition:
BLI_ghash.h:56
GHash
Definition:
BLI_ghash.c:99
MenuType
Definition:
BKE_screen.h:372
MenuType::description
const char * description
Definition:
BKE_screen.h:379
MenuType::owner_id
char owner_id[BKE_ST_MAXNAME]
Definition:
BKE_screen.h:378
MenuType::rna_ext
ExtensionRNA rna_ext
Definition:
BKE_screen.h:387
MenuType::idname
char idname[BKE_ST_MAXNAME]
Definition:
BKE_screen.h:375
MenuType::poll
bool(* poll)(const struct bContext *C, struct MenuType *mt)
Definition:
BKE_screen.h:382
WorkSpace
Definition:
DNA_workspace_types.h:109
bContext
Definition:
context.c:69
WM_menutype_iter
void WM_menutype_iter(GHashIterator *ghi)
Definition:
wm_menu_type.c:60
WM_menutype_find
MenuType * WM_menutype_find(const char *idname, bool quiet)
Definition:
wm_menu_type.c:44
WM_menutype_free
void WM_menutype_free(void)
Definition:
wm_menu_type.c:87
WM_menutype_add
bool WM_menutype_add(MenuType *mt)
Definition:
wm_menu_type.c:65
WM_menutype_init
void WM_menutype_init(void)
Definition:
wm_menu_type.c:81
WM_menutype_poll
bool WM_menutype_poll(bContext *C, MenuType *mt)
Definition:
wm_menu_type.c:102
WM_menutype_freelink
void WM_menutype_freelink(MenuType *mt)
Definition:
wm_menu_type.c:72
menutypes_hash
static GHash * menutypes_hash
Definition:
wm_menu_type.c:42
Generated on Tue Jan 31 2023 14:37:24 for Blender by
doxygen
1.9.1