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