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

Generated by: LCOV version 1.11