cui/source/factory/dlgfact.cxx | 2 cui/source/factory/dlgfact.hxx | 2 include/svx/grfflt.hxx | 8 sc/source/ui/drawfunc/graphsh.cxx | 31 +- sd/source/ui/view/GraphicObjectBar.cxx | 36 +-- svx/source/dialog/grfflt.cxx | 383 +++++++++++++++++---------------- sw/source/uibase/shells/grfsh.cxx | 11 7 files changed, 242 insertions(+), 231 deletions(-)
New commits: commit 07b26af18d45ad7ecacc30c2c4cb2c23033e9f2d Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Mon Jan 22 16:01:03 2024 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Tue Jan 23 13:38:40 2024 +0100 make the graphic filter dialogs async Change-Id: I49a1ff800c6b5fcee69e160158a089659d288bdc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162422 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/cui/source/factory/dlgfact.cxx b/cui/source/factory/dlgfact.cxx index f30ba3115851..21eb97db09a5 100644 --- a/cui/source/factory/dlgfact.cxx +++ b/cui/source/factory/dlgfact.cxx @@ -108,7 +108,7 @@ IMPL_ABSTDLG_CLASS(AbstractFmInputRecordNoDialog) IMPL_ABSTDLG_CLASS(AbstractFmSearchDialog) IMPL_ABSTDLG_CLASS(AbstractFmShowColsDialog) IMPL_ABSTDLG_CLASS(AbstractGalleryIdDialog) -IMPL_ABSTDLG_CLASS(AbstractGraphicFilterDialog) +IMPL_ABSTDLG_CLASS_ASYNC(AbstractGraphicFilterDialog, GraphicFilterDialog) IMPL_ABSTDLG_CLASS(AbstractHangulHanjaConversionDialog) IMPL_ABSTDLG_CLASS(AbstractInsertObjectDialog) IMPL_ABSTDLG_CLASS_ASYNC(AbstractLinksDialog, SvBaseLinksDlg) diff --git a/cui/source/factory/dlgfact.hxx b/cui/source/factory/dlgfact.hxx index c2fc4ebf3a4f..ebb5f85a6b4e 100644 --- a/cui/source/factory/dlgfact.hxx +++ b/cui/source/factory/dlgfact.hxx @@ -329,7 +329,7 @@ DECL_ABSTDLG_CLASS(AbstractFmSearchDialog,FmSearchDialog) }; // AbstractGraphicFilterDialog_Impl -DECL_ABSTDLG_CLASS(AbstractGraphicFilterDialog,GraphicFilterDialog) +DECL_ABSTDLG_CLASS_ASYNC(AbstractGraphicFilterDialog,GraphicFilterDialog) virtual Graphic GetFilteredGraphic( const Graphic& rGraphic, double fScaleX, double fScaleY ) override; }; diff --git a/include/svx/grfflt.hxx b/include/svx/grfflt.hxx index 7c24bcd38c92..731ef94bcdcb 100644 --- a/include/svx/grfflt.hxx +++ b/include/svx/grfflt.hxx @@ -22,10 +22,6 @@ #include <svx/svxdllapi.h> -enum class SvxGraphicFilterResult { - NONE, UnsupportedGraphicType, UnsupportedSlot -}; - class GraphicObject; class SfxRequest; class SfxItemSet; @@ -34,7 +30,9 @@ class SVX_DLLPUBLIC SvxGraphicFilter { public: - static SvxGraphicFilterResult ExecuteGrfFilterSlot( SfxRequest const & rReq, GraphicObject& rFilterObject ); + /// this will execute a dialog and then call function f with the output of the filtering operation + static void ExecuteGrfFilterSlot( SfxRequest const & rReq, const GraphicObject& rInputObject, + std::function<void(GraphicObject)> f); static void DisableGraphicFilterSlots( SfxItemSet& rSet ); }; diff --git a/sc/source/ui/drawfunc/graphsh.cxx b/sc/source/ui/drawfunc/graphsh.cxx index 9252dffa7695..c383d6e42620 100644 --- a/sc/source/ui/drawfunc/graphsh.cxx +++ b/sc/source/ui/drawfunc/graphsh.cxx @@ -111,27 +111,22 @@ void ScGraphicShell::ExecuteFilter( const SfxRequest& rReq ) if( auto pGraphicObj = dynamic_cast<SdrGrafObj*>( pObj) ) if( pGraphicObj->GetGraphicType() == GraphicType::Bitmap ) { - GraphicObject aFilterObj( pGraphicObj->GetGraphicObject() ); - - if( SvxGraphicFilterResult::NONE == - SvxGraphicFilter::ExecuteGrfFilterSlot( rReq, aFilterObj ) ) - { - SdrPageView* pPageView = pView->GetSdrPageView(); - - if( pPageView ) + SvxGraphicFilter::ExecuteGrfFilterSlot( rReq, pGraphicObj->GetGraphicObject(), + [this, pView, pGraphicObj, pObj] (GraphicObject aFilterObj) -> void { - rtl::Reference<SdrGrafObj> pFilteredObj = SdrObject::Clone(*pGraphicObj, pGraphicObj->getSdrModelFromSdrObject()); - OUString aStr = pView->GetDescriptionOfMarkedObjects() + " " + ScResId(SCSTR_UNDO_GRAFFILTER); - pView->BegUndo( aStr ); - pFilteredObj->SetGraphicObject( aFilterObj ); - pView->ReplaceObjectAtView( pObj, *pPageView, pFilteredObj.get() ); - pView->EndUndo(); - } - } + if( SdrPageView* pPageView = pView->GetSdrPageView() ) + { + rtl::Reference<SdrGrafObj> pFilteredObj = SdrObject::Clone(*pGraphicObj, pGraphicObj->getSdrModelFromSdrObject()); + OUString aStr = pView->GetDescriptionOfMarkedObjects() + " " + ScResId(SCSTR_UNDO_GRAFFILTER); + pView->BegUndo( aStr ); + pFilteredObj->SetGraphicObject( aFilterObj ); + pView->ReplaceObjectAtView( pObj, *pPageView, pFilteredObj.get() ); + pView->EndUndo(); + } + Invalidate(); + }); } } - - Invalidate(); } void ScGraphicShell::GetExternalEditState( SfxItemSet& rSet ) diff --git a/sd/source/ui/view/GraphicObjectBar.cxx b/sd/source/ui/view/GraphicObjectBar.cxx index b1e94f7219ec..a96eeabcaea5 100644 --- a/sd/source/ui/view/GraphicObjectBar.cxx +++ b/sd/source/ui/view/GraphicObjectBar.cxx @@ -110,30 +110,24 @@ void GraphicObjectBar::ExecuteFilter( SfxRequest const & rReq ) if( auto pGrafObj = dynamic_cast< SdrGrafObj *>( pObj ) ) if( pGrafObj->GetGraphicType() == GraphicType::Bitmap ) { - GraphicObject aFilterObj( pGrafObj->GetGraphicObject() ); - - if( SvxGraphicFilterResult::NONE == - SvxGraphicFilter::ExecuteGrfFilterSlot( rReq, aFilterObj ) ) - { - SdrPageView* pPageView = mpView->GetSdrPageView(); - - if( pPageView ) + SvxGraphicFilter::ExecuteGrfFilterSlot( rReq, pGrafObj->GetGraphicObject(), + [this, pObj] (GraphicObject aFilterObj) -> void { - rtl::Reference<SdrGrafObj> pFilteredObj = SdrObject::Clone(static_cast<SdrGrafObj&>(*pObj), pObj->getSdrModelFromSdrObject()); - OUString aStr = mpView->GetDescriptionOfMarkedObjects() + - " " + SdResId(STR_UNDO_GRAFFILTER); - mpView->BegUndo( aStr ); - pFilteredObj->SetGraphicObject( aFilterObj ); - ::sd::View* const pView = mpView; - pView->ReplaceObjectAtView( pObj, *pPageView, pFilteredObj.get() ); - pView->EndUndo(); - return; - } - } + if (SdrPageView* pPageView = mpView->GetSdrPageView()) + { + rtl::Reference<SdrGrafObj> pFilteredObj = SdrObject::Clone(static_cast<SdrGrafObj&>(*pObj), pObj->getSdrModelFromSdrObject()); + OUString aStr = mpView->GetDescriptionOfMarkedObjects() + + " " + SdResId(STR_UNDO_GRAFFILTER); + mpView->BegUndo( aStr ); + pFilteredObj->SetGraphicObject( aFilterObj ); + ::sd::View* const pView = mpView; + pView->ReplaceObjectAtView( pObj, *pPageView, pFilteredObj.get() ); + pView->EndUndo(); + } + Invalidate(); + }); } } - - Invalidate(); } } // end of namespace sd diff --git a/svx/source/dialog/grfflt.cxx b/svx/source/dialog/grfflt.cxx index 81b9289009dd..562e0d52c990 100644 --- a/svx/source/dialog/grfflt.cxx +++ b/svx/source/dialog/grfflt.cxx @@ -33,224 +33,247 @@ #include <svx/svxdlg.hxx> -SvxGraphicFilterResult SvxGraphicFilter::ExecuteGrfFilterSlot( SfxRequest const & rReq, GraphicObject& rFilterObject ) +static void handleGraphicFilterDialog(const VclPtr<AbstractGraphicFilterDialog>& pDlg, + const Graphic& aInputGraphic, + std::function<void(GraphicObject)> f); + +void SvxGraphicFilter::ExecuteGrfFilterSlot( SfxRequest const & rReq, + const GraphicObject& rInputObject, + std::function<void(GraphicObject)> f) { - const Graphic& rGraphic = rFilterObject.GetGraphic(); - SvxGraphicFilterResult nRet = SvxGraphicFilterResult::UnsupportedGraphicType; + Graphic aInputGraphic = rInputObject.GetGraphic(); - if( rGraphic.GetType() == GraphicType::Bitmap ) - { - SfxViewFrame* pViewFrame = SfxViewFrame::Current(); - SfxObjectShell* pShell = pViewFrame ? pViewFrame->GetObjectShell() : nullptr; - weld::Window* pFrameWeld = (pViewFrame && pViewFrame->GetViewShell()) ? pViewFrame->GetViewShell()->GetFrameWeld() : nullptr; - Graphic aGraphic; + if( aInputGraphic.GetType() != GraphicType::Bitmap ) + return; + + SfxViewFrame* pViewFrame = SfxViewFrame::Current(); + SfxObjectShell* pShell = pViewFrame ? pViewFrame->GetObjectShell() : nullptr; + weld::Window* pFrameWeld = (pViewFrame && pViewFrame->GetViewShell()) ? pViewFrame->GetViewShell()->GetFrameWeld() : nullptr; - switch( rReq.GetSlot() ) + switch( rReq.GetSlot() ) + { + case SID_GRFFILTER_INVERT: { - case SID_GRFFILTER_INVERT: - { - if( pShell ) - pShell->SetWaitCursor( true ); - - if( rGraphic.IsAnimated() ) - { - Animation aAnimation( rGraphic.GetAnimation() ); - - if( aAnimation.Invert() ) - aGraphic = aAnimation; - } - else - { - BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); - - if( aBmpEx.Invert() ) - aGraphic = aBmpEx; - } - - if( pShell ) - pShell->SetWaitCursor( false ); - } - break; + Graphic aOutputGraphic; - case SID_GRFFILTER_SMOOTH: - { - SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - ScopedVclPtr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterSmooth(pFrameWeld, rGraphic, 0.7)); - if( aDlg->Execute() == RET_OK ) - aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 ); - } - break; + if( pShell ) + pShell->SetWaitCursor( true ); - case SID_GRFFILTER_SHARPEN: + if( aInputGraphic.IsAnimated() ) { - if( pShell ) - pShell->SetWaitCursor( true ); - - if( rGraphic.IsAnimated() ) - { - Animation aAnimation( rGraphic.GetAnimation() ); - - if (BitmapFilter::Filter(aAnimation, BitmapSharpenFilter())) - aGraphic = aAnimation; - } - else - { - BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); - - if (BitmapFilter::Filter(aBmpEx, BitmapSharpenFilter())) - aGraphic = aBmpEx; - } - - if( pShell ) - pShell->SetWaitCursor( false ); - } - break; + Animation aAnimation( aInputGraphic.GetAnimation() ); - case SID_GRFFILTER_REMOVENOISE: - { - if( pShell ) - pShell->SetWaitCursor( true ); - - if( rGraphic.IsAnimated() ) - { - Animation aAnimation( rGraphic.GetAnimation() ); - - if (BitmapFilter::Filter(aAnimation, BitmapMedianFilter())) - aGraphic = aAnimation; - } - else - { - BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); - - if (BitmapFilter::Filter(aBmpEx, BitmapMedianFilter())) - aGraphic = aBmpEx; - } - - if( pShell ) - pShell->SetWaitCursor( false ); + if( aAnimation.Invert() ) + aOutputGraphic = aAnimation; } - break; - - case SID_GRFFILTER_SOBEL: + else { - if( pShell ) - pShell->SetWaitCursor( true ); - - if( rGraphic.IsAnimated() ) - { - Animation aAnimation( rGraphic.GetAnimation() ); - - if (BitmapFilter::Filter(aAnimation, BitmapSobelGreyFilter())) - aGraphic = aAnimation; - } - else - { - BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); - - if (BitmapFilter::Filter(aBmpEx, BitmapSobelGreyFilter())) - aGraphic = aBmpEx; - } - - if( pShell ) - pShell->SetWaitCursor( false ); + BitmapEx aBmpEx( aInputGraphic.GetBitmapEx() ); + + if( aBmpEx.Invert() ) + aOutputGraphic = aBmpEx; } - break; - case SID_GRFFILTER_MOSAIC: + if( pShell ) + pShell->SetWaitCursor( false ); + + if( aOutputGraphic.GetType() != GraphicType::NONE ) + f(aOutputGraphic); + } + break; + + case SID_GRFFILTER_SMOOTH: + { + SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); + handleGraphicFilterDialog(pFact->CreateGraphicFilterSmooth(pFrameWeld, aInputGraphic, 0.7), aInputGraphic, f); + } + break; + + case SID_GRFFILTER_SHARPEN: + { + Graphic aOutputGraphic; + + if( pShell ) + pShell->SetWaitCursor( true ); + + if( aInputGraphic.IsAnimated() ) { - SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - ScopedVclPtr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterMosaic(pFrameWeld, rGraphic)); - if( aDlg->Execute() == RET_OK ) - aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 ); - } - break; + Animation aAnimation( aInputGraphic.GetAnimation() ); - case SID_GRFFILTER_EMBOSS: + if (BitmapFilter::Filter(aAnimation, BitmapSharpenFilter())) + aOutputGraphic = aAnimation; + } + else { - SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - ScopedVclPtr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterEmboss(pFrameWeld, rGraphic)); - if( aDlg->Execute() == RET_OK ) - aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 ); + BitmapEx aBmpEx( aInputGraphic.GetBitmapEx() ); + + if (BitmapFilter::Filter(aBmpEx, BitmapSharpenFilter())) + aOutputGraphic = aBmpEx; } - break; - case SID_GRFFILTER_POSTER: + if( pShell ) + pShell->SetWaitCursor( false ); + + if( aOutputGraphic.GetType() != GraphicType::NONE ) + f(aOutputGraphic); + } + break; + + case SID_GRFFILTER_REMOVENOISE: + { + Graphic aOutputGraphic; + + if( pShell ) + pShell->SetWaitCursor( true ); + + if( aInputGraphic.IsAnimated() ) { - SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - ScopedVclPtr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterPoster(pFrameWeld, rGraphic)); - if( aDlg->Execute() == RET_OK ) - aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 ); - } - break; + Animation aAnimation( aInputGraphic.GetAnimation() ); - case SID_GRFFILTER_POPART: + if (BitmapFilter::Filter(aAnimation, BitmapMedianFilter())) + aOutputGraphic = aAnimation; + } + else { - if( pShell ) - pShell->SetWaitCursor( true ); - - if( rGraphic.IsAnimated() ) - { - Animation aAnimation( rGraphic.GetAnimation() ); - - if (BitmapFilter::Filter(aAnimation, BitmapPopArtFilter())) - aGraphic = aAnimation; - } - else - { - BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); - - if (BitmapFilter::Filter(aBmpEx, BitmapPopArtFilter())) - aGraphic = aBmpEx; - } - - if( pShell ) - pShell->SetWaitCursor( false ); + BitmapEx aBmpEx( aInputGraphic.GetBitmapEx() ); + + if (BitmapFilter::Filter(aBmpEx, BitmapMedianFilter())) + aOutputGraphic = aBmpEx; } - break; - case SID_GRFFILTER_SEPIA: + if( pShell ) + pShell->SetWaitCursor( false ); + + if( aOutputGraphic.GetType() != GraphicType::NONE ) + f(aOutputGraphic); + } + break; + + case SID_GRFFILTER_SOBEL: + { + Graphic aOutputGraphic; + + if( pShell ) + pShell->SetWaitCursor( true ); + + if( aInputGraphic.IsAnimated() ) { - SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - ScopedVclPtr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterSepia(pFrameWeld, rGraphic)); - if( aDlg->Execute() == RET_OK ) - aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 ); - } - break; + Animation aAnimation( aInputGraphic.GetAnimation() ); - case SID_GRFFILTER_SOLARIZE: + if (BitmapFilter::Filter(aAnimation, BitmapSobelGreyFilter())) + aOutputGraphic = aAnimation; + } + else { - SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); - ScopedVclPtr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterSolarize(pFrameWeld, rGraphic)); - if( aDlg->Execute() == RET_OK ) - aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 ); + BitmapEx aBmpEx( aInputGraphic.GetBitmapEx() ); + + if (BitmapFilter::Filter(aBmpEx, BitmapSobelGreyFilter())) + aOutputGraphic = aBmpEx; } - break; - case SID_GRFFILTER : + if( pShell ) + pShell->SetWaitCursor( false ); + + if( aOutputGraphic.GetType() != GraphicType::NONE ) + f(aOutputGraphic); + } + break; + + case SID_GRFFILTER_MOSAIC: + { + SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); + handleGraphicFilterDialog(pFact->CreateGraphicFilterMosaic(pFrameWeld, aInputGraphic), aInputGraphic, f); + } + break; + + case SID_GRFFILTER_EMBOSS: + { + SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); + handleGraphicFilterDialog(pFact->CreateGraphicFilterEmboss(pFrameWeld, aInputGraphic), aInputGraphic, f); + } + break; + + case SID_GRFFILTER_POSTER: + { + SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); + handleGraphicFilterDialog(pFact->CreateGraphicFilterPoster(pFrameWeld, aInputGraphic), aInputGraphic, f); + } + break; + + case SID_GRFFILTER_POPART: + { + Graphic aOutputGraphic; + + if( pShell ) + pShell->SetWaitCursor( true ); + + if( aInputGraphic.IsAnimated() ) { - // do nothing; no error - nRet = SvxGraphicFilterResult::NONE; - break; - } + Animation aAnimation( aInputGraphic.GetAnimation() ); - default: + if (BitmapFilter::Filter(aAnimation, BitmapPopArtFilter())) + aOutputGraphic = aAnimation; + } + else { - OSL_FAIL( "SvxGraphicFilter: selected filter slot not yet implemented" ); - nRet = SvxGraphicFilterResult::UnsupportedSlot; + BitmapEx aBmpEx( aInputGraphic.GetBitmapEx() ); + + if (BitmapFilter::Filter(aBmpEx, BitmapPopArtFilter())) + aOutputGraphic = aBmpEx; } - break; + + if( pShell ) + pShell->SetWaitCursor( false ); + + if( aOutputGraphic.GetType() != GraphicType::NONE ) + f(aOutputGraphic); } + break; - if( aGraphic.GetType() != GraphicType::NONE ) + case SID_GRFFILTER_SEPIA: { - rFilterObject.SetGraphic( aGraphic ); - nRet = SvxGraphicFilterResult::NONE; + SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); + handleGraphicFilterDialog(pFact->CreateGraphicFilterSepia(pFrameWeld, aInputGraphic), aInputGraphic, f); + } + break; + + case SID_GRFFILTER_SOLARIZE: + { + SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create(); + handleGraphicFilterDialog(pFact->CreateGraphicFilterSolarize(pFrameWeld, aInputGraphic), aInputGraphic, f); + } + break; + + case SID_GRFFILTER : + { + // do nothing; no error + return; } - } - return nRet; + default: + { + OSL_FAIL( "SvxGraphicFilter: selected filter slot not yet implemented" ); + return; + } + } } +static void handleGraphicFilterDialog(const VclPtr<AbstractGraphicFilterDialog>& pDlg, + const Graphic& aInputGraphic, + std::function<void(GraphicObject)> f) +{ + pDlg->StartExecuteAsync( + [pDlg, aInputGraphic, f] (sal_Int32 nResult)->void + { + if (nResult == RET_OK) + { + Graphic aOutputGraphic = pDlg->GetFilteredGraphic( aInputGraphic, 1.0, 1.0 ); + f(aOutputGraphic); + } + pDlg->disposeOnce(); + } + ); +} void SvxGraphicFilter::DisableGraphicFilterSlots( SfxItemSet& rSet ) { diff --git a/sw/source/uibase/shells/grfsh.cxx b/sw/source/uibase/shells/grfsh.cxx index bb090fed460d..4be126fc1595 100644 --- a/sw/source/uibase/shells/grfsh.cxx +++ b/sw/source/uibase/shells/grfsh.cxx @@ -689,11 +689,12 @@ void SwGrfShell::ExecAttr( SfxRequest const &rReq ) const GraphicObject* pFilterObj( GetShell().GetGraphicObj() ); if ( pFilterObj ) { - GraphicObject aFilterObj( *pFilterObj ); - if( SvxGraphicFilterResult::NONE == - SvxGraphicFilter::ExecuteGrfFilterSlot( rReq, aFilterObj )) - GetShell().ReRead( OUString(), OUString(), - &aFilterObj.GetGraphic() ); + SvxGraphicFilter::ExecuteGrfFilterSlot( rReq, *pFilterObj, + [this] (GraphicObject aFilteredObject) -> void + { + GetShell().ReRead( OUString(), OUString(), + &aFilteredObject.GetGraphic() ); + }); } } break;