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