2.5
[blender-staging.git] / source / blender / editors / space_outliner / space_outliner.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) 2008 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 "DNA_color_types.h"
33 #include "DNA_object_types.h"
34 #include "DNA_oops_types.h"
35 #include "DNA_space_types.h"
36 #include "DNA_scene_types.h"
37 #include "DNA_screen_types.h"
38 #include "DNA_space_types.h"
39 #include "DNA_texture_types.h"
40 #include "DNA_vec_types.h"
41 #include "DNA_windowmanager_types.h"
42
43 #include "MEM_guardedalloc.h"
44
45 #include "BLI_blenlib.h"
46 #include "BLI_arithb.h"
47 #include "BLI_rand.h"
48
49 #include "BKE_colortools.h"
50 #include "BKE_context.h"
51 #include "BKE_screen.h"
52 #include "BKE_texture.h"
53 #include "BKE_utildefines.h"
54
55 #include "ED_space_api.h"
56 #include "ED_screen.h"
57
58 #include "WM_api.h"
59 #include "WM_types.h"
60
61 #include "BIF_gl.h"
62 #include "BIF_glutil.h"
63
64 #include "UI_interface.h"
65 #include "UI_text.h"
66 #include "UI_resources.h"
67 #include "UI_view2d.h"
68
69 #include "RNA_access.h"
70 #include "RNA_types.h"
71
72 #include "outliner_intern.h"
73
74 #define SET_INT_IN_POINTER(i) ((void*)(intptr_t)(i))
75 #define GET_INT_FROM_POINTER(i) ((int)(intptr_t)(i))
76
77 #define ROW_HEIGHT              19
78 #define COLUMN_WIDTH    150
79
80 typedef void (*uiTableCellFunc)(void *userdata, int row, int col, struct rcti *rct, struct uiBlock *block);
81
82 typedef struct uiTable {
83         rcti rct;
84         int rows, cols;
85
86         uiTableCellFunc cellfunc;
87         void *userdata;
88 } uiTable;
89
90 uiTable *UI_table_create(int rows, int cols, rcti *rct, uiTableCellFunc cellfunc, void *userdata)
91 {
92         uiTable *table;
93
94         table= MEM_callocN(sizeof(uiTable), "uiTable");
95         table->rct= *rct;
96         table->cellfunc= cellfunc;
97         table->rows= rows;
98         table->cols= cols;
99         table->userdata= userdata;
100
101         return table;
102 }
103
104 void UI_table_free(uiTable *table)
105 {
106         MEM_freeN(table);
107 }
108
109 void UI_table_draw(const bContext *C, uiTable *table)
110 {
111         ARegion *ar= CTX_wm_region(C);
112         uiBlock *block;
113         View2D *v2d;
114         rcti *rct, cellrct;
115         int y, row, col;
116         
117         v2d= &ar->v2d;
118         rct= &table->rct;
119         
120         block= uiBeginBlock(C, ar, "table outliner", UI_EMBOSST, UI_HELV);
121         
122         for(y=rct->ymax, row=0; y>rct->ymin; y-=ROW_HEIGHT, row++) {
123                 if(row%2 == 0) {
124                         UI_ThemeColorShade(TH_BACK, 6);
125                         glRecti(v2d->cur.xmin, y-ROW_HEIGHT, v2d->cur.xmax, y);
126                 }
127
128                 if(row >= table->rows)
129                         continue;
130
131                 for(col=0; col<table->cols; col++) {
132                         cellrct.xmin= rct->xmin+COLUMN_WIDTH*col + 1;
133                         cellrct.xmax= rct->xmin+COLUMN_WIDTH*(col+1);
134                         cellrct.ymin= y-ROW_HEIGHT;
135                         cellrct.ymax= y;
136
137                         table->cellfunc(table->userdata, row, col, &cellrct, block);
138                 }
139         }
140
141         UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
142
143         for(col=0; col<table->cols; col++)
144                 fdrawline(rct->xmin+COLUMN_WIDTH*(col+1), rct->ymin, rct->xmin+COLUMN_WIDTH*(col+1), rct->ymax);
145
146         uiEndBlock(C, block);
147         uiDrawBlock(C, block);
148 }
149
150
151 /* ************************ main outliner area region *********************** */
152
153 typedef struct CellRNA {
154         SpaceOops *space;
155         StructRNA *srna;
156         PropertyRNA *prop;
157         PointerRNA ptr;
158         int lastrow, index;
159
160         CollectionPropertyIterator iter;
161 } CellRNA;
162
163 static void rna_back_cb(bContext *C, void *arg_unused, void *arg_unused2)
164 {
165         SpaceOops *soutliner= (SpaceOops*)CTX_wm_space_data(C);
166         char *newpath;
167
168         newpath= RNA_path_back(soutliner->rnapath);
169         if(soutliner->rnapath)
170                 MEM_freeN(soutliner->rnapath);
171         soutliner->rnapath= newpath;
172 }
173
174 static void rna_pointer_cb(bContext *C, void *arg_prop, void *arg_index)
175 {
176         SpaceOops *soutliner= (SpaceOops*)CTX_wm_space_data(C);
177         PropertyRNA *prop= arg_prop;
178         char *newpath;
179         int index= GET_INT_FROM_POINTER(arg_index);;
180
181         newpath= RNA_path_append(soutliner->rnapath, NULL, prop, index, NULL);
182         if(soutliner->rnapath)
183                 MEM_freeN(soutliner->rnapath);
184         soutliner->rnapath= newpath;
185 }
186
187 static void rna_label(CellRNA *cell, rcti *rct, uiBlock *block)
188 {
189         PropertySubType subtype;
190         PropertyType type;
191         PropertyRNA *prop;
192         char *vectoritem[4]= {"x", "y", "z", "w"};
193         char *quatitem[4]= {"w", "x", "y", "z"};
194         char *coloritem[4]= {"r", "g", "b", "a"};
195         char item[32];
196         int arraylength;
197
198         prop= cell->prop;
199         type= RNA_property_type(&cell->ptr, prop);
200         subtype= RNA_property_subtype(&cell->ptr, prop);
201         arraylength= RNA_property_array_length(&cell->ptr, prop);
202
203         if(cell->index == -1) {
204                 uiDefBut(block, LABEL, 0, (char*)RNA_property_ui_name(&cell->ptr, prop), rct->xmin, rct->ymin, rct->xmax-rct->xmin, rct->ymax-rct->ymin, 0, 0, 0, 0, 0, (char*)RNA_property_ui_description(&cell->ptr, prop));
205         }
206         else if (type != PROP_COLLECTION) {
207                 if(arraylength == 4 && subtype == PROP_ROTATION)
208                         sprintf(item, "    %s", quatitem[cell->index]);
209                 else if(arraylength <= 4 && (subtype == PROP_VECTOR || subtype == PROP_ROTATION))
210                         sprintf(item, "    %s", vectoritem[cell->index]);
211                 else if(arraylength <= 4 && subtype == PROP_COLOR)
212                         sprintf(item, "    %s", coloritem[cell->index]);
213                 else
214                         sprintf(item, "    %d", cell->index+1);
215
216                 uiDefBut(block, LABEL, 0, item, rct->xmin, rct->ymin, rct->xmax-rct->xmin, rct->ymax-rct->ymin, 0, 0, 0, 0, 0, "");
217         }
218 }
219
220 static void rna_collection_but(CellRNA *cell, rcti *rct, uiBlock *block)
221 {
222         uiBut *but;
223         PointerRNA lookup;
224         PropertyRNA *nameprop;
225         char name[256]= "", *nameptr= name;
226
227         RNA_property_collection_lookup_int(&cell->ptr, cell->prop, cell->index, &lookup);
228
229         if(lookup.data) {
230                 nameprop= RNA_struct_name_property(&lookup);
231
232                 if(nameprop)
233                         nameptr= RNA_property_string_get_alloc(&lookup, nameprop, name, sizeof(name));
234
235                 if(!nameprop || strlen(nameptr) == 0)
236                         sprintf(nameptr, "%d", cell->index+1);
237         }
238
239         but= uiDefBut(block, BUT, 0, nameptr, rct->xmin, rct->ymin, rct->xmax-rct->xmin, rct->ymax-rct->ymin, 0, 0, 0, 0, 0, "");
240         uiButSetFlag(but, UI_TEXT_LEFT);
241
242         if(nameptr != name)
243                 MEM_freeN(nameptr);
244
245         uiButSetFunc(but, rna_pointer_cb, cell->prop, SET_INT_IN_POINTER(cell->index));
246 }
247
248 static uiBut *rna_auto_but(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int index, int x1, int y1, int x2, int y2)
249 {
250         uiBut *but;
251         const char *propname= RNA_property_identifier(ptr, prop);
252
253         switch(RNA_property_type(ptr, prop)) {
254                 case PROP_BOOLEAN: {
255                         int value, length;
256
257                         length= RNA_property_array_length(ptr, prop);
258
259                         if(length)
260                                 value= RNA_property_boolean_get_array(ptr, prop, index);
261                         else
262                                 value= RNA_property_boolean_get(ptr, prop);
263
264                         but= uiDefButR(block, TOG, 0, (value)? "True": "False", x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
265                         break;
266                 }
267                 case PROP_INT:
268                 case PROP_FLOAT:
269                         but= uiDefButR(block, NUM, 0, "", x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
270                         break;
271                 case PROP_ENUM:
272                         but= uiDefButR(block, MENU, 0, NULL, x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
273                         break;
274                 case PROP_STRING:
275                         but= uiDefButR(block, TEX, 0, "", x1, y1, x2, y2, ptr, propname, index, 0, 0, -1, -1, NULL);
276                         break;
277                 case PROP_POINTER: {
278                         PointerRNA pptr;
279                         PropertyRNA *nameprop;
280                         char name[256]= "", *nameptr= name;
281
282                         RNA_property_pointer_get(ptr, prop, &pptr);
283
284                         if(pptr.data) {
285                                 nameprop= RNA_struct_name_property(&pptr);
286                                 if(pptr.type && nameprop)
287                                         nameptr= RNA_property_string_get_alloc(&pptr, nameprop, name, sizeof(name));
288                                 else
289                                         strcpy(nameptr, "->");
290                         }
291
292                         but= uiDefButR(block, BUT, 0, nameptr, x1, y1, x2, y2, ptr, propname, index, 0, 0, 0, 0, NULL);
293                         uiButSetFlag(but, UI_TEXT_LEFT);
294
295                         if(nameptr != name)
296                                 MEM_freeN(nameptr);
297
298                         break;
299                 }
300                 default:
301                         but= NULL;
302                         break;
303         }
304
305         return but;
306 }
307
308 static void rna_but(CellRNA *cell, rcti *rct, uiBlock *block)
309 {
310         uiBut *but;
311         PropertyRNA *prop;
312         PropertyType type;
313         int arraylength, index;
314
315         prop= cell->prop;
316         type= RNA_property_type(&cell->ptr, prop);
317         arraylength= RNA_property_array_length(&cell->ptr, prop);
318
319         if(type == PROP_COLLECTION) {
320                 /* item in a collection */
321                 if(cell->index >= 0)
322                         rna_collection_but(cell, rct, block);
323         }
324         else {
325                 /* other cases */
326                 index= (arraylength)? cell->index: 0;
327
328                 if(index >= 0) {
329                         but= rna_auto_but(block, &cell->ptr, prop, index, rct->xmin, rct->ymin, rct->xmax-rct->xmin, rct->ymax-rct->ymin);
330
331                         if(type == PROP_POINTER)
332                                 uiButSetFunc(but, rna_pointer_cb, prop, SET_INT_IN_POINTER(0));
333                 }
334         }
335 }
336
337 static void rna_path_but(CellRNA *cell, rcti *rct, uiBlock *block)
338 {
339         uiBut *but;
340
341         but= uiDefBut(block, BUT, 0, (cell->space->rnapath)? "..": ".", rct->xmin, rct->ymin, rct->xmax-rct->xmin, rct->ymax-rct->ymin, 0, 0, 0, 0, 0, "");
342         uiButSetFlag(but, UI_TEXT_LEFT);
343         uiButSetFunc(but, rna_back_cb, cell->space, NULL);
344 }
345
346 static void rna_table_cell_func(void *userdata, int row, int col, rcti *rct, uiBlock *block)
347 {
348         CellRNA *cell= userdata;
349         PropertyType type;
350         int length;
351
352         /* path button */
353         if(row == 0) {
354                 if(col == 0)
355                         rna_path_but(cell, rct, block);
356
357                 return;
358         }
359
360         /* set next property for new row */
361         if(row != cell->lastrow) {
362                 if(cell->prop) {
363                         cell->index++;
364
365                         type= RNA_property_type(&cell->ptr, cell->prop);
366                         if(type == PROP_COLLECTION)
367                                 length= RNA_property_collection_length(&cell->ptr, cell->prop);
368                         else
369                                 length= RNA_property_array_length(&cell->ptr, cell->prop);
370
371                         /* verify if we need to go to the next property */
372                         if(type == PROP_COLLECTION && cell->index < length);
373                         else if(length && cell->index < length);
374                         else {
375                                 RNA_property_collection_next(&cell->iter);
376                                 cell->prop= cell->iter.ptr.data;
377                                 cell->index= -1;
378                         }
379                 }
380                 else {
381                         /* initialize */
382                         cell->prop= cell->iter.ptr.data;
383                         cell->index= -1;
384                 }
385
386                 cell->lastrow= row;
387         }
388
389         /* make button */
390         if(col == 0)
391                 rna_label(cell, rct, block);
392         else if(col == 1)
393                 rna_but(cell, rct, block);
394 }
395
396 static void outliner_main_area_init(wmWindowManager *wm, ARegion *ar)
397 {
398         ListBase *keymap;
399         
400         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
401         
402         /* own keymap */
403         keymap= WM_keymap_listbase(wm, "Outliner", SPACE_OOPS, 0);      /* XXX weak? */
404         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
405 }
406
407 static void outliner_rna_draw(const bContext *C, ARegion *ar)
408 {
409         uiTable *table;
410         rcti rct;
411         CellRNA cell;
412         PropertyRNA *prop, *iterprop;
413         PointerRNA newptr;
414         float col[3];
415         int rows, cols, awidth, aheight, width, height;
416         SpaceOops *soutliner= (SpaceOops*)CTX_wm_space_data(C);
417         View2D *v2d= &ar->v2d;
418         View2DScrollers *scrollers;
419
420         /* clear */
421         UI_GetThemeColor3fv(TH_BACK, col);
422         glClearColor(col[0], col[1], col[2], 0.0);
423         glClear(GL_COLOR_BUFFER_BIT);
424         
425         awidth= width= ar->winx;
426         aheight= height= ar->winy;
427         
428         /* create table */
429         cell.space= soutliner;
430         cell.lastrow= -1;
431         RNA_main_pointer_create(CTX_data_main(C), &cell.ptr);
432         cell.prop= NULL;
433
434         /* solve RNA path or reset if fails */
435         if(soutliner->rnapath) {
436                 if(!RNA_path_resolve(&cell.ptr, soutliner->rnapath, &newptr, &prop)) {
437                         newptr.data= NULL;
438                         printf("RNA outliner: failed resolving path. (%s)\n", soutliner->rnapath);
439                 }
440
441                 if(newptr.data && newptr.type) {
442                         cell.ptr= newptr;
443                 }
444                 else {
445                         MEM_freeN(soutliner->rnapath);
446                         soutliner->rnapath= NULL;
447                 }
448         }
449
450         /* compute number of rows and columns */
451         rows= 1;
452         cols= 2;
453
454         iterprop= RNA_struct_iterator_property(&cell.ptr);
455         RNA_property_collection_begin(&cell.ptr, iterprop, &cell.iter);
456
457         for(; cell.iter.valid; RNA_property_collection_next(&cell.iter)) {
458                 prop= cell.iter.ptr.data;
459
460                 rows += 1 + RNA_property_array_length(&cell.ptr, prop);
461                 if(RNA_property_type(&cell.ptr, prop) == PROP_COLLECTION)
462                         rows += RNA_property_collection_length(&cell.ptr, prop);
463         }
464
465         RNA_property_collection_end(&cell.iter);
466         
467         /* determine extents of data
468          *      - height must be at least the height of the mask area
469          *      - width is columns + 1, as otherwise, part of last column 
470          *        will be obscured by scrollers
471          */
472         if ((rows*ROW_HEIGHT) > height)
473                 height= rows * ROW_HEIGHT;
474         width= (cols + 1) * COLUMN_WIDTH;
475         
476         /* update size of tot-rect (extents of data/viewable area) */
477         UI_view2d_totRect_set(v2d, width, height);
478         
479         rct.xmin= 0;
480         rct.ymin= -height;
481         rct.xmax= width;
482         rct.ymax= 0;
483         
484         /* set matrix for 2d-view controls */
485         UI_view2d_view_ortho(C, v2d);
486         
487         /* create and draw table */
488         table= UI_table_create(rows, 2, &rct, rna_table_cell_func, &cell);
489
490         RNA_property_collection_begin(&cell.ptr, iterprop, &cell.iter);
491         UI_table_draw(C, table);
492         RNA_property_collection_end(&cell.iter);
493
494         UI_table_free(table);
495         
496         /* reset view matrix */
497         UI_view2d_view_restore(C);
498         
499         /* scrollers */
500         scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
501         UI_view2d_scrollers_draw(C, v2d, scrollers);
502         UI_view2d_scrollers_free(scrollers);
503 }
504
505 static void outliner_tree_draw(const bContext *C, ARegion *ar)
506 {
507         View2D *v2d= &ar->v2d;
508         View2DScrollers *scrollers;
509         float col[3];
510         
511         /* clear */
512         UI_GetThemeColor3fv(TH_BACK, col);
513         glClearColor(col[0], col[1], col[2], 0.0);
514         glClear(GL_COLOR_BUFFER_BIT);
515         
516         draw_outliner(C);
517         
518         /* reset view matrix */
519         UI_view2d_view_restore(C);
520         
521         /* scrollers */
522         scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
523         UI_view2d_scrollers_draw(C, v2d, scrollers);
524         UI_view2d_scrollers_free(scrollers);
525 }
526
527 static void outliner_main_area_draw(const bContext *C, ARegion *ar)
528 {
529         SpaceOops *so= (SpaceOops *)CTX_wm_space_data(C);
530         
531         if(so->type==SO_RNA)
532                 outliner_rna_draw(C, ar);
533         else
534                 outliner_tree_draw(C, ar);
535 }
536
537
538 static void outliner_main_area_free(ARegion *ar)
539 {
540 }
541
542
543 static void outliner_main_area_listener(ARegion *ar, wmNotifier *wmn)
544 {
545         /* context changes */
546         switch(wmn->category) {
547                 case NC_SCENE:
548                         switch(wmn->data) {
549                                 case ND_OB_ACTIVE:
550                                 case ND_OB_SELECT:
551                                         ED_region_tag_redraw(ar);
552                                         break;
553                         }
554                         break;
555                 case NC_OBJECT:
556                         switch(wmn->data) {
557                                 case ND_BONE_ACTIVE:
558                                 case ND_BONE_SELECT:
559                                 case ND_TRANSFORM:
560                                         ED_region_tag_redraw(ar);
561                                         break;
562                         }
563         }
564         
565 }
566
567
568 /* ************************ header outliner area region *********************** */
569
570 /* add handlers, stuff you only do once or on area/region changes */
571 static void outliner_header_area_init(wmWindowManager *wm, ARegion *ar)
572 {
573         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
574 }
575
576 static void outliner_header_area_draw(const bContext *C, ARegion *ar)
577 {
578         float col[3];
579         
580         if(ED_screen_area_active(C))
581                 UI_GetThemeColor3fv(TH_HEADER, col);
582         else
583                 UI_GetThemeColor3fv(TH_HEADERDESEL, col);
584         
585         glClearColor(col[0], col[1], col[2], 0.0);
586         glClear(GL_COLOR_BUFFER_BIT);
587
588         /* set view2d view matrix for scrolling (without scrollers) */
589         UI_view2d_view_ortho(C, &ar->v2d);
590
591         outliner_header_buttons(C, ar);
592 }
593
594 static void outliner_header_area_free(ARegion *ar)
595 {
596 }
597
598 /* ******************** default callbacks for outliner space ***************** */
599
600 static SpaceLink *outliner_new(const bContext *C)
601 {
602         ARegion *ar;
603         SpaceOops *soutliner;
604
605         soutliner= MEM_callocN(sizeof(SpaceOops), "initoutliner");
606         soutliner->spacetype= SPACE_OOPS;
607         
608         /* header */
609         ar= MEM_callocN(sizeof(ARegion), "header for outliner");
610         
611         BLI_addtail(&soutliner->regionbase, ar);
612         ar->regiontype= RGN_TYPE_HEADER;
613         ar->alignment= RGN_ALIGN_BOTTOM;
614         
615         /* main area */
616         ar= MEM_callocN(sizeof(ARegion), "main area for outliner");
617         
618         BLI_addtail(&soutliner->regionbase, ar);
619         ar->regiontype= RGN_TYPE_WINDOW;
620         
621         ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM_O);
622         ar->v2d.align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
623         ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_KEEPZOOM|V2D_KEEPASPECT);
624         ar->v2d.keeptot= V2D_KEEPTOT_STRICT;
625         ar->v2d.minzoom= ar->v2d.maxzoom= 1.0f;
626         
627         return (SpaceLink*)soutliner;
628 }
629
630 static void free_oops(Oops *oops)       /* also oops itself */
631 {
632         BLI_freelistN(&oops->link);
633         MEM_freeN(oops);
634 }
635
636 static void outliner_free_tree(ListBase *lb)
637 {
638         
639         while(lb->first) {
640                 TreeElement *te= lb->first;
641                 
642                 outliner_free_tree(&te->subtree);
643                 BLI_remlink(lb, te);
644                 MEM_freeN(te);
645         }
646 }
647
648 /* not spacelink itself */
649 static void outliner_free(SpaceLink *sl)
650 {
651         SpaceOops *soutliner= (SpaceOops*)sl;
652         Oops *oops;
653
654         if(soutliner->rnapath) {
655                 MEM_freeN(soutliner->rnapath);
656                 soutliner->rnapath= NULL;
657         }
658
659         while( (oops= soutliner->oops.first) ) {
660                 BLI_remlink(&soutliner->oops, oops);
661                 free_oops(oops);
662         }
663         
664         outliner_free_tree(&soutliner->tree);
665         if(soutliner->treestore) {
666                 if(soutliner->treestore->data) MEM_freeN(soutliner->treestore->data);
667                 MEM_freeN(soutliner->treestore);
668         }
669         
670 }
671
672 /* spacetype; init callback */
673 static void outliner_init(wmWindowManager *wm, ScrArea *sa)
674 {
675         
676 }
677
678 static SpaceLink *outliner_duplicate(SpaceLink *sl)
679 {
680         SpaceOops *soutliner= (SpaceOops *)sl;
681         SpaceOops *soutlinern= MEM_dupallocN(soutliner);
682
683         if(soutlinern->rnapath)
684                 soutlinern->rnapath= MEM_dupallocN(soutlinern->rnapath);
685         
686         soutlinern->oops.first= soutlinern->oops.last= NULL;
687         soutlinern->tree.first= soutlinern->tree.last= NULL;
688         soutlinern->treestore= NULL;
689         
690         return (SpaceLink *)soutlinern;
691 }
692
693 /* only called once, from space_api/spacetypes.c */
694 void ED_spacetype_outliner(void)
695 {
696         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype time");
697         ARegionType *art;
698         
699         st->spaceid= SPACE_OOPS;
700         strncpy(st->name, "Outliner", BKE_ST_MAXNAME);
701         
702         st->new= outliner_new;
703         st->free= outliner_free;
704         st->init= outliner_init;
705         st->duplicate= outliner_duplicate;
706         st->operatortypes= outliner_operatortypes;
707         st->keymap= outliner_keymap;
708         
709         /* regions: main window */
710         art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
711         art->regionid = RGN_TYPE_WINDOW;
712         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
713         
714         art->init= outliner_main_area_init;
715         art->draw= outliner_main_area_draw;
716         art->free= outliner_main_area_free;
717         art->listener= outliner_main_area_listener;
718         BLI_addhead(&st->regiontypes, art);
719         
720         /* regions: header */
721         art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
722         art->regionid = RGN_TYPE_HEADER;
723         art->minsizey= HEADERY;
724         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
725         
726         art->init= outliner_header_area_init;
727         art->draw= outliner_header_area_draw;
728         art->free= outliner_header_area_free;
729         BLI_addhead(&st->regiontypes, art);
730         
731         BKE_spacetype_register(st);
732 }
733