doxygen: prevent GPL license block from being parsed as doxygen comment.
[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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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
33 #include "BKE_context.h"
34
35 #ifdef RNA_RUNTIME
36
37 static PointerRNA rna_Context_manager_get(PointerRNA *ptr)
38 {
39         bContext *C= (bContext*)ptr->data;
40         return rna_pointer_inherit_refine(ptr, &RNA_WindowManager, CTX_wm_manager(C));
41 }
42
43 static PointerRNA rna_Context_window_get(PointerRNA *ptr)
44 {
45         bContext *C= (bContext*)ptr->data;
46         return rna_pointer_inherit_refine(ptr, &RNA_Window, CTX_wm_window(C));
47 }
48
49 static PointerRNA rna_Context_screen_get(PointerRNA *ptr)
50 {
51         bContext *C= (bContext*)ptr->data;
52         return rna_pointer_inherit_refine(ptr, &RNA_Screen, CTX_wm_screen(C));
53 }
54
55 static PointerRNA rna_Context_area_get(PointerRNA *ptr)
56 {
57         bContext *C= (bContext*)ptr->data;
58         PointerRNA newptr;
59         RNA_pointer_create((ID*)CTX_wm_screen(C), &RNA_Area, CTX_wm_area(C), &newptr);
60         return newptr;
61 }
62
63 static PointerRNA rna_Context_space_data_get(PointerRNA *ptr)
64 {
65         bContext *C= (bContext*)ptr->data;
66         PointerRNA newptr;
67         RNA_pointer_create((ID*)CTX_wm_screen(C), &RNA_Space, CTX_wm_space_data(C), &newptr);
68         return newptr;
69 }
70
71 static PointerRNA rna_Context_region_get(PointerRNA *ptr)
72 {
73         bContext *C= (bContext*)ptr->data;
74         PointerRNA newptr;
75         RNA_pointer_create((ID*)CTX_wm_screen(C), &RNA_Region, CTX_wm_region(C), &newptr);
76         return newptr;
77 }
78
79 static PointerRNA rna_Context_region_data_get(PointerRNA *ptr)
80 {
81         bContext *C= (bContext*)ptr->data;
82
83         /* only exists for one space still, no generic system yet */
84         if(CTX_wm_view3d(C)) {
85                 PointerRNA newptr;
86                 RNA_pointer_create((ID*)CTX_wm_screen(C), &RNA_RegionView3D, CTX_wm_region_data(C), &newptr);
87                 return newptr;
88         }
89
90         return PointerRNA_NULL;
91 }
92
93 static PointerRNA rna_Context_main_get(PointerRNA *ptr)
94 {
95         bContext *C= (bContext*)ptr->data;
96         return rna_pointer_inherit_refine(ptr, &RNA_BlendData, CTX_data_main(C));
97 }
98
99 static PointerRNA rna_Context_scene_get(PointerRNA *ptr)
100 {
101         bContext *C= (bContext*)ptr->data;
102         return rna_pointer_inherit_refine(ptr, &RNA_Scene, CTX_data_scene(C));
103 }
104
105 static PointerRNA rna_Context_tool_settings_get(PointerRNA *ptr)
106 {
107         bContext *C= (bContext*)ptr->data;
108         ptr->id.data= CTX_data_scene(C);
109         return rna_pointer_inherit_refine(ptr, &RNA_ToolSettings, CTX_data_tool_settings(C));
110 }
111
112 static PointerRNA rna_Context_user_preferences_get(PointerRNA *ptr)
113 {
114         PointerRNA newptr;
115         RNA_pointer_create(NULL, &RNA_UserPreferences, &U, &newptr);
116         return newptr;
117 }
118
119 static int rna_Context_mode_get(PointerRNA *ptr)
120 {
121         bContext *C= (bContext*)ptr->data;
122         return CTX_data_mode_enum(C);
123 }
124
125 #else
126
127 void RNA_def_context(BlenderRNA *brna)
128 {
129         StructRNA *srna;
130         PropertyRNA *prop;
131
132         static EnumPropertyItem mode_items[] = {
133                 {CTX_MODE_EDIT_MESH, "EDIT_MESH", 0, "Mesh Edit", ""},
134                 {CTX_MODE_EDIT_CURVE, "EDIT_CURVE", 0, "Curve Edit", ""},
135                 {CTX_MODE_EDIT_SURFACE, "EDIT_SURFACE", 0, "Surface Edit", ""},
136                 {CTX_MODE_EDIT_TEXT, "EDIT_TEXT", 0, "Edit Edit", ""},
137                 {CTX_MODE_EDIT_ARMATURE, "EDIT_ARMATURE", 0, "Armature Edit", ""}, // PARSKEL reuse will give issues
138                 {CTX_MODE_EDIT_METABALL, "EDIT_METABALL", 0, "Metaball Edit", ""},
139                 {CTX_MODE_EDIT_LATTICE, "EDIT_LATTICE", 0, "Lattice Edit", ""},
140                 {CTX_MODE_POSE, "POSE", 0, "Pose ", ""},
141                 {CTX_MODE_SCULPT, "SCULPT", 0, "Sculpt", ""},
142                 {CTX_MODE_PAINT_WEIGHT, "PAINT_WEIGHT", 0, "Weight Paint", ""},
143                 {CTX_MODE_PAINT_VERTEX, "PAINT_VERTEX", 0, "Vertex Paint", ""},
144                 {CTX_MODE_PAINT_TEXTURE, "PAINT_TEXTURE", 0, "Texture Paint", ""},
145                 {CTX_MODE_PARTICLE, "PARTICLE", 0, "Particle", ""},
146                 {CTX_MODE_OBJECT, "OBJECT", 0, "Object", ""},
147                 {0, NULL, 0, NULL, NULL}};
148
149         srna= RNA_def_struct(brna, "Context", NULL);
150         RNA_def_struct_ui_text(srna, "Context", "Current windowmanager and data context");
151         RNA_def_struct_sdna(srna, "bContext");
152
153         /* WM */
154         prop= RNA_def_property(srna, "window_manager", PROP_POINTER, PROP_NONE);
155         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
156         RNA_def_property_struct_type(prop, "WindowManager");
157         RNA_def_property_pointer_funcs(prop, "rna_Context_manager_get", NULL, NULL, NULL);
158
159         prop= RNA_def_property(srna, "window", PROP_POINTER, PROP_NONE);
160         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
161         RNA_def_property_struct_type(prop, "Window");
162         RNA_def_property_pointer_funcs(prop, "rna_Context_window_get", NULL, NULL, NULL);
163
164         prop= RNA_def_property(srna, "screen", PROP_POINTER, PROP_NONE);
165         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
166         RNA_def_property_struct_type(prop, "Screen");
167         RNA_def_property_pointer_funcs(prop, "rna_Context_screen_get", NULL, NULL, NULL);
168
169         prop= RNA_def_property(srna, "area", PROP_POINTER, PROP_NONE);
170         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
171         RNA_def_property_struct_type(prop, "Area");
172         RNA_def_property_pointer_funcs(prop, "rna_Context_area_get", NULL, NULL, NULL);
173
174         prop= RNA_def_property(srna, "space_data", PROP_POINTER, PROP_NONE);
175         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
176         RNA_def_property_struct_type(prop, "Space");
177         RNA_def_property_pointer_funcs(prop, "rna_Context_space_data_get", NULL, NULL, NULL);
178
179         prop= RNA_def_property(srna, "region", PROP_POINTER, PROP_NONE);
180         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
181         RNA_def_property_struct_type(prop, "Region");
182         RNA_def_property_pointer_funcs(prop, "rna_Context_region_get", NULL, NULL, NULL);
183
184         prop= RNA_def_property(srna, "region_data", PROP_POINTER, PROP_NONE);
185         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
186         RNA_def_property_struct_type(prop, "RegionView3D");
187         RNA_def_property_pointer_funcs(prop, "rna_Context_region_data_get", NULL, NULL, NULL);
188
189         /* Data */
190         prop= RNA_def_property(srna, "blend_data", PROP_POINTER, PROP_NONE);
191         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
192         RNA_def_property_struct_type(prop, "BlendData");
193         RNA_def_property_pointer_funcs(prop, "rna_Context_main_get", NULL, NULL, NULL);
194
195         prop= RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
196         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
197         RNA_def_property_struct_type(prop, "Scene");
198         RNA_def_property_pointer_funcs(prop, "rna_Context_scene_get", NULL, NULL, NULL);
199
200         prop= RNA_def_property(srna, "tool_settings", PROP_POINTER, PROP_NONE);
201         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
202         RNA_def_property_struct_type(prop, "ToolSettings");
203         RNA_def_property_pointer_funcs(prop, "rna_Context_tool_settings_get", NULL, NULL, NULL);
204
205         prop= RNA_def_property(srna, "user_preferences", PROP_POINTER, PROP_NONE);
206         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
207         RNA_def_property_struct_type(prop, "UserPreferences");
208         RNA_def_property_pointer_funcs(prop, "rna_Context_user_preferences_get", NULL, NULL, NULL);
209
210         prop= RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
211         RNA_def_property_enum_items(prop, mode_items);
212         RNA_def_property_clear_flag(prop, PROP_EDITABLE);
213         RNA_def_property_enum_funcs(prop, "rna_Context_mode_get", NULL, NULL);
214 }
215
216 #endif
217