sd/source/ui/dlg/custsdlg.cxx | 34 ++++++++++++++++++++++++++++++++++ sd/source/ui/inc/custsdlg.hxx | 14 ++++++++++++++ 2 files changed, 48 insertions(+)
New commits: commit 7d2e195ec6562ac108580117638c7bf6d10c525c Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Tue Nov 2 11:30:16 2021 +0000 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Wed Nov 3 10:24:37 2021 +0100 Resolves: tdf#136945 fix custom slide show dnd to reorder pages Change-Id: Ib28d6779e772fd8ad30899354cde2c281085b328 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124479 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/sd/source/ui/dlg/custsdlg.cxx b/sd/source/ui/dlg/custsdlg.cxx index db2414a51fa2..89e29a237aa8 100644 --- a/sd/source/ui/dlg/custsdlg.cxx +++ b/sd/source/ui/dlg/custsdlg.cxx @@ -261,6 +261,7 @@ SdDefineCustomShowDlg::SdDefineCustomShowDlg(weld::Window* pWindow, SdDrawDocume , m_xBtnAdd(m_xBuilder->weld_button("add")) , m_xBtnRemove(m_xBuilder->weld_button("remove")) , m_xLbCustomPages(m_xBuilder->weld_tree_view("custompages")) + , m_xDropTargetHelper(new CustomPagesDropTarget(*m_xLbCustomPages)) , m_xBtnOK(m_xBuilder->weld_button("ok")) , m_xBtnCancel(m_xBuilder->weld_button("cancel")) , m_xBtnHelp(m_xBuilder->weld_button("help")) @@ -485,4 +486,37 @@ IMPL_LINK_NOARG(SdDefineCustomShowDlg, OKHdl, weld::Button&, void) } } +CustomPagesDropTarget::CustomPagesDropTarget(weld::TreeView& rTreeView) + : DropTargetHelper(rTreeView.get_drop_target()) + , m_rTreeView(rTreeView) +{ +} + +sal_Int8 CustomPagesDropTarget::AcceptDrop(const AcceptDropEvent& rEvt) +{ + // to enable the autoscroll when we're close to the edges + m_rTreeView.get_dest_row_at_pos(rEvt.maPosPixel, nullptr, true); + return DND_ACTION_MOVE; +} + +sal_Int8 CustomPagesDropTarget::ExecuteDrop( const ExecuteDropEvent& rEvt ) +{ + weld::TreeView* pSource = m_rTreeView.get_drag_source(); + // only dragging within the same widget allowed + if (!pSource || pSource != &m_rTreeView) + return DND_ACTION_NONE; + + std::unique_ptr<weld::TreeIter> xSource(m_rTreeView.make_iterator()); + if (!m_rTreeView.get_selected(xSource.get())) + return DND_ACTION_NONE; + + std::unique_ptr<weld::TreeIter> xTarget(m_rTreeView.make_iterator()); + int nTargetPos = -1; + if (m_rTreeView.get_dest_row_at_pos(rEvt.maPosPixel, xTarget.get(), true)) + nTargetPos = m_rTreeView.get_iter_index_in_parent(*xTarget); + m_rTreeView.move_subtree(*xSource, nullptr, nTargetPos); + + return DND_ACTION_NONE; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sd/source/ui/inc/custsdlg.hxx b/sd/source/ui/inc/custsdlg.hxx index cd25983e9528..f8638845789a 100644 --- a/sd/source/ui/inc/custsdlg.hxx +++ b/sd/source/ui/inc/custsdlg.hxx @@ -19,6 +19,7 @@ #pragma once +#include <vcl/transfer.hxx> #include <vcl/weld.hxx> class SdDrawDocument; @@ -55,6 +56,18 @@ public: bool IsCustomShow() const; }; +class CustomPagesDropTarget : public DropTargetHelper +{ +private: + weld::TreeView& m_rTreeView; + + virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override; + virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override; + +public: + CustomPagesDropTarget(weld::TreeView& rTreeView); +}; + class SdDefineCustomShowDlg : public weld::GenericDialogController { private: @@ -68,6 +81,7 @@ private: std::unique_ptr<weld::Button> m_xBtnAdd; std::unique_ptr<weld::Button> m_xBtnRemove; std::unique_ptr<weld::TreeView> m_xLbCustomPages; + std::unique_ptr<CustomPagesDropTarget> m_xDropTargetHelper; std::unique_ptr<weld::Button> m_xBtnOK; std::unique_ptr<weld::Button> m_xBtnCancel; std::unique_ptr<weld::Button> m_xBtnHelp;