files missing from recent merge
[blender-staging.git] / source / blender / editors / space_outliner / outliner_header.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_ID.h"
33 #include "DNA_anim_types.h"
34 #include "DNA_space_types.h"
35 #include "DNA_scene_types.h"
36 #include "DNA_screen_types.h"
37 #include "DNA_windowmanager_types.h"
38
39 #include "MEM_guardedalloc.h"
40
41 #include "BLI_blenlib.h"
42
43 #include "BKE_animsys.h"
44 #include "BKE_context.h"
45 #include "BKE_global.h"
46 #include "BKE_main.h"
47 #include "BKE_screen.h"
48
49 #include "ED_keyframing.h"
50 #include "ED_screen.h"
51 #include "ED_util.h"
52 #include "ED_types.h"
53
54 #include "WM_api.h"
55 #include "WM_types.h"
56
57 #include "BIF_gl.h"
58 #include "BIF_glutil.h"
59
60 #include "UI_interface.h"
61 #include "UI_resources.h"
62 #include "UI_view2d.h"
63
64 #include "outliner_intern.h"
65
66
67 /* ************************ header area region *********************** */
68
69 static void do_viewmenu(bContext *C, void *arg, int event)
70 {
71         ScrArea *curarea= CTX_wm_area(C);
72         SpaceOops *soops= curarea->spacedata.first;
73         
74         switch(event) {
75                 case 0: /* Shuffle Selected Blocks */
76                         //shuffle_oops();
77                         break;
78                 case 1: /* Shrink Selected Blocks */
79                         //shrink_oops();
80                         break;
81                 case 2: /* View All */
82                         //do_oops_buttons(B_OOPSHOME);
83                         break;
84                 case 3: /* View All */
85                         //do_oops_buttons(B_OOPSVIEWSEL);
86                         break;
87                 case 4: /* Maximize Window */
88                         /* using event B_FULL */
89                         break;
90                         break;
91                 case 6:
92                         //outliner_toggle_visible(curarea);
93                         break;
94                 case 7:
95                         //outliner_show_hierarchy(curarea);
96                         break;
97                 case 8:
98                         //outliner_show_active(curarea);
99                         break;
100                 case 9:
101                         //outliner_one_level(curarea, 1);
102                         break;
103                 case 10:
104                         //outliner_one_level(curarea, -1);
105                         break;
106                 case 12:
107                         if (soops->flag & SO_HIDE_RESTRICTCOLS) soops->flag &= ~SO_HIDE_RESTRICTCOLS;
108                         else soops->flag |= SO_HIDE_RESTRICTCOLS;
109                         break;
110         }
111         ED_area_tag_redraw(curarea);
112 }
113
114 static uiBlock *outliner_viewmenu(bContext *C, ARegion *ar, void *arg_unused)
115 {
116         ScrArea *curarea= CTX_wm_area(C);
117         SpaceOops *soops= curarea->spacedata.first;
118         uiBlock *block;
119         short yco= 0, menuwidth=120;
120         
121         block= uiBeginBlock(C, ar, "outliner_viewmenu", UI_EMBOSSP);
122         uiBlockSetButmFunc(block, do_viewmenu, NULL);
123         
124         if (soops->flag & SO_HIDE_RESTRICTCOLS)
125                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_DEHLT, "Show Restriction Columns", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
126         else
127                 uiDefIconTextBut(block, BUTM, 1, ICON_CHECKBOX_HLT, "Show Restriction Columns", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 12, "");
128         
129         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
130         
131         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Expand One Level|NumPad +", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 9, "");
132         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Collapse One Level|NumPad -", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 10, "");
133         
134         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");  
135         
136         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show/Hide All", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 6, "");
137         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Hierarchy|Home", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 7, "");
138         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Show Active|NumPad .", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 1, 8, "");
139         
140 //      uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");  
141 //      if(!curarea->full) uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Maximize Window|Ctrl UpArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
142 //      else uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, "Tile Window|Ctrl DownArrow", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 4, "");
143         
144         
145         if(curarea->headertype==HEADERTOP) {
146                 uiBlockSetDirection(block, UI_DOWN);
147         }
148         else {
149                 uiBlockSetDirection(block, UI_TOP);
150                 uiBlockFlipOrder(block);
151         }
152         
153         uiTextBoundsBlock(block, 50);
154         uiEndBlock(C, block);
155         
156         return block;
157 }
158
159 enum {
160         B_REDR  = 1,
161         
162         B_KEYINGSET_CHANGE,
163         B_KEYINGSET_REMOVE,
164 } eOutlinerHeader_Events;
165
166 static void do_outliner_buttons(bContext *C, void *arg, int event)
167 {
168         ScrArea *sa= CTX_wm_area(C);
169         Scene *scene= CTX_data_scene(C);
170         
171         switch(event) {
172                 case B_REDR:
173                         ED_area_tag_redraw(sa);
174                         break;
175                         
176                 case B_KEYINGSET_CHANGE:
177                         /* add a new KeyingSet if active is -1 */
178                         if (scene->active_keyingset == -1) {
179                                 // XXX the default settings have yet to evolve... need to keep this in sync with the 
180                                 BKE_keyingset_add(&scene->keyingsets, NULL, KEYINGSET_ABSOLUTE, 0);
181                                 scene->active_keyingset= BLI_countlist(&scene->keyingsets);
182                         }
183                         
184                         /* redraw regions with KeyingSet info */
185                         WM_event_add_notifier(C, NC_SCENE|ND_KEYINGSET, scene);
186                         break;
187                         
188                 case B_KEYINGSET_REMOVE:
189                         /* remove the active KeyingSet */
190                         if (scene->active_keyingset) {
191                                 KeyingSet *ks= BLI_findlink(&scene->keyingsets, scene->active_keyingset-1);
192                                 
193                                 /* firstly free KeyingSet's data, then free the KeyingSet itself */
194                                 if (ks) {
195                                         BKE_keyingset_free(ks);
196                                         BLI_freelinkN(&scene->keyingsets, ks);
197                                         scene->active_keyingset= 0;
198                                 }
199                                 else
200                                         scene->active_keyingset= 0;
201                         }
202                         
203                         /* redraw regions with KeyingSet info */
204                         WM_event_add_notifier(C, NC_SCENE|ND_KEYINGSET, scene);
205                         break;
206         }
207 }
208
209
210 void outliner_header_buttons(const bContext *C, ARegion *ar)
211 {
212         ScrArea *sa= CTX_wm_area(C);
213         Scene *scene= CTX_data_scene(C);
214         SpaceOops *soutliner= CTX_wm_space_outliner(C);
215         uiBlock *block;
216         int xco, yco= 3, xmax;
217         
218         block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS);
219         uiBlockSetHandleFunc(block, do_outliner_buttons, NULL);
220         
221         xco= ED_area_header_standardbuttons(C, block, yco);
222         
223         if((sa->flag & HEADER_NO_PULLDOWN)==0) {
224                 
225                 xmax= GetButStringLength("View");
226                 uiDefPulldownBut(block, outliner_viewmenu, CTX_wm_area(C), 
227                                                  "View", xco, yco-2, xmax-3, 24, ""); 
228                 xco += xmax;
229                 
230                 /* header text */
231                 xco += XIC;
232                 
233                 uiBlockSetEmboss(block, UI_EMBOSS);
234         }
235         
236         /* data selector*/
237         if(G.main->library.first) 
238                 uiDefButS(block, MENU, B_REDR, "Outliner Display%t|Libraries %x7|All Scenes %x0|Current Scene %x1|Visible Layers %x2|Groups %x6|Same Types %x5|Selected %x3|Active %x4|Sequence %x10|Datablocks %x11|User Preferences %x12||Key Maps %x13",      xco, yco, 120, 20,  &soutliner->outlinevis, 0, 0, 0, 0, "");
239         else
240                 uiDefButS(block, MENU, B_REDR, "Outliner Display%t|All Scenes %x0|Current Scene %x1|Visible Layers %x2|Groups %x6|Same Types %x5|Selected %x3|Active %x4|Sequence %x10|Datablocks %x11|User Preferences %x12||Key Maps %x13",    xco, yco, 120, 20,  &soutliner->outlinevis, 0, 0, 0, 0, "");   
241         xco += 120;
242         
243         /* KeyingSet editing buttons */
244         if ((soutliner->flag & SO_HIDE_KEYINGSETINFO)==0 && (soutliner->outlinevis==SO_DATABLOCKS)) {
245                 KeyingSet *ks= NULL;
246                 char *menustr= NULL;
247                 
248                 xco+= (int)(XIC*1.5);
249                 
250                 if (scene->active_keyingset)
251                         ks= (KeyingSet *)BLI_findlink(&scene->keyingsets, scene->active_keyingset-1);
252                 
253                 uiBlockBeginAlign(block);
254                         /* currently 'active' KeyingSet */
255                         menustr= ANIM_build_keyingsets_menu(&scene->keyingsets, 1);
256                         uiDefButI(block, MENU, B_KEYINGSET_CHANGE, menustr, xco,yco, 18,20, &scene->active_keyingset, 0, 0, 0, 0, "Browse Keying Sets");
257                         MEM_freeN(menustr);
258                         xco += 18;
259                         
260                         /* currently 'active' KeyingSet - change name */
261                         if (ks) {
262                                 /* active KeyingSet */
263                                 uiDefBut(block, TEX, B_KEYINGSET_CHANGE,"", xco,yco,120,20, ks->name, 0, 63, 0, 0, "Name of Active Keying Set");
264                                 xco += 120;
265                                 uiDefIconBut(block, BUT, B_KEYINGSET_REMOVE, VICON_X, xco, yco, 20, 20, NULL, 0.0, 0.0, 0.0, 0.0, "Remove this Keying Set");
266                                 xco += 20;
267                         }
268                         else {
269                                 /* no active KeyingSet... so placeholder instead */
270                                 uiDefBut(block, LABEL, 0,"<No Keying Set Active>", xco,yco,140,20, NULL, 0, 63, 0, 0, "Name of Active Keying Set");
271                                 xco += 140;
272                         }
273                 uiBlockEndAlign(block);
274                 
275                 /* current 'active' KeyingSet */
276                 if (ks) {
277                         xco += 5;
278                         
279                         /* operator buttons to add/remove selected items from set */
280                         uiBlockBeginAlign(block);
281                                         // XXX the icons here are temporary
282                                 uiDefIconButO(block, BUT, "OUTLINER_OT_keyingset_remove_selected", WM_OP_INVOKE_REGION_WIN, ICON_ZOOMOUT, xco,yco,XIC,YIC, "Remove selected properties from active Keying Set (Alt-K)");
283                                 xco += XIC;
284                                 uiDefIconButO(block, BUT, "OUTLINER_OT_keyingset_add_selected", WM_OP_INVOKE_REGION_WIN, ICON_ZOOMIN, xco,yco,XIC,YIC, "Add selected properties to active Keying Set (K)");
285                                 xco += XIC;
286                         uiBlockEndAlign(block);
287                         
288                         xco += 10;
289                         
290                         /* operator buttons to insert/delete keyframes for the active set */
291                         uiBlockBeginAlign(block);
292                                 uiDefIconButO(block, BUT, "ANIM_OT_delete_keyframe", WM_OP_INVOKE_REGION_WIN, ICON_KEY_DEHLT, xco,yco,XIC,YIC, "Delete Keyframes for the Active Keying Set (Alt-I)");
293                                 xco+= XIC;
294                                 uiDefIconButO(block, BUT, "ANIM_OT_insert_keyframe", WM_OP_INVOKE_REGION_WIN, ICON_KEY_HLT, xco,yco,XIC,YIC, "Insert Keyframes for the Active Keying Set (I)");
295                                 xco+= XIC;
296                         uiBlockEndAlign(block);
297                 }
298                 
299                 xco += XIC*2;
300         }
301         
302         /* always as last  */
303         UI_view2d_totRect_set(&ar->v2d, xco+XIC+100, (int)(ar->v2d.tot.ymax-ar->v2d.tot.ymin));
304         
305         uiEndBlock(C, block);
306         uiDrawBlock(C, block);
307 }
308
309