LCOV - code coverage report
Current view: top level - sw/source/core/tox - ToxLinkProcessor.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 24 25 96.0 %
Date: 2014-11-03 Functions: 6 6 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             : 
      10             : #include "ToxLinkProcessor.hxx"
      11             : 
      12             : #include "SwStyleNameMapper.hxx"
      13             : #include "ndtxt.hxx"
      14             : 
      15             : #include <boost/foreach.hpp>
      16             : #include <stdexcept>
      17             : 
      18             : namespace sw {
      19             : 
      20             : void
      21          18 : ToxLinkProcessor::StartNewLink(sal_Int32 startPosition, const OUString& characterStyle)
      22             : {
      23          18 :     mStartedLinks.push_back(new StartedLink(startPosition, characterStyle));
      24          18 : }
      25             : 
      26             : void
      27          20 : ToxLinkProcessor::CloseLink(sal_Int32 endPosition, const OUString& url)
      28             : {
      29          20 :     if (mStartedLinks.empty()) {
      30           2 :         throw std::runtime_error("ToxLinkProcessor: More calls for CloseLink() than open links exist.");
      31             :     }
      32          18 :     StartedLink startedLink = mStartedLinks.back();
      33          18 :     mStartedLinks.pop_back();
      34             : 
      35          18 :     if (url.isEmpty()) {
      36          18 :         return;
      37             :     }
      38             : 
      39          18 :     ClosedLink* closedLink = new ClosedLink(url, startedLink.mStartPosition, endPosition);
      40             : 
      41          18 :     const OUString& characterStyle = startedLink.mCharacterStyle;
      42          18 :     sal_uInt16 poolId = ObtainPoolId(characterStyle);
      43          18 :     closedLink->mINetFmt.SetVisitedFmtAndId(characterStyle, poolId);
      44          18 :     closedLink->mINetFmt.SetINetFmtAndId(characterStyle, poolId);
      45             : 
      46          18 :     mClosedLinks.push_back(closedLink);
      47             : }
      48             : 
      49             : sal_uInt16
      50          12 : ToxLinkProcessor::ObtainPoolId(const OUString& characterStyle) const
      51             : {
      52          12 :     if (characterStyle.isEmpty()) {
      53           0 :         return USHRT_MAX;
      54             :     }
      55             :     else {
      56          12 :         return SwStyleNameMapper::GetPoolIdFromUIName(characterStyle, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT);
      57             :     }
      58             : }
      59             : 
      60             : 
      61             : void
      62           8 : ToxLinkProcessor::InsertLinkAttributes(SwTxtNode& node)
      63             : {
      64          14 :     BOOST_FOREACH(ClosedLink& clink, mClosedLinks) {
      65           6 :         node.InsertItem(clink.mINetFmt, clink.mStartTextPos, clink.mEndTextPos);
      66             :     }
      67           8 : }
      68             : 
      69         270 : }
      70             : 
      71             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10