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