Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
21 : #include <com/sun/star/document/XDocumentProperties.hpp>
22 : #include <com/sun/star/beans/XPropertySet.hpp>
23 : #include <com/sun/star/beans/XPropertySetInfo.hpp>
24 :
25 : #include <doc.hxx>
26 : #include <IDocumentUndoRedo.hxx>
27 : #include <shellio.hxx>
28 : #include <pam.hxx>
29 : #include <swundo.hxx>
30 : #include <ndtxt.hxx>
31 : #include <acorrect.hxx>
32 : #include <crsrsh.hxx>
33 : #include <docsh.hxx>
34 :
35 : using namespace ::com::sun::star;
36 :
37 : /// copy document properties via public interface
38 4 : static void lcl_copyDocumentProperties(
39 : uno::Reference<document::XDocumentProperties> i_xSource,
40 : uno::Reference<document::XDocumentProperties> i_xTarget) {
41 : OSL_ENSURE(i_xSource.is(), "null reference");
42 : OSL_ENSURE(i_xTarget.is(), "null reference");
43 :
44 4 : i_xTarget->setAuthor(i_xSource->getAuthor());
45 4 : i_xTarget->setGenerator(i_xSource->getGenerator());
46 4 : i_xTarget->setCreationDate(i_xSource->getCreationDate());
47 4 : i_xTarget->setTitle(i_xSource->getTitle());
48 4 : i_xTarget->setSubject(i_xSource->getSubject());
49 4 : i_xTarget->setDescription(i_xSource->getDescription());
50 4 : i_xTarget->setKeywords(i_xSource->getKeywords());
51 4 : i_xTarget->setLanguage(i_xSource->getLanguage());
52 4 : i_xTarget->setModifiedBy(i_xSource->getModifiedBy());
53 4 : i_xTarget->setModificationDate(i_xSource->getModificationDate());
54 4 : i_xTarget->setPrintedBy(i_xSource->getPrintedBy());
55 4 : i_xTarget->setPrintDate(i_xSource->getPrintDate());
56 4 : i_xTarget->setTemplateName(i_xSource->getTemplateName());
57 4 : i_xTarget->setTemplateURL(i_xSource->getTemplateURL());
58 4 : i_xTarget->setTemplateDate(i_xSource->getTemplateDate());
59 4 : i_xTarget->setAutoloadURL(i_xSource->getAutoloadURL());
60 4 : i_xTarget->setAutoloadSecs(i_xSource->getAutoloadSecs());
61 4 : i_xTarget->setDefaultTarget(i_xSource->getDefaultTarget());
62 4 : i_xTarget->setDocumentStatistics(i_xSource->getDocumentStatistics());
63 4 : i_xTarget->setEditingCycles(i_xSource->getEditingCycles());
64 4 : i_xTarget->setEditingDuration(i_xSource->getEditingDuration());
65 :
66 : uno::Reference<beans::XPropertySet> xSourceUDSet(
67 4 : i_xSource->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
68 : uno::Reference<beans::XPropertyContainer> xTargetUD(
69 8 : i_xTarget->getUserDefinedProperties());
70 : uno::Reference<beans::XPropertySet> xTargetUDSet(xTargetUD,
71 8 : uno::UNO_QUERY_THROW);
72 : uno::Sequence<beans::Property> tgtprops
73 8 : = xTargetUDSet->getPropertySetInfo()->getProperties();
74 4 : for (sal_Int32 i = 0; i < tgtprops.getLength(); ++i) {
75 : try {
76 0 : xTargetUD->removeProperty(tgtprops [i].Name);
77 0 : } catch (uno::Exception &) {
78 : // ignore
79 : }
80 : }
81 : try {
82 : uno::Reference<beans::XPropertySetInfo> xSetInfo
83 4 : = xSourceUDSet->getPropertySetInfo();
84 8 : uno::Sequence<beans::Property> srcprops = xSetInfo->getProperties();
85 4 : for (sal_Int32 i = 0; i < srcprops.getLength(); ++i) {
86 0 : OUString name = srcprops[i].Name;
87 0 : xTargetUD->addProperty(name, srcprops[i].Attributes,
88 0 : xSourceUDSet->getPropertyValue(name));
89 4 : }
90 0 : } catch (uno::Exception &) {
91 : // ignore
92 4 : }
93 4 : }
94 :
95 : /// inserts an AutoText block
96 4 : bool SwDoc::InsertGlossary( SwTextBlocks& rBlock, const OUString& rEntry,
97 : SwPaM& rPaM, SwCrsrShell* pShell )
98 : {
99 4 : bool bRet = false;
100 4 : sal_uInt16 nIdx = rBlock.GetIndex( rEntry );
101 4 : if( (sal_uInt16) -1 != nIdx )
102 : {
103 4 : bool bSav_IsInsGlossary = mbInsOnlyTxtGlssry;
104 4 : mbInsOnlyTxtGlssry = rBlock.IsOnlyTextBlock( nIdx );
105 :
106 4 : if( rBlock.BeginGetDoc( nIdx ) )
107 : {
108 4 : SwDoc* pGDoc = rBlock.GetDoc();
109 :
110 : // Update all fixed fields, with the right DocInfo.
111 : // FIXME: UGLY: Because we cannot limit the range in which to do
112 : // field updates, we must update the fixed fields at the glossary
113 : // entry document.
114 : // To be able to do this, we copy the document properties of the
115 : // target document to the glossary document
116 : // OSL_ENSURE(GetDocShell(), "no SwDocShell"); // may be clipboard!
117 : OSL_ENSURE(pGDoc->GetDocShell(), "no SwDocShell at glossary");
118 4 : if (GetDocShell() && pGDoc->GetDocShell()) {
119 : uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
120 4 : GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
121 : uno::Reference<document::XDocumentProperties> xDocProps(
122 8 : xDPS->getDocumentProperties() );
123 : uno::Reference<document::XDocumentPropertiesSupplier> xGlosDPS(
124 8 : pGDoc->GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
125 : uno::Reference<document::XDocumentProperties> xGlosDocProps(
126 8 : xGlosDPS->getDocumentProperties() );
127 8 : lcl_copyDocumentProperties(xDocProps, xGlosDocProps);
128 : }
129 4 : pGDoc->SetFixFields(false, NULL);
130 :
131 : // StartAllAction();
132 4 : LockExpFlds();
133 :
134 4 : SwNodeIndex aStt( pGDoc->GetNodes().GetEndOfExtras(), 1 );
135 4 : SwCntntNode* pCntntNd = pGDoc->GetNodes().GoNext( &aStt );
136 4 : const SwTableNode* pTblNd = pCntntNd->FindTableNode();
137 8 : SwPaM aCpyPam( pTblNd ? *(SwNode*)pTblNd : *(SwNode*)pCntntNd );
138 4 : aCpyPam.SetMark();
139 :
140 : // till the nodes array's end
141 4 : aCpyPam.GetPoint()->nNode = pGDoc->GetNodes().GetEndOfContent().GetIndex()-1;
142 4 : pCntntNd = aCpyPam.GetCntntNode();
143 4 : aCpyPam.GetPoint()->nContent.Assign( pCntntNd, pCntntNd->Len() );
144 :
145 4 : GetIDocumentUndoRedo().StartUndo( UNDO_INSGLOSSARY, NULL );
146 4 : SwPaM *_pStartCrsr = &rPaM, *__pStartCrsr = _pStartCrsr;
147 4 : do {
148 :
149 4 : SwPosition& rInsPos = *_pStartCrsr->GetPoint();
150 4 : SwStartNode* pBoxSttNd = (SwStartNode*)rInsPos.nNode.GetNode().
151 4 : FindTableBoxStartNode();
152 :
153 4 : if( pBoxSttNd && 2 == pBoxSttNd->EndOfSectionIndex() -
154 4 : pBoxSttNd->GetIndex() &&
155 0 : aCpyPam.GetPoint()->nNode != aCpyPam.GetMark()->nNode )
156 : {
157 : // We copy more than one Node to the current Box.
158 : // However, we have to remove the BoxAttributes then.
159 0 : ClearBoxNumAttrs( rInsPos.nNode );
160 : }
161 :
162 4 : SwDontExpandItem aACD;
163 4 : aACD.SaveDontExpandItems( rInsPos );
164 :
165 4 : pGDoc->CopyRange( aCpyPam, rInsPos, false );
166 :
167 4 : aACD.RestoreDontExpandItems( rInsPos );
168 4 : if( pShell )
169 1 : pShell->SaveTblBoxCntnt( &rInsPos );
170 4 : } while( (_pStartCrsr=(SwPaM *)_pStartCrsr->GetNext()) !=
171 : __pStartCrsr );
172 4 : GetIDocumentUndoRedo().EndUndo( UNDO_INSGLOSSARY, NULL );
173 :
174 4 : UnlockExpFlds();
175 4 : if( !IsExpFldsLocked() )
176 4 : UpdateExpFlds(NULL, true);
177 8 : bRet = true;
178 : }
179 4 : mbInsOnlyTxtGlssry = bSav_IsInsGlossary;
180 : }
181 4 : rBlock.EndGetDoc();
182 4 : return bRet;
183 : }
184 :
185 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|