* merge r22734 from trunk
[blender.git] / source / blender / editors / space_api / spacetypes.c
1 /**
2  * $Id: spacetypes.c
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  * The Original Code is Copyright (C) Blender Foundation, 2008
21  *
22  * ***** END GPL/BL DUAL LICENSE BLOCK *****
23  */
24
25 #include <stdlib.h>
26
27 #include "MEM_guardedalloc.h"
28 #include "BLI_blenlib.h"
29
30 #include "DNA_object_types.h"
31 #include "DNA_scene_types.h"
32 #include "DNA_windowmanager_types.h"
33
34 #include "BKE_context.h"
35 #include "BKE_screen.h"
36
37 #include "UI_interface.h"
38 #include "UI_view2d.h"
39
40 #include "BIF_gl.h"
41
42 #include "ED_anim_api.h"
43 #include "ED_armature.h"
44 #include "ED_curve.h"
45 #include "ED_markers.h"
46 #include "ED_mesh.h"
47 #include "ED_object.h"
48 #include "ED_particle.h"
49 #include "ED_physics.h"
50 #include "ED_screen.h"
51 #include "ED_sculpt.h"
52 #include "ED_space_api.h"
53 #include "ED_uvedit.h"
54 #include "ED_mball.h"
55
56 /* only call once on startup, storage is global in BKE kernel listbase */
57 void ED_spacetypes_init(void)
58 {
59         const ListBase *spacetypes;
60         SpaceType *type;
61
62         /* create space types */
63         ED_spacetype_outliner();
64         ED_spacetype_time();
65         ED_spacetype_view3d();
66         ED_spacetype_ipo();
67         ED_spacetype_image();
68         ED_spacetype_node();
69         ED_spacetype_buttons();
70         ED_spacetype_info();
71         ED_spacetype_file();
72         ED_spacetype_sound();
73         ED_spacetype_action();
74         ED_spacetype_nla();
75         ED_spacetype_script();
76         ED_spacetype_text();
77         ED_spacetype_sequencer();
78         ED_spacetype_logic();
79         ED_spacetype_console();
80         ED_spacetype_userpref();
81 //      ...
82         
83         /* register operator types for screen and all spaces */
84         ED_operatortypes_screen();
85         ED_operatortypes_anim();
86         ED_operatortypes_animchannels(); // XXX have this as part of anim() ones instead?
87         ED_operatortypes_object();
88         ED_operatortypes_mesh();
89         ED_operatortypes_sculpt();
90         ED_operatortypes_uvedit();
91         ED_operatortypes_paint();
92         ED_operatortypes_particle();
93         ED_operatortypes_curve();
94         ED_operatortypes_armature();
95         ED_operatortypes_marker();
96         ED_operatortypes_pointcache();
97         ED_operatortypes_fluid();
98         ED_operatortypes_metaball();
99         ED_operatortypes_boids();
100         
101         ui_view2d_operatortypes();
102         
103         spacetypes = BKE_spacetypes_list();
104         for(type=spacetypes->first; type; type=type->next)
105                 type->operatortypes();
106 }
107
108 /* called in wm.c */
109 /* keymap definitions are registered only once per WM initialize, usually on file read,
110    using the keymap the actual areas/regions add the handlers */
111 void ED_spacetypes_keymap(wmWindowManager *wm)
112 {
113         const ListBase *spacetypes;
114         SpaceType *stype;
115         ARegionType *atype;
116
117         ED_keymap_screen(wm);
118         ED_keymap_anim(wm);
119         ED_keymap_animchannels(wm);
120         ED_keymap_object(wm);
121         ED_keymap_mesh(wm);
122         ED_keymap_uvedit(wm);
123         ED_keymap_curve(wm);
124         ED_keymap_armature(wm);
125         ED_keymap_particle(wm);
126         ED_keymap_metaball(wm);
127         ED_marker_keymap(wm);
128
129         UI_view2d_keymap(wm);
130
131         spacetypes = BKE_spacetypes_list();
132         for(stype=spacetypes->first; stype; stype=stype->next) {
133                 if(stype->keymap)
134                         stype->keymap(wm);
135                 for(atype=stype->regiontypes.first; atype; atype=atype->next) {
136                         if(atype->keymap)
137                                 atype->keymap(wm);
138                 }
139         }
140 }
141
142 /* ********************** custom drawcall api ***************** */
143
144 /* type */
145 #define REGION_DRAW_PRE         1
146 #define REGION_DRAW_POST        0
147
148 typedef struct RegionDrawCB {
149         struct RegionDrawCB *next, *prev;
150         
151         void (*draw)(const struct bContext *, struct ARegion *, void *);        
152         void *customdata;
153         
154         int type;
155         
156 } RegionDrawCB;
157
158 void *ED_region_draw_cb_activate(ARegionType *art, 
159                                                                  void   (*draw)(const struct bContext *, struct ARegion *, void *),
160                                                                  void *customdata, int type)
161 {
162         RegionDrawCB *rdc= MEM_callocN(sizeof(RegionDrawCB), "RegionDrawCB");
163         
164         BLI_addtail(&art->drawcalls, rdc);
165         rdc->draw= draw;
166         rdc->customdata= customdata;
167         rdc->type= type;
168         
169         return rdc;
170 }
171
172 void ED_region_draw_cb_exit(ARegionType *art, void *handle)
173 {
174         RegionDrawCB *rdc;
175         
176         for(rdc= art->drawcalls.first; rdc; rdc= rdc->next) {
177                 if(rdc==(RegionDrawCB *)handle) {
178                         BLI_remlink(&art->drawcalls, rdc);
179                         MEM_freeN(rdc);
180                         return;
181                 }
182         }
183 }
184
185 void ED_region_draw_cb_draw(const bContext *C, ARegion *ar, int type)
186 {
187         RegionDrawCB *rdc;
188         
189         for(rdc= ar->type->drawcalls.first; rdc; rdc= rdc->next) {
190                 if(rdc->type==type)
191                         rdc->draw(C, ar, rdc->customdata);
192         }               
193 }
194
195
196
197 /* ********************* space template *********************** */
198
199 /* allocate and init some vars */
200 static SpaceLink *xxx_new(const bContext *C)
201 {
202         return NULL;
203 }
204
205 /* not spacelink itself */
206 static void xxx_free(SpaceLink *sl)
207 {
208
209 }
210
211 /* spacetype; init callback for usage, should be redoable */
212 static void xxx_init(wmWindowManager *wm, ScrArea *sa)
213 {
214         
215         /* link area to SpaceXXX struct */
216         
217         /* define how many regions, the order and types */
218         
219         /* add types to regions */
220 }
221
222 static SpaceLink *xxx_duplicate(SpaceLink *sl)
223 {
224         
225         return NULL;
226 }
227
228 static void xxx_operatortypes(void)
229 {
230         /* register operator types for this space */
231 }
232
233 static void xxx_keymap(wmWindowManager *wm)
234 {
235         /* add default items to keymap */
236 }
237
238 /* only called once, from screen/spacetypes.c */
239 void ED_spacetype_xxx(void)
240 {
241         static SpaceType st;
242         
243         st.spaceid= SPACE_VIEW3D;
244         
245         st.new= xxx_new;
246         st.free= xxx_free;
247         st.init= xxx_init;
248         st.duplicate= xxx_duplicate;
249         st.operatortypes= xxx_operatortypes;
250         st.keymap= xxx_keymap;
251         
252         BKE_spacetype_register(&st);
253 }
254
255 /* ****************************** end template *********************** */
256
257
258
259