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