1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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;
48 switch( rReq
.GetSlot() )
50 case SID_GRFFILTER_INVERT
:
53 pShell
->SetWaitCursor( true );
55 if( rGraphic
.IsAnimated() )
57 Animation
aAnimation( rGraphic
.GetAnimation() );
59 if( aAnimation
.Invert() )
60 aGraphic
= aAnimation
;
64 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
71 pShell
->SetWaitCursor( false );
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 );
84 case SID_GRFFILTER_SHARPEN
:
87 pShell
->SetWaitCursor( true );
89 if( rGraphic
.IsAnimated() )
91 Animation
aAnimation( rGraphic
.GetAnimation() );
93 if (BitmapFilter::Filter(aAnimation
, BitmapSharpenFilter()))
94 aGraphic
= aAnimation
;
98 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
100 if (BitmapFilter::Filter(aBmpEx
, BitmapSharpenFilter()))
105 pShell
->SetWaitCursor( false );
109 case SID_GRFFILTER_REMOVENOISE
:
112 pShell
->SetWaitCursor( true );
114 if( rGraphic
.IsAnimated() )
116 Animation
aAnimation( rGraphic
.GetAnimation() );
118 if (BitmapFilter::Filter(aAnimation
, BitmapMedianFilter()))
119 aGraphic
= aAnimation
;
123 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
125 if (BitmapFilter::Filter(aBmpEx
, BitmapMedianFilter()))
130 pShell
->SetWaitCursor( false );
134 case SID_GRFFILTER_SOBEL
:
137 pShell
->SetWaitCursor( true );
139 if( rGraphic
.IsAnimated() )
141 Animation
aAnimation( rGraphic
.GetAnimation() );
143 if (BitmapFilter::Filter(aAnimation
, BitmapSobelGreyFilter()))
144 aGraphic
= aAnimation
;
148 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
150 if (BitmapFilter::Filter(aBmpEx
, BitmapSobelGreyFilter()))
155 pShell
->SetWaitCursor( false );
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 );
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 );
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 );
186 case SID_GRFFILTER_POPART
:
189 pShell
->SetWaitCursor( true );
191 if( rGraphic
.IsAnimated() )
193 Animation
aAnimation( rGraphic
.GetAnimation() );
195 if (BitmapFilter::Filter(aAnimation
, BitmapPopArtFilter()))
196 aGraphic
= aAnimation
;
200 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
202 if (BitmapFilter::Filter(aBmpEx
, BitmapPopArtFilter()))
207 pShell
->SetWaitCursor( false );
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 );
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 );
231 // do nothing; no error
232 nRet
= SvxGraphicFilterResult::NONE
;
238 OSL_FAIL( "SvxGraphicFilter: selected filter slot not yet implemented" );
239 nRet
= SvxGraphicFilterResult::UnsupportedSlot
;
244 if( aGraphic
.GetType() != GraphicType::NONE
)
246 rFilterObject
.SetGraphic( aGraphic
);
247 nRet
= SvxGraphicFilterResult::NONE
;
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: */