bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / dialog / grfflt.cxx
blob74ad3d11154747bc81c3120b9ed11720c976862d
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 <tools/shl.hxx>
21 #include <vcl/msgbox.hxx>
22 #include <sfx2/viewfrm.hxx>
23 #include <sfx2/viewsh.hxx>
24 #include <sfx2/objsh.hxx>
25 #include <sfx2/request.hxx>
27 #include <svx/dialmgr.hxx>
28 #include <svx/grfflt.hxx>
29 #include <svx/dialogs.hrc>
30 #include <svx/svxdlg.hxx>
32 // --------------------
33 // - SvxGraphicFilter -
34 // --------------------
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 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( sal_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( sal_False );
73 break;
75 case( SID_GRFFILTER_SMOOTH ):
77 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
78 if(pFact)
80 AbstractGraphicFilterDialog* aDlg = pFact->CreateGraphicFilterSmooth( pWindow, rGraphic, 0.7, RID_SVX_GRFFILTER_DLG_SEPIA);
81 DBG_ASSERT(aDlg, "Dialogdiet fail!");
82 if( aDlg->Execute() == RET_OK )
83 aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
84 delete aDlg;
87 break;
89 case( SID_GRFFILTER_SHARPEN ):
91 if( pShell )
92 pShell->SetWaitCursor( sal_True );
94 if( rGraphic.IsAnimated() )
96 Animation aAnimation( rGraphic.GetAnimation() );
98 if( aAnimation.Filter( BMP_FILTER_SHARPEN ) )
99 aGraphic = aAnimation;
101 else
103 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
105 if( aBmpEx.Filter( BMP_FILTER_SHARPEN ) )
106 aGraphic = aBmpEx;
109 if( pShell )
110 pShell->SetWaitCursor( sal_False );
112 break;
114 case( SID_GRFFILTER_REMOVENOISE ):
116 if( pShell )
117 pShell->SetWaitCursor( sal_True );
119 if( rGraphic.IsAnimated() )
121 Animation aAnimation( rGraphic.GetAnimation() );
123 if( aAnimation.Filter( BMP_FILTER_REMOVENOISE ) )
124 aGraphic = aAnimation;
126 else
128 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
130 if( aBmpEx.Filter( BMP_FILTER_REMOVENOISE ) )
131 aGraphic = aBmpEx;
134 if( pShell )
135 pShell->SetWaitCursor( sal_False );
137 break;
139 case( SID_GRFFILTER_SOBEL ):
141 if( pShell )
142 pShell->SetWaitCursor( sal_True );
144 if( rGraphic.IsAnimated() )
146 Animation aAnimation( rGraphic.GetAnimation() );
148 if( aAnimation.Filter( BMP_FILTER_SOBEL_GREY ) )
149 aGraphic = aAnimation;
151 else
153 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
155 if( aBmpEx.Filter( BMP_FILTER_SOBEL_GREY ) )
156 aGraphic = aBmpEx;
159 if( pShell )
160 pShell->SetWaitCursor( sal_False );
162 break;
164 case( SID_GRFFILTER_MOSAIC ):
166 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
167 if(pFact)
169 AbstractGraphicFilterDialog* aDlg = pFact->CreateGraphicFilterMosaic( pWindow, rGraphic, 4, 4, sal_False, RID_SVX_GRFFILTER_DLG_MOSAIC);
170 DBG_ASSERT(aDlg, "Dialogdiet fail!");
171 if( aDlg->Execute() == RET_OK )
172 aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
173 delete aDlg;
176 break;
178 case( SID_GRFFILTER_EMBOSS ):
180 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
181 if(pFact)
183 AbstractGraphicFilterDialog* aDlg = pFact->CreateGraphicFilterEmboss( pWindow, rGraphic, RP_MM, RID_SVX_GRFFILTER_DLG_EMBOSS );
184 DBG_ASSERT(aDlg, "Dialogdiet fail!");
185 if( aDlg->Execute() == RET_OK )
186 aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
187 delete aDlg;
190 break;
192 case( SID_GRFFILTER_POSTER ):
194 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
195 if(pFact)
197 AbstractGraphicFilterDialog* aDlg = pFact->CreateGraphicFilterPosterSepia( pWindow, rGraphic, 16, RID_SVX_GRFFILTER_DLG_POSTER );
198 DBG_ASSERT(aDlg, "Dialogdiet fail!");
199 if( aDlg->Execute() == RET_OK )
200 aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
201 delete aDlg;
204 break;
206 case( SID_GRFFILTER_POPART ):
208 if( pShell )
209 pShell->SetWaitCursor( sal_True );
211 if( rGraphic.IsAnimated() )
213 Animation aAnimation( rGraphic.GetAnimation() );
215 if( aAnimation.Filter( BMP_FILTER_POPART ) )
216 aGraphic = aAnimation;
218 else
220 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
222 if( aBmpEx.Filter( BMP_FILTER_POPART ) )
223 aGraphic = aBmpEx;
226 if( pShell )
227 pShell->SetWaitCursor( sal_False );
229 break;
231 case( SID_GRFFILTER_SEPIA ):
233 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
234 if(pFact)
236 AbstractGraphicFilterDialog* aDlg = pFact->CreateGraphicFilterPosterSepia( pWindow, rGraphic, 10, RID_SVX_GRFFILTER_DLG_SEPIA );
237 DBG_ASSERT(aDlg, "Dialogdiet fail!");
238 if( aDlg->Execute() == RET_OK )
239 aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
240 delete aDlg;
243 break;
245 case( SID_GRFFILTER_SOLARIZE ):
247 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
248 if(pFact)
250 AbstractGraphicFilterDialog* aDlg = pFact->CreateGraphicFilterSolarize( pWindow, rGraphic, 128, sal_False, RID_SVX_GRFFILTER_DLG_SOLARIZE );
251 DBG_ASSERT(aDlg, "Dialogdiet fail!");
252 if( aDlg->Execute() == RET_OK )
253 aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
254 delete aDlg;
257 break;
259 case SID_GRFFILTER :
261 // do nothing; no error
262 nRet = SVX_GRAPHICFILTER_ERRCODE_NONE;
263 break;
266 default:
268 OSL_FAIL( "SvxGraphicFilter: selected filter slot not yet implemented" );
269 nRet = SVX_GRAPHICFILTER_UNSUPPORTED_SLOT;
271 break;
274 if( aGraphic.GetType() != GRAPHIC_NONE )
276 rFilterObject.SetGraphic( aGraphic );
277 nRet = SVX_GRAPHICFILTER_ERRCODE_NONE;
281 return nRet;
284 // -----------------------------------------------------------------------------
286 void SvxGraphicFilter::DisableGraphicFilterSlots( SfxItemSet& rSet )
288 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER ) )
289 rSet.DisableItem( SID_GRFFILTER );
291 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_INVERT ) )
292 rSet.DisableItem( SID_GRFFILTER_INVERT );
294 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_SMOOTH ) )
295 rSet.DisableItem( SID_GRFFILTER_SMOOTH );
297 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_SHARPEN ) )
298 rSet.DisableItem( SID_GRFFILTER_SHARPEN );
300 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_REMOVENOISE ) )
301 rSet.DisableItem( SID_GRFFILTER_REMOVENOISE );
303 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_SOBEL ) )
304 rSet.DisableItem( SID_GRFFILTER_SOBEL );
306 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_MOSAIC ) )
307 rSet.DisableItem( SID_GRFFILTER_MOSAIC );
309 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_EMBOSS ) )
310 rSet.DisableItem( SID_GRFFILTER_EMBOSS );
312 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_POSTER ) )
313 rSet.DisableItem( SID_GRFFILTER_POSTER );
315 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_POPART ) )
316 rSet.DisableItem( SID_GRFFILTER_POPART );
318 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_SEPIA ) )
319 rSet.DisableItem( SID_GRFFILTER_SEPIA );
321 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_SOLARIZE ) )
322 rSet.DisableItem( SID_GRFFILTER_SOLARIZE );
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */