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