diff options
author | Maxim Monastirsky <momonasmon@gmail.com> | 2023-04-10 00:38:33 +0300 |
---|---|---|
committer | Maxim Monastirsky <momonasmon@gmail.com> | 2023-04-18 01:09:21 +0200 |
commit | 3e4b8463f288d87f91cd5bc864d30ae02d4f5579 (patch) | |
tree | 0716bc9ea72532d4fded3920742c6fa1ee5e58f5 /sc | |
parent | 6feafa2c5a2c593b1852ac44e2ea88eb9375c01d (diff) |
sc drawstyles: Maintain comment formatting with styles
Up to now the look of comments was maintained with the comment
shape's DF, with the default formatting being reapplied on
import (for hidden comments), on changing Tools > Options... >
LibreOffice > AC > Notes background, and on changing the
default cell style, while keeping the user-applied DF to some
extent. However, as we attempt to support drawing styles, this
approach is no longer viable, as applying DF on top of styles
at random times makes styles useless in the context of
comments.
(One might argue, that the look of comments should ideally be
treated as an app view setting, and not as a formatting of an
individual shape. This definitely makes sense, but has compat.
implications, as both LO and Excel allow formatting individual
comments (e.g. show a comment, right click > Area...). However
we will probably do it anyway if we ever implement threaded
comments like in recent Excel [1], as the callout shape based
approach seems to not scale to it.)
One way around it could be to explicitly disable any style
interaction with comments. But this will be unfortunate, as
styles have a clear advantage of being able to consistently
maintain the same formatting for several elements, much more
that the fragile approach of mixing the default formatting and
user-applied formatting in the same formatting layer. Not to
mention the possibility to define several custom styles. In
addition there is a request in tdf#55682 to disconnect the
formatting of comments from the default cell style, having a
dedicated style instead, which I find reasonable.
So this commit introduces a comment style, and uses it for new
comments instead of DF, making it easy to format all comments at
once. And a style based formatting is never overriden with DF,
unless explicitly set by the user. Changing Tools > Options... >
LibreOffice > AC > Notes background still has an effect in two
ways: (1) Sets the default background of the comment style for new
documents, and (2) if changed while a document is open, changes
also the comment style of the current document. An undo action
is also added, in case changing the current document wasn't
deliberate. Changing the default cell style no longer has any
effect on comment formatting.
One unfortunate side effect of this change, is that newly
created and permanently visible comments will lose their
default look when opened in an older version. But there is not
much I can do here, as older versions don't support styles, and
I believe the advantage of using styles outweigh this concern.
Hidden comments are not affected by this.
[1] see https://support.microsoft.com/en-us/office/the-difference-between-threaded-comments-and-notes-75a51eec-4092-42ab-abf8-7669077b7be3
Change-Id: I84215791b9e6ce393c6d979aa2b19ef70c76dff9
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/150352
Tested-by: Jenkins
Reviewed-by: Maxim Monastirsky <momonasmon@gmail.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/subsequent_export_test4.cxx | 13 | ||||
-rw-r--r-- | sc/qa/unit/ucalc.cxx | 18 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 7 | ||||
-rw-r--r-- | sc/source/core/data/drwlayer.cxx | 59 | ||||
-rw-r--r-- | sc/source/core/data/postit.cxx | 63 | ||||
-rw-r--r-- | sc/source/core/tool/detfunc.cxx | 147 | ||||
-rw-r--r-- | sc/source/core/tool/stylehelper.cxx | 1 |
7 files changed, 130 insertions, 178 deletions
diff --git a/sc/qa/unit/subsequent_export_test4.cxx b/sc/qa/unit/subsequent_export_test4.cxx index 9d6e38ef8a09..5d629e83eb4a 100644 --- a/sc/qa/unit/subsequent_export_test4.cxx +++ b/sc/qa/unit/subsequent_export_test4.cxx @@ -26,6 +26,7 @@ #include <editeng/postitem.hxx> #include <editeng/eeitem.hxx> #include <editeng/editobj.hxx> +#include <editeng/fhgtitem.hxx> #include <editeng/flditem.hxx> #include <editeng/justifyitem.hxx> #include <comphelper/scopeguard.hxx> @@ -1553,12 +1554,14 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, testCommentStyles) 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); + auto& rSet = pStyleSheet->GetItemSet(); + rSet.Put(SvxFontHeightItem(1129, 100, EE_CHAR_FONTHEIGHT)); + + pCaption->SetStyleSheet(static_cast<SfxStyleSheet*>(pStyleSheet), false); // Hidden comments use different code path on import pNote->ShowCaption(aPos, false); @@ -1575,12 +1578,14 @@ CPPUNIT_TEST_FIXTURE(ScExportTest4, testCommentStyles) ScPostIt* pNote = aDoc.GetNote(aPos); CPPUNIT_ASSERT(pNote); - pNote->ShowCaption(aPos, true); - auto pCaption = pNote->GetCaption(); + auto pCaption = pNote->GetOrCreateCaption(aPos); CPPUNIT_ASSERT(pCaption); // Check that the style was imported, and survived copying CPPUNIT_ASSERT_EQUAL(OUString("MyStyle1"), pCaption->GetStyleSheet()->GetName()); + // Check that the style formatting is in effect + CPPUNIT_ASSERT_EQUAL(sal_uInt32(1129), + pCaption->GetMergedItemSet().Get(EE_CHAR_FONTHEIGHT).GetHeight()); } } diff --git a/sc/qa/unit/ucalc.cxx b/sc/qa/unit/ucalc.cxx index aa8dbc32b220..6ca40d64582e 100644 --- a/sc/qa/unit/ucalc.cxx +++ b/sc/qa/unit/ucalc.cxx @@ -28,6 +28,8 @@ #include <docfunc.hxx> #include <funcdesc.hxx> +#include <globstr.hrc> +#include <scresid.hxx> #include <columniterator.hxx> #include <scopetools.hxx> @@ -4781,6 +4783,22 @@ CPPUNIT_TEST_FIXTURE(Test, testShiftCells) m_pDoc->DeleteTab(0); } +CPPUNIT_TEST_FIXTURE(Test, testNoteDefaultStyle) +{ + m_pDoc->InsertTab(0, "PostIts"); + + // We need a drawing layer in order to create caption objects. + m_pDoc->InitDrawLayer(m_xDocShell.get()); + + auto pNote = m_pDoc->GetOrCreateNote({0, 0, 0}); + auto pCaption = pNote->GetCaption(); + + CPPUNIT_ASSERT(pCaption); + CPPUNIT_ASSERT_EQUAL(ScResId(STR_STYLENAME_NOTE), pCaption->GetStyleSheet()->GetName()); + + m_pDoc->DeleteTab(0); +} + CPPUNIT_TEST_FIXTURE(Test, testNoteBasic) { m_pDoc->InsertTab(0, "PostIts"); diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index afec7f072b3c..fdf300a6e229 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -66,7 +66,6 @@ #include <hints.hxx> #include <detdata.hxx> #include <dpobject.hxx> -#include <detfunc.hxx> #include <scmod.hxx> #include <dociter.hxx> #include <progress.hxx> @@ -5057,12 +5056,6 @@ void ScDocument::StyleSheetChanged( const SfxStyleSheetBase* pStyleSheet, bool b a->StyleSheetChanged ( pStyleSheet, bRemoved, pDev, nPPTX, nPPTY, rZoomX, rZoomY ); } - - if ( pStyleSheet && pStyleSheet->GetName() == ScResId(STR_STYLENAME_STANDARD) ) - { - // update attributes for all note objects - ScDetectiveFunc::UpdateAllComments( *this ); - } } bool ScDocument::IsStyleSheetUsed( const ScStyleSheet& rStyle ) const diff --git a/sc/source/core/data/drwlayer.cxx b/sc/source/core/data/drwlayer.cxx index 830852bd4fd1..3940d09906ee 100644 --- a/sc/source/core/data/drwlayer.cxx +++ b/sc/source/core/data/drwlayer.cxx @@ -25,6 +25,7 @@ #include <scitems.hxx> #include <editeng/eeitem.hxx> +#include <editeng/fontitem.hxx> #include <editeng/frmdiritem.hxx> #include <sot/exchange.hxx> #include <svx/objfac3d.hxx> @@ -41,6 +42,16 @@ #include <svx/svdundo.hxx> #include <svx/sdsxyitm.hxx> #include <svx/svxids.hrc> +#include <svx/sxcecitm.hxx> +#include <svx/sdshitm.hxx> +#include <svx/sdtditm.hxx> +#include <svx/sdtagitm.hxx> +#include <svx/xflclit.hxx> +#include <svx/xfillit0.hxx> +#include <svx/xlineit0.hxx> +#include <svx/xlnstit.hxx> +#include <svx/xlnstwit.hxx> +#include <svx/xlnstcit.hxx> #include <i18nlangtag/mslangid.hxx> #include <editeng/unolingu.hxx> #include <svx/drawitem.hxx> @@ -73,6 +84,8 @@ #include <charthelper.hxx> #include <table.hxx> #include <stlpool.hxx> +#include <docpool.hxx> +#include <detfunc.hxx> #include <basegfx/matrix/b2dhommatrix.hxx> #include <memory> @@ -348,6 +361,52 @@ void ScDrawLayer::CreateDefaultStyles() // Default auto pSheet = &GetStyleSheetPool()->Make(ScResId(STR_STYLENAME_STANDARD), SfxStyleFamily::Frame, SfxStyleSearchBits::ScStandard); SetDefaultStyleSheet(static_cast<SfxStyleSheet*>(pSheet)); + + // Note + pSheet = &GetStyleSheetPool()->Make(ScResId(STR_STYLENAME_NOTE), SfxStyleFamily::Frame, SfxStyleSearchBits::ScStandard); + + // caption tail arrow + ::basegfx::B2DPolygon aTriangle; + aTriangle.append(::basegfx::B2DPoint(10.0, 0.0)); + aTriangle.append(::basegfx::B2DPoint(0.0, 30.0)); + aTriangle.append(::basegfx::B2DPoint(20.0, 30.0)); + aTriangle.setClosed(true); + + auto pSet = &pSheet->GetItemSet(); + pSet->Put(XLineStartItem(OUString(), ::basegfx::B2DPolyPolygon(aTriangle)).checkForUniqueItem(this)); + pSet->Put(XLineStartWidthItem(200)); + pSet->Put(XLineStartCenterItem(false)); + pSet->Put(XLineStyleItem(drawing::LineStyle_SOLID)); + pSet->Put(XFillStyleItem(drawing::FillStyle_SOLID)); + pSet->Put(XFillColorItem(OUString(), ScDetectiveFunc::GetCommentColor())); + pSet->Put(SdrCaptionEscDirItem(SdrCaptionEscDir::BestFit)); + + // shadow + /* SdrShadowItem has false, instead the shadow is set for the rectangle + only with SetSpecialTextBoxShadow() when the object is created. */ + pSet->Put(makeSdrShadowItem(false)); + pSet->Put(makeSdrShadowXDistItem(100)); + pSet->Put(makeSdrShadowYDistItem(100)); + + // text attributes + pSet->Put(makeSdrTextLeftDistItem(100)); + pSet->Put(makeSdrTextRightDistItem(100)); + pSet->Put(makeSdrTextUpperDistItem(100)); + pSet->Put(makeSdrTextLowerDistItem(100)); + pSet->Put(makeSdrTextAutoGrowWidthItem(false)); + pSet->Put(makeSdrTextAutoGrowHeightItem(true)); + + // text formatting + SfxItemSet aEditSet(GetItemPool()); + ScPatternAttr::FillToEditItemSet(aEditSet, pDoc->GetPool()->GetDefaultItem(ATTR_PATTERN).GetItemSet()); + + pSet->Put(aEditSet.Get(EE_CHAR_FONTINFO)); + pSet->Put(aEditSet.Get(EE_CHAR_FONTINFO_CJK)); + pSet->Put(aEditSet.Get(EE_CHAR_FONTINFO_CTL)); + + pSet->Put(aEditSet.Get(EE_CHAR_FONTHEIGHT)); + pSet->Put(aEditSet.Get(EE_CHAR_FONTHEIGHT_CJK)); + pSet->Put(aEditSet.Get(EE_CHAR_FONTHEIGHT_CTL)); } void ScDrawLayer::UseHyphenator() diff --git a/sc/source/core/data/postit.cxx b/sc/source/core/data/postit.cxx index 74bd5a22adbd..8f6c14f7901b 100644 --- a/sc/source/core/data/postit.cxx +++ b/sc/source/core/data/postit.cxx @@ -54,6 +54,8 @@ #include <userdat.hxx> #include <detfunc.hxx> #include <editutil.hxx> +#include <globstr.hrc> +#include <scresid.hxx> #include <utility> using namespace com::sun::star; @@ -109,38 +111,9 @@ void ScCaptionUtil::SetDefaultItems( SdrCaptionObj& rCaption, ScDocument& rDoc, { SfxItemSet aItemSet = rCaption.GetMergedItemSet(); - // caption tail arrow - ::basegfx::B2DPolygon aTriangle; - aTriangle.append( ::basegfx::B2DPoint( 10.0, 0.0 ) ); - aTriangle.append( ::basegfx::B2DPoint( 0.0, 30.0 ) ); - aTriangle.append( ::basegfx::B2DPoint( 20.0, 30.0 ) ); - aTriangle.setClosed( true ); - /* Line ends are now created with an empty name. The - checkForUniqueItem() method then finds a unique name for the item's - value. */ - aItemSet.Put( XLineStartItem( OUString(), ::basegfx::B2DPolyPolygon( aTriangle ) ) ); - aItemSet.Put( XLineStartWidthItem( 200 ) ); - aItemSet.Put( XLineStartCenterItem( false ) ); - aItemSet.Put( XFillStyleItem( drawing::FillStyle_SOLID ) ); - aItemSet.Put( XFillColorItem( OUString(), ScDetectiveFunc::GetCommentColor() ) ); - aItemSet.Put( SdrCaptionEscDirItem( SdrCaptionEscDir::BestFit ) ); - - // shadow - /* SdrShadowItem has sal_False, instead the shadow is set for the - rectangle only with SetSpecialTextBoxShadow() when the object is - created (item must be set to adjust objects from older files). */ - aItemSet.Put( makeSdrShadowItem( false ) ); - aItemSet.Put( makeSdrShadowXDistItem( 100 ) ); - aItemSet.Put( makeSdrShadowYDistItem( 100 ) ); - - // text attributes - aItemSet.Put( makeSdrTextLeftDistItem( 100 ) ); - aItemSet.Put( makeSdrTextRightDistItem( 100 ) ); - aItemSet.Put( makeSdrTextUpperDistItem( 100 ) ); - aItemSet.Put( makeSdrTextLowerDistItem( 100 ) ); - aItemSet.Put( makeSdrTextAutoGrowWidthItem( false ) ); - aItemSet.Put( makeSdrTextAutoGrowHeightItem( true ) ); - // use the default cell style to be able to modify the caption font + if (auto pStyleSheet = rDoc.GetStyleSheetPool()->Find(ScResId(STR_STYLENAME_NOTE), SfxStyleFamily::Frame)) + aItemSet.Put(pStyleSheet->GetItemSet()); + const ScPatternAttr& rDefPattern = rDoc.GetPool()->GetDefaultItem( ATTR_PATTERN ); rDefPattern.FillEditItemSet( &aItemSet ); @@ -701,10 +674,15 @@ void ScPostIt::CreateCaptionFromInitData( const ScAddress& rPos ) const { 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 ); + if (xInitData->moItemSet) + maNoteData.mxCaption->SetMergedItemSet(*xInitData->moItemSet); + } + else + { + // copy all items or set default items; reset shadow items + ScCaptionUtil::SetDefaultItems( *maNoteData.mxCaption, mrDoc, xInitData->moItemSet ? &*xInitData->moItemSet : nullptr ); + } // set position and size of the caption object if( xInitData->mbDefaultPosSize ) @@ -776,13 +754,14 @@ void ScPostIt::CreateCaption( const ScAddress& rPos, const SdrCaptionObj* pCapti } else { + if (auto pStyleSheet = mrDoc.GetStyleSheetPool()->Find(ScResId(STR_STYLENAME_NOTE), SfxStyleFamily::Frame)) + maNoteData.mxCaption->SetStyleSheet(static_cast<SfxStyleSheet*>(pStyleSheet), true); // set default size, undoing sdr::TextProperties::SetStyleSheet's // adjustment that use a wrong min height. - maNoteData.mxCaption->SetMergedItem(makeSdrTextMinFrameHeightItem(SC_NOTECAPTION_HEIGHT)); - maNoteData.mxCaption->SetMergedItem(makeSdrTextMinFrameWidthItem(SC_NOTECAPTION_WIDTH)); - maNoteData.mxCaption->NbcAdjustTextFrameWidthAndHeight(); - // set default formatting and default position - ScCaptionUtil::SetDefaultItems( *maNoteData.mxCaption, mrDoc, nullptr ); + tools::Rectangle aCaptRect = maNoteData.mxCaption->GetLogicRect(); + aCaptRect.SetSize({ SC_NOTECAPTION_WIDTH, SC_NOTECAPTION_HEIGHT }); + maNoteData.mxCaption->SetLogicRect(aCaptRect); + // set default position aCreator.AutoPlaceCaption(); } @@ -881,7 +860,8 @@ rtl::Reference<SdrCaptionObj> ScNoteUtil::CreateTempCaption( { // if pNoteCaption is null, then aBuffer contains some text pCaption->SetText( aBuffer.makeStringAndClear() ); - ScCaptionUtil::SetDefaultItems( *pCaption, rDoc, nullptr ); + if (auto pStyleSheet = rDoc.GetStyleSheetPool()->Find(ScResId(STR_STYLENAME_NOTE), SfxStyleFamily::Frame)) + pCaption->SetStyleSheet(static_cast<SfxStyleSheet*>(pStyleSheet), true); // adjust caption size to text size tools::Long nMaxWidth = ::std::min< tools::Long >( aVisRect.GetWidth() * 2 / 3, SC_NOTECAPTION_MAXWIDTH_TEMP ); pCaption->SetMergedItem( makeSdrTextAutoGrowWidthItem( true ) ); @@ -958,6 +938,7 @@ ScPostIt* ScNoteUtil::CreateNoteFromString( aNoteData.mxInitData = std::make_shared<ScCaptionInitData>(); ScCaptionInitData& rInitData = *aNoteData.mxInitData; rInitData.maSimpleText = rNoteText; + rInitData.maStyleName = ScResId(STR_STYLENAME_NOTE); rInitData.mbDefaultPosSize = true; /* Create the note and insert it into the document. If the note is diff --git a/sc/source/core/tool/detfunc.cxx b/sc/source/core/tool/detfunc.cxx index ee8ba8b2226d..4ec4d4349918 100644 --- a/sc/source/core/tool/detfunc.cxx +++ b/sc/source/core/tool/detfunc.cxx @@ -59,6 +59,10 @@ #include <userdat.hxx> #include <validat.hxx> #include <formulacell.hxx> +#include <globstr.hrc> +#include <scresid.hxx> +#include <undostyl.hxx> +#include <stlpool.hxx> #include <docpool.hxx> #include <patattr.hxx> #include <scmod.hxx> @@ -106,22 +110,6 @@ public: sal_uInt16 GetMaxLevel() const { return nMaxLevel; } }; -namespace { - -class ScCommentData -{ -public: - ScCommentData( ScDocument& rDoc, SdrModel* pModel ); - - SfxItemSet& GetCaptionSet() { return aCaptionSet; } - void UpdateCaptionSet( const SfxItemSet& rItemSet ); - -private: - SfxItemSet aCaptionSet; -}; - -} - Color ScDetectiveFunc::nArrowColor = Color(0); Color ScDetectiveFunc::nErrorColor = Color(0); Color ScDetectiveFunc::nCommentColor = Color(0); @@ -193,80 +181,6 @@ ScDetectiveData::ScDetectiveData( SdrModel* pModel ) : aCircleSet.Put( XLineWidthItem( 55 ) ); // 54 = 1 Pixel } -ScCommentData::ScCommentData( ScDocument& rDoc, SdrModel* pModel ) : - aCaptionSet( pModel->GetItemPool(), svl::Items<SDRATTR_START, SDRATTR_END, EE_ITEMS_START, EE_ITEMS_END> ) -{ - basegfx::B2DPolygon aTriangle; - aTriangle.append(basegfx::B2DPoint(10.0, 0.0)); - aTriangle.append(basegfx::B2DPoint(0.0, 30.0)); - aTriangle.append(basegfx::B2DPoint(20.0, 30.0)); - aTriangle.setClosed(true); - - aCaptionSet.Put( XLineStartItem( OUString(), basegfx::B2DPolyPolygon(aTriangle))); - aCaptionSet.Put( XLineStartWidthItem( 200 ) ); - aCaptionSet.Put( XLineStartCenterItem( false ) ); - aCaptionSet.Put( XFillStyleItem( drawing::FillStyle_SOLID ) ); - Color aYellow( ScDetectiveFunc::GetCommentColor() ); - aCaptionSet.Put( XFillColorItem( OUString(), aYellow ) ); - - // shadow - // SdrShadowItem has sal_False, instead the shadow is set for the rectangle - // only with SetSpecialTextBoxShadow when the object is created - // (item must be set to adjust objects from older files) - aCaptionSet.Put( makeSdrShadowItem( false ) ); - aCaptionSet.Put( makeSdrShadowXDistItem( 100 ) ); - aCaptionSet.Put( makeSdrShadowYDistItem( 100 ) ); - - // text attributes - aCaptionSet.Put( makeSdrTextLeftDistItem( 100 ) ); - aCaptionSet.Put( makeSdrTextRightDistItem( 100 ) ); - aCaptionSet.Put( makeSdrTextUpperDistItem( 100 ) ); - aCaptionSet.Put( makeSdrTextLowerDistItem( 100 ) ); - - aCaptionSet.Put( makeSdrTextAutoGrowWidthItem( false ) ); - aCaptionSet.Put( makeSdrTextAutoGrowHeightItem( true ) ); - - // do use the default cell style, so the user has a chance to - // modify the font for the annotations - rDoc.GetPool()->GetDefaultItem(ATTR_PATTERN).FillEditItemSet( &aCaptionSet ); - - // support the best position for the tail connector now that - // that notes can be resized and repositioned. - aCaptionSet.Put( SdrCaptionEscDirItem( SdrCaptionEscDir::BestFit) ); -} - -void ScCommentData::UpdateCaptionSet( const SfxItemSet& rItemSet ) -{ - SfxWhichIter aWhichIter( rItemSet ); - const SfxPoolItem* pPoolItem = nullptr; - - for( sal_uInt16 nWhich = aWhichIter.FirstWhich(); nWhich > 0; nWhich = aWhichIter.NextWhich() ) - { - if(aWhichIter.GetItemState(false, &pPoolItem) == SfxItemState::SET) - { - switch(nWhich) - { - case SDRATTR_SHADOW: - // use existing Caption default - appears that setting this - // to true screws up the tail appearance. See also comment - // for default setting above. - break; - case SDRATTR_SHADOWXDIST: - // use existing Caption default - svx sets a value of 35 - // but default 100 gives a better appearance. - break; - case SDRATTR_SHADOWYDIST: - // use existing Caption default - svx sets a value of 35 - // but default 100 gives a better appearance. - break; - - default: - aCaptionSet.Put(*pPoolItem); - } - } - } -} - void ScDetectiveFunc::Modified() { rDoc.SetStreamValid(nTab, false); @@ -1458,46 +1372,27 @@ void ScDetectiveFunc::GetAllSuccs(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW n void ScDetectiveFunc::UpdateAllComments( ScDocument& rDoc ) { - // for all caption objects, update attributes and SpecialTextBoxShadow flag - // (on all tables - nTab is ignored!) - - // no undo actions, this is refreshed after undo - ScDrawLayer* pModel = rDoc.GetDrawLayer(); if (!pModel) return; - for( SCTAB nObjTab = 0, nTabCount = rDoc.GetTableCount(); nObjTab < nTabCount; ++nObjTab ) - { - SdrPage* pPage = pModel->GetPage( static_cast< sal_uInt16 >( nObjTab ) ); - OSL_ENSURE( pPage, "Page ?" ); - if( pPage ) - { - SdrObjListIter aIter( pPage, SdrIterMode::Flat ); - for( SdrObject* pObject = aIter.Next(); pObject; pObject = aIter.Next() ) - { - if ( ScDrawObjData* pData = ScDrawLayer::GetNoteCaptionData( pObject, nObjTab ) ) - { - ScPostIt* pNote = rDoc.GetNote( pData->maStart ); - // caption should exist, we iterate over drawing objects... - OSL_ENSURE( pNote && (pNote->GetCaption() == pObject), "ScDetectiveFunc::UpdateAllComments - invalid cell note" ); - if( pNote ) - { - ScCommentData aData( rDoc, pModel ); - SfxItemSet aAttrColorSet = pObject->GetMergedItemSet(); - aAttrColorSet.Put( XFillColorItem( OUString(), GetCommentColor() ) ); - aData.UpdateCaptionSet( aAttrColorSet ); - pObject->SetMergedItemSetAndBroadcast( aData.GetCaptionSet() ); - if( SdrCaptionObj* pCaption = dynamic_cast< SdrCaptionObj* >( pObject ) ) - { - pCaption->SetSpecialTextBoxShadow(); - pCaption->SetFixedTail(); - } - } - } - } - } - } + auto pStyleSheet = rDoc.GetStyleSheetPool()->Find(ScResId(STR_STYLENAME_NOTE), SfxStyleFamily::Frame); + if (!pStyleSheet) + return; + + ScStyleSaveData aOldData, aNewData; + aOldData.InitFromStyle(pStyleSheet); + + auto& rSet = pStyleSheet->GetItemSet(); + rSet.Put(XFillStyleItem(drawing::FillStyle_SOLID)); + rSet.Put(XFillColorItem(OUString(), ScDetectiveFunc::GetCommentColor())); + static_cast<SfxStyleSheet*>(pStyleSheet)->Broadcast(SfxHint(SfxHintId::DataChanged)); + + aNewData.InitFromStyle(pStyleSheet); + + ScDocShell* pDocSh = static_cast<ScDocShell*>(rDoc.GetDocumentShell()); + pDocSh->GetUndoManager()->AddUndoAction( + std::make_unique<ScUndoModifyStyle>(pDocSh, pStyleSheet->GetFamily(), aOldData, aNewData)); } void ScDetectiveFunc::UpdateAllArrowColors() diff --git a/sc/source/core/tool/stylehelper.cxx b/sc/source/core/tool/stylehelper.cxx index 3adcfb4847bc..e4bfed1f1b0e 100644 --- a/sc/source/core/tool/stylehelper.cxx +++ b/sc/source/core/tool/stylehelper.cxx @@ -102,6 +102,7 @@ static const ScDisplayNameMap* lcl_GetStyleNameMap( SfxStyleFamily nType ) static ScDisplayNameMap const aGraphicMap[] { { ScResId( STR_STYLENAME_STANDARD ), OUString(SC_STYLE_PROG_STANDARD) }, + { ScResId( STR_STYLENAME_NOTE ), "Note" }, // last entry remains empty { OUString(), OUString() }, }; |