4 * ***** BEGIN GPL LICENSE BLOCK *****
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 * Contributor(s): Blender Foundation (2008).
22 * ***** END GPL LICENSE BLOCK *****
27 #include "RNA_define.h"
28 #include "RNA_types.h"
30 #include "rna_internal.h"
32 #include "DNA_windowmanager_types.h"
33 #include "WM_types.h" /* wmEvent */
36 EnumPropertyItem event_value_items[] = {
37 {KM_ANY, "ANY", 0, "Any", ""},
38 {KM_NOTHING, "NOTHING", 0, "Nothing", ""},
39 {KM_PRESS, "PRESS", 0, "Press", ""},
40 {KM_RELEASE, "RELEASE", 0, "Release", ""},
41 {0, NULL, 0, NULL, NULL}};
43 /* not returned: CAPSLOCKKEY, UNKNOWNKEY, GRLESSKEY */
44 EnumPropertyItem event_type_items[] = {
46 {LEFTMOUSE, "LEFTMOUSE", 0, "Left Mouse", ""},
47 {MIDDLEMOUSE, "MIDDLEMOUSE", 0, "Middle Mouse", ""},
48 {RIGHTMOUSE, "RIGHTMOUSE", 0, "Right Mouse", ""},
49 {ACTIONMOUSE, "ACTIONMOUSE", 0, "Action Mouse", ""},
50 {SELECTMOUSE, "SELECTMOUSE", 0, "Select Mouse", ""},
52 {MOUSEMOVE, "MOUSEMOVE", 0, "Mouse Move", ""},
54 {WHEELUPMOUSE, "WHEELUPMOUSE", 0, "Wheel Up", ""},
55 {WHEELDOWNMOUSE, "WHEELDOWNMOUSE", 0, "Wheel Down", ""},
56 {WHEELINMOUSE, "WHEELINMOUSE", 0, "Wheel In", ""},
57 {WHEELOUTMOUSE, "WHEELOUTMOUSE", 0, "Wheel Out", ""},
59 {EVT_TWEAK_L, "EVT_TWEAK_L", 0, "Tweak Left", ""},
60 {EVT_TWEAK_M, "EVT_TWEAK_M", 0, "Tweak Middle", ""},
61 {EVT_TWEAK_R, "EVT_TWEAK_R", 0, "Tweak Right", ""},
62 {EVT_TWEAK_A, "EVT_TWEAK_A", 0, "Tweak Action", ""},
63 {EVT_TWEAK_S, "EVT_TWEAK_S", 0, "Tweak Select", ""},
65 {AKEY, "A", 0, "A", ""},
66 {BKEY, "B", 0, "B", ""},
67 {CKEY, "C", 0, "C", ""},
68 {DKEY, "D", 0, "D", ""},
69 {EKEY, "E", 0, "E", ""},
70 {FKEY, "F", 0, "F", ""},
71 {GKEY, "G", 0, "G", ""},
72 {HKEY, "H", 0, "H", ""},
73 {IKEY, "I", 0, "I", ""},
74 {JKEY, "J", 0, "J", ""},
75 {KKEY, "K", 0, "K", ""},
76 {LKEY, "L", 0, "L", ""},
77 {MKEY, "M", 0, "M", ""},
78 {NKEY, "N", 0, "N", ""},
79 {OKEY, "O", 0, "O", ""},
80 {PKEY, "P", 0, "P", ""},
81 {QKEY, "Q", 0, "Q", ""},
82 {RKEY, "R", 0, "R", ""},
83 {SKEY, "S", 0, "S", ""},
84 {TKEY, "T", 0, "T", ""},
85 {UKEY, "U", 0, "U", ""},
86 {VKEY, "V", 0, "V", ""},
87 {WKEY, "W", 0, "W", ""},
88 {XKEY, "X", 0, "X", ""},
89 {YKEY, "Y", 0, "Y", ""},
90 {ZKEY, "Z", 0, "Z", ""},
92 {ZEROKEY, "ZERO", 0, "0", ""},
93 {ONEKEY, "ONE", 0, "1", ""},
94 {TWOKEY, "TWO", 0, "2", ""},
95 {THREEKEY, "THREE", 0, "3", ""},
96 {FOURKEY, "FOUR", 0, "4", ""},
97 {FIVEKEY, "FIVE", 0, "5", ""},
98 {SIXKEY, "SIX", 0, "6", ""},
99 {SEVENKEY, "SEVEN", 0, "7", ""},
100 {EIGHTKEY, "EIGHT", 0, "8", ""},
101 {NINEKEY, "NINE", 0, "9", ""},
103 {LEFTCTRLKEY, "LEFT_CTRL", 0, "Left Ctrl", ""},
104 {LEFTALTKEY, "LEFT_ALT", 0, "Left Alt", ""},
105 {LEFTSHIFTKEY, "LEFT_SHIFT", 0, "Left Shift", ""},
106 {RIGHTALTKEY, "RIGHT_ALT", 0, "Right Alt", ""},
107 {RIGHTCTRLKEY, "RIGHT_CTRL", 0, "Right Ctrl", ""},
108 {RIGHTSHIFTKEY, "RIGHT_SHIFT", 0, "Right Shift", ""},
110 {COMMANDKEY, "COMMAND", 0, "Command", ""},
112 {ESCKEY, "ESC", 0, "Esc", ""},
113 {TABKEY, "TAB", 0, "Tab", ""},
114 {RETKEY, "RET", 0, "Return", ""},
115 {SPACEKEY, "SPACE", 0, "Spacebar", ""},
116 {LINEFEEDKEY, "LINE_FEED", 0, "Line Feed", ""},
117 {BACKSPACEKEY, "BACK_SPACE", 0, "Back Space", ""},
118 {DELKEY, "DEL", 0, "Delete", ""},
119 {SEMICOLONKEY, "SEMI_COLON", 0, ";", ""},
120 {PERIODKEY, "PERIOD", 0, ".", ""},
121 {COMMAKEY, "COMMA", 0, ",", ""},
122 {QUOTEKEY, "QUOTE", 0, "\"", ""},
123 {ACCENTGRAVEKEY, "ACCENT_GRAVE", 0, "`", ""},
124 {MINUSKEY, "MINUS", 0, "-", ""},
125 {SLASHKEY, "SLASH", 0, "/", ""},
126 {BACKSLASHKEY, "BACK_SLASH", 0, "\\", ""},
127 {EQUALKEY, "EQUAL", 0, "=", ""},
128 {LEFTBRACKETKEY, "LEFT_BRACKET", 0, "]", ""},
129 {RIGHTBRACKETKEY, "RIGHT_BRACKET", 0, "[", ""},
130 {LEFTARROWKEY, "LEFT_ARROW", 0, "Left Arrow", ""},
131 {DOWNARROWKEY, "DOWN_ARROW", 0, "Down Arrow", ""},
132 {RIGHTARROWKEY, "RIGHT_ARROW", 0, "Right Arrow", ""},
133 {UPARROWKEY, "UP_ARROW", 0, "Up Arrow", ""},
134 {PAD2, "NUMPAD_2", 0, "Numpad 2", ""},
135 {PAD4, "NUMPAD_4", 0, "Numpad 4", ""},
136 {PAD6, "NUMPAD_6", 0, "Numpad 6", ""},
137 {PAD8, "NUMPAD_8", 0, "Numpad 8", ""},
138 {PAD1, "NUMPAD_1", 0, "Numpad 1", ""},
139 {PAD3, "NUMPAD_3", 0, "Numpad 3", ""},
140 {PAD5, "NUMPAD_5", 0, "Numpad 5", ""},
141 {PAD7, "NUMPAD_7", 0, "Numpad 7", ""},
142 {PAD9, "NUMPAD_9", 0, "Numpad 9", ""},
143 {PADPERIOD, "NUMPAD_PERIOD", 0, "Numpad .", ""},
144 {PADSLASHKEY, "NUMPAD_SLASH", 0, "Numpad /", ""},
145 {PADASTERKEY, "NUMPAD_ASTERIX", 0, "Numpad *", ""},
146 {PAD0, "NUMPAD_0", 0, "Numpad 0", ""},
147 {PADMINUS, "NUMPAD_MINUS", 0, "Numpad -", ""},
148 {PADENTER, "NUMPAD_ENTER", 0, "Numpad Enter", ""},
149 {PADPLUSKEY, "NUMPAD_PLUS", 0, "Numpad +", ""},
150 {F1KEY, "F1", 0, "F1", ""},
151 {F2KEY, "F2", 0, "F2", ""},
152 {F3KEY, "F3", 0, "F3", ""},
153 {F4KEY, "F4", 0, "F4", ""},
154 {F5KEY, "F5", 0, "F5", ""},
155 {F6KEY, "F6", 0, "F6", ""},
156 {F7KEY, "F7", 0, "F7", ""},
157 {F8KEY, "F8", 0, "F8", ""},
158 {F9KEY, "F9", 0, "F9", ""},
159 {F10KEY, "F10", 0, "F10", ""},
160 {F11KEY, "F11", 0, "F11", ""},
161 {F12KEY, "F12", 0, "F12", ""},
162 {PAUSEKEY, "PAUSE", 0, "Pause", ""},
163 {INSERTKEY, "INSERT", 0, "Insert", ""},
164 {HOMEKEY, "HOME", 0, "Home", ""},
165 {PAGEUPKEY, "PAGE_UP", 0, "Page Up", ""},
166 {PAGEDOWNKEY, "PAGE_DOWN", 0, "Page Down", ""},
167 {ENDKEY, "END", 0, "End", ""},
168 {0, NULL, 0, NULL, NULL}};
174 #include "BKE_idprop.h"
176 static wmOperator *rna_OperatorProperties_find_operator(PointerRNA *ptr)
178 wmWindowManager *wm= ptr->id.data;
179 IDProperty *properties= (IDProperty*)ptr->data;
183 for(op=wm->operators.first; op; op=op->next)
184 if(op->properties == properties)
190 static StructRNA *rna_OperatorProperties_refine(PointerRNA *ptr)
192 wmOperator *op= rna_OperatorProperties_find_operator(ptr);
195 return op->type->srna;
200 IDProperty *rna_OperatorProperties_idproperties(PointerRNA *ptr, int create)
202 if(create && !ptr->data) {
203 IDPropertyTemplate val = {0};
204 ptr->data= IDP_New(IDP_GROUP, val, "RNA_OperatorProperties group");
210 static void rna_Operator_name_get(PointerRNA *ptr, char *value)
212 wmOperator *op= (wmOperator*)ptr->data;
213 strcpy(value, op->type->name);
216 static int rna_Operator_name_length(PointerRNA *ptr)
218 wmOperator *op= (wmOperator*)ptr->data;
219 return strlen(op->type->name);
222 static PointerRNA rna_Operator_properties_get(PointerRNA *ptr)
224 wmOperator *op= (wmOperator*)ptr->data;
225 return rna_pointer_inherit_refine(ptr, &RNA_OperatorProperties, op->properties);
229 static void rna_Event_ascii_get(PointerRNA *ptr, char *value)
231 wmEvent *event= (wmEvent*)ptr->id.data;
232 value[0]= event->ascii;
236 static int rna_Event_ascii_length(PointerRNA *ptr)
238 wmEvent *event= (wmEvent*)ptr->id.data;
239 return (event->ascii)? 1 : 0;
242 static void rna_Window_screen_set(PointerRNA *ptr, PointerRNA value)
244 wmWindow *win= (wmWindow*)ptr->data;
246 if(value.data == NULL)
249 /* exception: can't set screens inside of area/region handers */
250 win->newscreen= value.data;
253 static void rna_Window_screen_update(bContext *C, PointerRNA *ptr)
255 wmWindow *win= (wmWindow*)ptr->data;
257 /* exception: can't set screens inside of area/region handers */
259 WM_event_add_notifier(C, NC_SCREEN|ND_SCREENBROWSE, win->newscreen);
260 win->newscreen= NULL;
266 static void rna_def_operator(BlenderRNA *brna)
271 srna= RNA_def_struct(brna, "Operator", NULL);
272 RNA_def_struct_ui_text(srna, "Operator", "Storage of an operator being executed, or registered after execution.");
273 RNA_def_struct_sdna(srna, "wmOperator");
275 prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
276 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
277 RNA_def_property_string_funcs(prop, "rna_Operator_name_get", "rna_Operator_name_length", NULL);
278 RNA_def_property_ui_text(prop, "Name", "");
279 RNA_def_struct_name_property(srna, prop);
281 prop= RNA_def_property(srna, "properties", PROP_POINTER, PROP_NEVER_NULL);
282 RNA_def_property_struct_type(prop, "OperatorProperties");
283 RNA_def_property_ui_text(prop, "Properties", "");
284 RNA_def_property_pointer_funcs(prop, "rna_Operator_properties_get", NULL, NULL);
286 srna= RNA_def_struct(brna, "OperatorProperties", NULL);
287 RNA_def_struct_ui_text(srna, "Operator Properties", "Input properties of an Operator.");
288 RNA_def_struct_refine_func(srna, "rna_OperatorProperties_refine");
289 RNA_def_struct_idproperties_func(srna, "rna_OperatorProperties_idproperties");
292 static void rna_def_operator_utils(BlenderRNA *brna)
297 srna= RNA_def_struct(brna, "OperatorMousePath", "IDPropertyGroup");
298 RNA_def_struct_ui_text(srna, "Operator Mouse Path", "Mouse path values for operators that record such paths.");
300 prop= RNA_def_property(srna, "loc", PROP_FLOAT, PROP_VECTOR);
301 RNA_def_property_flag(prop, PROP_IDPROPERTY);
302 RNA_def_property_array(prop, 2);
303 RNA_def_property_ui_text(prop, "Location", "Mouse location.");
305 prop= RNA_def_property(srna, "time", PROP_FLOAT, PROP_NONE);
306 RNA_def_property_flag(prop, PROP_IDPROPERTY);
307 RNA_def_property_ui_text(prop, "Time", "Time of mouse location.");
310 static void rna_def_operator_filelist_element(BlenderRNA *brna)
315 srna= RNA_def_struct(brna, "OperatorFileListElement", "IDPropertyGroup");
316 RNA_def_struct_ui_text(srna, "Operator File List Element", "");
319 prop= RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
320 RNA_def_property_flag(prop, PROP_IDPROPERTY);
321 RNA_def_property_ui_text(prop, "Name", "the name of a file or directory within a file list");
324 static void rna_def_event(BlenderRNA *brna)
329 srna= RNA_def_struct(brna, "Event", NULL);
330 RNA_def_struct_ui_text(srna, "Event", "Window Manager Event");
331 RNA_def_struct_sdna(srna, "wmEvent");
334 prop= RNA_def_property(srna, "ascii", PROP_STRING, PROP_NONE);
335 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
336 RNA_def_property_string_funcs(prop, "rna_Event_ascii_get", "rna_Event_ascii_length", NULL);
337 RNA_def_property_ui_text(prop, "ASCII", "Single ASCII character for this event.");
341 prop= RNA_def_property(srna, "value", PROP_ENUM, PROP_NONE);
342 RNA_def_property_enum_sdna(prop, NULL, "val");
343 RNA_def_property_enum_items(prop, event_value_items);
344 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
345 RNA_def_property_ui_text(prop, "Value", "The type of event, only applies to some.");
347 prop= RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
348 RNA_def_property_enum_sdna(prop, NULL, "type");
349 RNA_def_property_enum_items(prop, event_type_items);
350 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
351 RNA_def_property_ui_text(prop, "Type", "");
355 prop= RNA_def_property(srna, "mouse_x", PROP_INT, PROP_NONE);
356 RNA_def_property_int_sdna(prop, NULL, "x");
357 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
358 RNA_def_property_ui_text(prop, "Mouse X Position", "The window relative vertical location of the mouse.");
360 prop= RNA_def_property(srna, "mouse_y", PROP_INT, PROP_NONE);
361 RNA_def_property_int_sdna(prop, NULL, "y");
362 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
363 RNA_def_property_ui_text(prop, "Mouse Y Position", "The window relative horizontal location of the mouse.");
365 prop= RNA_def_property(srna, "mouse_prev_x", PROP_INT, PROP_NONE);
366 RNA_def_property_int_sdna(prop, NULL, "prevx");
367 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
368 RNA_def_property_ui_text(prop, "Mouse Previous X Position", "The window relative vertical location of the mouse.");
370 prop= RNA_def_property(srna, "mouse_prev_y", PROP_INT, PROP_NONE);
371 RNA_def_property_int_sdna(prop, NULL, "prevy");
372 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
373 RNA_def_property_ui_text(prop, "Mouse Previous Y Position", "The window relative horizontal location of the mouse.");
377 prop= RNA_def_property(srna, "shift", PROP_BOOLEAN, PROP_NONE);
378 RNA_def_property_boolean_sdna(prop, NULL, "shift", 1);
379 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
380 RNA_def_property_ui_text(prop, "Shift", "True when the shift key is held.");
382 prop= RNA_def_property(srna, "ctrl", PROP_BOOLEAN, PROP_NONE);
383 RNA_def_property_boolean_sdna(prop, NULL, "ctrl", 1);
384 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
385 RNA_def_property_ui_text(prop, "Ctrl", "True when the shift key is held.");
387 prop= RNA_def_property(srna, "alt", PROP_BOOLEAN, PROP_NONE);
388 RNA_def_property_boolean_sdna(prop, NULL, "alt", 1);
389 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
390 RNA_def_property_ui_text(prop, "Alt", "True when the shift key is held.");
392 prop= RNA_def_property(srna, "oskey", PROP_BOOLEAN, PROP_NONE);
393 RNA_def_property_boolean_sdna(prop, NULL, "oskey", 1);
394 RNA_def_property_clear_flag(prop, PROP_EDITABLE);
395 RNA_def_property_ui_text(prop, "OS Key", "True when the shift key is held.");
398 static void rna_def_window(BlenderRNA *brna)
403 srna= RNA_def_struct(brna, "Window", NULL);
404 RNA_def_struct_ui_text(srna, "Window", "Open window.");
405 RNA_def_struct_sdna(srna, "wmWindow");
407 prop= RNA_def_property(srna, "screen", PROP_POINTER, PROP_NEVER_NULL);
408 RNA_def_property_struct_type(prop, "Screen");
409 RNA_def_property_ui_text(prop, "Screen", "Active screen showing in the window.");
410 RNA_def_property_flag(prop, PROP_EDITABLE);
411 RNA_def_property_pointer_funcs(prop, NULL, "rna_Window_screen_set", NULL);
412 RNA_def_property_update(prop, 0, "rna_Window_screen_update");
415 static void rna_def_windowmanager(BlenderRNA *brna)
420 srna= RNA_def_struct(brna, "WindowManager", "ID");
421 RNA_def_struct_ui_text(srna, "Window Manager", "Window manager datablock defining open windows and other user interface data.");
422 RNA_def_struct_sdna(srna, "wmWindowManager");
424 prop= RNA_def_property(srna, "operators", PROP_COLLECTION, PROP_NONE);
425 RNA_def_property_struct_type(prop, "Operator");
426 RNA_def_property_ui_text(prop, "Operators", "Operator registry.");
428 prop= RNA_def_property(srna, "windows", PROP_COLLECTION, PROP_NONE);
429 RNA_def_property_struct_type(prop, "Window");
430 RNA_def_property_ui_text(prop, "Windows", "Open windows.");
435 void RNA_def_wm(BlenderRNA *brna)
437 rna_def_operator(brna);
438 rna_def_operator_utils(brna);
439 rna_def_operator_filelist_element(brna);
441 rna_def_window(brna);
442 rna_def_windowmanager(brna);