bump product version to 4.1.6.2
[LibreOffice.git] / oox / source / drawingml / textfield.cxx
blob95f5e24f7fb63dbe0a56a54b31b8d7952fd9bf5f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "oox/drawingml/textfield.hxx"
22 #include <list>
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>
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"
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;
43 namespace oox { namespace drawingml {
45 TextField::TextField()
49 namespace {
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.
57 void lclCreateTextFields( std::list< Reference< XTextField > > & aFields,
58 const Reference< XModel > & xModel, const OUString & sType )
60 Reference< XInterface > xIface;
61 Reference< XMultiServiceFactory > xFactory( xModel, UNO_QUERY_THROW );
63 if( sType.startsWith("datetime"))
65 OString s = OUStringToOString( sType, RTL_TEXTENCODING_UTF8);
66 OString p( s.pData->buffer + 8 );
67 try
69 bool bIsDate = true;
70 int idx = p.toInt32();
71 // OSL_TRACE( "OOX: p = %s, %d", p.pData->buffer, idx );
72 xIface = xFactory->createInstance( "com.sun.star.text.TextField.DateTime" );
73 aFields.push_back( Reference< XTextField > ( xIface, UNO_QUERY ) );
74 Reference< XPropertySet > xProps( xIface, UNO_QUERY_THROW );
76 // here we should format the field properly. waiting after #i81091.
77 switch( idx )
79 case 1: // Date dd/mm/yyyy
80 // this is the default format...
81 break;
82 case 2: // Date Day, Month dd, yyyy
83 break;
84 case 3: // Date dd Month yyyy
85 break;
86 case 4: // Date Month dd, yyyy
87 break;
88 case 5: // Date dd-Mon-yy
89 break;
90 case 6: // Date Month yy
91 break;
92 case 7: // Date Mon-yy
93 break;
94 case 8: // DateTime dd/mm/yyyy H:MM PM
95 lclCreateTextFields( aFields, xModel, "datetime12" );
96 break;
97 case 9: // DateTime dd/mm/yy H:MM:SS PM
98 lclCreateTextFields( aFields, xModel, "datetime13" );
99 break;
100 case 10: // Time H:MM
101 bIsDate = false;
102 break;
103 case 11: // Time H:MM:SS
104 bIsDate = false;
105 // this is the default format
106 break;
107 case 12: // Time H:MM PM
108 bIsDate = false;
109 break;
110 case 13: // Time H:MM:SS PM
111 bIsDate = false;
112 break;
114 xProps->setPropertyValue( "IsDate", makeAny( bIsDate ) );
115 xProps->setPropertyValue( "IsFixed", makeAny( false ) );
117 catch(Exception & e)
119 OSL_TRACE( "Exception %s", OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
122 else if ( sType.compareToAscii( "slidenum" ) == 0 )
124 xIface = xFactory->createInstance( "com.sun.star.text.TextField.PageNumber" );
125 aFields.push_back( Reference< XTextField > ( xIface, UNO_QUERY ) );
129 } // namespace
131 sal_Int32 TextField::insertAt(
132 const ::oox::core::XmlFilterBase& rFilterBase,
133 const Reference < XText > & xText,
134 const Reference < XTextCursor > &xAt,
135 const TextCharacterProperties& rTextCharacterStyle ) const
137 sal_Int32 nCharHeight = 0;
140 PropertyMap aioBulletList;
141 Reference< XTextRange > xStart( xAt, UNO_QUERY );
142 Reference< XPropertySet > xProps( xStart, UNO_QUERY);
143 PropertySet aPropSet( xProps );
145 maTextParagraphProperties.pushToPropSet( &rFilterBase, xProps, aioBulletList, NULL, sal_True, 18 );
147 TextCharacterProperties aTextCharacterProps( rTextCharacterStyle );
148 aTextCharacterProps.assignUsed( maTextParagraphProperties.getTextCharacterProperties() );
149 aTextCharacterProps.assignUsed( getTextCharacterProperties() );
150 if ( aTextCharacterProps.moHeight.has() )
151 nCharHeight = aTextCharacterProps.moHeight.get();
152 aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
154 std::list< Reference< XTextField > > fields;
155 lclCreateTextFields( fields, rFilterBase.getModel(), msType );
156 if( !fields.empty() )
158 bool bFirst = true;
159 for( std::list< Reference< XTextField > >::iterator iter = fields.begin();
160 iter != fields.end(); ++iter )
162 if( iter->is() )
164 Reference< XTextContent > xContent( *iter, UNO_QUERY);
165 if( bFirst)
167 bFirst = false;
169 else
171 xText->insertString( xStart, " ", sal_False );
173 xText->insertTextContent( xStart, xContent, sal_False );
177 else
179 xText->insertString( xStart, getText(), sal_False );
182 catch( const Exception& )
184 OSL_TRACE("OOX: TextField::insertAt() exception");
187 return nCharHeight;
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */