Changes to functions from blender/windowmanager/intern/wm_event_system.c
[blender-staging.git] / source / blender / editors / space_action / action_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_action_types.h"
33 #include "DNA_key_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_context.h"
44 #include "BKE_screen.h"
45
46 #include "ED_anim_api.h"
47 #include "ED_screen.h"
48 #include "ED_types.h"
49 #include "ED_util.h"
50
51 #include "WM_api.h"
52 #include "WM_types.h"
53
54 #include "BIF_gl.h"
55 #include "BIF_glutil.h"
56
57 #include "UI_interface.h"
58 #include "UI_resources.h"
59 #include "UI_view2d.h"
60
61 #include "action_intern.h"
62
63 /* ********************************************************* */
64 /* Menu Defines... */
65
66 /* button events */
67 enum {
68         B_REDR  = 0,
69         B_ACTCOPYKEYS,
70         B_ACTPASTEKEYS,
71 } eActHeader_ButEvents;
72
73 /* ------------------------------- */
74 /* enums declaring constants that are used as menu event codes  */
75
76 enum {
77         ACTMENU_VIEW_CENTERVIEW= 0,
78         ACTMENU_VIEW_AUTOUPDATE,
79         ACTMENU_VIEW_PLAY3D,
80         ACTMENU_VIEW_PLAYALL,
81         ACTMENU_VIEW_ALL,
82         ACTMENU_VIEW_MAXIMIZE,
83         ACTMENU_VIEW_LOCK,
84         ACTMENU_VIEW_SLIDERS,
85         ACTMENU_VIEW_NEXTMARKER,
86         ACTMENU_VIEW_PREVMARKER,
87         ACTMENU_VIEW_NEXTKEYFRAME,
88         ACTMENU_VIEW_PREVKEYFRAME,
89         ACTMENU_VIEW_TIME,
90         ACTMENU_VIEW_NOHIDE,
91         ACTMENU_VIEW_FRANUM,
92         ACTMENU_VIEW_TRANSDELDUPS,
93         ACTMENU_VIEW_HORIZOPTIMISE,
94         ACTMENU_VIEW_GCOLORS,
95         ACTMENU_VIEW_PREVRANGESET,
96         ACTMENU_VIEW_PREVRANGECLEAR,
97         ACTMENU_VIEW_PREVRANGEAUTO
98 };
99
100 enum {
101         ACTMENU_SEL_BORDER = 0,
102         ACTMENU_SEL_BORDERC,
103         ACTMENU_SEL_BORDERM,
104         ACTMENU_SEL_ALL_KEYS,
105         ACTMENU_SEL_ALL_CHAN,
106         ACTMENU_SEL_ALL_MARKERS,
107         ACTMENU_SEL_INVERSE_KEYS,
108         ACTMENU_SEL_INVERSE_MARKERS,
109         ACTMENU_SEL_INVERSE_CHANNELS,
110         ACTMENU_SEL_LEFTKEYS,
111         ACTMENU_SEL_RIGHTKEYS
112 };
113
114 enum {
115         ACTMENU_SEL_COLUMN_KEYS = 1,
116         ACTMENU_SEL_COLUMN_CFRA,
117         ACTMENU_SEL_COLUMN_MARKERSCOLUMN,
118         ACTMENU_SEL_COLUMN_MARKERSBETWEEN 
119 };
120
121 enum {
122         ACTMENU_CHANNELS_OPENLEVELS = 0,
123         ACTMENU_CHANNELS_CLOSELEVELS,
124         ACTMENU_CHANNELS_EXPANDALL,
125         ACTMENU_CHANNELS_SHOWACHANS,
126         ACTMENU_CHANNELS_DELETE
127 };
128
129 enum {
130         ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_UP        = 0,
131         ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_DOWN,
132         ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_TOP,
133         ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_BOTTOM
134 };
135
136 enum {
137         ACTMENU_CHANNELS_GROUP_ADD_TOACTIVE     = 0,
138         ACTMENU_CHANNELS_GROUP_ADD_TONEW,
139         ACTMENU_CHANNELS_GROUP_REMOVE,
140         ACTMENU_CHANNELS_GROUP_SYNCPOSE
141 };
142
143 enum {
144         ACTMENU_CHANNELS_SETTINGS_TOGGLE = 0,
145         ACTMENU_CHANNELS_SETTINGS_ENABLE,
146         ACTMENU_CHANNELS_SETTINGS_DISABLE,
147 };
148
149 enum {
150         ACTMENU_KEY_DUPLICATE = 0,
151         ACTMENU_KEY_DELETE,
152         ACTMENU_KEY_CLEAN,
153         ACTMENU_KEY_SAMPLEKEYS,
154         ACTMENU_KEY_INSERTKEY
155 };
156
157 enum {
158         ACTMENU_KEY_TRANSFORM_MOVE  = 0,
159         ACTMENU_KEY_TRANSFORM_SCALE,
160         ACTMENU_KEY_TRANSFORM_SLIDE,
161         ACTMENU_KEY_TRANSFORM_EXTEND
162 };
163
164 enum {
165         ACTMENU_KEY_HANDLE_AUTO = 0,
166         ACTMENU_KEY_HANDLE_ALIGN,
167         ACTMENU_KEY_HANDLE_FREE,
168         ACTMENU_KEY_HANDLE_VECTOR
169 };
170
171 enum {
172         ACTMENU_KEY_INTERP_CONST = 0,
173         ACTMENU_KEY_INTERP_LINEAR,
174         ACTMENU_KEY_INTERP_BEZIER
175 };
176
177 enum {
178         ACTMENU_KEY_EXTEND_CONST = 0,
179         ACTMENU_KEY_EXTEND_EXTRAPOLATION,
180         ACTMENU_KEY_EXTEND_CYCLIC,
181         ACTMENU_KEY_EXTEND_CYCLICEXTRAPOLATION
182 };
183
184 enum {
185         ACTMENU_KEY_SNAP_NEARFRAME = 1,
186         ACTMENU_KEY_SNAP_CURFRAME,
187         ACTMENU_KEY_SNAP_NEARMARK,
188         ACTMENU_KEY_SNAP_NEARTIME,
189         ACTMENU_KEY_SNAP_CFRA2KEY,
190 };
191
192 enum {
193         ACTMENU_KEY_MIRROR_CURFRAME = 1,
194         ACTMENU_KEY_MIRROR_YAXIS,
195         ACTMENU_KEY_MIRROR_XAXIS,
196         ACTMENU_KEY_MIRROR_MARKER
197 };
198
199 enum {
200         ACTMENU_MARKERS_ADD = 0,
201         ACTMENU_MARKERS_DUPLICATE,
202         ACTMENU_MARKERS_DELETE,
203         ACTMENU_MARKERS_NAME,
204         ACTMENU_MARKERS_MOVE,
205         ACTMENU_MARKERS_LOCALADD,
206         ACTMENU_MARKERS_LOCALRENAME,
207         ACTMENU_MARKERS_LOCALDELETE,
208         ACTMENU_MARKERS_LOCALMOVE
209 };
210
211 /* ------------------------------- */
212 /* macros for easier state testing (only for use here) */
213
214 /* test if active action editor is showing any markers */
215 #if 0
216         #define SACTION_HASMARKERS \
217                 ((saction->action && saction->action->markers.first) \
218                  || (scene->markers.first))
219 #endif
220
221 /* need to find out how to get scene from context */
222 #define SACTION_HASMARKERS (saction->action && saction->action->markers.first)
223
224 /* ------------------------------- */
225
226 /* *************************************************************** */
227 /* menus */
228
229 /* Key menu ---------------------------  */
230
231 static void do_keymenu_transformmenu(bContext *C, void *arg, int event)
232 {
233         switch (event)
234         {
235                 case ACTMENU_KEY_TRANSFORM_MOVE:
236                         //transform_action_keys('g', 0);
237                         break;
238                 case ACTMENU_KEY_TRANSFORM_SCALE:
239                         //transform_action_keys('s', 0);
240                         break;
241                 case ACTMENU_KEY_TRANSFORM_SLIDE:
242                         //transform_action_keys('t', 0);
243                         break;
244                 case ACTMENU_KEY_TRANSFORM_EXTEND:
245                         //transform_action_keys('e', 0);
246                         break;
247         }
248 }
249
250 static uiBlock *action_keymenu_transformmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
251 {
252         uiBlock *block;
253         short yco= 0, menuwidth=120;
254         
255         block= uiBeginBlock(C, handle->region, "action_keymenu_transformmenu", UI_EMBOSSP, UI_HELV);
256         uiBlockSetButmFunc(block, do_keymenu_transformmenu, NULL);
257
258         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
259                                          "Grab/Move|G", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0,  
260                                          ACTMENU_KEY_TRANSFORM_MOVE, "");
261         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
262                                          "Grab/Extend from Frame|E", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 
263                                          ACTMENU_KEY_TRANSFORM_EXTEND, "");
264         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
265                                          "Scale|S", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 
266                                          ACTMENU_KEY_TRANSFORM_SCALE, "");
267         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
268                                          "Time Slide|T", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 
269                                          ACTMENU_KEY_TRANSFORM_SLIDE, "");
270         
271         uiBlockSetDirection(block, UI_RIGHT);
272         
273         uiTextBoundsBlock(block, 60);
274         uiEndBlock(C, block);
275         
276         return block;
277 }
278
279 static void do_keymenu_snapmenu(bContext *C, void *arg, int event)
280 {
281         switch(event)
282         {
283                 case ACTMENU_KEY_SNAP_NEARFRAME:
284                 case ACTMENU_KEY_SNAP_CURFRAME:
285                 case ACTMENU_KEY_SNAP_NEARMARK:
286                 case ACTMENU_KEY_SNAP_NEARTIME:
287                         //snap_action_keys(event);
288                         break;
289                         
290                 case ACTMENU_KEY_SNAP_CFRA2KEY:
291                         //snap_cfra_action();
292                         break;
293         }
294 }
295
296 static uiBlock *action_keymenu_snapmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
297 {
298         SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
299         uiBlock *block;
300         short yco= 0, menuwidth=120;
301
302         
303         block= uiBeginBlock(C, handle->region, "action_keymenu_snapmenu", UI_EMBOSSP, UI_HELV);
304         uiBlockSetButmFunc(block, do_keymenu_snapmenu, NULL);
305
306         if (saction->flag & SACTION_DRAWTIME) {
307                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
308                                                  "Key -> Nearest Second|Shift S, 1", 0, yco-=20, 
309                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
310                                                  ACTMENU_KEY_SNAP_NEARTIME, "");
311                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
312                                                  "Key -> Current Time|Shift S, 2", 0, yco-=20, 
313                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
314                                                  ACTMENU_KEY_SNAP_CURFRAME, "");
315
316         }
317         else {
318                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
319                                                  "Key -> Nearest Frame|Shift S, 1", 0, yco-=20, 
320                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
321                                                  ACTMENU_KEY_SNAP_NEARFRAME, "");
322                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
323                                                  "Key -> Current Frame|Shift S, 2", 0, yco-=20, 
324                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
325                                                  ACTMENU_KEY_SNAP_CURFRAME, "");
326         }
327         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
328                                          "Key -> Nearest Marker|Shift S, 3", 0, yco-=20, 
329                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
330                                          ACTMENU_KEY_SNAP_NEARMARK, "");
331                                          
332         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
333                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
334                          
335         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
336                                          "Current Frame -> Key|Ctrl Shift S", 0, yco-=20, 
337                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
338                                          ACTMENU_KEY_SNAP_NEARMARK, "");
339         
340         uiBlockSetDirection(block, UI_RIGHT);
341         
342         uiTextBoundsBlock(block, 60);
343         uiEndBlock(C, block);
344         
345         return block;
346 }
347
348 static void do_keymenu_mirrormenu(bContext *C, void *arg, int event)
349 {
350         switch(event)
351         {
352                 case ACTMENU_KEY_MIRROR_CURFRAME:
353                 case ACTMENU_KEY_MIRROR_YAXIS:
354                         //mirror_action_keys(event);
355                         break;
356         }
357
358 }
359
360 static uiBlock *action_keymenu_mirrormenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
361 {
362         uiBlock *block;
363         short yco= 0, menuwidth=120;
364         
365         block= uiBeginBlock(C, handle->region, "action_keymenu_mirrormenu", UI_EMBOSSP, UI_HELV);
366         uiBlockSetButmFunc(block, do_keymenu_mirrormenu, NULL);
367
368         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
369                                          "Current Frame|Shift M, 1", 0, yco-=20, 
370                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
371                                          ACTMENU_KEY_MIRROR_CURFRAME, "");
372         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
373                                          "Vertical Axis|Shift M, 2", 0, yco-=20, 
374                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
375                                          ACTMENU_KEY_MIRROR_YAXIS, "");
376         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
377                                          "Horizontal Axis|Shift M, 3", 0, yco-=20, 
378                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
379                                          ACTMENU_KEY_MIRROR_XAXIS, "");
380         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
381                                          "Selected Marker|Shift M, 4", 0, yco-=20, 
382                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
383                                          ACTMENU_KEY_MIRROR_MARKER, "");
384         
385         uiBlockSetDirection(block, UI_RIGHT);
386         
387         uiTextBoundsBlock(block, 60);
388         uiEndBlock(C, block);
389         
390         return block;
391 }
392
393 static void do_keymenu_handlemenu(bContext *C, void *arg, int event)
394 {
395         switch (event) {
396                 case ACTMENU_KEY_HANDLE_AUTO:
397                         //sethandles_action_keys(HD_AUTO);
398                         break;
399
400                 case ACTMENU_KEY_HANDLE_ALIGN:
401                 case ACTMENU_KEY_HANDLE_FREE:
402                         /* OK, this is kinda dumb, need to fix the
403                          * toggle crap in sethandles_ipo_keys() 
404                          */
405                         //sethandles_action_keys(HD_ALIGN);
406                         break;
407
408                 case ACTMENU_KEY_HANDLE_VECTOR:
409                         //sethandles_action_keys(HD_VECT);      
410                         break;
411         }
412 }
413
414 static uiBlock *action_keymenu_handlemenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
415 {
416         uiBlock *block;
417         short yco= 0, menuwidth=120;
418         
419         block= uiBeginBlock(C, handle->region, "action_keymenu_handlemenu", UI_EMBOSSP, UI_HELV);
420         uiBlockSetButmFunc(block, do_keymenu_handlemenu, NULL);
421
422         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
423                                          "Auto|Shift H", 0, yco-=20, 
424                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
425                                          ACTMENU_KEY_HANDLE_AUTO, "");
426         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
427                                          "Aligned|H", 0, yco-=20, 
428                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
429                                          ACTMENU_KEY_HANDLE_ALIGN, "");
430         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
431                                          "Free|H", 0, yco-=20, menuwidth, 
432                                          19, NULL, 0.0, 0.0, 0, 
433                                          ACTMENU_KEY_HANDLE_FREE, "");
434         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
435                                          "Vector|V", 0, yco-=20, 
436                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
437                                          ACTMENU_KEY_HANDLE_VECTOR, "");
438         
439         uiBlockSetDirection(block, UI_RIGHT);
440         
441         uiTextBoundsBlock(block, 60);
442         uiEndBlock(C, block);
443         
444         return block;
445 }
446
447 static void do_keymenu_extendmenu(bContext *C, void *arg, int event)
448 {
449         switch(event)
450         {
451                 case ACTMENU_KEY_EXTEND_CONST:
452                         //action_set_ipo_flags(SET_EXTEND_MENU, SET_EXTEND_CONSTANT);
453                         break;
454                 case ACTMENU_KEY_EXTEND_EXTRAPOLATION:
455                         //action_set_ipo_flags(SET_EXTEND_MENU, SET_EXTEND_EXTRAPOLATION);
456                         break;
457                 case ACTMENU_KEY_EXTEND_CYCLIC:
458                         //action_set_ipo_flags(SET_EXTEND_MENU, SET_EXTEND_CYCLIC);
459                         break;
460                 case ACTMENU_KEY_EXTEND_CYCLICEXTRAPOLATION:
461                         //action_set_ipo_flags(SET_EXTEND_MENU, SET_EXTEND_CYCLICEXTRAPOLATION);
462                         break;
463         }
464 }
465
466 static uiBlock *action_keymenu_extendmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
467 {
468         uiBlock *block;
469         short yco= 0, menuwidth=120;
470         
471         block= uiBeginBlock(C, handle->region, "action_keymenu_extendmenu", UI_EMBOSSP, UI_HELV);
472         uiBlockSetButmFunc(block, do_keymenu_extendmenu, NULL);
473         
474         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
475                                          "Constant", 0, yco-=20, 
476                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
477                                          ACTMENU_KEY_EXTEND_CONST, "");
478         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
479                                          "Extrapolation", 0, yco-=20, 
480                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
481                                          ACTMENU_KEY_EXTEND_EXTRAPOLATION, "");
482         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
483                                          "Cyclic", 0, yco-=20, 
484                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
485                                          ACTMENU_KEY_EXTEND_CYCLIC, "");
486         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
487                                          "Cyclic Extrapolation", 0, yco-=20, 
488                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
489                                          ACTMENU_KEY_EXTEND_CYCLICEXTRAPOLATION, "");
490         
491         uiBlockSetDirection(block, UI_RIGHT);
492         
493         uiTextBoundsBlock(block, 60);
494         uiEndBlock(C, block);
495         
496         return block;
497 }
498
499 static void do_keymenu_intpolmenu(bContext *C, void *arg, int event)
500 {
501         switch(event)
502         {
503                 case ACTMENU_KEY_INTERP_CONST:
504                         //action_set_ipo_flags(SET_IPO_MENU, SET_IPO_CONSTANT);
505                         break;
506                 case ACTMENU_KEY_INTERP_LINEAR:
507                         //action_set_ipo_flags(SET_IPO_MENU, SET_IPO_LINEAR);
508                         break;
509                 case ACTMENU_KEY_INTERP_BEZIER:
510                         //action_set_ipo_flags(SET_IPO_MENU, SET_IPO_BEZIER);
511                         break;
512         }
513 }
514
515 static uiBlock *action_keymenu_intpolmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
516 {
517         uiBlock *block;
518         short yco= 0, menuwidth=120;
519         
520         block= uiBeginBlock(C, handle->region, "action_keymenu_intpolmenu", UI_EMBOSSP, UI_HELV);
521         uiBlockSetButmFunc(block, do_keymenu_intpolmenu, NULL);
522         
523         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
524                                          "Constant|Shift T, 1", 0, yco-=20, 
525                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
526                                          ACTMENU_KEY_INTERP_CONST, "");
527         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
528                                          "Linear|Shift T, 2", 0, yco-=20, 
529                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
530                                          ACTMENU_KEY_INTERP_LINEAR, "");
531         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
532                                          "Bezier|Shift T, 3", 0, yco-=20, 
533                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
534                                          ACTMENU_KEY_INTERP_BEZIER, "");
535         
536         uiBlockSetDirection(block, UI_RIGHT);
537         
538         uiTextBoundsBlock(block, 60);
539         uiEndBlock(C, block);
540         
541         return block;
542 }
543
544 static void do_action_keymenu(bContext *C, void *arg, int event)
545 {
546         SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
547         bAction *act;
548         //Key *key;
549         
550         if (!saction) return;
551
552         act = saction->action;
553         //key = get_action_mesh_key();
554
555         switch(event)
556         {
557                 case ACTMENU_KEY_DUPLICATE:
558                         //duplicate_action_keys();
559                         break;
560                 case ACTMENU_KEY_DELETE:
561                         //delete_action_keys();
562                         break;
563                 case ACTMENU_KEY_CLEAN:
564                         //clean_action();
565                         break;
566                 case ACTMENU_KEY_SAMPLEKEYS:
567                         //sample_action_keys();
568                         break;
569                 case ACTMENU_KEY_INSERTKEY:
570                         //insertkey_action();
571                         break;
572         }
573 }
574
575 static uiBlock *action_keymenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
576 {
577         ScrArea *curarea= CTX_wm_area(C);
578         uiBlock *block;
579         short yco= 0, menuwidth=120;
580         
581         block= uiBeginBlock(C, handle->region, "action_keymenu", UI_EMBOSSP, UI_HELV);
582
583
584         uiBlockSetButmFunc(block, do_action_keymenu, NULL);
585         
586         uiDefIconTextBlockBut(block, action_keymenu_transformmenu, 
587                                                   NULL, ICON_RIGHTARROW_THIN, "Transform", 0, yco-=20, 120, 20, "");
588         
589         uiDefIconTextBlockBut(block, action_keymenu_snapmenu, 
590                                                   NULL, ICON_RIGHTARROW_THIN, "Snap", 0, yco-=20, 120, 20, "");
591         
592         uiDefIconTextBlockBut(block, action_keymenu_mirrormenu, 
593                                                   NULL, ICON_RIGHTARROW_THIN, "Mirror", 0, yco-=20, 120, 20, "");
594         
595         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
596                                         menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
597         
598         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
599                                         "Insert Key|I", 0, yco-=20, 
600                                         menuwidth, 19, NULL, 0.0, 0.0, 0, 
601                                         ACTMENU_KEY_INSERTKEY, "");
602
603         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
604                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
605                                         
606         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
607                                         "Duplicate|Shift D", 0, yco-=20, 
608                                         menuwidth, 19, NULL, 0.0, 0.0, 0, 
609                                         ACTMENU_KEY_DUPLICATE, "");
610         
611         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
612                                         "Delete|X", 0, yco-=20, 
613                                         menuwidth, 19, NULL, 0.0, 0.0, 0, 
614                                         ACTMENU_KEY_DELETE, "");
615
616         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
617                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
618
619         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
620                                          "Clean Action|O", 0, yco-=20, 
621                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
622                                          ACTMENU_KEY_CLEAN, "");
623                                          
624         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
625                                          "Sample Keys|Alt O", 0, yco-=20, 
626                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
627                                          ACTMENU_KEY_SAMPLEKEYS, "");
628
629         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
630                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
631
632         uiDefIconTextBlockBut(block, action_keymenu_handlemenu, 
633                                                   NULL, ICON_RIGHTARROW_THIN, 
634                                                   "Handle Type", 0, yco-=20, 120, 20, "");
635         
636         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
637                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
638
639         uiDefIconTextBlockBut(block, action_keymenu_extendmenu, 
640                                                   NULL, ICON_RIGHTARROW_THIN, 
641                                                   "Extend Mode", 0, yco-=20, 120, 20, "");
642         uiDefIconTextBlockBut(block, action_keymenu_intpolmenu, 
643                                                   NULL, ICON_RIGHTARROW_THIN, 
644                                                   "Interpolation Mode", 0, yco-=20, 120, 20, "");
645         
646         if(curarea->headertype==HEADERTOP) {
647                 uiBlockSetDirection(block, UI_DOWN);
648         }
649         else {
650                 uiBlockSetDirection(block, UI_TOP);
651                 uiBlockFlipOrder(block);
652         }
653         
654         uiTextBoundsBlock(block, 50);
655         uiEndBlock(C, block);
656         
657         return block;
658 }
659
660 /* Frame menu ---------------------------  */
661
662
663 // framemenu uses functions from keymenu
664 static uiBlock *action_framemenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
665 {
666         ScrArea *curarea= CTX_wm_area(C);
667         uiBlock *block;
668         short yco= 0, menuwidth=120;
669         
670         block= uiBeginBlock(C, handle->region, "action_framemenu", UI_EMBOSSP, UI_HELV);
671         uiBlockSetButmFunc(block, do_action_keymenu, NULL);
672         
673         uiDefIconTextBlockBut(block, action_keymenu_transformmenu, 
674                                                   NULL, ICON_RIGHTARROW_THIN, "Transform", 0, yco-=20, 120, 20, "");
675         
676         uiDefIconTextBlockBut(block, action_keymenu_snapmenu, 
677                                                   NULL, ICON_RIGHTARROW_THIN, "Snap", 0, yco-=20, 120, 20, "");
678         
679         uiDefIconTextBlockBut(block, action_keymenu_mirrormenu, 
680                                                   NULL, ICON_RIGHTARROW_THIN, "Mirror", 0, yco-=20, 120, 20, "");
681         
682         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
683                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
684                                         
685         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
686                                         "Duplicate|Shift D", 0, yco-=20, 
687                                         menuwidth, 19, NULL, 0.0, 0.0, 0, 
688                                         ACTMENU_KEY_DUPLICATE, "");
689         
690         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
691                                         "Delete|X", 0, yco-=20, 
692                                         menuwidth, 19, NULL, 0.0, 0.0, 0, 
693                                         ACTMENU_KEY_DELETE, "");
694         
695         if(curarea->headertype==HEADERTOP) {
696                 uiBlockSetDirection(block, UI_DOWN);
697         }
698         else {
699                 uiBlockSetDirection(block, UI_TOP);
700                 uiBlockFlipOrder(block);
701         }
702         
703         uiTextBoundsBlock(block, 50);
704         uiEndBlock(C, block);
705         
706         return block;
707 }
708
709 /* Marker menu ---------------------------  */
710
711 static void do_markermenu(bContext *C, void *arg, int event)
712 {
713         switch(event)
714         {
715                 case ACTMENU_MARKERS_ADD:
716                         //add_marker(CFRA);
717                         break;
718                 case ACTMENU_MARKERS_DUPLICATE:
719                         //duplicate_marker();
720                         break;
721                 case ACTMENU_MARKERS_DELETE:
722                         //remove_marker();
723                         break;
724                 case ACTMENU_MARKERS_NAME:
725                         //rename_marker();
726                         break;
727                 case ACTMENU_MARKERS_MOVE:
728                         //transform_markers('g', 0);
729                         break;
730                 case ACTMENU_MARKERS_LOCALADD:
731                         //action_add_localmarker(G.saction->action, CFRA);
732                         break;
733                 case ACTMENU_MARKERS_LOCALDELETE:
734                         //action_remove_localmarkers(G.saction->action);
735                         break;
736                 case ACTMENU_MARKERS_LOCALRENAME:
737                         //action_rename_localmarker(G.saction->action);
738                         break;
739                 case ACTMENU_MARKERS_LOCALMOVE:
740                         /*G.saction->flag |= SACTION_POSEMARKERS_MOVE;
741                         transform_markers('g', 0);
742                         G.saction->flag &= ~SACTION_POSEMARKERS_MOVE;*/
743                         break;
744         }
745 }
746
747 static uiBlock *action_markermenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
748 {
749         SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
750         ScrArea *curarea= CTX_wm_area(C);
751         uiBlock *block;
752         short yco= 0, menuwidth=120;
753         
754         block= uiBeginBlock(C, handle->region, "action_markermenu", UI_EMBOSSP, UI_HELV);
755         uiBlockSetButmFunc(block, do_markermenu, NULL);
756         
757         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Add Marker|M", 0, yco-=20, 
758                                          menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_ADD, "");
759         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Duplicate Marker|Ctrl Shift D", 0, yco-=20, 
760                                          menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_DUPLICATE, "");
761         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Delete Marker|Shift X", 0, yco-=20,
762                                          menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_DELETE, "");
763                                         
764         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
765                                         
766         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "(Re)Name Marker|Ctrl M", 0, yco-=20,
767                                          menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_NAME, "");
768         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grab/Move Marker|Ctrl G", 0, yco-=20,
769                                          menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_MOVE, "");
770                 
771         if (saction->mode == SACTCONT_ACTION) {
772                 uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
773                 
774                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Add Pose Marker|Shift L", 0, yco-=20, 
775                                                  menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_LOCALADD, "");
776                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Rename Pose Marker|Ctrl Shift L", 0, yco-=20, 
777                                                  menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_LOCALRENAME, "");
778                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Delete Pose Marker|Alt L", 0, yco-=20,
779                                                  menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_LOCALDELETE, "");
780                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, "Grab/Move Pose Marker|Ctrl L", 0, yco-=20, 
781                                                  menuwidth, 19, NULL, 0.0, 0.0, 1, ACTMENU_MARKERS_LOCALMOVE, "");
782         }
783         
784         if(curarea->headertype==HEADERTOP) {
785                 uiBlockSetDirection(block, UI_DOWN);
786         }
787         else {
788                 uiBlockSetDirection(block, UI_TOP);
789                 uiBlockFlipOrder(block);
790         }
791         
792         uiTextBoundsBlock(block, 50);
793         uiEndBlock(C, block);
794         
795         return block;
796 }
797
798
799 /* Channel menu ---------------------------  */
800
801 static void do_channelmenu_posmenu(bContext *C, void *arg, int event)
802 {
803         switch(event)
804         {
805                 case ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_DOWN:
806                         //rearrange_action_channels(REARRANGE_ACTCHAN_DOWN);
807                         break;
808                 case ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_UP:
809                         //rearrange_action_channels(REARRANGE_ACTCHAN_UP);
810                         break;
811                 case ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_TOP:
812                         //rearrange_action_channels(REARRANGE_ACTCHAN_TOP);
813                         break;
814                 case ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_BOTTOM:
815                         //rearrange_action_channels(REARRANGE_ACTCHAN_BOTTOM);
816                         break;
817         }
818 }
819
820 static uiBlock *action_channelmenu_posmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
821 {
822         uiBlock *block;
823         short yco= 0, menuwidth=120;
824
825         block= uiBeginBlock(C, handle->region, "action_channelmenu_posmenu", UI_EMBOSSP, UI_HELV);
826         uiBlockSetButmFunc(block, do_channelmenu_posmenu, NULL);
827
828         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
829                                          "Move Up|Shift Page Up", 0, yco-=20, 
830                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
831                                          ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_UP, "");
832         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
833                                          "Move Down|Shift Page Down", 0, yco-=20, 
834                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
835                                          ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_DOWN, "");
836         
837         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
838                                         menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
839                                         
840         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
841                                          "Move to Top|Ctrl Shift Page Up", 0, yco-=20, 
842                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
843                                          ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_TOP, "");
844         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
845                                          "Move to Bottom|Ctrl Shift Page Down", 0, yco-=20, 
846                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
847                                          ACTMENU_CHANNELS_CHANPOS_MOVE_CHANNEL_BOTTOM, "");
848
849         uiBlockSetDirection(block, UI_RIGHT);
850         uiTextBoundsBlock(block, 60);
851
852         return block;
853 }
854
855 static void do_channelmenu_groupmenu(bContext *C, void *arg, int event)
856 {
857         switch(event)
858         {
859                 case ACTMENU_CHANNELS_GROUP_ADD_TOACTIVE:
860                         //action_groups_group(0);
861                         break;
862                 case ACTMENU_CHANNELS_GROUP_ADD_TONEW:
863                         //action_groups_group(1);
864                         break;
865                 case ACTMENU_CHANNELS_GROUP_REMOVE:
866                         //action_groups_ungroup();
867                         break;
868                 case ACTMENU_CHANNELS_GROUP_SYNCPOSE: /* Syncronise Pose-data and Action-data */
869                         //sync_pchan2achan_grouping();
870                         break;
871         }
872 }
873
874 static uiBlock *action_channelmenu_groupmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
875 {
876         uiBlock *block;
877         short yco= 0, menuwidth=120;
878
879         block= uiBeginBlock(C, handle->region, "action_channelmenu_groupmenu", UI_EMBOSSP, UI_HELV);
880         uiBlockSetButmFunc(block, do_channelmenu_groupmenu, NULL);
881
882         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
883                                          "Add to Active Group|Shift G", 0, yco-=20, 
884                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
885                                          ACTMENU_CHANNELS_GROUP_ADD_TOACTIVE, "");
886         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
887                                          "Add to New Group|Ctrl Shift G", 0, yco-=20, 
888                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
889                                          ACTMENU_CHANNELS_GROUP_ADD_TONEW, "");
890                 
891         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
892                                         menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
893                                         
894         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
895                                          "Remove From Group|Alt G", 0, yco-=20, 
896                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
897                                          ACTMENU_CHANNELS_GROUP_REMOVE, "");
898                                          
899         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
900                                         menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
901                                         
902         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
903                                          "Synchronise with Armature", 0, yco-=20, 
904                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
905                                          ACTMENU_CHANNELS_GROUP_SYNCPOSE, "");
906
907         uiBlockSetDirection(block, UI_RIGHT);
908         uiTextBoundsBlock(block, 60);
909
910         return block;
911 }
912
913 static void do_channelmenu_settingsmenu(bContext *C, void *arg, int event)
914 {
915         //setflag_action_channels(event);
916 }
917
918 static uiBlock *action_channelmenu_settingsmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
919 {
920         uiBlock *block;
921         short yco= 0, menuwidth=120;
922
923         block= uiBeginBlock(C, handle->region, "action_channelmenu_settingsmenu", UI_EMBOSSP, UI_HELV);
924         uiBlockSetButmFunc(block, do_channelmenu_settingsmenu, NULL);
925
926         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
927                                          "Toggle a Setting|Shift W", 0, yco-=20, 
928                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
929                                          ACTMENU_CHANNELS_SETTINGS_TOGGLE, "");
930                                          
931         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
932                                          "Enable a Setting|Ctrl Shift W", 0, yco-=20, 
933                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
934                                          ACTMENU_CHANNELS_SETTINGS_ENABLE, "");
935                                         
936         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
937                                          "Disable a Setting|Alt W", 0, yco-=20, 
938                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
939                                          ACTMENU_CHANNELS_SETTINGS_DISABLE, "");
940
941         uiBlockSetDirection(block, UI_RIGHT);
942         uiTextBoundsBlock(block, 60);
943
944         return block;
945 }
946
947 static void do_channelmenu(bContext *C, void *arg, int event)
948 {
949         SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
950         
951         if (saction == NULL) return;
952         
953         switch(event)
954         {
955                 case ACTMENU_CHANNELS_OPENLEVELS: /* Unfold selected channels one step */
956                         //openclose_level_action(1);
957                         break;
958                 case ACTMENU_CHANNELS_CLOSELEVELS: /* Fold selected channels one step */
959                         //openclose_level_action(-1);
960                         break;
961                 case ACTMENU_CHANNELS_EXPANDALL: /* Expands all channels */
962                         //expand_all_action();
963                         break;
964                 case ACTMENU_CHANNELS_SHOWACHANS: /* Unfold groups that are hiding selected achans */
965                         //expand_obscuregroups_action();
966                         break;
967                 case ACTMENU_CHANNELS_DELETE: /* Deletes selected channels */
968                         //delete_action_channels();
969                         break;
970         }
971 }
972
973 static uiBlock *action_channelmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
974 {
975         ScrArea *curarea= CTX_wm_area(C);
976         uiBlock *block;
977         short yco= 0, menuwidth=120;
978         
979         block= uiBeginBlock(C, handle->region, "action_channelmenu", UI_EMBOSSP, UI_HELV);
980         uiBlockSetButmFunc(block, do_channelmenu, NULL);
981                 
982         uiDefIconTextBlockBut(block, action_channelmenu_groupmenu, 
983                                                   NULL, ICON_RIGHTARROW_THIN, 
984                                                   "Grouping", 0, yco-=20, 120, 20, "");  
985                                                   
986         uiDefIconTextBlockBut(block, action_channelmenu_posmenu, 
987                                                   NULL, ICON_RIGHTARROW_THIN, 
988                                                   "Ordering", 0, yco-=20, 120, 20, "");
989         
990         uiDefIconTextBlockBut(block, action_channelmenu_settingsmenu, 
991                                                   NULL, ICON_RIGHTARROW_THIN, 
992                                                   "Settings", 0, yco-=20, 120, 20, ""); 
993         
994         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
995                                         menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
996         
997         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
998                         "Delete|X", 0, yco-=20,
999                         menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_CHANNELS_DELETE, "");
1000         
1001         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1002                                         menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1003                 
1004         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1005                         "Toggle Show Hierachy|~", 0, yco-=20,
1006                         menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_CHANNELS_EXPANDALL, "");
1007                         
1008         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1009                         "Show Group-Hidden Channels|Shift ~", 0, yco-=20,
1010                         menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_CHANNELS_SHOWACHANS, "");
1011                         
1012         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1013                         "Expand One Level|Ctrl NumPad+", 0, yco-=20,
1014                         menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_CHANNELS_OPENLEVELS, "");
1015                         
1016         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1017                         "Collapse One Level|Ctrl NumPad-", 0, yco-=20,
1018                         menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_CHANNELS_CLOSELEVELS, "");
1019         
1020         if(curarea->headertype==HEADERTOP) {
1021                 uiBlockSetDirection(block, UI_DOWN);
1022         }
1023         else {
1024                 uiBlockSetDirection(block, UI_TOP);
1025                 uiBlockFlipOrder(block);
1026         }
1027         
1028         uiTextBoundsBlock(block, 50);
1029         uiEndBlock(C, block);
1030         
1031         return block;
1032 }
1033
1034 /* Grease Pencil ---------------------------  */
1035
1036 /* Uses channelmenu functions */
1037 static uiBlock *action_gplayermenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
1038 {
1039         ScrArea *curarea= CTX_wm_area(C);
1040         uiBlock *block;
1041         short yco= 0, menuwidth=120;
1042         
1043         block= uiBeginBlock(C, handle->region, "action_gplayermenu", UI_EMBOSSP, UI_HELV);
1044         uiBlockSetButmFunc(block, do_channelmenu, NULL);
1045                 
1046         uiDefIconTextBlockBut(block, action_channelmenu_settingsmenu, 
1047                                                   NULL, ICON_RIGHTARROW_THIN, 
1048                                                   "Settings", 0, yco-=20, 120, 20, ""); 
1049         
1050         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1051                                         menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1052         
1053         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1054                         "Delete|X", 0, yco-=20,
1055                         menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_CHANNELS_DELETE, "");
1056         
1057         if(curarea->headertype==HEADERTOP) {
1058                 uiBlockSetDirection(block, UI_DOWN);
1059         }
1060         else {
1061                 uiBlockSetDirection(block, UI_TOP);
1062                 uiBlockFlipOrder(block);
1063         }
1064         
1065         uiTextBoundsBlock(block, 50);
1066         uiEndBlock(C, block);
1067         
1068         return block;
1069 }
1070
1071 /* Select menu ---------------------------  */
1072
1073 static void do_selectmenu_columnmenu(bContext *C, void *arg, int event)
1074 {
1075         switch (event) {
1076                 case ACTMENU_SEL_COLUMN_MARKERSBETWEEN:
1077                         //markers_selectkeys_between();
1078                         break;
1079                 case ACTMENU_SEL_COLUMN_KEYS:
1080                         //column_select_action_keys(1);
1081                         break;
1082                 case ACTMENU_SEL_COLUMN_MARKERSCOLUMN:
1083                         //column_select_action_keys(2);
1084                         break;
1085                 case ACTMENU_SEL_COLUMN_CFRA:
1086                         //column_select_action_keys(3);
1087                         break;
1088         }
1089 }
1090
1091 static uiBlock *action_selectmenu_columnmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
1092 {
1093         SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
1094         uiBlock *block;
1095         short yco= 0, menuwidth=120;
1096
1097         block= uiBeginBlock(C, handle->region, "action_selectmenu_columnmenu", UI_EMBOSSP, UI_HELV);
1098         uiBlockSetButmFunc(block, do_selectmenu_columnmenu, NULL);
1099
1100         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1101                                          "On Selected Keys|K", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0,  
1102                                          ACTMENU_SEL_COLUMN_KEYS, "");
1103         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1104                                          "On Current Frame|Ctrl K", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0,  
1105                                          ACTMENU_SEL_COLUMN_CFRA, "");
1106         
1107         if (SACTION_HASMARKERS) {
1108                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1109                                                  "On Selected Markers|Shift K", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 
1110                                                  ACTMENU_SEL_COLUMN_MARKERSCOLUMN, "");
1111                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1112                                                  "Between Selected Markers|Alt K", 0, yco-=20, menuwidth, 19, NULL, 0.0, 0.0, 0, 
1113                                                  ACTMENU_SEL_COLUMN_MARKERSBETWEEN, "");
1114         }
1115         
1116         uiBlockSetDirection(block, UI_RIGHT);
1117         uiTextBoundsBlock(block, 60);
1118
1119         return block;
1120 }
1121
1122 static void do_selectmenu(bContext *C, void *arg, int event)
1123 {
1124         SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
1125         //Key *key;
1126         
1127         if (saction == NULL) return;
1128
1129         //key = get_action_mesh_key();
1130         
1131         switch(event)
1132         {
1133                 case ACTMENU_SEL_BORDER: /* Border Select */
1134                         //borderselect_action();
1135                         break;
1136                         
1137                 case ACTMENU_SEL_BORDERC: /* Border Select */
1138                         //borderselect_actionchannels();
1139                         break;
1140                         
1141                 case ACTMENU_SEL_BORDERM: /* Border Select */
1142                         //borderselect_markers();
1143                         break;
1144                         
1145                 case ACTMENU_SEL_ALL_KEYS: /* Select/Deselect All Keys */
1146                         /*deselect_action_keys(1, 1);
1147                         BIF_undo_push("(De)Select Keys");
1148                         allqueue(REDRAWACTION, 0);
1149                         allqueue(REDRAWNLA, 0);
1150                         allqueue(REDRAWIPO, 0);*/
1151                         break;
1152                         
1153                 case ACTMENU_SEL_ALL_CHAN: /* Select/Deselect All Channels */
1154                         /*deselect_action_channels(1);
1155                         BIF_undo_push("(De)Select Action Channels");
1156                         allqueue(REDRAWVIEW3D, 0);
1157                         allqueue(REDRAWACTION, 0);
1158                         allqueue(REDRAWNLA, 0);
1159                         allqueue(REDRAWIPO, 0);*/
1160                         break;
1161                         
1162                 case ACTMENU_SEL_ALL_MARKERS: /* select/deselect all markers */
1163                         /*deselect_markers(1, 0);
1164                         BIF_undo_push("(De)Select Markers");
1165                         allqueue(REDRAWMARKER, 0);*/
1166                         break;
1167                         
1168                 case ACTMENU_SEL_INVERSE_KEYS: /* invert selection status of keys */
1169                         /*deselect_action_keys(0, 2);
1170                         BIF_undo_push("Inverse Keys");
1171                         allqueue(REDRAWACTION, 0);
1172                         allqueue(REDRAWNLA, 0);
1173                         allqueue(REDRAWIPO, 0);*/
1174                         break;
1175                         
1176                 case ACTMENU_SEL_INVERSE_CHANNELS: /* invert selection status of channels */
1177                         /*deselect_action_channels(2);
1178                         BIF_undo_push("Inverse Action Channels");
1179                         allqueue(REDRAWVIEW3D, 0);
1180                         allqueue(REDRAWACTION, 0);
1181                         allqueue(REDRAWNLA, 0);
1182                         allqueue(REDRAWIPO, 0);*/
1183                         break;
1184                         
1185                 case ACTMENU_SEL_INVERSE_MARKERS: /* invert selection of markers */
1186                         /*deselect_markers(0, 2);
1187                         BIF_undo_push("Inverse Action Channels");
1188                         allqueue(REDRAWMARKER, 0);*/
1189                         break;
1190                         
1191                 case ACTMENU_SEL_LEFTKEYS:
1192                         //selectkeys_leftright(1, SELECT_REPLACE);
1193                         break;
1194                         
1195                 case ACTMENU_SEL_RIGHTKEYS:
1196                         //selectkeys_leftright(0, SELECT_REPLACE);
1197                         break;
1198         }
1199 }
1200
1201 static uiBlock *action_selectmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
1202 {
1203         ScrArea *curarea= CTX_wm_area(C);
1204         SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
1205         uiBlock *block;
1206         short yco= 0, menuwidth=120;
1207         
1208         block= uiBeginBlock(C, handle->region, "action_selectmenu", UI_EMBOSSP, UI_HELV);
1209         uiBlockSetButmFunc(block, do_selectmenu, NULL);
1210
1211         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1212                                          "Border Select Keys|B", 0, yco-=20, 
1213                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
1214                                          ACTMENU_SEL_BORDER, "");
1215         if (SACTION_HASMARKERS) {
1216                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1217                                                  "Border Select Markers|Ctrl B", 0, yco-=20, 
1218                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
1219                                                  ACTMENU_SEL_BORDERM, "");
1220         }
1221         if (saction->mode != SACTCONT_SHAPEKEY) {
1222                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1223                                                  "Border Select Channels|B", 0, yco-=20, 
1224                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
1225                                                  ACTMENU_SEL_BORDERC, "");
1226         }
1227                                          
1228         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1229                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1230                          
1231         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1232                                          "Select/Deselect All Keys|A", 0, yco-=20, 
1233                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
1234                                          ACTMENU_SEL_ALL_KEYS, "");
1235         if (SACTION_HASMARKERS) {
1236                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1237                                                  "Select/Deselect All Markers|Ctrl A", 0, yco-=20, 
1238                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
1239                                                  ACTMENU_SEL_ALL_MARKERS, "");
1240         }
1241         if (saction->mode != SACTCONT_SHAPEKEY) {
1242                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1243                                                  "Select/Deselect All Channels|A", 0, yco-=20, 
1244                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
1245                                                  ACTMENU_SEL_ALL_CHAN, "");
1246         }
1247                                          
1248         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1249                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1250
1251         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1252                                          "Inverse Keys|Ctrl I", 0, yco-=20, 
1253                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
1254                                          ACTMENU_SEL_INVERSE_KEYS, "");
1255         if (SACTION_HASMARKERS) {
1256                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1257                                                  "Inverse Markers|Ctrl Shift I", 0, yco-=20, 
1258                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
1259                                                  ACTMENU_SEL_INVERSE_MARKERS, "");
1260         }
1261         if (saction->mode != SACTCONT_SHAPEKEY) {
1262                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1263                                                  "Inverse All Channels|Ctrl I", 0, yco-=20, 
1264                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
1265                                                  ACTMENU_SEL_INVERSE_CHANNELS, "");
1266         }
1267                 
1268         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1269                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1270                          
1271         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1272                                          "Back In Time|Alt RMB", 0, yco-=20, 
1273                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
1274                                          ACTMENU_SEL_LEFTKEYS, "");
1275                                                                  
1276         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1277                                          "Ahead In Time|Alt RMB", 0, yco-=20, 
1278                                          menuwidth, 19, NULL, 0.0, 0.0, 0, 
1279                                          ACTMENU_SEL_RIGHTKEYS, "");             
1280                          
1281         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1282                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1283                          
1284         uiDefIconTextBlockBut(block, action_selectmenu_columnmenu, 
1285                                                   NULL, ICON_RIGHTARROW_THIN, "Column Select Keys", 0, yco-=20, 120, 20, "");
1286         
1287         if(curarea->headertype==HEADERTOP) {
1288                 uiBlockSetDirection(block, UI_DOWN);
1289         }
1290         else {
1291                 uiBlockSetDirection(block, UI_TOP);
1292                 uiBlockFlipOrder(block);
1293         }
1294         
1295         uiTextBoundsBlock(block, 50);
1296         uiEndBlock(C, block);
1297         
1298         return block;
1299 }
1300
1301 /* View menu ---------------------------  */
1302
1303 static void do_viewmenu(bContext *C, void *arg, int event)
1304 {
1305         switch(event) {
1306                 case ACTMENU_VIEW_CENTERVIEW: /* Center View to Current Frame */
1307                         //center_currframe();
1308                         break;
1309                 case ACTMENU_VIEW_AUTOUPDATE: /* Update Automatically */
1310                         /*if (BTST(G.saction->lock, 0)) 
1311                                 G.saction->lock = BCLR(G.saction->lock, 0);
1312                         else 
1313                                 G.saction->lock = BSET(G.saction->lock, 0);*/
1314                         break;
1315                 case ACTMENU_VIEW_PLAY3D: /* Play Back Animation */
1316                         //play_anim(0);
1317                         break;
1318                 case ACTMENU_VIEW_PLAYALL: /* Play Back Animation in All */
1319                         //play_anim(1);
1320                         break;  
1321                 case ACTMENU_VIEW_ALL: /* View All */
1322                         //do_action_buttons(B_ACTHOME);
1323                         break;
1324                 case ACTMENU_VIEW_LOCK:
1325                         /*G.v2d->flag ^= V2D_VIEWLOCK;
1326                         if (G.v2d->flag & V2D_VIEWLOCK)
1327                                 view2d_do_locks(curarea, 0);*/
1328                         break;
1329                 case ACTMENU_VIEW_SLIDERS:       /* Show sliders (when applicable) */
1330                         //G.saction->flag ^= SACTION_SLIDERS;
1331                         break;
1332                 case ACTMENU_VIEW_MAXIMIZE: /* Maximize Window */
1333                         /* using event B_FULL */
1334                         break;
1335                 case ACTMENU_VIEW_NEXTMARKER: /* Jump to next marker */
1336                         //nextprev_marker(1);
1337                         break;
1338                 case ACTMENU_VIEW_PREVMARKER: /* Jump to previous marker */
1339                         //nextprev_marker(-1);
1340                         break;
1341                 case ACTMENU_VIEW_TIME: /* switch between frames and seconds display */
1342                         //G.saction->flag ^= SACTION_DRAWTIME;
1343                         break;
1344                 case ACTMENU_VIEW_NOHIDE: /* Show hidden channels */
1345                         //G.saction->flag ^= SACTION_NOHIDE;
1346                         break;
1347                 case ACTMENU_VIEW_NEXTKEYFRAME: /* Jump to next keyframe */
1348                         //nextprev_action_keyframe(1);
1349                         break;
1350                 case ACTMENU_VIEW_PREVKEYFRAME: /* Jump to previous keyframe */
1351                         //nextprev_action_keyframe(-1);
1352                         break;
1353                 case ACTMENU_VIEW_TRANSDELDUPS: /* Don't delete duplicate/overlapping keyframes after transform */
1354                         //G.saction->flag ^= SACTION_NOTRANSKEYCULL;
1355                         break;
1356                 case ACTMENU_VIEW_HORIZOPTIMISE: /* Include keyframes not in view (horizontally) when preparing to draw */
1357                         //G.saction->flag ^= SACTION_HORIZOPTIMISEON;
1358                         break;
1359                 case ACTMENU_VIEW_GCOLORS: /* Draw grouped-action channels using its group's color */
1360                         //G.saction->flag ^= SACTION_NODRAWGCOLORS;
1361                         break;
1362                 case ACTMENU_VIEW_PREVRANGESET: /* Set preview range */
1363                         //anim_previewrange_set();
1364                         break;
1365                 case ACTMENU_VIEW_PREVRANGECLEAR: /* Clear preview range */
1366                         //anim_previewrange_clear();
1367                         break;
1368                 case ACTMENU_VIEW_PREVRANGEAUTO: /* Auto preview-range length */
1369                         //action_previewrange_set(G.saction->action);
1370                         break;
1371         }
1372 }
1373
1374 static uiBlock *action_viewmenu(bContext *C, uiMenuBlockHandle *handle, void *arg_unused)
1375 {
1376         ScrArea *curarea= CTX_wm_area(C);
1377         SpaceAction *saction= (SpaceAction*)CTX_wm_space_data(C);
1378         View2D *v2d= UI_view2d_fromcontext_rwin(C);
1379         uiBlock *block;
1380         short yco= 0, menuwidth=120;
1381         
1382         block= uiBeginBlock(C, handle->region, "viewmenu", UI_EMBOSSP, UI_HELV);
1383         uiBlockSetButmFunc(block, do_viewmenu, NULL);
1384         
1385         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1386                                          "Center View to Current Frame|C", 0, yco-=20, 
1387                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 
1388                                          ACTMENU_VIEW_CENTERVIEW, "");
1389                 
1390         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1391                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1392                          
1393         if (saction->flag & SACTION_DRAWTIME) {
1394                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1395                                                 "Show Frames|Ctrl T", 0, yco-=20, 
1396                                                 menuwidth, 19, NULL, 0.0, 0.0, 1, 
1397                                                 ACTMENU_VIEW_TIME, "");
1398         }
1399         else {
1400                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1401                                                 "Show Seconds|Ctrl T", 0, yco-=20, 
1402                                                 menuwidth, 19, NULL, 0.0, 0.0, 1, 
1403                                                 ACTMENU_VIEW_TIME, "");
1404         }
1405         
1406         uiDefBut(block, SEPR, 0, "",        0, yco-=6, menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1407         
1408         if (saction->mode == SACTCONT_GPENCIL) {
1409                         // this option may get removed in future
1410                 uiDefIconTextBut(block, BUTM, 1, (saction->flag & SACTION_HORIZOPTIMISEON)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, 
1411                                                  "Cull Out-of-View Keys (Time)|", 0, yco-=20, 
1412                                                  menuwidth, 19, NULL, 0.0, 0.0, 1, 
1413                                                  ACTMENU_VIEW_HORIZOPTIMISE, "");
1414         }
1415         else {
1416                 uiDefIconTextBut(block, BUTM, 1, (saction->flag & SACTION_SLIDERS)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, 
1417                                                  "Show Sliders|", 0, yco-=20, 
1418                                                  menuwidth, 19, NULL, 0.0, 0.0, 1, 
1419                                                  ACTMENU_VIEW_SLIDERS, "");
1420                                                  
1421                 uiDefIconTextBut(block, BUTM, 1, (saction->flag & SACTION_NOHIDE)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, 
1422                                                  "Show Hidden Channels|", 0, yco-=20, 
1423                                                  menuwidth, 19, NULL, 0.0, 0.0, 1, 
1424                                                  ACTMENU_VIEW_NOHIDE, "");
1425                                                  
1426                 uiDefIconTextBut(block, BUTM, 1, (saction->flag & SACTION_NODRAWGCOLORS)?ICON_CHECKBOX_DEHLT:ICON_CHECKBOX_HLT, 
1427                                                  "Use Group Colors|", 0, yco-=20, 
1428                                                  menuwidth, 19, NULL, 0.0, 0.0, 1, 
1429                                                  ACTMENU_VIEW_GCOLORS, "");
1430                                                  
1431                         // this option may get removed in future
1432                 uiDefIconTextBut(block, BUTM, 1, (saction->flag & SACTION_HORIZOPTIMISEON)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, 
1433                                                  "Cull Out-of-View Keys (Time)|", 0, yco-=20, 
1434                                                  menuwidth, 19, NULL, 0.0, 0.0, 1, 
1435                                                  ACTMENU_VIEW_HORIZOPTIMISE, "");
1436                 
1437                 uiDefIconTextBut(block, BUTM, 1, (saction->flag & SACTION_NOTRANSKEYCULL)?ICON_CHECKBOX_DEHLT:ICON_CHECKBOX_HLT, 
1438                                                  "AutoMerge Keyframes|", 0, yco-=20, 
1439                                                  menuwidth, 19, NULL, 0.0, 0.0, 1, 
1440                                                  ACTMENU_VIEW_TRANSDELDUPS, "");
1441         }       
1442         
1443                 
1444         uiDefIconTextBut(block, BUTM, 1, (v2d->flag & V2D_VIEWSYNC_SCREEN_TIME)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, 
1445                                          "Lock Time to Other Windows|", 0, yco-=20, 
1446                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 
1447                                          ACTMENU_VIEW_LOCK, "");
1448                                          
1449         /*uiDefIconTextBut(block, BUTM, 1, BTST(saction->lock, 0)?ICON_CHECKBOX_HLT:ICON_CHECKBOX_DEHLT, 
1450                                          "Update Automatically|", 0, yco-=20, 
1451                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 
1452                                          ACTMENU_VIEW_AUTOUPDATE, "");*/
1453
1454         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1455                                         menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1456                 
1457         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1458                                 "Jump To Next Marker|PageUp", 0, yco-=20,
1459                                 menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_VIEW_NEXTMARKER, "");
1460         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1461                                 "Jump To Prev Marker|PageDown", 0, yco-=20, 
1462                                 menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_VIEW_PREVMARKER, "");
1463                                 
1464         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1465                                 "Jump To Next Keyframe|Ctrl PageUp", 0, yco-=20,
1466                                 menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_VIEW_NEXTKEYFRAME, "");
1467         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1468                                 "Jump To Prev Keyframe|Ctrl PageDown", 0, yco-=20, 
1469                                 menuwidth, 19, NULL, 0.0, 0.0, 0, ACTMENU_VIEW_PREVKEYFRAME, "");
1470                                          
1471         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1472                                         menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1473                         
1474         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1475                                          "Play Back Animation|Alt A", 0, yco-=20, 
1476                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 
1477                                          ACTMENU_VIEW_PLAY3D, "");
1478         //uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1479         //                               "Play Back Animation in 3D View|Alt Shift A", 0, yco-=20,
1480         //                               menuwidth, 19, NULL, 0.0, 0.0, 1, 
1481         //                               ACTMENU_VIEW_PLAYALL, "");
1482         
1483         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1484                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1485                 
1486         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1487                                          "Set Preview Range|Ctrl P", 0, yco-=20, 
1488                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 
1489                                          ACTMENU_VIEW_PREVRANGESET, "");
1490         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1491                                          "Clear Preview Range|Alt P", 0, yco-=20,
1492                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 
1493                                          ACTMENU_VIEW_PREVRANGECLEAR, "");
1494                 
1495         if ((saction->mode == SACTCONT_ACTION) && (saction->action)) {
1496                 uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1497                                          "Preview Range from Action Length|Ctrl Alt P", 0, yco-=20, 
1498                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 
1499                                          ACTMENU_VIEW_PREVRANGEAUTO, "");
1500         }
1501                 
1502         uiDefBut(block, SEPR, 0, "", 0, yco-=6, 
1503                          menuwidth, 6, NULL, 0.0, 0.0, 0, 0, "");
1504         
1505         uiDefIconTextBut(block, BUTM, 1, ICON_BLANK1, 
1506                                          "View All|Home", 0, yco-=20, 
1507                                          menuwidth, 19, NULL, 0.0, 0.0, 1, 
1508                                          ACTMENU_VIEW_ALL, "");
1509         
1510 /*      if (!curarea->full) 
1511                 uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, 
1512                                                  "Maximize Window|Ctrl UpArrow", 0, yco-=20, 
1513                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
1514                                                  ACTMENU_VIEW_MAXIMIZE, "");
1515         else 
1516                 uiDefIconTextBut(block, BUTM, B_FULL, ICON_BLANK1, 
1517                                                  "Tile Window|Ctrl DownArrow", 0, yco-=20, 
1518                                                  menuwidth, 19, NULL, 0.0, 0.0, 0, 
1519                                                  ACTMENU_VIEW_MAXIMIZE, "");
1520 */
1521         
1522         if (curarea->headertype==HEADERTOP) {
1523                 uiBlockSetDirection(block, UI_DOWN);
1524         }
1525         else {
1526                 uiBlockSetDirection(block, UI_TOP);
1527                 uiBlockFlipOrder(block);
1528         }
1529         
1530         uiTextBoundsBlock(block, 50);
1531         uiEndBlock(C, block);
1532         
1533         return block;
1534 }
1535
1536 /* ************************ header area region *********************** */
1537
1538 static void do_action_buttons(bContext *C, void *arg, int event)
1539 {
1540         switch(event) {
1541                 case B_REDR:
1542                         ED_region_tag_redraw(CTX_wm_region(C));
1543                         break;
1544                         
1545                 case B_ACTCOPYKEYS:
1546                         WM_operator_name_call(C, "ACT_OT_keyframes_copy", WM_OP_EXEC_REGION_WIN, NULL);
1547                         break;
1548                 case B_ACTPASTEKEYS:
1549                         WM_operator_name_call(C, "ACT_OT_keyframes_paste", WM_OP_EXEC_REGION_WIN, NULL);
1550                         break;
1551         }
1552 }
1553
1554 void action_header_buttons(const bContext *C, ARegion *ar)
1555 {
1556         ScrArea *sa= CTX_wm_area(C);
1557         SpaceAction *saction= (SpaceAction *)CTX_wm_space_data(C);
1558         bAnimContext ac;
1559         uiBlock *block;
1560         int xco, yco= 3, xmax;
1561         
1562         block= uiBeginBlock(C, ar, "header buttons", UI_EMBOSS, UI_HELV);
1563         uiBlockSetHandleFunc(block, do_action_buttons, NULL);
1564         
1565         xco= ED_area_header_standardbuttons(C, block, yco);
1566         
1567         uiBlockSetEmboss(block, UI_EMBOSS);
1568         
1569         /* get context... (also syncs data) */
1570         ANIM_animdata_get_context(C, &ac);
1571         
1572         if ((sa->flag & HEADER_NO_PULLDOWN)==0) {
1573                 /* pull down menus */
1574                 uiBlockSetEmboss(block, UI_EMBOSSP);
1575                 
1576                 xmax= GetButStringLength("View");
1577                 uiDefPulldownBut(block, action_viewmenu, CTX_wm_area(C), 
1578                                           "View", xco, yco-2, xmax-3, 24, "");
1579                 xco+= xmax;
1580                 
1581                 xmax= GetButStringLength("Select");
1582                 uiDefPulldownBut(block, action_selectmenu, CTX_wm_area(C), 
1583                                           "Select", xco, yco-2, xmax-3, 24, "");
1584                 xco+= xmax;
1585                 
1586                 if ( (saction->mode == SACTCONT_DOPESHEET) ||
1587                          ((saction->action) && (saction->mode==SACTCONT_ACTION)) ) 
1588                 {
1589                         xmax= GetButStringLength("Channel");
1590                         uiDefPulldownBut(block, action_channelmenu, CTX_wm_area(C), 
1591                                                   "Channel", xco, yco-2, xmax-3, 24, "");
1592                         xco+= xmax;
1593                 }
1594                 else if (saction->mode==SACTCONT_GPENCIL) {
1595                         xmax= GetButStringLength("Channel");
1596                         uiDefPulldownBut(block, action_gplayermenu, CTX_wm_area(C), 
1597                                                   "Channel", xco, yco-2, xmax-3, 24, "");
1598                         xco+= xmax;
1599                 }
1600                 
1601                 xmax= GetButStringLength("Marker");
1602                 uiDefPulldownBut(block, action_markermenu, CTX_wm_area(C), 
1603                                           "Marker", xco, yco-2, xmax-3, 24, "");
1604                 xco+= xmax;
1605                 
1606                 if (saction->mode == SACTCONT_GPENCIL) {
1607                         xmax= GetButStringLength("Frame");
1608                         uiDefPulldownBut(block, action_framemenu, CTX_wm_area(C), 
1609                                                   "Frame", xco, yco-2, xmax-3, 24, "");
1610                         xco+= xmax;
1611                 }
1612                 else {
1613                         xmax= GetButStringLength("Key");
1614                         uiDefPulldownBut(block, action_keymenu, CTX_wm_area(C), 
1615                                                   "Key", xco, yco-2, xmax-3, 24, "");
1616                         xco+= xmax;
1617                 }
1618         }
1619
1620         uiBlockSetEmboss(block, UI_EMBOSS);
1621         
1622         /* MODE SELECTOR */
1623         uiDefButC(block, MENU, B_REDR, 
1624                         "Editor Mode %t|DopeSheet %x3|Action Editor %x0|ShapeKey Editor %x1|Grease Pencil %x2", 
1625                         xco,yco,90,YIC, &saction->mode, 0, 1, 0, 0, 
1626                         "Editing modes for this editor");
1627         
1628         
1629         xco += (90 + 8);
1630         
1631         if (ac.data) {
1632                 /* MODE-DEPENDENT DRAWING */
1633                 if (saction->mode == SACTCONT_DOPESHEET) {
1634                         /* FILTERING OPTIONS */
1635                         xco -= 10;
1636                         
1637                         //uiBlockBeginAlign(block);
1638                                 uiDefIconButBitI(block, TOG, ADS_FILTER_ONLYSEL, B_REDR, ICON_RESTRICT_SELECT_OFF,      (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Only display selected Objects");
1639                         //uiBlockEndAlign(block);
1640                         xco += 5;
1641                         
1642                         uiBlockBeginAlign(block);
1643                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOOBJ, B_REDR, ICON_OBJECT,    (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Non-Armature Objects");
1644                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOARM, B_REDR, ICON_ARMATURE,  (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Armature Objects");
1645                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOSHAPEKEYS, B_REDR, ICON_EDIT,        (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display ShapeKeys");
1646                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOMAT, B_REDR, ICON_MATERIAL,  (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Materials");
1647                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOLAM, B_REDR, ICON_LAMP,      (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Lamps");
1648                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOCAM, B_REDR, ICON_CAMERA,    (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Cameras");
1649                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOCUR, B_REDR, ICON_CURVE,     (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Curves");
1650                         uiBlockEndAlign(block);
1651                         xco += 5;
1652                         
1653                         uiBlockBeginAlign(block);               
1654                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOIPOS, B_REDR, ICON_IPO,      (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Object IPO's");
1655                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOACTS, B_REDR, ICON_ACTION,   (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Actions");
1656                                 uiDefIconButBitI(block, TOGN, ADS_FILTER_NOCONSTRAINTS, B_REDR, ICON_CONSTRAINT,        (short)(xco+=XIC),yco,XIC,YIC, &(saction->ads.filterflag), 0, 0, 0, 0, "Display Object Constraints");
1657                         uiBlockEndAlign(block);
1658                         xco += 30;
1659                 }
1660                 else if (saction->mode == SACTCONT_ACTION) { // not too appropriate for shapekeys atm...
1661                         /* NAME ETC */
1662                                 // XXX missing stuff here!
1663                         //ob= OBACT;
1664                         //from = (ID *)ob;
1665                         
1666                         //xco= std_libbuttons(block, xco, 0, B_ACTPIN, saction->pin, 
1667                         //                                      B_ACTIONBROWSE, ID_AC, 0, (ID*)saction->action, 
1668                         //                                      from, &(saction->actnr), B_ACTALONE, 
1669                         //                                      B_ACTLOCAL, B_ACTIONDELETE, 0, B_KEEPDATA);     
1670                         
1671                         //uiClearButLock();
1672                         
1673                         xco += 8;
1674                 }
1675                 
1676                 /* COPY PASTE */
1677                 uiBlockBeginAlign(block);
1678                 uiDefIconBut(block, BUT, B_ACTCOPYKEYS, ICON_COPYDOWN,  xco,yco,XIC,YIC, 0, 0, 0, 0, 0, "Copies the selected keyframes from the selected channel(s) to the buffer");
1679                 uiDefIconBut(block, BUT, B_ACTPASTEKEYS, ICON_PASTEDOWN,        xco+=XIC,yco,XIC,YIC, 0, 0, 0, 0, 0, "Pastes the keyframes from the buffer");
1680                 uiBlockEndAlign(block);
1681                 xco += (XIC + 8);
1682                 
1683                 /* draw AUTOSNAP */
1684                 if (saction->mode != SACTCONT_GPENCIL) {
1685                         if (saction->flag & SACTION_DRAWTIME) {
1686                                 uiDefButC(block, MENU, B_REDR,
1687                                                 "Auto-Snap Keyframes %t|No Snap %x0|Second Step %x1|Nearest Second %x2|Nearest Marker %x3", 
1688                                                 xco,yco,70,YIC, &(saction->autosnap), 0, 1, 0, 0, 
1689                                                 "Auto-snapping mode for keyframes when transforming");
1690                         }
1691                         else {
1692                                 uiDefButC(block, MENU, B_REDR, 
1693                                                 "Auto-Snap Keyframes %t|No Snap %x0|Frame Step %x1|Nearest Frame %x2|Nearest Marker %x3", 
1694                                                 xco,yco,70,YIC, &(saction->autosnap), 0, 1, 0, 0, 
1695                                                 "Auto-snapping mode for keyframes when transforming");
1696                         }
1697                         
1698                         xco += (70 + 8);
1699                 }
1700                 
1701                 /* draw LOCK */
1702                         // XXX this feature is probably not relevant anymore!
1703                 //uiDefIconButS(block, ICONTOG, B_LOCK, ICON_UNLOCKED,  xco, yco, XIC, YIC, 
1704                 //                        &(saction->lock), 0, 0, 0, 0, 
1705                 //                        "Updates other affected window spaces automatically "
1706                 //                        "to reflect changes in real time");
1707         }
1708
1709         /* always as last  */
1710         UI_view2d_totRect_set(&ar->v2d, xco+XIC+80, (int)(ar->v2d.tot.ymax-ar->v2d.tot.ymin));
1711         
1712         uiEndBlock(C, block);
1713         uiDrawBlock(C, block);
1714 }
1715
1716