2.5
[blender.git] / source / blender / editors / screen / space.c
1 /**
2  * $Id:
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) 2007 Blender Foundation.
21  * All rights reserved.
22  *
23  * 
24  * Contributor(s): Blender Foundation
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 #include <string.h>
30 #include <stdio.h>
31
32 #include "MEM_guardedalloc.h"
33
34 #include "IMB_imbuf_types.h"
35 #include "IMB_imbuf.h"
36
37 #include "BLI_blenlib.h"
38 #include "BLI_arithb.h"
39
40 #include "BKE_global.h"
41 #include "BKE_screen.h"
42
43 #include "BLO_readfile.h"
44
45 #include "WM_api.h"
46
47 #include "ED_area.h"
48 #include "ED_screen.h"
49
50 /* */
51
52 void ED_newspace(ScrArea *sa, int type)
53 {
54         if(sa->spacetype != type) {
55                 SpaceType *st= BKE_spacetype_from_id(type);
56                 SpaceLink *slold= sa->spacedata.first;
57                 SpaceLink *sl;
58                 
59                 sa->spacetype= type;
60                 sa->butspacetype= type;
61                 
62                 /* check previously stored space */
63                 for (sl= sa->spacedata.first; sl; sl= sl->next)
64                         if(sl->spacetype==type)
65                                 break;
66                 
67                 /* old spacedata... happened during work on 2.50, remove */
68                 if(sl && sl->regionbase.first==NULL) {
69                         st->free(sl);
70                         MEM_freeN(sl);
71                         sl= NULL;
72                 }
73                 
74                 if (sl) {
75                         
76                         /* swap regions */
77                         slold->regionbase= sa->regionbase;
78                         sa->regionbase= sl->regionbase;
79                         sl->regionbase.first= sl->regionbase.last= NULL;
80                         
81                         /* put in front of list */
82                         BLI_remlink(&sa->spacedata, sl);
83                         BLI_addhead(&sa->spacedata, sl);
84                 } 
85                 else {
86                         /* new space */
87                         if(st) {
88                                 sl= st->new();
89                                 BLI_addhead(&sa->spacedata, sl);
90                                 
91                                 /* swap regions */
92                                 slold->regionbase= sa->regionbase;
93                                 sa->regionbase= sl->regionbase;
94                                 sl->regionbase.first= sl->regionbase.last= NULL;
95                         }
96                 }
97         }
98         
99 }
100
101
102