doxygen: prevent GPL license block from being parsed as doxygen comment.
[blender.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, 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 "MEM_guardedalloc.h"
33
34 #include "BLI_blenlib.h"
35 #include "BLI_math.h"
36 #include "BLI_rand.h"
37 #include "BLI_utildefines.h"
38
39 #include "BKE_context.h"
40 #include "BKE_screen.h"
41
42 #include "ED_space_api.h"
43 #include "ED_screen.h"
44
45 #include "WM_api.h"
46 #include "WM_types.h"
47
48 #include "BIF_gl.h"
49
50 #include "UI_resources.h"
51 #include "UI_view2d.h"
52
53
54 #include "outliner_intern.h"
55
56 static void outliner_main_area_init(wmWindowManager *wm, ARegion *ar)
57 {
58         wmKeyMap *keymap;
59         
60         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
61         
62         /* own keymap */
63         keymap= WM_keymap_find(wm->defaultconf, "Outliner", SPACE_OUTLINER, 0);
64         /* don't pass on view2d mask, it's always set with scrollbar space, hide fails */
65         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, NULL, &ar->winrct);
66 }
67
68 static void outliner_main_area_draw(const bContext *C, ARegion *ar)
69 {
70         View2D *v2d= &ar->v2d;
71         View2DScrollers *scrollers;
72         
73         /* clear */
74         UI_ThemeClearColor(TH_BACK);
75         glClear(GL_COLOR_BUFFER_BIT);
76         
77         draw_outliner(C);
78         
79         /* reset view matrix */
80         UI_view2d_view_restore(C);
81         
82         /* scrollers */
83         scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
84         UI_view2d_scrollers_draw(C, v2d, scrollers);
85         UI_view2d_scrollers_free(scrollers);
86 }
87
88
89 static void outliner_main_area_free(ARegion *UNUSED(ar))
90 {
91         
92 }
93
94 static void outliner_main_area_listener(ARegion *ar, wmNotifier *wmn)
95 {
96         /* context changes */
97         switch(wmn->category) {
98                 case NC_SCENE:
99                         switch(wmn->data) {
100                                 case ND_OB_ACTIVE:
101                                 case ND_OB_SELECT:
102                                 case ND_OB_VISIBLE:
103                                 case ND_OB_RENDER:
104                                 case ND_MODE:
105                                 case ND_KEYINGSET:
106                                 case ND_FRAME:
107                                 case ND_RENDER_OPTIONS:
108                                 case ND_LAYER:
109                                 case ND_WORLD:
110                                         ED_region_tag_redraw(ar);
111                                         break;
112                         }
113                         break;
114                 case NC_OBJECT:
115                         switch(wmn->data) {
116                                 case ND_TRANSFORM:
117                                         /* transform doesn't change outliner data */
118                                         break;
119                                 case ND_BONE_ACTIVE:
120                                 case ND_BONE_SELECT:
121                                 case ND_DRAW:
122                                 case ND_PARENT:
123                                 case ND_OB_SHADING:
124                                         ED_region_tag_redraw(ar);
125                                         break;
126                                 case ND_CONSTRAINT:
127                                         switch(wmn->action) {
128                                                 case NA_ADDED:
129                                                 case NA_REMOVED:
130                                                 case NA_RENAME:
131                                                         ED_region_tag_redraw(ar);
132                                                         break;
133                                         }
134                                         break;
135                                 case ND_MODIFIER:
136                                         /* all modifier actions now */
137                                         ED_region_tag_redraw(ar);
138                                         break;
139                         }
140                         break;
141                 case NC_GROUP:
142                         /* all actions now, todo: check outliner view mode? */
143                         ED_region_tag_redraw(ar);
144                         break;
145                 case NC_LAMP:
146                         /* For updating lamp icons, when changing lamp type */
147                         if(wmn->data == ND_LIGHTING_DRAW)
148                                 ED_region_tag_redraw(ar);
149                                 break;
150                 case NC_SPACE:
151                         if(wmn->data == ND_SPACE_OUTLINER)
152                                 ED_region_tag_redraw(ar);
153                                 break;
154                 case NC_ID:
155                         if(wmn->action == NA_RENAME)
156                                 ED_region_tag_redraw(ar);
157                         break;
158                 case NC_MATERIAL:
159                         switch(wmn->data) {
160                                 case ND_SHADING:
161                                 case ND_SHADING_DRAW:
162                                         ED_region_tag_redraw(ar);
163                                         break;
164                         }
165                         break;
166                 case NC_TEXTURE:
167                         ED_region_tag_redraw(ar);
168                         break;
169                 case NC_GEOM:
170                         switch(wmn->data) {
171                                 case ND_DATA:
172                                         /* needed for vertex groups only, no special notifier atm so use NC_GEOM|ND_DATA */
173                                         ED_region_tag_redraw(ar);
174                                         break;
175                         }
176                         break;
177         }
178         
179 }
180
181
182 /* ************************ header outliner area region *********************** */
183
184 /* add handlers, stuff you only do once or on area/region changes */
185 static void outliner_header_area_init(wmWindowManager *UNUSED(wm), ARegion *ar)
186 {
187         ED_region_header_init(ar);
188 }
189
190 static void outliner_header_area_draw(const bContext *C, ARegion *ar)
191 {
192         ED_region_header(C, ar);
193 }
194
195 static void outliner_header_area_free(ARegion *UNUSED(ar))
196 {
197 }
198
199 static void outliner_header_area_listener(ARegion *ar, wmNotifier *wmn)
200 {
201         /* context changes */
202         switch(wmn->category) {
203                 case NC_SCENE:
204                         if(wmn->data == ND_KEYINGSET)
205                                 ED_region_tag_redraw(ar);
206                         break;
207                 case NC_SPACE:
208                         if(wmn->data == ND_SPACE_OUTLINER)
209                                 ED_region_tag_redraw(ar);
210                         break;
211         }
212 }
213
214 /* ******************** default callbacks for outliner space ***************** */
215
216 static SpaceLink *outliner_new(const bContext *UNUSED(C))
217 {
218         ARegion *ar;
219         SpaceOops *soutliner;
220
221         soutliner= MEM_callocN(sizeof(SpaceOops), "initoutliner");
222         soutliner->spacetype= SPACE_OUTLINER;
223         
224         /* header */
225         ar= MEM_callocN(sizeof(ARegion), "header for outliner");
226         
227         BLI_addtail(&soutliner->regionbase, ar);
228         ar->regiontype= RGN_TYPE_HEADER;
229         ar->alignment= RGN_ALIGN_BOTTOM;
230         
231         /* main area */
232         ar= MEM_callocN(sizeof(ARegion), "main area for outliner");
233         
234         BLI_addtail(&soutliner->regionbase, ar);
235         ar->regiontype= RGN_TYPE_WINDOW;
236         
237         ar->v2d.scroll = (V2D_SCROLL_RIGHT|V2D_SCROLL_BOTTOM_O);
238         ar->v2d.align = (V2D_ALIGN_NO_NEG_X|V2D_ALIGN_NO_POS_Y);
239         ar->v2d.keepzoom = (V2D_LOCKZOOM_X|V2D_LOCKZOOM_Y|V2D_LIMITZOOM|V2D_KEEPASPECT);
240         ar->v2d.keeptot= V2D_KEEPTOT_STRICT;
241         ar->v2d.minzoom= ar->v2d.maxzoom= 1.0f;
242         
243         return (SpaceLink*)soutliner;
244 }
245
246 /* not spacelink itself */
247 static void outliner_free(SpaceLink *sl)
248 {
249         SpaceOops *soutliner= (SpaceOops*)sl;
250         
251         outliner_free_tree(&soutliner->tree);
252         if(soutliner->treestore) {
253                 if(soutliner->treestore->data) MEM_freeN(soutliner->treestore->data);
254                 MEM_freeN(soutliner->treestore);
255         }
256         
257 }
258
259 /* spacetype; init callback */
260 static void outliner_init(wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
261 {
262         
263 }
264
265 static SpaceLink *outliner_duplicate(SpaceLink *sl)
266 {
267         SpaceOops *soutliner= (SpaceOops *)sl;
268         SpaceOops *soutlinern= MEM_dupallocN(soutliner);
269
270         soutlinern->tree.first= soutlinern->tree.last= NULL;
271         soutlinern->treestore= NULL;
272         
273         return (SpaceLink *)soutlinern;
274 }
275
276 /* only called once, from space_api/spacetypes.c */
277 void ED_spacetype_outliner(void)
278 {
279         SpaceType *st= MEM_callocN(sizeof(SpaceType), "spacetype time");
280         ARegionType *art;
281         
282         st->spaceid= SPACE_OUTLINER;
283         strncpy(st->name, "Outliner", BKE_ST_MAXNAME);
284         
285         st->new= outliner_new;
286         st->free= outliner_free;
287         st->init= outliner_init;
288         st->duplicate= outliner_duplicate;
289         st->operatortypes= outliner_operatortypes;
290         st->keymap= outliner_keymap;
291         
292         /* regions: main window */
293         art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
294         art->regionid = RGN_TYPE_WINDOW;
295         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D;
296         
297         art->init= outliner_main_area_init;
298         art->draw= outliner_main_area_draw;
299         art->free= outliner_main_area_free;
300         art->listener= outliner_main_area_listener;
301         BLI_addhead(&st->regiontypes, art);
302         
303         /* regions: header */
304         art= MEM_callocN(sizeof(ARegionType), "spacetype time region");
305         art->regionid = RGN_TYPE_HEADER;
306         art->prefsizey= HEADERY;
307         art->keymapflag= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES|ED_KEYMAP_HEADER;
308         
309         art->init= outliner_header_area_init;
310         art->draw= outliner_header_area_draw;
311         art->free= outliner_header_area_free;
312         art->listener= outliner_header_area_listener;
313         BLI_addhead(&st->regiontypes, art);
314         
315         BKE_spacetype_register(st);
316 }
317