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