4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * The Original Code is Copyright (C) 2009 Blender Foundation.
21 * All rights reserved.
24 * Contributor(s): Blender Foundation
26 * ***** END GPL LICENSE BLOCK *****
29 /** \file blender/makesrna/intern/rna_wm_api.c
37 #include "RNA_define.h"
38 #include "RNA_enum_types.h"
40 #include "DNA_screen_types.h"
41 #include "DNA_space_types.h"
42 #include "DNA_windowmanager_types.h"
46 #include "BKE_context.h"
48 static wmKeyMap *rna_keymap_active(wmKeyMap *km, bContext *C)
50 wmWindowManager *wm = CTX_wm_manager(C);
51 return WM_keymap_active(wm, km);
54 static void rna_keymap_restore_item_to_default(wmKeyMap *km, bContext *C, wmKeyMapItem *kmi)
56 WM_keymap_restore_item_to_default(C, km, kmi);
59 static void rna_Operator_report(wmOperator *op, int type, const char *msg)
61 BKE_report(op->reports, type, msg);
64 /* since event isnt needed... */
65 static void rna_Operator_enum_search_invoke(bContext *C, wmOperator *op)
67 WM_enum_search_invoke(C, op, NULL);
71 static int rna_event_modal_handler_add(struct bContext *C, struct wmOperator *operator)
73 return WM_event_add_modal_handler(C, operator) != NULL;
78 #define WM_GEN_INVOKE_EVENT (1<<0)
79 #define WM_GEN_INVOKE_SIZE (1<<1)
80 #define WM_GEN_INVOKE_RETURN (1<<2)
82 static void rna_generic_op_invoke(FunctionRNA *func, int flag)
86 RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT);
87 parm= RNA_def_pointer(func, "operator", "Operator", "", "Operator to call.");
88 RNA_def_property_flag(parm, PROP_REQUIRED);
90 if(flag & WM_GEN_INVOKE_EVENT) {
91 parm= RNA_def_pointer(func, "event", "Event", "", "Event.");
92 RNA_def_property_flag(parm, PROP_REQUIRED);
95 if(flag & WM_GEN_INVOKE_SIZE) {
96 RNA_def_int(func, "width", 300, 0, INT_MAX, "", "Width of the popup.", 0, INT_MAX);
97 RNA_def_int(func, "height", 20, 0, INT_MAX, "", "Height of the popup.", 0, INT_MAX);
100 if(flag & WM_GEN_INVOKE_RETURN) {
101 parm= RNA_def_enum_flag(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", "");
102 RNA_def_function_return(func, parm);
106 void RNA_api_wm(StructRNA *srna)
111 func= RNA_def_function(srna, "fileselect_add", "WM_event_add_fileselect");
112 RNA_def_function_ui_description(func, "Show up the file selector.");
113 rna_generic_op_invoke(func, 0);
115 func= RNA_def_function(srna, "modal_handler_add", "rna_event_modal_handler_add");
116 RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT);
117 parm= RNA_def_pointer(func, "operator", "Operator", "", "Operator to call.");
118 RNA_def_property_flag(parm, PROP_REQUIRED);
119 RNA_def_function_return(func, RNA_def_boolean(func, "handle", 1, "", ""));
121 /* invoke functions, for use with python */
122 func= RNA_def_function(srna, "invoke_props_popup", "WM_operator_props_popup");
123 RNA_def_function_ui_description(func, "Operator popup invoke.");
124 rna_generic_op_invoke(func, WM_GEN_INVOKE_EVENT|WM_GEN_INVOKE_RETURN);
126 /* invoked dialog opens popup with OK button, does not auto-exec operator. */
127 func= RNA_def_function(srna, "invoke_props_dialog", "WM_operator_props_dialog_popup");
128 RNA_def_function_ui_description(func, "Operator dialog (non-autoexec popup) invoke.");
129 rna_generic_op_invoke(func, WM_GEN_INVOKE_SIZE|WM_GEN_INVOKE_RETURN);
132 func= RNA_def_function(srna, "invoke_search_popup", "rna_Operator_enum_search_invoke");
133 rna_generic_op_invoke(func, 0);
135 /* invoke functions, for use with python */
136 func= RNA_def_function(srna, "invoke_popup", "WM_operator_ui_popup");
137 RNA_def_function_ui_description(func, "Operator popup invoke.");
138 rna_generic_op_invoke(func, WM_GEN_INVOKE_SIZE|WM_GEN_INVOKE_RETURN);
140 func= RNA_def_function(srna, "invoke_confirm", "WM_operator_confirm");
141 RNA_def_function_ui_description(func, "Operator confirmation.");
142 rna_generic_op_invoke(func, WM_GEN_INVOKE_EVENT|WM_GEN_INVOKE_RETURN);
146 void RNA_api_operator(StructRNA *srna)
151 /* utility, not for registering */
152 func= RNA_def_function(srna, "report", "rna_Operator_report");
153 parm= RNA_def_enum_flag(func, "type", wm_report_items, 0, "Type", "");
154 RNA_def_property_flag(parm, PROP_REQUIRED);
155 parm= RNA_def_string(func, "message", "", 0, "Report Message", "");
156 RNA_def_property_flag(parm, PROP_REQUIRED);
162 func= RNA_def_function(srna, "poll", NULL);
163 RNA_def_function_ui_description(func, "Test if the operator can be called or not.");
164 RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_REGISTER_OPTIONAL);
165 RNA_def_function_return(func, RNA_def_boolean(func, "visible", 1, "", ""));
166 parm= RNA_def_pointer(func, "context", "Context", "", "");
167 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
170 func= RNA_def_function(srna, "execute", NULL);
171 RNA_def_function_ui_description(func, "Execute the operator.");
172 RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
173 parm= RNA_def_pointer(func, "context", "Context", "", "");
174 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
176 parm= RNA_def_enum_flag(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name?
177 RNA_def_function_return(func, parm);
180 func= RNA_def_function(srna, "check", NULL);
181 RNA_def_function_ui_description(func, "Check the operator settings.");
182 RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
183 parm= RNA_def_pointer(func, "context", "Context", "", "");
184 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
186 parm= RNA_def_boolean(func, "result", 0, "result", ""); // better name?
187 RNA_def_function_return(func, parm);
190 func= RNA_def_function(srna, "invoke", NULL);
191 RNA_def_function_ui_description(func, "Invoke the operator.");
192 RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
193 parm= RNA_def_pointer(func, "context", "Context", "", "");
194 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
195 parm= RNA_def_pointer(func, "event", "Event", "", "");
196 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
198 parm= RNA_def_enum_flag(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name?
199 RNA_def_function_return(func, parm);
201 func= RNA_def_function(srna, "modal", NULL); /* same as invoke */
202 RNA_def_function_ui_description(func, "Modal operator function.");
203 RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
204 parm= RNA_def_pointer(func, "context", "Context", "", "");
205 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
206 parm= RNA_def_pointer(func, "event", "Event", "", "");
207 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
209 parm= RNA_def_enum_flag(func, "result", operator_return_items, OPERATOR_CANCELLED, "result", ""); // better name?
210 RNA_def_function_return(func, parm);
213 func= RNA_def_function(srna, "draw", NULL);
214 RNA_def_function_ui_description(func, "Draw function for the operator.");
215 RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
216 parm= RNA_def_pointer(func, "context", "Context", "", "");
217 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
220 func= RNA_def_function(srna, "cancel", NULL);
221 RNA_def_function_ui_description(func, "Called when the operator is cancelled.");
222 RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
223 parm= RNA_def_pointer(func, "context", "Context", "", "");
224 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
227 void RNA_api_macro(StructRNA *srna)
232 /* utility, not for registering */
233 func= RNA_def_function(srna, "report", "rna_Operator_report");
234 parm= RNA_def_enum_flag(func, "type", wm_report_items, 0, "Type", "");
235 RNA_def_property_flag(parm, PROP_REQUIRED);
236 parm= RNA_def_string(func, "message", "", 0, "Report Message", "");
237 RNA_def_property_flag(parm, PROP_REQUIRED);
243 func= RNA_def_function(srna, "poll", NULL);
244 RNA_def_function_ui_description(func, "Test if the operator can be called or not.");
245 RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_REGISTER_OPTIONAL);
246 RNA_def_function_return(func, RNA_def_boolean(func, "visible", 1, "", ""));
247 parm= RNA_def_pointer(func, "context", "Context", "", "");
248 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
251 func= RNA_def_function(srna, "draw", NULL);
252 RNA_def_function_ui_description(func, "Draw function for the operator.");
253 RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
254 parm= RNA_def_pointer(func, "context", "Context", "", "");
255 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
258 void RNA_api_keyconfig(StructRNA *srna)
260 // FunctionRNA *func;
261 // PropertyRNA *parm;
264 void RNA_api_keymap(StructRNA *srna)
269 func= RNA_def_function(srna, "active", "rna_keymap_active");
270 RNA_def_function_flag(func, FUNC_USE_CONTEXT);
271 parm= RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Active key map.");
272 RNA_def_function_return(func, parm);
274 func= RNA_def_function(srna, "copy_to_user", "WM_keymap_copy_to_user");
275 parm= RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "User editable key map.");
276 RNA_def_function_return(func, parm);
278 RNA_def_function(srna, "restore_to_default", "WM_keymap_restore_to_default");
280 func= RNA_def_function(srna, "restore_item_to_default", "rna_keymap_restore_item_to_default");
281 RNA_def_function_flag(func, FUNC_USE_CONTEXT);
282 parm= RNA_def_pointer(func, "item", "KeyMapItem", "Item", "");
283 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_NEVER_NULL);
286 void RNA_api_keymapitem(StructRNA *srna)
291 func= RNA_def_function(srna, "compare", "WM_keymap_item_compare");
292 parm= RNA_def_pointer(func, "item", "KeyMapItem", "Item", "");
293 RNA_def_property_flag(parm, PROP_REQUIRED);
294 parm= RNA_def_boolean(func, "result", 0, "Comparison result", "");
295 RNA_def_function_return(func, parm);