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