LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/doc - docglos.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 88 0.0 %
Date: 2012-12-17 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             : 
      21             : #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
      22             : #include <com/sun/star/document/XDocumentProperties.hpp>
      23             : #include <com/sun/star/beans/XPropertySet.hpp>
      24             : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      25             : 
      26             : #include <doc.hxx>
      27             : #include <IDocumentUndoRedo.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             : 
      37             : using namespace ::com::sun::star;
      38             : 
      39             : 
      40             : /// copy document properties via public interface
      41           0 : static void lcl_copyDocumentProperties(
      42             :         uno::Reference<document::XDocumentProperties> i_xSource,
      43             :         uno::Reference<document::XDocumentProperties> i_xTarget) {
      44             :     OSL_ENSURE(i_xSource.is(), "null reference");
      45             :     OSL_ENSURE(i_xTarget.is(), "null reference");
      46             : 
      47           0 :     i_xTarget->setAuthor(i_xSource->getAuthor());
      48           0 :     i_xTarget->setGenerator(i_xSource->getGenerator());
      49           0 :     i_xTarget->setCreationDate(i_xSource->getCreationDate());
      50           0 :     i_xTarget->setTitle(i_xSource->getTitle());
      51           0 :     i_xTarget->setSubject(i_xSource->getSubject());
      52           0 :     i_xTarget->setDescription(i_xSource->getDescription());
      53           0 :     i_xTarget->setKeywords(i_xSource->getKeywords());
      54           0 :     i_xTarget->setLanguage(i_xSource->getLanguage());
      55           0 :     i_xTarget->setModifiedBy(i_xSource->getModifiedBy());
      56           0 :     i_xTarget->setModificationDate(i_xSource->getModificationDate());
      57           0 :     i_xTarget->setPrintedBy(i_xSource->getPrintedBy());
      58           0 :     i_xTarget->setPrintDate(i_xSource->getPrintDate());
      59           0 :     i_xTarget->setTemplateName(i_xSource->getTemplateName());
      60           0 :     i_xTarget->setTemplateURL(i_xSource->getTemplateURL());
      61           0 :     i_xTarget->setTemplateDate(i_xSource->getTemplateDate());
      62           0 :     i_xTarget->setAutoloadURL(i_xSource->getAutoloadURL());
      63           0 :     i_xTarget->setAutoloadSecs(i_xSource->getAutoloadSecs());
      64           0 :     i_xTarget->setDefaultTarget(i_xSource->getDefaultTarget());
      65           0 :     i_xTarget->setDocumentStatistics(i_xSource->getDocumentStatistics());
      66           0 :     i_xTarget->setEditingCycles(i_xSource->getEditingCycles());
      67           0 :     i_xTarget->setEditingDuration(i_xSource->getEditingDuration());
      68             : 
      69             :     uno::Reference<beans::XPropertySet> xSourceUDSet(
      70           0 :         i_xSource->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
      71             :     uno::Reference<beans::XPropertyContainer> xTargetUD(
      72           0 :         i_xTarget->getUserDefinedProperties());
      73             :     uno::Reference<beans::XPropertySet> xTargetUDSet(xTargetUD,
      74           0 :         uno::UNO_QUERY_THROW);
      75             :     uno::Sequence<beans::Property> tgtprops
      76           0 :         = xTargetUDSet->getPropertySetInfo()->getProperties();
      77           0 :     for (sal_Int32 i = 0; i < tgtprops.getLength(); ++i) {
      78             :         try {
      79           0 :             xTargetUD->removeProperty(tgtprops [i].Name);
      80           0 :         } catch (uno::Exception &) {
      81             :             // ignore
      82             :         }
      83             :     }
      84             :     try {
      85             :         uno::Reference<beans::XPropertySetInfo> xSetInfo
      86           0 :             = xSourceUDSet->getPropertySetInfo();
      87           0 :         uno::Sequence<beans::Property> srcprops = xSetInfo->getProperties();
      88           0 :         for (sal_Int32 i = 0; i < srcprops.getLength(); ++i) {
      89           0 :             ::rtl::OUString name = srcprops[i].Name;
      90           0 :             xTargetUD->addProperty(name, srcprops[i].Attributes,
      91           0 :                 xSourceUDSet->getPropertyValue(name));
      92           0 :         }
      93           0 :     } catch (uno::Exception &) {
      94             :         // ignore
      95           0 :     }
      96           0 : }
      97             : 
      98             : /* --------------------------------------------------
      99             :     Description: inserts an AutoText block
     100             :  --------------------------------------------------*/
     101           0 : bool SwDoc::InsertGlossary( SwTextBlocks& rBlock, const String& rEntry,
     102             :                             SwPaM& rPaM, SwCrsrShell* pShell )
     103             : {
     104           0 :     bool bRet = false;
     105           0 :     sal_uInt16 nIdx = rBlock.GetIndex( rEntry );
     106           0 :     if( (sal_uInt16) -1 != nIdx )
     107             :     {
     108           0 :         bool bSav_IsInsGlossary = mbInsOnlyTxtGlssry;
     109           0 :         mbInsOnlyTxtGlssry = rBlock.IsOnlyTextBlock( nIdx );
     110             : 
     111           0 :         if( rBlock.BeginGetDoc( nIdx ) )
     112             :         {
     113           0 :             SwDoc* pGDoc = rBlock.GetDoc();
     114             : 
     115             :             // Update all fixed fields, with the right DocInfo.
     116             :             // FIXME: UGLY: Because we cannot limit the range in which to do
     117             :             // field updates, we must update the fixed fields at the glossary
     118             :             // entry document.
     119             :             // To be able to do this, we copy the document properties of the
     120             :             // target document to the glossary document
     121             :             // OSL_ENSURE(GetDocShell(), "no SwDocShell"); // may be clipboard!
     122             :             OSL_ENSURE(pGDoc->GetDocShell(), "no SwDocShell at glossary");
     123           0 :             if (GetDocShell() && pGDoc->GetDocShell()) {
     124             :                 uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
     125           0 :                     GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
     126             :                 uno::Reference<document::XDocumentProperties> xDocProps(
     127           0 :                     xDPS->getDocumentProperties() );
     128             :                 uno::Reference<document::XDocumentPropertiesSupplier> xGlosDPS(
     129           0 :                     pGDoc->GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
     130             :                 uno::Reference<document::XDocumentProperties> xGlosDocProps(
     131           0 :                     xGlosDPS->getDocumentProperties() );
     132           0 :                 lcl_copyDocumentProperties(xDocProps, xGlosDocProps);
     133             :         }
     134           0 :             pGDoc->SetFixFields(false, NULL);
     135             : 
     136             :             // StartAllAction();
     137           0 :             LockExpFlds();
     138             : 
     139           0 :             SwNodeIndex aStt( pGDoc->GetNodes().GetEndOfExtras(), 1 );
     140           0 :             SwCntntNode* pCntntNd = pGDoc->GetNodes().GoNext( &aStt );
     141           0 :             const SwTableNode* pTblNd = pCntntNd->FindTableNode();
     142           0 :             SwPaM aCpyPam( pTblNd ? *(SwNode*)pTblNd : *(SwNode*)pCntntNd );
     143           0 :             aCpyPam.SetMark();
     144             : 
     145             :             // till the nodes array's end
     146           0 :             aCpyPam.GetPoint()->nNode = pGDoc->GetNodes().GetEndOfContent().GetIndex()-1;
     147           0 :             pCntntNd = aCpyPam.GetCntntNode();
     148           0 :             aCpyPam.GetPoint()->nContent.Assign( pCntntNd, pCntntNd->Len() );
     149             : 
     150           0 :             GetIDocumentUndoRedo().StartUndo( UNDO_INSGLOSSARY, NULL );
     151           0 :             SwPaM *_pStartCrsr = &rPaM, *__pStartCrsr = _pStartCrsr;
     152           0 :             do {
     153             : 
     154           0 :                 SwPosition& rInsPos = *_pStartCrsr->GetPoint();
     155           0 :                 SwStartNode* pBoxSttNd = (SwStartNode*)rInsPos.nNode.GetNode().
     156           0 :                                             FindTableBoxStartNode();
     157             : 
     158           0 :                 if( pBoxSttNd && 2 == pBoxSttNd->EndOfSectionIndex() -
     159           0 :                                       pBoxSttNd->GetIndex() &&
     160           0 :                     aCpyPam.GetPoint()->nNode != aCpyPam.GetMark()->nNode )
     161             :                 {
     162             :                     // We copy more than one Node to the current Box.
     163             :                     // However, we have to remove the BoxAttributes then.
     164           0 :                     ClearBoxNumAttrs( rInsPos.nNode );
     165             :                 }
     166             : 
     167           0 :                 SwDontExpandItem aACD;
     168           0 :                 aACD.SaveDontExpandItems( rInsPos );
     169             : 
     170           0 :                 pGDoc->CopyRange( aCpyPam, rInsPos, false );
     171             : 
     172           0 :                 aACD.RestoreDontExpandItems( rInsPos );
     173           0 :                 if( pShell )
     174           0 :                     pShell->SaveTblBoxCntnt( &rInsPos );
     175           0 :             } while( (_pStartCrsr=(SwPaM *)_pStartCrsr->GetNext()) !=
     176             :                         __pStartCrsr );
     177           0 :             GetIDocumentUndoRedo().EndUndo( UNDO_INSGLOSSARY, NULL );
     178             : 
     179           0 :             UnlockExpFlds();
     180           0 :             if( !IsExpFldsLocked() )
     181           0 :                 UpdateExpFlds(NULL, true);
     182           0 :             bRet = true;
     183             :         }
     184           0 :         mbInsOnlyTxtGlssry = bSav_IsInsGlossary;
     185             :     }
     186           0 :     rBlock.EndGetDoc();
     187           0 :     return bRet;
     188             : }
     189             : 
     190             : 
     191             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10