Merge branch 'blender2.7'
[blender.git] / source / blender / editors / interface / interface_query.c
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 \ingroup edinterface
18  *
19  * Utilities to inspect the interface, extract information.
20  */
21
22 #include "BLI_utildefines.h"
23
24 #include "DNA_screen_types.h"
25
26 #include "UI_interface.h"
27
28 #include "interface_intern.h"
29
30 #include "WM_api.h"
31 #include "WM_types.h"
32
33 /* -------------------------------------------------------------------- */
34 /** \name Button (uiBut)
35  * \{ */
36
37 bool ui_but_is_editable(const uiBut *but)
38 {
39         return !ELEM(
40                 but->type,
41                 UI_BTYPE_LABEL, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE,
42                 UI_BTYPE_ROUNDBOX, UI_BTYPE_LISTBOX, UI_BTYPE_PROGRESS_BAR);
43 }
44
45 bool ui_but_is_editable_as_text(const uiBut *but)
46 {
47         return ELEM(
48                 but->type,
49                 UI_BTYPE_TEXT, UI_BTYPE_NUM, UI_BTYPE_NUM_SLIDER,
50                 UI_BTYPE_SEARCH_MENU);
51
52 }
53
54 bool ui_but_is_toggle(const uiBut *but)
55 {
56         return ELEM(
57                 but->type,
58                 UI_BTYPE_BUT_TOGGLE,
59                 UI_BTYPE_TOGGLE,
60                 UI_BTYPE_ICON_TOGGLE,
61                 UI_BTYPE_ICON_TOGGLE_N,
62                 UI_BTYPE_TOGGLE_N,
63                 UI_BTYPE_CHECKBOX,
64                 UI_BTYPE_CHECKBOX_N,
65                 UI_BTYPE_ROW
66         );
67 }
68
69 #ifdef USE_UI_POPOVER_ONCE
70 bool ui_but_is_popover_once_compat(const uiBut *but)
71 {
72         return (
73                 (but->type == UI_BTYPE_BUT) ||
74                 ui_but_is_toggle(but)
75         );
76 }
77 #endif
78
79 bool UI_but_is_tool(const uiBut *but)
80 {
81         /* very evil! */
82         if (but->optype != NULL) {
83                 static wmOperatorType *ot = NULL;
84                 if (ot == NULL) {
85                         ot = WM_operatortype_find("WM_OT_tool_set_by_name", false);
86                 }
87                 if (but->optype == ot) {
88                         return true;
89                 }
90         }
91         return false;
92 }
93
94 bool UI_but_has_tooltip_label(const uiBut *but)
95 {
96         if ((but->drawstr[0] == '\0') && !ui_block_is_popover(but->block)) {
97                 return UI_but_is_tool(but);
98         }
99         return false;
100 }
101
102 /** \} */
103
104 /* -------------------------------------------------------------------- */
105 /** \name Block (uiBlock)
106  * \{ */
107
108 bool ui_block_is_menu(const uiBlock *block)
109 {
110         return (((block->flag & UI_BLOCK_LOOP) != 0) &&
111                 /* non-menu popups use keep-open, so check this is off */
112                 ((block->flag & UI_BLOCK_KEEP_OPEN) == 0));
113 }
114
115 bool ui_block_is_popover(const uiBlock *block)
116 {
117         return (block->flag & UI_BLOCK_POPOVER) != 0;
118 }
119
120 bool ui_block_is_pie_menu(const uiBlock *block)
121 {
122         return ((block->flag & UI_BLOCK_RADIAL) != 0);
123 }
124
125 bool ui_block_is_popup_any(const uiBlock *block)
126 {
127         return (
128                 ui_block_is_menu(block) ||
129                 ui_block_is_popover(block) ||
130                 ui_block_is_pie_menu(block)
131         );
132 }
133
134 bool UI_block_is_empty(const uiBlock *block)
135 {
136         for (const uiBut *but = block->buttons.first; but; but = but->next) {
137                 if (!ELEM(but->type, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE)) {
138                         return false;
139                 }
140         }
141         return true;
142 }
143
144 /** \} */