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_windowmanager_types.h"
31
32 #include "BKE_context.h"
33 #include "BKE_screen.h"
34
35 #include "UI_interface.h"
36 #include "UI_view2d.h"
37
38 #include "BIF_gl.h"
39
40 #include "ED_screen.h"
41 #include "ED_object.h"
42 #include "ED_space_api.h"
43 #include "ED_anim_api.h"
44
45
46 ARegionType *ED_regiontype_from_id(SpaceType *st, int regionid)
47 {
48         ARegionType *art;
49         
50         for(art= st->regiontypes.first; art; art= art->next)
51                 if(art->regionid==regionid)
52                         return art;
53         
54         printf("Error, region type missing in %s\n", st->name);
55         return st->regiontypes.first;
56 }
57
58
59 /* only call once on startup, storage is global in BKE kernel listbase */
60 void ED_spacetypes_init(void)
61 {
62         const ListBase *spacetypes;
63         SpaceType *type;
64
65         /* create space types */
66         ED_spacetype_outliner();
67         ED_spacetype_time();
68         ED_spacetype_view3d();
69         ED_spacetype_ipo();
70         ED_spacetype_image();
71         ED_spacetype_node();
72         ED_spacetype_buttons();
73         ED_spacetype_info();
74         ED_spacetype_file();
75         ED_spacetype_sound();
76         ED_spacetype_action();
77         ED_spacetype_nla();
78         ED_spacetype_script();
79         ED_spacetype_text();
80         ED_spacetype_sequencer();
81 //      ...
82         
83         /* register operator types for screen and all spaces */
84         ED_operatortypes_screen();
85         ED_operatortypes_anim();
86         ED_operatortypes_animchannels(); // XXX have this as part of anim() ones instead?
87         ED_operatortypes_object();
88         ui_view2d_operatortypes();
89         
90         spacetypes = BKE_spacetypes_list();
91         for(type=spacetypes->first; type; type=type->next)
92                 type->operatortypes();
93 }
94
95 /* called in wm.c */
96 /* keymap definitions are registered only once per WM initialize, usually on file read,
97    using the keymap the actual areas/regions add the handlers */
98 void ED_spacetypes_keymap(wmWindowManager *wm)
99 {
100         const ListBase *spacetypes;
101         SpaceType *stype;
102         ARegionType *atype;
103
104         ED_keymap_screen(wm);
105         ED_keymap_anim(wm);
106         ED_keymap_animchannels(wm);
107         ED_keymap_object(wm);
108         UI_view2d_keymap(wm);
109
110         spacetypes = BKE_spacetypes_list();
111         for(stype=spacetypes->first; stype; stype=stype->next) {
112                 if(stype->keymap)
113                         stype->keymap(wm);
114                 for(atype=stype->regiontypes.first; atype; atype=atype->next) {
115                         if(atype->keymap)
116                                 atype->keymap(wm);
117                 }
118         }
119 }
120
121 /* ****************************** space template *********************** */
122
123 /* allocate and init some vars */
124 static SpaceLink *xxx_new(const bContext *C)
125 {
126         return NULL;
127 }
128
129 /* not spacelink itself */
130 static void xxx_free(SpaceLink *sl)
131 {
132
133 }
134
135 /* spacetype; init callback for usage, should be redoable */
136 static void xxx_init(wmWindowManager *wm, ScrArea *sa)
137 {
138         
139         /* link area to SpaceXXX struct */
140         
141         /* define how many regions, the order and types */
142         
143         /* add types to regions */
144 }
145
146 static SpaceLink *xxx_duplicate(SpaceLink *sl)
147 {
148         
149         return NULL;
150 }
151
152 static void xxx_operatortypes(void)
153 {
154         /* register operator types for this space */
155 }
156
157 static void xxx_keymap(wmWindowManager *wm)
158 {
159         /* add default items to keymap */
160 }
161
162 /* only called once, from screen/spacetypes.c */
163 void ED_spacetype_xxx(void)
164 {
165         static SpaceType st;
166         
167         st.spaceid= SPACE_VIEW3D;
168         
169         st.new= xxx_new;
170         st.free= xxx_free;
171         st.init= xxx_init;
172         st.duplicate= xxx_duplicate;
173         st.operatortypes= xxx_operatortypes;
174         st.keymap= xxx_keymap;
175         
176         BKE_spacetype_register(&st);
177 }
178
179 /* ****************************** end template *********************** */
180
181
182
183