1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sd.hxx"
26
27 #include "controller/SlsTransferableData.hxx"
28
29 #include "SlideSorterViewShell.hxx"
30 #include "View.hxx"
31
32 namespace sd { namespace slidesorter { namespace controller {
33
CreateTransferable(SdDrawDocument * pSrcDoc,::sd::View * pWorkView,sal_Bool bInitOnGetData,SlideSorterViewShell * pViewShell,const::std::vector<Representative> & rRepresentatives)34 SdTransferable* TransferableData::CreateTransferable (
35 SdDrawDocument* pSrcDoc,
36 ::sd::View* pWorkView,
37 sal_Bool bInitOnGetData,
38 SlideSorterViewShell* pViewShell,
39 const ::std::vector<Representative>& rRepresentatives)
40 {
41 SdTransferable* pTransferable = new SdTransferable (pSrcDoc, pWorkView, bInitOnGetData);
42 ::boost::shared_ptr<TransferableData> pData (new TransferableData(pViewShell, rRepresentatives));
43 pTransferable->AddUserData(pData);
44 return pTransferable;
45 }
46
47
48
49
GetFromTransferable(const SdTransferable * pTransferable)50 ::boost::shared_ptr<TransferableData> TransferableData::GetFromTransferable (const SdTransferable* pTransferable)
51 {
52 ::boost::shared_ptr<TransferableData> pData;
53 for (sal_Int32 nIndex=0,nCount=pTransferable->GetUserDataCount(); nIndex<nCount; ++nIndex)
54 {
55 pData = ::boost::dynamic_pointer_cast<TransferableData>(pTransferable->GetUserData(nIndex));
56 if (pData)
57 return pData;
58 }
59 return ::boost::shared_ptr<TransferableData>();
60 }
61
62
63
64
TransferableData(SlideSorterViewShell * pViewShell,const::std::vector<Representative> & rRepresentatives)65 TransferableData::TransferableData (
66 SlideSorterViewShell* pViewShell,
67 const ::std::vector<Representative>& rRepresentatives)
68 : mpViewShell(pViewShell),
69 maRepresentatives(rRepresentatives)
70 {
71 if (mpViewShell != NULL)
72 StartListening(*mpViewShell);
73 }
74
75
76
77
~TransferableData(void)78 TransferableData::~TransferableData (void)
79 {
80 if (mpViewShell != NULL)
81 EndListening(*mpViewShell);
82 }
83
84
85
86
DragFinished(sal_Int8 nDropAction)87 void TransferableData::DragFinished (sal_Int8 nDropAction)
88 {
89 if (mpViewShell != NULL)
90 mpViewShell->DragFinished(nDropAction);
91 /*
92 for (CallbackContainer::const_iterator
93 iCallback(maDragFinishCallbacks.begin()),
94 iEnd(maDragFinishCallbacks.end());
95 iCallback!=iEnd;
96 ++iCallback)
97 {
98 if (*iCallback)
99 (*iCallback)(nDropAction);
100 }
101 maDragFinishCallbacks.clear();
102 */
103 }
104
105
106
107
Notify(SfxBroadcaster &,const SfxHint & rHint)108 void TransferableData::Notify (SfxBroadcaster&, const SfxHint& rHint)
109 {
110 if (rHint.ISA(SfxSimpleHint) && mpViewShell!=NULL)
111 {
112 SfxSimpleHint& rSimpleHint (*PTR_CAST(SfxSimpleHint, &rHint));
113 if (rSimpleHint.GetId() == SFX_HINT_DYING)
114 {
115 // This hint may come either from the ViewShell or from the
116 // document (registered by SdTransferable). We do not know
117 // which but both are sufficient to disconnect from the
118 // ViewShell.
119 EndListening(*mpViewShell);
120 mpViewShell = NULL;
121 }
122 }
123 }
124
125
126
127
GetRepresentatives(void) const128 const ::std::vector<TransferableData::Representative>& TransferableData::GetRepresentatives (void) const
129 {
130 return maRepresentatives;
131 }
132
133
134
135
GetSourceViewShell(void) const136 SlideSorterViewShell* TransferableData::GetSourceViewShell (void) const
137 {
138 return mpViewShell;
139 }
140
141 } } } // end of namespace ::sd::slidesorter::controller
142