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

Generated by: LCOV version 1.10