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 <model/SlsPageEnumerationProvider.hxx>
25 #include <view/SlideSorterView.hxx>
26 #include <controller/SlideSorterController.hxx>
27 #include <controller/SlsInsertionIndicatorHandler.hxx>
28 #include <controller/SlsScrollBarManager.hxx>
29 #include <controller/SlsProperties.hxx>
30 #include <controller/SlsSelectionFunction.hxx>
31 #include <controller/SlsSelectionManager.hxx>
32 #include <controller/SlsClipboard.hxx>
33 #include <controller/SlsTransferableData.hxx>
34 #include <DrawDocShell.hxx>
35 #include <drawdoc.hxx>
38 #include <sdtreelb.hxx>
40 #include <sfx2/bindings.hxx>
42 namespace sd
{ namespace slidesorter
{ namespace controller
{
44 DragAndDropContext::DragAndDropContext (SlideSorter
& rSlideSorter
)
45 : mpTargetSlideSorter(&rSlideSorter
),
48 // No Drag-and-Drop for master pages.
49 if (rSlideSorter
.GetModel().GetEditMode() != EditMode::Page
)
52 // For properly handling transferables created by the navigator we
53 // need additional information. For this a user data object is
54 // created that contains the necessary information.
55 SdTransferable
* pTransferable
= SD_MOD()->pTransferDrag
;
56 SdPageObjsTLB::SdPageObjsTransferable
* pTreeListBoxTransferable
57 = dynamic_cast<SdPageObjsTLB::SdPageObjsTransferable
*>(pTransferable
);
58 if (pTreeListBoxTransferable
!=nullptr && !TransferableData::GetFromTransferable(pTransferable
))
60 pTransferable
->AddUserData(
61 sd::slidesorter::controller::Clipboard::CreateTransferableUserData(pTransferable
));
64 rSlideSorter
.GetController().GetInsertionIndicatorHandler()->UpdateIndicatorIcon(pTransferable
);
67 DragAndDropContext::~DragAndDropContext() COVERITY_NOEXCEPT_FALSE
69 SetTargetSlideSorter();
72 void DragAndDropContext::Dispose()
74 mnInsertionIndex
= -1;
77 void DragAndDropContext::UpdatePosition (
78 const Point
& rMousePosition
,
79 const InsertionIndicatorHandler::Mode eMode
,
80 const bool bAllowAutoScroll
)
82 if (mpTargetSlideSorter
== nullptr)
85 if (mpTargetSlideSorter
->GetProperties()->IsUIReadOnly())
88 // Convert window coordinates into model coordinates (we need the
89 // window coordinates for auto-scrolling because that remains
90 // constant while scrolling.)
91 sd::Window
*pWindow
= mpTargetSlideSorter
->GetContentWindow().get();
92 const Point
aMouseModelPosition (pWindow
->PixelToLogic(rMousePosition
));
93 std::shared_ptr
<InsertionIndicatorHandler
> pInsertionIndicatorHandler (
94 mpTargetSlideSorter
->GetController().GetInsertionIndicatorHandler());
96 bool bDoAutoScroll
= bAllowAutoScroll
97 && mpTargetSlideSorter
->GetController().GetScrollBarManager().AutoScroll(
99 [this, eMode
, &rMousePosition
] () {
100 return this->UpdatePosition(rMousePosition
, eMode
, false);
105 pInsertionIndicatorHandler
->UpdatePosition(aMouseModelPosition
, eMode
);
107 // Remember the new insertion index.
108 mnInsertionIndex
= pInsertionIndicatorHandler
->GetInsertionPageIndex();
109 if (pInsertionIndicatorHandler
->IsInsertionTrivial(mnInsertionIndex
, eMode
))
110 mnInsertionIndex
= -1;
114 void DragAndDropContext::SetTargetSlideSorter()
116 if (mpTargetSlideSorter
!= nullptr)
118 mpTargetSlideSorter
->GetController().GetScrollBarManager().StopAutoScroll();
119 mpTargetSlideSorter
->GetController().GetInsertionIndicatorHandler()->End(
120 Animator::AM_Animated
);
123 mpTargetSlideSorter
= nullptr;
126 } } } // end of namespace ::sd::slidesorter::controller
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */