Bugfix #26317
[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         
132         /* register dropboxes (can use macros) */
133         spacetypes = BKE_spacetypes_list();
134         for(type=spacetypes->first; type; type=type->next) {
135                 if(type->dropboxes)
136                         type->dropboxes();
137         }
138         
139 }
140
141 /* called in wm.c */
142 /* keymap definitions are registered only once per WM initialize, usually on file read,
143    using the keymap the actual areas/regions add the handlers */
144 void ED_spacetypes_keymap(wmKeyConfig *keyconf)
145 {
146         const ListBase *spacetypes;
147         SpaceType *stype;
148         ARegionType *atype;
149
150         ED_keymap_screen(keyconf);
151         ED_keymap_anim(keyconf);
152         ED_keymap_animchannels(keyconf);
153         ED_keymap_gpencil(keyconf);
154         ED_keymap_object(keyconf); /* defines lattice also */
155         ED_keymap_mesh(keyconf);
156         ED_keymap_uvedit(keyconf);
157         ED_keymap_curve(keyconf);
158         ED_keymap_armature(keyconf);
159         ED_keymap_physics(keyconf);
160         ED_keymap_metaball(keyconf);
161         ED_keymap_paint(keyconf);
162         ED_marker_keymap(keyconf);
163
164         UI_view2d_keymap(keyconf);
165
166         spacetypes = BKE_spacetypes_list();
167         for(stype=spacetypes->first; stype; stype=stype->next) {
168                 if(stype->keymap)
169                         stype->keymap(keyconf);
170                 for(atype=stype->regiontypes.first; atype; atype=atype->next) {
171                         if(atype->keymap)
172                                 atype->keymap(keyconf);
173                 }
174         }
175 }
176
177 /* ********************** custom drawcall api ***************** */
178
179 typedef struct RegionDrawCB {
180         struct RegionDrawCB *next, *prev;
181         
182         void (*draw)(const struct bContext *, struct ARegion *, void *);        
183         void *customdata;
184         
185         int type;
186         
187 } RegionDrawCB;
188
189 void *ED_region_draw_cb_activate(ARegionType *art, 
190                                                                  void   (*draw)(const struct bContext *, struct ARegion *, void *),
191                                                                  void *customdata, int type)
192 {
193         RegionDrawCB *rdc= MEM_callocN(sizeof(RegionDrawCB), "RegionDrawCB");
194         
195         BLI_addtail(&art->drawcalls, rdc);
196         rdc->draw= draw;
197         rdc->customdata= customdata;
198         rdc->type= type;
199         
200         return rdc;
201 }
202
203 void ED_region_draw_cb_exit(ARegionType *art, void *handle)
204 {
205         RegionDrawCB *rdc;
206         
207         for(rdc= art->drawcalls.first; rdc; rdc= rdc->next) {
208                 if(rdc==(RegionDrawCB *)handle) {
209                         BLI_remlink(&art->drawcalls, rdc);
210                         MEM_freeN(rdc);
211                         return;
212                 }
213         }
214 }
215
216 void *ED_region_draw_cb_customdata(void *handle)
217 {
218         return ((RegionDrawCB *)handle)->customdata;
219 }
220
221 void ED_region_draw_cb_draw(const bContext *C, ARegion *ar, int type)
222 {
223         RegionDrawCB *rdc;
224         
225         for(rdc= ar->type->drawcalls.first; rdc; rdc= rdc->next) {
226                 if(rdc->type==type)
227                         rdc->draw(C, ar, rdc->customdata);
228         }               
229 }
230
231
232
233 /* ********************* space template *********************** */
234 /* forward declare */
235 void ED_spacetype_xxx(void);
236
237 /* allocate and init some vars */
238 static SpaceLink *xxx_new(const bContext *UNUSED(C))
239 {
240         return NULL;
241 }
242
243 /* not spacelink itself */
244 static void xxx_free(SpaceLink *UNUSED(sl))
245 {
246
247 }
248
249 /* spacetype; init callback for usage, should be redoable */
250 static void xxx_init(wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
251 {
252         
253         /* link area to SpaceXXX struct */
254         
255         /* define how many regions, the order and types */
256         
257         /* add types to regions */
258 }
259
260 static SpaceLink *xxx_duplicate(SpaceLink *UNUSED(sl))
261 {
262         
263         return NULL;
264 }
265
266 static void xxx_operatortypes(void)
267 {
268         /* register operator types for this space */
269 }
270
271 static void xxx_keymap(wmKeyConfig *UNUSED(keyconf))
272 {
273         /* add default items to keymap */
274 }
275
276 /* only called once, from screen/spacetypes.c */
277 void ED_spacetype_xxx(void)
278 {
279         static SpaceType st;
280         
281         st.spaceid= SPACE_VIEW3D;
282         
283         st.new= xxx_new;
284         st.free= xxx_free;
285         st.init= xxx_init;
286         st.duplicate= xxx_duplicate;
287         st.operatortypes= xxx_operatortypes;
288         st.keymap= xxx_keymap;
289         
290         BKE_spacetype_register(&st);
291 }
292
293 /* ****************************** end template *********************** */
294
295
296
297