Undo revision 23130 which was a merge with 2.5, a messy one because I did something...
[blender.git] / source / blender / makesrna / intern / rna_context.c
1 /**
2  * $Id$
3  *
4  * ***** BEGIN GPL LICENSE BLOCK *****
5  *
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.
10  *
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.
15  *
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.
19  *
20  * Contributor(s): Blender Foundation (2009).
21  *
22  * ***** END GPL LICENSE BLOCK *****
23  */
24
25 #include <stdlib.h>
26
27 #include "DNA_ID.h"
28 #include "DNA_userdef_types.h"
29
30 #include "RNA_access.h"
31 #include "RNA_define.h"
32 #include "RNA_types.h"
33
34 #include "BKE_context.h"
35
36 #ifdef RNA_RUNTIME
37
38 static PointerRNA rna_Context_manager_get(PointerRNA *ptr)
39 {
40         bContext *C= (bContext*)ptr->data;
41         return rna_pointer_inherit_refine(ptr, &RNA_WindowManager, CTX_wm_manager(C));
42 }
43
44 static PointerRNA rna_Context_window_get(PointerRNA *ptr)
45 {
46         bContext *C= (bContext*)ptr->data;
47         return rna_pointer_inherit_refine(ptr, &RNA_Window, CTX_wm_window(C));
48 }
49
50 static PointerRNA rna_Context_screen_get(PointerRNA *ptr)
51 {
52         bContext *C= (bContext*)ptr->data;
53         return rna_pointer_inherit_refine(ptr, &RNA_Screen, CTX_wm_screen(C));
54 }
55
56 static PointerRNA rna_Context_area_get(PointerRNA *ptr)
57 {
58         bContext *C= (bContext*)ptr->data;
59         PointerRNA newptr;
60         RNA_pointer_create((ID*)CTX_wm_screen(C), &RNA_Area, CTX_wm_area(C), &newptr);
61         return newptr;
62 }
63
64 static PointerRNA rna_Context_space_data_get(PointerRNA *ptr)
65 {
66         bContext *C= (bContext*)ptr->data;
67         PointerRNA newptr;
68         RNA_pointer_create((ID*)CTX_wm_screen(C), &RNA_Space, CTX_wm_space_data(C), &newptr);
69         return newptr;
70 }
71
72 static PointerRNA rna_Context_region_get(PointerRNA *ptr)
73 {
74         bContext *C= (bContext*)ptr->data;
75         PointerRNA newptr;
76         RNA_pointer_create((ID*)CTX_wm_screen(C), &RNA_Region, CTX_wm_region(C), &newptr);
77         return newptr;
78 }
79
80 /*static PointerRNA rna_Context_region_data_get(PointerRNA *ptr)
81 {
82         bContext *C= (bContext*)ptr->data;
83         PointerRNA newptr;
84         RNA_pointer_create((ID*)CTX_wm_screen(C), &RNA_RegionData, CTX_wm_region_data(C), &newptr);
85         return newptr;
86 }*/
87
88 static PointerRNA rna_Context_main_get(PointerRNA *ptr)
89 {
90         bContext *C= (bContext*)ptr->data;
91         return rna_pointer_inherit_refine(ptr, &RNA_Main, CTX_data_main(C));
92 }
93
94 static PointerRNA rna_Context_scene_get(PointerRNA *ptr)
95 {
96         bContext *C= (bContext*)ptr->data;
97         return rna_pointer_inherit_refine(ptr, &RNA_Scene, CTX_data_scene(C));
98 }
99
100 static PointerRNA rna_Context_tool_settings_get(PointerRNA *ptr)
101 {
102         bContext *C= (bContext*)ptr->data;
103         return rna_pointer_inherit_refine(ptr, &RNA_ToolSettings, CTX_data_tool_settings(C));
104 }
105
106 static PointerRNA rna_Context_user_preferences_get(PointerRNA *ptr)
107 {
108         PointerRNA newptr;
109         RNA_pointer_create(NULL, &RNA_UserPreferences, &U, &newptr);
110         return newptr;
111 }
112
113 static int rna_Context_mode_get(PointerRNA *ptr)
114 {
115         bContext *C= (bContext*)ptr->data;
116         return CTX_data_mode_enum(C);
117 }
118
119 #else
120
121 void RNA_def_context(BlenderRNA *brna)
122 {
123         StructRNA *srna;
124         PropertyRNA *prop;
125
126         static EnumPropertyItem mode_items[] = {
127                 {CTX_MODE_EDIT_MESH, "EDIT_MESH", 0, "Mesh Edit", ""},
128                 {CTX_MODE_EDIT_CURVE, "EDIT_CURVE", 0, "Curve Edit", ""},
129                 {CTX_MODE_EDIT_SURFACE, "EDIT_SURFACE", 0, "Surface Edit", ""},
130                 {CTX_MODE_EDIT_TEXT, "EDIT_TEXT", 0, "Edit Edit", ""},
131                 {CTX_MODE_EDIT_ARMATURE, "EDIT_ARMATURE", 0, "Armature Edit", ""}, // PARSKEL reuse will give issues
132                 {CTX_MODE_EDIT_METABALL, "EDIT_METABALL", 0, "Metaball Edit", ""},
133                 {CTX_MODE_EDIT_LATTICE, "EDIT_LATTICE", 0, "Lattice Edit", ""},
134                 {CTX_MODE_POSE, "POSE", 0, "Pose ", ""},
135                 {CTX_MODE_SCULPT, "SCULPT", 0, "Sculpt", ""},
136                 {CTX_MODE_PAINT_WEIGHT, "PAINT_WEIGHT", 0, "Weight Paint", ""},
137                 {CTX_MODE_PAINT_VERTEX, "PAINT_VERTEX", 0, "Vertex Paint", ""},
138                 {CTX_MODE_PAINT_TEXTURE, "PAINT_TEXTURE", 0, "Texture Paint", ""},
139                 {CTX_MODE_PARTICLE, "PARTICLE", 0, "Particle", ""},
140                 {CTX_MODE_OBJECT, "OBJECT", 0, "Object", ""},
141                 {0, NULL, 0, NULL, NULL}};
142
143         srna= RNA_def_struct(brna, "Context", NULL);
144         RNA_def_struct_ui_text(srna, "Context", "Current windowmanager and data context.");
145         RNA_def_struct_sdna(srna, "bContext");
146
147         /* WM */
148         prop= RNA_def_property(srna, "manager", PROP_POINTER, PROP_NONE);
149         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
150         RNA_def_property_struct_type(prop, "WindowManager");
151         RNA_def_property_pointer_funcs(prop, "rna_Context_manager_get", NULL, NULL);
152
153         prop= RNA_def_property(srna, "window", PROP_POINTER, PROP_NONE);
154         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
155         RNA_def_property_struct_type(prop, "Window");
156         RNA_def_property_pointer_funcs(prop, "rna_Context_window_get", NULL, NULL);
157
158         prop= RNA_def_property(srna, "screen", PROP_POINTER, PROP_NONE);
159         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
160         RNA_def_property_struct_type(prop, "Screen");
161         RNA_def_property_pointer_funcs(prop, "rna_Context_screen_get", NULL, NULL);
162
163         prop= RNA_def_property(srna, "area", PROP_POINTER, PROP_NONE);
164         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
165         RNA_def_property_struct_type(prop, "Area");
166         RNA_def_property_pointer_funcs(prop, "rna_Context_area_get", NULL, NULL);
167
168         prop= RNA_def_property(srna, "space_data", PROP_POINTER, PROP_NONE);
169         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
170         RNA_def_property_struct_type(prop, "Space");
171         RNA_def_property_pointer_funcs(prop, "rna_Context_space_data_get", NULL, NULL);
172
173         prop= RNA_def_property(srna, "region", PROP_POINTER, PROP_NONE);
174         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
175         RNA_def_property_struct_type(prop, "Region");
176         RNA_def_property_pointer_funcs(prop, "rna_Context_region_get", NULL, NULL);
177
178         /*prop= RNA_def_property(srna, "region_data", PROP_POINTER, PROP_NONE);
179         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
180         RNA_def_property_struct_type(prop, "RegionData");
181         RNA_def_property_pointer_funcs(prop, "rna_Context_region_data_get", NULL, NULL);*/
182
183         /* Data */
184         prop= RNA_def_property(srna, "main", PROP_POINTER, PROP_NONE);
185         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
186         RNA_def_property_struct_type(prop, "Main");
187         RNA_def_property_pointer_funcs(prop, "rna_Context_main_get", NULL, NULL);
188
189         prop= RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
190         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
191         RNA_def_property_struct_type(prop, "Scene");
192         RNA_def_property_pointer_funcs(prop, "rna_Context_scene_get", NULL, NULL);
193
194         prop= RNA_def_property(srna, "tool_settings", PROP_POINTER, PROP_NONE);
195         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
196         RNA_def_property_struct_type(prop, "ToolSettings");
197         RNA_def_property_pointer_funcs(prop, "rna_Context_tool_settings_get", NULL, NULL);
198
199         prop= RNA_def_property(srna, "user_preferences", PROP_POINTER, PROP_NONE);
200         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
201         RNA_def_property_struct_type(prop, "UserPreferences");
202         RNA_def_property_pointer_funcs(prop, "rna_Context_user_preferences_get", NULL, NULL);
203
204         prop= RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
205         RNA_def_property_enum_items(prop, mode_items);
206         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
207         RNA_def_property_enum_funcs(prop, "rna_Context_mode_get", NULL, NULL);
208 }
209
210 #endif
211