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 <DomainMapper_Impl.hxx>
21 : #include <ConversionHelper.hxx>
22 : #include <SdtHelper.hxx>
23 : #include <DomainMapperTableHandler.hxx>
24 : #include <com/sun/star/uno/XComponentContext.hpp>
25 : #include <com/sun/star/graphic/XGraphic.hpp>
26 : #include <com/sun/star/beans/XPropertyState.hpp>
27 : #include <com/sun/star/container/XNamed.hpp>
28 : #include <com/sun/star/document/PrinterIndependentLayout.hpp>
29 : #include <com/sun/star/document/IndexedPropertyValues.hpp>
30 : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
31 : #include <com/sun/star/lang/XServiceInfo.hpp>
32 : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
33 : #include <com/sun/star/style/LineNumberPosition.hpp>
34 : #include <com/sun/star/style/LineSpacing.hpp>
35 : #include <com/sun/star/style/LineSpacingMode.hpp>
36 : #include <com/sun/star/text/ChapterFormat.hpp>
37 : #include <com/sun/star/text/FilenameDisplayFormat.hpp>
38 : #include <com/sun/star/text/SetVariableType.hpp>
39 : #include <com/sun/star/text/XFootnote.hpp>
40 : #include <com/sun/star/text/XLineNumberingProperties.hpp>
41 : #include <com/sun/star/text/PageNumberType.hpp>
42 : #include <com/sun/star/text/HoriOrientation.hpp>
43 : #include <com/sun/star/text/VertOrientation.hpp>
44 : #include <com/sun/star/text/ReferenceFieldPart.hpp>
45 : #include <com/sun/star/text/ReferenceFieldSource.hpp>
46 : #include <com/sun/star/text/SizeType.hpp>
47 : #include <com/sun/star/text/TextContentAnchorType.hpp>
48 : #include <com/sun/star/text/WrapTextMode.hpp>
49 : #include <com/sun/star/text/XDependentTextField.hpp>
50 : #include <com/sun/star/text/XParagraphCursor.hpp>
51 : #include <com/sun/star/text/XRedline.hpp>
52 : #include <com/sun/star/text/XTextFieldsSupplier.hpp>
53 : #include <com/sun/star/style/DropCapFormat.hpp>
54 : #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
55 : #include <com/sun/star/document/XViewDataSupplier.hpp>
56 : #include <com/sun/star/container/XIndexContainer.hpp>
57 : #include <com/sun/star/awt/XControlModel.hpp>
58 : #include <com/sun/star/drawing/XControlShape.hpp>
59 : #include <com/sun/star/text/ControlCharacter.hpp>
60 : #include <com/sun/star/text/XTextColumns.hpp>
61 : #include <oox/mathml/import.hxx>
62 : #include <GraphicHelpers.hxx>
63 :
64 : #ifdef DEBUG_DOMAINMAPPER
65 : #include <resourcemodel/QNameToString.hxx>
66 : #include <resourcemodel/util.hxx>
67 : #include <dmapperLoggers.hxx>
68 : #endif
69 : #include <ooxml/OOXMLFastTokens.hxx>
70 :
71 : #include <map>
72 : #include <boost/tuple/tuple.hpp>
73 :
74 : #include <vcl/svapp.hxx>
75 : #include <vcl/outdev.hxx>
76 : #include <officecfg/Office/Common.hxx>
77 : #include <filter/msfilter/util.hxx>
78 :
79 : using namespace ::com::sun::star;
80 : using namespace ::rtl;
81 : namespace writerfilter {
82 : namespace dmapper{
83 :
84 : // Populate Dropdown Field properties from FFData structure
85 0 : void lcl_handleDropdownField( const uno::Reference< beans::XPropertySet >& rxFieldProps, FFDataHandler::Pointer_t pFFDataHandler )
86 : {
87 0 : if ( rxFieldProps.is() )
88 : {
89 0 : if ( !pFFDataHandler->getName().isEmpty() )
90 0 : rxFieldProps->setPropertyValue( "Name", uno::makeAny( pFFDataHandler->getName() ) );
91 :
92 0 : const FFDataHandler::DropDownEntries_t& rEntries = pFFDataHandler->getDropDownEntries();
93 0 : uno::Sequence< OUString > sItems( rEntries.size() );
94 0 : ::std::copy( rEntries.begin(), rEntries.end(), sItems.begin());
95 0 : if ( sItems.getLength() )
96 0 : rxFieldProps->setPropertyValue( "Items", uno::makeAny( sItems ) );
97 :
98 0 : sal_Int32 nResult = pFFDataHandler->getDropDownResult().toInt32();
99 0 : if ( nResult )
100 0 : rxFieldProps->setPropertyValue( "SelectedItem", uno::makeAny( sItems[ nResult ] ) );
101 0 : if ( !pFFDataHandler->getHelpText().isEmpty() )
102 0 : rxFieldProps->setPropertyValue( "Help", uno::makeAny( pFFDataHandler->getHelpText() ) );
103 : }
104 0 : }
105 :
106 0 : void lcl_handleTextField( const uno::Reference< beans::XPropertySet >& rxFieldProps, FFDataHandler::Pointer_t pFFDataHandler, PropertyNameSupplier& rPropNameSupplier )
107 : {
108 0 : if ( rxFieldProps.is() && pFFDataHandler )
109 : {
110 0 : rxFieldProps->setPropertyValue
111 : (rPropNameSupplier.GetName(PROP_HINT),
112 0 : uno::makeAny(pFFDataHandler->getStatusText()));
113 0 : rxFieldProps->setPropertyValue
114 : (rPropNameSupplier.GetName(PROP_HELP),
115 0 : uno::makeAny(pFFDataHandler->getHelpText()));
116 0 : rxFieldProps->setPropertyValue
117 : (rPropNameSupplier.GetName(PROP_CONTENT),
118 0 : uno::makeAny(pFFDataHandler->getTextDefault()));
119 : }
120 0 : }
121 :
122 176975 : struct FieldConversion
123 : {
124 : OUString sWordCommand;
125 : const sal_Char* cFieldServiceName;
126 : const sal_Char* cFieldMasterServiceName;
127 : FieldId eFieldId;
128 : };
129 :
130 : typedef ::std::map< OUString, FieldConversion>
131 : FieldConversionMap_t;
132 :
133 29 : uno::Any FloatingTableInfo::getPropertyValue(const OUString &propertyName)
134 : {
135 :
136 29 : beans::PropertyValue* pFrameProperties = m_aFrameProperties.getArray();
137 406 : for( int i = 0 ; i < m_aFrameProperties.getLength(); i++ )
138 406 : if( pFrameProperties[i].Name == propertyName )
139 29 : return pFrameProperties[i].Value ;
140 0 : return uno::Any() ;
141 : }
142 :
143 1192 : DomainMapper_Impl::DomainMapper_Impl(
144 : DomainMapper& rDMapper,
145 : uno::Reference < uno::XComponentContext > xContext,
146 : uno::Reference< lang::XComponent > xModel,
147 : SourceDocumentType eDocumentType,
148 : uno::Reference< text::XTextRange > xInsertTextRange,
149 : bool bIsNewDoc) :
150 : m_eDocumentType( eDocumentType ),
151 : m_rDMapper( rDMapper ),
152 : m_xTextDocument( xModel, uno::UNO_QUERY ),
153 : m_xTextFactory( xModel, uno::UNO_QUERY ),
154 : m_xComponentContext( xContext ),
155 : m_bSetUserFieldContent( false ),
156 : m_bSetCitation( false ),
157 : m_bIsFirstSection( true ),
158 : m_bIsColumnBreakDeferred( false ),
159 : m_bIsPageBreakDeferred( false ),
160 : m_bStartTOC(false),
161 : m_bStartedTOC(false),
162 : m_bStartIndex(false),
163 : m_bStartBibliography(false),
164 : m_bTOCPageRef(false),
165 : m_bStartGenericField(false),
166 : m_bTextInserted(false),
167 : m_pLastSectionContext( ),
168 : m_pLastCharacterContext(),
169 : m_nCurrentTabStopIndex( 0 ),
170 : m_sCurrentParaStyleId(),
171 : m_bInStyleSheetImport( false ),
172 : m_bInAnyTableImport( false ),
173 : m_bInHeaderFooterImport( false ),
174 : m_bDiscardHeaderFooter( false ),
175 : m_bLineNumberingSet( false ),
176 : m_bIsInFootnoteProperties( false ),
177 : m_bIsCustomFtnMark( false ),
178 : m_bIsParaMarkerChange( false ),
179 : m_bParaChanged( false ),
180 : m_bIsFirstParaInSection( true ),
181 : m_bIsLastParaInSection( false ),
182 : m_bIsInComments( false ),
183 : m_bParaSectpr( false ),
184 : m_bUsingEnhancedFields( false ),
185 : m_bSdt(false),
186 : m_bIsFirstRun(false),
187 : m_xAnnotationField(),
188 : m_nAnnotationId( -1 ),
189 : m_aAnnotationPositions(),
190 : m_xInsertTextRange(xInsertTextRange),
191 : m_bIsNewDoc(bIsNewDoc),
192 : m_bInTableStyleRunProps(false),
193 : m_pSdtHelper(0),
194 : m_nTableDepth(0),
195 : m_bHasFtnSep(false),
196 : m_bIgnoreNextPara(false),
197 : m_bIgnoreNextTab(false),
198 1193 : m_bFrameBtLr(false)
199 :
200 : {
201 1192 : appendTableManager( );
202 1192 : GetBodyText();
203 1192 : uno::Reference< text::XTextAppend > xBodyTextAppend = uno::Reference< text::XTextAppend >( m_xBodyText, uno::UNO_QUERY );
204 : m_aTextAppendStack.push(TextAppendContext(xBodyTextAppend,
205 1192 : m_bIsNewDoc ? uno::Reference<text::XTextCursor>() : m_xBodyText->createTextCursorByRange(m_xInsertTextRange)));
206 :
207 : //todo: does it make sense to set the body text as static text interface?
208 2382 : uno::Reference< text::XTextAppendAndConvert > xBodyTextAppendAndConvert( m_xBodyText, uno::UNO_QUERY );
209 : m_pTableHandler.reset
210 1191 : (new DomainMapperTableHandler(xBodyTextAppendAndConvert, *this));
211 1191 : getTableManager( ).setHandler(m_pTableHandler);
212 :
213 1191 : getTableManager( ).startLevel();
214 1191 : m_bUsingEnhancedFields = officecfg::Office::Common::Filter::Microsoft::Import::ImportWWFieldsAsEnhancedFields::get(m_xComponentContext);
215 :
216 1191 : m_pSdtHelper = new SdtHelper(*this);
217 :
218 2383 : m_aRedlines.push(std::vector<RedlineParamsPtr>());
219 1191 : }
220 :
221 :
222 3573 : DomainMapper_Impl::~DomainMapper_Impl()
223 : {
224 1191 : RemoveLastParagraph( );
225 1191 : getTableManager( ).endLevel();
226 1191 : popTableManager( );
227 1191 : delete m_pSdtHelper;
228 2382 : }
229 :
230 :
231 3741 : uno::Reference< container::XNameContainer > DomainMapper_Impl::GetPageStyles()
232 : {
233 3741 : if(!m_xPageStyles.is())
234 : {
235 1192 : uno::Reference< style::XStyleFamiliesSupplier > xSupplier( m_xTextDocument, uno::UNO_QUERY );
236 1192 : if (xSupplier.is())
237 1170 : xSupplier->getStyleFamilies()->getByName("PageStyles") >>= m_xPageStyles;
238 : }
239 3741 : return m_xPageStyles;
240 : }
241 :
242 :
243 4874 : uno::Reference< text::XText > DomainMapper_Impl::GetBodyText()
244 : {
245 4874 : if(!m_xBodyText.is())
246 : {
247 1214 : if (m_xInsertTextRange.is())
248 7 : m_xBodyText = m_xInsertTextRange->getText();
249 1207 : else if (m_xTextDocument.is())
250 1169 : m_xBodyText = m_xTextDocument->getText();
251 : }
252 4874 : return m_xBodyText;
253 : }
254 :
255 :
256 2382 : uno::Reference< beans::XPropertySet > DomainMapper_Impl::GetDocumentSettings()
257 : {
258 2382 : if( !m_xDocumentSettings.is() && m_xTextFactory.is())
259 : {
260 2350 : m_xDocumentSettings = uno::Reference< beans::XPropertySet >(
261 2350 : m_xTextFactory->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY );
262 : }
263 2382 : return m_xDocumentSettings;
264 : }
265 :
266 :
267 2382 : void DomainMapper_Impl::SetDocumentSettingsProperty( const OUString& rPropName, const uno::Any& rValue )
268 : {
269 2382 : uno::Reference< beans::XPropertySet > xSettings = GetDocumentSettings();
270 2382 : if( xSettings.is() )
271 : {
272 : try
273 : {
274 2350 : xSettings->setPropertyValue( rPropName, rValue );
275 : }
276 0 : catch( const uno::Exception& )
277 : {
278 : }
279 2382 : }
280 2382 : }
281 :
282 2997 : void DomainMapper_Impl::RemoveLastParagraph( )
283 : {
284 2997 : if (m_aTextAppendStack.empty())
285 110 : return;
286 2997 : uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend;
287 2997 : if (!xTextAppend.is())
288 110 : return;
289 : try
290 : {
291 2887 : uno::Reference< text::XTextCursor > xCursor;
292 2887 : if (m_bIsNewDoc)
293 : {
294 2879 : xCursor = xTextAppend->createTextCursor();
295 2879 : xCursor->gotoEnd(false);
296 : }
297 : else
298 8 : xCursor.set(m_aTextAppendStack.top().xCursor, uno::UNO_QUERY);
299 5774 : uno::Reference<container::XEnumerationAccess> xEnumerationAccess(xCursor, uno::UNO_QUERY);
300 : // Keep the character properties of the last but one paragraph, even if
301 : // it's empty. This works for headers/footers, and maybe in other cases
302 : // as well, but surely not in textboxes.
303 : // fdo#58327: also do this at the end of the document: when pasting,
304 : // a table before the cursor position would be deleted
305 : // (but only for paste/insert, not load; otherwise it can happen that
306 : // flys anchored at the disposed paragraph are deleted (fdo47036.rtf))
307 2887 : bool const bEndOfDocument(m_aTextAppendStack.size() == 1);
308 4869 : if ((m_bInHeaderFooterImport || (bEndOfDocument && !m_bIsNewDoc))
309 3799 : && xEnumerationAccess.is())
310 : {
311 871 : uno::Reference<container::XEnumeration> xEnumeration = xEnumerationAccess->createEnumeration();
312 1742 : uno::Reference<lang::XComponent> xParagraph(xEnumeration->nextElement(), uno::UNO_QUERY);
313 1742 : xParagraph->dispose();
314 : }
315 2016 : else if (xCursor.is())
316 : {
317 2015 : xCursor->goLeft( 1, true );
318 : // If this is a text on a shape, possibly the text has the trailing
319 : // newline removed already.
320 2015 : if (xCursor->getString() == SAL_NEWLINE_STRING)
321 : {
322 1535 : uno::Reference<beans::XPropertySet> xDocProps(GetTextDocument(), uno::UNO_QUERY);
323 3070 : const OUString aRecordChanges("RecordChanges");
324 3070 : uno::Any aPreviousValue(xDocProps->getPropertyValue(aRecordChanges));
325 :
326 : // disable redlining for this operation, otherwise we might
327 : // end up with an unwanted recorded deletion
328 1535 : xDocProps->setPropertyValue(aRecordChanges, uno::Any(sal_False));
329 :
330 : // delete
331 1535 : xCursor->setString(OUString());
332 :
333 : // restore again
334 3070 : xDocProps->setPropertyValue(aRecordChanges, aPreviousValue);
335 : }
336 2887 : }
337 : }
338 0 : catch( const uno::Exception& )
339 : {
340 2887 : }
341 : }
342 :
343 999 : void DomainMapper_Impl::SetIsLastParagraphInSection( bool bIsLast )
344 : {
345 999 : m_bIsLastParaInSection = bIsLast;
346 999 : }
347 :
348 1009 : bool DomainMapper_Impl::GetIsLastParagraphInSection()
349 : {
350 1009 : return m_bIsLastParaInSection;
351 : }
352 :
353 1331 : void DomainMapper_Impl::SetIsFirstParagraphInSection( bool bIsFirst )
354 : {
355 1331 : m_bIsFirstParaInSection = bIsFirst;
356 1331 : }
357 :
358 21101 : bool DomainMapper_Impl::GetIsFirstParagraphInSection()
359 : {
360 21101 : return m_bIsFirstParaInSection;
361 : }
362 :
363 21512 : void DomainMapper_Impl::SetParaSectpr(bool bParaSectpr)
364 : {
365 21512 : m_bParaSectpr = bParaSectpr;
366 21512 : }
367 :
368 9828 : bool DomainMapper_Impl::GetParaSectpr()
369 : {
370 9828 : return m_bParaSectpr;
371 : }
372 :
373 388 : void DomainMapper_Impl::SetSdt(bool bSdt)
374 : {
375 388 : m_bSdt = bSdt;
376 388 : }
377 :
378 85 : bool DomainMapper_Impl::GetSdt()
379 : {
380 85 : return m_bSdt;
381 : }
382 :
383 21101 : bool DomainMapper_Impl::GetParaChanged()
384 : {
385 21101 : return m_bParaChanged;
386 : }
387 :
388 77964 : void DomainMapper_Impl::PushProperties(ContextType eId)
389 : {
390 77964 : PropertyMapPtr pInsert(eId == CONTEXT_SECTION ?
391 1336 : (new SectionPropertyMap( m_bIsFirstSection )) :
392 79300 : eId == CONTEXT_PARAGRAPH ? new ParagraphPropertyMap : new PropertyMap);
393 77964 : if(eId == CONTEXT_SECTION)
394 : {
395 1336 : if( m_bIsFirstSection )
396 1184 : m_bIsFirstSection = false;
397 : // beginning with the second section group a section has to be inserted
398 : // into the document
399 1336 : SectionPropertyMap* pSectionContext_ = dynamic_cast< SectionPropertyMap* >( pInsert.get() );
400 1336 : if (!m_aTextAppendStack.empty())
401 : {
402 1336 : uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend;
403 1336 : if (xTextAppend.is() && pSectionContext_)
404 1324 : pSectionContext_->SetStart( xTextAppend->getEnd() );
405 : }
406 : }
407 77964 : m_aPropertyStacks[eId].push( pInsert );
408 77964 : m_aContextStack.push(eId);
409 :
410 77964 : m_pTopContext = m_aPropertyStacks[eId].top();
411 77964 : }
412 :
413 :
414 52378 : void DomainMapper_Impl::PushStyleProperties( PropertyMapPtr pStyleProperties )
415 : {
416 52378 : m_aPropertyStacks[CONTEXT_STYLESHEET].push( pStyleProperties );
417 52378 : m_aContextStack.push(CONTEXT_STYLESHEET);
418 :
419 52378 : m_pTopContext = m_aPropertyStacks[CONTEXT_STYLESHEET].top();
420 52378 : }
421 :
422 :
423 10701 : void DomainMapper_Impl::PushListProperties(PropertyMapPtr pListProperties)
424 : {
425 10701 : m_aPropertyStacks[CONTEXT_LIST].push( pListProperties );
426 10701 : m_aContextStack.push(CONTEXT_LIST);
427 10701 : m_pTopContext = m_aPropertyStacks[CONTEXT_LIST].top();
428 10701 : }
429 :
430 :
431 141027 : void DomainMapper_Impl::PopProperties(ContextType eId)
432 : {
433 : OSL_ENSURE(!m_aPropertyStacks[eId].empty(), "section stack already empty");
434 141027 : if ( m_aPropertyStacks[eId].empty() )
435 141027 : return;
436 :
437 141027 : if ( eId == CONTEXT_SECTION )
438 : {
439 1331 : m_pLastSectionContext = m_aPropertyStacks[eId].top( );
440 : }
441 139696 : else if (eId == CONTEXT_CHARACTER)
442 : {
443 53804 : m_pLastCharacterContext = m_aPropertyStacks[eId].top();
444 : // Sadly an assert about deferredCharacterProperties being empty is not possible
445 : // here, becase appendTextPortion() may not be called for every character section.
446 53804 : deferredCharacterProperties.clear();
447 : }
448 :
449 141027 : m_aPropertyStacks[eId].pop();
450 141027 : m_aContextStack.pop();
451 141027 : if(!m_aContextStack.empty() && !m_aPropertyStacks[m_aContextStack.top()].empty())
452 :
453 100028 : m_pTopContext = m_aPropertyStacks[m_aContextStack.top()].top();
454 : else
455 : {
456 : // OSL_ENSURE(eId == CONTEXT_SECTION, "this should happen at a section context end");
457 40999 : m_pTopContext.reset();
458 : }
459 : }
460 :
461 :
462 380966 : PropertyMapPtr DomainMapper_Impl::GetTopContextOfType(ContextType eId)
463 : {
464 380966 : PropertyMapPtr pRet;
465 : SAL_WARN_IF( m_aPropertyStacks[eId].empty(), "writerfilter",
466 : "no context of type " << static_cast<int>(eId) << " available");
467 380966 : if(!m_aPropertyStacks[eId].empty())
468 380744 : pRet = m_aPropertyStacks[eId].top();
469 380966 : return pRet;
470 : }
471 :
472 :
473 :
474 472 : uno::Reference< text::XTextAppend > DomainMapper_Impl::GetTopTextAppend()
475 : {
476 : OSL_ENSURE(!m_aTextAppendStack.empty(), "text append stack is empty" );
477 472 : return m_aTextAppendStack.top().xTextAppend;
478 : }
479 :
480 19 : FieldContextPtr DomainMapper_Impl::GetTopFieldContext()
481 : {
482 : SAL_WARN_IF(m_aFieldStack.empty(), "writerfilter", "Field stack is empty");
483 19 : return m_aFieldStack.top();
484 : }
485 :
486 63 : void DomainMapper_Impl::InitTabStopFromStyle( const uno::Sequence< style::TabStop >& rInitTabStops )
487 : {
488 : OSL_ENSURE(!m_aCurrentTabStops.size(), "tab stops already initialized");
489 198 : for( sal_Int32 nTab = 0; nTab < rInitTabStops.getLength(); ++nTab)
490 : {
491 135 : m_aCurrentTabStops.push_back( DeletableTabStop(rInitTabStops[nTab]) );
492 : }
493 63 : }
494 :
495 4041 : void DomainMapper_Impl::IncorporateTabStop( const DeletableTabStop & rTabStop )
496 : {
497 4041 : ::std::vector<DeletableTabStop>::iterator aIt = m_aCurrentTabStops.begin();
498 4041 : ::std::vector<DeletableTabStop>::iterator aEndIt = m_aCurrentTabStops.end();
499 4041 : sal_Int32 nConverted = rTabStop.Position;
500 4041 : bool bFound = false;
501 10530 : for( ; aIt != aEndIt; ++aIt)
502 : {
503 6570 : if( aIt->Position == nConverted )
504 : {
505 81 : bFound = true;
506 81 : if( rTabStop.bDeleted )
507 60 : m_aCurrentTabStops.erase( aIt );
508 : else
509 21 : *aIt = rTabStop;
510 81 : break;
511 : }
512 : }
513 4041 : if( !bFound )
514 3960 : m_aCurrentTabStops.push_back( rTabStop );
515 4041 : }
516 :
517 :
518 2205 : uno::Sequence< style::TabStop > DomainMapper_Impl::GetCurrentTabStopAndClear()
519 : {
520 2205 : uno::Sequence< style::TabStop > aRet( sal_Int32( m_aCurrentTabStops.size() ) );
521 2205 : style::TabStop* pArray = aRet.getArray();
522 2205 : ::std::vector<DeletableTabStop>::const_iterator aIt = m_aCurrentTabStops.begin();
523 2205 : ::std::vector<DeletableTabStop>::const_iterator aEndIt = m_aCurrentTabStops.end();
524 2205 : sal_Int32 nDeleted = 0;
525 6240 : for(sal_Int32 nIndex = 0; aIt != aEndIt; ++aIt)
526 : {
527 4035 : if(!aIt->bDeleted)
528 3911 : pArray[nIndex++] = *aIt;
529 : else
530 124 : ++nDeleted;
531 : }
532 2205 : m_aCurrentTabStops.clear();
533 2205 : m_nCurrentTabStopIndex = 0;
534 2205 : if(nDeleted)
535 : {
536 51 : aRet.realloc( aRet.getLength() - nDeleted);
537 : }
538 2205 : return aRet;
539 : }
540 :
541 : /*-------------------------------------------------------------------------
542 : returns a the value from the current paragraph style - if available
543 : TODO: What about parent styles?
544 : -----------------------------------------------------------------------*/
545 1174 : uno::Any DomainMapper_Impl::GetPropertyFromStyleSheet(PropertyIds eId)
546 : {
547 1174 : StyleSheetEntryPtr pEntry;
548 1174 : if( m_bInStyleSheetImport )
549 0 : pEntry = GetStyleSheetTable()->FindParentStyleSheet(OUString());
550 : else
551 2348 : pEntry =
552 1174 : GetStyleSheetTable()->FindStyleSheetByISTD(GetCurrentParaStyleId());
553 3665 : while(pEntry.get( ) )
554 : {
555 : //is there a tab stop set?
556 1381 : if(pEntry->pProperties)
557 : {
558 : PropertyMap::const_iterator aPropertyIter =
559 1381 : pEntry->pProperties->find(eId);
560 1381 : if( aPropertyIter != pEntry->pProperties->end())
561 : {
562 64 : return aPropertyIter->second.getValue();
563 : }
564 : }
565 : //search until the property is set or no parent is available
566 1317 : StyleSheetEntryPtr pNewEntry = GetStyleSheetTable()->FindParentStyleSheet(pEntry->sBaseStyleIdentifier);
567 :
568 : SAL_WARN_IF( pEntry == pNewEntry, "writerfilter", "circular loop in style hierarchy?");
569 :
570 1317 : if (pEntry == pNewEntry) //fdo#49587
571 0 : break;
572 :
573 1317 : pEntry = pNewEntry;
574 1317 : }
575 1110 : return uno::Any();
576 : }
577 :
578 :
579 1863 : ListsManager::Pointer DomainMapper_Impl::GetListTable()
580 : {
581 1863 : if(!m_pListTable)
582 : m_pListTable.reset(
583 166 : new ListsManager( m_rDMapper, m_xTextFactory ));
584 1863 : return m_pListTable;
585 : }
586 :
587 :
588 351 : void DomainMapper_Impl::deferBreak( BreakType deferredBreakType)
589 : {
590 351 : switch (deferredBreakType)
591 : {
592 : case COLUMN_BREAK:
593 6 : m_bIsColumnBreakDeferred = true;
594 6 : break;
595 : case PAGE_BREAK:
596 : // See SwWW8ImplReader::HandlePageBreakChar(), page break should be
597 : // ignored inside tables.
598 345 : if (m_nTableDepth > 0)
599 17 : return;
600 :
601 328 : m_bIsPageBreakDeferred = true;
602 328 : break;
603 : default:
604 0 : return;
605 : }
606 : }
607 :
608 122274 : bool DomainMapper_Impl::isBreakDeferred( BreakType deferredBreakType )
609 : {
610 122274 : switch (deferredBreakType)
611 : {
612 : case COLUMN_BREAK:
613 60498 : return m_bIsColumnBreakDeferred;
614 : case PAGE_BREAK:
615 61776 : return m_bIsPageBreakDeferred;
616 : default:
617 0 : return false;
618 : }
619 : }
620 :
621 0 : void DomainMapper_Impl::clearDeferredBreak(BreakType deferredBreakType)
622 : {
623 0 : switch (deferredBreakType)
624 : {
625 : case COLUMN_BREAK:
626 0 : m_bIsColumnBreakDeferred = false;
627 0 : break;
628 : case PAGE_BREAK:
629 0 : m_bIsPageBreakDeferred = false;
630 0 : break;
631 : default:
632 0 : break;
633 : }
634 0 : }
635 :
636 60825 : void DomainMapper_Impl::clearDeferredBreaks()
637 : {
638 60825 : m_bIsColumnBreakDeferred = false;
639 60825 : m_bIsPageBreakDeferred = false;
640 60825 : }
641 :
642 :
643 35 : void lcl_MoveBorderPropertiesToFrame(uno::Sequence<beans::PropertyValue>& rFrameProperties,
644 : uno::Reference<text::XTextRange> xStartTextRange,
645 : uno::Reference<text::XTextRange> xEndTextRange )
646 : {
647 : try
648 : {
649 35 : if (!xStartTextRange.is()) //rhbz#1077780
650 0 : return;
651 35 : uno::Reference<text::XTextCursor> xRangeCursor = xStartTextRange->getText()->createTextCursorByRange( xStartTextRange );
652 35 : xRangeCursor->gotoRange( xEndTextRange, true );
653 :
654 70 : uno::Reference<beans::XPropertySet> xTextRangeProperties(xRangeCursor, uno::UNO_QUERY);
655 35 : if(!xTextRangeProperties.is())
656 0 : return ;
657 :
658 : PropertyIds aBorderProperties[] =
659 : {
660 : PROP_LEFT_BORDER,
661 : PROP_RIGHT_BORDER,
662 : PROP_TOP_BORDER,
663 : PROP_BOTTOM_BORDER,
664 : PROP_LEFT_BORDER_DISTANCE,
665 : PROP_RIGHT_BORDER_DISTANCE,
666 : PROP_TOP_BORDER_DISTANCE,
667 : PROP_BOTTOM_BORDER_DISTANCE
668 35 : };
669 :
670 35 : sal_uInt32 nStart = rFrameProperties.getLength();
671 35 : sal_uInt32 nBorderPropertyCount = sizeof( aBorderProperties ) / sizeof(PropertyIds);
672 35 : rFrameProperties.realloc(nStart + nBorderPropertyCount);
673 :
674 35 : beans::PropertyValue* pFrameProperties = rFrameProperties.getArray();
675 35 : PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
676 315 : for( sal_uInt32 nProperty = 0; nProperty < nBorderPropertyCount; ++nProperty)
677 : {
678 280 : OUString sPropertyName = rPropNameSupplier.GetName(aBorderProperties[nProperty]);
679 280 : pFrameProperties[nStart].Name = sPropertyName;
680 280 : pFrameProperties[nStart].Value = xTextRangeProperties->getPropertyValue(sPropertyName);
681 280 : if( nProperty < 4 )
682 140 : xTextRangeProperties->setPropertyValue( sPropertyName, uno::makeAny(table::BorderLine2()));
683 280 : ++nStart;
684 280 : }
685 70 : rFrameProperties.realloc(nStart);
686 : }
687 0 : catch( const uno::Exception& )
688 : {
689 : }
690 : }
691 :
692 :
693 36 : void lcl_AddRangeAndStyle(
694 : ParagraphPropertiesPtr& pToBeSavedProperties,
695 : uno::Reference< text::XTextAppend > xTextAppend,
696 : PropertyMapPtr pPropertyMap,
697 : TextAppendContext& rAppendContext)
698 : {
699 : uno::Reference<text::XParagraphCursor> xParaCursor(
700 36 : xTextAppend->createTextCursorByRange( rAppendContext.xInsertPosition.is() ? rAppendContext.xInsertPosition : xTextAppend->getEnd()), uno::UNO_QUERY_THROW );
701 36 : pToBeSavedProperties->SetEndingRange(xParaCursor->getStart());
702 36 : xParaCursor->gotoStartOfParagraph( false );
703 :
704 36 : pToBeSavedProperties->SetStartingRange(xParaCursor->getStart());
705 36 : if(pPropertyMap)
706 : {
707 36 : PropertyMap::iterator aParaStyleIter = pPropertyMap->find(PROP_PARA_STYLE_NAME);
708 36 : if( aParaStyleIter != pPropertyMap->end())
709 : {
710 36 : OUString sName;
711 36 : aParaStyleIter->second.getValue() >>= sName;
712 36 : pToBeSavedProperties->SetParaStyleName(sName);
713 : }
714 36 : }
715 36 : }
716 :
717 :
718 : //define some default frame width - 0cm ATM: this allow the frame to be wrapped around the text
719 : #define DEFAULT_FRAME_MIN_WIDTH 0
720 :
721 1362 : void DomainMapper_Impl::CheckUnregisteredFrameConversion( )
722 : {
723 1362 : PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
724 1362 : if (m_aTextAppendStack.empty())
725 0 : return;
726 1362 : TextAppendContext& rAppendContext = m_aTextAppendStack.top();
727 : // n#779642: ignore fly frame inside table as it could lead to messy situations
728 2760 : if( rAppendContext.pLastParagraphProperties.get() && rAppendContext.pLastParagraphProperties->IsFrameMode()
729 1398 : && !getTableManager().isInTable() )
730 : {
731 : try
732 : {
733 : StyleSheetEntryPtr pParaStyle =
734 35 : GetStyleSheetTable()->FindStyleSheetByConvertedStyleName(rAppendContext.pLastParagraphProperties->GetParaStyleName());
735 :
736 70 : uno::Sequence< beans::PropertyValue > aFrameProperties(pParaStyle ? 16: 9);
737 :
738 35 : if ( pParaStyle.get( ) )
739 : {
740 20 : beans::PropertyValue* pFrameProperties = aFrameProperties.getArray();
741 20 : pFrameProperties[0].Name = rPropNameSupplier.GetName(PROP_WIDTH);
742 20 : pFrameProperties[1].Name = rPropNameSupplier.GetName(PROP_HEIGHT);
743 20 : pFrameProperties[2].Name = rPropNameSupplier.GetName(PROP_SIZE_TYPE);
744 20 : pFrameProperties[3].Name = rPropNameSupplier.GetName(PROP_WIDTH_TYPE);
745 20 : pFrameProperties[4].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT);
746 20 : pFrameProperties[5].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT_POSITION);
747 20 : pFrameProperties[6].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT_RELATION);
748 20 : pFrameProperties[7].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT);
749 20 : pFrameProperties[8].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT_POSITION);
750 20 : pFrameProperties[9].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT_RELATION);
751 20 : pFrameProperties[10].Name = rPropNameSupplier.GetName(PROP_SURROUND);
752 20 : pFrameProperties[11].Name = rPropNameSupplier.GetName(PROP_LEFT_MARGIN);
753 20 : pFrameProperties[12].Name = rPropNameSupplier.GetName(PROP_RIGHT_MARGIN);
754 20 : pFrameProperties[13].Name = rPropNameSupplier.GetName(PROP_TOP_MARGIN);
755 20 : pFrameProperties[14].Name = rPropNameSupplier.GetName(PROP_BOTTOM_MARGIN);
756 20 : pFrameProperties[15].Name = rPropNameSupplier.GetName(PROP_BACK_COLOR_TRANSPARENCY);
757 :
758 20 : const ParagraphProperties* pStyleProperties = dynamic_cast<const ParagraphProperties*>( pParaStyle->pProperties.get() );
759 20 : if (!pStyleProperties)
760 0 : return;
761 : sal_Int32 nWidth =
762 20 : rAppendContext.pLastParagraphProperties->Getw() > 0 ?
763 3 : rAppendContext.pLastParagraphProperties->Getw() :
764 23 : pStyleProperties->Getw();
765 20 : bool bAutoWidth = nWidth < 1;
766 20 : if( bAutoWidth )
767 17 : nWidth = DEFAULT_FRAME_MIN_WIDTH;
768 20 : pFrameProperties[0].Value <<= nWidth;
769 :
770 42 : pFrameProperties[1].Value <<=
771 20 : rAppendContext.pLastParagraphProperties->Geth() > 0 ?
772 2 : rAppendContext.pLastParagraphProperties->Geth() :
773 20 : pStyleProperties->Geth();
774 :
775 60 : pFrameProperties[2].Value <<= sal_Int16(
776 20 : rAppendContext.pLastParagraphProperties->GethRule() >= 0 ?
777 2 : rAppendContext.pLastParagraphProperties->GethRule() :
778 38 : pStyleProperties->GethRule() >=0 ? pStyleProperties->GethRule() : text::SizeType::VARIABLE);
779 :
780 20 : pFrameProperties[3].Value <<= bAutoWidth ? text::SizeType::MIN : text::SizeType::FIX;
781 :
782 : sal_Int16 nHoriOrient = sal_Int16(
783 20 : rAppendContext.pLastParagraphProperties->GetxAlign() >= 0 ?
784 9 : rAppendContext.pLastParagraphProperties->GetxAlign() :
785 29 : pStyleProperties->GetxAlign() >= 0 ? pStyleProperties->GetxAlign() : text::HoriOrientation::NONE );
786 20 : pFrameProperties[4].Value <<= nHoriOrient;
787 :
788 44 : pFrameProperties[5].Value <<=
789 20 : rAppendContext.pLastParagraphProperties->IsxValid() ?
790 24 : rAppendContext.pLastParagraphProperties->Getx() : pStyleProperties->Getx();
791 60 : pFrameProperties[6].Value <<= sal_Int16(
792 20 : rAppendContext.pLastParagraphProperties->GethAnchor() >= 0 ?
793 20 : rAppendContext.pLastParagraphProperties->GethAnchor() :
794 20 : pStyleProperties->GethAnchor() );
795 :
796 : sal_Int16 nVertOrient = sal_Int16(
797 20 : rAppendContext.pLastParagraphProperties->GetyAlign() >= 0 ?
798 0 : rAppendContext.pLastParagraphProperties->GetyAlign() :
799 20 : pStyleProperties->GetyAlign() >= 0 ? pStyleProperties->GetyAlign() : text::VertOrientation::NONE );
800 20 : pFrameProperties[7].Value <<= nVertOrient;
801 :
802 60 : pFrameProperties[8].Value <<=
803 20 : rAppendContext.pLastParagraphProperties->IsyValid() ?
804 40 : rAppendContext.pLastParagraphProperties->Gety() : pStyleProperties->Gety();
805 60 : pFrameProperties[9].Value <<= sal_Int16(
806 20 : rAppendContext.pLastParagraphProperties->GetvAnchor() >= 0 ?
807 20 : rAppendContext.pLastParagraphProperties->GetvAnchor() :
808 20 : pStyleProperties->GetvAnchor() );
809 :
810 60 : pFrameProperties[10].Value <<= text::WrapTextMode(
811 20 : rAppendContext.pLastParagraphProperties->GetWrap() >= 0 ?
812 20 : rAppendContext.pLastParagraphProperties->GetWrap() :
813 20 : pStyleProperties->GetWrap());
814 :
815 : /** FDO#73546 : distL & distR should be unsigned intgers <Ecma 20.4.3.6>
816 : Swapped the array elements 11,12 & 13,14 since 11 & 12 are
817 : LEFT & RIGHT margins and 13,14 are TOP and BOTTOM margins respectively.
818 : */
819 : sal_Int32 nRightDist;
820 : sal_Int32 nLeftDist = nRightDist =
821 20 : rAppendContext.pLastParagraphProperties->GethSpace() >= 0 ?
822 1 : rAppendContext.pLastParagraphProperties->GethSpace() :
823 21 : pStyleProperties->GethSpace() >= 0 ? pStyleProperties->GethSpace() : 0;
824 :
825 20 : pFrameProperties[11].Value <<= nHoriOrient == text::HoriOrientation::LEFT ? 0 : nLeftDist;
826 20 : pFrameProperties[12].Value <<= nHoriOrient == text::HoriOrientation::RIGHT ? 0 : nRightDist;
827 :
828 : sal_Int32 nBottomDist;
829 : sal_Int32 nTopDist = nBottomDist =
830 20 : rAppendContext.pLastParagraphProperties->GetvSpace() >= 0 ?
831 0 : rAppendContext.pLastParagraphProperties->GetvSpace() :
832 20 : pStyleProperties->GetvSpace() >= 0 ? pStyleProperties->GetvSpace() : 0;
833 :
834 20 : pFrameProperties[13].Value <<= nVertOrient == text::VertOrientation::TOP ? 0 : nTopDist;
835 20 : pFrameProperties[14].Value <<= nVertOrient == text::VertOrientation::BOTTOM ? 0 : nBottomDist;
836 : // If there is no fill, the Word default is 100% transparency.
837 : // Otherwise CellColorHandler has priority, and this setting
838 : // will be ignored.
839 20 : pFrameProperties[15].Value <<= sal_Int32(100);
840 :
841 : lcl_MoveBorderPropertiesToFrame(aFrameProperties,
842 : rAppendContext.pLastParagraphProperties->GetStartingRange(),
843 20 : rAppendContext.pLastParagraphProperties->GetEndingRange());
844 : }
845 : else
846 : {
847 15 : beans::PropertyValue* pFrameProperties = aFrameProperties.getArray();
848 15 : pFrameProperties[0].Name = rPropNameSupplier.GetName(PROP_WIDTH);
849 15 : pFrameProperties[1].Name = rPropNameSupplier.GetName(PROP_SIZE_TYPE);
850 15 : pFrameProperties[2].Name = rPropNameSupplier.GetName(PROP_WIDTH_TYPE);
851 15 : pFrameProperties[3].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT);
852 15 : pFrameProperties[4].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT);
853 15 : pFrameProperties[5].Name = rPropNameSupplier.GetName(PROP_LEFT_MARGIN);
854 15 : pFrameProperties[6].Name = rPropNameSupplier.GetName(PROP_RIGHT_MARGIN);
855 15 : pFrameProperties[7].Name = rPropNameSupplier.GetName(PROP_TOP_MARGIN);
856 15 : pFrameProperties[8].Name = rPropNameSupplier.GetName(PROP_BOTTOM_MARGIN);
857 :
858 15 : sal_Int32 nWidth = rAppendContext.pLastParagraphProperties->Getw();
859 15 : bool bAutoWidth = nWidth < 1;
860 15 : if( bAutoWidth )
861 0 : nWidth = DEFAULT_FRAME_MIN_WIDTH;
862 15 : pFrameProperties[0].Value <<= nWidth;
863 :
864 45 : pFrameProperties[1].Value <<= sal_Int16(
865 15 : rAppendContext.pLastParagraphProperties->GethRule() >= 0 ?
866 15 : rAppendContext.pLastParagraphProperties->GethRule() :
867 15 : text::SizeType::VARIABLE);
868 :
869 15 : pFrameProperties[2].Value <<= bAutoWidth ? text::SizeType::MIN : text::SizeType::FIX;
870 :
871 : sal_Int16 nHoriOrient = sal_Int16(
872 15 : rAppendContext.pLastParagraphProperties->GetxAlign() >= 0 ?
873 15 : rAppendContext.pLastParagraphProperties->GetxAlign() :
874 30 : text::HoriOrientation::NONE );
875 15 : pFrameProperties[3].Value <<= nHoriOrient;
876 :
877 : sal_Int16 nVertOrient = sal_Int16(
878 15 : rAppendContext.pLastParagraphProperties->GetyAlign() >= 0 ?
879 15 : rAppendContext.pLastParagraphProperties->GetyAlign() :
880 30 : text::VertOrientation::NONE );
881 15 : pFrameProperties[4].Value <<= nVertOrient;
882 :
883 15 : sal_Int32 nVertDist = rAppendContext.pLastParagraphProperties->GethSpace();
884 15 : if( nVertDist < 0 )
885 14 : nVertDist = 0;
886 15 : pFrameProperties[5].Value <<= nVertOrient == text::VertOrientation::TOP ? 0 : nVertDist;
887 15 : pFrameProperties[6].Value <<= nVertOrient == text::VertOrientation::BOTTOM ? 0 : nVertDist;
888 :
889 15 : sal_Int32 nHoriDist = rAppendContext.pLastParagraphProperties->GetvSpace();
890 15 : if( nHoriDist < 0 )
891 14 : nHoriDist = 0;
892 15 : pFrameProperties[7].Value <<= nHoriOrient == text::HoriOrientation::LEFT ? 0 : nHoriDist;
893 15 : pFrameProperties[8].Value <<= nHoriOrient == text::HoriOrientation::RIGHT ? 0 : nHoriDist;
894 :
895 15 : if( rAppendContext.pLastParagraphProperties->Geth() > 0 )
896 : {
897 13 : sal_Int32 nOldSize = aFrameProperties.getLength();
898 13 : aFrameProperties.realloc( nOldSize + 1 );
899 13 : pFrameProperties = aFrameProperties.getArray();
900 13 : pFrameProperties[nOldSize].Name = rPropNameSupplier.GetName(PROP_HEIGHT);
901 13 : pFrameProperties[nOldSize].Value <<= rAppendContext.pLastParagraphProperties->Geth();
902 : }
903 :
904 15 : if( rAppendContext.pLastParagraphProperties->IsxValid() )
905 : {
906 15 : sal_Int32 nOldSize = aFrameProperties.getLength();
907 15 : aFrameProperties.realloc( nOldSize + 1 );
908 15 : pFrameProperties = aFrameProperties.getArray();
909 15 : pFrameProperties[nOldSize].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT_POSITION);
910 15 : pFrameProperties[nOldSize].Value <<= rAppendContext.pLastParagraphProperties->Getx();
911 : }
912 :
913 15 : if( rAppendContext.pLastParagraphProperties->GethAnchor() >= 0 )
914 : {
915 15 : sal_Int32 nOldSize = aFrameProperties.getLength();
916 15 : aFrameProperties.realloc( nOldSize + 1 );
917 15 : pFrameProperties = aFrameProperties.getArray();
918 15 : pFrameProperties[nOldSize].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT_RELATION);
919 30 : pFrameProperties[nOldSize].Value <<= sal_Int16(
920 30 : rAppendContext.pLastParagraphProperties->GethAnchor() );
921 : }
922 :
923 15 : if( rAppendContext.pLastParagraphProperties->IsyValid() )
924 : {
925 15 : sal_Int32 nOldSize = aFrameProperties.getLength();
926 15 : aFrameProperties.realloc( nOldSize + 1 );
927 15 : pFrameProperties = aFrameProperties.getArray();
928 15 : pFrameProperties[nOldSize].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT_POSITION);
929 15 : pFrameProperties[nOldSize].Value <<= rAppendContext.pLastParagraphProperties->Gety();
930 : }
931 :
932 15 : if( rAppendContext.pLastParagraphProperties->GetvAnchor() >= 0 )
933 : {
934 15 : sal_Int32 nOldSize = aFrameProperties.getLength();
935 15 : aFrameProperties.realloc( nOldSize + 1 );
936 15 : pFrameProperties = aFrameProperties.getArray();
937 15 : pFrameProperties[nOldSize].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT_RELATION);
938 30 : pFrameProperties[nOldSize].Value <<= sal_Int16(
939 30 : rAppendContext.pLastParagraphProperties->GetvAnchor() );
940 : }
941 :
942 15 : if( rAppendContext.pLastParagraphProperties->GetWrap() >= 0 )
943 : {
944 1 : sal_Int32 nOldSize = aFrameProperties.getLength();
945 1 : aFrameProperties.realloc( nOldSize + 1 );
946 1 : pFrameProperties = aFrameProperties.getArray();
947 1 : pFrameProperties[nOldSize].Name = rPropNameSupplier.GetName(PROP_SURROUND);
948 2 : pFrameProperties[nOldSize].Value <<= text::WrapTextMode(
949 2 : rAppendContext.pLastParagraphProperties->GetWrap() );
950 : }
951 :
952 : lcl_MoveBorderPropertiesToFrame(aFrameProperties,
953 : rAppendContext.pLastParagraphProperties->GetStartingRange(),
954 15 : rAppendContext.pLastParagraphProperties->GetEndingRange());
955 : }
956 :
957 : //frame conversion has to be executed after table conversion
958 : RegisterFrameConversion(
959 : rAppendContext.pLastParagraphProperties->GetStartingRange(),
960 : rAppendContext.pLastParagraphProperties->GetEndingRange(),
961 70 : aFrameProperties );
962 : }
963 0 : catch( const uno::Exception& )
964 : {
965 : }
966 : }
967 : }
968 :
969 22136 : void DomainMapper_Impl::finishParagraph( PropertyMapPtr pPropertyMap )
970 : {
971 : #ifdef DEBUG_DOMAINMAPPER
972 : dmapper_logger->startElement("finishParagraph");
973 : #endif
974 :
975 22136 : ParagraphPropertyMap* pParaContext = dynamic_cast< ParagraphPropertyMap* >( pPropertyMap.get() );
976 22136 : if (!m_aTextAppendStack.size())
977 22136 : return;
978 22136 : TextAppendContext& rAppendContext = m_aTextAppendStack.top();
979 22136 : uno::Reference< text::XTextAppend > xTextAppend;
980 22136 : if (!m_aTextAppendStack.empty())
981 22136 : xTextAppend = rAppendContext.xTextAppend;
982 22136 : PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
983 :
984 : #ifdef DEBUG_DOMAINMAPPER
985 : dmapper_logger->attribute("isTextAppend", xTextAppend.is());
986 : #endif
987 :
988 22136 : if(xTextAppend.is() && ! getTableManager( ).isIgnore() && pParaContext != NULL)
989 : {
990 : try
991 : {
992 : /*the following combinations of previous and current frame settings can occur:
993 : (1) - no old frame and no current frame -> no special action
994 : (2) - no old frame and current DropCap -> save DropCap for later use, don't call finishParagraph
995 : remove character properties of the DropCap?
996 : (3) - no old frame and current Frame -> save Frame for later use
997 : (4) - old DropCap and no current frame -> add DropCap to the properties of the finished paragraph, delete previous setting
998 : (5) - old DropCap and current frame -> add DropCap to the properties of the finished paragraph, save current frame settings
999 : (6) - old Frame and new DropCap -> add old Frame, save DropCap for later use
1000 : (7) - old Frame and new same Frame -> continue
1001 : (8) - old Frame and new different Frame -> add old Frame, save new Frame for later use
1002 : (9) - old Frame and no current frame -> add old Frame, delete previous settings
1003 :
1004 : old _and_ new DropCap must not occur
1005 : */
1006 :
1007 : bool bIsDropCap =
1008 19814 : pParaContext->IsFrameMode() &&
1009 19814 : sal::static_int_cast<Id>(pParaContext->GetDropCap()) != NS_ooxml::LN_Value_wordprocessingml_ST_DropCap_none;
1010 :
1011 19759 : style::DropCapFormat aDrop;
1012 19759 : ParagraphPropertiesPtr pToBeSavedProperties;
1013 19759 : bool bKeepLastParagraphProperties = false;
1014 19759 : if( bIsDropCap )
1015 : {
1016 : uno::Reference<text::XParagraphCursor> xParaCursor(
1017 0 : xTextAppend->createTextCursorByRange(xTextAppend->getEnd()), uno::UNO_QUERY_THROW);
1018 : //select paragraph
1019 0 : xParaCursor->gotoStartOfParagraph( true );
1020 0 : uno::Reference< beans::XPropertyState > xParaProperties( xParaCursor, uno::UNO_QUERY_THROW );
1021 0 : xParaProperties->setPropertyToDefault(rPropNameSupplier.GetName(PROP_CHAR_ESCAPEMENT));
1022 0 : xParaProperties->setPropertyToDefault(rPropNameSupplier.GetName(PROP_CHAR_HEIGHT));
1023 : //handles (2) and part of (6)
1024 0 : pToBeSavedProperties.reset( new ParagraphProperties(*pParaContext) );
1025 0 : sal_Int32 nCount = xParaCursor->getString().getLength();
1026 0 : pToBeSavedProperties->SetDropCapLength(nCount > 0 && nCount < 255 ? (sal_Int8)nCount : 1);
1027 : }
1028 19759 : if( rAppendContext.pLastParagraphProperties.get() )
1029 : {
1030 50 : if( sal::static_int_cast<Id>(rAppendContext.pLastParagraphProperties->GetDropCap()) != NS_ooxml::LN_Value_wordprocessingml_ST_DropCap_none)
1031 : {
1032 : //handles (4) and part of (5)
1033 : //create a DropCap property, add it to the property sequence of finishParagraph
1034 0 : sal_Int32 nLines = rAppendContext.pLastParagraphProperties->GetLines();
1035 0 : aDrop.Lines = nLines > 0 && nLines < 254 ? (sal_Int8)++nLines : 2;
1036 0 : aDrop.Count = rAppendContext.pLastParagraphProperties->GetDropCapLength();
1037 0 : aDrop.Distance = 0; //TODO: find distance value
1038 : //completes (5)
1039 0 : if( pParaContext->IsFrameMode() )
1040 0 : pToBeSavedProperties.reset( new ParagraphProperties(*pParaContext) );
1041 : }
1042 50 : else if(*rAppendContext.pLastParagraphProperties == *pParaContext )
1043 : {
1044 : //handles (7)
1045 19 : rAppendContext.pLastParagraphProperties->SetEndingRange(rAppendContext.xInsertPosition.is() ? rAppendContext.xInsertPosition : xTextAppend->getEnd());
1046 19 : bKeepLastParagraphProperties = true;
1047 : }
1048 : else
1049 : {
1050 : //handles (8)(9) and completes (6)
1051 31 : CheckUnregisteredFrameConversion( );
1052 :
1053 : // If different frame properties are set on this paragraph, keep them.
1054 31 : if ( !bIsDropCap && pParaContext->IsFrameMode() )
1055 : {
1056 2 : pToBeSavedProperties.reset( new ParagraphProperties(*pParaContext) );
1057 2 : lcl_AddRangeAndStyle(pToBeSavedProperties, xTextAppend, pPropertyMap, rAppendContext);
1058 : }
1059 : }
1060 :
1061 : }
1062 : else
1063 : {
1064 : // (1) doesn't need handling
1065 :
1066 19709 : if( !bIsDropCap && pParaContext->IsFrameMode() )
1067 : {
1068 34 : pToBeSavedProperties.reset( new ParagraphProperties(*pParaContext) );
1069 34 : lcl_AddRangeAndStyle(pToBeSavedProperties, xTextAppend, pPropertyMap, rAppendContext);
1070 : }
1071 : }
1072 39518 : uno::Sequence< beans::PropertyValue > aProperties;
1073 19759 : if( pPropertyMap.get() )
1074 : {
1075 19759 : aProperties = pPropertyMap->GetPropertyValues();
1076 : }
1077 19759 : if( !bIsDropCap )
1078 : {
1079 19759 : if( aDrop.Lines > 1 )
1080 : {
1081 0 : sal_uInt32 nLength = aProperties.getLength();
1082 0 : aProperties.realloc( nLength + 1 );
1083 0 : aProperties[nLength].Value <<= aDrop;
1084 0 : aProperties[nLength].Name = rPropNameSupplier.GetName(PROP_DROP_CAP_FORMAT);
1085 : }
1086 19759 : uno::Reference< text::XTextRange > xTextRange;
1087 19759 : if (rAppendContext.xInsertPosition.is())
1088 : {
1089 3038 : xTextRange = xTextAppend->finishParagraphInsert( aProperties, rAppendContext.xInsertPosition );
1090 3038 : rAppendContext.xCursor->gotoNextParagraph(false);
1091 3038 : if (rAppendContext.pLastParagraphProperties.get())
1092 0 : rAppendContext.pLastParagraphProperties->SetEndingRange(xTextRange->getEnd());
1093 : }
1094 : else
1095 16721 : xTextRange = xTextAppend->finishParagraph( aProperties );
1096 19738 : getTableManager( ).handle(xTextRange);
1097 :
1098 : // Get the end of paragraph character inserted
1099 39476 : uno::Reference< text::XTextCursor > xCur = xTextRange->getText( )->createTextCursor( );
1100 19738 : if (rAppendContext.xInsertPosition.is())
1101 3038 : xCur->gotoRange( rAppendContext.xInsertPosition, false );
1102 : else
1103 16700 : xCur->gotoEnd( false );
1104 19738 : xCur->goLeft( 1 , true );
1105 39476 : uno::Reference< text::XTextRange > xParaEnd( xCur, uno::UNO_QUERY );
1106 19738 : CheckParaMarkerRedline( xParaEnd );
1107 :
1108 19738 : m_bIsFirstParaInSection = false;
1109 19738 : m_bIsLastParaInSection = false;
1110 19738 : m_bParaChanged = false;
1111 :
1112 : // Reset the frame properties for the next paragraph
1113 39497 : pParaContext->ResetFrameProperties();
1114 : }
1115 19738 : if( !bKeepLastParagraphProperties )
1116 39478 : rAppendContext.pLastParagraphProperties = pToBeSavedProperties;
1117 : }
1118 0 : catch(const lang::IllegalArgumentException&)
1119 : {
1120 : OSL_FAIL( "IllegalArgumentException in DomainMapper_Impl::finishParagraph" );
1121 : }
1122 21 : catch(const uno::Exception&)
1123 : {
1124 : }
1125 22136 : }
1126 :
1127 : #ifdef DEBUG_DOMAINMAPPER
1128 : dmapper_logger->endElement();
1129 : #endif
1130 : }
1131 :
1132 34836 : void DomainMapper_Impl::appendTextPortion( const OUString& rString, PropertyMapPtr pPropertyMap )
1133 : {
1134 34836 : if (m_bDiscardHeaderFooter)
1135 54 : return;
1136 :
1137 34809 : if (m_aTextAppendStack.empty())
1138 0 : return;
1139 :
1140 34809 : if( pPropertyMap == m_pTopContext && !deferredCharacterProperties.empty())
1141 15813 : processDeferredCharacterProperties();
1142 34809 : uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend;
1143 34809 : if(xTextAppend.is() && ! getTableManager( ).isIgnore())
1144 : {
1145 : try
1146 : {
1147 : // If we are in comments, then disable CharGrabBag, comment text doesn't support that.
1148 31022 : uno::Sequence< beans::PropertyValue > pValues = pPropertyMap->GetPropertyValues(/*bCharGrabBag=*/!m_bIsInComments);
1149 31022 : sal_Int32 len = pValues.getLength();
1150 :
1151 31022 : if (m_bStartTOC || m_bStartIndex || m_bStartBibliography)
1152 3374 : for( int i =0; i < len; ++i )
1153 : {
1154 1800 : if (pValues[i].Name == "CharHidden")
1155 647 : pValues[i].Value = uno::makeAny(sal_False);
1156 : }
1157 :
1158 62044 : uno::Reference< text::XTextRange > xTextRange;
1159 31022 : if (m_aTextAppendStack.top().xInsertPosition.is())
1160 : {
1161 7497 : xTextRange = xTextAppend->insertTextPortion(rString, pValues, m_aTextAppendStack.top().xInsertPosition);
1162 7497 : m_aTextAppendStack.top().xCursor->gotoRange(xTextRange->getEnd(), true);
1163 : }
1164 : else
1165 : {
1166 23525 : if (m_bStartTOC || m_bStartIndex || m_bStartBibliography || m_bStartGenericField)
1167 : {
1168 127 : m_bStartedTOC = true;
1169 127 : uno::Reference< text::XTextCursor > xTOCTextCursor;
1170 127 : xTOCTextCursor = xTextAppend->getEnd()->getText( )->createTextCursor( );
1171 127 : xTOCTextCursor->gotoEnd(false);
1172 127 : if (xTOCTextCursor.is())
1173 : {
1174 127 : if (m_bStartIndex || m_bStartBibliography || m_bStartGenericField)
1175 87 : xTOCTextCursor->goLeft(1, false);
1176 127 : xTextRange = xTextAppend->insertTextPortion(rString, pValues, xTOCTextCursor);
1177 127 : m_bTextInserted = true;
1178 127 : xTOCTextCursor->gotoRange(xTextRange->getEnd(), true);
1179 127 : mxTOCTextCursor = xTOCTextCursor;
1180 : }
1181 : else
1182 : {
1183 0 : xTextRange = xTextAppend->appendTextPortion(rString, pValues);
1184 0 : xTOCTextCursor = xTextAppend->createTextCursor();
1185 0 : xTOCTextCursor->gotoRange(xTextRange->getEnd(), false);
1186 : }
1187 127 : m_aTextAppendStack.push(TextAppendContext(xTextAppend, xTOCTextCursor));
1188 : }
1189 : else
1190 23398 : xTextRange = xTextAppend->appendTextPortion(rString, pValues);
1191 : }
1192 :
1193 31022 : CheckRedline( xTextRange );
1194 62044 : m_bParaChanged = true;
1195 :
1196 : //getTableManager( ).handle(xTextRange);
1197 : }
1198 0 : catch(const lang::IllegalArgumentException&)
1199 : {
1200 : OSL_FAIL( "IllegalArgumentException in DomainMapper_Impl::appendTextPortion" );
1201 : }
1202 0 : catch(const uno::Exception&)
1203 : {
1204 : OSL_FAIL( "Exception in DomainMapper_Impl::appendTextPortion" );
1205 : }
1206 34809 : }
1207 : }
1208 :
1209 :
1210 2530 : void DomainMapper_Impl::appendTextContent(
1211 : const uno::Reference< text::XTextContent > xContent,
1212 : const uno::Sequence< beans::PropertyValue > xPropertyValues
1213 : )
1214 : {
1215 2530 : uno::Reference< text::XTextAppendAndConvert > xTextAppendAndConvert( m_aTextAppendStack.top().xTextAppend, uno::UNO_QUERY );
1216 : OSL_ENSURE( xTextAppendAndConvert.is(), "trying to append a text content without XTextAppendAndConvert" );
1217 2530 : if(xTextAppendAndConvert.is() && ! getTableManager( ).isIgnore())
1218 : {
1219 : try
1220 : {
1221 2530 : if (m_aTextAppendStack.top().xInsertPosition.is())
1222 114 : xTextAppendAndConvert->insertTextContentWithProperties( xContent, xPropertyValues, m_aTextAppendStack.top().xInsertPosition );
1223 : else
1224 2416 : xTextAppendAndConvert->appendTextContent( xContent, xPropertyValues );
1225 : }
1226 454 : catch(const lang::IllegalArgumentException&)
1227 : {
1228 : }
1229 592 : catch(const uno::Exception&)
1230 : {
1231 : }
1232 2530 : }
1233 2530 : }
1234 :
1235 :
1236 :
1237 22 : void DomainMapper_Impl::appendOLE( const OUString& rStreamName, OLEHandlerPtr pOLEHandler )
1238 : {
1239 22 : static const OUString sEmbeddedService("com.sun.star.text.TextEmbeddedObject");
1240 : try
1241 : {
1242 22 : uno::Reference< text::XTextContent > xOLE( m_xTextFactory->createInstance(sEmbeddedService), uno::UNO_QUERY_THROW );
1243 44 : uno::Reference< beans::XPropertySet > xOLEProperties(xOLE, uno::UNO_QUERY_THROW);
1244 :
1245 44 : xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_STREAM_NAME ),
1246 44 : uno::makeAny( rStreamName ));
1247 22 : awt::Size aSize = pOLEHandler->getSize();
1248 22 : if( !aSize.Width )
1249 0 : aSize.Width = 1000;
1250 22 : if( !aSize.Height )
1251 0 : aSize.Height = 1000;
1252 44 : xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_WIDTH ),
1253 44 : uno::makeAny(aSize.Width));
1254 44 : xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_HEIGHT ),
1255 44 : uno::makeAny(aSize.Height));
1256 :
1257 44 : uno::Reference< graphic::XGraphic > xGraphic = pOLEHandler->getReplacement();
1258 44 : xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_GRAPHIC ),
1259 44 : uno::makeAny(xGraphic));
1260 44 : uno::Reference<beans::XPropertySet> xReplacementProperties(pOLEHandler->getShape(), uno::UNO_QUERY);
1261 22 : if (xReplacementProperties.is())
1262 : {
1263 : OUString pProperties[] = {
1264 : OUString("AnchorType"),
1265 : OUString("Surround"),
1266 : OUString("HoriOrient"),
1267 : OUString("HoriOrientPosition"),
1268 : OUString("VertOrient"),
1269 : OUString("VertOrientPosition")
1270 154 : };
1271 154 : for (size_t i = 0; i < SAL_N_ELEMENTS(pProperties); ++i)
1272 286 : xOLEProperties->setPropertyValue(pProperties[i], xReplacementProperties->getPropertyValue(pProperties[i]));
1273 : }
1274 : else
1275 : // mimic the treatment of graphics here.. it seems anchoring as character
1276 : // gives a better ( visually ) result
1277 0 : xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_ANCHOR_TYPE ), uno::makeAny( text::TextContentAnchorType_AS_CHARACTER ) );
1278 : // remove ( if valid ) associated shape ( used for graphic replacement )
1279 22 : m_aAnchoredStack.top( ).bToRemove = true;
1280 22 : RemoveLastParagraph();
1281 22 : m_aTextAppendStack.pop();
1282 :
1283 :
1284 44 : appendTextContent( xOLE, uno::Sequence< beans::PropertyValue >() );
1285 :
1286 : }
1287 0 : catch( const uno::Exception& )
1288 : {
1289 : OSL_FAIL( "Exception in creation of OLE object" );
1290 : }
1291 :
1292 22 : }
1293 :
1294 266 : void DomainMapper_Impl::appendStarMath( const Value& val )
1295 : {
1296 266 : uno::Reference< embed::XEmbeddedObject > formula;
1297 266 : val.getAny() >>= formula;
1298 266 : if( formula.is() )
1299 : {
1300 266 : static const OUString sEmbeddedService("com.sun.star.text.TextEmbeddedObject");
1301 : try
1302 : {
1303 266 : uno::Reference< text::XTextContent > xStarMath( m_xTextFactory->createInstance(sEmbeddedService), uno::UNO_QUERY_THROW );
1304 532 : uno::Reference< beans::XPropertySet > xStarMathProperties(xStarMath, uno::UNO_QUERY_THROW);
1305 :
1306 532 : xStarMathProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_EMBEDDED_OBJECT ),
1307 532 : val.getAny());
1308 :
1309 532 : uno::Reference< uno::XInterface > xInterface( formula->getComponent(), uno::UNO_QUERY );
1310 266 : Size size( 1000, 1000 );
1311 266 : if( oox::FormulaImportBase* formulaimport = dynamic_cast< oox::FormulaImportBase* >( xInterface.get()))
1312 266 : size = formulaimport->getFormulaSize();
1313 532 : xStarMathProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_WIDTH ),
1314 532 : uno::makeAny( sal_Int32(size.Width())));
1315 532 : xStarMathProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_HEIGHT ),
1316 532 : uno::makeAny( sal_Int32(size.Height())));
1317 : // mimic the treatment of graphics here.. it seems anchoring as character
1318 : // gives a better ( visually ) result
1319 532 : xStarMathProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_ANCHOR_TYPE ),
1320 532 : uno::makeAny( text::TextContentAnchorType_AS_CHARACTER ) );
1321 532 : appendTextContent( xStarMath, uno::Sequence< beans::PropertyValue >() );
1322 : }
1323 0 : catch( const uno::Exception& )
1324 : {
1325 : OSL_FAIL( "Exception in creation of StarMath object" );
1326 : }
1327 266 : }
1328 266 : }
1329 :
1330 58 : uno::Reference< beans::XPropertySet > DomainMapper_Impl::appendTextSectionAfter(
1331 : uno::Reference< text::XTextRange >& xBefore )
1332 : {
1333 58 : uno::Reference< beans::XPropertySet > xRet;
1334 58 : if (m_aTextAppendStack.empty())
1335 0 : return xRet;
1336 116 : uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend;
1337 58 : if(xTextAppend.is())
1338 : {
1339 : try
1340 : {
1341 : uno::Reference< text::XParagraphCursor > xCursor(
1342 58 : xTextAppend->createTextCursorByRange( xBefore ), uno::UNO_QUERY_THROW);
1343 : //the cursor has been moved to the end of the paragraph because of the appendTextPortion() calls
1344 54 : xCursor->gotoStartOfParagraph( false );
1345 54 : if (m_aTextAppendStack.top().xInsertPosition.is())
1346 2 : xCursor->gotoRange( m_aTextAppendStack.top().xInsertPosition, true );
1347 : else
1348 52 : xCursor->gotoEnd( true );
1349 : //the paragraph after this new section is already inserted
1350 54 : xCursor->goLeft(1, true);
1351 54 : static const OUString sSectionService("com.sun.star.text.TextSection");
1352 108 : uno::Reference< text::XTextContent > xSection( m_xTextFactory->createInstance(sSectionService), uno::UNO_QUERY_THROW );
1353 54 : xSection->attach( uno::Reference< text::XTextRange >( xCursor, uno::UNO_QUERY_THROW) );
1354 108 : xRet = uno::Reference< beans::XPropertySet > (xSection, uno::UNO_QUERY );
1355 : }
1356 4 : catch(const uno::Exception&)
1357 : {
1358 : }
1359 :
1360 : }
1361 :
1362 58 : return xRet;
1363 : }
1364 :
1365 809 : void DomainMapper_Impl::PushPageHeaderFooter(bool bHeader, SectionPropertyMap::PageType eType)
1366 : {
1367 809 : const PropertyIds ePropIsOn = bHeader? PROP_HEADER_IS_ON: PROP_FOOTER_IS_ON;
1368 809 : const PropertyIds ePropShared = bHeader? PROP_HEADER_IS_SHARED: PROP_FOOTER_IS_SHARED;
1369 809 : const PropertyIds ePropTextLeft = bHeader? PROP_HEADER_TEXT_LEFT: PROP_FOOTER_TEXT_LEFT;
1370 809 : const PropertyIds ePropText = bHeader? PROP_HEADER_TEXT: PROP_FOOTER_TEXT;
1371 :
1372 809 : m_bInHeaderFooterImport = true;
1373 :
1374 : //get the section context
1375 809 : PropertyMapPtr pContext = DomainMapper_Impl::GetTopContextOfType(CONTEXT_SECTION);
1376 : //ask for the header/footer name of the given type
1377 809 : SectionPropertyMap* pSectionContext = dynamic_cast< SectionPropertyMap* >( pContext.get() );
1378 809 : if(pSectionContext)
1379 : {
1380 : uno::Reference< beans::XPropertySet > xPageStyle =
1381 : pSectionContext->GetPageStyle(
1382 : GetPageStyles(),
1383 : m_xTextFactory,
1384 809 : eType == SectionPropertyMap::PAGE_FIRST );
1385 809 : if (!xPageStyle.is())
1386 809 : return;
1387 : try
1388 : {
1389 809 : bool bLeft = eType == SectionPropertyMap::PAGE_LEFT;
1390 809 : if ((!bLeft && !GetSettingsTable()->GetEvenAndOddHeaders()) || (GetSettingsTable()->GetEvenAndOddHeaders()))
1391 : {
1392 634 : PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
1393 :
1394 : //switch on header/footer use
1395 634 : xPageStyle->setPropertyValue(
1396 : rPropNameSupplier.GetName(ePropIsOn),
1397 634 : uno::makeAny(sal_True));
1398 :
1399 : // If the 'Different Even & Odd Pages' flag is turned on - do not ignore it
1400 : // Even if the 'Even' header/footer is blank - the flag should be imported (so it would look in LO like in Word)
1401 634 : if (GetSettingsTable()->GetEvenAndOddHeaders())
1402 46 : xPageStyle->setPropertyValue(rPropNameSupplier.GetName(ePropShared), uno::makeAny(false));
1403 :
1404 : //set the interface
1405 634 : uno::Reference< text::XText > xText;
1406 634 : xPageStyle->getPropertyValue(rPropNameSupplier.GetName(bLeft? ePropTextLeft: ePropText)) >>= xText;
1407 :
1408 : m_aTextAppendStack.push(TextAppendContext(uno::Reference< text::XTextAppend >(xText, uno::UNO_QUERY_THROW),
1409 634 : m_bIsNewDoc? uno::Reference<text::XTextCursor>(): m_xBodyText->createTextCursorByRange(xText->getStart())));
1410 : }
1411 : else
1412 : {
1413 175 : m_bDiscardHeaderFooter = true;
1414 : }
1415 : }
1416 0 : catch( const uno::Exception& )
1417 : {
1418 809 : }
1419 809 : }
1420 : }
1421 :
1422 396 : void DomainMapper_Impl::PushPageHeader(SectionPropertyMap::PageType eType)
1423 : {
1424 396 : PushPageHeaderFooter(/* bHeader = */ true, eType);
1425 396 : }
1426 :
1427 413 : void DomainMapper_Impl::PushPageFooter(SectionPropertyMap::PageType eType)
1428 : {
1429 413 : PushPageHeaderFooter(/* bHeader = */ false, eType);
1430 413 : }
1431 :
1432 809 : void DomainMapper_Impl::PopPageHeaderFooter()
1433 : {
1434 : //header and footer always have an empty paragraph at the end
1435 : //this has to be removed
1436 809 : RemoveLastParagraph( );
1437 809 : if (!m_aTextAppendStack.empty())
1438 : {
1439 809 : if (!m_bDiscardHeaderFooter)
1440 : {
1441 634 : m_aTextAppendStack.pop();
1442 : }
1443 809 : m_bDiscardHeaderFooter = false;
1444 : }
1445 809 : m_bInHeaderFooterImport = false;
1446 809 : }
1447 :
1448 :
1449 39 : void DomainMapper_Impl::PushFootOrEndnote( bool bIsFootnote )
1450 : {
1451 : try
1452 : {
1453 : // Redlines outside the footnote should not affect footnote content
1454 39 : m_aRedlines.push(std::vector< RedlineParamsPtr >());
1455 :
1456 39 : PropertyMapPtr pTopContext = GetTopContext();
1457 78 : uno::Reference< text::XText > xFootnoteText;
1458 39 : if (GetTextFactory().is())
1459 78 : xFootnoteText.set( GetTextFactory()->createInstance(
1460 : bIsFootnote ?
1461 39 : OUString( "com.sun.star.text.Footnote" ) : OUString( "com.sun.star.text.Endnote" )),
1462 39 : uno::UNO_QUERY_THROW );
1463 78 : uno::Reference< text::XFootnote > xFootnote( xFootnoteText, uno::UNO_QUERY_THROW );
1464 39 : pTopContext->SetFootnote( xFootnote );
1465 39 : if( pTopContext->GetFootnoteSymbol() != 0)
1466 : {
1467 0 : xFootnote->setLabel( OUString( pTopContext->GetFootnoteSymbol() ) );
1468 : }
1469 78 : FontTablePtr pFontTable = GetFontTable();
1470 78 : uno::Sequence< beans::PropertyValue > aFontProperties;
1471 39 : if( pFontTable && pTopContext->GetFootnoteFontId() >= 0 && pFontTable->size() > (size_t)pTopContext->GetFootnoteFontId() )
1472 : {
1473 0 : const FontEntry::Pointer_t pFontEntry(pFontTable->getFontEntry(sal_uInt32(pTopContext->GetFootnoteFontId())));
1474 0 : PropertyMapPtr aFontProps( new PropertyMap );
1475 0 : aFontProps->Insert(PROP_CHAR_FONT_NAME, uno::makeAny( pFontEntry->sFontName ));
1476 0 : aFontProps->Insert(PROP_CHAR_FONT_CHAR_SET, uno::makeAny( (sal_Int16)pFontEntry->nTextEncoding ));
1477 0 : aFontProps->Insert(PROP_CHAR_FONT_PITCH, uno::makeAny( pFontEntry->nPitchRequest ));
1478 0 : aFontProperties = aFontProps->GetPropertyValues();
1479 : }
1480 39 : else if(!pTopContext->GetFootnoteFontName().isEmpty())
1481 : {
1482 0 : PropertyMapPtr aFontProps( new PropertyMap );
1483 0 : aFontProps->Insert(PROP_CHAR_FONT_NAME, uno::makeAny( pTopContext->GetFootnoteFontName() ));
1484 0 : aFontProperties = aFontProps->GetPropertyValues();
1485 : }
1486 39 : appendTextContent( uno::Reference< text::XTextContent >( xFootnoteText, uno::UNO_QUERY_THROW ), aFontProperties );
1487 : m_aTextAppendStack.push(TextAppendContext(uno::Reference< text::XTextAppend >( xFootnoteText, uno::UNO_QUERY_THROW ),
1488 39 : m_bIsNewDoc ? uno::Reference<text::XTextCursor>() : xFootnoteText->createTextCursorByRange(xFootnoteText->getStart())));
1489 :
1490 : // Redlines for the footnote anchor
1491 39 : CheckRedline( xFootnote->getAnchor( ) );
1492 :
1493 : // Word has a leading tab on footnotes, but we don't implement space
1494 : // between the footnote number and text using a tab, so just ignore
1495 : // that for now.
1496 78 : m_bIgnoreNextTab = true;
1497 : }
1498 0 : catch( const uno::Exception& e )
1499 : {
1500 : SAL_WARN("writerfilter", "exception in PushFootOrEndnote: " << e.Message);
1501 : }
1502 39 : }
1503 :
1504 768 : void DomainMapper_Impl::CreateRedline( uno::Reference< text::XTextRange > xRange, RedlineParamsPtr& pRedline )
1505 : {
1506 768 : if ( pRedline.get( ) )
1507 : {
1508 : try
1509 : {
1510 768 : OUString sType;
1511 768 : PropertyNameSupplier & rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier( );
1512 768 : switch ( pRedline->m_nToken & 0xffff )
1513 : {
1514 : case OOXML_mod:
1515 459 : sType = rPropNameSupplier.GetName( PROP_FORMAT );
1516 459 : break;
1517 : case OOXML_ins:
1518 47 : sType = rPropNameSupplier.GetName( PROP_INSERT );
1519 47 : break;
1520 : case OOXML_del:
1521 201 : sType = rPropNameSupplier.GetName( PROP_DELETE );
1522 201 : break;
1523 : case OOXML_ParagraphFormat:
1524 61 : sType = rPropNameSupplier.GetName( PROP_PARAGRAPH_FORMAT );
1525 61 : break;
1526 : default:
1527 0 : throw ::com::sun::star::lang::IllegalArgumentException("illegal redline token type", NULL, 0);
1528 : }
1529 768 : uno::Reference < text::XRedline > xRedline( xRange, uno::UNO_QUERY_THROW );
1530 1536 : beans::PropertyValues aRedlineProperties( 3 );
1531 768 : beans::PropertyValue * pRedlineProperties = aRedlineProperties.getArray( );
1532 768 : pRedlineProperties[0].Name = rPropNameSupplier.GetName( PROP_REDLINE_AUTHOR );
1533 768 : pRedlineProperties[0].Value <<= pRedline->m_sAuthor;
1534 768 : pRedlineProperties[1].Name = rPropNameSupplier.GetName( PROP_REDLINE_DATE_TIME );
1535 768 : pRedlineProperties[1].Value <<= ConversionHelper::ConvertDateStringToDateTime( pRedline->m_sDate );
1536 768 : pRedlineProperties[2].Name = rPropNameSupplier.GetName( PROP_REDLINE_REVERT_PROPERTIES );
1537 768 : pRedlineProperties[2].Value <<= pRedline->m_aRevertProperties;
1538 1536 : xRedline->makeRedline( sType, aRedlineProperties );
1539 : }
1540 92 : catch( const uno::Exception & )
1541 : {
1542 : OSL_FAIL( "Exception in makeRedline" );
1543 : }
1544 : }
1545 768 : }
1546 :
1547 19738 : void DomainMapper_Impl::CheckParaMarkerRedline( uno::Reference< text::XTextRange > xRange )
1548 : {
1549 19738 : if ( m_pParaMarkerRedline.get( ) )
1550 : {
1551 117 : CreateRedline( xRange, m_pParaMarkerRedline );
1552 117 : ResetParaMarkerRedline( );
1553 : }
1554 19738 : }
1555 :
1556 31061 : void DomainMapper_Impl::CheckRedline( uno::Reference< text::XTextRange > xRange )
1557 : {
1558 31061 : vector<RedlineParamsPtr>::iterator pIt = m_aRedlines.top().begin( );
1559 31061 : vector< RedlineParamsPtr > aCleaned;
1560 31712 : for (; pIt != m_aRedlines.top().end( ); ++pIt )
1561 : {
1562 651 : CreateRedline( xRange, *pIt );
1563 :
1564 : // Adding the non-mod redlines to the temporary vector
1565 651 : if ( pIt->get( ) )
1566 : {
1567 651 : if (((*pIt)->m_nToken & 0xffff) != OOXML_mod && ((*pIt)->m_nToken & 0xffff) != OOXML_ParagraphFormat)
1568 131 : aCleaned.push_back(*pIt);
1569 : }
1570 : }
1571 :
1572 31061 : m_aRedlines.top().swap( aCleaned );
1573 31061 : }
1574 :
1575 224 : void DomainMapper_Impl::StartParaMarkerChange( )
1576 : {
1577 224 : m_bIsParaMarkerChange = true;
1578 224 : }
1579 :
1580 912 : void DomainMapper_Impl::EndParaMarkerChange( )
1581 : {
1582 912 : m_bIsParaMarkerChange = false;
1583 912 : }
1584 :
1585 :
1586 :
1587 18 : void DomainMapper_Impl::PushAnnotation()
1588 : {
1589 : try
1590 : {
1591 18 : PropertyMapPtr pTopContext = GetTopContext();
1592 18 : m_bIsInComments = true;
1593 18 : if (!GetTextFactory().is())
1594 18 : return;
1595 54 : m_xAnnotationField = uno::Reference< beans::XPropertySet >( GetTextFactory()->createInstance(
1596 18 : "com.sun.star.text.TextField.Annotation" ),
1597 18 : uno::UNO_QUERY_THROW );
1598 36 : uno::Reference< text::XText > xAnnotationText;
1599 18 : m_xAnnotationField->getPropertyValue("TextRange") >>= xAnnotationText;
1600 : m_aTextAppendStack.push(TextAppendContext(uno::Reference< text::XTextAppend >( xAnnotationText, uno::UNO_QUERY_THROW ),
1601 36 : m_bIsNewDoc ? uno::Reference<text::XTextCursor>() : xAnnotationText->createTextCursorByRange(xAnnotationText->getStart())));
1602 : }
1603 0 : catch( const uno::Exception& rException)
1604 : {
1605 : SAL_WARN("writerfilter", "exception in PushAnnotation: " << rException.Message);
1606 : }
1607 : }
1608 :
1609 :
1610 39 : void DomainMapper_Impl::PopFootOrEndnote()
1611 : {
1612 39 : if (!m_aTextAppendStack.empty())
1613 39 : m_aTextAppendStack.pop();
1614 :
1615 39 : if (m_aRedlines.size() == 1)
1616 : {
1617 : SAL_WARN("writerfilter", "PopFootOrEndnote() is called without PushFootOrEndnote()?");
1618 39 : return;
1619 : }
1620 39 : m_aRedlines.pop();
1621 : }
1622 :
1623 :
1624 18 : void DomainMapper_Impl::PopAnnotation()
1625 : {
1626 18 : RemoveLastParagraph();
1627 :
1628 18 : m_bIsInComments = false;
1629 18 : m_aTextAppendStack.pop();
1630 :
1631 : try
1632 : {
1633 : // See if the annotation will be a single position or a range.
1634 18 : if (m_nAnnotationId == -1 || !m_aAnnotationPositions[m_nAnnotationId].m_xStart.is() || !m_aAnnotationPositions[m_nAnnotationId].m_xEnd.is())
1635 : {
1636 2 : uno::Sequence< beans::PropertyValue > aEmptyProperties;
1637 2 : appendTextContent( uno::Reference< text::XTextContent >( m_xAnnotationField, uno::UNO_QUERY_THROW ), aEmptyProperties );
1638 : }
1639 : else
1640 : {
1641 16 : AnnotationPosition& aAnnotationPosition = m_aAnnotationPositions[m_nAnnotationId];
1642 : // Create a range that points to the annotation start/end.
1643 16 : uno::Reference<text::XText> const xText = aAnnotationPosition.m_xStart->getText();
1644 32 : uno::Reference<text::XTextCursor> const xCursor = xText->createTextCursorByRange(aAnnotationPosition.m_xStart);
1645 16 : xCursor->gotoRange(aAnnotationPosition.m_xEnd, true);
1646 32 : uno::Reference<text::XTextRange> const xTextRange(xCursor, uno::UNO_QUERY_THROW);
1647 :
1648 : // Attach the annotation to the range.
1649 32 : uno::Reference<text::XTextAppend> const xTextAppend = m_aTextAppendStack.top().xTextAppend;
1650 32 : xTextAppend->insertTextContent(xTextRange, uno::Reference<text::XTextContent>(m_xAnnotationField, uno::UNO_QUERY_THROW), !xCursor->isCollapsed());
1651 : }
1652 18 : m_aAnnotationPositions.erase( m_nAnnotationId );
1653 : }
1654 0 : catch (uno::Exception const& e)
1655 : {
1656 : SAL_WARN("writerfilter",
1657 : "Cannot insert annotation field: exception: " << e.Message);
1658 : }
1659 :
1660 18 : m_xAnnotationField.clear();
1661 18 : m_nAnnotationId = -1;
1662 18 : }
1663 :
1664 65 : void DomainMapper_Impl::PushPendingShape( const uno::Reference< drawing::XShape > xShape )
1665 : {
1666 65 : m_aPendingShapes.push_back(xShape);
1667 65 : }
1668 :
1669 39 : uno::Reference<drawing::XShape> DomainMapper_Impl::PopPendingShape()
1670 : {
1671 39 : uno::Reference<drawing::XShape> xRet;
1672 39 : if (!m_aPendingShapes.empty())
1673 : {
1674 39 : xRet = m_aPendingShapes.front();
1675 39 : m_aPendingShapes.pop_front();
1676 : }
1677 39 : return xRet;
1678 : }
1679 :
1680 951 : void DomainMapper_Impl::PushShapeContext( const uno::Reference< drawing::XShape > xShape )
1681 : {
1682 951 : if (m_aTextAppendStack.empty())
1683 951 : return;
1684 951 : uno::Reference<text::XTextAppend> xTextAppend = m_aTextAppendStack.top().xTextAppend;
1685 :
1686 951 : appendTableManager( );
1687 951 : appendTableHandler( );
1688 951 : getTableManager().startLevel();
1689 : try
1690 : {
1691 951 : uno::Reference< lang::XServiceInfo > xSInfo( xShape, uno::UNO_QUERY_THROW );
1692 950 : if (xSInfo->supportsService("com.sun.star.drawing.GroupShape"))
1693 : {
1694 : // A GroupShape doesn't implement text::XTextRange, but appending
1695 : // an empty reference to the stacks still makes sense, because this
1696 : // way bToRemove can be set, and we won't end up with duplicated
1697 : // shapes for OLE objects.
1698 94 : m_aTextAppendStack.push(TextAppendContext(uno::Reference<text::XTextAppend>(xShape, uno::UNO_QUERY), uno::Reference<text::XTextCursor>()));
1699 94 : uno::Reference<text::XTextContent> xTxtContent(xShape, uno::UNO_QUERY);
1700 94 : m_aAnchoredStack.push(xTxtContent);
1701 : }
1702 856 : else if (xSInfo->supportsService("com.sun.star.drawing.OLE2Shape"))
1703 : {
1704 : // OLE2Shape from oox should be converted to a TextEmbeddedObject for sw.
1705 53 : m_aTextAppendStack.push(TextAppendContext(uno::Reference<text::XTextAppend>(xShape, uno::UNO_QUERY), uno::Reference<text::XTextCursor>()));
1706 53 : uno::Reference<text::XTextContent> xTextContent(xShape, uno::UNO_QUERY);
1707 53 : m_aAnchoredStack.push(xTextContent);
1708 106 : uno::Reference<beans::XPropertySet> xShapePropertySet(xShape, uno::UNO_QUERY);
1709 :
1710 53 : PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
1711 :
1712 53 : m_xEmbedded.set(m_xTextFactory->createInstance("com.sun.star.text.TextEmbeddedObject"), uno::UNO_QUERY_THROW);
1713 106 : uno::Reference<beans::XPropertySet> xEmbeddedProperties(m_xEmbedded, uno::UNO_QUERY_THROW);
1714 53 : xEmbeddedProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_EMBEDDED_OBJECT), xShapePropertySet->getPropertyValue(rPropNameSupplier.GetName(PROP_EMBEDDED_OBJECT)));
1715 53 : xEmbeddedProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_ANCHOR_TYPE), uno::makeAny(text::TextContentAnchorType_AS_CHARACTER));
1716 : // So that the original bitmap-only shape will be replaced by the embedded object.
1717 53 : m_aAnchoredStack.top().bToRemove = true;
1718 53 : m_aTextAppendStack.pop();
1719 106 : appendTextContent(m_xEmbedded, uno::Sequence<beans::PropertyValue>());
1720 : }
1721 : else
1722 : {
1723 803 : uno::Reference< text::XTextRange > xShapeText( xShape, uno::UNO_QUERY_THROW);
1724 : // Add the shape to the text append stack
1725 : m_aTextAppendStack.push( TextAppendContext(uno::Reference< text::XTextAppend >( xShape, uno::UNO_QUERY_THROW ),
1726 803 : m_bIsNewDoc ? uno::Reference<text::XTextCursor>() : m_xBodyText->createTextCursorByRange(xShapeText->getStart() )));
1727 :
1728 : // Add the shape to the anchored objects stack
1729 1606 : uno::Reference< text::XTextContent > xTxtContent( xShape, uno::UNO_QUERY_THROW );
1730 803 : m_aAnchoredStack.push( xTxtContent );
1731 :
1732 803 : PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
1733 :
1734 1606 : uno::Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY_THROW );
1735 : #ifdef DEBUG_DOMAINMAPPER
1736 : dmapper_logger->unoPropertySet(xProps);
1737 : #endif
1738 803 : text::TextContentAnchorType nAnchorType(text::TextContentAnchorType_AT_PARAGRAPH);
1739 803 : xProps->getPropertyValue(rPropNameSupplier.GetName( PROP_ANCHOR_TYPE )) >>= nAnchorType;
1740 :
1741 803 : if (!m_bInHeaderFooterImport)
1742 707 : xProps->setPropertyValue(
1743 : rPropNameSupplier.GetName( PROP_OPAQUE ),
1744 707 : uno::makeAny( true ) );
1745 803 : if (xSInfo->supportsService("com.sun.star.text.TextFrame"))
1746 : {
1747 : // Extract the special "btLr text frame" mode, requested by oox, if needed.
1748 : // Extract vml ZOrder from FrameInteropGrabBag
1749 359 : uno::Reference<beans::XPropertySet> xShapePropertySet(xShape, uno::UNO_QUERY);
1750 718 : uno::Sequence<beans::PropertyValue> aGrabBag;
1751 359 : xShapePropertySet->getPropertyValue("FrameInteropGrabBag") >>= aGrabBag;
1752 359 : bool checkBtLrStatus = false;bool checkZOredrStatus = false;
1753 :
1754 680 : for (int i = 0; i < aGrabBag.getLength(); ++i)
1755 : {
1756 322 : if (aGrabBag[i].Name == "mso-layout-flow-alt")
1757 : {
1758 1 : m_bFrameBtLr = aGrabBag[i].Value.get<OUString>() == "bottom-to-top";
1759 1 : checkBtLrStatus = true;
1760 : }
1761 322 : if (aGrabBag[i].Name == "VML-Z-ORDER")
1762 : {
1763 30 : GraphicZOrderHelper* pZOrderHelper = m_rDMapper.graphicZOrderHelper();
1764 30 : sal_Int32 zOrder(0);
1765 30 : aGrabBag[i].Value >>= zOrder;
1766 30 : xShapePropertySet->setPropertyValue( "ZOrder", uno::makeAny(pZOrderHelper->findZOrder(zOrder)));
1767 30 : pZOrderHelper->addItem(xShapePropertySet, zOrder);
1768 30 : checkZOredrStatus = true;
1769 : }
1770 322 : if(checkBtLrStatus && checkZOredrStatus)
1771 1 : break;
1772 : }
1773 :
1774 718 : uno::Reference<text::XTextContent> xTextContent(xShape, uno::UNO_QUERY_THROW);
1775 718 : uno::Reference<text::XTextRange> xTextRange(xTextAppend->createTextCursorByRange(xTextAppend->getEnd()), uno::UNO_QUERY_THROW);
1776 359 : xTextAppend->insertTextContent(xTextRange, xTextContent, sal_False);
1777 :
1778 718 : uno::Reference<beans::XPropertySet> xPropertySet(xTextContent, uno::UNO_QUERY);
1779 : // we need to re-set this value to xTextContent, then only values are preserved.
1780 718 : xPropertySet->setPropertyValue("FrameInteropGrabBag",uno::makeAny(aGrabBag));
1781 : }
1782 444 : else if (nAnchorType == text::TextContentAnchorType_AS_CHARACTER)
1783 : {
1784 : // Fix spacing for as-character objects. If the paragraph has CT_Spacing_after set,
1785 : // it needs to be set on the object too, as that's what object placement code uses.
1786 61 : PropertyMapPtr paragraphContext = GetTopContextOfType( CONTEXT_PARAGRAPH );
1787 61 : PropertyMap::const_iterator pos = paragraphContext->find(PROP_PARA_BOTTOM_MARGIN);
1788 61 : if( pos != paragraphContext->end())
1789 13 : xProps->setPropertyValue( rPropNameSupplier.GetName( PROP_BOTTOM_MARGIN ), (*pos).second.getValue() );
1790 803 : }
1791 950 : }
1792 : }
1793 1 : catch ( const uno::Exception& e )
1794 : {
1795 : SAL_WARN("writerfilter", "Exception when adding shape: " << e.Message);
1796 951 : }
1797 : }
1798 : /*
1799 : * Updating chart height and width after reading the actual values from wp:extent
1800 : */
1801 72 : void DomainMapper_Impl::UpdateEmbeddedShapeProps(const uno::Reference< drawing::XShape > xShape)
1802 : {
1803 72 : if (!xShape.is())
1804 77 : return;
1805 :
1806 67 : PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
1807 67 : uno::Reference<beans::XPropertySet> xEmbeddedProperties(m_xEmbedded, uno::UNO_QUERY_THROW);
1808 67 : awt::Size aSize = xShape->getSize( );
1809 67 : xEmbeddedProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_WIDTH), uno::makeAny(sal_Int32(aSize.Width)));
1810 67 : xEmbeddedProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_HEIGHT), uno::makeAny(sal_Int32(aSize.Height)));
1811 : }
1812 :
1813 :
1814 951 : void DomainMapper_Impl::PopShapeContext()
1815 : {
1816 951 : getTableManager().endLevel();
1817 951 : popTableManager();
1818 951 : if ( m_aAnchoredStack.size() > 0 )
1819 : {
1820 : // For OLE object replacement shape, the text append context was already removed
1821 : // or the OLE object couldn't be inserted.
1822 950 : if ( !m_aAnchoredStack.top().bToRemove )
1823 : {
1824 875 : RemoveLastParagraph();
1825 875 : m_aTextAppendStack.pop();
1826 : }
1827 :
1828 950 : uno::Reference< text::XTextContent > xObj = m_aAnchoredStack.top( ).xTextContent;
1829 : try
1830 : {
1831 950 : appendTextContent( xObj, uno::Sequence< beans::PropertyValue >() );
1832 : }
1833 0 : catch ( const uno::RuntimeException& )
1834 : {
1835 : // this is normal: the shape is already attached
1836 : }
1837 :
1838 : // Remove the shape if required (most likely replacement shape for OLE object)
1839 950 : if ( m_aAnchoredStack.top().bToRemove )
1840 : {
1841 : try
1842 : {
1843 75 : uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(m_xTextDocument, uno::UNO_QUERY_THROW);
1844 150 : uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
1845 75 : if ( xDrawPage.is() )
1846 : {
1847 75 : uno::Reference<drawing::XShape> xShape( xObj, uno::UNO_QUERY_THROW );
1848 75 : xDrawPage->remove( xShape );
1849 75 : }
1850 : }
1851 0 : catch( const uno::Exception& )
1852 : {
1853 : }
1854 : }
1855 950 : m_aAnchoredStack.pop();
1856 : }
1857 951 : m_bFrameBtLr = false;
1858 951 : }
1859 :
1860 222 : sal_Int16 lcl_ParseNumberingType( const OUString& rCommand )
1861 : {
1862 222 : sal_Int16 nRet = style::NumberingType::PAGE_DESCRIPTOR;
1863 :
1864 : // The command looks like: " PAGE \* Arabic "
1865 222 : OUString sNumber = msfilter::util::findQuotedText(rCommand, "\\* ", ' ');
1866 :
1867 222 : if( !sNumber.isEmpty() )
1868 : {
1869 : //todo: might make sense to hash this list, too
1870 : struct NumberingPairs
1871 : {
1872 : const sal_Char* cWordName;
1873 : sal_Int16 nType;
1874 : };
1875 : static const NumberingPairs aNumberingPairs[] =
1876 : {
1877 : {"Arabic", style::NumberingType::ARABIC}
1878 : ,{"ROMAN", style::NumberingType::ROMAN_UPPER}
1879 : ,{"roman", style::NumberingType::ROMAN_LOWER}
1880 : ,{"ALPHABETIC", style::NumberingType::CHARS_UPPER_LETTER}
1881 : ,{"alphabetic", style::NumberingType::CHARS_LOWER_LETTER}
1882 : ,{"CircleNum", style::NumberingType::CIRCLE_NUMBER}
1883 : ,{"ThaiArabic", style::NumberingType::CHARS_THAI}
1884 : ,{"ThaiCardText", style::NumberingType::CHARS_THAI}
1885 : ,{"ThaiLetter", style::NumberingType::CHARS_THAI}
1886 : // ,{"SBCHAR", style::NumberingType::}
1887 : // ,{"DBCHAR", style::NumberingType::}
1888 : // ,{"DBNUM1", style::NumberingType::}
1889 : // ,{"DBNUM2", style::NumberingType::}
1890 : // ,{"DBNUM3", style::NumberingType::}
1891 : // ,{"DBNUM4", style::NumberingType::}
1892 : ,{"Aiueo", style::NumberingType::AIU_FULLWIDTH_JA}
1893 : ,{"Iroha", style::NumberingType::IROHA_FULLWIDTH_JA}
1894 : // ,{"ZODIAC1", style::NumberingType::}
1895 : // ,{"ZODIAC2", style::NumberingType::}
1896 : // ,{"ZODIAC3", style::NumberingType::}
1897 : // ,{"CHINESENUM1", style::NumberingType::}
1898 : // ,{"CHINESENUM2", style::NumberingType::}
1899 : // ,{"CHINESENUM3", style::NumberingType::}
1900 : ,{"ArabicAlpha", style::NumberingType::CHARS_ARABIC}
1901 : ,{"ArabicAbjad", style::NumberingType::FULLWIDTH_ARABIC}
1902 : /* possible values:
1903 : style::NumberingType::
1904 :
1905 : CHARS_UPPER_LETTER_N
1906 : CHARS_LOWER_LETTER_N
1907 : TRANSLITERATION
1908 : NATIVE_NUMBERING
1909 : CIRCLE_NUMBER
1910 : NUMBER_LOWER_ZH
1911 : NUMBER_UPPER_ZH
1912 : NUMBER_UPPER_ZH_TW
1913 : TIAN_GAN_ZH
1914 : DI_ZI_ZH
1915 : NUMBER_TRADITIONAL_JA
1916 : AIU_HALFWIDTH_JA
1917 : IROHA_HALFWIDTH_JA
1918 : NUMBER_UPPER_KO
1919 : NUMBER_HANGUL_KO
1920 : HANGUL_JAMO_KO
1921 : HANGUL_SYLLABLE_KO
1922 : HANGUL_CIRCLED_JAMO_KO
1923 : HANGUL_CIRCLED_SYLLABLE_KO
1924 : CHARS_HEBREW
1925 : CHARS_NEPALI
1926 : CHARS_KHMER
1927 : CHARS_LAO
1928 : CHARS_TIBETAN
1929 : CHARS_CYRILLIC_UPPER_LETTER_BG
1930 : CHARS_CYRILLIC_LOWER_LETTER_BG
1931 : CHARS_CYRILLIC_UPPER_LETTER_N_BG
1932 : CHARS_CYRILLIC_LOWER_LETTER_N_BG
1933 : CHARS_CYRILLIC_UPPER_LETTER_RU
1934 : CHARS_CYRILLIC_LOWER_LETTER_RU
1935 : CHARS_CYRILLIC_UPPER_LETTER_N_RU
1936 : CHARS_CYRILLIC_LOWER_LETTER_N_RU
1937 : CHARS_CYRILLIC_UPPER_LETTER_SR
1938 : CHARS_CYRILLIC_LOWER_LETTER_SR
1939 : CHARS_CYRILLIC_UPPER_LETTER_N_SR
1940 : CHARS_CYRILLIC_LOWER_LETTER_N_SR*/
1941 :
1942 : };
1943 1526 : for( sal_uInt32 nNum = 0; nNum < sizeof(aNumberingPairs)/sizeof( NumberingPairs ); ++nNum)
1944 : {
1945 1418 : if( /*sCommand*/sNumber.equalsAscii(aNumberingPairs[nNum].cWordName ))
1946 : {
1947 8 : nRet = aNumberingPairs[nNum].nType;
1948 8 : break;
1949 : }
1950 : }
1951 :
1952 : }
1953 222 : return nRet;
1954 : }
1955 :
1956 :
1957 14 : OUString lcl_ParseFormat( const OUString& rCommand )
1958 : {
1959 : // The command looks like: " DATE \@ "dd MMMM yyyy"
1960 14 : return msfilter::util::findQuotedText(rCommand, "\\@ \"", '\"');
1961 : }
1962 : /*-------------------------------------------------------------------------
1963 : extract a parameter (with or without quotes) between the command and the following backslash
1964 : -----------------------------------------------------------------------*/
1965 6089 : static OUString lcl_ExtractToken(OUString const& rCommand,
1966 : sal_Int32 & rIndex, bool & rHaveToken, bool & rIsSwitch)
1967 : {
1968 6089 : rHaveToken = false;
1969 6089 : rIsSwitch = false;
1970 :
1971 6089 : OUStringBuffer token;
1972 6089 : bool bQuoted(false);
1973 73152 : for (; rIndex < rCommand.getLength(); ++rIndex)
1974 : {
1975 72590 : sal_Unicode const currentChar(rCommand[rIndex]);
1976 72590 : switch (currentChar)
1977 : {
1978 : case '\\':
1979 : {
1980 1196 : if (rIndex == rCommand.getLength() - 1)
1981 : {
1982 : SAL_INFO("writerfilter.dmapper", "field: trailing escape");
1983 0 : ++rIndex;
1984 0 : return OUString();
1985 : }
1986 1196 : sal_Unicode const nextChar(rCommand[rIndex+1]);
1987 1196 : if (bQuoted || '\\' == nextChar)
1988 : {
1989 9 : ++rIndex; // read 2 chars
1990 9 : token.append(nextChar);
1991 : }
1992 : else // field switch (case insensitive)
1993 : {
1994 1187 : rHaveToken = true;
1995 1187 : if (token.isEmpty())
1996 : {
1997 1183 : rIsSwitch = true;
1998 1183 : rIndex += 2; // read 2 chars
1999 1183 : return rCommand.copy(rIndex - 2, 2).toAsciiUpperCase();
2000 : }
2001 : else
2002 : { // leave rIndex, read it again next time
2003 4 : return token.makeStringAndClear();
2004 : }
2005 : }
2006 : }
2007 9 : break;
2008 : case '\"':
2009 3437 : if (bQuoted || !token.isEmpty())
2010 : {
2011 1784 : rHaveToken = true;
2012 1784 : if (bQuoted)
2013 : {
2014 1652 : ++rIndex;
2015 : }
2016 1784 : return token.makeStringAndClear();
2017 : }
2018 : else
2019 : {
2020 1653 : bQuoted = true;
2021 : }
2022 1653 : break;
2023 : case ' ':
2024 6352 : if (bQuoted)
2025 : {
2026 232 : token.append(' ');
2027 : }
2028 : else
2029 : {
2030 6120 : if (!token.isEmpty())
2031 : {
2032 2556 : rHaveToken = true;
2033 2556 : ++rIndex;
2034 2556 : return token.makeStringAndClear();
2035 : }
2036 : }
2037 3796 : break;
2038 : default:
2039 61605 : token.append(currentChar);
2040 61605 : break;
2041 : }
2042 : }
2043 : assert(rIndex == rCommand.getLength());
2044 562 : if (bQuoted)
2045 : {
2046 : SAL_INFO("writerfilter.dmapper",
2047 : "field argument with unterminated quote");
2048 1 : return OUString();
2049 : }
2050 : else
2051 : {
2052 561 : rHaveToken = !token.isEmpty();
2053 561 : return token.makeStringAndClear();
2054 6089 : }
2055 : }
2056 :
2057 : SAL_DLLPUBLIC_EXPORT // export just for test
2058 : boost::tuple<OUString, vector<OUString>, vector<OUString> >
2059 1877 : lcl_SplitFieldCommand(const OUString& rCommand)
2060 : {
2061 1877 : OUString sType;
2062 3754 : vector<OUString> arguments;
2063 3754 : vector<OUString> switches;
2064 1877 : sal_Int32 nStartIndex(0);
2065 :
2066 6089 : do
2067 : {
2068 : bool bHaveToken;
2069 : bool bIsSwitch;
2070 : OUString const token =
2071 6089 : lcl_ExtractToken(rCommand, nStartIndex, bHaveToken, bIsSwitch);
2072 : assert(nStartIndex <= rCommand.getLength());
2073 6089 : if (bHaveToken)
2074 : {
2075 5572 : if (sType.isEmpty())
2076 : {
2077 1877 : sType = token.toAsciiUpperCase();
2078 : }
2079 3695 : else if (bIsSwitch || !switches.empty())
2080 : {
2081 1831 : switches.push_back(token);
2082 : }
2083 : else
2084 : {
2085 1864 : arguments.push_back(token);
2086 : }
2087 6089 : }
2088 6089 : } while (nStartIndex < rCommand.getLength());
2089 :
2090 3754 : return boost::make_tuple(sType, arguments, switches);
2091 : }
2092 :
2093 :
2094 1 : OUString lcl_ExctractAskVariableAndHint( const OUString& rCommand, OUString& rHint )
2095 : {
2096 : // the first word after "ASK " is the variable
2097 : // the text after the variable and before a '\' is the hint
2098 : // if no hint is set the variable is used as hint
2099 : // the quotes of the hint have to be removed
2100 1 : sal_Int32 nIndex = rCommand.indexOf( ' ', 2); //find last space after 'ASK'
2101 1 : if (nIndex == -1)
2102 0 : return OUString();
2103 3 : while(rCommand[nIndex] == ' ')
2104 1 : ++nIndex;
2105 1 : OUString sShortCommand( rCommand.copy( nIndex ) ); //cut off the " ASK "
2106 :
2107 1 : nIndex = 0;
2108 1 : sShortCommand = sShortCommand.getToken( 0, '\\', nIndex);
2109 1 : nIndex = 0;
2110 2 : OUString sRet = sShortCommand.getToken( 0, ' ', nIndex);
2111 1 : if( nIndex > 0)
2112 1 : rHint = sShortCommand.copy( nIndex );
2113 1 : if( rHint.isEmpty() )
2114 0 : rHint = sRet;
2115 2 : return sRet;
2116 : }
2117 :
2118 :
2119 796 : bool lcl_FindInCommand(
2120 : const OUString& rCommand,
2121 : sal_Unicode cSwitch,
2122 : OUString& rValue )
2123 : {
2124 796 : bool bRet = false;
2125 796 : OUString sSearch('\\');
2126 796 : sSearch += OUString( cSwitch );
2127 796 : sal_Int32 nIndex = rCommand.indexOf( sSearch );
2128 796 : if( nIndex >= 0 )
2129 : {
2130 174 : bRet = true;
2131 : //find next '\' or end of string
2132 174 : sal_Int32 nEndIndex = rCommand.indexOf( '\\', nIndex + 1);
2133 174 : if( nEndIndex < 0 )
2134 41 : nEndIndex = rCommand.getLength() - 1;
2135 174 : if( nEndIndex - nIndex > 3 )
2136 61 : rValue = rCommand.copy( nIndex + 3, nEndIndex - nIndex - 3);
2137 : }
2138 796 : return bRet;
2139 : }
2140 :
2141 :
2142 14 : void DomainMapper_Impl::GetCurrentLocale(lang::Locale& rLocale)
2143 : {
2144 14 : PropertyMapPtr pTopContext = GetTopContext();
2145 14 : PropertyMap::iterator aLocaleIter = pTopContext->find(PROP_CHAR_LOCALE);
2146 14 : if( aLocaleIter != pTopContext->end())
2147 0 : aLocaleIter->second.getValue() >>= rLocale;
2148 : else
2149 : {
2150 14 : PropertyMapPtr pParaContext = GetTopContextOfType(CONTEXT_PARAGRAPH);
2151 14 : aLocaleIter = pParaContext->find(PROP_CHAR_LOCALE);
2152 14 : if( aLocaleIter != pParaContext->end())
2153 : {
2154 1 : aLocaleIter->second.getValue() >>= rLocale;
2155 14 : }
2156 14 : }
2157 14 : }
2158 :
2159 : /*-------------------------------------------------------------------------
2160 : extract the number format from the command and apply the resulting number
2161 : format to the XPropertySet
2162 : -----------------------------------------------------------------------*/
2163 14 : void DomainMapper_Impl::SetNumberFormat( const OUString& rCommand,
2164 : uno::Reference< beans::XPropertySet >& xPropertySet )
2165 : {
2166 14 : OUString sFormatString = lcl_ParseFormat( rCommand );
2167 : // find \h - hijri/luna calendar todo: what about saka/era calendar?
2168 14 : bool bHijri = 0 < rCommand.indexOf("\\h ");
2169 28 : lang::Locale aUSLocale;
2170 14 : aUSLocale.Language = "en";
2171 14 : aUSLocale.Country = "US";
2172 :
2173 : //determine current locale - todo: is it necessary to initialize this locale?
2174 28 : lang::Locale aCurrentLocale = aUSLocale;
2175 14 : GetCurrentLocale( aCurrentLocale );
2176 28 : OUString sFormat = ConversionHelper::ConvertMSFormatStringToSO( sFormatString, aCurrentLocale, bHijri);
2177 : //get the number formatter and convert the string to a format value
2178 : try
2179 : {
2180 14 : uno::Reference< util::XNumberFormatsSupplier > xNumberSupplier( m_xTextDocument, uno::UNO_QUERY_THROW );
2181 20 : sal_Int32 nKey = xNumberSupplier->getNumberFormats()->addNewConverted( sFormat, aUSLocale, aCurrentLocale );
2182 8 : xPropertySet->setPropertyValue(
2183 8 : PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_NUMBER_FORMAT),
2184 16 : uno::makeAny( nKey ));
2185 8 : xPropertySet->getPropertyValue(
2186 8 : PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_NUMBER_FORMAT ) ) >>= nKey;
2187 : }
2188 6 : catch(const uno::Exception&)
2189 : {
2190 14 : }
2191 14 : }
2192 :
2193 :
2194 :
2195 42 : uno::Reference< beans::XPropertySet > DomainMapper_Impl::FindOrCreateFieldMaster(
2196 : const sal_Char* pFieldMasterService, const OUString& rFieldMasterName )
2197 : throw(::com::sun::star::uno::Exception)
2198 : {
2199 : // query master, create if not available
2200 42 : uno::Reference< text::XTextFieldsSupplier > xFieldsSupplier( GetTextDocument(), uno::UNO_QUERY_THROW );
2201 84 : uno::Reference< container::XNameAccess > xFieldMasterAccess = xFieldsSupplier->getTextFieldMasters();
2202 42 : uno::Reference< beans::XPropertySet > xMaster;
2203 84 : OUString sFieldMasterService( OUString::createFromAscii(pFieldMasterService) );
2204 84 : OUStringBuffer aFieldMasterName;
2205 42 : aFieldMasterName.appendAscii( pFieldMasterService );
2206 42 : aFieldMasterName.append('.');
2207 42 : aFieldMasterName.append(rFieldMasterName);
2208 84 : OUString sFieldMasterName = aFieldMasterName.makeStringAndClear();
2209 42 : if(xFieldMasterAccess->hasByName(sFieldMasterName))
2210 : {
2211 : //get the master
2212 56 : xMaster = uno::Reference< beans::XPropertySet >(xFieldMasterAccess->getByName(sFieldMasterName),
2213 28 : uno::UNO_QUERY_THROW);
2214 : }
2215 : else
2216 : {
2217 : //create the master
2218 28 : xMaster = uno::Reference< beans::XPropertySet >(
2219 28 : m_xTextFactory->createInstance(sFieldMasterService), uno::UNO_QUERY_THROW);
2220 : //set the master's name
2221 14 : xMaster->setPropertyValue(
2222 14 : PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_NAME),
2223 28 : uno::makeAny(rFieldMasterName));
2224 : }
2225 84 : return xMaster;
2226 : }
2227 :
2228 : /*-------------------------------------------------------------------------
2229 : //field context starts with a 0x13
2230 : -----------------------------------------------------------------------*/
2231 1864 : void DomainMapper_Impl::PushFieldContext()
2232 : {
2233 : #ifdef DEBUG_DOMAINMAPPER
2234 : dmapper_logger->element("pushFieldContext");
2235 : #endif
2236 :
2237 1864 : uno::Reference< text::XTextAppend > xTextAppend;
2238 1864 : if (!m_aTextAppendStack.empty())
2239 1864 : xTextAppend = m_aTextAppendStack.top().xTextAppend;
2240 3728 : uno::Reference< text::XTextRange > xStart;
2241 1864 : if (xTextAppend.is())
2242 : {
2243 1864 : uno::Reference< text::XTextCursor > xCrsr = xTextAppend->createTextCursorByRange( xTextAppend->getEnd() );
2244 1864 : xStart = xCrsr->getStart();
2245 : }
2246 3728 : m_aFieldStack.push( FieldContextPtr( new FieldContext( xStart ) ) );
2247 1864 : }
2248 : /*-------------------------------------------------------------------------
2249 : //the current field context waits for the completion of the command
2250 : -----------------------------------------------------------------------*/
2251 37863 : bool DomainMapper_Impl::IsOpenFieldCommand() const
2252 : {
2253 37863 : return !m_aFieldStack.empty() && !m_aFieldStack.top()->IsCommandCompleted();
2254 : }
2255 : /*-------------------------------------------------------------------------
2256 : //the current field context waits for the completion of the command
2257 : -----------------------------------------------------------------------*/
2258 35117 : bool DomainMapper_Impl::IsOpenField() const
2259 : {
2260 35117 : return !m_aFieldStack.empty();
2261 : }
2262 :
2263 :
2264 1864 : FieldContext::FieldContext(uno::Reference< text::XTextRange > xStart) :
2265 : m_bFieldCommandCompleted( false )
2266 1864 : ,m_xStartRange( xStart )
2267 : {
2268 1864 : }
2269 :
2270 :
2271 1864 : FieldContext::~FieldContext()
2272 : {
2273 1864 : }
2274 :
2275 :
2276 2746 : void FieldContext::AppendCommand(const OUString& rPart)
2277 : {
2278 2746 : m_sCommand += rPart;
2279 2746 : }
2280 :
2281 932 : ::std::vector<OUString> FieldContext::GetCommandParts() const
2282 : {
2283 932 : ::std::vector<OUString> aResult;
2284 932 : sal_Int32 nIndex = 0;
2285 932 : bool bInString = false;
2286 1864 : OUString sPart;
2287 5413 : while (nIndex != -1)
2288 : {
2289 3549 : OUString sToken = GetCommand().getToken(0, ' ', nIndex);
2290 3549 : bool bInStringNext = bInString;
2291 :
2292 3549 : if (sToken.isEmpty())
2293 931 : continue;
2294 :
2295 2618 : if (sToken[0] == '"')
2296 : {
2297 1274 : bInStringNext = true;
2298 1274 : sToken = sToken.copy(1);
2299 : }
2300 2618 : if (sToken.endsWith("\""))
2301 : {
2302 1270 : bInStringNext = false;
2303 1270 : sToken = sToken.copy(0, sToken.getLength() - 1);
2304 : }
2305 :
2306 2618 : if (bInString)
2307 : {
2308 73 : sPart += OUString(' ');
2309 73 : sPart += sToken;
2310 73 : if (!bInStringNext)
2311 : {
2312 13 : aResult.push_back(sPart);
2313 : }
2314 : }
2315 : else
2316 : {
2317 2545 : if (bInStringNext)
2318 : {
2319 15 : sPart = sToken;
2320 : }
2321 : else
2322 : {
2323 2530 : aResult.push_back(sToken);
2324 : }
2325 : }
2326 :
2327 2618 : bInString = bInStringNext;
2328 2618 : }
2329 :
2330 1864 : return aResult;
2331 : }
2332 :
2333 : /*-------------------------------------------------------------------------
2334 : //collect the pieces of the command
2335 : -----------------------------------------------------------------------*/
2336 2746 : void DomainMapper_Impl::AppendFieldCommand(OUString& rPartOfCommand)
2337 : {
2338 : #ifdef DEBUG_DOMAINMAPPER
2339 : dmapper_logger->startElement("appendFieldCommand");
2340 : dmapper_logger->chars(rPartOfCommand);
2341 : dmapper_logger->endElement();
2342 : #endif
2343 :
2344 2746 : FieldContextPtr pContext = m_aFieldStack.top();
2345 : OSL_ENSURE( pContext.get(), "no field context available");
2346 2746 : if( pContext.get() )
2347 : {
2348 2746 : pContext->AppendCommand( rPartOfCommand );
2349 2746 : }
2350 2746 : }
2351 :
2352 :
2353 : typedef std::multimap < sal_Int32, OUString > TOCStyleMap;
2354 :
2355 1864 : const FieldConversionMap_t & lcl_GetFieldConversion()
2356 : {
2357 1864 : static FieldConversionMap_t aFieldConversionMap;
2358 1864 : static FieldConversionMap_t aEnhancedFieldConversionMap;
2359 :
2360 : static bool bFilled = false;
2361 :
2362 1864 : if(!bFilled)
2363 : {
2364 : static const FieldConversion aFields[] =
2365 : {
2366 : // {OUString("ADDRESSBLOCK"), "", "", FIELD_ADDRESSBLOCK },
2367 : // {OUString("ADVANCE"), "", "", FIELD_ADVANCE },
2368 : {OUString("ASK"), "SetExpression", "SetExpression", FIELD_ASK },
2369 : {OUString("AUTONUM"), "SetExpression", "SetExpression", FIELD_AUTONUM },
2370 : {OUString("AUTONUMLGL"), "SetExpression", "SetExpression", FIELD_AUTONUMLGL },
2371 : {OUString("AUTONUMOUT"), "SetExpression", "SetExpression", FIELD_AUTONUMOUT },
2372 : {OUString("AUTHOR"), "DocInfo.CreateAuthor", "", FIELD_AUTHOR },
2373 : {OUString("DATE"), "DateTime", "", FIELD_DATE },
2374 : {OUString("COMMENTS"), "DocInfo.Description", "", FIELD_COMMENTS },
2375 : {OUString("CREATEDATE"), "DocInfo.CreateDateTime", "", FIELD_CREATEDATE },
2376 : {OUString("DOCPROPERTY"), "", "", FIELD_DOCPROPERTY },
2377 : {OUString("DOCVARIABLE"), "User", "", FIELD_DOCVARIABLE },
2378 : {OUString("EDITTIME"), "DocInfo.EditTime", "", FIELD_EDITTIME },
2379 : {OUString("EQ"), "", "", FIELD_EQ },
2380 : {OUString("FILLIN"), "Input", "", FIELD_FILLIN },
2381 : {OUString("FILENAME"), "FileName", "", FIELD_FILENAME },
2382 : // {OUString("FILESIZE"), "", "", FIELD_FILESIZE },
2383 : // {OUString("FORMULA"), "", "", FIELD_FORMULA },
2384 : {OUString("FORMCHECKBOX"), "", "", FIELD_FORMCHECKBOX},
2385 : {OUString("FORMDROPDOWN"), "DropDown", "", FIELD_FORMDROPDOWN},
2386 : {OUString("FORMTEXT"), "Input", "", FIELD_FORMTEXT},
2387 : // {OUString("GOTOBUTTON"), "", "", FIELD_GOTOBUTTON },
2388 : {OUString("HYPERLINK"), "", "", FIELD_HYPERLINK },
2389 : {OUString("IF"), "ConditionalText", "", FIELD_IF },
2390 : // {OUString("INFO"), "","", FIELD_INFO },
2391 : // {OUString("INCLUDEPICTURE"), "", "", FIELD_INCLUDEPICTURE},
2392 : {OUString("KEYWORDS"), "DocInfo.KeyWords", "", FIELD_KEYWORDS },
2393 : {OUString("LASTSAVEDBY"), "DocInfo.ChangeAuthor", "", FIELD_LASTSAVEDBY },
2394 : {OUString("MACROBUTTON"), "Macro", "", FIELD_MACROBUTTON },
2395 : {OUString("MERGEFIELD"), "Database", "Database", FIELD_MERGEFIELD},
2396 : {OUString("MERGEREC"), "DatabaseNumberOfSet", "", FIELD_MERGEREC },
2397 : // {OUString("MERGESEQ"), "", "", FIELD_MERGESEQ },
2398 : {OUString("NEXT"), "DatabaseNextSet", "", FIELD_NEXT },
2399 : {OUString("NEXTIF"), "DatabaseNextSet", "", FIELD_NEXTIF },
2400 : {OUString("PAGE"), "PageNumber", "", FIELD_PAGE },
2401 : {OUString("PAGEREF"), "GetReference", "", FIELD_PAGEREF },
2402 : {OUString("REF"), "GetReference", "", FIELD_REF },
2403 : {OUString("REVNUM"), "DocInfo.Revision", "", FIELD_REVNUM },
2404 : {OUString("SAVEDATE"), "DocInfo.Change", "", FIELD_SAVEDATE },
2405 : // {OUString("SECTION"), "", "", FIELD_SECTION },
2406 : // {OUString("SECTIONPAGES"), "", "", FIELD_SECTIONPAGES },
2407 : {OUString("SEQ"), "SetExpression", "SetExpression", FIELD_SEQ },
2408 : // {OUString("SET"), "","", FIELD_SET },
2409 : // {OUString("SKIPIF"),"", "", FIELD_SKIPIF },
2410 : // {OUString("STYLEREF"),"", "", FIELD_STYLEREF },
2411 : {OUString("SUBJECT"), "DocInfo.Subject", "", FIELD_SUBJECT },
2412 : // {OUString("SYMBOL"),"", "", FIELD_SYMBOL },
2413 : {OUString("TEMPLATE"), "TemplateName", "", FIELD_TEMPLATE},
2414 : {OUString("TIME"), "DateTime", "", FIELD_TIME },
2415 : {OUString("TITLE"), "DocInfo.Title", "", FIELD_TITLE },
2416 : {OUString("USERINITIALS"), "Author", "", FIELD_USERINITIALS },
2417 : // {OUString("USERADDRESS"), "", "", FIELD_USERADDRESS },
2418 : {OUString("USERNAME"), "Author", "", FIELD_USERNAME },
2419 :
2420 :
2421 : {OUString("TOC"), "com.sun.star.text.ContentIndex", "", FIELD_TOC},
2422 : {OUString("TC"), "com.sun.star.text.ContentIndexMark", "", FIELD_TC},
2423 : {OUString("NUMCHARS"), "CharacterCount", "", FIELD_NUMCHARS},
2424 : {OUString("NUMWORDS"), "WordCount", "", FIELD_NUMWORDS},
2425 : {OUString("NUMPAGES"), "PageCount", "", FIELD_NUMPAGES},
2426 : {OUString("INDEX"), "com.sun.star.text.DocumentIndex", "", FIELD_INDEX},
2427 : {OUString("XE"), "com.sun.star.text.DocumentIndexMark", "", FIELD_XE},
2428 : {OUString("BIBLIOGRAPHY"), "com.sun.star.text.Bibliography", "", FILED_BIBLIOGRAPHY},
2429 : {OUString("CITATION"), "com.sun.star.text.TextField.Bibliography", "", FIELD_CITATION},
2430 :
2431 : // {OUString(""), "", "", FIELD_},
2432 :
2433 14 : };
2434 7 : size_t nConversions = SAL_N_ELEMENTS(aFields);
2435 336 : for( size_t nConversion = 0; nConversion < nConversions; ++nConversion)
2436 : {
2437 : aFieldConversionMap.insert( FieldConversionMap_t::value_type(
2438 : aFields[nConversion].sWordCommand,
2439 329 : aFields[nConversion] ));
2440 : }
2441 :
2442 7 : bFilled = true;
2443 : }
2444 :
2445 1864 : return aFieldConversionMap;
2446 : }
2447 :
2448 8 : const FieldConversionMap_t & lcl_GetEnhancedFieldConversion()
2449 : {
2450 8 : static FieldConversionMap_t aEnhancedFieldConversionMap;
2451 :
2452 : static bool bFilled = false;
2453 :
2454 8 : if(!bFilled)
2455 : {
2456 : static const FieldConversion aEnhancedFields[] =
2457 : {
2458 : {OUString("FORMCHECKBOX"), "FormFieldmark", "", FIELD_FORMCHECKBOX},
2459 : {OUString("FORMDROPDOWN"), "FormFieldmark", "", FIELD_FORMDROPDOWN},
2460 : {OUString("FORMTEXT"), "Fieldmark", "", FIELD_FORMTEXT},
2461 10 : };
2462 :
2463 8 : size_t nConversions = SAL_N_ELEMENTS(aEnhancedFields);
2464 32 : for( size_t nConversion = 0; nConversion < nConversions; ++nConversion)
2465 : {
2466 : aEnhancedFieldConversionMap.insert( FieldConversionMap_t::value_type(
2467 : aEnhancedFields[nConversion].sWordCommand,
2468 24 : aEnhancedFields[nConversion] ));
2469 : }
2470 : }
2471 8 : return aEnhancedFieldConversionMap;
2472 : }
2473 :
2474 1 : void DomainMapper_Impl::handleFieldAsk
2475 : (FieldContextPtr pContext,
2476 : PropertyNameSupplier& rPropNameSupplier,
2477 : uno::Reference< uno::XInterface > & xFieldInterface,
2478 : uno::Reference< beans::XPropertySet > xFieldProperties)
2479 : {
2480 : //doesn the command contain a variable name?
2481 2 : OUString sVariable, sHint;
2482 :
2483 2 : sVariable = lcl_ExctractAskVariableAndHint( pContext->GetCommand(),
2484 1 : sHint );
2485 1 : if(!sVariable.isEmpty())
2486 : {
2487 : // determine field master name
2488 : uno::Reference< beans::XPropertySet > xMaster =
2489 : FindOrCreateFieldMaster
2490 1 : ("com.sun.star.text.FieldMaster.SetExpression", sVariable );
2491 : // An ASK field is always a string of characters
2492 1 : xMaster->setPropertyValue(rPropNameSupplier.GetName(PROP_SUB_TYPE), uno::makeAny(text::SetVariableType::STRING));
2493 :
2494 : // attach the master to the field
2495 : uno::Reference< text::XDependentTextField > xDependentField
2496 2 : ( xFieldInterface, uno::UNO_QUERY_THROW );
2497 1 : xDependentField->attachTextFieldMaster( xMaster );
2498 :
2499 : // set input flag at the field
2500 1 : xFieldProperties->setPropertyValue(
2501 1 : rPropNameSupplier.GetName(PROP_IS_INPUT), uno::makeAny( true ));
2502 : // set the prompt
2503 1 : xFieldProperties->setPropertyValue(
2504 : rPropNameSupplier.GetName(PROP_HINT),
2505 1 : uno::makeAny( sHint ));
2506 1 : xFieldProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_SUB_TYPE), uno::makeAny(text::SetVariableType::STRING));
2507 : // The ASK has no field value to display
2508 2 : xFieldProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_IS_VISIBLE), uno::makeAny(sal_False));
2509 : }
2510 : else
2511 : {
2512 : //don't insert the field
2513 : //todo: maybe import a 'normal' input field here?
2514 0 : xFieldInterface = 0;
2515 1 : }
2516 1 : }
2517 :
2518 0 : void DomainMapper_Impl::handleAutoNum
2519 : (FieldContextPtr pContext,
2520 : PropertyNameSupplier& rPropNameSupplier,
2521 : uno::Reference< uno::XInterface > & xFieldInterface,
2522 : uno::Reference< beans::XPropertySet > xFieldProperties)
2523 : {
2524 : //create a sequence field master "AutoNr"
2525 : uno::Reference< beans::XPropertySet > xMaster =
2526 : FindOrCreateFieldMaster
2527 : ("com.sun.star.text.FieldMaster.SetExpression",
2528 0 : "AutoNr");
2529 :
2530 0 : xMaster->setPropertyValue( rPropNameSupplier.GetName(PROP_SUB_TYPE),
2531 0 : uno::makeAny(text::SetVariableType::SEQUENCE));
2532 :
2533 : //apply the numbering type
2534 0 : xFieldProperties->setPropertyValue(
2535 : rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
2536 0 : uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) ));
2537 : // attach the master to the field
2538 : uno::Reference< text::XDependentTextField > xDependentField
2539 0 : ( xFieldInterface, uno::UNO_QUERY_THROW );
2540 0 : xDependentField->attachTextFieldMaster( xMaster );
2541 0 : }
2542 :
2543 0 : void DomainMapper_Impl::handleAuthor
2544 : (OUString const& rFirstParam,
2545 : PropertyNameSupplier& rPropNameSupplier,
2546 : uno::Reference< uno::XInterface > & /*xFieldInterface*/,
2547 : uno::Reference< beans::XPropertySet > xFieldProperties,
2548 : FieldId eFieldId )
2549 : {
2550 0 : if ( eFieldId != FIELD_USERINITIALS )
2551 0 : xFieldProperties->setPropertyValue
2552 0 : ( rPropNameSupplier.GetName(PROP_FULL_NAME), uno::makeAny( true ));
2553 :
2554 0 : if (!rFirstParam.isEmpty())
2555 : {
2556 0 : xFieldProperties->setPropertyValue(
2557 : rPropNameSupplier.GetName( PROP_IS_FIXED ),
2558 0 : uno::makeAny( true ));
2559 : //PROP_CURRENT_PRESENTATION is set later anyway
2560 : }
2561 0 : }
2562 :
2563 0 : void DomainMapper_Impl::handleDocProperty
2564 : (FieldContextPtr pContext,
2565 : OUString const& rFirstParam,
2566 : PropertyNameSupplier& rPropNameSupplier,
2567 : uno::Reference< uno::XInterface > & xFieldInterface,
2568 : uno::Reference< beans::XPropertySet > xFieldProperties)
2569 : {
2570 : //some docproperties should be imported as document statistic fields, some as DocInfo fields
2571 : //others should be user fields
2572 0 : if (!rFirstParam.isEmpty())
2573 : {
2574 : #define SET_ARABIC 0x01
2575 : #define SET_FULL_NAME 0x02
2576 : #define SET_DATE 0x04
2577 : struct DocPropertyMap
2578 : {
2579 : const sal_Char* pDocPropertyName;
2580 : const sal_Char* pServiceName;
2581 : sal_uInt8 nFlags;
2582 : };
2583 : static const DocPropertyMap aDocProperties[] =
2584 : {
2585 : {"CreateTime", "DocInfo.CreateDateTime", SET_DATE},
2586 : {"Characters", "CharacterCount", SET_ARABIC},
2587 : {"Comments", "DocInfo.Description", 0},
2588 : {"Keywords", "DocInfo.KeyWords", 0},
2589 : {"LastPrinted", "DocInfo.PrintDateTime", 0},
2590 : {"LastSavedBy", "DocInfo.ChangeAuthor", 0},
2591 : {"LastSavedTime", "DocInfo.ChangeDateTime", SET_DATE},
2592 : {"Paragraphs", "ParagraphCount", SET_ARABIC},
2593 : {"RevisionNumber", "DocInfo.Revision", 0},
2594 : {"Subject", "DocInfo.Subject", 0},
2595 : {"Template", "TemplateName", 0},
2596 : {"Title", "DocInfo.Title", 0},
2597 : {"TotalEditingTime", "DocInfo.EditTime", 0},
2598 : {"Words", "WordCount", SET_ARABIC}
2599 :
2600 : //other available DocProperties:
2601 : //Bytes, Category, CharactersWithSpaces, Company
2602 : //HyperlinkBase,
2603 : //Lines, Manager, NameofApplication, ODMADocId, Pages,
2604 : //Security,
2605 : };
2606 : //search for a field mapping
2607 0 : OUString sFieldServiceName;
2608 0 : sal_uInt16 nMap = 0;
2609 0 : for( ; nMap < sizeof(aDocProperties) / sizeof(DocPropertyMap);
2610 : ++nMap )
2611 : {
2612 0 : if (rFirstParam.equalsAscii(aDocProperties[nMap].pDocPropertyName))
2613 : {
2614 0 : sFieldServiceName =
2615 : OUString::createFromAscii
2616 0 : (aDocProperties[nMap].pServiceName);
2617 0 : break;
2618 : }
2619 : }
2620 0 : OUString sServiceName("com.sun.star.text.TextField.");
2621 0 : bool bIsCustomField = false;
2622 0 : if(sFieldServiceName.isEmpty())
2623 : {
2624 : //create a custom property field
2625 0 : sServiceName += "DocInfo.Custom";
2626 0 : bIsCustomField = true;
2627 : }
2628 : else
2629 : {
2630 0 : sServiceName += sFieldServiceName;
2631 : }
2632 0 : if (m_xTextFactory.is())
2633 0 : xFieldInterface = m_xTextFactory->createInstance(sServiceName);
2634 0 : xFieldProperties =
2635 : uno::Reference< beans::XPropertySet >( xFieldInterface,
2636 0 : uno::UNO_QUERY_THROW);
2637 0 : if( bIsCustomField )
2638 0 : xFieldProperties->setPropertyValue(
2639 0 : rPropNameSupplier.GetName(PROP_NAME), uno::makeAny(rFirstParam));
2640 : else
2641 : {
2642 0 : if(0 != (aDocProperties[nMap].nFlags & SET_ARABIC))
2643 0 : xFieldProperties->setPropertyValue(
2644 : rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
2645 0 : uno::makeAny( style::NumberingType::ARABIC ));
2646 0 : else if(0 != (aDocProperties[nMap].nFlags & SET_FULL_NAME))
2647 0 : xFieldProperties->setPropertyValue(
2648 : rPropNameSupplier.GetName(PROP_FULL_NAME),
2649 0 : uno::makeAny( true ));
2650 0 : else if(0 != (aDocProperties[nMap].nFlags & SET_DATE))
2651 : {
2652 0 : xFieldProperties->setPropertyValue(
2653 : rPropNameSupplier.GetName(PROP_IS_DATE),
2654 0 : uno::makeAny( true ));
2655 0 : SetNumberFormat( pContext->GetCommand(), xFieldProperties );
2656 : }
2657 0 : }
2658 : }
2659 :
2660 : #undef SET_ARABIC
2661 : #undef SET_FULL_NAME
2662 : #undef SET_DATE
2663 0 : }
2664 :
2665 352 : uno::Sequence< beans::PropertyValues > lcl_createTOXLevelHyperlinks( bool bHyperlinks, const OUString& sChapterNoSeparator,
2666 : uno::Sequence< beans::PropertyValues >aLevel,
2667 : PropertyNameSupplier& rPropNameSupplier )
2668 : {
2669 : //create a copy of the level and add two new entries - hyperlink start and end
2670 352 : bool bChapterNoSeparator = !sChapterNoSeparator.isEmpty();
2671 352 : sal_Int32 nAdd = (bHyperlinks && bChapterNoSeparator) ? 4 : 2;
2672 352 : uno::Sequence< beans::PropertyValues > aNewLevel( aLevel.getLength() + nAdd);
2673 352 : beans::PropertyValues* pNewLevel = aNewLevel.getArray();
2674 352 : if( bHyperlinks )
2675 : {
2676 352 : beans::PropertyValues aHyperlink(1);
2677 352 : aHyperlink[0].Name = rPropNameSupplier.GetName( PROP_TOKEN_TYPE );
2678 352 : aHyperlink[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_HYPERLINK_START );
2679 352 : pNewLevel[0] = aHyperlink;
2680 352 : aHyperlink[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_HYPERLINK_END );
2681 352 : pNewLevel[aNewLevel.getLength() -1] = aHyperlink;
2682 : }
2683 352 : if( bChapterNoSeparator )
2684 : {
2685 0 : beans::PropertyValues aChapterNo(2);
2686 0 : aChapterNo[0].Name = rPropNameSupplier.GetName( PROP_TOKEN_TYPE );
2687 0 : aChapterNo[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_CHAPTER_INFO );
2688 0 : aChapterNo[1].Name = rPropNameSupplier.GetName( PROP_CHAPTER_FORMAT );
2689 : //todo: is ChapterFormat::Number correct?
2690 0 : aChapterNo[1].Value <<= (sal_Int16)text::ChapterFormat::NUMBER;
2691 0 : pNewLevel[aNewLevel.getLength() - (bHyperlinks ? 4 : 2) ] = aChapterNo;
2692 :
2693 0 : beans::PropertyValues aChapterSeparator(2);
2694 0 : aChapterSeparator[0].Name = rPropNameSupplier.GetName( PROP_TOKEN_TYPE );
2695 0 : aChapterSeparator[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_TEXT );
2696 0 : aChapterSeparator[1].Name = rPropNameSupplier.GetName( PROP_TEXT );
2697 0 : aChapterSeparator[1].Value <<= sChapterNoSeparator;
2698 0 : pNewLevel[aNewLevel.getLength() - (bHyperlinks ? 3 : 1)] = aChapterSeparator;
2699 : }
2700 : //copy the 'old' entries except the last (page no)
2701 2110 : for( sal_Int32 nToken = 0; nToken < aLevel.getLength() - 1; ++nToken)
2702 : {
2703 1758 : pNewLevel[nToken + 1] = aLevel[nToken];
2704 : }
2705 : //copy page no entry (last or last but one depending on bHyperlinks
2706 352 : sal_Int32 nPageNo = aNewLevel.getLength() - (bHyperlinks ? 2 : 3);
2707 352 : pNewLevel[nPageNo] = aLevel[aLevel.getLength() - 1];
2708 :
2709 352 : return aNewLevel;
2710 : }
2711 :
2712 41 : void DomainMapper_Impl::handleToc
2713 : (FieldContextPtr pContext,
2714 : PropertyNameSupplier& rPropNameSupplier,
2715 : uno::Reference< uno::XInterface > & /*xFieldInterface*/,
2716 : uno::Reference< beans::XPropertySet > /*xFieldProperties*/,
2717 : const OUString & sTOCServiceName)
2718 : {
2719 41 : OUString sValue;
2720 41 : m_bStartTOC = true;
2721 41 : bool bTableOfFigures = false;
2722 41 : bool bHyperlinks = false;
2723 41 : bool bFromOutline = false;
2724 41 : bool bFromEntries = false;
2725 41 : bool bHideTabLeaderPageNumbers = false ;
2726 41 : bool bIsTabEntry = false ;
2727 41 : bool bNewLine = false ;
2728 41 : bool bParagraphOutlineLevel = false;
2729 :
2730 41 : sal_Int16 nMaxLevel = 10;
2731 82 : OUString sTemplate;
2732 82 : OUString sChapterNoSeparator;
2733 82 : OUString sFigureSequence;
2734 82 : uno::Reference< beans::XPropertySet > xTOC;
2735 82 : OUString aBookmarkName;
2736 :
2737 : // \a Builds a table of figures but does not include the captions's label and number
2738 41 : if( lcl_FindInCommand( pContext->GetCommand(), 'a', sValue ))
2739 : { //make it a table of figures
2740 0 : bTableOfFigures = true;
2741 : }
2742 : // \b Uses a bookmark to specify area of document from which to build table of contents
2743 41 : if( lcl_FindInCommand( pContext->GetCommand(), 'b', sValue ))
2744 : {
2745 3 : aBookmarkName = sValue;
2746 : }
2747 41 : if( lcl_FindInCommand( pContext->GetCommand(), 'c', sValue ))
2748 : // \c Builds a table of figures of the given label
2749 : {
2750 : //todo: sValue contains the label's name
2751 3 : bTableOfFigures = true;
2752 3 : sFigureSequence = sValue.trim();
2753 3 : sFigureSequence = sFigureSequence.replaceAll("\"", "").replaceAll("'","");
2754 : }
2755 : // \d Defines the separator between sequence and page numbers
2756 41 : if( lcl_FindInCommand( pContext->GetCommand(), 'd', sValue ))
2757 : {
2758 : //todo: insert the chapter number into each level and insert the separator additionally
2759 0 : sChapterNoSeparator = sValue;
2760 : }
2761 : // \f Builds a table of contents using TC entries instead of outline levels
2762 41 : if( lcl_FindInCommand( pContext->GetCommand(), 'f', sValue ))
2763 : {
2764 : //todo: sValue can contain a TOC entry identifier - use unclear
2765 12 : bFromEntries = true;
2766 : }
2767 : // \h Hyperlinks the entries and page numbers within the table of contents
2768 41 : if( lcl_FindInCommand( pContext->GetCommand(), 'h', sValue ))
2769 : {
2770 : //todo: make all entries to hyperlinks
2771 37 : bHyperlinks = true;
2772 : }
2773 : // \l Defines the TC entries field level used to build a table of contents
2774 : // if( lcl_FindInCommand( pContext->GetCommand(), 'l', sValue ))
2775 : // {
2776 : //todo: entries can only be included completely
2777 : // }
2778 : // \n Builds a table of contents or a range of entries, such as 1-9 in a table of contents without page numbers
2779 : // if( lcl_FindInCommand( pContext->GetCommand(), 'n', sValue ))
2780 : // {
2781 : //todo: what does the description mean?
2782 : // }
2783 : // \o Builds a table of contents by using outline levels instead of TC entries
2784 41 : if( lcl_FindInCommand( pContext->GetCommand(), 'o', sValue ))
2785 : {
2786 36 : bFromOutline = true;
2787 36 : if (sValue.isEmpty())
2788 2 : nMaxLevel = WW_OUTLINE_MAX;
2789 : else
2790 : {
2791 34 : sal_Int32 nIndex = 0;
2792 34 : sValue.getToken( 0, '-', nIndex );
2793 34 : nMaxLevel = static_cast<sal_Int16>(nIndex != -1 ? sValue.copy(nIndex).toInt32() : 0);
2794 : }
2795 : }
2796 : // \p Defines the separator between the table entry and its page number
2797 41 : if( lcl_FindInCommand( pContext->GetCommand(), 'p', sValue ))
2798 : { }
2799 : // \s Builds a table of contents by using a sequence type
2800 41 : if( lcl_FindInCommand( pContext->GetCommand(), 's', sValue ))
2801 : { }
2802 : // \t Builds a table of contents by using style names other than the standard outline styles
2803 41 : if( lcl_FindInCommand( pContext->GetCommand(), 't', sValue ))
2804 : {
2805 0 : sal_Int32 nPos = 0;
2806 0 : OUString sToken = sValue.getToken( 1, '"', nPos);
2807 0 : sTemplate = sToken.isEmpty() ? sValue : sToken;
2808 : }
2809 : // \u Builds a table of contents by using the applied paragraph outline level
2810 41 : if( lcl_FindInCommand( pContext->GetCommand(), 'u', sValue ))
2811 : {
2812 25 : bFromOutline = true;
2813 25 : bParagraphOutlineLevel = true;
2814 : //todo: what doesn 'the applied paragraph outline level' refer to?
2815 : }
2816 : // \w Preserve tab characters within table entries
2817 41 : if( lcl_FindInCommand( pContext->GetCommand(), 'w', sValue ))
2818 : {
2819 3 : bIsTabEntry = true ;
2820 : }
2821 : // \x Preserve newline characters within table entries
2822 41 : if( lcl_FindInCommand( pContext->GetCommand(), 'x', sValue ))
2823 : {
2824 3 : bNewLine = true ;
2825 : }
2826 : // \z Hides page numbers within the table of contens when shown in Web Layout View
2827 41 : if( lcl_FindInCommand( pContext->GetCommand(), 'z', sValue ))
2828 : {
2829 33 : bHideTabLeaderPageNumbers = true ;
2830 : }
2831 :
2832 : //if there's no option then it should be created from outline
2833 41 : if( !bFromOutline && !bFromEntries && sTemplate.isEmpty() )
2834 5 : bFromOutline = true;
2835 :
2836 :
2837 41 : if (m_xTextFactory.is())
2838 : xTOC.set(
2839 41 : m_xTextFactory->createInstance
2840 : ( bTableOfFigures ?
2841 : "com.sun.star.text.IllustrationsIndex"
2842 41 : : sTOCServiceName),
2843 41 : uno::UNO_QUERY_THROW);
2844 41 : if (xTOC.is())
2845 41 : xTOC->setPropertyValue(rPropNameSupplier.GetName( PROP_TITLE ), uno::makeAny(OUString()));
2846 41 : if (!aBookmarkName.isEmpty())
2847 3 : xTOC->setPropertyValue(rPropNameSupplier.GetName(PROP_TOC_BOOKMARK), uno::makeAny(aBookmarkName));
2848 41 : if( !bTableOfFigures && xTOC.is() )
2849 : {
2850 38 : xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_LEVEL ), uno::makeAny( nMaxLevel ) );
2851 38 : xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_CREATE_FROM_OUTLINE ), uno::makeAny( bFromOutline ));
2852 38 : xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_CREATE_FROM_MARKS ), uno::makeAny( bFromEntries ));
2853 38 : xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_HIDE_TAB_LEADER_AND_PAGE_NUMBERS ), uno::makeAny( bHideTabLeaderPageNumbers ));
2854 38 : xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_TAB_IN_TOC ), uno::makeAny( bIsTabEntry ));
2855 38 : xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_TOC_NEW_LINE ), uno::makeAny( bNewLine ));
2856 38 : xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_TOC_PARAGRAPH_OUTLINE_LEVEL ), uno::makeAny( bParagraphOutlineLevel ));
2857 38 : if( !sTemplate.isEmpty() )
2858 : {
2859 : //the string contains comma separated the names and related levels
2860 : //like: "Heading 1,1,Heading 2,2"
2861 0 : TOCStyleMap aMap;
2862 : sal_Int32 nLevel;
2863 0 : sal_Int32 nPosition = 0;
2864 0 : while( nPosition >= 0)
2865 : {
2866 0 : OUString sStyleName = sTemplate.getToken( 0, ',', nPosition );
2867 : //empty tokens should be skipped
2868 0 : while( sStyleName.isEmpty() && nPosition > 0 )
2869 0 : sStyleName = sTemplate.getToken( 0, ',', nPosition );
2870 0 : nLevel = sTemplate.getToken( 0, ',', nPosition ).toInt32();
2871 0 : if( !nLevel )
2872 0 : nLevel = 1;
2873 0 : if( !sStyleName.isEmpty() )
2874 0 : aMap.insert( TOCStyleMap::value_type(nLevel, sStyleName) );
2875 0 : }
2876 0 : uno::Reference< container::XIndexReplace> xParaStyles;
2877 0 : xTOC->getPropertyValue(rPropNameSupplier.GetName(PROP_LEVEL_PARAGRAPH_STYLES)) >>= xParaStyles;
2878 0 : for( nLevel = 1; nLevel < 10; ++nLevel)
2879 : {
2880 0 : sal_Int32 nLevelCount = aMap.count( nLevel );
2881 0 : if( nLevelCount )
2882 : {
2883 0 : TOCStyleMap::iterator aTOCStyleIter = aMap.find( nLevel );
2884 :
2885 0 : uno::Sequence< OUString> aStyles( nLevelCount );
2886 0 : for ( sal_Int32 nStyle = 0; nStyle < nLevelCount; ++nStyle, ++aTOCStyleIter )
2887 : {
2888 0 : aStyles[nStyle] = aTOCStyleIter->second;
2889 : }
2890 0 : xParaStyles->replaceByIndex(nLevel - 1, uno::makeAny(aStyles));
2891 : }
2892 : }
2893 0 : xTOC->setPropertyValue(rPropNameSupplier.GetName(PROP_CREATE_FROM_LEVEL_PARAGRAPH_STYLES), uno::makeAny( true ));
2894 :
2895 : }
2896 38 : if(bHyperlinks || !sChapterNoSeparator.isEmpty())
2897 : {
2898 35 : uno::Reference< container::XIndexReplace> xLevelFormats;
2899 35 : xTOC->getPropertyValue(rPropNameSupplier.GetName(PROP_LEVEL_FORMAT)) >>= xLevelFormats;
2900 35 : sal_Int32 nLevelCount = xLevelFormats->getCount();
2901 : //start with level 1, 0 is the header level
2902 385 : for( sal_Int32 nLevel = 1; nLevel < nLevelCount; ++nLevel)
2903 : {
2904 350 : uno::Sequence< beans::PropertyValues > aLevel;
2905 350 : xLevelFormats->getByIndex( nLevel ) >>= aLevel;
2906 :
2907 : uno::Sequence< beans::PropertyValues > aNewLevel = lcl_createTOXLevelHyperlinks(
2908 : bHyperlinks, sChapterNoSeparator,
2909 700 : aLevel, rPropNameSupplier );
2910 350 : xLevelFormats->replaceByIndex( nLevel, uno::makeAny( aNewLevel ) );
2911 385 : }
2912 : }
2913 : }
2914 3 : else if (bTableOfFigures && xTOC.is())
2915 : {
2916 3 : if (!sFigureSequence.isEmpty())
2917 3 : xTOC->setPropertyValue(rPropNameSupplier.GetName(PROP_LABEL_CATEGORY),
2918 3 : uno::makeAny(sFigureSequence));
2919 :
2920 3 : if ( bHyperlinks )
2921 : {
2922 2 : uno::Reference< container::XIndexReplace> xLevelFormats;
2923 2 : xTOC->getPropertyValue(rPropNameSupplier.GetName(PROP_LEVEL_FORMAT)) >>= xLevelFormats;
2924 4 : uno::Sequence< beans::PropertyValues > aLevel;
2925 2 : xLevelFormats->getByIndex( 1 ) >>= aLevel;
2926 :
2927 : uno::Sequence< beans::PropertyValues > aNewLevel = lcl_createTOXLevelHyperlinks(
2928 : bHyperlinks, sChapterNoSeparator,
2929 4 : aLevel, rPropNameSupplier );
2930 4 : xLevelFormats->replaceByIndex( 1, uno::makeAny( aNewLevel ) );
2931 : }
2932 : }
2933 41 : pContext->SetTOC( xTOC );
2934 :
2935 82 : OUString sMarker("Y");
2936 : //insert index
2937 82 : uno::Reference< text::XTextContent > xToInsert( xTOC, uno::UNO_QUERY );
2938 82 : uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend;
2939 41 : if (xTextAppend.is())
2940 : {
2941 41 : uno::Reference< text::XTextCursor > xCrsr = xTextAppend->getText()->createTextCursor();
2942 :
2943 82 : uno::Reference< text::XText > xText = xTextAppend->getText();
2944 41 : if(xCrsr.is() && xText.is())
2945 : {
2946 41 : xCrsr->gotoEnd(false);
2947 41 : xText->insertString(xCrsr, sMarker, sal_False);
2948 42 : xText->insertTextContent(uno::Reference< text::XTextRange >( xCrsr, uno::UNO_QUERY_THROW ), xToInsert, sal_False);
2949 40 : xTOCMarkerCursor = xCrsr;
2950 41 : }
2951 41 : }
2952 40 : }
2953 :
2954 15 : void DomainMapper_Impl::handleBibliography
2955 : (FieldContextPtr pContext,
2956 : PropertyNameSupplier& rPropNameSupplier,
2957 : const OUString & sTOCServiceName)
2958 : {
2959 15 : uno::Reference< beans::XPropertySet > xTOC;
2960 15 : m_bStartTOC = true;
2961 15 : m_bStartBibliography = true;
2962 15 : if (m_xTextFactory.is())
2963 : xTOC.set(
2964 15 : m_xTextFactory->createInstance(
2965 15 : sTOCServiceName),
2966 15 : uno::UNO_QUERY_THROW);
2967 15 : if (xTOC.is())
2968 15 : xTOC->setPropertyValue(rPropNameSupplier.GetName( PROP_TITLE ), uno::makeAny(OUString()));
2969 :
2970 15 : pContext->SetTOC( xTOC );
2971 :
2972 30 : uno::Reference< text::XTextContent > xToInsert( xTOC, uno::UNO_QUERY );
2973 30 : appendTextContent(xToInsert, uno::Sequence< beans::PropertyValue >() );
2974 15 : }
2975 :
2976 18 : void DomainMapper_Impl::handleIndex
2977 : (FieldContextPtr pContext,
2978 : PropertyNameSupplier& rPropNameSupplier,
2979 : uno::Reference< uno::XInterface > & /*xFieldInterface*/,
2980 : uno::Reference< beans::XPropertySet > /*xFieldProperties*/,
2981 : const OUString & sTOCServiceName)
2982 : {
2983 18 : uno::Reference< beans::XPropertySet > xTOC;
2984 18 : m_bStartTOC = true;
2985 18 : m_bStartIndex = true;
2986 36 : OUString sValue;
2987 36 : OUString sIndexEntryType = "I"; // Default value for field flag '\f' is 'I'.
2988 :
2989 :
2990 18 : if (m_xTextFactory.is())
2991 : xTOC.set(
2992 18 : m_xTextFactory->createInstance(
2993 18 : sTOCServiceName),
2994 18 : uno::UNO_QUERY_THROW);
2995 18 : if (xTOC.is())
2996 : {
2997 18 : xTOC->setPropertyValue(rPropNameSupplier.GetName( PROP_TITLE ), uno::makeAny(OUString()));
2998 :
2999 18 : if( lcl_FindInCommand( pContext->GetCommand(), 'r', sValue ))
3000 : {
3001 0 : xTOC->setPropertyValue("IsCommaSeparated", uno::makeAny(true));
3002 : }
3003 18 : if( lcl_FindInCommand( pContext->GetCommand(), 'h', sValue ))
3004 : {
3005 3 : xTOC->setPropertyValue("UseAlphabeticalSeparators", uno::makeAny(true));
3006 : }
3007 18 : if( lcl_FindInCommand( pContext->GetCommand(), 'f', sValue ))
3008 : {
3009 3 : if(!sValue.isEmpty())
3010 3 : sIndexEntryType = sValue ;
3011 3 : xTOC->setPropertyValue(rPropNameSupplier.GetName( PROP_INDEX_ENTRY_TYPE ), uno::makeAny(sIndexEntryType));
3012 : }
3013 : }
3014 18 : pContext->SetTOC( xTOC );
3015 :
3016 36 : uno::Reference< text::XTextContent > xToInsert( xTOC, uno::UNO_QUERY );
3017 18 : appendTextContent(xToInsert, uno::Sequence< beans::PropertyValue >() );
3018 :
3019 18 : if( lcl_FindInCommand( pContext->GetCommand(), 'c', sValue ))
3020 : {
3021 13 : sValue = sValue.replaceAll("\"", "");
3022 13 : uno::Reference<text::XTextColumns> xTextColumns;
3023 13 : xTOC->getPropertyValue(rPropNameSupplier.GetName( PROP_TEXT_COLUMNS )) >>= xTextColumns;
3024 13 : if (xTextColumns.is())
3025 : {
3026 13 : xTextColumns->setColumnCount( sValue.toInt32() );
3027 13 : xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_TEXT_COLUMNS ), uno::makeAny( xTextColumns ) );
3028 13 : }
3029 18 : }
3030 18 : }
3031 :
3032 : /*-------------------------------------------------------------------------
3033 : //the field command has to be closed (0x14 appeared)
3034 : -----------------------------------------------------------------------*/
3035 1864 : void DomainMapper_Impl::CloseFieldCommand()
3036 : {
3037 : #ifdef DEBUG_DOMAINMAPPER
3038 : dmapper_logger->element("closeFieldCommand");
3039 : #endif
3040 :
3041 1864 : FieldContextPtr pContext = m_aFieldStack.top();
3042 : OSL_ENSURE( pContext.get(), "no field context available");
3043 1864 : if( pContext.get() )
3044 : {
3045 1864 : m_bSetUserFieldContent = false;
3046 1864 : m_bSetCitation = false;
3047 1864 : FieldConversionMap_t aFieldConversionMap = lcl_GetFieldConversion();
3048 :
3049 : try
3050 : {
3051 1864 : uno::Reference< uno::XInterface > xFieldInterface;
3052 :
3053 : boost::tuple<OUString, vector<OUString>, vector<OUString> > const
3054 3728 : field(lcl_SplitFieldCommand(pContext->GetCommand()));
3055 1864 : OUString const sFirstParam(boost::get<1>(field).empty()
3056 3728 : ? OUString() : boost::get<1>(field).front());
3057 :
3058 : FieldConversionMap_t::iterator const aIt =
3059 1864 : aFieldConversionMap.find(boost::get<0>(field));
3060 1864 : if(aIt != aFieldConversionMap.end())
3061 : {
3062 1785 : bool bCreateEnhancedField = false;
3063 1785 : uno::Reference< beans::XPropertySet > xFieldProperties;
3064 1785 : bool bCreateField = true;
3065 1785 : switch (aIt->second.eFieldId)
3066 : {
3067 : case FIELD_HYPERLINK:
3068 : case FIELD_DOCPROPERTY:
3069 : case FIELD_TOC:
3070 : case FIELD_INDEX:
3071 : case FIELD_XE:
3072 : case FILED_BIBLIOGRAPHY:
3073 : case FIELD_CITATION:
3074 : case FIELD_TC:
3075 : case FIELD_EQ:
3076 1151 : bCreateField = false;
3077 1151 : break;
3078 : case FIELD_FORMCHECKBOX :
3079 : case FIELD_FORMTEXT :
3080 : case FIELD_FORMDROPDOWN :
3081 : {
3082 : // If we use 'enhanced' fields then FIELD_FORMCHECKBOX,
3083 : // FIELD_FORMTEXT & FIELD_FORMDROPDOWN are treated specially
3084 8 : if ( m_bUsingEnhancedFields )
3085 : {
3086 8 : bCreateField = false;
3087 8 : bCreateEnhancedField = true;
3088 : }
3089 : // for non enhanced fields checkboxes are displayed
3090 : // as an awt control not a field
3091 0 : else if ( aIt->second.eFieldId == FIELD_FORMCHECKBOX )
3092 0 : bCreateField = false;
3093 8 : break;
3094 : }
3095 : default:
3096 626 : break;
3097 : }
3098 1785 : if (m_bStartTOC && (aIt->second.eFieldId == FIELD_PAGEREF) )
3099 : {
3100 390 : m_bTOCPageRef = true;
3101 390 : bCreateField = false;
3102 : }
3103 :
3104 1785 : if( bCreateField || bCreateEnhancedField )
3105 : {
3106 : //add the service prefix
3107 244 : OUString sServiceName("com.sun.star.text.");
3108 244 : if ( bCreateEnhancedField )
3109 : {
3110 8 : FieldConversionMap_t aEnhancedFieldConversionMap = lcl_GetEnhancedFieldConversion();
3111 : FieldConversionMap_t::iterator aEnhancedIt =
3112 8 : aEnhancedFieldConversionMap.find(boost::get<0>(field));
3113 8 : if ( aEnhancedIt != aEnhancedFieldConversionMap.end())
3114 8 : sServiceName += OUString::createFromAscii(aEnhancedIt->second.cFieldServiceName );
3115 : }
3116 : else
3117 : {
3118 236 : sServiceName += "TextField.";
3119 236 : sServiceName += OUString::createFromAscii(aIt->second.cFieldServiceName );
3120 : }
3121 :
3122 : #ifdef DEBUG_DOMAINMAPPER
3123 : dmapper_logger->startElement("fieldService");
3124 : dmapper_logger->chars(sServiceName);
3125 : dmapper_logger->endElement();
3126 : #endif
3127 :
3128 244 : if (m_xTextFactory.is())
3129 : {
3130 244 : xFieldInterface = m_xTextFactory->createInstance(sServiceName);
3131 244 : xFieldProperties = uno::Reference< beans::XPropertySet >( xFieldInterface, uno::UNO_QUERY_THROW);
3132 244 : }
3133 : }
3134 1785 : PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
3135 1785 : switch( aIt->second.eFieldId )
3136 : {
3137 0 : case FIELD_ADDRESSBLOCK: break;
3138 0 : case FIELD_ADVANCE : break;
3139 : case FIELD_ASK :
3140 1 : handleFieldAsk(pContext, rPropNameSupplier, xFieldInterface, xFieldProperties);
3141 1 : break;
3142 : case FIELD_AUTONUM :
3143 : case FIELD_AUTONUMLGL :
3144 : case FIELD_AUTONUMOUT :
3145 0 : handleAutoNum(pContext, rPropNameSupplier, xFieldInterface, xFieldProperties);
3146 0 : break;
3147 : case FIELD_AUTHOR :
3148 : case FIELD_USERNAME :
3149 : case FIELD_USERINITIALS :
3150 : handleAuthor(sFirstParam, rPropNameSupplier,
3151 : xFieldInterface, xFieldProperties,
3152 0 : aIt->second.eFieldId);
3153 0 : break;
3154 : case FIELD_DATE:
3155 14 : if (xFieldProperties.is())
3156 : {
3157 : //not fixed,
3158 14 : xFieldProperties->setPropertyValue(
3159 : rPropNameSupplier.GetName(PROP_IS_FIXED),
3160 14 : uno::makeAny( false ));
3161 14 : xFieldProperties->setPropertyValue(
3162 : rPropNameSupplier.GetName(PROP_IS_DATE),
3163 14 : uno::makeAny( true ));
3164 14 : SetNumberFormat( pContext->GetCommand(), xFieldProperties );
3165 : }
3166 14 : break;
3167 : case FIELD_COMMENTS :
3168 : {
3169 : // OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" COMMENTS") );
3170 : // A parameter with COMMENTS shouldn't set fixed
3171 : // ( or at least the binary filter doesn't )
3172 : // If we set fixed then we wont export a field cmd.
3173 : // Additionally the para in COMMENTS is more like an
3174 : // instruction to set the document property comments
3175 : // with the param ( e.g. each COMMENT with a param will
3176 : // overwrite the Comments document property
3177 : // #TODO implement the above too
3178 0 : xFieldProperties->setPropertyValue(
3179 0 : rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( false ));
3180 : //PROP_CURRENT_PRESENTATION is set later anyway
3181 : }
3182 0 : break;
3183 : case FIELD_CREATEDATE :
3184 : {
3185 0 : xFieldProperties->setPropertyValue(
3186 0 : rPropNameSupplier.GetName( PROP_IS_DATE ), uno::makeAny( true ));
3187 0 : SetNumberFormat( pContext->GetCommand(), xFieldProperties );
3188 : }
3189 0 : break;
3190 : case FIELD_DOCPROPERTY :
3191 : handleDocProperty(pContext, sFirstParam, rPropNameSupplier,
3192 0 : xFieldInterface, xFieldProperties);
3193 0 : break;
3194 : case FIELD_DOCVARIABLE :
3195 : {
3196 : //create a user field and type
3197 : uno::Reference< beans::XPropertySet > xMaster =
3198 2 : FindOrCreateFieldMaster("com.sun.star.text.FieldMaster.User", sFirstParam);
3199 4 : uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
3200 2 : xDependentField->attachTextFieldMaster( xMaster );
3201 4 : m_bSetUserFieldContent = true;
3202 : }
3203 2 : break;
3204 : case FIELD_EDITTIME :
3205 : //it's a numbering type, no number format! SetNumberFormat( pContext->GetCommand(), xFieldProperties );
3206 0 : break;
3207 : case FIELD_EQ:
3208 : {
3209 1 : OUString aCommand = pContext->GetCommand().trim();
3210 :
3211 2 : msfilter::util::EquationResult aResult(msfilter::util::ParseCombinedChars(aCommand));
3212 1 : if (!aResult.sType.isEmpty() && m_xTextFactory.is())
3213 : {
3214 0 : OUString sServiceName("com.sun.star.text.TextField.");
3215 0 : xFieldInterface = m_xTextFactory->createInstance(sServiceName + aResult.sType);
3216 0 : xFieldProperties =
3217 : uno::Reference< beans::XPropertySet >( xFieldInterface,
3218 0 : uno::UNO_QUERY_THROW);
3219 0 : xFieldProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_CONTENT), uno::makeAny(aResult.sResult));
3220 : }
3221 : else
3222 : {
3223 : //merge Read_SubF_Ruby into filter/.../util.cxx and reuse that ?
3224 1 : sal_Int32 nSpaceIndex = aCommand.indexOf(' ');
3225 1 : if(nSpaceIndex > 0)
3226 1 : aCommand = aCommand.copy(nSpaceIndex).trim();
3227 1 : if (aCommand.startsWith("\\s"))
3228 : {
3229 1 : aCommand = aCommand.copy(2);
3230 1 : if (aCommand.startsWith("\\do"))
3231 : {
3232 1 : aCommand = aCommand.copy(3);
3233 1 : sal_Int32 nStartIndex = aCommand.indexOf('(');
3234 1 : sal_Int32 nEndIndex = aCommand.indexOf(')');
3235 1 : if (nStartIndex > 0 && nEndIndex > 0)
3236 : {
3237 : // nDown is the requested "lower by" value in points.
3238 1 : sal_Int32 nDown = aCommand.copy(0, nStartIndex).toInt32();
3239 1 : OUString aContent = aCommand.copy(nStartIndex + 1, nEndIndex - nStartIndex - 1);
3240 2 : PropertyMapPtr pCharContext = GetTopContext();
3241 : // dHeight is the font size of the current style.
3242 1 : double dHeight = 0;
3243 1 : if (GetPropertyFromStyleSheet(PROP_CHAR_HEIGHT) >>= dHeight)
3244 : // Character escapement should be given in negative percents for subscripts.
3245 1 : pCharContext->Insert(PROP_CHAR_ESCAPEMENT, uno::makeAny( sal_Int16(- 100 * nDown / dHeight) ) );
3246 2 : appendTextPortion(aContent, pCharContext);
3247 : }
3248 : }
3249 : }
3250 1 : }
3251 : }
3252 1 : break;
3253 : case FIELD_FILLIN :
3254 : {
3255 0 : sal_Int32 nIndex = 0;
3256 0 : if (xFieldProperties.is())
3257 0 : xFieldProperties->setPropertyValue(
3258 0 : rPropNameSupplier.GetName(PROP_HINT), uno::makeAny( pContext->GetCommand().getToken( 1, '\"', nIndex)));
3259 : }
3260 0 : break;
3261 : case FIELD_FILENAME:
3262 : {
3263 8 : sal_Int32 nNumberingTypeIndex = pContext->GetCommand().indexOf("\\p");
3264 8 : if (xFieldProperties.is())
3265 8 : xFieldProperties->setPropertyValue(
3266 : rPropNameSupplier.GetName(PROP_FILE_FORMAT),
3267 8 : uno::makeAny( nNumberingTypeIndex > 0 ? text::FilenameDisplayFormat::FULL : text::FilenameDisplayFormat::NAME_AND_EXT ));
3268 : }
3269 8 : break;
3270 0 : case FIELD_FILESIZE : break;
3271 0 : case FIELD_FORMULA : break;
3272 : case FIELD_FORMCHECKBOX :
3273 : case FIELD_FORMDROPDOWN :
3274 : case FIELD_FORMTEXT :
3275 : {
3276 8 : uno::Reference< text::XTextField > xTextField( xFieldInterface, uno::UNO_QUERY );
3277 8 : if ( !xTextField.is() )
3278 : {
3279 : FFDataHandler::Pointer_t
3280 8 : pFFDataHandler(pContext->getFFDataHandler());
3281 : FormControlHelper::Pointer_t
3282 : pFormControlHelper(new FormControlHelper
3283 8 : (m_bUsingEnhancedFields ? aIt->second.eFieldId : FIELD_FORMCHECKBOX,
3284 :
3285 24 : m_xTextDocument, pFFDataHandler));
3286 8 : pContext->setFormControlHelper(pFormControlHelper);
3287 16 : uno::Reference< text::XFormField > xFormField( xFieldInterface, uno::UNO_QUERY );
3288 16 : uno::Reference< container::XNamed > xNamed( xFormField, uno::UNO_QUERY );
3289 8 : if ( xNamed.is() )
3290 : {
3291 8 : if ( pFFDataHandler && !pFFDataHandler->getName().isEmpty() )
3292 5 : xNamed->setName( pFFDataHandler->getName() );
3293 8 : pContext->SetFormField( xFormField );
3294 8 : }
3295 : }
3296 : else
3297 : {
3298 0 : if ( aIt->second.eFieldId == FIELD_FORMDROPDOWN )
3299 0 : lcl_handleDropdownField( xFieldProperties, pContext->getFFDataHandler() );
3300 : else
3301 0 : lcl_handleTextField( xFieldProperties, pContext->getFFDataHandler(), rPropNameSupplier );
3302 8 : }
3303 : }
3304 8 : break;
3305 0 : case FIELD_GOTOBUTTON : break;
3306 : case FIELD_HYPERLINK:
3307 : {
3308 932 : ::std::vector<OUString> aParts = pContext->GetCommandParts();
3309 932 : ::std::vector<OUString>::const_iterator aItEnd = aParts.end();
3310 932 : ::std::vector<OUString>::const_iterator aPartIt = aParts.begin();
3311 :
3312 1864 : OUString sURL;
3313 :
3314 4066 : while (aPartIt != aItEnd)
3315 : {
3316 2204 : if ( *aPartIt == "\\l" )
3317 : {
3318 316 : ++aPartIt;
3319 :
3320 316 : if (aPartIt == aItEnd)
3321 0 : break;
3322 :
3323 316 : sURL += OUString('#');
3324 316 : sURL += *aPartIt;
3325 : }
3326 1888 : else if ( *aPartIt == "\\m" || *aPartIt == "\\n" )
3327 : {
3328 : }
3329 1888 : else if ( *aPartIt == "\\o" || *aPartIt == "\\t" )
3330 : {
3331 25 : ++aPartIt;
3332 :
3333 25 : if (aPartIt == aItEnd)
3334 2 : break;
3335 : }
3336 : else
3337 : {
3338 1863 : sURL = *aPartIt;
3339 : }
3340 :
3341 2202 : ++aPartIt;
3342 : }
3343 :
3344 932 : if (!sURL.isEmpty())
3345 : {
3346 931 : pContext->SetHyperlinkURL(sURL);
3347 932 : }
3348 : }
3349 932 : break;
3350 0 : case FIELD_IF : break;
3351 0 : case FIELD_INFO : break;
3352 0 : case FIELD_INCLUDEPICTURE: break;
3353 : case FIELD_KEYWORDS :
3354 : {
3355 0 : if (!sFirstParam.isEmpty())
3356 : {
3357 0 : xFieldProperties->setPropertyValue(
3358 0 : rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
3359 : //PROP_CURRENT_PRESENTATION is set later anyway
3360 : }
3361 : }
3362 0 : break;
3363 3 : case FIELD_LASTSAVEDBY : break;
3364 : case FIELD_MACROBUTTON:
3365 : {
3366 : //extract macro name
3367 3 : sal_Int32 nIndex = sizeof(" MACROBUTTON ");
3368 3 : OUString sMacro = pContext->GetCommand().getToken( 0, ' ', nIndex);
3369 3 : if (xFieldProperties.is())
3370 3 : xFieldProperties->setPropertyValue(
3371 3 : rPropNameSupplier.GetName(PROP_MACRO_NAME), uno::makeAny( sMacro ));
3372 :
3373 : //extract quick help text
3374 3 : if(xFieldProperties.is() && pContext->GetCommand().getLength() > nIndex + 1)
3375 : {
3376 3 : xFieldProperties->setPropertyValue(
3377 : rPropNameSupplier.GetName(PROP_HINT),
3378 3 : uno::makeAny( pContext->GetCommand().copy( nIndex )));
3379 3 : }
3380 : }
3381 3 : break;
3382 : case FIELD_MERGEFIELD :
3383 : {
3384 : //todo: create a database field and fieldmaster pointing to a column, only
3385 : //create a user field and type
3386 : uno::Reference< beans::XPropertySet > xMaster =
3387 0 : FindOrCreateFieldMaster("com.sun.star.text.FieldMaster.Database", sFirstParam);
3388 :
3389 : // xFieldProperties->setPropertyValue(
3390 : // "FieldCode",
3391 : // uno::makeAny( pContext->GetCommand().copy( nIndex + 1 )));
3392 0 : uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
3393 0 : xDependentField->attachTextFieldMaster( xMaster );
3394 : }
3395 0 : break;
3396 0 : case FIELD_MERGEREC : break;
3397 0 : case FIELD_MERGESEQ : break;
3398 0 : case FIELD_NEXT : break;
3399 0 : case FIELD_NEXTIF : break;
3400 : case FIELD_PAGE :
3401 130 : if (xFieldProperties.is())
3402 : {
3403 130 : xFieldProperties->setPropertyValue(
3404 : rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
3405 130 : uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) ));
3406 130 : xFieldProperties->setPropertyValue(
3407 : rPropNameSupplier.GetName(PROP_SUB_TYPE),
3408 130 : uno::makeAny( text::PageNumberType_CURRENT ));
3409 : }
3410 :
3411 130 : break;
3412 : case FIELD_PAGEREF:
3413 : case FIELD_REF:
3414 409 : if (xFieldProperties.is() && !m_bStartTOC)
3415 : {
3416 19 : bool bPageRef = aIt->second.eFieldId == FIELD_PAGEREF;
3417 :
3418 : // Do we need a GetReference (default) or a GetExpression field?
3419 19 : uno::Reference< text::XTextFieldsSupplier > xFieldsSupplier( GetTextDocument(), uno::UNO_QUERY );
3420 38 : uno::Reference< container::XNameAccess > xFieldMasterAccess = xFieldsSupplier->getTextFieldMasters();
3421 :
3422 57 : if (!xFieldMasterAccess->hasByName(
3423 : "com.sun.star.text.FieldMaster.SetExpression."
3424 38 : + sFirstParam))
3425 : {
3426 18 : xFieldProperties->setPropertyValue(
3427 : rPropNameSupplier.GetName(PROP_REFERENCE_FIELD_SOURCE),
3428 18 : uno::makeAny( sal_Int16(text::ReferenceFieldSource::BOOKMARK)) );
3429 18 : xFieldProperties->setPropertyValue(
3430 : rPropNameSupplier.GetName(PROP_SOURCE_NAME),
3431 18 : uno::makeAny(sFirstParam) );
3432 18 : sal_Int16 nFieldPart = (bPageRef ? text::ReferenceFieldPart::PAGE : text::ReferenceFieldPart::TEXT);
3433 18 : OUString sValue;
3434 18 : if( lcl_FindInCommand( pContext->GetCommand(), 'p', sValue ))
3435 : {
3436 : //above-below
3437 0 : nFieldPart = text::ReferenceFieldPart::UP_DOWN;
3438 : }
3439 18 : else if( lcl_FindInCommand( pContext->GetCommand(), 'r', sValue ))
3440 : {
3441 : //number
3442 0 : nFieldPart = text::ReferenceFieldPart::NUMBER;
3443 : }
3444 18 : else if( lcl_FindInCommand( pContext->GetCommand(), 'n', sValue ))
3445 : {
3446 : //number-no-context
3447 0 : nFieldPart = text::ReferenceFieldPart::NUMBER_NO_CONTEXT;
3448 : }
3449 18 : else if( lcl_FindInCommand( pContext->GetCommand(), 'w', sValue ))
3450 : {
3451 : //number-full-context
3452 0 : nFieldPart = text::ReferenceFieldPart::NUMBER_FULL_CONTEXT;
3453 : }
3454 18 : xFieldProperties->setPropertyValue(
3455 18 : rPropNameSupplier.GetName( PROP_REFERENCE_FIELD_PART ), uno::makeAny( nFieldPart ));
3456 : }
3457 : else
3458 : {
3459 1 : xFieldInterface = m_xTextFactory->createInstance("com.sun.star.text.TextField.GetExpression");
3460 1 : xFieldProperties.set(xFieldInterface, uno::UNO_QUERY);
3461 1 : xFieldProperties->setPropertyValue(
3462 : rPropNameSupplier.GetName(PROP_CONTENT),
3463 1 : uno::makeAny(sFirstParam));
3464 1 : xFieldProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_SUB_TYPE), uno::makeAny(text::SetVariableType::STRING));
3465 19 : }
3466 : }
3467 409 : break;
3468 3 : case FIELD_REVNUM : break;
3469 : case FIELD_SAVEDATE :
3470 0 : SetNumberFormat( pContext->GetCommand(), xFieldProperties );
3471 0 : break;
3472 0 : case FIELD_SECTION : break;
3473 0 : case FIELD_SECTIONPAGES : break;
3474 : case FIELD_SEQ :
3475 : {
3476 : // command looks like: " SEQ Table \* ARABIC "
3477 39 : OUString sCmd(pContext->GetCommand());
3478 : // find the sequence name, e.g. "SEQ"
3479 78 : OUString sSeqName = msfilter::util::findQuotedText(sCmd, "SEQ ", '\\');
3480 39 : sSeqName = sSeqName.trim();
3481 :
3482 : // create a sequence field master using the sequence name
3483 : uno::Reference< beans::XPropertySet > xMaster = FindOrCreateFieldMaster(
3484 : "com.sun.star.text.FieldMaster.SetExpression",
3485 78 : sSeqName);
3486 :
3487 39 : xMaster->setPropertyValue(
3488 : rPropNameSupplier.GetName(PROP_SUB_TYPE),
3489 39 : uno::makeAny(text::SetVariableType::SEQUENCE));
3490 :
3491 : // apply the numbering type
3492 39 : xFieldProperties->setPropertyValue(
3493 : rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
3494 39 : uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) ));
3495 :
3496 : // attach the master to the field
3497 78 : uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
3498 39 : xDependentField->attachTextFieldMaster( xMaster );
3499 :
3500 78 : rtl::OUString sFormula = sSeqName + "+1";
3501 78 : rtl::OUString sValue;
3502 39 : if( lcl_FindInCommand( pContext->GetCommand(), 'c', sValue ))
3503 : {
3504 0 : sFormula = sSeqName;
3505 : }
3506 39 : else if( lcl_FindInCommand( pContext->GetCommand(), 'r', sValue ))
3507 : {
3508 0 : sFormula = sValue;
3509 : }
3510 : // TODO \s isn't handled, but the spec isn't easy to understand without
3511 : // an example for this one.
3512 39 : xFieldProperties->setPropertyValue(
3513 : rPropNameSupplier.GetName(PROP_CONTENT),
3514 39 : uno::makeAny(sFormula));
3515 :
3516 : // Take care of the numeric formatting definition, default is Arabic
3517 39 : sal_Int16 nNumberingType = lcl_ParseNumberingType(pContext->GetCommand());
3518 39 : if (nNumberingType == style::NumberingType::PAGE_DESCRIPTOR)
3519 36 : nNumberingType = style::NumberingType::ARABIC;
3520 39 : xFieldProperties->setPropertyValue(
3521 : rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
3522 78 : uno::makeAny(nNumberingType));
3523 : }
3524 39 : break;
3525 0 : case FIELD_SET : break;
3526 0 : case FIELD_SKIPIF : break;
3527 0 : case FIELD_STYLEREF : break;
3528 : case FIELD_SUBJECT :
3529 : {
3530 0 : if (!sFirstParam.isEmpty())
3531 : {
3532 0 : xFieldProperties->setPropertyValue(
3533 0 : rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
3534 : //PROP_CURRENT_PRESENTATION is set later anyway
3535 : }
3536 : }
3537 0 : break;
3538 0 : case FIELD_SYMBOL : break;
3539 0 : case FIELD_TEMPLATE: break;
3540 : case FIELD_TIME :
3541 0 : SetNumberFormat( pContext->GetCommand(), xFieldProperties );
3542 0 : break;
3543 : case FIELD_TITLE :
3544 : {
3545 0 : if (!sFirstParam.isEmpty())
3546 : {
3547 0 : xFieldProperties->setPropertyValue(
3548 0 : rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
3549 : //PROP_CURRENT_PRESENTATION is set later anyway
3550 : }
3551 : }
3552 0 : break;
3553 : case FIELD_USERADDRESS : //todo: user address collects street, city ...
3554 0 : break;
3555 : case FIELD_INDEX:
3556 : handleIndex(pContext, rPropNameSupplier, xFieldInterface, xFieldProperties,
3557 18 : OUString::createFromAscii(aIt->second.cFieldServiceName));
3558 18 : break;
3559 : case FILED_BIBLIOGRAPHY:
3560 : handleBibliography(pContext, rPropNameSupplier,
3561 15 : OUString::createFromAscii(aIt->second.cFieldServiceName));
3562 15 : break;
3563 : case FIELD_TOC:
3564 : handleToc(pContext, rPropNameSupplier, xFieldInterface, xFieldProperties,
3565 42 : OUString::createFromAscii(aIt->second.cFieldServiceName));
3566 40 : break;
3567 : case FIELD_XE:
3568 : {
3569 : uno::Reference< beans::XPropertySet > xTC(
3570 126 : m_xTextFactory->createInstance(
3571 126 : OUString::createFromAscii(aIt->second.cFieldServiceName)),
3572 126 : uno::UNO_QUERY_THROW);
3573 126 : if (!sFirstParam.isEmpty())
3574 : {
3575 126 : xTC->setPropertyValue("PrimaryKey",
3576 126 : uno::makeAny(sFirstParam));
3577 : }
3578 252 : uno::Reference< text::XTextContent > xToInsert( xTC, uno::UNO_QUERY );
3579 252 : uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend;
3580 126 : if (xTextAppend.is())
3581 : {
3582 126 : uno::Reference< text::XTextCursor > xCrsr = xTextAppend->getText()->createTextCursor();
3583 :
3584 252 : uno::Reference< text::XText > xText = xTextAppend->getText();
3585 126 : if(xCrsr.is() && xText.is())
3586 : {
3587 126 : xCrsr->gotoEnd(false);
3588 126 : xText->insertTextContent(uno::Reference< text::XTextRange >( xCrsr, uno::UNO_QUERY_THROW ), xToInsert, sal_False);
3589 126 : }
3590 126 : }
3591 : }
3592 126 : break;
3593 : case FIELD_CITATION:
3594 : {
3595 54 : xFieldInterface = m_xTextFactory->createInstance(
3596 36 : OUString::createFromAscii(aIt->second.cFieldServiceName));
3597 : uno::Reference< beans::XPropertySet > xTC(xFieldInterface,
3598 18 : uno::UNO_QUERY_THROW);
3599 :
3600 18 : if( !sFirstParam.isEmpty()){
3601 16 : uno::Sequence<com::sun::star::beans::PropertyValue> aValues(1);
3602 32 : com::sun::star::beans::PropertyValue propertyVal;
3603 16 : propertyVal.Name = "Identifier";
3604 16 : propertyVal.Value = uno::makeAny(sFirstParam);
3605 16 : aValues[0] = propertyVal;
3606 16 : xTC->setPropertyValue("Fields",
3607 32 : uno::makeAny(aValues));
3608 : }
3609 36 : uno::Reference< text::XTextContent > xToInsert( xTC, uno::UNO_QUERY );
3610 36 : uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend;
3611 18 : if (xTextAppend.is())
3612 : {
3613 18 : uno::Reference< text::XTextCursor > xCrsr = xTextAppend->getText()->createTextCursor();
3614 36 : uno::Reference< text::XText > xText = xTextAppend->getText();
3615 18 : if(xCrsr.is() && xText.is())
3616 : {
3617 18 : xCrsr->gotoEnd(false);
3618 18 : xText->insertTextContent(uno::Reference< text::XTextRange >( xCrsr, uno::UNO_QUERY_THROW ), xToInsert, sal_False);
3619 18 : }
3620 : }
3621 36 : m_bSetCitation = true;
3622 : }
3623 18 : break;
3624 :
3625 : case FIELD_TC :
3626 : {
3627 : uno::Reference< beans::XPropertySet > xTC(
3628 0 : m_xTextFactory->createInstance(
3629 0 : OUString::createFromAscii(aIt->second.cFieldServiceName)),
3630 0 : uno::UNO_QUERY_THROW);
3631 0 : if (!sFirstParam.isEmpty())
3632 : {
3633 0 : xTC->setPropertyValue(rPropNameSupplier.GetName(PROP_ALTERNATIVE_TEXT),
3634 0 : uno::makeAny(sFirstParam));
3635 : }
3636 0 : OUString sValue;
3637 : // \f TC entry in doc with multiple tables
3638 : // if( lcl_FindInCommand( pContext->GetCommand(), 'f', sValue ))
3639 : // {
3640 : // todo: unsupported
3641 : // }
3642 0 : if( lcl_FindInCommand( pContext->GetCommand(), 'l', sValue ))
3643 : // \l Outline Level
3644 : {
3645 0 : sal_Int32 nLevel = sValue.toInt32();
3646 0 : if( !sValue.isEmpty() && nLevel >= 0 && nLevel <= 10 )
3647 0 : xTC->setPropertyValue(rPropNameSupplier.GetName(PROP_LEVEL), uno::makeAny( (sal_Int16)nLevel ));
3648 : }
3649 : // if( lcl_FindInCommand( pContext->GetCommand(), 'n', sValue ))
3650 : // \n Suppress page numbers
3651 : // {
3652 : //todo: unsupported feature
3653 : // }
3654 0 : pContext->SetTC( xTC );
3655 : }
3656 0 : break;
3657 : case FIELD_NUMCHARS:
3658 : case FIELD_NUMWORDS:
3659 : case FIELD_NUMPAGES:
3660 14 : if (xFieldProperties.is())
3661 14 : xFieldProperties->setPropertyValue(
3662 : rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
3663 14 : uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) ));
3664 14 : break;
3665 1785 : }
3666 : }
3667 : else
3668 : {
3669 : /* Unsupported fields will be handled here for docx file.
3670 : * To handle unsupported fields used fieldmark API.
3671 : */
3672 79 : OUString aCode( pContext->GetCommand().trim() );
3673 79 : xFieldInterface = m_xTextFactory->createInstance("com.sun.star.text.Fieldmark");
3674 158 : const uno::Reference<text::XTextContent> xTextContent(xFieldInterface, uno::UNO_QUERY_THROW);
3675 158 : uno::Reference< text::XTextAppend > xTextAppend;
3676 79 : xTextAppend = m_aTextAppendStack.top().xTextAppend;
3677 158 : uno::Reference< text::XTextCursor > xCrsr = xTextAppend->createTextCursorByRange(pContext->GetStartRange());
3678 79 : if (xTextContent.is())
3679 : {
3680 79 : xTextAppend->insertTextContent(xCrsr,xTextContent, sal_True);
3681 : }
3682 158 : const uno::Reference<uno::XInterface> xContent(xTextContent);
3683 158 : uno::Reference< text::XFormField> xFormField(xContent, uno::UNO_QUERY);
3684 79 : xFormField->setFieldType(aCode);
3685 79 : m_bStartGenericField = true;
3686 158 : pContext->SetFormField( xFormField );
3687 : }
3688 : //set the text field if there is any
3689 3727 : pContext->SetTextField( uno::Reference< text::XTextField >( xFieldInterface, uno::UNO_QUERY ) );
3690 : }
3691 1 : catch( const uno::Exception& e )
3692 : {
3693 : SAL_WARN( "writerfilter", "Exception in CloseFieldCommand(): " << e.Message );
3694 : }
3695 1864 : pContext->SetCommandCompleted();
3696 1864 : }
3697 1864 : }
3698 : /*-------------------------------------------------------------------------
3699 : //the _current_ fields require a string type result while TOCs accept richt results
3700 : -----------------------------------------------------------------------*/
3701 2607 : bool DomainMapper_Impl::IsFieldResultAsString()
3702 : {
3703 2607 : bool bRet = false;
3704 : OSL_ENSURE( !m_aFieldStack.empty(), "field stack empty?");
3705 2607 : FieldContextPtr pContext = m_aFieldStack.top();
3706 : OSL_ENSURE( pContext.get(), "no field context available");
3707 2607 : if( pContext.get() )
3708 : {
3709 2607 : bRet = pContext->GetTextField().is();
3710 : }
3711 2607 : return bRet;
3712 : }
3713 :
3714 282 : void DomainMapper_Impl::AppendFieldResult(OUString const& rString)
3715 : {
3716 : assert(!m_aFieldStack.empty());
3717 282 : FieldContextPtr pContext = m_aFieldStack.top();
3718 : SAL_WARN_IF(!pContext.get(), "writerfilter.dmapper", "no field context");
3719 282 : if (pContext.get())
3720 : {
3721 282 : pContext->AppendResult(rString);
3722 282 : }
3723 282 : }
3724 :
3725 242 : void DomainMapper_Impl::SetFieldResult(OUString const& rResult)
3726 : {
3727 : #ifdef DEBUG_DOMAINMAPPER
3728 : dmapper_logger->startElement("setFieldResult");
3729 : dmapper_logger->chars(rResult);
3730 : #endif
3731 :
3732 242 : FieldContextPtr pContext = m_aFieldStack.top();
3733 : OSL_ENSURE( pContext.get(), "no field context available");
3734 242 : if( pContext.get() )
3735 : {
3736 242 : uno::Reference<text::XTextField> xTextField = pContext->GetTextField();
3737 : try
3738 : {
3739 242 : PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
3740 : OSL_ENSURE( xTextField.is()
3741 : //||m_xTOC.is() ||m_xTC.is()
3742 : //||m_sHyperlinkURL.getLength()
3743 : , "DomainMapper_Impl::SetFieldResult: field not created" );
3744 242 : if(xTextField.is())
3745 : {
3746 : try
3747 : {
3748 242 : if( m_bSetUserFieldContent )
3749 : {
3750 : // user field content has to be set at the field master
3751 2 : uno::Reference< text::XDependentTextField > xDependentField( xTextField, uno::UNO_QUERY_THROW );
3752 4 : xDependentField->getTextFieldMaster()->setPropertyValue(
3753 : rPropNameSupplier.GetName(PROP_CONTENT),
3754 4 : uno::makeAny( rResult ));
3755 : }
3756 240 : else if ( m_bSetCitation )
3757 : {
3758 :
3759 18 : uno::Reference< beans::XPropertySet > xFieldProperties( xTextField, uno::UNO_QUERY_THROW);
3760 : // In case of SetExpression, the field result contains the content of the variable.
3761 36 : uno::Reference<lang::XServiceInfo> xServiceInfo(xTextField, uno::UNO_QUERY);
3762 :
3763 18 : bool bIsSetbiblio = xServiceInfo->supportsService("com.sun.star.text.TextField.Bibliography");
3764 18 : if( bIsSetbiblio )
3765 : {
3766 18 : com::sun::star::uno::Any aProperty = xFieldProperties->getPropertyValue("Fields");
3767 36 : uno::Sequence<com::sun::star::beans::PropertyValue> aValues ;
3768 18 : aProperty >>= aValues;
3769 36 : com::sun::star::beans::PropertyValue propertyVal;
3770 18 : bool bTitleFound = false;
3771 18 : int i=0;
3772 378 : for (; i < aValues.getLength(); i++)
3773 : {
3774 378 : propertyVal = aValues[i];
3775 378 : if(propertyVal.Name == "Title")
3776 : {
3777 18 : bTitleFound = true;
3778 18 : break;
3779 : }
3780 : }
3781 18 : if(bTitleFound)
3782 : {
3783 18 : OUString titleStr;
3784 36 : uno::Any aValue(propertyVal.Value);
3785 18 : aValue >>= titleStr;
3786 18 : titleStr = titleStr + rResult;
3787 18 : propertyVal.Value = uno::makeAny(titleStr);
3788 36 : aValues[i] = propertyVal;
3789 : }
3790 : else
3791 : {
3792 0 : propertyVal.Name = "Title";
3793 0 : propertyVal.Value = uno::makeAny(rResult);
3794 0 : aValues[i] = propertyVal;
3795 : }
3796 18 : xFieldProperties->setPropertyValue("Fields",
3797 36 : uno::makeAny(aValues));
3798 18 : }
3799 : }
3800 : else
3801 : {
3802 222 : uno::Reference< beans::XPropertySet > xFieldProperties( xTextField, uno::UNO_QUERY_THROW);
3803 : // In case of SetExpression, the field result contains the content of the variable.
3804 444 : uno::Reference<lang::XServiceInfo> xServiceInfo(xTextField, uno::UNO_QUERY);
3805 222 : bool bIsSetExpression = xServiceInfo->supportsService("com.sun.star.text.TextField.SetExpression");
3806 : // If we already have content set, then use the current presentation
3807 444 : rtl::OUString sValue;
3808 222 : if (bIsSetExpression)
3809 : { // this will throw for field types without Content
3810 40 : uno::Any aValue(xFieldProperties->getPropertyValue(
3811 40 : rPropNameSupplier.GetName(PROP_CONTENT)));
3812 40 : aValue >>= sValue;
3813 : }
3814 222 : xFieldProperties->setPropertyValue(
3815 40 : rPropNameSupplier.GetName(bIsSetExpression && sValue.isEmpty()? PROP_CONTENT : PROP_CURRENT_PRESENTATION),
3816 594 : uno::makeAny( rResult ));
3817 : }
3818 : }
3819 149 : catch( const beans::UnknownPropertyException& )
3820 : {
3821 : //some fields don't have a CurrentPresentation (DateTime)
3822 : }
3823 : }
3824 : }
3825 0 : catch (const uno::Exception& e)
3826 : {
3827 : SAL_WARN("writerfilter.dmapper",
3828 : "DomainMapper_Impl::SetFieldResult: exception: " << e.Message);
3829 242 : }
3830 242 : }
3831 242 : }
3832 :
3833 20 : void DomainMapper_Impl::SetFieldFFData(FFDataHandler::Pointer_t pFFDataHandler)
3834 : {
3835 : #ifdef DEBUG_DOMAINMAPPER
3836 : dmapper_logger->startElement("setFieldFFData");
3837 : #endif
3838 :
3839 20 : if (m_aFieldStack.size())
3840 : {
3841 19 : FieldContextPtr pContext = m_aFieldStack.top();
3842 19 : if (pContext.get())
3843 : {
3844 19 : pContext->setFFDataHandler(pFFDataHandler);
3845 19 : }
3846 : }
3847 :
3848 : #ifdef DEBUG_DOMAINMAPPER
3849 : dmapper_logger->endElement();
3850 : #endif
3851 20 : }
3852 :
3853 : /*-------------------------------------------------------------------------
3854 : //the end of field is reached (0x15 appeared) - the command might still be open
3855 : -----------------------------------------------------------------------*/
3856 1864 : void DomainMapper_Impl::PopFieldContext()
3857 : {
3858 : #ifdef DEBUG_DOMAINMAPPER
3859 : dmapper_logger->element("popFieldContext");
3860 : #endif
3861 :
3862 1864 : if (m_aFieldStack.empty())
3863 1865 : return;
3864 :
3865 1863 : FieldContextPtr pContext = m_aFieldStack.top();
3866 : OSL_ENSURE( pContext.get(), "no field context available");
3867 1863 : if( pContext.get() )
3868 : {
3869 1863 : if( !pContext->IsCommandCompleted() )
3870 106 : CloseFieldCommand();
3871 :
3872 1863 : if (!pContext->GetResult().isEmpty())
3873 242 : SetFieldResult(pContext->GetResult());
3874 :
3875 : //insert the field, TC or TOC
3876 1863 : uno::Reference< text::XTextAppend > xTextAppend;
3877 1863 : if (!m_aTextAppendStack.empty())
3878 1863 : xTextAppend = m_aTextAppendStack.top().xTextAppend;
3879 1863 : if(xTextAppend.is())
3880 : {
3881 : try
3882 : {
3883 1863 : uno::Reference< text::XTextCursor > xCrsr = xTextAppend->createTextCursorByRange(pContext->GetStartRange());
3884 3726 : uno::Reference< text::XTextContent > xToInsert( pContext->GetTOC(), uno::UNO_QUERY );
3885 1863 : if( xToInsert.is() )
3886 : {
3887 74 : if(xTOCMarkerCursor.is() || m_bStartIndex || m_bStartBibliography)
3888 : {
3889 74 : if (m_bStartIndex || m_bStartBibliography)
3890 : {
3891 33 : if (mxTOCTextCursor.is())
3892 : {
3893 33 : mxTOCTextCursor->goLeft(1,true);
3894 33 : mxTOCTextCursor->setString(OUString());
3895 : }
3896 33 : xTextAppend->finishParagraph( uno::Sequence< beans::PropertyValue >() );
3897 : }
3898 : else
3899 : {
3900 41 : xTOCMarkerCursor->goLeft(1,sal_True);
3901 41 : xTOCMarkerCursor->setString(OUString());
3902 41 : xTOCMarkerCursor->goLeft(1,sal_True);
3903 41 : xTOCMarkerCursor->setString(OUString());
3904 : }
3905 : }
3906 74 : if (m_bStartedTOC || m_bStartIndex || m_bStartBibliography)
3907 : {
3908 72 : m_bStartedTOC = false;
3909 72 : m_aTextAppendStack.pop();
3910 72 : m_bTextInserted = false;
3911 : }
3912 74 : m_bStartTOC = false;
3913 74 : m_bStartIndex = false;
3914 74 : m_bStartBibliography = false;
3915 : }
3916 : else
3917 : {
3918 1789 : xToInsert = uno::Reference< text::XTextContent >(pContext->GetTC(), uno::UNO_QUERY);
3919 1789 : if( !xToInsert.is() && !m_bStartTOC && !m_bStartIndex && !m_bStartBibliography )
3920 1105 : xToInsert = uno::Reference< text::XTextContent >(pContext->GetTextField(), uno::UNO_QUERY);
3921 1789 : if( xToInsert.is() && !m_bStartTOC && !m_bStartIndex && !m_bStartBibliography)
3922 : {
3923 253 : uno::Sequence<beans::PropertyValue> aValues;
3924 : // Character properties of the field show up here the
3925 : // last (always empty) run. Inherit character
3926 : // properties from there.
3927 253 : if (m_pLastCharacterContext.get())
3928 253 : aValues = m_pLastCharacterContext->GetPropertyValues();
3929 253 : appendTextContent(xToInsert, aValues);
3930 : }
3931 : else
3932 : {
3933 1536 : FormControlHelper::Pointer_t pFormControlHelper(pContext->getFormControlHelper());
3934 1536 : if (pFormControlHelper.get() != NULL && pFormControlHelper->hasFFDataHandler() )
3935 : {
3936 8 : uno::Reference< text::XFormField > xFormField( pContext->GetFormField() );
3937 8 : xToInsert.set(xFormField, uno::UNO_QUERY);
3938 8 : if ( xFormField.is() && xToInsert.is() )
3939 : {
3940 8 : xCrsr->gotoEnd( true );
3941 8 : xToInsert->attach( uno::Reference< text::XTextRange >( xCrsr, uno::UNO_QUERY_THROW ));
3942 8 : pFormControlHelper->processField( xFormField );
3943 : }
3944 : else
3945 : {
3946 0 : uno::Reference<text::XTextRange> xTxtRange(xCrsr, uno::UNO_QUERY);
3947 0 : pFormControlHelper->insertControl(xTxtRange);
3948 8 : }
3949 : }
3950 1528 : else if(!pContext->GetHyperlinkURL().isEmpty())
3951 : {
3952 930 : PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
3953 930 : xCrsr->gotoEnd( true );
3954 :
3955 930 : uno::Reference< beans::XPropertySet > xCrsrProperties( xCrsr, uno::UNO_QUERY_THROW );
3956 930 : xCrsrProperties->setPropertyValue(rPropNameSupplier.GetName(PROP_HYPER_LINK_U_R_L), uno::
3957 930 : makeAny(pContext->GetHyperlinkURL()));
3958 :
3959 930 : if (m_bStartTOC) {
3960 293 : OUString sDisplayName("Index Link");
3961 293 : xCrsrProperties->setPropertyValue("VisitedCharStyleName",uno::makeAny(sDisplayName));
3962 293 : xCrsrProperties->setPropertyValue("UnvisitedCharStyleName",uno::makeAny(sDisplayName));
3963 930 : }
3964 : }
3965 598 : else if(m_bStartGenericField)
3966 : {
3967 78 : m_bStartGenericField = false;
3968 78 : if(m_bTextInserted)
3969 : {
3970 54 : m_aTextAppendStack.pop();
3971 54 : m_bTextInserted = false;
3972 : }
3973 1536 : }
3974 : }
3975 1863 : }
3976 : }
3977 0 : catch(const lang::IllegalArgumentException&)
3978 : {
3979 : OSL_FAIL( "IllegalArgumentException in PopFieldContext()" );
3980 : }
3981 0 : catch(const uno::Exception&)
3982 : {
3983 : OSL_FAIL( "exception in PopFieldContext()" );
3984 : }
3985 1863 : }
3986 :
3987 : //TOCs have to include all the imported content
3988 :
3989 : }
3990 : //remove the field context
3991 1863 : m_aFieldStack.pop();
3992 : }
3993 :
3994 :
3995 3100 : void DomainMapper_Impl::AddBookmark( const OUString& rBookmarkName, const OUString& rId )
3996 : {
3997 3100 : if (m_aTextAppendStack.empty())
3998 3100 : return;
3999 3100 : uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend;
4000 3100 : BookmarkMap_t::iterator aBookmarkIter = m_aBookmarkMap.find( rId );
4001 : //is the bookmark name already registered?
4002 : try
4003 : {
4004 3100 : if( aBookmarkIter != m_aBookmarkMap.end() )
4005 : {
4006 1491 : static const OUString sBookmarkService("com.sun.star.text.Bookmark");
4007 1491 : if (m_xTextFactory.is())
4008 : {
4009 1491 : uno::Reference< text::XTextContent > xBookmark( m_xTextFactory->createInstance( sBookmarkService ), uno::UNO_QUERY_THROW );
4010 2982 : uno::Reference< text::XTextCursor > xCursor;
4011 2982 : uno::Reference< text::XText > xText = aBookmarkIter->second.m_xTextRange->getText();
4012 1491 : if( aBookmarkIter->second.m_bIsStartOfText )
4013 262 : xCursor = xText->createTextCursorByRange( xText->getStart() );
4014 : else
4015 : {
4016 1229 : xCursor = xText->createTextCursorByRange( aBookmarkIter->second.m_xTextRange );
4017 1229 : xCursor->goRight( 1, false );
4018 : }
4019 :
4020 1491 : xCursor->gotoRange( xTextAppend->getEnd(), true );
4021 2982 : uno::Reference< container::XNamed > xBkmNamed( xBookmark, uno::UNO_QUERY_THROW );
4022 : //todo: make sure the name is not used already!
4023 1491 : if ( !aBookmarkIter->second.m_sBookmarkName.isEmpty() )
4024 1491 : xBkmNamed->setName( aBookmarkIter->second.m_sBookmarkName );
4025 : else
4026 0 : xBkmNamed->setName( rBookmarkName );
4027 2982 : xTextAppend->insertTextContent( uno::Reference< text::XTextRange >( xCursor, uno::UNO_QUERY_THROW), xBookmark, !xCursor->isCollapsed() );
4028 : }
4029 1491 : m_aBookmarkMap.erase( aBookmarkIter );
4030 : }
4031 : else
4032 : {
4033 : //otherwise insert a text range as marker
4034 1609 : bool bIsStart = true;
4035 1609 : uno::Reference< text::XTextRange > xCurrent;
4036 1609 : if (xTextAppend.is())
4037 : {
4038 1609 : uno::Reference< text::XTextCursor > xCursor = xTextAppend->createTextCursorByRange( xTextAppend->getEnd() );
4039 1609 : bIsStart = !xCursor->goLeft(1, false);
4040 1609 : xCurrent = xCursor->getStart();
4041 : }
4042 1609 : m_aBookmarkMap.insert(BookmarkMap_t::value_type( rId, BookmarkInsertPosition( bIsStart, rBookmarkName, xCurrent ) ));
4043 : }
4044 : }
4045 0 : catch( const uno::Exception& )
4046 : {
4047 : //TODO: What happens to bookmarks where start and end are at different XText objects?
4048 3100 : }
4049 : }
4050 :
4051 32 : void DomainMapper_Impl::AddAnnotationPosition(
4052 : const bool bStart,
4053 : const sal_Int32 nAnnotationId)
4054 : {
4055 32 : if (m_aTextAppendStack.empty())
4056 32 : return;
4057 :
4058 : // Create a cursor, pointing to the current position.
4059 32 : uno::Reference<text::XTextAppend> xTextAppend = m_aTextAppendStack.top().xTextAppend;
4060 64 : uno::Reference<text::XTextRange> xCurrent;
4061 32 : if (xTextAppend.is())
4062 : {
4063 32 : uno::Reference<text::XTextCursor> xCursor;
4064 32 : if (m_bIsNewDoc)
4065 30 : xCursor = xTextAppend->createTextCursorByRange(xTextAppend->getEnd());
4066 : else
4067 2 : xCursor = m_aTextAppendStack.top().xCursor;
4068 32 : if (xCursor.is())
4069 32 : xCurrent = xCursor->getStart();
4070 : }
4071 :
4072 : // And save it, to be used by PopAnnotation() later.
4073 32 : AnnotationPosition& aAnnotationPosition = m_aAnnotationPositions[ nAnnotationId ];
4074 32 : if (bStart)
4075 : {
4076 16 : aAnnotationPosition.m_xStart = xCurrent;
4077 : }
4078 : else
4079 : {
4080 16 : aAnnotationPosition.m_xEnd = xCurrent;
4081 : }
4082 64 : m_aAnnotationPositions[ nAnnotationId ] = aAnnotationPosition;
4083 : }
4084 :
4085 1796 : GraphicImportPtr DomainMapper_Impl::GetGraphicImport(GraphicImportType eGraphicImportType)
4086 : {
4087 1796 : if(!m_pGraphicImport)
4088 898 : m_pGraphicImport.reset( new GraphicImport( m_xComponentContext, m_xTextFactory, m_rDMapper, eGraphicImportType, m_aPositivePercentages ) );
4089 1796 : return m_pGraphicImport;
4090 : }
4091 : /*-------------------------------------------------------------------------
4092 : reset graphic import if the last import resulted in a shape, not a graphic
4093 : -----------------------------------------------------------------------*/
4094 0 : void DomainMapper_Impl::ResetGraphicImport()
4095 : {
4096 0 : m_pGraphicImport.reset();
4097 0 : }
4098 :
4099 :
4100 898 : void DomainMapper_Impl::ImportGraphic(writerfilter::Reference< Properties >::Pointer_t ref, GraphicImportType eGraphicImportType)
4101 : {
4102 898 : GetGraphicImport(eGraphicImportType);
4103 898 : if( eGraphicImportType != IMPORT_AS_DETECTED_INLINE && eGraphicImportType != IMPORT_AS_DETECTED_ANCHOR )
4104 : {
4105 : //create the graphic
4106 0 : ref->resolve( *m_pGraphicImport );
4107 : }
4108 :
4109 : //insert it into the document at the current cursor position
4110 :
4111 : uno::Reference<text::XTextContent> xTextContent
4112 898 : (m_pGraphicImport->GetGraphicObject());
4113 :
4114 : // Update the shape properties if it is embedded object.
4115 898 : if(m_xEmbedded.is()){
4116 72 : UpdateEmbeddedShapeProps(m_pGraphicImport->GetXShapeObject());
4117 : }
4118 : //insert it into the document at the current cursor position
4119 : OSL_ENSURE( xTextContent.is(), "DomainMapper_Impl::ImportGraphic");
4120 898 : if( xTextContent.is())
4121 897 : appendTextContent( xTextContent, uno::Sequence< beans::PropertyValue >() );
4122 :
4123 898 : m_pGraphicImport.reset();
4124 898 : }
4125 :
4126 :
4127 :
4128 7 : void DomainMapper_Impl::SetLineNumbering( sal_Int32 nLnnMod, sal_Int32 nLnc, sal_Int32 ndxaLnn )
4129 : {
4130 7 : if( !m_bLineNumberingSet )
4131 : {
4132 7 : const PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
4133 :
4134 : try
4135 : {
4136 7 : uno::Reference< text::XLineNumberingProperties > xLineProperties( m_xTextDocument, uno::UNO_QUERY_THROW );
4137 14 : uno::Reference< beans::XPropertySet > xProperties = xLineProperties->getLineNumberingProperties();
4138 14 : uno::Any aTrue( uno::makeAny( true ));
4139 7 : xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_IS_ON ), aTrue);
4140 7 : xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_COUNT_EMPTY_LINES ), aTrue );
4141 7 : xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_COUNT_LINES_IN_FRAMES ), uno::makeAny( false ) );
4142 7 : xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_INTERVAL ), uno::makeAny( static_cast< sal_Int16 >( nLnnMod )));
4143 7 : xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_DISTANCE ), uno::makeAny( ConversionHelper::convertTwipToMM100(ndxaLnn) ));
4144 7 : xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_NUMBER_POSITION ), uno::makeAny( style::LineNumberPosition::LEFT));
4145 7 : xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_NUMBERING_TYPE ), uno::makeAny( style::NumberingType::ARABIC));
4146 14 : xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_RESTART_AT_EACH_PAGE ), uno::makeAny( nLnc == 0 ));
4147 : }
4148 0 : catch( const uno::Exception& )
4149 : {}
4150 : }
4151 7 : m_bLineNumberingSet = true;
4152 7 : }
4153 :
4154 :
4155 7463 : void DomainMapper_Impl::SetPageMarginTwip( PageMarElement eElement, sal_Int32 nValue )
4156 : {
4157 7463 : nValue = ConversionHelper::convertTwipToMM100(nValue);
4158 7463 : switch(eElement)
4159 : {
4160 1111 : case PAGE_MAR_TOP : m_aPageMargins.top = nValue; break;
4161 1114 : case PAGE_MAR_RIGHT : m_aPageMargins.right = nValue; break;
4162 1110 : case PAGE_MAR_BOTTOM : m_aPageMargins.bottom = nValue; break;
4163 1114 : case PAGE_MAR_LEFT : m_aPageMargins.left = nValue; break;
4164 1010 : case PAGE_MAR_HEADER : m_aPageMargins.header = nValue; break;
4165 1009 : case PAGE_MAR_FOOTER : m_aPageMargins.footer = nValue; break;
4166 995 : case PAGE_MAR_GUTTER : m_aPageMargins.gutter = nValue; break;
4167 : }
4168 7463 : }
4169 :
4170 :
4171 :
4172 2308 : _PageMar::_PageMar()
4173 : {
4174 2308 : header = footer = ConversionHelper::convertTwipToMM100(sal_Int32(720));
4175 2308 : top = bottom = ConversionHelper::convertTwipToMM100( sal_Int32(1440));
4176 : // This is strange, the RTF spec says it's 1800, but it's clearly 1440 in Word
4177 : // OOXML seems not to specify a default value
4178 2308 : right = left = ConversionHelper::convertTwipToMM100( sal_Int32(1440));
4179 2308 : gutter = 0;
4180 2308 : }
4181 :
4182 :
4183 :
4184 35 : void DomainMapper_Impl::RegisterFrameConversion(
4185 : uno::Reference< text::XTextRange > xFrameStartRange,
4186 : uno::Reference< text::XTextRange > xFrameEndRange,
4187 : uno::Sequence< beans::PropertyValue > aFrameProperties
4188 : )
4189 : {
4190 : OSL_ENSURE(
4191 : !m_aFrameProperties.getLength() && !m_xFrameStartRange.is() && !m_xFrameEndRange.is(),
4192 : "frame properties not removed");
4193 35 : m_aFrameProperties = aFrameProperties;
4194 35 : m_xFrameStartRange = xFrameStartRange;
4195 35 : m_xFrameEndRange = xFrameEndRange;
4196 35 : }
4197 :
4198 :
4199 24046 : bool DomainMapper_Impl::ExecuteFrameConversion()
4200 : {
4201 24046 : bool bRet = false;
4202 24046 : if( m_xFrameStartRange.is() && m_xFrameEndRange.is() )
4203 : {
4204 35 : bRet = true;
4205 : try
4206 : {
4207 35 : uno::Reference< text::XTextAppendAndConvert > xTextAppendAndConvert( GetTopTextAppend(), uno::UNO_QUERY_THROW );
4208 35 : xTextAppendAndConvert->convertToTextFrame(
4209 : m_xFrameStartRange,
4210 : m_xFrameEndRange,
4211 35 : m_aFrameProperties );
4212 : }
4213 0 : catch( const uno::Exception& rEx)
4214 : {
4215 : SAL_WARN( "writerfilter", "Exception caught when converting to frame: " + rEx.Message );
4216 0 : bRet = false;
4217 : }
4218 35 : m_xFrameStartRange = 0;
4219 35 : m_xFrameEndRange = 0;
4220 35 : m_aFrameProperties.realloc( 0 );
4221 : }
4222 24046 : return bRet;
4223 : }
4224 :
4225 912 : void DomainMapper_Impl::AddNewRedline( )
4226 : {
4227 912 : RedlineParamsPtr pNew( new RedlineParams );
4228 912 : pNew->m_nToken = OOXML_mod;
4229 912 : if ( !m_bIsParaMarkerChange )
4230 : {
4231 688 : m_aRedlines.top().push_back( pNew );
4232 : }
4233 : else
4234 : {
4235 224 : m_pParaMarkerRedline.swap( pNew );
4236 912 : }
4237 912 : }
4238 :
4239 2815 : RedlineParamsPtr DomainMapper_Impl::GetTopRedline( )
4240 : {
4241 2815 : RedlineParamsPtr pResult;
4242 2815 : if ( !m_bIsParaMarkerChange && m_aRedlines.top().size( ) > 0 )
4243 1692 : pResult = m_aRedlines.top().back( );
4244 1123 : else if ( m_bIsParaMarkerChange )
4245 1112 : pResult = m_pParaMarkerRedline;
4246 2815 : return pResult;
4247 : }
4248 :
4249 912 : sal_Int32 DomainMapper_Impl::GetCurrentRedlineToken( )
4250 : {
4251 912 : sal_Int32 nToken = 0;
4252 912 : RedlineParamsPtr pCurrent( GetTopRedline( ) );
4253 912 : if ( pCurrent.get( ) )
4254 912 : nToken = pCurrent->m_nToken;
4255 912 : return nToken;
4256 : }
4257 :
4258 469 : void DomainMapper_Impl::SetCurrentRedlineAuthor( const OUString& sAuthor )
4259 : {
4260 469 : if (!m_xAnnotationField.is())
4261 : {
4262 452 : RedlineParamsPtr pCurrent( GetTopRedline( ) );
4263 452 : if ( pCurrent.get( ) )
4264 452 : pCurrent->m_sAuthor = sAuthor;
4265 : }
4266 : else
4267 17 : m_xAnnotationField->setPropertyValue("Author", uno::makeAny(sAuthor));
4268 469 : }
4269 :
4270 16 : void DomainMapper_Impl::SetCurrentRedlineInitials( const OUString& sInitials )
4271 : {
4272 16 : if (m_xAnnotationField.is())
4273 16 : m_xAnnotationField->setPropertyValue("Initials", uno::makeAny(sInitials));
4274 16 : }
4275 :
4276 455 : void DomainMapper_Impl::SetCurrentRedlineDate( const OUString& sDate )
4277 : {
4278 455 : if (!m_xAnnotationField.is())
4279 : {
4280 438 : RedlineParamsPtr pCurrent( GetTopRedline( ) );
4281 438 : if ( pCurrent.get( ) )
4282 438 : pCurrent->m_sDate = sDate;
4283 : }
4284 : else
4285 17 : m_xAnnotationField->setPropertyValue("DateTimeValue", uno::makeAny(ConversionHelper::ConvertDateStringToDateTime(sDate)));
4286 455 : }
4287 :
4288 480 : void DomainMapper_Impl::SetCurrentRedlineId( sal_Int32 sId )
4289 : {
4290 480 : if (m_xAnnotationField.is())
4291 : {
4292 17 : m_nAnnotationId = sId;
4293 : }
4294 : else
4295 : {
4296 463 : RedlineParamsPtr pCurrent( GetTopRedline( ) );
4297 463 : if ( pCurrent.get( ) )
4298 452 : pCurrent->m_nId = sId;
4299 : }
4300 480 : }
4301 :
4302 452 : void DomainMapper_Impl::SetCurrentRedlineToken( sal_Int32 nToken )
4303 : {
4304 452 : RedlineParamsPtr pCurrent( GetTopRedline( ) );
4305 452 : if ( pCurrent.get( ) )
4306 452 : pCurrent->m_nToken = nToken;
4307 452 : }
4308 :
4309 98 : void DomainMapper_Impl::SetCurrentRedlineRevertProperties( uno::Sequence<beans::PropertyValue> aProperties )
4310 : {
4311 98 : RedlineParamsPtr pCurrent( GetTopRedline( ) );
4312 98 : if ( pCurrent.get( ) )
4313 98 : pCurrent->m_aRevertProperties = aProperties;
4314 98 : }
4315 :
4316 :
4317 586 : void DomainMapper_Impl::RemoveCurrentRedline( )
4318 : {
4319 586 : if ( m_aRedlines.top().size( ) > 0 )
4320 : {
4321 165 : m_aRedlines.top().pop_back( );
4322 : }
4323 586 : }
4324 :
4325 117 : void DomainMapper_Impl::ResetParaMarkerRedline( )
4326 : {
4327 117 : if ( m_pParaMarkerRedline.get( ) )
4328 : {
4329 117 : RedlineParamsPtr pEmpty;
4330 117 : m_pParaMarkerRedline.swap( pEmpty );
4331 : }
4332 117 : }
4333 :
4334 :
4335 :
4336 1177 : void DomainMapper_Impl::ApplySettingsTable()
4337 : {
4338 1177 : if (m_pSettingsTable && m_xTextFactory.is())
4339 : {
4340 : try
4341 : {
4342 1165 : uno::Reference< beans::XPropertySet > xTextDefaults(m_xTextFactory->createInstance("com.sun.star.text.Defaults"), uno::UNO_QUERY_THROW );
4343 1165 : sal_Int32 nDefTab = m_pSettingsTable->GetDefaultTabStop();
4344 1165 : xTextDefaults->setPropertyValue( PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_TAB_STOP_DISTANCE ), uno::makeAny(nDefTab) );
4345 1165 : if (m_pSettingsTable->GetLinkStyles())
4346 : {
4347 3 : PropertyNameSupplier& rSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
4348 : // If linked styles are enabled, set paragraph defaults from Word's default template
4349 3 : xTextDefaults->setPropertyValue(rSupplier.GetName(PROP_PARA_BOTTOM_MARGIN), uno::makeAny(ConversionHelper::convertTwipToMM100(200)));
4350 3 : style::LineSpacing aSpacing;
4351 3 : aSpacing.Mode = style::LineSpacingMode::PROP;
4352 3 : aSpacing.Height = sal_Int16(115);
4353 3 : xTextDefaults->setPropertyValue(rSupplier.GetName(PROP_PARA_LINE_SPACING), uno::makeAny(aSpacing));
4354 : }
4355 :
4356 1165 : if (m_pSettingsTable->GetZoomFactor())
4357 : {
4358 948 : uno::Sequence<beans::PropertyValue> aViewProps(3);
4359 948 : aViewProps[0].Name = "ZoomFactor";
4360 948 : aViewProps[0].Value <<= m_pSettingsTable->GetZoomFactor();
4361 948 : aViewProps[1].Name = "VisibleBottom";
4362 948 : aViewProps[1].Value <<= sal_Int32(0);
4363 948 : aViewProps[2].Name = "ZoomType";
4364 948 : aViewProps[2].Value <<= sal_Int16(0);
4365 :
4366 1896 : uno::Reference<container::XIndexContainer> xBox = document::IndexedPropertyValues::create(m_xComponentContext);
4367 948 : xBox->insertByIndex(sal_Int32(0), uno::makeAny(aViewProps));
4368 1896 : uno::Reference<container::XIndexAccess> xIndexAccess(xBox, uno::UNO_QUERY);
4369 1896 : uno::Reference<document::XViewDataSupplier> xViewDataSupplier(m_xTextDocument, uno::UNO_QUERY);
4370 1896 : xViewDataSupplier->setViewData(xIndexAccess);
4371 : }
4372 :
4373 2330 : uno::Reference< beans::XPropertySet > xSettings(m_xTextFactory->createInstance("com.sun.star.document.Settings"), uno::UNO_QUERY);
4374 1165 : if (m_pSettingsTable->GetUsePrinterMetrics())
4375 0 : xSettings->setPropertyValue("PrinterIndependentLayout", uno::makeAny(document::PrinterIndependentLayout::DISABLED));
4376 1165 : if( m_pSettingsTable->GetEmbedTrueTypeFonts())
4377 0 : xSettings->setPropertyValue( PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_EMBED_FONTS ), uno::makeAny(true) );
4378 1165 : if( m_pSettingsTable->GetEmbedSystemFonts())
4379 68 : xSettings->setPropertyValue( PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_EMBED_SYSTEM_FONTS ), uno::makeAny(true) );
4380 2330 : xSettings->setPropertyValue("AddParaTableSpacing", uno::makeAny(m_pSettingsTable->GetDoNotUseHTMLParagraphAutoSpacing()));
4381 : }
4382 0 : catch(const uno::Exception&)
4383 : {
4384 : }
4385 : }
4386 1177 : }
4387 :
4388 49962 : uno::Reference<container::XIndexAccess> DomainMapper_Impl::GetCurrentNumberingRules(sal_Int32* pListLevel)
4389 : {
4390 49962 : uno::Reference<container::XIndexAccess> xRet;
4391 : try
4392 : {
4393 49962 : OUString aStyle = GetCurrentParaStyleId();
4394 49962 : if (aStyle.isEmpty() || GetTopContextType() != CONTEXT_PARAGRAPH)
4395 36027 : return xRet;
4396 13967 : const StyleSheetEntryPtr pEntry = GetStyleSheetTable()->FindStyleSheetByISTD(aStyle);
4397 13935 : if (!pEntry)
4398 6348 : return xRet;
4399 7587 : const StyleSheetPropertyMap* pStyleSheetProperties = dynamic_cast<const StyleSheetPropertyMap*>(pEntry->pProperties.get());
4400 7587 : if (!pStyleSheetProperties)
4401 0 : return xRet;
4402 7587 : sal_Int32 nListId = pStyleSheetProperties->GetListId();
4403 7587 : if (nListId < 0)
4404 7555 : return xRet;
4405 32 : if (pListLevel)
4406 30 : *pListLevel = pStyleSheetProperties->GetListLevel();
4407 :
4408 : // So we are in a paragraph style and it has numbering. Look up the relevant numbering rules.
4409 64 : OUString aListName = ListDef::GetStyleName(nListId);
4410 64 : uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier(GetTextDocument(), uno::UNO_QUERY);
4411 64 : uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies();
4412 64 : uno::Reference<container::XNameAccess> xNumberingStyles;
4413 32 : xStyleFamilies->getByName("NumberingStyles") >>= xNumberingStyles;
4414 64 : uno::Reference<beans::XPropertySet> xStyle(xNumberingStyles->getByName(aListName), uno::UNO_QUERY);
4415 64 : xRet.set(xStyle->getPropertyValue("NumberingRules"), uno::UNO_QUERY);
4416 : }
4417 0 : catch( const uno::Exception& )
4418 : {
4419 : }
4420 32 : return xRet;
4421 : }
4422 :
4423 49960 : uno::Reference<beans::XPropertySet> DomainMapper_Impl::GetCurrentNumberingCharStyle()
4424 : {
4425 49960 : uno::Reference<beans::XPropertySet> xRet;
4426 : try
4427 : {
4428 49960 : sal_Int32 nListLevel = -1;
4429 49960 : uno::Reference<container::XIndexAccess> xLevels = GetCurrentNumberingRules(&nListLevel);
4430 49960 : if (!xLevels.is())
4431 49930 : return xRet;
4432 60 : uno::Sequence<beans::PropertyValue> aProps;
4433 30 : xLevels->getByIndex(nListLevel) >>= aProps;
4434 125 : for (int i = 0; i < aProps.getLength(); ++i)
4435 : {
4436 125 : const beans::PropertyValue& rProp = aProps[i];
4437 :
4438 125 : if (rProp.Name == "CharStyleName")
4439 : {
4440 25 : OUString aCharStyle;
4441 25 : rProp.Value >>= aCharStyle;
4442 50 : uno::Reference<container::XNameAccess> xCharacterStyles;
4443 50 : uno::Reference< style::XStyleFamiliesSupplier > xStylesSupplier(GetTextDocument(), uno::UNO_QUERY);
4444 50 : uno::Reference< container::XNameAccess > xStyleFamilies = xStylesSupplier->getStyleFamilies();
4445 25 : xStyleFamilies->getByName("CharacterStyles") >>= xCharacterStyles;
4446 25 : xRet.set(xCharacterStyles->getByName(aCharStyle), uno::UNO_QUERY_THROW);
4447 27 : break;
4448 : }
4449 30 : }
4450 : }
4451 28 : catch( const uno::Exception& )
4452 : {
4453 : }
4454 30 : return xRet;
4455 : }
4456 :
4457 480670 : SectionPropertyMap * DomainMapper_Impl::GetSectionContext()
4458 : {
4459 480670 : SectionPropertyMap* pSectionContext = 0;
4460 : //the section context is not available before the first call of startSectionGroup()
4461 480670 : if( !IsAnyTableImport() )
4462 : {
4463 311994 : PropertyMapPtr pContext = GetTopContextOfType(CONTEXT_SECTION);
4464 : OSL_ENSURE(pContext.get(), "Section context is not in the stack!");
4465 311994 : pSectionContext = dynamic_cast< SectionPropertyMap* >( pContext.get() );
4466 : }
4467 :
4468 480670 : return pSectionContext;
4469 : }
4470 :
4471 40939 : void DomainMapper_Impl::deferCharacterProperty( sal_Int32 id, com::sun::star::uno::Any value )
4472 : {
4473 40939 : deferredCharacterProperties[ id ] = value;
4474 40939 : }
4475 :
4476 15813 : void DomainMapper_Impl::processDeferredCharacterProperties()
4477 : {
4478 : // ACtually process in DomainMapper, so that it's the same source file like normal processing.
4479 15813 : if( !deferredCharacterProperties.empty())
4480 : {
4481 15813 : m_rDMapper.processDeferredCharacterProperties( deferredCharacterProperties );
4482 15813 : deferredCharacterProperties.clear();
4483 : }
4484 15813 : }
4485 :
4486 6077 : sal_Int32 DomainMapper_Impl::getCurrentNumberingProperty(const OUString& aProp)
4487 : {
4488 6077 : sal_Int32 nRet = 0;
4489 :
4490 6077 : PropertyMap::iterator it = m_pTopContext->find(PROP_NUMBERING_RULES);
4491 6077 : uno::Reference<container::XIndexAccess> xNumberingRules;
4492 6077 : if (it != m_pTopContext->end())
4493 367 : xNumberingRules.set(it->second.getValue(), uno::UNO_QUERY);
4494 6077 : it = m_pTopContext->find(PROP_NUMBERING_LEVEL);
4495 6077 : sal_Int32 nNumberingLevel = -1;
4496 6077 : if (it != m_pTopContext->end())
4497 364 : it->second.getValue() >>= nNumberingLevel;
4498 6077 : if (xNumberingRules.is() && nNumberingLevel != -1)
4499 : {
4500 359 : uno::Sequence<beans::PropertyValue> aProps;
4501 359 : xNumberingRules->getByIndex(nNumberingLevel) >>= aProps;
4502 3646 : for (int i = 0; i < aProps.getLength(); ++i)
4503 : {
4504 3646 : const beans::PropertyValue& rProp = aProps[i];
4505 :
4506 3646 : if (rProp.Name == aProp)
4507 : {
4508 359 : rProp.Value >>= nRet;
4509 359 : break;
4510 : }
4511 359 : }
4512 : }
4513 :
4514 6077 : return nRet;
4515 : }
4516 :
4517 2655 : bool DomainMapper_Impl::IsNewDoc()
4518 : {
4519 2655 : return m_bIsNewDoc;
4520 : }
4521 :
4522 14646 : void DomainMapper_Impl::enableInteropGrabBag(const OUString& aName)
4523 : {
4524 14646 : m_aInteropGrabBagName = aName;
4525 14646 : }
4526 :
4527 14987 : void DomainMapper_Impl::disableInteropGrabBag()
4528 : {
4529 14987 : m_aInteropGrabBagName = "";
4530 14987 : m_aInteropGrabBag.clear();
4531 14987 : m_aSubInteropGrabBag.clear();
4532 14987 : }
4533 :
4534 119668 : bool DomainMapper_Impl::isInteropGrabBagEnabled()
4535 : {
4536 119668 : return !(m_aInteropGrabBagName.isEmpty());
4537 : }
4538 :
4539 168700 : void DomainMapper_Impl::appendGrabBag(std::vector<beans::PropertyValue>& rInteropGrabBag, const OUString& aKey, const OUString& aValue)
4540 : {
4541 168700 : if (m_aInteropGrabBagName.isEmpty())
4542 316252 : return;
4543 21148 : beans::PropertyValue aProperty;
4544 21148 : aProperty.Name = aKey;
4545 21148 : aProperty.Value = uno::makeAny(aValue);
4546 21148 : rInteropGrabBag.push_back(aProperty);
4547 : }
4548 :
4549 84832 : void DomainMapper_Impl::appendGrabBag(std::vector<beans::PropertyValue>& rInteropGrabBag, const OUString& aKey, std::vector<beans::PropertyValue>& rValue)
4550 : {
4551 84832 : if (m_aInteropGrabBagName.isEmpty())
4552 168823 : return;
4553 841 : beans::PropertyValue aProperty;
4554 841 : aProperty.Name = aKey;
4555 :
4556 1682 : uno::Sequence<beans::PropertyValue> aSeq(rValue.size());
4557 841 : beans::PropertyValue* pSeq = aSeq.getArray();
4558 2779 : for (std::vector<beans::PropertyValue>::iterator i = rValue.begin(); i != rValue.end(); ++i)
4559 1938 : *pSeq++ = *i;
4560 :
4561 841 : rValue.clear();
4562 841 : aProperty.Value = uno::makeAny(aSeq);
4563 1682 : rInteropGrabBag.push_back(aProperty);
4564 : }
4565 :
4566 : }}
4567 :
4568 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|