1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 /** \file
18  * \ingroup RNA
19  */
20 
21 #include <stdlib.h>
22 
23 #include "DNA_screen_types.h"
24 #include "DNA_space_types.h"
25 #include "DNA_userdef_types.h"
26 #include "DNA_windowmanager_types.h"
27 
28 #include "BLI_utildefines.h"
29 
30 #include "BLT_translation.h"
31 
32 #include "BKE_keyconfig.h"
33 #include "BKE_workspace.h"
34 
35 #include "RNA_access.h"
36 #include "RNA_define.h"
37 #include "RNA_enum_types.h"
38 
39 #include "rna_internal.h"
40 
41 #include "WM_types.h"
42 
43 #ifdef RNA_RUNTIME
44 
45 static const EnumPropertyItem event_keymouse_value_items[] = {
46     {KM_ANY, "ANY", 0, "Any", ""},
47     {KM_PRESS, "PRESS", 0, "Press", ""},
48     {KM_RELEASE, "RELEASE", 0, "Release", ""},
49     {KM_CLICK, "CLICK", 0, "Click", ""},
50     {KM_DBL_CLICK, "DOUBLE_CLICK", 0, "Double Click", ""},
51     {KM_CLICK_DRAG, "CLICK_DRAG", 0, "Click Drag", ""},
52     /* Used for NDOF and trackpad events. */
53     {KM_NOTHING, "NOTHING", 0, "Nothing", ""},
54     {0, NULL, 0, NULL, NULL},
55 };
56 
57 static const EnumPropertyItem event_tweak_value_items[] = {
58     {KM_ANY, "ANY", 0, "Any", ""},
59     {EVT_GESTURE_N, "NORTH", 0, "North", ""},
60     {EVT_GESTURE_NE, "NORTH_EAST", 0, "North-East", ""},
61     {EVT_GESTURE_E, "EAST", 0, "East", ""},
62     {EVT_GESTURE_SE, "SOUTH_EAST", 0, "South-East", ""},
63     {EVT_GESTURE_S, "SOUTH", 0, "South", ""},
64     {EVT_GESTURE_SW, "SOUTH_WEST", 0, "South-West", ""},
65     {EVT_GESTURE_W, "WEST", 0, "West", ""},
66     {EVT_GESTURE_NW, "NORTH_WEST", 0, "North-West", ""},
67     {0, NULL, 0, NULL, NULL},
68 };
69 
70 static const EnumPropertyItem event_tweak_type_items[] = {
71     {EVT_TWEAK_L, "EVT_TWEAK_L", 0, "Left", ""},
72     {EVT_TWEAK_M, "EVT_TWEAK_M", 0, "Middle", ""},
73     {EVT_TWEAK_R, "EVT_TWEAK_R", 0, "Right", ""},
74     {0, NULL, 0, NULL, NULL},
75 };
76 
77 static const EnumPropertyItem event_mouse_type_items[] = {
78     {LEFTMOUSE, "LEFTMOUSE", 0, "Left", ""},
79     {MIDDLEMOUSE, "MIDDLEMOUSE", 0, "Middle", ""},
80     {RIGHTMOUSE, "RIGHTMOUSE", 0, "Right", ""},
81     {BUTTON4MOUSE, "BUTTON4MOUSE", 0, "Button4", ""},
82     {BUTTON5MOUSE, "BUTTON5MOUSE", 0, "Button5", ""},
83     {BUTTON6MOUSE, "BUTTON6MOUSE", 0, "Button6", ""},
84     {BUTTON7MOUSE, "BUTTON7MOUSE", 0, "Button7", ""},
85     {0, "", 0, NULL, NULL},
86     {TABLET_STYLUS, "PEN", 0, "Pen", ""},
87     {TABLET_ERASER, "ERASER", 0, "Eraser", ""},
88     {0, "", 0, NULL, NULL},
89     {MOUSEMOVE, "MOUSEMOVE", 0, "Move", ""},
90     {MOUSEPAN, "TRACKPADPAN", 0, "Mouse/Trackpad Pan", ""},
91     {MOUSEZOOM, "TRACKPADZOOM", 0, "Mouse/Trackpad Zoom", ""},
92     {MOUSEROTATE, "MOUSEROTATE", 0, "Mouse/Trackpad Rotate", ""},
93     {MOUSESMARTZOOM, "MOUSESMARTZOOM", 0, "Mouse/Trackpad Smart Zoom", ""},
94     {0, "", 0, NULL, NULL},
95     {WHEELUPMOUSE, "WHEELUPMOUSE", 0, "Wheel Up", ""},
96     {WHEELDOWNMOUSE, "WHEELDOWNMOUSE", 0, "Wheel Down", ""},
97     {WHEELINMOUSE, "WHEELINMOUSE", 0, "Wheel In", ""},
98     {WHEELOUTMOUSE, "WHEELOUTMOUSE", 0, "Wheel Out", ""},
99     {0, NULL, 0, NULL, NULL},
100 };
101 
102 static const EnumPropertyItem event_timer_type_items[] = {
103     {TIMER, "TIMER", 0, "Timer", ""},
104     {TIMER0, "TIMER0", 0, "Timer 0", ""},
105     {TIMER1, "TIMER1", 0, "Timer 1", ""},
106     {TIMER2, "TIMER2", 0, "Timer 2", ""},
107     {TIMERJOBS, "TIMER_JOBS", 0, "Timer Jobs", ""},
108     {TIMERAUTOSAVE, "TIMER_AUTOSAVE", 0, "Timer Autosave", ""},
109     {TIMERREPORT, "TIMER_REPORT", 0, "Timer Report", ""},
110     {TIMERREGION, "TIMERREGION", 0, "Timer Region", ""},
111     {0, NULL, 0, NULL, NULL},
112 };
113 
114 static const EnumPropertyItem event_textinput_type_items[] = {
115     {KM_TEXTINPUT, "TEXTINPUT", 0, "Text Input", ""},
116     {0, NULL, 0, NULL, NULL},
117 };
118 
119 static const EnumPropertyItem event_ndof_type_items[] = {
120     {NDOF_MOTION, "NDOF_MOTION", 0, "Motion", ""},
121     /* buttons on all 3dconnexion devices */
122     {NDOF_BUTTON_MENU, "NDOF_BUTTON_MENU", 0, "Menu", ""},
123     {NDOF_BUTTON_FIT, "NDOF_BUTTON_FIT", 0, "Fit", ""},
124     /* view buttons */
125     {NDOF_BUTTON_TOP, "NDOF_BUTTON_TOP", 0, "Top", ""},
126     {NDOF_BUTTON_BOTTOM, "NDOF_BUTTON_BOTTOM", 0, "Bottom", ""},
127     {NDOF_BUTTON_LEFT, "NDOF_BUTTON_LEFT", 0, "Left", ""},
128     {NDOF_BUTTON_RIGHT, "NDOF_BUTTON_RIGHT", 0, "Right", ""},
129     {NDOF_BUTTON_FRONT, "NDOF_BUTTON_FRONT", 0, "Front", ""},
130     {NDOF_BUTTON_BACK, "NDOF_BUTTON_BACK", 0, "Back", ""},
131     /* more views */
132     {NDOF_BUTTON_ISO1, "NDOF_BUTTON_ISO1", 0, "Isometric 1", ""},
133     {NDOF_BUTTON_ISO2, "NDOF_BUTTON_ISO2", 0, "Isometric 2", ""},
134     /* 90 degree rotations */
135     {NDOF_BUTTON_ROLL_CW, "NDOF_BUTTON_ROLL_CW", 0, "Roll CW", ""},
136     {NDOF_BUTTON_ROLL_CCW, "NDOF_BUTTON_ROLL_CCW", 0, "Roll CCW", ""},
137     {NDOF_BUTTON_SPIN_CW, "NDOF_BUTTON_SPIN_CW", 0, "Spin CW", ""},
138     {NDOF_BUTTON_SPIN_CCW, "NDOF_BUTTON_SPIN_CCW", 0, "Spin CCW", ""},
139     {NDOF_BUTTON_TILT_CW, "NDOF_BUTTON_TILT_CW", 0, "Tilt CW", ""},
140     {NDOF_BUTTON_TILT_CCW, "NDOF_BUTTON_TILT_CCW", 0, "Tilt CCW", ""},
141     /* device control */
142     {NDOF_BUTTON_ROTATE, "NDOF_BUTTON_ROTATE", 0, "Rotate", ""},
143     {NDOF_BUTTON_PANZOOM, "NDOF_BUTTON_PANZOOM", 0, "Pan/Zoom", ""},
144     {NDOF_BUTTON_DOMINANT, "NDOF_BUTTON_DOMINANT", 0, "Dominant", ""},
145     {NDOF_BUTTON_PLUS, "NDOF_BUTTON_PLUS", 0, "Plus", ""},
146     {NDOF_BUTTON_MINUS, "NDOF_BUTTON_MINUS", 0, "Minus", ""},
147     /* keyboard emulation */
148     {NDOF_BUTTON_ESC, "NDOF_BUTTON_ESC", 0, "Esc"},
149     {NDOF_BUTTON_ALT, "NDOF_BUTTON_ALT", 0, "Alt"},
150     {NDOF_BUTTON_SHIFT, "NDOF_BUTTON_SHIFT", 0, "Shift"},
151     {NDOF_BUTTON_CTRL, "NDOF_BUTTON_CTRL", 0, "Ctrl"},
152     /* general-purpose buttons */
153     {NDOF_BUTTON_1, "NDOF_BUTTON_1", 0, "Button 1", ""},
154     {NDOF_BUTTON_2, "NDOF_BUTTON_2", 0, "Button 2", ""},
155     {NDOF_BUTTON_3, "NDOF_BUTTON_3", 0, "Button 3", ""},
156     {NDOF_BUTTON_4, "NDOF_BUTTON_4", 0, "Button 4", ""},
157     {NDOF_BUTTON_5, "NDOF_BUTTON_5", 0, "Button 5", ""},
158     {NDOF_BUTTON_6, "NDOF_BUTTON_6", 0, "Button 6", ""},
159     {NDOF_BUTTON_7, "NDOF_BUTTON_7", 0, "Button 7", ""},
160     {NDOF_BUTTON_8, "NDOF_BUTTON_8", 0, "Button 8", ""},
161     {NDOF_BUTTON_9, "NDOF_BUTTON_9", 0, "Button 9", ""},
162     {NDOF_BUTTON_10, "NDOF_BUTTON_10", 0, "Button 10", ""},
163     {NDOF_BUTTON_A, "NDOF_BUTTON_A", 0, "Button A", ""},
164     {NDOF_BUTTON_B, "NDOF_BUTTON_B", 0, "Button B", ""},
165     {NDOF_BUTTON_C, "NDOF_BUTTON_C", 0, "Button C", ""},
166     {0, NULL, 0, NULL, NULL},
167 };
168 #endif /* RNA_RUNTIME */
169 
170 /* not returned: CAPSLOCKKEY, UNKNOWNKEY */
171 const EnumPropertyItem rna_enum_event_type_items[] = {
172     /* Note we abuse 'tooltip' message here to store a 'compact' form of some (too) long names. */
173     {0, "NONE", 0, "", ""},
174     {LEFTMOUSE, "LEFTMOUSE", 0, "Left Mouse", "LMB"},
175     {MIDDLEMOUSE, "MIDDLEMOUSE", 0, "Middle Mouse", "MMB"},
176     {RIGHTMOUSE, "RIGHTMOUSE", 0, "Right Mouse", "RMB"},
177     {BUTTON4MOUSE, "BUTTON4MOUSE", 0, "Button4 Mouse", "MB4"},
178     {BUTTON5MOUSE, "BUTTON5MOUSE", 0, "Button5 Mouse", "MB5"},
179     {BUTTON6MOUSE, "BUTTON6MOUSE", 0, "Button6 Mouse", "MB6"},
180     {BUTTON7MOUSE, "BUTTON7MOUSE", 0, "Button7 Mouse", "MB7"},
181     {0, "", 0, NULL, NULL},
182     {TABLET_STYLUS, "PEN", 0, "Pen", ""},
183     {TABLET_ERASER, "ERASER", 0, "Eraser", ""},
184     {0, "", 0, NULL, NULL},
185     {MOUSEMOVE, "MOUSEMOVE", 0, "Mouse Move", "MsMov"},
186     {INBETWEEN_MOUSEMOVE, "INBETWEEN_MOUSEMOVE", 0, "In-between Move", "MsSubMov"},
187     {MOUSEPAN, "TRACKPADPAN", 0, "Mouse/Trackpad Pan", "MsPan"},
188     {MOUSEZOOM, "TRACKPADZOOM", 0, "Mouse/Trackpad Zoom", "MsZoom"},
189     {MOUSEROTATE, "MOUSEROTATE", 0, "Mouse/Trackpad Rotate", "MsRot"},
190     {MOUSESMARTZOOM, "MOUSESMARTZOOM", 0, "Mouse/Trackpad Smart Zoom", "MsSmartZoom"},
191     {0, "", 0, NULL, NULL},
192     {WHEELUPMOUSE, "WHEELUPMOUSE", 0, "Wheel Up", "WhUp"},
193     {WHEELDOWNMOUSE, "WHEELDOWNMOUSE", 0, "Wheel Down", "WhDown"},
194     {WHEELINMOUSE, "WHEELINMOUSE", 0, "Wheel In", "WhIn"},
195     {WHEELOUTMOUSE, "WHEELOUTMOUSE", 0, "Wheel Out", "WhOut"},
196     {0, "", 0, NULL, NULL},
197     {EVT_TWEAK_L, "EVT_TWEAK_L", 0, "Tweak Left", "TwkL"},
198     {EVT_TWEAK_M, "EVT_TWEAK_M", 0, "Tweak Middle", "TwkM"},
199     {EVT_TWEAK_R, "EVT_TWEAK_R", 0, "Tweak Right", "TwkR"},
200     {0, "", 0, NULL, NULL},
201     {EVT_AKEY, "A", 0, "A", ""},
202     {EVT_BKEY, "B", 0, "B", ""},
203     {EVT_CKEY, "C", 0, "C", ""},
204     {EVT_DKEY, "D", 0, "D", ""},
205     {EVT_EKEY, "E", 0, "E", ""},
206     {EVT_FKEY, "F", 0, "F", ""},
207     {EVT_GKEY, "G", 0, "G", ""},
208     {EVT_HKEY, "H", 0, "H", ""},
209     {EVT_IKEY, "I", 0, "I", ""},
210     {EVT_JKEY, "J", 0, "J", ""},
211     {EVT_KKEY, "K", 0, "K", ""},
212     {EVT_LKEY, "L", 0, "L", ""},
213     {EVT_MKEY, "M", 0, "M", ""},
214     {EVT_NKEY, "N", 0, "N", ""},
215     {EVT_OKEY, "O", 0, "O", ""},
216     {EVT_PKEY, "P", 0, "P", ""},
217     {EVT_QKEY, "Q", 0, "Q", ""},
218     {EVT_RKEY, "R", 0, "R", ""},
219     {EVT_SKEY, "S", 0, "S", ""},
220     {EVT_TKEY, "T", 0, "T", ""},
221     {EVT_UKEY, "U", 0, "U", ""},
222     {EVT_VKEY, "V", 0, "V", ""},
223     {EVT_WKEY, "W", 0, "W", ""},
224     {EVT_XKEY, "X", 0, "X", ""},
225     {EVT_YKEY, "Y", 0, "Y", ""},
226     {EVT_ZKEY, "Z", 0, "Z", ""},
227     {0, "", 0, NULL, NULL},
228     {EVT_ZEROKEY, "ZERO", 0, "0", ""},
229     {EVT_ONEKEY, "ONE", 0, "1", ""},
230     {EVT_TWOKEY, "TWO", 0, "2", ""},
231     {EVT_THREEKEY, "THREE", 0, "3", ""},
232     {EVT_FOURKEY, "FOUR", 0, "4", ""},
233     {EVT_FIVEKEY, "FIVE", 0, "5", ""},
234     {EVT_SIXKEY, "SIX", 0, "6", ""},
235     {EVT_SEVENKEY, "SEVEN", 0, "7", ""},
236     {EVT_EIGHTKEY, "EIGHT", 0, "8", ""},
237     {EVT_NINEKEY, "NINE", 0, "9", ""},
238     {0, "", 0, NULL, NULL},
239     {EVT_LEFTCTRLKEY, "LEFT_CTRL", 0, "Left Ctrl", "CtrlL"},
240     {EVT_LEFTALTKEY, "LEFT_ALT", 0, "Left Alt", "AltL"},
241     {EVT_LEFTSHIFTKEY, "LEFT_SHIFT", 0, "Left Shift", "ShiftL"},
242     {EVT_RIGHTALTKEY, "RIGHT_ALT", 0, "Right Alt", "AltR"},
243     {EVT_RIGHTCTRLKEY, "RIGHT_CTRL", 0, "Right Ctrl", "CtrlR"},
244     {EVT_RIGHTSHIFTKEY, "RIGHT_SHIFT", 0, "Right Shift", "ShiftR"},
245     {0, "", 0, NULL, NULL},
246     {EVT_OSKEY, "OSKEY", 0, "OS Key", "Cmd"},
247     {EVT_APPKEY, "APP", 0, "Application", "App"},
248     {EVT_GRLESSKEY, "GRLESS", 0, "Grless", ""},
249     {EVT_ESCKEY, "ESC", 0, "Esc", ""},
250     {EVT_TABKEY, "TAB", 0, "Tab", ""},
251     {EVT_RETKEY, "RET", 0, "Return", "Enter"},
252     {EVT_SPACEKEY, "SPACE", 0, "Spacebar", "Space"},
253     {EVT_LINEFEEDKEY, "LINE_FEED", 0, "Line Feed", ""},
254     {EVT_BACKSPACEKEY, "BACK_SPACE", 0, "Backspace", "BkSpace"},
255     {EVT_DELKEY, "DEL", 0, "Delete", "Del"},
256     {EVT_SEMICOLONKEY, "SEMI_COLON", 0, ";", ""},
257     {EVT_PERIODKEY, "PERIOD", 0, ".", ""},
258     {EVT_COMMAKEY, "COMMA", 0, ",", ""},
259     {EVT_QUOTEKEY, "QUOTE", 0, "\"", ""},
260     {EVT_ACCENTGRAVEKEY, "ACCENT_GRAVE", 0, "`", ""},
261     {EVT_MINUSKEY, "MINUS", 0, "-", ""},
262     {EVT_PLUSKEY, "PLUS", 0, "+", ""},
263     {EVT_SLASHKEY, "SLASH", 0, "/", ""},
264     {EVT_BACKSLASHKEY, "BACK_SLASH", 0, "\\", ""},
265     {EVT_EQUALKEY, "EQUAL", 0, "=", ""},
266     {EVT_LEFTBRACKETKEY, "LEFT_BRACKET", 0, "[", ""},
267     {EVT_RIGHTBRACKETKEY, "RIGHT_BRACKET", 0, "]", ""},
268     {EVT_LEFTARROWKEY, "LEFT_ARROW", 0, "Left Arrow", "←"},
269     {EVT_DOWNARROWKEY, "DOWN_ARROW", 0, "Down Arrow", "↓"},
270     {EVT_RIGHTARROWKEY, "RIGHT_ARROW", 0, "Right Arrow", "→"},
271     {EVT_UPARROWKEY, "UP_ARROW", 0, "Up Arrow", "↑"},
272     {EVT_PAD2, "NUMPAD_2", 0, "Numpad 2", "Pad2"},
273     {EVT_PAD4, "NUMPAD_4", 0, "Numpad 4", "Pad4"},
274     {EVT_PAD6, "NUMPAD_6", 0, "Numpad 6", "Pad6"},
275     {EVT_PAD8, "NUMPAD_8", 0, "Numpad 8", "Pad8"},
276     {EVT_PAD1, "NUMPAD_1", 0, "Numpad 1", "Pad1"},
277     {EVT_PAD3, "NUMPAD_3", 0, "Numpad 3", "Pad3"},
278     {EVT_PAD5, "NUMPAD_5", 0, "Numpad 5", "Pad5"},
279     {EVT_PAD7, "NUMPAD_7", 0, "Numpad 7", "Pad7"},
280     {EVT_PAD9, "NUMPAD_9", 0, "Numpad 9", "Pad9"},
281     {EVT_PADPERIOD, "NUMPAD_PERIOD", 0, "Numpad .", "Pad."},
282     {EVT_PADSLASHKEY, "NUMPAD_SLASH", 0, "Numpad /", "Pad/"},
283     {EVT_PADASTERKEY, "NUMPAD_ASTERIX", 0, "Numpad *", "Pad*"},
284     {EVT_PAD0, "NUMPAD_0", 0, "Numpad 0", "Pad0"},
285     {EVT_PADMINUS, "NUMPAD_MINUS", 0, "Numpad -", "Pad-"},
286     {EVT_PADENTER, "NUMPAD_ENTER", 0, "Numpad Enter", "PadEnter"},
287     {EVT_PADPLUSKEY, "NUMPAD_PLUS", 0, "Numpad +", "Pad+"},
288     {EVT_F1KEY, "F1", 0, "F1", ""},
289     {EVT_F2KEY, "F2", 0, "F2", ""},
290     {EVT_F3KEY, "F3", 0, "F3", ""},
291     {EVT_F4KEY, "F4", 0, "F4", ""},
292     {EVT_F5KEY, "F5", 0, "F5", ""},
293     {EVT_F6KEY, "F6", 0, "F6", ""},
294     {EVT_F7KEY, "F7", 0, "F7", ""},
295     {EVT_F8KEY, "F8", 0, "F8", ""},
296     {EVT_F9KEY, "F9", 0, "F9", ""},
297     {EVT_F10KEY, "F10", 0, "F10", ""},
298     {EVT_F11KEY, "F11", 0, "F11", ""},
299     {EVT_F12KEY, "F12", 0, "F12", ""},
300     {EVT_F13KEY, "F13", 0, "F13", ""},
301     {EVT_F14KEY, "F14", 0, "F14", ""},
302     {EVT_F15KEY, "F15", 0, "F15", ""},
303     {EVT_F16KEY, "F16", 0, "F16", ""},
304     {EVT_F17KEY, "F17", 0, "F17", ""},
305     {EVT_F18KEY, "F18", 0, "F18", ""},
306     {EVT_F19KEY, "F19", 0, "F19", ""},
307     {EVT_F20KEY, "F20", 0, "F20", ""},
308     {EVT_F21KEY, "F21", 0, "F21", ""},
309     {EVT_F22KEY, "F22", 0, "F22", ""},
310     {EVT_F23KEY, "F23", 0, "F23", ""},
311     {EVT_F24KEY, "F24", 0, "F24", ""},
312     {EVT_PAUSEKEY, "PAUSE", 0, "Pause", ""},
313     {EVT_INSERTKEY, "INSERT", 0, "Insert", "Ins"},
314     {EVT_HOMEKEY, "HOME", 0, "Home", ""},
315     {EVT_PAGEUPKEY, "PAGE_UP", 0, "Page Up", "PgUp"},
316     {EVT_PAGEDOWNKEY, "PAGE_DOWN", 0, "Page Down", "PgDown"},
317     {EVT_ENDKEY, "END", 0, "End", ""},
318     {0, "", 0, NULL, NULL},
319     {EVT_MEDIAPLAY, "MEDIA_PLAY", 0, "Media Play/Pause", ">/||"},
320     {EVT_MEDIASTOP, "MEDIA_STOP", 0, "Media Stop", "Stop"},
321     {EVT_MEDIAFIRST, "MEDIA_FIRST", 0, "Media First", "|<<"},
322     {EVT_MEDIALAST, "MEDIA_LAST", 0, "Media Last", ">>|"},
323     {0, "", 0, NULL, NULL},
324     {KM_TEXTINPUT, "TEXTINPUT", 0, "Text Input", "TxtIn"},
325     {0, "", 0, NULL, NULL},
326     {WINDEACTIVATE, "WINDOW_DEACTIVATE", 0, "Window Deactivate", ""},
327     {TIMER, "TIMER", 0, "Timer", "Tmr"},
328     {TIMER0, "TIMER0", 0, "Timer 0", "Tmr0"},
329     {TIMER1, "TIMER1", 0, "Timer 1", "Tmr1"},
330     {TIMER2, "TIMER2", 0, "Timer 2", "Tmr2"},
331     {TIMERJOBS, "TIMER_JOBS", 0, "Timer Jobs", "TmrJob"},
332     {TIMERAUTOSAVE, "TIMER_AUTOSAVE", 0, "Timer Autosave", "TmrSave"},
333     {TIMERREPORT, "TIMER_REPORT", 0, "Timer Report", "TmrReport"},
334     {TIMERREGION, "TIMERREGION", 0, "Timer Region", "TmrReg"},
335     {0, "", 0, NULL, NULL},
336     {NDOF_MOTION, "NDOF_MOTION", 0, "NDOF Motion", "NdofMov"},
337     /* buttons on all 3dconnexion devices */
338     {NDOF_BUTTON_MENU, "NDOF_BUTTON_MENU", 0, "NDOF Menu", "NdofMenu"},
339     {NDOF_BUTTON_FIT, "NDOF_BUTTON_FIT", 0, "NDOF Fit", "NdofFit"},
340     /* view buttons */
341     {NDOF_BUTTON_TOP, "NDOF_BUTTON_TOP", 0, "NDOF Top", "Ndof↑"},
342     {NDOF_BUTTON_BOTTOM, "NDOF_BUTTON_BOTTOM", 0, "NDOF Bottom", "Ndof↓"},
343     {NDOF_BUTTON_LEFT, "NDOF_BUTTON_LEFT", 0, "NDOF Left", "Ndof←"},
344     {NDOF_BUTTON_RIGHT, "NDOF_BUTTON_RIGHT", 0, "NDOF Right", "Ndof→"},
345     {NDOF_BUTTON_FRONT, "NDOF_BUTTON_FRONT", 0, "NDOF Front", "NdofFront"},
346     {NDOF_BUTTON_BACK, "NDOF_BUTTON_BACK", 0, "NDOF Back", "NdofBack"},
347     /* more views */
348     {NDOF_BUTTON_ISO1, "NDOF_BUTTON_ISO1", 0, "NDOF Isometric 1", "NdofIso1"},
349     {NDOF_BUTTON_ISO2, "NDOF_BUTTON_ISO2", 0, "NDOF Isometric 2", "NdofIso2"},
350     /* 90 degree rotations */
351     {NDOF_BUTTON_ROLL_CW, "NDOF_BUTTON_ROLL_CW", 0, "NDOF Roll CW", "NdofRCW"},
352     {NDOF_BUTTON_ROLL_CCW, "NDOF_BUTTON_ROLL_CCW", 0, "NDOF Roll CCW", "NdofRCCW"},
353     {NDOF_BUTTON_SPIN_CW, "NDOF_BUTTON_SPIN_CW", 0, "NDOF Spin CW", "NdofSCW"},
354     {NDOF_BUTTON_SPIN_CCW, "NDOF_BUTTON_SPIN_CCW", 0, "NDOF Spin CCW", "NdofSCCW"},
355     {NDOF_BUTTON_TILT_CW, "NDOF_BUTTON_TILT_CW", 0, "NDOF Tilt CW", "NdofTCW"},
356     {NDOF_BUTTON_TILT_CCW, "NDOF_BUTTON_TILT_CCW", 0, "NDOF Tilt CCW", "NdofTCCW"},
357     /* device control */
358     {NDOF_BUTTON_ROTATE, "NDOF_BUTTON_ROTATE", 0, "NDOF Rotate", "NdofRot"},
359     {NDOF_BUTTON_PANZOOM, "NDOF_BUTTON_PANZOOM", 0, "NDOF Pan/Zoom", "NdofPanZoom"},
360     {NDOF_BUTTON_DOMINANT, "NDOF_BUTTON_DOMINANT", 0, "NDOF Dominant", "NdofDom"},
361     {NDOF_BUTTON_PLUS, "NDOF_BUTTON_PLUS", 0, "NDOF Plus", "Ndof+"},
362     {NDOF_BUTTON_MINUS, "NDOF_BUTTON_MINUS", 0, "NDOF Minus", "Ndof-"},
363     /* keyboard emulation */
364     {NDOF_BUTTON_ESC, "NDOF_BUTTON_ESC", 0, "NDOF Esc", "NdofEsc"},
365     {NDOF_BUTTON_ALT, "NDOF_BUTTON_ALT", 0, "NDOF Alt", "NdofAlt"},
366     {NDOF_BUTTON_SHIFT, "NDOF_BUTTON_SHIFT", 0, "NDOF Shift", "NdofShift"},
367     {NDOF_BUTTON_CTRL, "NDOF_BUTTON_CTRL", 0, "NDOF Ctrl", "NdofCtrl"},
368     /* general-purpose buttons */
369     {NDOF_BUTTON_1, "NDOF_BUTTON_1", 0, "NDOF Button 1", "NdofB1"},
370     {NDOF_BUTTON_2, "NDOF_BUTTON_2", 0, "NDOF Button 2", "NdofB2"},
371     {NDOF_BUTTON_3, "NDOF_BUTTON_3", 0, "NDOF Button 3", "NdofB3"},
372     {NDOF_BUTTON_4, "NDOF_BUTTON_4", 0, "NDOF Button 4", "NdofB4"},
373     {NDOF_BUTTON_5, "NDOF_BUTTON_5", 0, "NDOF Button 5", "NdofB5"},
374     {NDOF_BUTTON_6, "NDOF_BUTTON_6", 0, "NDOF Button 6", "NdofB6"},
375     {NDOF_BUTTON_7, "NDOF_BUTTON_7", 0, "NDOF Button 7", "NdofB7"},
376     {NDOF_BUTTON_8, "NDOF_BUTTON_8", 0, "NDOF Button 8", "NdofB8"},
377     {NDOF_BUTTON_9, "NDOF_BUTTON_9", 0, "NDOF Button 9", "NdofB9"},
378     {NDOF_BUTTON_10, "NDOF_BUTTON_10", 0, "NDOF Button 10", "NdofB10"},
379     {NDOF_BUTTON_A, "NDOF_BUTTON_A", 0, "NDOF Button A", "NdofBA"},
380     {NDOF_BUTTON_B, "NDOF_BUTTON_B", 0, "NDOF Button B", "NdofBB"},
381     {NDOF_BUTTON_C, "NDOF_BUTTON_C", 0, "NDOF Button C", "NdofBC"},
382     /* Action Zones. */
383     {EVT_ACTIONZONE_AREA, "ACTIONZONE_AREA", 0, "ActionZone Area", "AZone Area"},
384     {EVT_ACTIONZONE_REGION, "ACTIONZONE_REGION", 0, "ActionZone Region", "AZone Region"},
385     {EVT_ACTIONZONE_FULLSCREEN,
386      "ACTIONZONE_FULLSCREEN",
387      0,
388      "ActionZone Fullscreen",
389      "AZone FullScr"},
390     {0, NULL, 0, NULL, NULL},
391 };
392 
393 const EnumPropertyItem rna_enum_event_value_items[] = {
394     {KM_ANY, "ANY", 0, "Any", ""},
395     {KM_PRESS, "PRESS", 0, "Press", ""},
396     {KM_RELEASE, "RELEASE", 0, "Release", ""},
397     {KM_CLICK, "CLICK", 0, "Click", ""},
398     {KM_DBL_CLICK, "DOUBLE_CLICK", 0, "Double Click", ""},
399     {KM_CLICK_DRAG, "CLICK_DRAG", 0, "Click Drag", ""},
400     {EVT_GESTURE_N, "NORTH", 0, "North", ""},
401     {EVT_GESTURE_NE, "NORTH_EAST", 0, "North-East", ""},
402     {EVT_GESTURE_E, "EAST", 0, "East", ""},
403     {EVT_GESTURE_SE, "SOUTH_EAST", 0, "South-East", ""},
404     {EVT_GESTURE_S, "SOUTH", 0, "South", ""},
405     {EVT_GESTURE_SW, "SOUTH_WEST", 0, "South-West", ""},
406     {EVT_GESTURE_W, "WEST", 0, "West", ""},
407     {EVT_GESTURE_NW, "NORTH_WEST", 0, "North-West", ""},
408     {KM_NOTHING, "NOTHING", 0, "Nothing", ""},
409     {0, NULL, 0, NULL, NULL},
410 };
411 
412 const EnumPropertyItem rna_enum_keymap_propvalue_items[] = {
413     {0, "NONE", 0, "", ""},
414     {0, NULL, 0, NULL, NULL},
415 };
416 
417 /* Mask event types used in keymap items. */
418 const EnumPropertyItem rna_enum_event_type_mask_items[] = {
419     {EVT_TYPE_MASK_KEYBOARD_MODIFIER, "KEYBOARD_MODIFIER", 0, "Keyboard Modifier", ""},
420     {EVT_TYPE_MASK_KEYBOARD, "KEYBOARD", 0, "Keyboard", ""},
421     {EVT_TYPE_MASK_MOUSE_WHEEL, "MOUSE_WHEEL", 0, "Mouse Wheel", ""},
422     {EVT_TYPE_MASK_MOUSE_GESTURE, "MOUSE_GESTURE", 0, "Mouse Gesture", ""},
423     {EVT_TYPE_MASK_MOUSE_BUTTON, "MOUSE_BUTTON", 0, "Mouse Button", ""},
424     {EVT_TYPE_MASK_MOUSE, "MOUSE", 0, "Mouse", ""},
425     {EVT_TYPE_MASK_NDOF, "NDOF", 0, "NDOF", ""},
426     {EVT_TYPE_MASK_TWEAK, "TWEAK", 0, "Tweak", ""},
427     {EVT_TYPE_MASK_ACTIONZONE, "ACTIONZONE", 0, "Action Zone", ""},
428     {0, NULL, 0, NULL, NULL},
429 };
430 
431 #if 0
432 static const EnumPropertyItem keymap_modifiers_items[] = {
433     {KM_ANY, "ANY", 0, "Any", ""},
434     {0, "NONE", 0, "None", ""},
435     {1, "FIRST", 0, "First", ""},
436     {2, "SECOND", 0, "Second", ""},
437     {0, NULL, 0, NULL, NULL},
438 };
439 #endif
440 
441 const EnumPropertyItem rna_enum_operator_type_flag_items[] = {
442     {OPTYPE_REGISTER,
443      "REGISTER",
444      0,
445      "Register",
446      "Display in the info window and support the redo toolbar panel"},
447     {OPTYPE_UNDO, "UNDO", 0, "Undo", "Push an undo event (needed for operator redo)"},
448     {OPTYPE_UNDO_GROUPED,
449      "UNDO_GROUPED",
450      0,
451      "Grouped Undo",
452      "Push a single undo event for repeated instances of this operator"},
453     {OPTYPE_BLOCKING, "BLOCKING", 0, "Blocking", "Block anything else from using the cursor"},
454     {OPTYPE_MACRO, "MACRO", 0, "Macro", "Use to check if an operator is a macro"},
455     {OPTYPE_GRAB_CURSOR_XY,
456      "GRAB_CURSOR",
457      0,
458      "Grab Pointer",
459      "Use so the operator grabs the mouse focus, enables wrapping when continuous grab "
460      "is enabled"},
461     {OPTYPE_GRAB_CURSOR_X, "GRAB_CURSOR_X", 0, "Grab Pointer X", "Grab, only warping the X axis"},
462     {OPTYPE_GRAB_CURSOR_Y, "GRAB_CURSOR_Y", 0, "Grab Pointer Y", "Grab, only warping the Y axis"},
463     {OPTYPE_PRESET, "PRESET", 0, "Preset", "Display a preset button with the operators settings"},
464     {OPTYPE_INTERNAL, "INTERNAL", 0, "Internal", "Removes the operator from search results"},
465     {0, NULL, 0, NULL, NULL},
466 };
467 
468 const EnumPropertyItem rna_enum_operator_return_items[] = {
469     {OPERATOR_RUNNING_MODAL,
470      "RUNNING_MODAL",
471      0,
472      "Running Modal",
473      "Keep the operator running with blender"},
474     {OPERATOR_CANCELLED,
475      "CANCELLED",
476      0,
477      "Cancelled",
478      "The operator exited without doing anything, so no undo entry should be pushed"},
479     {OPERATOR_FINISHED,
480      "FINISHED",
481      0,
482      "Finished",
483      "The operator exited after completing its action"},
484     /* used as a flag */
485     {OPERATOR_PASS_THROUGH, "PASS_THROUGH", 0, "Pass Through", "Do nothing and pass the event on"},
486     {OPERATOR_INTERFACE, "INTERFACE", 0, "Interface", "Handled but not executed (popup menus)"},
487     {0, NULL, 0, NULL, NULL},
488 };
489 
490 const EnumPropertyItem rna_enum_operator_property_tags[] = {
491     {OP_PROP_TAG_ADVANCED,
492      "ADVANCED",
493      0,
494      "Advanced",
495      "The property is advanced so UI is suggested to hide it"},
496     {0, NULL, 0, NULL, NULL},
497 };
498 
499 /* flag/enum */
500 const EnumPropertyItem rna_enum_wm_report_items[] = {
501     {RPT_DEBUG, "DEBUG", 0, "Debug", ""},
502     {RPT_INFO, "INFO", 0, "Info", ""},
503     {RPT_OPERATOR, "OPERATOR", 0, "Operator", ""},
504     {RPT_PROPERTY, "PROPERTY", 0, "Property", ""},
505     {RPT_WARNING, "WARNING", 0, "Warning", ""},
506     {RPT_ERROR, "ERROR", 0, "Error", ""},
507     {RPT_ERROR_INVALID_INPUT, "ERROR_INVALID_INPUT", 0, "Invalid Input", ""},
508     {RPT_ERROR_INVALID_CONTEXT, "ERROR_INVALID_CONTEXT", 0, "Invalid Context", ""},
509     {RPT_ERROR_OUT_OF_MEMORY, "ERROR_OUT_OF_MEMORY", 0, "Out of Memory", ""},
510     {0, NULL, 0, NULL, NULL},
511 };
512 
513 #ifdef RNA_RUNTIME
514 
515 #  include "BLI_string_utils.h"
516 
517 #  include "WM_api.h"
518 
519 #  include "DNA_object_types.h"
520 #  include "DNA_workspace_types.h"
521 
522 #  include "ED_screen.h"
523 
524 #  include "UI_interface.h"
525 
526 #  include "BKE_global.h"
527 #  include "BKE_idprop.h"
528 
529 #  include "MEM_guardedalloc.h"
530 
531 #  ifdef WITH_PYTHON
532 #    include "BPY_extern.h"
533 #  endif
534 
rna_OperatorProperties_find_operator(PointerRNA * ptr)535 static wmOperator *rna_OperatorProperties_find_operator(PointerRNA *ptr)
536 {
537   wmWindowManager *wm = (wmWindowManager *)ptr->owner_id;
538 
539   if (wm) {
540     IDProperty *properties = (IDProperty *)ptr->data;
541     for (wmOperator *op = wm->operators.last; op; op = op->prev) {
542       if (op->properties == properties) {
543         return op;
544       }
545     }
546   }
547 
548   return NULL;
549 }
550 
rna_OperatorProperties_refine(PointerRNA * ptr)551 static StructRNA *rna_OperatorProperties_refine(PointerRNA *ptr)
552 {
553   wmOperator *op = rna_OperatorProperties_find_operator(ptr);
554 
555   if (op) {
556     return op->type->srna;
557   }
558   else {
559     return ptr->type;
560   }
561 }
562 
rna_OperatorProperties_idprops(PointerRNA * ptr,bool create)563 static IDProperty *rna_OperatorProperties_idprops(PointerRNA *ptr, bool create)
564 {
565   if (create && !ptr->data) {
566     IDPropertyTemplate val = {0};
567     ptr->data = IDP_New(IDP_GROUP, &val, "RNA_OperatorProperties group");
568   }
569 
570   return ptr->data;
571 }
572 
rna_Operator_name_get(PointerRNA * ptr,char * value)573 static void rna_Operator_name_get(PointerRNA *ptr, char *value)
574 {
575   wmOperator *op = (wmOperator *)ptr->data;
576   strcpy(value, op->type->name);
577 }
578 
rna_Operator_name_length(PointerRNA * ptr)579 static int rna_Operator_name_length(PointerRNA *ptr)
580 {
581   wmOperator *op = (wmOperator *)ptr->data;
582   return strlen(op->type->name);
583 }
584 
rna_Operator_has_reports_get(PointerRNA * ptr)585 static bool rna_Operator_has_reports_get(PointerRNA *ptr)
586 {
587   wmOperator *op = (wmOperator *)ptr->data;
588   return (op->reports && op->reports->list.first);
589 }
590 
rna_Operator_options_get(PointerRNA * ptr)591 static PointerRNA rna_Operator_options_get(PointerRNA *ptr)
592 {
593   return rna_pointer_inherit_refine(ptr, &RNA_OperatorOptions, ptr->data);
594 }
595 
rna_Operator_properties_get(PointerRNA * ptr)596 static PointerRNA rna_Operator_properties_get(PointerRNA *ptr)
597 {
598   wmOperator *op = (wmOperator *)ptr->data;
599   return rna_pointer_inherit_refine(ptr, op->type->srna, op->properties);
600 }
601 
rna_OperatorMacro_properties_get(PointerRNA * ptr)602 static PointerRNA rna_OperatorMacro_properties_get(PointerRNA *ptr)
603 {
604   wmOperatorTypeMacro *otmacro = (wmOperatorTypeMacro *)ptr->data;
605   wmOperatorType *ot = WM_operatortype_find(otmacro->idname, true);
606   return rna_pointer_inherit_refine(ptr, ot->srna, otmacro->properties);
607 }
608 
rna_Event_ascii_get(PointerRNA * ptr,char * value)609 static void rna_Event_ascii_get(PointerRNA *ptr, char *value)
610 {
611   const wmEvent *event = ptr->data;
612   value[0] = event->ascii;
613   value[1] = '\0';
614 }
615 
rna_Event_ascii_length(PointerRNA * ptr)616 static int rna_Event_ascii_length(PointerRNA *ptr)
617 {
618   const wmEvent *event = ptr->data;
619   return (event->ascii) ? 1 : 0;
620 }
621 
rna_Event_unicode_get(PointerRNA * ptr,char * value)622 static void rna_Event_unicode_get(PointerRNA *ptr, char *value)
623 {
624   /* utf8 buf isn't \0 terminated */
625   const wmEvent *event = ptr->data;
626   size_t len = 0;
627 
628   if (event->utf8_buf[0]) {
629     BLI_str_utf8_as_unicode_and_size(event->utf8_buf, &len);
630     if (len > 0) {
631       memcpy(value, event->utf8_buf, len);
632     }
633   }
634 
635   value[len] = '\0';
636 }
637 
rna_Event_unicode_length(PointerRNA * ptr)638 static int rna_Event_unicode_length(PointerRNA *ptr)
639 {
640 
641   const wmEvent *event = ptr->data;
642   if (event->utf8_buf[0]) {
643     /* invalid value is checked on assignment so we don't need to account for this */
644     return BLI_str_utf8_size(event->utf8_buf);
645   }
646   else {
647     return 0;
648   }
649 }
650 
rna_Event_is_repeat_get(PointerRNA * ptr)651 static bool rna_Event_is_repeat_get(PointerRNA *ptr)
652 {
653   const wmEvent *event = ptr->data;
654   return event->is_repeat;
655 }
656 
rna_Event_pressure_get(PointerRNA * ptr)657 static float rna_Event_pressure_get(PointerRNA *ptr)
658 {
659   const wmEvent *event = ptr->data;
660   return WM_event_tablet_data(event, NULL, NULL);
661 }
662 
rna_Event_is_tablet_get(PointerRNA * ptr)663 static bool rna_Event_is_tablet_get(PointerRNA *ptr)
664 {
665   const wmEvent *event = ptr->data;
666   return WM_event_is_tablet(event);
667 }
668 
rna_Event_tilt_get(PointerRNA * ptr,float * values)669 static void rna_Event_tilt_get(PointerRNA *ptr, float *values)
670 {
671   wmEvent *event = ptr->data;
672   WM_event_tablet_data(event, NULL, values);
673 }
674 
rna_PopupMenu_layout_get(PointerRNA * ptr)675 static PointerRNA rna_PopupMenu_layout_get(PointerRNA *ptr)
676 {
677   struct uiPopupMenu *pup = ptr->data;
678   uiLayout *layout = UI_popup_menu_layout(pup);
679 
680   PointerRNA rptr;
681   RNA_pointer_create(ptr->owner_id, &RNA_UILayout, layout, &rptr);
682 
683   return rptr;
684 }
685 
rna_PopoverMenu_layout_get(PointerRNA * ptr)686 static PointerRNA rna_PopoverMenu_layout_get(PointerRNA *ptr)
687 {
688   struct uiPopover *pup = ptr->data;
689   uiLayout *layout = UI_popover_layout(pup);
690 
691   PointerRNA rptr;
692   RNA_pointer_create(ptr->owner_id, &RNA_UILayout, layout, &rptr);
693 
694   return rptr;
695 }
696 
rna_PieMenu_layout_get(PointerRNA * ptr)697 static PointerRNA rna_PieMenu_layout_get(PointerRNA *ptr)
698 {
699   struct uiPieMenu *pie = ptr->data;
700   uiLayout *layout = UI_pie_menu_layout(pie);
701 
702   PointerRNA rptr;
703   RNA_pointer_create(ptr->owner_id, &RNA_UILayout, layout, &rptr);
704 
705   return rptr;
706 }
707 
rna_Window_scene_set(PointerRNA * ptr,PointerRNA value,struct ReportList * UNUSED (reports))708 static void rna_Window_scene_set(PointerRNA *ptr,
709                                  PointerRNA value,
710                                  struct ReportList *UNUSED(reports))
711 {
712   wmWindow *win = ptr->data;
713 
714   if (value.data == NULL) {
715     return;
716   }
717 
718   win->new_scene = value.data;
719 }
720 
rna_Window_scene_update(bContext * C,PointerRNA * ptr)721 static void rna_Window_scene_update(bContext *C, PointerRNA *ptr)
722 {
723   Main *bmain = CTX_data_main(C);
724   wmWindow *win = ptr->data;
725 
726   /* exception: must use context so notifier gets to the right window  */
727   if (win->new_scene) {
728 #  ifdef WITH_PYTHON
729     BPy_BEGIN_ALLOW_THREADS;
730 #  endif
731 
732     WM_window_set_active_scene(bmain, C, win, win->new_scene);
733 
734 #  ifdef WITH_PYTHON
735     BPy_END_ALLOW_THREADS;
736 #  endif
737 
738     wmWindowManager *wm = CTX_wm_manager(C);
739     WM_event_add_notifier_ex(wm, win, NC_SCENE | ND_SCENEBROWSE, win->new_scene);
740 
741     if (G.debug & G_DEBUG) {
742       printf("scene set %p\n", win->new_scene);
743     }
744 
745     win->new_scene = NULL;
746   }
747 }
748 
rna_Window_workspace_get(PointerRNA * ptr)749 static PointerRNA rna_Window_workspace_get(PointerRNA *ptr)
750 {
751   wmWindow *win = ptr->data;
752   return rna_pointer_inherit_refine(
753       ptr, &RNA_WorkSpace, BKE_workspace_active_get(win->workspace_hook));
754 }
755 
rna_Window_workspace_set(PointerRNA * ptr,PointerRNA value,struct ReportList * UNUSED (reports))756 static void rna_Window_workspace_set(PointerRNA *ptr,
757                                      PointerRNA value,
758                                      struct ReportList *UNUSED(reports))
759 {
760   wmWindow *win = (wmWindow *)ptr->data;
761 
762   /* disallow ID-browsing away from temp screens */
763   if (WM_window_is_temp_screen(win)) {
764     return;
765   }
766   if (value.data == NULL) {
767     return;
768   }
769 
770   /* exception: can't set workspaces inside of area/region handlers */
771   win->workspace_hook->temp_workspace_store = value.data;
772 }
773 
rna_Window_workspace_update(bContext * C,PointerRNA * ptr)774 static void rna_Window_workspace_update(bContext *C, PointerRNA *ptr)
775 {
776   wmWindow *win = ptr->data;
777   WorkSpace *new_workspace = win->workspace_hook->temp_workspace_store;
778 
779   /* exception: can't set screens inside of area/region handlers,
780    * and must use context so notifier gets to the right window */
781   if (new_workspace) {
782     wmWindowManager *wm = CTX_wm_manager(C);
783     WM_event_add_notifier_ex(wm, win, NC_SCREEN | ND_WORKSPACE_SET, new_workspace);
784     win->workspace_hook->temp_workspace_store = NULL;
785   }
786 }
787 
rna_Window_screen_get(PointerRNA * ptr)788 PointerRNA rna_Window_screen_get(PointerRNA *ptr)
789 {
790   wmWindow *win = ptr->data;
791   return rna_pointer_inherit_refine(
792       ptr, &RNA_Screen, BKE_workspace_active_screen_get(win->workspace_hook));
793 }
794 
rna_Window_screen_set(PointerRNA * ptr,PointerRNA value,struct ReportList * UNUSED (reports))795 static void rna_Window_screen_set(PointerRNA *ptr,
796                                   PointerRNA value,
797                                   struct ReportList *UNUSED(reports))
798 {
799   wmWindow *win = ptr->data;
800   WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook);
801   WorkSpaceLayout *layout_new;
802   const bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook);
803 
804   /* disallow ID-browsing away from temp screens */
805   if (screen->temp) {
806     return;
807   }
808   if (value.data == NULL) {
809     return;
810   }
811 
812   /* exception: can't set screens inside of area/region handlers */
813   layout_new = BKE_workspace_layout_find(workspace, value.data);
814   win->workspace_hook->temp_layout_store = layout_new;
815 }
816 
rna_Window_screen_assign_poll(PointerRNA * UNUSED (ptr),PointerRNA value)817 static bool rna_Window_screen_assign_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
818 {
819   bScreen *screen = (bScreen *)value.owner_id;
820   return !screen->temp;
821 }
822 
rna_workspace_screen_update(bContext * C,PointerRNA * ptr)823 static void rna_workspace_screen_update(bContext *C, PointerRNA *ptr)
824 {
825   wmWindow *win = ptr->data;
826   WorkSpaceLayout *layout_new = win->workspace_hook->temp_layout_store;
827 
828   /* exception: can't set screens inside of area/region handlers,
829    * and must use context so notifier gets to the right window */
830   if (layout_new) {
831     wmWindowManager *wm = CTX_wm_manager(C);
832     WM_event_add_notifier_ex(wm, win, NC_SCREEN | ND_LAYOUTBROWSE, layout_new);
833     win->workspace_hook->temp_layout_store = NULL;
834   }
835 }
836 
rna_Window_view_layer_get(PointerRNA * ptr)837 static PointerRNA rna_Window_view_layer_get(PointerRNA *ptr)
838 {
839   wmWindow *win = ptr->data;
840   Scene *scene = WM_window_get_active_scene(win);
841   ViewLayer *view_layer = WM_window_get_active_view_layer(win);
842   PointerRNA scene_ptr;
843 
844   RNA_id_pointer_create(&scene->id, &scene_ptr);
845   return rna_pointer_inherit_refine(&scene_ptr, &RNA_ViewLayer, view_layer);
846 }
847 
rna_Window_view_layer_set(PointerRNA * ptr,PointerRNA value,struct ReportList * UNUSED (reports))848 static void rna_Window_view_layer_set(PointerRNA *ptr,
849                                       PointerRNA value,
850                                       struct ReportList *UNUSED(reports))
851 {
852   wmWindow *win = ptr->data;
853   ViewLayer *view_layer = value.data;
854 
855   WM_window_set_active_view_layer(win, view_layer);
856 }
857 
rna_KeyMapItem_properties_get(PointerRNA * ptr)858 static PointerRNA rna_KeyMapItem_properties_get(PointerRNA *ptr)
859 {
860   wmKeyMapItem *kmi = ptr->data;
861 
862   if (kmi->ptr) {
863     return *(kmi->ptr);
864   }
865 
866   /*return rna_pointer_inherit_refine(ptr, &RNA_OperatorProperties, op->properties); */
867   return PointerRNA_NULL;
868 }
869 
rna_wmKeyMapItem_map_type_get(PointerRNA * ptr)870 static int rna_wmKeyMapItem_map_type_get(PointerRNA *ptr)
871 {
872   wmKeyMapItem *kmi = ptr->data;
873 
874   return WM_keymap_item_map_type_get(kmi);
875 }
876 
rna_wmKeyMapItem_map_type_set(PointerRNA * ptr,int value)877 static void rna_wmKeyMapItem_map_type_set(PointerRNA *ptr, int value)
878 {
879   wmKeyMapItem *kmi = ptr->data;
880   int map_type = rna_wmKeyMapItem_map_type_get(ptr);
881 
882   if (value != map_type) {
883     switch (value) {
884       case KMI_TYPE_KEYBOARD:
885         kmi->type = EVT_AKEY;
886         kmi->val = KM_PRESS;
887         break;
888       case KMI_TYPE_TWEAK:
889         kmi->type = EVT_TWEAK_L;
890         kmi->val = KM_ANY;
891         break;
892       case KMI_TYPE_MOUSE:
893         kmi->type = LEFTMOUSE;
894         kmi->val = KM_PRESS;
895         break;
896       case KMI_TYPE_TEXTINPUT:
897         kmi->type = KM_TEXTINPUT;
898         kmi->val = KM_NOTHING;
899         break;
900       case KMI_TYPE_TIMER:
901         kmi->type = TIMER;
902         kmi->val = KM_NOTHING;
903         break;
904       case KMI_TYPE_NDOF:
905         kmi->type = NDOF_MOTION;
906         kmi->val = KM_NOTHING;
907         break;
908     }
909   }
910 }
911 
912 /* assumes value to be an enum from rna_enum_event_type_items */
913 /* function makes sure keymodifiers are only valid keys, ESC keeps it unaltered */
rna_wmKeyMapItem_keymodifier_set(PointerRNA * ptr,int value)914 static void rna_wmKeyMapItem_keymodifier_set(PointerRNA *ptr, int value)
915 {
916   wmKeyMapItem *kmi = ptr->data;
917 
918   /* XXX, this should really be managed in an _itemf function,
919    * giving a list of valid enums, then silently changing them when they are set is not
920    * a good precedent, don't do this unless you have a good reason! */
921   if (value == EVT_ESCKEY) {
922     /* pass */
923   }
924   else if (value >= EVT_AKEY) {
925     kmi->keymodifier = value;
926   }
927   else {
928     kmi->keymodifier = 0;
929   }
930 }
931 
rna_KeyMapItem_type_itemf(bContext * UNUSED (C),PointerRNA * ptr,PropertyRNA * UNUSED (prop),bool * UNUSED (r_free))932 static const EnumPropertyItem *rna_KeyMapItem_type_itemf(bContext *UNUSED(C),
933                                                          PointerRNA *ptr,
934                                                          PropertyRNA *UNUSED(prop),
935                                                          bool *UNUSED(r_free))
936 {
937   int map_type = rna_wmKeyMapItem_map_type_get(ptr);
938 
939   if (map_type == KMI_TYPE_MOUSE) {
940     return event_mouse_type_items;
941   }
942   if (map_type == KMI_TYPE_TWEAK) {
943     return event_tweak_type_items;
944   }
945   if (map_type == KMI_TYPE_TIMER) {
946     return event_timer_type_items;
947   }
948   if (map_type == KMI_TYPE_NDOF) {
949     return event_ndof_type_items;
950   }
951   if (map_type == KMI_TYPE_TEXTINPUT) {
952     return event_textinput_type_items;
953   }
954   else {
955     return rna_enum_event_type_items;
956   }
957 }
958 
rna_KeyMapItem_value_itemf(bContext * UNUSED (C),PointerRNA * ptr,PropertyRNA * UNUSED (prop),bool * UNUSED (r_free))959 static const EnumPropertyItem *rna_KeyMapItem_value_itemf(bContext *UNUSED(C),
960                                                           PointerRNA *ptr,
961                                                           PropertyRNA *UNUSED(prop),
962                                                           bool *UNUSED(r_free))
963 {
964   int map_type = rna_wmKeyMapItem_map_type_get(ptr);
965 
966   if (map_type == KMI_TYPE_MOUSE || map_type == KMI_TYPE_KEYBOARD || map_type == KMI_TYPE_NDOF) {
967     return event_keymouse_value_items;
968   }
969   if (map_type == KMI_TYPE_TWEAK) {
970     return event_tweak_value_items;
971   }
972   else {
973     return rna_enum_event_value_items;
974   }
975 }
976 
rna_KeyMapItem_propvalue_itemf(bContext * C,PointerRNA * ptr,PropertyRNA * UNUSED (prop),bool * UNUSED (r_free))977 static const EnumPropertyItem *rna_KeyMapItem_propvalue_itemf(bContext *C,
978                                                               PointerRNA *ptr,
979                                                               PropertyRNA *UNUSED(prop),
980                                                               bool *UNUSED(r_free))
981 {
982   wmWindowManager *wm = CTX_wm_manager(C);
983   wmKeyConfig *kc;
984   wmKeyMap *km;
985 
986   for (kc = wm->keyconfigs.first; kc; kc = kc->next) {
987     for (km = kc->keymaps.first; km; km = km->next) {
988       /* only check if it's a modal keymap */
989       if (km->modal_items) {
990         wmKeyMapItem *kmi;
991         for (kmi = km->items.first; kmi; kmi = kmi->next) {
992           if (kmi == ptr->data) {
993             return km->modal_items;
994           }
995         }
996       }
997     }
998   }
999 
1000   return rna_enum_keymap_propvalue_items; /* ERROR */
1001 }
1002 
rna_KeyMapItem_any_get(PointerRNA * ptr)1003 static bool rna_KeyMapItem_any_get(PointerRNA *ptr)
1004 {
1005   wmKeyMapItem *kmi = (wmKeyMapItem *)ptr->data;
1006 
1007   if (kmi->shift == KM_ANY && kmi->ctrl == KM_ANY && kmi->alt == KM_ANY && kmi->oskey == KM_ANY) {
1008     return 1;
1009   }
1010   else {
1011     return 0;
1012   }
1013 }
1014 
rna_KeyMapItem_any_set(PointerRNA * ptr,bool value)1015 static void rna_KeyMapItem_any_set(PointerRNA *ptr, bool value)
1016 {
1017   wmKeyMapItem *kmi = (wmKeyMapItem *)ptr->data;
1018 
1019   if (value) {
1020     kmi->shift = kmi->ctrl = kmi->alt = kmi->oskey = KM_ANY;
1021   }
1022   else {
1023     kmi->shift = kmi->ctrl = kmi->alt = kmi->oskey = 0;
1024   }
1025 }
1026 
rna_KeyMapItem_shift_get(PointerRNA * ptr)1027 static bool rna_KeyMapItem_shift_get(PointerRNA *ptr)
1028 {
1029   wmKeyMapItem *kmi = (wmKeyMapItem *)ptr->data;
1030   return kmi->shift != 0;
1031 }
1032 
rna_KeyMapItem_ctrl_get(PointerRNA * ptr)1033 static bool rna_KeyMapItem_ctrl_get(PointerRNA *ptr)
1034 {
1035   wmKeyMapItem *kmi = (wmKeyMapItem *)ptr->data;
1036   return kmi->ctrl != 0;
1037 }
1038 
rna_KeyMapItem_alt_get(PointerRNA * ptr)1039 static bool rna_KeyMapItem_alt_get(PointerRNA *ptr)
1040 {
1041   wmKeyMapItem *kmi = (wmKeyMapItem *)ptr->data;
1042   return kmi->alt != 0;
1043 }
1044 
rna_KeyMapItem_oskey_get(PointerRNA * ptr)1045 static bool rna_KeyMapItem_oskey_get(PointerRNA *ptr)
1046 {
1047   wmKeyMapItem *kmi = (wmKeyMapItem *)ptr->data;
1048   return kmi->oskey != 0;
1049 }
1050 
rna_WindowManager_active_keyconfig_get(PointerRNA * ptr)1051 static PointerRNA rna_WindowManager_active_keyconfig_get(PointerRNA *ptr)
1052 {
1053   wmWindowManager *wm = ptr->data;
1054   wmKeyConfig *kc;
1055 
1056   kc = BLI_findstring(&wm->keyconfigs, U.keyconfigstr, offsetof(wmKeyConfig, idname));
1057 
1058   if (!kc) {
1059     kc = wm->defaultconf;
1060   }
1061 
1062   return rna_pointer_inherit_refine(ptr, &RNA_KeyConfig, kc);
1063 }
1064 
rna_WindowManager_active_keyconfig_set(PointerRNA * ptr,PointerRNA value,struct ReportList * UNUSED (reports))1065 static void rna_WindowManager_active_keyconfig_set(PointerRNA *ptr,
1066                                                    PointerRNA value,
1067                                                    struct ReportList *UNUSED(reports))
1068 {
1069   wmWindowManager *wm = ptr->data;
1070   wmKeyConfig *kc = value.data;
1071 
1072   if (kc) {
1073     WM_keyconfig_set_active(wm, kc->idname);
1074   }
1075 }
1076 
1077 /* -------------------------------------------------------------------- */
1078 /** \name Key Config Preferences
1079  * \{ */
1080 
rna_wmKeyConfig_preferences_get(PointerRNA * ptr)1081 static PointerRNA rna_wmKeyConfig_preferences_get(PointerRNA *ptr)
1082 {
1083   wmKeyConfig *kc = ptr->data;
1084   wmKeyConfigPrefType_Runtime *kpt_rt = BKE_keyconfig_pref_type_find(kc->idname, true);
1085   if (kpt_rt) {
1086     wmKeyConfigPref *kpt = BKE_keyconfig_pref_ensure(&U, kc->idname);
1087     return rna_pointer_inherit_refine(ptr, kpt_rt->rna_ext.srna, kpt->prop);
1088   }
1089   else {
1090     return PointerRNA_NULL;
1091   }
1092 }
1093 
rna_wmKeyConfigPref_idprops(PointerRNA * ptr,bool create)1094 static IDProperty *rna_wmKeyConfigPref_idprops(PointerRNA *ptr, bool create)
1095 {
1096   if (create && !ptr->data) {
1097     IDPropertyTemplate val = {0};
1098     ptr->data = IDP_New(IDP_GROUP, &val, "RNA_KeyConfigPreferences group");
1099   }
1100   return ptr->data;
1101 }
1102 
rna_wmKeyConfigPref_unregister(Main * UNUSED (bmain),StructRNA * type)1103 static void rna_wmKeyConfigPref_unregister(Main *UNUSED(bmain), StructRNA *type)
1104 {
1105   wmKeyConfigPrefType_Runtime *kpt_rt = RNA_struct_blender_type_get(type);
1106 
1107   if (!kpt_rt) {
1108     return;
1109   }
1110 
1111   RNA_struct_free_extension(type, &kpt_rt->rna_ext);
1112   RNA_struct_free(&BLENDER_RNA, type);
1113 
1114   /* Possible we're not in the preferences if they have been reset. */
1115   BKE_keyconfig_pref_type_remove(kpt_rt);
1116 
1117   /* update while blender is running */
1118   WM_main_add_notifier(NC_WINDOW, NULL);
1119 }
1120 
rna_wmKeyConfigPref_register(Main * bmain,ReportList * reports,void * data,const char * identifier,StructValidateFunc validate,StructCallbackFunc call,StructFreeFunc free)1121 static StructRNA *rna_wmKeyConfigPref_register(Main *bmain,
1122                                                ReportList *reports,
1123                                                void *data,
1124                                                const char *identifier,
1125                                                StructValidateFunc validate,
1126                                                StructCallbackFunc call,
1127                                                StructFreeFunc free)
1128 {
1129   wmKeyConfigPrefType_Runtime *kpt_rt, dummy_kpt_rt = {{'\0'}};
1130   wmKeyConfigPref dummy_kpt = {NULL};
1131   PointerRNA dummy_ptr;
1132   // int have_function[1];
1133 
1134   /* setup dummy keyconf-prefs & keyconf-prefs type to store static properties in */
1135   RNA_pointer_create(NULL, &RNA_KeyConfigPreferences, &dummy_kpt, &dummy_ptr);
1136 
1137   /* validate the python class */
1138   if (validate(&dummy_ptr, data, NULL /* have_function */) != 0) {
1139     return NULL;
1140   }
1141 
1142   STRNCPY(dummy_kpt_rt.idname, dummy_kpt.idname);
1143   if (strlen(identifier) >= sizeof(dummy_kpt_rt.idname)) {
1144     BKE_reportf(reports,
1145                 RPT_ERROR,
1146                 "Registering key-config preferences class: '%s' is too long, maximum length is %d",
1147                 identifier,
1148                 (int)sizeof(dummy_kpt_rt.idname));
1149     return NULL;
1150   }
1151 
1152   /* check if we have registered this keyconf-prefs type before, and remove it */
1153   kpt_rt = BKE_keyconfig_pref_type_find(dummy_kpt.idname, true);
1154   if (kpt_rt && kpt_rt->rna_ext.srna) {
1155     rna_wmKeyConfigPref_unregister(bmain, kpt_rt->rna_ext.srna);
1156   }
1157 
1158   /* create a new keyconf-prefs type */
1159   kpt_rt = MEM_mallocN(sizeof(wmKeyConfigPrefType_Runtime), "keyconfigpreftype");
1160   memcpy(kpt_rt, &dummy_kpt_rt, sizeof(dummy_kpt_rt));
1161 
1162   BKE_keyconfig_pref_type_add(kpt_rt);
1163 
1164   kpt_rt->rna_ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, identifier, &RNA_KeyConfigPreferences);
1165   kpt_rt->rna_ext.data = data;
1166   kpt_rt->rna_ext.call = call;
1167   kpt_rt->rna_ext.free = free;
1168   RNA_struct_blender_type_set(kpt_rt->rna_ext.srna, kpt_rt);
1169 
1170   //  kpt_rt->draw = (have_function[0]) ? header_draw : NULL;
1171 
1172   /* update while blender is running */
1173   WM_main_add_notifier(NC_WINDOW, NULL);
1174 
1175   return kpt_rt->rna_ext.srna;
1176 }
1177 
1178 /* placeholder, doesn't do anything useful yet */
rna_wmKeyConfigPref_refine(PointerRNA * ptr)1179 static StructRNA *rna_wmKeyConfigPref_refine(PointerRNA *ptr)
1180 {
1181   return (ptr->type) ? ptr->type : &RNA_KeyConfigPreferences;
1182 }
1183 
1184 /** \} */
1185 
rna_wmKeyMapItem_idname_get(PointerRNA * ptr,char * value)1186 static void rna_wmKeyMapItem_idname_get(PointerRNA *ptr, char *value)
1187 {
1188   wmKeyMapItem *kmi = ptr->data;
1189   WM_operator_py_idname(value, kmi->idname);
1190 }
1191 
rna_wmKeyMapItem_idname_length(PointerRNA * ptr)1192 static int rna_wmKeyMapItem_idname_length(PointerRNA *ptr)
1193 {
1194   wmKeyMapItem *kmi = ptr->data;
1195   char pyname[OP_MAX_TYPENAME];
1196 
1197   WM_operator_py_idname(pyname, kmi->idname);
1198   return strlen(pyname);
1199 }
1200 
rna_wmKeyMapItem_idname_set(PointerRNA * ptr,const char * value)1201 static void rna_wmKeyMapItem_idname_set(PointerRNA *ptr, const char *value)
1202 {
1203   wmKeyMapItem *kmi = ptr->data;
1204   char idname[OP_MAX_TYPENAME];
1205 
1206   WM_operator_bl_idname(idname, value);
1207 
1208   if (!STREQ(idname, kmi->idname)) {
1209     BLI_strncpy(kmi->idname, idname, sizeof(kmi->idname));
1210 
1211     WM_keymap_item_properties_reset(kmi, NULL);
1212   }
1213 }
1214 
rna_wmKeyMapItem_name_get(PointerRNA * ptr,char * value)1215 static void rna_wmKeyMapItem_name_get(PointerRNA *ptr, char *value)
1216 {
1217   wmKeyMapItem *kmi = ptr->data;
1218   wmOperatorType *ot = WM_operatortype_find(kmi->idname, 1);
1219   strcpy(value, ot ? WM_operatortype_name(ot, kmi->ptr) : kmi->idname);
1220 }
1221 
rna_wmKeyMapItem_name_length(PointerRNA * ptr)1222 static int rna_wmKeyMapItem_name_length(PointerRNA *ptr)
1223 {
1224   wmKeyMapItem *kmi = ptr->data;
1225   wmOperatorType *ot = WM_operatortype_find(kmi->idname, 1);
1226   return strlen(ot ? WM_operatortype_name(ot, kmi->ptr) : kmi->idname);
1227 }
1228 
rna_KeyMapItem_userdefined_get(PointerRNA * ptr)1229 static bool rna_KeyMapItem_userdefined_get(PointerRNA *ptr)
1230 {
1231   wmKeyMapItem *kmi = ptr->data;
1232   return kmi->id < 0;
1233 }
1234 
rna_WindowManager_xr_session_state_get(PointerRNA * ptr)1235 static PointerRNA rna_WindowManager_xr_session_state_get(PointerRNA *ptr)
1236 {
1237   wmWindowManager *wm = ptr->data;
1238   struct wmXrSessionState *state =
1239 #  ifdef WITH_XR_OPENXR
1240       WM_xr_session_state_handle_get(&wm->xr);
1241 #  else
1242       NULL;
1243   UNUSED_VARS(wm);
1244 #  endif
1245 
1246   return rna_pointer_inherit_refine(ptr, &RNA_XrSessionState, state);
1247 }
1248 
1249 #  ifdef WITH_PYTHON
1250 
rna_operator_poll_cb(bContext * C,wmOperatorType * ot)1251 static bool rna_operator_poll_cb(bContext *C, wmOperatorType *ot)
1252 {
1253   extern FunctionRNA rna_Operator_poll_func;
1254 
1255   PointerRNA ptr;
1256   ParameterList list;
1257   FunctionRNA *func;
1258   void *ret;
1259   bool visible;
1260 
1261   RNA_pointer_create(NULL, ot->rna_ext.srna, NULL, &ptr); /* dummy */
1262   func = &rna_Operator_poll_func; /* RNA_struct_find_function(&ptr, "poll"); */
1263 
1264   RNA_parameter_list_create(&list, &ptr, func);
1265   RNA_parameter_set_lookup(&list, "context", &C);
1266   ot->rna_ext.call(C, &ptr, func, &list);
1267 
1268   RNA_parameter_get_lookup(&list, "visible", &ret);
1269   visible = *(bool *)ret;
1270 
1271   RNA_parameter_list_free(&list);
1272 
1273   return visible;
1274 }
1275 
rna_operator_execute_cb(bContext * C,wmOperator * op)1276 static int rna_operator_execute_cb(bContext *C, wmOperator *op)
1277 {
1278   extern FunctionRNA rna_Operator_execute_func;
1279 
1280   PointerRNA opr;
1281   ParameterList list;
1282   FunctionRNA *func;
1283   void *ret;
1284   int result;
1285 
1286   RNA_pointer_create(NULL, op->type->rna_ext.srna, op, &opr);
1287   func = &rna_Operator_execute_func; /* RNA_struct_find_function(&opr, "execute"); */
1288 
1289   RNA_parameter_list_create(&list, &opr, func);
1290   RNA_parameter_set_lookup(&list, "context", &C);
1291   op->type->rna_ext.call(C, &opr, func, &list);
1292 
1293   RNA_parameter_get_lookup(&list, "result", &ret);
1294   result = *(int *)ret;
1295 
1296   RNA_parameter_list_free(&list);
1297 
1298   return result;
1299 }
1300 
1301 /* same as execute() but no return value */
rna_operator_check_cb(bContext * C,wmOperator * op)1302 static bool rna_operator_check_cb(bContext *C, wmOperator *op)
1303 {
1304   extern FunctionRNA rna_Operator_check_func;
1305 
1306   PointerRNA opr;
1307   ParameterList list;
1308   FunctionRNA *func;
1309   void *ret;
1310   bool result;
1311 
1312   RNA_pointer_create(NULL, op->type->rna_ext.srna, op, &opr);
1313   func = &rna_Operator_check_func; /* RNA_struct_find_function(&opr, "check"); */
1314 
1315   RNA_parameter_list_create(&list, &opr, func);
1316   RNA_parameter_set_lookup(&list, "context", &C);
1317   op->type->rna_ext.call(C, &opr, func, &list);
1318 
1319   RNA_parameter_get_lookup(&list, "result", &ret);
1320   result = (*(bool *)ret) != 0;
1321 
1322   RNA_parameter_list_free(&list);
1323 
1324   return result;
1325 }
1326 
rna_operator_invoke_cb(bContext * C,wmOperator * op,const wmEvent * event)1327 static int rna_operator_invoke_cb(bContext *C, wmOperator *op, const wmEvent *event)
1328 {
1329   extern FunctionRNA rna_Operator_invoke_func;
1330 
1331   PointerRNA opr;
1332   ParameterList list;
1333   FunctionRNA *func;
1334   void *ret;
1335   int result;
1336 
1337   RNA_pointer_create(NULL, op->type->rna_ext.srna, op, &opr);
1338   func = &rna_Operator_invoke_func; /* RNA_struct_find_function(&opr, "invoke"); */
1339 
1340   RNA_parameter_list_create(&list, &opr, func);
1341   RNA_parameter_set_lookup(&list, "context", &C);
1342   RNA_parameter_set_lookup(&list, "event", &event);
1343   op->type->rna_ext.call(C, &opr, func, &list);
1344 
1345   RNA_parameter_get_lookup(&list, "result", &ret);
1346   result = *(int *)ret;
1347 
1348   RNA_parameter_list_free(&list);
1349 
1350   return result;
1351 }
1352 
1353 /* same as invoke */
rna_operator_modal_cb(bContext * C,wmOperator * op,const wmEvent * event)1354 static int rna_operator_modal_cb(bContext *C, wmOperator *op, const wmEvent *event)
1355 {
1356   extern FunctionRNA rna_Operator_modal_func;
1357 
1358   PointerRNA opr;
1359   ParameterList list;
1360   FunctionRNA *func;
1361   void *ret;
1362   int result;
1363 
1364   RNA_pointer_create(NULL, op->type->rna_ext.srna, op, &opr);
1365   func = &rna_Operator_modal_func; /* RNA_struct_find_function(&opr, "modal"); */
1366 
1367   RNA_parameter_list_create(&list, &opr, func);
1368   RNA_parameter_set_lookup(&list, "context", &C);
1369   RNA_parameter_set_lookup(&list, "event", &event);
1370   op->type->rna_ext.call(C, &opr, func, &list);
1371 
1372   RNA_parameter_get_lookup(&list, "result", &ret);
1373   result = *(int *)ret;
1374 
1375   RNA_parameter_list_free(&list);
1376 
1377   return result;
1378 }
1379 
rna_operator_draw_cb(bContext * C,wmOperator * op)1380 static void rna_operator_draw_cb(bContext *C, wmOperator *op)
1381 {
1382   extern FunctionRNA rna_Operator_draw_func;
1383 
1384   PointerRNA opr;
1385   ParameterList list;
1386   FunctionRNA *func;
1387 
1388   RNA_pointer_create(NULL, op->type->rna_ext.srna, op, &opr);
1389   func = &rna_Operator_draw_func; /* RNA_struct_find_function(&opr, "draw"); */
1390 
1391   RNA_parameter_list_create(&list, &opr, func);
1392   RNA_parameter_set_lookup(&list, "context", &C);
1393   op->type->rna_ext.call(C, &opr, func, &list);
1394 
1395   RNA_parameter_list_free(&list);
1396 }
1397 
1398 /* same as exec(), but call cancel */
rna_operator_cancel_cb(bContext * C,wmOperator * op)1399 static void rna_operator_cancel_cb(bContext *C, wmOperator *op)
1400 {
1401   extern FunctionRNA rna_Operator_cancel_func;
1402 
1403   PointerRNA opr;
1404   ParameterList list;
1405   FunctionRNA *func;
1406 
1407   RNA_pointer_create(NULL, op->type->rna_ext.srna, op, &opr);
1408   func = &rna_Operator_cancel_func; /* RNA_struct_find_function(&opr, "cancel"); */
1409 
1410   RNA_parameter_list_create(&list, &opr, func);
1411   RNA_parameter_set_lookup(&list, "context", &C);
1412   op->type->rna_ext.call(C, &opr, func, &list);
1413 
1414   RNA_parameter_list_free(&list);
1415 }
1416 
rna_operator_description_cb(bContext * C,wmOperatorType * ot,PointerRNA * prop_ptr)1417 static char *rna_operator_description_cb(bContext *C, wmOperatorType *ot, PointerRNA *prop_ptr)
1418 {
1419   extern FunctionRNA rna_Operator_description_func;
1420 
1421   PointerRNA ptr;
1422   ParameterList list;
1423   FunctionRNA *func;
1424   void *ret;
1425   char *result;
1426 
1427   RNA_pointer_create(NULL, ot->rna_ext.srna, NULL, &ptr); /* dummy */
1428   func = &rna_Operator_description_func; /* RNA_struct_find_function(&ptr, "description"); */
1429 
1430   RNA_parameter_list_create(&list, &ptr, func);
1431   RNA_parameter_set_lookup(&list, "context", &C);
1432   RNA_parameter_set_lookup(&list, "properties", prop_ptr);
1433   ot->rna_ext.call(C, &ptr, func, &list);
1434 
1435   RNA_parameter_get_lookup(&list, "result", &ret);
1436   result = (char *)ret;
1437 
1438   if (result && result[0]) {
1439     result = BLI_strdup(result);
1440   }
1441   else {
1442     result = NULL;
1443   }
1444 
1445   RNA_parameter_list_free(&list);
1446 
1447   return result;
1448 }
1449 
1450 static void rna_Operator_unregister(struct Main *bmain, StructRNA *type);
1451 
1452 /* bpy_operator_wrap.c */
1453 extern void BPY_RNA_operator_wrapper(wmOperatorType *ot, void *userdata);
1454 extern void BPY_RNA_operator_macro_wrapper(wmOperatorType *ot, void *userdata);
1455 
rna_Operator_register(Main * bmain,ReportList * reports,void * data,const char * identifier,StructValidateFunc validate,StructCallbackFunc call,StructFreeFunc free)1456 static StructRNA *rna_Operator_register(Main *bmain,
1457                                         ReportList *reports,
1458                                         void *data,
1459                                         const char *identifier,
1460                                         StructValidateFunc validate,
1461                                         StructCallbackFunc call,
1462                                         StructFreeFunc free)
1463 {
1464   wmOperatorType dummyot = {NULL};
1465   wmOperator dummyop = {NULL};
1466   PointerRNA dummyotr;
1467   int have_function[8];
1468 
1469   struct {
1470     char idname[OP_MAX_TYPENAME];
1471     char name[OP_MAX_TYPENAME];
1472     char description[RNA_DYN_DESCR_MAX];
1473     char translation_context[RNA_DYN_DESCR_MAX];
1474     char undo_group[OP_MAX_TYPENAME];
1475   } temp_buffers;
1476 
1477   /* setup dummy operator & operator type to store static properties in */
1478   dummyop.type = &dummyot;
1479   dummyot.idname = temp_buffers.idname;           /* only assign the pointer, string is NULL'd */
1480   dummyot.name = temp_buffers.name;               /* only assign the pointer, string is NULL'd */
1481   dummyot.description = temp_buffers.description; /* only assign the pointer, string is NULL'd */
1482   dummyot.translation_context =
1483       temp_buffers.translation_context;         /* only assign the pointer, string is NULL'd */
1484   dummyot.undo_group = temp_buffers.undo_group; /* only assign the pointer, string is NULL'd */
1485   RNA_pointer_create(NULL, &RNA_Operator, &dummyop, &dummyotr);
1486 
1487   /* clear in case they are left unset */
1488   temp_buffers.idname[0] = temp_buffers.name[0] = temp_buffers.description[0] =
1489       temp_buffers.undo_group[0] = temp_buffers.translation_context[0] = '\0';
1490 
1491   /* validate the python class */
1492   if (validate(&dummyotr, data, have_function) != 0) {
1493     return NULL;
1494   }
1495 
1496   /* check if we have registered this operator type before, and remove it */
1497   {
1498     wmOperatorType *ot = WM_operatortype_find(dummyot.idname, true);
1499     if (ot && ot->rna_ext.srna) {
1500       rna_Operator_unregister(bmain, ot->rna_ext.srna);
1501     }
1502   }
1503 
1504   if (!WM_operator_py_idname_ok_or_report(reports, identifier, dummyot.idname)) {
1505     return NULL;
1506   }
1507 
1508   char idname_conv[sizeof(dummyop.idname)];
1509   WM_operator_bl_idname(idname_conv, dummyot.idname); /* convert the idname from python */
1510 
1511   if (!RNA_struct_available_or_report(reports, idname_conv)) {
1512     return NULL;
1513   }
1514 
1515   /* We have to set default context if the class doesn't define it. */
1516   if (temp_buffers.translation_context[0] == '\0') {
1517     STRNCPY(temp_buffers.translation_context, BLT_I18NCONTEXT_OPERATOR_DEFAULT);
1518   }
1519 
1520   /* Convert foo.bar to FOO_OT_bar
1521    * allocate all strings at once. */
1522   {
1523     const char *strings[] = {
1524         idname_conv,
1525         temp_buffers.name,
1526         temp_buffers.description,
1527         temp_buffers.translation_context,
1528         temp_buffers.undo_group,
1529     };
1530     char *strings_table[ARRAY_SIZE(strings)];
1531     BLI_string_join_array_by_sep_char_with_tableN(
1532         '\0', strings_table, strings, ARRAY_SIZE(strings));
1533 
1534     dummyot.idname = strings_table[0]; /* allocated string stored here */
1535     dummyot.name = strings_table[1];
1536     dummyot.description = *strings_table[2] ? strings_table[2] : NULL;
1537     dummyot.translation_context = strings_table[3];
1538     dummyot.undo_group = strings_table[4];
1539     BLI_assert(ARRAY_SIZE(strings) == 5);
1540   }
1541 
1542   /* XXX, this doubles up with the operator name T29666.
1543    * for now just remove from dir(bpy.types) */
1544 
1545   /* create a new operator type */
1546   dummyot.rna_ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, dummyot.idname, &RNA_Operator);
1547 
1548   /* Operator properties are registered separately. */
1549   RNA_def_struct_flag(dummyot.rna_ext.srna, STRUCT_NO_IDPROPERTIES);
1550 
1551   RNA_def_struct_property_tags(dummyot.rna_ext.srna, rna_enum_operator_property_tags);
1552   RNA_def_struct_translation_context(dummyot.rna_ext.srna, dummyot.translation_context);
1553   dummyot.rna_ext.data = data;
1554   dummyot.rna_ext.call = call;
1555   dummyot.rna_ext.free = free;
1556 
1557   dummyot.pyop_poll = (have_function[0]) ? rna_operator_poll_cb : NULL;
1558   dummyot.exec = (have_function[1]) ? rna_operator_execute_cb : NULL;
1559   dummyot.check = (have_function[2]) ? rna_operator_check_cb : NULL;
1560   dummyot.invoke = (have_function[3]) ? rna_operator_invoke_cb : NULL;
1561   dummyot.modal = (have_function[4]) ? rna_operator_modal_cb : NULL;
1562   dummyot.ui = (have_function[5]) ? rna_operator_draw_cb : NULL;
1563   dummyot.cancel = (have_function[6]) ? rna_operator_cancel_cb : NULL;
1564   dummyot.get_description = (have_function[7]) ? rna_operator_description_cb : NULL;
1565   WM_operatortype_append_ptr(BPY_RNA_operator_wrapper, (void *)&dummyot);
1566 
1567   /* update while blender is running */
1568   WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL);
1569 
1570   return dummyot.rna_ext.srna;
1571 }
1572 
rna_Operator_unregister(struct Main * bmain,StructRNA * type)1573 static void rna_Operator_unregister(struct Main *bmain, StructRNA *type)
1574 {
1575   const char *idname;
1576   wmOperatorType *ot = RNA_struct_blender_type_get(type);
1577   wmWindowManager *wm;
1578 
1579   if (!ot) {
1580     return;
1581   }
1582 
1583   /* update while blender is running */
1584   wm = bmain->wm.first;
1585   if (wm) {
1586     WM_operator_stack_clear(wm);
1587 
1588     WM_operator_handlers_clear(wm, ot);
1589   }
1590   WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL);
1591 
1592   RNA_struct_free_extension(type, &ot->rna_ext);
1593 
1594   idname = ot->idname;
1595   WM_operatortype_remove_ptr(ot);
1596 
1597   /* Not to be confused with the RNA_struct_free that WM_operatortype_remove calls,
1598    * they are 2 different srna's. */
1599   RNA_struct_free(&BLENDER_RNA, type);
1600 
1601   MEM_freeN((void *)idname);
1602 }
1603 
rna_Operator_instance(PointerRNA * ptr)1604 static void **rna_Operator_instance(PointerRNA *ptr)
1605 {
1606   wmOperator *op = ptr->data;
1607   return &op->py_instance;
1608 }
1609 
rna_MacroOperator_register(Main * bmain,ReportList * reports,void * data,const char * identifier,StructValidateFunc validate,StructCallbackFunc call,StructFreeFunc free)1610 static StructRNA *rna_MacroOperator_register(Main *bmain,
1611                                              ReportList *reports,
1612                                              void *data,
1613                                              const char *identifier,
1614                                              StructValidateFunc validate,
1615                                              StructCallbackFunc call,
1616                                              StructFreeFunc free)
1617 {
1618   wmOperatorType dummyot = {NULL};
1619   wmOperator dummyop = {NULL};
1620   PointerRNA dummyotr;
1621   int have_function[4];
1622 
1623   struct {
1624     char idname[OP_MAX_TYPENAME];
1625     char name[OP_MAX_TYPENAME];
1626     char description[RNA_DYN_DESCR_MAX];
1627     char translation_context[RNA_DYN_DESCR_MAX];
1628     char undo_group[OP_MAX_TYPENAME];
1629   } temp_buffers;
1630 
1631   /* setup dummy operator & operator type to store static properties in */
1632   dummyop.type = &dummyot;
1633   dummyot.idname = temp_buffers.idname;           /* only assign the pointer, string is NULL'd */
1634   dummyot.name = temp_buffers.name;               /* only assign the pointer, string is NULL'd */
1635   dummyot.description = temp_buffers.description; /* only assign the pointer, string is NULL'd */
1636   dummyot.translation_context =
1637       temp_buffers.translation_context;         /* only assign the pointer, string is NULL'd */
1638   dummyot.undo_group = temp_buffers.undo_group; /* only assign the pointer, string is NULL'd */
1639   RNA_pointer_create(NULL, &RNA_Macro, &dummyop, &dummyotr);
1640 
1641   /* clear in case they are left unset */
1642   temp_buffers.idname[0] = temp_buffers.name[0] = temp_buffers.description[0] =
1643       temp_buffers.undo_group[0] = temp_buffers.translation_context[0] = '\0';
1644 
1645   /* validate the python class */
1646   if (validate(&dummyotr, data, have_function) != 0) {
1647     return NULL;
1648   }
1649 
1650   if (strlen(identifier) >= sizeof(dummyop.idname)) {
1651     BKE_reportf(reports,
1652                 RPT_ERROR,
1653                 "Registering operator class: '%s' is too long, maximum length is %d",
1654                 identifier,
1655                 (int)sizeof(dummyop.idname));
1656     return NULL;
1657   }
1658 
1659   /* check if we have registered this operator type before, and remove it */
1660   {
1661     wmOperatorType *ot = WM_operatortype_find(dummyot.idname, true);
1662     if (ot && ot->rna_ext.srna) {
1663       rna_Operator_unregister(bmain, ot->rna_ext.srna);
1664     }
1665   }
1666 
1667   if (!WM_operator_py_idname_ok_or_report(reports, identifier, dummyot.idname)) {
1668     return NULL;
1669   }
1670 
1671   char idname_conv[sizeof(dummyop.idname)];
1672   WM_operator_bl_idname(idname_conv, dummyot.idname); /* convert the idname from python */
1673 
1674   if (!RNA_struct_available_or_report(reports, idname_conv)) {
1675     return NULL;
1676   }
1677 
1678   /* We have to set default context if the class doesn't define it. */
1679   if (temp_buffers.translation_context[0] == '\0') {
1680     STRNCPY(temp_buffers.translation_context, BLT_I18NCONTEXT_OPERATOR_DEFAULT);
1681   }
1682 
1683   /* Convert foo.bar to FOO_OT_bar
1684    * allocate all strings at once. */
1685   {
1686     const char *strings[] = {
1687         idname_conv,
1688         temp_buffers.name,
1689         temp_buffers.description,
1690         temp_buffers.translation_context,
1691         temp_buffers.undo_group,
1692     };
1693     char *strings_table[ARRAY_SIZE(strings)];
1694     BLI_string_join_array_by_sep_char_with_tableN(
1695         '\0', strings_table, strings, ARRAY_SIZE(strings));
1696 
1697     dummyot.idname = strings_table[0]; /* allocated string stored here */
1698     dummyot.name = strings_table[1];
1699     dummyot.description = *strings_table[2] ? strings_table[2] : NULL;
1700     dummyot.translation_context = strings_table[3];
1701     dummyot.undo_group = strings_table[4];
1702     BLI_assert(ARRAY_SIZE(strings) == 5);
1703   }
1704 
1705   /* XXX, this doubles up with the operator name T29666.
1706    * for now just remove from dir(bpy.types) */
1707 
1708   /* create a new operator type */
1709   dummyot.rna_ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, dummyot.idname, &RNA_Operator);
1710   RNA_def_struct_translation_context(dummyot.rna_ext.srna, dummyot.translation_context);
1711   dummyot.rna_ext.data = data;
1712   dummyot.rna_ext.call = call;
1713   dummyot.rna_ext.free = free;
1714 
1715   dummyot.pyop_poll = (have_function[0]) ? rna_operator_poll_cb : NULL;
1716   dummyot.ui = (have_function[3]) ? rna_operator_draw_cb : NULL;
1717 
1718   WM_operatortype_append_macro_ptr(BPY_RNA_operator_macro_wrapper, (void *)&dummyot);
1719 
1720   /* update while blender is running */
1721   WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL);
1722 
1723   return dummyot.rna_ext.srna;
1724 }
1725 #  endif /* WITH_PYTHON */
1726 
rna_Operator_refine(PointerRNA * opr)1727 static StructRNA *rna_Operator_refine(PointerRNA *opr)
1728 {
1729   wmOperator *op = (wmOperator *)opr->data;
1730   return (op->type && op->type->rna_ext.srna) ? op->type->rna_ext.srna : &RNA_Operator;
1731 }
1732 
rna_MacroOperator_refine(PointerRNA * opr)1733 static StructRNA *rna_MacroOperator_refine(PointerRNA *opr)
1734 {
1735   wmOperator *op = (wmOperator *)opr->data;
1736   return (op->type && op->type->rna_ext.srna) ? op->type->rna_ext.srna : &RNA_Macro;
1737 }
1738 
1739 /* just to work around 'const char *' warning and to ensure this is a python op */
rna_Operator_bl_idname_set(PointerRNA * ptr,const char * value)1740 static void rna_Operator_bl_idname_set(PointerRNA *ptr, const char *value)
1741 {
1742   wmOperator *data = (wmOperator *)(ptr->data);
1743   char *str = (char *)data->type->idname;
1744   if (!str[0]) {
1745     BLI_strncpy(str, value, OP_MAX_TYPENAME); /* utf8 already ensured */
1746   }
1747   else {
1748     BLI_assert(!"setting the bl_idname on a non-builtin operator");
1749   }
1750 }
1751 
rna_Operator_bl_label_set(PointerRNA * ptr,const char * value)1752 static void rna_Operator_bl_label_set(PointerRNA *ptr, const char *value)
1753 {
1754   wmOperator *data = (wmOperator *)(ptr->data);
1755   char *str = (char *)data->type->name;
1756   if (!str[0]) {
1757     BLI_strncpy(str, value, OP_MAX_TYPENAME); /* utf8 already ensured */
1758   }
1759   else {
1760     BLI_assert(!"setting the bl_label on a non-builtin operator");
1761   }
1762 }
1763 
rna_Operator_bl_translation_context_set(PointerRNA * ptr,const char * value)1764 static void rna_Operator_bl_translation_context_set(PointerRNA *ptr, const char *value)
1765 {
1766   wmOperator *data = (wmOperator *)(ptr->data);
1767   char *str = (char *)data->type->translation_context;
1768   if (!str[0]) {
1769     BLI_strncpy(str, value, RNA_DYN_DESCR_MAX); /* utf8 already ensured */
1770   }
1771   else {
1772     BLI_assert(!"setting the bl_translation_context on a non-builtin operator");
1773   }
1774 }
1775 
rna_Operator_bl_description_set(PointerRNA * ptr,const char * value)1776 static void rna_Operator_bl_description_set(PointerRNA *ptr, const char *value)
1777 {
1778   wmOperator *data = (wmOperator *)(ptr->data);
1779   char *str = (char *)data->type->description;
1780   if (!str[0]) {
1781     BLI_strncpy(str, value, RNA_DYN_DESCR_MAX); /* utf8 already ensured */
1782   }
1783   else {
1784     BLI_assert(!"setting the bl_description on a non-builtin operator");
1785   }
1786 }
1787 
rna_Operator_bl_undo_group_set(PointerRNA * ptr,const char * value)1788 static void rna_Operator_bl_undo_group_set(PointerRNA *ptr, const char *value)
1789 {
1790   wmOperator *data = (wmOperator *)(ptr->data);
1791   char *str = (char *)data->type->undo_group;
1792   if (!str[0]) {
1793     BLI_strncpy(str, value, OP_MAX_TYPENAME); /* utf8 already ensured */
1794   }
1795   else {
1796     BLI_assert(!"setting the bl_undo_group on a non-builtin operator");
1797   }
1798 }
1799 
rna_KeyMapItem_update(Main * UNUSED (bmain),Scene * UNUSED (scene),PointerRNA * ptr)1800 static void rna_KeyMapItem_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
1801 {
1802   wmKeyMapItem *kmi = ptr->data;
1803   WM_keyconfig_update_tag(NULL, kmi);
1804 }
1805 
1806 #else /* RNA_RUNTIME */
1807 
1808 /**
1809  * expose ``Operator.options`` as its own type so we can control each flags use
1810  * (some are read-only).
1811  */
rna_def_operator_options_runtime(BlenderRNA * brna)1812 static void rna_def_operator_options_runtime(BlenderRNA *brna)
1813 {
1814   StructRNA *srna;
1815   PropertyRNA *prop;
1816 
1817   srna = RNA_def_struct(brna, "OperatorOptions", NULL);
1818   RNA_def_struct_ui_text(srna, "Operator Options", "Runtime options");
1819   RNA_def_struct_sdna(srna, "wmOperator");
1820 
1821   prop = RNA_def_property(srna, "is_grab_cursor", PROP_BOOLEAN, PROP_BOOLEAN);
1822   RNA_def_property_boolean_sdna(prop, NULL, "flag", OP_IS_MODAL_GRAB_CURSOR);
1823   RNA_def_property_ui_text(prop, "Grab Cursor", "True when the cursor is grabbed");
1824   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1825 
1826   prop = RNA_def_property(srna, "is_invoke", PROP_BOOLEAN, PROP_BOOLEAN);
1827   RNA_def_property_boolean_sdna(prop, NULL, "flag", OP_IS_INVOKE);
1828   RNA_def_property_ui_text(
1829       prop, "Invoke", "True when invoked (even if only the execute callbacks available)");
1830   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1831 
1832   prop = RNA_def_property(srna, "is_repeat", PROP_BOOLEAN, PROP_BOOLEAN);
1833   RNA_def_property_boolean_sdna(prop, NULL, "flag", OP_IS_REPEAT);
1834   RNA_def_property_ui_text(prop, "Repeat", "True when run from the 'Adjust Last Operation' panel");
1835   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1836 
1837   prop = RNA_def_property(srna, "is_repeat_last", PROP_BOOLEAN, PROP_BOOLEAN);
1838   RNA_def_property_boolean_sdna(prop, NULL, "flag", OP_IS_REPEAT_LAST);
1839   RNA_def_property_ui_text(prop, "Repeat Call", "True when run from the operator 'Repeat Last'");
1840   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1841 
1842   prop = RNA_def_property(srna, "use_cursor_region", PROP_BOOLEAN, PROP_BOOLEAN);
1843   RNA_def_property_boolean_sdna(prop, NULL, "flag", OP_IS_MODAL_CURSOR_REGION);
1844   RNA_def_property_ui_text(
1845       prop, "Focus Region", "Enable to use the region under the cursor for modal execution");
1846 }
1847 
rna_def_operator(BlenderRNA * brna)1848 static void rna_def_operator(BlenderRNA *brna)
1849 {
1850   StructRNA *srna;
1851   PropertyRNA *prop;
1852 
1853   srna = RNA_def_struct(brna, "Operator", NULL);
1854   RNA_def_struct_ui_text(
1855       srna, "Operator", "Storage of an operator being executed, or registered after execution");
1856   RNA_def_struct_sdna(srna, "wmOperator");
1857   RNA_def_struct_refine_func(srna, "rna_Operator_refine");
1858 #  ifdef WITH_PYTHON
1859   RNA_def_struct_register_funcs(
1860       srna, "rna_Operator_register", "rna_Operator_unregister", "rna_Operator_instance");
1861 #  endif
1862   RNA_def_struct_translation_context(srna, BLT_I18NCONTEXT_OPERATOR_DEFAULT);
1863   RNA_def_struct_flag(srna, STRUCT_PUBLIC_NAMESPACE_INHERIT);
1864 
1865   prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
1866   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1867   RNA_def_property_string_funcs(prop, "rna_Operator_name_get", "rna_Operator_name_length", NULL);
1868   RNA_def_property_ui_text(prop, "Name", "");
1869 
1870   prop = RNA_def_property(srna, "properties", PROP_POINTER, PROP_NONE);
1871   RNA_def_property_flag(prop, PROP_NEVER_NULL);
1872   RNA_def_property_struct_type(prop, "OperatorProperties");
1873   RNA_def_property_ui_text(prop, "Properties", "");
1874   RNA_def_property_pointer_funcs(prop, "rna_Operator_properties_get", NULL, NULL, NULL);
1875 
1876   prop = RNA_def_property(srna, "has_reports", PROP_BOOLEAN, PROP_NONE);
1877   RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* this is 'virtual' property */
1878   RNA_def_property_boolean_funcs(prop, "rna_Operator_has_reports_get", NULL);
1879   RNA_def_property_ui_text(
1880       prop,
1881       "Has Reports",
1882       "Operator has a set of reports (warnings and errors) from last execution");
1883 
1884   prop = RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE);
1885   RNA_def_property_struct_type(prop, "UILayout");
1886 
1887   prop = RNA_def_property(srna, "options", PROP_POINTER, PROP_NONE);
1888   RNA_def_property_flag(prop, PROP_NEVER_NULL);
1889   RNA_def_property_struct_type(prop, "OperatorOptions");
1890   RNA_def_property_pointer_funcs(prop, "rna_Operator_options_get", NULL, NULL, NULL);
1891   RNA_def_property_ui_text(prop, "Options", "Runtime options");
1892 
1893   /* Registration */
1894   prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
1895   RNA_def_property_string_sdna(prop, NULL, "type->idname");
1896   /* else it uses the pointer size!. -3 because '.' -> '_OT_' */
1897   RNA_def_property_string_maxlength(prop, OP_MAX_TYPENAME - 3);
1898   RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_idname_set");
1899   /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
1900   RNA_def_property_flag(prop, PROP_REGISTER);
1901   RNA_def_struct_name_property(srna, prop);
1902 
1903   prop = RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
1904   RNA_def_property_string_sdna(prop, NULL, "type->name");
1905   RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */
1906   RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_label_set");
1907   /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
1908   RNA_def_property_flag(prop, PROP_REGISTER);
1909 
1910   prop = RNA_def_property(srna, "bl_translation_context", PROP_STRING, PROP_NONE);
1911   RNA_def_property_string_sdna(prop, NULL, "type->translation_context");
1912   RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */
1913   RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_translation_context_set");
1914   RNA_def_property_string_default(prop, BLT_I18NCONTEXT_OPERATOR_DEFAULT);
1915   RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
1916   RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for NULL */
1917 
1918   prop = RNA_def_property(srna, "bl_description", PROP_STRING, PROP_NONE);
1919   RNA_def_property_string_sdna(prop, NULL, "type->description");
1920   RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */
1921   RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_description_set");
1922   /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
1923   RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
1924   RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for NULL */
1925 
1926   prop = RNA_def_property(srna, "bl_undo_group", PROP_STRING, PROP_NONE);
1927   RNA_def_property_string_sdna(prop, NULL, "type->undo_group");
1928   RNA_def_property_string_maxlength(prop, OP_MAX_TYPENAME); /* else it uses the pointer size! */
1929   RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_undo_group_set");
1930   /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
1931   RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
1932   RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for NULL */
1933 
1934   prop = RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE);
1935   RNA_def_property_enum_sdna(prop, NULL, "type->flag");
1936   RNA_def_property_enum_items(prop, rna_enum_operator_type_flag_items);
1937   RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL | PROP_ENUM_FLAG);
1938   RNA_def_property_ui_text(prop, "Options", "Options for this operator type");
1939 
1940   prop = RNA_def_property(srna, "macros", PROP_COLLECTION, PROP_NONE);
1941   RNA_def_property_collection_sdna(prop, NULL, "macro", NULL);
1942   RNA_def_property_struct_type(prop, "Macro");
1943   RNA_def_property_ui_text(prop, "Macros", "");
1944 
1945   RNA_api_operator(srna);
1946 
1947   srna = RNA_def_struct(brna, "OperatorProperties", NULL);
1948   RNA_def_struct_ui_text(srna, "Operator Properties", "Input properties of an Operator");
1949   RNA_def_struct_refine_func(srna, "rna_OperatorProperties_refine");
1950   RNA_def_struct_idprops_func(srna, "rna_OperatorProperties_idprops");
1951   RNA_def_struct_property_tags(srna, rna_enum_operator_property_tags);
1952   RNA_def_struct_flag(srna, STRUCT_NO_DATABLOCK_IDPROPERTIES);
1953   RNA_def_struct_clear_flag(srna, STRUCT_UNDO);
1954 }
1955 
rna_def_macro_operator(BlenderRNA * brna)1956 static void rna_def_macro_operator(BlenderRNA *brna)
1957 {
1958   StructRNA *srna;
1959   PropertyRNA *prop;
1960 
1961   srna = RNA_def_struct(brna, "Macro", NULL);
1962   RNA_def_struct_ui_text(
1963       srna,
1964       "Macro Operator",
1965       "Storage of a macro operator being executed, or registered after execution");
1966   RNA_def_struct_sdna(srna, "wmOperator");
1967   RNA_def_struct_refine_func(srna, "rna_MacroOperator_refine");
1968 #  ifdef WITH_PYTHON
1969   RNA_def_struct_register_funcs(
1970       srna, "rna_MacroOperator_register", "rna_Operator_unregister", "rna_Operator_instance");
1971 #  endif
1972   RNA_def_struct_translation_context(srna, BLT_I18NCONTEXT_OPERATOR_DEFAULT);
1973   RNA_def_struct_flag(srna, STRUCT_PUBLIC_NAMESPACE_INHERIT);
1974 
1975   prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
1976   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1977   RNA_def_property_string_funcs(prop, "rna_Operator_name_get", "rna_Operator_name_length", NULL);
1978   RNA_def_property_ui_text(prop, "Name", "");
1979 
1980   prop = RNA_def_property(srna, "properties", PROP_POINTER, PROP_NONE);
1981   RNA_def_property_flag(prop, PROP_NEVER_NULL);
1982   RNA_def_property_struct_type(prop, "OperatorProperties");
1983   RNA_def_property_ui_text(prop, "Properties", "");
1984   RNA_def_property_pointer_funcs(prop, "rna_Operator_properties_get", NULL, NULL, NULL);
1985 
1986   /* Registration */
1987   prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
1988   RNA_def_property_string_sdna(prop, NULL, "type->idname");
1989   RNA_def_property_string_maxlength(prop, OP_MAX_TYPENAME); /* else it uses the pointer size! */
1990   RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_idname_set");
1991   /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
1992   RNA_def_property_flag(prop, PROP_REGISTER);
1993   RNA_def_struct_name_property(srna, prop);
1994 
1995   prop = RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
1996   RNA_def_property_string_sdna(prop, NULL, "type->name");
1997   RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */
1998   RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_label_set");
1999   /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
2000   RNA_def_property_flag(prop, PROP_REGISTER);
2001 
2002   prop = RNA_def_property(srna, "bl_translation_context", PROP_STRING, PROP_NONE);
2003   RNA_def_property_string_sdna(prop, NULL, "type->translation_context");
2004   RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */
2005   RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_translation_context_set");
2006   RNA_def_property_string_default(prop, BLT_I18NCONTEXT_OPERATOR_DEFAULT);
2007   RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
2008   RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for NULL */
2009 
2010   prop = RNA_def_property(srna, "bl_description", PROP_STRING, PROP_NONE);
2011   RNA_def_property_string_sdna(prop, NULL, "type->description");
2012   RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */
2013   RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_description_set");
2014   /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
2015   RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
2016   RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for NULL */
2017 
2018   prop = RNA_def_property(srna, "bl_undo_group", PROP_STRING, PROP_NONE);
2019   RNA_def_property_string_sdna(prop, NULL, "type->undo_group");
2020   RNA_def_property_string_maxlength(prop, OP_MAX_TYPENAME); /* else it uses the pointer size! */
2021   RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_undo_group_set");
2022   /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
2023   RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
2024   RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for NULL */
2025 
2026   prop = RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE);
2027   RNA_def_property_enum_sdna(prop, NULL, "type->flag");
2028   RNA_def_property_enum_items(prop, rna_enum_operator_type_flag_items);
2029   RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL | PROP_ENUM_FLAG);
2030   RNA_def_property_ui_text(prop, "Options", "Options for this operator type");
2031 
2032   RNA_api_macro(srna);
2033 }
2034 
rna_def_operator_type_macro(BlenderRNA * brna)2035 static void rna_def_operator_type_macro(BlenderRNA *brna)
2036 {
2037   StructRNA *srna;
2038   PropertyRNA *prop;
2039 
2040   srna = RNA_def_struct(brna, "OperatorMacro", NULL);
2041   RNA_def_struct_ui_text(
2042       srna, "Operator Macro", "Storage of a sub operator in a macro after it has been added");
2043   RNA_def_struct_sdna(srna, "wmOperatorTypeMacro");
2044 
2045   /*  prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE); */
2046   /*  RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
2047   /*  RNA_def_property_string_sdna(prop, NULL, "idname"); */
2048   /*  RNA_def_property_ui_text(prop, "Name", "Name of the sub operator"); */
2049   /*  RNA_def_struct_name_property(srna, prop); */
2050 
2051   prop = RNA_def_property(srna, "properties", PROP_POINTER, PROP_NONE);
2052   RNA_def_property_flag(prop, PROP_NEVER_NULL);
2053   RNA_def_property_struct_type(prop, "OperatorProperties");
2054   RNA_def_property_ui_text(prop, "Properties", "");
2055   RNA_def_property_pointer_funcs(prop, "rna_OperatorMacro_properties_get", NULL, NULL, NULL);
2056 }
2057 
rna_def_operator_utils(BlenderRNA * brna)2058 static void rna_def_operator_utils(BlenderRNA *brna)
2059 {
2060   StructRNA *srna;
2061   PropertyRNA *prop;
2062 
2063   srna = RNA_def_struct(brna, "OperatorMousePath", "PropertyGroup");
2064   RNA_def_struct_ui_text(
2065       srna, "Operator Mouse Path", "Mouse path values for operators that record such paths");
2066 
2067   prop = RNA_def_property(srna, "loc", PROP_FLOAT, PROP_XYZ);
2068   RNA_def_property_flag(prop, PROP_IDPROPERTY);
2069   RNA_def_property_array(prop, 2);
2070   RNA_def_property_ui_text(prop, "Location", "Mouse location");
2071 
2072   prop = RNA_def_property(srna, "time", PROP_FLOAT, PROP_NONE);
2073   RNA_def_property_flag(prop, PROP_IDPROPERTY);
2074   RNA_def_property_ui_text(prop, "Time", "Time of mouse location");
2075 }
2076 
rna_def_operator_filelist_element(BlenderRNA * brna)2077 static void rna_def_operator_filelist_element(BlenderRNA *brna)
2078 {
2079   StructRNA *srna;
2080   PropertyRNA *prop;
2081 
2082   srna = RNA_def_struct(brna, "OperatorFileListElement", "PropertyGroup");
2083   RNA_def_struct_ui_text(srna, "Operator File List Element", "");
2084 
2085   prop = RNA_def_property(srna, "name", PROP_STRING, PROP_FILENAME);
2086   RNA_def_property_flag(prop, PROP_IDPROPERTY);
2087   RNA_def_property_ui_text(prop, "Name", "Name of a file or directory within a file list");
2088 }
2089 
rna_def_event(BlenderRNA * brna)2090 static void rna_def_event(BlenderRNA *brna)
2091 {
2092   StructRNA *srna;
2093   PropertyRNA *prop;
2094 
2095   srna = RNA_def_struct(brna, "Event", NULL);
2096   RNA_def_struct_ui_text(srna, "Event", "Window Manager Event");
2097   RNA_def_struct_sdna(srna, "wmEvent");
2098 
2099   RNA_define_verify_sdna(0); /* not in sdna */
2100 
2101   /* strings */
2102   prop = RNA_def_property(srna, "ascii", PROP_STRING, PROP_NONE);
2103   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2104   RNA_def_property_string_funcs(prop, "rna_Event_ascii_get", "rna_Event_ascii_length", NULL);
2105   RNA_def_property_ui_text(prop, "ASCII", "Single ASCII character for this event");
2106 
2107   prop = RNA_def_property(srna, "unicode", PROP_STRING, PROP_NONE);
2108   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2109   RNA_def_property_string_funcs(prop, "rna_Event_unicode_get", "rna_Event_unicode_length", NULL);
2110   RNA_def_property_ui_text(prop, "Unicode", "Single unicode character for this event");
2111 
2112   /* enums */
2113   prop = RNA_def_property(srna, "value", PROP_ENUM, PROP_NONE);
2114   RNA_def_property_enum_sdna(prop, NULL, "val");
2115   RNA_def_property_enum_items(prop, rna_enum_event_value_items);
2116   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2117   RNA_def_property_ui_text(prop, "Value", "The type of event, only applies to some");
2118 
2119   prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
2120   RNA_def_property_enum_sdna(prop, NULL, "type");
2121   RNA_def_property_enum_items(prop, rna_enum_event_type_items);
2122   RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UI_EVENTS);
2123   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2124   RNA_def_property_ui_text(prop, "Type", "");
2125 
2126   /* keyboard */
2127   prop = RNA_def_property(srna, "is_repeat", PROP_BOOLEAN, PROP_NONE);
2128   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2129   RNA_def_property_boolean_funcs(prop, "rna_Event_is_repeat_get", NULL);
2130   RNA_def_property_ui_text(prop, "Is Repeat", "The event is generated by holding a key down");
2131 
2132   /* mouse */
2133   prop = RNA_def_property(srna, "mouse_x", PROP_INT, PROP_NONE);
2134   RNA_def_property_int_sdna(prop, NULL, "x");
2135   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2136   RNA_def_property_ui_text(
2137       prop, "Mouse X Position", "The window relative horizontal location of the mouse");
2138 
2139   prop = RNA_def_property(srna, "mouse_y", PROP_INT, PROP_NONE);
2140   RNA_def_property_int_sdna(prop, NULL, "y");
2141   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2142   RNA_def_property_ui_text(
2143       prop, "Mouse Y Position", "The window relative vertical location of the mouse");
2144 
2145   prop = RNA_def_property(srna, "mouse_region_x", PROP_INT, PROP_NONE);
2146   RNA_def_property_int_sdna(prop, NULL, "mval[0]");
2147   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2148   RNA_def_property_ui_text(
2149       prop, "Mouse X Position", "The region relative horizontal location of the mouse");
2150 
2151   prop = RNA_def_property(srna, "mouse_region_y", PROP_INT, PROP_NONE);
2152   RNA_def_property_int_sdna(prop, NULL, "mval[1]");
2153   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2154   RNA_def_property_ui_text(
2155       prop, "Mouse Y Position", "The region relative vertical location of the mouse");
2156 
2157   prop = RNA_def_property(srna, "mouse_prev_x", PROP_INT, PROP_NONE);
2158   RNA_def_property_int_sdna(prop, NULL, "prevx");
2159   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2160   RNA_def_property_ui_text(
2161       prop, "Mouse Previous X Position", "The window relative horizontal location of the mouse");
2162 
2163   prop = RNA_def_property(srna, "mouse_prev_y", PROP_INT, PROP_NONE);
2164   RNA_def_property_int_sdna(prop, NULL, "prevy");
2165   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2166   RNA_def_property_ui_text(
2167       prop, "Mouse Previous Y Position", "The window relative vertical location of the mouse");
2168 
2169   prop = RNA_def_property(srna, "pressure", PROP_FLOAT, PROP_NONE);
2170   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2171   RNA_def_property_float_funcs(prop, "rna_Event_pressure_get", NULL, NULL);
2172   RNA_def_property_ui_text(
2173       prop, "Tablet Pressure", "The pressure of the tablet or 1.0 if no tablet present");
2174 
2175   prop = RNA_def_property(srna, "tilt", PROP_FLOAT, PROP_XYZ_LENGTH);
2176   RNA_def_property_array(prop, 2);
2177   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2178   RNA_def_property_float_funcs(prop, "rna_Event_tilt_get", NULL, NULL);
2179   RNA_def_property_ui_text(
2180       prop, "Tablet Tilt", "The pressure of the tablet or zeroes if no tablet present");
2181 
2182   prop = RNA_def_property(srna, "is_tablet", PROP_BOOLEAN, PROP_NONE);
2183   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2184   RNA_def_property_boolean_funcs(prop, "rna_Event_is_tablet_get", NULL);
2185   RNA_def_property_ui_text(prop, "Is Tablet", "The event has tablet data");
2186 
2187   prop = RNA_def_property(srna, "is_mouse_absolute", PROP_BOOLEAN, PROP_NONE);
2188   RNA_def_property_boolean_sdna(prop, NULL, "tablet.is_motion_absolute", 1);
2189   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2190   RNA_def_property_ui_text(prop, "Absolute Motion", "The last motion event was an absolute input");
2191 
2192   /* modifiers */
2193   prop = RNA_def_property(srna, "shift", PROP_BOOLEAN, PROP_NONE);
2194   RNA_def_property_boolean_sdna(prop, NULL, "shift", 1);
2195   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2196   RNA_def_property_ui_text(prop, "Shift", "True when the Shift key is held");
2197   RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_WINDOWMANAGER);
2198 
2199   prop = RNA_def_property(srna, "ctrl", PROP_BOOLEAN, PROP_NONE);
2200   RNA_def_property_boolean_sdna(prop, NULL, "ctrl", 1);
2201   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2202   RNA_def_property_ui_text(prop, "Ctrl", "True when the Ctrl key is held");
2203 
2204   prop = RNA_def_property(srna, "alt", PROP_BOOLEAN, PROP_NONE);
2205   RNA_def_property_boolean_sdna(prop, NULL, "alt", 1);
2206   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2207   RNA_def_property_ui_text(prop, "Alt", "True when the Alt/Option key is held");
2208 
2209   prop = RNA_def_property(srna, "oskey", PROP_BOOLEAN, PROP_NONE);
2210   RNA_def_property_boolean_sdna(prop, NULL, "oskey", 1);
2211   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2212   RNA_def_property_ui_text(prop, "OS Key", "True when the Cmd key is held");
2213 
2214   RNA_define_verify_sdna(1); /* not in sdna */
2215 }
2216 
rna_def_timer(BlenderRNA * brna)2217 static void rna_def_timer(BlenderRNA *brna)
2218 {
2219   StructRNA *srna;
2220   PropertyRNA *prop;
2221 
2222   srna = RNA_def_struct(brna, "Timer", NULL);
2223   RNA_def_struct_ui_text(srna, "Timer", "Window event timer");
2224   RNA_def_struct_sdna(srna, "wmTimer");
2225 
2226   RNA_define_verify_sdna(0); /* not in sdna */
2227 
2228   /* could wrap more, for now this is enough */
2229   prop = RNA_def_property(srna, "time_step", PROP_FLOAT, PROP_NONE);
2230   RNA_def_property_float_sdna(prop, NULL, "timestep");
2231   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2232   RNA_def_property_ui_text(prop, "Time Step", "");
2233 
2234   prop = RNA_def_property(srna, "time_delta", PROP_FLOAT, PROP_NONE);
2235   RNA_def_property_float_sdna(prop, NULL, "delta");
2236   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2237   RNA_def_property_ui_text(prop, "Delta", "Time since last step in seconds");
2238 
2239   prop = RNA_def_property(srna, "time_duration", PROP_FLOAT, PROP_NONE);
2240   RNA_def_property_float_sdna(prop, NULL, "duration");
2241   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2242   RNA_def_property_ui_text(prop, "Delta", "Time since last step in seconds");
2243 
2244   RNA_define_verify_sdna(1); /* not in sdna */
2245 }
2246 
rna_def_popup_menu_wrapper(BlenderRNA * brna,const char * rna_type,const char * c_type,const char * layout_get_fn)2247 static void rna_def_popup_menu_wrapper(BlenderRNA *brna,
2248                                        const char *rna_type,
2249                                        const char *c_type,
2250                                        const char *layout_get_fn)
2251 {
2252   StructRNA *srna;
2253   PropertyRNA *prop;
2254 
2255   srna = RNA_def_struct(brna, rna_type, NULL);
2256   /* UI name isn't visible, name same as type. */
2257   RNA_def_struct_ui_text(srna, rna_type, "");
2258   RNA_def_struct_sdna(srna, c_type);
2259 
2260   RNA_define_verify_sdna(0); /* not in sdna */
2261 
2262   /* could wrap more, for now this is enough */
2263   prop = RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE);
2264   RNA_def_property_struct_type(prop, "UILayout");
2265   RNA_def_property_pointer_funcs(prop, layout_get_fn, NULL, NULL, NULL);
2266 
2267   RNA_define_verify_sdna(1); /* not in sdna */
2268 }
2269 
rna_def_popupmenu(BlenderRNA * brna)2270 static void rna_def_popupmenu(BlenderRNA *brna)
2271 {
2272   rna_def_popup_menu_wrapper(brna, "UIPopupMenu", "uiPopupMenu", "rna_PopupMenu_layout_get");
2273 }
2274 
rna_def_popovermenu(BlenderRNA * brna)2275 static void rna_def_popovermenu(BlenderRNA *brna)
2276 {
2277   rna_def_popup_menu_wrapper(brna, "UIPopover", "uiPopover", "rna_PopoverMenu_layout_get");
2278 }
2279 
rna_def_piemenu(BlenderRNA * brna)2280 static void rna_def_piemenu(BlenderRNA *brna)
2281 {
2282   rna_def_popup_menu_wrapper(brna, "UIPieMenu", "uiPieMenu", "rna_PieMenu_layout_get");
2283 }
2284 
rna_def_window_stereo3d(BlenderRNA * brna)2285 static void rna_def_window_stereo3d(BlenderRNA *brna)
2286 {
2287   StructRNA *srna;
2288   PropertyRNA *prop;
2289 
2290   srna = RNA_def_struct(brna, "Stereo3dDisplay", NULL);
2291   RNA_def_struct_sdna(srna, "Stereo3dFormat");
2292   RNA_def_struct_clear_flag(srna, STRUCT_UNDO);
2293   RNA_def_struct_ui_text(srna, "Stereo 3D Display", "Settings for stereo 3D display");
2294 
2295   prop = RNA_def_property(srna, "display_mode", PROP_ENUM, PROP_NONE);
2296   RNA_def_property_enum_items(prop, rna_enum_stereo3d_display_items);
2297   RNA_def_property_ui_text(prop, "Display Mode", "");
2298 
2299   prop = RNA_def_property(srna, "anaglyph_type", PROP_ENUM, PROP_NONE);
2300   RNA_def_property_enum_items(prop, rna_enum_stereo3d_anaglyph_type_items);
2301   RNA_def_property_ui_text(prop, "Anaglyph Type", "");
2302 
2303   prop = RNA_def_property(srna, "interlace_type", PROP_ENUM, PROP_NONE);
2304   RNA_def_property_enum_items(prop, rna_enum_stereo3d_interlace_type_items);
2305   RNA_def_property_ui_text(prop, "Interlace Type", "");
2306 
2307   prop = RNA_def_property(srna, "use_interlace_swap", PROP_BOOLEAN, PROP_BOOLEAN);
2308   RNA_def_property_boolean_sdna(prop, NULL, "flag", S3D_INTERLACE_SWAP);
2309   RNA_def_property_ui_text(prop, "Swap Left/Right", "Swap left and right stereo channels");
2310 
2311   prop = RNA_def_property(srna, "use_sidebyside_crosseyed", PROP_BOOLEAN, PROP_BOOLEAN);
2312   RNA_def_property_boolean_sdna(prop, NULL, "flag", S3D_SIDEBYSIDE_CROSSEYED);
2313   RNA_def_property_ui_text(prop, "Cross-Eyed", "Right eye should see left image and vice-versa");
2314 }
2315 
rna_def_window(BlenderRNA * brna)2316 static void rna_def_window(BlenderRNA *brna)
2317 {
2318   StructRNA *srna;
2319   PropertyRNA *prop;
2320 
2321   srna = RNA_def_struct(brna, "Window", NULL);
2322   RNA_def_struct_ui_text(srna, "Window", "Open window");
2323   RNA_def_struct_sdna(srna, "wmWindow");
2324 
2325   prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
2326   RNA_def_property_ui_text(prop, "Parent Window", "Active workspace and scene follow this window");
2327 
2328   rna_def_window_stereo3d(brna);
2329 
2330   prop = RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
2331   RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL);
2332   RNA_def_property_pointer_funcs(prop, NULL, "rna_Window_scene_set", NULL, NULL);
2333   RNA_def_property_ui_text(prop, "Scene", "Active scene to be edited in the window");
2334   RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
2335   RNA_def_property_update(prop, 0, "rna_Window_scene_update");
2336 
2337   prop = RNA_def_property(srna, "workspace", PROP_POINTER, PROP_NONE);
2338   RNA_def_property_flag(prop, PROP_NEVER_NULL);
2339   RNA_def_property_struct_type(prop, "WorkSpace");
2340   RNA_def_property_ui_text(prop, "Workspace", "Active workspace showing in the window");
2341   RNA_def_property_pointer_funcs(
2342       prop, "rna_Window_workspace_get", "rna_Window_workspace_set", NULL, NULL);
2343   RNA_def_property_flag(prop, PROP_EDITABLE | PROP_CONTEXT_UPDATE);
2344   RNA_def_property_update(prop, 0, "rna_Window_workspace_update");
2345 
2346   prop = RNA_def_property(srna, "screen", PROP_POINTER, PROP_NONE);
2347   RNA_def_property_struct_type(prop, "Screen");
2348   RNA_def_property_ui_text(prop, "Screen", "Active workspace screen showing in the window");
2349   RNA_def_property_pointer_funcs(prop,
2350                                  "rna_Window_screen_get",
2351                                  "rna_Window_screen_set",
2352                                  NULL,
2353                                  "rna_Window_screen_assign_poll");
2354   RNA_def_property_flag(prop, PROP_NEVER_NULL | PROP_EDITABLE | PROP_CONTEXT_UPDATE);
2355   RNA_def_property_update(prop, 0, "rna_workspace_screen_update");
2356 
2357   prop = RNA_def_property(srna, "view_layer", PROP_POINTER, PROP_NONE);
2358   RNA_def_property_struct_type(prop, "ViewLayer");
2359   RNA_def_property_pointer_funcs(
2360       prop, "rna_Window_view_layer_get", "rna_Window_view_layer_set", NULL, NULL);
2361   RNA_def_property_ui_text(
2362       prop, "Active View Layer", "The active workspace view layer showing in the window");
2363   RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL);
2364   RNA_def_property_update(prop, NC_SCREEN | ND_LAYER, NULL);
2365 
2366   prop = RNA_def_property(srna, "x", PROP_INT, PROP_NONE);
2367   RNA_def_property_int_sdna(prop, NULL, "posx");
2368   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2369   RNA_def_property_ui_text(prop, "X Position", "Horizontal location of the window");
2370 
2371   prop = RNA_def_property(srna, "y", PROP_INT, PROP_NONE);
2372   RNA_def_property_int_sdna(prop, NULL, "posy");
2373   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2374   RNA_def_property_ui_text(prop, "Y Position", "Vertical location of the window");
2375 
2376   prop = RNA_def_property(srna, "width", PROP_INT, PROP_UNSIGNED);
2377   RNA_def_property_int_sdna(prop, NULL, "sizex");
2378   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2379   RNA_def_property_ui_text(prop, "Width", "Window width");
2380 
2381   prop = RNA_def_property(srna, "height", PROP_INT, PROP_UNSIGNED);
2382   RNA_def_property_int_sdna(prop, NULL, "sizey");
2383   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2384   RNA_def_property_ui_text(prop, "Height", "Window height");
2385 
2386   prop = RNA_def_property(srna, "stereo_3d_display", PROP_POINTER, PROP_NONE);
2387   RNA_def_property_pointer_sdna(prop, NULL, "stereo3d_format");
2388   RNA_def_property_flag(prop, PROP_NEVER_NULL);
2389   RNA_def_property_struct_type(prop, "Stereo3dDisplay");
2390   RNA_def_property_ui_text(prop, "Stereo 3D Display", "Settings for stereo 3d display");
2391 
2392   RNA_api_window(srna);
2393 }
2394 
2395 /* curve.splines */
rna_def_wm_keyconfigs(BlenderRNA * brna,PropertyRNA * cprop)2396 static void rna_def_wm_keyconfigs(BlenderRNA *brna, PropertyRNA *cprop)
2397 {
2398   StructRNA *srna;
2399   PropertyRNA *prop;
2400 
2401   RNA_def_property_srna(cprop, "KeyConfigurations");
2402   srna = RNA_def_struct(brna, "KeyConfigurations", NULL);
2403   RNA_def_struct_sdna(srna, "wmWindowManager");
2404   RNA_def_struct_ui_text(srna, "KeyConfigs", "Collection of KeyConfigs");
2405 
2406   prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
2407   RNA_def_property_struct_type(prop, "KeyConfig");
2408   RNA_def_property_pointer_funcs(prop,
2409                                  "rna_WindowManager_active_keyconfig_get",
2410                                  "rna_WindowManager_active_keyconfig_set",
2411                                  NULL,
2412                                  NULL);
2413   RNA_def_property_flag(prop, PROP_EDITABLE);
2414   RNA_def_property_ui_text(prop, "Active KeyConfig", "Active key configuration (preset)");
2415 
2416   prop = RNA_def_property(srna, "default", PROP_POINTER, PROP_NEVER_NULL);
2417   RNA_def_property_pointer_sdna(prop, NULL, "defaultconf");
2418   RNA_def_property_struct_type(prop, "KeyConfig");
2419   RNA_def_property_ui_text(prop, "Default Key Configuration", "Default builtin key configuration");
2420 
2421   prop = RNA_def_property(srna, "addon", PROP_POINTER, PROP_NEVER_NULL);
2422   RNA_def_property_pointer_sdna(prop, NULL, "addonconf");
2423   RNA_def_property_struct_type(prop, "KeyConfig");
2424   RNA_def_property_ui_text(
2425       prop,
2426       "Add-on Key Configuration",
2427       "Key configuration that can be extended by add-ons, and is added to the active "
2428       "configuration when handling events");
2429 
2430   prop = RNA_def_property(srna, "user", PROP_POINTER, PROP_NEVER_NULL);
2431   RNA_def_property_pointer_sdna(prop, NULL, "userconf");
2432   RNA_def_property_struct_type(prop, "KeyConfig");
2433   RNA_def_property_ui_text(
2434       prop,
2435       "User Key Configuration",
2436       "Final key configuration that combines keymaps from the active and add-on configurations, "
2437       "and can be edited by the user");
2438 
2439   RNA_api_keyconfigs(srna);
2440 }
2441 
rna_def_windowmanager(BlenderRNA * brna)2442 static void rna_def_windowmanager(BlenderRNA *brna)
2443 {
2444   StructRNA *srna;
2445   PropertyRNA *prop;
2446 
2447   srna = RNA_def_struct(brna, "WindowManager", "ID");
2448   RNA_def_struct_ui_text(
2449       srna,
2450       "Window Manager",
2451       "Window manager data-block defining open windows and other user interface data");
2452   RNA_def_struct_clear_flag(srna, STRUCT_ID_REFCOUNT);
2453   RNA_def_struct_sdna(srna, "wmWindowManager");
2454 
2455   prop = RNA_def_property(srna, "operators", PROP_COLLECTION, PROP_NONE);
2456   RNA_def_property_struct_type(prop, "Operator");
2457   RNA_def_property_ui_text(prop, "Operators", "Operator registry");
2458 
2459   prop = RNA_def_property(srna, "windows", PROP_COLLECTION, PROP_NONE);
2460   RNA_def_property_struct_type(prop, "Window");
2461   RNA_def_property_ui_text(prop, "Windows", "Open windows");
2462 
2463   prop = RNA_def_property(srna, "keyconfigs", PROP_COLLECTION, PROP_NONE);
2464   RNA_def_property_struct_type(prop, "KeyConfig");
2465   RNA_def_property_ui_text(prop, "Key Configurations", "Registered key configurations");
2466   rna_def_wm_keyconfigs(brna, prop);
2467 
2468   prop = RNA_def_property(srna, "xr_session_settings", PROP_POINTER, PROP_NONE);
2469   RNA_def_property_pointer_sdna(prop, NULL, "xr.session_settings");
2470   RNA_def_property_flag(prop, PROP_NEVER_NULL);
2471   RNA_def_property_ui_text(prop, "XR Session Settings", "");
2472 
2473   prop = RNA_def_property(srna, "xr_session_state", PROP_POINTER, PROP_NONE);
2474   RNA_def_property_struct_type(prop, "XrSessionState");
2475   RNA_def_property_pointer_funcs(prop, "rna_WindowManager_xr_session_state_get", NULL, NULL, NULL);
2476   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2477   RNA_def_property_ui_text(
2478       prop, "XR Session State", "Runtime state information about the VR session");
2479 
2480   RNA_api_wm(srna);
2481 }
2482 
2483 /* keyconfig.items */
rna_def_keymap_items(BlenderRNA * brna,PropertyRNA * cprop)2484 static void rna_def_keymap_items(BlenderRNA *brna, PropertyRNA *cprop)
2485 {
2486   StructRNA *srna;
2487 
2488   RNA_def_property_srna(cprop, "KeyMapItems");
2489   srna = RNA_def_struct(brna, "KeyMapItems", NULL);
2490   RNA_def_struct_sdna(srna, "wmKeyMap");
2491   RNA_def_struct_ui_text(srna, "KeyMap Items", "Collection of keymap items");
2492 
2493   RNA_api_keymapitems(srna);
2494 }
2495 
rna_def_wm_keymaps(BlenderRNA * brna,PropertyRNA * cprop)2496 static void rna_def_wm_keymaps(BlenderRNA *brna, PropertyRNA *cprop)
2497 {
2498   StructRNA *srna;
2499 
2500   RNA_def_property_srna(cprop, "KeyMaps");
2501   srna = RNA_def_struct(brna, "KeyMaps", NULL);
2502   RNA_def_struct_sdna(srna, "wmKeyConfig");
2503   RNA_def_struct_ui_text(srna, "Key Maps", "Collection of keymaps");
2504 
2505   RNA_api_keymaps(srna);
2506 }
2507 
rna_def_keyconfig_prefs(BlenderRNA * brna)2508 static void rna_def_keyconfig_prefs(BlenderRNA *brna)
2509 {
2510   StructRNA *srna;
2511   PropertyRNA *prop;
2512 
2513   srna = RNA_def_struct(brna, "KeyConfigPreferences", NULL);
2514   RNA_def_struct_ui_text(srna, "Key-Config Preferences", "");
2515   RNA_def_struct_sdna(srna, "wmKeyConfigPref"); /* WARNING: only a bAddon during registration */
2516 
2517   RNA_def_struct_refine_func(srna, "rna_wmKeyConfigPref_refine");
2518   RNA_def_struct_register_funcs(
2519       srna, "rna_wmKeyConfigPref_register", "rna_wmKeyConfigPref_unregister", NULL);
2520   RNA_def_struct_idprops_func(srna, "rna_wmKeyConfigPref_idprops");
2521   RNA_def_struct_flag(srna, STRUCT_NO_DATABLOCK_IDPROPERTIES); /* Mandatory! */
2522 
2523   /* registration */
2524   RNA_define_verify_sdna(0);
2525   prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
2526   RNA_def_property_string_sdna(prop, NULL, "idname");
2527   RNA_def_property_flag(prop, PROP_REGISTER);
2528   RNA_define_verify_sdna(1);
2529 }
2530 
rna_def_keyconfig(BlenderRNA * brna)2531 static void rna_def_keyconfig(BlenderRNA *brna)
2532 {
2533   StructRNA *srna;
2534   PropertyRNA *prop;
2535 
2536   static const EnumPropertyItem map_type_items[] = {
2537       {KMI_TYPE_KEYBOARD, "KEYBOARD", 0, "Keyboard", ""},
2538       {KMI_TYPE_TWEAK, "TWEAK", 0, "Tweak", ""},
2539       {KMI_TYPE_MOUSE, "MOUSE", 0, "Mouse", ""},
2540       {KMI_TYPE_NDOF, "NDOF", 0, "NDOF", ""},
2541       {KMI_TYPE_TEXTINPUT, "TEXTINPUT", 0, "Text Input", ""},
2542       {KMI_TYPE_TIMER, "TIMER", 0, "Timer", ""},
2543       {0, NULL, 0, NULL, NULL},
2544   };
2545 
2546   /* KeyConfig */
2547   srna = RNA_def_struct(brna, "KeyConfig", NULL);
2548   RNA_def_struct_sdna(srna, "wmKeyConfig");
2549   RNA_def_struct_ui_text(srna, "Key Configuration", "Input configuration, including keymaps");
2550 
2551   prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
2552   RNA_def_property_string_sdna(prop, NULL, "idname");
2553   RNA_def_property_ui_text(prop, "Name", "Name of the key configuration");
2554   RNA_def_struct_name_property(srna, prop);
2555 
2556   prop = RNA_def_property(srna, "keymaps", PROP_COLLECTION, PROP_NONE);
2557   RNA_def_property_struct_type(prop, "KeyMap");
2558   RNA_def_property_ui_text(prop, "Key Maps", "Key maps configured as part of this configuration");
2559   rna_def_wm_keymaps(brna, prop);
2560 
2561   prop = RNA_def_property(srna, "is_user_defined", PROP_BOOLEAN, PROP_NONE);
2562   RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYCONF_USER);
2563   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2564   RNA_def_property_ui_text(
2565       prop, "User Defined", "Indicates that a keyconfig was defined by the user");
2566 
2567   /* Collection active property */
2568   prop = RNA_def_property(srna, "preferences", PROP_POINTER, PROP_NONE);
2569   RNA_def_property_struct_type(prop, "KeyConfigPreferences");
2570   RNA_def_property_pointer_funcs(prop, "rna_wmKeyConfig_preferences_get", NULL, NULL, NULL);
2571 
2572   RNA_api_keyconfig(srna);
2573 
2574   /* KeyMap */
2575   srna = RNA_def_struct(brna, "KeyMap", NULL);
2576   RNA_def_struct_sdna(srna, "wmKeyMap");
2577   RNA_def_struct_ui_text(srna, "Key Map", "Input configuration, including keymaps");
2578 
2579   prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
2580   RNA_def_property_string_sdna(prop, NULL, "idname");
2581   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2582   RNA_def_property_ui_text(prop, "Name", "Name of the key map");
2583   RNA_def_struct_name_property(srna, prop);
2584 
2585   prop = RNA_def_property(srna, "bl_owner_id", PROP_STRING, PROP_NONE);
2586   RNA_def_property_string_sdna(prop, NULL, "owner_id");
2587   RNA_def_property_ui_text(prop, "Owner", "Internal owner");
2588 
2589   prop = RNA_def_property(srna, "space_type", PROP_ENUM, PROP_NONE);
2590   RNA_def_property_enum_sdna(prop, NULL, "spaceid");
2591   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2592   RNA_def_property_enum_items(prop, rna_enum_space_type_items);
2593   RNA_def_property_ui_text(prop, "Space Type", "Optional space type keymap is associated with");
2594 
2595   prop = RNA_def_property(srna, "region_type", PROP_ENUM, PROP_NONE);
2596   RNA_def_property_enum_sdna(prop, NULL, "regionid");
2597   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2598   RNA_def_property_enum_items(prop, rna_enum_region_type_items);
2599   RNA_def_property_ui_text(prop, "Region Type", "Optional region type keymap is associated with");
2600 
2601   prop = RNA_def_property(srna, "keymap_items", PROP_COLLECTION, PROP_NONE);
2602   RNA_def_property_collection_sdna(prop, NULL, "items", NULL);
2603   RNA_def_property_struct_type(prop, "KeyMapItem");
2604   RNA_def_property_ui_text(
2605       prop, "Items", "Items in the keymap, linking an operator to an input event");
2606   rna_def_keymap_items(brna, prop);
2607 
2608   prop = RNA_def_property(srna, "is_user_modified", PROP_BOOLEAN, PROP_NONE);
2609   RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYMAP_USER_MODIFIED);
2610   RNA_def_property_ui_text(prop, "User Defined", "Keymap is defined by the user");
2611 
2612   prop = RNA_def_property(srna, "is_modal", PROP_BOOLEAN, PROP_NONE);
2613   RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYMAP_MODAL);
2614   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2615   RNA_def_property_ui_text(
2616       prop,
2617       "Modal Keymap",
2618       "Indicates that a keymap is used for translate modal events for an operator");
2619 
2620   prop = RNA_def_property(srna, "show_expanded_items", PROP_BOOLEAN, PROP_NONE);
2621   RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYMAP_EXPANDED);
2622   RNA_def_property_ui_text(prop, "Items Expanded", "Expanded in the user interface");
2623   RNA_def_property_ui_icon(prop, ICON_DISCLOSURE_TRI_RIGHT, 1);
2624 
2625   prop = RNA_def_property(srna, "show_expanded_children", PROP_BOOLEAN, PROP_NONE);
2626   RNA_def_property_boolean_sdna(prop, NULL, "flag", KEYMAP_CHILDREN_EXPANDED);
2627   RNA_def_property_ui_text(prop, "Children Expanded", "Children expanded in the user interface");
2628   RNA_def_property_ui_icon(prop, ICON_DISCLOSURE_TRI_RIGHT, 1);
2629 
2630   RNA_api_keymap(srna);
2631 
2632   /* KeyMapItem */
2633   srna = RNA_def_struct(brna, "KeyMapItem", NULL);
2634   RNA_def_struct_sdna(srna, "wmKeyMapItem");
2635   RNA_def_struct_ui_text(srna, "Key Map Item", "Item in a Key Map");
2636 
2637   prop = RNA_def_property(srna, "idname", PROP_STRING, PROP_NONE);
2638   RNA_def_property_string_sdna(prop, NULL, "idname");
2639   RNA_def_property_ui_text(prop, "Identifier", "Identifier of operator to call on input event");
2640   RNA_def_property_string_funcs(prop,
2641                                 "rna_wmKeyMapItem_idname_get",
2642                                 "rna_wmKeyMapItem_idname_length",
2643                                 "rna_wmKeyMapItem_idname_set");
2644   RNA_def_struct_name_property(srna, prop);
2645   RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
2646 
2647   /* this is in fact the operator name, but if the operator can't be found we
2648    * fallback on the operator ID */
2649   prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
2650   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2651   RNA_def_property_ui_text(prop, "Name", "Name of operator (translated) to call on input event");
2652   RNA_def_property_string_funcs(
2653       prop, "rna_wmKeyMapItem_name_get", "rna_wmKeyMapItem_name_length", NULL);
2654 
2655   prop = RNA_def_property(srna, "properties", PROP_POINTER, PROP_NONE);
2656   RNA_def_property_struct_type(prop, "OperatorProperties");
2657   RNA_def_property_pointer_funcs(prop, "rna_KeyMapItem_properties_get", NULL, NULL, NULL);
2658   RNA_def_property_ui_text(prop, "Properties", "Properties to set when the operator is called");
2659   RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
2660 
2661   prop = RNA_def_property(srna, "map_type", PROP_ENUM, PROP_NONE);
2662   RNA_def_property_enum_sdna(prop, NULL, "maptype");
2663   RNA_def_property_enum_items(prop, map_type_items);
2664   RNA_def_property_enum_funcs(
2665       prop, "rna_wmKeyMapItem_map_type_get", "rna_wmKeyMapItem_map_type_set", NULL);
2666   RNA_def_property_ui_text(prop, "Map Type", "Type of event mapping");
2667   RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
2668 
2669   prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
2670   RNA_def_property_enum_sdna(prop, NULL, "type");
2671   RNA_def_property_enum_items(prop, rna_enum_event_type_items);
2672   RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UI_EVENTS);
2673   RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_KeyMapItem_type_itemf");
2674   RNA_def_property_ui_text(prop, "Type", "Type of event");
2675   RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
2676 
2677   prop = RNA_def_property(srna, "value", PROP_ENUM, PROP_NONE);
2678   RNA_def_property_enum_sdna(prop, NULL, "val");
2679   RNA_def_property_enum_items(prop, rna_enum_event_value_items);
2680   RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_KeyMapItem_value_itemf");
2681   RNA_def_property_ui_text(prop, "Value", "");
2682   RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
2683 
2684   prop = RNA_def_property(srna, "id", PROP_INT, PROP_NONE);
2685   RNA_def_property_int_sdna(prop, NULL, "id");
2686   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2687   RNA_def_property_ui_text(prop, "ID", "ID of the item");
2688   RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
2689 
2690   prop = RNA_def_property(srna, "any", PROP_BOOLEAN, PROP_NONE);
2691   RNA_def_property_boolean_funcs(prop, "rna_KeyMapItem_any_get", "rna_KeyMapItem_any_set");
2692   RNA_def_property_ui_text(prop, "Any", "Any modifier keys pressed");
2693   RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
2694 
2695   prop = RNA_def_property(srna, "shift", PROP_BOOLEAN, PROP_NONE);
2696   RNA_def_property_boolean_sdna(prop, NULL, "shift", 0);
2697   RNA_def_property_boolean_funcs(prop, "rna_KeyMapItem_shift_get", NULL);
2698   /*  RNA_def_property_enum_sdna(prop, NULL, "shift"); */
2699   /*  RNA_def_property_enum_items(prop, keymap_modifiers_items); */
2700   RNA_def_property_ui_text(prop, "Shift", "Shift key pressed");
2701   RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_WINDOWMANAGER);
2702   RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
2703 
2704   prop = RNA_def_property(srna, "ctrl", PROP_BOOLEAN, PROP_NONE);
2705   RNA_def_property_boolean_sdna(prop, NULL, "ctrl", 0);
2706   RNA_def_property_boolean_funcs(prop, "rna_KeyMapItem_ctrl_get", NULL);
2707   /*  RNA_def_property_enum_sdna(prop, NULL, "ctrl"); */
2708   /*  RNA_def_property_enum_items(prop, keymap_modifiers_items); */
2709   RNA_def_property_ui_text(prop, "Ctrl", "Control key pressed");
2710   RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
2711 
2712   prop = RNA_def_property(srna, "alt", PROP_BOOLEAN, PROP_NONE);
2713   RNA_def_property_boolean_sdna(prop, NULL, "alt", 0);
2714   RNA_def_property_boolean_funcs(prop, "rna_KeyMapItem_alt_get", NULL);
2715   /*  RNA_def_property_enum_sdna(prop, NULL, "alt"); */
2716   /*  RNA_def_property_enum_items(prop, keymap_modifiers_items); */
2717   RNA_def_property_ui_text(prop, "Alt", "Alt key pressed");
2718   RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
2719 
2720   prop = RNA_def_property(srna, "oskey", PROP_BOOLEAN, PROP_NONE);
2721   RNA_def_property_boolean_sdna(prop, NULL, "oskey", 0);
2722   RNA_def_property_boolean_funcs(prop, "rna_KeyMapItem_oskey_get", NULL);
2723   /*  RNA_def_property_enum_sdna(prop, NULL, "oskey"); */
2724   /*  RNA_def_property_enum_items(prop, keymap_modifiers_items); */
2725   RNA_def_property_ui_text(prop, "OS Key", "Operating system key pressed");
2726   RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
2727 
2728   prop = RNA_def_property(srna, "key_modifier", PROP_ENUM, PROP_NONE);
2729   RNA_def_property_enum_sdna(prop, NULL, "keymodifier");
2730   RNA_def_property_enum_items(prop, rna_enum_event_type_items);
2731   RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UI_EVENTS);
2732   RNA_def_property_enum_funcs(prop, NULL, "rna_wmKeyMapItem_keymodifier_set", NULL);
2733   RNA_def_property_ui_text(prop, "Key Modifier", "Regular key pressed as a modifier");
2734   RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
2735 
2736   prop = RNA_def_property(srna, "repeat", PROP_BOOLEAN, PROP_NONE);
2737   RNA_def_property_flag(prop, PROP_NO_DEG_UPDATE);
2738   RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", KMI_REPEAT_IGNORE);
2739   RNA_def_property_ui_text(prop, "Repeat", "Active on key-repeat events (when a key is held)");
2740   RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
2741 
2742   prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
2743   RNA_def_property_flag(prop, PROP_NO_DEG_UPDATE);
2744   RNA_def_property_boolean_sdna(prop, NULL, "flag", KMI_EXPANDED);
2745   RNA_def_property_ui_text(
2746       prop, "Expanded", "Show key map event and property details in the user interface");
2747   RNA_def_property_ui_icon(prop, ICON_DISCLOSURE_TRI_RIGHT, 1);
2748 
2749   prop = RNA_def_property(srna, "propvalue", PROP_ENUM, PROP_NONE);
2750   RNA_def_property_enum_sdna(prop, NULL, "propvalue");
2751   RNA_def_property_enum_items(prop, rna_enum_keymap_propvalue_items);
2752   RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_KeyMapItem_propvalue_itemf");
2753   RNA_def_property_ui_text(
2754       prop, "Property Value", "The value this event translates to in a modal keymap");
2755   RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
2756 
2757   prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
2758   RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", KMI_INACTIVE);
2759   RNA_def_property_ui_text(prop, "Active", "Activate or deactivate item");
2760   RNA_def_property_ui_icon(prop, ICON_CHECKBOX_DEHLT, 1);
2761   RNA_def_property_update(prop, 0, "rna_KeyMapItem_update");
2762 
2763   prop = RNA_def_property(srna, "is_user_modified", PROP_BOOLEAN, PROP_NONE);
2764   RNA_def_property_boolean_sdna(prop, NULL, "flag", KMI_USER_MODIFIED);
2765   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2766   RNA_def_property_ui_text(prop, "User Modified", "Is this keymap item modified by the user");
2767 
2768   prop = RNA_def_property(srna, "is_user_defined", PROP_BOOLEAN, PROP_NONE);
2769   RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2770   RNA_def_property_ui_text(
2771       prop,
2772       "User Defined",
2773       "Is this keymap item user defined (doesn't just replace a builtin item)");
2774   RNA_def_property_boolean_funcs(prop, "rna_KeyMapItem_userdefined_get", NULL);
2775 
2776   RNA_api_keymapitem(srna);
2777 }
2778 
RNA_def_wm(BlenderRNA * brna)2779 void RNA_def_wm(BlenderRNA *brna)
2780 {
2781   rna_def_operator(brna);
2782   rna_def_operator_options_runtime(brna);
2783   rna_def_operator_utils(brna);
2784   rna_def_operator_filelist_element(brna);
2785   rna_def_macro_operator(brna);
2786   rna_def_operator_type_macro(brna);
2787   rna_def_event(brna);
2788   rna_def_timer(brna);
2789   rna_def_popupmenu(brna);
2790   rna_def_popovermenu(brna);
2791   rna_def_piemenu(brna);
2792   rna_def_window(brna);
2793   rna_def_windowmanager(brna);
2794   rna_def_keyconfig_prefs(brna);
2795   rna_def_keyconfig(brna);
2796 }
2797 
2798 #endif /* RNA_RUNTIME */
2799