cui/source/customize/cfg.cxx | 31 ++++--------------------------- cui/source/inc/cfg.hxx | 6 ++---- include/vcl/weldutils.hxx | 21 +++++++++++++++++++++ sd/source/ui/dlg/custsdlg.cxx | 35 +---------------------------------- sd/source/ui/inc/custsdlg.hxx | 16 ++-------------- vcl/source/app/weldutils.cxx | 33 +++++++++++++++++++++++++++++++++ 6 files changed, 63 insertions(+), 79 deletions(-)
New commits: commit 0f684565d9246ccc39766289e9a5c383e8f9d838 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Tue Nov 2 11:44:47 2021 +0000 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Tue Nov 2 17:13:35 2021 +0100 extract a ReorderingDropTarget for reuse Change-Id: I0ae69bbf644e220e1bf3352d98eb4fd735167416 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124596 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/cui/source/customize/cfg.cxx b/cui/source/customize/cfg.cxx index 943dc83247d4..79961fe690c2 100644 --- a/cui/source/customize/cfg.cxx +++ b/cui/source/customize/cfg.cxx @@ -3201,39 +3201,16 @@ SvxIconChangeDialog::SvxIconChangeDialog(weld::Window *pWindow, const OUString& } SvxConfigPageFunctionDropTarget::SvxConfigPageFunctionDropTarget(SvxConfigPage&rPage, weld::TreeView& rTreeView) - : DropTargetHelper(rTreeView.get_drop_target()) + : weld::ReorderingDropTarget(rTreeView) , m_rPage(rPage) - , m_rTreeView(rTreeView) { } -sal_Int8 SvxConfigPageFunctionDropTarget::AcceptDrop(const AcceptDropEvent& rEvt) +sal_Int8 SvxConfigPageFunctionDropTarget::ExecuteDrop(const ExecuteDropEvent& 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 SvxConfigPageFunctionDropTarget::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); - + sal_Int8 nRet = weld::ReorderingDropTarget::ExecuteDrop(rEvt); m_rPage.ListModified(); - - return DND_ACTION_NONE; + return nRet;; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/cui/source/inc/cfg.hxx b/cui/source/inc/cfg.hxx index c1b492cb4b90..b143367a547f 100644 --- a/cui/source/inc/cfg.hxx +++ b/cui/source/inc/cfg.hxx @@ -19,9 +19,9 @@ #pragma once -#include <vcl/transfer.hxx> #include <vcl/timer.hxx> #include <vcl/weld.hxx> +#include <vcl/weldutils.hxx> #include <svtools/valueset.hxx> #include <com/sun/star/container/XIndexContainer.hpp> @@ -352,13 +352,11 @@ public: void CreateDropDown(); }; -class SvxConfigPageFunctionDropTarget : public DropTargetHelper +class SvxConfigPageFunctionDropTarget : public weld::ReorderingDropTarget { private: SvxConfigPage& m_rPage; - weld::TreeView& m_rTreeView; - virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt ) override; virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt ) override; public: diff --git a/include/vcl/weldutils.hxx b/include/vcl/weldutils.hxx index 8cb591ce8140..cadbd5585ef7 100644 --- a/include/vcl/weldutils.hxx +++ b/include/vcl/weldutils.hxx @@ -21,6 +21,7 @@ #include <vcl/dllapi.h> #include <vcl/formatter.hxx> #include <vcl/timer.hxx> +#include <vcl/transfer.hxx> #include <vcl/weld.hxx> class CalendarWrapper; @@ -418,6 +419,26 @@ public: bool IsModKeyPressed() const { return m_bModKey; } }; +/* + If a TreeView is used as a list, rather than a tree, and DnD should just + reorder rows, then this can be used to implement that. + + Because the TreeView doesn't want or need subnodes, the drop target can be + simply visually indicated as being between rows (the issue of a final drop + location of a child of the drop target doesn't arise), and the meaning of + what a drop before or after the last row should do is unambigious. +*/ +class VCL_DLLPUBLIC ReorderingDropTarget : public DropTargetHelper +{ +protected: + weld::TreeView& m_rTreeView; + virtual sal_Int8 AcceptDrop(const AcceptDropEvent& rEvt) override; + virtual sal_Int8 ExecuteDrop(const ExecuteDropEvent& rEvt) override; + +public: + ReorderingDropTarget(weld::TreeView& rTreeView); +}; + // get the row the iterator is on VCL_DLLPUBLIC size_t GetAbsPos(const weld::TreeView& rTreeView, const weld::TreeIter& rIter); diff --git a/sd/source/ui/dlg/custsdlg.cxx b/sd/source/ui/dlg/custsdlg.cxx index bd629f87bfaa..fc8e774d82e9 100644 --- a/sd/source/ui/dlg/custsdlg.cxx +++ b/sd/source/ui/dlg/custsdlg.cxx @@ -250,7 +250,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_xDropTargetHelper(new weld::ReorderingDropTarget(*m_xLbCustomPages)) , m_xBtnOK(m_xBuilder->weld_button("ok")) , m_xBtnCancel(m_xBuilder->weld_button("cancel")) , m_xBtnHelp(m_xBuilder->weld_button("help")) @@ -475,37 +475,4 @@ 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 70df26a065fc..52ae878529a9 100644 --- a/sd/source/ui/inc/custsdlg.hxx +++ b/sd/source/ui/inc/custsdlg.hxx @@ -19,8 +19,8 @@ #pragma once -#include <vcl/transfer.hxx> #include <vcl/weld.hxx> +#include <vcl/weldutils.hxx> class SdDrawDocument; class SdCustomShow; @@ -54,18 +54,6 @@ 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: @@ -79,7 +67,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::ReorderingDropTarget> m_xDropTargetHelper; std::unique_ptr<weld::Button> m_xBtnOK; std::unique_ptr<weld::Button> m_xBtnCancel; std::unique_ptr<weld::Button> m_xBtnHelp; diff --git a/vcl/source/app/weldutils.cxx b/vcl/source/app/weldutils.cxx index 4c160cfd6930..32d457293829 100644 --- a/vcl/source/app/weldutils.cxx +++ b/vcl/source/app/weldutils.cxx @@ -622,6 +622,39 @@ void SetPointFont(OutputDevice& rDevice, const vcl::Font& rFont) if (vcl::Window* pDefaultWindow = pDefaultDevice->GetOwnerWindow()) pDefaultWindow->SetPointFont(rDevice, rFont); } + +ReorderingDropTarget::ReorderingDropTarget(weld::TreeView& rTreeView) + : DropTargetHelper(rTreeView.get_drop_target()) + , m_rTreeView(rTreeView) +{ +} + +sal_Int8 ReorderingDropTarget::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 ReorderingDropTarget::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: */