1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_cui.hxx" 26 27 #include <tools/shl.hxx> 28 #include <vcl/msgbox.hxx> 29 #include <sfx2/viewfrm.hxx> 30 #include <sfx2/viewsh.hxx> 31 #include <sfx2/objsh.hxx> 32 #include <sfx2/request.hxx> 33 #include <dialmgr.hxx> 34 #include "cuigrfflt.hxx" 35 #include "grfflt.hrc" 36 #include <cuires.hrc> 37 #include <svx/dialogs.hrc> // RID_SVX_GRFFILTER_DLG_... 38 39 // -------------------- 40 // - SvxGraphicFilter - 41 // -------------------- 42 /* 43 sal_uLong SvxGraphicFilter::ExecuteGrfFilterSlot( SfxRequest& rReq, GraphicObject& rFilterObject ) 44 { 45 const Graphic& rGraphic = rFilterObject.GetGraphic(); 46 sal_uLong nRet; 47 48 if( rGraphic.GetType() == GRAPHIC_BITMAP ) 49 { 50 SfxViewFrame* pViewFrame = SfxViewFrame::Current(); 51 SfxObjectShell* pShell = pViewFrame ? pViewFrame->GetObjectShell() : NULL; 52 Window* pWindow = ( pViewFrame && pViewFrame->GetViewShell() ) ? pViewFrame->GetViewShell()->GetWindow() : NULL; 53 Graphic aGraphic; 54 55 switch( rReq.GetSlot() ) 56 { 57 case( SID_GRFFILTER_INVERT ): 58 { 59 if( pShell ) 60 pShell->SetWaitCursor( sal_True ); 61 62 if( rGraphic.IsAnimated() ) 63 { 64 Animation aAnimation( rGraphic.GetAnimation() ); 65 66 if( aAnimation.Invert() ) 67 aGraphic = aAnimation; 68 } 69 else 70 { 71 BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); 72 73 if( aBmpEx.Invert() ) 74 aGraphic = aBmpEx; 75 } 76 77 if( pShell ) 78 pShell->SetWaitCursor( sal_False ); 79 } 80 break; 81 82 case( SID_GRFFILTER_SMOOTH ): 83 { 84 if( pShell ) 85 pShell->SetWaitCursor( sal_True ); 86 87 if( rGraphic.IsAnimated() ) 88 { 89 Animation aAnimation( rGraphic.GetAnimation() ); 90 91 if( aAnimation.Filter( BMP_FILTER_SMOOTH ) ) 92 aGraphic = aAnimation; 93 } 94 else 95 { 96 BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); 97 98 if( aBmpEx.Filter( BMP_FILTER_SMOOTH ) ) 99 aGraphic = aBmpEx; 100 } 101 102 if( pShell ) 103 pShell->SetWaitCursor( sal_False ); 104 } 105 break; 106 107 case( SID_GRFFILTER_SHARPEN ): 108 { 109 if( pShell ) 110 pShell->SetWaitCursor( sal_True ); 111 112 if( rGraphic.IsAnimated() ) 113 { 114 Animation aAnimation( rGraphic.GetAnimation() ); 115 116 if( aAnimation.Filter( BMP_FILTER_SHARPEN ) ) 117 aGraphic = aAnimation; 118 } 119 else 120 { 121 BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); 122 123 if( aBmpEx.Filter( BMP_FILTER_SHARPEN ) ) 124 aGraphic = aBmpEx; 125 } 126 127 if( pShell ) 128 pShell->SetWaitCursor( sal_False ); 129 } 130 break; 131 132 case( SID_GRFFILTER_REMOVENOISE ): 133 { 134 if( pShell ) 135 pShell->SetWaitCursor( sal_True ); 136 137 if( rGraphic.IsAnimated() ) 138 { 139 Animation aAnimation( rGraphic.GetAnimation() ); 140 141 if( aAnimation.Filter( BMP_FILTER_REMOVENOISE ) ) 142 aGraphic = aAnimation; 143 } 144 else 145 { 146 BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); 147 148 if( aBmpEx.Filter( BMP_FILTER_REMOVENOISE ) ) 149 aGraphic = aBmpEx; 150 } 151 152 if( pShell ) 153 pShell->SetWaitCursor( sal_False ); 154 } 155 break; 156 157 case( SID_GRFFILTER_SOBEL ): 158 { 159 if( pShell ) 160 pShell->SetWaitCursor( sal_True ); 161 162 if( rGraphic.IsAnimated() ) 163 { 164 Animation aAnimation( rGraphic.GetAnimation() ); 165 166 if( aAnimation.Filter( BMP_FILTER_SOBEL_GREY ) ) 167 aGraphic = aAnimation; 168 } 169 else 170 { 171 BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); 172 173 if( aBmpEx.Filter( BMP_FILTER_SOBEL_GREY ) ) 174 aGraphic = aBmpEx; 175 } 176 177 if( pShell ) 178 pShell->SetWaitCursor( sal_False ); 179 } 180 break; 181 182 case( SID_GRFFILTER_MOSAIC ): 183 { 184 GraphicFilterMosaic aDlg( pWindow, rGraphic, 4, 4, sal_False ); 185 186 if( aDlg.Execute() == RET_OK ) 187 aGraphic = aDlg.GetFilteredGraphic( rGraphic, 1.0, 1.0 ); 188 } 189 break; 190 191 case( SID_GRFFILTER_EMBOSS ): 192 { 193 GraphicFilterEmboss aDlg( pWindow, rGraphic, RP_MM ); 194 195 if( aDlg.Execute() == RET_OK ) 196 aGraphic = aDlg.GetFilteredGraphic( rGraphic, 1.0, 1.0 ); 197 } 198 break; 199 200 case( SID_GRFFILTER_POSTER ): 201 { 202 GraphicFilterPoster aDlg( pWindow, rGraphic, 16 ); 203 204 if( aDlg.Execute() == RET_OK ) 205 aGraphic = aDlg.GetFilteredGraphic( rGraphic, 1.0, 1.0 ); 206 } 207 break; 208 209 case( SID_GRFFILTER_POPART ): 210 { 211 if( pShell ) 212 pShell->SetWaitCursor( sal_True ); 213 214 if( rGraphic.IsAnimated() ) 215 { 216 Animation aAnimation( rGraphic.GetAnimation() ); 217 218 if( aAnimation.Filter( BMP_FILTER_POPART ) ) 219 aGraphic = aAnimation; 220 } 221 else 222 { 223 BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); 224 225 if( aBmpEx.Filter( BMP_FILTER_POPART ) ) 226 aGraphic = aBmpEx; 227 } 228 229 if( pShell ) 230 pShell->SetWaitCursor( sal_False ); 231 } 232 break; 233 234 case( SID_GRFFILTER_SEPIA ): 235 { 236 GraphicFilterSepia aDlg( pWindow, rGraphic, 10 ); 237 238 if( aDlg.Execute() == RET_OK ) 239 aGraphic = aDlg.GetFilteredGraphic( rGraphic, 1.0, 1.0 ); 240 } 241 break; 242 243 case( SID_GRFFILTER_SOLARIZE ): 244 { 245 GraphicFilterSolarize aDlg( pWindow, rGraphic, 128, sal_False ); 246 247 if( aDlg.Execute() == RET_OK ) 248 aGraphic = aDlg.GetFilteredGraphic( rGraphic, 1.0, 1.0 ); 249 } 250 break; 251 252 default: 253 { 254 DBG_ERROR( "SvxGraphicFilter: selected filter slot not yet implemented" ); 255 nRet = SVX_GRAPHICFILTER_UNSUPPORTED_SLOT; 256 } 257 break; 258 } 259 260 if( aGraphic.GetType() != GRAPHIC_NONE ) 261 { 262 rFilterObject.SetGraphic( aGraphic ); 263 nRet = SVX_GRAPHICFILTER_ERRCODE_NONE; 264 } 265 } 266 else 267 nRet = SVX_GRAPHICFILTER_UNSUPPORTED_GRAPHICTYPE; 268 269 return nRet; 270 } 271 272 // ----------------------------------------------------------------------------- 273 274 void SvxGraphicFilter::DisableGraphicFilterSlots( SfxItemSet& rSet ) 275 { 276 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER ) ) 277 rSet.DisableItem( SID_GRFFILTER ); 278 279 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_INVERT ) ) 280 rSet.DisableItem( SID_GRFFILTER_INVERT ); 281 282 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_SMOOTH ) ) 283 rSet.DisableItem( SID_GRFFILTER_SMOOTH ); 284 285 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_SHARPEN ) ) 286 rSet.DisableItem( SID_GRFFILTER_SHARPEN ); 287 288 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_REMOVENOISE ) ) 289 rSet.DisableItem( SID_GRFFILTER_REMOVENOISE ); 290 291 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_SOBEL ) ) 292 rSet.DisableItem( SID_GRFFILTER_SOBEL ); 293 294 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_MOSAIC ) ) 295 rSet.DisableItem( SID_GRFFILTER_MOSAIC ); 296 297 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_EMBOSS ) ) 298 rSet.DisableItem( SID_GRFFILTER_EMBOSS ); 299 300 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_POSTER ) ) 301 rSet.DisableItem( SID_GRFFILTER_POSTER ); 302 303 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_POPART ) ) 304 rSet.DisableItem( SID_GRFFILTER_POPART ); 305 306 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_SEPIA ) ) 307 rSet.DisableItem( SID_GRFFILTER_SEPIA ); 308 309 if( SFX_ITEM_AVAILABLE <= rSet.GetItemState( SID_GRFFILTER_SOLARIZE ) ) 310 rSet.DisableItem( SID_GRFFILTER_SOLARIZE ); 311 }; 312 */ 313 // -------------------------------------- 314 // - GraphicFilterDialog::PreviewWindow - 315 // -------------------------------------- 316 317 GraphicFilterDialog::PreviewWindow::PreviewWindow( Window* pParent, const ResId& rResId ) : 318 Control( pParent, rResId ) 319 { 320 } 321 322 // ----------------------------------------------------------------------------- 323 324 GraphicFilterDialog::PreviewWindow::~PreviewWindow() 325 { 326 } 327 328 // ----------------------------------------------------------------------------- 329 330 void GraphicFilterDialog::PreviewWindow::Paint( const Rectangle& rRect ) 331 { 332 Control::Paint( rRect ); 333 334 const Size aGrfSize( LogicToPixel( maGraphic.GetPrefSize(), maGraphic.GetPrefMapMode() ) ); 335 const Size aOutSize( GetOutputSizePixel() ); 336 const Point aGrfPos( ( aOutSize.Width() - aGrfSize.Width() ) >> 1, 337 ( aOutSize.Height() - aGrfSize.Height() ) >> 1 ); 338 339 if( maGraphic.IsAnimated() ) 340 maGraphic.StartAnimation( this , aGrfPos, aGrfSize ); 341 else 342 maGraphic.Draw( this, aGrfPos, aGrfSize ); 343 } 344 345 // ----------------------------------------------------------------------------- 346 347 void GraphicFilterDialog::PreviewWindow::SetGraphic( const Graphic& rGraphic ) 348 { 349 maGraphic = rGraphic; 350 351 if( maGraphic.IsAnimated() || maGraphic.IsTransparent() ) 352 Invalidate(); 353 else 354 Paint( Rectangle( Point(), GetOutputSizePixel() ) ); 355 } 356 357 // ----------------------- 358 // - GraphicFilterDialog - 359 // ----------------------- 360 361 GraphicFilterDialog::GraphicFilterDialog( Window* pParent, const ResId& rResId, const Graphic& rGraphic ) : 362 ModalDialog ( pParent, rResId ), 363 maModifyHdl ( LINK( this, GraphicFilterDialog, ImplModifyHdl ) ), 364 mfScaleX ( 0.0 ), 365 mfScaleY ( 0.0 ), 366 maSizePixel ( LogicToPixel( rGraphic.GetPrefSize(), rGraphic.GetPrefMapMode() ) ), 367 maPreview ( this, CUI_RES( CTL_PREVIEW ) ), 368 maBtnOK ( this, CUI_RES( BTN_OK ) ), 369 maBtnCancel ( this, CUI_RES( BTN_CANCEL ) ), 370 maBtnHelp ( this, CUI_RES( BTN_HELP ) ), 371 maFlParameter ( this, CUI_RES( FL_PARAMETER ) ) 372 { 373 const Size aPreviewSize( maPreview.GetOutputSizePixel() ); 374 Size aGrfSize( maSizePixel ); 375 376 if( rGraphic.GetType() == GRAPHIC_BITMAP && 377 aPreviewSize.Width() && aPreviewSize.Height() && 378 aGrfSize.Width() && aGrfSize.Height() ) 379 { 380 const double fGrfWH = (double) aGrfSize.Width() / aGrfSize.Height(); 381 const double fPreWH = (double) aPreviewSize.Width() / aPreviewSize.Height(); 382 383 if( fGrfWH < fPreWH ) 384 { 385 aGrfSize.Width() = (long) ( aPreviewSize.Height() * fGrfWH ); 386 aGrfSize.Height()= aPreviewSize.Height(); 387 } 388 else 389 { 390 aGrfSize.Width() = aPreviewSize.Width(); 391 aGrfSize.Height()= (long) ( aPreviewSize.Width() / fGrfWH); 392 } 393 394 mfScaleX = (double) aGrfSize.Width() / maSizePixel.Width(); 395 mfScaleY = (double) aGrfSize.Height() / maSizePixel.Height(); 396 397 if( !rGraphic.IsAnimated() ) 398 { 399 BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); 400 401 if( aBmpEx.Scale( aGrfSize, BMP_SCALE_INTERPOLATE ) ) 402 maGraphic = aBmpEx; 403 } 404 } 405 406 maTimer.SetTimeoutHdl( LINK( this, GraphicFilterDialog, ImplPreviewTimeoutHdl ) ); 407 maTimer.SetTimeout( 100 ); 408 ImplModifyHdl( NULL ); 409 } 410 411 // ----------------------------------------------------------------------------- 412 413 GraphicFilterDialog::~GraphicFilterDialog() 414 { 415 } 416 417 // ----------------------------------------------------------------------------- 418 419 IMPL_LINK( GraphicFilterDialog, ImplPreviewTimeoutHdl, Timer*, EMPTYARG ) 420 { 421 maTimer.Stop(); 422 maPreview.SetGraphic( GetFilteredGraphic( maGraphic, mfScaleX, mfScaleY ) ); 423 424 return 0; 425 } 426 427 // ----------------------------------------------------------------------------- 428 429 IMPL_LINK( GraphicFilterDialog, ImplModifyHdl, void*, EMPTYARG ) 430 { 431 if( maGraphic.GetType() == GRAPHIC_BITMAP ) 432 { 433 maTimer.Stop(); 434 maTimer.Start(); 435 } 436 437 return 0; 438 } 439 440 // ---------------- 441 // - FilterMosaic - 442 // ---------------- 443 444 GraphicFilterMosaic::GraphicFilterMosaic( Window* pParent, const Graphic& rGraphic, 445 sal_uInt16 nTileWidth, sal_uInt16 nTileHeight, sal_Bool bEnhanceEdges ) : 446 GraphicFilterDialog( pParent, CUI_RES( RID_SVX_GRFFILTER_DLG_MOSAIC ), rGraphic ), 447 maFtWidth ( this, CUI_RES( DLG_FILTERMOSAIC_FT_WIDTH ) ), 448 maMtrWidth ( this, CUI_RES( DLG_FILTERMOSAIC_MTR_WIDTH ) ), 449 maFtHeight ( this, CUI_RES( DLG_FILTERMOSAIC_FT_HEIGHT ) ), 450 maMtrHeight ( this, CUI_RES( DLG_FILTERMOSAIC_MTR_HEIGHT ) ), 451 maCbxEdges ( this, CUI_RES( DLG_FILTERMOSAIC_CBX_EDGES ) ) 452 { 453 FreeResource(); 454 455 maMtrWidth.SetValue( nTileWidth ); 456 maMtrWidth.SetLast( GetGraphicSizePixel().Width() ); 457 maMtrWidth.SetModifyHdl( GetModifyHdl() ); 458 459 maMtrHeight.SetValue( nTileHeight ); 460 maMtrHeight.SetLast( GetGraphicSizePixel().Height() ); 461 maMtrHeight.SetModifyHdl( GetModifyHdl() ); 462 463 maCbxEdges.Check( bEnhanceEdges ); 464 maCbxEdges.SetToggleHdl( GetModifyHdl() ); 465 466 maMtrWidth.GrabFocus(); 467 468 maFtWidth.SetAccessibleRelationMemberOf(&maFlParameter); 469 maMtrWidth.SetAccessibleRelationMemberOf(&maFlParameter); 470 maFtHeight.SetAccessibleRelationMemberOf(&maFlParameter); 471 maMtrHeight.SetAccessibleRelationMemberOf(&maFlParameter); 472 maCbxEdges.SetAccessibleRelationMemberOf(&maFlParameter); 473 } 474 475 // ----------------------------------------------------------------------------- 476 477 GraphicFilterMosaic::~GraphicFilterMosaic() 478 { 479 } 480 481 // ----------------------------------------------------------------------------- 482 483 Graphic GraphicFilterMosaic::GetFilteredGraphic( const Graphic& rGraphic, 484 double fScaleX, double fScaleY ) 485 { 486 Graphic aRet; 487 const Size aSize( Max( FRound( GetTileWidth() * fScaleX ), 1L ), 488 Max( FRound( GetTileHeight() * fScaleY ), 1L ) ); 489 BmpFilterParam aParam( aSize ); 490 491 if( rGraphic.IsAnimated() ) 492 { 493 Animation aAnim( rGraphic.GetAnimation() ); 494 495 if( aAnim.Filter( BMP_FILTER_MOSAIC, &aParam ) ) 496 { 497 if( IsEnhanceEdges() ) 498 aAnim.Filter( BMP_FILTER_SHARPEN ); 499 500 aRet = aAnim; 501 } 502 } 503 else 504 { 505 BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); 506 507 if( aBmpEx.Filter( BMP_FILTER_MOSAIC, &aParam ) ) 508 { 509 if( IsEnhanceEdges() ) 510 aBmpEx.Filter( BMP_FILTER_SHARPEN ); 511 512 aRet = aBmpEx; 513 } 514 } 515 516 return aRet; 517 } 518 519 // ------------------ 520 // - GraphicFilterSolarize - 521 // ------------------ 522 523 GraphicFilterSolarize::GraphicFilterSolarize( Window* pParent, const Graphic& rGraphic, 524 sal_uInt8 cGreyThreshold, sal_Bool bInvert ) : 525 GraphicFilterDialog ( pParent, CUI_RES( RID_SVX_GRFFILTER_DLG_SOLARIZE ), rGraphic ), 526 maFtThreshold ( this, CUI_RES( DLG_FILTERSOLARIZE_FT_THRESHOLD ) ), 527 maMtrThreshold ( this, CUI_RES( DLG_FILTERSOLARIZE_MTR_THRESHOLD ) ), 528 maCbxInvert ( this, CUI_RES( DLG_FILTERSOLARIZE_CBX_INVERT ) ) 529 { 530 FreeResource(); 531 532 maMtrThreshold.SetValue( FRound( cGreyThreshold / 2.55 ) ); 533 maMtrThreshold.SetModifyHdl( GetModifyHdl() ); 534 535 maCbxInvert.Check( bInvert ); 536 maCbxInvert.SetToggleHdl( GetModifyHdl() ); 537 538 // IAccessibility2 Implementation 2009 539 // maMtrThreshold.GrabFocus(); 540 } 541 542 // ----------------------------------------------------------------------------- 543 544 GraphicFilterSolarize::~GraphicFilterSolarize() 545 { 546 } 547 548 // ----------------------------------------------------------------------------- 549 550 Graphic GraphicFilterSolarize::GetFilteredGraphic( const Graphic& rGraphic, 551 double /*fScaleX*/, double /*fScaleY*/ ) 552 { 553 Graphic aRet; 554 BmpFilterParam aParam( GetGreyThreshold() ); 555 556 if( rGraphic.IsAnimated() ) 557 { 558 Animation aAnim( rGraphic.GetAnimation() ); 559 560 if( aAnim.Filter( BMP_FILTER_SOLARIZE, &aParam ) ) 561 { 562 if( IsInvert() ) 563 aAnim.Invert(); 564 565 aRet = aAnim; 566 } 567 } 568 else 569 { 570 BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); 571 572 if( aBmpEx.Filter( BMP_FILTER_SOLARIZE, &aParam ) ) 573 { 574 if( IsInvert() ) 575 aBmpEx.Invert(); 576 577 aRet = aBmpEx; 578 } 579 } 580 581 return aRet; 582 } 583 584 // ---------------------- 585 // - GraphicFilterSepia - 586 // ---------------------- 587 588 GraphicFilterSepia::GraphicFilterSepia( Window* pParent, const Graphic& rGraphic, 589 sal_uInt16 nSepiaPercent ) : 590 GraphicFilterDialog ( pParent, CUI_RES( RID_SVX_GRFFILTER_DLG_SEPIA ), rGraphic ), 591 maFtSepia ( this, CUI_RES( DLG_FILTERSEPIA_FT_SEPIA ) ), 592 maMtrSepia ( this, CUI_RES( DLG_FILTERSEPIA_MTR_SEPIA ) ) 593 { 594 FreeResource(); 595 596 maMtrSepia.SetValue( nSepiaPercent ); 597 maMtrSepia.SetModifyHdl( GetModifyHdl() ); 598 599 // IAccessibility2 Implementation 2009 600 // maMtrSepia.GrabFocus(); 601 } 602 603 // ----------------------------------------------------------------------------- 604 605 GraphicFilterSepia::~GraphicFilterSepia() 606 { 607 } 608 609 // ----------------------------------------------------------------------------- 610 611 Graphic GraphicFilterSepia::GetFilteredGraphic( const Graphic& rGraphic, 612 double /*fScaleX*/, double /*fScaleY*/ ) 613 { 614 Graphic aRet; 615 BmpFilterParam aParam( GetSepiaPercent() ); 616 617 if( rGraphic.IsAnimated() ) 618 { 619 Animation aAnim( rGraphic.GetAnimation() ); 620 621 if( aAnim.Filter( BMP_FILTER_SEPIA, &aParam ) ) 622 aRet = aAnim; 623 } 624 else 625 { 626 BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); 627 628 if( aBmpEx.Filter( BMP_FILTER_SEPIA, &aParam ) ) 629 aRet = aBmpEx; 630 } 631 632 return aRet; 633 } 634 635 // ----------------------- 636 // - GraphicFilterPoster - 637 // ----------------------- 638 639 GraphicFilterPoster::GraphicFilterPoster( Window* pParent, const Graphic& rGraphic, 640 sal_uInt16 nPosterCount ) : 641 GraphicFilterDialog ( pParent, CUI_RES( RID_SVX_GRFFILTER_DLG_POSTER ), rGraphic ), 642 maFtPoster ( this, CUI_RES( DLG_FILTERPOSTER_FT_POSTER ) ), 643 maNumPoster ( this, CUI_RES( DLG_FILTERPOSTER_NUM_POSTER ) ) 644 { 645 FreeResource(); 646 647 maNumPoster.SetFirst( 2 ); 648 maNumPoster.SetLast( rGraphic.GetBitmapEx().GetBitCount() ); 649 maNumPoster.SetValue( nPosterCount ); 650 maNumPoster.SetModifyHdl( GetModifyHdl() ); 651 652 // IAccessibility2 Implementation 2009 653 // maNumPoster.GrabFocus(); 654 } 655 656 // ----------------------------------------------------------------------------- 657 658 GraphicFilterPoster::~GraphicFilterPoster() 659 { 660 } 661 662 // ----------------------------------------------------------------------------- 663 664 Graphic GraphicFilterPoster::GetFilteredGraphic( const Graphic& rGraphic, 665 double /*fScaleX*/, double /*fScaleY*/ ) 666 { 667 Graphic aRet; 668 const sal_uInt16 nPosterCount = GetPosterColorCount(); 669 670 if( rGraphic.IsAnimated() ) 671 { 672 Animation aAnim( rGraphic.GetAnimation() ); 673 674 if( aAnim.ReduceColors( nPosterCount, BMP_REDUCE_POPULAR ) ) 675 aRet = aAnim; 676 } 677 else 678 { 679 BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); 680 681 if( aBmpEx.ReduceColors( nPosterCount, BMP_REDUCE_POPULAR ) ) 682 aRet = aBmpEx; 683 } 684 685 return aRet; 686 } 687 688 // ----------------------- 689 // - GraphicFilterEmboss - 690 // ----------------------- 691 692 void GraphicFilterEmboss::EmbossControl::MouseButtonDown( const MouseEvent& rEvt ) 693 { 694 const RECT_POINT eOldRP = GetActualRP(); 695 696 SvxRectCtl::MouseButtonDown( rEvt ); 697 698 if( GetActualRP() != eOldRP ) 699 maModifyHdl.Call( this ); 700 } 701 702 // ----------------------------------------------------------------------------- 703 704 GraphicFilterEmboss::GraphicFilterEmboss( Window* pParent, const Graphic& rGraphic, 705 RECT_POINT eLightSource ) : 706 GraphicFilterDialog ( pParent, CUI_RES( RID_SVX_GRFFILTER_DLG_EMBOSS ), rGraphic ), 707 maFtLight ( this, CUI_RES( DLG_FILTEREMBOSS_FT_LIGHT ) ), 708 maCtlLight ( this, CUI_RES( DLG_FILTEREMBOSS_CTL_LIGHT ), eLightSource ) 709 { 710 FreeResource(); 711 712 maCtlLight.SetModifyHdl( GetModifyHdl() ); 713 maCtlLight.GrabFocus(); 714 } 715 716 // ----------------------------------------------------------------------------- 717 718 GraphicFilterEmboss::~GraphicFilterEmboss() 719 { 720 } 721 722 // ----------------------------------------------------------------------------- 723 724 Graphic GraphicFilterEmboss::GetFilteredGraphic( const Graphic& rGraphic, 725 double /*fScaleX*/, double /*fScaleY*/ ) 726 { 727 Graphic aRet; 728 sal_uInt16 nAzim, nElev; 729 730 switch( maCtlLight.GetActualRP() ) 731 { 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; 742 } 743 744 BmpFilterParam aParam( nAzim, nElev ); 745 746 if( rGraphic.IsAnimated() ) 747 { 748 Animation aAnim( rGraphic.GetAnimation() ); 749 750 if( aAnim.Filter( BMP_FILTER_EMBOSS_GREY, &aParam ) ) 751 aRet = aAnim; 752 } 753 else 754 { 755 BitmapEx aBmpEx( rGraphic.GetBitmapEx() ); 756 757 if( aBmpEx.Filter( BMP_FILTER_EMBOSS_GREY, &aParam ) ) 758 aRet = aBmpEx; 759 } 760 761 return aRet; 762 } 763