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