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