diff options
author | Maxim Monastirsky <momonasmon@gmail.com> | 2023-03-31 16:38:32 +0300 |
---|---|---|
committer | Maxim Monastirsky <momonasmon@gmail.com> | 2023-04-07 15:59:04 +0200 |
commit | 1e442e2c6800cf38e42749ac6644502cb3717bc3 (patch) | |
tree | b1fcf2c9199baf46e5625d2bc2dd075dba0c0fe2 /sc | |
parent | 94ec3df7733dfbc5f48bc1d1a5f0578572749400 (diff) |
sc drawstyles: Keep style assignment for comments
Need to handle 3 cases:
- Import of hidden comments (not too much useful by itself,
as we still force the default comment formatting as DF).
- Copying cells with comments.
- The comment popup that is shown when hovering over a
comment marker.
Change-Id: Ibf2e22f1432745fe46f89da624ed3586b5d9fb55
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/149943
Tested-by: Jenkins
Reviewed-by: Maxim Monastirsky <momonasmon@gmail.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/postit.hxx | 4 | ||||
-rw-r--r-- | sc/qa/unit/subsequent_export_test4.cxx | 44 | ||||
-rw-r--r-- | sc/source/core/data/postit.cxx | 23 | ||||
-rw-r--r-- | sc/source/filter/excel/xiescher.cxx | 2 | ||||
-rw-r--r-- | sc/source/filter/xml/xmlcelli.cxx | 14 |
5 files changed, 81 insertions, 6 deletions
diff --git a/sc/inc/postit.hxx b/sc/inc/postit.hxx index 36473542e1df..7da83a9ebea0 100644 --- a/sc/inc/postit.hxx +++ b/sc/inc/postit.hxx @@ -216,6 +216,8 @@ public: formatting attributes of the caption object. This function takes ownership of the passed item set. + @param rStyleName Drawing style associated with the caption object. + @param rOutlinerObj An outliner object containing (formatted) text for the caption object. @@ -229,7 +231,7 @@ public: */ static ScPostIt* CreateNoteFromObjectData( ScDocument& rDoc, const ScAddress& rPos, - SfxItemSet&& oItemSet, + SfxItemSet&& oItemSet, const OUString& rStyleName, const OutlinerParaObject& rOutlinerObj, const tools::Rectangle& rCaptionRect, bool bShown ); diff --git a/sc/qa/unit/subsequent_export_test4.cxx b/sc/qa/unit/subsequent_export_test4.cxx index 275493f61387..9d6e38ef8a09 100644 --- a/sc/qa/unit/subsequent_export_test4.cxx +++ b/sc/qa/unit/subsequent_export_test4.cxx @@ -17,6 +17,7 @@ #include <attrib.hxx> #include <stlpool.hxx> #include <formulacell.hxx> +#include <postit.hxx> #include <validat.hxx> #include <scresid.hxx> #include <globstr.hrc> @@ -32,6 +33,7 @@ #include <tools/fldunit.hxx> #include <svl/numformat.hxx> #include <svl/zformat.hxx> +#include <svx/svdocapt.hxx> #include <com/sun/star/chart2/XChartDocument.hpp> #include <com/sun/star/chart2/XChartTypeContainer.hpp> @@ -1540,6 +1542,48 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, testShapeStyles) } } +CPPUNIT_TEST_FIXTURE(ScExportTest4, testCommentStyles) +{ + createScDoc("ods/comment.ods"); + + { + ScDocument* pDoc = getScDoc(); + + ScAddress aPos(0, 0, 0); + ScPostIt* pNote = pDoc->GetNote(aPos); + CPPUNIT_ASSERT(pNote); + + pNote->ShowCaption(aPos, true); + auto pCaption = pNote->GetCaption(); + CPPUNIT_ASSERT(pCaption); + + auto pStyleSheet = &pDoc->GetStyleSheetPool()->Make("MyStyle1", SfxStyleFamily::Frame); + pCaption->SetStyleSheet(static_cast<SfxStyleSheet*>(pStyleSheet), true); + + // Hidden comments use different code path on import + pNote->ShowCaption(aPos, false); + } + + saveAndReload("calc8"); + + { + ScDocument aDoc; + aDoc.InitDrawLayer(); + aDoc.TransferTab(*getScDoc(), 0, 0); + + ScAddress aPos(0, 0, 0); + ScPostIt* pNote = aDoc.GetNote(aPos); + CPPUNIT_ASSERT(pNote); + + pNote->ShowCaption(aPos, true); + auto pCaption = pNote->GetCaption(); + CPPUNIT_ASSERT(pCaption); + + // Check that the style was imported, and survived copying + CPPUNIT_ASSERT_EQUAL(OUString("MyStyle1"), pCaption->GetStyleSheet()->GetName()); + } +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/data/postit.cxx b/sc/source/core/data/postit.cxx index 00aab1d52030..6da509043c12 100644 --- a/sc/source/core/data/postit.cxx +++ b/sc/source/core/data/postit.cxx @@ -47,6 +47,7 @@ #include <document.hxx> #include <docpool.hxx> +#include <stlpool.hxx> #include <patattr.hxx> #include <drwlayer.hxx> #include <userdat.hxx> @@ -89,9 +90,9 @@ void ScCaptionUtil::SetCaptionLayer( SdrCaptionObj& rCaption, bool bShown ) void ScCaptionUtil::SetBasicCaptionSettings( SdrCaptionObj& rCaption, bool bShown ) { - SetCaptionLayer( rCaption, bShown ); rCaption.SetFixedTail(); rCaption.SetSpecialTextBoxShadow(); + SetCaptionLayer( rCaption, bShown ); } void ScCaptionUtil::SetCaptionUserData( SdrCaptionObj& rCaption, const ScAddress& rPos ) @@ -458,6 +459,7 @@ struct ScCaptionInitData { std::optional< SfxItemSet > moItemSet; /// Caption object formatting. std::optional< OutlinerParaObject > mxOutlinerObj; /// Text object with all text portion formatting. + OUString maStyleName; /// Drawing style associated with the caption object. OUString maSimpleText; /// Simple text without formatting. Point maCaptionOffset; /// Caption position relative to cell corner. Size maCaptionSize; /// Size of the caption object. @@ -694,6 +696,12 @@ void ScPostIt::CreateCaptionFromInitData( const ScAddress& rPos ) const else maNoteData.mxCaption->SetText( xInitData->maSimpleText ); + if (!xInitData->maStyleName.isEmpty()) + { + if (auto pStyleSheet = mrDoc.GetStyleSheetPool()->Find(xInitData->maStyleName, SfxStyleFamily::Frame)) + maNoteData.mxCaption->SetStyleSheet(static_cast<SfxStyleSheet*>(pStyleSheet), true); + } + // copy all items or set default items; reset shadow items ScCaptionUtil::SetDefaultItems( *maNoteData.mxCaption, mrDoc, xInitData->moItemSet ? &*xInitData->moItemSet : nullptr ); @@ -749,6 +757,14 @@ void ScPostIt::CreateCaption( const ScAddress& rPos, const SdrCaptionObj* pCapti if( OutlinerParaObject* pOPO = pCaption->GetOutlinerParaObject() ) maNoteData.mxCaption->SetOutlinerParaObject( *pOPO ); // copy formatting items (after text has been copied to apply font formatting) + if (auto pStyleSheet = pCaption->GetStyleSheet()) + { + auto pPool = mrDoc.GetStyleSheetPool(); + pPool->CopyStyleFrom(pStyleSheet->GetPool(), pStyleSheet->GetName(), pStyleSheet->GetFamily(), true); + + if (auto pDestStyleSheet = pPool->Find(pStyleSheet->GetName(), pStyleSheet->GetFamily())) + maNoteData.mxCaption->SetStyleSheet(static_cast<SfxStyleSheet*>(pDestStyleSheet), true); + } maNoteData.mxCaption->SetMergedItemSetAndBroadcast( pCaption->GetMergedItemSet() ); // move textbox position relative to new cell, copy textbox size tools::Rectangle aCaptRect = pCaption->GetLogicRect(); @@ -854,6 +870,8 @@ rtl::Reference<SdrCaptionObj> ScNoteUtil::CreateTempCaption( if( OutlinerParaObject* pOPO = pNoteCaption->GetOutlinerParaObject() ) pCaption->SetOutlinerParaObject( *pOPO ); // set formatting (must be done after setting text) and resize the box to fit the text + if (auto pStyleSheet = pNoteCaption->GetStyleSheet()) + pCaption->SetStyleSheet(pStyleSheet, true); pCaption->SetMergedItemSetAndBroadcast( pNoteCaption->GetMergedItemSet() ); tools::Rectangle aCaptRect( pCaption->GetLogicRect().TopLeft(), pNoteCaption->GetLogicRect().GetSize() ); pCaption->SetLogicRect( aCaptRect ); @@ -896,7 +914,7 @@ ScPostIt* ScNoteUtil::CreateNoteFromCaption( } ScPostIt* ScNoteUtil::CreateNoteFromObjectData( - ScDocument& rDoc, const ScAddress& rPos, SfxItemSet&& rItemSet, + ScDocument& rDoc, const ScAddress& rPos, SfxItemSet&& rItemSet, const OUString& rStyleName, const OutlinerParaObject& rOutlinerObj, const tools::Rectangle& rCaptionRect, bool bShown ) { @@ -905,6 +923,7 @@ ScPostIt* ScNoteUtil::CreateNoteFromObjectData( ScCaptionInitData& rInitData = *aNoteData.mxInitData; rInitData.moItemSet.emplace(std::move(rItemSet)); rInitData.mxOutlinerObj = rOutlinerObj; + rInitData.maStyleName = rStyleName; // convert absolute caption position to relative position rInitData.mbDefaultPosSize = rCaptionRect.IsEmpty(); diff --git a/sc/source/filter/excel/xiescher.cxx b/sc/source/filter/excel/xiescher.cxx index 718f464e0c9c..e9a47fada31c 100644 --- a/sc/source/filter/excel/xiescher.cxx +++ b/sc/source/filter/excel/xiescher.cxx @@ -1870,7 +1870,7 @@ void XclImpNoteObj::DoPreProcessSdrObj( XclImpDffConverter& rDffConv, SdrObject& ScNoteUtil::CreateNoteFromObjectData( GetDoc(), maScPos, rSdrObj.GetMergedItemSet().CloneAsValue(), // new object on heap expected - *pOutlinerObj, + OUString(), *pOutlinerObj, rSdrObj.GetLogicRect(), ::get_flag( mnNoteFlags, EXC_NOTE_VISIBLE ) ); } diff --git a/sc/source/filter/xml/xmlcelli.cxx b/sc/source/filter/xml/xmlcelli.cxx index 7ae3aaaa6e35..dbbfccf5a5a0 100644 --- a/sc/source/filter/xml/xmlcelli.cxx +++ b/sc/source/filter/xml/xmlcelli.cxx @@ -838,6 +838,16 @@ void ScXMLTableRowCellContext::SetAnnotation(const ScAddress& rPos) if( mxAnnotationData->mxShape.is() && mxAnnotationData->mxShapes.is() ) { OSL_ENSURE( mxAnnotationData->mxShapes.get() == xShapes.get(), "ScXMLTableRowCellContext::SetAnnotation - different drawing pages" ); + + /* Don't attempt to get the style from the SdrObject, + as it might be a default assigned one. */ + auto pStyle = rXMLImport.GetShapeImport()->GetAutoStylesContext()->FindStyleChildContext( + XmlStyleFamily::SD_GRAPHICS_ID, mxAnnotationData->maStyleName); + OUString aStyleName = pStyle ? pStyle->GetParentName() : mxAnnotationData->maStyleName; + assert(!rXMLImport.GetShapeImport()->GetAutoStylesContext()->FindStyleChildContext( + XmlStyleFamily::SD_GRAPHICS_ID, aStyleName)); + aStyleName = rXMLImport.GetStyleDisplayName(XmlStyleFamily::SD_GRAPHICS_ID, aStyleName); + SdrObject* pObject = SdrObject::getSdrObjectFromXShape(mxAnnotationData->mxShape); OSL_ENSURE( pObject, "ScXMLTableRowCellContext::SetAnnotation - cannot get SdrObject from shape" ); @@ -880,13 +890,13 @@ void ScXMLTableRowCellContext::SetAnnotation(const ScAddress& rPos) if(!comphelper::LibreOfficeKit::isActive()) { pNote = ScNoteUtil::CreateNoteFromObjectData( *pDoc, rPos, - std::move(aItemSet), *pOutlinerObj, + std::move(aItemSet), aStyleName, *pOutlinerObj, aCaptionRect, mxAnnotationData->mbShown ); } else { pNote = ScNoteUtil::CreateNoteFromObjectData( *pDoc, rPos, - std::move(aItemSet), *pOutlinerObj, + std::move(aItemSet), aStyleName, *pOutlinerObj, aCaptionRect, false ); } |