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