LCOV - code coverage report
Current view: top level - sw/source/core/doc - docglos.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 90 96 93.8 %
Date: 2014-11-03 Functions: 5 5 100.0 %
Legend: Lines: hit not hit

          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 <IDocumentFieldsAccess.hxx>
      28             : #include <shellio.hxx>
      29             : #include <pam.hxx>
      30             : #include <swundo.hxx>
      31             : #include <ndtxt.hxx>
      32             : #include <acorrect.hxx>
      33             : #include <crsrsh.hxx>
      34             : #include <docsh.hxx>
      35             : 
      36             : using namespace ::com::sun::star;
      37             : 
      38          22 : void SwDoc::ReplaceUserDefinedDocumentProperties(
      39             :         uno::Reference<document::XDocumentProperties> xSourceDocProps)
      40             : {
      41             :     OSL_ENSURE(xSourceDocProps.is(), "null reference");
      42             : 
      43             :     uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
      44          22 :         GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
      45             :     uno::Reference<document::XDocumentProperties> xDocProps(
      46          44 :         xDPS->getDocumentProperties() );
      47             :     OSL_ENSURE(xDocProps.is(), "null reference");
      48             : 
      49             :     uno::Reference<beans::XPropertySet> xSourceUDSet(
      50          44 :         xSourceDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
      51             :     uno::Reference<beans::XPropertyContainer> xTargetUD(
      52          44 :         xDocProps->getUserDefinedProperties());
      53             :     uno::Reference<beans::XPropertySet> xTargetUDSet(xTargetUD,
      54          44 :         uno::UNO_QUERY_THROW);
      55             :     uno::Sequence<beans::Property> tgtprops
      56          44 :         = xTargetUDSet->getPropertySetInfo()->getProperties();
      57             : 
      58          22 :     for (sal_Int32 i = 0; i < tgtprops.getLength(); ++i) {
      59             :         try {
      60           0 :             xTargetUD->removeProperty(tgtprops [i].Name);
      61           0 :         } catch (uno::Exception &) {
      62             :             // ignore
      63             :         }
      64             :     }
      65             : 
      66             :     uno::Reference<beans::XPropertySetInfo> xSetInfo
      67          44 :         = xSourceUDSet->getPropertySetInfo();
      68          44 :     uno::Sequence<beans::Property> srcprops = xSetInfo->getProperties();
      69             : 
      70          38 :     for (sal_Int32 i = 0; i < srcprops.getLength(); ++i) {
      71             :         try {
      72          16 :             OUString name = srcprops[i].Name;
      73          32 :             xTargetUD->addProperty(name, srcprops[i].Attributes,
      74          32 :                 xSourceUDSet->getPropertyValue(name));
      75           0 :         } catch (uno::Exception &) {
      76             :             // ignore
      77             :         }
      78          22 :     }
      79          22 : }
      80             : 
      81          22 : void SwDoc::ReplaceDocumentProperties(const SwDoc& rSource, bool mailMerge)
      82             : {
      83             :     uno::Reference<document::XDocumentPropertiesSupplier> xSourceDPS(
      84          22 :         rSource.GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
      85             :     uno::Reference<document::XDocumentProperties> xSourceDocProps(
      86          44 :         xSourceDPS->getDocumentProperties() );
      87             :     OSL_ENSURE(xSourceDocProps.is(), "null reference");
      88             : 
      89             :     uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
      90          44 :         GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
      91             :     uno::Reference<document::XDocumentProperties> xDocProps(
      92          44 :         xDPS->getDocumentProperties() );
      93             :     OSL_ENSURE(xDocProps.is(), "null reference");
      94             : 
      95          22 :     xDocProps->setAuthor(xSourceDocProps->getAuthor());
      96          22 :     xDocProps->setGenerator(xSourceDocProps->getGenerator());
      97          22 :     xDocProps->setCreationDate(xSourceDocProps->getCreationDate());
      98          22 :     xDocProps->setTitle(xSourceDocProps->getTitle());
      99          22 :     xDocProps->setSubject(xSourceDocProps->getSubject());
     100          22 :     xDocProps->setDescription(xSourceDocProps->getDescription());
     101          22 :     xDocProps->setKeywords(xSourceDocProps->getKeywords());
     102          22 :     xDocProps->setLanguage(xSourceDocProps->getLanguage());
     103             :     // Note: These below originally weren't copied for mailmerge, but I don't see why not.
     104          22 :     xDocProps->setModifiedBy(xSourceDocProps->getModifiedBy());
     105          22 :     xDocProps->setModificationDate(xSourceDocProps->getModificationDate());
     106          22 :     xDocProps->setPrintedBy(xSourceDocProps->getPrintedBy());
     107          22 :     xDocProps->setPrintDate(xSourceDocProps->getPrintDate());
     108          22 :     xDocProps->setTemplateName(xSourceDocProps->getTemplateName());
     109          22 :     xDocProps->setTemplateURL(xSourceDocProps->getTemplateURL());
     110          22 :     xDocProps->setTemplateDate(xSourceDocProps->getTemplateDate());
     111          22 :     xDocProps->setAutoloadURL(xSourceDocProps->getAutoloadURL());
     112          22 :     xDocProps->setAutoloadSecs(xSourceDocProps->getAutoloadSecs());
     113          22 :     xDocProps->setDefaultTarget(xSourceDocProps->getDefaultTarget());
     114          22 :     xDocProps->setDocumentStatistics(xSourceDocProps->getDocumentStatistics());
     115          22 :     xDocProps->setEditingCycles(xSourceDocProps->getEditingCycles());
     116          22 :     xDocProps->setEditingDuration(xSourceDocProps->getEditingDuration());
     117             : 
     118          22 :     if( mailMerge ) // Note: Not sure this is needed.
     119             :     {
     120             :         // Manually set the creation date, otherwise author field isn't filled
     121             :         // during MM, as it's set when saving the document the first time.
     122           0 :         xDocProps->setCreationDate( xSourceDocProps->getModificationDate() );
     123             :     }
     124             : 
     125          44 :     ReplaceUserDefinedDocumentProperties( xSourceDocProps );
     126          22 : }
     127             : 
     128             : /// inserts an AutoText block
     129           8 : bool SwDoc::InsertGlossary( SwTextBlocks& rBlock, const OUString& rEntry,
     130             :                             SwPaM& rPaM, SwCrsrShell* pShell )
     131             : {
     132           8 :     bool bRet = false;
     133           8 :     sal_uInt16 nIdx = rBlock.GetIndex( rEntry );
     134           8 :     if( (sal_uInt16) -1 != nIdx )
     135             :     {
     136           8 :         bool bSav_IsInsGlossary = mbInsOnlyTxtGlssry;
     137           8 :         mbInsOnlyTxtGlssry = rBlock.IsOnlyTextBlock( nIdx );
     138             : 
     139           8 :         if( rBlock.BeginGetDoc( nIdx ) )
     140             :         {
     141           8 :             SwDoc* pGDoc = rBlock.GetDoc();
     142             : 
     143             :             // Update all fixed fields, with the right DocInfo.
     144             :             // FIXME: UGLY: Because we cannot limit the range in which to do
     145             :             // field updates, we must update the fixed fields at the glossary
     146             :             // entry document.
     147             :             // To be able to do this, we copy the document properties of the
     148             :             // target document to the glossary document
     149             :             // OSL_ENSURE(GetDocShell(), "no SwDocShell"); // may be clipboard!
     150             :             OSL_ENSURE(pGDoc->GetDocShell(), "no SwDocShell at glossary");
     151           8 :             if (GetDocShell() && pGDoc->GetDocShell())
     152           8 :                 pGDoc->ReplaceDocumentProperties( *this );
     153           8 :             pGDoc->getIDocumentFieldsAccess().SetFixFields(false, NULL);
     154             : 
     155             :             // StartAllAction();
     156           8 :             getIDocumentFieldsAccess().LockExpFlds();
     157             : 
     158           8 :             SwNodeIndex aStt( pGDoc->GetNodes().GetEndOfExtras(), 1 );
     159           8 :             SwCntntNode* pCntntNd = pGDoc->GetNodes().GoNext( &aStt );
     160           8 :             const SwTableNode* pTblNd = pCntntNd->FindTableNode();
     161          16 :             SwPaM aCpyPam( pTblNd ? *(SwNode*)pTblNd : *(SwNode*)pCntntNd );
     162           8 :             aCpyPam.SetMark();
     163             : 
     164             :             // till the nodes array's end
     165           8 :             aCpyPam.GetPoint()->nNode = pGDoc->GetNodes().GetEndOfContent().GetIndex()-1;
     166           8 :             pCntntNd = aCpyPam.GetCntntNode();
     167           8 :             aCpyPam.GetPoint()->nContent.Assign(
     168          16 :                     pCntntNd, (pCntntNd) ? pCntntNd->Len() : 0 );
     169             : 
     170           8 :             GetIDocumentUndoRedo().StartUndo( UNDO_INSGLOSSARY, NULL );
     171           8 :             SwPaM *_pStartCrsr = &rPaM, *__pStartCrsr = _pStartCrsr;
     172           8 :             do {
     173             : 
     174           8 :                 SwPosition& rInsPos = *_pStartCrsr->GetPoint();
     175           8 :                 SwStartNode* pBoxSttNd = (SwStartNode*)rInsPos.nNode.GetNode().
     176           8 :                                             FindTableBoxStartNode();
     177             : 
     178           8 :                 if( pBoxSttNd && 2 == pBoxSttNd->EndOfSectionIndex() -
     179           8 :                                       pBoxSttNd->GetIndex() &&
     180           0 :                     aCpyPam.GetPoint()->nNode != aCpyPam.GetMark()->nNode )
     181             :                 {
     182             :                     // We copy more than one Node to the current Box.
     183             :                     // However, we have to remove the BoxAttributes then.
     184           0 :                     ClearBoxNumAttrs( rInsPos.nNode );
     185             :                 }
     186             : 
     187           8 :                 SwDontExpandItem aACD;
     188           8 :                 aACD.SaveDontExpandItems( rInsPos );
     189             : 
     190           8 :                 pGDoc->getIDocumentContentOperations().CopyRange( aCpyPam, rInsPos, false );
     191             : 
     192           8 :                 aACD.RestoreDontExpandItems( rInsPos );
     193           8 :                 if( pShell )
     194           2 :                     pShell->SaveTblBoxCntnt( &rInsPos );
     195           8 :             } while( (_pStartCrsr=(SwPaM *)_pStartCrsr->GetNext()) !=
     196             :                         __pStartCrsr );
     197           8 :             GetIDocumentUndoRedo().EndUndo( UNDO_INSGLOSSARY, NULL );
     198             : 
     199           8 :             getIDocumentFieldsAccess().UnlockExpFlds();
     200           8 :             if( !getIDocumentFieldsAccess().IsExpFldsLocked() )
     201           8 :                 getIDocumentFieldsAccess().UpdateExpFlds(NULL, true);
     202          16 :             bRet = true;
     203             :         }
     204           8 :         mbInsOnlyTxtGlssry = bSav_IsInsGlossary;
     205             :     }
     206           8 :     rBlock.EndGetDoc();
     207           8 :     return bRet;
     208         270 : }
     209             : 
     210             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10