Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "ViewClipboard.hxx"
31 : :
32 : : #include "DrawDocShell.hxx"
33 : : #include "View.hxx"
34 : : #include "ViewShell.hxx"
35 : : #include "Window.hxx"
36 : :
37 : : #include "drawdoc.hxx"
38 : : #include "sdpage.hxx"
39 : : #include "sdxfer.hxx"
40 : : #include "sdresid.hxx"
41 : : #include "glob.hrc"
42 : :
43 : : #include <svx/svdpagv.hxx>
44 : : #include <osl/mutex.hxx>
45 : : #include <vcl/svapp.hxx>
46 : :
47 : : namespace sd {
48 : :
49 : 520 : ViewClipboard::ViewClipboard (::sd::View& rView)
50 : 520 : : mrView(rView)
51 : : {
52 : 520 : }
53 : :
54 : :
55 : :
56 : :
57 : 520 : ViewClipboard::~ViewClipboard (void)
58 : : {
59 [ - + ]: 910 : }
60 : :
61 : :
62 : :
63 : :
64 : 0 : void ViewClipboard::HandlePageDrop (const SdTransferable& rTransferable)
65 : : {
66 : : // Determine whether to insert the given set of slides or to assign a
67 : : // given master page.
68 : 0 : SdPage* pMasterPage = GetFirstMasterPage (rTransferable);
69 [ # # ]: 0 : if (pMasterPage != NULL)
70 : 0 : AssignMasterPage (rTransferable, pMasterPage);
71 : : else
72 : 0 : InsertSlides (rTransferable, DetermineInsertPosition (rTransferable));
73 : 0 : }
74 : :
75 : :
76 : :
77 : :
78 : 0 : SdPage* ViewClipboard::GetFirstMasterPage (const SdTransferable& rTransferable)
79 : : {
80 : 0 : SdPage* pFirstMasterPage = NULL;
81 : :
82 [ # # ]: 0 : if (rTransferable.HasPageBookmarks())
83 : : {
84 : : do
85 : : {
86 : 0 : const std::vector<rtl::OUString> &rBookmarks = rTransferable.GetPageBookmarks();
87 : :
88 [ # # ]: 0 : if (rBookmarks.empty())
89 : : break;
90 : :
91 : 0 : DrawDocShell* pDocShell = rTransferable.GetPageDocShell();
92 [ # # ]: 0 : if (pDocShell == NULL)
93 : : break;
94 : :
95 [ # # ]: 0 : SdDrawDocument* pDocument = pDocShell->GetDoc();
96 [ # # ]: 0 : if (pDocument == NULL)
97 : : break;
98 : :
99 : 0 : std::vector<rtl::OUString>::const_iterator pIter;
100 [ # # ][ # # ]: 0 : for ( pIter = rBookmarks.begin(); pIter != rBookmarks.end(); ++pIter )
101 : : {
102 [ # # ]: 0 : String sName (*pIter);
103 : : sal_Bool bIsMasterPage;
104 : :
105 : : // SdPage* GetMasterSdPage(sal_uInt16 nPgNum, PageKind ePgKind);
106 : : // sal_uInt16 GetMasterSdPageCount(PageKind ePgKind) const;
107 : :
108 : : sal_uInt16 nBMPage = pDocument->GetPageByName (
109 [ # # ]: 0 : sName, bIsMasterPage);
110 [ # # ]: 0 : if ( ! bIsMasterPage)
111 : : {
112 : : // At least one regular slide: return NULL to indicate
113 : : // that not all bookmarks point to master pages.
114 : 0 : pFirstMasterPage = NULL;
115 : : break;
116 : : }
117 [ # # ]: 0 : else if (pFirstMasterPage == NULL)
118 : : {
119 : : // Remember the first master page for later.
120 [ # # ]: 0 : if (nBMPage != SDRPAGE_NOTFOUND)
121 : : pFirstMasterPage = static_cast<SdPage*>(
122 [ # # ]: 0 : pDocument->GetMasterPage(nBMPage));
123 : : }
124 [ # # ][ # # ]: 0 : }
125 : : }
126 : : while (false);
127 : : }
128 : :
129 : 0 : return pFirstMasterPage;
130 : : }
131 : :
132 : :
133 : :
134 : :
135 : 0 : void ViewClipboard::AssignMasterPage (
136 : : const SdTransferable& rTransferable,
137 : : SdPage* pMasterPage)
138 : : {
139 [ # # ]: 0 : if (pMasterPage == NULL)
140 : : return;
141 : :
142 : : // Get the target page to which the master page is assigned.
143 : 0 : SdrPageView* pPageView = mrView.GetSdrPageView();
144 [ # # ]: 0 : if (pPageView == NULL)
145 : : return;
146 : :
147 : 0 : SdPage* pPage = static_cast<SdPage*>(pPageView->GetPage());
148 [ # # ]: 0 : if (pPage == NULL)
149 : : return;
150 : :
151 : 0 : SdDrawDocument& rDocument = mrView.GetDoc();
152 : :
153 [ # # ]: 0 : if ( ! rTransferable.HasPageBookmarks())
154 : : return;
155 : :
156 : 0 : DrawDocShell* pDataDocShell = rTransferable.GetPageDocShell();
157 [ # # ]: 0 : if (pDataDocShell == NULL)
158 : : return;
159 : :
160 [ # # ]: 0 : SdDrawDocument* pSourceDocument = pDataDocShell->GetDoc();
161 [ # # ]: 0 : if (pSourceDocument == NULL)
162 : : return;
163 : :
164 : : // We have to remove the layout suffix from the layout name which is
165 : : // appended again by SetMasterPage() to the given name. Don't ask.
166 [ # # ]: 0 : String sLayoutSuffix (RTL_CONSTASCII_USTRINGPARAM(SD_LT_SEPARATOR));
167 [ # # ][ # # ]: 0 : sLayoutSuffix.Append (SdResId(STR_LAYOUT_OUTLINE));
[ # # ][ # # ]
168 : 0 : sal_uInt16 nLength = sLayoutSuffix.Len();
169 [ # # ]: 0 : String sLayoutName (pMasterPage->GetLayoutName());
170 [ # # ]: 0 : if (String(sLayoutName, sLayoutName.Len()-nLength, nLength).Equals (
171 [ # # ][ # # ]: 0 : sLayoutSuffix))
[ # # ]
172 [ # # ][ # # ]: 0 : sLayoutName = String(sLayoutName, 0, sLayoutName.Len()-nLength);
[ # # ]
173 : :
174 : : rDocument.SetMasterPage (
175 [ # # ]: 0 : pPage->GetPageNum() / 2,
176 : : sLayoutName,
177 : : pSourceDocument,
178 : : sal_False, // Exchange the master page of only the target page.
179 : : sal_False // Keep unused master pages.
180 [ # # ][ # # ]: 0 : );
[ # # ]
181 : : }
182 : :
183 : :
184 : :
185 : :
186 : 0 : sal_uInt16 ViewClipboard::DetermineInsertPosition (
187 : : const SdTransferable& )
188 : : {
189 : 0 : SdDrawDocument& rDoc = mrView.GetDoc();
190 : 0 : sal_uInt16 nPgCnt = rDoc.GetSdPageCount( PK_STANDARD );
191 : :
192 : : // Insert position is the behind the last selected page or behind the
193 : : // last page when the selection is empty.
194 : 0 : sal_uInt16 nInsertPos = rDoc.GetSdPageCount( PK_STANDARD ) * 2 + 1;
195 [ # # ]: 0 : for( sal_uInt16 nPage = 0; nPage < nPgCnt; nPage++ )
196 : : {
197 : 0 : SdPage* pPage = rDoc.GetSdPage( nPage, PK_STANDARD );
198 : :
199 [ # # ]: 0 : if( pPage->IsSelected() )
200 : 0 : nInsertPos = nPage * 2 + 3;
201 : : }
202 : :
203 : 0 : return nInsertPos;
204 : : }
205 : :
206 : :
207 : :
208 : :
209 : 0 : sal_uInt16 ViewClipboard::InsertSlides (
210 : : const SdTransferable& rTransferable,
211 : : sal_uInt16 nInsertPosition)
212 : : {
213 : 0 : SdDrawDocument& rDoc = mrView.GetDoc();
214 : :
215 : 0 : sal_uInt16 nInsertPgCnt = 0;
216 : 0 : sal_Bool bMergeMasterPages = !rTransferable.HasSourceDoc( &rDoc );
217 : :
218 : : // Prepare the insertion.
219 : 0 : const std::vector<rtl::OUString> *pBookmarkList = NULL;
220 : : DrawDocShell* pDataDocSh;
221 [ # # ]: 0 : if (rTransferable.HasPageBookmarks())
222 : : {
223 : : // When the transferable contains page bookmarks then the referenced
224 : : // pages are inserted.
225 : 0 : pBookmarkList = &rTransferable.GetPageBookmarks();
226 : 0 : pDataDocSh = rTransferable.GetPageDocShell();
227 : 0 : nInsertPgCnt = (sal_uInt16)pBookmarkList->size();
228 : : }
229 : : else
230 : : {
231 : : // Otherwise all pages of the document of the transferable are
232 : : // inserted.
233 : 0 : SfxObjectShell* pShell = rTransferable.GetDocShell();
234 : 0 : pDataDocSh = (DrawDocShell*) pShell;
235 : 0 : SdDrawDocument* pDataDoc = pDataDocSh->GetDoc();
236 : :
237 [ # # ][ # # ]: 0 : if (pDataDoc!=NULL && pDataDoc->GetSdPageCount(PK_STANDARD))
[ # # ]
238 : 0 : nInsertPgCnt = pDataDoc->GetSdPageCount(PK_STANDARD);
239 : : }
240 [ # # ]: 0 : if (nInsertPgCnt > 0)
241 : : {
242 [ # # ]: 0 : const SolarMutexGuard aGuard;
243 [ # # ]: 0 : ::sd::Window* pWin = mrView.GetViewShell()->GetActiveWindow();
244 [ # # ][ # # ]: 0 : const sal_Bool bWait = pWin && pWin->IsWait();
[ # # ]
245 : :
246 [ # # ]: 0 : if( bWait )
247 [ # # ]: 0 : pWin->LeaveWait();
248 : :
249 : : rDoc.InsertBookmarkAsPage(
250 : : pBookmarkList ? *pBookmarkList : std::vector<rtl::OUString>(),
251 : : NULL,
252 : : sal_False,
253 : : sal_False,
254 : : nInsertPosition,
255 [ # # ]: 0 : (&rTransferable == SD_MOD()->pTransferDrag),
256 : : pDataDocSh,
257 : : sal_True,
258 : : bMergeMasterPages,
259 [ # # ][ # # ]: 0 : sal_False);
[ # # ][ # # ]
260 : :
261 [ # # ]: 0 : if( bWait )
262 [ # # ][ # # ]: 0 : pWin->EnterWait();
263 : : }
264 : :
265 : 0 : return nInsertPgCnt;
266 : : }
267 : :
268 : :
269 : : } // end of namespace ::sd
270 : :
271 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|