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