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 <controller/SlsTransferableData.hxx>
22 #include <SlideSorterViewShell.hxx>
24 namespace sd::slidesorter::controller
{
26 rtl::Reference
<SdTransferable
> TransferableData::CreateTransferable (
27 SdDrawDocument
* pSrcDoc
,
28 SlideSorterViewShell
* pViewShell
,
29 ::std::vector
<Representative
>&& rRepresentatives
)
31 rtl::Reference
<SdTransferable
> pTransferable
= new SdTransferable (pSrcDoc
, nullptr, false/*bInitOnGetData*/);
32 auto pData
= std::make_shared
<TransferableData
>(pViewShell
, std::move(rRepresentatives
));
33 pTransferable
->AddUserData(pData
);
37 std::shared_ptr
<TransferableData
> TransferableData::GetFromTransferable (const SdTransferable
* pTransferable
)
41 for (sal_Int32 nIndex
=0,nCount
=pTransferable
->GetUserDataCount(); nIndex
<nCount
; ++nIndex
)
43 std::shared_ptr
<TransferableData
> xData
=
44 std::dynamic_pointer_cast
<TransferableData
>(pTransferable
->GetUserData(nIndex
));
49 return std::shared_ptr
<TransferableData
>();
52 TransferableData::TransferableData (
53 SlideSorterViewShell
* pViewShell
,
54 ::std::vector
<Representative
>&& rRepresentatives
)
55 : mpViewShell(pViewShell
),
56 maRepresentatives(std::move(rRepresentatives
))
58 if (mpViewShell
!= nullptr)
59 StartListening(*mpViewShell
);
62 TransferableData::~TransferableData()
64 if (mpViewShell
!= nullptr)
65 EndListening(*mpViewShell
);
68 void TransferableData::Notify (SfxBroadcaster
&, const SfxHint
& rHint
)
72 if (rHint
.GetId() == SfxHintId::Dying
)
74 // This hint may come either from the ViewShell or from the
75 // document (registered by SdTransferable). We do not know
76 // which but both are sufficient to disconnect from the
78 EndListening(*mpViewShell
);
79 mpViewShell
= nullptr;
84 } // end of namespace ::sd::slidesorter::controller
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */