LibreOffice Module sw (master) 1
docglos.cxx
Go to the documentation of this file.
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 <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
21#include <com/sun/star/document/XDocumentProperties.hpp>
22#include <com/sun/star/beans/XPropertySet.hpp>
23#include <com/sun/star/beans/XPropertySetInfo.hpp>
24#include <com/sun/star/frame/XModel.hpp>
25#include <osl/diagnose.h>
26
27#include <doc.hxx>
29#include <IDocumentUndoRedo.hxx>
31#include <shellio.hxx>
32#include <pam.hxx>
33#include <swundo.hxx>
34#include <acorrect.hxx>
35#include <crsrsh.hxx>
36#include <docsh.hxx>
37
38using namespace ::com::sun::star;
39
41 const uno::Reference<document::XDocumentProperties>& xSourceDocProps)
42{
43 OSL_ENSURE(xSourceDocProps.is(), "null reference");
44
45 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
46 GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
47 uno::Reference<document::XDocumentProperties> xDocProps(
48 xDPS->getDocumentProperties() );
49 OSL_ENSURE(xDocProps.is(), "null reference");
50
51 uno::Reference<beans::XPropertySet> xSourceUDSet(
52 xSourceDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
53 uno::Reference<beans::XPropertyContainer> xTargetUD(
54 xDocProps->getUserDefinedProperties());
55 uno::Reference<beans::XPropertySet> xTargetUDSet(xTargetUD,
56 uno::UNO_QUERY_THROW);
57 const uno::Sequence<beans::Property> tgtprops
58 = xTargetUDSet->getPropertySetInfo()->getProperties();
59
60 for (const auto& rTgtProp : tgtprops) {
61 try {
62 xTargetUD->removeProperty(rTgtProp.Name);
63 } catch (uno::Exception &) {
64 // ignore
65 }
66 }
67
68 uno::Reference<beans::XPropertySetInfo> xSetInfo
69 = xSourceUDSet->getPropertySetInfo();
70 const uno::Sequence<beans::Property> srcprops = xSetInfo->getProperties();
71
72 for (const auto& rSrcProp : srcprops) {
73 try {
74 OUString name = rSrcProp.Name;
75 xTargetUD->addProperty(name, rSrcProp.Attributes,
76 xSourceUDSet->getPropertyValue(name));
77 } catch (uno::Exception &) {
78 // ignore
79 }
80 }
81}
82
83void SwDoc::ReplaceDocumentProperties(const SwDoc& rSource, bool mailMerge)
84{
85 uno::Reference<document::XDocumentPropertiesSupplier> xSourceDPS(
86 rSource.GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
87 uno::Reference<document::XDocumentProperties> xSourceDocProps(
88 xSourceDPS->getDocumentProperties() );
89 OSL_ENSURE(xSourceDocProps.is(), "null reference");
90
91 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
92 GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
93 uno::Reference<document::XDocumentProperties> xDocProps(
94 xDPS->getDocumentProperties() );
95 OSL_ENSURE(xDocProps.is(), "null reference");
96
97 xDocProps->setAuthor(xSourceDocProps->getAuthor());
98 xDocProps->setGenerator(xSourceDocProps->getGenerator());
99 xDocProps->setCreationDate(xSourceDocProps->getCreationDate());
100 xDocProps->setTitle(xSourceDocProps->getTitle());
101 xDocProps->setSubject(xSourceDocProps->getSubject());
102 xDocProps->setDescription(xSourceDocProps->getDescription());
103 xDocProps->setKeywords(xSourceDocProps->getKeywords());
104 xDocProps->setLanguage(xSourceDocProps->getLanguage());
105 // Note: These below originally weren't copied for mailmerge, but I don't see why not.
106 xDocProps->setModifiedBy(xSourceDocProps->getModifiedBy());
107 xDocProps->setModificationDate(xSourceDocProps->getModificationDate());
108 xDocProps->setPrintedBy(xSourceDocProps->getPrintedBy());
109 xDocProps->setPrintDate(xSourceDocProps->getPrintDate());
110 xDocProps->setTemplateName(xSourceDocProps->getTemplateName());
111 xDocProps->setTemplateURL(xSourceDocProps->getTemplateURL());
112 xDocProps->setTemplateDate(xSourceDocProps->getTemplateDate());
113 xDocProps->setAutoloadURL(xSourceDocProps->getAutoloadURL());
114 xDocProps->setAutoloadSecs(xSourceDocProps->getAutoloadSecs());
115 xDocProps->setDefaultTarget(xSourceDocProps->getDefaultTarget());
116 xDocProps->setDocumentStatistics(xSourceDocProps->getDocumentStatistics());
117 xDocProps->setEditingCycles(xSourceDocProps->getEditingCycles());
118 xDocProps->setEditingDuration(xSourceDocProps->getEditingDuration());
119
120 if( mailMerge ) // Note: Not sure this is needed.
121 {
122 // Manually set the creation date, otherwise author field isn't filled
123 // during MM, as it's set when saving the document the first time.
124 xDocProps->setCreationDate( xSourceDocProps->getModificationDate() );
125 }
126
127 ReplaceUserDefinedDocumentProperties( xSourceDocProps );
128}
129
131bool SwDoc::InsertGlossary( SwTextBlocks& rBlock, const OUString& rEntry,
132 SwPaM& rPaM, SwCursorShell* pShell )
133{
134 bool bRet = false;
135 const sal_uInt16 nIdx = rBlock.GetIndex( rEntry );
136 if( USHRT_MAX != nIdx )
137 {
138 bool bSav_IsInsGlossary = mbInsOnlyTextGlssry;
139 mbInsOnlyTextGlssry = rBlock.IsOnlyTextBlock( nIdx );
140
141 if( rBlock.BeginGetDoc( nIdx ) )
142 {
143 SwDoc* pGDoc = rBlock.GetDoc();
144
145 // Update all fixed fields, with the right DocInfo.
146 // FIXME: UGLY: Because we cannot limit the range in which to do
147 // field updates, we must update the fixed fields at the glossary
148 // entry document.
149 // To be able to do this, we copy the document properties of the
150 // target document to the glossary document
151 // OSL_ENSURE(GetDocShell(), "no SwDocShell"); // may be clipboard!
152 OSL_ENSURE(pGDoc->GetDocShell(), "no SwDocShell at glossary");
153 if (GetDocShell() && pGDoc->GetDocShell())
154 pGDoc->ReplaceDocumentProperties( *this );
155 pGDoc->getIDocumentFieldsAccess().SetFixFields(nullptr);
156
157 // StartAllAction();
159
160 SwNodeIndex aStt( pGDoc->GetNodes().GetEndOfExtras(), 1 );
161 SwContentNode* pContentNd = pGDoc->GetNodes().GoNext( &aStt );
162 const SwTableNode* pTableNd = pContentNd->FindTableNode();
163 SwPaM aCpyPam( pTableNd ? *const_cast<SwNode*>(static_cast<SwNode const *>(pTableNd)) : *static_cast<SwNode*>(pContentNd) );
164 aCpyPam.SetMark();
165
166 // till the nodes array's end
167 aCpyPam.GetPoint()->Assign( pGDoc->GetNodes().GetEndOfContent().GetIndex()-SwNodeOffset(1) );
168 pContentNd = aCpyPam.GetPointContentNode();
169 if (pContentNd)
170 aCpyPam.GetPoint()->SetContent( pContentNd->Len() );
171
172 GetIDocumentUndoRedo().StartUndo( SwUndoId::INSGLOSSARY, nullptr );
173 SwPaM *_pStartCursor = &rPaM, *_pStartCursor2 = _pStartCursor;
174 do {
175
176 SwPosition& rInsPos = *_pStartCursor->GetPoint();
177 SwStartNode* pBoxSttNd = const_cast<SwStartNode*>(rInsPos.GetNode().
178 FindTableBoxStartNode());
179
180 if( pBoxSttNd && SwNodeOffset(2) == pBoxSttNd->EndOfSectionIndex() -
181 pBoxSttNd->GetIndex() &&
182 aCpyPam.GetPoint()->GetNode() != aCpyPam.GetMark()->GetNode() )
183 {
184 // We copy more than one Node to the current Box.
185 // However, we have to remove the BoxAttributes then.
186 ClearBoxNumAttrs( rInsPos.GetNode() );
187 }
188
189 SwDontExpandItem aACD;
190 aACD.SaveDontExpandItems( rInsPos );
191
193
194 aACD.RestoreDontExpandItems( rInsPos );
195 if( pShell )
196 pShell->SaveTableBoxContent( &rInsPos );
197 } while( (_pStartCursor = _pStartCursor->GetNext()) !=
198 _pStartCursor2 );
199 GetIDocumentUndoRedo().EndUndo( SwUndoId::INSGLOSSARY, nullptr );
200
202 if( !getIDocumentFieldsAccess().IsExpFieldsLocked() )
204 bRet = true;
205 }
206 mbInsOnlyTextGlssry = bSav_IsInsGlossary;
207 }
208 rBlock.EndGetDoc();
209 return bRet;
210}
211
212/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
@ CheckPosInFly
check if target position is in fly anchored at source range
virtual bool CopyRange(SwPaM &rPam, SwPosition &rPos, SwCopyFlags flags) const =0
Copy a selected content range to a position.
virtual void LockExpFields()=0
virtual void SetFixFields(const DateTime *pNewDateTime)=0
virtual void UpdateExpFields(SwTextField *pField, bool bUpdateRefFields)=0
virtual void UnlockExpFields()=0
css::uno::Reference< css::frame::XModel3 > GetModel() const
virtual sal_Int32 Len() const
Definition: node.cxx:1263
void SaveTableBoxContent(const SwPosition *pPos=nullptr)
Definition: trvltbl.cxx:867
Definition: doc.hxx:194
bool InsertGlossary(SwTextBlocks &rBlock, const OUString &rEntry, SwPaM &rPaM, SwCursorShell *pShell=nullptr)
inserts an AutoText block
Definition: docglos.cxx:131
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:321
IDocumentUndoRedo & GetIDocumentUndoRedo()
Definition: doc.cxx:150
SwNodes & GetNodes()
Definition: doc.hxx:417
IDocumentFieldsAccess const & getIDocumentFieldsAccess() const
Definition: doc.cxx:363
void ReplaceDocumentProperties(const SwDoc &rSource, bool mailMerge=false)
Replace document properties with those from rSource.
Definition: docglos.cxx:83
void ReplaceUserDefinedDocumentProperties(const css::uno::Reference< css::document::XDocumentProperties > &xSourceDocProps)
Replace all user defined document properties with xSourceDocProps.
Definition: docglos.cxx:40
bool mbInsOnlyTextGlssry
Definition: doc.hxx:325
void ClearBoxNumAttrs(SwNode &rNode)
Definition: ndtbl.cxx:4230
SwDocShell * GetDocShell()
Definition: doc.hxx:1359
void RestoreDontExpandItems(const SwPosition &rPos)
Definition: acorrect.cxx:670
void SaveDontExpandItems(const SwPosition &rPos)
Definition: acorrect.cxx:654
Marks a node in the document model.
Definition: ndindex.hxx:31
Base class of the Writer document model elements.
Definition: node.hxx:98
SwNodeOffset GetIndex() const
Definition: node.hxx:312
SwTableNode * FindTableNode()
Search table node, in which it is.
Definition: node.cxx:380
SwNodeOffset EndOfSectionIndex() const
Definition: node.hxx:726
SwNode & GetEndOfExtras() const
This is the last EndNode of a special section.
Definition: ndarr.hxx:163
SwNode & GetEndOfContent() const
Regular ContentSection (i.e. the BodyText).
Definition: ndarr.hxx:165
SwContentNode * GoNext(SwNodeIndex *) const
Definition: nodes.cxx:1294
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:187
const SwPosition * GetMark() const
Definition: pam.hxx:263
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:642
SwContentNode * GetPointContentNode() const
Definition: pam.hxx:287
SwPaM * GetNext()
Definition: pam.hxx:320
const SwPosition * GetPoint() const
Definition: pam.hxx:261
Starts a section of nodes in the document model.
Definition: node.hxx:348
SwDoc * GetDoc()
Definition: swblocks.cxx:481
bool BeginGetDoc(sal_uInt16)
Definition: swblocks.cxx:359
bool IsOnlyTextBlock(sal_uInt16) const
Definition: swblocks.cxx:507
sal_uInt16 GetIndex(const OUString &) const
Definition: swblocks.cxx:261
void EndGetDoc()
Definition: swblocks.cxx:379
const char * name
o3tl::strong_int< sal_Int32, struct Tag_SwNodeOffset > SwNodeOffset
Definition: nodeoffset.hxx:16
Marks a position in the document model.
Definition: pam.hxx:37
SwNode & GetNode() const
Definition: pam.hxx:80
void Assign(const SwNode &rNd, SwNodeOffset nDelta, sal_Int32 nContentOffset=0)
These all set both nNode and nContent.
Definition: pam.cxx:230
void SetContent(sal_Int32 nContentIndex)
Set content index, only valid to call this if the position points to a SwContentNode subclass.
Definition: pam.cxx:266