Blender V5.0
outliner_dragdrop.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2004 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstring>
10
11#include "MEM_guardedalloc.h"
12
14#include "DNA_material_types.h"
15#include "DNA_object_types.h"
16#include "DNA_space_types.h"
17
18#include "BLI_listbase.h"
19
20#include "BLT_translation.hh"
21
22#include "BKE_collection.hh"
23#include "BKE_context.hh"
24#include "BKE_layer.hh"
25#include "BKE_lib_id.hh"
26#include "BKE_library.hh"
27#include "BKE_main.hh"
28#include "BKE_material.hh"
29#include "BKE_object.hh"
30#include "BKE_report.hh"
31
32#include "DEG_depsgraph.hh"
34
35#include "ED_object.hh"
36#include "ED_outliner.hh"
37#include "ED_screen.hh"
38
39#include "UI_interface.hh"
40#include "UI_view2d.hh"
41
42#include "RNA_access.hh"
43
44#include "WM_api.hh"
45#include "WM_types.hh"
46
47#include "outliner_intern.hh"
48
49namespace blender::ed::outliner {
50
52
53/* -------------------------------------------------------------------- */
56
58 const float fmval[2],
59 const bool children)
60{
61 if ((fmval[1] > te->ys) && (fmval[1] < (te->ys + UI_UNIT_Y))) {
62 /* name and first icon */
63 if ((fmval[0] > te->xs + UI_UNIT_X) && (fmval[0] < te->xend)) {
64 return te;
65 }
66 }
67 /* Not it. Let's look at its children. */
68 if (children && (TREESTORE(te)->flag & TSE_CLOSED) == 0 && (te->subtree.first)) {
69 LISTBASE_FOREACH (TreeElement *, te_sub, &te->subtree) {
70 TreeElement *te_valid = outliner_dropzone_element(te_sub, fmval, children);
71 if (te_valid) {
72 return te_valid;
73 }
74 }
75 }
76 return nullptr;
77}
78
79/* Find tree element to drop into. */
80static TreeElement *outliner_dropzone_find(const SpaceOutliner *space_outliner,
81 const float fmval[2],
82 const bool children)
83{
84 LISTBASE_FOREACH (TreeElement *, te, &space_outliner->tree) {
85 TreeElement *te_valid = outliner_dropzone_element(te, fmval, children);
86 if (te_valid) {
87 return te_valid;
88 }
89 }
90 return nullptr;
91}
92
94{
95 ARegion *region = CTX_wm_region(C);
96 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
97 float fmval[2];
98 UI_view2d_region_to_view(&region->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]);
99
100 return outliner_dropzone_find(space_outliner, fmval, true);
101}
102
103static ID *outliner_ID_drop_find(bContext *C, const wmEvent *event, short idcode)
104{
105 TreeElement *te = outliner_drop_find(C, event);
106 TreeStoreElem *tselem = (te) ? TREESTORE(te) : nullptr;
107
108 if (te && (te->idcode == idcode) && (tselem->type == TSE_SOME_ID)) {
109 return tselem->id;
110 }
111 return nullptr;
112}
113
114/* Find tree element to drop into, with additional before and after reorder support. */
116 const int xy[2],
117 TreeElementInsertType *r_insert_type)
118{
119 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
120 ARegion *region = CTX_wm_region(C);
121 TreeElement *te_hovered;
122 float view_mval[2];
123
124 /* Empty tree, e.g. while filtered. */
125 if (BLI_listbase_is_empty(&space_outliner->tree)) {
126 return nullptr;
127 }
128
129 int mval[2];
130 mval[0] = xy[0] - region->winrct.xmin;
131 mval[1] = xy[1] - region->winrct.ymin;
132
133 UI_view2d_region_to_view(&region->v2d, mval[0], mval[1], &view_mval[0], &view_mval[1]);
134 te_hovered = outliner_find_item_at_y(space_outliner, &space_outliner->tree, view_mval[1]);
135
136 if (te_hovered) {
137 /* Mouse hovers an element (ignoring x-axis),
138 * now find out how to insert the dragged item exactly. */
139 const float margin = UI_UNIT_Y * (1.0f / 4);
140
141 if (view_mval[1] < (te_hovered->ys + margin)) {
142 if (TSELEM_OPEN(TREESTORE(te_hovered), space_outliner) &&
143 !BLI_listbase_is_empty(&te_hovered->subtree))
144 {
145 /* inserting after a open item means we insert into it, but as first child */
146 if (BLI_listbase_is_empty(&te_hovered->subtree)) {
147 *r_insert_type = TE_INSERT_INTO;
148 return te_hovered;
149 }
150 *r_insert_type = TE_INSERT_BEFORE;
151 return static_cast<TreeElement *>(te_hovered->subtree.first);
152 }
153 *r_insert_type = TE_INSERT_AFTER;
154 return te_hovered;
155 }
156 if (view_mval[1] > (te_hovered->ys + (3 * margin))) {
157 *r_insert_type = TE_INSERT_BEFORE;
158 return te_hovered;
159 }
160 *r_insert_type = TE_INSERT_INTO;
161 return te_hovered;
162 }
163
164 /* Mouse doesn't hover any item (ignoring x-axis),
165 * so it's either above list bounds or below. */
166 TreeElement *first = static_cast<TreeElement *>(space_outliner->tree.first);
167 TreeElement *last = static_cast<TreeElement *>(space_outliner->tree.last);
168
169 if (view_mval[1] < last->ys) {
170 *r_insert_type = TE_INSERT_AFTER;
171 return last;
172 }
173 if (view_mval[1] > (first->ys + UI_UNIT_Y)) {
174 *r_insert_type = TE_INSERT_BEFORE;
175 return first;
176 }
177
179 return nullptr;
180}
181
182using CheckTypeFn = bool (*)(TreeElement *te);
183
185 TreeElement *te)
186{
187 while (te != nullptr) {
188 if (check_type(te)) {
189 return te;
190 }
191 te = te->parent;
192 }
193 return nullptr;
194}
195
200
202{
203 TreeStoreElem *tselem = TREESTORE(te);
204 return (tselem->type == TSE_SOME_ID) && te->idcode == ID_OB;
205}
206
208{
209 TreeStoreElem *tselem = TREESTORE(te);
210 return tselem->type == TSE_POSE_CHANNEL;
211}
212
214 const int xy[2],
215 TreeElementInsertType *r_insert_type)
216{
217 TreeElement *te = outliner_drop_insert_find(C, xy, r_insert_type);
218 if (!te) {
219 return nullptr;
220 }
221
223 te);
224 if (!collection_te) {
225 return nullptr;
226 }
227 Collection *collection = outliner_collection_from_tree_element(collection_te);
228
229 if (collection_te != te) {
230 *r_insert_type = TE_INSERT_INTO;
231 }
232
233 /* We can't insert before/after master collection. */
234 if (collection->flag & COLLECTION_IS_MASTER) {
235 *r_insert_type = TE_INSERT_INTO;
236 }
237
238 return collection_te;
239}
240
242 TreeElement *drop_te,
243 TreeElementInsertType insert_type,
244 ListBase *listbase)
245{
246 /* Find the element to insert after. Null is the start of the list. */
247 if (drag_te->index < drop_te->index) {
248 if (insert_type == TE_INSERT_BEFORE) {
249 drop_te = drop_te->prev;
250 }
251 }
252 else {
253 if (insert_type == TE_INSERT_AFTER) {
254 drop_te = drop_te->next;
255 }
256 }
257
258 if (drop_te == nullptr) {
259 return 0;
260 }
261
262 return BLI_findindex(listbase, drop_te->directdata);
263}
264
266
267/* -------------------------------------------------------------------- */
270
271static bool parent_drop_allowed(TreeElement *te, Object *potential_child)
272{
273 TreeStoreElem *tselem = TREESTORE(te);
274 if ((te->idcode != ID_OB) || (tselem->type != TSE_SOME_ID)) {
275 return false;
276 }
277
278 Object *potential_parent = (Object *)tselem->id;
279
280 if (potential_parent == potential_child) {
281 return false;
282 }
283 if (BKE_object_is_child_recursive(potential_child, potential_parent)) {
284 return false;
285 }
286 if (potential_parent == potential_child->parent) {
287 return false;
288 }
289
290 /* check that parent/child are both in the same scene */
291 Scene *scene = (Scene *)outliner_search_back(te, ID_SCE);
292
293 /* currently outliner organized in a way that if there's no parent scene
294 * element for object it means that all displayed objects belong to
295 * active scene and parenting them is allowed (sergey) */
296 if (scene) {
297 LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
298 BKE_view_layer_synced_ensure(scene, view_layer);
299 if (BKE_view_layer_base_find(view_layer, potential_child)) {
300 return true;
301 }
302 }
303 return false;
304 }
305 return true;
306}
307
309{
310 switch (space_outliner->outlinevis) {
311 case SO_VIEW_LAYER:
312 return space_outliner->filter & SO_FILTER_NO_COLLECTION;
313 case SO_SCENES:
314 return true;
315 default:
316 return false;
317 }
318}
319
320static bool parent_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
321{
322 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
323
324 bool changed = outliner_flag_set(*space_outliner, TSE_DRAG_ANY, false);
325 if (changed) {
327 }
328
329 Object *potential_child = (Object *)WM_drag_get_local_ID(drag, ID_OB);
330 if (!potential_child) {
331 return false;
332 }
333
334 if (!allow_parenting_without_modifier_key(space_outliner)) {
335 if ((event->modifier & KM_SHIFT) == 0) {
336 return false;
337 }
338 }
339
340 TreeElement *te = outliner_drop_find(C, event);
341 if (!te) {
342 return false;
343 }
344
345 if (parent_drop_allowed(te, potential_child)) {
346 TREESTORE(te)->flag |= TSE_DRAG_INTO;
348 return true;
349 }
350
351 return false;
352}
353
355 ReportList *reports,
356 wmDragID *drag,
357 Object *parent,
358 short parent_type,
359 const bool keep_transform)
360{
361 Main *bmain = CTX_data_main(C);
362 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
363
364 TreeElement *te = outliner_find_id(space_outliner, &space_outliner->tree, &parent->id);
365 Scene *scene = (Scene *)outliner_search_back(te, ID_SCE);
366
367 if (scene == nullptr) {
368 /* currently outliner organized in a way, that if there's no parent scene
369 * element for object it means that all displayed objects belong to
370 * active scene and parenting them is allowed (sergey)
371 */
372
373 scene = CTX_data_scene(C);
374 }
375
376 bool parent_set = false;
377 bool linked_objects = false;
378
379 for (wmDragID *drag_id = drag; drag_id; drag_id = drag_id->next) {
380 if (GS(drag_id->id->name) == ID_OB) {
381 Object *object = (Object *)drag_id->id;
382
383 /* Do nothing to linked data */
384 if (!BKE_id_is_editable(bmain, &object->id)) {
385 linked_objects = true;
386 continue;
387 }
388
390 reports, C, scene, object, parent, parent_type, false, keep_transform, nullptr))
391 {
392 parent_set = true;
393 }
394 }
395 }
396
397 if (linked_objects) {
398 BKE_report(reports, RPT_INFO, "Cannot edit library linked or non-editable override object(s)");
399 }
400
401 if (parent_set) {
405 }
406}
407
409{
410 TreeElement *te = outliner_drop_find(C, event);
411 TreeStoreElem *tselem = te ? TREESTORE(te) : nullptr;
412
413 if (!(te && (te->idcode == ID_OB) && (tselem->type == TSE_SOME_ID))) {
414 return OPERATOR_CANCELLED;
415 }
416
417 Object *par = (Object *)tselem->id;
419
420 if (ELEM(nullptr, ob, par)) {
421 return OPERATOR_CANCELLED;
422 }
423 if (ob == par) {
424 return OPERATOR_CANCELLED;
425 }
426
427 if (event->custom != EVT_DATA_DRAGDROP) {
428 return OPERATOR_CANCELLED;
429 }
430
431 ListBase *lb = static_cast<ListBase *>(event->customdata);
432 wmDrag *drag = static_cast<wmDrag *>(lb->first);
433
435 op->reports,
436 static_cast<wmDragID *>(drag->ids.first),
437 par,
439 !(event->modifier & KM_ALT));
440
441 return OPERATOR_FINISHED;
442}
443
445{
446 /* identifiers */
447 ot->name = "Drop to Set Parent (hold Alt to not keep transforms)";
448 ot->description = "Drag to parent in Outliner";
449 ot->idname = "OUTLINER_OT_parent_drop";
450
451 /* API callbacks. */
452 ot->invoke = parent_drop_invoke;
453
455
456 /* flags */
458}
459
461
462/* -------------------------------------------------------------------- */
465
466static bool parent_clear_poll(bContext *C, wmDrag *drag, const wmEvent *event)
467{
468 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
469
470 if (!allow_parenting_without_modifier_key(space_outliner)) {
471 if ((event->modifier & KM_SHIFT) == 0) {
472 return false;
473 }
474 }
475
476 Object *ob = (Object *)WM_drag_get_local_ID(drag, ID_OB);
477 if (!ob) {
478 return false;
479 }
480 if (!ob->parent) {
481 return false;
482 }
483
484 TreeElement *te = outliner_drop_find(C, event);
485 if (te) {
486 TreeStoreElem *tselem = TREESTORE(te);
487 ID *id = tselem->id;
488 if (!id) {
489 return true;
490 }
491
492 switch (GS(id->name)) {
493 case ID_OB:
495 case ID_GR:
496 return (event->modifier & KM_SHIFT) || ELEM(tselem->type, TSE_LIBRARY_OVERRIDE_BASE);
497 default:
498 return true;
499 }
500 }
501 else {
502 return true;
503 }
504}
505
507{
508 Main *bmain = CTX_data_main(C);
509
510 if (event->custom != EVT_DATA_DRAGDROP) {
511 return OPERATOR_CANCELLED;
512 }
513
514 ListBase *lb = static_cast<ListBase *>(event->customdata);
515 wmDrag *drag = static_cast<wmDrag *>(lb->first);
516
517 LISTBASE_FOREACH (wmDragID *, drag_id, &drag->ids) {
518 if (GS(drag_id->id->name) == ID_OB) {
519 Object *object = (Object *)drag_id->id;
520
524 }
525 }
526
530 return OPERATOR_FINISHED;
531}
532
534{
535 /* identifiers */
536 ot->name = "Drop to Clear Parent (hold Alt to not keep transforms)";
537 ot->description = "Drag to clear parent in Outliner";
538 ot->idname = "OUTLINER_OT_parent_clear";
539
540 /* API callbacks. */
541 ot->invoke = parent_clear_invoke;
542
544
545 /* flags */
547}
548
550
551/* -------------------------------------------------------------------- */
554
555static bool scene_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
556{
557 /* Ensure item under cursor is valid drop target */
558 Object *ob = (Object *)WM_drag_get_local_ID(drag, ID_OB);
559 return (ob && (outliner_ID_drop_find(C, event, ID_SCE) != nullptr));
560}
561
563{
564 Main *bmain = CTX_data_main(C);
565 Scene *scene = (Scene *)outliner_ID_drop_find(C, event, ID_SCE);
567
568 if (ELEM(nullptr, ob, scene) || !BKE_id_is_editable(bmain, &scene->id)) {
569 return OPERATOR_CANCELLED;
570 }
571
572 if (BKE_scene_has_object(scene, ob)) {
573 return OPERATOR_CANCELLED;
574 }
575
576 Collection *collection;
577 if (scene != CTX_data_scene(C)) {
578 /* when linking to an inactive scene link to the master collection */
579 collection = scene->master_collection;
580 }
581 else {
582 collection = CTX_data_collection(C);
583 }
584
585 BKE_collection_object_add(bmain, collection, ob);
586
587 LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
588 BKE_view_layer_synced_ensure(scene, view_layer);
589 Base *base = BKE_view_layer_base_find(view_layer, ob);
590 if (base) {
592 }
593 }
594
597
600
601 return OPERATOR_FINISHED;
602}
603
605{
606 /* identifiers */
607 ot->name = "Drop Object to Scene";
608 ot->description = "Drag object to scene in Outliner";
609 ot->idname = "OUTLINER_OT_scene_drop";
610
611 /* API callbacks. */
612 ot->invoke = scene_drop_invoke;
613
615
616 /* flags */
618}
619
621
622/* -------------------------------------------------------------------- */
625
626static bool material_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
627{
628 /* Ensure item under cursor is valid drop target */
630 Object *ob = reinterpret_cast<Object *>(outliner_ID_drop_find(C, event, ID_OB));
631
632 return (!ELEM(nullptr, ob, ma) && ID_IS_EDITABLE(&ob->id) && !ID_IS_OVERRIDE_LIBRARY(&ob->id));
633}
634
636 wmOperator * /*op*/,
637 const wmEvent *event)
638{
639 Main *bmain = CTX_data_main(C);
640 Object *ob = (Object *)outliner_ID_drop_find(C, event, ID_OB);
642
643 if (ELEM(nullptr, ob, ma) || !BKE_id_is_editable(bmain, &ob->id)) {
644 return OPERATOR_CANCELLED;
645 }
646
647 /* only drop grease pencil material on grease pencil objects */
648 if ((ma->gp_style != nullptr) && (ob->type != OB_GREASE_PENCIL)) {
649 return OPERATOR_CANCELLED;
650 }
651
653
657
658 return OPERATOR_FINISHED;
659}
660
662{
663 /* identifiers */
664 ot->name = "Drop Material on Object";
665 ot->description = "Drag material to object in Outliner";
666 ot->idname = "OUTLINER_OT_material_drop";
667
668 /* API callbacks. */
669 ot->invoke = material_drop_invoke;
670
672
673 /* flags */
675}
676
678
679/* -------------------------------------------------------------------- */
690
696
708
710 Object *ob,
711 bPoseChannel *pchan,
712 TreeElement *te,
713 TreeStoreElem *tselem,
714 void *directdata)
715{
716 StackDropData *drop_data = MEM_callocN<StackDropData>("datastack drop data");
717
718 drop_data->ob_parent = ob;
719 drop_data->pchan_parent = pchan;
720 drop_data->drag_tselem = tselem;
721 drop_data->drag_directdata = directdata;
722 drop_data->drag_index = te->index;
723
724 drag->poin = drop_data;
725 drag->flags |= WM_DRAG_FREE_DATA;
726}
727
728static bool datastack_drop_init(bContext *C, const wmEvent *event, StackDropData *drop_data)
729{
730 if (!ELEM(drop_data->drag_tselem->type,
737 {
738 return false;
739 }
740
741 TreeElement *te_target = outliner_drop_insert_find(C, event->xy, &drop_data->insert_type);
742 if (!te_target) {
743 return false;
744 }
745 TreeStoreElem *tselem_target = TREESTORE(te_target);
746
747 if (drop_data->drag_tselem == tselem_target) {
748 return false;
749 }
750
751 Object *ob = nullptr;
753 te_target);
754 if (object_te) {
755 ob = (Object *)TREESTORE(object_te)->id;
756 }
757
758 bPoseChannel *pchan = nullptr;
760 if (pchan_te) {
761 pchan = (bPoseChannel *)pchan_te->directdata;
762 }
763 if (pchan) {
764 ob = nullptr;
765 }
766
767 if (ob && !BKE_id_is_editable(CTX_data_main(C), &ob->id)) {
768 return false;
769 }
770
771 /* Drag a base for linking. */
772 if (ELEM(drop_data->drag_tselem->type,
776 {
777 drop_data->insert_type = TE_INSERT_INTO;
779
780 if (pchan && pchan != drop_data->pchan_parent) {
781 drop_data->drop_te = pchan_te;
782 tselem_target = TREESTORE(pchan_te);
783 }
784 else if (ob && ob != drop_data->ob_parent) {
785 drop_data->drop_te = object_te;
786 tselem_target = TREESTORE(object_te);
787 }
788 else {
789 return false;
790 }
791 }
792 else if (ob || pchan) {
793 /* Drag a single item. */
794 if (pchan && pchan != drop_data->pchan_parent) {
795 drop_data->insert_type = TE_INSERT_INTO;
797 drop_data->drop_te = pchan_te;
798 tselem_target = TREESTORE(pchan_te);
799 }
800 else if (ob && ob != drop_data->ob_parent) {
801 drop_data->insert_type = TE_INSERT_INTO;
803 drop_data->drop_te = object_te;
804 tselem_target = TREESTORE(object_te);
805 }
806 else if (tselem_target->type == drop_data->drag_tselem->type) {
807 if (drop_data->insert_type == TE_INSERT_INTO) {
808 return false;
809 }
811 drop_data->drop_te = te_target;
812 }
813 else {
814 return false;
815 }
816 }
817 else {
818 return false;
819 }
820
821 return true;
822}
823
824/* Ensure that grease pencil and object data remain separate. */
826{
827 TreeStoreElem *tselem = TREESTORE(drop_data->drop_te);
828 Object *ob_parent = drop_data->ob_parent;
829 Object *ob_dst = (Object *)tselem->id;
830
831 /* Don't allow data to be moved between objects and bones. */
832 if (tselem->type == TSE_CONSTRAINT) {
833 }
834 else if ((drop_data->pchan_parent && tselem->type != TSE_POSE_CHANNEL) ||
835 (!drop_data->pchan_parent && tselem->type == TSE_POSE_CHANNEL))
836 {
837 return false;
838 }
839
840 switch (drop_data->drag_tselem->type) {
842 case TSE_MODIFIER:
843 return (ob_parent->type == OB_GREASE_PENCIL) == (ob_dst->type == OB_GREASE_PENCIL);
844 break;
846 case TSE_CONSTRAINT:
847
848 break;
851 return ob_parent->type == OB_GREASE_PENCIL && ob_dst->type == OB_GREASE_PENCIL;
852 break;
853 }
854
855 return true;
856}
857
858static bool datastack_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
859{
860 if (drag->type != WM_DRAG_DATASTACK) {
861 return false;
862 }
863
864 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
865 ARegion *region = CTX_wm_region(C);
866 bool changed = outliner_flag_set(*space_outliner, TSE_HIGHLIGHTED_ANY | TSE_DRAG_ANY, false);
867
868 StackDropData *drop_data = static_cast<StackDropData *>(drag->poin);
869 if (!drop_data) {
870 return false;
871 }
872
873 if (!datastack_drop_init(C, event, drop_data)) {
874 return false;
875 }
876
877 if (!datastack_drop_are_types_valid(drop_data)) {
878 return false;
879 }
880
881 TreeStoreElem *tselem_target = TREESTORE(drop_data->drop_te);
882 switch (drop_data->insert_type) {
883 case TE_INSERT_BEFORE:
884 tselem_target->flag |= TSE_DRAG_BEFORE;
885 break;
886 case TE_INSERT_AFTER:
887 tselem_target->flag |= TSE_DRAG_AFTER;
888 break;
889 case TE_INSERT_INTO:
890 tselem_target->flag |= TSE_DRAG_INTO;
891 break;
892 }
893
894 if (changed) {
896 }
897
898 return true;
899}
900
901static std::string datastack_drop_tooltip(bContext * /*C*/,
902 wmDrag *drag,
903 const int /*xy*/[2],
904 wmDropBox * /*drop*/)
905{
906 StackDropData *drop_data = static_cast<StackDropData *>(drag->poin);
907 switch (drop_data->drop_action) {
909 return TIP_("Reorder");
911 if (drop_data->pchan_parent) {
912 return TIP_("Copy to bone");
913 }
914 return TIP_("Copy to object");
915
917 if (drop_data->pchan_parent) {
918 return TIP_("Link all to bone");
919 }
920 return TIP_("Link all to object");
921 }
922 return {};
923}
924
926{
927 Main *bmain = CTX_data_main(C);
928 TreeStoreElem *tselem = TREESTORE(drop_data->drop_te);
929 Object *ob_dst = (Object *)tselem->id;
930
931 switch (drop_data->drag_tselem->type) {
933 object::modifier_link(C, ob_dst, drop_data->ob_parent);
934 break;
935 case TSE_CONSTRAINT_BASE: {
936 ListBase *src;
937
938 if (drop_data->pchan_parent) {
939 src = &drop_data->pchan_parent->constraints;
940 }
941 else {
942 src = &drop_data->ob_parent->constraints;
943 }
944
945 ListBase *dst;
946 if (tselem->type == TSE_POSE_CHANNEL) {
947 bPoseChannel *pchan = (bPoseChannel *)drop_data->drop_te->directdata;
948 dst = &pchan->constraints;
949 }
950 else {
951 dst = &ob_dst->constraints;
952 }
953
954 object::constraint_link(bmain, ob_dst, dst, src);
955 break;
956 }
958 if (ob_dst->type != OB_GREASE_PENCIL) {
959 return;
960 }
961
962 object::shaderfx_link(ob_dst, drop_data->ob_parent);
963 break;
964 }
965}
966
968{
969 Main *bmain = CTX_data_main(C);
970
971 TreeStoreElem *tselem = TREESTORE(drop_data->drop_te);
972 Object *ob_dst = (Object *)tselem->id;
973
974 switch (drop_data->drag_tselem->type) {
975 case TSE_MODIFIER:
977 bmain,
979 drop_data->ob_parent,
980 static_cast<const ModifierData *>(drop_data->drag_directdata),
981 ob_dst,
983 break;
984 case TSE_CONSTRAINT:
985 if (tselem->type == TSE_POSE_CHANNEL) {
987 bmain,
988 ob_dst,
989 static_cast<bPoseChannel *>(drop_data->drop_te->directdata),
990 static_cast<bConstraint *>(drop_data->drag_directdata));
991 }
992 else {
994 bmain, ob_dst, static_cast<bConstraint *>(drop_data->drag_directdata));
995 }
996 break;
997 case TSE_GPENCIL_EFFECT: {
998 if (ob_dst->type != OB_GREASE_PENCIL) {
999 return;
1000 }
1001
1002 object::shaderfx_copy(ob_dst, static_cast<ShaderFxData *>(drop_data->drag_directdata));
1003 break;
1004 }
1005 }
1006}
1007
1008static void datastack_drop_reorder(bContext *C, ReportList *reports, StackDropData *drop_data)
1009{
1010 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
1011
1012 TreeElement *drag_te = outliner_find_tree_element(&space_outliner->tree, drop_data->drag_tselem);
1013 if (!drag_te) {
1014 return;
1015 }
1016
1017 TreeElement *drop_te = drop_data->drop_te;
1018 TreeElementInsertType insert_type = drop_data->insert_type;
1019
1020 Object *ob = drop_data->ob_parent;
1021
1022 int index = 0;
1023 switch (drop_data->drag_tselem->type) {
1024 case TSE_MODIFIER:
1025 index = outliner_get_insert_index(drag_te, drop_te, insert_type, &ob->modifiers);
1028 ob,
1029 static_cast<ModifierData *>(drop_data->drag_directdata),
1030 index,
1031 true);
1032 break;
1033 case TSE_CONSTRAINT:
1034 if (drop_data->pchan_parent) {
1036 drag_te, drop_te, insert_type, &drop_data->pchan_parent->constraints);
1037 }
1038 else {
1039 index = outliner_get_insert_index(drag_te, drop_te, insert_type, &ob->constraints);
1040 }
1042 ob, static_cast<bConstraint *>(drop_data->drag_directdata), index);
1043
1044 break;
1045 case TSE_GPENCIL_EFFECT:
1046 index = outliner_get_insert_index(drag_te, drop_te, insert_type, &ob->shader_fx);
1048 reports, ob, static_cast<ShaderFxData *>(drop_data->drag_directdata), index);
1049 }
1050}
1051
1053{
1054 if (event->custom != EVT_DATA_DRAGDROP) {
1055 return OPERATOR_CANCELLED;
1056 }
1057
1058 ListBase *lb = static_cast<ListBase *>(event->customdata);
1059 wmDrag *drag = static_cast<wmDrag *>(lb->first);
1060 StackDropData *drop_data = static_cast<StackDropData *>(drag->poin);
1061
1062 switch (drop_data->drop_action) {
1064 datastack_drop_link(C, drop_data);
1065 break;
1067 datastack_drop_copy(C, drop_data);
1068 break;
1070 datastack_drop_reorder(C, op->reports, drop_data);
1071 break;
1072 }
1073
1074 return OPERATOR_FINISHED;
1075}
1076
1078{
1079 /* identifiers */
1080 ot->name = "Data Stack Drop";
1081 ot->description = "Copy or reorder modifiers, constraints, and effects";
1082 ot->idname = "OUTLINER_OT_datastack_drop";
1083
1084 /* API callbacks. */
1085 ot->invoke = datastack_drop_invoke;
1086
1088
1089 /* flags */
1091}
1092
1094
1095/* -------------------------------------------------------------------- */
1098
1106
1108{
1109 /* Can't change linked or override parent collections. */
1110 if (!id || !ID_IS_EDITABLE(id) || ID_IS_OVERRIDE_LIBRARY(id)) {
1111 return nullptr;
1112 }
1113
1114 /* Also support dropping into/from scene collection. */
1115 if (GS(id->name) == ID_SCE) {
1116 return ((Scene *)id)->master_collection;
1117 }
1118 if (GS(id->name) == ID_GR) {
1119 return (Collection *)id;
1120 }
1121
1122 return nullptr;
1123}
1124
1125static bool collection_drop_init(bContext *C, wmDrag *drag, const int xy[2], CollectionDrop *data)
1126{
1127 /* Get collection to drop into. */
1128 TreeElementInsertType insert_type;
1130 if (!te) {
1131 return false;
1132 }
1133
1135 if (!ID_IS_EDITABLE(to_collection) || ID_IS_OVERRIDE_LIBRARY(to_collection)) {
1136 if (insert_type == TE_INSERT_INTO) {
1137 return false;
1138 }
1139 }
1140
1141 /* Get drag datablocks. */
1142 if (drag->type != WM_DRAG_ID) {
1143 return false;
1144 }
1145
1146 wmDragID *drag_id = static_cast<wmDragID *>(drag->ids.first);
1147 if (drag_id == nullptr) {
1148 return false;
1149 }
1150
1151 ID *id = drag_id->id;
1152 if (!(id && ELEM(GS(id->name), ID_GR, ID_OB))) {
1153 return false;
1154 }
1155
1156 /* Get collection to drag out of. */
1157 ID *parent = drag_id->from_parent;
1158 Collection *from_collection = collection_parent_from_ID(parent);
1159
1160 /* Currently this should not be allowed, cannot edit items in an override of a Collection. */
1161 if (from_collection != nullptr && ID_IS_OVERRIDE_LIBRARY(from_collection)) {
1162 return false;
1163 }
1164
1165 /* Get collections. */
1166 if (GS(id->name) == ID_GR) {
1167 if (id == &to_collection->id) {
1168 return false;
1169 }
1170 }
1171 else {
1172 insert_type = TE_INSERT_INTO;
1173 }
1174
1175 /* Currently this should not be allowed, cannot edit items in an override of a Collection. */
1176 if (ID_IS_OVERRIDE_LIBRARY(to_collection) &&
1177 !ELEM(insert_type, TE_INSERT_AFTER, TE_INSERT_BEFORE))
1178 {
1179 return false;
1180 }
1181
1182 data->from = from_collection;
1183 data->to = to_collection;
1184 data->te = te;
1185 data->insert_type = insert_type;
1186
1187 return true;
1188}
1189
1190static bool collection_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
1191{
1192 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
1193 ARegion *region = CTX_wm_region(C);
1194 bool changed = outliner_flag_set(*space_outliner, TSE_HIGHLIGHTED_ANY | TSE_DRAG_ANY, false);
1195
1197 if (((event->modifier & KM_SHIFT) == 0) && collection_drop_init(C, drag, event->xy, &data)) {
1198 TreeElement *te = data.te;
1199 TreeStoreElem *tselem = TREESTORE(te);
1200 switch (data.insert_type) {
1201 case TE_INSERT_BEFORE:
1202 tselem->flag |= TSE_DRAG_BEFORE;
1203 changed = true;
1204 break;
1205 case TE_INSERT_AFTER:
1206 tselem->flag |= TSE_DRAG_AFTER;
1207 changed = true;
1208 break;
1209 case TE_INSERT_INTO: {
1210 tselem->flag |= TSE_DRAG_INTO;
1211 changed = true;
1212 break;
1213 }
1214 }
1215 if (changed) {
1217 }
1218 return true;
1219 }
1220 if (changed) {
1222 }
1223 return false;
1224}
1225
1227 wmDrag *drag,
1228 const int xy[2],
1229 wmDropBox * /*drop*/)
1230{
1231 wmWindow *win = CTX_wm_window(C);
1232 const wmEvent *event = win ? win->eventstate : nullptr;
1233
1235 if (event && ((event->modifier & KM_SHIFT) == 0) && collection_drop_init(C, drag, xy, &data)) {
1236 const bool is_link = !data.from || (event->modifier & KM_CTRL);
1237
1238 /* Test if we are moving within same parent collection. */
1239 bool same_level = false;
1240 LISTBASE_FOREACH (CollectionParent *, parent, &data.to->runtime->parents) {
1241 if (data.from == parent->collection) {
1242 same_level = true;
1243 }
1244 }
1245
1246 /* Tooltips when not moving directly into another collection i.e. mouse on border of
1247 * collections. Later we will decide which tooltip to return. */
1248 const bool tooltip_link = (is_link && !same_level);
1249 const char *tooltip_before = tooltip_link ? TIP_("Link before collection") :
1250 TIP_("Move before collection");
1251 const char *tooltip_between = tooltip_link ? TIP_("Link between collections") :
1252 TIP_("Move between collections");
1253 const char *tooltip_after = tooltip_link ? TIP_("Link after collection") :
1254 TIP_("Move after collection");
1255
1256 TreeElement *te = data.te;
1257 switch (data.insert_type) {
1258 case TE_INSERT_BEFORE:
1260 return tooltip_between;
1261 }
1262 return tooltip_before;
1263 case TE_INSERT_AFTER:
1265 return tooltip_between;
1266 }
1267 return tooltip_after;
1268 case TE_INSERT_INTO: {
1269 if (is_link) {
1270 return TIP_("Link inside collection");
1271 }
1272
1273 /* Check the type of the drag IDs to avoid the incorrect "Shift to parent"
1274 * for collections. Checking the type of the first ID works fine here since
1275 * all drag IDs are the same type. */
1276 wmDragID *drag_id = (wmDragID *)drag->ids.first;
1277 const bool is_object = (GS(drag_id->id->name) == ID_OB);
1278 if (is_object) {
1279 return TIP_("Move inside collection (Ctrl to link, Shift to parent)");
1280 }
1281 return TIP_("Move inside collection (Ctrl to link)");
1282 }
1283 }
1284 }
1285 return {};
1286}
1287
1289 wmOperator * /*op*/,
1290 const wmEvent *event)
1291{
1292 Main *bmain = CTX_data_main(C);
1293 Scene *scene = CTX_data_scene(C);
1294
1295 if (event->custom != EVT_DATA_DRAGDROP) {
1296 return OPERATOR_CANCELLED;
1297 }
1298
1299 ListBase *lb = static_cast<ListBase *>(event->customdata);
1300 wmDrag *drag = static_cast<wmDrag *>(lb->first);
1301
1303 if (!collection_drop_init(C, drag, event->xy, &data)) {
1304 return OPERATOR_CANCELLED;
1305 }
1306
1307 /* Before/after insert handling. */
1308 Collection *relative = nullptr;
1309 bool relative_after = false;
1310
1311 if (ELEM(data.insert_type, TE_INSERT_BEFORE, TE_INSERT_AFTER)) {
1312 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
1313
1314 relative = data.to;
1315 relative_after = (data.insert_type == TE_INSERT_AFTER);
1316
1317 TreeElement *parent_te = outliner_find_parent_element(&space_outliner->tree, nullptr, data.te);
1318 data.to = (parent_te) ? outliner_collection_from_tree_element(parent_te) : nullptr;
1319 }
1320
1321 if (!data.to) {
1322 return OPERATOR_CANCELLED;
1323 }
1324
1325 if (BKE_collection_is_empty(data.to)) {
1326 TREESTORE(data.te)->flag &= ~TSE_CLOSED;
1327 }
1328
1329 LISTBASE_FOREACH (wmDragID *, drag_id, &drag->ids) {
1330 /* Ctrl enables linking, so we don't need a from collection then. */
1331 Collection *from = (event->modifier & KM_CTRL) ?
1332 nullptr :
1333 collection_parent_from_ID(drag_id->from_parent);
1334
1335 if (GS(drag_id->id->name) == ID_OB) {
1336 /* Move/link object into collection. */
1337 Object *object = (Object *)drag_id->id;
1338
1339 if (from) {
1340 BKE_collection_object_move(bmain, scene, data.to, from, object);
1341 }
1342 else {
1343 BKE_collection_object_add(bmain, data.to, object);
1344 }
1345 }
1346 else if (GS(drag_id->id->name) == ID_GR) {
1347 /* Move/link collection into collection. */
1348 Collection *collection = (Collection *)drag_id->id;
1349
1350 if (collection != from) {
1351 BKE_collection_move(bmain, data.to, from, relative, relative_after, collection);
1352 }
1353 }
1354
1355 if (from) {
1356 DEG_id_tag_update(&from->id,
1358 }
1359 }
1360
1361 /* Update dependency graph. */
1365
1366 return OPERATOR_FINISHED;
1367}
1368
1370{
1371 /* identifiers */
1372 ot->name = "Move to Collection";
1373 ot->description = "Drag to move to collection in Outliner";
1374 ot->idname = "OUTLINER_OT_collection_drop";
1375
1376 /* API callbacks. */
1377 ot->invoke = collection_drop_invoke;
1379
1380 /* flags */
1382}
1383
1385
1386/* -------------------------------------------------------------------- */
1389
1390#define OUTLINER_DRAG_SCOLL_OUTSIDE_PAD 7 /* In UI units */
1391
1393 ARegion *region,
1394 const wmEvent *event)
1395{
1396 /* NOTE: using click-drag events to trigger dragging is fine,
1397 * it sends coordinates from where dragging was started */
1398 int mval[2];
1399 WM_event_drag_start_mval(event, region, mval);
1400
1401 const float my = UI_view2d_region_to_view_y(&region->v2d, mval[1]);
1402 return outliner_find_item_at_y(space_outliner, &space_outliner->tree, my);
1403}
1404
1406 wmOperator * /*op*/,
1407 const wmEvent *event)
1408{
1409 ARegion *region = CTX_wm_region(C);
1410 SpaceOutliner *space_outliner = CTX_wm_space_outliner(C);
1411 TreeElement *te = outliner_item_drag_element_find(space_outliner, region, event);
1412
1413 int mval[2];
1414 WM_event_drag_start_mval(event, region, mval);
1415
1416 if (!te) {
1418 }
1419
1420 TreeStoreElem *tselem = TREESTORE(te);
1422 if (!data.drag_id) {
1424 }
1425
1426 float view_mval[2];
1427 UI_view2d_region_to_view(&region->v2d, mval[0], mval[1], &view_mval[0], &view_mval[1]);
1428 if (outliner_item_is_co_within_close_toggle(te, view_mval[0])) {
1430 }
1431 if (outliner_is_co_within_mode_column(space_outliner, view_mval)) {
1433 }
1434
1435 /* Scroll the view when dragging near edges, but not
1436 * when the drag goes too far outside the region. */
1437 {
1438 wmOperatorType *ot = WM_operatortype_find("VIEW2D_OT_edge_pan", true);
1439 PointerRNA op_ptr;
1441 RNA_float_set(&op_ptr, "outside_padding", OUTLINER_DRAG_SCOLL_OUTSIDE_PAD);
1444 }
1445
1446 const bool use_datastack_drag = ELEM(tselem->type,
1453
1454 const eWM_DragDataType wm_drag_type = use_datastack_drag ? WM_DRAG_DATASTACK : WM_DRAG_ID;
1455 wmDrag *drag = WM_drag_data_create(C, data.icon, wm_drag_type, nullptr, WM_DRAG_NOP);
1456
1457 if (use_datastack_drag) {
1458 TreeElement *te_bone = nullptr;
1459 bPoseChannel *pchan = outliner_find_parent_bone(te, &te_bone);
1460 datastack_drop_data_init(drag, (Object *)tselem->id, pchan, te, tselem, te->directdata);
1461 }
1462 else if (ELEM(GS(data.drag_id->name), ID_OB, ID_GR)) {
1463 /* For collections and objects we cheat and drag all selected. */
1464
1465 /* Only drag element under mouse if it was not selected before. */
1466 if ((tselem->flag & TSE_SELECTED) == 0) {
1467 outliner_flag_set(*space_outliner, TSE_SELECTED, 0);
1468 tselem->flag |= TSE_SELECTED;
1469 }
1470
1471 /* Gather all selected elements. */
1472 IDsSelectedData selected{};
1473
1474 if (GS(data.drag_id->name) == ID_OB) {
1475 outliner_tree_traverse(space_outliner,
1476 &space_outliner->tree,
1477 0,
1480 &selected);
1481 }
1482 else {
1483 outliner_tree_traverse(space_outliner,
1484 &space_outliner->tree,
1485 0,
1488 &selected);
1489 }
1490
1491 LISTBASE_FOREACH (LinkData *, link, &selected.selected_array) {
1492 TreeElement *te_selected = (TreeElement *)link->data;
1493 ID *id;
1494
1495 if (GS(data.drag_id->name) == ID_OB) {
1496 id = TREESTORE(te_selected)->id;
1497 }
1498 else {
1499 /* Keep collection hierarchies intact when dragging. */
1500 bool parent_selected = false;
1501 for (TreeElement *te_parent = te_selected->parent; te_parent;
1502 te_parent = te_parent->parent)
1503 {
1504 if (outliner_is_collection_tree_element(te_parent)) {
1505 if (TREESTORE(te_parent)->flag & TSE_SELECTED) {
1506 parent_selected = true;
1507 break;
1508 }
1509 }
1510 }
1511
1512 if (parent_selected) {
1513 continue;
1514 }
1515
1516 id = &outliner_collection_from_tree_element(te_selected)->id;
1517 }
1518
1519 /* Find parent collection. */
1520 Collection *parent = nullptr;
1521
1522 if (te_selected->parent) {
1523 for (TreeElement *te_parent = te_selected->parent; te_parent;
1524 te_parent = te_parent->parent)
1525 {
1526 if (outliner_is_collection_tree_element(te_parent)) {
1527 parent = outliner_collection_from_tree_element(te_parent);
1528 break;
1529 }
1530 }
1531 }
1532 else {
1533 Scene *scene = CTX_data_scene(C);
1534 parent = scene->master_collection;
1535 }
1536
1537 WM_drag_add_local_ID(drag, id, &parent->id);
1538 }
1539
1540 BLI_freelistN(&selected.selected_array);
1541 }
1542 else {
1543 /* Add single ID. */
1544 WM_drag_add_local_ID(drag, data.drag_id, data.drag_parent);
1545 }
1546
1548
1550
1552}
1553
1554/* Outliner drag and drop. This operator mostly exists to support dragging
1555 * from outliner text instead of only from the icon, and also to show a
1556 * hint in the status-bar key-map. */
1557
1559{
1560 ot->name = "Drag and Drop";
1561 ot->idname = "OUTLINER_OT_item_drag_drop";
1562 ot->description = "Drag and drop element to another place";
1563
1566}
1567
1568#undef OUTLINER_DRAG_SCOLL_OUTSIDE_PAD
1569
1571
1572/* -------------------------------------------------------------------- */
1575
1577{
1579
1580 WM_dropbox_add(lb, "OUTLINER_OT_parent_drop", parent_drop_poll, nullptr, nullptr, nullptr);
1581 WM_dropbox_add(lb, "OUTLINER_OT_parent_clear", parent_clear_poll, nullptr, nullptr, nullptr);
1582 WM_dropbox_add(lb, "OUTLINER_OT_scene_drop", scene_drop_poll, nullptr, nullptr, nullptr);
1583 WM_dropbox_add(lb, "OUTLINER_OT_material_drop", material_drop_poll, nullptr, nullptr, nullptr);
1584 WM_dropbox_add(lb,
1585 "OUTLINER_OT_datastack_drop",
1587 nullptr,
1588 nullptr,
1590 WM_dropbox_add(lb,
1591 "OUTLINER_OT_collection_drop",
1593 nullptr,
1594 nullptr,
1596}
1597
1599
1600} // namespace blender::ed::outliner
bool BKE_collection_is_empty(const Collection *collection)
bool BKE_collection_move(Main *bmain, Collection *to_parent, Collection *from_parent, Collection *relative, bool relative_after, Collection *collection)
void BKE_collection_object_move(Main *bmain, Scene *scene, Collection *collection_dst, Collection *collection_src, Object *ob)
bool BKE_collection_object_add(Main *bmain, Collection *collection, Object *ob)
ReportList * CTX_wm_reports(const bContext *C)
SpaceOutliner * CTX_wm_space_outliner(const bContext *C)
wmWindow * CTX_wm_window(const bContext *C)
Scene * CTX_data_scene(const bContext *C)
Main * CTX_data_main(const bContext *C)
ARegion * CTX_wm_region(const bContext *C)
Collection * CTX_data_collection(const bContext *C)
void BKE_view_layer_synced_ensure(const Scene *scene, ViewLayer *view_layer)
bool BKE_scene_has_object(Scene *scene, Object *ob)
Base * BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
bool BKE_id_is_editable(const Main *bmain, const ID *id)
Definition lib_id.cc:2523
General operations, lookup, etc. for materials.
@ BKE_MAT_ASSIGN_USERPREF
void BKE_object_material_assign(Main *bmain, Object *ob, Material *ma, short act, int assign_type)
General operations, lookup, etc. for blender objects.
bool BKE_object_is_child_recursive(const Object *ob_parent, const Object *ob_child)
@ RPT_INFO
Definition BKE_report.hh:35
@ RPT_WARNING
Definition BKE_report.hh:38
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:153
#define BLI_assert_unreachable()
Definition BLI_assert.h:93
int BLI_findindex(const ListBase *listbase, const void *vlink) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:586
#define LISTBASE_FOREACH(type, var, list)
BLI_INLINE bool BLI_listbase_is_empty(const ListBase *lb)
void void BLI_freelistN(ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:497
#define ELEM(...)
#define TIP_(msgid)
void DEG_id_tag_update(ID *id, unsigned int flags)
void DEG_relations_tag_update(Main *bmain)
@ ID_RECALC_SELECT
Definition DNA_ID.h:1101
@ ID_RECALC_HIERARCHY
Definition DNA_ID.h:1158
@ ID_RECALC_SYNC_TO_EVAL
Definition DNA_ID.h:1118
@ ID_RECALC_GEOMETRY
Definition DNA_ID.h:1074
struct ID ID
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:705
#define ID_IS_OVERRIDE_LIBRARY(_id)
Definition DNA_ID.h:730
@ ID_SCE
@ ID_MA
@ ID_GR
@ ID_OB
Object groups, one object can be in many groups at once.
struct Collection Collection
@ COLLECTION_IS_MASTER
Object is a sort of wrapper for general info.
@ OB_GREASE_PENCIL
@ TSE_POSE_CHANNEL
@ TSE_CONSTRAINT_BASE
@ TSE_MODIFIER_BASE
@ TSE_GPENCIL_EFFECT
@ TSE_LIBRARY_OVERRIDE_BASE
@ TSE_CONSTRAINT
@ TSE_GPENCIL_EFFECT_BASE
@ TSE_SOME_ID
@ TSE_MODIFIER
@ TSE_DRAG_AFTER
@ TSE_HIGHLIGHTED_ANY
@ TSE_SELECTED
@ TSE_DRAG_INTO
@ TSE_CLOSED
@ TSE_DRAG_BEFORE
@ TSE_DRAG_ANY
@ RGN_TYPE_WINDOW
@ SPACE_OUTLINER
@ SO_FILTER_NO_COLLECTION
@ SO_VIEW_LAYER
@ SO_SCENES
@ OPERATOR_CANCELLED
@ OPERATOR_FINISHED
@ OPERATOR_PASS_THROUGH
void ED_outliner_select_sync_from_outliner(bContext *C, SpaceOutliner *space_outliner)
bool ED_operator_region_outliner_active(bContext *C)
void ED_region_tag_redraw_no_rebuild(ARegion *region)
Definition area.cc:638
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:618
bool ED_operator_outliner_active(bContext *C)
Read Guarded memory(de)allocation.
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_UNIT_X
float UI_view2d_region_to_view_y(const View2D *v2d, float y)
Definition view2d.cc:1662
void UI_view2d_region_to_view(const View2D *v2d, float x, float y, float *r_view_x, float *r_view_y) ATTR_NONNULL()
Definition view2d.cc:1668
@ KM_CTRL
Definition WM_types.hh:279
@ KM_ALT
Definition WM_types.hh:280
@ KM_SHIFT
Definition WM_types.hh:278
@ WM_DRAG_NOP
Definition WM_types.hh:1229
@ WM_DRAG_FREE_DATA
Definition WM_types.hh:1230
eWM_DragDataType
Definition WM_types.hh:1200
@ WM_DRAG_DATASTACK
Definition WM_types.hh:1219
@ WM_DRAG_ID
Definition WM_types.hh:1201
#define ND_OB_SELECT
Definition WM_types.hh:442
#define NC_SCENE
Definition WM_types.hh:378
@ OPTYPE_INTERNAL
Definition WM_types.hh:202
@ OPTYPE_UNDO
Definition WM_types.hh:182
@ OPTYPE_REGISTER
Definition WM_types.hh:180
#define ND_PARENT
Definition WM_types.hh:467
#define NC_MATERIAL
Definition WM_types.hh:380
#define ND_TRANSFORM
Definition WM_types.hh:456
#define ND_LAYER
Definition WM_types.hh:450
#define ND_OB_SHADING
Definition WM_types.hh:457
#define ND_SPACE_VIEW3D
Definition WM_types.hh:528
#define NC_OBJECT
Definition WM_types.hh:379
#define ND_SHADING_LINKS
Definition WM_types.hh:479
#define NC_SPACE
Definition WM_types.hh:392
BMesh const char void * data
#define GS(x)
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void constraint_link(Main *bmain, Object *ob_dst, ListBase *dst, ListBase *src)
void constraint_copy_for_object(Main *bmain, Object *ob_dst, bConstraint *con)
bool modifier_copy_to_object(Main *bmain, const Scene *scene, const Object *ob_src, const ModifierData *md, Object *ob_dst, ReportList *reports)
void constraint_copy_for_pose(Main *bmain, Object *ob_dst, bPoseChannel *pchan, bConstraint *con)
void base_select(Base *base, eObjectSelect_Mode mode)
void parent_clear(Object *ob, int type)
bool parent_set(ReportList *reports, const bContext *C, Scene *scene, Object *const ob, Object *const par, int partype, bool xmirror, bool keep_transform, const int vert_par[3])
void shaderfx_copy(Object *dst, ShaderFxData *fx)
bool constraint_move_to_index(Object *ob, bConstraint *con, int index)
bool modifier_move_to_index(ReportList *reports, eReportType error_type, Object *ob, ModifierData *md, int index, bool allow_partial)
bool shaderfx_move_to_index(ReportList *reports, Object *ob, ShaderFxData *fx, int index)
void modifier_link(bContext *C, Object *ob_dst, Object *ob_src)
void shaderfx_link(Object *dst, Object *src)
static bool scene_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
bool outliner_item_is_co_within_close_toggle(const TreeElement *te, float view_co_x)
static bool collection_drop_init(bContext *C, wmDrag *drag, const int xy[2], CollectionDrop *data)
static bool is_pchan_element(TreeElement *te)
static void datastack_drop_link(bContext *C, StackDropData *drop_data)
bool(*)(TreeElement *te) CheckTypeFn
static wmOperatorStatus outliner_item_drag_drop_invoke(bContext *C, wmOperator *, const wmEvent *event)
static TreeElement * outliner_drop_find(bContext *C, const wmEvent *event)
static bool parent_drop_allowed(TreeElement *te, Object *potential_child)
static std::string datastack_drop_tooltip(bContext *, wmDrag *drag, const int[2], wmDropBox *)
bool outliner_is_collection_tree_element(const TreeElement *te)
static std::string collection_drop_tooltip(bContext *C, wmDrag *drag, const int xy[2], wmDropBox *)
static ID * outliner_ID_drop_find(bContext *C, const wmEvent *event, short idcode)
TreeElement * outliner_find_id(SpaceOutliner *space_outliner, ListBase *lb, const ID *id)
static bool collection_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
static wmOperatorStatus scene_drop_invoke(bContext *C, wmOperator *, const wmEvent *event)
static bool datastack_drop_are_types_valid(StackDropData *drop_data)
static void datastack_drop_reorder(bContext *C, ReportList *reports, StackDropData *drop_data)
static wmOperatorStatus datastack_drop_invoke(bContext *C, wmOperator *op, const wmEvent *event)
bool outliner_flag_set(const SpaceOutliner &space_outliner, const short flag, const short set)
static bool datastack_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
void OUTLINER_OT_collection_drop(wmOperatorType *ot)
TreeElementIcon tree_element_get_icon(TreeStoreElem *tselem, TreeElement *te)
TreeElement * outliner_find_item_at_y(const SpaceOutliner *space_outliner, const ListBase *tree, float view_co_y)
static TreeElement * outliner_drop_insert_collection_find(bContext *C, const int xy[2], TreeElementInsertType *r_insert_type)
bPoseChannel * outliner_find_parent_bone(TreeElement *te, TreeElement **r_bone_te)
void OUTLINER_OT_datastack_drop(wmOperatorType *ot)
static TreeElement * outliner_drop_insert_find(bContext *C, const int xy[2], TreeElementInsertType *r_insert_type)
static void datastack_drop_data_init(wmDrag *drag, Object *ob, bPoseChannel *pchan, TreeElement *te, TreeStoreElem *tselem, void *directdata)
static int outliner_get_insert_index(TreeElement *drag_te, TreeElement *drop_te, TreeElementInsertType insert_type, ListBase *listbase)
TreeTraversalAction outliner_collect_selected_objects(TreeElement *te, void *customdata)
Collection * outliner_collection_from_tree_element(const TreeElement *te)
static bool parent_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
bool outliner_is_co_within_mode_column(SpaceOutliner *space_outliner, const float view_mval[2])
void OUTLINER_OT_material_drop(wmOperatorType *ot)
void OUTLINER_OT_scene_drop(wmOperatorType *ot)
static TreeElement * outliner_dropzone_find(const SpaceOutliner *space_outliner, const float fmval[2], const bool children)
static wmOperatorStatus material_drop_invoke(bContext *C, wmOperator *, const wmEvent *event)
static TreeElement * outliner_item_drag_element_find(SpaceOutliner *space_outliner, ARegion *region, const wmEvent *event)
void OUTLINER_OT_parent_drop(wmOperatorType *ot)
bool outliner_tree_traverse(const SpaceOutliner *space_outliner, ListBase *tree, int filter_te_flag, int filter_tselem_flag, TreeTraversalFunc func, void *customdata)
ID * outliner_search_back(TreeElement *te, short idcode)
static bool datastack_drop_init(bContext *C, const wmEvent *event, StackDropData *drop_data)
static bool allow_parenting_without_modifier_key(SpaceOutliner *space_outliner)
static void parent_drop_set_parents(bContext *C, ReportList *reports, wmDragID *drag, Object *parent, short parent_type, const bool keep_transform)
TreeElement * outliner_find_tree_element(ListBase *lb, const TreeStoreElem *store_elem)
TreeElement * outliner_find_parent_element(ListBase *lb, TreeElement *parent_te, const TreeElement *child_te)
static wmOperatorStatus parent_drop_invoke(bContext *C, wmOperator *op, const wmEvent *event)
static bool is_object_element(TreeElement *te)
static void datastack_drop_copy(bContext *C, StackDropData *drop_data)
static wmOperatorStatus collection_drop_invoke(bContext *C, wmOperator *, const wmEvent *event)
static bool is_collection_element(TreeElement *te)
static TreeElement * outliner_data_from_tree_element_and_parents(CheckTypeFn check_type, TreeElement *te)
static Collection * collection_parent_from_ID(ID *id)
void OUTLINER_OT_parent_clear(wmOperatorType *ot)
static TreeElement * outliner_dropzone_element(TreeElement *te, const float fmval[2], const bool children)
static wmOperatorStatus parent_clear_invoke(bContext *C, wmOperator *, const wmEvent *event)
TreeTraversalAction outliner_collect_selected_collections(TreeElement *te, void *customdata)
static bool material_drop_poll(bContext *C, wmDrag *drag, const wmEvent *event)
void OUTLINER_OT_item_drag_drop(wmOperatorType *ot)
static bool parent_clear_poll(bContext *C, wmDrag *drag, const wmEvent *event)
#define OUTLINER_DRAG_SCOLL_OUTSIDE_PAD
#define TREESTORE(a)
#define TSELEM_OPEN(telm, sv)
void RNA_float_set(PointerRNA *ptr, const char *name, float value)
Definition DNA_ID.h:414
char name[258]
Definition DNA_ID.h:432
void * last
void * first
struct MaterialGPencilStyle * gp_style
ListBase constraints
ListBase modifiers
ListBase shader_fx
struct Object * parent
struct Collection * master_collection
ListBase view_layers
int ymin
int xmin
wmDragID * next
Definition WM_types.hh:1237
ID * from_parent
Definition WM_types.hh:1239
eWM_DragDataType type
Definition WM_types.hh:1331
void * poin
Definition WM_types.hh:1332
ListBase ids
Definition WM_types.hh:1345
eWM_DragFlags flags
Definition WM_types.hh:1342
wmEventModifierFlag modifier
Definition WM_types.hh:774
short custom
Definition WM_types.hh:793
int xy[2]
Definition WM_types.hh:761
int mval[2]
Definition WM_types.hh:763
struct ReportList * reports
struct wmEvent * eventstate
wmDropBox * WM_dropbox_add(ListBase *lb, const char *idname, bool(*poll)(bContext *C, wmDrag *drag, const wmEvent *event), void(*copy)(bContext *C, wmDrag *drag, wmDropBox *drop), void(*cancel)(Main *bmain, wmDrag *drag, wmDropBox *drop), WMDropboxTooltipFunc tooltip)
void WM_event_start_prepared_drag(bContext *C, wmDrag *drag)
wmDrag * WM_drag_data_create(bContext *C, int icon, eWM_DragDataType type, void *poin, uint flags)
ID * WM_drag_get_local_ID_from_event(const wmEvent *event, short idcode)
ListBase * WM_dropboxmap_find(const char *idname, int spaceid, int regionid)
void WM_drag_add_local_ID(wmDrag *drag, ID *id, ID *from_parent)
ID * WM_drag_get_local_ID(const wmDrag *drag, short idcode)
int xy[2]
Definition wm_draw.cc:178
void WM_event_drag_start_mval(const wmEvent *event, const ARegion *region, int r_mval[2])
wmOperatorStatus WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, blender::wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
void WM_main_add_notifier(uint type, void *reference)
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
@ EVT_DATA_DRAGDROP
wmOperatorType * ot
Definition wm_files.cc:4237
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
void WM_operator_properties_create_ptr(PointerRNA *ptr, wmOperatorType *ot)
void WM_operator_properties_free(PointerRNA *ptr)
uint8_t flag
Definition wm_window.cc:145