1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "SlsDragAndDropContext.hxx"
22 #include <SlideSorter.hxx>
23 #include <model/SlideSorterModel.hxx>
24 #include <controller/SlideSorterController.hxx>
25 #include <controller/SlsInsertionIndicatorHandler.hxx>
26 #include <controller/SlsScrollBarManager.hxx>
27 #include <controller/SlsProperties.hxx>
28 #include <controller/SlsClipboard.hxx>
29 #include <controller/SlsTransferableData.hxx>
31 #include <sdtreelb.hxx>
34 namespace sd::slidesorter::controller
{
36 DragAndDropContext::DragAndDropContext (SlideSorter
& rSlideSorter
)
37 : mpTargetSlideSorter(&rSlideSorter
),
40 // No Drag-and-Drop for master pages.
41 if (rSlideSorter
.GetModel().GetEditMode() != EditMode::Page
)
44 // For properly handling transferables created by the navigator we
45 // need additional information. For this a user data object is
46 // created that contains the necessary information.
47 SdTransferable
* pTransferable
= SdModule::get()->pTransferDrag
;
48 SdPageObjsTLV::SdPageObjsTransferable
* pTreeListBoxTransferable
49 = dynamic_cast<SdPageObjsTLV::SdPageObjsTransferable
*>(pTransferable
);
50 if (pTreeListBoxTransferable
!=nullptr && !TransferableData::GetFromTransferable(pTransferable
))
52 pTransferable
->AddUserData(
53 sd::slidesorter::controller::Clipboard::CreateTransferableUserData(pTransferable
));
56 rSlideSorter
.GetController().GetInsertionIndicatorHandler()->UpdateIndicatorIcon(pTransferable
);
59 DragAndDropContext::~DragAndDropContext() COVERITY_NOEXCEPT_FALSE
61 SetTargetSlideSorter();
64 void DragAndDropContext::Dispose()
66 mnInsertionIndex
= -1;
69 void DragAndDropContext::UpdatePosition (
70 const Point
& rMousePosition
,
71 const InsertionIndicatorHandler::Mode eMode
,
72 const bool bAllowAutoScroll
)
74 if (mpTargetSlideSorter
== nullptr)
77 // Convert window coordinates into model coordinates (we need the
78 // window coordinates for auto-scrolling because that remains
79 // constant while scrolling.)
80 sd::Window
*pWindow
= mpTargetSlideSorter
->GetContentWindow().get();
81 const Point
aMouseModelPosition (pWindow
->PixelToLogic(rMousePosition
));
82 std::shared_ptr
<InsertionIndicatorHandler
> pInsertionIndicatorHandler (
83 mpTargetSlideSorter
->GetController().GetInsertionIndicatorHandler());
85 bool bDoAutoScroll
= bAllowAutoScroll
86 && mpTargetSlideSorter
->GetController().GetScrollBarManager().AutoScroll(
88 [this, eMode
, rMousePosition
] () {
89 return this->UpdatePosition(rMousePosition
, eMode
, false);
94 pInsertionIndicatorHandler
->UpdatePosition(aMouseModelPosition
, eMode
);
96 // Remember the new insertion index.
97 mnInsertionIndex
= pInsertionIndicatorHandler
->GetInsertionPageIndex();
98 if (pInsertionIndicatorHandler
->IsInsertionTrivial(mnInsertionIndex
, eMode
))
99 mnInsertionIndex
= -1;
103 void DragAndDropContext::SetTargetSlideSorter()
105 if (mpTargetSlideSorter
!= nullptr)
107 mpTargetSlideSorter
->GetController().GetScrollBarManager().StopAutoScroll();
108 mpTargetSlideSorter
->GetController().GetInsertionIndicatorHandler()->End(
109 Animator::AM_Animated
);
112 mpTargetSlideSorter
= nullptr;
115 } // end of namespace ::sd::slidesorter::controller
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */