Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / dialog / grfflt.cxx
blob81b9289009dda8cd3e0330dcb298365c7b6752eb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/BitmapSharpenFilter.hxx>
21 #include <vcl/BitmapMedianFilter.hxx>
22 #include <vcl/BitmapSobelGreyFilter.hxx>
23 #include <vcl/BitmapPopArtFilter.hxx>
25 #include <sfx2/viewfrm.hxx>
26 #include <sfx2/viewsh.hxx>
27 #include <sfx2/objsh.hxx>
28 #include <sfx2/request.hxx>
30 #include <osl/diagnose.h>
31 #include <svx/grfflt.hxx>
32 #include <svx/svxids.hrc>
33 #include <svx/svxdlg.hxx>
36 SvxGraphicFilterResult SvxGraphicFilter::ExecuteGrfFilterSlot( SfxRequest const & rReq, GraphicObject& rFilterObject )
38 const Graphic& rGraphic = rFilterObject.GetGraphic();
39 SvxGraphicFilterResult nRet = SvxGraphicFilterResult::UnsupportedGraphicType;
41 if( rGraphic.GetType() == GraphicType::Bitmap )
43 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
44 SfxObjectShell* pShell = pViewFrame ? pViewFrame->GetObjectShell() : nullptr;
45 weld::Window* pFrameWeld = (pViewFrame && pViewFrame->GetViewShell()) ? pViewFrame->GetViewShell()->GetFrameWeld() : nullptr;
46 Graphic aGraphic;
48 switch( rReq.GetSlot() )
50 case SID_GRFFILTER_INVERT:
52 if( pShell )
53 pShell->SetWaitCursor( true );
55 if( rGraphic.IsAnimated() )
57 Animation aAnimation( rGraphic.GetAnimation() );
59 if( aAnimation.Invert() )
60 aGraphic = aAnimation;
62 else
64 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
66 if( aBmpEx.Invert() )
67 aGraphic = aBmpEx;
70 if( pShell )
71 pShell->SetWaitCursor( false );
73 break;
75 case SID_GRFFILTER_SMOOTH:
77 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
78 ScopedVclPtr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterSmooth(pFrameWeld, rGraphic, 0.7));
79 if( aDlg->Execute() == RET_OK )
80 aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
82 break;
84 case SID_GRFFILTER_SHARPEN:
86 if( pShell )
87 pShell->SetWaitCursor( true );
89 if( rGraphic.IsAnimated() )
91 Animation aAnimation( rGraphic.GetAnimation() );
93 if (BitmapFilter::Filter(aAnimation, BitmapSharpenFilter()))
94 aGraphic = aAnimation;
96 else
98 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
100 if (BitmapFilter::Filter(aBmpEx, BitmapSharpenFilter()))
101 aGraphic = aBmpEx;
104 if( pShell )
105 pShell->SetWaitCursor( false );
107 break;
109 case SID_GRFFILTER_REMOVENOISE:
111 if( pShell )
112 pShell->SetWaitCursor( true );
114 if( rGraphic.IsAnimated() )
116 Animation aAnimation( rGraphic.GetAnimation() );
118 if (BitmapFilter::Filter(aAnimation, BitmapMedianFilter()))
119 aGraphic = aAnimation;
121 else
123 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
125 if (BitmapFilter::Filter(aBmpEx, BitmapMedianFilter()))
126 aGraphic = aBmpEx;
129 if( pShell )
130 pShell->SetWaitCursor( false );
132 break;
134 case SID_GRFFILTER_SOBEL:
136 if( pShell )
137 pShell->SetWaitCursor( true );
139 if( rGraphic.IsAnimated() )
141 Animation aAnimation( rGraphic.GetAnimation() );
143 if (BitmapFilter::Filter(aAnimation, BitmapSobelGreyFilter()))
144 aGraphic = aAnimation;
146 else
148 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
150 if (BitmapFilter::Filter(aBmpEx, BitmapSobelGreyFilter()))
151 aGraphic = aBmpEx;
154 if( pShell )
155 pShell->SetWaitCursor( false );
157 break;
159 case SID_GRFFILTER_MOSAIC:
161 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
162 ScopedVclPtr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterMosaic(pFrameWeld, rGraphic));
163 if( aDlg->Execute() == RET_OK )
164 aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
166 break;
168 case SID_GRFFILTER_EMBOSS:
170 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
171 ScopedVclPtr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterEmboss(pFrameWeld, rGraphic));
172 if( aDlg->Execute() == RET_OK )
173 aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
175 break;
177 case SID_GRFFILTER_POSTER:
179 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
180 ScopedVclPtr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterPoster(pFrameWeld, rGraphic));
181 if( aDlg->Execute() == RET_OK )
182 aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
184 break;
186 case SID_GRFFILTER_POPART:
188 if( pShell )
189 pShell->SetWaitCursor( true );
191 if( rGraphic.IsAnimated() )
193 Animation aAnimation( rGraphic.GetAnimation() );
195 if (BitmapFilter::Filter(aAnimation, BitmapPopArtFilter()))
196 aGraphic = aAnimation;
198 else
200 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
202 if (BitmapFilter::Filter(aBmpEx, BitmapPopArtFilter()))
203 aGraphic = aBmpEx;
206 if( pShell )
207 pShell->SetWaitCursor( false );
209 break;
211 case SID_GRFFILTER_SEPIA:
213 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
214 ScopedVclPtr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterSepia(pFrameWeld, rGraphic));
215 if( aDlg->Execute() == RET_OK )
216 aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
218 break;
220 case SID_GRFFILTER_SOLARIZE:
222 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
223 ScopedVclPtr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterSolarize(pFrameWeld, rGraphic));
224 if( aDlg->Execute() == RET_OK )
225 aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
227 break;
229 case SID_GRFFILTER :
231 // do nothing; no error
232 nRet = SvxGraphicFilterResult::NONE;
233 break;
236 default:
238 OSL_FAIL( "SvxGraphicFilter: selected filter slot not yet implemented" );
239 nRet = SvxGraphicFilterResult::UnsupportedSlot;
241 break;
244 if( aGraphic.GetType() != GraphicType::NONE )
246 rFilterObject.SetGraphic( aGraphic );
247 nRet = SvxGraphicFilterResult::NONE;
251 return nRet;
255 void SvxGraphicFilter::DisableGraphicFilterSlots( SfxItemSet& rSet )
257 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER ) )
258 rSet.DisableItem( SID_GRFFILTER );
260 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_INVERT ) )
261 rSet.DisableItem( SID_GRFFILTER_INVERT );
263 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_SMOOTH ) )
264 rSet.DisableItem( SID_GRFFILTER_SMOOTH );
266 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_SHARPEN ) )
267 rSet.DisableItem( SID_GRFFILTER_SHARPEN );
269 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_REMOVENOISE ) )
270 rSet.DisableItem( SID_GRFFILTER_REMOVENOISE );
272 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_SOBEL ) )
273 rSet.DisableItem( SID_GRFFILTER_SOBEL );
275 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_MOSAIC ) )
276 rSet.DisableItem( SID_GRFFILTER_MOSAIC );
278 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_EMBOSS ) )
279 rSet.DisableItem( SID_GRFFILTER_EMBOSS );
281 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_POSTER ) )
282 rSet.DisableItem( SID_GRFFILTER_POSTER );
284 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_POPART ) )
285 rSet.DisableItem( SID_GRFFILTER_POPART );
287 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_SEPIA ) )
288 rSet.DisableItem( SID_GRFFILTER_SEPIA );
290 if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_SOLARIZE ) )
291 rSet.DisableItem( SID_GRFFILTER_SOLARIZE );
294 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */