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