framework/inc/uielement/toolbarmanager.hxx | 2 framework/source/uielement/toolbarmanager.cxx | 8 - framework/source/uielement/toolbarmerger.cxx | 2 include/svx/fillctrl.hxx | 3 svx/source/tbxctrls/fillctrl.cxx | 165 ++++++++++++++++++++++---- 5 files changed, 149 insertions(+), 31 deletions(-)
New commits: commit 7d1175c46588c246c455cd7c8874136bf61197fd Author: Michael Stahl <michael.st...@allotropia.de> AuthorDate: Mon Jul 19 17:33:04 2021 +0200 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Tue Jul 20 11:59:24 2021 +0200 framework: fix multiple-free in VclToolBarManager::Destroy() Multiple ImplToolItem with mnId 1000 are inserted in the same ToolBox and the problem is that only the first one gets its mpUserData set, because setting and getting that is based on the assumption that mnId is unique per container. So in Destroy() for every item with mnId 1000 the same AddonsParams object is deleted. The problem is that in ToolBarManager::FillToolbar() the local nItemId is copied, so its value never changes when iterating the loop because only its copy is incremented. (regression from ac1aefd5174258d9bcb41465ce566ed1a0819f3d) Change-Id: Ica47051f9447c2b9d1981f8373d754874f0f31b0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119228 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/framework/inc/uielement/toolbarmanager.hxx b/framework/inc/uielement/toolbarmanager.hxx index 8a87c2a6b78a..6de526423d38 100644 --- a/framework/inc/uielement/toolbarmanager.hxx +++ b/framework/inc/uielement/toolbarmanager.hxx @@ -92,7 +92,7 @@ public: virtual vcl::ImageType GetImageSize() = 0; virtual void ConnectCallbacks(ToolBarManager* pManager) = 0; virtual void SetMenuType(ToolBoxMenuType eType) = 0; - virtual void MergeToolbar(ToolBoxItemId nItemId, + virtual void MergeToolbar(ToolBoxItemId & rItemId, const OUString& rModuleIdentifier, CommandToInfoMap& rCommandMap, MergeToolbarInstruction& rInstruction) = 0; diff --git a/framework/source/uielement/toolbarmanager.cxx b/framework/source/uielement/toolbarmanager.cxx index f08cfe60a6d8..e85de886b442 100644 --- a/framework/source/uielement/toolbarmanager.cxx +++ b/framework/source/uielement/toolbarmanager.cxx @@ -333,7 +333,7 @@ public: m_pToolBar->SetMenuType( eType ); } - virtual void MergeToolbar(ToolBoxItemId nItemId, + virtual void MergeToolbar(ToolBoxItemId & rItemId, const OUString& rModuleIdentifier, CommandToInfoMap& rCommandMap, MergeToolbarInstruction& rInstruction) override @@ -349,7 +349,7 @@ public: { ToolBarMerger::ProcessMergeOperation( m_pToolBar, aRefPoint.nPos, - nItemId, + rItemId, rCommandMap, rModuleIdentifier, rInstruction.aMergeCommand, @@ -359,7 +359,7 @@ public: else { ToolBarMerger::ProcessMergeFallback( m_pToolBar, - nItemId, + rItemId, rCommandMap, rModuleIdentifier, rInstruction.aMergeCommand, @@ -521,7 +521,7 @@ public: virtual void SetMenuType(ToolBoxMenuType /*eType*/) override {} - virtual void MergeToolbar(ToolBoxItemId /*nItemId*/, + virtual void MergeToolbar(ToolBoxItemId & /*rItemId*/, const OUString& /*rModuleIdentifier*/, CommandToInfoMap& /*rCommandMap*/, MergeToolbarInstruction& /*rInstruction*/) override {} diff --git a/framework/source/uielement/toolbarmerger.cxx b/framework/source/uielement/toolbarmerger.cxx index 652383988bcd..faba3cb4e8d9 100644 --- a/framework/source/uielement/toolbarmerger.cxx +++ b/framework/source/uielement/toolbarmerger.cxx @@ -623,6 +623,8 @@ rtl::Reference<::cppu::OWeakObject> ToolBarMerger::CreateController( void ToolBarMerger::CreateToolbarItem( ToolBox* pToolbar, ToolBox::ImplToolItems::size_type nPos, ToolBoxItemId nItemId, const AddonToolbarItem& rItem ) { + assert(pToolbar->GetItemData(nItemId) == nullptr); // that future would contain a double free + pToolbar->InsertItem( nItemId, rItem.aLabel, ToolBoxItemBits::NONE, nPos ); pToolbar->SetItemCommand( nItemId, rItem.aCommandURL ); pToolbar->SetQuickHelpText( nItemId, rItem.aLabel ); commit c1a8ff837e3e369561150c0022c6ab02aab27c2c Author: Katarina Behrens <bu...@bubli.org> AuthorDate: Mon Jul 19 17:42:02 2021 +0200 Commit: Katarina Behrens <bu...@bubli.org> CommitDate: Tue Jul 20 11:59:15 2021 +0200 tdf#128612: Support applying pattern fill from toolbar List available pattern fills and add 'pattern' case to state and execute functions This is likely not perfect and there's still boatloads of code duplication that should be cleaned up eventually, but hey, it fixes the bug Change-Id: I3381a4271bb32a63c048cbecb0b54ebabe12ef51 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119229 Tested-by: Jenkins Reviewed-by: Katarina Behrens <bu...@bubli.org> diff --git a/include/svx/fillctrl.hxx b/include/svx/fillctrl.hxx index 750257dd06f7..aedc5e6c173a 100644 --- a/include/svx/fillctrl.hxx +++ b/include/svx/fillctrl.hxx @@ -54,10 +54,11 @@ private: weld::Toolbar* mpToolBoxColor; weld::ComboBox* mpLbFillAttr; - css::drawing::FillStyle meLastXFS; + sal_Int32 mnLastXFS; sal_Int32 mnLastPosGradient; sal_Int32 mnLastPosHatch; sal_Int32 mnLastPosBitmap; + sal_Int32 mnLastPosPattern; DECL_LINK(SelectFillTypeHdl, weld::ComboBox&, void); DECL_LINK(SelectFillAttrHdl, weld::ComboBox&, void); diff --git a/svx/source/tbxctrls/fillctrl.cxx b/svx/source/tbxctrls/fillctrl.cxx index 3748265457d8..752424c34734 100644 --- a/svx/source/tbxctrls/fillctrl.cxx +++ b/svx/source/tbxctrls/fillctrl.cxx @@ -49,6 +49,30 @@ using namespace ::com::sun::star::util; using namespace ::com::sun::star::beans; using namespace ::com::sun::star::lang; +namespace { + +enum eFillStyle +{ + NONE, + SOLID, + GRADIENT, + HATCH, + BITMAP, + PATTERN +}; + +drawing::FillStyle toCssFillStyle( eFillStyle eXFS ) +{ + if (eXFS == PATTERN) + { + return drawing::FillStyle_BITMAP; + } + + return static_cast<drawing::FillStyle>(eXFS); +} + +} + SFX_IMPL_TOOLBOX_CONTROL( SvxFillToolBoxControl, XFillStyleItem ); SvxFillToolBoxControl::SvxFillToolBoxControl( @@ -65,10 +89,11 @@ SvxFillToolBoxControl::SvxFillToolBoxControl( , mpLbFillType(nullptr) , mpToolBoxColor(nullptr) , mpLbFillAttr(nullptr) - , meLastXFS(static_cast<drawing::FillStyle>(-1)) + , mnLastXFS(-1) , mnLastPosGradient(0) , mnLastPosHatch(0) , mnLastPosBitmap(0) + , mnLastPosPattern(0) { addStatusListener( ".uno:FillColor"); addStatusListener( ".uno:FillGradient"); @@ -103,7 +128,7 @@ void SvxFillToolBoxControl::StateChangedAtToolBoxControl( mpLbFillAttr->set_sensitive(false); mpLbFillAttr->set_active(-1); mpToolBoxColor->hide(); - meLastXFS = static_cast<drawing::FillStyle>(-1); + mnLastXFS = -1; mpStyleItem.reset(); } @@ -116,8 +141,15 @@ void SvxFillToolBoxControl::StateChangedAtToolBoxControl( mpStyleItem.reset(pItem->Clone()); mpLbFillType->set_sensitive(true); drawing::FillStyle eXFS = mpStyleItem->GetValue(); - meLastXFS = eXFS; - mpLbFillType->set_active(sal::static_int_cast< sal_Int32 >(eXFS)); + mnLastXFS = sal::static_int_cast< sal_Int32 >(eXFS); + + if (eXFS == drawing::FillStyle_BITMAP && + mpBitmapItem && mpBitmapItem->isPattern() ) + { + mnLastXFS = sal::static_int_cast<sal_Int32>(PATTERN); + } + + mpLbFillType->set_active(mnLastXFS); if(drawing::FillStyle_NONE == eXFS) { @@ -135,7 +167,7 @@ void SvxFillToolBoxControl::StateChangedAtToolBoxControl( mpLbFillAttr->set_sensitive(false); mpLbFillAttr->set_active(-1); mpToolBoxColor->hide(); - meLastXFS = static_cast<drawing::FillStyle>(-1); + mnLastXFS = -1; mpStyleItem.reset(); mxFillControl->Resize(); break; @@ -480,14 +512,15 @@ void SvxFillToolBoxControl::Update() mpToolBoxColor->hide(); mxFillControl->Resize(); - if(pSh && pSh->GetItem(SID_BITMAP_LIST)) + if(pSh) { mpLbFillAttr->set_sensitive(true); mpLbFillAttr->clear(); - SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_BITMAP_LIST)->GetBitmapList()); - if(mpBitmapItem) + if(mpBitmapItem && !mpBitmapItem->isPattern() && pSh->GetItem(SID_BITMAP_LIST)) { + SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_BITMAP_LIST)->GetBitmapList()); + const OUString aString(mpBitmapItem->GetName()); mpLbFillAttr->set_active_text(aString); @@ -520,6 +553,13 @@ void SvxFillToolBoxControl::Update() } } + else if (mpBitmapItem && mpBitmapItem->isPattern() && pSh->GetItem(SID_PATTERN_LIST)) + { + SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_PATTERN_LIST)->GetPatternList()); + const OUString aString(mpBitmapItem->GetName()); + + mpLbFillAttr->set_active_text(aString); + } else { mpLbFillAttr->set_active(-1); @@ -665,14 +705,15 @@ void FillControl::dispose() IMPL_LINK_NOARG(SvxFillToolBoxControl, SelectFillTypeHdl, weld::ComboBox&, void) { - const drawing::FillStyle eXFS = static_cast<drawing::FillStyle>(mpLbFillType->get_active()); + sal_Int32 nXFS = mpLbFillType->get_active(); - if(meLastXFS == eXFS) + if(mnLastXFS == nXFS) return; + eFillStyle eXFS = static_cast<eFillStyle>(nXFS); mpLbFillAttr->clear(); SfxObjectShell* pSh = SfxObjectShell::Current(); - const XFillStyleItem aXFillStyleItem(eXFS); + const XFillStyleItem aXFillStyleItem(toCssFillStyle(eXFS)); // #i122676# Do no longer trigger two Execute calls, one for SID_ATTR_FILL_STYLE // and one for setting the fill attribute itself, but add two SfxPoolItems to the @@ -681,7 +722,7 @@ IMPL_LINK_NOARG(SvxFillToolBoxControl, SelectFillTypeHdl, weld::ComboBox&, void) switch( eXFS ) { default: - case drawing::FillStyle_NONE: + case NONE: { mpLbFillAttr->show(); mpToolBoxColor->hide(); @@ -695,7 +736,7 @@ IMPL_LINK_NOARG(SvxFillToolBoxControl, SelectFillTypeHdl, weld::ComboBox&, void) } break; } - case drawing::FillStyle_SOLID: + case SOLID: { mpLbFillAttr->hide(); mpToolBoxColor->show(); @@ -710,7 +751,7 @@ IMPL_LINK_NOARG(SvxFillToolBoxControl, SelectFillTypeHdl, weld::ComboBox&, void) } break; } - case drawing::FillStyle_GRADIENT: + case GRADIENT: { mpLbFillAttr->show(); mpToolBoxColor->hide(); @@ -747,7 +788,7 @@ IMPL_LINK_NOARG(SvxFillToolBoxControl, SelectFillTypeHdl, weld::ComboBox&, void) } break; } - case drawing::FillStyle_HATCH: + case HATCH: { mpLbFillAttr->show(); mpToolBoxColor->hide(); @@ -784,7 +825,7 @@ IMPL_LINK_NOARG(SvxFillToolBoxControl, SelectFillTypeHdl, weld::ComboBox&, void) } break; } - case drawing::FillStyle_BITMAP: + case BITMAP: { mpLbFillAttr->show(); mpToolBoxColor->hide(); @@ -821,26 +862,66 @@ IMPL_LINK_NOARG(SvxFillToolBoxControl, SelectFillTypeHdl, weld::ComboBox&, void) } break; } + case PATTERN: + { + mpLbFillAttr->show(); + mpToolBoxColor->hide(); + + if(pSh && pSh->GetItem(SID_PATTERN_LIST)) + { + if(!mpLbFillAttr->get_count()) + { + mpLbFillAttr->set_sensitive(true); + mpLbFillAttr->clear(); + SvxFillAttrBox::Fill(*mpLbFillAttr, pSh->GetItem(SID_PATTERN_LIST)->GetPatternList()); + } + + if (mnLastPosPattern != -1) + { + const SvxPatternListItem * pItem = pSh->GetItem(SID_PATTERN_LIST); + + if(mnLastPosPattern < pItem->GetPatternList()->Count()) + { + const XBitmapEntry* pXBitmapEntry = pItem->GetPatternList()->GetBitmap(mnLastPosPattern); + const XFillBitmapItem aXFillBitmapItem(mpLbFillAttr->get_active_text(), pXBitmapEntry->GetGraphicObject()); + + // #i122676# change FillStyle and Bitmap in one call + pSh->GetDispatcher()->ExecuteList( + SID_ATTR_FILL_BITMAP, SfxCallMode::RECORD, + { &aXFillBitmapItem, &aXFillStyleItem }); + mpLbFillAttr->set_active(mnLastPosPattern); + } + } + } + else + { + mpLbFillAttr->set_sensitive(false); + } + break; + } + } - meLastXFS = eXFS; + mnLastXFS = nXFS; mxFillControl->Resize(); } IMPL_LINK_NOARG(SvxFillToolBoxControl, SelectFillAttrHdl, weld::ComboBox&, void) { - const drawing::FillStyle eXFS = static_cast<drawing::FillStyle>(mpLbFillType->get_active()); - const XFillStyleItem aXFillStyleItem(eXFS); + sal_Int32 nXFS = mpLbFillType->get_active(); + eFillStyle eXFS = static_cast<eFillStyle>(nXFS); + + const XFillStyleItem aXFillStyleItem(toCssFillStyle(eXFS)); SfxObjectShell* pSh = SfxObjectShell::Current(); // #i122676# dependent from bFillStyleChange, do execute a single or two // changes in one Execute call - const bool bFillStyleChange(meLastXFS != eXFS); + const bool bFillStyleChange(mnLastXFS != nXFS); - switch(eXFS) + switch (eXFS) { - case drawing::FillStyle_SOLID: + case SOLID: { if (bFillStyleChange && pSh) { @@ -851,7 +932,7 @@ IMPL_LINK_NOARG(SvxFillToolBoxControl, SelectFillAttrHdl, weld::ComboBox&, void) } break; } - case drawing::FillStyle_GRADIENT: + case GRADIENT: { sal_Int32 nPos = mpLbFillAttr->get_active(); @@ -884,7 +965,7 @@ IMPL_LINK_NOARG(SvxFillToolBoxControl, SelectFillAttrHdl, weld::ComboBox&, void) } break; } - case drawing::FillStyle_HATCH: + case HATCH: { sal_Int32 nPos = mpLbFillAttr->get_active(); @@ -917,7 +998,7 @@ IMPL_LINK_NOARG(SvxFillToolBoxControl, SelectFillAttrHdl, weld::ComboBox&, void) } break; } - case drawing::FillStyle_BITMAP: + case BITMAP: { sal_Int32 nPos = mpLbFillAttr->get_active(); @@ -950,6 +1031,40 @@ IMPL_LINK_NOARG(SvxFillToolBoxControl, SelectFillAttrHdl, weld::ComboBox&, void) } break; } + case PATTERN: + { + sal_Int32 nPos = mpLbFillAttr->get_active(); + + if (nPos == -1) + { + nPos = mnLastPosPattern; + } + + if (nPos != -1 && pSh && pSh->GetItem(SID_PATTERN_LIST)) + { + const SvxPatternListItem * pItem = pSh->GetItem(SID_PATTERN_LIST); + + if(nPos < pItem->GetPatternList()->Count()) + { + const XBitmapEntry* pXBitmapEntry = pItem->GetPatternList()->GetBitmap(nPos); + const XFillBitmapItem aXFillBitmapItem(mpLbFillAttr->get_active_text(), pXBitmapEntry->GetGraphicObject()); + + // #i122676# Change FillStyle and Bitmap in one call + pSh->GetDispatcher()->ExecuteList( + SID_ATTR_FILL_BITMAP, SfxCallMode::RECORD, + bFillStyleChange + ? std::initializer_list<SfxPoolItem const*>{ &aXFillBitmapItem, &aXFillStyleItem } + : std::initializer_list<SfxPoolItem const*>{ &aXFillBitmapItem }); + } + } + + if (nPos != -1) + { + mnLastPosPattern = nPos; + } + break; + } + default: break; } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits