4 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
20 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
21 * All rights reserved.
23 * The Original Code is: all of this file.
25 * Contributor(s): none yet.
27 * ***** END GPL LICENSE BLOCK *****
34 #include "MEM_guardedalloc.h"
36 #include "DNA_screen_types.h"
37 #include "DNA_space_types.h"
39 #include "BLI_blenlib.h"
41 #include "BKE_screen.h"
43 #ifndef DISABLE_PYTHON
44 #include "BPY_extern.h"
47 /* ************ Spacetype/regiontype handling ************** */
49 /* keep global; this has to be accessible outside of windowmanager */
50 static ListBase spacetypes= {NULL, NULL};
52 /* not SpaceType itself */
53 static void spacetype_free(SpaceType *st)
60 for(art= st->regiontypes.first; art; art= art->next) {
61 BLI_freelistN(&art->drawcalls);
63 for(pt= art->paneltypes.first; pt; pt= pt->next)
65 pt->ext.free(pt->ext.data);
67 for(ht= art->headertypes.first; ht; ht= ht->next)
69 ht->ext.free(ht->ext.data);
71 for(mt= art->menutypes.first; mt; mt= mt->next)
73 mt->ext.free(mt->ext.data);
75 BLI_freelistN(&art->paneltypes);
76 BLI_freelistN(&art->headertypes);
77 BLI_freelistN(&art->menutypes);
80 BLI_freelistN(&st->regiontypes);
81 BLI_freelistN(&st->toolshelf);
85 void BKE_spacetypes_free(void)
89 for(st= spacetypes.first; st; st= st->next) {
93 BLI_freelistN(&spacetypes);
96 SpaceType *BKE_spacetype_from_id(int spaceid)
100 for(st= spacetypes.first; st; st= st->next) {
101 if(st->spaceid==spaceid)
107 ARegionType *BKE_regiontype_from_id(SpaceType *st, int regionid)
111 for(art= st->regiontypes.first; art; art= art->next)
112 if(art->regionid==regionid)
115 printf("Error, region type missing in - name:\"%s\", id:%d\n", st->name, st->spaceid);
116 return st->regiontypes.first;
120 const ListBase *BKE_spacetypes_list()
125 void BKE_spacetype_register(SpaceType *st)
130 stype= BKE_spacetype_from_id(st->spaceid);
132 printf("error: redefinition of spacetype %s\n", stype->name);
133 spacetype_free(stype);
137 BLI_addtail(&spacetypes, st);
140 /* ***************** Space handling ********************** */
142 void BKE_spacedata_freelist(ListBase *lb)
147 for (sl= lb->first; sl; sl= sl->next) {
148 SpaceType *st= BKE_spacetype_from_id(sl->spacetype);
150 /* free regions for pushed spaces */
151 for(ar=sl->regionbase.first; ar; ar=ar->next)
152 BKE_area_region_free(st, ar);
154 BLI_freelistN(&sl->regionbase);
163 ARegion *BKE_area_region_copy(SpaceType *st, ARegion *ar)
165 ARegion *newar= MEM_dupallocN(ar);
166 Panel *pa, *newpa, *patab;
168 newar->prev= newar->next= NULL;
169 newar->handlers.first= newar->handlers.last= NULL;
170 newar->uiblocks.first= newar->uiblocks.last= NULL;
173 /* use optional regiondata callback */
175 ARegionType *art= BKE_regiontype_from_id(st, ar->regiontype);
177 if(art && art->duplicate)
178 newar->regiondata= art->duplicate(ar->regiondata);
180 newar->regiondata= MEM_dupallocN(ar->regiondata);
183 if(ar->v2d.tab_offset)
184 newar->v2d.tab_offset= MEM_dupallocN(ar->v2d.tab_offset);
186 newar->panels.first= newar->panels.last= NULL;
187 BLI_duplicatelist(&newar->panels, &ar->panels);
189 /* copy panel pointers */
190 for(newpa= newar->panels.first; newpa; newpa= newpa->next) {
191 patab= newar->panels.first;
192 pa= ar->panels.first;
194 if(newpa->paneltab == pa) {
195 newpa->paneltab = patab;
207 /* from lb2 to lb1, lb1 is supposed to be free'd */
208 static void region_copylist(SpaceType *st, ListBase *lb1, ListBase *lb2)
213 lb1->first= lb1->last= NULL;
215 for(ar= lb2->first; ar; ar= ar->next) {
216 ARegion *arnew= BKE_area_region_copy(st, ar);
217 BLI_addtail(lb1, arnew);
222 /* lb1 should be empty */
223 void BKE_spacedata_copylist(ListBase *lb1, ListBase *lb2)
227 lb1->first= lb1->last= NULL; /* to be sure */
229 for (sl= lb2->first; sl; sl= sl->next) {
230 SpaceType *st= BKE_spacetype_from_id(sl->spacetype);
232 if(st && st->duplicate) {
233 SpaceLink *slnew= st->duplicate(sl);
235 BLI_addtail(lb1, slnew);
237 region_copylist(st, &slnew->regionbase, &sl->regionbase);
242 /* lb1 should be empty */
243 void BKE_spacedata_copyfirst(ListBase *lb1, ListBase *lb2)
247 lb1->first= lb1->last= NULL; /* to be sure */
251 SpaceType *st= BKE_spacetype_from_id(sl->spacetype);
253 if(st && st->duplicate) {
254 SpaceLink *slnew= st->duplicate(sl);
256 BLI_addtail(lb1, slnew);
258 region_copylist(st, &slnew->regionbase, &sl->regionbase);
263 /* not region itself */
264 void BKE_area_region_free(SpaceType *st, ARegion *ar)
267 ARegionType *art= BKE_regiontype_from_id(st, ar->regiontype);
273 printf("regiondata free error\n");
275 else if(ar->type && ar->type->free)
278 if(ar->v2d.tab_offset) {
279 MEM_freeN(ar->v2d.tab_offset);
280 ar->v2d.tab_offset= NULL;
284 BLI_freelistN(&ar->panels);
287 /* not area itself */
288 void BKE_screen_area_free(ScrArea *sa)
290 SpaceType *st= BKE_spacetype_from_id(sa->spacetype);
293 for(ar=sa->regionbase.first; ar; ar=ar->next)
294 BKE_area_region_free(st, ar);
296 BLI_freelistN(&sa->regionbase);
298 BKE_spacedata_freelist(&sa->spacedata);
300 BLI_freelistN(&sa->actionzones);
303 /* don't free screen itself */
304 void free_screen(bScreen *sc)
309 for(ar=sc->regionbase.first; ar; ar=ar->next)
310 BKE_area_region_free(NULL, ar);
312 BLI_freelistN(&sc->regionbase);
314 for(sa= sc->areabase.first; sa; sa= san) {
316 BKE_screen_area_free(sa);
319 BLI_freelistN(&sc->vertbase);
320 BLI_freelistN(&sc->edgebase);
321 BLI_freelistN(&sc->areabase);