update dev300-m58
[ooovba.git] / svx / source / cui / cuigrfflt.cxx
blob39c4e44e3117c316e861be70e161c1a8dbd19432
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cuigrfflt.cxx,v $
10 * $Revision: 1.9 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifdef SVX_DLLIMPLEMENTATION
35 #undef SVX_DLLIMPLEMENTATION
36 #endif
37 #include <tools/shl.hxx>
38 #include <vcl/msgbox.hxx>
39 #include <sfx2/viewfrm.hxx>
40 #include <sfx2/viewsh.hxx>
41 #include <sfx2/objsh.hxx>
42 #include <sfx2/request.hxx>
44 #include <svx/dialmgr.hxx>
45 #include "cuigrfflt.hxx"
46 #include "grfflt.hrc"
47 #include <svx/dialogs.hrc>
49 // --------------------
50 // - SvxGraphicFilter -
51 // --------------------
53 ULONG SvxGraphicFilter::ExecuteGrfFilterSlot( SfxRequest& rReq, GraphicObject& rFilterObject )
55 const Graphic& rGraphic = rFilterObject.GetGraphic();
56 ULONG nRet;
58 if( rGraphic.GetType() == GRAPHIC_BITMAP )
60 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
61 SfxObjectShell* pShell = pViewFrame ? pViewFrame->GetObjectShell() : NULL;
62 Window* pWindow = ( pViewFrame && pViewFrame->GetViewShell() ) ? pViewFrame->GetViewShell()->GetWindow() : NULL;
63 Graphic aGraphic;
65 switch( rReq.GetSlot() )
67 case( SID_GRFFILTER_INVERT ):
69 if( pShell )
70 pShell->SetWaitCursor( TRUE );
72 if( rGraphic.IsAnimated() )
74 Animation aAnimation( rGraphic.GetAnimation() );
76 if( aAnimation.Invert() )
77 aGraphic = aAnimation;
79 else
81 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
83 if( aBmpEx.Invert() )
84 aGraphic = aBmpEx;
87 if( pShell )
88 pShell->SetWaitCursor( FALSE );
90 break;
92 case( SID_GRFFILTER_SMOOTH ):
94 if( pShell )
95 pShell->SetWaitCursor( TRUE );
97 if( rGraphic.IsAnimated() )
99 Animation aAnimation( rGraphic.GetAnimation() );
101 if( aAnimation.Filter( BMP_FILTER_SMOOTH ) )
102 aGraphic = aAnimation;
104 else
106 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
108 if( aBmpEx.Filter( BMP_FILTER_SMOOTH ) )
109 aGraphic = aBmpEx;
112 if( pShell )
113 pShell->SetWaitCursor( FALSE );
115 break;
117 case( SID_GRFFILTER_SHARPEN ):
119 if( pShell )
120 pShell->SetWaitCursor( TRUE );
122 if( rGraphic.IsAnimated() )
124 Animation aAnimation( rGraphic.GetAnimation() );
126 if( aAnimation.Filter( BMP_FILTER_SHARPEN ) )
127 aGraphic = aAnimation;
129 else
131 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
133 if( aBmpEx.Filter( BMP_FILTER_SHARPEN ) )
134 aGraphic = aBmpEx;
137 if( pShell )
138 pShell->SetWaitCursor( FALSE );
140 break;
142 case( SID_GRFFILTER_REMOVENOISE ):
144 if( pShell )
145 pShell->SetWaitCursor( TRUE );
147 if( rGraphic.IsAnimated() )
149 Animation aAnimation( rGraphic.GetAnimation() );
151 if( aAnimation.Filter( BMP_FILTER_REMOVENOISE ) )
152 aGraphic = aAnimation;
154 else
156 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
158 if( aBmpEx.Filter( BMP_FILTER_REMOVENOISE ) )
159 aGraphic = aBmpEx;
162 if( pShell )
163 pShell->SetWaitCursor( FALSE );
165 break;
167 case( SID_GRFFILTER_SOBEL ):
169 if( pShell )
170 pShell->SetWaitCursor( TRUE );
172 if( rGraphic.IsAnimated() )
174 Animation aAnimation( rGraphic.GetAnimation() );
176 if( aAnimation.Filter( BMP_FILTER_SOBEL_GREY ) )
177 aGraphic = aAnimation;
179 else
181 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
183 if( aBmpEx.Filter( BMP_FILTER_SOBEL_GREY ) )
184 aGraphic = aBmpEx;
187 if( pShell )
188 pShell->SetWaitCursor( FALSE );
190 break;
192 case( SID_GRFFILTER_MOSAIC ):
194 GraphicFilterMosaic aDlg( pWindow, rGraphic, 4, 4, FALSE );
196 if( aDlg.Execute() == RET_OK )
197 aGraphic = aDlg.GetFilteredGraphic( rGraphic, 1.0, 1.0 );
199 break;
201 case( SID_GRFFILTER_EMBOSS ):
203 GraphicFilterEmboss aDlg( pWindow, rGraphic, RP_MM );
205 if( aDlg.Execute() == RET_OK )
206 aGraphic = aDlg.GetFilteredGraphic( rGraphic, 1.0, 1.0 );
208 break;
210 case( SID_GRFFILTER_POSTER ):
212 GraphicFilterPoster aDlg( pWindow, rGraphic, 16 );
214 if( aDlg.Execute() == RET_OK )
215 aGraphic = aDlg.GetFilteredGraphic( rGraphic, 1.0, 1.0 );
217 break;
219 case( SID_GRFFILTER_POPART ):
221 if( pShell )
222 pShell->SetWaitCursor( TRUE );
224 if( rGraphic.IsAnimated() )
226 Animation aAnimation( rGraphic.GetAnimation() );
228 if( aAnimation.Filter( BMP_FILTER_POPART ) )
229 aGraphic = aAnimation;
231 else
233 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
235 if( aBmpEx.Filter( BMP_FILTER_POPART ) )
236 aGraphic = aBmpEx;
239 if( pShell )
240 pShell->SetWaitCursor( FALSE );
242 break;
244 case( SID_GRFFILTER_SEPIA ):
246 GraphicFilterSepia aDlg( pWindow, rGraphic, 10 );
248 if( aDlg.Execute() == RET_OK )
249 aGraphic = aDlg.GetFilteredGraphic( rGraphic, 1.0, 1.0 );
251 break;
253 case( SID_GRFFILTER_SOLARIZE ):
255 GraphicFilterSolarize aDlg( pWindow, rGraphic, 128, FALSE );
257 if( aDlg.Execute() == RET_OK )
258 aGraphic = aDlg.GetFilteredGraphic( rGraphic, 1.0, 1.0 );
260 break;
262 default:
264 DBG_ERROR( "SvxGraphicFilter: selected filter slot not yet implemented" );
265 nRet = SVX_GRAPHICFILTER_UNSUPPORTED_SLOT;
267 break;
270 if( aGraphic.GetType() != GRAPHIC_NONE )
272 rFilterObject.SetGraphic( aGraphic );
273 nRet = SVX_GRAPHICFILTER_ERRCODE_NONE;
276 else
277 nRet = SVX_GRAPHICFILTER_UNSUPPORTED_GRAPHICTYPE;
279 return nRet;
282 // -----------------------------------------------------------------------------
284 void SvxGraphicFilter::DisableGraphicFilterSlots( SfxItemSet& rSet )
286 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER ) )
287 rSet.DisableItem( SID_GRFFILTER );
289 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_INVERT ) )
290 rSet.DisableItem( SID_GRFFILTER_INVERT );
292 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_SMOOTH ) )
293 rSet.DisableItem( SID_GRFFILTER_SMOOTH );
295 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_SHARPEN ) )
296 rSet.DisableItem( SID_GRFFILTER_SHARPEN );
298 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_REMOVENOISE ) )
299 rSet.DisableItem( SID_GRFFILTER_REMOVENOISE );
301 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_SOBEL ) )
302 rSet.DisableItem( SID_GRFFILTER_SOBEL );
304 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_MOSAIC ) )
305 rSet.DisableItem( SID_GRFFILTER_MOSAIC );
307 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_EMBOSS ) )
308 rSet.DisableItem( SID_GRFFILTER_EMBOSS );
310 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_POSTER ) )
311 rSet.DisableItem( SID_GRFFILTER_POSTER );
313 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_POPART ) )
314 rSet.DisableItem( SID_GRFFILTER_POPART );
316 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_SEPIA ) )
317 rSet.DisableItem( SID_GRFFILTER_SEPIA );
319 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_SOLARIZE ) )
320 rSet.DisableItem( SID_GRFFILTER_SOLARIZE );
323 // --------------------------------------
324 // - GraphicFilterDialog::PreviewWindow -
325 // --------------------------------------
327 GraphicFilterDialog::PreviewWindow::PreviewWindow( Window* pParent, const ResId& rResId ) :
328 Control( pParent, rResId )
332 // -----------------------------------------------------------------------------
334 GraphicFilterDialog::PreviewWindow::~PreviewWindow()
338 // -----------------------------------------------------------------------------
340 void GraphicFilterDialog::PreviewWindow::Paint( const Rectangle& rRect )
342 Control::Paint( rRect );
344 const Size aGrfSize( LogicToPixel( maGraphic.GetPrefSize(), maGraphic.GetPrefMapMode() ) );
345 const Size aOutSize( GetOutputSizePixel() );
346 const Point aGrfPos( ( aOutSize.Width() - aGrfSize.Width() ) >> 1,
347 ( aOutSize.Height() - aGrfSize.Height() ) >> 1 );
349 if( maGraphic.IsAnimated() )
350 maGraphic.StartAnimation( this , aGrfPos, aGrfSize );
351 else
352 maGraphic.Draw( this, aGrfPos, aGrfSize );
355 // -----------------------------------------------------------------------------
357 void GraphicFilterDialog::PreviewWindow::SetGraphic( const Graphic& rGraphic )
359 maGraphic = rGraphic;
361 if( maGraphic.IsAnimated() || maGraphic.IsTransparent() )
362 Invalidate();
363 else
364 Paint( Rectangle( Point(), GetOutputSizePixel() ) );
367 // -----------------------
368 // - GraphicFilterDialog -
369 // -----------------------
371 GraphicFilterDialog::GraphicFilterDialog( Window* pParent, const ResId& rResId, const Graphic& rGraphic ) :
372 ModalDialog ( pParent, rResId ),
373 maModifyHdl ( LINK( this, GraphicFilterDialog, ImplModifyHdl ) ),
374 mfScaleX ( 0.0 ),
375 mfScaleY ( 0.0 ),
376 maSizePixel ( LogicToPixel( rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode() ) ),
377 maPreview ( this, SVX_RES( CTL_PREVIEW ) ),
378 maFlParameter ( this, SVX_RES( FL_PARAMETER ) ),
379 maBtnOK ( this, SVX_RES( BTN_OK ) ),
380 maBtnCancel ( this, SVX_RES( BTN_CANCEL ) ),
381 maBtnHelp ( this, SVX_RES( BTN_HELP ) )
383 const Size aPreviewSize( maPreview.GetOutputSizePixel() );
384 Size aGrfSize( maSizePixel );
386 if( rGraphic.GetType() == GRAPHIC_BITMAP &&
387 aPreviewSize.Width() && aPreviewSize.Height() &&
388 aGrfSize.Width() && aGrfSize.Height() )
390 const double fGrfWH = (double) aGrfSize.Width() / aGrfSize.Height();
391 const double fPreWH = (double) aPreviewSize.Width() / aPreviewSize.Height();
393 if( fGrfWH < fPreWH )
395 aGrfSize.Width() = (long) ( aPreviewSize.Height() * fGrfWH );
396 aGrfSize.Height()= aPreviewSize.Height();
398 else
400 aGrfSize.Width() = aPreviewSize.Width();
401 aGrfSize.Height()= (long) ( aPreviewSize.Width() / fGrfWH);
404 mfScaleX = (double) aGrfSize.Width() / maSizePixel.Width();
405 mfScaleY = (double) aGrfSize.Height() / maSizePixel.Height();
407 if( !rGraphic.IsAnimated() )
409 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
411 if( aBmpEx.Scale( aGrfSize, BMP_SCALE_INTERPOLATE ) )
412 maGraphic = aBmpEx;
416 maTimer.SetTimeoutHdl( LINK( this, GraphicFilterDialog, ImplPreviewTimeoutHdl ) );
417 maTimer.SetTimeout( 100 );
418 ImplModifyHdl( NULL );
421 // -----------------------------------------------------------------------------
423 GraphicFilterDialog::~GraphicFilterDialog()
427 // -----------------------------------------------------------------------------
429 IMPL_LINK( GraphicFilterDialog, ImplPreviewTimeoutHdl, Timer*, EMPTYARG )
431 maTimer.Stop();
432 maPreview.SetGraphic( GetFilteredGraphic( maGraphic, mfScaleX, mfScaleY ) );
434 return 0;
437 // -----------------------------------------------------------------------------
439 IMPL_LINK( GraphicFilterDialog, ImplModifyHdl, void*, EMPTYARG )
441 if( maGraphic.GetType() == GRAPHIC_BITMAP )
443 maTimer.Stop();
444 maTimer.Start();
447 return 0;
450 // ----------------
451 // - FilterMosaic -
452 // ----------------
454 GraphicFilterMosaic::GraphicFilterMosaic( Window* pParent, const Graphic& rGraphic,
455 USHORT nTileWidth, USHORT nTileHeight, BOOL bEnhanceEdges ) :
456 GraphicFilterDialog( pParent, SVX_RES( RID_SVX_GRFFILTER_DLG_MOSAIC ), rGraphic ),
457 maFtWidth ( this, SVX_RES( DLG_FILTERMOSAIC_FT_WIDTH ) ),
458 maMtrWidth ( this, SVX_RES( DLG_FILTERMOSAIC_MTR_WIDTH ) ),
459 maFtHeight ( this, SVX_RES( DLG_FILTERMOSAIC_FT_HEIGHT ) ),
460 maMtrHeight ( this, SVX_RES( DLG_FILTERMOSAIC_MTR_HEIGHT ) ),
461 maCbxEdges ( this, SVX_RES( DLG_FILTERMOSAIC_CBX_EDGES ) )
463 FreeResource();
465 maMtrWidth.SetValue( nTileWidth );
466 maMtrWidth.SetLast( GetGraphicSizePixel().Width() );
467 maMtrWidth.SetModifyHdl( GetModifyHdl() );
469 maMtrHeight.SetValue( nTileHeight );
470 maMtrHeight.SetLast( GetGraphicSizePixel().Height() );
471 maMtrHeight.SetModifyHdl( GetModifyHdl() );
473 maCbxEdges.Check( bEnhanceEdges );
474 maCbxEdges.SetToggleHdl( GetModifyHdl() );
476 maMtrWidth.GrabFocus();
479 // -----------------------------------------------------------------------------
481 GraphicFilterMosaic::~GraphicFilterMosaic()
485 // -----------------------------------------------------------------------------
487 Graphic GraphicFilterMosaic::GetFilteredGraphic( const Graphic& rGraphic,
488 double fScaleX, double fScaleY )
490 Graphic aRet;
491 const Size aSize( Max( FRound( GetTileWidth() * fScaleX ), 1L ),
492 Max( FRound( GetTileHeight() * fScaleY ), 1L ) );
493 BmpFilterParam aParam( aSize );
495 if( rGraphic.IsAnimated() )
497 Animation aAnim( rGraphic.GetAnimation() );
499 if( aAnim.Filter( BMP_FILTER_MOSAIC, &aParam ) )
501 if( IsEnhanceEdges() )
502 aAnim.Filter( BMP_FILTER_SHARPEN );
504 aRet = aAnim;
507 else
509 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
511 if( aBmpEx.Filter( BMP_FILTER_MOSAIC, &aParam ) )
513 if( IsEnhanceEdges() )
514 aBmpEx.Filter( BMP_FILTER_SHARPEN );
516 aRet = aBmpEx;
520 return aRet;
523 // ------------------
524 // - GraphicFilterSolarize -
525 // ------------------
527 GraphicFilterSolarize::GraphicFilterSolarize( Window* pParent, const Graphic& rGraphic,
528 BYTE cGreyThreshold, BOOL bInvert ) :
529 GraphicFilterDialog ( pParent, SVX_RES( RID_SVX_GRFFILTER_DLG_SOLARIZE ), rGraphic ),
530 maFtThreshold ( this, SVX_RES( DLG_FILTERSOLARIZE_FT_THRESHOLD ) ),
531 maMtrThreshold ( this, SVX_RES( DLG_FILTERSOLARIZE_MTR_THRESHOLD ) ),
532 maCbxInvert ( this, SVX_RES( DLG_FILTERSOLARIZE_CBX_INVERT ) )
534 FreeResource();
536 maMtrThreshold.SetValue( FRound( cGreyThreshold / 2.55 ) );
537 maMtrThreshold.SetModifyHdl( GetModifyHdl() );
539 maCbxInvert.Check( bInvert );
540 maCbxInvert.SetToggleHdl( GetModifyHdl() );
542 maMtrThreshold.GrabFocus();
545 // -----------------------------------------------------------------------------
547 GraphicFilterSolarize::~GraphicFilterSolarize()
551 // -----------------------------------------------------------------------------
553 Graphic GraphicFilterSolarize::GetFilteredGraphic( const Graphic& rGraphic,
554 double /*fScaleX*/, double /*fScaleY*/ )
556 Graphic aRet;
557 BmpFilterParam aParam( GetGreyThreshold() );
559 if( rGraphic.IsAnimated() )
561 Animation aAnim( rGraphic.GetAnimation() );
563 if( aAnim.Filter( BMP_FILTER_SOLARIZE, &aParam ) )
565 if( IsInvert() )
566 aAnim.Invert();
568 aRet = aAnim;
571 else
573 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
575 if( aBmpEx.Filter( BMP_FILTER_SOLARIZE, &aParam ) )
577 if( IsInvert() )
578 aBmpEx.Invert();
580 aRet = aBmpEx;
584 return aRet;
587 // ----------------------
588 // - GraphicFilterSepia -
589 // ----------------------
591 GraphicFilterSepia::GraphicFilterSepia( Window* pParent, const Graphic& rGraphic,
592 USHORT nSepiaPercent ) :
593 GraphicFilterDialog ( pParent, SVX_RES( RID_SVX_GRFFILTER_DLG_SEPIA ), rGraphic ),
594 maFtSepia ( this, SVX_RES( DLG_FILTERSEPIA_FT_SEPIA ) ),
595 maMtrSepia ( this, SVX_RES( DLG_FILTERSEPIA_MTR_SEPIA ) )
597 FreeResource();
599 maMtrSepia.SetValue( nSepiaPercent );
600 maMtrSepia.SetModifyHdl( GetModifyHdl() );
602 maMtrSepia.GrabFocus();
605 // -----------------------------------------------------------------------------
607 GraphicFilterSepia::~GraphicFilterSepia()
611 // -----------------------------------------------------------------------------
613 Graphic GraphicFilterSepia::GetFilteredGraphic( const Graphic& rGraphic,
614 double /*fScaleX*/, double /*fScaleY*/ )
616 Graphic aRet;
617 BmpFilterParam aParam( GetSepiaPercent() );
619 if( rGraphic.IsAnimated() )
621 Animation aAnim( rGraphic.GetAnimation() );
623 if( aAnim.Filter( BMP_FILTER_SEPIA, &aParam ) )
624 aRet = aAnim;
626 else
628 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
630 if( aBmpEx.Filter( BMP_FILTER_SEPIA, &aParam ) )
631 aRet = aBmpEx;
634 return aRet;
637 // -----------------------
638 // - GraphicFilterPoster -
639 // -----------------------
641 GraphicFilterPoster::GraphicFilterPoster( Window* pParent, const Graphic& rGraphic,
642 USHORT nPosterCount ) :
643 GraphicFilterDialog ( pParent, SVX_RES( RID_SVX_GRFFILTER_DLG_POSTER ), rGraphic ),
644 maFtPoster ( this, SVX_RES( DLG_FILTERPOSTER_FT_POSTER ) ),
645 maNumPoster ( this, SVX_RES( DLG_FILTERPOSTER_NUM_POSTER ) )
647 FreeResource();
649 maNumPoster.SetFirst( 2 );
650 maNumPoster.SetLast( rGraphic.GetBitmapEx().GetBitCount() );
651 maNumPoster.SetValue( nPosterCount );
652 maNumPoster.SetModifyHdl( GetModifyHdl() );
653 maNumPoster.GrabFocus();
656 // -----------------------------------------------------------------------------
658 GraphicFilterPoster::~GraphicFilterPoster()
662 // -----------------------------------------------------------------------------
664 Graphic GraphicFilterPoster::GetFilteredGraphic( const Graphic& rGraphic,
665 double /*fScaleX*/, double /*fScaleY*/ )
667 Graphic aRet;
668 const USHORT nPosterCount = GetPosterColorCount();
670 if( rGraphic.IsAnimated() )
672 Animation aAnim( rGraphic.GetAnimation() );
674 if( aAnim.ReduceColors( nPosterCount, BMP_REDUCE_POPULAR ) )
675 aRet = aAnim;
677 else
679 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
681 if( aBmpEx.ReduceColors( nPosterCount, BMP_REDUCE_POPULAR ) )
682 aRet = aBmpEx;
685 return aRet;
688 // -----------------------
689 // - GraphicFilterEmboss -
690 // -----------------------
692 void GraphicFilterEmboss::EmbossControl::MouseButtonDown( const MouseEvent& rEvt )
694 const RECT_POINT eOldRP = GetActualRP();
696 SvxRectCtl::MouseButtonDown( rEvt );
698 if( GetActualRP() != eOldRP )
699 maModifyHdl.Call( this );
702 // -----------------------------------------------------------------------------
704 GraphicFilterEmboss::GraphicFilterEmboss( Window* pParent, const Graphic& rGraphic,
705 RECT_POINT eLightSource ) :
706 GraphicFilterDialog ( pParent, SVX_RES( RID_SVX_GRFFILTER_DLG_EMBOSS ), rGraphic ),
707 maFtLight ( this, SVX_RES( DLG_FILTEREMBOSS_FT_LIGHT ) ),
708 maCtlLight ( this, SVX_RES( DLG_FILTEREMBOSS_CTL_LIGHT ), eLightSource )
710 FreeResource();
712 maCtlLight.SetModifyHdl( GetModifyHdl() );
713 maCtlLight.GrabFocus();
716 // -----------------------------------------------------------------------------
718 GraphicFilterEmboss::~GraphicFilterEmboss()
722 // -----------------------------------------------------------------------------
724 Graphic GraphicFilterEmboss::GetFilteredGraphic( const Graphic& rGraphic,
725 double /*fScaleX*/, double /*fScaleY*/ )
727 Graphic aRet;
728 USHORT nAzim, nElev;
730 switch( maCtlLight.GetActualRP() )
732 default: DBG_ERROR("svx::GraphicFilterEmboss::GetFilteredGraphic(), unknown Reference Point!" );
733 case( RP_LT ): nAzim = 4500, nElev = 4500; break;
734 case( RP_MT ): nAzim = 9000, nElev = 4500; break;
735 case( RP_RT ): nAzim = 13500, nElev = 4500; break;
736 case( RP_LM ): nAzim = 0, nElev = 4500; break;
737 case( RP_MM ): nAzim = 0, nElev = 9000; break;
738 case( RP_RM ): nAzim = 18000, nElev = 4500; break;
739 case( RP_LB ): nAzim = 31500, nElev = 4500; break;
740 case( RP_MB ): nAzim = 27000, nElev = 4500; break;
741 case( RP_RB ): nAzim = 22500, nElev = 4500; break;
744 BmpFilterParam aParam( nAzim, nElev );
746 if( rGraphic.IsAnimated() )
748 Animation aAnim( rGraphic.GetAnimation() );
750 if( aAnim.Filter( BMP_FILTER_EMBOSS_GREY, &aParam ) )
751 aRet = aAnim;
753 else
755 BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
757 if( aBmpEx.Filter( BMP_FILTER_EMBOSS_GREY, &aParam ) )
758 aRet = aBmpEx;
761 return aRet;