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