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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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 *****
32 #include "RNA_define.h"
33 #include "RNA_types.h"
34 #include "RNA_enum_types.h"
36 #include "DNA_screen_types.h"
37 #include "DNA_space_types.h"
41 #include "BKE_context.h"
46 static wmKeyMap *rna_keymap_add(wmKeyConfig *keyconf, char *idname, int spaceid, int regionid, int modal)
49 return WM_keymap_find(keyconf, idname, spaceid, regionid);
51 return WM_modalkeymap_add(keyconf, idname, NULL); /* items will be lazy init */
55 static wmKeyMap *rna_keymap_find(wmKeyConfig *keyconf, char *idname, int spaceid, int regionid)
57 return WM_keymap_list_find(&keyconf->keymaps, idname, spaceid, regionid);
60 static wmKeyMap *rna_keymap_find_modal(wmKeyConfig *keyconf, char *idname)
62 wmOperatorType *ot = WM_operatortype_find(idname, 0);
67 return ot->modalkeymap;
70 static wmKeyMap *rna_keymap_active(wmKeyMap *km, bContext *C)
72 wmWindowManager *wm = CTX_wm_manager(C);
73 return WM_keymap_active(wm, km);
77 static wmKeyMapItem *rna_KeyMap_add_modal_item(wmKeyMap *km, bContext *C, ReportList *reports, char* propvalue_str, int type, int value, int any, int shift, int ctrl, int alt, int oskey, int keymodifier)
79 wmWindowManager *wm = CTX_wm_manager(C);
84 if ((km->flag & KEYMAP_MODAL) == 0) {
85 BKE_report(reports, RPT_ERROR, "Not a modal keymap.");
89 if (!km->modal_items) {
90 if(!WM_keymap_user_init(wm, km)) {
91 BKE_report(reports, RPT_ERROR, "User defined keymap doesn't correspond to a system keymap.");
96 if (!km->modal_items) {
97 BKE_report(reports, RPT_ERROR, "No property values defined.");
102 if(RNA_enum_value_from_id(km->modal_items, propvalue_str, &propvalue)==0) {
103 BKE_report(reports, RPT_WARNING, "Property value not in enumeration.");
106 if(shift) modifier |= KM_SHIFT;
107 if(ctrl) modifier |= KM_CTRL;
108 if(alt) modifier |= KM_ALT;
109 if(oskey) modifier |= KM_OSKEY;
111 if(any) modifier = KM_ANY;
113 return WM_modalkeymap_add_item(km, type, value, modifier, keymodifier, propvalue);
116 static wmKeyMapItem *rna_KeyMap_add_item(wmKeyMap *km, ReportList *reports, char *idname, int type, int any, int value, int shift, int ctrl, int alt, int oskey, int keymodifier)
118 // wmWindowManager *wm = CTX_wm_manager(C);
121 /* only on non-modal maps */
122 if (km->flag & KEYMAP_MODAL) {
123 BKE_report(reports, RPT_ERROR, "Not a non-modal keymap.");
127 if(shift) modifier |= KM_SHIFT;
128 if(ctrl) modifier |= KM_CTRL;
129 if(alt) modifier |= KM_ALT;
130 if(oskey) modifier |= KM_OSKEY;
132 if(any) modifier = KM_ANY;
134 return WM_keymap_add_item(km, idname, type, value, modifier, keymodifier);
137 static void rna_Operator_report(wmOperator *op, int type, char *msg)
139 BKE_report(op->reports, type, msg);
144 void RNA_api_wm(StructRNA *srna)
149 func= RNA_def_function(srna, "add_fileselect", "WM_event_add_fileselect");
150 RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT);
151 RNA_def_function_ui_description(func, "Show up the file selector.");
152 parm= RNA_def_pointer(func, "operator", "Operator", "", "Operator to call.");
153 RNA_def_property_flag(parm, PROP_REQUIRED);
155 func= RNA_def_function(srna, "add_keyconfig", "WM_keyconfig_add");
156 parm= RNA_def_string(func, "name", "", 0, "Name", "");
157 RNA_def_property_flag(parm, PROP_REQUIRED);
158 parm= RNA_def_pointer(func, "keyconfig", "KeyConfig", "Key Configuration", "Added key configuration.");
159 RNA_def_function_return(func, parm);
161 /* invoke functions, for use with python */
162 func= RNA_def_function(srna, "invoke_props_popup", "WM_operator_props_popup");
163 RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT);
164 RNA_def_function_ui_description(func, "Operator popup invoke.");
165 parm= RNA_def_pointer(func, "operator", "Operator", "", "Operator to call.");
166 RNA_def_property_flag(parm, PROP_REQUIRED);
167 parm= RNA_def_pointer(func, "event", "Event", "", "Event.");
168 RNA_def_property_flag(parm, PROP_REQUIRED);
170 parm= RNA_def_enum(func, "result", operator_return_items, 0, "result", ""); // better name?
171 RNA_def_property_flag(parm, PROP_ENUM_FLAG);
172 RNA_def_function_return(func, parm);
175 /* invoke functions, for use with python */
176 func= RNA_def_function(srna, "invoke_popup", "WM_operator_ui_popup");
177 RNA_def_function_flag(func, FUNC_NO_SELF|FUNC_USE_CONTEXT);
178 RNA_def_function_ui_description(func, "Operator popup invoke.");
179 parm= RNA_def_pointer(func, "operator", "Operator", "", "Operator to call.");
180 RNA_def_property_flag(parm, PROP_REQUIRED);
181 parm= RNA_def_int(func, "width", 300, 0, INT_MAX, "", "Width of the popup.", 0, INT_MAX);
182 parm= RNA_def_int(func, "height", 20, 0, INT_MAX, "", "Height of the popup.", 0, INT_MAX);
185 void RNA_api_operator(StructRNA *srna)
190 func= RNA_def_function(srna, "report", "rna_Operator_report");
191 parm= RNA_def_enum(func, "type", wm_report_items, 0, "Type", "");
192 RNA_def_property_flag(parm, PROP_REQUIRED|PROP_ENUM_FLAG);
193 parm= RNA_def_string(func, "message", "", 0, "Report Message", "");
194 RNA_def_property_flag(parm, PROP_REQUIRED);
197 void RNA_api_keyconfig(StructRNA *srna)
202 func= RNA_def_function(srna, "add_keymap", "rna_keymap_add");
203 parm= RNA_def_string(func, "name", "", 0, "Name", "");
204 RNA_def_property_flag(parm, PROP_REQUIRED);
205 RNA_def_enum(func, "space_type", space_type_items, SPACE_EMPTY, "Space Type", "");
206 RNA_def_enum(func, "region_type", region_type_items, RGN_TYPE_WINDOW, "Region Type", "");
207 RNA_def_boolean(func, "modal", 0, "Modal", "");
208 parm= RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Added key map.");
209 RNA_def_function_return(func, parm);
211 func= RNA_def_function(srna, "find_keymap", "rna_keymap_find");
212 parm= RNA_def_string(func, "name", "", 0, "Name", "");
213 RNA_def_property_flag(parm, PROP_REQUIRED);
214 RNA_def_enum(func, "space_type", space_type_items, SPACE_EMPTY, "Space Type", "");
215 RNA_def_enum(func, "region_type", region_type_items, RGN_TYPE_WINDOW, "Region Type", "");
216 parm= RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Corresponding key map.");
217 RNA_def_function_return(func, parm);
219 func= RNA_def_function(srna, "find_keymap_modal", "rna_keymap_find_modal");
220 parm= RNA_def_string(func, "name", "", 0, "Operator Name", "");
221 RNA_def_property_flag(parm, PROP_REQUIRED);
222 parm= RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Corresponding key map.");
223 RNA_def_function_return(func, parm);
226 void RNA_api_keymap(StructRNA *srna)
231 func= RNA_def_function(srna, "add_item", "rna_KeyMap_add_item");
232 RNA_def_function_flag(func, FUNC_USE_REPORTS);
233 parm= RNA_def_string(func, "idname", "", 0, "Operator Identifier", "");
234 RNA_def_property_flag(parm, PROP_REQUIRED);
235 parm= RNA_def_enum(func, "type", event_type_items, 0, "Type", "");
236 RNA_def_property_flag(parm, PROP_REQUIRED);
237 parm= RNA_def_enum(func, "value", event_value_items, 0, "Value", "");
238 RNA_def_property_flag(parm, PROP_REQUIRED);
239 RNA_def_boolean(func, "any", 0, "Any", "");
240 RNA_def_boolean(func, "shift", 0, "Shift", "");
241 RNA_def_boolean(func, "ctrl", 0, "Ctrl", "");
242 RNA_def_boolean(func, "alt", 0, "Alt", "");
243 RNA_def_boolean(func, "oskey", 0, "OS Key", "");
244 RNA_def_enum(func, "key_modifier", event_type_items, 0, "Key Modifier", "");
245 parm= RNA_def_pointer(func, "item", "KeyMapItem", "Item", "Added key map item.");
246 RNA_def_function_return(func, parm);
248 func= RNA_def_function(srna, "add_modal_item", "rna_KeyMap_add_modal_item");
249 RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
250 parm= RNA_def_string(func, "propvalue", "", 0, "Property Value", "");
251 RNA_def_property_flag(parm, PROP_REQUIRED);
252 parm= RNA_def_enum(func, "type", event_type_items, 0, "Type", "");
253 RNA_def_property_flag(parm, PROP_REQUIRED);
254 parm= RNA_def_enum(func, "value", event_value_items, 0, "Value", "");
255 RNA_def_property_flag(parm, PROP_REQUIRED);
256 RNA_def_boolean(func, "any", 0, "Any", "");
257 RNA_def_boolean(func, "shift", 0, "Shift", "");
258 RNA_def_boolean(func, "ctrl", 0, "Ctrl", "");
259 RNA_def_boolean(func, "alt", 0, "Alt", "");
260 RNA_def_boolean(func, "oskey", 0, "OS Key", "");
261 RNA_def_enum(func, "key_modifier", event_type_items, 0, "Key Modifier", "");
262 parm= RNA_def_pointer(func, "item", "KeyMapItem", "Item", "Added key map item.");
263 RNA_def_function_return(func, parm);
265 func= RNA_def_function(srna, "active", "rna_keymap_active");
266 RNA_def_function_flag(func, FUNC_USE_CONTEXT);
267 parm= RNA_def_pointer(func, "keymap", "KeyMap", "Key Map", "Active key map.");
268 RNA_def_function_return(func, parm);
270 func= RNA_def_function(srna, "remove_item", "WM_keymap_remove_item");
271 parm= RNA_def_pointer(func, "item", "KeyMapItem", "Item", "");
272 RNA_def_property_flag(parm, PROP_REQUIRED);
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 func= RNA_def_function(srna, "restore_to_default", "WM_keymap_restore_to_default");