1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "drawingml/textfield.hxx"
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 "drawingml/textparagraphproperties.hxx"
34 #include "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()
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
);
62 if( sType
.startsWith("datetime"))
64 OString s
= OUStringToOString( sType
, RTL_TEXTENCODING_UTF8
);
65 OString
p( s
.pData
->buffer
+ 8 );
69 int idx
= p
.toInt32();
71 xIface
= xFactory
->createInstance( "com.sun.star.text.TextField.DateTime" );
72 aFields
.push_back( Reference
< XTextField
> ( xIface
, UNO_QUERY
) );
73 Reference
< XPropertySet
> xProps( xIface
, UNO_QUERY_THROW
);
75 // here we should format the field properly. waiting after #i81091.
78 case 1: // Date dd/mm/yyyy
79 // this is the default format...
81 xProps
->setPropertyValue("NumberFormat", makeAny(nNumFmt
));
83 case 2: // Date Day, Month dd, yyyy
85 case 3: // Date dd Month yyyy
87 xProps
->setPropertyValue("NumberFormat", makeAny(nNumFmt
));
89 case 4: // Date Month dd, yyyy
91 case 5: // Date dd-Mon-yy
93 case 6: // Date Month yy
95 case 7: // Date Mon-yy
97 case 8: // DateTime dd/mm/yyyy H:MM PM
98 lclCreateTextFields( aFields
, xModel
, "datetime12" );
100 case 9: // DateTime dd/mm/yy H:MM:SS PM
101 lclCreateTextFields( aFields
, xModel
, "datetime13" );
103 case 10: // Time H:MM
106 xProps
->setPropertyValue("NumberFormat", makeAny(nNumFmt
));
108 case 11: // Time H:MM:SS
110 // this is the default format
112 xProps
->setPropertyValue("NumberFormat", makeAny(nNumFmt
));
114 case 12: // Time H:MM PM
117 xProps
->setPropertyValue("NumberFormat", makeAny(nNumFmt
));
119 case 13: // Time H:MM:SS PM
122 xProps
->setPropertyValue("NumberFormat", makeAny(nNumFmt
));
126 xProps
->setPropertyValue("NumberFormat", makeAny(nNumFmt
));
128 xProps
->setPropertyValue( "IsDate", makeAny( bIsDate
) );
129 xProps
->setPropertyValue( "IsFixed", makeAny( false ) );
133 SAL_WARN("oox", "Exception " << e
.Message
);
136 else if ( sType
== "slidenum" )
138 xIface
= xFactory
->createInstance( "com.sun.star.text.TextField.PageNumber" );
139 aFields
.push_back( Reference
< XTextField
> ( xIface
, UNO_QUERY
) );
141 else if ( sType
== "slidecount" )
143 xIface
= xFactory
->createInstance( "com.sun.star.text.TextField.PageCount" );
144 aFields
.push_back( Reference
< XTextField
> ( xIface
, UNO_QUERY
) );
146 else if ( sType
== "slidename" )
148 xIface
= xFactory
->createInstance( "com.sun.star.text.TextField.PageName" );
149 aFields
.push_back( Reference
< XTextField
> ( xIface
, uno::UNO_QUERY
) );
151 else if ( sType
.startsWith("file") )
153 OString s
= OUStringToOString( sType
, RTL_TEXTENCODING_UTF8
);
154 OString
p( s
.pData
->buffer
+ 4 );
155 int idx
= p
.toInt32();
156 xIface
= xFactory
->createInstance( "com.sun.star.text.TextField.FileName" );
157 aFields
.push_back( Reference
< XTextField
> ( xIface
, UNO_QUERY
) );
158 Reference
< XPropertySet
> xProps( xIface
, UNO_QUERY_THROW
);
163 xProps
->setPropertyValue("FileFormat", makeAny
<sal_Int16
>(1));
165 case 2: // File name without extension
166 xProps
->setPropertyValue("FileFormat", makeAny
<sal_Int16
>(2));
168 case 3: // File name with extension
169 xProps
->setPropertyValue("FileFormat", makeAny
<sal_Int16
>(3));
171 default: // Path/File name
172 xProps
->setPropertyValue("FileFormat", makeAny
<sal_Int16
>(0));
175 else if( sType
== "author" )
177 xIface
= xFactory
->createInstance( "com.sun.star.text.TextField.Author" );
178 aFields
.push_back( Reference
< XTextField
> ( xIface
, UNO_QUERY
) );
184 sal_Int32
TextField::insertAt(
185 const ::oox::core::XmlFilterBase
& rFilterBase
,
186 const Reference
< XText
> & xText
,
187 const Reference
< XTextCursor
> &xAt
,
188 const TextCharacterProperties
& rTextCharacterStyle
,
189 float /*nDefaultCharHeight*/) const
191 sal_Int32 nCharHeight
= 0;
194 PropertyMap aioBulletList
;
195 Reference
< XPropertySet
> xProps( xAt
, UNO_QUERY
);
196 PropertySet
aPropSet( xProps
);
198 maTextParagraphProperties
.pushToPropSet( &rFilterBase
, xProps
, aioBulletList
, nullptr, true, 18 );
200 TextCharacterProperties
aTextCharacterProps( rTextCharacterStyle
);
201 aTextCharacterProps
.assignUsed( maTextParagraphProperties
.getTextCharacterProperties() );
202 aTextCharacterProps
.assignUsed( getTextCharacterProperties() );
203 if ( aTextCharacterProps
.moHeight
.has() )
204 nCharHeight
= aTextCharacterProps
.moHeight
.get();
205 aTextCharacterProps
.pushToPropSet( aPropSet
, rFilterBase
);
207 std::list
< Reference
< XTextField
> > fields
;
208 lclCreateTextFields( fields
, rFilterBase
.getModel(), msType
);
209 if( !fields
.empty() )
212 for( std::list
< Reference
< XTextField
> >::iterator iter
= fields
.begin();
213 iter
!= fields
.end(); ++iter
)
217 Reference
< XTextContent
> xContent( *iter
, UNO_QUERY
);
224 xText
->insertString( xAt
, " ", false );
226 xText
->insertTextContent( xAt
, xContent
, false );
232 xText
->insertString( xAt
, getText(), false );
235 catch( const Exception
& )
237 SAL_WARN("oox", "OOX: TextField::insertAt() exception");
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */