1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*efeef26fSAndrew Rist * distributed with this work for additional information
6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at
10*efeef26fSAndrew Rist *
11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist *
13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the
17*efeef26fSAndrew Rist * specific language governing permissions and limitations
18*efeef26fSAndrew Rist * under the License.
19*efeef26fSAndrew Rist *
20*efeef26fSAndrew Rist *************************************************************/
21*efeef26fSAndrew Rist
22*efeef26fSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
28cdf0e10cSrcweir #include <com/sun/star/document/XDocumentProperties.hpp>
29cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
30cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySetInfo.hpp>
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include <doc.hxx>
33cdf0e10cSrcweir #include <IDocumentUndoRedo.hxx>
34cdf0e10cSrcweir #include <shellio.hxx>
35cdf0e10cSrcweir #include <pam.hxx>
36cdf0e10cSrcweir #include <swundo.hxx>
37cdf0e10cSrcweir #include <ndtxt.hxx>
38cdf0e10cSrcweir #include <acorrect.hxx>
39cdf0e10cSrcweir #include <crsrsh.hxx>
40cdf0e10cSrcweir #include <docsh.hxx>
41cdf0e10cSrcweir
42cdf0e10cSrcweir
43cdf0e10cSrcweir using namespace ::com::sun::star;
44cdf0e10cSrcweir
45cdf0e10cSrcweir
46cdf0e10cSrcweir /// copy document properties via public interface
lcl_copyDocumentProperties(uno::Reference<document::XDocumentProperties> i_xSource,uno::Reference<document::XDocumentProperties> i_xTarget)47cdf0e10cSrcweir static void lcl_copyDocumentProperties(
48cdf0e10cSrcweir uno::Reference<document::XDocumentProperties> i_xSource,
49cdf0e10cSrcweir uno::Reference<document::XDocumentProperties> i_xTarget) {
50cdf0e10cSrcweir DBG_ASSERT(i_xSource.is(), "null reference");
51cdf0e10cSrcweir DBG_ASSERT(i_xTarget.is(), "null reference");
52cdf0e10cSrcweir
53cdf0e10cSrcweir i_xTarget->setAuthor(i_xSource->getAuthor());
54cdf0e10cSrcweir i_xTarget->setGenerator(i_xSource->getGenerator());
55cdf0e10cSrcweir i_xTarget->setCreationDate(i_xSource->getCreationDate());
56cdf0e10cSrcweir i_xTarget->setTitle(i_xSource->getTitle());
57cdf0e10cSrcweir i_xTarget->setSubject(i_xSource->getSubject());
58cdf0e10cSrcweir i_xTarget->setDescription(i_xSource->getDescription());
59cdf0e10cSrcweir i_xTarget->setKeywords(i_xSource->getKeywords());
60cdf0e10cSrcweir i_xTarget->setLanguage(i_xSource->getLanguage());
61cdf0e10cSrcweir i_xTarget->setModifiedBy(i_xSource->getModifiedBy());
62cdf0e10cSrcweir i_xTarget->setModificationDate(i_xSource->getModificationDate());
63cdf0e10cSrcweir i_xTarget->setPrintedBy(i_xSource->getPrintedBy());
64cdf0e10cSrcweir i_xTarget->setPrintDate(i_xSource->getPrintDate());
65cdf0e10cSrcweir i_xTarget->setTemplateName(i_xSource->getTemplateName());
66cdf0e10cSrcweir i_xTarget->setTemplateURL(i_xSource->getTemplateURL());
67cdf0e10cSrcweir i_xTarget->setTemplateDate(i_xSource->getTemplateDate());
68cdf0e10cSrcweir i_xTarget->setAutoloadURL(i_xSource->getAutoloadURL());
69cdf0e10cSrcweir i_xTarget->setAutoloadSecs(i_xSource->getAutoloadSecs());
70cdf0e10cSrcweir i_xTarget->setDefaultTarget(i_xSource->getDefaultTarget());
71cdf0e10cSrcweir i_xTarget->setDocumentStatistics(i_xSource->getDocumentStatistics());
72cdf0e10cSrcweir i_xTarget->setEditingCycles(i_xSource->getEditingCycles());
73cdf0e10cSrcweir i_xTarget->setEditingDuration(i_xSource->getEditingDuration());
74cdf0e10cSrcweir
75cdf0e10cSrcweir uno::Reference<beans::XPropertySet> xSourceUDSet(
76cdf0e10cSrcweir i_xSource->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
77cdf0e10cSrcweir uno::Reference<beans::XPropertyContainer> xTargetUD(
78cdf0e10cSrcweir i_xTarget->getUserDefinedProperties());
79cdf0e10cSrcweir uno::Reference<beans::XPropertySet> xTargetUDSet(xTargetUD,
80cdf0e10cSrcweir uno::UNO_QUERY_THROW);
81cdf0e10cSrcweir uno::Sequence<beans::Property> tgtprops
82cdf0e10cSrcweir = xTargetUDSet->getPropertySetInfo()->getProperties();
83cdf0e10cSrcweir for (sal_Int32 i = 0; i < tgtprops.getLength(); ++i) {
84cdf0e10cSrcweir try {
85cdf0e10cSrcweir xTargetUD->removeProperty(tgtprops [i].Name);
86cdf0e10cSrcweir } catch (uno::Exception &) {
87cdf0e10cSrcweir // ignore
88cdf0e10cSrcweir }
89cdf0e10cSrcweir }
90cdf0e10cSrcweir try {
91cdf0e10cSrcweir uno::Reference<beans::XPropertySetInfo> xSetInfo
92cdf0e10cSrcweir = xSourceUDSet->getPropertySetInfo();
93cdf0e10cSrcweir uno::Sequence<beans::Property> srcprops = xSetInfo->getProperties();
94cdf0e10cSrcweir for (sal_Int32 i = 0; i < srcprops.getLength(); ++i) {
95cdf0e10cSrcweir ::rtl::OUString name = srcprops[i].Name;
96cdf0e10cSrcweir xTargetUD->addProperty(name, srcprops[i].Attributes,
97cdf0e10cSrcweir xSourceUDSet->getPropertyValue(name));
98cdf0e10cSrcweir }
99cdf0e10cSrcweir } catch (uno::Exception &) {
100cdf0e10cSrcweir // ignore
101cdf0e10cSrcweir }
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
104cdf0e10cSrcweir /* -----------------22.07.99 11:47-------------------
105cdf0e10cSrcweir Description: inserts an AutoText block
106cdf0e10cSrcweir --------------------------------------------------*/
InsertGlossary(SwTextBlocks & rBlock,const String & rEntry,SwPaM & rPaM,SwCrsrShell * pShell)107cdf0e10cSrcweir sal_Bool SwDoc::InsertGlossary( SwTextBlocks& rBlock, const String& rEntry,
108cdf0e10cSrcweir SwPaM& rPaM, SwCrsrShell* pShell )
109cdf0e10cSrcweir {
110cdf0e10cSrcweir sal_Bool bRet = sal_False;
111cdf0e10cSrcweir sal_uInt16 nIdx = rBlock.GetIndex( rEntry );
112cdf0e10cSrcweir if( (sal_uInt16) -1 != nIdx )
113cdf0e10cSrcweir {
114cdf0e10cSrcweir // Bug #70238# ask the TextOnly-Flag before BeginGetDoc, because
115cdf0e10cSrcweir // the method closed the Storage!
116cdf0e10cSrcweir sal_Bool bSav_IsInsGlossary = mbInsOnlyTxtGlssry;
117cdf0e10cSrcweir mbInsOnlyTxtGlssry = rBlock.IsOnlyTextBlock( nIdx );
118cdf0e10cSrcweir
119cdf0e10cSrcweir if( rBlock.BeginGetDoc( nIdx ) )
120cdf0e10cSrcweir {
121cdf0e10cSrcweir SwDoc* pGDoc = rBlock.GetDoc();
122cdf0e10cSrcweir
123cdf0e10cSrcweir // alle FixFelder aktualisieren. Dann aber auch mit der
124cdf0e10cSrcweir // richtigen DocInfo!
125cdf0e10cSrcweir // FIXME: UGLY: Because we cannot limit the range in which to do
126cdf0e10cSrcweir // field updates, we must update the fixed fields at the glossary
127cdf0e10cSrcweir // entry document.
128cdf0e10cSrcweir // To be able to do this, we copy the document properties of the
129cdf0e10cSrcweir // target document to the glossary document
130cdf0e10cSrcweir // DBG_ASSERT(GetDocShell(), "no SwDocShell"); // may be clipboard!
131cdf0e10cSrcweir DBG_ASSERT(pGDoc->GetDocShell(), "no SwDocShell at glossary");
132cdf0e10cSrcweir if (GetDocShell() && pGDoc->GetDocShell()) {
133cdf0e10cSrcweir uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
134cdf0e10cSrcweir GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
135cdf0e10cSrcweir uno::Reference<document::XDocumentProperties> xDocProps(
136cdf0e10cSrcweir xDPS->getDocumentProperties() );
137cdf0e10cSrcweir uno::Reference<document::XDocumentPropertiesSupplier> xGlosDPS(
138cdf0e10cSrcweir pGDoc->GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
139cdf0e10cSrcweir uno::Reference<document::XDocumentProperties> xGlosDocProps(
140cdf0e10cSrcweir xGlosDPS->getDocumentProperties() );
141cdf0e10cSrcweir lcl_copyDocumentProperties(xDocProps, xGlosDocProps);
142cdf0e10cSrcweir }
143cdf0e10cSrcweir pGDoc->SetFixFields(false, NULL);
144cdf0e10cSrcweir
145cdf0e10cSrcweir //StartAllAction();
146cdf0e10cSrcweir LockExpFlds();
147cdf0e10cSrcweir
148cdf0e10cSrcweir SwNodeIndex aStt( pGDoc->GetNodes().GetEndOfExtras(), 1 );
149cdf0e10cSrcweir SwCntntNode* pCntntNd = pGDoc->GetNodes().GoNext( &aStt );
150cdf0e10cSrcweir const SwTableNode* pTblNd = pCntntNd->FindTableNode();
151cdf0e10cSrcweir SwPaM aCpyPam( pTblNd ? *(SwNode*)pTblNd : *(SwNode*)pCntntNd );
152cdf0e10cSrcweir aCpyPam.SetMark();
153cdf0e10cSrcweir
154cdf0e10cSrcweir // dann bis zum Ende vom Nodes Array
155cdf0e10cSrcweir aCpyPam.GetPoint()->nNode = pGDoc->GetNodes().GetEndOfContent().GetIndex()-1;
156cdf0e10cSrcweir pCntntNd = aCpyPam.GetCntntNode();
157cdf0e10cSrcweir aCpyPam.GetPoint()->nContent.Assign( pCntntNd, pCntntNd->Len() );
158cdf0e10cSrcweir
159cdf0e10cSrcweir GetIDocumentUndoRedo().StartUndo( UNDO_INSGLOSSARY, NULL );
160cdf0e10cSrcweir SwPaM *_pStartCrsr = &rPaM, *__pStartCrsr = _pStartCrsr;
161cdf0e10cSrcweir do {
162cdf0e10cSrcweir
163cdf0e10cSrcweir SwPosition& rInsPos = *_pStartCrsr->GetPoint();
164cdf0e10cSrcweir SwStartNode* pBoxSttNd = (SwStartNode*)rInsPos.nNode.GetNode().
165cdf0e10cSrcweir FindTableBoxStartNode();
166cdf0e10cSrcweir
167cdf0e10cSrcweir if( pBoxSttNd && 2 == pBoxSttNd->EndOfSectionIndex() -
168cdf0e10cSrcweir pBoxSttNd->GetIndex() &&
169cdf0e10cSrcweir aCpyPam.GetPoint()->nNode != aCpyPam.GetMark()->nNode )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir // es wird mehr als 1 Node in die akt. Box kopiert.
172cdf0e10cSrcweir // Dann muessen die BoxAttribute aber entfernt werden.
173cdf0e10cSrcweir ClearBoxNumAttrs( rInsPos.nNode );
174cdf0e10cSrcweir }
175cdf0e10cSrcweir
176cdf0e10cSrcweir SwDontExpandItem aACD;
177cdf0e10cSrcweir aACD.SaveDontExpandItems( rInsPos );
178cdf0e10cSrcweir
179cdf0e10cSrcweir pGDoc->CopyRange( aCpyPam, rInsPos, false );
180cdf0e10cSrcweir
181cdf0e10cSrcweir aACD.RestoreDontExpandItems( rInsPos );
182cdf0e10cSrcweir if( pShell )
183cdf0e10cSrcweir pShell->SaveTblBoxCntnt( &rInsPos );
184cdf0e10cSrcweir } while( (_pStartCrsr=(SwPaM *)_pStartCrsr->GetNext()) !=
185cdf0e10cSrcweir __pStartCrsr );
186cdf0e10cSrcweir GetIDocumentUndoRedo().EndUndo( UNDO_INSGLOSSARY, NULL );
187cdf0e10cSrcweir
188cdf0e10cSrcweir UnlockExpFlds();
189cdf0e10cSrcweir if( !IsExpFldsLocked() )
190cdf0e10cSrcweir UpdateExpFlds(NULL, true);
191cdf0e10cSrcweir bRet = sal_True;
192cdf0e10cSrcweir }
193cdf0e10cSrcweir mbInsOnlyTxtGlssry = bSav_IsInsGlossary;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir rBlock.EndGetDoc();
196cdf0e10cSrcweir return bRet;
197cdf0e10cSrcweir }
198cdf0e10cSrcweir
199cdf0e10cSrcweir
200