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_screen.h"
43 #include "ED_object.h"
44 #include "ED_mesh.h"
45 #include "ED_space_api.h"
46 #include "ED_anim_api.h"
47
48
49 ARegionType *ED_regiontype_from_id(SpaceType *st, int regionid)
50 {
51         ARegionType *art;
52         
53         for(art= st->regiontypes.first; art; art= art->next)
54                 if(art->regionid==regionid)
55                         return art;
56         
57         printf("Error, region type missing in %s\n", st->name);
58         return st->regiontypes.first;
59 }
60
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 //      ...
85         
86         /* register operator types for screen and all spaces */
87         ED_operatortypes_screen();
88         ED_operatortypes_anim();
89         ED_operatortypes_animchannels(); // XXX have this as part of anim() ones instead?
90         ED_operatortypes_object();
91         ED_operatortypes_mesh();
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         UI_view2d_keymap(wm);
114
115         spacetypes = BKE_spacetypes_list();
116         for(stype=spacetypes->first; stype; stype=stype->next) {
117                 if(stype->keymap)
118                         stype->keymap(wm);
119                 for(atype=stype->regiontypes.first; atype; atype=atype->next) {
120                         if(atype->keymap)
121                                 atype->keymap(wm);
122                 }
123         }
124 }
125
126 /* ****************************** space template *********************** */
127
128 /* allocate and init some vars */
129 static SpaceLink *xxx_new(const bContext *C)
130 {
131         return NULL;
132 }
133
134 /* not spacelink itself */
135 static void xxx_free(SpaceLink *sl)
136 {
137
138 }
139
140 /* spacetype; init callback for usage, should be redoable */
141 static void xxx_init(wmWindowManager *wm, ScrArea *sa)
142 {
143         
144         /* link area to SpaceXXX struct */
145         
146         /* define how many regions, the order and types */
147         
148         /* add types to regions */
149 }
150
151 static SpaceLink *xxx_duplicate(SpaceLink *sl)
152 {
153         
154         return NULL;
155 }
156
157 static void xxx_operatortypes(void)
158 {
159         /* register operator types for this space */
160 }
161
162 static void xxx_keymap(wmWindowManager *wm)
163 {
164         /* add default items to keymap */
165 }
166
167 /* only called once, from screen/spacetypes.c */
168 void ED_spacetype_xxx(void)
169 {
170         static SpaceType st;
171         
172         st.spaceid= SPACE_VIEW3D;
173         
174         st.new= xxx_new;
175         st.free= xxx_free;
176         st.init= xxx_init;
177         st.duplicate= xxx_duplicate;
178         st.operatortypes= xxx_operatortypes;
179         st.keymap= xxx_keymap;
180         
181         BKE_spacetype_register(&st);
182 }
183
184 /* ****************************** end template *********************** */
185
186
187
188