Remove unneeded notifier data added in revision 26219.
[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_outliner_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_math.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_resources.h"
66 #include "UI_view2d.h"
67
68 #include "RNA_access.h"
69 #include "RNA_types.h"
70
71 #include "outliner_intern.h"
72
73 static void outliner_main_area_init(wmWindowManager *wm, ARegion *ar)
74 {
75         wmKeyMap *keymap;
76         
77         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
78         
79         /* own keymap */
80         keymap= WM_keymap_find(wm->defaultconf, "Outliner", SPACE_OUTLINER, 0);
81         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
82 }
83
84 static void outliner_main_area_draw(const bContext *C, ARegion *ar)
85 {
86         View2D *v2d= &ar->v2d;
87         View2DScrollers *scrollers;
88         float col[3];
89         
90         /* clear */
91         UI_GetThemeColor3fv(TH_BACK, col);
92         glClearColor(col[0], col[1], col[2], 0.0);
93         glClear(GL_COLOR_BUFFER_BIT);
94         
95         draw_outliner(C);
96         
97         /* reset view matrix */
98         UI_view2d_view_restore(C);
99         
100         /* scrollers */
101         scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
102         UI_view2d_scrollers_draw(C, v2d, scrollers);
103         UI_view2d_scrollers_free(scrollers);
104 }
105
106
107 static void outliner_main_area_free(ARegion *ar)
108 {
109 }
110
111
112 static void outliner_main_area_listener(ARegion *ar, wmNotifier *wmn)
113 {
114         /* context changes */
115         switch(wmn->category) {
116                 case NC_SCENE:
117                         switch(wmn->data) {
118                                 case ND_OB_ACTIVE:
119                                 case ND_OB_SELECT:
120                                 case ND_MODE:
121                                 case ND_KEYINGSET:
122                                 case ND_FRAME:
123                                 case ND_RENDER_OPTIONS:
124                                 case ND_LAYER:
125                                         ED_region_tag_redraw(ar);
126                                         break;
127                         }
128                         break;
129                 case NC_OBJECT:
130                         switch(wmn->data) {
131                                 case ND_TRANSFORM:
132                                         /* transform doesn't change outliner data */
133                                         break;
134                                 case ND_BONE_ACTIVE:
135                                 case ND_BONE_SELECT:
136                                         ED_region_tag_redraw(ar);
137                                         break;
138                                 case ND_MODIFIER:
139                                         if(wmn->action == NA_RENAME)
140                                                 ED_region_tag_redraw(ar);
141                                         break;
142                         }
143                 case NC_GROUP:
144                         /* all actions now, todo: check outliner view mode? */
145                         ED_region_tag_redraw(ar);
146                         break;
147                 case NC_LAMP:
148                         /* For updating lamp icons, when changing lamp type */
149                         if(wmn->data == ND_LIGHTING_DRAW)
150                                 ED_region_tag_redraw(ar);
151                                 break;
152                 case NC_SPACE:
153                         if(wmn->data == ND_SPACE_OUTLINER)
154                                 ED_region_tag_redraw(ar);
155                                 break;
156                 case NC_ID:
157                         if(wmn->action == NA_RENAME)
158                                 ED_region_tag_redraw(ar);
159                         break;
160         }
161         
162 }
163
164
165 /* ************************ header outliner area region *********************** */
166
167 /* add handlers, stuff you only do once or on area/region changes */
168 static void outliner_header_area_init(wmWindowManager *wm, ARegion *ar)
169 {
170         ED_region_header_init(ar);
171 }
172
173 static void outliner_header_area_draw(const bContext *C, ARegion *ar)
174 {
175         ED_region_header(C, ar);
176 }
177
178 static void outliner_header_area_free(ARegion *ar)
179 {
180 }
181
182 static void outliner_header_area_listener(ARegion *ar, wmNotifier *wmn)
183 {
184         /* context changes */
185         switch(wmn->category) {
186                 case NC_SCENE:
187                         if(wmn->data == ND_KEYINGSET)
188                                 ED_region_tag_redraw(ar);
189                         break;
190                 case NC_SPACE:
191                         if(wmn->data == ND_SPACE_OUTLINER)
192                                 ED_region_tag_redraw(ar);
193                         break;
194         }
195 }
196
197 /* ******************** default callbacks for outliner space ***************** */
198
199 static SpaceLink *outliner_new(const bContext *C)
200 {
201         ARegion *ar;
202         SpaceOops *soutliner;
203
204         soutliner= MEM_callocN(sizeof(SpaceOops), "initoutliner");
205         soutliner->spacetype= SPACE_OUTLINER;
206         
207         /* header */
208         ar= MEM_callocN(sizeof(ARegion), "header for outliner");
209         
210         BLI_addtail(&soutliner->regionbase, ar);
211         ar->regiontype= RGN_TYPE_HEADER;
212         ar->alignment= RGN_ALIGN_BOTTOM;
213         
214         /* main area */
215         ar= MEM_callocN(sizeof(ARegion), "main area for outliner");
216         
217         BLI_addtail(&soutliner->regionbase, ar);
218         ar->regiontype= RGN_TYPE_WINDOW;
219         
220         ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM_O);
221         ar->v2d.align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
222         ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_LIMITZOOM|V2D_KEEPASPECT);
223         ar->v2d.keeptot= V2D_KEEPTOT_STRICT;
224         ar->v2d.minzoom= ar->v2d.maxzoom= 1.0f;
225         
226         return (SpaceLink*)soutliner;
227 }
228
229 /* not spacelink itself */
230 static void outliner_free(SpaceLink *sl)
231 {
232         SpaceOops *soutliner= (SpaceOops*)sl;
233         
234         outliner_free_tree(&soutliner->tree);
235         if(soutliner->treestore) {
236                 if(soutliner->treestore->data) MEM_freeN(soutliner->treestore->data);
237                 MEM_freeN(soutliner->treestore);
238         }
239         
240 }
241
242 /* spacetype; init callback */
243 static void outliner_init(wmWindowManager *wm, ScrArea *sa)
244 {
245         
246 }
247
248 static SpaceLink *outliner_duplicate(SpaceLink *sl)
249 {
250         SpaceOops *soutliner= (SpaceOops *)sl;
251         SpaceOops *soutlinern= MEM_dupallocN(soutliner);
252
253         soutlinern->tree.first= soutlinern->tree.last= NULL;
254         soutlinern->treestore= NULL;
255         
256         return (SpaceLink *)soutlinern;
257 }
258
259 /* only called once, from space_api/spacetypes.c */
260 void ED_spacetype_outliner(void)
261 {
262         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype time");
263         ARegionType *art;
264         
265         st->spaceid= SPACE_OUTLINER;
266         strncpy(st->name, "Outliner", BKE_ST_MAXNAME);
267         
268         st->new= outliner_new;
269         st->free= outliner_free;
270         st->init= outliner_init;
271         st->duplicate= outliner_duplicate;
272         st->operatortypes= outliner_operatortypes;
273         st->keymap= outliner_keymap;
274         
275         /* regions: main window */
276         art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
277         art->regionid = RGN_TYPE_WINDOW;
278         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
279         
280         art->init= outliner_main_area_init;
281         art->draw= outliner_main_area_draw;
282         art->free= outliner_main_area_free;
283         art->listener= outliner_main_area_listener;
284         BLI_addhead(&st->regiontypes, art);
285         
286         /* regions: header */
287         art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
288         art->regionid = RGN_TYPE_HEADER;
289         art->minsizey= HEADERY;
290         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES|ED_KEYMAP_HEADER;
291         
292         art->init= outliner_header_area_init;
293         art->draw= outliner_header_area_draw;
294         art->free= outliner_header_area_free;
295         art->listener= outliner_header_area_listener;
296         BLI_addhead(&st->regiontypes, art);
297         
298         BKE_spacetype_register(st);
299 }
300