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