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
17 /** \file
18 * \ingroup wm
19 *
20 * UI List Registry.
21 */
22
23 #include "BLI_sys_types.h"
24
25 #include "DNA_windowmanager_types.h"
26
27 #include "MEM_guardedalloc.h"
28
29 #include "BLI_ghash.h"
30 #include "BLI_utildefines.h"
31
32 #include "BKE_screen.h"
33
34 #include "WM_api.h"
35 #include "WM_types.h"
36
37 static GHash *uilisttypes_hash = NULL;
38
WM_uilisttype_find(const char * idname,bool quiet)39 uiListType *WM_uilisttype_find(const char *idname, bool quiet)
40 {
41 if (idname[0]) {
42 uiListType *ult = BLI_ghash_lookup(uilisttypes_hash, idname);
43 if (ult) {
44 return ult;
45 }
46 }
47
48 if (!quiet) {
49 printf("search for unknown uilisttype %s\n", idname);
50 }
51
52 return NULL;
53 }
54
WM_uilisttype_add(uiListType * ult)55 bool WM_uilisttype_add(uiListType *ult)
56 {
57 BLI_ghash_insert(uilisttypes_hash, ult->idname, ult);
58 return 1;
59 }
60
WM_uilisttype_freelink(uiListType * ult)61 void WM_uilisttype_freelink(uiListType *ult)
62 {
63
64 bool ok = BLI_ghash_remove(uilisttypes_hash, ult->idname, NULL, MEM_freeN);
65
66 BLI_assert(ok);
67 UNUSED_VARS_NDEBUG(ok);
68 }
69
70 /* called on initialize WM_init() */
WM_uilisttype_init(void)71 void WM_uilisttype_init(void)
72 {
73 uilisttypes_hash = BLI_ghash_str_new_ex("uilisttypes_hash gh", 16);
74 }
75
WM_uilisttype_free(void)76 void WM_uilisttype_free(void)
77 {
78 GHashIterator gh_iter;
79 GHASH_ITER (gh_iter, uilisttypes_hash) {
80 uiListType *ult = BLI_ghashIterator_getValue(&gh_iter);
81 if (ult->rna_ext.free) {
82 ult->rna_ext.free(ult->rna_ext.data);
83 }
84 }
85
86 BLI_ghash_free(uilisttypes_hash, NULL, MEM_freeN);
87 uilisttypes_hash = NULL;
88 }
89