sw/source/core/access/accpara.cxx | 77 -- sw/source/core/unocore/SwXTextDefaults.cxx | 61 - sw/source/core/unocore/unobkm.cxx | 11 sw/source/core/unocore/unochart.cxx | 17 sw/source/core/unocore/unocoll.cxx | 282 +++---- sw/source/core/unocore/unodraw.cxx | 502 ++++++------- sw/source/core/unocore/unofield.cxx | 130 +-- sw/source/core/unocore/unoframe.cxx | 853 +++++++++++----------- sw/source/core/unocore/unoidx.cxx | 7 sw/source/core/unocore/unoobj.cxx | 16 sw/source/core/unocore/unoport.cxx | 7 sw/source/core/unocore/unoredline.cxx | 41 - sw/source/core/unocore/unoredlines.cxx | 12 sw/source/core/unocore/unosett.cxx | 1007 +++++++++++++-------------- sw/source/core/unocore/unosrch.cxx | 94 +- sw/source/core/unocore/unostyle.cxx | 61 - sw/source/core/unocore/unotbl.cxx | 332 ++++---- sw/source/core/unocore/unotextmarkup.cxx | 7 sw/source/ui/vba/vbaborders.cxx | 83 +- sw/source/ui/vba/vbaselection.cxx | 22 sw/source/ui/vba/vbastyle.cxx | 50 - sw/source/ui/vba/vbatemplate.cxx | 8 sw/source/uibase/misc/glosdoc.cxx | 12 sw/source/uibase/uno/SwXDocumentSettings.cxx | 78 +- sw/source/uibase/uno/unoatxt.cxx | 49 - sw/source/uibase/uno/unomailmerge.cxx | 10 sw/source/uibase/uno/unomod.cxx | 54 - sw/source/uibase/uno/unotxdoc.cxx | 348 ++++----- sw/source/uibase/uno/unotxvw.cxx | 763 +++++++++----------- 29 files changed, 2426 insertions(+), 2568 deletions(-)
New commits: commit 0b4135ec9945ea627318ecf5fccc4b7d0940ff0d Author: Noel Grandin <[email protected]> Date: Tue Sep 26 11:32:13 2017 +0200 loplugin:flatten in sw Change-Id: I77d92e7adc9af5c88ca1930c25a0585713f9e0d3 Reviewed-on: https://gerrit.libreoffice.org/42788 Tested-by: Jenkins <[email protected]> Reviewed-by: Noel Grandin <[email protected]> diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx index d413cda631af..e25061c79c33 100644 --- a/sw/source/core/access/accpara.cxx +++ b/sw/source/core/access/accpara.cxx @@ -1289,12 +1289,10 @@ sal_Unicode SwAccessibleParagraph::getCharacter( sal_Int32 nIndex ) OUString sText( GetString() ); // return character (if valid) - if( IsValidChar(nIndex, sText.getLength() ) ) - { - return sText[nIndex]; - } - else + if( !IsValidChar(nIndex, sText.getLength() ) ) throw lang::IndexOutOfBoundsException(); + + return sText[nIndex]; } css::uno::Sequence< css::style::TabStop > SwAccessibleParagraph::GetCurrentTabStop( sal_Int32 nIndex ) @@ -2515,13 +2513,11 @@ OUString SwAccessibleParagraph::getTextRange( OUString sText( GetString() ); - if ( IsValidRange( nStartIndex, nEndIndex, sText.getLength() ) ) - { - OrderRange( nStartIndex, nEndIndex ); - return sText.copy(nStartIndex, nEndIndex-nStartIndex ); - } - else + if ( !IsValidRange( nStartIndex, nEndIndex, sText.getLength() ) ) throw lang::IndexOutOfBoundsException(); + + OrderRange( nStartIndex, nEndIndex ); + return sText.copy(nStartIndex, nEndIndex-nStartIndex ); } /*accessibility::*/TextSegment SwAccessibleParagraph::getTextAtIndex( sal_Int32 nIndex, sal_Int16 nTextType ) @@ -2792,44 +2788,43 @@ sal_Bool SwAccessibleParagraph::replaceText( const OUString& rText = GetString(); - if( IsValidRange( nStartIndex, nEndIndex, rText.getLength() ) ) - { - if( !IsEditableState() ) - return false; + if( !IsValidRange( nStartIndex, nEndIndex, rText.getLength() ) ) + throw lang::IndexOutOfBoundsException(); - SwTextNode* pNode = const_cast<SwTextNode*>( GetTextNode() ); + if( !IsEditableState() ) + return false; - // translate positions - sal_Int32 nStart; - sal_Int32 nEnd; - bool bSuccess = GetPortionData().GetEditableRange( - nStartIndex, nEndIndex, nStart, nEnd ); + SwTextNode* pNode = const_cast<SwTextNode*>( GetTextNode() ); - // edit only if the range is editable - if( bSuccess ) - { - // create SwPosition for nStartIndex - SwIndex aIndex( pNode, nStart ); - SwPosition aStartPos( *pNode, aIndex ); + // translate positions + sal_Int32 nStart; + sal_Int32 nEnd; + bool bSuccess = GetPortionData().GetEditableRange( + nStartIndex, nEndIndex, nStart, nEnd ); - // create SwPosition for nEndIndex - SwPosition aEndPos( aStartPos ); - aEndPos.nContent = nEnd; + // edit only if the range is editable + if( bSuccess ) + { + // create SwPosition for nStartIndex + SwIndex aIndex( pNode, nStart ); + SwPosition aStartPos( *pNode, aIndex ); - // now create XTextRange as helper and set string - const uno::Reference<text::XTextRange> xRange( - SwXTextRange::CreateXTextRange( - *pNode->GetDoc(), aStartPos, &aEndPos)); - xRange->setString(sReplacement); + // create SwPosition for nEndIndex + SwPosition aEndPos( aStartPos ); + aEndPos.nContent = nEnd; - // delete portion data - ClearPortionData(); - } + // now create XTextRange as helper and set string + const uno::Reference<text::XTextRange> xRange( + SwXTextRange::CreateXTextRange( + *pNode->GetDoc(), aStartPos, &aEndPos)); + xRange->setString(sReplacement); - return bSuccess; + // delete portion data + ClearPortionData(); } - else - throw lang::IndexOutOfBoundsException(); + + return bSuccess; + } sal_Bool SwAccessibleParagraph::setAttributes( diff --git a/sw/source/core/unocore/SwXTextDefaults.cxx b/sw/source/core/unocore/SwXTextDefaults.cxx index c90e1212a8f7..4cc17c2ab7cd 100644 --- a/sw/source/core/unocore/SwXTextDefaults.cxx +++ b/sw/source/core/unocore/SwXTextDefaults.cxx @@ -80,40 +80,37 @@ void SAL_CALL SwXTextDefaults::setPropertyValue( const OUString& rPropertyName, (RES_TXTATR_CHARFMT == pMap->nWID)) { OUString uStyle; - if(aValue >>= uStyle) + if(!(aValue >>= uStyle)) + throw lang::IllegalArgumentException(); + + OUString sStyle; + SwStyleNameMapper::FillUIName(uStyle, sStyle, SwGetPoolIdFromName::ChrFmt, true ); + SwDocStyleSheet* pStyle = + static_cast<SwDocStyleSheet*>(m_pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle, SfxStyleFamily::Char)); + SwFormatDrop* pDrop = nullptr; + SwFormatCharFormat *pCharFormat = nullptr; + if(!pStyle) + throw lang::IllegalArgumentException(); + + rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *pStyle ) ); + if (xStyle->GetCharFormat() == m_pDoc->GetDfltCharFormat()) + return; // don't SetCharFormat with formats from mpDfltCharFormat + + if (RES_PARATR_DROP == pMap->nWID) { - OUString sStyle; - SwStyleNameMapper::FillUIName(uStyle, sStyle, SwGetPoolIdFromName::ChrFmt, true ); - SwDocStyleSheet* pStyle = - static_cast<SwDocStyleSheet*>(m_pDoc->GetDocShell()->GetStyleSheetPool()->Find(sStyle, SfxStyleFamily::Char)); - SwFormatDrop* pDrop = nullptr; - SwFormatCharFormat *pCharFormat = nullptr; - if(pStyle) - { - rtl::Reference< SwDocStyleSheet > xStyle( new SwDocStyleSheet( *pStyle ) ); - if (xStyle->GetCharFormat() == m_pDoc->GetDfltCharFormat()) - return; // don't SetCharFormat with formats from mpDfltCharFormat - - if (RES_PARATR_DROP == pMap->nWID) - { - pDrop = static_cast<SwFormatDrop*>(rItem.Clone()); // because rItem is const... - pDrop->SetCharFormat(xStyle->GetCharFormat()); - m_pDoc->SetDefault(*pDrop); - } - else // RES_TXTATR_CHARFMT == pMap->nWID - { - pCharFormat = static_cast<SwFormatCharFormat*>(rItem.Clone()); // because rItem is const... - pCharFormat->SetCharFormat(xStyle->GetCharFormat()); - m_pDoc->SetDefault(*pCharFormat); - } - } - else - throw lang::IllegalArgumentException(); - delete pDrop; - delete pCharFormat; + pDrop = static_cast<SwFormatDrop*>(rItem.Clone()); // because rItem is const... + pDrop->SetCharFormat(xStyle->GetCharFormat()); + m_pDoc->SetDefault(*pDrop); } - else - throw lang::IllegalArgumentException(); + else // RES_TXTATR_CHARFMT == pMap->nWID + { + pCharFormat = static_cast<SwFormatCharFormat*>(rItem.Clone()); // because rItem is const... + pCharFormat->SetCharFormat(xStyle->GetCharFormat()); + m_pDoc->SetDefault(*pCharFormat); + } + + delete pDrop; + delete pCharFormat; } else { diff --git a/sw/source/core/unocore/unobkm.cxx b/sw/source/core/unocore/unobkm.cxx index 6574c92ff75c..94b6c8053215 100644 --- a/sw/source/core/unocore/unobkm.cxx +++ b/sw/source/core/unocore/unobkm.cxx @@ -621,11 +621,10 @@ SwXFieldmark::setPropertyValue(const OUString& PropertyName, { ::sw::mark::ICheckboxFieldmark* pCheckboxFm = getCheckboxFieldmark(); bool bChecked( false ); - if ( pCheckboxFm && ( rValue >>= bChecked ) ) - pCheckboxFm->SetChecked( bChecked ); - else + if ( !(pCheckboxFm && ( rValue >>= bChecked )) ) throw uno::RuntimeException(); + pCheckboxFm->SetChecked( bChecked ); } else SwXFieldmark_Base::setPropertyValue( PropertyName, rValue ); @@ -640,10 +639,10 @@ uno::Any SAL_CALL SwXFieldmark::getPropertyValue(const OUString& rPropertyName) if ( rPropertyName == "Checked" ) { ::sw::mark::ICheckboxFieldmark* pCheckboxFm = getCheckboxFieldmark(); - if ( pCheckboxFm ) - return uno::makeAny( pCheckboxFm->IsChecked() ); - else + if ( !pCheckboxFm ) throw uno::RuntimeException(); + + return uno::makeAny( pCheckboxFm->IsChecked() ); } return SwXFieldmark_Base::getPropertyValue( rPropertyName ); } diff --git a/sw/source/core/unocore/unochart.cxx b/sw/source/core/unocore/unochart.cxx index 25217f56e2fa..03dac9d63e22 100644 --- a/sw/source/core/unocore/unochart.cxx +++ b/sw/source/core/unocore/unochart.cxx @@ -2172,13 +2172,11 @@ void SAL_CALL SwChartDataSequence::setPropertyValue( if (m_bDisposed) throw lang::DisposedException(); - if (rPropertyName == UNO_NAME_ROLE) - { - if ( !(rValue >>= m_aRole) ) - throw lang::IllegalArgumentException(); - } - else + if (rPropertyName != UNO_NAME_ROLE) throw beans::UnknownPropertyException(); + + if ( !(rValue >>= m_aRole) ) + throw lang::IllegalArgumentException(); } uno::Any SAL_CALL SwChartDataSequence::getPropertyValue( @@ -2188,13 +2186,10 @@ uno::Any SAL_CALL SwChartDataSequence::getPropertyValue( if (m_bDisposed) throw lang::DisposedException(); - uno::Any aRes; - if (rPropertyName == UNO_NAME_ROLE) - aRes <<= m_aRole; - else + if (!(rPropertyName == UNO_NAME_ROLE)) throw beans::UnknownPropertyException(); - return aRes; + return uno::Any(m_aRole); } void SAL_CALL SwChartDataSequence::addPropertyChangeListener( diff --git a/sw/source/core/unocore/unocoll.cxx b/sw/source/core/unocore/unocoll.cxx index fa647bcf9f18..b02349a9e483 100644 --- a/sw/source/core/unocore/unocoll.cxx +++ b/sw/source/core/unocore/unocoll.cxx @@ -860,58 +860,55 @@ uno::Any SAL_CALL SwXTextTables::getByIndex(sal_Int32 nInputIndex) { SolarMutexGuard aGuard; uno::Any aRet; - if (IsValid()) - { - if (nInputIndex < 0) - throw IndexOutOfBoundsException(); + if (!IsValid()) + throw uno::RuntimeException(); - SwAutoFormatGetDocNode aGetHt( &GetDoc()->GetNodes() ); - size_t nIndex = static_cast<size_t>(nInputIndex); - size_t nCurrentIndex = 0; + if (nInputIndex < 0) + throw IndexOutOfBoundsException(); - for (SwFrameFormat* const & pFormat : *GetDoc()->GetTableFrameFormats()) + SwAutoFormatGetDocNode aGetHt( &GetDoc()->GetNodes() ); + size_t nIndex = static_cast<size_t>(nInputIndex); + size_t nCurrentIndex = 0; + + for (SwFrameFormat* const & pFormat : *GetDoc()->GetTableFrameFormats()) + { + if (!pFormat->GetInfo(aGetHt)) { - if (!pFormat->GetInfo(aGetHt)) + if (nCurrentIndex == nIndex) { - if (nCurrentIndex == nIndex) - { - uno::Reference<XTextTable> xTable = SwXTextTables::GetObject(*pFormat); - aRet <<= xTable; - return aRet; - } - else - nCurrentIndex++; + uno::Reference<XTextTable> xTable = SwXTextTables::GetObject(*pFormat); + aRet <<= xTable; + return aRet; } + else + nCurrentIndex++; } - throw IndexOutOfBoundsException(); } - else - throw uno::RuntimeException(); + throw IndexOutOfBoundsException(); } uno::Any SwXTextTables::getByName(const OUString& rItemName) { SolarMutexGuard aGuard; uno::Any aRet; - if(IsValid()) + if(!IsValid()) + throw uno::RuntimeException(); + + const size_t nCount = GetDoc()->GetTableFrameFormatCount(true); + uno::Reference< XTextTable > xTable; + for( size_t i = 0; i < nCount; ++i) { - const size_t nCount = GetDoc()->GetTableFrameFormatCount(true); - uno::Reference< XTextTable > xTable; - for( size_t i = 0; i < nCount; ++i) + SwFrameFormat& rFormat = GetDoc()->GetTableFrameFormat(i, true); + if (rItemName == rFormat.GetName()) { - SwFrameFormat& rFormat = GetDoc()->GetTableFrameFormat(i, true); - if (rItemName == rFormat.GetName()) - { - xTable = SwXTextTables::GetObject(rFormat); - aRet <<= xTable; - break; - } + xTable = SwXTextTables::GetObject(rFormat); + aRet <<= xTable; + break; } - if(!xTable.is()) - throw NoSuchElementException(); } - else - throw uno::RuntimeException(); + if(!xTable.is()) + throw NoSuchElementException(); + return aRet; } @@ -939,21 +936,19 @@ sal_Bool SwXTextTables::hasByName(const OUString& rName) { SolarMutexGuard aGuard; bool bRet= false; - if(IsValid()) + if(!IsValid()) + throw uno::RuntimeException(); + + const size_t nCount = GetDoc()->GetTableFrameFormatCount(true); + for( size_t i = 0; i < nCount; ++i) { - const size_t nCount = GetDoc()->GetTableFrameFormatCount(true); - for( size_t i = 0; i < nCount; ++i) + SwFrameFormat& rFormat = GetDoc()->GetTableFrameFormat(i, true); + if (rName == rFormat.GetName()) { - SwFrameFormat& rFormat = GetDoc()->GetTableFrameFormat(i, true); - if (rName == rFormat.GetName()) - { - bRet = true; - break; - } + bRet = true; + break; } } - else - throw uno::RuntimeException(); return bRet; } @@ -1416,31 +1411,28 @@ uno::Any SwXTextSections::getByIndex(sal_Int32 nIndex) { SolarMutexGuard aGuard; uno::Reference< XTextSection > xRet; - if(IsValid()) - { - SwSectionFormats& rFormats = GetDoc()->GetSections(); + if(!IsValid()) + throw uno::RuntimeException(); - const SwSectionFormats& rSectFormats = GetDoc()->GetSections(); - const size_t nCount = rSectFormats.size(); - for(size_t i = 0; i < nCount; ++i) - { - if( !rSectFormats[i]->IsInNodesArr()) - nIndex ++; - else if(static_cast<size_t>(nIndex) == i) - break; - if(static_cast<size_t>(nIndex) == i) - break; - } - if(nIndex >= 0 && static_cast<size_t>(nIndex) < rFormats.size()) - { - SwSectionFormat* pFormat = rFormats[nIndex]; - xRet = GetObject(*pFormat); - } - else - throw IndexOutOfBoundsException(); + SwSectionFormats& rFormats = GetDoc()->GetSections(); + + const SwSectionFormats& rSectFormats = GetDoc()->GetSections(); + const size_t nCount = rSectFormats.size(); + for(size_t i = 0; i < nCount; ++i) + { + if( !rSectFormats[i]->IsInNodesArr()) + nIndex ++; + else if(static_cast<size_t>(nIndex) == i) + break; + if(static_cast<size_t>(nIndex) == i) + break; } - else - throw uno::RuntimeException(); + if(!(nIndex >= 0 && static_cast<size_t>(nIndex) < rFormats.size())) + throw IndexOutOfBoundsException(); + + SwSectionFormat* pFormat = rFormats[nIndex]; + xRet = GetObject(*pFormat); + return makeAny(xRet); } @@ -1448,26 +1440,25 @@ uno::Any SwXTextSections::getByName(const OUString& rName) { SolarMutexGuard aGuard; uno::Any aRet; - if(IsValid()) + if(!IsValid()) + throw uno::RuntimeException(); + + SwSectionFormats& rFormats = GetDoc()->GetSections(); + uno::Reference< XTextSection > xSect; + for(size_t i = 0; i < rFormats.size(); ++i) { - SwSectionFormats& rFormats = GetDoc()->GetSections(); - uno::Reference< XTextSection > xSect; - for(size_t i = 0; i < rFormats.size(); ++i) + SwSectionFormat* pFormat = rFormats[i]; + if (pFormat->IsInNodesArr() + && (rName == pFormat->GetSection()->GetSectionName())) { - SwSectionFormat* pFormat = rFormats[i]; - if (pFormat->IsInNodesArr() - && (rName == pFormat->GetSection()->GetSectionName())) - { - xSect = GetObject(*pFormat); - aRet <<= xSect; - break; - } + xSect = GetObject(*pFormat); + aRet <<= xSect; + break; } - if(!xSect.is()) - throw NoSuchElementException(); } - else - throw uno::RuntimeException(); + if(!xSect.is()) + throw NoSuchElementException(); + return aRet; } @@ -1538,13 +1529,12 @@ sal_Bool SwXTextSections::hasElements() { SolarMutexGuard aGuard; size_t nCount = 0; - if(IsValid()) - { - SwSectionFormats& rFormats = GetDoc()->GetSections(); - nCount = rFormats.size(); - } - else + if(!IsValid()) throw uno::RuntimeException(); + + SwSectionFormats& rFormats = GetDoc()->GetSections(); + nCount = rFormats.size(); + return nCount > 0; } @@ -1723,20 +1713,19 @@ uno::Any SwXNumberingRulesCollection::getByIndex(sal_Int32 nIndex) { SolarMutexGuard aGuard; uno::Any aRet; - if(IsValid()) - { - uno::Reference< XIndexReplace > xRef; - if ( static_cast<size_t>(nIndex) < GetDoc()->GetNumRuleTable().size() ) - { - xRef = new SwXNumberingRules( *GetDoc()->GetNumRuleTable()[ nIndex ], GetDoc()); - aRet <<= xRef; - } + if(!IsValid()) + throw uno::RuntimeException(); - if(!xRef.is()) - throw IndexOutOfBoundsException(); + uno::Reference< XIndexReplace > xRef; + if ( static_cast<size_t>(nIndex) < GetDoc()->GetNumRuleTable().size() ) + { + xRef = new SwXNumberingRules( *GetDoc()->GetNumRuleTable()[ nIndex ], GetDoc()); + aRet <<= xRef; } - else - throw uno::RuntimeException(); + + if(!xRef.is()) + throw IndexOutOfBoundsException(); + return aRet; } @@ -1803,32 +1792,31 @@ uno::Any SwXFootnotes::getByIndex(sal_Int32 nIndex) SolarMutexGuard aGuard; uno::Any aRet; sal_Int32 nCount = 0; - if(IsValid()) + if(!IsValid()) + throw uno::RuntimeException(); + + const size_t nFootnoteCnt = GetDoc()->GetFootnoteIdxs().size(); + SwTextFootnote* pTextFootnote; + uno::Reference< XFootnote > xRef; + for( size_t n = 0; n < nFootnoteCnt; ++n ) { - const size_t nFootnoteCnt = GetDoc()->GetFootnoteIdxs().size(); - SwTextFootnote* pTextFootnote; - uno::Reference< XFootnote > xRef; - for( size_t n = 0; n < nFootnoteCnt; ++n ) - { - pTextFootnote = GetDoc()->GetFootnoteIdxs()[ n ]; - const SwFormatFootnote& rFootnote = pTextFootnote->GetFootnote(); - if ( rFootnote.IsEndNote() != m_bEndnote ) - continue; + pTextFootnote = GetDoc()->GetFootnoteIdxs()[ n ]; + const SwFormatFootnote& rFootnote = pTextFootnote->GetFootnote(); + if ( rFootnote.IsEndNote() != m_bEndnote ) + continue; - if(nCount == nIndex) - { - xRef = SwXFootnote::CreateXFootnote(*GetDoc(), - &const_cast<SwFormatFootnote&>(rFootnote)); - aRet <<= xRef; - break; - } - nCount++; + if(nCount == nIndex) + { + xRef = SwXFootnote::CreateXFootnote(*GetDoc(), + &const_cast<SwFormatFootnote&>(rFootnote)); + aRet <<= xRef; + break; } - if(!xRef.is()) - throw IndexOutOfBoundsException(); + nCount++; } - else - throw uno::RuntimeException(); + if(!xRef.is()) + throw IndexOutOfBoundsException(); + return aRet; } @@ -1909,21 +1897,18 @@ uno::Any SwXReferenceMarks::getByName(const OUString& rName) { SolarMutexGuard aGuard; uno::Any aRet; - if(IsValid()) - { - SwFormatRefMark *const pMark = - const_cast<SwFormatRefMark*>(GetDoc()->GetRefMark(rName)); - if(pMark) - { - uno::Reference<XTextContent> const xRef = - SwXReferenceMark::CreateXReferenceMark(*GetDoc(), pMark); - aRet <<= xRef; - } - else - throw NoSuchElementException(); - } - else + if(!IsValid()) throw uno::RuntimeException(); + + SwFormatRefMark *const pMark = + const_cast<SwFormatRefMark*>(GetDoc()->GetRefMark(rName)); + if(!pMark) + throw NoSuchElementException(); + + uno::Reference<XTextContent> const xRef = + SwXReferenceMark::CreateXReferenceMark(*GetDoc(), pMark); + aRet <<= xRef; + return aRet; } @@ -1931,17 +1916,16 @@ uno::Sequence< OUString > SwXReferenceMarks::getElementNames() { SolarMutexGuard aGuard; uno::Sequence<OUString> aRet; - if(IsValid()) - { - std::vector<OUString> aStrings; - const sal_uInt16 nCount = GetDoc()->GetRefMarks( &aStrings ); - aRet.realloc(nCount); - OUString* pNames = aRet.getArray(); - for(sal_uInt16 i = 0; i < nCount; i++) - pNames[i] = aStrings[i]; - } - else + if(!IsValid()) throw uno::RuntimeException(); + + std::vector<OUString> aStrings; + const sal_uInt16 nCount = GetDoc()->GetRefMarks( &aStrings ); + aRet.realloc(nCount); + OUString* pNames = aRet.getArray(); + for(sal_uInt16 i = 0; i < nCount; i++) + pNames[i] = aStrings[i]; + return aRet; } diff --git a/sw/source/core/unocore/unodraw.cxx b/sw/source/core/unocore/unodraw.cxx index 6a6da5c57d9e..f76260626e28 100644 --- a/sw/source/core/unocore/unodraw.cxx +++ b/sw/source/core/unocore/unodraw.cxx @@ -673,20 +673,19 @@ void SwXDrawPage::add(const uno::Reference< drawing::XShape > & xShape) if( pDesc && (xRg = pDesc->GetTextRange()).is() ) { pInternalPam = new SwUnoInternalPaM(*pDoc); - if (::sw::XTextRangeToSwPaM(*pInternalPam, xRg)) + if (!::sw::XTextRangeToSwPaM(*pInternalPam, xRg)) + throw uno::RuntimeException(); + + if(RndStdIds::FLY_AT_FLY == aAnchor.GetAnchorId() && + !pInternalPam->GetNode().FindFlyStartNode()) { - if(RndStdIds::FLY_AT_FLY == aAnchor.GetAnchorId() && - !pInternalPam->GetNode().FindFlyStartNode()) - { - aAnchor.SetType(RndStdIds::FLY_AS_CHAR); - } - else if (RndStdIds::FLY_AT_PAGE == aAnchor.GetAnchorId()) - { - aAnchor.SetAnchor(pInternalPam->Start()); - } + aAnchor.SetType(RndStdIds::FLY_AS_CHAR); } - else - throw uno::RuntimeException(); + else if (RndStdIds::FLY_AT_PAGE == aAnchor.GetAnchorId()) + { + aAnchor.SetAnchor(pInternalPam->Start()); + } + } else if ((aAnchor.GetAnchorId() != RndStdIds::FLY_AT_PAGE) && pDoc->getIDocumentLayoutAccess().GetCurrentLayout()) { @@ -1128,49 +1127,48 @@ void SwXShape::setPropertyValue(const OUString& rPropertyName, const uno::Any& a new SwUnoInternalPaM( *(pFormat->GetDoc()) )); uno::Reference< text::XTextRange > xRg; aValue >>= xRg; - if (::sw::XTextRangeToSwPaM(*pInternalPam, xRg) ) + if (!::sw::XTextRangeToSwPaM(*pInternalPam, xRg) ) { - if (aAnchor.GetAnchorId() == RndStdIds::FLY_AS_CHAR) - { - //delete old SwFormatFlyCnt - //With AnchorAsCharacter the current TextAttribute has to be deleted. - //Tbis removes the frame format too. - //To prevent this the connection between format and attribute has to be broken before. - const SwPosition *pPos = aAnchor.GetContentAnchor(); - SwTextNode *pTextNode = pPos->nNode.GetNode().GetTextNode(); - SAL_WARN_IF( !pTextNode->HasHints(), "sw.uno", "Missing FlyInCnt-Hint." ); - const sal_Int32 nIdx = pPos->nContent.GetIndex(); - SwTextAttr * const pHint = - pTextNode->GetTextAttrForCharAt( - nIdx, RES_TXTATR_FLYCNT ); - assert(pHint && "Missing Hint."); - SAL_WARN_IF( pHint->Which() != RES_TXTATR_FLYCNT, - "sw.uno", "Missing FlyInCnt-Hint." ); - SAL_WARN_IF( pHint->GetFlyCnt().GetFrameFormat() != pFormat, - "sw.uno", "Wrong TextFlyCnt-Hint." ); - const_cast<SwFormatFlyCnt&>(pHint->GetFlyCnt()) - .SetFlyFormat(); - - //The connection is removed now the attribute can be deleted. - pTextNode->DeleteAttributes( RES_TXTATR_FLYCNT, nIdx ); - //create a new one - SwTextNode *pNd = pInternalPam->GetNode().GetTextNode(); - SAL_WARN_IF( !pNd, "sw.uno", "Cursor not at TextNode." ); - SwFormatFlyCnt aFormat( pFormat ); - pNd->InsertItem(aFormat, pInternalPam->GetPoint() - ->nContent.GetIndex(), 0 ); - } - else - { - aAnchor.SetAnchor( pInternalPam->GetPoint() ); - aSet.Put(aAnchor); - pFormat->SetFormatAttr(aSet); - } + throw uno::RuntimeException(); + } + + if (aAnchor.GetAnchorId() == RndStdIds::FLY_AS_CHAR) + { + //delete old SwFormatFlyCnt + //With AnchorAsCharacter the current TextAttribute has to be deleted. + //Tbis removes the frame format too. + //To prevent this the connection between format and attribute has to be broken before. + const SwPosition *pPos = aAnchor.GetContentAnchor(); + SwTextNode *pTextNode = pPos->nNode.GetNode().GetTextNode(); + SAL_WARN_IF( !pTextNode->HasHints(), "sw.uno", "Missing FlyInCnt-Hint." ); + const sal_Int32 nIdx = pPos->nContent.GetIndex(); + SwTextAttr * const pHint = + pTextNode->GetTextAttrForCharAt( + nIdx, RES_TXTATR_FLYCNT ); + assert(pHint && "Missing Hint."); + SAL_WARN_IF( pHint->Which() != RES_TXTATR_FLYCNT, + "sw.uno", "Missing FlyInCnt-Hint." ); + SAL_WARN_IF( pHint->GetFlyCnt().GetFrameFormat() != pFormat, + "sw.uno", "Wrong TextFlyCnt-Hint." ); + const_cast<SwFormatFlyCnt&>(pHint->GetFlyCnt()) + .SetFlyFormat(); + + //The connection is removed now the attribute can be deleted. + pTextNode->DeleteAttributes( RES_TXTATR_FLYCNT, nIdx ); + //create a new one + SwTextNode *pNd = pInternalPam->GetNode().GetTextNode(); + SAL_WARN_IF( !pNd, "sw.uno", "Cursor not at TextNode." ); + SwFormatFlyCnt aFormat( pFormat ); + pNd->InsertItem(aFormat, pInternalPam->GetPoint() + ->nContent.GetIndex(), 0 ); } else { - throw uno::RuntimeException(); + aAnchor.SetAnchor( pInternalPam->GetPoint() ); + aSet.Put(aAnchor); + pFormat->SetFormatAttr(aSet); } + } } else if (pEntry->nWID == FN_TEXT_BOX) @@ -1760,112 +1758,111 @@ uno::Sequence< beans::PropertyState > SwXShape::getPropertyStates( SolarMutexGuard aGuard; SwFrameFormat* pFormat = GetFrameFormat(); uno::Sequence< beans::PropertyState > aRet(aPropertyNames.getLength()); - if(xShapeAgg.is()) + if(!xShapeAgg.is()) + throw uno::RuntimeException(); + + SvxShape* pSvxShape = GetSvxShape(); + bool bGroupMember = false; + bool bFormControl = false; + SdrObject* pObject = pSvxShape ? pSvxShape->GetSdrObject() : nullptr; + if(pObject) { - SvxShape* pSvxShape = GetSvxShape(); - bool bGroupMember = false; - bool bFormControl = false; - SdrObject* pObject = pSvxShape ? pSvxShape->GetSdrObject() : nullptr; - if(pObject) - { - bGroupMember = pObject->GetUpGroup() != nullptr; - bFormControl = pObject->GetObjInventor() == SdrInventor::FmForm; - } - const OUString* pNames = aPropertyNames.getConstArray(); - beans::PropertyState* pRet = aRet.getArray(); - uno::Reference< XPropertyState > xShapePrState; - for(sal_Int32 nProperty = 0; nProperty < aPropertyNames.getLength(); nProperty++) + bGroupMember = pObject->GetUpGroup() != nullptr; + bFormControl = pObject->GetObjInventor() == SdrInventor::FmForm; + } + const OUString* pNames = aPropertyNames.getConstArray(); + beans::PropertyState* pRet = aRet.getArray(); + uno::Reference< XPropertyState > xShapePrState; + for(sal_Int32 nProperty = 0; nProperty < aPropertyNames.getLength(); nProperty++) + { + const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap().getByName( pNames[nProperty] ); + if(pEntry) { - const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap().getByName( pNames[nProperty] ); - if(pEntry) + if(RES_OPAQUE == pEntry->nWID) + pRet[nProperty] = bFormControl ? + beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; + else if(FN_ANCHOR_POSITION == pEntry->nWID) + pRet[nProperty] = beans::PropertyState_DIRECT_VALUE; + else if(FN_TEXT_RANGE == pEntry->nWID) + pRet[nProperty] = beans::PropertyState_DIRECT_VALUE; + else if(bGroupMember) + pRet[nProperty] = beans::PropertyState_DEFAULT_VALUE; + else if (pEntry->nWID == RES_FRM_SIZE && + (pEntry->nMemberId == MID_FRMSIZE_REL_HEIGHT_RELATION || + pEntry->nMemberId == MID_FRMSIZE_REL_WIDTH_RELATION)) + pRet[nProperty] = beans::PropertyState_DIRECT_VALUE; + else if (pEntry->nWID == FN_TEXT_BOX) { - if(RES_OPAQUE == pEntry->nWID) - pRet[nProperty] = bFormControl ? - beans::PropertyState_DEFAULT_VALUE : beans::PropertyState_DIRECT_VALUE; - else if(FN_ANCHOR_POSITION == pEntry->nWID) - pRet[nProperty] = beans::PropertyState_DIRECT_VALUE; - else if(FN_TEXT_RANGE == pEntry->nWID) + // The TextBox property is set, if we can find a textbox for this shape. + if (pFormat && SwTextBoxHelper::isTextBox(pFormat, RES_DRAWFRMFMT)) pRet[nProperty] = beans::PropertyState_DIRECT_VALUE; - else if(bGroupMember) + else pRet[nProperty] = beans::PropertyState_DEFAULT_VALUE; - else if (pEntry->nWID == RES_FRM_SIZE && - (pEntry->nMemberId == MID_FRMSIZE_REL_HEIGHT_RELATION || - pEntry->nMemberId == MID_FRMSIZE_REL_WIDTH_RELATION)) - pRet[nProperty] = beans::PropertyState_DIRECT_VALUE; - else if (pEntry->nWID == FN_TEXT_BOX) - { - // The TextBox property is set, if we can find a textbox for this shape. - if (pFormat && SwTextBoxHelper::isTextBox(pFormat, RES_DRAWFRMFMT)) - pRet[nProperty] = beans::PropertyState_DIRECT_VALUE; - else - pRet[nProperty] = beans::PropertyState_DEFAULT_VALUE; - } - else if(pFormat) - { - const SwAttrSet& rSet = pFormat->GetAttrSet(); - SfxItemState eItemState = rSet.GetItemState(pEntry->nWID, false); + } + else if(pFormat) + { + const SwAttrSet& rSet = pFormat->GetAttrSet(); + SfxItemState eItemState = rSet.GetItemState(pEntry->nWID, false); - if(SfxItemState::SET == eItemState) - pRet[nProperty] = beans::PropertyState_DIRECT_VALUE; - else if(SfxItemState::DEFAULT == eItemState) - pRet[nProperty] = beans::PropertyState_DEFAULT_VALUE; - else - pRet[nProperty] = beans::PropertyState_AMBIGUOUS_VALUE; - } + if(SfxItemState::SET == eItemState) + pRet[nProperty] = beans::PropertyState_DIRECT_VALUE; + else if(SfxItemState::DEFAULT == eItemState) + pRet[nProperty] = beans::PropertyState_DEFAULT_VALUE; else + pRet[nProperty] = beans::PropertyState_AMBIGUOUS_VALUE; + } + else + { + SfxPoolItem* pItem = nullptr; + switch(pEntry->nWID) { - SfxPoolItem* pItem = nullptr; - switch(pEntry->nWID) + case RES_ANCHOR: + pItem = pImpl->GetAnchor(); + break; + case RES_HORI_ORIENT: + pItem = pImpl->GetHOrient(); + break; + case RES_VERT_ORIENT: + pItem = pImpl->GetVOrient(); + break; + case RES_LR_SPACE: + pItem = pImpl->GetLRSpace(); + break; + case RES_UL_SPACE: + pItem = pImpl->GetULSpace(); + break; + case RES_SURROUND: + pItem = pImpl->GetSurround(); + break; + // #i28701# + case RES_WRAP_INFLUENCE_ON_OBJPOS: { - case RES_ANCHOR: - pItem = pImpl->GetAnchor(); - break; - case RES_HORI_ORIENT: - pItem = pImpl->GetHOrient(); - break; - case RES_VERT_ORIENT: - pItem = pImpl->GetVOrient(); - break; - case RES_LR_SPACE: - pItem = pImpl->GetLRSpace(); - break; - case RES_UL_SPACE: - pItem = pImpl->GetULSpace(); - break; - case RES_SURROUND: - pItem = pImpl->GetSurround(); - break; - // #i28701# - case RES_WRAP_INFLUENCE_ON_OBJPOS: - { - pItem = pImpl->GetWrapInfluenceOnObjPos(); - } - break; + pItem = pImpl->GetWrapInfluenceOnObjPos(); } - if(pItem) - pRet[nProperty] = beans::PropertyState_DIRECT_VALUE; - else - pRet[nProperty] = beans::PropertyState_DEFAULT_VALUE; + break; } + if(pItem) + pRet[nProperty] = beans::PropertyState_DIRECT_VALUE; + else + pRet[nProperty] = beans::PropertyState_DEFAULT_VALUE; } - else + } + else + { + if(!xShapePrState.is()) { - if(!xShapePrState.is()) - { - const uno::Type& rPStateType = cppu::UnoType<XPropertyState>::get(); - uno::Any aPState = xShapeAgg->queryAggregation(rPStateType); - auto ps = o3tl::tryAccess<uno::Reference<XPropertyState>>( - aPState); - if(!ps) - throw uno::RuntimeException(); - xShapePrState = *ps; - } - pRet[nProperty] = xShapePrState->getPropertyState(pNames[nProperty]); + const uno::Type& rPStateType = cppu::UnoType<XPropertyState>::get(); + uno::Any aPState = xShapeAgg->queryAggregation(rPStateType); + auto ps = o3tl::tryAccess<uno::Reference<XPropertyState>>( + aPState); + if(!ps) + throw uno::RuntimeException(); + xShapePrState = *ps; } + pRet[nProperty] = xShapePrState->getPropertyState(pNames[nProperty]); } } - else - throw uno::RuntimeException(); + return aRet; } @@ -1873,62 +1870,61 @@ void SwXShape::setPropertyToDefault( const OUString& rPropertyName ) { SolarMutexGuard aGuard; SwFrameFormat* pFormat = GetFrameFormat(); - if(xShapeAgg.is()) + if(!xShapeAgg.is()) + throw uno::RuntimeException(); + + const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName ); + if(pEntry) { - const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName ); - if(pEntry) + if ( pEntry->nFlags & beans::PropertyAttribute::READONLY) + throw uno::RuntimeException("Property is read-only: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) ); + if(pFormat) { - if ( pEntry->nFlags & beans::PropertyAttribute::READONLY) - throw uno::RuntimeException("Property is read-only: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) ); - if(pFormat) - { - const SfxItemSet& rSet = pFormat->GetAttrSet(); - SfxItemSet aSet(pFormat->GetDoc()->GetAttrPool(), {{pEntry->nWID, pEntry->nWID}}); - aSet.SetParent(&rSet); - aSet.ClearItem(pEntry->nWID); - pFormat->GetDoc()->SetAttr(aSet, *pFormat); - } - else + const SfxItemSet& rSet = pFormat->GetAttrSet(); + SfxItemSet aSet(pFormat->GetDoc()->GetAttrPool(), {{pEntry->nWID, pEntry->nWID}}); + aSet.SetParent(&rSet); + aSet.ClearItem(pEntry->nWID); + pFormat->GetDoc()->SetAttr(aSet, *pFormat); + } + else + { + switch(pEntry->nWID) { - switch(pEntry->nWID) + case RES_ANCHOR: pImpl->RemoveAnchor(); break; + case RES_HORI_ORIENT: pImpl->RemoveHOrient(); break; + case RES_VERT_ORIENT: pImpl->RemoveVOrient(); break; + case RES_LR_SPACE: pImpl->RemoveLRSpace(); break; + case RES_UL_SPACE: pImpl->RemoveULSpace(); break; + case RES_SURROUND: pImpl->RemoveSurround();break; + case RES_OPAQUE : pImpl->SetOpaque(false); break; + case FN_TEXT_RANGE : + break; + // #i26791# + case RES_FOLLOW_TEXT_FLOW: { - case RES_ANCHOR: pImpl->RemoveAnchor(); break; - case RES_HORI_ORIENT: pImpl->RemoveHOrient(); break; - case RES_VERT_ORIENT: pImpl->RemoveVOrient(); break; - case RES_LR_SPACE: pImpl->RemoveLRSpace(); break; - case RES_UL_SPACE: pImpl->RemoveULSpace(); break; - case RES_SURROUND: pImpl->RemoveSurround();break; - case RES_OPAQUE : pImpl->SetOpaque(false); break; - case FN_TEXT_RANGE : - break; - // #i26791# - case RES_FOLLOW_TEXT_FLOW: - { - pImpl->RemoveFollowTextFlow(); - } - break; - // #i28701# - case RES_WRAP_INFLUENCE_ON_OBJPOS: - { - pImpl->RemoveWrapInfluenceOnObjPos(); - } - break; + pImpl->RemoveFollowTextFlow(); } + break; + // #i28701# + case RES_WRAP_INFLUENCE_ON_OBJPOS: + { + pImpl->RemoveWrapInfluenceOnObjPos(); + } + break; } } - else - { - const uno::Type& rPStateType = cppu::UnoType<XPropertyState>::get(); - uno::Any aPState = xShapeAgg->queryAggregation(rPStateType); - auto xShapePrState = o3tl::tryAccess<uno::Reference<XPropertyState>>( - aPState); - if(!xShapePrState) - throw uno::RuntimeException(); - (*xShapePrState)->setPropertyToDefault( rPropertyName ); - } } else - throw uno::RuntimeException(); + { + const uno::Type& rPStateType = cppu::UnoType<XPropertyState>::get(); + uno::Any aPState = xShapeAgg->queryAggregation(rPStateType); + auto xShapePrState = o3tl::tryAccess<uno::Reference<XPropertyState>>( + aPState); + if(!xShapePrState) + throw uno::RuntimeException(); + (*xShapePrState)->setPropertyToDefault( rPropertyName ); + } + } uno::Any SwXShape::getPropertyDefault( const OUString& rPropertyName ) @@ -1936,33 +1932,31 @@ uno::Any SwXShape::getPropertyDefault( const OUString& rPropertyName ) SolarMutexGuard aGuard; SwFrameFormat* pFormat = GetFrameFormat(); uno::Any aRet; - if(xShapeAgg.is()) + if(!xShapeAgg.is()) + throw uno::RuntimeException(); + + const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName ); + if(pEntry) { - const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap().getByName( rPropertyName ); - if(pEntry) - { - if(pEntry->nWID < RES_FRMATR_END && pFormat) - { - const SfxPoolItem& rDefItem = - pFormat->GetDoc()->GetAttrPool().GetDefaultItem(pEntry->nWID); - rDefItem.QueryValue(aRet, pEntry->nMemberId); - } - else - throw uno::RuntimeException(); - } - else - { - const uno::Type& rPStateType = cppu::UnoType<XPropertyState>::get(); - uno::Any aPState = xShapeAgg->queryAggregation(rPStateType); - auto xShapePrState = o3tl::tryAccess<uno::Reference<XPropertyState>>( - aPState); - if(!xShapePrState) - throw uno::RuntimeException(); - (*xShapePrState)->getPropertyDefault( rPropertyName ); - } + if(!(pEntry->nWID < RES_FRMATR_END && pFormat)) + throw uno::RuntimeException(); + + const SfxPoolItem& rDefItem = + pFormat->GetDoc()->GetAttrPool().GetDefaultItem(pEntry->nWID); + rDefItem.QueryValue(aRet, pEntry->nMemberId); + } else - throw uno::RuntimeException(); + { + const uno::Type& rPStateType = cppu::UnoType<XPropertyState>::get(); + uno::Any aPState = xShapeAgg->queryAggregation(rPStateType); + auto xShapePrState = o3tl::tryAccess<uno::Reference<XPropertyState>>( + aPState); + if(!xShapePrState) + throw uno::RuntimeException(); + (*xShapePrState)->getPropertyDefault( rPropertyName ); + } + return aRet; } @@ -2740,58 +2734,58 @@ void SwXGroupShape::add( const uno::Reference< XShape >& xShape ) SolarMutexGuard aGuard; SvxShape* pSvxShape = GetSvxShape(); SwFrameFormat* pFormat = GetFrameFormat(); - if(pSvxShape && pFormat) + if(!(pSvxShape && pFormat)) + throw uno::RuntimeException(); + + uno::Reference<XShapes> xShapes; + if( xShapeAgg.is() ) { - uno::Reference<XShapes> xShapes; - if( xShapeAgg.is() ) - { - const uno::Type& rType = cppu::UnoType<XShapes>::get(); - uno::Any aAgg = xShapeAgg->queryAggregation( rType ); - aAgg >>= xShapes; - } - if(xShapes.is()) - xShapes->add(xShape); - else - throw uno::RuntimeException(); + const uno::Type& rType = cppu::UnoType<XShapes>::get(); + uno::Any aAgg = xShapeAgg->queryAggregation( rType ); + aAgg >>= xShapes; + } + if(!xShapes.is()) + throw uno::RuntimeException(); - uno::Reference<lang::XUnoTunnel> xTunnel(xShape, uno::UNO_QUERY); - SwXShape* pSwShape = nullptr; - if(xShape.is()) - pSwShape = reinterpret_cast< SwXShape * >( - sal::static_int_cast< sal_IntPtr >( xTunnel->getSomething(SwXShape::getUnoTunnelId()) )); - if(pSwShape && pSwShape->m_bDescriptor) + xShapes->add(xShape); + + + uno::Reference<lang::XUnoTunnel> xTunnel(xShape, uno::UNO_QUERY); + SwXShape* pSwShape = nullptr; + if(xShape.is()) + pSwShape = reinterpret_cast< SwXShape * >( + sal::static_int_cast< sal_IntPtr >( xTunnel->getSomething(SwXShape::getUnoTunnelId()) )); + if(pSwShape && pSwShape->m_bDescriptor) + { + SvxShape* pAddShape = reinterpret_cast< SvxShape * >( + sal::static_int_cast< sal_IntPtr >( xTunnel->getSomething(SvxShape::getUnoTunnelId()) )); + if(pAddShape) { - SvxShape* pAddShape = reinterpret_cast< SvxShape * >( - sal::static_int_cast< sal_IntPtr >( xTunnel->getSomething(SvxShape::getUnoTunnelId()) )); - if(pAddShape) + SdrObject* pObj = pAddShape->GetSdrObject(); + if(pObj) { - SdrObject* pObj = pAddShape->GetSdrObject(); - if(pObj) + SwDoc* pDoc = pFormat->GetDoc(); + // set layer of new drawing + // object to corresponding invisible layer. + if( SdrInventor::FmForm != pObj->GetObjInventor()) { - SwDoc* pDoc = pFormat->GetDoc(); - // set layer of new drawing - // object to corresponding invisible layer. - if( SdrInventor::FmForm != pObj->GetObjInventor()) - { - pObj->SetLayer( pSwShape->pImpl->GetOpaque() - ? pDoc->getIDocumentDrawModelAccess().GetInvisibleHeavenId() - : pDoc->getIDocumentDrawModelAccess().GetInvisibleHellId() ); - } - else - { - pObj->SetLayer(pDoc->getIDocumentDrawModelAccess().GetInvisibleControlsId()); - } + pObj->SetLayer( pSwShape->pImpl->GetOpaque() + ? pDoc->getIDocumentDrawModelAccess().GetInvisibleHeavenId() + : pDoc->getIDocumentDrawModelAccess().GetInvisibleHellId() ); + } + else + { + pObj->SetLayer(pDoc->getIDocumentDrawModelAccess().GetInvisibleControlsId()); } } - pSwShape->m_bDescriptor = false; - //add the group member to the format of the group - SwFrameFormat* pShapeFormat = ::FindFrameFormat( pSvxShape->GetSdrObject() ); - if(pShapeFormat) - pFormat->Add(pSwShape); } + pSwShape->m_bDescriptor = false; + //add the group member to the format of the group + SwFrameFormat* pShapeFormat = ::FindFrameFormat( pSvxShape->GetSdrObject() ); + if(pShapeFormat) + pFormat->Add(pSwShape); } - else - throw uno::RuntimeException(); + } void SwXGroupShape::remove( const uno::Reference< XShape >& xShape ) diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx index bee8055a0fa6..0b0d8d0859a1 100644 --- a/sw/source/core/unocore/unofield.cxx +++ b/sw/source/core/unocore/unofield.cxx @@ -610,21 +610,20 @@ void SAL_CALL SwXFieldMaster::setPropertyValue( // Thus the last property set will be used as Data Source. const sal_uInt16 nMemberValueId = GetFieldTypeMId( rPropertyName, *pType ); - if ( USHRT_MAX != nMemberValueId ) - { - pType->PutValue( rValue, nMemberValueId ); - if ( pType->Which() == SwFieldIds::User ) - { - // trigger update of User field in order to get depending Input Fields updated. - pType->UpdateFields(); - } - } - else + if ( USHRT_MAX == nMemberValueId ) { throw beans::UnknownPropertyException( "Unknown property: " + rPropertyName, static_cast< cppu::OWeakObject * >( this ) ); } + + pType->PutValue( rValue, nMemberValueId ); + if ( pType->Which() == SwFieldIds::User ) + { + // trigger update of User field in order to get depending Input Fields updated. + pType->UpdateFields(); + } + } } else if (!pType && m_pImpl->m_pDoc && rPropertyName == UNO_NAME_NAME) @@ -1925,26 +1924,25 @@ void SAL_CALL SwXTextField::attach( SwTextAttr* pTextAttr = aPam.GetNode().GetTextNode()->GetFieldTextAttrAt( aPam.GetPoint()->nContent.GetIndex()-1, true ); // What about updating the fields? (see fldmgr.cxx) - if (pTextAttr) - { - const SwFormatField& rField = pTextAttr->GetFormatField(); - m_pImpl->m_pFormatField = &rField; + if (!pTextAttr) + throw uno::RuntimeException("no SwTextAttr inserted?"); // could theoretically happen, if paragraph is full - if ( pTextAttr->Which() == RES_TXTATR_ANNOTATION - && *aPam.GetPoint() != *aPam.GetMark() ) + const SwFormatField& rField = pTextAttr->GetFormatField(); + m_pImpl->m_pFormatField = &rField; + + if ( pTextAttr->Which() == RES_TXTATR_ANNOTATION + && *aPam.GetPoint() != *aPam.GetMark() ) + { + // create annotation mark + const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pTextAttr->GetFormatField().GetField()); + OSL_ENSURE( pPostItField != nullptr, "<SwXTextField::attachToRange(..)> - annotation field missing!" ); + if ( pPostItField != nullptr ) { - // create annotation mark - const SwPostItField* pPostItField = dynamic_cast< const SwPostItField* >(pTextAttr->GetFormatField().GetField()); - OSL_ENSURE( pPostItField != nullptr, "<SwXTextField::attachToRange(..)> - annotation field missing!" ); - if ( pPostItField != nullptr ) - { - IDocumentMarkAccess* pMarksAccess = pDoc->getIDocumentMarkAccess(); - pMarksAccess->makeAnnotationMark( aPam, pPostItField->GetName() ); - } + IDocumentMarkAccess* pMarksAccess = pDoc->getIDocumentMarkAccess(); + pMarksAccess->makeAnnotationMark( aPam, pPostItField->GetName() ); } } - else // could theoretically happen, if paragraph is full - throw uno::RuntimeException("no SwTextAttr inserted?"); + } delete pField; @@ -1966,52 +1964,51 @@ void SAL_CALL SwXTextField::attach( && m_pImpl->m_nServiceId == SwServiceType::FieldTypeAnnotation ) { SwUnoInternalPaM aIntPam( *m_pImpl->m_pDoc ); - if ( ::sw::XTextRangeToSwPaM( aIntPam, xTextRange ) ) - { - // nothing to do, if the text range only covers the former annotation field - if ( aIntPam.Start()->nNode != aIntPam.End()->nNode - || aIntPam.Start()->nContent.GetIndex() != aIntPam.End()->nContent.GetIndex()-1 ) + if ( !::sw::XTextRangeToSwPaM( aIntPam, xTextRange ) ) + throw lang::IllegalArgumentException(); + + // nothing to do, if the text range only covers the former annotation field + if ( aIntPam.Start()->nNode != aIntPam.End()->nNode + || aIntPam.Start()->nContent.GetIndex() != aIntPam.End()->nContent.GetIndex()-1 ) + { + UnoActionContext aCont( m_pImpl->m_pDoc ); + // insert copy of annotation at new text range + SwPostItField* pPostItField = static_cast< SwPostItField* >(m_pImpl->m_pFormatField->GetField()->CopyField()); + SwFormatField aFormatField( *pPostItField ); + delete pPostItField; + SwPaM aEnd( *aIntPam.End(), *aIntPam.End() ); + m_pImpl->m_pDoc->getIDocumentContentOperations().InsertPoolItem( aEnd, aFormatField ); + // delete former annotation { - UnoActionContext aCont( m_pImpl->m_pDoc ); - // insert copy of annotation at new text range - SwPostItField* pPostItField = static_cast< SwPostItField* >(m_pImpl->m_pFormatField->GetField()->CopyField()); - SwFormatField aFormatField( *pPostItField ); - delete pPostItField; - SwPaM aEnd( *aIntPam.End(), *aIntPam.End() ); - m_pImpl->m_pDoc->getIDocumentContentOperations().InsertPoolItem( aEnd, aFormatField ); - // delete former annotation - { - const SwTextField* pTextField = m_pImpl->m_pFormatField->GetTextField(); - SwTextNode& rTextNode = *pTextField->GetpTextNode(); - SwPaM aPam( rTextNode, pTextField->GetStart() ); - aPam.SetMark(); - aPam.Move(); - m_pImpl->m_pDoc->getIDocumentContentOperations().DeleteAndJoin(aPam); - } - // keep inserted annotation + const SwTextField* pTextField = m_pImpl->m_pFormatField->GetTextField(); + SwTextNode& rTextNode = *pTextField->GetpTextNode(); + SwPaM aPam( rTextNode, pTextField->GetStart() ); + aPam.SetMark(); + aPam.Move(); + m_pImpl->m_pDoc->getIDocumentContentOperations().DeleteAndJoin(aPam); + } + // keep inserted annotation + { + SwTextField* pTextAttr = aEnd.GetNode().GetTextNode()->GetFieldTextAttrAt( aEnd.End()->nContent.GetIndex()-1, true ); + if ( pTextAttr != nullptr ) { - SwTextField* pTextAttr = aEnd.GetNode().GetTextNode()->GetFieldTextAttrAt( aEnd.End()->nContent.GetIndex()-1, true ); - if ( pTextAttr != nullptr ) - { - m_pImpl->m_pFormatField = &pTextAttr->GetFormatField(); + m_pImpl->m_pFormatField = &pTextAttr->GetFormatField(); - if ( *aIntPam.GetPoint() != *aIntPam.GetMark() ) + if ( *aIntPam.GetPoint() != *aIntPam.GetMark() ) + { + // create annotation mark + const SwPostItField* pField = dynamic_cast< const SwPostItField* >(pTextAttr->GetFormatField().GetField()); + OSL_ENSURE( pField != nullptr, "<SwXTextField::attach(..)> - annotation field missing!" ); + if ( pField != nullptr ) { - // create annotation mark - const SwPostItField* pField = dynamic_cast< const SwPostItField* >(pTextAttr->GetFormatField().GetField()); - OSL_ENSURE( pField != nullptr, "<SwXTextField::attach(..)> - annotation field missing!" ); - if ( pField != nullptr ) - { - IDocumentMarkAccess* pMarksAccess = aIntPam.GetDoc()->getIDocumentMarkAccess(); - pMarksAccess->makeAnnotationMark( aIntPam, pField->GetName() ); - } + IDocumentMarkAccess* pMarksAccess = aIntPam.GetDoc()->getIDocumentMarkAccess(); + pMarksAccess->makeAnnotationMark( aIntPam, pField->GetName() ); } } } } } - else - throw lang::IllegalArgumentException(); + } else throw lang::IllegalArgumentException(); @@ -2251,10 +2248,11 @@ SwXTextField::setPropertyValue( } if (pBool) { - if( auto b = o3tl::tryAccess<bool>(rValue) ) - *pBool = *b; - else + auto b = o3tl::tryAccess<bool>(rValue); + if( !b ) throw lang::IllegalArgumentException(); + *pBool = *b; + } } else diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx index 9b33f94a1387..87828b3eb23e 100644 --- a/sw/source/core/unocore/unoframe.cxx +++ b/sw/source/core/unocore/unoframe.cxx @@ -1498,11 +1498,11 @@ void SwXFrame::setPropertyValue(const OUString& rPropertyName, const ::uno::Any& // is no contour, or if the contour has been set by the // API itself (or in other words, if the contour isn't // used already). - if( !pNoText->HasContour_() || - !pNoText->IsContourMapModeValid() ) - pNoText->SetPixelContour( *o3tl::doAccess<bool>(aValue) ); - else + if( pNoText->HasContour_() && pNoText->IsContourMapModeValid() ) throw lang::IllegalArgumentException(); + + pNoText->SetPixelContour( *o3tl::doAccess<bool>(aValue) ); + } else { @@ -1535,45 +1535,44 @@ void SwXFrame::setPropertyValue(const OUString& rPropertyName, const ::uno::Any& else if(FN_UNO_FRAME_STYLE_NAME == pEntry->nWID) { SwFrameFormat *pFrameFormat = lcl_GetFrameFormat( aValue, pFormat->GetDoc() ); - if( pFrameFormat ) - { - UnoActionContext aAction(pFormat->GetDoc()); + if( !pFrameFormat ) + throw lang::IllegalArgumentException(); - SfxItemSet* pSet = nullptr; - // #i31771#, #i25798# - No adjustment of - // anchor ( no call of method <sw_ChkAndSetNewAnchor(..)> ), - // if document is currently in reading mode. - if ( !pFormat->GetDoc()->IsInReading() ) + UnoActionContext aAction(pFormat->GetDoc()); + + SfxItemSet* pSet = nullptr; + // #i31771#, #i25798# - No adjustment of + // anchor ( no call of method <sw_ChkAndSetNewAnchor(..)> ), + // if document is currently in reading mode. + if ( !pFormat->GetDoc()->IsInReading() ) + { + // see SwFEShell::SetFrameFormat( SwFrameFormat *pNewFormat, bool bKeepOrient, Point* pDocPos ) + SwFlyFrame *pFly = nullptr; { - // see SwFEShell::SetFrameFormat( SwFrameFormat *pNewFormat, bool bKeepOrient, Point* pDocPos ) - SwFlyFrame *pFly = nullptr; - { - const SwFrameFormat* pFormatXX = pFormat; - if (dynamic_cast<const SwFlyFrameFormat*>( pFormatXX) ) - pFly = static_cast<const SwFlyFrameFormat*>(pFormatXX)->GetFrame(); - } - if ( pFly ) + const SwFrameFormat* pFormatXX = pFormat; + if (dynamic_cast<const SwFlyFrameFormat*>( pFormatXX) ) + pFly = static_cast<const SwFlyFrameFormat*>(pFormatXX)->GetFrame(); + } + if ( pFly ) + { + const ::SfxPoolItem* pItem; + if( SfxItemState::SET == pFrameFormat->GetItemState( RES_ANCHOR, false, &pItem )) { - const ::SfxPoolItem* pItem; - if( SfxItemState::SET == pFrameFormat->GetItemState( RES_ANCHOR, false, &pItem )) + pSet = new SfxItemSet( pDoc->GetAttrPool(), aFrameFormatSetRange ); + pSet->Put( *pItem ); + if ( pFormat->GetDoc()->GetEditShell() != nullptr + && !sw_ChkAndSetNewAnchor( *pFly, *pSet ) ) { - pSet = new SfxItemSet( pDoc->GetAttrPool(), aFrameFormatSetRange ); - pSet->Put( *pItem ); - if ( pFormat->GetDoc()->GetEditShell() != nullptr - && !sw_ChkAndSetNewAnchor( *pFly, *pSet ) ) - { - delete pSet; - pSet = nullptr; - } + delete pSet; + pSet = nullptr; } } } - - pFormat->GetDoc()->SetFrameFormatToFly( *pFormat, *pFrameFormat, pSet ); - delete pSet; } - else - throw lang::IllegalArgumentException(); + + pFormat->GetDoc()->SetFrameFormatToFly( *pFormat, *pFrameFormat, pSet ); + delete pSet; + } else if( FN_UNO_GRAPHIC_U_R_L == pEntry->nWID || FN_UNO_GRAPHIC_FILTER == pEntry->nWID) @@ -2569,19 +2568,18 @@ uno::Any SwXFrame::getPropertyDefault( const OUString& rPropertyName ) if(pFormat) { const SfxItemPropertySimpleEntry* pEntry = m_pPropSet->getPropertyMap().getByName(rPropertyName); - if(pEntry) + if(!pEntry) + throw beans::UnknownPropertyException( "Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) ); + + if ( pEntry->nWID < RES_FRMATR_END ) { - if ( pEntry->nWID < RES_FRMATR_END ) - { - const SfxPoolItem& rDefItem = - pFormat->GetDoc()->GetAttrPool().GetDefaultItem(pEntry->nWID); - const sal_uInt8 nMemberId(pEntry->nMemberId & (~SFX_METRIC_ITEM)); + const SfxPoolItem& rDefItem = + pFormat->GetDoc()->GetAttrPool().GetDefaultItem(pEntry->nWID); + const sal_uInt8 nMemberId(pEntry->nMemberId & (~SFX_METRIC_ITEM)); - rDefItem.QueryValue(aRet, nMemberId); - } + rDefItem.QueryValue(aRet, nMemberId); } - else - throw beans::UnknownPropertyException( "Unknown property: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) ); + } else if(!IsDescriptor()) throw uno::RuntimeException(); @@ -2655,20 +2653,19 @@ uno::Reference< text::XTextRange > SwXFrame::getAnchor() SolarMutexGuard aGuard; uno::Reference< text::XTextRange > aRef; SwFrameFormat* pFormat = GetFrameFormat(); - if(pFormat) + if(!pFormat) + throw uno::RuntimeException(); + + const SwFormatAnchor& rAnchor = pFormat->GetAnchor(); + // return an anchor for non-page bound frames + // and for page bound frames that have a page no == NULL and a content position + if ((rAnchor.GetAnchorId() != RndStdIds::FLY_AT_PAGE) || + (rAnchor.GetContentAnchor() && !rAnchor.GetPageNum())) { - const SwFormatAnchor& rAnchor = pFormat->GetAnchor(); - // return an anchor for non-page bound frames - // and for page bound frames that have a page no == NULL and a content position - if ((rAnchor.GetAnchorId() != RndStdIds::FLY_AT_PAGE) || - (rAnchor.GetContentAnchor() && !rAnchor.GetPageNum())) - { - const SwPosition &rPos = *(rAnchor.GetContentAnchor()); - aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), rPos, nullptr); - } + const SwPosition &rPos = *(rAnchor.GetContentAnchor()); + aRef = SwXTextRange::CreateXTextRange(*pFormat->GetDoc(), rPos, nullptr); } - else - throw uno::RuntimeException(); + return aRef; } @@ -2697,379 +2694,378 @@ void SwXFrame::attachToRange(const uno::Reference< text::XTextRange > & xTextRan } SwDoc* pDoc = pRange ? &pRange->GetDoc() : pCursor ? pCursor->GetDoc() : nullptr; - if(pDoc) + if(!pDoc) + throw lang::IllegalArgumentException(); + + SwUnoInternalPaM aIntPam(*pDoc); + // this now needs to return TRUE + ::sw::XTextRangeToSwPaM(aIntPam, xTextRange); + + SwNode& rNode = pDoc->GetNodes().GetEndOfContent(); + SwPaM aPam(rNode); + aPam.Move( fnMoveBackward, GoInDoc ); + static sal_uInt16 const aFrameAttrRange[] = { - SwUnoInternalPaM aIntPam(*pDoc); - // this now needs to return TRUE - ::sw::XTextRangeToSwPaM(aIntPam, xTextRange); + RES_FRMATR_BEGIN, RES_FRMATR_END-1, + RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER, - SwNode& rNode = pDoc->GetNodes().GetEndOfContent(); - SwPaM aPam(rNode); - aPam.Move( fnMoveBackward, GoInDoc ); - static sal_uInt16 const aFrameAttrRange[] = - { - RES_FRMATR_BEGIN, RES_FRMATR_END-1, - RES_UNKNOWNATR_CONTAINER, RES_UNKNOWNATR_CONTAINER, + // FillAttribute support + XATTR_FILL_FIRST, XATTR_FILL_LAST, - // FillAttribute support - XATTR_FILL_FIRST, XATTR_FILL_LAST, + SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER, + 0 + }; + static sal_uInt16 const aGrAttrRange[] = + { + RES_GRFATR_BEGIN, RES_GRFATR_END-1, + 0 + }; + SfxItemSet aGrSet(pDoc->GetAttrPool(), aGrAttrRange ); - SID_ATTR_BORDER_INNER, SID_ATTR_BORDER_INNER, - 0 - }; - static sal_uInt16 const aGrAttrRange[] = - { - RES_GRFATR_BEGIN, RES_GRFATR_END-1, - 0 - }; - SfxItemSet aGrSet(pDoc->GetAttrPool(), aGrAttrRange ); + SfxItemSet aFrameSet(pDoc->GetAttrPool(), aFrameAttrRange ); - SfxItemSet aFrameSet(pDoc->GetAttrPool(), aFrameAttrRange ); + // set correct parent to get the XFILL_NONE FillStyle as needed + aFrameSet.SetParent(&pDoc->GetDfltFrameFormat()->GetAttrSet()); - // set correct parent to get the XFILL_NONE FillStyle as needed - aFrameSet.SetParent(&pDoc->GetDfltFrameFormat()->GetAttrSet()); + // no the related items need to be added to the set + bool bSizeFound; + if(!pProps->AnyToItemSet( pDoc, aFrameSet, aGrSet, bSizeFound)) + throw lang::IllegalArgumentException(); + // a TextRange is handled separately + *aPam.GetPoint() = *aIntPam.GetPoint(); + if(aIntPam.HasMark()) + { + aPam.SetMark(); + *aPam.GetMark() = *aIntPam.GetMark(); + } - // no the related items need to be added to the set - bool bSizeFound; - if(!pProps->AnyToItemSet( pDoc, aFrameSet, aGrSet, bSizeFound)) - throw lang::IllegalArgumentException(); - // a TextRange is handled separately - *aPam.GetPoint() = *aIntPam.GetPoint(); - if(aIntPam.HasMark()) + const SfxPoolItem* pItem; + RndStdIds eAnchorId = RndStdIds::FLY_AT_PARA; + if(SfxItemState::SET == aFrameSet.GetItemState(RES_ANCHOR, false, &pItem) ) + { + eAnchorId = static_cast<const SwFormatAnchor*>(pItem)->GetAnchorId(); + if( RndStdIds::FLY_AT_FLY == eAnchorId && + !aPam.GetNode().FindFlyStartNode()) { - aPam.SetMark(); - *aPam.GetMark() = *aIntPam.GetMark(); + // framebound only where a frame exists + SwFormatAnchor aAnchor(RndStdIds::FLY_AT_PARA); + aFrameSet.Put(aAnchor); } - - const SfxPoolItem* pItem; - RndStdIds eAnchorId = RndStdIds::FLY_AT_PARA; - if(SfxItemState::SET == aFrameSet.GetItemState(RES_ANCHOR, false, &pItem) ) + else if ((RndStdIds::FLY_AT_PAGE == eAnchorId) && + 0 == static_cast<const SwFormatAnchor*>(pItem)->GetPageNum() ) { - eAnchorId = static_cast<const SwFormatAnchor*>(pItem)->GetAnchorId(); - if( RndStdIds::FLY_AT_FLY == eAnchorId && - !aPam.GetNode().FindFlyStartNode()) - { - // framebound only where a frame exists - SwFormatAnchor aAnchor(RndStdIds::FLY_AT_PARA); - aFrameSet.Put(aAnchor); - } - else if ((RndStdIds::FLY_AT_PAGE == eAnchorId) && - 0 == static_cast<const SwFormatAnchor*>(pItem)->GetPageNum() ) - { - SwFormatAnchor aAnchor( *static_cast<const SwFormatAnchor*>(pItem) ); - aAnchor.SetAnchor( aPam.GetPoint() ); - aFrameSet.Put(aAnchor); - } + SwFormatAnchor aAnchor( *static_cast<const SwFormatAnchor*>(pItem) ); + aAnchor.SetAnchor( aPam.GetPoint() ); + aFrameSet.Put(aAnchor); } + } - const ::uno::Any* pStyle; - SwFrameFormat *pParentFrameFormat = nullptr; - if(pProps->GetProperty(FN_UNO_FRAME_STYLE_NAME, 0, pStyle)) - pParentFrameFormat = lcl_GetFrameFormat( *pStyle, pDoc ); + const ::uno::Any* pStyle; + SwFrameFormat *pParentFrameFormat = nullptr; + if(pProps->GetProperty(FN_UNO_FRAME_STYLE_NAME, 0, pStyle)) + pParentFrameFormat = lcl_GetFrameFormat( *pStyle, pDoc ); - SwFlyFrameFormat* pFormat = nullptr; - if( eType == FLYCNTTYPE_FRM) + SwFlyFrameFormat* pFormat = nullptr; + if( eType == FLYCNTTYPE_FRM) + { + UnoActionContext aCont(pDoc); + if(m_pCopySource) { - UnoActionContext aCont(pDoc); - if(m_pCopySource) - { - SwFormatAnchor* pAnchorItem = nullptr; - // the frame is inserted bound to page - // to prevent conflicts if the to-be-anchored position is part of the to-be-copied text - if (eAnchorId != RndStdIds::FLY_AT_PAGE) - { - pAnchorItem = static_cast<SwFormatAnchor*>(aFrameSet.Get(RES_ANCHOR).Clone()); - aFrameSet.Put( SwFormatAnchor( RndStdIds::FLY_AT_PAGE, 1 )); - } - - aPam.DeleteMark(); // mark position node will be deleted! - aIntPam.DeleteMark(); // mark position node will be deleted! - pFormat = pDoc->MakeFlyAndMove( *m_pCopySource, aFrameSet, - nullptr, - pParentFrameFormat ); - if(pAnchorItem && pFormat) - { - pFormat->DelFrames(); - pAnchorItem->SetAnchor( m_pCopySource->Start() ); - SfxItemSet aAnchorSet( pDoc->GetAttrPool(), svl::Items<RES_ANCHOR, RES_ANCHOR>{} ); - aAnchorSet.Put( *pAnchorItem ); - pDoc->SetFlyFrameAttr( *pFormat, aAnchorSet ); - delete pAnchorItem; - } - DELETEZ( m_pCopySource ); - } - else + SwFormatAnchor* pAnchorItem = nullptr; + // the frame is inserted bound to page + // to prevent conflicts if the to-be-anchored position is part of the to-be-copied text + if (eAnchorId != RndStdIds::FLY_AT_PAGE) { - pFormat = pDoc->MakeFlySection( RndStdIds::FLY_AT_PARA, aPam.GetPoint(), - &aFrameSet, pParentFrameFormat ); + pAnchorItem = static_cast<SwFormatAnchor*>(aFrameSet.Get(RES_ANCHOR).Clone()); + aFrameSet.Put( SwFormatAnchor( RndStdIds::FLY_AT_PAGE, 1 )); } - if(pFormat) + + aPam.DeleteMark(); // mark position node will be deleted! + aIntPam.DeleteMark(); // mark position node will be deleted! + pFormat = pDoc->MakeFlyAndMove( *m_pCopySource, aFrameSet, + nullptr, + pParentFrameFormat ); + if(pAnchorItem && pFormat) { - pFormat->Add(this); - if(!m_sName.isEmpty()) - pDoc->SetFlyName(*pFormat, m_sName); + pFormat->DelFrames(); + pAnchorItem->SetAnchor( m_pCopySource->Start() ); + SfxItemSet aAnchorSet( pDoc->GetAttrPool(), svl::Items<RES_ANCHOR, RES_ANCHOR>{} ); + aAnchorSet.Put( *pAnchorItem ); + pDoc->SetFlyFrameAttr( *pFormat, aAnchorSet ); + delete pAnchorItem; } - // wake up the SwXTextFrame - static_cast<SwXTextFrame*>(this)->SetDoc( bIsDescriptor ? m_pDoc : GetFrameFormat()->GetDoc() ); + DELETEZ( m_pCopySource ); } - else if( eType == FLYCNTTYPE_GRF) + else { - UnoActionContext aCont(pDoc); - const ::uno::Any* pGraphicURL; - OUString sGraphicURL; - GraphicObject *pGrfObj = nullptr; - if(pProps->GetProperty(FN_UNO_GRAPHIC_U_R_L, 0, pGraphicURL)) - { - (*pGraphicURL) >>= sGraphicURL; - if( sGraphicURL.startsWith(sPackageProtocol) ) - { - pGrfObj = new GraphicObject; - pGrfObj->SetUserData( sGraphicURL ); - sGraphicURL.clear(); - } - else if( sGraphicURL.startsWith(sGraphicObjectProtocol) ) - { - OString sId(OUStringToOString( - sGraphicURL.copy( sizeof(sGraphicObjectProtocol)-1 ), - RTL_TEXTENCODING_ASCII_US)); - pGrfObj = new GraphicObject( sId ); - sGraphicURL.clear(); - } - } - Graphic aGraphic; - const ::uno::Any* pGraphic; - if( pProps->GetProperty( FN_UNO_GRAPHIC, 0, pGraphic )) + pFormat = pDoc->MakeFlySection( RndStdIds::FLY_AT_PARA, aPam.GetPoint(), + &aFrameSet, pParentFrameFormat ); + } + if(pFormat) + { + pFormat->Add(this); + if(!m_sName.isEmpty()) + pDoc->SetFlyName(*pFormat, m_sName); + } + // wake up the SwXTextFrame + static_cast<SwXTextFrame*>(this)->SetDoc( bIsDescriptor ? m_pDoc : GetFrameFormat()->GetDoc() ); + } + else if( eType == FLYCNTTYPE_GRF) + { + UnoActionContext aCont(pDoc); + const ::uno::Any* pGraphicURL; + OUString sGraphicURL; + GraphicObject *pGrfObj = nullptr; + if(pProps->GetProperty(FN_UNO_GRAPHIC_U_R_L, 0, pGraphicURL)) + { + (*pGraphicURL) >>= sGraphicURL; + if( sGraphicURL.startsWith(sPackageProtocol) ) { - uno::Reference< graphic::XGraphic > xGraphic; - (*pGraphic) >>= xGraphic; - aGraphic = Graphic( xGraphic ); + pGrfObj = new GraphicObject; + pGrfObj->SetUserData( sGraphicURL ); + sGraphicURL.clear(); } - - OUString sFltName; - const ::uno::Any* pFilter; - if(pProps->GetProperty(FN_UNO_GRAPHIC_FILTER, 0, pFilter)) + else if( sGraphicURL.startsWith(sGraphicObjectProtocol) ) { - (*pFilter) >>= sFltName; + OString sId(OUStringToOString( + sGraphicURL.copy( sizeof(sGraphicObjectProtocol)-1 ), + RTL_TEXTENCODING_ASCII_US)); + pGrfObj = new GraphicObject( sId ); + sGraphicURL.clear(); } - - pFormat = (pGrfObj) - ? pDoc->getIDocumentContentOperations().InsertGraphicObject( - aPam, *pGrfObj, &aFrameSet, &aGrSet, pParentFrameFormat) - : pDoc->getIDocumentContentOperations().InsertGraphic( - aPam, sGraphicURL, sFltName, &aGraphic, - &aFrameSet, &aGrSet, pParentFrameFormat); - delete pGrfObj; - if(pFormat) - { - SwGrfNode *pGrfNd = pDoc->GetNodes()[ pFormat->GetContent().GetContentIdx() - ->GetIndex()+1 ]->GetGrfNode(); - if (pGrfNd) - pGrfNd->SetChgTwipSize( !bSizeFound ); - pFormat->Add(this); - if(!m_sName.isEmpty()) - pDoc->SetFlyName(*pFormat, m_sName); - - } - const ::uno::Any* pSurroundContour; - if(pProps->GetProperty(RES_SURROUND, MID_SURROUND_CONTOUR, pSurroundContour)) - setPropertyValue(UNO_NAME_SURROUND_CONTOUR, *pSurroundContour); - const ::uno::Any* pContourOutside; - if(pProps->GetProperty(RES_SURROUND, MID_SURROUND_CONTOUROUTSIDE, pContourOutside)) - setPropertyValue(UNO_NAME_CONTOUR_OUTSIDE, *pContourOutside); - const ::uno::Any* pContourPoly; - if(pProps->GetProperty(FN_PARAM_CONTOUR_PP, 0, pContourPoly)) - setPropertyValue(UNO_NAME_CONTOUR_POLY_POLYGON, *pContourPoly); - const ::uno::Any* pPixelContour; - if(pProps->GetProperty(FN_UNO_IS_PIXEL_CONTOUR, 0, pPixelContour)) - setPropertyValue(UNO_NAME_IS_PIXEL_CONTOUR, *pPixelContour); - const ::uno::Any* pAutoContour; - if(pProps->GetProperty(FN_UNO_IS_AUTOMATIC_CONTOUR, 0, pAutoContour)) - setPropertyValue(UNO_NAME_IS_AUTOMATIC_CONTOUR, *pAutoContour); } - else + Graphic aGraphic; + const ::uno::Any* pGraphic; + if( pProps->GetProperty( FN_UNO_GRAPHIC, 0, pGraphic )) { - const ::uno::Any* pCLSID = nullptr; - const ::uno::Any* pStreamName = nullptr; - const ::uno::Any* pEmbeddedObject = nullptr; - if(!pProps->GetProperty(FN_UNO_CLSID, 0, pCLSID) - && !pProps->GetProperty( FN_UNO_STREAM_NAME, 0, pStreamName ) - && !pProps->GetProperty( FN_EMBEDDED_OBJECT, 0, pEmbeddedObject )) - throw uno::RuntimeException(); - if(pCLSID) - { - OUString aCLSID; - SvGlobalName aClassName; - uno::Reference < embed::XEmbeddedObject > xIPObj; - std::unique_ptr < comphelper::EmbeddedObjectContainer > pCnt; - if( (*pCLSID) >>= aCLSID ) + uno::Reference< graphic::XGraphic > xGraphic; + (*pGraphic) >>= xGraphic; + aGraphic = Graphic( xGraphic ); + } + + OUString sFltName; + const ::uno::Any* pFilter; + if(pProps->GetProperty(FN_UNO_GRAPHIC_FILTER, 0, pFilter)) + { + (*pFilter) >>= sFltName; + } + + pFormat = (pGrfObj) + ? pDoc->getIDocumentContentOperations().InsertGraphicObject( + aPam, *pGrfObj, &aFrameSet, &aGrSet, pParentFrameFormat) + : pDoc->getIDocumentContentOperations().InsertGraphic( + aPam, sGraphicURL, sFltName, &aGraphic, + &aFrameSet, &aGrSet, pParentFrameFormat); + delete pGrfObj; + if(pFormat) + { + SwGrfNode *pGrfNd = pDoc->GetNodes()[ pFormat->GetContent().GetContentIdx() + ->GetIndex()+1 ]->GetGrfNode(); + if (pGrfNd) + pGrfNd->SetChgTwipSize( !bSizeFound ); + pFormat->Add(this); + if(!m_sName.isEmpty()) + pDoc->SetFlyName(*pFormat, m_sName); + + } + const ::uno::Any* pSurroundContour; + if(pProps->GetProperty(RES_SURROUND, MID_SURROUND_CONTOUR, pSurroundContour)) + setPropertyValue(UNO_NAME_SURROUND_CONTOUR, *pSurroundContour); + const ::uno::Any* pContourOutside; + if(pProps->GetProperty(RES_SURROUND, MID_SURROUND_CONTOUROUTSIDE, pContourOutside)) + setPropertyValue(UNO_NAME_CONTOUR_OUTSIDE, *pContourOutside); + const ::uno::Any* pContourPoly; + if(pProps->GetProperty(FN_PARAM_CONTOUR_PP, 0, pContourPoly)) + setPropertyValue(UNO_NAME_CONTOUR_POLY_POLYGON, *pContourPoly); + const ::uno::Any* pPixelContour; + if(pProps->GetProperty(FN_UNO_IS_PIXEL_CONTOUR, 0, pPixelContour)) + setPropertyValue(UNO_NAME_IS_PIXEL_CONTOUR, *pPixelContour); + const ::uno::Any* pAutoContour; + if(pProps->GetProperty(FN_UNO_IS_AUTOMATIC_CONTOUR, 0, pAutoContour)) + setPropertyValue(UNO_NAME_IS_AUTOMATIC_CONTOUR, *pAutoContour); + } + else + { + const ::uno::Any* pCLSID = nullptr; + const ::uno::Any* pStreamName = nullptr; + const ::uno::Any* pEmbeddedObject = nullptr; + if(!pProps->GetProperty(FN_UNO_CLSID, 0, pCLSID) + && !pProps->GetProperty( FN_UNO_STREAM_NAME, 0, pStreamName ) + && !pProps->GetProperty( FN_EMBEDDED_OBJECT, 0, pEmbeddedObject )) + throw uno::RuntimeException(); + if(pCLSID) + { + OUString aCLSID; + SvGlobalName aClassName; + uno::Reference < embed::XEmbeddedObject > xIPObj; + std::unique_ptr < comphelper::EmbeddedObjectContainer > pCnt; + if( (*pCLSID) >>= aCLSID ) + { + if( !aClassName.MakeId( aCLSID ) ) { - if( !aClassName.MakeId( aCLSID ) ) - { - lang::IllegalArgumentException aExcept; - aExcept.Message = "CLSID invalid"; - throw aExcept; - } - - pCnt.reset( new comphelper::EmbeddedObjectContainer ); - OUString aName; - - OUString sDocumentBaseURL = pDoc->GetPersist()->getDocumentBaseURL(); - xIPObj = pCnt->CreateEmbeddedObject(aClassName.GetByteSequence(), aName, - &sDocumentBaseURL); + lang::IllegalArgumentException aExcept; + aExcept.Message = "CLSID invalid"; + throw aExcept; } - if ( xIPObj.is() ) - { - UnoActionContext aAction(pDoc); - pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT, nullptr); - if(!bSizeFound) - { - //TODO/LATER: how do I transport it to the OLENode? - sal_Int64 nAspect = m_nDrawAspect; - // TODO/LEAN: VisualArea still needs running state - svt::EmbeddedObjectRef::TryRunningState( xIPObj ); + pCnt.reset( new comphelper::EmbeddedObjectContainer ); + OUString aName; - // set parent to get correct VisArea(in case of object needing parent printer) - uno::Reference < container::XChild > xChild( xIPObj, uno::UNO_QUERY ); - if ( xChild.is() ) - xChild->setParent( pDoc->GetDocShell()->GetModel() ); - - //The Size should be suggested by the OLE server if not manually set - MapUnit aRefMap = VCLUnoHelper::UnoEmbed2VCLMapUnit( xIPObj->getMapUnit( nAspect ) ); - awt::Size aSize; - try - { - aSize = xIPObj->getVisualAreaSize( nAspect ); - } - catch ( embed::NoVisualAreaSizeException& ) - { - // the default size will be set later - } - - Size aSz( aSize.Width, aSize.Height ); - if ( !aSz.Width() || !aSz.Height() ) - { - aSz.Width() = aSz.Height() = 5000; - aSz = OutputDevice::LogicToLogic - ( aSz, MapMode( MapUnit::Map100thMM ), aRefMap ); - } - MapMode aMyMap( MapUnit::MapTwip ); - aSz = OutputDevice::LogicToLogic( aSz, aRefMap, aMyMap ); - SwFormatFrameSize aFrameSz; - aFrameSz.SetSize(aSz); - aFrameSet.Put(aFrameSz); - } - SwFlyFrameFormat* pFormat2 = nullptr; - - ::svt::EmbeddedObjectRef xObjRef( xIPObj, m_nDrawAspect); - pFormat2 = pDoc->getIDocumentContentOperations().InsertEmbObject( - aPam, xObjRef, &aFrameSet ); - - // store main document name to show in the title bar - uno::Reference< frame::XTitle > xModelTitle( pDoc->GetDocShell()->GetModel(), css::uno::UNO_QUERY ); - if( xModelTitle.is() ) - xIPObj->setContainerName( xModelTitle->getTitle() ); - - assert(pFormat2 && "Doc->Insert(notxt) failed."); - - pDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSERT, nullptr); - pFormat2->Add(this); - if(!m_sName.isEmpty()) - pDoc->SetFlyName(*pFormat2, m_sName); - } + OUString sDocumentBaseURL = pDoc->GetPersist()->getDocumentBaseURL(); + xIPObj = pCnt->CreateEmbeddedObject(aClassName.GetByteSequence(), aName, + &sDocumentBaseURL); } - else if( pStreamName ) + if ( xIPObj.is() ) { - OUString sStreamName; - (*pStreamName) >>= sStreamName; + UnoActionContext aAction(pDoc); pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT, nullptr); + if(!bSizeFound) + { + //TODO/LATER: how do I transport it to the OLENode? + sal_Int64 nAspect = m_nDrawAspect; - SwFlyFrameFormat* pFrameFormat = nullptr; - pFrameFormat = pDoc->getIDocumentContentOperations().InsertOLE( aPam, sStreamName, m_nDrawAspect, &aFrameSet, nullptr ); + // TODO/LEAN: VisualArea still needs running state + svt::EmbeddedObjectRef::TryRunningState( xIPObj ); - // store main document name to show in the title bar - SwOLENode* pNd = nullptr; - const SwNodeIndex* pIdx = pFrameFormat->GetContent().GetContentIdx(); - if( pIdx ) - { - SwNodeIndex aIdx( *pIdx, 1 ); - SwNoTextNode* pNoText = aIdx.GetNode().GetNoTextNode(); - pNd = pNoText->GetOLENode(); - } - if( pNd ) - { - uno::Reference < embed::XEmbeddedObject > xObj = pNd->GetOLEObj().GetOleRef(); - if( xObj.is() ) + // set parent to get correct VisArea(in case of object needing parent printer) + uno::Reference < container::XChild > xChild( xIPObj, uno::UNO_QUERY ); + if ( xChild.is() ) + xChild->setParent( pDoc->GetDocShell()->GetModel() ); + + //The Size should be suggested by the OLE server if not manually set + MapUnit aRefMap = VCLUnoHelper::UnoEmbed2VCLMapUnit( xIPObj->getMapUnit( nAspect ) ); + awt::Size aSize; + try { - uno::Reference< frame::XTitle > xModelTitle( pDoc->GetDocShell()->GetModel(), css::uno::UNO_QUERY ); - if( xModelTitle.is() ) - xObj->setContainerName( xModelTitle->getTitle() ); + aSize = xIPObj->getVisualAreaSize( nAspect ); } + catch ( embed::NoVisualAreaSizeException& ) + { + // the default size will be set later + } + + Size aSz( aSize.Width, aSize.Height ); + if ( !aSz.Width() || !aSz.Height() ) + { + aSz.Width() = aSz.Height() = 5000; + aSz = OutputDevice::LogicToLogic + ( aSz, MapMode( MapUnit::Map100thMM ), aRefMap ); + } + MapMode aMyMap( MapUnit::MapTwip ); + aSz = OutputDevice::LogicToLogic( aSz, aRefMap, aMyMap ); + SwFormatFrameSize aFrameSz; + aFrameSz.SetSize(aSz); + aFrameSet.Put(aFrameSz); } + SwFlyFrameFormat* pFormat2 = nullptr; - pDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSERT, nullptr); - pFrameFormat->Add(this); - if(!m_sName.isEmpty()) - pDoc->SetFlyName(*pFrameFormat, m_sName); - } - else if (pEmbeddedObject) - { - uno::Reference< embed::XEmbeddedObject > obj; - (*pEmbeddedObject) >>= obj; - svt::EmbeddedObjectRef xObj; - xObj.Assign( obj, embed::Aspects::MSOLE_CONTENT ); + ::svt::EmbeddedObjectRef xObjRef( xIPObj, m_nDrawAspect); + pFormat2 = pDoc->getIDocumentContentOperations().InsertEmbObject( + aPam, xObjRef, &aFrameSet ); - pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT, nullptr); + // store main document name to show in the title bar + uno::Reference< frame::XTitle > xModelTitle( pDoc->GetDocShell()->GetModel(), css::uno::UNO_QUERY ); + if( xModelTitle.is() ) + xIPObj->setContainerName( xModelTitle->getTitle() ); + + assert(pFormat2 && "Doc->Insert(notxt) failed."); - // Not sure if these setParent() and InsertEmbeddedObject() calls are really - // needed, it seems to work without, but logic from code elsewhere suggests - // they should be done. - SfxObjectShell& rPers = *pDoc->GetPersist(); - uno::Reference < container::XChild > xChild( obj, uno::UNO_QUERY ); - if ( xChild.is() ) - xChild->setParent( rPers.GetModel() ); - OUString rName; - rPers.GetEmbeddedObjectContainer().InsertEmbeddedObject( obj, rName ); - - SwFlyFrameFormat* pFrameFormat = nullptr; - pFrameFormat = pDoc->getIDocumentContentOperations().InsertEmbObject( - aPam, xObj, &aFrameSet); pDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSERT, nullptr); - pFrameFormat->Add(this); + pFormat2->Add(this); if(!m_sName.isEmpty()) - pDoc->SetFlyName(*pFrameFormat, m_sName); + pDoc->SetFlyName(*pFormat2, m_sName); } } - if( pFormat && pDoc->getIDocumentDrawModelAccess().GetDrawModel() ) - GetOrCreateSdrObject(*pFormat); - const ::uno::Any* pOrder; - if( pProps->GetProperty(FN_UNO_Z_ORDER, 0, pOrder) ) - setPropertyValue(UNO_NAME_Z_ORDER, *pOrder); - const ::uno::Any* pReplacement; - if( pProps->GetProperty(FN_UNO_REPLACEMENT_GRAPHIC, 0, pReplacement) ) - setPropertyValue(UNO_NAME_GRAPHIC, *pReplacement); - // new attribute Title - const ::uno::Any* pTitle; - if ( pProps->GetProperty(FN_UNO_TITLE, 0, pTitle) ) + else if( pStreamName ) { - setPropertyValue(UNO_NAME_TITLE, *pTitle); + OUString sStreamName; + (*pStreamName) >>= sStreamName; + pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT, nullptr); + + SwFlyFrameFormat* pFrameFormat = nullptr; + pFrameFormat = pDoc->getIDocumentContentOperations().InsertOLE( aPam, sStreamName, m_nDrawAspect, &aFrameSet, nullptr ); + + // store main document name to show in the title bar + SwOLENode* pNd = nullptr; + const SwNodeIndex* pIdx = pFrameFormat->GetContent().GetContentIdx(); + if( pIdx ) + { + SwNodeIndex aIdx( *pIdx, 1 ); + SwNoTextNode* pNoText = aIdx.GetNode().GetNoTextNode(); + pNd = pNoText->GetOLENode(); + } + if( pNd ) + { + uno::Reference < embed::XEmbeddedObject > xObj = pNd->GetOLEObj().GetOleRef(); + if( xObj.is() ) + { + uno::Reference< frame::XTitle > xModelTitle( pDoc->GetDocShell()->GetModel(), css::uno::UNO_QUERY ); + if( xModelTitle.is() ) + xObj->setContainerName( xModelTitle->getTitle() ); + } + } + + pDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSERT, nullptr); + pFrameFormat->Add(this); + if(!m_sName.isEmpty()) + pDoc->SetFlyName(*pFrameFormat, m_sName); } - // new attribute Description - const ::uno::Any* pDescription; - if ( pProps->GetProperty(FN_UNO_DESCRIPTION, 0, pDescription) ) + else if (pEmbeddedObject) { - setPropertyValue(UNO_NAME_DESCRIPTION, *pDescription); - } + uno::Reference< embed::XEmbeddedObject > obj; + (*pEmbeddedObject) >>= obj; + svt::EmbeddedObjectRef xObj; + xObj.Assign( obj, embed::Aspects::MSOLE_CONTENT ); - // For grabbag - const uno::Any* pFrameIntropgrabbagItem; - if( pProps->GetProperty(RES_FRMATR_GRABBAG, 0, pFrameIntropgrabbagItem) ) - { - setPropertyValue(UNO_NAME_FRAME_INTEROP_GRAB_BAG, *pFrameIntropgrabbagItem); + pDoc->GetIDocumentUndoRedo().StartUndo(SwUndoId::INSERT, nullptr); + + // Not sure if these setParent() and InsertEmbeddedObject() calls are really + // needed, it seems to work without, but logic from code elsewhere suggests + // they should be done. + SfxObjectShell& rPers = *pDoc->GetPersist(); + uno::Reference < container::XChild > xChild( obj, uno::UNO_QUERY ); + if ( xChild.is() ) + xChild->setParent( rPers.GetModel() ); + OUString rName; + rPers.GetEmbeddedObjectContainer().InsertEmbeddedObject( obj, rName ); + + SwFlyFrameFormat* pFrameFormat = nullptr; + pFrameFormat = pDoc->getIDocumentContentOperations().InsertEmbObject( + aPam, xObj, &aFrameSet); + pDoc->GetIDocumentUndoRedo().EndUndo(SwUndoId::INSERT, nullptr); + pFrameFormat->Add(this); + if(!m_sName.isEmpty()) + pDoc->SetFlyName(*pFrameFormat, m_sName); } } - else - throw lang::IllegalArgumentException(); + if( pFormat && pDoc->getIDocumentDrawModelAccess().GetDrawModel() ) + GetOrCreateSdrObject(*pFormat); + const ::uno::Any* pOrder; + if( pProps->GetProperty(FN_UNO_Z_ORDER, 0, pOrder) ) + setPropertyValue(UNO_NAME_Z_ORDER, *pOrder); + const ::uno::Any* pReplacement; + if( pProps->GetProperty(FN_UNO_REPLACEMENT_GRAPHIC, 0, pReplacement) ) + setPropertyValue(UNO_NAME_GRAPHIC, *pReplacement); + // new attribute Title + const ::uno::Any* pTitle; + if ( pProps->GetProperty(FN_UNO_TITLE, 0, pTitle) ) + { + setPropertyValue(UNO_NAME_TITLE, *pTitle); + } + // new attribute Description + const ::uno::Any* pDescription; + if ( pProps->GetProperty(FN_UNO_DESCRIPTION, 0, pDescription) ) + { + setPropertyValue(UNO_NAME_DESCRIPTION, *pDescription); + } + + // For grabbag + const uno::Any* pFrameIntropgrabbagItem; + if( pProps->GetProperty(RES_FRMATR_GRABBAG, 0, pFrameIntropgrabbagItem) ) + { + setPropertyValue(UNO_NAME_FRAME_INTEROP_GRAB_BAG, *pFrameIntropgrabbagItem); + } + // reset the flag and delete Descriptor pointer ResetDescriptor(); } @@ -3083,17 +3079,16 @@ void SwXFrame::attach(const uno::Reference< text::XTextRange > & xTextRange) { SwDoc* pDoc = pFormat->GetDoc(); SwUnoInternalPaM aIntPam(*pDoc); - if (::sw::XTextRangeToSwPaM(aIntPam, xTextRange)) - { - SfxItemSet aSet( pDoc->GetAttrPool(), svl::Items<RES_ANCHOR, RES_ANCHOR>{} ); ... etc. - the rest is truncated _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
