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