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)
57 for(art= st->regiontypes.first; art; art= art->next)
58 BLI_freelistN(&art->drawcalls);
60 BLI_freelistN(&st->regiontypes);
63 void BKE_spacetypes_free(void)
67 for(st= spacetypes.first; st; st= st->next) {
71 BLI_freelistN(&spacetypes);
74 SpaceType *BKE_spacetype_from_id(int spaceid)
78 for(st= spacetypes.first; st; st= st->next) {
79 if(st->spaceid==spaceid)
85 const ListBase *BKE_spacetypes_list()
90 void BKE_spacetype_register(SpaceType *st)
95 stype= BKE_spacetype_from_id(st->spaceid);
97 printf("error: redefinition of spacetype %s\n", stype->name);
98 spacetype_free(stype);
102 BLI_addtail(&spacetypes, st);
105 /* ***************** Space handling ********************** */
107 void BKE_spacedata_freelist(ListBase *lb)
112 for (sl= lb->first; sl; sl= sl->next) {
113 SpaceType *st= BKE_spacetype_from_id(sl->spacetype);
115 /* free regions for pushed spaces */
116 for(ar=sl->regionbase.first; ar; ar=ar->next) {
117 BKE_area_region_free(ar);
119 BLI_freelistN(&sl->regionbase);
128 ARegion *BKE_area_region_copy(ARegion *ar)
130 ARegion *newar= MEM_dupallocN(ar);
131 Panel *pa, *newpa, *patab;
133 newar->handlers.first= newar->handlers.last= NULL;
134 newar->uiblocks.first= newar->uiblocks.last= NULL;
137 /* XXX regiondata callback */
139 newar->regiondata= MEM_dupallocN(ar->regiondata);
141 newar->panels.first= newar->panels.last= NULL;
142 BLI_duplicatelist(&newar->panels, &ar->panels);
144 /* copy panel pointers */
145 for(newpa= newar->panels.first; newpa; newpa= newpa->next) {
146 patab= newar->panels.first;
147 pa= ar->panels.first;
149 if(newpa->paneltab == pa) {
150 newpa->paneltab = patab;
162 /* from lb2 to lb1, lb1 is supposed to be free'd */
163 static void region_copylist(ListBase *lb1, ListBase *lb2)
168 lb1->first= lb1->last= NULL;
170 for(ar= lb2->first; ar; ar= ar->next) {
171 ARegion *arnew= BKE_area_region_copy(ar);
172 BLI_addtail(lb1, arnew);
177 /* lb1 should be empty */
178 void BKE_spacedata_copylist(ListBase *lb1, ListBase *lb2)
182 lb1->first= lb2->last= NULL; /* to be sure */
184 for (sl= lb2->first; sl; sl= sl->next) {
185 SpaceType *st= BKE_spacetype_from_id(sl->spacetype);
187 if(st && st->duplicate) {
188 SpaceLink *slnew= st->duplicate(sl);
190 BLI_addtail(lb1, slnew);
192 region_copylist(&slnew->regionbase, &sl->regionbase);
197 /* not region itself */
198 void BKE_area_region_free(ARegion *ar)
201 if(ar->type && ar->type->free)
204 BLI_freelistN(&ar->panels);
208 /* not area itself */
209 void BKE_screen_area_free(ScrArea *sa)
213 for(ar=sa->regionbase.first; ar; ar=arn) {
215 BKE_area_region_free(ar);
218 BKE_spacedata_freelist(&sa->spacedata);
220 BLI_freelistN(&sa->regionbase);
221 BLI_freelistN(&sa->actionzones);
223 #ifndef DISABLE_PYTHON
224 BPY_free_scriptlink(&sa->scriptlink);
228 /* don't free screen itself */
229 void free_screen(bScreen *sc)
234 for(ar=sc->regionbase.first; ar; ar=arn) {
236 BKE_area_region_free(ar);
238 BLI_freelistN(&sc->regionbase);
240 for(sa= sc->areabase.first; sa; sa= san) {
242 BKE_screen_area_free(sa);
245 BLI_freelistN(&sc->vertbase);
246 BLI_freelistN(&sc->edgebase);
247 BLI_freelistN(&sc->areabase);