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