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 <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
;
48 switch( rReq
.GetSlot() )
50 case( SID_GRFFILTER_INVERT
):
53 pShell
->SetWaitCursor( sal_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( sal_False
);
75 case( SID_GRFFILTER_SMOOTH
):
77 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
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 );
89 case( SID_GRFFILTER_SHARPEN
):
92 pShell
->SetWaitCursor( sal_True
);
94 if( rGraphic
.IsAnimated() )
96 Animation
aAnimation( rGraphic
.GetAnimation() );
98 if( aAnimation
.Filter( BMP_FILTER_SHARPEN
) )
99 aGraphic
= aAnimation
;
103 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
105 if( aBmpEx
.Filter( BMP_FILTER_SHARPEN
) )
110 pShell
->SetWaitCursor( sal_False
);
114 case( SID_GRFFILTER_REMOVENOISE
):
117 pShell
->SetWaitCursor( sal_True
);
119 if( rGraphic
.IsAnimated() )
121 Animation
aAnimation( rGraphic
.GetAnimation() );
123 if( aAnimation
.Filter( BMP_FILTER_REMOVENOISE
) )
124 aGraphic
= aAnimation
;
128 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
130 if( aBmpEx
.Filter( BMP_FILTER_REMOVENOISE
) )
135 pShell
->SetWaitCursor( sal_False
);
139 case( SID_GRFFILTER_SOBEL
):
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
;
153 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
155 if( aBmpEx
.Filter( BMP_FILTER_SOBEL_GREY
) )
160 pShell
->SetWaitCursor( sal_False
);
164 case( SID_GRFFILTER_MOSAIC
):
166 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
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 );
178 case( SID_GRFFILTER_EMBOSS
):
180 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
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 );
192 case( SID_GRFFILTER_POSTER
):
194 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
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 );
206 case( SID_GRFFILTER_POPART
):
209 pShell
->SetWaitCursor( sal_True
);
211 if( rGraphic
.IsAnimated() )
213 Animation
aAnimation( rGraphic
.GetAnimation() );
215 if( aAnimation
.Filter( BMP_FILTER_POPART
) )
216 aGraphic
= aAnimation
;
220 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
222 if( aBmpEx
.Filter( BMP_FILTER_POPART
) )
227 pShell
->SetWaitCursor( sal_False
);
231 case( SID_GRFFILTER_SEPIA
):
233 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
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 );
245 case( SID_GRFFILTER_SOLARIZE
):
247 SvxAbstractDialogFactory
* pFact
= SvxAbstractDialogFactory::Create();
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 );
261 // do nothing; no error
262 nRet
= SVX_GRAPHICFILTER_ERRCODE_NONE
;
268 OSL_FAIL( "SvxGraphicFilter: selected filter slot not yet implemented" );
269 nRet
= SVX_GRAPHICFILTER_UNSUPPORTED_SLOT
;
274 if( aGraphic
.GetType() != GRAPHIC_NONE
)
276 rFilterObject
.SetGraphic( aGraphic
);
277 nRet
= SVX_GRAPHICFILTER_ERRCODE_NONE
;
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: */