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>
26 #include <dialmgr.hxx>
27 #include "cuigrfflt.hxx"
30 #include <svx/dialogs.hrc> // RID_SVX_GRFFILTER_DLG_...
32 // --------------------------------------
33 // - GraphicFilterDialog::PreviewWindow -
34 // --------------------------------------
36 GraphicFilterDialog::PreviewWindow::PreviewWindow( Window
* pParent
, const ResId
& rResId
) :
37 Control( pParent
, rResId
)
41 // -----------------------------------------------------------------------------
43 GraphicFilterDialog::PreviewWindow::~PreviewWindow()
47 // -----------------------------------------------------------------------------
49 void GraphicFilterDialog::PreviewWindow::Paint( const Rectangle
& rRect
)
51 Control::Paint( rRect
);
53 const Size
aOutputSize( GetOutputSizePixel() );
55 if( maGraphic
.IsAnimated() )
57 const Size
aGraphicSize( LogicToPixel( maGraphic
.GetPrefSize(), maGraphic
.GetPrefMapMode() ) );
58 const Point
aGraphicPosition( ( aOutputSize
.Width() - aGraphicSize
.Width() ) >> 1,
59 ( aOutputSize
.Height() - aGraphicSize
.Height() ) >> 1 );
60 maGraphic
.StartAnimation( this, aGraphicPosition
, aGraphicSize
);
64 const Size
aGraphicSize( maGraphic
.GetSizePixel() );
65 const Point
aGraphicPosition( ( aOutputSize
.Width() - aGraphicSize
.Width() ) >> 1,
66 ( aOutputSize
.Height() - aGraphicSize
.Height() ) >> 1 );
67 maGraphic
.Draw( this, aGraphicPosition
, aGraphicSize
);
71 // -----------------------------------------------------------------------------
73 void GraphicFilterDialog::PreviewWindow::SetGraphic( const Graphic
& rGraphic
)
77 if( maGraphic
.IsAnimated() || maGraphic
.IsTransparent() )
80 Paint( Rectangle( Point(), GetOutputSizePixel() ) );
83 // -----------------------
84 // - GraphicFilterDialog -
85 // -----------------------
87 GraphicFilterDialog::GraphicFilterDialog( Window
* pParent
, const ResId
& rResId
, const Graphic
& rGraphic
) :
88 ModalDialog ( pParent
, rResId
),
89 maModifyHdl ( LINK( this, GraphicFilterDialog
, ImplModifyHdl
) ),
92 maSizePixel ( LogicToPixel( rGraphic
.GetPrefSize(), rGraphic
.GetPrefMapMode() ) ),
93 maPreview ( this, CUI_RES( CTL_PREVIEW
) ),
94 maBtnOK ( this, CUI_RES( BTN_OK
) ),
95 maBtnCancel ( this, CUI_RES( BTN_CANCEL
) ),
96 maBtnHelp ( this, CUI_RES( BTN_HELP
) ),
97 maFlParameter ( this, CUI_RES( FL_PARAMETER
) )
99 const Size
aPreviewSize( maPreview
.GetOutputSizePixel() );
100 Size
aGrfSize( maSizePixel
);
102 if( rGraphic
.GetType() == GRAPHIC_BITMAP
&&
103 aPreviewSize
.Width() && aPreviewSize
.Height() &&
104 aGrfSize
.Width() && aGrfSize
.Height() )
106 const double fGrfWH
= (double) aGrfSize
.Width() / aGrfSize
.Height();
107 const double fPreWH
= (double) aPreviewSize
.Width() / aPreviewSize
.Height();
109 if( fGrfWH
< fPreWH
)
111 aGrfSize
.Width() = (long) ( aPreviewSize
.Height() * fGrfWH
);
112 aGrfSize
.Height() = aPreviewSize
.Height();
116 aGrfSize
.Width() = aPreviewSize
.Width();
117 aGrfSize
.Height() = (long) ( aPreviewSize
.Width() / fGrfWH
);
120 mfScaleX
= (double) aGrfSize
.Width() / maSizePixel
.Width();
121 mfScaleY
= (double) aGrfSize
.Height() / maSizePixel
.Height();
123 if( !rGraphic
.IsAnimated() )
125 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
127 if( aBmpEx
.Scale( aGrfSize
, BMP_SCALE_DEFAULT
) )
132 maTimer
.SetTimeoutHdl( LINK( this, GraphicFilterDialog
, ImplPreviewTimeoutHdl
) );
133 maTimer
.SetTimeout( 100 );
134 ImplModifyHdl( NULL
);
137 // -----------------------------------------------------------------------------
139 GraphicFilterDialog::~GraphicFilterDialog()
143 // -----------------------------------------------------------------------------
145 IMPL_LINK_NOARG(GraphicFilterDialog
, ImplPreviewTimeoutHdl
)
148 maPreview
.SetGraphic( GetFilteredGraphic( maGraphic
, mfScaleX
, mfScaleY
) );
153 // -----------------------------------------------------------------------------
155 IMPL_LINK_NOARG(GraphicFilterDialog
, ImplModifyHdl
)
157 if( maGraphic
.GetType() == GRAPHIC_BITMAP
)
170 GraphicFilterMosaic::GraphicFilterMosaic( Window
* pParent
, const Graphic
& rGraphic
,
171 sal_uInt16 nTileWidth
, sal_uInt16 nTileHeight
, sal_Bool bEnhanceEdges
) :
172 GraphicFilterDialog( pParent
, CUI_RES( RID_SVX_GRFFILTER_DLG_MOSAIC
), rGraphic
),
173 maFtWidth ( this, CUI_RES( DLG_FILTERMOSAIC_FT_WIDTH
) ),
174 maMtrWidth ( this, CUI_RES( DLG_FILTERMOSAIC_MTR_WIDTH
) ),
175 maFtHeight ( this, CUI_RES( DLG_FILTERMOSAIC_FT_HEIGHT
) ),
176 maMtrHeight ( this, CUI_RES( DLG_FILTERMOSAIC_MTR_HEIGHT
) ),
177 maCbxEdges ( this, CUI_RES( DLG_FILTERMOSAIC_CBX_EDGES
) )
181 maMtrWidth
.SetValue( nTileWidth
);
182 maMtrWidth
.SetLast( GetGraphicSizePixel().Width() );
183 maMtrWidth
.SetModifyHdl( GetModifyHdl() );
185 maMtrHeight
.SetValue( nTileHeight
);
186 maMtrHeight
.SetLast( GetGraphicSizePixel().Height() );
187 maMtrHeight
.SetModifyHdl( GetModifyHdl() );
189 maCbxEdges
.Check( bEnhanceEdges
);
190 maCbxEdges
.SetToggleHdl( GetModifyHdl() );
192 maMtrWidth
.GrabFocus();
194 maFtWidth
.SetAccessibleRelationMemberOf(&maFlParameter
);
195 maMtrWidth
.SetAccessibleRelationMemberOf(&maFlParameter
);
196 maFtHeight
.SetAccessibleRelationMemberOf(&maFlParameter
);
197 maMtrHeight
.SetAccessibleRelationMemberOf(&maFlParameter
);
198 maCbxEdges
.SetAccessibleRelationMemberOf(&maFlParameter
);
201 // -----------------------------------------------------------------------------
203 GraphicFilterMosaic::~GraphicFilterMosaic()
207 // -----------------------------------------------------------------------------
209 Graphic
GraphicFilterMosaic::GetFilteredGraphic( const Graphic
& rGraphic
,
210 double fScaleX
, double fScaleY
)
213 const Size
aSize( std::max( FRound( GetTileWidth() * fScaleX
), 1L ),
214 std::max( FRound( GetTileHeight() * fScaleY
), 1L ) );
215 BmpFilterParam
aParam( aSize
);
217 if( rGraphic
.IsAnimated() )
219 Animation
aAnim( rGraphic
.GetAnimation() );
221 if( aAnim
.Filter( BMP_FILTER_MOSAIC
, &aParam
) )
223 if( IsEnhanceEdges() )
224 aAnim
.Filter( BMP_FILTER_SHARPEN
);
231 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
233 if( aBmpEx
.Filter( BMP_FILTER_MOSAIC
, &aParam
) )
235 if( IsEnhanceEdges() )
236 aBmpEx
.Filter( BMP_FILTER_SHARPEN
);
245 // ------------------
246 // - GraphicFilterSmooth -
247 // ------------------
249 GraphicFilterSmooth::GraphicFilterSmooth( Window
* pParent
, const Graphic
& rGraphic
, double nRadius
) :
250 GraphicFilterDialog ( pParent
, CUI_RES( RID_SVX_GRFFILTER_DLG_SMOOTH
), rGraphic
),
251 maFtRadius ( this, CUI_RES( DLG_FILTERSMOOTH_FT_RADIUS
) ),
252 maMtrRadius ( this, CUI_RES( DLG_FILTERSMOOTH_MTR_RADIUS
) )
256 maMtrRadius
.SetValue( nRadius
* 10 );
257 maMtrRadius
.SetModifyHdl( GetModifyHdl() );
258 maMtrRadius
.GrabFocus();
261 // -----------------------------------------------------------------------------
263 GraphicFilterSmooth::~GraphicFilterSmooth()
267 // -----------------------------------------------------------------------------
269 Graphic
GraphicFilterSmooth::GetFilteredGraphic( const Graphic
& rGraphic
, double /*fScaleX*/, double /*fScaleY*/ )
272 BmpFilterParam
aParam( GetRadius() );
274 if( rGraphic
.IsAnimated() )
276 Animation
aAnim( rGraphic
.GetAnimation() );
278 if( aAnim
.Filter( BMP_FILTER_SMOOTH
, &aParam
) )
285 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
287 if( aBmpEx
.Filter( BMP_FILTER_SMOOTH
, &aParam
) )
296 // ------------------
297 // - GraphicFilterSolarize -
298 // ------------------
300 GraphicFilterSolarize::GraphicFilterSolarize( Window
* pParent
, const Graphic
& rGraphic
,
301 sal_uInt8 cGreyThreshold
, sal_Bool bInvert
) :
302 GraphicFilterDialog ( pParent
, CUI_RES( RID_SVX_GRFFILTER_DLG_SOLARIZE
), rGraphic
),
303 maFtThreshold ( this, CUI_RES( DLG_FILTERSOLARIZE_FT_THRESHOLD
) ),
304 maMtrThreshold ( this, CUI_RES( DLG_FILTERSOLARIZE_MTR_THRESHOLD
) ),
305 maCbxInvert ( this, CUI_RES( DLG_FILTERSOLARIZE_CBX_INVERT
) )
309 maMtrThreshold
.SetValue( FRound( cGreyThreshold
/ 2.55 ) );
310 maMtrThreshold
.SetModifyHdl( GetModifyHdl() );
312 maCbxInvert
.Check( bInvert
);
313 maCbxInvert
.SetToggleHdl( GetModifyHdl() );
315 maMtrThreshold
.GrabFocus();
318 // -----------------------------------------------------------------------------
320 GraphicFilterSolarize::~GraphicFilterSolarize()
324 // -----------------------------------------------------------------------------
326 Graphic
GraphicFilterSolarize::GetFilteredGraphic( const Graphic
& rGraphic
,
327 double /*fScaleX*/, double /*fScaleY*/ )
330 BmpFilterParam
aParam( GetGreyThreshold() );
332 if( rGraphic
.IsAnimated() )
334 Animation
aAnim( rGraphic
.GetAnimation() );
336 if( aAnim
.Filter( BMP_FILTER_SOLARIZE
, &aParam
) )
346 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
348 if( aBmpEx
.Filter( BMP_FILTER_SOLARIZE
, &aParam
) )
360 // ----------------------
361 // - GraphicFilterSepia -
362 // ----------------------
364 GraphicFilterSepia::GraphicFilterSepia( Window
* pParent
, const Graphic
& rGraphic
,
365 sal_uInt16 nSepiaPercent
) :
366 GraphicFilterDialog ( pParent
, CUI_RES( RID_SVX_GRFFILTER_DLG_SEPIA
), rGraphic
),
367 maFtSepia ( this, CUI_RES( DLG_FILTERSEPIA_FT_SEPIA
) ),
368 maMtrSepia ( this, CUI_RES( DLG_FILTERSEPIA_MTR_SEPIA
) )
372 maMtrSepia
.SetValue( nSepiaPercent
);
373 maMtrSepia
.SetModifyHdl( GetModifyHdl() );
375 maMtrSepia
.GrabFocus();
378 // -----------------------------------------------------------------------------
380 GraphicFilterSepia::~GraphicFilterSepia()
384 // -----------------------------------------------------------------------------
386 Graphic
GraphicFilterSepia::GetFilteredGraphic( const Graphic
& rGraphic
,
387 double /*fScaleX*/, double /*fScaleY*/ )
390 BmpFilterParam
aParam( GetSepiaPercent() );
392 if( rGraphic
.IsAnimated() )
394 Animation
aAnim( rGraphic
.GetAnimation() );
396 if( aAnim
.Filter( BMP_FILTER_SEPIA
, &aParam
) )
401 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
403 if( aBmpEx
.Filter( BMP_FILTER_SEPIA
, &aParam
) )
410 // -----------------------
411 // - GraphicFilterPoster -
412 // -----------------------
414 GraphicFilterPoster::GraphicFilterPoster( Window
* pParent
, const Graphic
& rGraphic
,
415 sal_uInt16 nPosterCount
) :
416 GraphicFilterDialog ( pParent
, CUI_RES( RID_SVX_GRFFILTER_DLG_POSTER
), rGraphic
),
417 maFtPoster ( this, CUI_RES( DLG_FILTERPOSTER_FT_POSTER
) ),
418 maNumPoster ( this, CUI_RES( DLG_FILTERPOSTER_NUM_POSTER
) )
422 maNumPoster
.SetFirst( 2 );
423 maNumPoster
.SetLast( rGraphic
.GetBitmapEx().GetBitCount() );
424 maNumPoster
.SetValue( nPosterCount
);
425 maNumPoster
.SetModifyHdl( GetModifyHdl() );
426 maNumPoster
.GrabFocus();
429 // -----------------------------------------------------------------------------
431 GraphicFilterPoster::~GraphicFilterPoster()
435 // -----------------------------------------------------------------------------
437 Graphic
GraphicFilterPoster::GetFilteredGraphic( const Graphic
& rGraphic
,
438 double /*fScaleX*/, double /*fScaleY*/ )
441 const sal_uInt16 nPosterCount
= GetPosterColorCount();
443 if( rGraphic
.IsAnimated() )
445 Animation
aAnim( rGraphic
.GetAnimation() );
447 if( aAnim
.ReduceColors( nPosterCount
, BMP_REDUCE_POPULAR
) )
452 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
454 if( aBmpEx
.ReduceColors( nPosterCount
, BMP_REDUCE_POPULAR
) )
461 // -----------------------
462 // - GraphicFilterEmboss -
463 // -----------------------
465 void GraphicFilterEmboss::EmbossControl::MouseButtonDown( const MouseEvent
& rEvt
)
467 const RECT_POINT eOldRP
= GetActualRP();
469 SvxRectCtl::MouseButtonDown( rEvt
);
471 if( GetActualRP() != eOldRP
)
472 maModifyHdl
.Call( this );
475 // -----------------------------------------------------------------------------
477 GraphicFilterEmboss::GraphicFilterEmboss( Window
* pParent
, const Graphic
& rGraphic
,
478 RECT_POINT eLightSource
) :
479 GraphicFilterDialog ( pParent
, CUI_RES( RID_SVX_GRFFILTER_DLG_EMBOSS
), rGraphic
),
480 maFtLight ( this, CUI_RES( DLG_FILTEREMBOSS_FT_LIGHT
) ),
481 maCtlLight ( this, CUI_RES( DLG_FILTEREMBOSS_CTL_LIGHT
), eLightSource
)
485 maCtlLight
.SetModifyHdl( GetModifyHdl() );
486 maCtlLight
.GrabFocus();
489 // -----------------------------------------------------------------------------
491 GraphicFilterEmboss::~GraphicFilterEmboss()
495 // -----------------------------------------------------------------------------
497 Graphic
GraphicFilterEmboss::GetFilteredGraphic( const Graphic
& rGraphic
,
498 double /*fScaleX*/, double /*fScaleY*/ )
501 sal_uInt16 nAzim
, nElev
;
503 switch( maCtlLight
.GetActualRP() )
505 default: OSL_FAIL("svx::GraphicFilterEmboss::GetFilteredGraphic(), unknown Reference Point!" );
506 case( RP_LT
): nAzim
= 4500, nElev
= 4500; break;
507 case( RP_MT
): nAzim
= 9000, nElev
= 4500; break;
508 case( RP_RT
): nAzim
= 13500, nElev
= 4500; break;
509 case( RP_LM
): nAzim
= 0, nElev
= 4500; break;
510 case( RP_MM
): nAzim
= 0, nElev
= 9000; break;
511 case( RP_RM
): nAzim
= 18000, nElev
= 4500; break;
512 case( RP_LB
): nAzim
= 31500, nElev
= 4500; break;
513 case( RP_MB
): nAzim
= 27000, nElev
= 4500; break;
514 case( RP_RB
): nAzim
= 22500, nElev
= 4500; break;
517 BmpFilterParam
aParam( nAzim
, nElev
);
519 if( rGraphic
.IsAnimated() )
521 Animation
aAnim( rGraphic
.GetAnimation() );
523 if( aAnim
.Filter( BMP_FILTER_EMBOSS_GREY
, &aParam
) )
528 BitmapEx
aBmpEx( rGraphic
.GetBitmapEx() );
530 if( aBmpEx
.Filter( BMP_FILTER_EMBOSS_GREY
, &aParam
) )
537 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */