now dragging an image onto an empty can be done without holding Ctrl.
[blender.git] / source / blender / editors / space_view3d / space_view3d.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_view3d/space_view3d.c
28  *  \ingroup spview3d
29  */
30
31
32 #include <string.h>
33 #include <stdio.h>
34
35 #include "DNA_material_types.h"
36 #include "DNA_object_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_rand.h"
44 #include "BLI_utildefines.h"
45
46 #include "BKE_context.h"
47 #include "BKE_icons.h"
48 #include "BKE_object.h"
49 #include "BKE_screen.h"
50
51 #include "ED_space_api.h"
52 #include "ED_screen.h"
53 #include "ED_object.h"
54
55 #include "GPU_material.h"
56
57 #include "BIF_gl.h"
58
59 #include "WM_api.h"
60 #include "WM_types.h"
61
62 #include "RE_engine.h"
63
64 #include "RNA_access.h"
65
66 #include "UI_resources.h"
67
68 #include "view3d_intern.h"  /* own include */
69
70 /* ******************** manage regions ********************* */
71
72 ARegion *view3d_has_buttons_region(ScrArea *sa)
73 {
74         ARegion *ar, *arnew;
75
76         ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
77         if (ar) return ar;
78         
79         /* add subdiv level; after header */
80         ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
81
82         /* is error! */
83         if (ar == NULL) return NULL;
84         
85         arnew = MEM_callocN(sizeof(ARegion), "buttons for view3d");
86         
87         BLI_insertlinkafter(&sa->regionbase, ar, arnew);
88         arnew->regiontype = RGN_TYPE_UI;
89         arnew->alignment = RGN_ALIGN_RIGHT;
90         
91         arnew->flag = RGN_FLAG_HIDDEN;
92         
93         return arnew;
94 }
95
96 ARegion *view3d_has_tools_region(ScrArea *sa)
97 {
98         ARegion *ar, *artool = NULL, *arprops = NULL, *arhead;
99         
100         for (ar = sa->regionbase.first; ar; ar = ar->next) {
101                 if (ar->regiontype == RGN_TYPE_TOOLS)
102                         artool = ar;
103                 if (ar->regiontype == RGN_TYPE_TOOL_PROPS)
104                         arprops = ar;
105         }
106         
107         /* tool region hide/unhide also hides props */
108         if (arprops && artool) return artool;
109         
110         if (artool == NULL) {
111                 /* add subdiv level; after header */
112                 for (arhead = sa->regionbase.first; arhead; arhead = arhead->next)
113                         if (arhead->regiontype == RGN_TYPE_HEADER)
114                                 break;
115                 
116                 /* is error! */
117                 if (arhead == NULL) return NULL;
118                 
119                 artool = MEM_callocN(sizeof(ARegion), "tools for view3d");
120                 
121                 BLI_insertlinkafter(&sa->regionbase, arhead, artool);
122                 artool->regiontype = RGN_TYPE_TOOLS;
123                 artool->alignment = RGN_ALIGN_LEFT;
124                 artool->flag = RGN_FLAG_HIDDEN;
125         }
126
127         if (arprops == NULL) {
128                 /* add extra subdivided region for tool properties */
129                 arprops = MEM_callocN(sizeof(ARegion), "tool props for view3d");
130                 
131                 BLI_insertlinkafter(&sa->regionbase, artool, arprops);
132                 arprops->regiontype = RGN_TYPE_TOOL_PROPS;
133                 arprops->alignment = RGN_ALIGN_BOTTOM | RGN_SPLIT_PREV;
134         }
135         
136         return artool;
137 }
138
139 /* ****************************************************** */
140
141 /* function to always find a regionview3d context inside 3D window */
142 RegionView3D *ED_view3d_context_rv3d(bContext *C)
143 {
144         RegionView3D *rv3d = CTX_wm_region_view3d(C);
145         
146         if (rv3d == NULL) {
147                 ScrArea *sa = CTX_wm_area(C);
148                 if (sa && sa->spacetype == SPACE_VIEW3D) {
149                         ARegion *ar = BKE_area_find_region_active_win(sa);
150                         if (ar) {
151                                 rv3d = ar->regiondata;
152                         }
153                 }
154         }
155         return rv3d;
156 }
157
158 /* ideally would return an rv3d but in some cases the region is needed too
159  * so return that, the caller can then access the ar->regiondata */
160 int ED_view3d_context_user_region(bContext *C, View3D **v3d_r, ARegion **ar_r)
161 {
162         ScrArea *sa = CTX_wm_area(C);
163
164         *v3d_r = NULL;
165         *ar_r = NULL;
166
167         if (sa && sa->spacetype == SPACE_VIEW3D) {
168                 ARegion *ar = CTX_wm_region(C);
169                 View3D *v3d = (View3D *)sa->spacedata.first;
170
171                 if (ar) {
172                         RegionView3D *rv3d = ar->regiondata;
173                         if (rv3d && rv3d->viewlock == 0) {
174                                 *v3d_r = v3d;
175                                 *ar_r = ar;
176                                 return 1;
177                         }
178                         else {
179                                 ARegion *ar_unlock_user = NULL;
180                                 ARegion *ar_unlock = NULL;
181                                 for (ar = sa->regionbase.first; ar; ar = ar->next) {
182                                         /* find the first unlocked rv3d */
183                                         if (ar->regiondata && ar->regiontype == RGN_TYPE_WINDOW) {
184                                                 rv3d = ar->regiondata;
185                                                 if (rv3d->viewlock == 0) {
186                                                         ar_unlock = ar;
187                                                         if (rv3d->persp == RV3D_PERSP || rv3d->persp == RV3D_CAMOB) {
188                                                                 ar_unlock_user = ar;
189                                                                 break;
190                                                         }
191                                                 }
192                                         }
193                                 }
194
195                                 /* camera/perspective view get priority when the active region is locked */
196                                 if (ar_unlock_user) {
197                                         *v3d_r = v3d;
198                                         *ar_r = ar_unlock_user;
199                                         return 1;
200                                 }
201
202                                 if (ar_unlock) {
203                                         *v3d_r = v3d;
204                                         *ar_r = ar_unlock;
205                                         return 1;
206                                 }
207                         }
208                 }
209         }
210
211         return 0;
212 }
213
214 /* Most of the time this isn't needed since you could assume the view matrix was
215  * set while drawing, however when functions like mesh_foreachScreenVert are
216  * called by selection tools, we can't be sure this object was the last.
217  *
218  * for example, transparent objects are drawn after editmode and will cause
219  * the rv3d mat's to change and break selection.
220  *
221  * 'ED_view3d_init_mats_rv3d' should be called before
222  * view3d_project_short_clip and view3d_project_short_noclip in cases where
223  * these functions are not used during draw_object
224  */
225 void ED_view3d_init_mats_rv3d(struct Object *ob, struct RegionView3D *rv3d)
226 {
227         /* local viewmat and persmat, to calculate projections */
228         mult_m4_m4m4(rv3d->viewmatob, rv3d->viewmat, ob->obmat);
229         mult_m4_m4m4(rv3d->persmatob, rv3d->persmat, ob->obmat);
230
231         /* initializes object space clipping, speeds up clip tests */
232         ED_view3d_clipping_local(rv3d, ob->obmat);
233 }
234
235 void ED_view3d_init_mats_rv3d_gl(struct Object *ob, struct RegionView3D *rv3d)
236 {
237         ED_view3d_init_mats_rv3d(ob, rv3d);
238
239         /* we have to multiply instead of loading viewmatob to make
240          * it work with duplis using displists, otherwise it will
241          * override the dupli-matrix */
242         glMultMatrixf(ob->obmat);
243 }
244
245 /* ******************** default callbacks for view3d space ***************** */
246
247 static SpaceLink *view3d_new(const bContext *C)
248 {
249         Scene *scene = CTX_data_scene(C);
250         ARegion *ar;
251         View3D *v3d;
252         RegionView3D *rv3d;
253         
254         v3d = MEM_callocN(sizeof(View3D), "initview3d");
255         v3d->spacetype = SPACE_VIEW3D;
256         v3d->blockscale = 0.7f;
257         v3d->lay = v3d->layact = 1;
258         if (scene) {
259                 v3d->lay = v3d->layact = scene->lay;
260                 v3d->camera = scene->camera;
261         }
262         v3d->scenelock = TRUE;
263         v3d->grid = 1.0f;
264         v3d->gridlines = 16;
265         v3d->gridsubdiv = 10;
266         v3d->drawtype = OB_SOLID;
267
268         v3d->gridflag = V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_FLOOR;
269         
270         v3d->flag = V3D_SELECT_OUTLINE;
271         v3d->flag2 = V3D_SHOW_RECONSTRUCTION | V3D_SHOW_GPENCIL;
272         
273         v3d->lens = 35.0f;
274         v3d->near = 0.01f;
275         v3d->far = 1000.0f;
276
277         v3d->twflag |= U.tw_flag & V3D_USE_MANIPULATOR;
278         v3d->twtype = V3D_MANIP_TRANSLATE;
279         v3d->around = V3D_CENTROID;
280         
281         v3d->bundle_size = 0.2f;
282         v3d->bundle_drawtype = OB_PLAINAXES;
283         
284         /* header */
285         ar = MEM_callocN(sizeof(ARegion), "header for view3d");
286         
287         BLI_addtail(&v3d->regionbase, ar);
288         ar->regiontype = RGN_TYPE_HEADER;
289         ar->alignment = RGN_ALIGN_BOTTOM;
290         
291         /* tool shelf */
292         ar = MEM_callocN(sizeof(ARegion), "toolshelf for view3d");
293         
294         BLI_addtail(&v3d->regionbase, ar);
295         ar->regiontype = RGN_TYPE_TOOLS;
296         ar->alignment = RGN_ALIGN_LEFT;
297         ar->flag = RGN_FLAG_HIDDEN;
298         
299         /* tool properties */
300         ar = MEM_callocN(sizeof(ARegion), "tool properties for view3d");
301         
302         BLI_addtail(&v3d->regionbase, ar);
303         ar->regiontype = RGN_TYPE_TOOL_PROPS;
304         ar->alignment = RGN_ALIGN_BOTTOM | RGN_SPLIT_PREV;
305         ar->flag = RGN_FLAG_HIDDEN;
306         
307         /* buttons/list view */
308         ar = MEM_callocN(sizeof(ARegion), "buttons for view3d");
309         
310         BLI_addtail(&v3d->regionbase, ar);
311         ar->regiontype = RGN_TYPE_UI;
312         ar->alignment = RGN_ALIGN_RIGHT;
313         ar->flag = RGN_FLAG_HIDDEN;
314         
315         /* main area */
316         ar = MEM_callocN(sizeof(ARegion), "main area for view3d");
317         
318         BLI_addtail(&v3d->regionbase, ar);
319         ar->regiontype = RGN_TYPE_WINDOW;
320         
321         ar->regiondata = MEM_callocN(sizeof(RegionView3D), "region view3d");
322         rv3d = ar->regiondata;
323         rv3d->viewquat[0] = 1.0f;
324         rv3d->persp = RV3D_PERSP;
325         rv3d->view = RV3D_VIEW_PERSPORTHO;
326         rv3d->dist = 10.0;
327         
328         return (SpaceLink *)v3d;
329 }
330
331 /* not spacelink itself */
332 static void view3d_free(SpaceLink *sl)
333 {
334         View3D *vd = (View3D *) sl;
335
336         BLI_freelistN(&vd->bgpicbase);
337
338         if (vd->localvd) MEM_freeN(vd->localvd);
339         
340         if (vd->properties_storage) MEM_freeN(vd->properties_storage);
341         
342         /* matcap material, its preview rect gets freed via icons */
343         if (vd->defmaterial) {
344                 if (vd->defmaterial->gpumaterial.first)
345                         GPU_material_free(vd->defmaterial);
346                 BKE_previewimg_free(&vd->defmaterial->preview);
347                 MEM_freeN(vd->defmaterial);
348         }
349 }
350
351
352 /* spacetype; init callback */
353 static void view3d_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
354 {
355
356 }
357
358 static SpaceLink *view3d_duplicate(SpaceLink *sl)
359 {
360         View3D *v3do = (View3D *)sl;
361         View3D *v3dn = MEM_dupallocN(sl);
362         
363         /* clear or remove stuff from old */
364         
365 // XXX  BIF_view3d_previewrender_free(v3do);
366         
367         if (v3do->localvd) {
368                 v3do->localvd = NULL;
369                 v3do->properties_storage = NULL;
370                 v3do->lay = v3dn->localvd->lay;
371                 v3do->lay &= 0xFFFFFF;
372         }
373
374         if (v3dn->drawtype == OB_RENDER)
375                 v3dn->drawtype = OB_SOLID;
376         
377         /* copy or clear inside new stuff */
378
379         v3dn->defmaterial = NULL;
380         
381         BLI_duplicatelist(&v3dn->bgpicbase, &v3do->bgpicbase);
382
383         v3dn->properties_storage = NULL;
384         
385         return (SpaceLink *)v3dn;
386 }
387
388 /* add handlers, stuff you only do once or on area/region changes */
389 static void view3d_main_area_init(wmWindowManager *wm, ARegion *ar)
390 {
391         ListBase *lb;
392         wmKeyMap *keymap;
393
394         /* object ops. */
395         
396         /* important to be before Pose keymap since they can both be enabled at once */
397         keymap = WM_keymap_find(wm->defaultconf, "Face Mask", 0, 0);
398         WM_event_add_keymap_handler(&ar->handlers, keymap);
399         
400         
401         keymap = WM_keymap_find(wm->defaultconf, "Weight Paint Vertex Selection", 0, 0);
402         WM_event_add_keymap_handler(&ar->handlers, keymap);
403
404         /* pose is not modal, operator poll checks for this */
405         keymap = WM_keymap_find(wm->defaultconf, "Pose", 0, 0);
406         WM_event_add_keymap_handler(&ar->handlers, keymap);
407         
408         keymap = WM_keymap_find(wm->defaultconf, "Object Mode", 0, 0);
409         WM_event_add_keymap_handler(&ar->handlers, keymap);
410
411         keymap = WM_keymap_find(wm->defaultconf, "Image Paint", 0, 0);
412         WM_event_add_keymap_handler(&ar->handlers, keymap);
413
414         keymap = WM_keymap_find(wm->defaultconf, "Vertex Paint", 0, 0);
415         WM_event_add_keymap_handler(&ar->handlers, keymap);
416
417         keymap = WM_keymap_find(wm->defaultconf, "Weight Paint", 0, 0);
418         WM_event_add_keymap_handler(&ar->handlers, keymap);
419
420         keymap = WM_keymap_find(wm->defaultconf, "Sculpt", 0, 0);
421         WM_event_add_keymap_handler(&ar->handlers, keymap);
422         
423         keymap = WM_keymap_find(wm->defaultconf, "Mesh", 0, 0);
424         WM_event_add_keymap_handler(&ar->handlers, keymap);
425         
426         keymap = WM_keymap_find(wm->defaultconf, "Curve", 0, 0);
427         WM_event_add_keymap_handler(&ar->handlers, keymap);
428         
429         keymap = WM_keymap_find(wm->defaultconf, "Armature", 0, 0);
430         WM_event_add_keymap_handler(&ar->handlers, keymap);
431
432         keymap = WM_keymap_find(wm->defaultconf, "Pose", 0, 0);
433         WM_event_add_keymap_handler(&ar->handlers, keymap);
434
435         keymap = WM_keymap_find(wm->defaultconf, "Metaball", 0, 0);
436         WM_event_add_keymap_handler(&ar->handlers, keymap);
437         
438         keymap = WM_keymap_find(wm->defaultconf, "Lattice", 0, 0);
439         WM_event_add_keymap_handler(&ar->handlers, keymap);
440
441         /* armature sketching needs to take over mouse */
442         keymap = WM_keymap_find(wm->defaultconf, "Armature Sketch", 0, 0);
443         WM_event_add_keymap_handler(&ar->handlers, keymap);
444
445         keymap = WM_keymap_find(wm->defaultconf, "Particle", 0, 0);
446         WM_event_add_keymap_handler(&ar->handlers, keymap);
447
448         /* editfont keymap swallows all... */
449         keymap = WM_keymap_find(wm->defaultconf, "Font", 0, 0);
450         WM_event_add_keymap_handler(&ar->handlers, keymap);
451
452         keymap = WM_keymap_find(wm->defaultconf, "Object Non-modal", 0, 0);
453         WM_event_add_keymap_handler(&ar->handlers, keymap);
454
455         keymap = WM_keymap_find(wm->defaultconf, "Frames", 0, 0);
456         WM_event_add_keymap_handler(&ar->handlers, keymap);
457
458         /* own keymap, last so modes can override it */
459         keymap = WM_keymap_find(wm->defaultconf, "3D View Generic", SPACE_VIEW3D, 0);
460         WM_event_add_keymap_handler(&ar->handlers, keymap);
461
462         keymap = WM_keymap_find(wm->defaultconf, "3D View", SPACE_VIEW3D, 0);
463         WM_event_add_keymap_handler(&ar->handlers, keymap);
464         
465         /* add drop boxes */
466         lb = WM_dropboxmap_find("View3D", SPACE_VIEW3D, RGN_TYPE_WINDOW);
467         
468         WM_event_add_dropbox_handler(&ar->handlers, lb);
469         
470 }
471
472 static int view3d_ob_drop_poll(bContext *UNUSED(C), wmDrag *drag, wmEvent *UNUSED(event))
473 {
474         if (drag->type == WM_DRAG_ID) {
475                 ID *id = (ID *)drag->poin;
476                 if (GS(id->name) == ID_OB)
477                         return 1;
478         }
479         return 0;
480 }
481
482 static int view3d_group_drop_poll(bContext *UNUSED(C), wmDrag *drag, wmEvent *UNUSED(event))
483 {
484         if (drag->type == WM_DRAG_ID) {
485                 ID *id = (ID *)drag->poin;
486                 if (GS(id->name) == ID_GR)
487                         return 1;
488         }
489         return 0;
490 }
491
492 static int view3d_mat_drop_poll(bContext *UNUSED(C), wmDrag *drag, wmEvent *UNUSED(event))
493 {
494         if (drag->type == WM_DRAG_ID) {
495                 ID *id = (ID *)drag->poin;
496                 if (GS(id->name) == ID_MA)
497                         return 1;
498         }
499         return 0;
500 }
501
502 static int view3d_ima_drop_poll(bContext *UNUSED(C), wmDrag *drag, wmEvent *UNUSED(event))
503 {
504         if (drag->type == WM_DRAG_ID) {
505                 ID *id = (ID *)drag->poin;
506                 if (GS(id->name) == ID_IM)
507                         return 1;
508         }
509         else if (drag->type == WM_DRAG_PATH) {
510                 if (ELEM(drag->icon, 0, ICON_FILE_IMAGE))   /* rule might not work? */
511                         return 1;
512         }
513         return 0;
514 }
515
516 static int view3d_ima_bg_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
517 {
518         if (event->ctrl)
519                 return false;
520
521         if (!ED_view3d_give_base_under_cursor(C, event->mval)) {
522                 return view3d_ima_drop_poll(C, drag, event);
523         }
524         return 0;
525 }
526
527 static int view3d_ima_empty_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
528 {
529         Base *base = ED_view3d_give_base_under_cursor(C, event->mval);
530
531         /* either holding and ctrl and no object, or dropping to empty */
532         if ((event->ctrl && !base) || (base && base->object->type == OB_EMPTY))
533                 return view3d_ima_drop_poll(C, drag, event);
534
535         return 0;
536 }
537
538 static int view3d_ima_mesh_drop_poll(bContext *C, wmDrag *drag, wmEvent *event)
539 {
540         Base *base = ED_view3d_give_base_under_cursor(C, event->mval);
541
542         if (base && base->object->type == OB_MESH)
543                 return view3d_ima_drop_poll(C, drag, event);
544         return 0;
545 }
546
547 static void view3d_ob_drop_copy(wmDrag *drag, wmDropBox *drop)
548 {
549         ID *id = (ID *)drag->poin;
550
551         RNA_string_set(drop->ptr, "name", id->name + 2);
552 }
553
554 static void view3d_group_drop_copy(wmDrag *drag, wmDropBox *drop)
555 {
556         ID *id = (ID *)drag->poin;
557         
558         drop->opcontext = WM_OP_EXEC_DEFAULT;
559         RNA_string_set(drop->ptr, "name", id->name + 2);
560 }
561
562 static void view3d_id_drop_copy(wmDrag *drag, wmDropBox *drop)
563 {
564         ID *id = (ID *)drag->poin;
565         
566         RNA_string_set(drop->ptr, "name", id->name + 2);
567 }
568
569 static void view3d_id_path_drop_copy(wmDrag *drag, wmDropBox *drop)
570 {
571         ID *id = (ID *)drag->poin;
572         
573         if (id)
574                 RNA_string_set(drop->ptr, "name", id->name + 2);
575         if (drag->path[0])
576                 RNA_string_set(drop->ptr, "filepath", drag->path);
577 }
578
579
580 /* region dropbox definition */
581 static void view3d_dropboxes(void)
582 {
583         ListBase *lb = WM_dropboxmap_find("View3D", SPACE_VIEW3D, RGN_TYPE_WINDOW);
584         
585         WM_dropbox_add(lb, "OBJECT_OT_add_named", view3d_ob_drop_poll, view3d_ob_drop_copy);
586         WM_dropbox_add(lb, "OBJECT_OT_drop_named_material", view3d_mat_drop_poll, view3d_id_drop_copy);
587         WM_dropbox_add(lb, "MESH_OT_drop_named_image", view3d_ima_mesh_drop_poll, view3d_id_path_drop_copy);
588         WM_dropbox_add(lb, "OBJECT_OT_drop_named_image", view3d_ima_empty_drop_poll, view3d_id_path_drop_copy);
589         WM_dropbox_add(lb, "VIEW3D_OT_background_image_add", view3d_ima_bg_drop_poll, view3d_id_path_drop_copy);
590         WM_dropbox_add(lb, "OBJECT_OT_group_instance_add", view3d_group_drop_poll, view3d_group_drop_copy);
591 }
592
593
594
595 /* type callback, not region itself */
596 static void view3d_main_area_free(ARegion *ar)
597 {
598         RegionView3D *rv3d = ar->regiondata;
599         
600         if (rv3d) {
601                 if (rv3d->localvd) MEM_freeN(rv3d->localvd);
602                 if (rv3d->clipbb) MEM_freeN(rv3d->clipbb);
603
604                 if (rv3d->ri) {
605                         // XXX          BIF_view3d_previewrender_free(rv3d);
606                 }
607
608                 if (rv3d->render_engine)
609                         RE_engine_free(rv3d->render_engine);
610                 
611                 if (rv3d->depths) {
612                         if (rv3d->depths->depths) MEM_freeN(rv3d->depths->depths);
613                         MEM_freeN(rv3d->depths);
614                 }
615                 if (rv3d->sms) {
616                         MEM_freeN(rv3d->sms);
617                 }
618                 MEM_freeN(rv3d);
619                 ar->regiondata = NULL;
620         }
621 }
622
623 /* copy regiondata */
624 static void *view3d_main_area_duplicate(void *poin)
625 {
626         if (poin) {
627                 RegionView3D *rv3d = poin, *new;
628         
629                 new = MEM_dupallocN(rv3d);
630                 if (rv3d->localvd)
631                         new->localvd = MEM_dupallocN(rv3d->localvd);
632                 if (rv3d->clipbb)
633                         new->clipbb = MEM_dupallocN(rv3d->clipbb);
634                 
635                 new->depths = NULL;
636                 new->ri = NULL;
637                 new->render_engine = NULL;
638                 new->gpd = NULL;
639                 new->sms = NULL;
640                 new->smooth_timer = NULL;
641                 
642                 return new;
643         }
644         return NULL;
645 }
646
647 static void view3d_recalc_used_layers(ARegion *ar, wmNotifier *wmn, Scene *scene)
648 {
649         wmWindow *win = wmn->wm->winactive;
650         ScrArea *sa;
651         unsigned int lay_used = 0;
652         Base *base;
653
654         if (!win) return;
655
656         base = scene->base.first;
657         while (base) {
658                 lay_used |= base->lay & ((1 << 20) - 1); /* ignore localview */
659
660                 if (lay_used == (1 << 20) - 1)
661                         break;
662
663                 base = base->next;
664         }
665
666         for (sa = win->screen->areabase.first; sa; sa = sa->next) {
667                 if (sa->spacetype == SPACE_VIEW3D) {
668                         if (BLI_findindex(&sa->regionbase, ar) != -1) {
669                                 View3D *v3d = sa->spacedata.first;
670                                 v3d->lay_used = lay_used;
671                                 break;
672                         }
673                 }
674         }
675 }
676
677 static void view3d_main_area_listener(ARegion *ar, wmNotifier *wmn)
678 {
679         
680         /* context changes */
681         switch (wmn->category) {
682                 case NC_ANIMATION:
683                         switch (wmn->data) {
684                                 case ND_KEYFRAME_PROP:
685                                 case ND_NLA_ACTCHANGE:
686                                         ED_region_tag_redraw(ar);
687                                         break;
688                                 case ND_NLA:
689                                 case ND_KEYFRAME:
690                                         if (wmn->action == NA_EDITED)
691                                                 ED_region_tag_redraw(ar);
692                                         break;
693                                 case ND_ANIMCHAN:
694                                         if (wmn->action == NA_SELECTED)
695                                                 ED_region_tag_redraw(ar);
696                                         break;
697                         }
698                         break;
699                 case NC_SCENE:
700                         switch (wmn->data) {
701                                 case ND_LAYER_CONTENT:
702                                         if (wmn->reference)
703                                                 view3d_recalc_used_layers(ar, wmn, wmn->reference);
704                                         ED_region_tag_redraw(ar);
705                                         break;
706                                 case ND_FRAME:
707                                 case ND_TRANSFORM:
708                                 case ND_OB_ACTIVE:
709                                 case ND_OB_SELECT:
710                                 case ND_OB_VISIBLE:
711                                 case ND_LAYER:
712                                 case ND_RENDER_OPTIONS:
713                                 case ND_MODE:
714                                         ED_region_tag_redraw(ar);
715                                         break;
716                                 case ND_WORLD:
717                                         /* handled by space_view3d_listener() for v3d access */
718                                         break;
719                         }
720                         if (wmn->action == NA_EDITED)
721                                 ED_region_tag_redraw(ar);
722                         break;
723                 case NC_OBJECT:
724                         switch (wmn->data) {
725                                 case ND_BONE_ACTIVE:
726                                 case ND_BONE_SELECT:
727                                 case ND_TRANSFORM:
728                                 case ND_POSE:
729                                 case ND_DRAW:
730                                 case ND_MODIFIER:
731                                 case ND_CONSTRAINT:
732                                 case ND_KEYS:
733                                 case ND_PARTICLE:
734                                         ED_region_tag_redraw(ar);
735                                         break;
736                         }
737                         switch (wmn->action) {
738                                 case NA_ADDED:
739                                         ED_region_tag_redraw(ar);
740                                         break;
741                         }
742                         break;
743                 case NC_GEOM:
744                         switch (wmn->data) {
745                                 case ND_DATA:
746                                 case ND_VERTEX_GROUP:
747                                 case ND_SELECT:
748                                         ED_region_tag_redraw(ar);
749                                         break;
750                         }
751                         switch (wmn->action) {
752                                 case NA_EDITED:
753                                         ED_region_tag_redraw(ar);
754                                         break;
755                         }
756                         break;
757                 case NC_GROUP:
758                         /* all group ops for now */
759                         ED_region_tag_redraw(ar);
760                         break;
761                 case NC_BRUSH:
762                         if (wmn->action == NA_EDITED)
763                                 ED_region_tag_redraw_overlay(ar);
764                         break;
765                 case NC_MATERIAL:
766                         switch (wmn->data) {
767                                 case ND_SHADING_DRAW:
768                                 case ND_SHADING_LINKS:
769                                         ED_region_tag_redraw(ar);
770                                         break;
771                         }
772                         break;
773                 case NC_WORLD:
774                         switch (wmn->data) {
775                                 case ND_WORLD_DRAW:
776                                         /* handled by space_view3d_listener() for v3d access */
777                                         break;
778                                 case ND_WORLD_STARS:
779                                 {
780                                         RegionView3D *rv3d = ar->regiondata;
781                                         if (rv3d->persp == RV3D_CAMOB) {
782                                                 ED_region_tag_redraw(ar);
783                                         }
784                                 }
785                         }
786                         break;
787                 case NC_LAMP:
788                         switch (wmn->data) {
789                                 case ND_LIGHTING_DRAW:
790                                         ED_region_tag_redraw(ar);
791                                         break;
792                         }
793                         break;
794                 case NC_IMAGE:
795                         /* this could be more fine grained checks if we had
796                          * more context than just the region */
797                         ED_region_tag_redraw(ar);
798                         break;
799                 case NC_TEXTURE:
800                         /* same as above */
801                         ED_region_tag_redraw(ar);
802                         break;
803                 case NC_MOVIECLIP:
804                         if (wmn->data == ND_DISPLAY)
805                                 ED_region_tag_redraw(ar);
806                         break;
807                 case NC_SPACE:
808                         if (wmn->data == ND_SPACE_VIEW3D) {
809                                 if (wmn->subtype == NS_VIEW3D_GPU) {
810                                         RegionView3D *rv3d = ar->regiondata;
811                                         rv3d->rflag |= RV3D_GPULIGHT_UPDATE;
812                                 }
813                                 ED_region_tag_redraw(ar);
814                         }
815                         break;
816                 case NC_ID:
817                         if (wmn->action == NA_RENAME)
818                                 ED_region_tag_redraw(ar);
819                         break;
820                 case NC_SCREEN:
821                         switch (wmn->data) {
822                                 case ND_ANIMPLAY:
823                                 case ND_SKETCH:
824                                         ED_region_tag_redraw(ar);
825                                         break;
826                                 case ND_SCREENBROWSE:
827                                 case ND_SCREENDELETE:
828                                 case ND_SCREENSET:
829                                         /* screen was changed, need to update used layers due to NC_SCENE|ND_LAYER_CONTENT */
830                                         /* updates used layers only for View3D in active screen */
831                                         if (wmn->reference) {
832                                                 bScreen *sc = wmn->reference;
833                                                 view3d_recalc_used_layers(ar, wmn, sc->scene);
834                                         }
835                                         ED_region_tag_redraw(ar);
836                                         break;
837                         }
838
839                         break;
840                 case NC_GPENCIL:
841                         if (wmn->action == NA_EDITED)
842                                 ED_region_tag_redraw(ar);
843                         break;
844         }
845 }
846
847 /* concept is to retrieve cursor type context-less */
848 static void view3d_main_area_cursor(wmWindow *win, ScrArea *UNUSED(sa), ARegion *UNUSED(ar))
849 {
850         Scene *scene = win->screen->scene;
851
852         if (scene->obedit) {
853                 WM_cursor_set(win, CURSOR_EDIT);
854         }
855         else {
856                 WM_cursor_set(win, CURSOR_STD);
857         }
858 }
859
860 /* add handlers, stuff you only do once or on area/region changes */
861 static void view3d_header_area_init(wmWindowManager *wm, ARegion *ar)
862 {
863         wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "3D View Generic", SPACE_VIEW3D, 0);
864         
865         WM_event_add_keymap_handler(&ar->handlers, keymap);
866
867         ED_region_header_init(ar);
868 }
869
870 static void view3d_header_area_draw(const bContext *C, ARegion *ar)
871 {
872         ED_region_header(C, ar);
873 }
874
875 static void view3d_header_area_listener(ARegion *ar, wmNotifier *wmn)
876 {
877         /* context changes */
878         switch (wmn->category) {
879                 case NC_SCENE:
880                         switch (wmn->data) {
881                                 case ND_FRAME:
882                                 case ND_OB_ACTIVE:
883                                 case ND_OB_SELECT:
884                                 case ND_OB_VISIBLE:
885                                 case ND_MODE:
886                                 case ND_LAYER:
887                                 case ND_TOOLSETTINGS:
888                                 case ND_LAYER_CONTENT:
889                                         ED_region_tag_redraw(ar);
890                                         break;
891                         }
892                         break;
893                 case NC_SPACE:
894                         if (wmn->data == ND_SPACE_VIEW3D)
895                                 ED_region_tag_redraw(ar);
896                         break;
897         }
898 }
899
900 /* add handlers, stuff you only do once or on area/region changes */
901 static void view3d_buttons_area_init(wmWindowManager *wm, ARegion *ar)
902 {
903         wmKeyMap *keymap;
904
905         ED_region_panels_init(wm, ar);
906         
907         keymap = WM_keymap_find(wm->defaultconf, "3D View Generic", SPACE_VIEW3D, 0);
908         WM_event_add_keymap_handler(&ar->handlers, keymap);
909 }
910
911 static void view3d_buttons_area_draw(const bContext *C, ARegion *ar)
912 {
913         ED_region_panels(C, ar, 1, NULL, -1);
914 }
915
916 static void view3d_buttons_area_listener(ARegion *ar, wmNotifier *wmn)
917 {
918         /* context changes */
919         switch (wmn->category) {
920                 case NC_ANIMATION:
921                         switch (wmn->data) {
922                                 case ND_KEYFRAME_PROP:
923                                 case ND_NLA_ACTCHANGE:
924                                         ED_region_tag_redraw(ar);
925                                         break;
926                                 case ND_NLA:
927                                 case ND_KEYFRAME:
928                                         if (wmn->action == NA_EDITED)
929                                                 ED_region_tag_redraw(ar);
930                                         break;
931                         }
932                         break;
933                 case NC_SCENE:
934                         switch (wmn->data) {
935                                 case ND_FRAME:
936                                 case ND_OB_ACTIVE:
937                                 case ND_OB_SELECT:
938                                 case ND_OB_VISIBLE:
939                                 case ND_MODE:
940                                 case ND_LAYER:
941                                 case ND_LAYER_CONTENT:
942                                 case ND_TOOLSETTINGS:
943                                         ED_region_tag_redraw(ar);
944                                         break;
945                         }
946                         switch (wmn->action) {
947                                 case NA_EDITED:
948                                         ED_region_tag_redraw(ar);
949                                         break;
950                         }
951                         break;
952                 case NC_OBJECT:
953                         switch (wmn->data) {
954                                 case ND_BONE_ACTIVE:
955                                 case ND_BONE_SELECT:
956                                 case ND_TRANSFORM:
957                                 case ND_POSE:
958                                 case ND_DRAW:
959                                 case ND_KEYS:
960                                 case ND_MODIFIER:
961                                         ED_region_tag_redraw(ar);
962                                         break;
963                         }
964                         break;
965                 case NC_GEOM:
966                         switch (wmn->data) {
967                                 case ND_DATA:
968                                 case ND_VERTEX_GROUP:
969                                 case ND_SELECT:
970                                         ED_region_tag_redraw(ar);
971                                         break;
972                         }
973                         if (wmn->action == NA_EDITED)
974                                 ED_region_tag_redraw(ar);
975                         break;
976                 case NC_TEXTURE:
977                 case NC_MATERIAL:
978                         /* for brush textures */
979                         ED_region_tag_redraw(ar);
980                         break;
981                 case NC_BRUSH:
982                         if (wmn->action == NA_EDITED)
983                                 ED_region_tag_redraw(ar);
984                         break;
985                 case NC_SPACE:
986                         if (wmn->data == ND_SPACE_VIEW3D)
987                                 ED_region_tag_redraw(ar);
988                         break;
989                 case NC_ID:
990                         if (wmn->action == NA_RENAME)
991                                 ED_region_tag_redraw(ar);
992                         break;
993                 case NC_GPENCIL:
994                         if (wmn->data == ND_DATA || wmn->action == NA_EDITED)
995                                 ED_region_tag_redraw(ar);
996                         break;
997         }
998 }
999
1000 /* add handlers, stuff you only do once or on area/region changes */
1001 static void view3d_tools_area_init(wmWindowManager *wm, ARegion *ar)
1002 {
1003         wmKeyMap *keymap;
1004         
1005         ED_region_panels_init(wm, ar);
1006
1007         keymap = WM_keymap_find(wm->defaultconf, "3D View Generic", SPACE_VIEW3D, 0);
1008         WM_event_add_keymap_handler(&ar->handlers, keymap);
1009 }
1010
1011 static void view3d_tools_area_draw(const bContext *C, ARegion *ar)
1012 {
1013         ED_region_panels(C, ar, 1, CTX_data_mode_string(C), -1);
1014 }
1015
1016 static void view3d_props_area_listener(ARegion *ar, wmNotifier *wmn)
1017 {
1018         /* context changes */
1019         switch (wmn->category) {
1020                 case NC_WM:
1021                         if (wmn->data == ND_HISTORY)
1022                                 ED_region_tag_redraw(ar);
1023                         break;
1024                 case NC_SCENE:
1025                         if (wmn->data == ND_MODE)
1026                                 ED_region_tag_redraw(ar);
1027                         break;
1028                 case NC_SPACE:
1029                         if (wmn->data == ND_SPACE_VIEW3D)
1030                                 ED_region_tag_redraw(ar);
1031                         break;
1032         }
1033 }
1034
1035 /*area (not region) level listener*/
1036 static void space_view3d_listener(ScrArea *sa, struct wmNotifier *wmn)
1037 {
1038         View3D *v3d = sa->spacedata.first;
1039
1040         /* context changes */
1041         switch (wmn->category) {
1042                 case NC_SCENE:
1043                         switch (wmn->data) {
1044                                 case ND_WORLD:
1045                                         if (v3d->flag2 & V3D_RENDER_OVERRIDE)
1046                                                 ED_area_tag_redraw_regiontype(sa, RGN_TYPE_WINDOW);
1047                                         break;
1048                         }
1049                         break;
1050                 case NC_WORLD:
1051                         switch (wmn->data) {
1052                                 case ND_WORLD_DRAW:
1053                                         if (v3d->flag2 & V3D_RENDER_OVERRIDE)
1054                                                 ED_area_tag_redraw_regiontype(sa, RGN_TYPE_WINDOW);
1055                                         break;
1056                         }
1057                         break;
1058                 case NC_MATERIAL:
1059                         switch (wmn->data) {
1060                                 case ND_NODES:
1061                                         if (v3d->drawtype == OB_TEXTURE)
1062                                                 ED_area_tag_redraw_regiontype(sa, RGN_TYPE_WINDOW);
1063                                         break;
1064                         }
1065                         break;
1066         }
1067
1068         /* removed since BKE_image_user_frame_calc is now called in view3d_draw_bgpic because screen_ops doesnt call the notifier. */
1069 #if 0
1070         if (wmn->category == NC_SCENE && wmn->data == ND_FRAME) {
1071                 View3D *v3d = area->spacedata.first;
1072                 BGpic *bgpic = v3d->bgpicbase.first;
1073
1074                 for (; bgpic; bgpic = bgpic->next) {
1075                         if (bgpic->ima) {
1076                                 Scene *scene = wmn->reference;
1077                                 BKE_image_user_frame_calc(&bgpic->iuser, scene->r.cfra, 0);
1078                         }
1079                 }
1080         }
1081 #endif
1082 }
1083
1084 const char *view3d_context_dir[] = {
1085         "selected_objects", "selected_bases", "selected_editable_objects",
1086         "selected_editable_bases", "visible_objects", "visible_bases", "selectable_objects", "selectable_bases",
1087         "active_base", "active_object", NULL
1088 };
1089
1090 static int view3d_context(const bContext *C, const char *member, bContextDataResult *result)
1091 {
1092         View3D *v3d = CTX_wm_view3d(C);
1093         Scene *scene = CTX_data_scene(C);
1094         Base *base;
1095         /* fallback to the scene layer, allows duplicate and other object operators to run outside the 3d view */
1096         unsigned int lay = v3d ? v3d->lay : scene->lay;
1097
1098         if (CTX_data_dir(member)) {
1099                 CTX_data_dir_set(result, view3d_context_dir);
1100         }
1101         else if (CTX_data_equals(member, "selected_objects") || CTX_data_equals(member, "selected_bases")) {
1102                 int selected_objects = CTX_data_equals(member, "selected_objects");
1103
1104                 for (base = scene->base.first; base; base = base->next) {
1105                         if ((base->flag & SELECT) && (base->lay & lay)) {
1106                                 if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) {
1107                                         if (selected_objects)
1108                                                 CTX_data_id_list_add(result, &base->object->id);
1109                                         else
1110                                                 CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
1111                                 }
1112                         }
1113                 }
1114                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
1115                 return 1;
1116         }
1117         else if (CTX_data_equals(member, "selected_editable_objects") || CTX_data_equals(member, "selected_editable_bases")) {
1118                 int selected_editable_objects = CTX_data_equals(member, "selected_editable_objects");
1119
1120                 for (base = scene->base.first; base; base = base->next) {
1121                         if ((base->flag & SELECT) && (base->lay & lay)) {
1122                                 if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) {
1123                                         if (0 == BKE_object_is_libdata(base->object)) {
1124                                                 if (selected_editable_objects)
1125                                                         CTX_data_id_list_add(result, &base->object->id);
1126                                                 else
1127                                                         CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
1128                                         }
1129                                 }
1130                         }
1131                 }
1132                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
1133                 return 1;
1134         }
1135         else if (CTX_data_equals(member, "visible_objects") || CTX_data_equals(member, "visible_bases")) {
1136                 int visible_objects = CTX_data_equals(member, "visible_objects");
1137
1138                 for (base = scene->base.first; base; base = base->next) {
1139                         if (base->lay & lay) {
1140                                 if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) {
1141                                         if (visible_objects)
1142                                                 CTX_data_id_list_add(result, &base->object->id);
1143                                         else
1144                                                 CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
1145                                 }
1146                         }
1147                 }
1148                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
1149                 return 1;
1150         }
1151         else if (CTX_data_equals(member, "selectable_objects") || CTX_data_equals(member, "selectable_bases")) {
1152                 int selectable_objects = CTX_data_equals(member, "selectable_objects");
1153
1154                 for (base = scene->base.first; base; base = base->next) {
1155                         if (base->lay & lay) {
1156                                 if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0 && (base->object->restrictflag & OB_RESTRICT_SELECT) == 0) {
1157                                         if (selectable_objects)
1158                                                 CTX_data_id_list_add(result, &base->object->id);
1159                                         else
1160                                                 CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
1161                                 }
1162                         }
1163                 }
1164                 CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
1165                 return 1;
1166         }
1167         else if (CTX_data_equals(member, "active_base")) {
1168                 if (scene->basact && (scene->basact->lay & lay)) {
1169                         Object *ob = scene->basact->object;
1170                         /* if hidden but in edit mode, we still display, can happen with animation */
1171                         if ((ob->restrictflag & OB_RESTRICT_VIEW) == 0 || (ob->mode & OB_MODE_EDIT))
1172                                 CTX_data_pointer_set(result, &scene->id, &RNA_ObjectBase, scene->basact);
1173                 }
1174                 
1175                 return 1;
1176         }
1177         else if (CTX_data_equals(member, "active_object")) {
1178                 if (scene->basact && (scene->basact->lay & lay)) {
1179                         Object *ob = scene->basact->object;
1180                         if ((ob->restrictflag & OB_RESTRICT_VIEW) == 0 || (ob->mode & OB_MODE_EDIT))
1181                                 CTX_data_id_pointer_set(result, &scene->basact->object->id);
1182                 }
1183                 
1184                 return 1;
1185         }
1186         else {
1187                 return 0; /* not found */
1188         }
1189
1190         return -1; /* found but not available */
1191 }
1192
1193
1194 /* only called once, from space/spacetypes.c */
1195 void ED_spacetype_view3d(void)
1196 {
1197         SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype view3d");
1198         ARegionType *art;
1199         
1200         st->spaceid = SPACE_VIEW3D;
1201         strncpy(st->name, "View3D", BKE_ST_MAXNAME);
1202         
1203         st->new = view3d_new;
1204         st->free = view3d_free;
1205         st->init = view3d_init;
1206         st->listener = space_view3d_listener;
1207         st->duplicate = view3d_duplicate;
1208         st->operatortypes = view3d_operatortypes;
1209         st->keymap = view3d_keymap;
1210         st->dropboxes = view3d_dropboxes;
1211         st->context = view3d_context;
1212         
1213         /* regions: main window */
1214         art = MEM_callocN(sizeof(ARegionType), "spacetype view3d main region");
1215         art->regionid = RGN_TYPE_WINDOW;
1216         art->keymapflag = ED_KEYMAP_GPENCIL;
1217         art->draw = view3d_main_area_draw;
1218         art->init = view3d_main_area_init;
1219         art->free = view3d_main_area_free;
1220         art->duplicate = view3d_main_area_duplicate;
1221         art->listener = view3d_main_area_listener;
1222         art->cursor = view3d_main_area_cursor;
1223         art->lock = 1;   /* can become flag, see BKE_spacedata_draw_locks */
1224         BLI_addhead(&st->regiontypes, art);
1225         
1226         /* regions: listview/buttons */
1227         art = MEM_callocN(sizeof(ARegionType), "spacetype view3d buttons region");
1228         art->regionid = RGN_TYPE_UI;
1229         art->prefsizex = 180; /* XXX */
1230         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
1231         art->listener = view3d_buttons_area_listener;
1232         art->init = view3d_buttons_area_init;
1233         art->draw = view3d_buttons_area_draw;
1234         BLI_addhead(&st->regiontypes, art);
1235
1236         view3d_buttons_register(art);
1237
1238         /* regions: tool(bar) */
1239         art = MEM_callocN(sizeof(ARegionType), "spacetype view3d tools region");
1240         art->regionid = RGN_TYPE_TOOLS;
1241         art->prefsizex = 160; /* XXX */
1242         art->prefsizey = 50; /* XXX */
1243         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
1244         art->listener = view3d_buttons_area_listener;
1245         art->init = view3d_tools_area_init;
1246         art->draw = view3d_tools_area_draw;
1247         BLI_addhead(&st->regiontypes, art);
1248         
1249 #if 0
1250         /* unfinished still */
1251         view3d_toolshelf_register(art);
1252 #endif
1253
1254         /* regions: tool properties */
1255         art = MEM_callocN(sizeof(ARegionType), "spacetype view3d tool properties region");
1256         art->regionid = RGN_TYPE_TOOL_PROPS;
1257         art->prefsizex = 0;
1258         art->prefsizey = 120;
1259         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
1260         art->listener = view3d_props_area_listener;
1261         art->init = view3d_tools_area_init;
1262         art->draw = view3d_tools_area_draw;
1263         BLI_addhead(&st->regiontypes, art);
1264         
1265         view3d_tool_props_register(art);
1266         
1267         
1268         /* regions: header */
1269         art = MEM_callocN(sizeof(ARegionType), "spacetype view3d header region");
1270         art->regionid = RGN_TYPE_HEADER;
1271         art->prefsizey = HEADERY;
1272         art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER;
1273         art->listener = view3d_header_area_listener;
1274         art->init = view3d_header_area_init;
1275         art->draw = view3d_header_area_draw;
1276         BLI_addhead(&st->regiontypes, art);
1277         
1278         BKE_spacetype_register(st);
1279 }
1280