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/msgbox.hxx>
21 #include <sfx2/viewfrm.hxx>
22 #include <sfx2/viewsh.hxx>
23 #include <sfx2/objsh.hxx>
24 #include <sfx2/request.hxx>
26 #include <svx/dialmgr.hxx>
27 #include <svx/grfflt.hxx>
28 #include <svx/dialogs.hrc>
29 #include <svx/svxdlg.hxx>
30 #include <boost/scoped_ptr.hpp>
33 // - SvxGraphicFilter -
36 sal_uIntPtr
SvxGraphicFilter::ExecuteGrfFilterSlot( SfxRequest
& rReq
, GraphicObject
& rFilterObject
)
38 const Graphic
& rGraphic
= rFilterObject
.GetGraphic();
39 sal_uIntPtr nRet
= SVX_GRAPHICFILTER_UNSUPPORTED_GRAPHICTYPE
;
41 if( rGraphic
.GetType() == GRAPHIC_BITMAP
)
43 SfxViewFrame
* pViewFrame
= SfxViewFrame::Current();
44 SfxObjectShell
* pShell
= pViewFrame
? pViewFrame
->GetObjectShell() : NULL
;
45 vcl::Window
* pWindow
= ( pViewFrame
&& pViewFrame
->GetViewShell() ) ? pViewFrame
->GetViewShell()->GetWindow() : NULL
;
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();
80 boost::scoped_ptr
<AbstractGraphicFilterDialog
> aDlg(pFact
->CreateGraphicFilterSmooth(pWindow
, rGraphic
, 0.7));
81 DBG_ASSERT(aDlg
, "Dialog creation failed!");
82 if( aDlg
->Execute() == RET_OK
)
83 aGraphic
= aDlg
->GetFilteredGraphic( rGraphic
, 1.0, 1.0 );
88 case( SID_GRFFILTER_SHARPEN
):
91 pShell
->SetWaitCursor( true );
93 if( rGraphic
.IsAnimated() )
95 Animation
aAnimation( rGraphic
.GetAnimation() );
97 if( aAnimation
.Filter( BMP_FILTER_SHARPEN
) )
98 aGraphic
= aAnimation
;
102 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
104 if( aBmpEx
.Filter( BMP_FILTER_SHARPEN
) )
109 pShell
->SetWaitCursor( false );
113 case( SID_GRFFILTER_REMOVENOISE
):
116 pShell
->SetWaitCursor( true );
118 if( rGraphic
.IsAnimated() )
120 Animation
aAnimation( rGraphic
.GetAnimation() );
122 if( aAnimation
.Filter( BMP_FILTER_REMOVENOISE
) )
123 aGraphic
= aAnimation
;
127 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
129 if( aBmpEx
.Filter( BMP_FILTER_REMOVENOISE
) )
134 pShell
->SetWaitCursor( false );
138 case( SID_GRFFILTER_SOBEL
):
141 pShell
->SetWaitCursor( true );
143 if( rGraphic
.IsAnimated() )
145 Animation
aAnimation( rGraphic
.GetAnimation() );
147 if( aAnimation
.Filter( BMP_FILTER_SOBEL_GREY
) )
148 aGraphic
= aAnimation
;
152 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
154 if( aBmpEx
.Filter( BMP_FILTER_SOBEL_GREY
) )
159 pShell
->SetWaitCursor( false );
163 case( SID_GRFFILTER_MOSAIC
):
165 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
168 boost::scoped_ptr
<AbstractGraphicFilterDialog
> aDlg(pFact
->CreateGraphicFilterMosaic(pWindow
, rGraphic
, 4, 4, false));
169 DBG_ASSERT(aDlg
, "Dialog creation failed!");
170 if( aDlg
->Execute() == RET_OK
)
171 aGraphic
= aDlg
->GetFilteredGraphic( rGraphic
, 1.0, 1.0 );
176 case( SID_GRFFILTER_EMBOSS
):
178 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
181 boost::scoped_ptr
<AbstractGraphicFilterDialog
> aDlg(pFact
->CreateGraphicFilterEmboss(pWindow
, rGraphic
, RP_MM
));
182 DBG_ASSERT(aDlg
, "Dialog creation failed!");
183 if( aDlg
->Execute() == RET_OK
)
184 aGraphic
= aDlg
->GetFilteredGraphic( rGraphic
, 1.0, 1.0 );
189 case( SID_GRFFILTER_POSTER
):
191 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
194 boost::scoped_ptr
<AbstractGraphicFilterDialog
> aDlg(pFact
->CreateGraphicFilterPoster(pWindow
, rGraphic
, 16));
195 DBG_ASSERT(aDlg
, "Dialog creation failed!");
196 if( aDlg
->Execute() == RET_OK
)
197 aGraphic
= aDlg
->GetFilteredGraphic( rGraphic
, 1.0, 1.0 );
202 case( SID_GRFFILTER_POPART
):
205 pShell
->SetWaitCursor( true );
207 if( rGraphic
.IsAnimated() )
209 Animation
aAnimation( rGraphic
.GetAnimation() );
211 if( aAnimation
.Filter( BMP_FILTER_POPART
) )
212 aGraphic
= aAnimation
;
216 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
218 if( aBmpEx
.Filter( BMP_FILTER_POPART
) )
223 pShell
->SetWaitCursor( false );
227 case( SID_GRFFILTER_SEPIA
):
229 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
232 boost::scoped_ptr
<AbstractGraphicFilterDialog
> aDlg(pFact
->CreateGraphicFilterSepia(pWindow
, rGraphic
, 10));
233 DBG_ASSERT(aDlg
, "Dialog creation failed!");
234 if( aDlg
->Execute() == RET_OK
)
235 aGraphic
= aDlg
->GetFilteredGraphic( rGraphic
, 1.0, 1.0 );
240 case( SID_GRFFILTER_SOLARIZE
):
242 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
245 boost::scoped_ptr
<AbstractGraphicFilterDialog
> aDlg(pFact
->CreateGraphicFilterSolarize(pWindow
, rGraphic
, 128, false));
246 DBG_ASSERT(aDlg
, "Dialog creation failed!");
247 if( aDlg
->Execute() == RET_OK
)
248 aGraphic
= aDlg
->GetFilteredGraphic( rGraphic
, 1.0, 1.0 );
255 // do nothing; no error
256 nRet
= SVX_GRAPHICFILTER_ERRCODE_NONE
;
262 OSL_FAIL( "SvxGraphicFilter: selected filter slot not yet implemented" );
263 nRet
= SVX_GRAPHICFILTER_UNSUPPORTED_SLOT
;
268 if( aGraphic
.GetType() != GRAPHIC_NONE
)
270 rFilterObject
.SetGraphic( aGraphic
);
271 nRet
= SVX_GRAPHICFILTER_ERRCODE_NONE
;
280 void SvxGraphicFilter::DisableGraphicFilterSlots( SfxItemSet
& rSet
)
282 if( SfxItemState::DEFAULT
<= rSet
.GetItemState( SID_GRFFILTER
) )
283 rSet
.DisableItem( SID_GRFFILTER
);
285 if( SfxItemState::DEFAULT
<= rSet
.GetItemState( SID_GRFFILTER_INVERT
) )
286 rSet
.DisableItem( SID_GRFFILTER_INVERT
);
288 if( SfxItemState::DEFAULT
<= rSet
.GetItemState( SID_GRFFILTER_SMOOTH
) )
289 rSet
.DisableItem( SID_GRFFILTER_SMOOTH
);
291 if( SfxItemState::DEFAULT
<= rSet
.GetItemState( SID_GRFFILTER_SHARPEN
) )
292 rSet
.DisableItem( SID_GRFFILTER_SHARPEN
);
294 if( SfxItemState::DEFAULT
<= rSet
.GetItemState( SID_GRFFILTER_REMOVENOISE
) )
295 rSet
.DisableItem( SID_GRFFILTER_REMOVENOISE
);
297 if( SfxItemState::DEFAULT
<= rSet
.GetItemState( SID_GRFFILTER_SOBEL
) )
298 rSet
.DisableItem( SID_GRFFILTER_SOBEL
);
300 if( SfxItemState::DEFAULT
<= rSet
.GetItemState( SID_GRFFILTER_MOSAIC
) )
301 rSet
.DisableItem( SID_GRFFILTER_MOSAIC
);
303 if( SfxItemState::DEFAULT
<= rSet
.GetItemState( SID_GRFFILTER_EMBOSS
) )
304 rSet
.DisableItem( SID_GRFFILTER_EMBOSS
);
306 if( SfxItemState::DEFAULT
<= rSet
.GetItemState( SID_GRFFILTER_POSTER
) )
307 rSet
.DisableItem( SID_GRFFILTER_POSTER
);
309 if( SfxItemState::DEFAULT
<= rSet
.GetItemState( SID_GRFFILTER_POPART
) )
310 rSet
.DisableItem( SID_GRFFILTER_POPART
);
312 if( SfxItemState::DEFAULT
<= rSet
.GetItemState( SID_GRFFILTER_SEPIA
) )
313 rSet
.DisableItem( SID_GRFFILTER_SEPIA
);
315 if( SfxItemState::DEFAULT
<= rSet
.GetItemState( SID_GRFFILTER_SOLARIZE
) )
316 rSet
.DisableItem( SID_GRFFILTER_SOLARIZE
);
319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */