Blender V5.3
interface_drop.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include "BLI_listbase.hh"
10
11#include "UI_interface.hh"
12#include "UI_tree_view.hh"
13
14namespace blender::ui {
15
20
22 const ARegion & /*region*/, const wmEvent & /*event*/) const
23{
24 return DropLocation::Into;
25}
26
28 const ARegion &region,
29 const wmEvent &event,
30 const DropTargetInterface &drop_target,
31 const ListBaseT<wmDrag> &drags)
32{
33 const char *disabled_hint_dummy = nullptr;
34 for (const wmDrag &drag : drags) {
35 if (!drop_target.can_drop(drag, &disabled_hint_dummy)) {
36 return false;
37 }
38
39 std::optional<DropLocation> drop_location = drop_target.choose_drop_location(region, event);
40 if (!drop_location) {
41 return false;
42 }
43
44 AbstractView *view = region_view_find_at(&region, event.xy, 0);
45 if (AbstractTreeView *tree_view = dynamic_cast<AbstractTreeView *>(view)) {
46 TreeViewSortOrder sortorder = tree_view->invert_sort_type_get();
47 if (sortorder != TreeViewSortOrder::None) {
48 AbstractTreeViewItem *dropitem = dynamic_cast<AbstractTreeViewItem *>(
49 region_views_find_item_at(region, event.xy));
50
51 bool change_drop_order = (sortorder == TreeViewSortOrder::InvertNested);
52 if (sortorder == TreeViewSortOrder::InvertRoot) {
53 tree_view->foreach_root_item(
54 [&](AbstractTreeViewItem &item) { change_drop_order |= (dropitem == &item); });
55 }
56 if (change_drop_order) {
57 /* Switch drop location when invert sorting is enabled. */
58 if (*drop_location == DropLocation::After) {
59 *drop_location = DropLocation::Before;
60 }
61 else if (*drop_location == DropLocation::Before) {
62 *drop_location = DropLocation::After;
63 }
64 }
65 }
66 }
67
68 const DragInfo drag_info{drag, event, *drop_location};
69 return drop_target.on_drop(&C, drag_info);
70 }
71
72 return false;
73}
74
75std::string drop_target_tooltip(const ARegion &region,
76 const DropTargetInterface &drop_target,
77 const wmDrag &drag,
78 const wmEvent &event)
79{
80 const char *disabled_hint_dummy = nullptr;
81 if (!drop_target.can_drop(drag, &disabled_hint_dummy)) {
82 return {};
83 }
84
85 const std::optional<DropLocation> drop_location = drop_target.choose_drop_location(region,
86 event);
87 if (!drop_location) {
88 return {};
89 }
90
91 const DragInfo drag_info{drag, event, *drop_location};
92 return drop_target.drop_tooltip(drag_info);
93}
94
95} // namespace blender::ui
#define C
Definition RandGen.cpp:29
Abstract base class for defining a customizable tree-view item.
virtual bool on_drop(bContext *C, const DragInfo &drag) const =0
virtual bool can_drop(const wmDrag &drag, const char **r_disabled_hint) const =0
virtual std::string drop_tooltip(const DragInfo &drag) const =0
virtual std::optional< DropLocation > choose_drop_location(const ARegion &region, const wmEvent &event) const
AbstractViewItem * region_views_find_item_at(const ARegion &region, const int xy[2])
bool drop_target_apply_drop(bContext &C, const ARegion &region, const wmEvent &event, const DropTargetInterface &drop_target, const ListBaseT< wmDrag > &drags)
std::string drop_target_tooltip(const ARegion &region, const DropTargetInterface &drop_target, const wmDrag &drag, const wmEvent &event)
AbstractView * region_view_find_at(const ARegion *region, const int xy[2], int pad, Block **r_block=nullptr)
DragInfo(const wmDrag &drag, const wmEvent &event, DropLocation drop_location)
const wmDrag & drag_data
const DropLocation drop_location
const wmEvent & event