Merge remote-tracking branch 'origin/master' into blender2.8
[blender.git] / source / blender / editors / interface / interface_query.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * ***** END GPL LICENSE BLOCK *****
19  */
20
21 /** \file blender/editors/interface/interface_query.c
22  *  \ingroup edinterface
23  *
24  * Utilities to inspect the interface, extract information.
25  */
26
27 #include "BLI_utildefines.h"
28
29 #include "DNA_screen_types.h"
30
31 #include "UI_interface.h"
32
33 #include "interface_intern.h"
34
35 #include "WM_api.h"
36 #include "WM_types.h"
37
38 /* -------------------------------------------------------------------- */
39 /** \name Button (uiBut)
40  * \{ */
41
42 bool ui_but_is_editable(const uiBut *but)
43 {
44         return !ELEM(
45                 but->type,
46                 UI_BTYPE_LABEL, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE,
47                 UI_BTYPE_ROUNDBOX, UI_BTYPE_LISTBOX, UI_BTYPE_PROGRESS_BAR);
48 }
49
50 bool ui_but_is_editable_as_text(const uiBut *but)
51 {
52         return ELEM(
53                 but->type,
54                 UI_BTYPE_TEXT, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER,
55                 UI_BTYPE_SEARCH_MENU);
56
57 }
58
59 bool ui_but_is_toggle(const uiBut *but)
60 {
61         return ELEM(
62                 but->type,
63                 UI_BTYPE_BUT_TOGGLE,
64                 UI_BTYPE_TOGGLE,
65                 UI_BTYPE_ICON_TOGGLE,
66                 UI_BTYPE_ICON_TOGGLE_N,
67                 UI_BTYPE_TOGGLE_N,
68                 UI_BTYPE_CHECKBOX,
69                 UI_BTYPE_CHECKBOX_N,
70                 UI_BTYPE_ROW
71         );
72 }
73
74 #ifdef USE_UI_POPOVER_ONCE
75 bool ui_but_is_popover_once_compat(const uiBut *but)
76 {
77         return (
78                 (but->type == UI_BTYPE_BUT) ||
79                 ui_but_is_toggle(but)
80         );
81 }
82 #endif
83
84 bool UI_but_is_tool(const uiBut *but)
85 {
86         /* very evil! */
87         if (but->optype != NULL) {
88                 static wmOperatorType *ot = NULL;
89                 if (ot == NULL) {
90                         ot = WM_operatortype_find("WM_OT_tool_set_by_name", false);
91                 }
92                 if (but->optype == ot) {
93                         return true;
94                 }
95         }
96         return false;
97 }
98
99 bool UI_but_has_tooltip_label(const uiBut *but)
100 {
101         if ((but->drawstr[0] == '\0') && !ui_block_is_popover(but->block)) {
102                 return UI_but_is_tool(but);
103         }
104         return false;
105 }
106
107 /** \} */
108
109 /* -------------------------------------------------------------------- */
110 /** \name Block (uiBlock)
111  * \{ */
112
113 bool ui_block_is_menu(const uiBlock *block)
114 {
115         return (((block->flag & UI_BLOCK_LOOP) != 0) &&
116                 /* non-menu popups use keep-open, so check this is off */
117                 ((block->flag & UI_BLOCK_KEEP_OPEN) == 0));
118 }
119
120 bool ui_block_is_popover(const uiBlock *block)
121 {
122         return (block->flag & UI_BLOCK_POPOVER) != 0;
123 }
124
125 bool ui_block_is_pie_menu(const uiBlock *block)
126 {
127         return ((block->flag & UI_BLOCK_RADIAL) != 0);
128 }
129
130 bool ui_block_is_popup_any(const uiBlock *block)
131 {
132         return (
133                 ui_block_is_menu(block) ||
134                 ui_block_is_popover(block) ||
135                 ui_block_is_pie_menu(block)
136         );
137 }
138
139 bool UI_block_is_empty(const uiBlock *block)
140 {
141         for (const uiBut *but = block->buttons.first; but; but = but->next) {
142                 if (!ELEM(but->type, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE)) {
143                         return false;
144                 }
145         }
146         return true;
147 }
148
149 /** \} */