Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sd / source / core / pglink.cxx
blob6762dcdd9bfa64cc109eca4281c79b5708c68b7a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 <sfx2/linkmgr.hxx>
22 #include <pglink.hxx>
23 #include <sdpage.hxx>
24 #include <drawdoc.hxx>
26 /*************************************************************************
28 |* Ctor
30 \************************************************************************/
32 SdPageLink::SdPageLink(SdPage* pPg, const OUString& rFileName,
33 const OUString& rBookmarkName) :
34 ::sfx2::SvBaseLink( ::SfxLinkUpdateMode::ONCALL, SotClipboardFormatId::SIMPLE_FILE),
35 pPage(pPg)
37 pPage->SetFileName(rFileName);
38 pPage->SetBookmarkName(rBookmarkName);
41 /*************************************************************************
43 |* Dtor
45 \************************************************************************/
47 SdPageLink::~SdPageLink()
51 /*************************************************************************
53 |* Date have changed
55 \************************************************************************/
57 ::sfx2::SvBaseLink::UpdateResult SdPageLink::DataChanged(
58 const OUString&, const css::uno::Any& )
60 SdDrawDocument* pDoc = static_cast<SdDrawDocument*>( &pPage->getSdrModelFromSdrPage() );
61 sfx2::LinkManager* pLinkManager = pDoc!=nullptr ? pDoc->GetLinkManager() : nullptr;
63 if (pLinkManager)
65 /**********************************************************************
66 * Only standard pages are allowed to be linked
67 * The corresponding note pages are updated automatically
68 **********************************************************************/
69 OUString aFileName;
70 OUString aBookmarkName;
71 OUString aFilterName;
72 sfx2::LinkManager::GetDisplayNames( this,nullptr, &aFileName, &aBookmarkName,
73 &aFilterName);
74 pPage->SetFileName(aFileName);
75 pPage->SetBookmarkName(aBookmarkName);
77 SdDrawDocument* pBookmarkDoc = pDoc->OpenBookmarkDoc(aFileName);
79 if (pBookmarkDoc)
81 /******************************************************************
82 * the linked page is replaced in the model
83 ******************************************************************/
84 if (aBookmarkName.isEmpty())
86 // no page name specified: we assume it is the first page
87 aBookmarkName = pBookmarkDoc->GetSdPage(0, PageKind::Standard)->GetName();
88 pPage->SetBookmarkName(aBookmarkName);
91 std::vector<OUString> aBookmarkList;
92 aBookmarkList.push_back(aBookmarkName);
93 sal_uInt16 nInsertPos = pPage->GetPageNum();
94 bool bNoDialogs = false;
95 bool bCopy = false;
97 if (SdDrawDocument::s_pDocLockedInsertingLinks)
99 // resolving links while loading pDoc
100 bNoDialogs = true;
101 bCopy = true;
104 pDoc->InsertBookmarkAsPage(aBookmarkList, nullptr, true/*bLink*/, true/*bReplace*/,
105 nInsertPos, bNoDialogs, nullptr, bCopy, true, true);
107 if (!SdDrawDocument::s_pDocLockedInsertingLinks)
108 pDoc->CloseBookmarkDoc();
111 return SUCCESS;
114 /*************************************************************************
116 |* Connect or disconnect link
118 \************************************************************************/
120 void SdPageLink::Closed()
122 // the connection is closed
123 pPage->SetFileName(OUString());
124 pPage->SetBookmarkName(OUString());
126 SvBaseLink::Closed();
129 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */