fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / svx / source / dialog / grfflt.cxx
blob2842ae87286abbade39ffd883b3f6aeb8aacbe7d
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/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;
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 if(pFact)
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 );
86 break;
88 case( SID_GRFFILTER_SHARPEN ):
90 if( pShell )
91 pShell->SetWaitCursor( true );
93 if( rGraphic.IsAnimated() )
95 Animation aAnimation( rGraphic.GetAnimation() );
97 if( aAnimation.Filter( BMP_FILTER_SHARPEN ) )
98 aGraphic = aAnimation;
100 else
102 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
104 if( aBmpEx.Filter( BMP_FILTER_SHARPEN ) )
105 aGraphic = aBmpEx;
108 if( pShell )
109 pShell->SetWaitCursor( false );
111 break;
113 case( SID_GRFFILTER_REMOVENOISE ):
115 if( pShell )
116 pShell->SetWaitCursor( true );
118 if( rGraphic.IsAnimated() )
120 Animation aAnimation( rGraphic.GetAnimation() );
122 if( aAnimation.Filter( BMP_FILTER_REMOVENOISE ) )
123 aGraphic = aAnimation;
125 else
127 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
129 if( aBmpEx.Filter( BMP_FILTER_REMOVENOISE ) )
130 aGraphic = aBmpEx;
133 if( pShell )
134 pShell->SetWaitCursor( false );
136 break;
138 case( SID_GRFFILTER_SOBEL ):
140 if( pShell )
141 pShell->SetWaitCursor( true );
143 if( rGraphic.IsAnimated() )
145 Animation aAnimation( rGraphic.GetAnimation() );
147 if( aAnimation.Filter( BMP_FILTER_SOBEL_GREY ) )
148 aGraphic = aAnimation;
150 else
152 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
154 if( aBmpEx.Filter( BMP_FILTER_SOBEL_GREY ) )
155 aGraphic = aBmpEx;
158 if( pShell )
159 pShell->SetWaitCursor( false );
161 break;
163 case( SID_GRFFILTER_MOSAIC ):
165 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
166 if(pFact)
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 );
174 break;
176 case( SID_GRFFILTER_EMBOSS ):
178 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
179 if(pFact)
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 );
187 break;
189 case( SID_GRFFILTER_POSTER ):
191 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
192 if(pFact)
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 );
200 break;
202 case( SID_GRFFILTER_POPART ):
204 if( pShell )
205 pShell->SetWaitCursor( true );
207 if( rGraphic.IsAnimated() )
209 Animation aAnimation( rGraphic.GetAnimation() );
211 if( aAnimation.Filter( BMP_FILTER_POPART ) )
212 aGraphic = aAnimation;
214 else
216 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
218 if( aBmpEx.Filter( BMP_FILTER_POPART ) )
219 aGraphic = aBmpEx;
222 if( pShell )
223 pShell->SetWaitCursor( false );
225 break;
227 case( SID_GRFFILTER_SEPIA ):
229 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
230 if(pFact)
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 );
238 break;
240 case( SID_GRFFILTER_SOLARIZE ):
242 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
243 if(pFact)
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 );
251 break;
253 case SID_GRFFILTER :
255 // do nothing; no error
256 nRet = SVX_GRAPHICFILTER_ERRCODE_NONE;
257 break;
260 default:
262 OSL_FAIL( "SvxGraphicFilter: selected filter slot not yet implemented" );
263 nRet = SVX_GRAPHICFILTER_UNSUPPORTED_SLOT;
265 break;
268 if( aGraphic.GetType() != GRAPHIC_NONE )
270 rFilterObject.SetGraphic( aGraphic );
271 nRet = SVX_GRAPHICFILTER_ERRCODE_NONE;
275 return nRet;
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: */