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