LCOV - code coverage report
Current view: top level - sw/source/core/doc - docglos.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 88 0.0 %
Date: 2014-04-14 Functions: 0 2 0.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 <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           0 : 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           0 :     i_xTarget->setAuthor(i_xSource->getAuthor());
      45           0 :     i_xTarget->setGenerator(i_xSource->getGenerator());
      46           0 :     i_xTarget->setCreationDate(i_xSource->getCreationDate());
      47           0 :     i_xTarget->setTitle(i_xSource->getTitle());
      48           0 :     i_xTarget->setSubject(i_xSource->getSubject());
      49           0 :     i_xTarget->setDescription(i_xSource->getDescription());
      50           0 :     i_xTarget->setKeywords(i_xSource->getKeywords());
      51           0 :     i_xTarget->setLanguage(i_xSource->getLanguage());
      52           0 :     i_xTarget->setModifiedBy(i_xSource->getModifiedBy());
      53           0 :     i_xTarget->setModificationDate(i_xSource->getModificationDate());
      54           0 :     i_xTarget->setPrintedBy(i_xSource->getPrintedBy());
      55           0 :     i_xTarget->setPrintDate(i_xSource->getPrintDate());
      56           0 :     i_xTarget->setTemplateName(i_xSource->getTemplateName());
      57           0 :     i_xTarget->setTemplateURL(i_xSource->getTemplateURL());
      58           0 :     i_xTarget->setTemplateDate(i_xSource->getTemplateDate());
      59           0 :     i_xTarget->setAutoloadURL(i_xSource->getAutoloadURL());
      60           0 :     i_xTarget->setAutoloadSecs(i_xSource->getAutoloadSecs());
      61           0 :     i_xTarget->setDefaultTarget(i_xSource->getDefaultTarget());
      62           0 :     i_xTarget->setDocumentStatistics(i_xSource->getDocumentStatistics());
      63           0 :     i_xTarget->setEditingCycles(i_xSource->getEditingCycles());
      64           0 :     i_xTarget->setEditingDuration(i_xSource->getEditingDuration());
      65             : 
      66             :     uno::Reference<beans::XPropertySet> xSourceUDSet(
      67           0 :         i_xSource->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
      68             :     uno::Reference<beans::XPropertyContainer> xTargetUD(
      69           0 :         i_xTarget->getUserDefinedProperties());
      70             :     uno::Reference<beans::XPropertySet> xTargetUDSet(xTargetUD,
      71           0 :         uno::UNO_QUERY_THROW);
      72             :     uno::Sequence<beans::Property> tgtprops
      73           0 :         = xTargetUDSet->getPropertySetInfo()->getProperties();
      74           0 :     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           0 :             = xSourceUDSet->getPropertySetInfo();
      84           0 :         uno::Sequence<beans::Property> srcprops = xSetInfo->getProperties();
      85           0 :         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           0 :         }
      90           0 :     } catch (uno::Exception &) {
      91             :         // ignore
      92           0 :     }
      93           0 : }
      94             : 
      95             : /// inserts an AutoText block
      96           0 : bool SwDoc::InsertGlossary( SwTextBlocks& rBlock, const OUString& rEntry,
      97             :                             SwPaM& rPaM, SwCrsrShell* pShell )
      98             : {
      99           0 :     bool bRet = false;
     100           0 :     sal_uInt16 nIdx = rBlock.GetIndex( rEntry );
     101           0 :     if( (sal_uInt16) -1 != nIdx )
     102             :     {
     103           0 :         bool bSav_IsInsGlossary = mbInsOnlyTxtGlssry;
     104           0 :         mbInsOnlyTxtGlssry = rBlock.IsOnlyTextBlock( nIdx );
     105             : 
     106           0 :         if( rBlock.BeginGetDoc( nIdx ) )
     107             :         {
     108           0 :             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           0 :             if (GetDocShell() && pGDoc->GetDocShell()) {
     119             :                 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
     120           0 :                     GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
     121             :                 uno::Reference<document::XDocumentProperties> xDocProps(
     122           0 :                     xDPS->getDocumentProperties() );
     123             :                 uno::Reference<document::XDocumentPropertiesSupplier> xGlosDPS(
     124           0 :                     pGDoc->GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
     125             :                 uno::Reference<document::XDocumentProperties> xGlosDocProps(
     126           0 :                     xGlosDPS->getDocumentProperties() );
     127           0 :                 lcl_copyDocumentProperties(xDocProps, xGlosDocProps);
     128             :         }
     129           0 :             pGDoc->SetFixFields(false, NULL);
     130             : 
     131             :             // StartAllAction();
     132           0 :             LockExpFlds();
     133             : 
     134           0 :             SwNodeIndex aStt( pGDoc->GetNodes().GetEndOfExtras(), 1 );
     135           0 :             SwCntntNode* pCntntNd = pGDoc->GetNodes().GoNext( &aStt );
     136           0 :             const SwTableNode* pTblNd = pCntntNd->FindTableNode();
     137           0 :             SwPaM aCpyPam( pTblNd ? *(SwNode*)pTblNd : *(SwNode*)pCntntNd );
     138           0 :             aCpyPam.SetMark();
     139             : 
     140             :             // till the nodes array's end
     141           0 :             aCpyPam.GetPoint()->nNode = pGDoc->GetNodes().GetEndOfContent().GetIndex()-1;
     142           0 :             pCntntNd = aCpyPam.GetCntntNode();
     143           0 :             aCpyPam.GetPoint()->nContent.Assign( pCntntNd, pCntntNd->Len() );
     144             : 
     145           0 :             GetIDocumentUndoRedo().StartUndo( UNDO_INSGLOSSARY, NULL );
     146           0 :             SwPaM *_pStartCrsr = &rPaM, *__pStartCrsr = _pStartCrsr;
     147           0 :             do {
     148             : 
     149           0 :                 SwPosition& rInsPos = *_pStartCrsr->GetPoint();
     150           0 :                 SwStartNode* pBoxSttNd = (SwStartNode*)rInsPos.nNode.GetNode().
     151           0 :                                             FindTableBoxStartNode();
     152             : 
     153           0 :                 if( pBoxSttNd && 2 == pBoxSttNd->EndOfSectionIndex() -
     154           0 :                                       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           0 :                 SwDontExpandItem aACD;
     163           0 :                 aACD.SaveDontExpandItems( rInsPos );
     164             : 
     165           0 :                 pGDoc->CopyRange( aCpyPam, rInsPos, false );
     166             : 
     167           0 :                 aACD.RestoreDontExpandItems( rInsPos );
     168           0 :                 if( pShell )
     169           0 :                     pShell->SaveTblBoxCntnt( &rInsPos );
     170           0 :             } while( (_pStartCrsr=(SwPaM *)_pStartCrsr->GetNext()) !=
     171             :                         __pStartCrsr );
     172           0 :             GetIDocumentUndoRedo().EndUndo( UNDO_INSGLOSSARY, NULL );
     173             : 
     174           0 :             UnlockExpFlds();
     175           0 :             if( !IsExpFldsLocked() )
     176           0 :                 UpdateExpFlds(NULL, true);
     177           0 :             bRet = true;
     178             :         }
     179           0 :         mbInsOnlyTxtGlssry = bSav_IsInsGlossary;
     180             :     }
     181           0 :     rBlock.EndGetDoc();
     182           0 :     return bRet;
     183             : }
     184             : 
     185             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10