1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include "oox/drawingml/textfield.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <list> 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include <rtl/ustring.hxx> 33*cdf0e10cSrcweir #include <rtl/string.hxx> 34*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/text/XTextField.hpp> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include "oox/helper/helper.hxx" 39*cdf0e10cSrcweir #include "oox/helper/propertyset.hxx" 40*cdf0e10cSrcweir #include "oox/core/xmlfilterbase.hxx" 41*cdf0e10cSrcweir #include "oox/drawingml/textparagraphproperties.hxx" 42*cdf0e10cSrcweir #include "oox/drawingml/textcharacterproperties.hxx" 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir using ::rtl::OString; 45*cdf0e10cSrcweir using ::rtl::OUString; 46*cdf0e10cSrcweir using namespace ::com::sun::star; 47*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 48*cdf0e10cSrcweir using namespace ::com::sun::star::text; 49*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 50*cdf0e10cSrcweir using namespace ::com::sun::star::frame; 51*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir namespace oox { namespace drawingml { 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir TextField::TextField() 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir } 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir namespace { 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir /** intsanciate the textfields. Because of semantics difference between 62*cdf0e10cSrcweir * OpenXML and OpenOffice, some OpenXML field might cause two fields to be created. 63*cdf0e10cSrcweir * @param aFields the created fields. The list is empty if no field has been created. 64*cdf0e10cSrcweir * @param xModel the model 65*cdf0e10cSrcweir * @param sType the OpenXML field type. 66*cdf0e10cSrcweir */ 67*cdf0e10cSrcweir void lclCreateTextFields( std::list< Reference< XTextField > > & aFields, 68*cdf0e10cSrcweir const Reference< XModel > & xModel, const OUString & sType ) 69*cdf0e10cSrcweir { 70*cdf0e10cSrcweir Reference< XInterface > xIface; 71*cdf0e10cSrcweir Reference< XMultiServiceFactory > xFactory( xModel, UNO_QUERY_THROW ); 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir if( sType.compareToAscii( "datetime", 8 ) == 0) 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir OString s = ::rtl::OUStringToOString( sType, RTL_TEXTENCODING_UTF8); 76*cdf0e10cSrcweir OString p( s.pData->buffer + 8 ); 77*cdf0e10cSrcweir try 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir bool bIsDate = true; 80*cdf0e10cSrcweir int idx = p.toInt32(); 81*cdf0e10cSrcweir // OSL_TRACE( "OOX: p = %s, %d", p.pData->buffer, idx ); 82*cdf0e10cSrcweir xIface = xFactory->createInstance( CREATE_OUSTRING( "com.sun.star.text.TextField.DateTime" ) ); 83*cdf0e10cSrcweir aFields.push_back( Reference< XTextField > ( xIface, UNO_QUERY ) ); 84*cdf0e10cSrcweir Reference< XPropertySet > xProps( xIface, UNO_QUERY_THROW ); 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir // here we should format the field properly. waiting after #i81091. 87*cdf0e10cSrcweir switch( idx ) 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir case 1: // Date dd/mm/yyyy 90*cdf0e10cSrcweir // this is the default format... 91*cdf0e10cSrcweir break; 92*cdf0e10cSrcweir case 2: // Date Day, Month dd, yyyy 93*cdf0e10cSrcweir break; 94*cdf0e10cSrcweir case 3: // Date dd Month yyyy 95*cdf0e10cSrcweir break; 96*cdf0e10cSrcweir case 4: // Date Month dd, yyyy 97*cdf0e10cSrcweir break; 98*cdf0e10cSrcweir case 5: // Date dd-Mon-yy 99*cdf0e10cSrcweir break; 100*cdf0e10cSrcweir case 6: // Date Month yy 101*cdf0e10cSrcweir break; 102*cdf0e10cSrcweir case 7: // Date Mon-yy 103*cdf0e10cSrcweir break; 104*cdf0e10cSrcweir case 8: // DateTime dd/mm/yyyy H:MM PM 105*cdf0e10cSrcweir lclCreateTextFields( aFields, xModel, CREATE_OUSTRING( "datetime12" ) ); 106*cdf0e10cSrcweir break; 107*cdf0e10cSrcweir case 9: // DateTime dd/mm/yy H:MM:SS PM 108*cdf0e10cSrcweir lclCreateTextFields( aFields, xModel, CREATE_OUSTRING( "datetime13" ) ); 109*cdf0e10cSrcweir break; 110*cdf0e10cSrcweir case 10: // Time H:MM 111*cdf0e10cSrcweir bIsDate = false; 112*cdf0e10cSrcweir break; 113*cdf0e10cSrcweir case 11: // Time H:MM:SS 114*cdf0e10cSrcweir bIsDate = false; 115*cdf0e10cSrcweir // this is the default format 116*cdf0e10cSrcweir break; 117*cdf0e10cSrcweir case 12: // Time H:MM PM 118*cdf0e10cSrcweir bIsDate = false; 119*cdf0e10cSrcweir break; 120*cdf0e10cSrcweir case 13: // Time H:MM:SS PM 121*cdf0e10cSrcweir bIsDate = false; 122*cdf0e10cSrcweir break; 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir xProps->setPropertyValue( CREATE_OUSTRING( "IsDate" ), makeAny( bIsDate ) ); 125*cdf0e10cSrcweir xProps->setPropertyValue( CREATE_OUSTRING( "IsFixed" ), makeAny( false ) ); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir catch(Exception & e) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir OSL_TRACE( "Exception %s", OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).getStr() ); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir else if ( sType.compareToAscii( "slidenum" ) == 0 ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir xIface = xFactory->createInstance( CREATE_OUSTRING( "com.sun.star.text.TextField.PageNumber" ) ); 135*cdf0e10cSrcweir aFields.push_back( Reference< XTextField > ( xIface, UNO_QUERY ) ); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir } // namespace 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir void TextField::insertAt( 142*cdf0e10cSrcweir const ::oox::core::XmlFilterBase& rFilterBase, 143*cdf0e10cSrcweir const Reference < XText > & xText, 144*cdf0e10cSrcweir const Reference < XTextCursor > &xAt, 145*cdf0e10cSrcweir const TextCharacterProperties& rTextCharacterStyle ) const 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir try 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir PropertyMap aioBulletList; 150*cdf0e10cSrcweir Reference< XTextRange > xStart( xAt, UNO_QUERY ); 151*cdf0e10cSrcweir Reference< XPropertySet > xProps( xStart, UNO_QUERY); 152*cdf0e10cSrcweir PropertySet aPropSet( xProps ); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir maTextParagraphProperties.pushToPropSet( rFilterBase, xProps, aioBulletList, NULL, sal_True, 18 ); 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir TextCharacterProperties aTextCharacterProps( rTextCharacterStyle ); 157*cdf0e10cSrcweir aTextCharacterProps.assignUsed( maTextParagraphProperties.getTextCharacterProperties() ); 158*cdf0e10cSrcweir aTextCharacterProps.assignUsed( getTextCharacterProperties() ); 159*cdf0e10cSrcweir aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase ); 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir std::list< Reference< XTextField > > fields; 162*cdf0e10cSrcweir lclCreateTextFields( fields, rFilterBase.getModel(), msType ); 163*cdf0e10cSrcweir if( !fields.empty() ) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir bool bFirst = true; 166*cdf0e10cSrcweir for( std::list< Reference< XTextField > >::iterator iter = fields.begin(); 167*cdf0e10cSrcweir iter != fields.end(); ++iter ) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir if( iter->is() ) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir Reference< XTextContent > xContent( *iter, UNO_QUERY); 172*cdf0e10cSrcweir if( bFirst) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir bFirst = false; 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir else 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir xText->insertString( xStart, CREATE_OUSTRING( " " ), sal_False ); 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir xText->insertTextContent( xStart, xContent, sal_False ); 181*cdf0e10cSrcweir } 182*cdf0e10cSrcweir } 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir else 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir xText->insertString( xStart, getText(), sal_False ); 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir catch( const Exception& ) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir OSL_TRACE("OOX: TextField::insertAt() exception"); 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir } } 196