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