LCOV - code coverage report
Current view: top level - sw/source/core/fields - macrofld.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 94 3.2 %
Date: 2012-08-25 Functions: 1 17 5.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 166 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <hintids.hxx>
      31                 :            : #include <doc.hxx>
      32                 :            : #include <docufld.hxx>
      33                 :            : #include <unofldmid.h>
      34                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      35                 :            : #include <com/sun/star/uri/XUriReferenceFactory.hpp>
      36                 :            : #include <com/sun/star/uri/XVndSunStarScriptUrl.hpp>
      37                 :            : #include <comphelper/processfactory.hxx>
      38                 :            : 
      39                 :            : 
      40                 :            : using namespace ::com::sun::star;
      41                 :            : using ::rtl::OUString;
      42                 :            : 
      43                 :            : /*--------------------------------------------------------------------
      44                 :            :     Beschreibung: MacroFeldtypen
      45                 :            :  --------------------------------------------------------------------*/
      46                 :            : 
      47                 :       1549 : SwMacroFieldType::SwMacroFieldType(SwDoc* pDocument)
      48                 :            :     : SwFieldType( RES_MACROFLD ),
      49                 :       1549 :       pDoc(pDocument)
      50                 :            : {
      51                 :       1549 : }
      52                 :            : 
      53                 :          0 : SwFieldType* SwMacroFieldType::Copy() const
      54                 :            : {
      55         [ #  # ]:          0 :     SwMacroFieldType* pType = new SwMacroFieldType(pDoc);
      56                 :          0 :     return pType;
      57                 :            : }
      58                 :            : 
      59                 :            : /*--------------------------------------------------------------------
      60                 :            :     Beschreibung: Das Macrofeld selbst
      61                 :            :  --------------------------------------------------------------------*/
      62                 :            : 
      63                 :          0 : SwMacroField::SwMacroField(SwMacroFieldType* pInitType,
      64                 :            :                            const String& rLibAndName, const String& rTxt) :
      65 [ #  # ][ #  # ]:          0 :     SwField(pInitType), aMacro(rLibAndName), aText(rTxt), bIsScriptURL(sal_False)
      66                 :            : {
      67 [ #  # ][ #  # ]:          0 :     bIsScriptURL = isScriptURL(aMacro);
                 [ #  # ]
      68                 :          0 : }
      69                 :            : 
      70                 :          0 : String SwMacroField::Expand() const
      71                 :            : {   // Button malen anstatt von
      72                 :          0 :     return aText ;
      73                 :            : }
      74                 :            : 
      75                 :          0 : SwField* SwMacroField::Copy() const
      76                 :            : {
      77 [ #  # ][ #  # ]:          0 :     return new SwMacroField((SwMacroFieldType*)GetTyp(), aMacro, aText);
         [ #  # ][ #  # ]
      78                 :            : }
      79                 :            : 
      80                 :          0 : String SwMacroField::GetFieldName() const
      81                 :            : {
      82                 :          0 :     String aStr(GetTyp()->GetName());
      83         [ #  # ]:          0 :     aStr += ' ';
      84         [ #  # ]:          0 :     aStr += aMacro;
      85                 :          0 :     return aStr;
      86                 :            : }
      87                 :            : 
      88                 :          0 : String SwMacroField::GetLibName() const
      89                 :            : {
      90                 :            :     // if it is a Scripting Framework macro return an empty string
      91         [ #  # ]:          0 :     if (bIsScriptURL)
      92                 :            :     {
      93                 :          0 :         return String();
      94                 :            :     }
      95                 :            : 
      96         [ #  # ]:          0 :     if (!aMacro.isEmpty())
      97                 :            :     {
      98                 :          0 :         sal_Int32 nPos = aMacro.getLength();
      99                 :            : 
     100 [ #  # ][ #  # ]:          0 :         for (sal_Int32 i = 0; i < 3 && nPos > 0; i++)
                 [ #  # ]
     101 [ #  # ][ #  # ]:          0 :             while (aMacro[--nPos] != '.' && nPos > 0) ;
                 [ #  # ]
     102                 :            : 
     103         [ #  # ]:          0 :         return aMacro.copy(0, nPos);
     104                 :            :     }
     105                 :            : 
     106                 :            :     OSL_FAIL("Kein Macroname vorhanden");
     107                 :          0 :     return aEmptyStr;
     108                 :            : }
     109                 :            : 
     110                 :          0 : String SwMacroField::GetMacroName() const
     111                 :            : {
     112         [ #  # ]:          0 :     if (!aMacro.isEmpty())
     113                 :            :     {
     114         [ #  # ]:          0 :         if (bIsScriptURL)
     115                 :            :         {
     116                 :          0 :             return aMacro;
     117                 :            :         }
     118                 :            :         else
     119                 :            :         {
     120                 :          0 :             sal_Int32 nPos = aMacro.getLength();
     121                 :            : 
     122 [ #  # ][ #  # ]:          0 :             for (sal_Int32 i = 0; i < 3 && nPos > 0; i++)
                 [ #  # ]
     123 [ #  # ][ #  # ]:          0 :                 while (aMacro[--nPos] != '.' && nPos > 0) ;
                 [ #  # ]
     124                 :            : 
     125         [ #  # ]:          0 :             return aMacro.copy( ++nPos );
     126                 :            :         }
     127                 :            :     }
     128                 :            : 
     129                 :            :     OSL_FAIL("Kein Macroname vorhanden");
     130                 :          0 :     return aEmptyStr;
     131                 :            : }
     132                 :            : 
     133                 :          0 : SvxMacro SwMacroField::GetSvxMacro() const
     134                 :            : {
     135         [ #  # ]:          0 :   if (bIsScriptURL)
     136                 :            :     {
     137 [ #  # ][ #  # ]:          0 :         return SvxMacro(aMacro, String(), EXTENDED_STYPE);
     138                 :            :     }
     139                 :            :     else
     140                 :            :     {
     141 [ #  # ][ #  # ]:          0 :         return SvxMacro(GetMacroName(), GetLibName(), STARBASIC);
         [ #  # ][ #  # ]
                 [ #  # ]
     142                 :            :     }
     143                 :            : }
     144                 :            : 
     145                 :            : /*--------------------------------------------------------------------
     146                 :            :     Beschreibung: LibName und MacroName
     147                 :            :  --------------------------------------------------------------------*/
     148                 :            : 
     149                 :          0 : void SwMacroField::SetPar1(const rtl::OUString& rStr)
     150                 :            : {
     151                 :          0 :     aMacro = rStr;
     152         [ #  # ]:          0 :     bIsScriptURL = isScriptURL(aMacro);
     153                 :          0 : }
     154                 :            : 
     155                 :          0 : const rtl::OUString& SwMacroField::GetPar1() const
     156                 :            : {
     157                 :          0 :     return aMacro;
     158                 :            : }
     159                 :            : 
     160                 :            : /*--------------------------------------------------------------------
     161                 :            :     Beschreibung: Macrotext
     162                 :            :  --------------------------------------------------------------------*/
     163                 :            : 
     164                 :          0 : void SwMacroField::SetPar2(const rtl::OUString& rStr)
     165                 :            : {
     166                 :          0 :     aText = rStr;
     167                 :          0 : }
     168                 :            : 
     169                 :          0 : rtl::OUString SwMacroField::GetPar2() const
     170                 :            : {
     171                 :          0 :     return aText;
     172                 :            : }
     173                 :            : 
     174                 :          0 : bool SwMacroField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     175                 :            : {
     176   [ #  #  #  #  :          0 :     switch( nWhichId )
                      # ]
     177                 :            :     {
     178                 :            :     case FIELD_PROP_PAR1:
     179 [ #  # ][ #  # ]:          0 :         rAny <<= OUString(GetMacroName());
     180                 :          0 :         break;
     181                 :            :     case FIELD_PROP_PAR2:
     182         [ #  # ]:          0 :         rAny <<= OUString(aText);
     183                 :          0 :         break;
     184                 :            :     case FIELD_PROP_PAR3:
     185 [ #  # ][ #  # ]:          0 :         rAny <<= OUString(GetLibName());
     186                 :          0 :         break;
     187                 :            :     case FIELD_PROP_PAR4:
     188 [ #  # ][ #  # ]:          0 :         rAny <<= bIsScriptURL ? OUString(GetMacroName()): OUString();
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     189                 :          0 :         break;
     190                 :            :     default:
     191                 :            :         OSL_FAIL("illegal property");
     192                 :            :     }
     193                 :          0 :     return true;
     194                 :            : }
     195                 :            : 
     196                 :          0 : bool SwMacroField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     197                 :            : {
     198                 :          0 :     rtl::OUString sTmp;
     199   [ #  #  #  #  :          0 :     switch( nWhichId )
                      # ]
     200                 :            :     {
     201                 :            :     case FIELD_PROP_PAR1:
     202                 :          0 :         rAny >>= sTmp;
     203 [ #  # ][ #  # ]:          0 :         CreateMacroString( aMacro, sTmp, GetLibName());
         [ #  # ][ #  # ]
                 [ #  # ]
     204                 :          0 :         break;
     205                 :            :     case FIELD_PROP_PAR2:
     206                 :          0 :         rAny >>= aText;
     207                 :          0 :         break;
     208                 :            :     case FIELD_PROP_PAR3:
     209                 :          0 :         rAny >>= sTmp;
     210 [ #  # ][ #  # ]:          0 :         CreateMacroString(aMacro, GetMacroName(), sTmp );
         [ #  # ][ #  # ]
                 [ #  # ]
     211                 :          0 :         break;
     212                 :            :     case FIELD_PROP_PAR4:
     213                 :          0 :         rAny >>= aMacro;
     214 [ #  # ][ #  # ]:          0 :         bIsScriptURL = isScriptURL(aMacro);
                 [ #  # ]
     215                 :          0 :         break;
     216                 :            :     default:
     217                 :            :         OSL_FAIL("illegal property");
     218                 :            :     }
     219                 :            : 
     220                 :          0 :     return true;
     221                 :            : }
     222                 :            : 
     223                 :            : // create an internally used macro name from the library and macro name parts
     224                 :          0 : void SwMacroField::CreateMacroString(
     225                 :            :     rtl::OUString& rMacro,
     226                 :            :     const String& rMacroName,
     227                 :            :     const String& rLibraryName )
     228                 :            : {
     229                 :            :     // concatenate library and name; use dot only if both strings have content
     230                 :          0 :     rMacro = rLibraryName;
     231 [ #  # ][ #  # ]:          0 :     if ( rLibraryName.Len() > 0 && rMacroName.Len() > 0 )
                 [ #  # ]
     232                 :          0 :         rMacro += rtl::OUString('.');
     233                 :          0 :     rMacro += rMacroName;
     234                 :          0 : }
     235                 :            : 
     236                 :          0 : sal_Bool SwMacroField::isScriptURL( const String& str )
     237                 :            : {
     238                 :            :     uno::Reference< lang::XMultiServiceFactory > xSMgr =
     239         [ #  # ]:          0 :         ::comphelper::getProcessServiceFactory();
     240                 :            : 
     241                 :            :     uno::Reference< uri::XUriReferenceFactory >
     242         [ #  # ]:          0 :         xFactory( xSMgr->createInstance(
     243                 :            :             OUString(RTL_CONSTASCII_USTRINGPARAM(
     244 [ #  # ][ #  # ]:          0 :                 "com.sun.star.uri.UriReferenceFactory")) ), uno::UNO_QUERY );
                 [ #  # ]
     245                 :            : 
     246         [ #  # ]:          0 :     if ( xFactory.is() )
     247                 :            :     {
     248                 :            :         uno::Reference< uri::XVndSunStarScriptUrl >
     249 [ #  # ][ #  # ]:          0 :             xUrl( xFactory->parse( str ), uno::UNO_QUERY );
         [ #  # ][ #  # ]
     250                 :            : 
     251         [ #  # ]:          0 :         if ( xUrl.is() )
     252                 :            :         {
     253                 :          0 :             return sal_True;
     254         [ #  # ]:          0 :         }
     255                 :            :     }
     256                 :          0 :     return sal_False;
     257                 :            : }
     258                 :            : 
     259                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10