Blender  V2.93
interface_button_group.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 
21 #include "BLI_listbase.h"
22 
23 #include "MEM_guardedalloc.h"
24 
25 #include "interface_intern.h"
26 
27 /* -------------------------------------------------------------------- */
36 {
37  /* Don't create a new group if there is a "lock" on new groups. */
38  if (!BLI_listbase_is_empty(&block->button_groups)) {
39  uiButtonGroup *last_button_group = block->button_groups.last;
40  if (last_button_group->flag & UI_BUTTON_GROUP_LOCK) {
41  return;
42  }
43  }
44 
45  uiButtonGroup *new_group = MEM_mallocN(sizeof(uiButtonGroup), __func__);
46  BLI_listbase_clear(&new_group->buttons);
47  new_group->flag = flag;
48  BLI_addtail(&block->button_groups, new_group);
49 }
50 
52 {
53  if (BLI_listbase_is_empty(&block->button_groups)) {
54  ui_block_new_button_group(block, 0);
55  }
56 
57  uiButtonGroup *current_button_group = block->button_groups.last;
58 
59  /* We can't use the button directly because adding it to
60  * this list would mess with its prev and next pointers. */
61  LinkData *button_link = BLI_genericNodeN(but);
62  BLI_addtail(&current_button_group->buttons, button_link);
63 }
64 
65 static void button_group_free(uiButtonGroup *button_group)
66 {
67  BLI_freelistN(&button_group->buttons);
68  MEM_freeN(button_group);
69 }
70 
72 {
73  LISTBASE_FOREACH_MUTABLE (uiButtonGroup *, button_group, &block->button_groups) {
74  button_group_free(button_group);
75  }
76 }
77 
78 void ui_button_group_replace_but_ptr(uiBlock *block, const void *old_but_ptr, uiBut *new_but)
79 {
80  LISTBASE_FOREACH (uiButtonGroup *, button_group, &block->button_groups) {
81  LISTBASE_FOREACH (LinkData *, link, &button_group->buttons) {
82  if (link->data == old_but_ptr) {
83  link->data = new_but;
84  return;
85  }
86  }
87  }
88 }
89 
BLI_INLINE bool BLI_listbase_is_empty(const struct ListBase *lb)
Definition: BLI_listbase.h:124
#define LISTBASE_FOREACH(type, var, list)
Definition: BLI_listbase.h:172
#define LISTBASE_FOREACH_MUTABLE(type, var, list)
Definition: BLI_listbase.h:188
BLI_INLINE void BLI_listbase_clear(struct ListBase *lb)
Definition: BLI_listbase.h:128
struct LinkData * BLI_genericNodeN(void *data)
Definition: listbase.c:923
void void BLI_freelistN(struct ListBase *listbase) ATTR_NONNULL(1)
Definition: listbase.c:547
void BLI_addtail(struct ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition: listbase.c:110
Read Guarded memory(de)allocation.
void ui_button_group_replace_but_ptr(uiBlock *block, const void *old_but_ptr, uiBut *new_but)
void ui_block_free_button_groups(uiBlock *block)
void ui_block_new_button_group(uiBlock *block, uiButtonGroupFlag flag)
void ui_button_group_add_but(uiBlock *block, uiBut *but)
static void button_group_free(uiButtonGroup *button_group)
uiButtonGroupFlag
@ UI_BUTTON_GROUP_LOCK
void(* MEM_freeN)(void *vmemh)
Definition: mallocn.c:41
void *(* MEM_mallocN)(size_t len, const char *str)
Definition: mallocn.c:47
void * last
Definition: DNA_listBase.h:47
ListBase button_groups