LCOV - code coverage report
Current view: top level - oox/source/drawingml - textfield.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 49 72 68.1 %
Date: 2012-08-25 Functions: 5 5 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 53 138 38.4 %

           Branch data     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 "oox/drawingml/textfield.hxx"
      21                 :            : 
      22                 :            : #include <list>
      23                 :            : 
      24                 :            : #include <rtl/ustring.hxx>
      25                 :            : #include <rtl/string.hxx>
      26                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      27                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      28                 :            : #include <com/sun/star/text/XTextField.hpp>
      29                 :            : 
      30                 :            : #include "oox/helper/helper.hxx"
      31                 :            : #include "oox/helper/propertyset.hxx"
      32                 :            : #include "oox/core/xmlfilterbase.hxx"
      33                 :            : #include "oox/drawingml/textparagraphproperties.hxx"
      34                 :            : #include "oox/drawingml/textcharacterproperties.hxx"
      35                 :            : 
      36                 :            : using ::rtl::OString;
      37                 :            : using ::rtl::OUString;
      38                 :            : using namespace ::com::sun::star;
      39                 :            : using namespace ::com::sun::star::uno;
      40                 :            : using namespace ::com::sun::star::text;
      41                 :            : using namespace ::com::sun::star::beans;
      42                 :            : using namespace ::com::sun::star::frame;
      43                 :            : using namespace ::com::sun::star::lang;
      44                 :            : 
      45                 :            : namespace oox { namespace drawingml {
      46                 :            : 
      47         [ +  - ]:         33 : TextField::TextField()
      48                 :            : {
      49                 :         33 : }
      50                 :            : 
      51                 :            : namespace {
      52                 :            : 
      53                 :            : /** intsanciate the textfields. Because of semantics difference between
      54                 :            :  * OpenXML and OpenOffice, some OpenXML field might cause two fields to be created.
      55                 :            :  * @param aFields the created fields. The list is empty if no field has been created.
      56                 :            :  * @param xModel the model
      57                 :            :  * @param sType the OpenXML field type.
      58                 :            :  */
      59                 :         12 : void lclCreateTextFields( std::list< Reference< XTextField > > & aFields,
      60                 :            :                                                             const Reference< XModel > & xModel, const OUString & sType )
      61                 :            : {
      62                 :         12 :     Reference< XInterface > xIface;
      63         [ +  - ]:         12 :     Reference< XMultiServiceFactory > xFactory( xModel, UNO_QUERY_THROW );
      64                 :            : 
      65         [ +  + ]:         12 :     if( sType.compareToAscii( "datetime", 8 ) == 0)
      66                 :            :     {
      67         [ +  - ]:          3 :         OString s = ::rtl::OUStringToOString( sType, RTL_TEXTENCODING_UTF8);
      68                 :          3 :         OString p( s.pData->buffer + 8 );
      69                 :            :         try
      70                 :            :         {
      71                 :          3 :             bool bIsDate = true;
      72                 :          3 :             int idx = p.toInt32();
      73                 :            : //              OSL_TRACE( "OOX: p = %s, %d", p.pData->buffer, idx );
      74 [ +  - ][ +  - ]:          3 :             xIface = xFactory->createInstance( CREATE_OUSTRING( "com.sun.star.text.TextField.DateTime" ) );
         [ +  - ][ +  - ]
      75 [ +  - ][ +  - ]:          3 :             aFields.push_back( Reference< XTextField > ( xIface, UNO_QUERY ) );
      76         [ +  - ]:          3 :             Reference< XPropertySet > xProps( xIface, UNO_QUERY_THROW );
      77                 :            : 
      78                 :            :             // here we should format the field properly. waiting after #i81091.
      79   [ -  -  -  -  :          3 :             switch( idx )
          -  -  -  -  -  
             -  -  -  -  
                      + ]
      80                 :            :             {
      81                 :            :             case 1: // Date dd/mm/yyyy
      82                 :            :                 // this is the default format...
      83                 :          0 :                 break;
      84                 :            :             case 2: // Date Day, Month dd, yyyy
      85                 :          0 :                 break;
      86                 :            :             case 3: // Date dd Month yyyy
      87                 :          0 :                 break;
      88                 :            :             case 4: // Date Month dd, yyyy
      89                 :          0 :                 break;
      90                 :            :             case 5: // Date dd-Mon-yy
      91                 :          0 :                 break;
      92                 :            :             case 6: // Date Month yy
      93                 :          0 :                 break;
      94                 :            :             case 7: // Date Mon-yy
      95                 :          0 :                 break;
      96                 :            :             case 8: // DateTime dd/mm/yyyy H:MM PM
      97 [ #  # ][ #  # ]:          0 :                 lclCreateTextFields( aFields, xModel, CREATE_OUSTRING( "datetime12" ) );
      98                 :          0 :                 break;
      99                 :            :             case 9: // DateTime dd/mm/yy H:MM:SS PM
     100 [ #  # ][ #  # ]:          0 :                 lclCreateTextFields( aFields, xModel, CREATE_OUSTRING( "datetime13" ) );
     101                 :          0 :                 break;
     102                 :            :             case 10: // Time H:MM
     103                 :          0 :                 bIsDate = false;
     104                 :          0 :                 break;
     105                 :            :             case 11: // Time H:MM:SS
     106                 :          0 :                 bIsDate = false;
     107                 :            :                 // this is the default format
     108                 :          0 :                 break;
     109                 :            :             case 12: // Time H:MM PM
     110                 :          0 :                 bIsDate = false;
     111                 :          0 :                 break;
     112                 :            :             case 13: // Time H:MM:SS PM
     113                 :          0 :                 bIsDate = false;
     114                 :          0 :                 break;
     115                 :            :             }
     116 [ +  - ][ +  - ]:          3 :             xProps->setPropertyValue( CREATE_OUSTRING( "IsDate" ), makeAny( bIsDate ) );
         [ +  - ][ +  - ]
     117 [ +  - ][ +  - ]:          3 :             xProps->setPropertyValue( CREATE_OUSTRING( "IsFixed" ), makeAny( false ) );
         [ +  - ][ #  # ]
                 [ +  - ]
     118                 :            :         }
     119         [ #  # ]:          0 :         catch(Exception & e)
     120                 :            :         {
     121                 :            :             OSL_TRACE( "Exception %s",  OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
     122                 :          3 :         }
     123                 :            :     }
     124         [ +  - ]:          9 :     else if ( sType.compareToAscii( "slidenum" ) == 0 )
     125                 :            :     {
     126 [ +  - ][ +  - ]:          9 :         xIface = xFactory->createInstance( CREATE_OUSTRING( "com.sun.star.text.TextField.PageNumber" ) );
         [ +  - ][ +  - ]
     127 [ +  - ][ +  - ]:          9 :         aFields.push_back( Reference< XTextField > ( xIface, UNO_QUERY ) );
     128                 :         12 :     }
     129                 :         12 : }
     130                 :            : 
     131                 :            : } // namespace
     132                 :            : 
     133                 :         12 : sal_Int32 TextField::insertAt(
     134                 :            :         const ::oox::core::XmlFilterBase& rFilterBase,
     135                 :            :         const Reference < XText > & xText,
     136                 :            :         const Reference < XTextCursor > &xAt,
     137                 :            :         const TextCharacterProperties& rTextCharacterStyle ) const
     138                 :            : {
     139                 :         12 :     sal_Int32 nCharHeight = 0;
     140                 :            :     try
     141                 :            :     {
     142         [ +  - ]:         12 :         PropertyMap aioBulletList;
     143         [ +  - ]:         12 :         Reference< XTextRange > xStart( xAt, UNO_QUERY );
     144         [ +  - ]:         12 :         Reference< XPropertySet > xProps( xStart, UNO_QUERY);
     145         [ +  - ]:         12 :         PropertySet aPropSet( xProps );
     146                 :            : 
     147         [ +  - ]:         12 :         maTextParagraphProperties.pushToPropSet( &rFilterBase, xProps, aioBulletList, NULL, sal_True, 18 );
     148                 :            : 
     149         [ +  - ]:         12 :         TextCharacterProperties aTextCharacterProps( rTextCharacterStyle );
     150         [ +  - ]:         12 :         aTextCharacterProps.assignUsed( maTextParagraphProperties.getTextCharacterProperties() );
     151         [ +  - ]:         12 :         aTextCharacterProps.assignUsed( getTextCharacterProperties() );
     152         [ +  - ]:         12 :         if ( aTextCharacterProps.moHeight.has() )
     153                 :         12 :             nCharHeight = aTextCharacterProps.moHeight.get();
     154         [ +  - ]:         12 :         aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
     155                 :            : 
     156         [ +  - ]:         12 :         std::list< Reference< XTextField > > fields;
     157 [ +  - ][ +  - ]:         12 :         lclCreateTextFields( fields, rFilterBase.getModel(), msType );
     158         [ +  - ]:         12 :         if( !fields.empty() )
     159                 :            :         {
     160                 :         12 :             bool bFirst = true;
     161         [ +  + ]:         48 :             for( std::list< Reference< XTextField > >::iterator iter = fields.begin();
     162                 :         24 :                      iter != fields.end(); ++iter )
     163                 :            :             {
     164         [ +  - ]:         12 :                 if( iter->is() )
     165                 :            :                 {
     166         [ +  - ]:         12 :                     Reference< XTextContent > xContent( *iter, UNO_QUERY);
     167         [ +  - ]:         12 :                     if( bFirst)
     168                 :            :                     {
     169                 :         12 :                         bFirst = false;
     170                 :            :                     }
     171                 :            :                     else
     172                 :            :                     {
     173 [ #  # ][ #  # ]:          0 :                         xText->insertString( xStart, CREATE_OUSTRING( " " ), sal_False );
                 [ #  # ]
     174                 :            :                     }
     175 [ +  - ][ +  - ]:         12 :                     xText->insertTextContent( xStart, xContent, sal_False );
     176                 :            :                 }
     177                 :            :             }
     178                 :            :         }
     179                 :            :         else
     180                 :            :         {
     181 [ #  # ][ #  # ]:          0 :             xText->insertString( xStart, getText(), sal_False );
     182 [ +  - ][ +  - ]:         12 :         }
                 [ #  # ]
     183                 :            :     }
     184                 :          0 :     catch( const Exception&  )
     185                 :            :     {
     186                 :            :         OSL_TRACE("OOX:  TextField::insertAt() exception");
     187                 :            :     }
     188                 :            : 
     189                 :         12 :     return nCharHeight;
     190                 :            : }
     191                 :            : 
     192 [ +  - ][ +  - ]:        285 : } }
     193                 :            : 
     194                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10