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