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 .
21 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
22 #include <com/sun/star/document/XDocumentProperties.hpp>
23 #include <com/sun/star/beans/XPropertySet.hpp>
24 #include <com/sun/star/beans/XPropertySetInfo.hpp>
27 #include <IDocumentUndoRedo.hxx>
28 #include <shellio.hxx>
32 #include <acorrect.hxx>
37 using namespace ::com::sun::star
;
40 /// copy document properties via public interface
41 static void lcl_copyDocumentProperties(
42 uno::Reference
<document::XDocumentProperties
> i_xSource
,
43 uno::Reference
<document::XDocumentProperties
> i_xTarget
) {
44 OSL_ENSURE(i_xSource
.is(), "null reference");
45 OSL_ENSURE(i_xTarget
.is(), "null reference");
47 i_xTarget
->setAuthor(i_xSource
->getAuthor());
48 i_xTarget
->setGenerator(i_xSource
->getGenerator());
49 i_xTarget
->setCreationDate(i_xSource
->getCreationDate());
50 i_xTarget
->setTitle(i_xSource
->getTitle());
51 i_xTarget
->setSubject(i_xSource
->getSubject());
52 i_xTarget
->setDescription(i_xSource
->getDescription());
53 i_xTarget
->setKeywords(i_xSource
->getKeywords());
54 i_xTarget
->setLanguage(i_xSource
->getLanguage());
55 i_xTarget
->setModifiedBy(i_xSource
->getModifiedBy());
56 i_xTarget
->setModificationDate(i_xSource
->getModificationDate());
57 i_xTarget
->setPrintedBy(i_xSource
->getPrintedBy());
58 i_xTarget
->setPrintDate(i_xSource
->getPrintDate());
59 i_xTarget
->setTemplateName(i_xSource
->getTemplateName());
60 i_xTarget
->setTemplateURL(i_xSource
->getTemplateURL());
61 i_xTarget
->setTemplateDate(i_xSource
->getTemplateDate());
62 i_xTarget
->setAutoloadURL(i_xSource
->getAutoloadURL());
63 i_xTarget
->setAutoloadSecs(i_xSource
->getAutoloadSecs());
64 i_xTarget
->setDefaultTarget(i_xSource
->getDefaultTarget());
65 i_xTarget
->setDocumentStatistics(i_xSource
->getDocumentStatistics());
66 i_xTarget
->setEditingCycles(i_xSource
->getEditingCycles());
67 i_xTarget
->setEditingDuration(i_xSource
->getEditingDuration());
69 uno::Reference
<beans::XPropertySet
> xSourceUDSet(
70 i_xSource
->getUserDefinedProperties(), uno::UNO_QUERY_THROW
);
71 uno::Reference
<beans::XPropertyContainer
> xTargetUD(
72 i_xTarget
->getUserDefinedProperties());
73 uno::Reference
<beans::XPropertySet
> xTargetUDSet(xTargetUD
,
74 uno::UNO_QUERY_THROW
);
75 uno::Sequence
<beans::Property
> tgtprops
76 = xTargetUDSet
->getPropertySetInfo()->getProperties();
77 for (sal_Int32 i
= 0; i
< tgtprops
.getLength(); ++i
) {
79 xTargetUD
->removeProperty(tgtprops
[i
].Name
);
80 } catch (uno::Exception
&) {
85 uno::Reference
<beans::XPropertySetInfo
> xSetInfo
86 = xSourceUDSet
->getPropertySetInfo();
87 uno::Sequence
<beans::Property
> srcprops
= xSetInfo
->getProperties();
88 for (sal_Int32 i
= 0; i
< srcprops
.getLength(); ++i
) {
89 OUString name
= srcprops
[i
].Name
;
90 xTargetUD
->addProperty(name
, srcprops
[i
].Attributes
,
91 xSourceUDSet
->getPropertyValue(name
));
93 } catch (uno::Exception
&) {
98 /// inserts an AutoText block
99 bool SwDoc::InsertGlossary( SwTextBlocks
& rBlock
, const String
& rEntry
,
100 SwPaM
& rPaM
, SwCrsrShell
* pShell
)
103 sal_uInt16 nIdx
= rBlock
.GetIndex( rEntry
);
104 if( (sal_uInt16
) -1 != nIdx
)
106 bool bSav_IsInsGlossary
= mbInsOnlyTxtGlssry
;
107 mbInsOnlyTxtGlssry
= rBlock
.IsOnlyTextBlock( nIdx
);
109 if( rBlock
.BeginGetDoc( nIdx
) )
111 SwDoc
* pGDoc
= rBlock
.GetDoc();
113 // Update all fixed fields, with the right DocInfo.
114 // FIXME: UGLY: Because we cannot limit the range in which to do
115 // field updates, we must update the fixed fields at the glossary
117 // To be able to do this, we copy the document properties of the
118 // target document to the glossary document
119 // OSL_ENSURE(GetDocShell(), "no SwDocShell"); // may be clipboard!
120 OSL_ENSURE(pGDoc
->GetDocShell(), "no SwDocShell at glossary");
121 if (GetDocShell() && pGDoc
->GetDocShell()) {
122 uno::Reference
<document::XDocumentPropertiesSupplier
> xDPS(
123 GetDocShell()->GetModel(), uno::UNO_QUERY_THROW
);
124 uno::Reference
<document::XDocumentProperties
> xDocProps(
125 xDPS
->getDocumentProperties() );
126 uno::Reference
<document::XDocumentPropertiesSupplier
> xGlosDPS(
127 pGDoc
->GetDocShell()->GetModel(), uno::UNO_QUERY_THROW
);
128 uno::Reference
<document::XDocumentProperties
> xGlosDocProps(
129 xGlosDPS
->getDocumentProperties() );
130 lcl_copyDocumentProperties(xDocProps
, xGlosDocProps
);
132 pGDoc
->SetFixFields(false, NULL
);
137 SwNodeIndex
aStt( pGDoc
->GetNodes().GetEndOfExtras(), 1 );
138 SwCntntNode
* pCntntNd
= pGDoc
->GetNodes().GoNext( &aStt
);
139 const SwTableNode
* pTblNd
= pCntntNd
->FindTableNode();
140 SwPaM
aCpyPam( pTblNd
? *(SwNode
*)pTblNd
: *(SwNode
*)pCntntNd
);
143 // till the nodes array's end
144 aCpyPam
.GetPoint()->nNode
= pGDoc
->GetNodes().GetEndOfContent().GetIndex()-1;
145 pCntntNd
= aCpyPam
.GetCntntNode();
146 aCpyPam
.GetPoint()->nContent
.Assign( pCntntNd
, pCntntNd
->Len() );
148 GetIDocumentUndoRedo().StartUndo( UNDO_INSGLOSSARY
, NULL
);
149 SwPaM
*_pStartCrsr
= &rPaM
, *__pStartCrsr
= _pStartCrsr
;
152 SwPosition
& rInsPos
= *_pStartCrsr
->GetPoint();
153 SwStartNode
* pBoxSttNd
= (SwStartNode
*)rInsPos
.nNode
.GetNode().
154 FindTableBoxStartNode();
156 if( pBoxSttNd
&& 2 == pBoxSttNd
->EndOfSectionIndex() -
157 pBoxSttNd
->GetIndex() &&
158 aCpyPam
.GetPoint()->nNode
!= aCpyPam
.GetMark()->nNode
)
160 // We copy more than one Node to the current Box.
161 // However, we have to remove the BoxAttributes then.
162 ClearBoxNumAttrs( rInsPos
.nNode
);
165 SwDontExpandItem aACD
;
166 aACD
.SaveDontExpandItems( rInsPos
);
168 pGDoc
->CopyRange( aCpyPam
, rInsPos
, false );
170 aACD
.RestoreDontExpandItems( rInsPos
);
172 pShell
->SaveTblBoxCntnt( &rInsPos
);
173 } while( (_pStartCrsr
=(SwPaM
*)_pStartCrsr
->GetNext()) !=
175 GetIDocumentUndoRedo().EndUndo( UNDO_INSGLOSSARY
, NULL
);
178 if( !IsExpFldsLocked() )
179 UpdateExpFlds(NULL
, true);
182 mbInsOnlyTxtGlssry
= bSav_IsInsGlossary
;
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */