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