Cleanup: manually remove header text not handled by automation
[blender.git] / source / blender / editors / space_api / spacetypes.c
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) Blender Foundation, 2008
17  */
18
19 /** \file blender/editors/space_api/spacetypes.c
20  *  \ingroup spapi
21  */
22
23
24 #include <stdlib.h>
25
26 #include "MEM_guardedalloc.h"
27
28 #include "BLI_blenlib.h"
29 #include "BLI_utildefines.h"
30
31 #include "DNA_scene_types.h"
32 #include "DNA_windowmanager_types.h"
33
34
35 #include "BKE_context.h"
36 #include "BKE_screen.h"
37
38 #include "UI_interface.h"
39 #include "UI_view2d.h"
40
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_paint.h"
52 #include "ED_physics.h"
53 #include "ED_render.h"
54 #include "ED_scene.h"
55 #include "ED_screen.h"
56 #include "ED_sculpt.h"
57 #include "ED_space_api.h"
58 #include "ED_sound.h"
59 #include "ED_uvedit.h"
60 #include "ED_lattice.h"
61 #include "ED_mball.h"
62 #include "ED_logic.h"
63 #include "ED_clip.h"
64 #include "ED_mask.h"
65 #include "ED_sequencer.h"
66 #include "ED_gizmo_library.h"
67 #include "ED_transform.h"
68
69 #include "io_ops.h"
70
71 /* only call once on startup, storage is global in BKE kernel listbase */
72 void ED_spacetypes_init(void)
73 {
74         const ListBase *spacetypes;
75         SpaceType *type;
76
77         /* UI_UNIT_X is now a variable, is used in some spacetype inits? */
78         U.widget_unit = 20;
79
80         /* create space types */
81         ED_spacetype_outliner();
82         ED_spacetype_view3d();
83         ED_spacetype_ipo();
84         ED_spacetype_image();
85         ED_spacetype_node();
86         ED_spacetype_buttons();
87         ED_spacetype_info();
88         ED_spacetype_file();
89         ED_spacetype_action();
90         ED_spacetype_nla();
91         ED_spacetype_script();
92         ED_spacetype_text();
93         ED_spacetype_sequencer();
94         ED_spacetype_console();
95         ED_spacetype_userpref();
96         ED_spacetype_clip();
97         ED_spacetype_statusbar();
98         ED_spacetype_topbar();
99 //      ...
100
101         /* register operator types for screen and all spaces */
102         ED_operatortypes_workspace();
103         ED_operatortypes_scene();
104         ED_operatortypes_screen();
105         ED_operatortypes_anim();
106         ED_operatortypes_animchannels();
107         ED_operatortypes_gpencil();
108         ED_operatortypes_object();
109         ED_operatortypes_lattice();
110         ED_operatortypes_mesh();
111         ED_operatortypes_sculpt();
112         ED_operatortypes_uvedit();
113         ED_operatortypes_paint();
114         ED_operatortypes_physics();
115         ED_operatortypes_curve();
116         ED_operatortypes_armature();
117         ED_operatortypes_marker();
118         ED_operatortypes_metaball();
119         ED_operatortypes_sound();
120         ED_operatortypes_render();
121         ED_operatortypes_mask();
122         ED_operatortypes_io();
123
124         ED_operatortypes_view2d();
125         ED_operatortypes_ui();
126
127         ED_screen_user_menu_register();
128
129         /* gizmo types */
130         ED_gizmotypes_button_2d();
131         ED_gizmotypes_dial_3d();
132         ED_gizmotypes_move_3d();
133         ED_gizmotypes_arrow_2d();
134         ED_gizmotypes_arrow_3d();
135         ED_gizmotypes_preselect_3d();
136         ED_gizmotypes_primitive_3d();
137         ED_gizmotypes_blank_3d();
138         ED_gizmotypes_cage_2d();
139         ED_gizmotypes_cage_3d();
140         ED_gizmotypes_value_2d();
141
142         /* gizmo group types */
143         ED_gizmogrouptypes_value_2d();
144
145         /* register types for operators and gizmos */
146         spacetypes = BKE_spacetypes_list();
147         for (type = spacetypes->first; type; type = type->next) {
148                 /* init gizmo types first, operator-types need them */
149                 if (type->gizmos) {
150                         type->gizmos();
151                 }
152                 if (type->operatortypes) {
153                         type->operatortypes();
154                 }
155         }
156 }
157
158 void ED_spacemacros_init(void)
159 {
160         const ListBase *spacetypes;
161         SpaceType *type;
162
163         /* Macros's must go last since they reference other operators.
164          * We need to have them go after python operators too */
165         ED_operatormacros_armature();
166         ED_operatormacros_mesh();
167         ED_operatormacros_metaball();
168         ED_operatormacros_node();
169         ED_operatormacros_object();
170         ED_operatormacros_file();
171         ED_operatormacros_graph();
172         ED_operatormacros_action();
173         ED_operatormacros_clip();
174         ED_operatormacros_curve();
175         ED_operatormacros_mask();
176         ED_operatormacros_sequencer();
177         ED_operatormacros_paint();
178         ED_operatormacros_gpencil();
179
180         /* register dropboxes (can use macros) */
181         spacetypes = BKE_spacetypes_list();
182         for (type = spacetypes->first; type; type = type->next) {
183                 if (type->dropboxes)
184                         type->dropboxes();
185         }
186 }
187
188 /* called in wm.c */
189 /* keymap definitions are registered only once per WM initialize, usually on file read,
190  * using the keymap the actual areas/regions add the handlers */
191 void ED_spacetypes_keymap(wmKeyConfig *keyconf)
192 {
193         const ListBase *spacetypes;
194         SpaceType *stype;
195         ARegionType *atype;
196
197         ED_keymap_screen(keyconf);
198         ED_keymap_anim(keyconf);
199         ED_keymap_animchannels(keyconf);
200         ED_keymap_gpencil(keyconf);
201         ED_keymap_object(keyconf);
202         ED_keymap_lattice(keyconf);
203         ED_keymap_mesh(keyconf);
204         ED_keymap_uvedit(keyconf);
205         ED_keymap_curve(keyconf);
206         ED_keymap_armature(keyconf);
207         ED_keymap_physics(keyconf);
208         ED_keymap_metaball(keyconf);
209         ED_keymap_paint(keyconf);
210         ED_keymap_mask(keyconf);
211         ED_keymap_marker(keyconf);
212
213         ED_keymap_view2d(keyconf);
214         ED_keymap_ui(keyconf);
215
216         ED_keymap_transform(keyconf);
217
218         spacetypes = BKE_spacetypes_list();
219         for (stype = spacetypes->first; stype; stype = stype->next) {
220                 if (stype->keymap)
221                         stype->keymap(keyconf);
222                 for (atype = stype->regiontypes.first; atype; atype = atype->next) {
223                         if (atype->keymap)
224                                 atype->keymap(keyconf);
225                 }
226         }
227 }
228
229 /* ********************** custom drawcall api ***************** */
230
231 typedef struct RegionDrawCB {
232         struct RegionDrawCB *next, *prev;
233
234         void (*draw)(const struct bContext *, struct ARegion *, void *);
235         void *customdata;
236
237         int type;
238
239 } RegionDrawCB;
240
241 void *ED_region_draw_cb_activate(ARegionType *art,
242                                  void (*draw)(const struct bContext *, struct ARegion *, void *),
243                                  void *customdata, int type)
244 {
245         RegionDrawCB *rdc = MEM_callocN(sizeof(RegionDrawCB), "RegionDrawCB");
246
247         BLI_addtail(&art->drawcalls, rdc);
248         rdc->draw = draw;
249         rdc->customdata = customdata;
250         rdc->type = type;
251
252         return rdc;
253 }
254
255 void ED_region_draw_cb_exit(ARegionType *art, void *handle)
256 {
257         RegionDrawCB *rdc;
258
259         for (rdc = art->drawcalls.first; rdc; rdc = rdc->next) {
260                 if (rdc == (RegionDrawCB *)handle) {
261                         BLI_remlink(&art->drawcalls, rdc);
262                         MEM_freeN(rdc);
263                         return;
264                 }
265         }
266 }
267
268 void ED_region_draw_cb_draw(const bContext *C, ARegion *ar, int type)
269 {
270         RegionDrawCB *rdc;
271
272         for (rdc = ar->type->drawcalls.first; rdc; rdc = rdc->next) {
273                 if (rdc->type == type) {
274                         rdc->draw(C, ar, rdc->customdata);
275                 }
276         }
277 }
278
279
280
281 /* ********************* space template *********************** */
282 /* forward declare */
283 void ED_spacetype_xxx(void);
284
285 /* allocate and init some vars */
286 static SpaceLink *xxx_new(const ScrArea *UNUSED(sa), const Scene *UNUSED(scene))
287 {
288         return NULL;
289 }
290
291 /* not spacelink itself */
292 static void xxx_free(SpaceLink *UNUSED(sl))
293 {
294
295 }
296
297 /* spacetype; init callback for usage, should be redoable */
298 static void xxx_init(wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
299 {
300
301         /* link area to SpaceXXX struct */
302
303         /* define how many regions, the order and types */
304
305         /* add types to regions */
306 }
307
308 static SpaceLink *xxx_duplicate(SpaceLink *UNUSED(sl))
309 {
310
311         return NULL;
312 }
313
314 static void xxx_operatortypes(void)
315 {
316         /* register operator types for this space */
317 }
318
319 static void xxx_keymap(wmKeyConfig *UNUSED(keyconf))
320 {
321         /* add default items to keymap */
322 }
323
324 /* only called once, from screen/spacetypes.c */
325 void ED_spacetype_xxx(void)
326 {
327         static SpaceType st;
328
329         st.spaceid = SPACE_VIEW3D;
330
331         st.new = xxx_new;
332         st.free = xxx_free;
333         st.init = xxx_init;
334         st.duplicate = xxx_duplicate;
335         st.operatortypes = xxx_operatortypes;
336         st.keymap = xxx_keymap;
337
338         BKE_spacetype_register(&st);
339 }
340
341 /* ****************************** end template *********************** */