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