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 $
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"
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"
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()
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 );
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.
92 case 1: // Date dd/mm/yyyy
93 // this is the default format...
95 case 2: // Date Day, Month dd, yyyy
97 case 3: // Date dd Month yyyy
99 case 4: // Date Month dd, yyyy
101 case 5: // Date dd-Mon-yy
103 case 6: // Date Month yy
105 case 7: // Date Mon-yy
107 case 8: // DateTime dd/mm/yyyy H:MM PM
108 lclCreateTextFields( aFields
, xModel
, CREATE_OUSTRING( "datetime12" ) );
110 case 9: // DateTime dd/mm/yy H:MM:SS PM
111 lclCreateTextFields( aFields
, xModel
, CREATE_OUSTRING( "datetime13" ) );
113 case 10: // Time H:MM
116 case 11: // Time H:MM:SS
118 // this is the default format
120 case 12: // Time H:MM PM
123 case 13: // Time H:MM:SS PM
127 xProps
->setPropertyValue( CREATE_OUSTRING( "IsDate" ), makeAny( bIsDate
) );
128 xProps
->setPropertyValue( CREATE_OUSTRING( "IsFixed" ), makeAny( false ) );
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
) );
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() )
169 for( std::list
< Reference
< XTextField
> >::iterator iter
= fields
.begin();
170 iter
!= fields
.end(); ++iter
)
174 Reference
< XTextContent
> xContent( *iter
, UNO_QUERY
);
181 xText
->insertString( xStart
, CREATE_OUSTRING( " " ), sal_False
);
183 xText
->insertTextContent( xStart
, xContent
, sal_False
);
189 xText
->insertString( xStart
, getText(), sal_False
);
192 catch( const Exception
& )
194 OSL_TRACE("OOX: TextField::insertAt() exception");