LCOV - code coverage report
Current view: top level - sw/source/core/doc - docglos.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 89 95 93.7 %
Date: 2015-06-13 12:38:46 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          56 : 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          56 :         GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
      45             :     uno::Reference<document::XDocumentProperties> xDocProps(
      46         112 :         xDPS->getDocumentProperties() );
      47             :     OSL_ENSURE(xDocProps.is(), "null reference");
      48             : 
      49             :     uno::Reference<beans::XPropertySet> xSourceUDSet(
      50         112 :         xSourceDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
      51             :     uno::Reference<beans::XPropertyContainer> xTargetUD(
      52         112 :         xDocProps->getUserDefinedProperties());
      53             :     uno::Reference<beans::XPropertySet> xTargetUDSet(xTargetUD,
      54         112 :         uno::UNO_QUERY_THROW);
      55             :     uno::Sequence<beans::Property> tgtprops
      56         112 :         = xTargetUDSet->getPropertySetInfo()->getProperties();
      57             : 
      58          56 :     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         112 :         = xSourceUDSet->getPropertySetInfo();
      68         112 :     uno::Sequence<beans::Property> srcprops = xSetInfo->getProperties();
      69             : 
      70          60 :     for (sal_Int32 i = 0; i < srcprops.getLength(); ++i) {
      71             :         try {
      72           4 :             OUString name = srcprops[i].Name;
      73           8 :             xTargetUD->addProperty(name, srcprops[i].Attributes,
      74           8 :                 xSourceUDSet->getPropertyValue(name));
      75           0 :         } catch (uno::Exception &) {
      76             :             // ignore
      77             :         }
      78          56 :     }
      79          56 : }
      80             : 
      81          56 : void SwDoc::ReplaceDocumentProperties(const SwDoc& rSource, bool mailMerge)
      82             : {
      83             :     uno::Reference<document::XDocumentPropertiesSupplier> xSourceDPS(
      84          56 :         rSource.GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
      85             :     uno::Reference<document::XDocumentProperties> xSourceDocProps(
      86         112 :         xSourceDPS->getDocumentProperties() );
      87             :     OSL_ENSURE(xSourceDocProps.is(), "null reference");
      88             : 
      89             :     uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
      90         112 :         GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
      91             :     uno::Reference<document::XDocumentProperties> xDocProps(
      92         112 :         xDPS->getDocumentProperties() );
      93             :     OSL_ENSURE(xDocProps.is(), "null reference");
      94             : 
      95          56 :     xDocProps->setAuthor(xSourceDocProps->getAuthor());
      96          56 :     xDocProps->setGenerator(xSourceDocProps->getGenerator());
      97          56 :     xDocProps->setCreationDate(xSourceDocProps->getCreationDate());
      98          56 :     xDocProps->setTitle(xSourceDocProps->getTitle());
      99          56 :     xDocProps->setSubject(xSourceDocProps->getSubject());
     100          56 :     xDocProps->setDescription(xSourceDocProps->getDescription());
     101          56 :     xDocProps->setKeywords(xSourceDocProps->getKeywords());
     102          56 :     xDocProps->setLanguage(xSourceDocProps->getLanguage());
     103             :     // Note: These below originally weren't copied for mailmerge, but I don't see why not.
     104          56 :     xDocProps->setModifiedBy(xSourceDocProps->getModifiedBy());
     105          56 :     xDocProps->setModificationDate(xSourceDocProps->getModificationDate());
     106          56 :     xDocProps->setPrintedBy(xSourceDocProps->getPrintedBy());
     107          56 :     xDocProps->setPrintDate(xSourceDocProps->getPrintDate());
     108          56 :     xDocProps->setTemplateName(xSourceDocProps->getTemplateName());
     109          56 :     xDocProps->setTemplateURL(xSourceDocProps->getTemplateURL());
     110          56 :     xDocProps->setTemplateDate(xSourceDocProps->getTemplateDate());
     111          56 :     xDocProps->setAutoloadURL(xSourceDocProps->getAutoloadURL());
     112          56 :     xDocProps->setAutoloadSecs(xSourceDocProps->getAutoloadSecs());
     113          56 :     xDocProps->setDefaultTarget(xSourceDocProps->getDefaultTarget());
     114          56 :     xDocProps->setDocumentStatistics(xSourceDocProps->getDocumentStatistics());
     115          56 :     xDocProps->setEditingCycles(xSourceDocProps->getEditingCycles());
     116          56 :     xDocProps->setEditingDuration(xSourceDocProps->getEditingDuration());
     117             : 
     118          56 :     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         112 :     ReplaceUserDefinedDocumentProperties( xSourceDocProps );
     126          56 : }
     127             : 
     128             : /// inserts an AutoText block
     129           4 : bool SwDoc::InsertGlossary( SwTextBlocks& rBlock, const OUString& rEntry,
     130             :                             SwPaM& rPaM, SwCrsrShell* pShell )
     131             : {
     132           4 :     bool bRet = false;
     133           4 :     const sal_uInt16 nIdx = rBlock.GetIndex( rEntry );
     134           4 :     if( USHRT_MAX != nIdx )
     135             :     {
     136           4 :         bool bSav_IsInsGlossary = mbInsOnlyTextGlssry;
     137           4 :         mbInsOnlyTextGlssry = rBlock.IsOnlyTextBlock( nIdx );
     138             : 
     139           4 :         if( rBlock.BeginGetDoc( nIdx ) )
     140             :         {
     141           4 :             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           4 :             if (GetDocShell() && pGDoc->GetDocShell())
     152           4 :                 pGDoc->ReplaceDocumentProperties( *this );
     153           4 :             pGDoc->getIDocumentFieldsAccess().SetFixFields(false, NULL);
     154             : 
     155             :             // StartAllAction();
     156           4 :             getIDocumentFieldsAccess().LockExpFields();
     157             : 
     158           4 :             SwNodeIndex aStt( pGDoc->GetNodes().GetEndOfExtras(), 1 );
     159           4 :             SwContentNode* pContentNd = pGDoc->GetNodes().GoNext( &aStt );
     160           4 :             const SwTableNode* pTableNd = pContentNd->FindTableNode();
     161           8 :             SwPaM aCpyPam( pTableNd ? *const_cast<SwNode*>(static_cast<SwNode const *>(pTableNd)) : *static_cast<SwNode*>(pContentNd) );
     162           4 :             aCpyPam.SetMark();
     163             : 
     164             :             // till the nodes array's end
     165           4 :             aCpyPam.GetPoint()->nNode = pGDoc->GetNodes().GetEndOfContent().GetIndex()-1;
     166           4 :             pContentNd = aCpyPam.GetContentNode();
     167           4 :             aCpyPam.GetPoint()->nContent.Assign(
     168           8 :                     pContentNd, (pContentNd) ? pContentNd->Len() : 0 );
     169             : 
     170           4 :             GetIDocumentUndoRedo().StartUndo( UNDO_INSGLOSSARY, NULL );
     171           4 :             SwPaM *_pStartCrsr = &rPaM, *__pStartCrsr = _pStartCrsr;
     172           4 :             do {
     173             : 
     174           4 :                 SwPosition& rInsPos = *_pStartCrsr->GetPoint();
     175           4 :                 SwStartNode* pBoxSttNd = const_cast<SwStartNode*>(rInsPos.nNode.GetNode().
     176           4 :                                             FindTableBoxStartNode());
     177             : 
     178           4 :                 if( pBoxSttNd && 2 == pBoxSttNd->EndOfSectionIndex() -
     179           4 :                                       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           4 :                 SwDontExpandItem aACD;
     188           4 :                 aACD.SaveDontExpandItems( rInsPos );
     189             : 
     190           4 :                 pGDoc->getIDocumentContentOperations().CopyRange( aCpyPam, rInsPos, /*bCopyAll=*/false, /*bCheckPos=*/true );
     191             : 
     192           4 :                 aACD.RestoreDontExpandItems( rInsPos );
     193           4 :                 if( pShell )
     194           1 :                     pShell->SaveTableBoxContent( &rInsPos );
     195             :             } while( (_pStartCrsr = static_cast<SwPaM *>(_pStartCrsr->GetNext())) !=
     196             :                         __pStartCrsr );
     197           4 :             GetIDocumentUndoRedo().EndUndo( UNDO_INSGLOSSARY, NULL );
     198             : 
     199           4 :             getIDocumentFieldsAccess().UnlockExpFields();
     200           4 :             if( !getIDocumentFieldsAccess().IsExpFieldsLocked() )
     201           4 :                 getIDocumentFieldsAccess().UpdateExpFields(NULL, true);
     202           8 :             bRet = true;
     203             :         }
     204           4 :         mbInsOnlyTextGlssry = bSav_IsInsGlossary;
     205             :     }
     206           4 :     rBlock.EndGetDoc();
     207           4 :     return bRet;
     208         177 : }
     209             : 
     210             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11