Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <sfx2/linkmgr.hxx>
21 :
22 : #include "pglink.hxx"
23 : #include "sdpage.hxx"
24 : #include "drawdoc.hxx"
25 :
26 : /*************************************************************************
27 : |*
28 : |* Ctor
29 : |*
30 : \************************************************************************/
31 :
32 0 : SdPageLink::SdPageLink(SdPage* pPg, const OUString& rFileName,
33 : const OUString& rBookmarkName) :
34 : ::sfx2::SvBaseLink( ::SfxLinkUpdateMode::ONCALL, SotClipboardFormatId::SIMPLE_FILE),
35 0 : pPage(pPg)
36 : {
37 0 : pPage->SetFileName(rFileName);
38 0 : pPage->SetBookmarkName(rBookmarkName);
39 0 : }
40 :
41 : /*************************************************************************
42 : |*
43 : |* Dtor
44 : |*
45 : \************************************************************************/
46 :
47 0 : SdPageLink::~SdPageLink()
48 : {
49 0 : }
50 :
51 : /*************************************************************************
52 : |*
53 : |* Date have changed
54 : |*
55 : \************************************************************************/
56 :
57 0 : ::sfx2::SvBaseLink::UpdateResult SdPageLink::DataChanged(
58 : const OUString&, const ::com::sun::star::uno::Any& )
59 : {
60 0 : SdDrawDocument* pDoc = static_cast<SdDrawDocument*>( pPage->GetModel() );
61 0 : sfx2::LinkManager* pLinkManager = pDoc!=NULL ? pDoc->GetLinkManager() : NULL;
62 :
63 0 : if (pLinkManager)
64 : {
65 : /**********************************************************************
66 : * Only standard pages are allowed to be linked
67 : * The corresponding note pages are updated automatically
68 : **********************************************************************/
69 0 : OUString aFileName;
70 0 : OUString aBookmarkName;
71 0 : OUString aFilterName;
72 : sfx2::LinkManager::GetDisplayNames( this,0, &aFileName, &aBookmarkName,
73 0 : &aFilterName);
74 0 : pPage->SetFileName(aFileName);
75 0 : pPage->SetBookmarkName(aBookmarkName);
76 :
77 0 : SdDrawDocument* pBookmarkDoc = pDoc->OpenBookmarkDoc(aFileName);
78 :
79 0 : if (pBookmarkDoc)
80 : {
81 : /******************************************************************
82 : * the linked page is replaced in the model
83 : ******************************************************************/
84 0 : if (aBookmarkName.isEmpty())
85 : {
86 : // no page name specified: we assume it is the first page
87 0 : aBookmarkName = pBookmarkDoc->GetSdPage(0, PK_STANDARD)->GetName();
88 0 : pPage->SetBookmarkName(aBookmarkName);
89 : }
90 :
91 0 : std::vector<OUString> aBookmarkList;
92 0 : aBookmarkList.push_back(aBookmarkName);
93 0 : sal_uInt16 nInsertPos = pPage->GetPageNum();
94 0 : bool bLink = true;
95 0 : bool bReplace = true;
96 0 : bool bNoDialogs = false;
97 0 : bool bCopy = false;
98 :
99 0 : if( pDoc->pDocLockedInsertingLinks )
100 : {
101 : // resolving links while loading pDoc
102 0 : bNoDialogs = true;
103 0 : bCopy = true;
104 : }
105 :
106 : pDoc->InsertBookmarkAsPage(aBookmarkList, NULL, bLink, bReplace,
107 0 : nInsertPos, bNoDialogs, NULL, bCopy, true, true);
108 :
109 0 : if( !pDoc->pDocLockedInsertingLinks )
110 0 : pDoc->CloseBookmarkDoc();
111 0 : }
112 : }
113 0 : return SUCCESS;
114 : }
115 :
116 : /*************************************************************************
117 : |*
118 : |* Connect or disconnect link
119 : |*
120 : \************************************************************************/
121 :
122 0 : void SdPageLink::Closed()
123 : {
124 : // the connection is closed
125 0 : pPage->SetFileName(OUString());
126 0 : pPage->SetBookmarkName(OUString());
127 :
128 0 : SvBaseLink::Closed();
129 66 : }
130 :
131 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|