svn merge -r36725:36801 https://svn.blender.org/svnroot/bf-blender/trunk/blender
[blender.git] / source / blender / editors / space_api / spacetypes.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  * The Original Code is Copyright (C) Blender Foundation, 2008
21  *
22  * ***** END GPL/BL DUAL LICENSE BLOCK *****
23  */
24
25 /** \file blender/editors/space_api/spacetypes.c
26  *  \ingroup spapi
27  */
28
29
30 #include <stdlib.h>
31
32 #include "MEM_guardedalloc.h"
33
34 #include "BLI_blenlib.h"
35 #include "BLI_utildefines.h"
36
37 #include "DNA_object_types.h"
38 #include "DNA_windowmanager_types.h"
39
40
41 #include "BKE_context.h"
42 #include "BKE_screen.h"
43
44 #include "bmesh.h"
45
46 #include "UI_interface.h"
47 #include "UI_view2d.h"
48
49
50 #include "ED_anim_api.h"
51 #include "ED_armature.h"
52 #include "ED_curve.h"
53 #include "ED_fileselect.h"
54 #include "ED_gpencil.h"
55 #include "ED_markers.h"
56 #include "ED_mesh.h"
57 #include "ED_node.h"
58 #include "ED_object.h"
59 #include "ED_physics.h"
60 #include "ED_render.h"
61 #include "ED_screen.h"
62 #include "ED_sculpt.h"
63 #include "ED_space_api.h"
64 #include "ED_sound.h"
65 #include "ED_uvedit.h"
66 #include "ED_mball.h"
67 #include "ED_logic.h"
68
69 /* only call once on startup, storage is global in BKE kernel listbase */
70 void ED_spacetypes_init(void)
71 {
72         const ListBase *spacetypes;
73         SpaceType *type;
74
75         /* create space types */
76         ED_spacetype_outliner();
77         ED_spacetype_time();
78         ED_spacetype_view3d();
79         ED_spacetype_ipo();
80         ED_spacetype_image();
81         ED_spacetype_node();
82         ED_spacetype_buttons();
83         ED_spacetype_info();
84         ED_spacetype_file();
85         ED_spacetype_sound();
86         ED_spacetype_action();
87         ED_spacetype_nla();
88         ED_spacetype_script();
89         ED_spacetype_text();
90         ED_spacetype_sequencer();
91         ED_spacetype_logic();
92         ED_spacetype_console();
93         ED_spacetype_userpref();
94 //      ...
95         
96         /* register operator types for screen and all spaces */
97         ED_operatortypes_screen();
98         ED_operatortypes_anim();
99         ED_operatortypes_animchannels();
100         ED_operatortypes_gpencil();
101         ED_operatortypes_object();
102         ED_operatortypes_mesh();
103         ED_operatortypes_sculpt();
104         ED_operatortypes_uvedit();
105         ED_operatortypes_paint();
106         ED_operatortypes_physics();
107         ED_operatortypes_curve();
108         ED_operatortypes_armature();
109         ED_operatortypes_marker();
110         ED_operatortypes_metaball();
111         ED_operatortypes_sound();
112         ED_operatortypes_render();
113         ED_operatortypes_logic();
114         
115         UI_view2d_operatortypes();
116         UI_buttons_operatortypes();
117         
118         /* register operators */
119         spacetypes = BKE_spacetypes_list();
120         for(type=spacetypes->first; type; type=type->next) {
121                 if(type->operatortypes)
122                         type->operatortypes();
123         }
124
125         /* Macros's must go last since they reference other operators
126          * maybe we'll need to have them go after python operators too? */
127         ED_operatormacros_armature();
128         ED_operatormacros_mesh();
129         ED_operatormacros_node();
130         ED_operatormacros_object();
131         ED_operatormacros_file();
132         ED_operatormacros_graph();
133         ED_operatormacros_action();
134         
135         /* register dropboxes (can use macros) */
136         spacetypes = BKE_spacetypes_list();
137         for(type=spacetypes->first; type; type=type->next) {
138                 if(type->dropboxes)
139                         type->dropboxes();
140         }
141         
142 }
143
144 /* called in wm.c */
145 /* keymap definitions are registered only once per WM initialize, usually on file read,
146    using the keymap the actual areas/regions add the handlers */
147 void ED_spacetypes_keymap(wmKeyConfig *keyconf)
148 {
149         const ListBase *spacetypes;
150         SpaceType *stype;
151         ARegionType *atype;
152
153         ED_keymap_screen(keyconf);
154         ED_keymap_anim(keyconf);
155         ED_keymap_animchannels(keyconf);
156         ED_keymap_gpencil(keyconf);
157         ED_keymap_object(keyconf); /* defines lattice also */
158         ED_keymap_mesh(keyconf);
159         ED_keymap_uvedit(keyconf);
160         ED_keymap_curve(keyconf);
161         ED_keymap_armature(keyconf);
162         ED_keymap_physics(keyconf);
163         ED_keymap_metaball(keyconf);
164         ED_keymap_paint(keyconf);
165         ED_marker_keymap(keyconf);
166
167         UI_view2d_keymap(keyconf);
168
169         spacetypes = BKE_spacetypes_list();
170         for(stype=spacetypes->first; stype; stype=stype->next) {
171                 if(stype->keymap)
172                         stype->keymap(keyconf);
173                 for(atype=stype->regiontypes.first; atype; atype=atype->next) {
174                         if(atype->keymap)
175                                 atype->keymap(keyconf);
176                 }
177         }
178 }
179
180 /* ********************** custom drawcall api ***************** */
181
182 typedef struct RegionDrawCB {
183         struct RegionDrawCB *next, *prev;
184         
185         void (*draw)(const struct bContext *, struct ARegion *, void *);        
186         void *customdata;
187         
188         int type;
189         
190 } RegionDrawCB;
191
192 void *ED_region_draw_cb_activate(ARegionType *art, 
193                                                                  void   (*draw)(const struct bContext *, struct ARegion *, void *),
194                                                                  void *customdata, int type)
195 {
196         RegionDrawCB *rdc= MEM_callocN(sizeof(RegionDrawCB), "RegionDrawCB");
197         
198         BLI_addtail(&art->drawcalls, rdc);
199         rdc->draw= draw;
200         rdc->customdata= customdata;
201         rdc->type= type;
202         
203         return rdc;
204 }
205
206 void ED_region_draw_cb_exit(ARegionType *art, void *handle)
207 {
208         RegionDrawCB *rdc;
209         
210         for(rdc= art->drawcalls.first; rdc; rdc= rdc->next) {
211                 if(rdc==(RegionDrawCB *)handle) {
212                         BLI_remlink(&art->drawcalls, rdc);
213                         MEM_freeN(rdc);
214                         return;
215                 }
216         }
217 }
218
219 void *ED_region_draw_cb_customdata(void *handle)
220 {
221         return ((RegionDrawCB *)handle)->customdata;
222 }
223
224 void ED_region_draw_cb_draw(const bContext *C, ARegion *ar, int type)
225 {
226         RegionDrawCB *rdc;
227         
228         for(rdc= ar->type->drawcalls.first; rdc; rdc= rdc->next) {
229                 if(rdc->type==type)
230                         rdc->draw(C, ar, rdc->customdata);
231         }               
232 }
233
234
235
236 /* ********************* space template *********************** */
237 /* forward declare */
238 void ED_spacetype_xxx(void);
239
240 /* allocate and init some vars */
241 static SpaceLink *xxx_new(const bContext *UNUSED(C))
242 {
243         return NULL;
244 }
245
246 /* not spacelink itself */
247 static void xxx_free(SpaceLink *UNUSED(sl))
248 {
249
250 }
251
252 /* spacetype; init callback for usage, should be redoable */
253 static void xxx_init(wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
254 {
255         
256         /* link area to SpaceXXX struct */
257         
258         /* define how many regions, the order and types */
259         
260         /* add types to regions */
261 }
262
263 static SpaceLink *xxx_duplicate(SpaceLink *UNUSED(sl))
264 {
265         
266         return NULL;
267 }
268
269 static void xxx_operatortypes(void)
270 {
271         /* register operator types for this space */
272 }
273
274 static void xxx_keymap(wmKeyConfig *UNUSED(keyconf))
275 {
276         /* add default items to keymap */
277 }
278
279 /* only called once, from screen/spacetypes.c */
280 void ED_spacetype_xxx(void)
281 {
282         static SpaceType st;
283         
284         st.spaceid= SPACE_VIEW3D;
285         
286         st.new= xxx_new;
287         st.free= xxx_free;
288         st.init= xxx_init;
289         st.duplicate= xxx_duplicate;
290         st.operatortypes= xxx_operatortypes;
291         st.keymap= xxx_keymap;
292         
293         BKE_spacetype_register(&st);
294 }
295
296 /* ****************************** end template *********************** */
297
298
299
300