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