LCOV - code coverage report
Current view: top level - sw/source/core/fields - macrofld.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 88 0.0 %
Date: 2014-04-14 Functions: 0 17 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 <hintids.hxx>
      21             : #include <doc.hxx>
      22             : #include <docufld.hxx>
      23             : #include <unofldmid.h>
      24             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      25             : #include <com/sun/star/uri/UriReferenceFactory.hpp>
      26             : #include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
      27             : #include <comphelper/processfactory.hxx>
      28             : 
      29             : using namespace ::com::sun::star;
      30             : 
      31           0 : SwMacroFieldType::SwMacroFieldType(SwDoc* pDocument)
      32             :     : SwFieldType( RES_MACROFLD ),
      33           0 :       pDoc(pDocument)
      34             : {
      35           0 : }
      36             : 
      37           0 : SwFieldType* SwMacroFieldType::Copy() const
      38             : {
      39           0 :     SwMacroFieldType* pType = new SwMacroFieldType(pDoc);
      40           0 :     return pType;
      41             : }
      42             : 
      43           0 : SwMacroField::SwMacroField(SwMacroFieldType* pInitType,
      44             :                            const OUString& rLibAndName, const OUString& rTxt) :
      45           0 :     SwField(pInitType), aMacro(rLibAndName), aText(rTxt), bIsScriptURL(sal_False)
      46             : {
      47           0 :     bIsScriptURL = isScriptURL(aMacro);
      48           0 : }
      49             : 
      50           0 : OUString SwMacroField::Expand() const
      51             : {
      52           0 :     return aText ;
      53             : }
      54             : 
      55           0 : SwField* SwMacroField::Copy() const
      56             : {
      57           0 :     return new SwMacroField((SwMacroFieldType*)GetTyp(), aMacro, aText);
      58             : }
      59             : 
      60           0 : OUString SwMacroField::GetFieldName() const
      61             : {
      62           0 :     return GetTyp()->GetName() + " " + aMacro;
      63             : }
      64             : 
      65           0 : OUString SwMacroField::GetLibName() const
      66             : {
      67             :     // if it is a Scripting Framework macro return an empty string
      68           0 :     if (bIsScriptURL)
      69             :     {
      70           0 :         return OUString();
      71             :     }
      72             : 
      73           0 :     if (!aMacro.isEmpty())
      74             :     {
      75           0 :         sal_Int32 nPos = aMacro.getLength();
      76             : 
      77           0 :         for (sal_Int32 i = 0; i < 3 && nPos > 0; i++)
      78           0 :             while (aMacro[--nPos] != '.' && nPos > 0) ;
      79             : 
      80           0 :         return aMacro.copy(0, nPos);
      81             :     }
      82             : 
      83             :     OSL_FAIL("No LibName");
      84           0 :     return OUString();
      85             : }
      86             : 
      87           0 : OUString SwMacroField::GetMacroName() const
      88             : {
      89           0 :     if (!aMacro.isEmpty())
      90             :     {
      91           0 :         if (bIsScriptURL)
      92             :         {
      93           0 :             return aMacro;
      94             :         }
      95             :         else
      96             :         {
      97           0 :             sal_Int32 nPos = aMacro.getLength();
      98             : 
      99           0 :             for (sal_Int32 i = 0; i < 3 && nPos > 0; i++)
     100           0 :                 while (aMacro[--nPos] != '.' && nPos > 0) ;
     101             : 
     102           0 :             return aMacro.copy( ++nPos );
     103             :         }
     104             :     }
     105             : 
     106             :     OSL_FAIL("No MacroName");
     107           0 :     return OUString();
     108             : }
     109             : 
     110           0 : SvxMacro SwMacroField::GetSvxMacro() const
     111             : {
     112           0 :     if (bIsScriptURL)
     113             :     {
     114           0 :         return SvxMacro(aMacro, OUString(), EXTENDED_STYPE);
     115             :     }
     116             :     else
     117             :     {
     118           0 :         return SvxMacro(GetMacroName(), GetLibName(), STARBASIC);
     119             :     }
     120             : }
     121             : 
     122             : /// LibName and MacroName
     123           0 : void SwMacroField::SetPar1(const OUString& rStr)
     124             : {
     125           0 :     aMacro = rStr;
     126           0 :     bIsScriptURL = isScriptURL(aMacro);
     127           0 : }
     128             : 
     129             : /// Get macro
     130           0 : OUString SwMacroField::GetPar1() const
     131             : {
     132           0 :     return aMacro;
     133             : }
     134             : 
     135             : /// set macro text
     136           0 : void SwMacroField::SetPar2(const OUString& rStr)
     137             : {
     138           0 :     aText = rStr;
     139           0 : }
     140             : 
     141             : /// get macro text
     142           0 : OUString SwMacroField::GetPar2() const
     143             : {
     144           0 :     return aText;
     145             : }
     146             : 
     147           0 : bool SwMacroField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     148             : {
     149           0 :     switch( nWhichId )
     150             :     {
     151             :     case FIELD_PROP_PAR1:
     152           0 :         rAny <<= GetMacroName();
     153           0 :         break;
     154             :     case FIELD_PROP_PAR2:
     155           0 :         rAny <<= aText;
     156           0 :         break;
     157             :     case FIELD_PROP_PAR3:
     158           0 :         rAny <<= GetLibName();
     159           0 :         break;
     160             :     case FIELD_PROP_PAR4:
     161           0 :         rAny <<= bIsScriptURL ? GetMacroName() : OUString();
     162           0 :         break;
     163             :     default:
     164             :         OSL_FAIL("illegal property");
     165             :     }
     166           0 :     return true;
     167             : }
     168             : 
     169           0 : bool SwMacroField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     170             : {
     171           0 :     OUString sTmp;
     172           0 :     switch( nWhichId )
     173             :     {
     174             :     case FIELD_PROP_PAR1:
     175           0 :         rAny >>= sTmp;
     176           0 :         CreateMacroString( aMacro, sTmp, GetLibName());
     177           0 :         break;
     178             :     case FIELD_PROP_PAR2:
     179           0 :         rAny >>= aText;
     180           0 :         break;
     181             :     case FIELD_PROP_PAR3:
     182           0 :         rAny >>= sTmp;
     183           0 :         CreateMacroString(aMacro, GetMacroName(), sTmp );
     184           0 :         break;
     185             :     case FIELD_PROP_PAR4:
     186           0 :         rAny >>= aMacro;
     187           0 :         bIsScriptURL = isScriptURL(aMacro);
     188           0 :         break;
     189             :     default:
     190             :         OSL_FAIL("illegal property");
     191             :     }
     192             : 
     193           0 :     return true;
     194             : }
     195             : 
     196             : /// create an internally used macro name from the library and macro name parts
     197           0 : void SwMacroField::CreateMacroString(
     198             :     OUString& rMacro,
     199             :     const OUString& rMacroName,
     200             :     const OUString& rLibraryName )
     201             : {
     202             :     // concatenate library and name; use dot only if both strings have content
     203           0 :     rMacro = rLibraryName;
     204           0 :     if ( !rLibraryName.isEmpty() && !rMacroName.isEmpty() )
     205           0 :         rMacro += OUString('.');
     206           0 :     rMacro += rMacroName;
     207           0 : }
     208             : 
     209           0 : sal_Bool SwMacroField::isScriptURL( const OUString& str )
     210             : {
     211             :     uno::Reference< uno::XComponentContext > xContext =
     212           0 :         ::comphelper::getProcessComponentContext();
     213             : 
     214             :     uno::Reference< uri::XUriReferenceFactory >
     215           0 :         xFactory = uri::UriReferenceFactory::create( xContext );
     216             : 
     217             :     uno::Reference< uri::XVndSunStarScriptUrl >
     218           0 :         xUrl( xFactory->parse( str ), uno::UNO_QUERY );
     219             : 
     220           0 :     if ( xUrl.is() )
     221             :     {
     222           0 :         return sal_True;
     223             :     }
     224           0 :     return sal_False;
     225             : }
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10