LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/doc - docdde.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 188 0.0 %
Date: 2012-12-17 Functions: 0 9 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 <stdlib.h>
      21             : 
      22             : #include <vcl/svapp.hxx>
      23             : #include <tools/urlobj.hxx>
      24             : 
      25             : #include <sfx2/linkmgr.hxx>         // LinkManager
      26             : #include <unotools/charclass.hxx>
      27             : #include <fmtcntnt.hxx>
      28             : #include <doc.hxx>
      29             : #include <swserv.hxx>           // for server functionality
      30             : #include <IMark.hxx>
      31             : #include <bookmrk.hxx>
      32             : #include <section.hxx>          // for SwSectionFmt
      33             : #include <swtable.hxx>          // for SwTable
      34             : #include <node.hxx>
      35             : #include <ndtxt.hxx>
      36             : #include <pam.hxx>
      37             : #include <docary.hxx>
      38             : #include <MarkManager.hxx>
      39             : #include <boost/foreach.hpp>
      40             : 
      41             : using namespace ::com::sun::star;
      42             : 
      43             : namespace
      44             : {
      45             : 
      46           0 :     static ::sw::mark::DdeBookmark* lcl_FindDdeBookmark(const IDocumentMarkAccess& rMarkAccess, const rtl::OUString& rName, bool bCaseSensitive)
      47             :     {
      48             :         //Iterating over all bookmarks, checking DdeBookmarks
      49           0 :         const ::rtl::OUString sNameLc = bCaseSensitive ? rName : GetAppCharClass().lowercase(rName);
      50           0 :         for(IDocumentMarkAccess::const_iterator_t ppMark = rMarkAccess.getMarksBegin();
      51           0 :             ppMark != rMarkAccess.getMarksEnd();
      52             :             ++ppMark)
      53             :         {
      54           0 :             if (::sw::mark::DdeBookmark* const pBkmk = dynamic_cast< ::sw::mark::DdeBookmark*>(ppMark->get()))
      55             :             {
      56           0 :                 if (
      57           0 :                     (bCaseSensitive && (pBkmk->GetName() == sNameLc)) ||
      58           0 :                     (!bCaseSensitive && GetAppCharClass().lowercase(pBkmk->GetName()) == sNameLc)
      59             :                    )
      60             :                 {
      61           0 :                     return pBkmk;
      62             :                 }
      63             :             }
      64             :         }
      65           0 :         return NULL;
      66             :     }
      67             : }
      68             : 
      69           0 : struct _FindItem
      70             : {
      71             :     const String m_Item;
      72             :     SwTableNode* pTblNd;
      73             :     SwSectionNode* pSectNd;
      74             : 
      75           0 :     _FindItem(const String& rS)
      76           0 :         : m_Item(rS), pTblNd(0), pSectNd(0)
      77           0 :     {}
      78             : };
      79             : 
      80           0 : static bool lcl_FindSection( const SwSectionFmt* pSectFmt, _FindItem * const pItem, bool bCaseSensitive )
      81             : {
      82           0 :     SwSection* pSect = pSectFmt->GetSection();
      83           0 :     if( pSect )
      84             :     {
      85             :         String sNm( (bCaseSensitive)
      86           0 :                 ? pSect->GetSectionName()
      87           0 :                 : String(GetAppCharClass().lowercase( pSect->GetSectionName() )));
      88             :         String sCompare( (bCaseSensitive)
      89             :                 ? pItem->m_Item
      90           0 :                 : String(GetAppCharClass().lowercase( pItem->m_Item ) ));
      91           0 :         if( sNm == sCompare )
      92             :         {
      93             :             // found, so get the data
      94             :             const SwNodeIndex* pIdx;
      95           0 :             if( 0 != (pIdx = pSectFmt->GetCntnt().GetCntntIdx() ) &&
      96           0 :                 &pSectFmt->GetDoc()->GetNodes() == &pIdx->GetNodes() )
      97             :             {
      98             :                 // a table in the normal NodesArr
      99           0 :                 pItem->pSectNd = pIdx->GetNode().GetSectionNode();
     100           0 :                 return false;
     101             :             }
     102             :             // If the name is already correct, but not the rest then we don't have them.
     103             :             // The names are always unique.
     104           0 :         }
     105             :     }
     106           0 :     return true;
     107             : }
     108             : 
     109             : 
     110             : 
     111           0 : static bool lcl_FindTable( const SwFrmFmt* pTableFmt, _FindItem * const pItem )
     112             : {
     113           0 :     String sNm( GetAppCharClass().lowercase( pTableFmt->GetName() ));
     114           0 :     if (sNm.Equals( pItem->m_Item ))
     115             :     {
     116             :         SwTable* pTmpTbl;
     117             :         SwTableBox* pFBox;
     118           0 :         if( 0 != ( pTmpTbl = SwTable::FindTable( pTableFmt ) ) &&
     119           0 :             0 != ( pFBox = pTmpTbl->GetTabSortBoxes()[0] ) &&
     120           0 :             pFBox->GetSttNd() &&
     121           0 :             &pTableFmt->GetDoc()->GetNodes() == &pFBox->GetSttNd()->GetNodes() )
     122             :         {
     123             :             // a table in the normal NodesArr
     124             :             pItem->pTblNd = (SwTableNode*)
     125           0 :                                         pFBox->GetSttNd()->FindTableNode();
     126           0 :             return false;
     127             :         }
     128             :         // If the name is already correct, but not the rest then we don't have them.
     129             :         // The names are always unique.
     130             :     }
     131           0 :     return true;
     132             : }
     133             : 
     134             : 
     135             : 
     136           0 : bool SwDoc::GetData( const rtl::OUString& rItem, const String& rMimeType,
     137             :                      uno::Any & rValue ) const
     138             : {
     139             :     // search for bookmarks and sections case senstive at first. If nothing is found then try again case insensitive
     140           0 :     bool bCaseSensitive = true;
     141           0 :     while( true )
     142             :     {
     143           0 :         ::sw::mark::DdeBookmark* const pBkmk = lcl_FindDdeBookmark(*pMarkManager, rItem, bCaseSensitive);
     144           0 :         if(pBkmk)
     145           0 :             return SwServerObject(*pBkmk).GetData(rValue, rMimeType);
     146             : 
     147             :         // Do we already have the Item?
     148           0 :         String sItem( bCaseSensitive ? rItem : GetAppCharClass().lowercase(rItem));
     149           0 :         _FindItem aPara( sItem );
     150           0 :         BOOST_FOREACH( const SwSectionFmt* pFmt, *pSectionFmtTbl )
     151             :         {
     152           0 :             if (!(lcl_FindSection(pFmt, &aPara, bCaseSensitive)))
     153           0 :                 break;
     154             :         }
     155           0 :         if( aPara.pSectNd )
     156             :         {
     157             :             // found, so get the data
     158           0 :             return SwServerObject( *aPara.pSectNd ).GetData( rValue, rMimeType );
     159             :         }
     160           0 :         if( !bCaseSensitive )
     161             :             break;
     162           0 :         bCaseSensitive = false;
     163           0 :     }
     164             : 
     165           0 :     _FindItem aPara( GetAppCharClass().lowercase( rItem ));
     166           0 :     BOOST_FOREACH( const SwFrmFmt* pFmt, *pTblFrmFmtTbl )
     167             :     {
     168           0 :         if (!(lcl_FindTable(pFmt, &aPara)))
     169           0 :             break;
     170             :     }
     171           0 :     if( aPara.pTblNd )
     172             :     {
     173           0 :         return SwServerObject( *aPara.pTblNd ).GetData( rValue, rMimeType );
     174             :     }
     175             : 
     176           0 :     return sal_False;
     177             : }
     178             : 
     179             : 
     180             : 
     181           0 : bool SwDoc::SetData( const rtl::OUString& rItem, const String& rMimeType,
     182             :                      const uno::Any & rValue )
     183             : {
     184             :     // search for bookmarks and sections case senstive at first. If nothing is found then try again case insensitive
     185           0 :     bool bCaseSensitive = true;
     186           0 :     while( true )
     187             :     {
     188           0 :         ::sw::mark::DdeBookmark* const pBkmk = lcl_FindDdeBookmark(*pMarkManager, rItem, bCaseSensitive);
     189           0 :         if(pBkmk)
     190           0 :             return SwServerObject(*pBkmk).SetData(rMimeType, rValue);
     191             : 
     192             :         // Do we already have the Item?
     193           0 :         String sItem( bCaseSensitive ? rItem : GetAppCharClass().lowercase(rItem));
     194           0 :         _FindItem aPara( sItem );
     195           0 :         BOOST_FOREACH( const SwSectionFmt* pFmt, *pSectionFmtTbl )
     196             :         {
     197           0 :             if (!(lcl_FindSection(pFmt, &aPara, bCaseSensitive)))
     198           0 :                 break;
     199             :         }
     200           0 :         if( aPara.pSectNd )
     201             :         {
     202             :             // found, so get the data
     203           0 :             return SwServerObject( *aPara.pSectNd ).SetData( rMimeType, rValue );
     204             :         }
     205           0 :         if( !bCaseSensitive )
     206             :             break;
     207           0 :         bCaseSensitive = false;
     208           0 :     }
     209             : 
     210           0 :     String sItem(GetAppCharClass().lowercase(rItem));
     211           0 :     _FindItem aPara( sItem );
     212           0 :     BOOST_FOREACH( const SwFrmFmt* pFmt, *pTblFrmFmtTbl )
     213             :     {
     214           0 :         if (!(lcl_FindTable(pFmt, &aPara)))
     215           0 :             break;
     216             :     }
     217           0 :     if( aPara.pTblNd )
     218             :     {
     219           0 :         return SwServerObject( *aPara.pTblNd ).SetData( rMimeType, rValue );
     220             :     }
     221             : 
     222           0 :     return sal_False;
     223             : }
     224             : 
     225             : 
     226             : 
     227           0 : ::sfx2::SvLinkSource* SwDoc::CreateLinkSource(const rtl::OUString& rItem)
     228             : {
     229           0 :     SwServerObject* pObj = NULL;
     230             : 
     231             :     // search for bookmarks and sections case senstive at first. If nothing is found then try again case insensitive
     232           0 :     bool bCaseSensitive = true;
     233           0 :     while( true )
     234             :     {
     235             :         // bookmarks
     236           0 :         ::sw::mark::DdeBookmark* const pBkmk = lcl_FindDdeBookmark(*pMarkManager, rItem, bCaseSensitive);
     237           0 :         if(pBkmk && pBkmk->IsExpanded()
     238             :             && (0 == (pObj = pBkmk->GetRefObject())))
     239             :         {
     240             :             // mark found, but no link yet -> create hotlink
     241           0 :             pObj = new SwServerObject(*pBkmk);
     242           0 :             pBkmk->SetRefObject(pObj);
     243           0 :             GetLinkManager().InsertServer(pObj);
     244             :         }
     245           0 :         if(pObj)
     246           0 :             return pObj;
     247             : 
     248           0 :         _FindItem aPara(bCaseSensitive ? rItem : GetAppCharClass().lowercase(rItem));
     249             :         // sections
     250           0 :         BOOST_FOREACH( const SwSectionFmt* pFmt, *pSectionFmtTbl )
     251             :         {
     252           0 :             if (!(lcl_FindSection(pFmt, &aPara, bCaseSensitive)))
     253           0 :                 break;
     254             :         }
     255             : 
     256           0 :         if(aPara.pSectNd
     257           0 :             && (0 == (pObj = aPara.pSectNd->GetSection().GetObject())))
     258             :         {
     259             :             // section found, but no link yet -> create hotlink
     260           0 :             pObj = new SwServerObject( *aPara.pSectNd );
     261           0 :             aPara.pSectNd->GetSection().SetRefObject( pObj );
     262           0 :             GetLinkManager().InsertServer(pObj);
     263             :         }
     264           0 :         if(pObj)
     265           0 :             return pObj;
     266           0 :         if( !bCaseSensitive )
     267             :             break;
     268           0 :         bCaseSensitive = false;
     269           0 :     }
     270             : 
     271           0 :     _FindItem aPara( GetAppCharClass().lowercase(rItem) );
     272             :     // tables
     273           0 :     BOOST_FOREACH( const SwFrmFmt* pFmt, *pTblFrmFmtTbl )
     274             :     {
     275           0 :         if (!(lcl_FindTable(pFmt, &aPara)))
     276           0 :             break;
     277             :     }
     278           0 :     if(aPara.pTblNd
     279           0 :         && (0 == (pObj = aPara.pTblNd->GetTable().GetObject())))
     280             :     {
     281             :         // table found, but no link yet -> create hotlink
     282           0 :         pObj = new SwServerObject(*aPara.pTblNd);
     283           0 :         aPara.pTblNd->GetTable().SetRefObject(pObj);
     284           0 :         GetLinkManager().InsertServer(pObj);
     285             :     }
     286           0 :     return pObj;
     287             : }
     288             : 
     289           0 : bool SwDoc::SelectServerObj( const String& rStr, SwPaM*& rpPam,
     290             :                             SwNodeRange*& rpRange ) const
     291             : {
     292             :     // Do we actually have the Item?
     293           0 :     rpPam = 0;
     294           0 :     rpRange = 0;
     295             : 
     296             :     String sItem( INetURLObject::decode( rStr, INET_HEX_ESCAPE,
     297             :                                          INetURLObject::DECODE_WITH_CHARSET,
     298           0 :                                         RTL_TEXTENCODING_UTF8 ));
     299             : 
     300           0 :     xub_StrLen nPos = sItem.Search( cMarkSeperator );
     301             : 
     302           0 :     const CharClass& rCC = GetAppCharClass();
     303             : 
     304             :     // Extension for sections: not only link bookmarks/sections
     305             :     // but also frames (text!), tables, outlines:
     306           0 :     if( STRING_NOTFOUND != nPos )
     307             :     {
     308           0 :         bool bWeiter = false;
     309           0 :         String sName( sItem.Copy( 0, nPos ) );
     310           0 :         String sCmp( sItem.Copy( nPos + 1 ));
     311           0 :         sItem = rCC.lowercase( sItem );
     312             : 
     313           0 :         _FindItem aPara( sName );
     314             : 
     315           0 :         if( sCmp.EqualsAscii( pMarkToTable ) )
     316             :         {
     317           0 :             sName = rCC.lowercase( sName );
     318           0 :             BOOST_FOREACH( const SwFrmFmt* pFmt, *pTblFrmFmtTbl )
     319             :             {
     320           0 :                 if (!(lcl_FindTable(pFmt, &aPara)))
     321           0 :                     break;
     322             :             }
     323           0 :             if( aPara.pTblNd )
     324             :             {
     325             :                 rpRange = new SwNodeRange( *aPara.pTblNd, 0,
     326           0 :                                 *aPara.pTblNd->EndOfSectionNode(), 1 );
     327           0 :                 return true;
     328             :             }
     329             :         }
     330           0 :         else if( sCmp.EqualsAscii( pMarkToFrame ) )
     331             :         {
     332             :             SwNodeIndex* pIdx;
     333             :             SwNode* pNd;
     334           0 :             const SwFlyFrmFmt* pFlyFmt = FindFlyByName( sName );
     335           0 :             if( pFlyFmt &&
     336           0 :                 0 != ( pIdx = (SwNodeIndex*)pFlyFmt->GetCntnt().GetCntntIdx() ) &&
     337           0 :                 !( pNd = &pIdx->GetNode())->IsNoTxtNode() )
     338             :             {
     339           0 :                 rpRange = new SwNodeRange( *pNd, 1, *pNd->EndOfSectionNode() );
     340           0 :                 return true;
     341             :             }
     342             :         }
     343           0 :         else if( sCmp.EqualsAscii( pMarkToRegion ) )
     344             :         {
     345           0 :             sItem = sName;              // Is being dealt with further down!
     346           0 :             bWeiter = true;
     347             :         }
     348           0 :         else if( sCmp.EqualsAscii( pMarkToOutline ) )
     349             :         {
     350           0 :             SwPosition aPos( SwNodeIndex( (SwNodes&)GetNodes() ));
     351           0 :             if( GotoOutline( aPos, sName ))
     352             :             {
     353           0 :                 SwNode* pNd = &aPos.nNode.GetNode();
     354             :                 //sal_uInt8 nLvl = pNd->GetTxtNode()->GetTxtColl()->GetOutlineLevel();//#outline level,zhaojianwei
     355           0 :                 const int nLvl = pNd->GetTxtNode()->GetAttrOutlineLevel()-1;//<-end,zhaojianwei
     356             : 
     357           0 :                 const SwOutlineNodes& rOutlNds = GetNodes().GetOutLineNds();
     358             :                 sal_uInt16 nTmpPos;
     359           0 :                 rOutlNds.Seek_Entry( pNd, &nTmpPos );
     360           0 :                 rpRange = new SwNodeRange( aPos.nNode, 0, aPos.nNode );
     361             : 
     362             :                 // look for the section's end, now
     363           0 :                 for( ++nTmpPos;
     364           0 :                         nTmpPos < rOutlNds.size() &&
     365           0 :                         nLvl < rOutlNds[ nTmpPos ]->GetTxtNode()->
     366             :                                 //GetTxtColl()->GetOutlineLevel();//#outline level,zhaojianwei
     367           0 :                                 GetAttrOutlineLevel()-1;//<-end,zhaojianwei
     368             :                     ++nTmpPos )
     369             :                     ;       // there is no block
     370             : 
     371           0 :                 if( nTmpPos < rOutlNds.size() )
     372           0 :                     rpRange->aEnd = *rOutlNds[ nTmpPos ];
     373             :                 else
     374           0 :                     rpRange->aEnd = GetNodes().GetEndOfContent();
     375           0 :                 return true;
     376           0 :             }
     377             :         }
     378             : 
     379           0 :         if( !bWeiter )
     380           0 :             return false;
     381             :     }
     382             : 
     383             :     // search for bookmarks and sections case senstive at first. If nothing is found then try again case insensitive
     384           0 :     bool bCaseSensitive = true;
     385           0 :     while( true )
     386             :     {
     387           0 :         ::sw::mark::DdeBookmark* const pBkmk = lcl_FindDdeBookmark(*pMarkManager, sItem, bCaseSensitive);
     388           0 :         if(pBkmk)
     389             :         {
     390           0 :             if(pBkmk->IsExpanded())
     391             :                 rpPam = new SwPaM(
     392           0 :                     pBkmk->GetMarkPos(),
     393           0 :                     pBkmk->GetOtherMarkPos());
     394           0 :             return static_cast<bool>(rpPam);
     395             :         }
     396             : 
     397             :         //
     398           0 :         _FindItem aPara( bCaseSensitive ? sItem : String(rCC.lowercase( sItem )) );
     399             : 
     400           0 :         if( !pSectionFmtTbl->empty() )
     401             :         {
     402           0 :             BOOST_FOREACH( const SwSectionFmt* pFmt, *pSectionFmtTbl )
     403             :             {
     404           0 :                 if (!(lcl_FindSection(pFmt, &aPara, bCaseSensitive)))
     405           0 :                     break;
     406             :             }
     407           0 :             if( aPara.pSectNd )
     408             :             {
     409             :                 rpRange = new SwNodeRange( *aPara.pSectNd, 1,
     410           0 :                                         *aPara.pSectNd->EndOfSectionNode() );
     411           0 :                 return true;
     412             : 
     413             :             }
     414             :         }
     415           0 :         if( !bCaseSensitive )
     416             :             break;
     417           0 :         bCaseSensitive = false;
     418           0 :     }
     419           0 :     return false;
     420             : }
     421             : 
     422             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10