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