merge the formfield patch from ooo-build
[ooovba.git] / writerfilter / source / dmapper / DomainMapper_Impl.cxx
blob586b0028ed8c352520fefaeff5c761a3df21d6ca
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DomainMapper_Impl.cxx,v $
10 * $Revision: 1.27.6.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include <DomainMapper_Impl.hxx>
31 #include <ConversionHelper.hxx>
32 #include <DomainMapperTableHandler.hxx>
33 #include <com/sun/star/uno/XComponentContext.hpp>
34 #include <com/sun/star/graphic/XGraphic.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/beans/XPropertyState.hpp>
37 #include <com/sun/star/container/XIndexReplace.hpp>
38 #include <com/sun/star/container/XNamed.hpp>
39 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
40 #include <com/sun/star/drawing/XShapes.hpp>
41 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
42 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
43 #include <com/sun/star/style/LineNumberPosition.hpp>
44 #include <com/sun/star/style/NumberingType.hpp>
45 #include <com/sun/star/drawing/XShape.hpp>
46 #include <com/sun/star/table/BorderLine.hpp>
47 #include <com/sun/star/text/ChapterFormat.hpp>
48 #include <com/sun/star/text/FilenameDisplayFormat.hpp>
49 #include <com/sun/star/text/UserDataPart.hpp>
50 #include <com/sun/star/text/SetVariableType.hpp>
51 #include <com/sun/star/text/XFootnote.hpp>
52 #include <com/sun/star/text/XLineNumberingProperties.hpp>
53 #include <com/sun/star/text/PageNumberType.hpp>
54 #include <com/sun/star/text/RelOrientation.hpp>
55 #include <com/sun/star/text/HoriOrientation.hpp>
56 #include <com/sun/star/text/VertOrientation.hpp>
57 #include <com/sun/star/text/ReferenceFieldPart.hpp>
58 #include <com/sun/star/text/ReferenceFieldSource.hpp>
59 #include <com/sun/star/text/SizeType.hpp>
60 #include <com/sun/star/text/TextContentAnchorType.hpp>
61 #include <com/sun/star/text/WrapTextMode.hpp>
62 #include <com/sun/star/text/XDependentTextField.hpp>
63 #include <com/sun/star/text/XParagraphCursor.hpp>
64 #include <com/sun/star/text/XRedline.hpp>
65 #include <com/sun/star/text/XTextAppendAndConvert.hpp>
66 #include <com/sun/star/text/XTextCopy.hpp>
67 #include <com/sun/star/text/XTextField.hpp>
68 #include <com/sun/star/text/XTextFieldsSupplier.hpp>
69 #include <com/sun/star/style/DropCapFormat.hpp>
70 #include <com/sun/star/util/DateTime.hpp>
71 #include <com/sun/star/util/XNumberFormatsSupplier.hpp>
72 #include <com/sun/star/util/XNumberFormats.hpp>
73 #include <rtl/ustrbuf.hxx>
74 #include <rtl/string.h>
76 #include <tools/string.hxx>
77 #ifdef DEBUG_DOMAINMAPPER
78 #include <resourcemodel/QNameToString.hxx>
79 #include <resourcemodel/util.hxx>
80 #endif
81 #include <ooxml/OOXMLFastTokens.hxx>
83 #if DEBUG
84 #include <com/sun/star/lang/XServiceInfo.hpp>
85 #include <com/sun/star/style/TabStop.hpp>
86 #endif
88 #include <map>
90 using namespace ::com::sun::star;
91 using namespace ::rtl;
92 namespace writerfilter {
93 namespace dmapper{
94 /*-- 08.09.2006 09:39:50---------------------------------------------------
96 -----------------------------------------------------------------------*/
97 //defaultswitch { Upper FirstCap Lower }
98 //Numberingswitch { Arabic, ALPHABETIC, ...} see lcl_ParseNumberingType
99 enum FieldId
101 /* ADDRESSBLOCK \d \* MERGEFORMAT -> Addressblock completely unsupported*/
102 FIELD_ADDRESSBLOCK
103 /* ADVANCE \d downvalue \l leftvalue \r rightvalue \u upvalue \x xvalue \y yvalue -> unsupported*/
104 ,FIELD_ADVANCE
105 /* ASK bookmarkname "hint" \d defaultanswer \o \* MERGEFORMAT ->
106 the hint is not always quoted, inputfield with default answer, prompt before merge (\o)
108 ,FIELD_ASK
109 /* AUTONUM \* Numberingswitch ->
110 mapped to sequence field "AutoNr"
112 ,FIELD_AUTONUM
113 /* AUTONUMLGL \* Numberingswitch ->
114 mapped to sequence field "AutoNr"
116 ,FIELD_AUTONUMLGL
117 /* AUTONUMOUT \* Numberingswitch ->
118 mapped to sequence field "AutoNr"
120 ,FIELD_AUTONUMOUT
121 /* AUTHOR NewAuthor \* defaultswitch \* MERGEFORMAT ->
122 mapped to sequence field "AutoNr"
124 ,FIELD_AUTHOR
125 /* COMMENTS "comment" \* MERGEFORMAT ->
126 Docinfo-Comments
128 ,FIELD_COMMENTS
129 /* CREATEDATE \h \* MERGEFORMAT ->
130 docinfo-created-date
132 ,FIELD_CREATEDATE
133 /* DATE \@ "number format" \s \* MERGEFORMAT ->
134 ww8filterimprovement: multiple languages now supported
136 ,FIELD_DATE
137 /* DOCPROPERTY propertyname \* MERGEFORMAT ->
138 ww8filterimprovement: some fields imported as functionally equivalent fields if possible,
139 the others imported as UserField
141 ,FIELD_DOCPROPERTY
142 /* DOCVARIABLE Name \* MERGEFORMAT ->
143 ww8filterimprovement: now imported as user fields
145 ,FIELD_DOCVARIABLE
146 /* EDITTIME \# "displayformat" \* Numberingswitch \* MERGEFORMAT ->
147 DocInfo-Modified-Date
148 ww8filterimprovement: multiple languages now supported
150 ,FIELD_EDITTIME
151 /* FILLIN "text to fill in" \d defaultanswer \o \* MERGEFORMAT ->
152 Function-InputField
154 ,FIELD_FILLIN
155 /* FILENAME \p \* * MERGEFORMAT ->
156 file name (\p with path)
158 ,FIELD_FILENAME
159 /* FILESIZE \* NumberingType \* MERGEFORMAT ->
160 not imported in old ww8 filter, see lcl_ParseNumberingType
161 todo find alternative field
163 ,FIELD_FILESIZE
164 /* =formula \# "number format"
165 todo find alternative field
167 ,FIELD_FORMULA
168 /* GOTOBUTTON text \* MERGEFORMAT ->
169 not imported in old ww8 filter
170 todo find alternative field
172 ,FIELD_GOTOBUTTON
173 /* HYPERLINK "link" \* MERGEFORMAT ->
174 not imported in old ww8 filter
175 ww8filterimprovement: now imported as hyperlink
177 ,FIELD_HYPERLINK
178 /* IF condition "then text" "else text" ->
179 not imported in old ww8 filter
180 ww8filterimprovement: now imported
181 todo: condition, if text, else text still missing
183 ,FIELD_IF
184 /* INFO NameOfInfo \* MERGEFORMAT -> old
185 todo: filter imports wrong?
187 ,FIELD_INFO
188 /* INCLUDEPICTURE path \* MERGEFORMAT->
189 old filter imports an embedded picture
190 todo: not yet supported
192 ,FIELD_INCLUDEPICTURE
193 /* KEYWORDS keyword \* defaultswitch \* Numberingswitch \* MERGEFORMAT ->
194 DocInfo Keywords
196 ,FIELD_KEYWORDS
197 /* LASTSAVEDBY \* MERGEFORMAT ->
198 DocInfo-Modified-Author
200 ,FIELD_LASTSAVEDBY
201 /* MACROBUTTON MacroName quick help text ->
202 Macro field
204 ,FIELD_MACROBUTTON
205 /* MERGEFIELD ColumName \b prefix \f suffix \* MERGEFORMAT ->
206 ww8filterimprovement: column-only API now upporterd
208 ,FIELD_MERGEFIELD
209 /* MERGEREC \* MERGEFORMAT ->
210 RecordNumber field, maybe without db name
211 todo: currently unchecked
213 ,FIELD_MERGEREC
214 /* MERGESEQ \* MERGEFORMAT ->
215 not imported in old ww8 filter
216 ww8filterimprovement: now imported
217 todo: currently unchecked
219 ,FIELD_MERGESEQ
220 /* NEXT text ->
221 Next record
222 todo: currently unchecked
224 ,FIELD_NEXT
225 /* NEXTIF condition
226 todo: condition not imported
228 ,FIELD_NEXTIF
229 /* PAGE \* Numberingswitch \* MERGEFORMAT ->
230 see lcl_ParseNumberingType
232 ,FIELD_PAGE
233 /* REF targetbkm \f \* MERGEFORMAT ->
234 imports a ShowVariable (bookmarkname)?
235 \h hyerlink to paragraph
236 \p relative to para above/below
237 \f refenence number
238 \d separator number separator
239 \n paragraph number
240 \r paragraph number in relative context
241 \t suppres non delimiters
242 \w paragraph number in full context
243 \* Upper/Lower...
245 ,FIELD_REF //
246 /* REVNUM \* Numberingswitch \* MERGEFORMAT ->
247 DocInfo-revision number
249 ,FIELD_REVNUM
250 /* SAVEDATE \@ "NumberFormat"\* MERGEFORMAT ->
251 DocInfo-modified-date
253 ,FIELD_SAVEDATE
254 /* SECTION \* NumberFormat \* MERGEFORMAT ->
255 not imported in old ww8 filter see lcl_ParseNumberingType
256 todo: find alternative
258 ,FIELD_SECTION
259 /* SECTIONPAGES \* NumberFormat \* MERGEFORMAT ->
260 not imported in old ww8 filter see lcl_ParseNumberingType
261 todo: find alternative
263 ,FIELD_SECTIONPAGES
264 /* SEQ sequencename \h \c \n \r \s \* MERGEFORMAT ->
265 number range name:sequencename value:sequencename+1
266 todo: only partially implemented, switches unsupported
268 ,FIELD_SEQ
269 /* SET bookmarkname newtext \* MERGEFORMAT ->
270 SetVariable bookmarkname = newtext
271 todo: not implemented yet
273 ,FIELD_SET
274 /* SKIPIF condition \* MERGEFORMAT ->
276 todo: not implemented yet
278 ,FIELD_SKIPIF
279 /* STYLEREF stylename \* MERGEFORMAT ->
280 not imported in old ww8 filter
281 todo: add an equivalent field type
283 ,FIELD_STYLEREF
284 /* SUBJECT subject \* Defaultswitch \* MERGEFORMAT ->
285 DocInfo - subject
287 ,FIELD_SUBJECT
288 /* SYMBOL symbolnumber \* MERGEFORMAT ->
289 inserts a special char (symbolnumber)
290 todo: find alternative
292 ,FIELD_SYMBOL
293 /* TEMPLATE \* Defaultswitch \* MERGEFORMAT
294 TemplateName field
296 ,FIELD_TEMPLATE
297 /* TIME \@ "number format" \* MERGEFORMAT
298 ww8filterimprovement: multiple languages now supported
300 ,FIELD_TIME
301 /* TITLE \* Defaultswitch \* MERGEFORMAT ->
302 DocInfo-title
304 ,FIELD_TITLE
305 /* USERINITIALS newinitials \* MERGEFORMAT ->
306 ExtendedUser field (SHORTCUT)
308 ,FIELD_USERINITIALS
309 /* USERADDRESS \* MERGEFORMAT ->
310 not imported in old ww8 filter
311 todo: find alternative
313 ,FIELD_USERADDRESS
314 /* USERNAME newusername \* MERGEFORMAT ->
315 not imported in old ww8 filter
316 todo: import as extended user field(s)
318 ,FIELD_USERNAME
320 TOC options:
321 \a Builds a table of figures but does not include the captions's label and number
322 \b Uses a bookmark to specify area of document from which to build table of contents
323 \c Builds a table of figures of the given label
324 \d Defines the separator between sequence and page numbers
325 \f Builds a table of contents using TC entries instead of outline levels
326 \h Hyperlinks the entries and page numbers within the table of contents
327 \l Defines the TC entries field level used to build a table of contents
328 \n Builds a table of contents or a range of entries, sucah as “1-9”, in a table of contents without page numbers
329 \o Builds a table of contents by using outline levels instead of TC entries
330 \p Defines the separator between the table entry and its page number
331 \s Builds a table of contents by using a sequence type
332 \t Builds a table of contents by using style names other than the standard outline styles
333 \u Builds a table of contents by using the applied paragraph outline level
334 \w Preserve tab characters within table entries
335 \x Preserve newline characters within table entries
336 \z Hides page numbers within the table of contens when shown in Web Layout View
338 ,FIELD_TOC
340 TOC entry: “text”
341 \f TC entry in doc with multiple tables
342 \l Outline Level
343 \n Suppress page numbers
344 example: TOC "EntryText \f \l 2 \n
346 ,FIELD_TC
347 /* document statistic - number of characters
349 ,FIELD_NUMCHARS
350 /* document statistic - number of words
352 ,FIELD_NUMWORDS
353 /* document statistic - number of pages
355 ,FIELD_NUMPAGES
357 struct FieldConversion
359 ::rtl::OUString sWordCommand;
360 const sal_Char* cFieldServiceName;
361 const sal_Char* cFieldMasterServiceName;
362 FieldId eFieldId;
365 typedef ::std::map< ::rtl::OUString, FieldConversion>
366 FieldConversionMap_t;
368 /*-- 18.07.2006 08:56:55---------------------------------------------------
370 -----------------------------------------------------------------------*/
371 sal_Int32 FIB::GetData( Id nName )
373 if( nName >= NS_rtf::LN_WIDENT && nName <= NS_rtf::LN_LCBSTTBFUSSR)
374 return aFIBData[nName - NS_rtf::LN_WIDENT];
375 OSL_ENSURE( false, "invalid index in FIB");
376 return -1;
378 /*-- 18.07.2006 08:56:55---------------------------------------------------
380 -----------------------------------------------------------------------*/
381 void FIB::SetData( Id nName, sal_Int32 nValue )
383 OSL_ENSURE( nName >= NS_rtf::LN_WIDENT && nName <= NS_rtf::LN_LCBSTTBFUSSR, "invalid index in FIB");
384 if( nName >= NS_rtf::LN_WIDENT && nName <= NS_rtf::LN_LCBSTTBFUSSR)
385 aFIBData[nName - NS_rtf::LN_WIDENT] = nValue;
387 /*-- 01.09.2006 10:22:03---------------------------------------------------
389 -----------------------------------------------------------------------*/
390 DomainMapper_Impl::DomainMapper_Impl(
391 DomainMapper& rDMapper,
392 uno::Reference < uno::XComponentContext > xContext,
393 uno::Reference< lang::XComponent > xModel,
394 SourceDocumentType eDocumentType) :
395 m_eDocumentType( eDocumentType ),
396 m_rDMapper( rDMapper ),
397 m_xTextDocument( xModel, uno::UNO_QUERY ),
398 m_xTextFactory( xModel, uno::UNO_QUERY ),
399 m_xComponentContext( xContext ),
400 m_bFieldMode( false ),
401 m_bSetUserFieldContent( false ),
402 m_bIsFirstSection( true ),
403 m_bIsColumnBreakDeferred( false ),
404 m_bIsPageBreakDeferred( false ),
405 m_bIsInShape( false ),
406 m_bShapeContextAdded( false ),
407 m_pLastSectionContext( ),
408 m_nCurrentTabStopIndex( 0 ),
409 m_sCurrentParaStyleId(),
410 m_bInStyleSheetImport( false ),
411 m_bInAnyTableImport( false ),
412 m_bLineNumberingSet( false ),
413 m_bIsInFootnoteProperties( true ),
414 m_bIsCustomFtnMark( false ),
415 m_bIsParaChange( false ),
416 m_bParaChanged( false ),
417 m_bIsLastParaInSection( false )
419 appendTableManager( );
420 GetBodyText();
421 uno::Reference< text::XTextAppend > xBodyTextAppend = uno::Reference< text::XTextAppend >( m_xBodyText, uno::UNO_QUERY );
422 m_aTextAppendStack.push(xBodyTextAppend);
424 //todo: does it make sense to set the body text as static text interface?
425 uno::Reference< text::XTextAppendAndConvert > xBodyTextAppendAndConvert( m_xBodyText, uno::UNO_QUERY );
426 TableDataHandler_t::Pointer_t pTableHandler
427 (new DomainMapperTableHandler(xBodyTextAppendAndConvert, *this));
428 getTableManager( ).setHandler(pTableHandler);
430 getTableManager( ).startLevel();
432 /*-- 01.09.2006 10:22:28---------------------------------------------------
434 -----------------------------------------------------------------------*/
435 DomainMapper_Impl::~DomainMapper_Impl()
437 RemoveLastParagraph( );
438 getTableManager( ).endLevel();
439 popTableManager( );
441 /*-------------------------------------------------------------------------
443 -----------------------------------------------------------------------*/
444 uno::Reference< container::XNameContainer > DomainMapper_Impl::GetPageStyles()
446 if(!m_xPageStyles.is())
448 uno::Reference< style::XStyleFamiliesSupplier > xSupplier( m_xTextDocument, uno::UNO_QUERY );
449 xSupplier->getStyleFamilies()->getByName(::rtl::OUString::createFromAscii("PageStyles")) >>= m_xPageStyles;
451 return m_xPageStyles;
453 /*-------------------------------------------------------------------------
455 -----------------------------------------------------------------------*/
456 uno::Reference< text::XText > DomainMapper_Impl::GetBodyText()
458 if(!m_xBodyText.is() && m_xTextDocument.is())
460 m_xBodyText = m_xTextDocument->getText();
462 return m_xBodyText;
464 /*-- 21.12.2006 12:09:30---------------------------------------------------
466 -----------------------------------------------------------------------*/
467 uno::Reference< beans::XPropertySet > DomainMapper_Impl::GetDocumentSettings()
469 if( !m_xDocumentSettings.is() )
471 m_xDocumentSettings = uno::Reference< beans::XPropertySet >(
472 m_xTextFactory->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.Settings"))), uno::UNO_QUERY );
474 return m_xDocumentSettings;
476 /*-- 21.12.2006 12:16:23---------------------------------------------------
478 -----------------------------------------------------------------------*/
479 void DomainMapper_Impl::SetDocumentSettingsProperty( const ::rtl::OUString& rPropName, const uno::Any& rValue )
481 uno::Reference< beans::XPropertySet > xSettings = GetDocumentSettings();
482 if( xSettings.is() )
486 xSettings->setPropertyValue( rPropName, rValue );
488 catch( const uno::Exception& )
494 void DomainMapper_Impl::RemoveLastParagraph( )
496 uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend;
499 uno::Reference< text::XTextCursor > xCursor = xTextAppend->createTextCursor();
500 xCursor->gotoEnd(false);
501 xCursor->goLeft( 1, true );
502 xCursor->setString(::rtl::OUString());
504 catch( const uno::Exception& rEx)
506 (void)rEx;
510 void DomainMapper_Impl::SetIsLastParagraphInSection( bool bIsLast )
512 m_bIsLastParaInSection = bIsLast;
515 /*-------------------------------------------------------------------------
517 -----------------------------------------------------------------------*/
518 void DomainMapper_Impl::PushProperties(ContextType eId)
520 SectionPropertyMap* pSectionContext = 0;
521 PropertyMapPtr pInsert(eId == CONTEXT_SECTION ?
522 (pSectionContext = new SectionPropertyMap( m_bIsFirstSection )) :
523 eId == CONTEXT_PARAGRAPH ? new ParagraphPropertyMap : new PropertyMap);
524 if(eId == CONTEXT_SECTION)
526 if( m_bIsFirstSection )
527 m_bIsFirstSection = false;
528 // beginning with the second section group a section has to be inserted
529 // into the document
530 SectionPropertyMap* pSectionContext_ = dynamic_cast< SectionPropertyMap* >( pInsert.get() );
531 uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend;
532 if(xTextAppend.is())
533 pSectionContext_->SetStart( xTextAppend->getEnd() );
535 m_aPropertyStacks[eId].push( pInsert );
536 m_aContextStack.push(eId);
538 m_pTopContext = m_aPropertyStacks[eId].top();
540 /*-- 13.06.2007 16:18:18---------------------------------------------------
542 -----------------------------------------------------------------------*/
543 void DomainMapper_Impl::PushStyleProperties( PropertyMapPtr pStyleProperties )
545 m_aPropertyStacks[CONTEXT_STYLESHEET].push( pStyleProperties );
546 m_aContextStack.push(CONTEXT_STYLESHEET);
548 m_pTopContext = m_aPropertyStacks[CONTEXT_STYLESHEET].top();
550 /*-- 28.01.2008 14:47:46---------------------------------------------------
552 -----------------------------------------------------------------------*/
553 void DomainMapper_Impl::PushListProperties(PropertyMapPtr pListProperties)
555 m_aPropertyStacks[CONTEXT_LIST].push( pListProperties );
556 m_aContextStack.push(CONTEXT_LIST);
557 m_pTopContext = m_aPropertyStacks[CONTEXT_LIST].top();
559 /*-------------------------------------------------------------------------
561 -----------------------------------------------------------------------*/
562 void DomainMapper_Impl::PopProperties(ContextType eId)
564 OSL_ENSURE(!m_aPropertyStacks[eId].empty(), "section stack already empty");
566 if ( eId == CONTEXT_SECTION )
568 #if DEBUG
569 clog << "Saving the last section context" << endl;
570 #endif
571 m_pLastSectionContext = m_aPropertyStacks[eId].top( );
574 m_aPropertyStacks[eId].pop();
575 m_aContextStack.pop();
576 if(!m_aContextStack.empty() && !m_aPropertyStacks[m_aContextStack.top()].empty())
578 m_pTopContext = m_aPropertyStacks[m_aContextStack.top()].top();
579 else
581 // OSL_ENSURE(eId == CONTEXT_SECTION, "this should happen at a section context end");
582 m_pTopContext.reset();
585 /*-------------------------------------------------------------------------
587 -----------------------------------------------------------------------*/
588 PropertyMapPtr DomainMapper_Impl::GetTopContextOfType(ContextType eId)
590 PropertyMapPtr pRet;
591 OSL_ENSURE( !m_aPropertyStacks[eId].empty(),
592 "no context of this type available");
593 if(!m_aPropertyStacks[eId].empty())
594 pRet = m_aPropertyStacks[eId].top();
595 return pRet;
598 /*-- 24.05.2007 15:54:51---------------------------------------------------
600 -----------------------------------------------------------------------*/
601 uno::Reference< text::XTextAppend > DomainMapper_Impl::GetTopTextAppend()
603 OSL_ENSURE(!m_aTextAppendStack.empty(), "text append stack is empty" );
604 return m_aTextAppendStack.top().xTextAppend;
607 /*-- 17.07.2006 08:47:04---------------------------------------------------
609 -----------------------------------------------------------------------*/
610 void DomainMapper_Impl::InitTabStopFromStyle( const uno::Sequence< style::TabStop >& rInitTabStops )
612 OSL_ENSURE(!m_aCurrentTabStops.size(), "tab stops already initialized");
613 for( sal_Int32 nTab = 0; nTab < rInitTabStops.getLength(); ++nTab)
615 m_aCurrentTabStops.push_back( DeletableTabStop(rInitTabStops[nTab]) );
619 /*-- 29.06.2006 13:35:33---------------------------------------------------
621 -----------------------------------------------------------------------*/
622 void DomainMapper_Impl::ModifyCurrentTabStop( Id nId, sal_Int32 nValue)
624 OSL_ENSURE(nId == NS_rtf::LN_dxaAdd || m_nCurrentTabStopIndex < m_aCurrentTabStops.size(),
625 "tab stop creation error");
627 if( nId != NS_rtf::LN_dxaAdd && m_nCurrentTabStopIndex >= m_aCurrentTabStops.size())
628 return;
629 static const style::TabAlign aTabAlignFromWord[] =
631 style::TabAlign_LEFT,
632 style::TabAlign_CENTER,
633 style::TabAlign_RIGHT,
634 style::TabAlign_DECIMAL,
635 style::TabAlign_LEFT
637 static const sal_Unicode aTabFillCharWord[] =
639 ' ',
640 '.',
641 '-',
642 '_',
643 '_',
644 0xb7
647 switch(nId)
649 case NS_rtf::LN_dxaAdd: //set tab
650 m_aCurrentTabStops.push_back(
651 DeletableTabStop(style::TabStop(ConversionHelper::convertTwipToMM100(nValue), style::TabAlign_LEFT, ' ', ' ')));
652 break;
653 case NS_rtf::LN_dxaDel: //deleted tab
655 //mark the tab stop at the given position as deleted
656 ::std::vector<DeletableTabStop>::iterator aIt = m_aCurrentTabStops.begin();
657 ::std::vector<DeletableTabStop>::iterator aEndIt = m_aCurrentTabStops.end();
658 sal_Int32 nConverted = ConversionHelper::convertTwipToMM100(nValue);
659 for( ; aIt != aEndIt; ++aIt)
661 if( aIt->Position == nConverted )
663 aIt->bDeleted = true;
664 break;
668 break;
669 case NS_rtf::LN_TLC: //tab leading characters - for decimal tabs
670 // 0 - no leader, 1- dotted, 2 - hyphenated, 3 - single line, 4 - heavy line, 5 - middle dot
671 if( nValue >= 0 && nValue < sal::static_int_cast<sal_Int32>(sizeof(aTabFillCharWord) / sizeof (sal_Unicode)))
672 m_aCurrentTabStops[m_nCurrentTabStopIndex].FillChar = aTabFillCharWord[nValue];
673 break;
674 case NS_rtf::LN_JC: //tab justification
675 //0 - left, 1 - centered, 2 - right, 3 - decimal 4 - bar
676 if( nValue >= 0 && nValue < sal::static_int_cast<sal_Int32>(sizeof(aTabAlignFromWord) / sizeof (style::TabAlign)))
677 m_aCurrentTabStops[m_nCurrentTabStopIndex].Alignment = aTabAlignFromWord[nValue];
678 break;
682 void DomainMapper_Impl::IncorporateTabStop( const DeletableTabStop & rTabStop )
684 ::std::vector<DeletableTabStop>::iterator aIt = m_aCurrentTabStops.begin();
685 ::std::vector<DeletableTabStop>::iterator aEndIt = m_aCurrentTabStops.end();
686 sal_Int32 nConverted = rTabStop.Position;
687 bool bFound = false;
688 for( ; aIt != aEndIt; ++aIt)
690 if( aIt->Position == nConverted )
692 bFound = true;
693 if( rTabStop.bDeleted )
694 m_aCurrentTabStops.erase( aIt );
695 else
696 *aIt = rTabStop;
697 break;
700 if( !bFound )
701 m_aCurrentTabStops.push_back( rTabStop );
703 /*-- 29.06.2006 13:35:33---------------------------------------------------
705 -----------------------------------------------------------------------*/
706 uno::Sequence< style::TabStop > DomainMapper_Impl::GetCurrentTabStopAndClear()
708 uno::Sequence< style::TabStop > aRet( sal_Int32( m_aCurrentTabStops.size() ) );
709 style::TabStop* pArray = aRet.getArray();
710 ::std::vector<DeletableTabStop>::const_iterator aIt = m_aCurrentTabStops.begin();
711 ::std::vector<DeletableTabStop>::const_iterator aEndIt = m_aCurrentTabStops.end();
712 sal_Int32 nDeleted = 0;
713 for(sal_Int32 nIndex = 0; aIt != aEndIt; ++aIt)
715 if(!aIt->bDeleted)
716 pArray[nIndex++] = *aIt;
717 else
718 ++nDeleted;
720 m_aCurrentTabStops.clear();
721 m_nCurrentTabStopIndex = 0;
722 if(nDeleted)
724 aRet.realloc( aRet.getLength() - nDeleted);
726 return aRet;
729 /*-- 17.07.2006 09:08:26---------------------------------------------------
730 returns a the value from the current paragraph style - if available
731 TODO: What about parent styles?
732 -----------------------------------------------------------------------*/
733 uno::Any DomainMapper_Impl::GetPropertyFromStyleSheet(PropertyIds eId)
735 StyleSheetEntryPtr pEntry;
736 if( m_bInStyleSheetImport )
737 pEntry = GetStyleSheetTable()->FindParentStyleSheet(::rtl::OUString());
738 else
739 pEntry =
740 GetStyleSheetTable()->FindStyleSheetByISTD(GetCurrentParaStyleId());
741 while(pEntry.get( ) )
743 //is there a tab stop set?
744 if(pEntry->pProperties)
746 PropertyMap::const_iterator aPropertyIter =
747 pEntry->pProperties->find(PropertyDefinition(eId, false ));
748 if( aPropertyIter != pEntry->pProperties->end())
750 return aPropertyIter->second;
753 //search until the property is set or no parent is available
754 pEntry = GetStyleSheetTable()->FindParentStyleSheet(pEntry->sBaseStyleIdentifier);
756 return uno::Any();
758 /*-------------------------------------------------------------------------
760 -----------------------------------------------------------------------*/
761 ListsManager::Pointer DomainMapper_Impl::GetListTable()
763 if(!m_pListTable)
764 m_pListTable.reset(
765 new ListsManager( m_rDMapper, m_xTextFactory ));
766 return m_pListTable;
770 void DomainMapper_Impl::deferBreak( BreakType deferredBreakType)
772 switch (deferredBreakType)
774 case COLUMN_BREAK:
775 m_bIsColumnBreakDeferred = true;
776 break;
777 case PAGE_BREAK:
778 m_bIsPageBreakDeferred = true;
779 break;
780 default:
781 return;
785 bool DomainMapper_Impl::isBreakDeferred( BreakType deferredBreakType )
787 switch (deferredBreakType)
789 case COLUMN_BREAK:
790 return m_bIsColumnBreakDeferred;
791 case PAGE_BREAK:
792 return m_bIsPageBreakDeferred;
793 default:
794 return false;
798 void DomainMapper_Impl::clearDeferredBreaks()
800 m_bIsColumnBreakDeferred = false;
801 m_bIsPageBreakDeferred = false;
803 /*-------------------------------------------------------------------------
805 -----------------------------------------------------------------------*/
806 void lcl_MoveBorderPropertiesToFrame(uno::Sequence<beans::PropertyValue>& rFrameProperties,
807 uno::Reference<text::XTextRange> xStartTextRange,
808 uno::Reference<text::XTextRange> xEndTextRange )
812 uno::Reference<text::XTextCursor> xRangeCursor = xStartTextRange->getText()->createTextCursorByRange( xStartTextRange );
813 xRangeCursor->gotoRange( xEndTextRange, true );
815 uno::Reference<beans::XPropertySet> xTextRangeProperties(xRangeCursor, uno::UNO_QUERY);
816 if(!xTextRangeProperties.is())
817 return ;
819 PropertyIds aBorderProperties[] =
821 PROP_LEFT_BORDER,
822 PROP_RIGHT_BORDER,
823 PROP_TOP_BORDER,
824 PROP_BOTTOM_BORDER,
825 PROP_LEFT_BORDER_DISTANCE,
826 PROP_RIGHT_BORDER_DISTANCE,
827 PROP_TOP_BORDER_DISTANCE,
828 PROP_BOTTOM_BORDER_DISTANCE
831 sal_uInt32 nStart = rFrameProperties.getLength();
832 sal_uInt32 nBorderPropertyCount = sizeof( aBorderProperties ) / sizeof(PropertyIds);
833 rFrameProperties.realloc(nStart + nBorderPropertyCount);
835 beans::PropertyValue* pFrameProperties = rFrameProperties.getArray();
836 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
837 for( sal_uInt32 nProperty = 0; nProperty < nBorderPropertyCount; ++nProperty)
839 ::rtl::OUString sPropertyName = rPropNameSupplier.GetName(aBorderProperties[nProperty]);
840 pFrameProperties[nStart].Name = sPropertyName;
841 pFrameProperties[nStart].Value = xTextRangeProperties->getPropertyValue(sPropertyName);
842 if( nProperty < 4 )
843 xTextRangeProperties->setPropertyValue( sPropertyName, uno::makeAny(table::BorderLine()));
844 ++nStart;
846 rFrameProperties.realloc(nStart);
848 catch( const uno::Exception& rEx )
850 (void)rEx;
853 /*-- 04.01.2008 10:59:19---------------------------------------------------
855 -----------------------------------------------------------------------*/
856 void lcl_AddRangeAndStyle(
857 ParagraphPropertiesPtr& pToBeSavedProperties,
858 uno::Reference< text::XTextAppend > xTextAppend,
859 PropertyMapPtr pPropertyMap)
861 uno::Reference<text::XParagraphCursor> xParaCursor(
862 xTextAppend->createTextCursorByRange( xTextAppend->getEnd()), uno::UNO_QUERY_THROW );
863 pToBeSavedProperties->SetEndingRange(xParaCursor->getStart());
864 xParaCursor->gotoStartOfParagraph( false );
866 pToBeSavedProperties->SetStartingRange(xParaCursor->getStart());
867 if(pPropertyMap)
869 PropertyMap::iterator aParaStyleIter = pPropertyMap->find(PropertyDefinition( PROP_PARA_STYLE_NAME, false ) );
870 if( aParaStyleIter != pPropertyMap->end())
872 ::rtl::OUString sName;
873 aParaStyleIter->second >>= sName;
874 pToBeSavedProperties->SetParaStyleName(sName);
878 /*-------------------------------------------------------------------------
880 -----------------------------------------------------------------------*/
881 //define some default frame width - 0cm ATM: this allow the frame to be wrapped around the text
882 #define DEFAULT_FRAME_MIN_WIDTH 0
884 void DomainMapper_Impl::finishParagraph( PropertyMapPtr pPropertyMap )
886 #if DEBUG
887 clog << "finishParagraph" << endl;
888 #endif
890 ParagraphPropertyMap* pParaContext = dynamic_cast< ParagraphPropertyMap* >( pPropertyMap.get() );
891 TextAppendContext& rAppendContext = m_aTextAppendStack.top();
892 uno::Reference< text::XTextAppend > xTextAppend = rAppendContext.xTextAppend;
893 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
894 if(xTextAppend.is() && ! getTableManager( ).isIgnore())
898 /*the following combinations of previous and current frame settings can occur:
899 (1) - no old frame and no current frame -> no special action
900 (2) - no old frame and current DropCap -> save DropCap for later use, don't call finishParagraph
901 remove character properties of the DropCap?
902 (3) - no old frame and current Frame -> save Frame for later use
903 (4) - old DropCap and no current frame -> add DropCap to the properties of the finished paragraph, delete previous setting
904 (5) - old DropCap and current frame -> add DropCap to the properties of the finished paragraph, save current frame settings
905 (6) - old Frame and new DropCap -> add old Frame, save DropCap for later use
906 (7) - old Frame and new same Frame -> continue
907 (8) - old Frame and new different Frame -> add old Frame, save new Frame for later use
908 (9) - old Frame and no current frame -> add old Frame, delete previous settings
910 old _and_ new DropCap must not occur
913 bool bIsDropCap = pParaContext->IsFrameMode() && sal::static_int_cast<Id>(pParaContext->GetDropCap()) != NS_ooxml::LN_Value_wordprocessingml_ST_DropCap_none;
914 style::DropCapFormat aDrop;
915 ParagraphPropertiesPtr pToBeSavedProperties;
916 bool bKeepLastParagraphProperties = false;
917 if( bIsDropCap )
919 uno::Reference<text::XParagraphCursor> xParaCursor(
920 xTextAppend->createTextCursorByRange(xTextAppend->getEnd()), uno::UNO_QUERY_THROW);
921 //select paragraph
922 xParaCursor->gotoStartOfParagraph( true );
923 uno::Reference< beans::XPropertyState > xParaProperties( xParaCursor, uno::UNO_QUERY_THROW );
924 xParaProperties->setPropertyToDefault(rPropNameSupplier.GetName(PROP_CHAR_ESCAPEMENT));
925 xParaProperties->setPropertyToDefault(rPropNameSupplier.GetName(PROP_CHAR_HEIGHT));
926 //handles (2) and part of (6)
927 pToBeSavedProperties.reset( new ParagraphProperties(*pParaContext) );
928 sal_Int32 nCount = xParaCursor->getString().getLength();
929 pToBeSavedProperties->SetDropCapLength(nCount > 0 && nCount < 255 ? (sal_Int8)nCount : 1);
931 if( rAppendContext.pLastParagraphProperties.get() )
933 if( sal::static_int_cast<Id>(rAppendContext.pLastParagraphProperties->GetDropCap()) != NS_ooxml::LN_Value_wordprocessingml_ST_DropCap_none)
935 //handles (4) and part of (5)
936 //create a DropCap property, add it to the property sequence of finishParagraph
937 sal_Int32 nLines = rAppendContext.pLastParagraphProperties->GetLines();
938 aDrop.Lines = nLines > 0 && nLines < 254 ? (sal_Int8)++nLines : 2;
939 aDrop.Count = rAppendContext.pLastParagraphProperties->GetDropCapLength();
940 aDrop.Distance = 0; //TODO: find distance value
941 //completes (5)
942 if( pParaContext->IsFrameMode() )
943 pToBeSavedProperties.reset( new ParagraphProperties(*pParaContext) );
945 else if(*rAppendContext.pLastParagraphProperties == *pParaContext )
947 //handles (7)
948 rAppendContext.pLastParagraphProperties->SetEndingRange(xTextAppend->getEnd());
949 bKeepLastParagraphProperties = true;
951 else
953 //handles (8)(9) and completes (6)
957 StyleSheetEntryPtr pParaStyle =
958 m_pStyleSheetTable->FindStyleSheetByConvertedStyleName(rAppendContext.pLastParagraphProperties->GetParaStyleName());
960 uno::Sequence< beans::PropertyValue > aFrameProperties(pParaStyle ? 15: 0);
961 if ( pParaStyle.get( ) )
963 const ParagraphProperties* pStyleProperties = dynamic_cast<const ParagraphProperties*>( pParaStyle->pProperties.get() );
964 beans::PropertyValue* pFrameProperties = aFrameProperties.getArray();
965 pFrameProperties[0].Name = rPropNameSupplier.GetName(PROP_WIDTH);
966 pFrameProperties[1].Name = rPropNameSupplier.GetName(PROP_HEIGHT);
967 pFrameProperties[2].Name = rPropNameSupplier.GetName(PROP_SIZE_TYPE);
968 pFrameProperties[3].Name = rPropNameSupplier.GetName(PROP_WIDTH_TYPE);
969 pFrameProperties[4].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT);
970 pFrameProperties[5].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT_POSITION);
971 pFrameProperties[6].Name = rPropNameSupplier.GetName(PROP_HORI_ORIENT_RELATION);
972 pFrameProperties[7].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT);
973 pFrameProperties[8].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT_POSITION);
974 pFrameProperties[9].Name = rPropNameSupplier.GetName(PROP_VERT_ORIENT_RELATION);
975 pFrameProperties[10].Name = rPropNameSupplier.GetName(PROP_SURROUND);
976 pFrameProperties[11].Name = rPropNameSupplier.GetName(PROP_LEFT_MARGIN);
977 pFrameProperties[12].Name = rPropNameSupplier.GetName(PROP_RIGHT_MARGIN);
978 pFrameProperties[13].Name = rPropNameSupplier.GetName(PROP_TOP_MARGIN);
979 pFrameProperties[14].Name = rPropNameSupplier.GetName(PROP_BOTTOM_MARGIN);
980 sal_Int32 nWidth =
981 rAppendContext.pLastParagraphProperties->Getw() > 0 ?
982 rAppendContext.pLastParagraphProperties->Getw() :
983 pStyleProperties->Getw();
984 bool bAutoWidth = nWidth < 1;
985 if( bAutoWidth )
986 nWidth = DEFAULT_FRAME_MIN_WIDTH;
987 pFrameProperties[0].Value <<= nWidth;
988 pFrameProperties[1].Value <<=
989 rAppendContext.pLastParagraphProperties->Geth() > 0 ?
990 rAppendContext.pLastParagraphProperties->Geth() :
991 pStyleProperties->Geth();
992 pFrameProperties[2].Value <<= sal_Int16(
993 rAppendContext.pLastParagraphProperties->GethRule() >= 0 ?
994 rAppendContext.pLastParagraphProperties->GethRule() :
995 pStyleProperties->GethRule() >=0 ? pStyleProperties->GethRule() : text::SizeType::VARIABLE);
997 pFrameProperties[3].Value <<= bAutoWidth ? text::SizeType::MIN : text::SizeType::FIX;
999 sal_Int16 nHoriOrient = sal_Int16(
1000 rAppendContext.pLastParagraphProperties->GetxAlign() >= 0 ?
1001 rAppendContext.pLastParagraphProperties->GetxAlign() :
1002 pStyleProperties->GetxAlign() >= 0 ? pStyleProperties->GetxAlign() : text::HoriOrientation::NONE );
1003 pFrameProperties[4].Value <<= nHoriOrient;
1005 pFrameProperties[5].Value <<=
1006 rAppendContext.pLastParagraphProperties->IsxValid() ?
1007 rAppendContext.pLastParagraphProperties->Getx() : pStyleProperties->Getx();
1008 pFrameProperties[6].Value <<= sal_Int16(
1009 rAppendContext.pLastParagraphProperties->GethAnchor() >= 0 ?
1010 rAppendContext.pLastParagraphProperties->GethAnchor() :
1011 pStyleProperties->GethAnchor() );
1013 sal_Int16 nVertOrient = sal_Int16(
1014 rAppendContext.pLastParagraphProperties->GetyAlign() >= 0 ?
1015 rAppendContext.pLastParagraphProperties->GetyAlign() :
1016 pStyleProperties->GetyAlign() >= 0 ? pStyleProperties->GetyAlign() : text::VertOrientation::NONE );
1017 pFrameProperties[7].Value <<= nVertOrient;
1019 pFrameProperties[8].Value <<=
1020 rAppendContext.pLastParagraphProperties->IsyValid() ?
1021 rAppendContext.pLastParagraphProperties->Gety() : pStyleProperties->Gety();
1022 pFrameProperties[9].Value <<= sal_Int16(
1023 rAppendContext.pLastParagraphProperties->GetvAnchor() >= 0 ?
1024 rAppendContext.pLastParagraphProperties->GetvAnchor() :
1025 pStyleProperties->GetvAnchor() );
1027 pFrameProperties[10].Value <<= text::WrapTextMode(
1028 rAppendContext.pLastParagraphProperties->GetWrap() >= 0 ?
1029 rAppendContext.pLastParagraphProperties->GetWrap() :
1030 pStyleProperties->GetWrap());
1032 sal_Int32 nBottomDist;
1033 sal_Int32 nTopDist = nBottomDist =
1034 rAppendContext.pLastParagraphProperties->GethSpace() >= 0 ?
1035 rAppendContext.pLastParagraphProperties->GethSpace() :
1036 pStyleProperties->GethSpace();
1038 pFrameProperties[11].Value <<= nVertOrient == text::VertOrientation::TOP ? 0 : nTopDist;
1039 pFrameProperties[12].Value <<= nVertOrient == text::VertOrientation::BOTTOM ? 0 : nBottomDist;
1041 sal_Int32 nRightDist;
1042 sal_Int32 nLeftDist = nRightDist =
1043 rAppendContext.pLastParagraphProperties->GetvSpace() >= 0 ?
1044 rAppendContext.pLastParagraphProperties->GetvSpace() :
1045 pStyleProperties->GetvSpace() >= 0 ? pStyleProperties->GetvSpace() : 0;
1046 pFrameProperties[13].Value <<= nHoriOrient == text::HoriOrientation::LEFT ? 0 : nLeftDist;
1047 pFrameProperties[14].Value <<= nHoriOrient == text::HoriOrientation::RIGHT ? 0 : nRightDist;
1049 lcl_MoveBorderPropertiesToFrame(aFrameProperties,
1050 rAppendContext.pLastParagraphProperties->GetStartingRange(),
1051 rAppendContext.pLastParagraphProperties->GetEndingRange());
1053 //frame conversion has to be executed after table conversion
1054 RegisterFrameConversion(
1055 rAppendContext.pLastParagraphProperties->GetStartingRange(),
1056 rAppendContext.pLastParagraphProperties->GetEndingRange(),
1057 aFrameProperties );
1058 // next frame follows directly
1059 if( pParaContext->IsFrameMode() )
1061 pToBeSavedProperties.reset( new ParagraphProperties(*pParaContext) );
1062 lcl_AddRangeAndStyle(pToBeSavedProperties, xTextAppend, pPropertyMap);
1065 catch( const uno::Exception& rEx )
1067 (void)rEx;
1072 else //
1074 // (1) doesn't need handling
1076 if( !bIsDropCap && pParaContext->IsFrameMode() )
1078 pToBeSavedProperties.reset( new ParagraphProperties(*pParaContext) );
1079 lcl_AddRangeAndStyle(pToBeSavedProperties, xTextAppend, pPropertyMap);
1082 uno::Sequence< beans::PropertyValue > aProperties;
1083 if( pPropertyMap.get() )
1085 aProperties = pPropertyMap->GetPropertyValues();
1087 if( !bIsDropCap )
1089 if( aDrop.Lines > 1 )
1091 sal_uInt32 nLength = aProperties.getLength();
1092 aProperties.realloc( nLength + 1 );
1093 aProperties[nLength].Value <<= aDrop;
1094 aProperties[nLength].Name = rPropNameSupplier.GetName(PROP_DROP_CAP_FORMAT);
1096 #if DEBUG
1097 sal_Int32 nLen = aProperties.getLength();
1098 for ( sal_Int32 i = 0; i < nLen; i++ )
1100 uno::Any aValue = aProperties[i].Value;
1101 uno::Sequence< style::TabStop > aTabs;
1102 if ( aValue >>= aTabs )
1104 fprintf( stderr, "Found tab stops\n" );
1107 #endif
1108 uno::Reference< text::XTextRange > xTextRange =
1109 xTextAppend->finishParagraph( aProperties );
1110 getTableManager( ).handle(xTextRange);
1112 // Set the anchor of the objects to the created paragraph
1113 while ( m_aAnchoredStack.size( ) > 0 && !m_bIsInShape )
1115 uno::Reference< text::XTextContent > xObj = m_aAnchoredStack.top( );
1116 try
1118 #if DEBUG
1119 rtl::OUString sText( xTextRange->getString( ) );
1120 #endif
1121 xObj->attach( xTextRange );
1123 catch ( uno::RuntimeException& )
1125 // this is normal: the shape is already attached
1127 m_aAnchoredStack.pop( );
1130 // Get the end of paragraph character inserted
1131 uno::Reference< text::XTextCursor > xCur = xTextRange->getText( )->createTextCursor( );
1132 xCur->gotoEnd( false );
1133 xCur->goLeft( 1 , true );
1134 uno::Reference< text::XTextRange > xParaEnd( xCur, uno::UNO_QUERY );
1135 CheckParaRedline( xParaEnd );
1137 // Remove the last empty section paragraph if needed
1138 if ( m_bIsLastParaInSection && !m_bParaChanged )
1140 RemoveLastParagraph( );
1141 m_bIsLastParaInSection = false;
1144 m_bParaChanged = false;
1146 if( !bKeepLastParagraphProperties )
1147 rAppendContext.pLastParagraphProperties = pToBeSavedProperties;
1149 catch(const lang::IllegalArgumentException& rIllegal)
1151 (void)rIllegal;
1152 OSL_ENSURE( false, "IllegalArgumentException in DomainMapper_Impl::finishParagraph" );
1154 catch(const uno::Exception& rEx)
1156 (void)rEx;
1157 //OSL_ENSURE( false, "ArgumentException in DomainMapper_Impl::finishParagraph" );
1161 /*-------------------------------------------------------------------------
1163 -----------------------------------------------------------------------*/
1164 util::DateTime lcl_DateStringToDateTime( const ::rtl::OUString& rDateTime )
1166 util::DateTime aDateTime;
1167 //xsd::DateTime in the format [-]CCYY-MM-DDThh:mm:ss[Z|(+|-)hh:mm] example: 2008-01-21T10:42:00Z
1168 //OUString getToken( sal_Int32 token, sal_Unicode cTok, sal_Int32& index ) const SAL_THROW(())
1169 sal_Int32 nIndex = 0;
1170 ::rtl::OUString sDate = rDateTime.getToken( 0, 'T', nIndex );
1171 ::rtl::OUString sTime = rDateTime.getToken( 0, 'Z', nIndex );
1172 nIndex = 0;
1173 aDateTime.Year = sal_uInt16( sDate.getToken( 0, '-', nIndex ).toInt32() );
1174 aDateTime.Month = sal_uInt16( sDate.getToken( 0, '-', nIndex ).toInt32() );
1175 aDateTime.Day = sal_uInt16( sDate.copy( nIndex ).toInt32() );
1177 nIndex = 0;
1178 aDateTime.Hours = sal_uInt16( sTime.getToken( 0, ':', nIndex ).toInt32() );
1179 aDateTime.Minutes = sal_uInt16( sTime.getToken( 0, ':', nIndex ).toInt32() );
1180 aDateTime.Seconds = sal_uInt16( sTime.copy( nIndex ).toInt32() );
1182 return aDateTime;
1184 void DomainMapper_Impl::appendTextPortion( const ::rtl::OUString& rString, PropertyMapPtr pPropertyMap )
1186 uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend;
1187 if(xTextAppend.is() && ! getTableManager( ).isIgnore())
1191 uno::Reference< text::XTextRange > xTextRange =
1192 xTextAppend->appendTextPortion
1193 (rString, pPropertyMap->GetPropertyValues());
1194 CheckRedline( xTextRange );
1195 m_bParaChanged = true;
1197 //getTableManager( ).handle(xTextRange);
1199 catch(const lang::IllegalArgumentException& rEx)
1201 (void)rEx;
1202 OSL_ENSURE( false, "IllegalArgumentException in DomainMapper_Impl::appendTextPortion" );
1204 catch(const uno::Exception& rEx)
1206 (void)rEx;
1207 OSL_ENSURE( false, "Exception in DomainMapper_Impl::appendTextPortion" );
1211 /*-- 02.11.2006 12:08:33---------------------------------------------------
1213 -----------------------------------------------------------------------*/
1214 void DomainMapper_Impl::appendTextContent(
1215 const uno::Reference< text::XTextContent > xContent,
1216 const uno::Sequence< beans::PropertyValue > xPropertyValues
1219 uno::Reference< text::XTextAppendAndConvert > xTextAppendAndConvert( m_aTextAppendStack.top().xTextAppend, uno::UNO_QUERY );
1220 OSL_ENSURE( xTextAppendAndConvert.is(), "trying to append a text content without XTextAppendAndConvert" );
1221 if(xTextAppendAndConvert.is() && ! getTableManager( ).isIgnore())
1225 xTextAppendAndConvert->appendTextContent( xContent, xPropertyValues );
1227 catch(const lang::IllegalArgumentException& )
1230 catch(const uno::Exception& )
1236 /*-- 24.04.2008 08:38:07---------------------------------------------------
1238 -----------------------------------------------------------------------*/
1239 void DomainMapper_Impl::appendOLE( const ::rtl::OUString& rStreamName, OLEHandlerPtr pOLEHandler )
1241 static const rtl::OUString sEmbeddedService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextEmbeddedObject"));
1244 uno::Reference< text::XTextContent > xOLE( m_xTextFactory->createInstance(sEmbeddedService), uno::UNO_QUERY_THROW );
1245 uno::Reference< beans::XPropertySet > xOLEProperties(xOLE, uno::UNO_QUERY_THROW);
1247 xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_STREAM_NAME ),
1248 uno::makeAny( rStreamName ));
1249 awt::Size aSize = pOLEHandler->getSize();
1250 if( !aSize.Width )
1251 aSize.Width = 1000;
1252 if( !aSize.Height )
1253 aSize.Height = 1000;
1254 xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_WIDTH ),
1255 uno::makeAny(aSize.Width));
1256 xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_HEIGHT ),
1257 uno::makeAny(aSize.Height));
1259 uno::Reference< graphic::XGraphic > xGraphic = pOLEHandler->getReplacement();
1260 xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_GRAPHIC ),
1261 uno::makeAny(xGraphic));
1264 appendTextContent( xOLE, uno::Sequence< beans::PropertyValue >() );
1267 catch( const uno::Exception& rEx )
1269 (void)rEx;
1270 OSL_ENSURE( false, "Exception in creation of OLE object" );
1274 /*-- 14.12.2006 12:26:00---------------------------------------------------
1276 -----------------------------------------------------------------------*/
1277 uno::Reference< beans::XPropertySet > DomainMapper_Impl::appendTextSectionAfter(
1278 uno::Reference< text::XTextRange >& xBefore )
1280 uno::Reference< beans::XPropertySet > xRet;
1281 uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend;
1282 if(xTextAppend.is())
1286 uno::Reference< text::XParagraphCursor > xCursor(
1287 xTextAppend->createTextCursorByRange( xBefore ), uno::UNO_QUERY_THROW);
1288 //the cursor has been moved to the end of the paragraph because of the appendTextPortion() calls
1289 xCursor->gotoStartOfParagraph( false );
1290 xCursor->gotoEnd( true );
1291 //the paragraph after this new section is already inserted
1292 xCursor->goLeft(1, true);
1293 static const rtl::OUString sSectionService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextSection"));
1294 uno::Reference< text::XTextContent > xSection( m_xTextFactory->createInstance(sSectionService), uno::UNO_QUERY_THROW );
1295 xSection->attach( uno::Reference< text::XTextRange >( xCursor, uno::UNO_QUERY_THROW) );
1296 xRet = uno::Reference< beans::XPropertySet > (xSection, uno::UNO_QUERY );
1298 catch(const uno::Exception& )
1304 return xRet;
1306 /*-- 02.11.2006 12:08:33---------------------------------------------------
1308 -----------------------------------------------------------------------*/
1309 void DomainMapper_Impl::PushPageHeader(SectionPropertyMap::PageType eType)
1311 //get the section context
1312 PropertyMapPtr pContext = DomainMapper_Impl::GetTopContextOfType(CONTEXT_SECTION);
1313 //ask for the header name of the given type
1314 SectionPropertyMap* pSectionContext = dynamic_cast< SectionPropertyMap* >( pContext.get() );
1315 if(pSectionContext)
1317 uno::Reference< beans::XPropertySet > xPageStyle =
1318 pSectionContext->GetPageStyle(
1319 GetPageStyles(),
1320 m_xTextFactory,
1321 eType == SectionPropertyMap::PAGE_FIRST );
1324 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
1325 //switch on header use
1326 xPageStyle->setPropertyValue(
1327 rPropNameSupplier.GetName(PROP_HEADER_IS_ON),
1328 uno::makeAny(sal_True) );
1329 // if a left header is available then header are not shared
1330 bool bLeft = eType == SectionPropertyMap::PAGE_LEFT;
1331 if( bLeft )
1332 xPageStyle->setPropertyValue(rPropNameSupplier.GetName(PROP_HEADER_IS_SHARED), uno::makeAny( false ));
1334 //set the interface
1335 uno::Reference< text::XText > xHeaderText;
1336 xPageStyle->getPropertyValue(rPropNameSupplier.GetName( bLeft ? PROP_HEADER_TEXT_LEFT : PROP_HEADER_TEXT) ) >>= xHeaderText;
1337 m_aTextAppendStack.push( uno::Reference< text::XTextAppend >( xHeaderText, uno::UNO_QUERY_THROW));
1339 catch( uno::Exception& )
1344 /*-- 24.07.2006 09:41:20---------------------------------------------------
1346 -----------------------------------------------------------------------*/
1347 void DomainMapper_Impl::PushPageFooter(SectionPropertyMap::PageType eType)
1349 //get the section context
1350 PropertyMapPtr pContext = DomainMapper_Impl::GetTopContextOfType(CONTEXT_SECTION);
1351 //ask for the footer name of the given type
1352 SectionPropertyMap* pSectionContext = dynamic_cast< SectionPropertyMap* >( pContext.get() );
1353 if(pSectionContext)
1355 uno::Reference< beans::XPropertySet > xPageStyle =
1356 pSectionContext->GetPageStyle(
1357 GetPageStyles(),
1358 m_xTextFactory,
1359 eType == SectionPropertyMap::PAGE_FIRST );
1362 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
1363 //switch on footer use
1364 xPageStyle->setPropertyValue(
1365 rPropNameSupplier.GetName(PROP_FOOTER_IS_ON),
1366 uno::makeAny(sal_True) );
1367 // if a left header is available then footer is not shared
1368 bool bLeft = eType == SectionPropertyMap::PAGE_LEFT;
1369 if( bLeft )
1370 xPageStyle->setPropertyValue(rPropNameSupplier.GetName(PROP_FOOTER_IS_SHARED), uno::makeAny( false ));
1371 //set the interface
1372 uno::Reference< text::XText > xFooterText;
1373 xPageStyle->getPropertyValue(rPropNameSupplier.GetName( bLeft ? PROP_FOOTER_TEXT_LEFT : PROP_FOOTER_TEXT) ) >>= xFooterText;
1374 m_aTextAppendStack.push(uno::Reference< text::XTextAppend >( xFooterText, uno::UNO_QUERY_THROW ));
1376 catch( uno::Exception& )
1381 /*-- 24.07.2006 09:41:20---------------------------------------------------
1383 -----------------------------------------------------------------------*/
1384 void DomainMapper_Impl::PopPageHeaderFooter()
1386 //header and footer always have an empty paragraph at the end
1387 //this has to be removed
1388 RemoveLastParagraph( );
1389 m_aTextAppendStack.pop();
1391 /*-- 24.05.2007 14:22:28---------------------------------------------------
1393 -----------------------------------------------------------------------*/
1394 void DomainMapper_Impl::PushFootOrEndnote( bool bIsFootnote )
1398 PropertyMapPtr pTopContext = GetTopContext();
1399 uno::Reference< text::XText > xFootnoteText( GetTextFactory()->createInstance(
1400 bIsFootnote ?
1401 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Footnote") ) : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Endnote") )),
1402 uno::UNO_QUERY_THROW );
1403 uno::Reference< text::XFootnote > xFootnote( xFootnoteText, uno::UNO_QUERY_THROW );
1404 pTopContext->SetFootnote( xFootnote );
1405 if( pTopContext->GetFootnoteSymbol() != 0)
1407 xFootnote->setLabel( ::rtl::OUString( pTopContext->GetFootnoteSymbol() ) );
1409 FontTablePtr pFontTable = GetFontTable();
1410 uno::Sequence< beans::PropertyValue > aFontProperties;
1411 if( pFontTable && pTopContext->GetFootnoteFontId() >= 0 && pFontTable->size() > (size_t)pTopContext->GetFootnoteFontId() )
1413 const FontEntry* pFontEntry = pFontTable->getFontEntry(sal_uInt32(pTopContext->GetFootnoteFontId()));
1414 PropertyMapPtr aFontProps( new PropertyMap );
1415 aFontProps->Insert(PROP_CHAR_FONT_NAME, true, uno::makeAny( pFontEntry->sFontName ));
1416 aFontProps->Insert(PROP_CHAR_FONT_CHAR_SET, true, uno::makeAny( (sal_Int16)pFontEntry->nTextEncoding ));
1417 aFontProps->Insert(PROP_CHAR_FONT_PITCH, true, uno::makeAny( pFontEntry->nPitchRequest ));
1418 aFontProperties = aFontProps->GetPropertyValues();
1420 else if(pTopContext->GetFootnoteFontName().getLength())
1422 PropertyMapPtr aFontProps( new PropertyMap );
1423 aFontProps->Insert(PROP_CHAR_FONT_NAME, true, uno::makeAny( pTopContext->GetFootnoteFontName() ));
1424 aFontProperties = aFontProps->GetPropertyValues();
1426 appendTextContent( uno::Reference< text::XTextContent >( xFootnoteText, uno::UNO_QUERY_THROW ), aFontProperties );
1427 m_aTextAppendStack.push(uno::Reference< text::XTextAppend >( xFootnoteText, uno::UNO_QUERY_THROW ));
1429 // Redlines for the footnote anchor
1430 CheckRedline( xFootnote->getAnchor( ) );
1432 catch( uno::Exception& )
1434 OSL_ENSURE( false, "exception in PushFootOrEndnote" );
1438 void DomainMapper_Impl::CreateRedline( uno::Reference< text::XTextRange > xRange, RedlineParamsPtr& pRedline )
1440 if ( pRedline.get( ) )
1442 #if DEBUG
1443 clog << "REDLINE: Writing redline: " << pRedline->m_nId << endl;
1444 #endif
1447 ::rtl::OUString sType;
1448 PropertyNameSupplier & rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier( );
1449 switch ( pRedline->m_nToken & 0xffff )
1451 case ooxml::OOXML_mod:
1452 sType = rPropNameSupplier.GetName( PROP_FORMAT );
1453 break;
1454 case ooxml::OOXML_ins:
1455 sType = rPropNameSupplier.GetName( PROP_INSERT );
1456 break;
1457 case ooxml::OOXML_del:
1458 sType = rPropNameSupplier.GetName( PROP_DELETE );
1459 break;
1461 uno::Reference < text::XRedline > xRedline( xRange, uno::UNO_QUERY_THROW );
1462 beans::PropertyValues aRedlineProperties( 2 );
1463 beans::PropertyValue * pRedlineProperties = aRedlineProperties.getArray( );
1464 pRedlineProperties[0].Name = rPropNameSupplier.GetName( PROP_REDLINE_AUTHOR );
1465 pRedlineProperties[0].Value <<= pRedline->m_sAuthor;
1466 pRedlineProperties[1].Name = rPropNameSupplier.GetName( PROP_REDLINE_DATE_TIME );
1467 pRedlineProperties[1].Value <<= lcl_DateStringToDateTime( pRedline->m_sDate );
1469 xRedline->makeRedline( sType, aRedlineProperties );
1471 catch( const uno::Exception & rEx )
1473 #if DEBUG
1474 clog << "REDLINE: error - " << rtl::OUStringToOString( rEx.Message, RTL_TEXTENCODING_UTF8 ).getStr( ) << endl;
1475 #endif
1476 ( void ) rEx;
1477 OSL_ENSURE( false, "Exception in makeRedline" );
1482 void DomainMapper_Impl::CheckParaRedline( uno::Reference< text::XTextRange > xRange )
1484 if ( m_pParaRedline.get( ) )
1486 CreateRedline( xRange, m_pParaRedline );
1487 ResetParaRedline( );
1491 void DomainMapper_Impl::CheckRedline( uno::Reference< text::XTextRange > xRange )
1493 vector<RedlineParamsPtr>::iterator pIt = m_aRedlines.begin( );
1494 vector< RedlineParamsPtr > aCleaned;
1495 for (; pIt != m_aRedlines.end( ); pIt++ )
1497 CreateRedline( xRange, *pIt );
1499 // Adding the non-mod redlines to the temporary vector
1500 if ( pIt->get( ) && ( ( *pIt )->m_nToken & 0xffff ) != ooxml::OOXML_mod )
1502 aCleaned.push_back( *pIt );
1506 m_aRedlines.swap( aCleaned );
1509 void DomainMapper_Impl::StartParaChange( )
1511 m_bIsParaChange = true;
1514 void DomainMapper_Impl::EndParaChange( )
1516 m_bIsParaChange = false;
1519 /*-- 22.12.2008 13:45:15---------------------------------------------------
1521 -----------------------------------------------------------------------*/
1522 void DomainMapper_Impl::PushAnnotation()
1526 PropertyMapPtr pTopContext = GetTopContext();
1527 m_xAnnotationField = uno::Reference< beans::XPropertySet >( GetTextFactory()->createInstance(
1528 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField.Annotation") ) ),
1529 uno::UNO_QUERY_THROW );
1530 uno::Reference< text::XText > xAnnotationText;
1531 m_xAnnotationField->getPropertyValue(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("TextRange"))) >>= xAnnotationText;
1532 m_aTextAppendStack.push(uno::Reference< text::XTextAppend >( xAnnotationText, uno::UNO_QUERY_THROW ));
1534 catch( uno::Exception& )
1536 OSL_ENSURE( false, "exception in PushFootOrEndnote" );
1539 /*-- 24.05.2007 14:22:29---------------------------------------------------
1541 -----------------------------------------------------------------------*/
1542 void DomainMapper_Impl::PopFootOrEndnote()
1544 m_aTextAppendStack.pop();
1546 /*-- 22.12.2008 13:45:15---------------------------------------------------
1548 -----------------------------------------------------------------------*/
1549 void DomainMapper_Impl::PopAnnotation()
1551 m_aTextAppendStack.pop();
1552 uno::Sequence< beans::PropertyValue > aEmptyProperties;
1553 appendTextContent( uno::Reference< text::XTextContent >( m_xAnnotationField, uno::UNO_QUERY_THROW ), aEmptyProperties );
1554 m_xAnnotationField.clear();
1558 void DomainMapper_Impl::PushShapeContext( const uno::Reference< drawing::XShape > xShape )
1560 #if DEBUG
1561 clog << "PushShapeContext" << endl;
1562 #endif
1563 m_bIsInShape = true;
1564 try
1566 // Add the shape to the text append stack
1567 m_aTextAppendStack.push( uno::Reference< text::XTextAppend >( xShape, uno::UNO_QUERY_THROW ) );
1568 m_bShapeContextAdded = true;
1570 // Add the shape to the anchored objects stack
1571 uno::Reference< text::XTextContent > xTxtContent( xShape, uno::UNO_QUERY_THROW );
1572 m_aAnchoredStack.push( xTxtContent );
1574 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
1576 uno::Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY_THROW );
1577 xProps->setPropertyValue(
1578 rPropNameSupplier.GetName( PROP_ANCHOR_TYPE ),
1579 uno::makeAny( text::TextContentAnchorType_AT_PARAGRAPH ) );
1580 xProps->setPropertyValue(
1581 rPropNameSupplier.GetName( PROP_OPAQUE ),
1582 uno::makeAny( true ) );
1584 catch ( const uno::Exception& e )
1586 #if DEBUG
1587 clog << "Exception when adding shape: ";
1588 clog << rtl::OUStringToOString( e.Message, RTL_TEXTENCODING_UTF8 ).getStr( );
1589 clog << endl;
1590 #endif
1594 /*-- 20.03.2008 09:01:59---------------------------------------------------
1596 -----------------------------------------------------------------------*/
1597 void DomainMapper_Impl::PopShapeContext()
1599 #if DEBUG
1600 clog << "PopShapeContext" << endl;
1601 #endif
1603 if ( m_bShapeContextAdded )
1605 m_aTextAppendStack.pop();
1606 m_bShapeContextAdded = false;
1608 m_bIsInShape = false;
1610 /*-- 12.09.2006 08:07:55---------------------------------------------------
1612 -----------------------------------------------------------------------*/
1613 ::rtl::OUString lcl_FindQuotedText( const ::rtl::OUString& rCommand,
1614 const sal_Char* cStartQuote, const sal_Unicode uEndQuote )
1616 ::rtl::OUString sRet;
1617 ::rtl::OUString sStartQuote( ::rtl::OUString::createFromAscii(cStartQuote) );
1618 sal_Int32 nStartIndex = rCommand.indexOf( sStartQuote );
1619 if( nStartIndex >= 0 )
1621 sal_Int32 nStartLength = sStartQuote.getLength();
1622 sal_Int32 nEndIndex = rCommand.indexOf( uEndQuote, nStartIndex + nStartLength);
1623 if( nEndIndex > nStartIndex )
1625 sRet = rCommand.copy( nStartIndex + nStartLength, nEndIndex - nStartIndex - nStartLength);
1628 return sRet;
1631 /*-- 08.09.2006 14:05:17---------------------------------------------------
1633 -----------------------------------------------------------------------*/
1634 sal_Int16 lcl_ParseNumberingType( const ::rtl::OUString& rCommand )
1636 sal_Int16 nRet = style::NumberingType::PAGE_DESCRIPTOR;
1638 // The command looks like: " PAGE \* Arabic "
1639 ::rtl::OUString sNumber = lcl_FindQuotedText(rCommand, "\\* ", ' ');
1641 if( sNumber.getLength() )
1643 //todo: might make sense to hash this list, too
1644 struct NumberingPairs
1646 const sal_Char* cWordName;
1647 sal_Int16 nType;
1649 static const NumberingPairs aNumberingPairs[] =
1651 {"Arabic", style::NumberingType::ARABIC}
1652 ,{"ROMAN", style::NumberingType::ROMAN_UPPER}
1653 ,{"roman", style::NumberingType::ROMAN_LOWER}
1654 ,{"ALPHABETIC", style::NumberingType::CHARS_UPPER_LETTER}
1655 ,{"alphabetic", style::NumberingType::CHARS_LOWER_LETTER}
1656 ,{"CircleNum", style::NumberingType::CIRCLE_NUMBER}
1657 ,{"ThaiArabic", style::NumberingType::CHARS_THAI}
1658 ,{"ThaiCardText", style::NumberingType::CHARS_THAI}
1659 ,{"ThaiLetter", style::NumberingType::CHARS_THAI}
1660 // ,{"SBCHAR", style::NumberingType::}
1661 // ,{"DBCHAR", style::NumberingType::}
1662 // ,{"DBNUM1", style::NumberingType::}
1663 // ,{"DBNUM2", style::NumberingType::}
1664 // ,{"DBNUM3", style::NumberingType::}
1665 // ,{"DBNUM4", style::NumberingType::}
1666 ,{"Aiueo", style::NumberingType::AIU_FULLWIDTH_JA}
1667 ,{"Iroha", style::NumberingType::IROHA_FULLWIDTH_JA}
1668 // ,{"ZODIAC1", style::NumberingType::}
1669 // ,{"ZODIAC2", style::NumberingType::}
1670 // ,{"ZODIAC3", style::NumberingType::}
1671 // ,{"CHINESENUM1", style::NumberingType::}
1672 // ,{"CHINESENUM2", style::NumberingType::}
1673 // ,{"CHINESENUM3", style::NumberingType::}
1674 ,{"ArabicAlpha", style::NumberingType::CHARS_ARABIC}
1675 ,{"ArabicAbjad", style::NumberingType::FULLWIDTH_ARABIC}
1676 /* possible values:
1677 style::NumberingType::
1679 CHARS_UPPER_LETTER_N
1680 CHARS_LOWER_LETTER_N
1681 TRANSLITERATION
1682 NATIVE_NUMBERING
1683 CIRCLE_NUMBER
1684 NUMBER_LOWER_ZH
1685 NUMBER_UPPER_ZH
1686 NUMBER_UPPER_ZH_TW
1687 TIAN_GAN_ZH
1688 DI_ZI_ZH
1689 NUMBER_TRADITIONAL_JA
1690 AIU_HALFWIDTH_JA
1691 IROHA_HALFWIDTH_JA
1692 NUMBER_UPPER_KO
1693 NUMBER_HANGUL_KO
1694 HANGUL_JAMO_KO
1695 HANGUL_SYLLABLE_KO
1696 HANGUL_CIRCLED_JAMO_KO
1697 HANGUL_CIRCLED_SYLLABLE_KO
1698 CHARS_HEBREW
1699 CHARS_NEPALI
1700 CHARS_KHMER
1701 CHARS_LAO
1702 CHARS_TIBETAN
1703 CHARS_CYRILLIC_UPPER_LETTER_BG
1704 CHARS_CYRILLIC_LOWER_LETTER_BG
1705 CHARS_CYRILLIC_UPPER_LETTER_N_BG
1706 CHARS_CYRILLIC_LOWER_LETTER_N_BG
1707 CHARS_CYRILLIC_UPPER_LETTER_RU
1708 CHARS_CYRILLIC_LOWER_LETTER_RU
1709 CHARS_CYRILLIC_UPPER_LETTER_N_RU
1710 CHARS_CYRILLIC_LOWER_LETTER_N_RU
1711 CHARS_CYRILLIC_UPPER_LETTER_SR
1712 CHARS_CYRILLIC_LOWER_LETTER_SR
1713 CHARS_CYRILLIC_UPPER_LETTER_N_SR
1714 CHARS_CYRILLIC_LOWER_LETTER_N_SR*/
1717 for( sal_uInt32 nNum = 0; nNum < sizeof(aNumberingPairs)/sizeof( NumberingPairs ); ++nNum)
1719 if( /*sCommand*/sNumber.equalsAscii(aNumberingPairs[nNum].cWordName ))
1721 nRet = aNumberingPairs[nNum].nType;
1722 break;
1727 return nRet;
1729 /*-- 08.09.2006 13:52:09---------------------------------------------------
1731 -----------------------------------------------------------------------*/
1732 OUString lcl_ParseFormat( const ::rtl::OUString& rCommand )
1734 // The command looks like: " DATE \@ "dd MMMM yyyy"
1735 return lcl_FindQuotedText(rCommand, "\\@ \"", '\"');
1737 /*-- 19.09.2006 10:01:20---------------------------------------------------
1738 extract a parameter (with or without quotes) between the command and the following backslash
1739 -----------------------------------------------------------------------*/
1740 ::rtl::OUString lcl_ExtractParameter(const ::rtl::OUString& rCommand, sal_Int32 nCommandLength )
1742 sal_Int32 nStartIndex = nCommandLength;
1743 sal_Int32 nEndIndex = 0;
1744 sal_Int32 nQuoteIndex = rCommand.indexOf( '\"', nStartIndex);
1745 if( nQuoteIndex >= 0)
1747 nStartIndex = nQuoteIndex + 1;
1748 nEndIndex = rCommand.indexOf( '\"', nStartIndex + 1) - 1;
1750 else
1752 nEndIndex = rCommand.indexOf( ::rtl::OUString::createFromAscii(" \\"), nStartIndex);
1754 ::rtl::OUString sRet;
1755 if( nEndIndex > nStartIndex + 1 )
1757 //remove spaces at start and end of the result
1758 if(nQuoteIndex <= 0)
1760 const sal_Unicode* pCommandStr = rCommand.getStr();
1761 while( nStartIndex < nEndIndex && pCommandStr[nStartIndex] == ' ')
1762 ++nStartIndex;
1763 while( nEndIndex > nStartIndex && pCommandStr[nEndIndex] == ' ')
1764 --nEndIndex;
1766 sRet = rCommand.copy( nStartIndex, nEndIndex - nStartIndex + 1);
1768 return sRet;
1771 /*-- 15.09.2006 10:57:57---------------------------------------------------
1773 -----------------------------------------------------------------------*/
1774 ::rtl::OUString lcl_ExctractAskVariableAndHint( const ::rtl::OUString& rCommand, ::rtl::OUString& rHint )
1776 // the first word after "ASK " is the variable
1777 // the text after the variable and before a '\' is the hint
1778 // if no hint is set the variable is used as hint
1779 // the quotes of the hint have to be removed
1780 sal_Int32 nIndex = rCommand.indexOf( ' ', 2);//find last space after 'ASK'
1781 while(rCommand.getStr()[nIndex] == ' ')
1782 ++nIndex;
1783 ::rtl::OUString sShortCommand( rCommand.copy( nIndex ) ); //cut off the " ASK "
1785 nIndex = 0;
1786 sShortCommand = sShortCommand.getToken( 0, '\\', nIndex);
1787 nIndex = 0;
1788 ::rtl::OUString sRet = sShortCommand.getToken( 0, ' ', nIndex);
1789 if( nIndex > 0)
1790 rHint = sShortCommand.copy( nIndex );
1791 if( !rHint.getLength() )
1792 rHint = sRet;
1793 return sRet;
1795 /*-- 24.01.2007 16:04:33---------------------------------------------------
1797 -----------------------------------------------------------------------*/
1798 bool lcl_FindInCommand(
1799 const ::rtl::OUString& rCommand,
1800 sal_Unicode cSwitch,
1801 ::rtl::OUString& rValue )
1803 bool bRet = false;
1804 ::rtl::OUString sSearch('\\');
1805 sSearch += ::rtl::OUString( cSwitch );
1806 sal_Int32 nIndex = rCommand.indexOf( sSearch );
1807 if( nIndex >= 0 )
1809 bRet = true;
1810 //find next '\' or end of string
1811 sal_Int32 nEndIndex = rCommand.indexOf( '\\', nIndex + 1);
1812 if( nEndIndex < 0 )
1813 nEndIndex = rCommand.getLength() - 1;
1814 if( nEndIndex - nIndex > 3 )
1815 rValue = rCommand.copy( nIndex + 3, nEndIndex - nIndex - 3);
1817 return bRet;
1819 /*-- 01.09.2006 11:48:08---------------------------------------------------
1821 -----------------------------------------------------------------------*/
1822 /*void DomainMapper_Impl::CreateField( ::rtl::OUString& rCommand )
1824 static FieldConversionMap_t aFieldConversionMap;
1825 static bool bFilled = false;
1826 m_bSetUserFieldContent = false;
1827 if(!bFilled)
1829 static const FieldConversion aFields[] =
1831 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ADDRESSBLOCK")), "", "", FIELD_ADDRESSBLOCK },
1832 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ADVANCE")), "", "", FIELD_ADVANCE },
1833 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ASK")), "SetExpression", "SetExpression", FIELD_ASK },
1834 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AUTONUM")), "SetExpression", "SetExpression", FIELD_AUTONUM },
1835 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AUTONUMLGL")), "SetExpression", "SetExpression", FIELD_AUTONUMLGL },
1836 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AUTONUMOUT")), "SetExpression", "SetExpression", FIELD_AUTONUMOUT },
1837 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AUTHOR")), "Author", "", FIELD_AUTHOR },
1838 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DATE")), "DateTime", "", FIELD_DATE },
1839 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("COMMENTS")), "DocInfo.Description", "", FIELD_COMMENTS },
1840 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CREATEDATE")), "DocInfo.CreateDateTime", "", FIELD_CREATEDATE },
1841 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DOCPROPERTY")), "", "", FIELD_DOCPROPERTY },
1842 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DOCVARIABLE")), "User", "", FIELD_DOCVARIABLE },
1843 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EDITTIME")), "DocInfo.EditTime", "", FIELD_EDITTIME },
1844 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FILLIN")), "Input", "", FIELD_FILLIN },
1845 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FILENAME")), "FileName", "", FIELD_FILENAME },
1846 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FILESIZE")), "", "", FIELD_FILESIZE },
1847 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FORMULA")), "", "", FIELD_FORMULA
1848 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GOTOBUTTON")), "", "", FIELD_GOTOBUTTON },
1849 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HYPERLINK")), "", "", FIELD_HYPERLINK },
1850 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IF")), "ConditionalText", "", FIELD_IF },
1851 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("INFO")), "","", FIELD_INFO },
1852 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("INCLUDEPICTURE")), "", "", FIELD_INCLUDEPICTURE},
1853 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("KEYWORDS")), "DocInfo.KeyWords", "", FIELD_KEYWORDS },
1854 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LASTSAVEDBY")), "DocInfo.ChangeAuthor", "", FIELD_LASTSAVEDBY },
1855 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MACROBUTTON")), "Macro", "", FIELD_MACROBUTTON },
1856 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MERGEFIELD")), "Database", "Database", FIELD_MERGEFIELD},
1857 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MERGEREC")), "DatabaseNumberOfSet", "", FIELD_MERGEREC },
1858 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MERGESEQ")), "", "", FIELD_MERGESEQ },
1859 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NEXT")), "DatabaseNextSet", "", FIELD_NEXT },
1860 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NEXTIF")), "DatabaseNextSet", "", FIELD_NEXTIF },
1861 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PAGE")), "PageNumber", "", FIELD_PAGE },
1862 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("REF")), "", "", FIELD_REF },
1863 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("REVNUM")), "DocInfo.Revision", "", FIELD_REVNUM },
1864 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SAVEDATE")), "DocInfo.Change", "", FIELD_SAVEDATE },
1865 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SECTION")), "", "", FIELD_SECTION },
1866 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SECTIONPAGES")), "", "", FIELD_SECTIONPAGES },
1867 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SEQ")), "SetExpression", "SetExpression", FIELD_SEQ },
1868 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SET")), "","", FIELD_SET },
1869 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SKIPIF")),"", "", FIELD_SKIPIF },
1870 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("STYLEREF")),"", "", FIELD_STYLEREF },
1871 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SUBJECT")), "DocInfo.Subject", "", FIELD_SUBJECT },
1872 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("SYMBOL")),"", "", FIELD_SYMBOL },
1873 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TEMPLATE")), "TemplateName", "", FIELD_TEMPLATE},
1874 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TIME")), "DateTime", "", FIELD_TIME },
1875 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TITLE")), "DocInfo.Title", "", FIELD_TITLE },
1876 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("USERINITIALS")), "ExtendedUser", "", FIELD_USERINITIALS},
1877 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("USERADDRESS")), "", "", FIELD_USERADDRESS },
1878 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("USERNAME")), "ExtendedUser", "", FIELD_USERNAME }
1879 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TOC")), "com.sun.star.text.ContentIndex", "", FIELD_TOC},
1880 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TC")), "com.sun.star.text.ContentIndexMark", "", FIELD_TC},
1882 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("")), "", "", FIELD_},
1885 size_t nConversions = sizeof(aFields)/sizeof(FieldConversion);
1886 for( size_t nConversion = 0; nConversion < nConversions; ++nConversion)
1888 aFieldConversionMap.insert( FieldConversionMap_t::value_type(
1889 aFields[nConversion].sWordCommand,
1890 aFields[nConversion] ));
1893 bFilled = true;
1897 uno::Reference< uno::XInterface > xFieldInterface;
1898 //at first determine the field type - skip first space
1899 ::rtl::OUString sCommand( rCommand.copy(rCommand.getLength() ? 1 : 0) );
1900 sal_Int32 nSpaceIndex = sCommand.indexOf( ' ' );
1901 if( 0 <= nSpaceIndex )
1902 sCommand = sCommand.copy( 0, nSpaceIndex );
1904 FieldConversionMap_t::iterator aIt = aFieldConversionMap.find(sCommand);
1905 if(aIt != aFieldConversionMap.end())
1907 uno::Reference< beans::XPropertySet > xFieldProperties;
1908 if( FIELD_HYPERLINK != aIt->second.eFieldId &&
1909 FIELD_DOCPROPERTY != aIt->second.eFieldId &&
1910 FIELD_TOC != aIt->second.eFieldId &&
1911 FIELD_TC != aIt->second.eFieldId)
1913 //add the service prefix
1914 OUString sServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField."));
1915 sServiceName += ::rtl::OUString::createFromAscii(aIt->second.cFieldServiceName );
1916 xFieldInterface = m_xTextFactory->createInstance(sServiceName);
1917 xFieldProperties = uno::Reference< beans::XPropertySet >( xFieldInterface, uno::UNO_QUERY_THROW);
1919 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
1920 switch( aIt->second.eFieldId )
1922 case FIELD_ADDRESSBLOCK: break;
1923 case FIELD_ADVANCE : break;
1924 case FIELD_ASK :
1926 //doesn the command contain a variable name?
1927 ::rtl::OUString sVariable, sHint;
1929 sVariable = lcl_ExctractAskVariableAndHint( rCommand, sHint );
1930 if(sVariable.getLength())
1932 // determine field master name
1933 uno::Reference< beans::XPropertySet > xMaster = FindOrCreateFieldMaster(
1934 "com.sun.star.text.FieldMaster.SetExpression", sVariable );
1936 // attach the master to the field
1937 uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
1938 xDependentField->attachTextFieldMaster( xMaster );
1940 // set input flag at the field
1941 xFieldProperties->setPropertyValue(
1942 rPropNameSupplier.GetName(PROP_IS_INPUT), uno::makeAny( true ));
1943 // set the prompt
1944 xFieldProperties->setPropertyValue(
1945 rPropNameSupplier.GetName(PROP_HINT),
1946 uno::makeAny( sHint ));
1948 else
1950 //don't insert the field
1951 //todo: maybe import a 'normal' input field here?
1952 xFieldInterface = 0;
1955 break;
1956 case FIELD_AUTONUM :
1957 case FIELD_AUTONUMLGL :
1958 case FIELD_AUTONUMOUT :
1960 //create a sequence field master "AutoNr"
1961 uno::Reference< beans::XPropertySet > xMaster = FindOrCreateFieldMaster(
1962 "com.sun.star.text.FieldMaster.SetExpression",
1963 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutoNr") ));
1965 xMaster->setPropertyValue( rPropNameSupplier.GetName(PROP_SUB_TYPE),
1966 uno::makeAny(text::SetVariableType::SEQUENCE));
1968 //apply the numbering type
1969 xFieldProperties->setPropertyValue(
1970 rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
1971 uno::makeAny( lcl_ParseNumberingType(rCommand) ));
1972 // attach the master to the field
1973 uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
1974 xDependentField->attachTextFieldMaster( xMaster );
1976 break;
1977 case FIELD_AUTHOR :
1979 xFieldProperties->setPropertyValue( rPropNameSupplier.GetName(PROP_FULL_NAME), uno::makeAny( true ));
1980 ::rtl::OUString sParam = lcl_ExtractParameter(rCommand, sizeof(" AUTHOR") );
1981 if(sParam.getLength())
1983 xFieldProperties->setPropertyValue(
1984 rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
1985 //PROP_CURRENT_PRESENTATION is set later anyway
1988 break;
1989 case FIELD_DATE:
1991 //not fixed,
1992 xFieldProperties->setPropertyValue(
1993 rPropNameSupplier.GetName(PROP_IS_FIXED),
1994 uno::makeAny( false ));
1995 SetNumberFormat( rCommand, xFieldProperties );
1997 break;
1998 case FIELD_COMMENTS :
2000 ::rtl::OUString sParam = lcl_ExtractParameter(rCommand, sizeof(" COMMENTS") );
2001 if(sParam.getLength())
2003 xFieldProperties->setPropertyValue(
2004 rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
2005 //PROP_CURRENT_PRESENTATION is set later anyway
2008 break;
2009 case FIELD_CREATEDATE :
2011 SetNumberFormat( rCommand, xFieldProperties );
2013 break;
2014 case FIELD_DOCPROPERTY :
2016 //some docproperties should be imported as document statistic fields, some as DocInfo fields
2017 //others should be user fields
2018 ::rtl::OUString sParam = lcl_ExtractParameter(rCommand, sizeof(" DOCPROPERTY") );
2019 if(sParam.getLength())
2021 #define SET_ARABIC 0x01
2022 #define SET_FULL_NAME 0x02
2023 struct DocPropertyMap
2025 const sal_Char* pDocPropertyName;
2026 const sal_Char* pServiceName;
2027 sal_uInt8 nFlags;
2029 static const DocPropertyMap aDocProperties[] =
2031 {"Author", "Author", SET_FULL_NAME},
2032 {"CreateTime", "DocInfo.CreateDateTime", 0},
2033 {"Characters", "CharacterCount", SET_ARABIC},
2034 {"Comments", "DocInfo.Description", 0},
2035 {"Keywords", "DocInfo.KeyWords", 0},
2036 {"LastPrinted", "DocInfo.PrintDateTime", 0},
2037 {"LastSavedBy", "DocInfo.ChangeAuthor", 0},
2038 {"LastSavedTime", "DocInfo.ChangeDateTime", 0},
2039 {"Paragraphs", "ParagraphCount", SET_ARABIC},
2040 {"RevisionNumber", "DocInfo.Revision", 0},
2041 {"Subject", "DocInfo.Subject", 0},
2042 {"Template", "TemplateName", 0},
2043 {"Title", "DocInfo.Title", 0},
2044 {"TotalEditingTime", "DocInfo.EditTime", 9},
2045 {"Words", "WordCount", SET_ARABIC}
2047 //other available DocProperties:
2048 //Bytes, Category, CharactersWithSpaces, Company
2049 //HyperlinkBase,
2050 //Lines, Manager, NameofApplication, ODMADocId, Pages,
2051 //Security,
2053 //search for a field mapping
2054 ::rtl::OUString sFieldServiceName;
2055 sal_uInt16 nMap = 0;
2056 for( ; nMap < sizeof(aDocProperties) / sizeof(DocPropertyMap); ++nMap )
2058 if(sParam.equalsAscii(aDocProperties[nMap].pDocPropertyName))
2060 sFieldServiceName = ::rtl::OUString::createFromAscii(aDocProperties[nMap].pServiceName);
2061 break;
2064 ::rtl::OUString sServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField."));
2065 if(sFieldServiceName.getLength())
2067 sServiceName += sFieldServiceName;
2068 xFieldInterface = m_xTextFactory->createInstance(sServiceName);
2069 xFieldProperties = uno::Reference< beans::XPropertySet >( xFieldInterface, uno::UNO_QUERY_THROW);
2070 if(0 != (aDocProperties[nMap].nFlags & SET_ARABIC))
2071 xFieldProperties->setPropertyValue(
2072 rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
2073 uno::makeAny( style::NumberingType::ARABIC ));
2074 else if(0 != (aDocProperties[nMap].nFlags & SET_FULL_NAME))
2075 xFieldProperties->setPropertyValue(
2076 rPropNameSupplier.GetName(PROP_FULL_NAME), uno::makeAny( true ));
2079 else
2081 //create a user field and type
2082 uno::Reference< beans::XPropertySet > xMaster =
2083 FindOrCreateFieldMaster( "com.sun.star.text.FieldMaster.User", sParam );
2084 sServiceName += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("User"));
2085 xFieldInterface = m_xTextFactory->createInstance(sServiceName);
2086 xFieldProperties = uno::Reference< beans::XPropertySet >( xFieldInterface, uno::UNO_QUERY_THROW);
2087 uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
2088 xDependentField->attachTextFieldMaster( xMaster );
2089 m_bSetUserFieldContent = true;
2093 #undef SET_ARABIC
2094 #undef SET_FULL_NAME
2095 break;
2096 case FIELD_DOCVARIABLE :
2098 ::rtl::OUString sParam = lcl_ExtractParameter(rCommand, sizeof(" DOCVARIABLE") );
2099 //create a user field and type
2100 uno::Reference< beans::XPropertySet > xMaster =
2101 FindOrCreateFieldMaster( "com.sun.star.text.FieldMaster.User", sParam );
2102 uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
2103 xDependentField->attachTextFieldMaster( xMaster );
2104 m_bSetUserFieldContent = true;
2106 break;
2107 case FIELD_EDITTIME :
2108 //it's a numbering type, no number format! SetNumberFormat( rCommand, xFieldProperties );
2109 break;
2110 case FIELD_FILLIN :
2112 sal_Int32 nIndex = 0;
2113 xFieldProperties->setPropertyValue(
2114 rPropNameSupplier.GetName(PROP_HINT), uno::makeAny( rCommand.getToken( 1, '\"', nIndex)));
2116 break;
2117 case FIELD_FILENAME:
2119 sal_Int32 nNumberingTypeIndex = rCommand.indexOf( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\\p")));
2120 xFieldProperties->setPropertyValue(
2121 rPropNameSupplier.GetName(PROP_FILE_FORMAT),
2122 uno::makeAny( nNumberingTypeIndex > 0 ? text::FilenameDisplayFormat::FULL : text::FilenameDisplayFormat::NAME ));
2124 break;
2125 case FIELD_FILESIZE : break;
2126 case FIELD_FORMULA : break;
2127 case FIELD_GOTOBUTTON : break;
2128 case FIELD_HYPERLINK:
2130 sal_Int32 nStartQuote = rCommand.indexOf( '\"' );
2131 sal_Int32 nEndQuote = nStartQuote < rCommand.getLength() + 1 ? rCommand.indexOf( '\"', nStartQuote + 1) : -1;
2132 if( nEndQuote > 0)
2133 m_sHyperlinkURL = rCommand.copy(nStartQuote + 1, nEndQuote - nStartQuote - 1);
2135 break;
2136 case FIELD_IF : break;
2137 case FIELD_INFO : break;
2138 case FIELD_INCLUDEPICTURE: break;
2139 case FIELD_KEYWORDS :
2141 ::rtl::OUString sParam = lcl_ExtractParameter(rCommand, sizeof(" KEYWORDS") );
2142 if(sParam.getLength())
2144 xFieldProperties->setPropertyValue(
2145 rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
2146 //PROP_CURRENT_PRESENTATION is set later anyway
2149 break;
2150 case FIELD_LASTSAVEDBY : break;
2151 case FIELD_MACROBUTTON:
2153 //extract macro name
2154 sal_Int32 nIndex = sizeof(" MACROBUTTON ");
2155 ::rtl::OUString sMacro = rCommand.getToken( 0, ' ', nIndex);
2156 xFieldProperties->setPropertyValue(
2157 rPropNameSupplier.GetName(PROP_MACRO_NAME), uno::makeAny( sMacro ));
2159 //extract quick help text
2160 if( rCommand.getLength() > nIndex + 1)
2162 xFieldProperties->setPropertyValue(
2163 rPropNameSupplier.GetName(PROP_HINT),
2164 uno::makeAny( rCommand.copy( nIndex )));
2167 break;
2168 case FIELD_MERGEFIELD :
2170 //todo: create a database field and fieldmaster pointing to a column, only
2171 ::rtl::OUString sParam = lcl_ExtractParameter(rCommand, sizeof(" MERGEFIELD") );
2172 //create a user field and type
2173 uno::Reference< beans::XPropertySet > xMaster =
2174 FindOrCreateFieldMaster( "com.sun.star.text.FieldMaster.Database", sParam );
2176 // xFieldProperties->setPropertyValue(
2177 // ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FieldCode")),
2178 // uno::makeAny( rCommand.copy( nIndex + 1 )));
2179 uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
2180 xDependentField->attachTextFieldMaster( xMaster );
2181 m_bSetUserFieldContent = true;
2183 break;
2184 case FIELD_MERGEREC : break;
2185 case FIELD_MERGESEQ : break;
2186 case FIELD_NEXT : break;
2187 case FIELD_NEXTIF : break;
2188 case FIELD_PAGE :
2189 xFieldProperties->setPropertyValue(
2190 rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
2191 uno::makeAny( lcl_ParseNumberingType(rCommand) ));
2192 xFieldProperties->setPropertyValue(
2193 rPropNameSupplier.GetName(PROP_SUB_TYPE),
2194 uno::makeAny( text::PageNumberType_CURRENT ));
2196 break;
2197 case FIELD_REF : break;
2198 case FIELD_REVNUM : break;
2199 case FIELD_SAVEDATE :
2200 SetNumberFormat( rCommand, xFieldProperties );
2201 break;
2202 case FIELD_SECTION : break;
2203 case FIELD_SECTIONPAGES : break;
2204 case FIELD_SEQ : break;
2205 case FIELD_SET : break;
2206 case FIELD_SKIPIF : break;
2207 case FIELD_STYLEREF : break;
2208 case FIELD_SUBJECT :
2210 ::rtl::OUString sParam = lcl_ExtractParameter(rCommand, sizeof(" SUBJECT") );
2211 if(sParam.getLength())
2213 xFieldProperties->setPropertyValue(
2214 rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
2215 //PROP_CURRENT_PRESENTATION is set later anyway
2218 break;
2219 case FIELD_SYMBOL : break;
2220 case FIELD_TEMPLATE: break;
2221 case FIELD_TIME :
2222 SetNumberFormat( rCommand, xFieldProperties );
2223 break;
2224 case FIELD_TITLE :
2226 ::rtl::OUString sParam = lcl_ExtractParameter(rCommand, sizeof(" TITLE") );
2227 if(sParam.getLength())
2229 xFieldProperties->setPropertyValue(
2230 rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
2231 //PROP_CURRENT_PRESENTATION is set later anyway
2234 break;
2235 case FIELD_USERINITIALS:
2237 xFieldProperties->setPropertyValue(
2238 rPropNameSupplier.GetName(PROP_USER_DATA_TYPE), uno::makeAny( text::UserDataPart::SHORTCUT ));
2239 //todo: if initials are provided - set them as fixed content
2240 ::rtl::OUString sParam = lcl_ExtractParameter(rCommand, sizeof(" USERINITIALS") );
2241 if(sParam.getLength())
2243 xFieldProperties->setPropertyValue(
2244 rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
2245 //PROP_CURRENT_PRESENTATION is set later anyway
2248 break;
2249 case FIELD_USERADDRESS : //todo: user address collects street, city ...
2250 break;
2251 case FIELD_USERNAME : //todo: user name is firstname + lastname
2252 break;
2253 case FIELD_TOC:
2255 ::rtl::OUString sValue;
2256 bool bTableOfFigures = false;
2257 bool bHyperlinks = false;
2258 bool bFromOutline = false;
2259 bool bFromEntries = false;
2260 ::rtl::OUString sTemplate;
2261 ::rtl::OUString sChapterNoSeparator;
2262 // \a Builds a table of figures but does not include the captions's label and number
2263 if( lcl_FindInCommand( rCommand, 'a', sValue ))
2264 { //make it a table of figures
2265 bTableOfFigures = true;
2267 // \b Uses a bookmark to specify area of document from which to build table of contents
2268 // if( lcl_FindInCommand( rCommand, 'b', sValue ))
2269 // { //todo: sValue contains the bookmark name - unsupported feature
2270 // }
2271 if( lcl_FindInCommand( rCommand, 'c', sValue ))
2272 // \c Builds a table of figures of the given label
2274 //todo: sValue contains the label's name
2275 bTableOfFigures = true;
2277 // \d Defines the separator between sequence and page numbers
2278 if( lcl_FindInCommand( rCommand, 'd', sValue ))
2280 //todo: insert the chapter number into each level and insert the separator additionally
2281 sChapterNoSeparator = sValue;
2283 // \f Builds a table of contents using TC entries instead of outline levels
2284 if( lcl_FindInCommand( rCommand, 'f', sValue ))
2286 //todo: sValue can contain a TOC entry identifier - use unclear
2287 bFromEntries = true;
2289 // \h Hyperlinks the entries and page numbers within the table of contents
2290 if( lcl_FindInCommand( rCommand, 'h', sValue ))
2292 //todo: make all entries to hyperlinks
2293 bHyperlinks = true;
2295 // \l Defines the TC entries field level used to build a table of contents
2296 // if( lcl_FindInCommand( rCommand, 'l', sValue ))
2297 // {
2298 //todo: entries can only be included completely
2299 // }
2300 // \n Builds a table of contents or a range of entries, sucah as “1-9”, in a table of contents without page numbers
2301 // if( lcl_FindInCommand( rCommand, 'n', sValue ))
2302 // {
2303 //todo: what does the description mean?
2304 // }
2305 // \o Builds a table of contents by using outline levels instead of TC entries
2306 if( lcl_FindInCommand( rCommand, 'o', sValue ))
2308 bFromOutline = true;
2310 // \p Defines the separator between the table entry and its page number
2311 if( lcl_FindInCommand( rCommand, 'p', sValue ))
2313 // \s Builds a table of contents by using a sequence type
2314 if( lcl_FindInCommand( rCommand, 's', sValue ))
2316 // \t Builds a table of contents by using style names other than the standard outline styles
2317 if( lcl_FindInCommand( rCommand, 't', sValue ))
2319 sTemplate = sValue;
2321 // \u Builds a table of contents by using the applied paragraph outline level
2322 if( lcl_FindInCommand( rCommand, 'u', sValue ))
2324 bFromOutline = true;
2325 //todo: what doesn 'the applied paragraph outline level' refer to?
2327 // \w Preserve tab characters within table entries
2328 // if( lcl_FindInCommand( rCommand, 'w', sValue ))
2329 // {
2330 //todo: not supported
2331 // }
2332 // \x Preserve newline characters within table entries
2333 // if( lcl_FindInCommand( rCommand, 'x', sValue ))
2334 // {
2335 //todo: unsupported
2336 // }
2337 // \z Hides page numbers within the table of contens when shown in Web Layout View
2338 // if( lcl_FindInCommand( rCommand, 'z', sValue ))
2339 // { //todo: unsupported feature }
2341 m_xTOC = uno::Reference< beans::XPropertySet >(
2342 m_xTextFactory->createInstance(
2343 bTableOfFigures ?
2344 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.IllustrationsIndex")) :
2345 ::rtl::OUString::createFromAscii(aIt->second.cFieldServiceName)),
2346 uno::UNO_QUERY_THROW);
2347 if( !bTableOfFigures )
2349 m_xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_CREATE_FROM_OUTLINE ), uno::makeAny( bFromOutline ));
2350 m_xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_CREATE_FROM_MARKS ), uno::makeAny( bFromEntries ));
2351 if( sTemplate.getLength() )
2353 uno::Reference< container::XIndexReplace> xParaStyles;
2354 m_xTOC->getPropertyValue(rPropNameSupplier.GetName(PROP_LEVEL_PARAGRAPH_STYLES)) >>= xParaStyles;
2355 uno::Sequence< rtl::OUString> aStyles(1);
2356 aStyles[0] = sTemplate;
2357 xParaStyles->replaceByIndex(0, uno::makeAny(aStyles));
2359 if(bHyperlinks || sChapterNoSeparator.getLength())
2361 uno::Reference< container::XIndexReplace> xLevelFormats;
2362 m_xTOC->getPropertyValue(rPropNameSupplier.GetName(PROP_LEVEL_FORMAT)) >>= xLevelFormats;
2363 sal_Int32 nLevelCount = xLevelFormats->getCount();
2364 //start with level 1, 0 is the header level
2365 for( sal_Int32 nLevel = 1; nLevel < nLevelCount; ++nLevel)
2367 uno::Sequence< beans::PropertyValues > aLevel;
2368 xLevelFormats->getByIndex( nLevel ) >>= aLevel;
2369 //create a copy of the level and add two new entries - hyperlink start and end
2370 bool bChapterNoSeparator = sChapterNoSeparator.getLength() > 0;
2371 sal_Int32 nAdd = (bHyperlinks && bChapterNoSeparator) ? 4 : 2;
2372 uno::Sequence< beans::PropertyValues > aNewLevel( aLevel.getLength() + nAdd);
2373 beans::PropertyValues* pNewLevel = aNewLevel.getArray();
2374 if( bHyperlinks )
2376 beans::PropertyValues aHyperlink(1);
2377 aHyperlink[0].Name = rPropNameSupplier.GetName( PROP_TOKEN_TYPE );
2378 aHyperlink[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_HYPERLINK_START );
2379 pNewLevel[0] = aHyperlink;
2380 aHyperlink[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_HYPERLINK_END );
2381 pNewLevel[aNewLevel.getLength() -1] = aHyperlink;
2383 if( bChapterNoSeparator )
2385 beans::PropertyValues aChapterNo(2);
2386 aChapterNo[0].Name = rPropNameSupplier.GetName( PROP_TOKEN_TYPE );
2387 aChapterNo[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_CHAPTER_INFO );
2388 aChapterNo[1].Name = rPropNameSupplier.GetName( PROP_CHAPTER_FORMAT );
2389 //todo: is ChapterFormat::Number correct?
2390 aChapterNo[1].Value <<= (sal_Int16)text::ChapterFormat::NUMBER;
2391 pNewLevel[aNewLevel.getLength() - (bHyperlinks ? 4 : 2) ] = aChapterNo;
2393 beans::PropertyValues aChapterSeparator(2);
2394 aChapterSeparator[0].Name = rPropNameSupplier.GetName( PROP_TOKEN_TYPE );
2395 aChapterSeparator[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_TEXT );
2396 aChapterSeparator[1].Name = rPropNameSupplier.GetName( PROP_TEXT );
2397 aChapterSeparator[1].Value <<= sChapterNoSeparator;
2398 pNewLevel[aNewLevel.getLength() - (bHyperlinks ? 3 : 1)] = aChapterSeparator;
2400 //copy the 'old' entries except the last (page no)
2401 for( sal_Int32 nToken = 0; nToken < aLevel.getLength() - 1; ++nToken)
2403 pNewLevel[nToken + 1] = aLevel[nToken];
2405 //copy page no entry (last or last but one depending on bHyperlinks
2406 sal_Int32 nPageNo = aNewLevel.getLength() - (bHyperlinks ? 2 : 3);
2407 pNewLevel[nPageNo] = aLevel[aLevel.getLength() - 1];
2409 xLevelFormats->replaceByIndex( nLevel, uno::makeAny( aNewLevel ) );
2414 break;
2415 case FIELD_TC :
2417 m_xTC = uno::Reference< beans::XPropertySet >(
2418 m_xTextFactory->createInstance(
2419 ::rtl::OUString::createFromAscii(aIt->second.cFieldServiceName)),
2420 uno::UNO_QUERY_THROW);
2421 ::rtl::OUString sTCText = lcl_ExtractParameter(rCommand, sizeof(" TC") );
2422 if( sTCText.getLength())
2423 m_xTC->setPropertyValue(rPropNameSupplier.GetName(PROP_ALTERNATIVE_TEXT),
2424 uno::makeAny(sTCText));
2425 ::rtl::OUString sValue;
2426 // \f TC entry in doc with multiple tables
2427 // if( lcl_FindInCommand( rCommand, 'f', sValue ))
2428 // {
2429 // todo: unsupported
2430 // }
2431 if( lcl_FindInCommand( rCommand, 'l', sValue ))
2432 // \l Outline Level
2434 sal_Int32 nLevel = sValue.toInt32();
2435 if( sValue.getLength() && nLevel >= 0 && nLevel <= 10 )
2436 m_xTC->setPropertyValue(rPropNameSupplier.GetName(PROP_LEVEL), uno::makeAny( nLevel ));
2438 // if( lcl_FindInCommand( rCommand, 'n', sValue ))
2439 // \n Suppress page numbers
2440 // {
2441 //todo: unsupported feature
2442 // }
2444 break;
2447 m_xTextField = uno::Reference< text::XTextField >( xFieldInterface, uno::UNO_QUERY );
2449 catch( uno::Exception& )
2455 /*-- 11.09.2006 13:16:35---------------------------------------------------
2457 -----------------------------------------------------------------------*/
2458 /*bool DomainMapper_Impl::IsFieldAvailable() const
2460 return m_xTextField.is() || m_xTOC.is() || m_xTC.is() || m_sHyperlinkURL.getLength();
2463 /*-- 14.09.2006 12:46:52---------------------------------------------------
2465 -----------------------------------------------------------------------*/
2466 void DomainMapper_Impl::GetCurrentLocale(lang::Locale& rLocale)
2468 PropertyMapPtr pTopContext = GetTopContext();
2469 PropertyDefinition aCharLocale( PROP_CHAR_LOCALE, true );
2470 PropertyMap::iterator aLocaleIter = pTopContext->find( aCharLocale );
2471 if( aLocaleIter != pTopContext->end())
2472 aLocaleIter->second >>= rLocale;
2473 else
2475 PropertyMapPtr pParaContext = GetTopContextOfType(CONTEXT_PARAGRAPH);
2476 aLocaleIter = pParaContext->find(aCharLocale);
2477 if( aLocaleIter != pParaContext->end())
2479 aLocaleIter->second >>= rLocale;
2484 /*-- 14.09.2006 12:52:58---------------------------------------------------
2485 extract the number format from the command and apply the resulting number
2486 format to the XPropertySet
2487 -----------------------------------------------------------------------*/
2488 void DomainMapper_Impl::SetNumberFormat( const ::rtl::OUString& rCommand,
2489 uno::Reference< beans::XPropertySet >& xPropertySet )
2491 OUString sFormatString = lcl_ParseFormat( rCommand );
2492 // find \h - hijri/luna calendar todo: what about saka/era calendar?
2493 bool bHijri = 0 < rCommand.indexOf( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\\h ")));
2494 lang::Locale aUSLocale;
2495 aUSLocale.Language = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("en"));
2496 aUSLocale.Country = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("US"));
2498 //determine current locale - todo: is it necessary to initialize this locale?
2499 lang::Locale aCurrentLocale = aUSLocale;
2500 GetCurrentLocale( aCurrentLocale );
2501 ::rtl::OUString sFormat = ConversionHelper::ConvertMSFormatStringToSO( sFormatString, aCurrentLocale, bHijri);
2503 //get the number formatter and convert the string to a format value
2506 uno::Reference< util::XNumberFormatsSupplier > xNumberSupplier( m_xTextDocument, uno::UNO_QUERY_THROW );
2507 long nKey = xNumberSupplier->getNumberFormats()->addNewConverted( sFormat, aUSLocale, aCurrentLocale );
2508 xPropertySet->setPropertyValue(
2509 PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_NUMBER_FORMAT),
2510 uno::makeAny( nKey ));
2512 catch(const uno::Exception&)
2517 /*-- 15.09.2006 15:10:20---------------------------------------------------
2519 -----------------------------------------------------------------------*/
2520 uno::Reference< beans::XPropertySet > DomainMapper_Impl::FindOrCreateFieldMaster(
2521 const sal_Char* pFieldMasterService, const ::rtl::OUString& rFieldMasterName )
2522 throw(::com::sun::star::uno::Exception)
2524 // query master, create if not available
2525 uno::Reference< text::XTextFieldsSupplier > xFieldsSupplier( GetTextDocument(), uno::UNO_QUERY );
2526 uno::Reference< container::XNameAccess > xFieldMasterAccess = xFieldsSupplier->getTextFieldMasters();
2527 uno::Reference< beans::XPropertySet > xMaster;
2528 ::rtl::OUString sFieldMasterService( ::rtl::OUString::createFromAscii(pFieldMasterService) );
2529 ::rtl::OUStringBuffer aFieldMasterName;
2530 aFieldMasterName.appendAscii( pFieldMasterService );
2531 aFieldMasterName.append(sal_Unicode('.'));
2532 aFieldMasterName.append(rFieldMasterName);
2533 ::rtl::OUString sFieldMasterName = aFieldMasterName.makeStringAndClear();
2534 if(xFieldMasterAccess->hasByName(sFieldMasterName))
2536 //get the master
2537 xMaster = uno::Reference< beans::XPropertySet >(xFieldMasterAccess->getByName(sFieldMasterName),
2538 uno::UNO_QUERY_THROW);
2540 else
2542 //create the master
2543 xMaster = uno::Reference< beans::XPropertySet >(
2544 m_xTextFactory->createInstance(sFieldMasterService), uno::UNO_QUERY_THROW);
2545 //set the master's name
2546 // sal_Int32 nIndex = rtl_str_indexOfStr( pFieldMasterService, "Database" );
2547 // if( nIndex < 0 )
2548 xMaster->setPropertyValue(
2549 PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_NAME),
2550 uno::makeAny(rFieldMasterName));
2551 // else
2552 // {
2553 // xMaster->setPropertyValue(
2554 // PropertyNameSupplier::GetPropertyNameSupplier().GetName(PROP_DATA_COLUMN_NAME),
2555 // uno::makeAny(rFieldMasterName));
2556 // }
2558 return xMaster;
2561 /*-- 29.01.2007 11:33:10---------------------------------------------------
2562 //field context starts with a 0x13
2563 -----------------------------------------------------------------------*/
2564 void DomainMapper_Impl::PushFieldContext()
2566 uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend;
2567 //insert a dummy char to make sure the start range doesn't move together with the to-be-appended text
2568 xTextAppend->appendTextPortion(::rtl::OUString( '-' ), uno::Sequence< beans::PropertyValue >() );
2569 uno::Reference< text::XTextCursor > xCrsr = xTextAppend->createTextCursorByRange( xTextAppend->getEnd() );
2570 xCrsr->goLeft( 1, false );
2571 m_aFieldStack.push( FieldContextPtr( new FieldContext( xCrsr->getStart() ) ) );
2573 /*-- 29.01.2007 11:33:13---------------------------------------------------
2574 //the current field context waits for the completion of the command
2575 -----------------------------------------------------------------------*/
2576 bool DomainMapper_Impl::IsOpenFieldCommand() const
2578 return !m_aFieldStack.empty() && !m_aFieldStack.top()->IsCommandCompleted();
2580 /*-- 29.01.2007 11:33:13---------------------------------------------------
2581 //the current field context waits for the completion of the command
2582 -----------------------------------------------------------------------*/
2583 bool DomainMapper_Impl::IsOpenField() const
2585 return !m_aFieldStack.empty();
2587 /*-- 29.01.2007 11:49:13---------------------------------------------------
2589 -----------------------------------------------------------------------*/
2590 FieldContext::FieldContext(uno::Reference< text::XTextRange > xStart) :
2591 m_bFieldCommandCompleted( false )
2592 ,m_xStartRange( xStart )
2595 /*-- 29.01.2007 11:48:44---------------------------------------------------
2597 -----------------------------------------------------------------------*/
2598 FieldContext::~FieldContext()
2601 /*-- 29.01.2007 11:48:45---------------------------------------------------
2603 -----------------------------------------------------------------------*/
2604 void FieldContext::AppendCommand(const ::rtl::OUString& rPart)
2606 m_sCommand += rPart;
2608 /*-- 29.01.2007 11:33:15---------------------------------------------------
2609 //collect the pieces of the command
2610 -----------------------------------------------------------------------*/
2611 void DomainMapper_Impl::AppendFieldCommand(::rtl::OUString& rPartOfCommand)
2613 FieldContextPtr pContext = m_aFieldStack.top();
2614 OSL_ENSURE( pContext.get(), "no field context available");
2615 if( pContext.get() )
2617 pContext->AppendCommand( rPartOfCommand );
2620 /*-- 13.12.2007 11:45:43---------------------------------------------------
2622 -----------------------------------------------------------------------*/
2623 typedef std::multimap < sal_Int32, ::rtl::OUString > TOCStyleMap;
2624 /*-- 29.01.2007 11:33:16---------------------------------------------------
2625 //the field command has to be closed (0x14 appeared)
2626 -----------------------------------------------------------------------*/
2627 void DomainMapper_Impl::CloseFieldCommand()
2629 FieldContextPtr pContext = m_aFieldStack.top();
2630 OSL_ENSURE( pContext.get(), "no field context available");
2631 if( pContext.get() )
2633 static FieldConversionMap_t aFieldConversionMap;
2634 static bool bFilled = false;
2635 m_bSetUserFieldContent = false;
2636 if(!bFilled)
2638 static const FieldConversion aFields[] =
2640 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ADDRESSBLOCK")), "", "", FIELD_ADDRESSBLOCK },
2641 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ADVANCE")), "", "", FIELD_ADVANCE },
2642 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ASK")), "SetExpression", "SetExpression", FIELD_ASK },
2643 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AUTONUM")), "SetExpression", "SetExpression", FIELD_AUTONUM },
2644 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AUTONUMLGL")), "SetExpression", "SetExpression", FIELD_AUTONUMLGL },
2645 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AUTONUMOUT")), "SetExpression", "SetExpression", FIELD_AUTONUMOUT },
2646 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AUTHOR")), "Author", "", FIELD_AUTHOR },
2647 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DATE")), "DateTime", "", FIELD_DATE },
2648 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("COMMENTS")), "DocInfo.Description", "", FIELD_COMMENTS },
2649 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CREATEDATE")), "DocInfo.CreateDateTime", "", FIELD_CREATEDATE },
2650 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DOCPROPERTY")), "", "", FIELD_DOCPROPERTY },
2651 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DOCVARIABLE")), "User", "", FIELD_DOCVARIABLE },
2652 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EDITTIME")), "DocInfo.EditTime", "", FIELD_EDITTIME },
2653 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FILLIN")), "Input", "", FIELD_FILLIN },
2654 {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FILENAME")), "FileName", "", FIELD_FILENAME },
2655 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FILESIZE")), "", "", FIELD_FILESIZE },
2656 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FORMULA")), "", "", FIELD_FORMULA
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},
2694 // {::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("")), "", "", FIELD_},
2697 size_t nConversions = sizeof(aFields)/sizeof(FieldConversion);
2698 for( size_t nConversion = 0; nConversion < nConversions; ++nConversion)
2700 aFieldConversionMap.insert( FieldConversionMap_t::value_type(
2701 aFields[nConversion].sWordCommand,
2702 aFields[nConversion] ));
2705 bFilled = true;
2709 uno::Reference< uno::XInterface > xFieldInterface;
2710 //at first determine the field type - erase leading and trailing whitespaces
2711 ::rtl::OUString sCommand( pContext->GetCommand().trim() );
2712 sal_Int32 nSpaceIndex = sCommand.indexOf( ' ' );
2713 if( 0 <= nSpaceIndex )
2714 sCommand = sCommand.copy( 0, nSpaceIndex );
2716 FieldConversionMap_t::iterator aIt = aFieldConversionMap.find(sCommand);
2717 if(aIt != aFieldConversionMap.end())
2719 uno::Reference< beans::XPropertySet > xFieldProperties;
2720 if( FIELD_HYPERLINK != aIt->second.eFieldId &&
2721 FIELD_DOCPROPERTY != aIt->second.eFieldId &&
2722 FIELD_TOC != aIt->second.eFieldId &&
2723 FIELD_TC != aIt->second.eFieldId)
2725 //add the service prefix
2726 OUString sServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField."));
2727 sServiceName += ::rtl::OUString::createFromAscii(aIt->second.cFieldServiceName );
2728 xFieldInterface = m_xTextFactory->createInstance(sServiceName);
2729 xFieldProperties = uno::Reference< beans::XPropertySet >( xFieldInterface, uno::UNO_QUERY_THROW);
2731 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
2732 switch( aIt->second.eFieldId )
2734 case FIELD_ADDRESSBLOCK: break;
2735 case FIELD_ADVANCE : break;
2736 case FIELD_ASK :
2738 //doesn the command contain a variable name?
2739 ::rtl::OUString sVariable, sHint;
2741 sVariable = lcl_ExctractAskVariableAndHint( pContext->GetCommand(), sHint );
2742 if(sVariable.getLength())
2744 // determine field master name
2745 uno::Reference< beans::XPropertySet > xMaster = FindOrCreateFieldMaster(
2746 "com.sun.star.text.FieldMaster.SetExpression", sVariable );
2748 // attach the master to the field
2749 uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
2750 xDependentField->attachTextFieldMaster( xMaster );
2752 // set input flag at the field
2753 xFieldProperties->setPropertyValue(
2754 rPropNameSupplier.GetName(PROP_IS_INPUT), uno::makeAny( true ));
2755 // set the prompt
2756 xFieldProperties->setPropertyValue(
2757 rPropNameSupplier.GetName(PROP_HINT),
2758 uno::makeAny( sHint ));
2760 else
2762 //don't insert the field
2763 //todo: maybe import a 'normal' input field here?
2764 xFieldInterface = 0;
2767 break;
2768 case FIELD_AUTONUM :
2769 case FIELD_AUTONUMLGL :
2770 case FIELD_AUTONUMOUT :
2772 //create a sequence field master "AutoNr"
2773 uno::Reference< beans::XPropertySet > xMaster = FindOrCreateFieldMaster(
2774 "com.sun.star.text.FieldMaster.SetExpression",
2775 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("AutoNr") ));
2777 xMaster->setPropertyValue( rPropNameSupplier.GetName(PROP_SUB_TYPE),
2778 uno::makeAny(text::SetVariableType::SEQUENCE));
2780 //apply the numbering type
2781 xFieldProperties->setPropertyValue(
2782 rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
2783 uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) ));
2784 // attach the master to the field
2785 uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
2786 xDependentField->attachTextFieldMaster( xMaster );
2788 break;
2789 case FIELD_AUTHOR :
2791 xFieldProperties->setPropertyValue( rPropNameSupplier.GetName(PROP_FULL_NAME), uno::makeAny( true ));
2792 ::rtl::OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" AUTHOR") );
2793 if(sParam.getLength())
2795 xFieldProperties->setPropertyValue(
2796 rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
2797 //PROP_CURRENT_PRESENTATION is set later anyway
2800 break;
2801 case FIELD_DATE:
2803 //not fixed,
2804 xFieldProperties->setPropertyValue(
2805 rPropNameSupplier.GetName(PROP_IS_FIXED),
2806 uno::makeAny( false ));
2807 xFieldProperties->setPropertyValue(
2808 rPropNameSupplier.GetName(PROP_IS_DATE),
2809 uno::makeAny( true ));
2810 SetNumberFormat( pContext->GetCommand(), xFieldProperties );
2812 break;
2813 case FIELD_COMMENTS :
2815 ::rtl::OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" COMMENTS") );
2816 if(sParam.getLength())
2818 xFieldProperties->setPropertyValue(
2819 rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
2820 //PROP_CURRENT_PRESENTATION is set later anyway
2823 break;
2824 case FIELD_CREATEDATE :
2826 SetNumberFormat( pContext->GetCommand(), xFieldProperties );
2828 break;
2829 case FIELD_DOCPROPERTY :
2831 //some docproperties should be imported as document statistic fields, some as DocInfo fields
2832 //others should be user fields
2833 ::rtl::OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" DOCPROPERTY") );
2834 if(sParam.getLength())
2836 #define SET_ARABIC 0x01
2837 #define SET_FULL_NAME 0x02
2838 struct DocPropertyMap
2840 const sal_Char* pDocPropertyName;
2841 const sal_Char* pServiceName;
2842 sal_uInt8 nFlags;
2844 static const DocPropertyMap aDocProperties[] =
2846 {"Author", "Author", SET_FULL_NAME},
2847 {"CreateTime", "DocInfo.CreateDateTime", 0},
2848 {"Characters", "CharacterCount", SET_ARABIC},
2849 {"Comments", "DocInfo.Description", 0},
2850 {"Keywords", "DocInfo.KeyWords", 0},
2851 {"LastPrinted", "DocInfo.PrintDateTime", 0},
2852 {"LastSavedBy", "DocInfo.ChangeAuthor", 0},
2853 {"LastSavedTime", "DocInfo.ChangeDateTime", 0},
2854 {"Paragraphs", "ParagraphCount", SET_ARABIC},
2855 {"RevisionNumber", "DocInfo.Revision", 0},
2856 {"Subject", "DocInfo.Subject", 0},
2857 {"Template", "TemplateName", 0},
2858 {"Title", "DocInfo.Title", 0},
2859 {"TotalEditingTime", "DocInfo.EditTime", 9},
2860 {"Words", "WordCount", SET_ARABIC}
2862 //other available DocProperties:
2863 //Bytes, Category, CharactersWithSpaces, Company
2864 //HyperlinkBase,
2865 //Lines, Manager, NameofApplication, ODMADocId, Pages,
2866 //Security,
2868 //search for a field mapping
2869 ::rtl::OUString sFieldServiceName;
2870 sal_uInt16 nMap = 0;
2871 for( ; nMap < sizeof(aDocProperties) / sizeof(DocPropertyMap); ++nMap )
2873 if(sParam.equalsAscii(aDocProperties[nMap].pDocPropertyName))
2875 sFieldServiceName = ::rtl::OUString::createFromAscii(aDocProperties[nMap].pServiceName);
2876 break;
2879 ::rtl::OUString sServiceName(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField."));
2880 bool bIsCustomField = false;
2881 if(!sFieldServiceName.getLength())
2883 //create a custom property field
2884 sServiceName += ::rtl::OUString::createFromAscii("DocInfo.Custom");
2885 bIsCustomField = true;
2887 else
2889 sServiceName += sFieldServiceName;
2891 xFieldInterface = m_xTextFactory->createInstance(sServiceName);
2892 xFieldProperties = uno::Reference< beans::XPropertySet >( xFieldInterface, uno::UNO_QUERY_THROW);
2893 if( bIsCustomField )
2894 xFieldProperties->setPropertyValue(
2895 rPropNameSupplier.GetName(PROP_NAME), uno::makeAny( sParam ));
2896 else
2898 if(0 != (aDocProperties[nMap].nFlags & SET_ARABIC))
2899 xFieldProperties->setPropertyValue(
2900 rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
2901 uno::makeAny( style::NumberingType::ARABIC ));
2902 else if(0 != (aDocProperties[nMap].nFlags & SET_FULL_NAME))
2903 xFieldProperties->setPropertyValue(
2904 rPropNameSupplier.GetName(PROP_FULL_NAME), uno::makeAny( true ));
2908 #undef SET_ARABIC
2909 #undef SET_FULL_NAME
2910 break;
2911 case FIELD_DOCVARIABLE :
2913 ::rtl::OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" DOCVARIABLE") );
2914 //create a user field and type
2915 uno::Reference< beans::XPropertySet > xMaster =
2916 FindOrCreateFieldMaster( "com.sun.star.text.FieldMaster.User", sParam );
2917 uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
2918 xDependentField->attachTextFieldMaster( xMaster );
2919 m_bSetUserFieldContent = true;
2921 break;
2922 case FIELD_EDITTIME :
2923 //it's a numbering type, no number format! SetNumberFormat( pContext->GetCommand(), xFieldProperties );
2924 break;
2925 case FIELD_FILLIN :
2927 sal_Int32 nIndex = 0;
2928 xFieldProperties->setPropertyValue(
2929 rPropNameSupplier.GetName(PROP_HINT), uno::makeAny( pContext->GetCommand().getToken( 1, '\"', nIndex)));
2931 break;
2932 case FIELD_FILENAME:
2934 sal_Int32 nNumberingTypeIndex = pContext->GetCommand().indexOf( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("\\p")));
2935 xFieldProperties->setPropertyValue(
2936 rPropNameSupplier.GetName(PROP_FILE_FORMAT),
2937 uno::makeAny( nNumberingTypeIndex > 0 ? text::FilenameDisplayFormat::FULL : text::FilenameDisplayFormat::NAME ));
2939 break;
2940 case FIELD_FILESIZE : break;
2941 case FIELD_FORMULA : break;
2942 case FIELD_GOTOBUTTON : break;
2943 case FIELD_HYPERLINK:
2945 sal_Int32 nStartQuote = pContext->GetCommand().indexOf( '\"' );
2946 sal_Int32 nEndQuote = nStartQuote < pContext->GetCommand().getLength() + 1 ? pContext->GetCommand().indexOf( '\"', nStartQuote + 1) : -1;
2947 if( nEndQuote > 0)
2948 pContext->SetHyperlinkURL( pContext->GetCommand().copy(nStartQuote + 1, nEndQuote - nStartQuote - 1) );
2950 break;
2951 case FIELD_IF : break;
2952 case FIELD_INFO : break;
2953 case FIELD_INCLUDEPICTURE: break;
2954 case FIELD_KEYWORDS :
2956 ::rtl::OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" KEYWORDS") );
2957 if(sParam.getLength())
2959 xFieldProperties->setPropertyValue(
2960 rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
2961 //PROP_CURRENT_PRESENTATION is set later anyway
2964 break;
2965 case FIELD_LASTSAVEDBY : break;
2966 case FIELD_MACROBUTTON:
2968 //extract macro name
2969 sal_Int32 nIndex = sizeof(" MACROBUTTON ");
2970 ::rtl::OUString sMacro = pContext->GetCommand().getToken( 0, ' ', nIndex);
2971 xFieldProperties->setPropertyValue(
2972 rPropNameSupplier.GetName(PROP_MACRO_NAME), uno::makeAny( sMacro ));
2974 //extract quick help text
2975 if( pContext->GetCommand().getLength() > nIndex + 1)
2977 xFieldProperties->setPropertyValue(
2978 rPropNameSupplier.GetName(PROP_HINT),
2979 uno::makeAny( pContext->GetCommand().copy( nIndex )));
2982 break;
2983 case FIELD_MERGEFIELD :
2985 //todo: create a database field and fieldmaster pointing to a column, only
2986 ::rtl::OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" MERGEFIELD") );
2987 //create a user field and type
2988 uno::Reference< beans::XPropertySet > xMaster =
2989 FindOrCreateFieldMaster( "com.sun.star.text.FieldMaster.Database", sParam );
2991 // xFieldProperties->setPropertyValue(
2992 // ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FieldCode")),
2993 // uno::makeAny( pContext->GetCommand().copy( nIndex + 1 )));
2994 uno::Reference< text::XDependentTextField > xDependentField( xFieldInterface, uno::UNO_QUERY_THROW );
2995 xDependentField->attachTextFieldMaster( xMaster );
2996 m_bSetUserFieldContent = true;
2998 break;
2999 case FIELD_MERGEREC : break;
3000 case FIELD_MERGESEQ : break;
3001 case FIELD_NEXT : break;
3002 case FIELD_NEXTIF : break;
3003 case FIELD_PAGE :
3004 xFieldProperties->setPropertyValue(
3005 rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
3006 uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) ));
3007 xFieldProperties->setPropertyValue(
3008 rPropNameSupplier.GetName(PROP_SUB_TYPE),
3009 uno::makeAny( text::PageNumberType_CURRENT ));
3011 break;
3012 case FIELD_REF:
3014 ::rtl::OUString sBookmark = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" REF") );
3015 xFieldProperties->setPropertyValue(
3016 rPropNameSupplier.GetName(PROP_REFERENCE_FIELD_SOURCE),
3017 uno::makeAny( sal_Int16(text::ReferenceFieldSource::BOOKMARK)) );
3018 xFieldProperties->setPropertyValue(
3019 rPropNameSupplier.GetName(PROP_SOURCE_NAME),
3020 uno::makeAny( sBookmark) );
3021 sal_Int16 nFieldPart = text::ReferenceFieldPart::TEXT;
3022 ::rtl::OUString sValue;
3023 if( lcl_FindInCommand( pContext->GetCommand(), 'p', sValue ))
3025 //above-below
3026 nFieldPart = text::ReferenceFieldPart::UP_DOWN;
3028 xFieldProperties->setPropertyValue(
3029 rPropNameSupplier.GetName( PROP_REFERENCE_FIELD_PART ), uno::makeAny( nFieldPart ));
3031 break;
3032 case FIELD_REVNUM : break;
3033 case FIELD_SAVEDATE :
3034 SetNumberFormat( pContext->GetCommand(), xFieldProperties );
3035 break;
3036 case FIELD_SECTION : break;
3037 case FIELD_SECTIONPAGES : break;
3038 case FIELD_SEQ : break;
3039 case FIELD_SET : break;
3040 case FIELD_SKIPIF : break;
3041 case FIELD_STYLEREF : break;
3042 case FIELD_SUBJECT :
3044 ::rtl::OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" SUBJECT") );
3045 if(sParam.getLength())
3047 xFieldProperties->setPropertyValue(
3048 rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
3049 //PROP_CURRENT_PRESENTATION is set later anyway
3052 break;
3053 case FIELD_SYMBOL : break;
3054 case FIELD_TEMPLATE: break;
3055 case FIELD_TIME :
3056 SetNumberFormat( pContext->GetCommand(), xFieldProperties );
3057 break;
3058 case FIELD_TITLE :
3060 ::rtl::OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" TITLE") );
3061 if(sParam.getLength())
3063 xFieldProperties->setPropertyValue(
3064 rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
3065 //PROP_CURRENT_PRESENTATION is set later anyway
3068 break;
3069 case FIELD_USERINITIALS:
3071 xFieldProperties->setPropertyValue(
3072 rPropNameSupplier.GetName(PROP_USER_DATA_TYPE), uno::makeAny( text::UserDataPart::SHORTCUT ));
3073 //todo: if initials are provided - set them as fixed content
3074 ::rtl::OUString sParam = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" USERINITIALS") );
3075 if(sParam.getLength())
3077 xFieldProperties->setPropertyValue(
3078 rPropNameSupplier.GetName( PROP_IS_FIXED ), uno::makeAny( true ));
3079 //PROP_CURRENT_PRESENTATION is set later anyway
3082 break;
3083 case FIELD_USERADDRESS : //todo: user address collects street, city ...
3084 break;
3085 case FIELD_USERNAME : //todo: user name is firstname + lastname
3086 break;
3087 case FIELD_TOC:
3089 ::rtl::OUString sValue;
3090 bool bTableOfFigures = false;
3091 bool bHyperlinks = false;
3092 bool bFromOutline = false;
3093 bool bFromEntries = false;
3094 sal_Int16 nMaxLevel = 10;
3095 ::rtl::OUString sTemplate;
3096 ::rtl::OUString sChapterNoSeparator;
3097 // \a Builds a table of figures but does not include the captions's label and number
3098 if( lcl_FindInCommand( pContext->GetCommand(), 'a', sValue ))
3099 { //make it a table of figures
3100 bTableOfFigures = true;
3102 // \b Uses a bookmark to specify area of document from which to build table of contents
3103 // if( lcl_FindInCommand( pContext->GetCommand(), 'b', sValue ))
3104 // { //todo: sValue contains the bookmark name - unsupported feature
3105 // }
3106 if( lcl_FindInCommand( pContext->GetCommand(), 'c', sValue ))
3107 // \c Builds a table of figures of the given label
3109 //todo: sValue contains the label's name
3110 bTableOfFigures = true;
3112 // \d Defines the separator between sequence and page numbers
3113 if( lcl_FindInCommand( pContext->GetCommand(), 'd', sValue ))
3115 //todo: insert the chapter number into each level and insert the separator additionally
3116 sChapterNoSeparator = sValue;
3118 // \f Builds a table of contents using TC entries instead of outline levels
3119 if( lcl_FindInCommand( pContext->GetCommand(), 'f', sValue ))
3121 //todo: sValue can contain a TOC entry identifier - use unclear
3122 bFromEntries = true;
3124 // \h Hyperlinks the entries and page numbers within the table of contents
3125 if( lcl_FindInCommand( pContext->GetCommand(), 'h', sValue ))
3127 //todo: make all entries to hyperlinks
3128 bHyperlinks = true;
3130 // \l Defines the TC entries field level used to build a table of contents
3131 // if( lcl_FindInCommand( pContext->GetCommand(), 'l', sValue ))
3132 // {
3133 //todo: entries can only be included completely
3134 // }
3135 // \n Builds a table of contents or a range of entries, sucah as “1-9”, in a table of contents without page numbers
3136 // if( lcl_FindInCommand( pContext->GetCommand(), 'n', sValue ))
3137 // {
3138 //todo: what does the description mean?
3139 // }
3140 // \o Builds a table of contents by using outline levels instead of TC entries
3141 if( lcl_FindInCommand( pContext->GetCommand(), 'o', sValue ))
3143 bFromOutline = true;
3144 UniString sParam( sValue );
3145 xub_StrLen nIndex = 0;
3146 sParam.GetToken( 0, '-', nIndex );
3147 nMaxLevel = sal_Int16( sParam.Copy( nIndex ).ToInt32( ) );
3149 // \p Defines the separator between the table entry and its page number
3150 if( lcl_FindInCommand( pContext->GetCommand(), 'p', sValue ))
3152 // \s Builds a table of contents by using a sequence type
3153 if( lcl_FindInCommand( pContext->GetCommand(), 's', sValue ))
3155 // \t Builds a table of contents by using style names other than the standard outline styles
3156 if( lcl_FindInCommand( pContext->GetCommand(), 't', sValue ))
3158 sal_Int32 nPos = 0;
3159 ::rtl::OUString sToken = sValue.getToken( 1, '"', nPos);
3160 sTemplate = sToken.getLength() ? sToken : sValue;
3162 // \u Builds a table of contents by using the applied paragraph outline level
3163 if( lcl_FindInCommand( pContext->GetCommand(), 'u', sValue ))
3165 bFromOutline = true;
3166 //todo: what doesn 'the applied paragraph outline level' refer to?
3168 // \w Preserve tab characters within table entries
3169 // if( lcl_FindInCommand( pContext->GetCommand(), 'w', sValue ))
3170 // {
3171 //todo: not supported
3172 // }
3173 // \x Preserve newline characters within table entries
3174 // if( lcl_FindInCommand( pContext->GetCommand(), 'x', sValue ))
3175 // {
3176 //todo: unsupported
3177 // }
3178 // \z Hides page numbers within the table of contens when shown in Web Layout View
3179 // if( lcl_FindInCommand( pContext->GetCommand(), 'z', sValue ))
3180 // { //todo: unsupported feature }
3182 //if there's no option then it should be created from outline
3183 if( !bFromOutline && !bFromEntries && !sTemplate.getLength() )
3184 bFromOutline = true;
3186 uno::Reference< beans::XPropertySet > xTOC(
3187 m_xTextFactory->createInstance(
3188 bTableOfFigures ?
3189 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.IllustrationsIndex")) :
3190 ::rtl::OUString::createFromAscii(aIt->second.cFieldServiceName)),
3191 uno::UNO_QUERY_THROW);
3192 xTOC->setPropertyValue(rPropNameSupplier.GetName( PROP_TITLE ), uno::makeAny(::rtl::OUString()));
3193 if( !bTableOfFigures )
3195 xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_LEVEL ), uno::makeAny( nMaxLevel ) );
3196 xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_CREATE_FROM_OUTLINE ), uno::makeAny( bFromOutline ));
3197 xTOC->setPropertyValue( rPropNameSupplier.GetName( PROP_CREATE_FROM_MARKS ), uno::makeAny( bFromEntries ));
3198 if( sTemplate.getLength() )
3200 //the string contains comma separated the names and related levels
3201 //like: "Heading 1,1,Heading 2,2"
3202 TOCStyleMap aMap;
3203 sal_Int32 nLevel;
3204 sal_Int32 nPosition = 0;
3205 while( nPosition >= 0)
3207 ::rtl::OUString sStyleName = sTemplate.getToken( 0, ',', nPosition );
3208 //empty tokens should be skipped
3209 while( !sStyleName.getLength() && nPosition > 0 )
3210 sStyleName = sTemplate.getToken( 0, ',', nPosition );
3211 nLevel = sTemplate.getToken( 0, ',', nPosition ).toInt32();
3212 if( !nLevel )
3213 nLevel = 1;
3214 if( sStyleName.getLength() )
3215 aMap.insert( TOCStyleMap::value_type(nLevel, sStyleName) );
3217 uno::Reference< container::XIndexReplace> xParaStyles;
3218 xTOC->getPropertyValue(rPropNameSupplier.GetName(PROP_LEVEL_PARAGRAPH_STYLES)) >>= xParaStyles;
3219 for( nLevel = 1; nLevel < 10; ++nLevel)
3221 sal_Int32 nLevelCount = aMap.count( nLevel );
3222 if( nLevelCount )
3224 TOCStyleMap::iterator aTOCStyleIter = aMap.find( nLevel );
3226 uno::Sequence< rtl::OUString> aStyles( nLevelCount );
3227 for ( sal_Int32 nStyle = 0; nStyle < nLevelCount; ++nStyle, ++aTOCStyleIter )
3229 aStyles[nStyle] = aTOCStyleIter->second;
3231 xParaStyles->replaceByIndex(nLevel - 1, uno::makeAny(aStyles));
3234 xTOC->setPropertyValue(rPropNameSupplier.GetName(PROP_CREATE_FROM_LEVEL_PARAGRAPH_STYLES), uno::makeAny( true ));
3237 if(bHyperlinks || sChapterNoSeparator.getLength())
3239 uno::Reference< container::XIndexReplace> xLevelFormats;
3240 xTOC->getPropertyValue(rPropNameSupplier.GetName(PROP_LEVEL_FORMAT)) >>= xLevelFormats;
3241 sal_Int32 nLevelCount = xLevelFormats->getCount();
3242 //start with level 1, 0 is the header level
3243 for( sal_Int32 nLevel = 1; nLevel < nLevelCount; ++nLevel)
3245 uno::Sequence< beans::PropertyValues > aLevel;
3246 xLevelFormats->getByIndex( nLevel ) >>= aLevel;
3247 //create a copy of the level and add two new entries - hyperlink start and end
3248 bool bChapterNoSeparator = sChapterNoSeparator.getLength() > 0;
3249 sal_Int32 nAdd = (bHyperlinks && bChapterNoSeparator) ? 4 : 2;
3250 uno::Sequence< beans::PropertyValues > aNewLevel( aLevel.getLength() + nAdd);
3251 beans::PropertyValues* pNewLevel = aNewLevel.getArray();
3252 if( bHyperlinks )
3254 beans::PropertyValues aHyperlink(1);
3255 aHyperlink[0].Name = rPropNameSupplier.GetName( PROP_TOKEN_TYPE );
3256 aHyperlink[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_HYPERLINK_START );
3257 pNewLevel[0] = aHyperlink;
3258 aHyperlink[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_HYPERLINK_END );
3259 pNewLevel[aNewLevel.getLength() -1] = aHyperlink;
3261 if( bChapterNoSeparator )
3263 beans::PropertyValues aChapterNo(2);
3264 aChapterNo[0].Name = rPropNameSupplier.GetName( PROP_TOKEN_TYPE );
3265 aChapterNo[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_CHAPTER_INFO );
3266 aChapterNo[1].Name = rPropNameSupplier.GetName( PROP_CHAPTER_FORMAT );
3267 //todo: is ChapterFormat::Number correct?
3268 aChapterNo[1].Value <<= (sal_Int16)text::ChapterFormat::NUMBER;
3269 pNewLevel[aNewLevel.getLength() - (bHyperlinks ? 4 : 2) ] = aChapterNo;
3271 beans::PropertyValues aChapterSeparator(2);
3272 aChapterSeparator[0].Name = rPropNameSupplier.GetName( PROP_TOKEN_TYPE );
3273 aChapterSeparator[0].Value <<= rPropNameSupplier.GetName( PROP_TOKEN_TEXT );
3274 aChapterSeparator[1].Name = rPropNameSupplier.GetName( PROP_TEXT );
3275 aChapterSeparator[1].Value <<= sChapterNoSeparator;
3276 pNewLevel[aNewLevel.getLength() - (bHyperlinks ? 3 : 1)] = aChapterSeparator;
3278 //copy the 'old' entries except the last (page no)
3279 for( sal_Int32 nToken = 0; nToken < aLevel.getLength() - 1; ++nToken)
3281 pNewLevel[nToken + 1] = aLevel[nToken];
3283 //copy page no entry (last or last but one depending on bHyperlinks
3284 sal_Int32 nPageNo = aNewLevel.getLength() - (bHyperlinks ? 2 : 3);
3285 pNewLevel[nPageNo] = aLevel[aLevel.getLength() - 1];
3287 xLevelFormats->replaceByIndex( nLevel, uno::makeAny( aNewLevel ) );
3291 pContext->SetTOC( xTOC );
3293 break;
3294 case FIELD_TC :
3296 uno::Reference< beans::XPropertySet > xTC(
3297 m_xTextFactory->createInstance(
3298 ::rtl::OUString::createFromAscii(aIt->second.cFieldServiceName)),
3299 uno::UNO_QUERY_THROW);
3300 ::rtl::OUString sTCText = lcl_ExtractParameter(pContext->GetCommand(), sizeof(" TC") );
3301 if( sTCText.getLength())
3302 xTC->setPropertyValue(rPropNameSupplier.GetName(PROP_ALTERNATIVE_TEXT),
3303 uno::makeAny(sTCText));
3304 ::rtl::OUString sValue;
3305 // \f TC entry in doc with multiple tables
3306 // if( lcl_FindInCommand( pContext->GetCommand(), 'f', sValue ))
3307 // {
3308 // todo: unsupported
3309 // }
3310 if( lcl_FindInCommand( pContext->GetCommand(), 'l', sValue ))
3311 // \l Outline Level
3313 sal_Int32 nLevel = sValue.toInt32();
3314 if( sValue.getLength() && nLevel >= 0 && nLevel <= 10 )
3315 xTC->setPropertyValue(rPropNameSupplier.GetName(PROP_LEVEL), uno::makeAny( (sal_Int16)nLevel ));
3317 // if( lcl_FindInCommand( pContext->GetCommand(), 'n', sValue ))
3318 // \n Suppress page numbers
3319 // {
3320 //todo: unsupported feature
3321 // }
3322 pContext->SetTC( xTC );
3324 break;
3325 case FIELD_NUMCHARS:
3326 case FIELD_NUMWORDS:
3327 case FIELD_NUMPAGES:
3328 xFieldProperties->setPropertyValue(
3329 rPropNameSupplier.GetName(PROP_NUMBERING_TYPE),
3330 uno::makeAny( lcl_ParseNumberingType(pContext->GetCommand()) ));
3331 break;
3335 //set the text field if there is any
3336 pContext->SetTextField( uno::Reference< text::XTextField >( xFieldInterface, uno::UNO_QUERY ) );
3338 catch( uno::Exception& rEx)
3340 (void)rEx;
3341 OSL_ENSURE( false, "Exception in CloseFieldCommand()" );
3343 pContext->SetCommandCompleted();
3346 /*-- 29.01.2007 11:33:16---------------------------------------------------
3347 //the _current_ fields require a string type result while TOCs accept richt results
3348 -----------------------------------------------------------------------*/
3349 bool DomainMapper_Impl::IsFieldResultAsString()
3351 bool bRet = false;
3352 OSL_ENSURE( !m_aFieldStack.empty(), "field stack empty?");
3353 FieldContextPtr pContext = m_aFieldStack.top();
3354 OSL_ENSURE( pContext.get(), "no field context available");
3355 if( pContext.get() )
3357 bRet = pContext->GetTextField().is();
3359 return bRet;
3361 /*-- 01.09.2006 11:48:09---------------------------------------------------
3363 -----------------------------------------------------------------------*/
3364 void DomainMapper_Impl::SetFieldResult( ::rtl::OUString& rResult )
3366 FieldContextPtr pContext = m_aFieldStack.top();
3367 OSL_ENSURE( pContext.get(), "no field context available");
3368 if( pContext.get() )
3370 uno::Reference<text::XTextField> xTextField = pContext->GetTextField();
3373 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
3374 OSL_ENSURE( xTextField.is()
3375 //||m_xTOC.is() ||m_xTC.is()
3376 //||m_sHyperlinkURL.getLength()
3377 , "DomainMapper_Impl::SetFieldResult: field not created" );
3378 if(xTextField.is())
3382 if( m_bSetUserFieldContent )
3384 // user field content has to be set at the field master
3385 uno::Reference< text::XDependentTextField > xDependentField( xTextField, uno::UNO_QUERY_THROW );
3386 xDependentField->getTextFieldMaster()->setPropertyValue(
3387 rPropNameSupplier.GetName(PROP_CONTENT),
3388 uno::makeAny( rResult ));
3390 else
3392 uno::Reference< beans::XPropertySet > xFieldProperties( xTextField, uno::UNO_QUERY_THROW);
3393 xFieldProperties->setPropertyValue(
3394 rPropNameSupplier.GetName(PROP_CURRENT_PRESENTATION),
3395 uno::makeAny( rResult ));
3398 catch( const beans::UnknownPropertyException& )
3400 //some fields don't have a CurrentPresentation (DateTime)
3404 catch( uno::Exception& )
3411 /*-- 29.01.2007 11:33:17---------------------------------------------------
3412 //the end of field is reached (0x15 appeared) - the command might still be open
3413 -----------------------------------------------------------------------*/
3414 void DomainMapper_Impl::PopFieldContext()
3416 FieldContextPtr pContext = m_aFieldStack.top();
3417 OSL_ENSURE( pContext.get(), "no field context available");
3418 if( pContext.get() )
3420 if( !pContext->IsCommandCompleted() )
3421 CloseFieldCommand();
3423 //insert the field, TC or TOC
3424 uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend;
3425 if(xTextAppend.is())
3429 uno::Reference< text::XTextCursor > xCrsr = xTextAppend->createTextCursorByRange(pContext->GetStartRange());
3430 //remove the dummy character
3431 xCrsr->goRight( 1, true );
3432 xCrsr->setString( ::rtl::OUString() );
3433 uno::Reference< text::XTextContent > xToInsert( pContext->GetTOC(), uno::UNO_QUERY );
3434 if( xToInsert.is() )
3436 xCrsr->gotoEnd( true );
3437 xToInsert->attach( uno::Reference< text::XTextRange >( xCrsr, uno::UNO_QUERY_THROW ));
3439 else
3441 xToInsert = uno::Reference< text::XTextContent >(pContext->GetTC(), uno::UNO_QUERY);
3442 if( !xToInsert.is() )
3443 xToInsert = uno::Reference< text::XTextContent >(pContext->GetTextField(), uno::UNO_QUERY);
3444 if( xToInsert.is() )
3446 uno::Reference< text::XTextAppendAndConvert > xTextAppendAndConvert( xTextAppend, uno::UNO_QUERY_THROW );
3447 xTextAppendAndConvert->appendTextContent( xToInsert, uno::Sequence< beans::PropertyValue >() );
3449 else if(pContext->GetHyperlinkURL().getLength())
3451 PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
3452 xCrsr->gotoEnd( true );
3454 uno::Reference< beans::XPropertySet > xCrsrProperties( xCrsr, uno::UNO_QUERY_THROW );
3455 xCrsrProperties->setPropertyValue(
3456 rPropNameSupplier.GetName(PROP_HYPER_LINK_U_R_L), uno::
3457 makeAny(pContext->GetHyperlinkURL()));
3461 catch(const lang::IllegalArgumentException& )
3463 OSL_ENSURE( false, "IllegalArgumentException in PopFieldContext()" );
3465 catch(const uno::Exception& )
3467 OSL_ENSURE( false, "exception in PopFieldContext()" );
3471 //TOCs have to include all the imported content
3472 //...
3474 //remove the field context
3475 m_aFieldStack.pop();
3477 /*-- 11.06.2007 16:19:00---------------------------------------------------
3479 -----------------------------------------------------------------------*/
3480 void DomainMapper_Impl::AddBookmark( const ::rtl::OUString& rBookmarkName, const ::rtl::OUString& rId )
3482 uno::Reference< text::XTextAppend > xTextAppend = m_aTextAppendStack.top().xTextAppend;
3483 BookmarkMap_t::iterator aBookmarkIter = m_aBookmarkMap.find( rId );
3484 //is the bookmark name already registered?
3487 if( aBookmarkIter != m_aBookmarkMap.end() )
3489 static const rtl::OUString sBookmarkService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.Bookmark"));
3490 uno::Reference< text::XTextContent > xBookmark( m_xTextFactory->createInstance( sBookmarkService ), uno::UNO_QUERY_THROW );
3491 uno::Reference< text::XTextCursor > xCursor;
3492 uno::Reference< text::XText > xText = aBookmarkIter->second.m_xTextRange->getText();
3493 if( aBookmarkIter->second.m_bIsStartOfText )
3494 xCursor = xText->createTextCursorByRange( xText->getStart() );
3495 else
3497 xCursor = xText->createTextCursorByRange( aBookmarkIter->second.m_xTextRange );
3498 xCursor->goRight( 1, false );
3501 xCursor->gotoRange( xTextAppend->getEnd(), true );
3502 uno::Reference< container::XNamed > xBkmNamed( xBookmark, uno::UNO_QUERY_THROW );
3503 //todo: make sure the name is not used already!
3504 xBkmNamed->setName( aBookmarkIter->second.m_sBookmarkName );
3505 xTextAppend->insertTextContent( uno::Reference< text::XTextRange >( xCursor, uno::UNO_QUERY_THROW), xBookmark, !xCursor->isCollapsed() );
3506 m_aBookmarkMap.erase( aBookmarkIter );
3508 else
3510 //otherwise insert a text range as marker
3511 uno::Reference< text::XTextCursor > xCursor = xTextAppend->createTextCursorByRange( xTextAppend->getEnd() );
3512 bool bIsStart = !xCursor->goLeft(1, false);
3513 uno::Reference< text::XTextRange > xCurrent = xCursor->getStart();
3514 m_aBookmarkMap.insert(BookmarkMap_t::value_type( rId, BookmarkInsertPosition( bIsStart, rBookmarkName, xCurrent ) ));
3517 catch( const uno::Exception& )
3519 //TODO: What happens to bookmarks where start and end are at different XText objects?
3522 /*-- 01.11.2006 14:57:44---------------------------------------------------
3524 -----------------------------------------------------------------------*/
3525 GraphicImportPtr DomainMapper_Impl::GetGraphicImport(GraphicImportType eGraphicImportType)
3527 if(!m_pGraphicImport)
3528 m_pGraphicImport.reset( new GraphicImport( m_xComponentContext, m_xTextFactory, m_rDMapper, eGraphicImportType ) );
3529 return m_pGraphicImport;
3531 /*-- 09.08.2007 10:19:45---------------------------------------------------
3532 reset graphic import if the last import resulted in a shape, not a graphic
3533 -----------------------------------------------------------------------*/
3534 void DomainMapper_Impl::ResetGraphicImport()
3536 m_pGraphicImport.reset();
3538 /*-- 01.11.2006 09:25:40---------------------------------------------------
3540 -----------------------------------------------------------------------*/
3541 void DomainMapper_Impl::ImportGraphic(writerfilter::Reference< Properties >::Pointer_t ref, GraphicImportType eGraphicImportType)
3543 GetGraphicImport(eGraphicImportType);
3544 if( eGraphicImportType != IMPORT_AS_DETECTED_INLINE && eGraphicImportType != IMPORT_AS_DETECTED_ANCHOR )
3546 //create the graphic
3547 ref->resolve( *m_pGraphicImport );
3550 //insert it into the document at the current cursor position
3552 uno::Reference<text::XTextContent> xTextContent
3553 (m_pGraphicImport->GetGraphicObject());
3555 //insert it into the document at the current cursor position
3556 OSL_ENSURE( xTextContent.is(), "DomainMapper_Impl::ImportGraphic");
3557 if( xTextContent.is())
3558 appendTextContent( xTextContent, uno::Sequence< beans::PropertyValue >() );
3560 m_pGraphicImport.reset();
3563 /*-- 28.12.2006 14:00:47---------------------------------------------------
3565 -----------------------------------------------------------------------*/
3566 void DomainMapper_Impl::SetLineNumbering( sal_Int32 nLnnMod, sal_Int32 nLnc, sal_Int32 ndxaLnn )
3568 if( !m_bLineNumberingSet )
3570 const PropertyNameSupplier& rPropNameSupplier = PropertyNameSupplier::GetPropertyNameSupplier();
3574 uno::Reference< text::XLineNumberingProperties > xLineProperties( m_xTextDocument, uno::UNO_QUERY_THROW );
3575 uno::Reference< beans::XPropertySet > xProperties = xLineProperties->getLineNumberingProperties();
3576 uno::Any aTrue( uno::makeAny( true ));
3577 xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_IS_ON ), aTrue);
3578 xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_COUNT_EMPTY_LINES ), aTrue );
3579 xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_COUNT_LINES_IN_FRAMES ), uno::makeAny( false ) );
3580 xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_INTERVAL ), uno::makeAny( static_cast< sal_Int16 >( nLnnMod )));
3581 xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_DISTANCE ), uno::makeAny( ConversionHelper::convertTwipToMM100(ndxaLnn) ));
3582 xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_NUMBER_POSITION ), uno::makeAny( style::LineNumberPosition::LEFT));
3583 xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_NUMBERING_TYPE ), uno::makeAny( style::NumberingType::ARABIC));
3584 xProperties->setPropertyValue( rPropNameSupplier.GetName( PROP_RESTART_AT_EACH_PAGE ), uno::makeAny( nLnc == 0 ));
3586 catch( const uno::Exception& )
3592 { SW_PROP_NAME(UNO_NAME_CHAR_STYLE_NAME
3593 { SW_PROP_NAME(UNO_NAME_COUNT_EMPTY_LINES
3594 { SW_PROP_NAME(UNO_NAME_COUNT_LINES_IN_FRAMES
3595 { SW_PROP_NAME(UNO_NAME_DISTANCE
3596 { SW_PROP_NAME(UNO_NAME_IS_ON
3597 { SW_PROP_NAME(UNO_NAME_INTERVAL
3598 { SW_PROP_NAME(UNO_NAME_SEPARATOR_TEXT
3599 { SW_PROP_NAME(UNO_NAME_NUMBER_POSITION
3600 { SW_PROP_NAME(UNO_NAME_NUMBERING_TYPE
3601 { SW_PROP_NAME(UNO_NAME_RESTART_AT_EACH_PAGE
3602 { SW_PROP_NAME(UNO_NAME_SEPARATOR_INTERVAL
3605 m_bLineNumberingSet = true;
3607 /*-- 31.08.2007 13:50:49---------------------------------------------------
3609 -----------------------------------------------------------------------*/
3610 void DomainMapper_Impl::SetPageMarginTwip( PageMarElement eElement, sal_Int32 nValue )
3612 nValue = ConversionHelper::convertTwipToMM100(nValue);
3613 switch(eElement)
3615 case PAGE_MAR_TOP : m_aPageMargins.top = nValue; break;
3616 case PAGE_MAR_RIGHT : m_aPageMargins.right = nValue; break;
3617 case PAGE_MAR_BOTTOM : m_aPageMargins.bottom = nValue; break;
3618 case PAGE_MAR_LEFT : m_aPageMargins.left = nValue; break;
3619 case PAGE_MAR_HEADER : m_aPageMargins.header = nValue; break;
3620 case PAGE_MAR_FOOTER : m_aPageMargins.footer = nValue; break;
3621 case PAGE_MAR_GUTTER : m_aPageMargins.gutter = nValue; break;
3625 /*-- 31.08.2007 13:47:50---------------------------------------------------
3627 -----------------------------------------------------------------------*/
3628 _PageMar::_PageMar()
3630 header = footer = top = bottom = ConversionHelper::convertTwipToMM100( sal_Int32(1440));
3631 right = left = ConversionHelper::convertTwipToMM100( sal_Int32(1800));
3632 gutter = 0;
3635 /*-- 07.03.2008 12:07:27---------------------------------------------------
3637 -----------------------------------------------------------------------*/
3638 void DomainMapper_Impl::RegisterFrameConversion(
3639 uno::Reference< text::XTextRange > xFrameStartRange,
3640 uno::Reference< text::XTextRange > xFrameEndRange,
3641 uno::Sequence< beans::PropertyValue > aFrameProperties
3644 OSL_ENSURE(
3645 !m_aFrameProperties.getLength() && !m_xFrameStartRange.is() && !m_xFrameEndRange.is(),
3646 "frame properties not removed");
3647 m_aFrameProperties = aFrameProperties;
3648 m_xFrameStartRange = xFrameStartRange;
3649 m_xFrameEndRange = xFrameEndRange;
3651 /*-- 07.03.2008 12:07:33---------------------------------------------------
3653 -----------------------------------------------------------------------*/
3654 bool DomainMapper_Impl::ExecuteFrameConversion()
3656 bool bRet = false;
3657 if( m_xFrameStartRange.is() && m_xFrameEndRange.is() )
3659 bRet = true;
3662 uno::Reference< text::XTextAppendAndConvert > xTextAppendAndConvert( GetTopTextAppend(), uno::UNO_QUERY_THROW );
3663 xTextAppendAndConvert->convertToTextFrame(
3664 m_xFrameStartRange,
3665 m_xFrameEndRange,
3666 m_aFrameProperties );
3668 catch( const uno::Exception& rEx)
3670 (void)rEx;
3671 bRet = false;
3673 m_xFrameStartRange = 0;
3674 m_xFrameEndRange = 0;
3675 m_aFrameProperties.realloc( 0 );
3677 return bRet;
3680 void DomainMapper_Impl::AddNewRedline( )
3682 RedlineParamsPtr pNew( new RedlineParams );
3683 pNew->m_nToken = ooxml::OOXML_mod;
3684 if ( !m_bIsParaChange )
3686 #if DEBUG
3687 clog << "REDLINE: Adding a new redline to stack" << endl;
3688 #endif
3689 m_aRedlines.push_back( pNew );
3691 else
3693 #if DEBUG
3694 clog << "REDLINE: Setting a new paragraph redline" << endl;
3695 #endif
3696 m_pParaRedline.swap( pNew );
3700 RedlineParamsPtr DomainMapper_Impl::GetTopRedline( )
3702 RedlineParamsPtr pResult;
3703 if ( !m_bIsParaChange && m_aRedlines.size( ) > 0 )
3704 pResult = m_aRedlines.back( );
3705 else if ( m_bIsParaChange )
3706 pResult = m_pParaRedline;
3707 return pResult;
3710 sal_Int32 DomainMapper_Impl::GetCurrentRedlineToken( )
3712 sal_Int32 nToken = 0;
3713 RedlineParamsPtr pCurrent( GetTopRedline( ) );
3714 if ( pCurrent.get( ) )
3715 nToken = pCurrent->m_nToken;
3716 return nToken;
3719 void DomainMapper_Impl::SetCurrentRedlineAuthor( rtl::OUString sAuthor )
3721 RedlineParamsPtr pCurrent( GetTopRedline( ) );
3722 if ( pCurrent.get( ) )
3723 pCurrent->m_sAuthor = sAuthor;
3726 void DomainMapper_Impl::SetCurrentRedlineDate( rtl::OUString sDate )
3728 RedlineParamsPtr pCurrent( GetTopRedline( ) );
3729 if ( pCurrent.get( ) )
3730 pCurrent->m_sDate = sDate;
3733 void DomainMapper_Impl::SetCurrentRedlineId( sal_Int32 sId )
3735 RedlineParamsPtr pCurrent( GetTopRedline( ) );
3736 if ( pCurrent.get( ) )
3737 pCurrent->m_nId = sId;
3740 void DomainMapper_Impl::SetCurrentRedlineToken( sal_Int32 nToken )
3742 RedlineParamsPtr pCurrent( GetTopRedline( ) );
3743 if ( pCurrent.get( ) )
3744 pCurrent->m_nToken = nToken;
3747 /*-- 19.03.2008 11:35:38---------------------------------------------------
3749 -----------------------------------------------------------------------*/
3750 void DomainMapper_Impl::RemoveCurrentRedline( )
3752 if ( m_aRedlines.size( ) > 0 )
3754 #if DEBUG
3755 clog << "REDLINE: Removing back redline" << endl;
3756 #endif
3757 m_aRedlines.pop_back( );
3761 void DomainMapper_Impl::ResetParaRedline( )
3763 if ( m_pParaRedline.get( ) )
3765 #if DEBUG
3766 clog << "REDLINE: Cleaning the para redline" << endl;
3767 #endif
3768 RedlineParamsPtr pEmpty;
3769 m_pParaRedline.swap( pEmpty );