2 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
18 * Contributor(s): Blender Foundation (2008).
20 * ***** END GPL LICENSE BLOCK *****
23 /** \file blender/makesrna/intern/rna_wm.c
30 #include "RNA_access.h"
31 #include "RNA_define.h"
32 #include "RNA_enum_types.h"
34 #include "rna_internal.h"
36 #include "DNA_screen_types.h"
37 #include "DNA_space_types.h"
38 #include "DNA_userdef_types.h"
39 #include "DNA_windowmanager_types.h"
43 EnumPropertyItem event_keymouse_value_items[] = {
44 {KM_ANY, "ANY", 0, "Any", ""},
45 {KM_PRESS, "PRESS", 0, "Press", ""},
46 {KM_RELEASE, "RELEASE", 0, "Release", ""},
47 {KM_CLICK, "CLICK", 0, "Click", ""},
48 {KM_DBL_CLICK, "DOUBLE_CLICK", 0, "Double Click", ""},
49 {0, NULL, 0, NULL, NULL}
52 EnumPropertyItem event_tweak_value_items[] = {
53 {KM_ANY, "ANY", 0, "Any", ""},
54 {EVT_GESTURE_N, "NORTH", 0, "North", ""},
55 {EVT_GESTURE_NE, "NORTH_EAST", 0, "North-East", ""},
56 {EVT_GESTURE_E, "EAST", 0, "East", ""},
57 {EVT_GESTURE_SE, "SOUTH_EAST", 0, "South-East", ""},
58 {EVT_GESTURE_S, "SOUTH", 0, "South", ""},
59 {EVT_GESTURE_SW, "SOUTH_WEST", 0, "South-West", ""},
60 {EVT_GESTURE_W, "WEST", 0, "West", ""},
61 {EVT_GESTURE_NW, "NORTH_WEST", 0, "North-West", ""},
62 {0, NULL, 0, NULL, NULL}
65 EnumPropertyItem event_value_items[] = {
66 {KM_ANY, "ANY", 0, "Any", ""},
67 {KM_NOTHING, "NOTHING", 0, "Nothing", ""},
68 {KM_PRESS, "PRESS", 0, "Press", ""},
69 {KM_RELEASE, "RELEASE", 0, "Release", ""},
70 {KM_CLICK, "CLICK", 0, "Click", ""},
71 {KM_DBL_CLICK, "DOUBLE_CLICK", 0, "Double Click", ""},
72 {EVT_GESTURE_N, "NORTH", 0, "North", ""},
73 {EVT_GESTURE_NE, "NORTH_EAST", 0, "North-East", ""},
74 {EVT_GESTURE_E, "EAST", 0, "East", ""},
75 {EVT_GESTURE_SE, "SOUTH_EAST", 0, "South-East", ""},
76 {EVT_GESTURE_S, "SOUTH", 0, "South", ""},
77 {EVT_GESTURE_SW, "SOUTH_WEST", 0, "South-West", ""},
78 {EVT_GESTURE_W, "WEST", 0, "West", ""},
79 {EVT_GESTURE_NW, "NORTH_WEST", 0, "North-West", ""},
80 {0, NULL, 0, NULL, NULL}
83 EnumPropertyItem event_tweak_type_items[] = {
84 {EVT_TWEAK_L, "EVT_TWEAK_L", 0, "Left", ""},
85 {EVT_TWEAK_M, "EVT_TWEAK_M", 0, "Middle", ""},
86 {EVT_TWEAK_R, "EVT_TWEAK_R", 0, "Right", ""},
87 {EVT_TWEAK_A, "EVT_TWEAK_A", 0, "Action", ""},
88 {EVT_TWEAK_S, "EVT_TWEAK_S", 0, "Select", ""},
89 {0, NULL, 0, NULL, NULL}
92 EnumPropertyItem event_mouse_type_items[] = {
93 {LEFTMOUSE, "LEFTMOUSE", 0, "Left", ""},
94 {MIDDLEMOUSE, "MIDDLEMOUSE", 0, "Middle", ""},
95 {RIGHTMOUSE, "RIGHTMOUSE", 0, "Right", ""},
96 {BUTTON4MOUSE, "BUTTON4MOUSE", 0, "Button4", ""},
97 {BUTTON5MOUSE, "BUTTON5MOUSE", 0, "Button5", ""},
98 {ACTIONMOUSE, "ACTIONMOUSE", 0, "Action", ""},
99 {SELECTMOUSE, "SELECTMOUSE", 0, "Select", ""},
100 {0, "", 0, NULL, NULL},
101 {MOUSEMOVE, "MOUSEMOVE", 0, "Move", ""},
102 {MOUSEPAN, "TRACKPADPAN", 0, "Mouse/Trackpad Pan", ""},
103 {MOUSEZOOM, "TRACKPADZOOM", 0, "Mouse/Trackpad Zoom", ""},
104 {MOUSEROTATE, "MOUSEROTATE", 0, "Mouse/Trackpad Rotate", ""},
105 {0, "", 0, NULL, NULL},
106 {WHEELUPMOUSE, "WHEELUPMOUSE", 0, "Wheel Up", ""},
107 {WHEELDOWNMOUSE, "WHEELDOWNMOUSE", 0, "Wheel Down", ""},
108 {WHEELINMOUSE, "WHEELINMOUSE", 0, "Wheel In", ""},
109 {WHEELOUTMOUSE, "WHEELOUTMOUSE", 0, "Wheel Out", ""},
110 {0, NULL, 0, NULL, NULL}
113 EnumPropertyItem event_timer_type_items[] = {
114 {TIMER, "TIMER", 0, "Timer", ""},
115 {TIMER0, "TIMER0", 0, "Timer 0", ""},
116 {TIMER1, "TIMER1", 0, "Timer 1", ""},
117 {TIMER2, "TIMER2", 0, "Timer 2", ""},
118 {TIMERJOBS, "TIMER_JOBS", 0, "Timer Jobs", ""},
119 {TIMERAUTOSAVE, "TIMER_AUTOSAVE", 0, "Timer Autosave", ""},
120 {TIMERREPORT, "TIMER_REPORT", 0, "Timer Report", ""},
121 {0, NULL, 0, NULL, NULL}
124 EnumPropertyItem event_ndof_type_items[] = {
125 {NDOF_MOTION, "NDOF_MOTION", 0, "Motion", ""},
126 /* buttons on all 3dconnexion devices */
127 {NDOF_BUTTON_MENU, "NDOF_BUTTON_MENU", 0, "Menu", ""},
128 {NDOF_BUTTON_FIT, "NDOF_BUTTON_FIT", 0, "Fit", ""},
130 {NDOF_BUTTON_TOP, "NDOF_BUTTON_TOP", 0, "Top", ""},
131 {NDOF_BUTTON_BOTTOM, "NDOF_BUTTON_BOTTOM", 0, "Bottom", ""},
132 {NDOF_BUTTON_LEFT, "NDOF_BUTTON_LEFT", 0, "Left", ""},
133 {NDOF_BUTTON_RIGHT, "NDOF_BUTTON_RIGHT", 0, "Right", ""},
134 {NDOF_BUTTON_FRONT, "NDOF_BUTTON_FRONT", 0, "Front", ""},
135 {NDOF_BUTTON_BACK, "NDOF_BUTTON_BACK", 0, "Back", ""},
137 {NDOF_BUTTON_ISO1, "NDOF_BUTTON_ISO1", 0, "Isometric 1", ""},
138 {NDOF_BUTTON_ISO2, "NDOF_BUTTON_ISO2", 0, "Isometric 2", ""},
139 /* 90 degree rotations */
140 {NDOF_BUTTON_ROLL_CW, "NDOF_BUTTON_ROLL_CW", 0, "Roll CW", ""},
141 {NDOF_BUTTON_ROLL_CCW, "NDOF_BUTTON_ROLL_CCW", 0, "Roll CCW", ""},
142 {NDOF_BUTTON_SPIN_CW, "NDOF_BUTTON_SPIN_CW", 0, "Spin CW", ""},
143 {NDOF_BUTTON_SPIN_CCW, "NDOF_BUTTON_SPIN_CCW", 0, "Spin CCW", ""},
144 {NDOF_BUTTON_TILT_CW, "NDOF_BUTTON_TILT_CW", 0, "Tilt CW", ""},
145 {NDOF_BUTTON_TILT_CCW, "NDOF_BUTTON_TILT_CCW", 0, "Tilt CCW", ""},
147 {NDOF_BUTTON_ROTATE, "NDOF_BUTTON_ROTATE", 0, "Rotate", ""},
148 {NDOF_BUTTON_PANZOOM, "NDOF_BUTTON_PANZOOM", 0, "Pan/Zoom", ""},
149 {NDOF_BUTTON_DOMINANT, "NDOF_BUTTON_DOMINANT", 0, "Dominant", ""},
150 {NDOF_BUTTON_PLUS, "NDOF_BUTTON_PLUS", 0, "Plus", ""},
151 {NDOF_BUTTON_MINUS, "NDOF_BUTTON_MINUS", 0, "Minus", ""},
152 /* keyboard emulation */
153 {NDOF_BUTTON_ESC, "NDOF_BUTTON_ESC", 0, "Esc"},
154 {NDOF_BUTTON_ALT, "NDOF_BUTTON_ALT", 0, "Alt"},
155 {NDOF_BUTTON_SHIFT, "NDOF_BUTTON_SHIFT", 0, "Shift"},
156 {NDOF_BUTTON_CTRL, "NDOF_BUTTON_CTRL", 0, "Ctrl"},
157 /* general-purpose buttons */
158 {NDOF_BUTTON_1, "NDOF_BUTTON_1", 0, "Button 1", ""},
159 {NDOF_BUTTON_2, "NDOF_BUTTON_2", 0, "Button 2", ""},
160 {NDOF_BUTTON_3, "NDOF_BUTTON_3", 0, "Button 3", ""},
161 {NDOF_BUTTON_4, "NDOF_BUTTON_4", 0, "Button 4", ""},
162 {NDOF_BUTTON_5, "NDOF_BUTTON_5", 0, "Button 5", ""},
163 {NDOF_BUTTON_6, "NDOF_BUTTON_6", 0, "Button 6", ""},
164 {NDOF_BUTTON_7, "NDOF_BUTTON_7", 0, "Button 7", ""},
165 {NDOF_BUTTON_8, "NDOF_BUTTON_8", 0, "Button 8", ""},
166 {NDOF_BUTTON_9, "NDOF_BUTTON_9", 0, "Button 9", ""},
167 {NDOF_BUTTON_10, "NDOF_BUTTON_10", 0, "Button 10", ""},
168 {NDOF_BUTTON_A, "NDOF_BUTTON_A", 0, "Button A", ""},
169 {NDOF_BUTTON_B, "NDOF_BUTTON_B", 0, "Button B", ""},
170 {NDOF_BUTTON_C, "NDOF_BUTTON_C", 0, "Button C", ""},
171 {0, NULL, 0, NULL, NULL}
174 /* not returned: CAPSLOCKKEY, UNKNOWNKEY */
175 EnumPropertyItem event_type_items[] = {
177 {0, "NONE", 0, "", ""},
178 {LEFTMOUSE, "LEFTMOUSE", 0, "Left Mouse", ""},
179 {MIDDLEMOUSE, "MIDDLEMOUSE", 0, "Middle Mouse", ""},
180 {RIGHTMOUSE, "RIGHTMOUSE", 0, "Right Mouse", ""},
181 {BUTTON4MOUSE, "BUTTON4MOUSE", 0, "Button4 Mouse", ""},
182 {BUTTON5MOUSE, "BUTTON5MOUSE", 0, "Button5 Mouse", ""},
183 {ACTIONMOUSE, "ACTIONMOUSE", 0, "Action Mouse", ""},
184 {SELECTMOUSE, "SELECTMOUSE", 0, "Select Mouse", ""},
185 {0, "", 0, NULL, NULL},
186 {MOUSEMOVE, "MOUSEMOVE", 0, "Mouse Move", ""},
187 {INBETWEEN_MOUSEMOVE, "INBETWEEN_MOUSEMOVE", 0, "In-between Move", ""},
188 {MOUSEPAN, "TRACKPADPAN", 0, "Mouse/Trackpad Pan", ""},
189 {MOUSEZOOM, "TRACKPADZOOM", 0, "Mouse/Trackpad Zoom", ""},
190 {MOUSEROTATE, "MOUSEROTATE", 0, "Mouse/Trackpad Rotate", ""},
191 {0, "", 0, NULL, NULL},
192 {WHEELUPMOUSE, "WHEELUPMOUSE", 0, "Wheel Up", ""},
193 {WHEELDOWNMOUSE, "WHEELDOWNMOUSE", 0, "Wheel Down", ""},
194 {WHEELINMOUSE, "WHEELINMOUSE", 0, "Wheel In", ""},
195 {WHEELOUTMOUSE, "WHEELOUTMOUSE", 0, "Wheel Out", ""},
196 {0, "", 0, NULL, NULL},
197 {EVT_TWEAK_L, "EVT_TWEAK_L", 0, "Tweak Left", ""},
198 {EVT_TWEAK_M, "EVT_TWEAK_M", 0, "Tweak Middle", ""},
199 {EVT_TWEAK_R, "EVT_TWEAK_R", 0, "Tweak Right", ""},
200 {EVT_TWEAK_A, "EVT_TWEAK_A", 0, "Tweak Action", ""},
201 {EVT_TWEAK_S, "EVT_TWEAK_S", 0, "Tweak Select", ""},
202 {0, "", 0, NULL, NULL},
203 {AKEY, "A", 0, "A", ""},
204 {BKEY, "B", 0, "B", ""},
205 {CKEY, "C", 0, "C", ""},
206 {DKEY, "D", 0, "D", ""},
207 {EKEY, "E", 0, "E", ""},
208 {FKEY, "F", 0, "F", ""},
209 {GKEY, "G", 0, "G", ""},
210 {HKEY, "H", 0, "H", ""},
211 {IKEY, "I", 0, "I", ""},
212 {JKEY, "J", 0, "J", ""},
213 {KKEY, "K", 0, "K", ""},
214 {LKEY, "L", 0, "L", ""},
215 {MKEY, "M", 0, "M", ""},
216 {NKEY, "N", 0, "N", ""},
217 {OKEY, "O", 0, "O", ""},
218 {PKEY, "P", 0, "P", ""},
219 {QKEY, "Q", 0, "Q", ""},
220 {RKEY, "R", 0, "R", ""},
221 {SKEY, "S", 0, "S", ""},
222 {TKEY, "T", 0, "T", ""},
223 {UKEY, "U", 0, "U", ""},
224 {VKEY, "V", 0, "V", ""},
225 {WKEY, "W", 0, "W", ""},
226 {XKEY, "X", 0, "X", ""},
227 {YKEY, "Y", 0, "Y", ""},
228 {ZKEY, "Z", 0, "Z", ""},
229 {0, "", 0, NULL, NULL},
230 {ZEROKEY, "ZERO", 0, "0", ""},
231 {ONEKEY, "ONE", 0, "1", ""},
232 {TWOKEY, "TWO", 0, "2", ""},
233 {THREEKEY, "THREE", 0, "3", ""},
234 {FOURKEY, "FOUR", 0, "4", ""},
235 {FIVEKEY, "FIVE", 0, "5", ""},
236 {SIXKEY, "SIX", 0, "6", ""},
237 {SEVENKEY, "SEVEN", 0, "7", ""},
238 {EIGHTKEY, "EIGHT", 0, "8", ""},
239 {NINEKEY, "NINE", 0, "9", ""},
240 {0, "", 0, NULL, NULL},
241 {LEFTCTRLKEY, "LEFT_CTRL", 0, "Left Ctrl", ""},
242 {LEFTALTKEY, "LEFT_ALT", 0, "Left Alt", ""},
243 {LEFTSHIFTKEY, "LEFT_SHIFT", 0, "Left Shift", ""},
244 {RIGHTALTKEY, "RIGHT_ALT", 0, "Right Alt", ""},
245 {RIGHTCTRLKEY, "RIGHT_CTRL", 0, "Right Ctrl", ""},
246 {RIGHTSHIFTKEY, "RIGHT_SHIFT", 0, "Right Shift", ""},
247 {0, "", 0, NULL, NULL},
248 {OSKEY, "OSKEY", 0, "OS Key", ""},
249 {GRLESSKEY, "GRLESS", 0, "Grless", ""},
250 {ESCKEY, "ESC", 0, "Esc", ""},
251 {TABKEY, "TAB", 0, "Tab", ""},
252 {RETKEY, "RET", 0, "Return", ""},
253 {SPACEKEY, "SPACE", 0, "Spacebar", ""},
254 {LINEFEEDKEY, "LINE_FEED", 0, "Line Feed", ""},
255 {BACKSPACEKEY, "BACK_SPACE", 0, "Back Space", ""},
256 {DELKEY, "DEL", 0, "Delete", ""},
257 {SEMICOLONKEY, "SEMI_COLON", 0, ";", ""},
258 {PERIODKEY, "PERIOD", 0, ".", ""},
259 {COMMAKEY, "COMMA", 0, ",", ""},
260 {QUOTEKEY, "QUOTE", 0, "\"", ""},
261 {ACCENTGRAVEKEY, "ACCENT_GRAVE", 0, "`", ""},
262 {MINUSKEY, "MINUS", 0, "-", ""},
263 {SLASHKEY, "SLASH", 0, "/", ""},
264 {BACKSLASHKEY, "BACK_SLASH", 0, "\\", ""},
265 {EQUALKEY, "EQUAL", 0, "=", ""},
266 {LEFTBRACKETKEY, "LEFT_BRACKET", 0, "[", ""},
267 {RIGHTBRACKETKEY, "RIGHT_BRACKET", 0, "]", ""},
268 {LEFTARROWKEY, "LEFT_ARROW", 0, "Left Arrow", ""},
269 {DOWNARROWKEY, "DOWN_ARROW", 0, "Down Arrow", ""},
270 {RIGHTARROWKEY, "RIGHT_ARROW", 0, "Right Arrow", ""},
271 {UPARROWKEY, "UP_ARROW", 0, "Up Arrow", ""},
272 {PAD2, "NUMPAD_2", 0, "Numpad 2", ""},
273 {PAD4, "NUMPAD_4", 0, "Numpad 4", ""},
274 {PAD6, "NUMPAD_6", 0, "Numpad 6", ""},
275 {PAD8, "NUMPAD_8", 0, "Numpad 8", ""},
276 {PAD1, "NUMPAD_1", 0, "Numpad 1", ""},
277 {PAD3, "NUMPAD_3", 0, "Numpad 3", ""},
278 {PAD5, "NUMPAD_5", 0, "Numpad 5", ""},
279 {PAD7, "NUMPAD_7", 0, "Numpad 7", ""},
280 {PAD9, "NUMPAD_9", 0, "Numpad 9", ""},
281 {PADPERIOD, "NUMPAD_PERIOD", 0, "Numpad .", ""},
282 {PADSLASHKEY, "NUMPAD_SLASH", 0, "Numpad /", ""},
283 {PADASTERKEY, "NUMPAD_ASTERIX", 0, "Numpad *", ""},
284 {PAD0, "NUMPAD_0", 0, "Numpad 0", ""},
285 {PADMINUS, "NUMPAD_MINUS", 0, "Numpad -", ""},
286 {PADENTER, "NUMPAD_ENTER", 0, "Numpad Enter", ""},
287 {PADPLUSKEY, "NUMPAD_PLUS", 0, "Numpad +", ""},
288 {F1KEY, "F1", 0, "F1", ""},
289 {F2KEY, "F2", 0, "F2", ""},
290 {F3KEY, "F3", 0, "F3", ""},
291 {F4KEY, "F4", 0, "F4", ""},
292 {F5KEY, "F5", 0, "F5", ""},
293 {F6KEY, "F6", 0, "F6", ""},
294 {F7KEY, "F7", 0, "F7", ""},
295 {F8KEY, "F8", 0, "F8", ""},
296 {F9KEY, "F9", 0, "F9", ""},
297 {F10KEY, "F10", 0, "F10", ""},
298 {F11KEY, "F11", 0, "F11", ""},
299 {F12KEY, "F12", 0, "F12", ""},
300 {F13KEY, "F13", 0, "F13", ""},
301 {F14KEY, "F14", 0, "F14", ""},
302 {F15KEY, "F15", 0, "F15", ""},
303 {F16KEY, "F16", 0, "F16", ""},
304 {F17KEY, "F17", 0, "F17", ""},
305 {F18KEY, "F18", 0, "F18", ""},
306 {F19KEY, "F19", 0, "F19", ""},
307 {PAUSEKEY, "PAUSE", 0, "Pause", ""},
308 {INSERTKEY, "INSERT", 0, "Insert", ""},
309 {HOMEKEY, "HOME", 0, "Home", ""},
310 {PAGEUPKEY, "PAGE_UP", 0, "Page Up", ""},
311 {PAGEDOWNKEY, "PAGE_DOWN", 0, "Page Down", ""},
312 {ENDKEY, "END", 0, "End", ""},
313 {0, "", 0, NULL, NULL},
314 {MEDIAPLAY, "MEDIA_PLAY", 0, "Media Play/Pause", ""},
315 {MEDIASTOP, "MEDIA_STOP", 0, "Media Stop", ""},
316 {MEDIAFIRST, "MEDIA_FIRST", 0, "Media First", ""},
317 {MEDIALAST, "MEDIA_LAST", 0, "Media Last", ""},
318 {0, "", 0, NULL, NULL},
319 {WINDEACTIVATE, "WINDOW_DEACTIVATE", 0, "Window Deactivate", ""},
320 {TIMER, "TIMER", 0, "Timer", ""},
321 {TIMER0, "TIMER0", 0, "Timer 0", ""},
322 {TIMER1, "TIMER1", 0, "Timer 1", ""},
323 {TIMER2, "TIMER2", 0, "Timer 2", ""},
324 {TIMERJOBS, "TIMER_JOBS", 0, "Timer Jobs", ""},
325 {TIMERAUTOSAVE, "TIMER_AUTOSAVE", 0, "Timer Autosave", ""},
326 {TIMERREPORT, "TIMER_REPORT", 0, "Timer Report", ""},
327 {0, "", 0, NULL, NULL},
328 {NDOF_MOTION, "NDOF_MOTION", 0, "NDOF Motion", ""},
329 /* buttons on all 3dconnexion devices */
330 {NDOF_BUTTON_MENU, "NDOF_BUTTON_MENU", 0, "NDOF Menu", ""},
331 {NDOF_BUTTON_FIT, "NDOF_BUTTON_FIT", 0, "NDOF Fit", ""},
333 {NDOF_BUTTON_TOP, "NDOF_BUTTON_TOP", 0, "NDOF Top", ""},
334 {NDOF_BUTTON_BOTTOM, "NDOF_BUTTON_BOTTOM", 0, "NDOF Bottom", ""},
335 {NDOF_BUTTON_LEFT, "NDOF_BUTTON_LEFT", 0, "NDOF Left", ""},
336 {NDOF_BUTTON_RIGHT, "NDOF_BUTTON_RIGHT", 0, "NDOF Right", ""},
337 {NDOF_BUTTON_FRONT, "NDOF_BUTTON_FRONT", 0, "NDOF Front", ""},
338 {NDOF_BUTTON_BACK, "NDOF_BUTTON_BACK", 0, "NDOF Back", ""},
340 {NDOF_BUTTON_ISO1, "NDOF_BUTTON_ISO1", 0, "NDOF Isometric 1", ""},
341 {NDOF_BUTTON_ISO2, "NDOF_BUTTON_ISO2", 0, "NDOF Isometric 2", ""},
342 /* 90 degree rotations */
343 {NDOF_BUTTON_ROLL_CW, "NDOF_BUTTON_ROLL_CW", 0, "NDOF Roll CW", ""},
344 {NDOF_BUTTON_ROLL_CCW, "NDOF_BUTTON_ROLL_CCW", 0, "NDOF Roll CCW", ""},
345 {NDOF_BUTTON_SPIN_CW, "NDOF_BUTTON_SPIN_CW", 0, "NDOF Spin CW", ""},
346 {NDOF_BUTTON_SPIN_CCW, "NDOF_BUTTON_SPIN_CCW", 0, "NDOF Spin CCW", ""},
347 {NDOF_BUTTON_TILT_CW, "NDOF_BUTTON_TILT_CW", 0, "NDOF Tilt CW", ""},
348 {NDOF_BUTTON_TILT_CCW, "NDOF_BUTTON_TILT_CCW", 0, "NDOF Tilt CCW", ""},
350 {NDOF_BUTTON_ROTATE, "NDOF_BUTTON_ROTATE", 0, "NDOF Rotate", ""},
351 {NDOF_BUTTON_PANZOOM, "NDOF_BUTTON_PANZOOM", 0, "NDOF Pan/Zoom", ""},
352 {NDOF_BUTTON_DOMINANT, "NDOF_BUTTON_DOMINANT", 0, "NDOF Dominant", ""},
353 {NDOF_BUTTON_PLUS, "NDOF_BUTTON_PLUS", 0, "NDOF Plus", ""},
354 {NDOF_BUTTON_MINUS, "NDOF_BUTTON_MINUS", 0, "NDOF Minus", ""},
355 /* keyboard emulation */
356 {NDOF_BUTTON_ESC, "NDOF_BUTTON_ESC", 0, "NDOF Esc"},
357 {NDOF_BUTTON_ALT, "NDOF_BUTTON_ALT", 0, "NDOF Alt"},
358 {NDOF_BUTTON_SHIFT, "NDOF_BUTTON_SHIFT", 0, "NDOF Shift"},
359 {NDOF_BUTTON_CTRL, "NDOF_BUTTON_CTRL", 0, "NDOF Ctrl"},
360 /* general-purpose buttons */
361 {NDOF_BUTTON_1, "NDOF_BUTTON_1", 0, "NDOF Button 1", ""},
362 {NDOF_BUTTON_2, "NDOF_BUTTON_2", 0, "NDOF Button 2", ""},
363 {NDOF_BUTTON_3, "NDOF_BUTTON_3", 0, "NDOF Button 3", ""},
364 {NDOF_BUTTON_4, "NDOF_BUTTON_4", 0, "NDOF Button 4", ""},
365 {NDOF_BUTTON_5, "NDOF_BUTTON_5", 0, "NDOF Button 5", ""},
366 {NDOF_BUTTON_6, "NDOF_BUTTON_6", 0, "NDOF Button 6", ""},
367 {NDOF_BUTTON_7, "NDOF_BUTTON_7", 0, "NDOF Button 7", ""},
368 {NDOF_BUTTON_8, "NDOF_BUTTON_8", 0, "NDOF Button 8", ""},
369 {NDOF_BUTTON_9, "NDOF_BUTTON_9", 0, "NDOF Button 9", ""},
370 {NDOF_BUTTON_10, "NDOF_BUTTON_10", 0, "NDOF Button 10", ""},
371 {NDOF_BUTTON_A, "NDOF_BUTTON_A", 0, "NDOF Button A", ""},
372 {NDOF_BUTTON_B, "NDOF_BUTTON_B", 0, "NDOF Button B", ""},
373 {NDOF_BUTTON_C, "NDOF_BUTTON_C", 0, "NDOF Button C", ""},
374 {0, NULL, 0, NULL, NULL}
377 EnumPropertyItem keymap_propvalue_items[] = {
378 {0, "NONE", 0, "", ""},
379 {0, NULL, 0, NULL, NULL}
383 static EnumPropertyItem keymap_modifiers_items[] = {
384 {KM_ANY, "ANY", 0, "Any", ""},
385 {0, "NONE", 0, "None", ""},
386 {1, "FIRST", 0, "First", ""},
387 {2, "SECOND", 0, "Second", ""},
388 {0, NULL, 0, NULL, NULL}
392 EnumPropertyItem operator_flag_items[] = {
393 {OPTYPE_REGISTER, "REGISTER", 0, "Register", "Display in the info window and support the redo toolbar panel"},
394 {OPTYPE_UNDO, "UNDO", 0, "Undo", "Push an undo event (needed for operator redo)"},
395 {OPTYPE_BLOCKING, "BLOCKING", 0, "Blocking", "Block anything else from using the cursor"},
396 {OPTYPE_MACRO, "MACRO", 0, "Macro", "Use to check if an operator is a macro"},
397 {OPTYPE_GRAB_POINTER, "GRAB_POINTER", 0, "Grab Pointer",
398 "Use so the operator grabs the mouse focus, enables wrapping when continuous grab "
400 {OPTYPE_PRESET, "PRESET", 0, "Preset", "Display a preset button with the operators settings"},
401 {OPTYPE_INTERNAL, "INTERNAL", 0, "Internal", "Removes the operator from search results"},
402 {0, NULL, 0, NULL, NULL}
405 EnumPropertyItem operator_return_items[] = {
406 {OPERATOR_RUNNING_MODAL, "RUNNING_MODAL", 0, "Running Modal", "Keep the operator running with blender"},
407 {OPERATOR_CANCELLED, "CANCELLED", 0, "Cancelled", "When no action has been taken, operator exits"},
408 {OPERATOR_FINISHED, "FINISHED", 0, "Finished", "When the operator is complete, operator exits"},
410 {OPERATOR_PASS_THROUGH, "PASS_THROUGH", 0, "Pass Through", "Do nothing and pass the event on"},
411 {0, NULL, 0, NULL, NULL}
415 EnumPropertyItem wm_report_items[] = {
416 {RPT_DEBUG, "DEBUG", 0, "Debug", ""},
417 {RPT_INFO, "INFO", 0, "Info", ""},
418 {RPT_OPERATOR, "OPERATOR", 0, "Operator", ""},
419 {RPT_PROPERTY, "PROPERTY", 0, "Property", ""},
420 {RPT_WARNING, "WARNING", 0, "Warning", ""},
421 {RPT_ERROR, "ERROR", 0, "Error", ""},
422 {RPT_ERROR_INVALID_INPUT, "ERROR_INVALID_INPUT", 0, "Invalid Input", ""},
423 {RPT_ERROR_INVALID_CONTEXT, "ERROR_INVALID_CONTEXT", 0, "Invalid Context", ""},
424 {RPT_ERROR_OUT_OF_MEMORY, "ERROR_OUT_OF_MEMORY", 0, "Out of Memory", ""},
425 {0, NULL, 0, NULL, NULL}
428 #define KMI_TYPE_KEYBOARD 0
429 #define KMI_TYPE_MOUSE 1
430 #define KMI_TYPE_TWEAK 2
431 #define KMI_TYPE_TEXTINPUT 3
432 #define KMI_TYPE_TIMER 4
433 #define KMI_TYPE_NDOF 5
441 #include "BKE_idprop.h"
443 #include "MEM_guardedalloc.h"
445 static wmOperator *rna_OperatorProperties_find_operator(PointerRNA *ptr)
447 wmWindowManager *wm = ptr->id.data;
448 IDProperty *properties = (IDProperty *)ptr->data;
452 for (op = wm->operators.first; op; op = op->next)
453 if (op->properties == properties)
459 static StructRNA *rna_OperatorProperties_refine(PointerRNA *ptr)
461 wmOperator *op = rna_OperatorProperties_find_operator(ptr);
464 return op->type->srna;
469 static IDProperty *rna_OperatorProperties_idprops(PointerRNA *ptr, int create)
471 if (create && !ptr->data) {
472 IDPropertyTemplate val = {0};
473 ptr->data = IDP_New(IDP_GROUP, &val, "RNA_OperatorProperties group");
479 static void rna_Operator_name_get(PointerRNA *ptr, char *value)
481 wmOperator *op = (wmOperator *)ptr->data;
482 strcpy(value, op->type->name);
485 static int rna_Operator_name_length(PointerRNA *ptr)
487 wmOperator *op = (wmOperator *)ptr->data;
488 return strlen(op->type->name);
491 static int rna_Operator_has_reports_get(PointerRNA *ptr)
493 wmOperator *op = (wmOperator *)ptr->data;
494 return (op->reports && op->reports->list.first);
497 static PointerRNA rna_Operator_properties_get(PointerRNA *ptr)
499 wmOperator *op = (wmOperator *)ptr->data;
500 return rna_pointer_inherit_refine(ptr, op->type->srna, op->properties);
503 static PointerRNA rna_OperatorMacro_properties_get(PointerRNA *ptr)
505 wmOperatorTypeMacro *otmacro = (wmOperatorTypeMacro *)ptr->data;
506 wmOperatorType *ot = WM_operatortype_find(otmacro->idname, TRUE);
507 return rna_pointer_inherit_refine(ptr, ot->srna, otmacro->properties);
510 static void rna_Event_ascii_get(PointerRNA *ptr, char *value)
512 wmEvent *event = (wmEvent *)ptr->data;
513 value[0] = event->ascii;
517 static int rna_Event_ascii_length(PointerRNA *ptr)
519 wmEvent *event = (wmEvent *)ptr->data;
520 return (event->ascii) ? 1 : 0;
523 static void rna_Event_unicode_get(PointerRNA *ptr, char *value)
525 /* utf8 buf isn't \0 terminated */
526 wmEvent *event = (wmEvent *)ptr->data;
529 if (event->utf8_buf[0]) {
530 BLI_str_utf8_as_unicode_and_size(event->utf8_buf, &len);
532 memcpy(value, event->utf8_buf, len);
539 static int rna_Event_unicode_length(PointerRNA *ptr)
542 wmEvent *event = (wmEvent *)ptr->data;
543 if (event->utf8_buf[0]) {
544 /* invalid value is checked on assignment so we don't need to account for this */
545 return BLI_str_utf8_size(event->utf8_buf);
552 static void rna_Window_screen_set(PointerRNA *ptr, PointerRNA value)
554 wmWindow *win = (wmWindow *)ptr->data;
556 if (value.data == NULL)
559 /* exception: can't set screens inside of area/region handlers */
560 win->newscreen = value.data;
563 static void rna_Window_screen_update(bContext *C, PointerRNA *ptr)
565 wmWindow *win = (wmWindow *)ptr->data;
567 /* exception: can't set screens inside of area/region handlers,
568 * and must use context so notifier gets to the right window */
569 if (win->newscreen) {
570 WM_event_add_notifier(C, NC_SCREEN | ND_SCREENBROWSE, win->newscreen);
571 win->newscreen = NULL;
575 static PointerRNA rna_KeyMapItem_properties_get(PointerRNA *ptr)
577 wmKeyMapItem *kmi = ptr->data;
582 /*return rna_pointer_inherit_refine(ptr, &RNA_OperatorProperties, op->properties); */
583 return PointerRNA_NULL;
586 static int rna_wmKeyMapItem_map_type_get(PointerRNA *ptr)
588 wmKeyMapItem *kmi = ptr->data;
590 if (ISTIMER(kmi->type)) return KMI_TYPE_TIMER;
591 if (ISKEYBOARD(kmi->type)) return KMI_TYPE_KEYBOARD;
592 if (ISTWEAK(kmi->type)) return KMI_TYPE_TWEAK;
593 if (ISMOUSE(kmi->type)) return KMI_TYPE_MOUSE;
594 if (ISNDOF(kmi->type)) return KMI_TYPE_NDOF;
595 if (kmi->type == KM_TEXTINPUT) return KMI_TYPE_TEXTINPUT;
596 return KMI_TYPE_KEYBOARD;
599 static void rna_wmKeyMapItem_map_type_set(PointerRNA *ptr, int value)
601 wmKeyMapItem *kmi = ptr->data;
602 int map_type = rna_wmKeyMapItem_map_type_get(ptr);
604 if (value != map_type) {
606 case KMI_TYPE_KEYBOARD:
611 kmi->type = EVT_TWEAK_L;
615 kmi->type = LEFTMOUSE;
618 case KMI_TYPE_TEXTINPUT:
619 kmi->type = KM_TEXTINPUT;
620 kmi->val = KM_NOTHING;
624 kmi->val = KM_NOTHING;
627 kmi->type = NDOF_MOTION;
628 kmi->val = KM_NOTHING;
634 /* assumes value to be an enum from event_type_items */
635 /* function makes sure keymodifiers are only valid keys, ESC keeps it unaltered */
636 static void rna_wmKeyMapItem_keymodifier_set(PointerRNA *ptr, int value)
638 wmKeyMapItem *kmi = ptr->data;
640 /* XXX, this should really be managed in an _itemf function,
641 * giving a list of valid enums, then silently changing them when they are set is not
642 * a good precedent, don't do this unless you have a good reason! */
643 if (value == ESCKEY) {
646 else if (value >= AKEY) {
647 kmi->keymodifier = value;
650 kmi->keymodifier = 0;
655 static EnumPropertyItem *rna_KeyMapItem_type_itemf(bContext *UNUSED(C), PointerRNA *ptr, PropertyRNA *UNUSED(prop),
658 int map_type = rna_wmKeyMapItem_map_type_get(ptr);
660 if (map_type == KMI_TYPE_MOUSE) return event_mouse_type_items;
661 if (map_type == KMI_TYPE_TWEAK) return event_tweak_type_items;
662 if (map_type == KMI_TYPE_TIMER) return event_timer_type_items;
663 if (map_type == KMI_TYPE_NDOF) return event_ndof_type_items;
664 else return event_type_items;
667 static EnumPropertyItem *rna_KeyMapItem_value_itemf(bContext *UNUSED(C), PointerRNA *ptr, PropertyRNA *UNUSED(prop),
670 int map_type = rna_wmKeyMapItem_map_type_get(ptr);
672 if (map_type == KMI_TYPE_MOUSE || map_type == KMI_TYPE_KEYBOARD || map_type == KMI_TYPE_NDOF)
673 return event_keymouse_value_items;
674 if (map_type == KMI_TYPE_TWEAK)
675 return event_tweak_value_items;
677 return event_value_items;
680 static EnumPropertyItem *rna_KeyMapItem_propvalue_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop),
683 wmWindowManager *wm = CTX_wm_manager(C);
687 for (kc = wm->keyconfigs.first; kc; kc = kc->next) {
688 for (km = kc->keymaps.first; km; km = km->next) {
689 /* only check if it's a modal keymap */
690 if (km->modal_items) {
692 for (kmi = km->items.first; kmi; kmi = kmi->next) {
693 if (kmi == ptr->data) {
694 return km->modal_items;
702 return keymap_propvalue_items; /* ERROR */
705 static int rna_KeyMapItem_any_getf(PointerRNA *ptr)
707 wmKeyMapItem *kmi = (wmKeyMapItem *)ptr->data;
709 if (kmi->shift == KM_ANY &&
710 kmi->ctrl == KM_ANY &&
711 kmi->alt == KM_ANY &&
712 kmi->oskey == KM_ANY)
721 static void rna_KeyMapItem_any_setf(PointerRNA *ptr, int value)
723 wmKeyMapItem *kmi = (wmKeyMapItem *)ptr->data;
726 kmi->shift = kmi->ctrl = kmi->alt = kmi->oskey = KM_ANY;
729 kmi->shift = kmi->ctrl = kmi->alt = kmi->oskey = 0;
734 static PointerRNA rna_WindowManager_active_keyconfig_get(PointerRNA *ptr)
736 wmWindowManager *wm = ptr->data;
739 for (kc = wm->keyconfigs.first; kc; kc = kc->next)
740 if (strcmp(kc->idname, U.keyconfigstr) == 0)
744 kc = wm->defaultconf;
746 return rna_pointer_inherit_refine(ptr, &RNA_KeyConfig, kc);
749 static void rna_WindowManager_active_keyconfig_set(PointerRNA *ptr, PointerRNA value)
751 wmWindowManager *wm = ptr->data;
752 wmKeyConfig *kc = value.data;
755 WM_keyconfig_set_active(wm, kc->idname);
758 static void rna_wmKeyMapItem_idname_get(PointerRNA *ptr, char *value)
760 wmKeyMapItem *kmi = ptr->data;
761 WM_operator_py_idname(value, kmi->idname);
764 static int rna_wmKeyMapItem_idname_length(PointerRNA *ptr)
766 wmKeyMapItem *kmi = ptr->data;
767 char pyname[OP_MAX_TYPENAME];
769 WM_operator_py_idname(pyname, kmi->idname);
770 return strlen(pyname);
773 static void rna_wmKeyMapItem_idname_set(PointerRNA *ptr, const char *value)
775 wmKeyMapItem *kmi = ptr->data;
776 char idname[OP_MAX_TYPENAME];
778 WM_operator_bl_idname(idname, value);
780 if (strcmp(idname, kmi->idname) != 0) {
781 BLI_strncpy(kmi->idname, idname, sizeof(kmi->idname));
783 WM_keymap_properties_reset(kmi, NULL);
787 static void rna_wmKeyMapItem_name_get(PointerRNA *ptr, char *value)
789 wmKeyMapItem *kmi = ptr->data;
790 wmOperatorType *ot = WM_operatortype_find(kmi->idname, 1);
791 strcpy(value, ot ? RNA_struct_ui_name(ot->srna) : kmi->idname);
794 static int rna_wmKeyMapItem_name_length(PointerRNA *ptr)
796 wmKeyMapItem *kmi = ptr->data;
797 wmOperatorType *ot = WM_operatortype_find(kmi->idname, 1);
798 return strlen(ot ? RNA_struct_ui_name(ot->srna) : kmi->idname);
801 static int rna_KeyMapItem_userdefined_get(PointerRNA *ptr)
803 wmKeyMapItem *kmi = ptr->data;
807 static void rna_wmClipboard_get(PointerRNA *UNUSED(ptr), char *value)
811 pbuf = WM_clipboard_text_get(FALSE);
821 static int rna_wmClipboard_length(PointerRNA *UNUSED(ptr))
826 pbuf = WM_clipboard_text_get(FALSE);
828 length = strlen(pbuf);
839 static void rna_wmClipboard_set(PointerRNA *UNUSED(ptr), const char *value)
841 WM_clipboard_text_set((void *) value, FALSE);
845 static void rna_Operator_unregister(struct Main *bmain, StructRNA *type)
848 wmOperatorType *ot = RNA_struct_blender_type_get(type);
854 /* update while blender is running */
855 wm = bmain->wm.first;
857 WM_operator_stack_clear(wm);
858 WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL);
860 RNA_struct_free_extension(type, &ot->ext);
863 WM_operatortype_remove(ot->idname);
864 MEM_freeN((void *)idname);
866 /* not to be confused with the RNA_struct_free that WM_operatortype_remove calls, they are 2 different srna's */
867 RNA_struct_free(&BLENDER_RNA, type);
870 static int operator_poll(bContext *C, wmOperatorType *ot)
872 extern FunctionRNA rna_Operator_poll_func;
880 RNA_pointer_create(NULL, ot->ext.srna, NULL, &ptr); /* dummy */
881 func = &rna_Operator_poll_func; /* RNA_struct_find_function(&ptr, "poll"); */
883 RNA_parameter_list_create(&list, &ptr, func);
884 RNA_parameter_set_lookup(&list, "context", &C);
885 ot->ext.call(C, &ptr, func, &list);
887 RNA_parameter_get_lookup(&list, "visible", &ret);
888 visible = *(int *)ret;
890 RNA_parameter_list_free(&list);
895 static int operator_execute(bContext *C, wmOperator *op)
897 extern FunctionRNA rna_Operator_execute_func;
905 RNA_pointer_create(NULL, op->type->ext.srna, op, &opr);
906 func = &rna_Operator_execute_func; /* RNA_struct_find_function(&opr, "execute"); */
908 RNA_parameter_list_create(&list, &opr, func);
909 RNA_parameter_set_lookup(&list, "context", &C);
910 op->type->ext.call(C, &opr, func, &list);
912 RNA_parameter_get_lookup(&list, "result", &ret);
913 result = *(int *)ret;
915 RNA_parameter_list_free(&list);
920 /* same as execute() but no return value */
921 static int operator_check(bContext *C, wmOperator *op)
923 extern FunctionRNA rna_Operator_check_func;
931 RNA_pointer_create(NULL, op->type->ext.srna, op, &opr);
932 func = &rna_Operator_check_func; /* RNA_struct_find_function(&opr, "check"); */
934 RNA_parameter_list_create(&list, &opr, func);
935 RNA_parameter_set_lookup(&list, "context", &C);
936 op->type->ext.call(C, &opr, func, &list);
938 RNA_parameter_get_lookup(&list, "result", &ret);
939 result = *(int *)ret;
941 RNA_parameter_list_free(&list);
946 static int operator_invoke(bContext *C, wmOperator *op, wmEvent *event)
948 extern FunctionRNA rna_Operator_invoke_func;
956 RNA_pointer_create(NULL, op->type->ext.srna, op, &opr);
957 func = &rna_Operator_invoke_func; /* RNA_struct_find_function(&opr, "invoke"); */
959 RNA_parameter_list_create(&list, &opr, func);
960 RNA_parameter_set_lookup(&list, "context", &C);
961 RNA_parameter_set_lookup(&list, "event", &event);
962 op->type->ext.call(C, &opr, func, &list);
964 RNA_parameter_get_lookup(&list, "result", &ret);
965 result = *(int *)ret;
967 RNA_parameter_list_free(&list);
973 static int operator_modal(bContext *C, wmOperator *op, wmEvent *event)
975 extern FunctionRNA rna_Operator_modal_func;
983 RNA_pointer_create(NULL, op->type->ext.srna, op, &opr);
984 func = &rna_Operator_modal_func; /* RNA_struct_find_function(&opr, "modal"); */
986 RNA_parameter_list_create(&list, &opr, func);
987 RNA_parameter_set_lookup(&list, "context", &C);
988 RNA_parameter_set_lookup(&list, "event", &event);
989 op->type->ext.call(C, &opr, func, &list);
991 RNA_parameter_get_lookup(&list, "result", &ret);
992 result = *(int *)ret;
994 RNA_parameter_list_free(&list);
999 static void operator_draw(bContext *C, wmOperator *op)
1001 extern FunctionRNA rna_Operator_draw_func;
1007 RNA_pointer_create(NULL, op->type->ext.srna, op, &opr);
1008 func = &rna_Operator_draw_func; /* RNA_struct_find_function(&opr, "draw"); */
1010 RNA_parameter_list_create(&list, &opr, func);
1011 RNA_parameter_set_lookup(&list, "context", &C);
1012 op->type->ext.call(C, &opr, func, &list);
1014 RNA_parameter_list_free(&list);
1017 /* same as exec(), but call cancel */
1018 static int operator_cancel(bContext *C, wmOperator *op)
1020 extern FunctionRNA rna_Operator_cancel_func;
1028 RNA_pointer_create(NULL, op->type->ext.srna, op, &opr);
1029 func = &rna_Operator_cancel_func; /* RNA_struct_find_function(&opr, "cancel"); */
1031 RNA_parameter_list_create(&list, &opr, func);
1032 RNA_parameter_set_lookup(&list, "context", &C);
1033 op->type->ext.call(C, &opr, func, &list);
1035 RNA_parameter_get_lookup(&list, "result", &ret);
1036 result = *(int *)ret;
1038 RNA_parameter_list_free(&list);
1043 void operator_wrapper(wmOperatorType *ot, void *userdata);
1044 void macro_wrapper(wmOperatorType *ot, void *userdata);
1046 static char _operator_idname[OP_MAX_TYPENAME];
1047 static char _operator_name[OP_MAX_TYPENAME];
1048 static char _operator_descr[RNA_DYN_DESCR_MAX];
1049 static StructRNA *rna_Operator_register(Main *bmain, ReportList *reports, void *data, const char *identifier,
1050 StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
1052 wmOperatorType dummyot = {NULL};
1053 wmOperator dummyop = {NULL};
1054 PointerRNA dummyotr;
1055 int have_function[7];
1057 /* setup dummy operator & operator type to store static properties in */
1058 dummyop.type = &dummyot;
1059 dummyot.idname = _operator_idname; /* only assigne the pointer, string is NULL'd */
1060 dummyot.name = _operator_name; /* only assigne the pointer, string is NULL'd */
1061 dummyot.description = _operator_descr; /* only assigne the pointer, string is NULL'd */
1062 RNA_pointer_create(NULL, &RNA_Operator, &dummyop, &dummyotr);
1064 /* clear in case they are left unset */
1065 _operator_idname[0] = _operator_name[0] = _operator_descr[0] = '\0';
1067 /* validate the python class */
1068 if (validate(&dummyotr, data, have_function) != 0)
1071 { /* convert foo.bar to FOO_OT_bar
1072 * allocate the description and the idname in 1 go */
1074 /* inconveniently long name sanity check */
1076 char *ch = _operator_idname;
1079 for (i = 0; *ch; i++) {
1080 if ((*ch >= 'a' && *ch <= 'z') || (*ch >= '0' && *ch <= '9') || *ch == '_') {
1083 else if (*ch == '.') {
1087 BKE_reportf(reports, RPT_ERROR,
1088 "Registering operator class: '%s', invalid bl_idname '%s', at position %d",
1089 identifier, _operator_idname, i);
1096 if (i > ((int)sizeof(dummyop.idname)) - 3) {
1097 BKE_reportf(reports, RPT_ERROR, "Registering operator class: '%s', invalid bl_idname '%s', "
1098 "is too long, maximum length is %d", identifier, _operator_idname,
1099 (int)sizeof(dummyop.idname) - 3);
1104 BKE_reportf(reports, RPT_ERROR,
1105 "Registering operator class: '%s', invalid bl_idname '%s', must contain 1 '.' character",
1106 identifier, _operator_idname);
1110 /* end sanity check */
1113 int idlen = strlen(_operator_idname) + 4;
1114 int namelen = strlen(_operator_name) + 1;
1115 int desclen = strlen(_operator_descr) + 1;
1117 /* 2 terminators and 3 to convert a.b -> A_OT_b */
1118 ch = MEM_callocN(sizeof(char) * (idlen + namelen + desclen), "_operator_idname");
1119 WM_operator_bl_idname(ch, _operator_idname); /* convert the idname from python */
1120 dummyot.idname = ch;
1122 strcpy(ch, _operator_name);
1125 strcpy(ch, _operator_descr);
1126 dummyot.description = ch;
1130 /* check if we have registered this operator type before, and remove it */
1132 wmOperatorType *ot = WM_operatortype_find(dummyot.idname, TRUE);
1133 if (ot && ot->ext.srna)
1134 rna_Operator_unregister(bmain, ot->ext.srna);
1137 /* XXX, this doubles up with the operator name [#29666]
1138 * for now just remove from dir(bpy.types) */
1140 /* create a new operator type */
1141 dummyot.ext.srna = RNA_def_struct(&BLENDER_RNA, dummyot.idname, "Operator");
1142 RNA_def_struct_flag(dummyot.ext.srna, STRUCT_NO_IDPROPERTIES); /* operator properties are registered separately */
1143 dummyot.ext.data = data;
1144 dummyot.ext.call = call;
1145 dummyot.ext.free = free;
1147 dummyot.pyop_poll = (have_function[0]) ? operator_poll : NULL;
1148 dummyot.exec = (have_function[1]) ? operator_execute : NULL;
1149 dummyot.check = (have_function[2]) ? operator_check : NULL;
1150 dummyot.invoke = (have_function[3]) ? operator_invoke : NULL;
1151 dummyot.modal = (have_function[4]) ? operator_modal : NULL;
1152 dummyot.ui = (have_function[5]) ? operator_draw : NULL;
1153 dummyot.cancel = (have_function[6]) ? operator_cancel : NULL;
1154 WM_operatortype_append_ptr(operator_wrapper, (void *)&dummyot);
1156 /* update while blender is running */
1157 WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL);
1159 return dummyot.ext.srna;
1162 static void **rna_Operator_instance(PointerRNA *ptr)
1164 wmOperator *op = ptr->data;
1165 return &op->py_instance;
1168 static StructRNA *rna_MacroOperator_register(Main *bmain, ReportList *reports, void *data, const char *identifier,
1169 StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
1171 wmOperatorType dummyot = {NULL};
1172 wmOperator dummyop = {NULL};
1173 PointerRNA dummyotr;
1174 int have_function[4];
1176 /* setup dummy operator & operator type to store static properties in */
1177 dummyop.type = &dummyot;
1178 dummyot.idname = _operator_idname; /* only assigne the pointer, string is NULL'd */
1179 dummyot.name = _operator_name; /* only assigne the pointer, string is NULL'd */
1180 dummyot.description = _operator_descr; /* only assigne the pointer, string is NULL'd */
1181 RNA_pointer_create(NULL, &RNA_Macro, &dummyop, &dummyotr);
1183 /* validate the python class */
1184 if (validate(&dummyotr, data, have_function) != 0)
1187 { /* convert foo.bar to FOO_OT_bar
1188 * allocate the description and the idname in 1 go */
1189 int idlen = strlen(_operator_idname) + 4;
1190 int namelen = strlen(_operator_name) + 1;
1191 int desclen = strlen(_operator_descr) + 1;
1193 /* 2 terminators and 3 to convert a.b -> A_OT_b */
1194 ch = MEM_callocN(sizeof(char) * (idlen + namelen + desclen), "_operator_idname");
1195 WM_operator_bl_idname(ch, _operator_idname); /* convert the idname from python */
1196 dummyot.idname = ch;
1198 strcpy(ch, _operator_name);
1201 strcpy(ch, _operator_descr);
1202 dummyot.description = ch;
1205 if (strlen(identifier) >= sizeof(dummyop.idname)) {
1206 BKE_reportf(reports, RPT_ERROR, "Registering operator class: '%s' is too long, maximum length is %d",
1207 identifier, (int)sizeof(dummyop.idname));
1211 /* check if we have registered this operator type before, and remove it */
1213 wmOperatorType *ot = WM_operatortype_find(dummyot.idname, TRUE);
1214 if (ot && ot->ext.srna)
1215 rna_Operator_unregister(bmain, ot->ext.srna);
1218 /* XXX, this doubles up with the operator name [#29666]
1219 * for now just remove from dir(bpy.types) */
1221 /* create a new operator type */
1222 dummyot.ext.srna = RNA_def_struct(&BLENDER_RNA, dummyot.idname, "Operator");
1223 dummyot.ext.data = data;
1224 dummyot.ext.call = call;
1225 dummyot.ext.free = free;
1227 dummyot.pyop_poll = (have_function[0]) ? operator_poll : NULL;
1228 dummyot.ui = (have_function[3]) ? operator_draw : NULL;
1230 WM_operatortype_append_macro_ptr(macro_wrapper, (void *)&dummyot);
1232 /* update while blender is running */
1233 WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL);
1235 return dummyot.ext.srna;
1237 #endif /* WITH_PYTHON */
1239 static StructRNA *rna_Operator_refine(PointerRNA *opr)
1241 wmOperator *op = (wmOperator *)opr->data;
1242 return (op->type && op->type->ext.srna) ? op->type->ext.srna : &RNA_Operator;
1245 static StructRNA *rna_MacroOperator_refine(PointerRNA *opr)
1247 wmOperator *op = (wmOperator *)opr->data;
1248 return (op->type && op->type->ext.srna) ? op->type->ext.srna : &RNA_Macro;
1251 /* just to work around 'const char *' warning and to ensure this is a python op */
1252 static void rna_Operator_bl_idname_set(PointerRNA *ptr, const char *value)
1254 wmOperator *data = (wmOperator *)(ptr->data);
1255 char *str = (char *)data->type->idname;
1257 BLI_strncpy(str, value, OP_MAX_TYPENAME); /* utf8 already ensured */
1259 assert(!"setting the bl_idname on a non-builtin operator");
1262 static void rna_Operator_bl_label_set(PointerRNA *ptr, const char *value)
1264 wmOperator *data = (wmOperator *)(ptr->data);
1265 char *str = (char *)data->type->name;
1267 BLI_strncpy(str, value, OP_MAX_TYPENAME); /* utf8 already ensured */
1269 assert(!"setting the bl_label on a non-builtin operator");
1272 static void rna_Operator_bl_description_set(PointerRNA *ptr, const char *value)
1274 wmOperator *data = (wmOperator *)(ptr->data);
1275 char *str = (char *)data->type->description;
1277 BLI_strncpy(str, value, RNA_DYN_DESCR_MAX); /* utf8 already ensured */
1279 assert(!"setting the bl_description on a non-builtin operator");
1282 static void rna_KeyMapItem_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
1284 wmKeyMapItem *kmi = ptr->data;
1285 WM_keyconfig_update_tag(NULL, kmi);
1288 #else /* RNA_RUNTIME */
1290 static void rna_def_operator(BlenderRNA *brna)
1295 srna = RNA_def_struct(brna, "Operator", NULL);
1296 RNA_def_struct_ui_text(srna, "Operator", "Storage of an operator being executed, or registered after execution");
1297 RNA_def_struct_sdna(srna, "wmOperator");
1298 RNA_def_struct_refine_func(srna, "rna_Operator_refine");
1300 RNA_def_struct_register_funcs(srna, "rna_Operator_register", "rna_Operator_unregister", "rna_Operator_instance");
1303 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
1304 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1305 RNA_def_property_string_funcs(prop, "rna_Operator_name_get", "rna_Operator_name_length", NULL);
1306 RNA_def_property_ui_text(prop, "Name", "");
1308 prop = RNA_def_property(srna, "properties", PROP_POINTER, PROP_NONE);
1309 RNA_def_property_flag(prop, PROP_NEVER_NULL);
1310 RNA_def_property_struct_type(prop, "OperatorProperties");
1311 RNA_def_property_ui_text(prop, "Properties", "");
1312 RNA_def_property_pointer_funcs(prop, "rna_Operator_properties_get", NULL, NULL, NULL);
1314 prop = RNA_def_property(srna, "has_reports", PROP_BOOLEAN, PROP_NONE);
1315 RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* this is 'virtual' property */
1316 RNA_def_property_boolean_funcs(prop, "rna_Operator_has_reports_get", NULL);
1317 RNA_def_property_ui_text(prop, "Has Reports",
1318 "Operator has a set of reports (warnings and errors) from last execution");
1320 prop = RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE);
1321 RNA_def_property_struct_type(prop, "UILayout");
1324 prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
1325 RNA_def_property_string_sdna(prop, NULL, "type->idname");
1326 /* else it uses the pointer size!. -3 because '.' -> '_OT_' */
1327 RNA_def_property_string_maxlength(prop, OP_MAX_TYPENAME - 3);
1328 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_idname_set");
1329 /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
1330 RNA_def_property_flag(prop, PROP_REGISTER | PROP_NEVER_CLAMP);
1331 RNA_def_struct_name_property(srna, prop);
1333 /* operator's label indeed doesn't need PROP_TRANSLATE flag: translation of label happens in runtime
1334 * when drawing panel and having this flag set will make runtime switching of language much more tricky
1335 * because label will be stored translated */
1336 prop = RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
1337 RNA_def_property_string_sdna(prop, NULL, "type->name");
1338 RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */
1339 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_label_set");
1340 /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
1341 RNA_def_property_flag(prop, PROP_REGISTER);
1343 prop = RNA_def_property(srna, "bl_description", PROP_STRING, PROP_TRANSLATE);
1344 RNA_def_property_string_sdna(prop, NULL, "type->description");
1345 RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */
1346 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_description_set");
1347 /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
1348 RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
1349 RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for NULL */
1351 prop = RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE);
1352 RNA_def_property_enum_sdna(prop, NULL, "type->flag");
1353 RNA_def_property_enum_items(prop, operator_flag_items);
1354 RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL | PROP_ENUM_FLAG);
1355 RNA_def_property_ui_text(prop, "Options", "Options for this operator type");
1357 RNA_api_operator(srna);
1359 srna = RNA_def_struct(brna, "OperatorProperties", NULL);
1360 RNA_def_struct_ui_text(srna, "Operator Properties", "Input properties of an Operator");
1361 RNA_def_struct_refine_func(srna, "rna_OperatorProperties_refine");
1362 RNA_def_struct_idprops_func(srna, "rna_OperatorProperties_idprops");
1365 static void rna_def_macro_operator(BlenderRNA *brna)
1370 srna = RNA_def_struct(brna, "Macro", NULL);
1371 RNA_def_struct_ui_text(srna, "Macro Operator",
1372 "Storage of a macro operator being executed, or registered after execution");
1373 RNA_def_struct_sdna(srna, "wmOperator");
1374 RNA_def_struct_refine_func(srna, "rna_MacroOperator_refine");
1376 RNA_def_struct_register_funcs(srna, "rna_MacroOperator_register", "rna_Operator_unregister",
1377 "rna_Operator_instance");
1380 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
1381 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1382 RNA_def_property_string_funcs(prop, "rna_Operator_name_get", "rna_Operator_name_length", NULL);
1383 RNA_def_property_ui_text(prop, "Name", "");
1385 prop = RNA_def_property(srna, "properties", PROP_POINTER, PROP_NONE);
1386 RNA_def_property_flag(prop, PROP_NEVER_NULL);
1387 RNA_def_property_struct_type(prop, "OperatorProperties");
1388 RNA_def_property_ui_text(prop, "Properties", "");
1389 RNA_def_property_pointer_funcs(prop, "rna_Operator_properties_get", NULL, NULL, NULL);
1392 prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
1393 RNA_def_property_string_sdna(prop, NULL, "type->idname");
1394 RNA_def_property_string_maxlength(prop, OP_MAX_TYPENAME); /* else it uses the pointer size! */
1395 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_idname_set");
1396 /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
1397 RNA_def_property_flag(prop, PROP_REGISTER | PROP_NEVER_CLAMP);
1398 RNA_def_struct_name_property(srna, prop);
1400 /* menu's label indeed doesn't need PROP_TRANSLATE flag: translation of label happens in runtime
1401 * when drawing panel and having this flag set will make runtime switching of language much more tricky
1402 * because label will be stored translated */
1403 prop = RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
1404 RNA_def_property_string_sdna(prop, NULL, "type->name");
1405 RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */
1406 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_label_set");
1407 /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
1408 RNA_def_property_flag(prop, PROP_REGISTER);
1410 prop = RNA_def_property(srna, "bl_description", PROP_STRING, PROP_TRANSLATE);
1411 RNA_def_property_string_sdna(prop, NULL, "type->description");
1412 RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */
1413 RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_description_set");
1414 /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
1415 RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
1416 RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for NULL */
1418 prop = RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE);
1419 RNA_def_property_enum_sdna(prop, NULL, "type->flag");
1420 RNA_def_property_enum_items(prop, operator_flag_items);
1421 RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL | PROP_ENUM_FLAG);
1422 RNA_def_property_ui_text(prop, "Options", "Options for this operator type");
1424 RNA_api_macro(srna);
1427 static void rna_def_operator_type_macro(BlenderRNA *brna)
1432 srna = RNA_def_struct(brna, "OperatorMacro", NULL);
1433 RNA_def_struct_ui_text(srna, "Operator Macro", "Storage of a sub operator in a macro after it has been added");
1434 RNA_def_struct_sdna(srna, "wmOperatorTypeMacro");
1436 /* prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); */
1437 /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
1438 /* RNA_def_property_string_sdna(prop, NULL, "idname"); */
1439 /* RNA_def_property_ui_text(prop, "Name", "Name of the sub operator"); */
1440 /* RNA_def_struct_name_property(srna, prop); */
1442 prop = RNA_def_property(srna, "properties", PROP_POINTER, PROP_NONE);
1443 RNA_def_property_flag(prop, PROP_NEVER_NULL);
1444 RNA_def_property_struct_type(prop, "OperatorProperties");
1445 RNA_def_property_ui_text(prop, "Properties", "");
1446 RNA_def_property_pointer_funcs(prop, "rna_OperatorMacro_properties_get", NULL, NULL, NULL);
1449 static void rna_def_operator_utils(BlenderRNA *brna)
1454 srna = RNA_def_struct(brna, "OperatorMousePath", "PropertyGroup");
1455 RNA_def_struct_ui_text(srna, "Operator Mouse Path", "Mouse path values for operators that record such paths");
1457 prop = RNA_def_property(srna, "loc", PROP_FLOAT, PROP_XYZ);
1458 RNA_def_property_flag(prop, PROP_IDPROPERTY);
1459 RNA_def_property_array(prop, 2);
1460 RNA_def_property_ui_text(prop, "Location", "Mouse location");
1462 prop = RNA_def_property(srna, "time", PROP_FLOAT, PROP_NONE);
1463 RNA_def_property_flag(prop, PROP_IDPROPERTY);
1464 RNA_def_property_ui_text(prop, "Time", "Time of mouse location");
1467 static void rna_def_operator_filelist_element(BlenderRNA *brna)
1472 srna = RNA_def_struct(brna, "OperatorFileListElement", "PropertyGroup");
1473 RNA_def_struct_ui_text(srna, "Operator File List Element", "");
1476 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_FILENAME);
1477 RNA_def_property_flag(prop, PROP_IDPROPERTY);
1478 RNA_def_property_ui_text(prop, "Name", "Name of a file or directory within a file list");
1481 static void rna_def_event(BlenderRNA *brna)
1486 srna = RNA_def_struct(brna, "Event", NULL);
1487 RNA_def_struct_ui_text(srna, "Event", "Window Manager Event");
1488 RNA_def_struct_sdna(srna, "wmEvent");
1490 RNA_define_verify_sdna(0); /* not in sdna */
1493 prop = RNA_def_property(srna, "ascii", PROP_STRING, PROP_NONE);
1494 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1495 RNA_def_property_string_funcs(prop, "rna_Event_ascii_get", "rna_Event_ascii_length", NULL);
1496 RNA_def_property_ui_text(prop, "ASCII", "Single ASCII character for this event");
1499 prop = RNA_def_property(srna, "unicode", PROP_STRING, PROP_NONE);
1500 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1501 RNA_def_property_string_funcs(prop, "rna_Event_unicode_get", "rna_Event_unicode_length", NULL);
1502 RNA_def_property_ui_text(prop, "Unicode", "Single unicode character for this event");
1505 prop = RNA_def_property(srna, "value", PROP_ENUM, PROP_NONE);
1506 RNA_def_property_enum_sdna(prop, NULL, "val");
1507 RNA_def_property_enum_items(prop, event_value_items);
1508 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1509 RNA_def_property_ui_text(prop, "Value", "The type of event, only applies to some");
1511 prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
1512 RNA_def_property_enum_sdna(prop, NULL, "type");
1513 RNA_def_property_enum_items(prop, event_type_items);
1514 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1515 RNA_def_property_ui_text(prop, "Type", "");
1519 prop = RNA_def_property(srna, "mouse_x", PROP_INT, PROP_NONE);
1520 RNA_def_property_int_sdna(prop, NULL, "x");
1521 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1522 RNA_def_property_ui_text(prop, "Mouse X Position", "The window relative vertical location of the mouse");
1524 prop = RNA_def_property(srna, "mouse_y", PROP_INT, PROP_NONE);
1525 RNA_def_property_int_sdna(prop, NULL, "y");
1526 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1527 RNA_def_property_ui_text(prop, "Mouse Y Position", "The window relative horizontal location of the mouse");
1529 prop = RNA_def_property(srna, "mouse_region_x", PROP_INT, PROP_NONE);
1530 RNA_def_property_int_sdna(prop, NULL, "mval[0]");
1531 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1532 RNA_def_property_ui_text(prop, "Mouse X Position", "The region relative vertical location of the mouse");
1534 prop = RNA_def_property(srna, "mouse_region_y", PROP_INT, PROP_NONE);
1535 RNA_def_property_int_sdna(prop, NULL, "mval[1]");
1536 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1537 RNA_def_property_ui_text(prop, "Mouse Y Position", "The region relative horizontal location of the mouse");
1539 prop = RNA_def_property(srna, "mouse_prev_x", PROP_INT, PROP_NONE);
1540 RNA_def_property_int_sdna(prop, NULL, "prevx");
1541 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1542 RNA_def_property_ui_text(prop, "Mouse Previous X Position", "The window relative vertical location of the mouse");
1544 prop = RNA_def_property(srna, "mouse_prev_y", PROP_INT, PROP_NONE);
1545 RNA_def_property_int_sdna(prop, NULL, "prevy");
1546 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1547 RNA_def_property_ui_text(prop, "Mouse Previous Y Position", "The window relative horizontal location of the mouse");
1551 prop = RNA_def_property(srna, "shift", PROP_BOOLEAN, PROP_NONE);
1552 RNA_def_property_boolean_sdna(prop, NULL, "shift", 1);
1553 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1554 RNA_def_property_ui_text(prop, "Shift", "True when the Shift key is held");
1556 prop = RNA_def_property(srna, "ctrl", PROP_BOOLEAN, PROP_NONE);
1557 RNA_def_property_boolean_sdna(prop, NULL, "ctrl", 1);
1558 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1559 RNA_def_property_ui_text(prop, "Ctrl", "True when the Ctrl key is held");
1561 prop = RNA_def_property(srna, "alt", PROP_BOOLEAN, PROP_NONE);
1562 RNA_def_property_boolean_sdna(prop, NULL, "alt", 1);
1563 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1564 RNA_def_property_ui_text(prop, "Alt", "True when the Alt/Option key is held");
1566 prop = RNA_def_property(srna, "oskey", PROP_BOOLEAN, PROP_NONE);
1567 RNA_def_property_boolean_sdna(prop, NULL, "oskey", 1);
1568 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1569 RNA_def_property_ui_text(prop, "OS Key", "True when the Cmd key is held");
1571 RNA_define_verify_sdna(1); /* not in sdna */
1574 static void rna_def_timer(BlenderRNA *brna)
1579 srna = RNA_def_struct(brna, "Timer", NULL);
1580 RNA_def_struct_ui_text(srna, "Timer", "Window event timer");
1581 RNA_def_struct_sdna(srna, "wmTimer");
1583 RNA_define_verify_sdna(0); /* not in sdna */
1585 /* could wrap more, for now this is enough */
1586 prop = RNA_def_property(srna, "time_step", PROP_FLOAT, PROP_NONE);
1587 RNA_def_property_float_sdna(prop, NULL, "timestep");
1588 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1589 RNA_def_property_ui_text(prop, "Time Step", "");
1591 prop = RNA_def_property(srna, "time_delta", PROP_FLOAT, PROP_NONE);
1592 RNA_def_property_float_sdna(prop, NULL, "delta");
1593 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1594 RNA_def_property_ui_text(prop, "Delta", "Time since last step in seconds");
1596 prop = RNA_def_property(srna, "time_duration", PROP_FLOAT, PROP_NONE);
1597 RNA_def_property_float_sdna(prop, NULL, "duration");
1598 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1599 RNA_def_property_ui_text(prop, "Delta", "Time since last step in seconds");
1601 RNA_define_verify_sdna(1); /* not in sdna */
1604 static void rna_def_window(BlenderRNA *brna)
1609 srna = RNA_def_struct(brna, "Window", NULL);
1610 RNA_def_struct_ui_text(srna, "Window", "Open window");
1611 RNA_def_struct_sdna(srna, "wmWindow");
1613 prop = RNA_def_property(srna, "screen", PROP_POINTER, PROP_NONE);
1614 RNA_def_property_flag(prop, PROP_NEVER_NULL);
1615 RNA_def_property_struct_type(prop, "Screen");
1616 RNA_def_property_ui_text(prop, "Screen", "Active screen showing in the window");
1617 RNA_def_property_flag(prop, PROP_EDITABLE);
1618 RNA_def_property_pointer_funcs(prop, NULL, "rna_Window_screen_set", NULL, NULL);
1619 RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
1620 RNA_def_property_update(prop, 0, "rna_Window_screen_update");
1622 prop = RNA_def_property(srna, "x", PROP_INT, PROP_NONE);
1623 RNA_def_property_int_sdna(prop, NULL, "posx");
1624 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1625 RNA_def_property_ui_text(prop, "X Position", "Vertical location of the window");
1627 prop = RNA_def_property(srna, "y", PROP_INT, PROP_NONE);
1628 RNA_def_property_int_sdna(prop, NULL, "posy");
1629 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1630 RNA_def_property_ui_text(prop, "Y Position", "Horizontal location of the window");
1632 prop = RNA_def_property(srna, "width", PROP_INT, PROP_UNSIGNED);
1633 RNA_def_property_int_sdna(prop, NULL, "sizex");
1634 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1635 RNA_def_property_ui_text(prop, "Width", "Window width");
1637 prop = RNA_def_property(srna, "height", PROP_INT, PROP_UNSIGNED);
1638 RNA_def_property_int_sdna(prop, NULL, "sizey");
1639 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1640 RNA_def_property_ui_text(prop, "Height", "Window height");
1644 static void rna_def_wm_keyconfigs(BlenderRNA *brna, PropertyRNA *cprop)
1649 RNA_def_property_srna(cprop, "KeyConfigurations");
1650 srna = RNA_def_struct(brna, "KeyConfigurations", NULL);
1651 RNA_def_struct_sdna(srna, "wmWindowManager");
1652 RNA_def_struct_ui_text(srna, "KeyConfigs", "Collection of KeyConfigs");
1654 prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
1655 RNA_def_property_struct_type(prop, "KeyConfig");
1656 RNA_def_property_pointer_funcs(prop, "rna_WindowManager_active_keyconfig_get",
1657 "rna_WindowManager_active_keyconfig_set", NULL, NULL);
1658 RNA_def_property_flag(prop, PROP_EDITABLE);
1659 RNA_def_property_ui_text(prop, "Active KeyConfig", "Active key configuration (preset)");
1661 prop = RNA_def_property(srna, "default", PROP_POINTER, PROP_NEVER_NULL);
1662 RNA_def_property_pointer_sdna(prop, NULL, "defaultconf");
1663 RNA_def_property_struct_type(prop, "KeyConfig");
1664 RNA_def_property_ui_text(prop, "Default Key Configuration", "Default builtin key configuration");
1666 prop = RNA_def_property(srna, "addon", PROP_POINTER, PROP_NEVER_NULL);
1667 RNA_def_property_pointer_sdna(prop, NULL, "addonconf");
1668 RNA_def_property_struct_type(prop, "KeyConfig");
1669 RNA_def_property_ui_text(prop, "Addon Key Configuration",
1670 "Key configuration that can be extended by addons, and is added to the active "
1671 "configuration when handling events");
1673 prop = RNA_def_property(srna, "user", PROP_POINTER, PROP_NEVER_NULL);
1674 RNA_def_property_pointer_sdna(prop, NULL, "userconf");
1675 RNA_def_property_struct_type(prop, "KeyConfig");
1676 RNA_def_property_ui_text(prop, "User Key Configuration",
1677 "Final key configuration that combines keymaps from the active and addon configurations, "
1678 "and can be edited by the user");
1680 RNA_api_keyconfigs(srna);
1683 static void rna_def_windowmanager(BlenderRNA *brna)
1688 srna = RNA_def_struct(brna, "WindowManager", "ID");
1689 RNA_def_struct_ui_text(srna, "Window Manager",
1690 "Window manager datablock defining open windows and other user interface data");
1691 RNA_def_struct_clear_flag(srna, STRUCT_ID_REFCOUNT);
1692 RNA_def_struct_sdna(srna, "wmWindowManager");
1694 prop = RNA_def_property(srna, "operators", PROP_COLLECTION, PROP_NONE);
1695 RNA_def_property_struct_type(prop, "Operator");
1696 RNA_def_property_ui_text(prop, "Operators", "Operator registry");
1698 prop = RNA_def_property(srna, "windows", PROP_COLLECTION, PROP_NONE);
1699 RNA_def_property_struct_type(prop, "Window");
1700 RNA_def_property_ui_text(prop, "Windows", "Open windows");
1702 prop = RNA_def_property(srna, "keyconfigs", PROP_COLLECTION, PROP_NONE);
1703 RNA_def_property_struct_type(prop, "KeyConfig");
1704 RNA_def_property_ui_text(prop, "Key Configurations", "Registered key configurations");
1705 rna_def_wm_keyconfigs(brna, prop);
1707 prop = RNA_def_property(srna, "clipboard", PROP_STRING, PROP_NONE);
1708 RNA_def_property_string_funcs(prop, "rna_wmClipboard_get", "rna_wmClipboard_length", "rna_wmClipboard_set");
1709 RNA_def_property_ui_text(prop, "Text Clipboard", "");
1714 /* keyconfig.items */
1715 static void rna_def_keymap_items(BlenderRNA *brna, PropertyRNA *cprop)
1719 RNA_def_property_srna(cprop, "KeyMapItems");
1720 srna = RNA_def_struct(brna, "KeyMapItems", NULL);
1721 RNA_def_struct_sdna(srna, "wmKeyMap");
1722 RNA_def_struct_ui_text(srna, "KeyMap Items", "Collection of keymap items");
1724 RNA_api_keymapitems(srna);
1727 static void rna_def_wm_keymaps(BlenderRNA *brna, PropertyRNA *cprop)
1731 RNA_def_property_srna(cprop, "KeyMaps");
1732 srna = RNA_def_struct(brna, "KeyMaps", NULL);
1733 RNA_def_struct_sdna(srna, "wmKeyConfig");
1734 RNA_def_struct_ui_text(srna, "Key Maps", "Collection of keymaps");
1736 RNA_api_keymaps(srna);
1739 static void rna_def_keyconfig(BlenderRNA *brna)
1744 static EnumPropertyItem map_type_items[] = {
1745 {KMI_TYPE_KEYBOARD, "KEYBOARD", 0, "Keyboard", ""},
1746 {KMI_TYPE_TWEAK, "TWEAK", 0, "Tweak", ""},
1747 {KMI_TYPE_MOUSE, "MOUSE", 0, "Mouse", ""},
1748 {KMI_TYPE_NDOF, "NDOF", 0, "NDOF", ""},
1749 {KMI_TYPE_TEXTINPUT, "TEXTINPUT", 0, "Text Input", ""},
1750 {KMI_TYPE_TIMER, "TIMER", 0, "Timer", ""},
1751 {0, NULL, 0, NULL, NULL}
1755 srna = RNA_def_struct(brna, "KeyConfig", NULL);
1756 RNA_def_struct_sdna(srna, "wmKeyConfig");
1757 RNA_def_struct_ui_text(srna, "Key Configuration", "Input configuration, including keymaps");
1759 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
1760 RNA_def_property_string_sdna(prop, NULL, "idname");
1761 RNA_def_property_ui_text(prop, "Name", "Name of the key configuration");
1762 RNA_def_struct_name_property(srna, prop);
1764 prop = RNA_def_property(srna, "keymaps", PROP_COLLECTION, PROP_NONE);
1765 RNA_def_property_struct_type(prop, "KeyMap");
1766 RNA_def_property_ui_text(prop, "Key Maps", "Key maps configured as part of this configuration");
1767 rna_def_wm_keymaps(brna, prop);
1769 prop = RNA_def_property(srna, "is_user_defined", PROP_BOOLEAN, PROP_NONE);
1770 RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYCONF_USER);
1771 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1772 RNA_def_property_ui_text(prop, "User Defined", "Indicates that a keyconfig was defined by the user");
1774 RNA_api_keyconfig(srna);
1777 srna = RNA_def_struct(brna, "KeyMap", NULL);
1778 RNA_def_struct_sdna(srna, "wmKeyMap");
1779 RNA_def_struct_ui_text(srna, "Key Map", "Input configuration, including keymaps");
1781 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
1782 RNA_def_property_string_sdna(prop, NULL, "idname");
1783 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1784 RNA_def_property_ui_text(prop, "Name", "Name of the key map");
1785 RNA_def_struct_name_property(srna, prop);
1787 prop = RNA_def_property(srna, "space_type", PROP_ENUM, PROP_NONE);
1788 RNA_def_property_enum_sdna(prop, NULL, "spaceid");
1789 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1790 RNA_def_property_enum_items(prop, space_type_items);
1791 RNA_def_property_ui_text(prop, "Space Type", "Optional space type keymap is associated with");
1793 prop = RNA_def_property(srna, "region_type", PROP_ENUM, PROP_NONE);
1794 RNA_def_property_enum_sdna(prop, NULL, "regionid");
1795 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1796 RNA_def_property_enum_items(prop, region_type_items);
1797 RNA_def_property_ui_text(prop, "Region Type", "Optional region type keymap is associated with");
1799 prop = RNA_def_property(srna, "keymap_items", PROP_COLLECTION, PROP_NONE);
1800 RNA_def_property_collection_sdna(prop, NULL, "items", NULL);
1801 RNA_def_property_struct_type(prop, "KeyMapItem");
1802 RNA_def_property_ui_text(prop, "Items", "Items in the keymap, linking an operator to an input event");
1803 rna_def_keymap_items(brna, prop);
1805 prop = RNA_def_property(srna, "is_user_modified", PROP_BOOLEAN, PROP_NONE);
1806 RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYMAP_USER_MODIFIED);
1807 RNA_def_property_ui_text(prop, "User Defined", "Keymap is defined by the user");
1809 prop = RNA_def_property(srna, "is_modal", PROP_BOOLEAN, PROP_NONE);
1810 RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYMAP_MODAL);
1811 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1812 RNA_def_property_ui_text(prop, "Modal Keymap",
1813 "Indicates that a keymap is used for translate modal events for an operator");
1815 prop = RNA_def_property(srna, "show_expanded_items", PROP_BOOLEAN, PROP_NONE);
1816 RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYMAP_EXPANDED);
1817 RNA_def_property_ui_text(prop, "Items Expanded", "Expanded in the user interface");
1818 RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
1820 prop = RNA_def_property(srna, "show_expanded_children", PROP_BOOLEAN, PROP_NONE);
1821 RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYMAP_CHILDREN_EXPANDED);
1822 RNA_def_property_ui_text(prop, "Children Expanded", "Children expanded in the user interface");
1823 RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
1826 RNA_api_keymap(srna);
1829 srna = RNA_def_struct(brna, "KeyMapItem", NULL);
1830 RNA_def_struct_sdna(srna, "wmKeyMapItem");
1831 RNA_def_struct_ui_text(srna, "Key Map Item", "Item in a Key Map");
1833 prop = RNA_def_property(srna, "idname", PROP_STRING, PROP_NONE);
1834 RNA_def_property_string_sdna(prop, NULL, "idname");
1835 RNA_def_property_ui_text(prop, "Identifier", "Identifier of operator to call on input event");
1836 RNA_def_property_string_funcs(prop, "rna_wmKeyMapItem_idname_get", "rna_wmKeyMapItem_idname_length",
1837 "rna_wmKeyMapItem_idname_set");
1838 RNA_def_struct_name_property(srna, prop);
1839 RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
1841 /* this is in fact the operator name, but if the operator can't be found we
1842 * fallback on the operator ID */
1843 prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
1844 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1845 RNA_def_property_ui_text(prop, "Name", "Name of operator (translated) to call on input event");
1846 RNA_def_property_string_funcs(prop, "rna_wmKeyMapItem_name_get", "rna_wmKeyMapItem_name_length", NULL);
1848 prop = RNA_def_property(srna, "properties", PROP_POINTER, PROP_NONE);
1849 RNA_def_property_struct_type(prop, "OperatorProperties");
1850 RNA_def_property_pointer_funcs(prop, "rna_KeyMapItem_properties_get", NULL, NULL, NULL);
1851 RNA_def_property_ui_text(prop, "Properties", "Properties to set when the operator is called");
1852 RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
1854 prop = RNA_def_property(srna, "map_type", PROP_ENUM, PROP_NONE);
1855 RNA_def_property_enum_sdna(prop, NULL, "maptype");
1856 RNA_def_property_enum_items(prop, map_type_items);
1857 RNA_def_property_enum_funcs(prop, "rna_wmKeyMapItem_map_type_get", "rna_wmKeyMapItem_map_type_set", NULL);
1858 RNA_def_property_ui_text(prop, "Map Type", "Type of event mapping");
1859 RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
1861 prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
1862 RNA_def_property_enum_sdna(prop, NULL, "type");
1863 RNA_def_property_enum_items(prop, event_type_items);
1864 RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_KeyMapItem_type_itemf");
1865 RNA_def_property_ui_text(prop, "Type", "Type of event");
1866 RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
1868 prop = RNA_def_property(srna, "value", PROP_ENUM, PROP_NONE);
1869 RNA_def_property_enum_sdna(prop, NULL, "val");
1870 RNA_def_property_enum_items(prop, event_value_items);
1871 RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_KeyMapItem_value_itemf");
1872 RNA_def_property_ui_text(prop, "Value", "");
1873 RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
1875 prop = RNA_def_property(srna, "id", PROP_INT, PROP_NONE);
1876 RNA_def_property_int_sdna(prop, NULL, "id");
1877 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1878 RNA_def_property_ui_text(prop, "ID", "ID of the item");
1879 RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
1881 prop = RNA_def_property(srna, "any", PROP_BOOLEAN, PROP_NONE);
1882 RNA_def_property_boolean_funcs(prop, "rna_KeyMapItem_any_getf", "rna_KeyMapItem_any_setf");
1883 RNA_def_property_ui_text(prop, "Any", "Any modifier keys pressed");
1884 RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
1886 prop = RNA_def_property(srna, "shift", PROP_BOOLEAN, PROP_NONE);
1887 RNA_def_property_boolean_sdna(prop, NULL, "shift", 0);
1888 /* RNA_def_property_enum_sdna(prop, NULL, "shift"); */
1889 /* RNA_def_property_enum_items(prop, keymap_modifiers_items); */
1890 RNA_def_property_ui_text(prop, "Shift", "Shift key pressed");
1891 RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
1893 prop = RNA_def_property(srna, "ctrl", PROP_BOOLEAN, PROP_NONE);
1894 RNA_def_property_boolean_sdna(prop, NULL, "ctrl", 0);
1895 /* RNA_def_property_enum_sdna(prop, NULL, "ctrl"); */
1896 /* RNA_def_property_enum_items(prop, keymap_modifiers_items); */
1897 RNA_def_property_ui_text(prop, "Ctrl", "Control key pressed");
1898 RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
1900 prop = RNA_def_property(srna, "alt", PROP_BOOLEAN, PROP_NONE);
1901 RNA_def_property_boolean_sdna(prop, NULL, "alt", 0);
1902 /* RNA_def_property_enum_sdna(prop, NULL, "alt"); */
1903 /* RNA_def_property_enum_items(prop, keymap_modifiers_items); */
1904 RNA_def_property_ui_text(prop, "Alt", "Alt key pressed");
1905 RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
1907 prop = RNA_def_property(srna, "oskey", PROP_BOOLEAN, PROP_NONE);
1908 RNA_def_property_boolean_sdna(prop, NULL, "oskey", 0);
1909 /* RNA_def_property_enum_sdna(prop, NULL, "oskey"); */
1910 /* RNA_def_property_enum_items(prop, keymap_modifiers_items); */
1911 RNA_def_property_ui_text(prop, "OS Key", "Operating system key pressed");
1912 RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
1914 prop = RNA_def_property(srna, "key_modifier", PROP_ENUM, PROP_NONE);
1915 RNA_def_property_enum_sdna(prop, NULL, "keymodifier");
1916 RNA_def_property_enum_items(prop, event_type_items);
1917 RNA_def_property_enum_funcs(prop, NULL, "rna_wmKeyMapItem_keymodifier_set", NULL);
1918 RNA_def_property_ui_text(prop, "Key Modifier", "Regular key pressed as a modifier");
1919 RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
1921 prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
1922 RNA_def_property_boolean_sdna(prop, NULL, "flag", KMI_EXPANDED);
1923 RNA_def_property_ui_text(prop, "Expanded", "Show key map event and property details in the user interface");
1924 RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
1925 RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
1927 prop = RNA_def_property(srna, "propvalue", PROP_ENUM, PROP_NONE);
1928 RNA_def_property_enum_sdna(prop, NULL, "propvalue");
1929 RNA_def_property_enum_items(prop, keymap_propvalue_items);
1930 RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_KeyMapItem_propvalue_itemf");
1931 RNA_def_property_ui_text(prop, "Property Value", "The value this event translates to in a modal keymap");
1932 RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
1934 prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
1935 RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", KMI_INACTIVE);
1936 RNA_def_property_ui_text(prop, "Active", "Activate or deactivate item");
1937 RNA_def_property_ui_icon(prop, ICON_CHECKBOX_DEHLT, 1);
1938 RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
1940 prop = RNA_def_property(srna, "is_user_modified", PROP_BOOLEAN, PROP_NONE);
1941 RNA_def_property_boolean_sdna(prop, NULL, "flag", KMI_USER_MODIFIED);
1942 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1943 RNA_def_property_ui_text(prop, "User Modified", "Is this keymap item modified by the user");
1945 prop = RNA_def_property(srna, "is_user_defined", PROP_BOOLEAN, PROP_NONE);
1946 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1947 RNA_def_property_ui_text(prop, "User Defined",
1948 "Is this keymap item user defined (doesn't just replace a builtin item)");
1949 RNA_def_property_boolean_funcs(prop, "rna_KeyMapItem_userdefined_get", NULL);
1951 RNA_api_keymapitem(srna);
1954 void RNA_def_wm(BlenderRNA *brna)
1956 rna_def_operator(brna);
1957 rna_def_operator_utils(brna);
1958 rna_def_operator_filelist_element(brna);
1959 rna_def_macro_operator(brna);
1960 rna_def_operator_type_macro(brna);
1961 rna_def_event(brna);
1962 rna_def_timer(brna);
1963 rna_def_window(brna);
1964 rna_def_windowmanager(brna);
1965 rna_def_keyconfig(brna);
1968 #endif /* RNA_RUNTIME */