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"
37 #include "sdtreelb.hxx"
38 #include <sfx2/bindings.hxx>
39 #include <boost/bind.hpp>
41 namespace sd
{ namespace slidesorter
{ namespace controller
{
43 DragAndDropContext::DragAndDropContext (SlideSorter
& rSlideSorter
)
44 : mpTargetSlideSorter(&rSlideSorter
),
47 // No Drag-and-Drop for master pages.
48 if (rSlideSorter
.GetModel().GetEditMode() != EM_PAGE
)
51 // For poperly handling transferables created by the navigator we
52 // need additional information. For this a user data object is
53 // created that contains the necessary information.
54 SdTransferable
* pTransferable
= SD_MOD()->pTransferDrag
;
55 SdPageObjsTLB::SdPageObjsTransferable
* pTreeListBoxTransferable
56 = dynamic_cast<SdPageObjsTLB::SdPageObjsTransferable
*>(pTransferable
);
57 if (pTreeListBoxTransferable
!=NULL
&& !TransferableData::GetFromTransferable(pTransferable
))
59 pTransferable
->AddUserData(
60 sd::slidesorter::controller::Clipboard::CreateTransferableUserData(pTransferable
));
63 rSlideSorter
.GetController().GetInsertionIndicatorHandler()->UpdateIndicatorIcon(pTransferable
);
66 DragAndDropContext::~DragAndDropContext()
68 SetTargetSlideSorter (NULL
, Point(0,0), InsertionIndicatorHandler::UnknownMode
, false);
71 void DragAndDropContext::Dispose()
73 mnInsertionIndex
= -1;
76 void DragAndDropContext::UpdatePosition (
77 const Point
& rMousePosition
,
78 const InsertionIndicatorHandler::Mode eMode
,
79 const bool bAllowAutoScroll
)
81 if (mpTargetSlideSorter
== NULL
)
84 if (mpTargetSlideSorter
->GetProperties()->IsUIReadOnly())
87 // Convert window coordinates into model coordinates (we need the
88 // window coordinates for auto-scrolling because that remains
89 // constant while scrolling.)
90 sd::Window
*pWindow (mpTargetSlideSorter
->GetContentWindow());
91 const Point
aMouseModelPosition (pWindow
->PixelToLogic(rMousePosition
));
92 ::boost::shared_ptr
<InsertionIndicatorHandler
> pInsertionIndicatorHandler (
93 mpTargetSlideSorter
->GetController().GetInsertionIndicatorHandler());
95 bool bDoAutoScroll
= bAllowAutoScroll
96 && mpTargetSlideSorter
->GetController().GetScrollBarManager().AutoScroll(
99 &DragAndDropContext::UpdatePosition
, this, rMousePosition
, eMode
, false));
103 pInsertionIndicatorHandler
->UpdatePosition(aMouseModelPosition
, eMode
);
105 // Remember the new insertion index.
106 mnInsertionIndex
= pInsertionIndicatorHandler
->GetInsertionPageIndex();
107 if (pInsertionIndicatorHandler
->IsInsertionTrivial(mnInsertionIndex
, eMode
))
108 mnInsertionIndex
= -1;
112 void DragAndDropContext::SetTargetSlideSorter (
113 SlideSorter
* pSlideSorter
,
114 const Point
& rMousePosition
,
115 const InsertionIndicatorHandler::Mode eMode
,
116 const bool bIsOverSourceView
)
118 if (mpTargetSlideSorter
!= NULL
)
120 mpTargetSlideSorter
->GetController().GetScrollBarManager().StopAutoScroll();
121 mpTargetSlideSorter
->GetController().GetInsertionIndicatorHandler()->End(
122 Animator::AM_Animated
);
125 mpTargetSlideSorter
= pSlideSorter
;
127 if (mpTargetSlideSorter
!= NULL
)
129 mpTargetSlideSorter
->GetController().GetInsertionIndicatorHandler()->Start(
131 mpTargetSlideSorter
->GetController().GetInsertionIndicatorHandler()->UpdatePosition(
138 } } } // end of namespace ::sd::slidesorter::controller
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */