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