Merge branch 'master' into blender2.8
[blender.git] / source / blender / editors / space_action / space_action.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version. 
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2008 Blender Foundation.
19  * All rights reserved.
20  *
21  * 
22  * Contributor(s): Blender Foundation
23  *
24  * ***** END GPL LICENSE BLOCK *****
25  */
26
27 /** \file blender/editors/space_action/space_action.c
28  *  \ingroup spaction
29  */
30
31
32 #include <string.h>
33 #include <stdio.h>
34
35 #include "DNA_action_types.h"
36 #include "DNA_group_types.h"
37 #include "DNA_scene_types.h"
38
39 #include "MEM_guardedalloc.h"
40
41 #include "BLI_blenlib.h"
42 #include "BLI_math.h"
43 #include "BLI_utildefines.h"
44
45 #include "BKE_context.h"
46 #include "BKE_screen.h"
47
48 #include "BIF_gl.h"
49
50 #include "WM_api.h"
51 #include "WM_types.h"
52
53 #include "UI_resources.h"
54 #include "UI_view2d.h"
55
56 #include "ED_space_api.h"
57 #include "ED_screen.h"
58 #include "ED_anim_api.h"
59 #include "ED_markers.h"
60
61 #include "action_intern.h"  /* own include */
62
63 /* ******************** manage regions ********************* */
64
65 ARegion *action_has_buttons_region(ScrArea *sa)
66 {
67         ARegion *ar, *arnew;
68         
69         ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
70         if (ar) return ar;
71         
72         /* add subdiv level; after main */
73         ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
74         
75         /* is error! */
76         if (ar == NULL) return NULL;
77         
78         arnew = MEM_callocN(sizeof(ARegion), "buttons for action");
79         
80         BLI_insertlinkafter(&sa->regionbase, ar, arnew);
81         arnew->regiontype = RGN_TYPE_UI;
82         arnew->alignment = RGN_ALIGN_RIGHT;
83         
84         arnew->flag = RGN_FLAG_HIDDEN;
85         
86         return arnew;
87 }
88
89 /* ******************** default callbacks for action space ***************** */
90
91 static SpaceLink *action_new(const bContext *C)
92 {
93         Scene *scene = CTX_data_scene(C);
94         ScrArea *sa = CTX_wm_area(C);
95         SpaceAction *saction;
96         ARegion *ar;
97         
98         saction = MEM_callocN(sizeof(SpaceAction), "initaction");
99         saction->spacetype = SPACE_ACTION;
100         
101         saction->autosnap = SACTSNAP_FRAME;
102         saction->mode = SACTCONT_DOPESHEET;
103         
104         saction->ads.filterflag |= ADS_FILTER_SUMMARY;
105         
106         /* header */
107         ar = MEM_callocN(sizeof(ARegion), "header for action");
108         
109         BLI_addtail(&saction->regionbase, ar);
110         ar->regiontype = RGN_TYPE_HEADER;
111         ar->alignment = RGN_ALIGN_BOTTOM;
112         
113         /* channel list region */
114         ar = MEM_callocN(sizeof(ARegion), "channel region for action");
115         BLI_addtail(&saction->regionbase, ar);
116         ar->regiontype = RGN_TYPE_CHANNELS;
117         ar->alignment = RGN_ALIGN_LEFT;
118         
119         /* only need to set scroll settings, as this will use 'listview' v2d configuration */
120         ar->v2d.scroll = V2D_SCROLL_BOTTOM;
121         ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
122         
123         /* ui buttons */
124         ar = MEM_callocN(sizeof(ARegion), "buttons region for action");
125         
126         BLI_addtail(&saction->regionbase, ar);
127         ar->regiontype = RGN_TYPE_UI;
128         ar->alignment = RGN_ALIGN_RIGHT;
129         ar->flag = RGN_FLAG_HIDDEN;
130         
131         /* main region */
132         ar = MEM_callocN(sizeof(ARegion), "main region for action");
133         
134         BLI_addtail(&saction->regionbase, ar);
135         ar->regiontype = RGN_TYPE_WINDOW;
136         
137         ar->v2d.tot.xmin = (float)(SFRA - 10);
138         ar->v2d.tot.ymin = (float)(-sa->winy) / 3.0f;
139         ar->v2d.tot.xmax = (float)(EFRA + 10);
140         ar->v2d.tot.ymax = 0.0f;
141         
142         ar->v2d.cur = ar->v2d.tot;
143         
144         ar->v2d.min[0] = 0.0f;
145         ar->v2d.min[1] = 0.0f;
146         
147         ar->v2d.max[0] = MAXFRAMEF;
148         ar->v2d.max[1] = FLT_MAX;
149
150         ar->v2d.minzoom = 0.01f;
151         ar->v2d.maxzoom = 50;
152         ar->v2d.scroll = (V2D_SCROLL_BOTTOM | V2D_SCROLL_SCALE_HORIZONTAL);
153         ar->v2d.scroll |= (V2D_SCROLL_RIGHT);
154         ar->v2d.keepzoom = V2D_LOCKZOOM_Y;
155         ar->v2d.keepofs = V2D_KEEPOFS_Y;
156         ar->v2d.align = V2D_ALIGN_NO_POS_Y;
157         ar->v2d.flag = V2D_VIEWSYNC_AREA_VERTICAL;
158         
159         return (SpaceLink *)saction;
160 }
161
162 /* not spacelink itself */
163 static void action_free(SpaceLink *UNUSED(sl))
164 {       
165 //      SpaceAction *saction = (SpaceAction *) sl;
166 }
167
168
169 /* spacetype; init callback */
170 static void action_init(struct wmWindowManager *UNUSED(wm), ScrArea *sa)
171 {
172         SpaceAction *saction = sa->spacedata.first;
173         saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
174 }
175
176 static SpaceLink *action_duplicate(SpaceLink *sl)
177 {
178         SpaceAction *sactionn = MEM_dupallocN(sl);
179         
180         /* clear or remove stuff from old */
181         
182         return (SpaceLink *)sactionn;
183 }
184
185
186
187 /* add handlers, stuff you only do once or on area/region changes */
188 static void action_main_region_init(wmWindowManager *wm, ARegion *ar)
189 {
190         wmKeyMap *keymap;
191         
192         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
193         
194         /* own keymap */
195         keymap = WM_keymap_find(wm->defaultconf, "Dopesheet", SPACE_ACTION, 0);
196         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
197         keymap = WM_keymap_find(wm->defaultconf, "Dopesheet Generic", SPACE_ACTION, 0);
198         WM_event_add_keymap_handler(&ar->handlers, keymap);
199 }
200
201 static void action_main_region_draw(const bContext *C, ARegion *ar)
202 {
203         /* draw entirely, view changes should be handled here */
204         SpaceAction *saction = CTX_wm_space_action(C);
205         bAnimContext ac;
206         View2D *v2d = &ar->v2d;
207         View2DGrid *grid;
208         View2DScrollers *scrollers;
209         short unit = 0, flag = 0;
210         
211         /* clear and setup matrix */
212         UI_ThemeClearColor(TH_BACK);
213         glClear(GL_COLOR_BUFFER_BIT);
214         
215         UI_view2d_view_ortho(v2d);
216         
217         /* time grid */
218         unit = (saction->flag & SACTION_DRAWTIME) ? V2D_UNIT_SECONDS : V2D_UNIT_FRAMES;
219         grid = UI_view2d_grid_calc(CTX_data_scene(C), v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY, ar->winx, ar->winy);
220         UI_view2d_grid_draw(v2d, grid, V2D_GRIDLINES_ALL);
221         UI_view2d_grid_free(grid);
222         
223         ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
224
225         /* data */
226         if (ANIM_animdata_get_context(C, &ac)) {
227                 draw_channel_strips(&ac, saction, ar);
228         }
229         
230         /* current frame */
231         if (saction->flag & SACTION_DRAWTIME) flag |= DRAWCFRA_UNIT_SECONDS;
232         if ((saction->flag & SACTION_NODRAWCFRANUM) == 0) flag |= DRAWCFRA_SHOW_NUMBOX;
233         ANIM_draw_cfra(C, v2d, flag);
234         
235         /* markers */
236         UI_view2d_view_orthoSpecial(ar, v2d, 1);
237         
238         flag = ((ac.markers && (ac.markers != &ac.scene->markers)) ? DRAW_MARKERS_LOCAL : 0) | DRAW_MARKERS_MARGIN;
239         ED_markers_draw(C, flag);
240         
241         /* preview range */
242         UI_view2d_view_ortho(v2d);
243         ANIM_draw_previewrange(C, v2d, 0);
244
245         /* callback */
246         UI_view2d_view_ortho(v2d);
247         ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
248         
249         /* reset view matrix */
250         UI_view2d_view_restore(C);
251         
252         /* scrollers */
253         scrollers = UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
254         UI_view2d_scrollers_draw(C, v2d, scrollers);
255         UI_view2d_scrollers_free(scrollers);
256 }
257
258 /* add handlers, stuff you only do once or on area/region changes */
259 static void action_channel_region_init(wmWindowManager *wm, ARegion *ar)
260 {
261         wmKeyMap *keymap;
262         
263         /* ensure the 2d view sync works - main region has bottom scroller */
264         ar->v2d.scroll = V2D_SCROLL_BOTTOM;
265         
266         UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_LIST, ar->winx, ar->winy);
267         
268         /* own keymap */
269         keymap = WM_keymap_find(wm->defaultconf, "Animation Channels", 0, 0);
270         WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
271         
272         keymap = WM_keymap_find(wm->defaultconf, "Dopesheet Generic", SPACE_ACTION, 0);
273         WM_event_add_keymap_handler(&ar->handlers, keymap);
274 }
275
276 static void action_channel_region_draw(const bContext *C, ARegion *ar)
277 {
278         /* draw entirely, view changes should be handled here */
279         bAnimContext ac;
280         View2D *v2d = &ar->v2d;
281         
282         /* clear and setup matrix */
283         UI_ThemeClearColor(TH_BACK);
284         glClear(GL_COLOR_BUFFER_BIT);
285         
286         UI_view2d_view_ortho(v2d);
287         
288         /* data */
289         if (ANIM_animdata_get_context(C, &ac)) {
290                 draw_channel_names((bContext *)C, &ac, ar);
291         }
292         
293         /* reset view matrix */
294         UI_view2d_view_restore(C);
295         
296         /* no scrollers here */
297 }
298
299
300 /* add handlers, stuff you only do once or on area/region changes */
301 static void action_header_region_init(wmWindowManager *UNUSED(wm), ARegion *ar)
302 {
303         ED_region_header_init(ar);
304 }
305
306 static void action_header_region_draw(const bContext *C, ARegion *ar)
307 {
308         ED_region_header(C, ar);
309 }
310
311 static void action_channel_region_listener(
312         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
313         wmNotifier *wmn, const Scene *UNUSED(scene))
314 {
315         /* context changes */
316         switch (wmn->category) {
317                 case NC_ANIMATION:
318                         ED_region_tag_redraw(ar);
319                         break;
320                 case NC_SCENE:
321                         switch (wmn->data) {
322                                 case ND_OB_ACTIVE:
323                                 case ND_FRAME:
324                                         ED_region_tag_redraw(ar);
325                                         break;
326                         }
327                         break;
328                 case NC_OBJECT:
329                         switch (wmn->data) {
330                                 case ND_BONE_ACTIVE:
331                                 case ND_BONE_SELECT:
332                                 case ND_KEYS:
333                                         ED_region_tag_redraw(ar);
334                                         break;
335                                 case ND_MODIFIER:
336                                         if (wmn->action == NA_RENAME)
337                                                 ED_region_tag_redraw(ar);
338                                         break;
339                         }
340                         break;
341                 case NC_GPENCIL:
342                         if (ELEM(wmn->action, NA_RENAME, NA_SELECTED))
343                                 ED_region_tag_redraw(ar);
344                         break;
345                 case NC_ID:
346                         if (wmn->action == NA_RENAME)
347                                 ED_region_tag_redraw(ar);
348                         break;
349                 default:
350                         if (wmn->data == ND_KEYS)
351                                 ED_region_tag_redraw(ar);
352                         break;
353         }
354 }
355
356 static void action_main_region_listener(
357         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
358         wmNotifier *wmn, const Scene *UNUSED(scene))
359 {
360         /* context changes */
361         switch (wmn->category) {
362                 case NC_ANIMATION:
363                         ED_region_tag_redraw(ar);
364                         break;
365                 case NC_SCENE:
366                         switch (wmn->data) {
367                                 case ND_RENDER_OPTIONS:
368                                 case ND_OB_ACTIVE:
369                                 case ND_FRAME:
370                                 case ND_MARKERS:
371                                         ED_region_tag_redraw(ar);
372                                         break;
373                         }
374                         break;
375                 case NC_OBJECT:
376                         switch (wmn->data) {
377                                 case ND_TRANSFORM:
378                                         /* moving object shouldn't need to redraw action */
379                                         break;
380                                 case ND_BONE_ACTIVE:
381                                 case ND_BONE_SELECT:
382                                 case ND_KEYS:
383                                         ED_region_tag_redraw(ar);
384                                         break;
385                         }
386                         break;
387                 case NC_NODE:
388                         switch (wmn->action) {
389                                 case NA_EDITED:
390                                         ED_region_tag_redraw(ar);
391                                         break;
392                         }
393                         break;
394                 case NC_ID:
395                         if (wmn->action == NA_RENAME)
396                                 ED_region_tag_redraw(ar);
397                         break;
398                 case NC_SCREEN:
399                         if (ELEM(wmn->data, ND_LAYER)) {
400                                 ED_region_tag_redraw(ar);
401                         }
402                         break;
403                 default:
404                         if (wmn->data == ND_KEYS)
405                                 ED_region_tag_redraw(ar);
406                         break;
407         }
408 }
409
410 /* editor level listener */
411 static void action_listener(
412         bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn, const Scene *UNUSED(scene))
413 {
414         SpaceAction *saction = (SpaceAction *)sa->spacedata.first;
415         
416         /* context changes */
417         switch (wmn->category) {
418                 case NC_GPENCIL:
419                         /* only handle these events in GPencil mode for performance considerations */
420                         if (saction->mode == SACTCONT_GPENCIL) {
421                                 if (wmn->action == NA_EDITED) {
422                                         ED_area_tag_redraw(sa);
423                                 }
424                                 else if (wmn->action == NA_SELECTED) {
425                                         saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
426                                         ED_area_tag_refresh(sa);
427                                 }
428                         }
429                         break;
430                 case NC_ANIMATION:
431                         /* for NLA tweakmode enter/exit, need complete refresh */
432                         if (wmn->data == ND_NLA_ACTCHANGE) {
433                                 saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
434                                 ED_area_tag_refresh(sa);
435                         }
436                         /* autocolor only really needs to change when channels are added/removed, or previously hidden stuff appears 
437                          * (assume for now that if just adding these works, that will be fine)
438                          */
439                         else if (((wmn->data == ND_KEYFRAME) && ELEM(wmn->action, NA_ADDED, NA_REMOVED)) ||
440                                  ((wmn->data == ND_ANIMCHAN) && (wmn->action != NA_SELECTED)))
441                         {
442                                 ED_area_tag_refresh(sa);
443                         }
444                         /* for simple edits to the curve data though (or just plain selections), a simple redraw should work 
445                          * (see T39851 for an example of how this can go wrong)
446                          */
447                         else {
448                                 ED_area_tag_redraw(sa);
449                         }
450                         break;
451                 case NC_SCENE:
452                         switch (wmn->data) {
453                                 case ND_OB_ACTIVE:  /* selection changed, so force refresh to flush (needs flag set to do syncing) */
454                                 case ND_OB_SELECT:
455                                         saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
456                                         ED_area_tag_refresh(sa);
457                                         break;
458                                         
459                                 default: /* just redrawing the view will do */
460                                         ED_area_tag_redraw(sa);
461                                         break;
462                         }
463                         break;
464                 case NC_OBJECT:
465                         switch (wmn->data) {
466                                 case ND_BONE_SELECT:    /* selection changed, so force refresh to flush (needs flag set to do syncing) */
467                                 case ND_BONE_ACTIVE:
468                                         saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
469                                         ED_area_tag_refresh(sa);
470                                         break;
471                                 case ND_TRANSFORM:
472                                         /* moving object shouldn't need to redraw action */
473                                         break;
474                                 default: /* just redrawing the view will do */
475                                         ED_area_tag_redraw(sa);
476                                         break;
477                         }
478                         break;
479                 case NC_MASK:
480                         if (saction->mode == SACTCONT_MASK) {
481                                 switch (wmn->data) {
482                                         case ND_DATA:
483                                                 ED_area_tag_refresh(sa);
484                                                 ED_area_tag_redraw(sa);
485                                                 break;
486                                         default: /* just redrawing the view will do */
487                                                 ED_area_tag_redraw(sa);
488                                                 break;
489                                 }
490                         }
491                         break;
492                 case NC_NODE:
493                         if (wmn->action == NA_SELECTED) {
494                                 /* selection changed, so force refresh to flush (needs flag set to do syncing) */
495                                 saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
496                                 ED_area_tag_refresh(sa);
497                         }
498                         break;
499                 case NC_SPACE:
500                         switch (wmn->data) {
501                                 case ND_SPACE_DOPESHEET:
502                                         ED_area_tag_redraw(sa);
503                                         break;
504                                 case ND_SPACE_CHANGED:
505                                         saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
506                                         ED_area_tag_refresh(sa);
507                                         break;
508                         }
509                         break;
510                 case NC_WINDOW:
511                         if (saction->flag & SACTION_TEMP_NEEDCHANSYNC) {
512                                 /* force redraw/refresh after undo/redo - [#28962] */
513                                 ED_area_tag_refresh(sa);
514                         }
515                         break;
516         }
517 }
518
519 static void action_header_region_listener(
520         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
521         wmNotifier *wmn, const Scene *UNUSED(scene))
522 {
523         // SpaceAction *saction = (SpaceAction *)sa->spacedata.first;
524
525         /* context changes */
526         switch (wmn->category) {
527                 case NC_SCENE:
528                         switch (wmn->data) {
529                                 case ND_OB_ACTIVE:
530                                         ED_region_tag_redraw(ar);
531                                         break;
532                         }
533                         break;
534                 case NC_ID:
535                         if (wmn->action == NA_RENAME)
536                                 ED_region_tag_redraw(ar);
537                         break;
538                 case NC_ANIMATION:
539                         switch (wmn->data) {
540                                 case ND_ANIMCHAN: /* set of visible animchannels changed */
541                                         /* NOTE: for now, this should usually just mean that the filters changed 
542                                          *       It may be better if we had a dedicated flag for that though
543                                          */
544                                         ED_region_tag_redraw(ar);
545                                         break;
546                                         
547                                 case ND_KEYFRAME: /* new keyframed added -> active action may have changed */
548                                         //saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
549                                         ED_region_tag_redraw(ar);
550                                         break;
551                         }
552                         break;
553         }
554
555 }
556
557 /* add handlers, stuff you only do once or on area/region changes */
558 static void action_buttons_area_init(wmWindowManager *wm, ARegion *ar)
559 {
560         wmKeyMap *keymap;
561         
562         ED_region_panels_init(wm, ar);
563         
564         keymap = WM_keymap_find(wm->defaultconf, "Dopesheet Generic", SPACE_ACTION, 0);
565         WM_event_add_keymap_handler(&ar->handlers, keymap);
566 }
567
568 static void action_buttons_area_draw(const bContext *C, ARegion *ar)
569 {
570         ED_region_panels(C, ar, NULL, -1, true);
571 }
572
573 static void action_region_listener(
574         bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
575         wmNotifier *wmn, const Scene *UNUSED(scene))
576 {
577         /* context changes */
578         switch (wmn->category) {
579                 case NC_ANIMATION:
580                         ED_region_tag_redraw(ar);
581                         break;
582                 case NC_SCENE:
583                         switch (wmn->data) {
584                                 case ND_OB_ACTIVE:
585                                 case ND_FRAME:
586                                 case ND_MARKERS:
587                                         ED_region_tag_redraw(ar);
588                                         break;
589                         }
590                         break;
591                 case NC_OBJECT:
592                         switch (wmn->data) {
593                                 case ND_BONE_ACTIVE:
594                                 case ND_BONE_SELECT:
595                                 case ND_KEYS:
596                                         ED_region_tag_redraw(ar);
597                                         break;
598                         }
599                         break;
600                 default:
601                         if (wmn->data == ND_KEYS)
602                                 ED_region_tag_redraw(ar);
603                         break;
604         }
605 }
606
607 static void action_refresh(const bContext *C, ScrArea *sa)
608 {
609         SpaceAction *saction = (SpaceAction *)sa->spacedata.first;
610         
611         /* update the state of the animchannels in response to changes from the data they represent 
612          * NOTE: the temp flag is used to indicate when this needs to be done, and will be cleared once handled
613          */
614         if (saction->flag & SACTION_TEMP_NEEDCHANSYNC) {
615                 ARegion *ar;
616                 
617                 /* Perform syncing of channel state incl. selection
618                  * Active action setting also occurs here (as part of anim channel filtering in anim_filter.c)
619                  */
620                 ANIM_sync_animchannels_to_data(C);
621                 saction->flag &= ~SACTION_TEMP_NEEDCHANSYNC;
622                 
623                 /* Tag everything for redraw
624                  * - Regions (such as header) need to be manually tagged for redraw too
625                  *   or else they don't update [#28962]
626                  */
627                 ED_area_tag_redraw(sa);
628                 for (ar = sa->regionbase.first; ar; ar = ar->next)
629                         ED_region_tag_redraw(ar);
630         }
631         
632         /* region updates? */
633         // XXX re-sizing y-extents of tot should go here?
634 }
635
636 static void action_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID *new_id)
637 {
638         SpaceAction *sact = (SpaceAction *)slink;
639
640         if ((ID *)sact->action == old_id) {
641                 sact->action = (bAction *)new_id;
642         }
643
644         if ((ID *)sact->ads.filter_grp == old_id) {
645                 sact->ads.filter_grp = (Group *)new_id;
646         }
647         if ((ID *)sact->ads.source == old_id) {
648                 sact->ads.source = new_id;
649         }
650
651 }
652
653 /* only called once, from space/spacetypes.c */
654 void ED_spacetype_action(void)
655 {
656         SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype action");
657         ARegionType *art;
658         
659         st->spaceid = SPACE_ACTION;
660         strncpy(st->name, "Action", BKE_ST_MAXNAME);
661         
662         st->new = action_new;
663         st->free = action_free;
664         st->init = action_init;
665         st->duplicate = action_duplicate;
666         st->operatortypes = action_operatortypes;
667         st->keymap = action_keymap;
668         st->listener = action_listener;
669         st->refresh = action_refresh;
670         st->id_remap = action_id_remap;
671
672         /* regions: main window */
673         art = MEM_callocN(sizeof(ARegionType), "spacetype action region");
674         art->regionid = RGN_TYPE_WINDOW;
675         art->init = action_main_region_init;
676         art->draw = action_main_region_draw;
677         art->listener = action_main_region_listener;
678         art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_MARKERS | ED_KEYMAP_ANIMATION | ED_KEYMAP_FRAMES;
679
680         BLI_addhead(&st->regiontypes, art);
681         
682         /* regions: header */
683         art = MEM_callocN(sizeof(ARegionType), "spacetype action region");
684         art->regionid = RGN_TYPE_HEADER;
685         art->prefsizey = HEADERY;
686         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER;
687         
688         art->init = action_header_region_init;
689         art->draw = action_header_region_draw;
690         art->listener = action_header_region_listener;
691         
692         BLI_addhead(&st->regiontypes, art);
693         
694         /* regions: channels */
695         art = MEM_callocN(sizeof(ARegionType), "spacetype action region");
696         art->regionid = RGN_TYPE_CHANNELS;
697         art->prefsizex = 200;
698         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES;
699         
700         art->init = action_channel_region_init;
701         art->draw = action_channel_region_draw;
702         art->listener = action_channel_region_listener;
703         
704         BLI_addhead(&st->regiontypes, art);
705         
706         /* regions: UI buttons */
707         art = MEM_callocN(sizeof(ARegionType), "spacetype action region");
708         art->regionid = RGN_TYPE_UI;
709         art->prefsizex = 200;
710         art->keymapflag = ED_KEYMAP_UI;
711         art->listener = action_region_listener;
712         art->init = action_buttons_area_init;
713         art->draw = action_buttons_area_draw;
714         
715         BLI_addhead(&st->regiontypes, art);
716         
717         action_buttons_register(art);
718         
719         BKE_spacetype_register(st);
720 }
721