LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/edit - edglbldc.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 208 0.0 %
Date: 2012-12-17 Functions: 0 13 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 <doc.hxx>
      22             : #include <IDocumentUndoRedo.hxx>
      23             : #include <editsh.hxx>
      24             : #include <pam.hxx>
      25             : #include <ndtxt.hxx>
      26             : #include <docary.hxx>
      27             : #include <swwait.hxx>
      28             : #include <swundo.hxx>       // fuer die UndoIds
      29             : #include <section.hxx>
      30             : #include <doctxm.hxx>
      31             : #include <edglbldc.hxx>
      32             : 
      33             : 
      34           0 : sal_Bool SwEditShell::IsGlobalDoc() const
      35             : {
      36           0 :     return getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT);
      37             : }
      38             : 
      39           0 : void SwEditShell::SetGlblDocSaveLinks( sal_Bool bFlag )
      40             : {
      41           0 :     getIDocumentSettingAccess()->set(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS, bFlag);
      42           0 :     if( !GetDoc()->IsModified() )   // Bug 57028
      43             :     {
      44           0 :         GetDoc()->GetIDocumentUndoRedo().SetUndoNoResetModified();
      45             :     }
      46           0 :     GetDoc()->SetModified();
      47           0 : }
      48             : 
      49           0 : sal_Bool SwEditShell::IsGlblDocSaveLinks() const
      50             : {
      51           0 :     return getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT_SAVE_LINKS);
      52             : }
      53             : 
      54           0 : sal_uInt16 SwEditShell::GetGlobalDocContent( SwGlblDocContents& rArr ) const
      55             : {
      56           0 :     rArr.DeleteAndDestroyAll();
      57             : 
      58           0 :     if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
      59           0 :         return 0;
      60             : 
      61             :     // dann alle gelinkten Bereiche auf der obersten Ebene
      62           0 :     SwDoc* pMyDoc = GetDoc();
      63           0 :     const SwSectionFmts& rSectFmts = pMyDoc->GetSections();
      64             :     sal_uInt16 n;
      65             : 
      66           0 :     for( n = rSectFmts.size(); n; )
      67             :     {
      68           0 :         const SwSection* pSect = rSectFmts[ --n ]->GetGlobalDocSection();
      69           0 :         if( pSect )
      70             :         {
      71             :             SwGlblDocContent* pNew;
      72           0 :             switch( pSect->GetType() )
      73             :             {
      74           0 :             case TOX_HEADER_SECTION:    break;      // ignore
      75             :             case TOX_CONTENT_SECTION:
      76             :                 OSL_ENSURE( pSect->ISA( SwTOXBaseSection ), "keine TOXBaseSection!" );
      77           0 :                 pNew = new SwGlblDocContent( (SwTOXBaseSection*)pSect );
      78           0 :                 break;
      79             : 
      80             :             default:
      81           0 :                 pNew = new SwGlblDocContent( pSect );
      82           0 :                 break;
      83             :             }
      84           0 :             if( !rArr.insert( pNew ).second )
      85           0 :                 delete pNew;
      86             :         }
      87             :     }
      88             : 
      89             :     // und als letztes die Dummies (sonstiger Text) einfuegen
      90             :     SwNode* pNd;
      91           0 :     sal_uLong nSttIdx = pMyDoc->GetNodes().GetEndOfExtras().GetIndex() + 2;
      92           0 :     for( n = 0; n < rArr.size(); ++n )
      93             :     {
      94           0 :         const SwGlblDocContent& rNew = *rArr[ n ];
      95             :         // suche von StartPos bis rNew.DocPos nach einem Content Node.
      96             :         // Existiert dieser, so muss ein DummyEintrag eingefuegt werden.
      97           0 :         for( ; nSttIdx < rNew.GetDocPos(); ++nSttIdx )
      98           0 :             if( ( pNd = pMyDoc->GetNodes()[ nSttIdx ])->IsCntntNode()
      99           0 :                 || pNd->IsSectionNode() || pNd->IsTableNode() )
     100             :             {
     101           0 :                 SwGlblDocContent* pNew = new SwGlblDocContent( nSttIdx );
     102           0 :                 if( !rArr.insert( pNew ).second )
     103           0 :                     delete pNew;
     104             :                 else
     105           0 :                     ++n;        // auf die naechste Position
     106             :                 break;
     107             :             }
     108             : 
     109             :         // StartPosition aufs Ende setzen
     110           0 :         nSttIdx = pMyDoc->GetNodes()[ rNew.GetDocPos() ]->EndOfSectionIndex();
     111           0 :         ++nSttIdx;
     112             :     }
     113             : 
     114             :     // sollte man das Ende auch noch setzen??
     115           0 :     if( !rArr.empty() )
     116             :     {
     117           0 :         sal_uLong nNdEnd = pMyDoc->GetNodes().GetEndOfContent().GetIndex();
     118           0 :         for( ; nSttIdx < nNdEnd; ++nSttIdx )
     119           0 :             if( ( pNd = pMyDoc->GetNodes()[ nSttIdx ])->IsCntntNode()
     120           0 :                 || pNd->IsSectionNode() || pNd->IsTableNode() )
     121             :             {
     122           0 :                 SwGlblDocContent* pNew = new SwGlblDocContent( nSttIdx );
     123           0 :                 if( !rArr.insert( pNew ).second )
     124           0 :                     delete pNew;
     125             :                 break;
     126             :             }
     127             :     }
     128             :     else
     129             :     {
     130             :         SwGlblDocContent* pNew = new SwGlblDocContent(
     131           0 :                     pMyDoc->GetNodes().GetEndOfExtras().GetIndex() + 2 );
     132           0 :         rArr.insert( pNew );
     133             :     }
     134           0 :     return rArr.size();
     135             : }
     136             : 
     137           0 : sal_Bool SwEditShell::InsertGlobalDocContent( const SwGlblDocContent& rInsPos,
     138             :         SwSectionData & rNew)
     139             : {
     140           0 :     if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
     141           0 :         return sal_False;
     142             : 
     143           0 :     SET_CURR_SHELL( this );
     144           0 :     StartAllAction();
     145             : 
     146           0 :     SwPaM* pCrsr = GetCrsr();
     147           0 :     if( pCrsr->GetNext() != pCrsr || IsTableMode() )
     148           0 :         ClearMark();
     149             : 
     150           0 :     SwPosition& rPos = *pCrsr->GetPoint();
     151           0 :     rPos.nNode = rInsPos.GetDocPos();
     152             : 
     153           0 :     bool bEndUndo = false;
     154           0 :     SwDoc* pMyDoc = GetDoc();
     155           0 :     SwTxtNode *const pTxtNd = rPos.nNode.GetNode().GetTxtNode();
     156           0 :     if( pTxtNd )
     157           0 :         rPos.nContent.Assign( pTxtNd, 0 );
     158             :     else
     159             :     {
     160           0 :         bEndUndo = true;
     161           0 :         pMyDoc->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
     162           0 :         rPos.nNode--;
     163           0 :         pMyDoc->AppendTxtNode( rPos );
     164           0 :         pCrsr->SetMark();
     165             :     }
     166             : 
     167           0 :     InsertSection( rNew );
     168             : 
     169           0 :     if( bEndUndo )
     170             :     {
     171           0 :         pMyDoc->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
     172             :     }
     173           0 :     EndAllAction();
     174             : 
     175           0 :     return sal_True;
     176             : }
     177             : 
     178           0 : sal_Bool SwEditShell::InsertGlobalDocContent( const SwGlblDocContent& rInsPos,
     179             :                                             const SwTOXBase& rTOX )
     180             : {
     181           0 :     if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
     182           0 :         return sal_False;
     183             : 
     184           0 :     SET_CURR_SHELL( this );
     185           0 :     StartAllAction();
     186             : 
     187           0 :     SwPaM* pCrsr = GetCrsr();
     188           0 :     if( pCrsr->GetNext() != pCrsr || IsTableMode() )
     189           0 :         ClearMark();
     190             : 
     191           0 :     SwPosition& rPos = *pCrsr->GetPoint();
     192           0 :     rPos.nNode = rInsPos.GetDocPos();
     193             : 
     194           0 :     bool bEndUndo = false;
     195           0 :     SwDoc* pMyDoc = GetDoc();
     196           0 :     SwTxtNode* pTxtNd = rPos.nNode.GetNode().GetTxtNode();
     197           0 :     if( pTxtNd && pTxtNd->GetTxt().Len() && rPos.nNode.GetIndex() + 1 !=
     198           0 :         pMyDoc->GetNodes().GetEndOfContent().GetIndex() )
     199           0 :         rPos.nContent.Assign( pTxtNd, 0 );
     200             :     else
     201             :     {
     202           0 :         bEndUndo = true;
     203           0 :         pMyDoc->GetIDocumentUndoRedo().StartUndo( UNDO_START, NULL );
     204           0 :         rPos.nNode--;
     205           0 :         pMyDoc->AppendTxtNode( rPos );
     206             :     }
     207             : 
     208           0 :     InsertTableOf( rTOX );
     209             : 
     210           0 :     if( bEndUndo )
     211             :     {
     212           0 :         pMyDoc->GetIDocumentUndoRedo().EndUndo( UNDO_END, NULL );
     213             :     }
     214           0 :     EndAllAction();
     215             : 
     216           0 :     return sal_True;
     217             : }
     218             : 
     219           0 : sal_Bool SwEditShell::InsertGlobalDocContent( const SwGlblDocContent& rInsPos )
     220             : {
     221           0 :     if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
     222           0 :         return sal_False;
     223             : 
     224           0 :     SET_CURR_SHELL( this );
     225           0 :     StartAllAction();
     226             : 
     227           0 :     SwPaM* pCrsr = GetCrsr();
     228           0 :     if( pCrsr->GetNext() != pCrsr || IsTableMode() )
     229           0 :         ClearMark();
     230             : 
     231           0 :     SwPosition& rPos = *pCrsr->GetPoint();
     232           0 :     rPos.nNode = rInsPos.GetDocPos() - 1;
     233           0 :     rPos.nContent.Assign( 0, 0 );
     234             : 
     235           0 :     SwDoc* pMyDoc = GetDoc();
     236           0 :     pMyDoc->AppendTxtNode( rPos );
     237           0 :     EndAllAction();
     238           0 :     return sal_True;
     239             : }
     240             : 
     241           0 : sal_Bool SwEditShell::DeleteGlobalDocContent( const SwGlblDocContents& rArr ,
     242             :                                             sal_uInt16 nDelPos )
     243             : {
     244           0 :     if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
     245           0 :         return sal_False;
     246             : 
     247           0 :     SET_CURR_SHELL( this );
     248           0 :     StartAllAction();
     249           0 :     StartUndo( UNDO_START );
     250             : 
     251           0 :     SwPaM* pCrsr = GetCrsr();
     252           0 :     if( pCrsr->GetNext() != pCrsr || IsTableMode() )
     253           0 :         ClearMark();
     254             : 
     255           0 :     SwPosition& rPos = *pCrsr->GetPoint();
     256             : 
     257           0 :     SwDoc* pMyDoc = GetDoc();
     258           0 :     const SwGlblDocContent& rDelPos = *rArr[ nDelPos ];
     259           0 :     sal_uLong nDelIdx = rDelPos.GetDocPos();
     260           0 :     if( 1 == rArr.size() )
     261             :     {
     262             :         // ein Node muss aber da bleiben!
     263           0 :         rPos.nNode = nDelIdx - 1;
     264           0 :         rPos.nContent.Assign( 0, 0 );
     265             : 
     266           0 :         pMyDoc->AppendTxtNode( rPos );
     267           0 :         ++nDelIdx;
     268             :     }
     269             : 
     270           0 :     switch( rDelPos.GetType() )
     271             :     {
     272             :     case GLBLDOC_UNKNOWN:
     273             :         {
     274           0 :             rPos.nNode = nDelIdx;
     275           0 :             pCrsr->SetMark();
     276           0 :             if( ++nDelPos < rArr.size() )
     277           0 :                 rPos.nNode = rArr[ nDelPos ]->GetDocPos();
     278             :             else
     279           0 :                 rPos.nNode = pMyDoc->GetNodes().GetEndOfContent();
     280           0 :             rPos.nNode--;
     281           0 :             if( !pMyDoc->DelFullPara( *pCrsr ) )
     282           0 :                 Delete();
     283             :         }
     284           0 :         break;
     285             : 
     286             :     case GLBLDOC_TOXBASE:
     287             :         {
     288           0 :             SwTOXBaseSection* pTOX = (SwTOXBaseSection*)rDelPos.GetTOX();
     289           0 :             pMyDoc->DeleteTOX( *pTOX, true );
     290             :         }
     291           0 :         break;
     292             : 
     293             :     case GLBLDOC_SECTION:
     294             :         {
     295           0 :             SwSectionFmt* pSectFmt = (SwSectionFmt*)rDelPos.GetSection()->GetFmt();
     296           0 :             pMyDoc->DelSectionFmt( pSectFmt, true );
     297             :         }
     298           0 :         break;
     299             :     }
     300             : 
     301           0 :     EndUndo( UNDO_END );
     302           0 :     EndAllAction();
     303           0 :     return sal_True;
     304             : }
     305             : 
     306           0 : sal_Bool SwEditShell::MoveGlobalDocContent( const SwGlblDocContents& rArr ,
     307             :                                         sal_uInt16 nFromPos, sal_uInt16 nToPos,
     308             :                                         sal_uInt16 nInsPos )
     309             : {
     310           0 :     if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) ||
     311           0 :         nFromPos >= rArr.size() || nToPos > rArr.size() ||
     312           0 :         nInsPos > rArr.size() || nFromPos >= nToPos ||
     313             :         ( nFromPos <= nInsPos && nInsPos <= nToPos ) )
     314           0 :         return sal_False;
     315             : 
     316           0 :     SET_CURR_SHELL( this );
     317           0 :     StartAllAction();
     318             : 
     319           0 :     SwPaM* pCrsr = GetCrsr();
     320           0 :     if( pCrsr->GetNext() != pCrsr || IsTableMode() )
     321           0 :         ClearMark();
     322             : 
     323           0 :     SwDoc* pMyDoc = GetDoc();
     324           0 :     SwNodeRange aRg( pMyDoc->GetNodes(), rArr[ nFromPos ]->GetDocPos() );
     325           0 :     if( nToPos < rArr.size() )
     326           0 :         aRg.aEnd = rArr[ nToPos ]->GetDocPos();
     327             :     else
     328           0 :         aRg.aEnd = pMyDoc->GetNodes().GetEndOfContent();
     329             : 
     330           0 :     SwNodeIndex aInsPos( pMyDoc->GetNodes() );
     331           0 :     if( nInsPos < rArr.size() )
     332           0 :         aInsPos = rArr[ nInsPos ]->GetDocPos();
     333             :     else
     334           0 :         aInsPos  = pMyDoc->GetNodes().GetEndOfContent();
     335             : 
     336             :     bool bRet = pMyDoc->MoveNodeRange( aRg, aInsPos,
     337             :         static_cast<IDocumentContentOperations::SwMoveFlags>(
     338             :               IDocumentContentOperations::DOC_MOVEALLFLYS
     339           0 :             | IDocumentContentOperations::DOC_CREATEUNDOOBJ ));
     340             : 
     341           0 :     EndAllAction();
     342           0 :     return bRet;
     343             : }
     344             : 
     345           0 : sal_Bool SwEditShell::GotoGlobalDocContent( const SwGlblDocContent& rPos )
     346             : {
     347           0 :     if( !getIDocumentSettingAccess()->get(IDocumentSettingAccess::GLOBAL_DOCUMENT) )
     348           0 :         return sal_False;
     349             : 
     350           0 :     SET_CURR_SHELL( this );
     351           0 :     SttCrsrMove();
     352             : 
     353           0 :     SwPaM* pCrsr = GetCrsr();
     354           0 :     if( pCrsr->GetNext() != pCrsr || IsTableMode() )
     355           0 :         ClearMark();
     356             : 
     357           0 :     SwPosition& rCrsrPos = *pCrsr->GetPoint();
     358           0 :     rCrsrPos.nNode = rPos.GetDocPos();
     359             : 
     360           0 :     SwDoc* pMyDoc = GetDoc();
     361           0 :     SwCntntNode * pCNd = rCrsrPos.nNode.GetNode().GetCntntNode();
     362           0 :     if( !pCNd )
     363           0 :         pCNd = pMyDoc->GetNodes().GoNext( &rCrsrPos.nNode );
     364             : 
     365           0 :     rCrsrPos.nContent.Assign( pCNd, 0 );
     366             : 
     367           0 :     EndCrsrMove();
     368           0 :     return sal_True;
     369             : }
     370             : 
     371           0 : SwGlblDocContent::SwGlblDocContent( sal_uLong nPos )
     372             : {
     373           0 :     eType = GLBLDOC_UNKNOWN;
     374           0 :     PTR.pTOX = 0;
     375           0 :     nDocPos = nPos;
     376           0 : }
     377             : 
     378           0 : SwGlblDocContent::SwGlblDocContent( const SwTOXBaseSection* pTOX )
     379             : {
     380           0 :     eType = GLBLDOC_TOXBASE;
     381           0 :     PTR.pTOX = pTOX;
     382             : 
     383           0 :     const SwSectionNode* pSectNd = pTOX->GetFmt()->GetSectionNode();
     384           0 :     nDocPos = pSectNd ? pSectNd->GetIndex() : 0;
     385           0 : }
     386             : 
     387           0 : SwGlblDocContent::SwGlblDocContent( const SwSection* pSect )
     388             : {
     389           0 :     eType = GLBLDOC_SECTION;
     390           0 :     PTR.pSect = pSect;
     391             : 
     392           0 :     const SwSectionNode* pSectNd = pSect->GetFmt()->GetSectionNode();
     393           0 :     nDocPos = pSectNd ? pSectNd->GetIndex() : 0;
     394           0 : }
     395             : 
     396             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10