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 12 : TextField::TextField()
46 : {
47 12 : }
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 5 : void lclCreateTextFields( std::list< Reference< XTextField > > & aFields,
58 : const Reference< XModel > & xModel, const OUString & sType )
59 : {
60 5 : Reference< XInterface > xIface;
61 5 : Reference< XMultiServiceFactory > xFactory( xModel, UNO_QUERY_THROW );
62 :
63 5 : if( sType.compareToAscii( "datetime", 8 ) == 0)
64 : {
65 1 : OString s = OUStringToOString( sType, RTL_TEXTENCODING_UTF8);
66 1 : OString p( s.pData->buffer + 8 );
67 : try
68 : {
69 1 : bool bIsDate = true;
70 1 : int idx = p.toInt32();
71 : // OSL_TRACE( "OOX: p = %s, %d", p.pData->buffer, idx );
72 1 : xIface = xFactory->createInstance( CREATE_OUSTRING( "com.sun.star.text.TextField.DateTime" ) );
73 1 : aFields.push_back( Reference< XTextField > ( xIface, UNO_QUERY ) );
74 1 : Reference< XPropertySet > xProps( xIface, UNO_QUERY_THROW );
75 :
76 : // here we should format the field properly. waiting after #i81091.
77 1 : 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, CREATE_OUSTRING( "datetime12" ) );
96 0 : break;
97 : case 9: // DateTime dd/mm/yy H:MM:SS PM
98 0 : lclCreateTextFields( aFields, xModel, CREATE_OUSTRING( "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 1 : xProps->setPropertyValue( CREATE_OUSTRING( "IsDate" ), makeAny( bIsDate ) );
115 1 : xProps->setPropertyValue( CREATE_OUSTRING( "IsFixed" ), makeAny( false ) );
116 : }
117 0 : catch(Exception & e)
118 : {
119 : OSL_TRACE( "Exception %s", OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
120 1 : }
121 : }
122 4 : else if ( sType.compareToAscii( "slidenum" ) == 0 )
123 : {
124 4 : xIface = xFactory->createInstance( CREATE_OUSTRING( "com.sun.star.text.TextField.PageNumber" ) );
125 4 : aFields.push_back( Reference< XTextField > ( xIface, UNO_QUERY ) );
126 5 : }
127 5 : }
128 :
129 : } // namespace
130 :
131 5 : 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
136 : {
137 5 : sal_Int32 nCharHeight = 0;
138 : try
139 : {
140 5 : PropertyMap aioBulletList;
141 5 : Reference< XTextRange > xStart( xAt, UNO_QUERY );
142 5 : Reference< XPropertySet > xProps( xStart, UNO_QUERY);
143 5 : PropertySet aPropSet( xProps );
144 :
145 5 : maTextParagraphProperties.pushToPropSet( &rFilterBase, xProps, aioBulletList, NULL, sal_True, 18 );
146 :
147 5 : TextCharacterProperties aTextCharacterProps( rTextCharacterStyle );
148 5 : aTextCharacterProps.assignUsed( maTextParagraphProperties.getTextCharacterProperties() );
149 5 : aTextCharacterProps.assignUsed( getTextCharacterProperties() );
150 5 : if ( aTextCharacterProps.moHeight.has() )
151 4 : nCharHeight = aTextCharacterProps.moHeight.get();
152 5 : aTextCharacterProps.pushToPropSet( aPropSet, rFilterBase );
153 :
154 5 : std::list< Reference< XTextField > > fields;
155 5 : lclCreateTextFields( fields, rFilterBase.getModel(), msType );
156 5 : if( !fields.empty() )
157 : {
158 5 : bool bFirst = true;
159 30 : for( std::list< Reference< XTextField > >::iterator iter = fields.begin();
160 20 : iter != fields.end(); ++iter )
161 : {
162 5 : if( iter->is() )
163 : {
164 5 : Reference< XTextContent > xContent( *iter, UNO_QUERY);
165 5 : if( bFirst)
166 : {
167 5 : bFirst = false;
168 : }
169 : else
170 : {
171 0 : xText->insertString( xStart, CREATE_OUSTRING( " " ), sal_False );
172 : }
173 5 : xText->insertTextContent( xStart, xContent, sal_False );
174 : }
175 : }
176 : }
177 : else
178 : {
179 0 : xText->insertString( xStart, getText(), sal_False );
180 5 : }
181 : }
182 0 : catch( const Exception& )
183 : {
184 : OSL_TRACE("OOX: TextField::insertAt() exception");
185 : }
186 :
187 5 : return nCharHeight;
188 : }
189 :
190 51 : } }
191 :
192 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|