LCOV - code coverage report
Current view: top level - svx/source/dialog - grfflt.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 140 0.7 %
Date: 2015-06-13 12:38:46 Functions: 2 4 50.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #include <vcl/msgbox.hxx>
      21             : #include <sfx2/viewfrm.hxx>
      22             : #include <sfx2/viewsh.hxx>
      23             : #include <sfx2/objsh.hxx>
      24             : #include <sfx2/request.hxx>
      25             : 
      26             : #include <svx/dialmgr.hxx>
      27             : #include <svx/grfflt.hxx>
      28             : #include <svx/dialogs.hrc>
      29             : #include <svx/svxdlg.hxx>
      30             : #include <boost/scoped_ptr.hpp>
      31             : 
      32             : 
      33             : // - SvxGraphicFilter -
      34             : 
      35             : 
      36           0 : sal_uIntPtr SvxGraphicFilter::ExecuteGrfFilterSlot( SfxRequest& rReq, GraphicObject& rFilterObject )
      37             : {
      38           0 :     const Graphic&  rGraphic = rFilterObject.GetGraphic();
      39           0 :     sal_uIntPtr         nRet = SVX_GRAPHICFILTER_UNSUPPORTED_GRAPHICTYPE;
      40             : 
      41           0 :     if( rGraphic.GetType() == GRAPHIC_BITMAP )
      42             :     {
      43           0 :         SfxViewFrame*   pViewFrame = SfxViewFrame::Current();
      44           0 :         SfxObjectShell* pShell = pViewFrame ? pViewFrame->GetObjectShell() : NULL;
      45           0 :         vcl::Window*         pWindow = ( pViewFrame && pViewFrame->GetViewShell() ) ? pViewFrame->GetViewShell()->GetWindow() : NULL;
      46           0 :         Graphic         aGraphic;
      47             : 
      48           0 :         switch( rReq.GetSlot() )
      49             :         {
      50             :             case( SID_GRFFILTER_INVERT ):
      51             :             {
      52           0 :                 if( pShell )
      53           0 :                     pShell->SetWaitCursor( true );
      54             : 
      55           0 :                 if( rGraphic.IsAnimated() )
      56             :                 {
      57           0 :                     Animation aAnimation( rGraphic.GetAnimation() );
      58             : 
      59           0 :                     if( aAnimation.Invert() )
      60           0 :                         aGraphic = aAnimation;
      61             :                 }
      62             :                 else
      63             :                 {
      64           0 :                     BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
      65             : 
      66           0 :                     if( aBmpEx.Invert() )
      67           0 :                         aGraphic = aBmpEx;
      68             :                 }
      69             : 
      70           0 :                 if( pShell )
      71           0 :                     pShell->SetWaitCursor( false );
      72             :             }
      73           0 :             break;
      74             : 
      75             :             case( SID_GRFFILTER_SMOOTH ):
      76             :             {
      77           0 :                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
      78           0 :                 if(pFact)
      79             :                 {
      80           0 :                     boost::scoped_ptr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterSmooth(pWindow, rGraphic, 0.7));
      81             :                     DBG_ASSERT(aDlg, "Dialog creation failed!");
      82           0 :                     if( aDlg->Execute() == RET_OK )
      83           0 :                         aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
      84             :                 }
      85             :             }
      86           0 :             break;
      87             : 
      88             :             case( SID_GRFFILTER_SHARPEN ):
      89             :             {
      90           0 :                 if( pShell )
      91           0 :                     pShell->SetWaitCursor( true );
      92             : 
      93           0 :                 if( rGraphic.IsAnimated() )
      94             :                 {
      95           0 :                     Animation aAnimation( rGraphic.GetAnimation() );
      96             : 
      97           0 :                     if( aAnimation.Filter( BMP_FILTER_SHARPEN ) )
      98           0 :                         aGraphic = aAnimation;
      99             :                 }
     100             :                 else
     101             :                 {
     102           0 :                     BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
     103             : 
     104           0 :                     if( aBmpEx.Filter( BMP_FILTER_SHARPEN ) )
     105           0 :                         aGraphic = aBmpEx;
     106             :                 }
     107             : 
     108           0 :                 if( pShell )
     109           0 :                     pShell->SetWaitCursor( false );
     110             :             }
     111           0 :             break;
     112             : 
     113             :             case( SID_GRFFILTER_REMOVENOISE ):
     114             :             {
     115           0 :                 if( pShell )
     116           0 :                     pShell->SetWaitCursor( true );
     117             : 
     118           0 :                 if( rGraphic.IsAnimated() )
     119             :                 {
     120           0 :                     Animation aAnimation( rGraphic.GetAnimation() );
     121             : 
     122           0 :                     if( aAnimation.Filter( BMP_FILTER_REMOVENOISE ) )
     123           0 :                         aGraphic = aAnimation;
     124             :                 }
     125             :                 else
     126             :                 {
     127           0 :                     BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
     128             : 
     129           0 :                     if( aBmpEx.Filter( BMP_FILTER_REMOVENOISE ) )
     130           0 :                         aGraphic = aBmpEx;
     131             :                 }
     132             : 
     133           0 :                 if( pShell )
     134           0 :                     pShell->SetWaitCursor( false );
     135             :             }
     136           0 :             break;
     137             : 
     138             :             case( SID_GRFFILTER_SOBEL ):
     139             :             {
     140           0 :                 if( pShell )
     141           0 :                     pShell->SetWaitCursor( true );
     142             : 
     143           0 :                 if( rGraphic.IsAnimated() )
     144             :                 {
     145           0 :                     Animation aAnimation( rGraphic.GetAnimation() );
     146             : 
     147           0 :                     if( aAnimation.Filter( BMP_FILTER_SOBEL_GREY ) )
     148           0 :                         aGraphic = aAnimation;
     149             :                 }
     150             :                 else
     151             :                 {
     152           0 :                     BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
     153             : 
     154           0 :                     if( aBmpEx.Filter( BMP_FILTER_SOBEL_GREY ) )
     155           0 :                         aGraphic = aBmpEx;
     156             :                 }
     157             : 
     158           0 :                 if( pShell )
     159           0 :                     pShell->SetWaitCursor( false );
     160             :             }
     161           0 :             break;
     162             : 
     163             :             case( SID_GRFFILTER_MOSAIC ):
     164             :             {
     165           0 :                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     166           0 :                 if(pFact)
     167             :                 {
     168           0 :                     boost::scoped_ptr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterMosaic(pWindow, rGraphic, 4, 4, false));
     169             :                     DBG_ASSERT(aDlg, "Dialog creation failed!");
     170           0 :                     if( aDlg->Execute() == RET_OK )
     171           0 :                         aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
     172             :                 }
     173             :             }
     174           0 :             break;
     175             : 
     176             :             case( SID_GRFFILTER_EMBOSS  ):
     177             :             {
     178           0 :                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     179           0 :                 if(pFact)
     180             :                 {
     181           0 :                     boost::scoped_ptr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterEmboss(pWindow, rGraphic, RP_MM));
     182             :                     DBG_ASSERT(aDlg, "Dialog creation failed!");
     183           0 :                     if( aDlg->Execute() == RET_OK )
     184           0 :                         aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
     185             :                 }
     186             :             }
     187           0 :             break;
     188             : 
     189             :             case( SID_GRFFILTER_POSTER  ):
     190             :             {
     191           0 :                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     192           0 :                 if(pFact)
     193             :                 {
     194           0 :                     boost::scoped_ptr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterPoster(pWindow, rGraphic, 16));
     195             :                     DBG_ASSERT(aDlg, "Dialog creation failed!");
     196           0 :                     if( aDlg->Execute() == RET_OK )
     197           0 :                         aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
     198             :                 }
     199             :             }
     200           0 :             break;
     201             : 
     202             :             case( SID_GRFFILTER_POPART  ):
     203             :             {
     204           0 :                 if( pShell )
     205           0 :                     pShell->SetWaitCursor( true );
     206             : 
     207           0 :                 if( rGraphic.IsAnimated() )
     208             :                 {
     209           0 :                     Animation aAnimation( rGraphic.GetAnimation() );
     210             : 
     211           0 :                     if( aAnimation.Filter( BMP_FILTER_POPART ) )
     212           0 :                         aGraphic = aAnimation;
     213             :                 }
     214             :                 else
     215             :                 {
     216           0 :                     BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
     217             : 
     218           0 :                     if( aBmpEx.Filter( BMP_FILTER_POPART ) )
     219           0 :                         aGraphic = aBmpEx;
     220             :                 }
     221             : 
     222           0 :                 if( pShell )
     223           0 :                     pShell->SetWaitCursor( false );
     224             :             }
     225           0 :             break;
     226             : 
     227             :             case( SID_GRFFILTER_SEPIA ):
     228             :             {
     229           0 :                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     230           0 :                 if(pFact)
     231             :                 {
     232           0 :                     boost::scoped_ptr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterSepia(pWindow, rGraphic, 10));
     233             :                     DBG_ASSERT(aDlg, "Dialog creation failed!");
     234           0 :                     if( aDlg->Execute() == RET_OK )
     235           0 :                         aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
     236             :                 }
     237             :             }
     238           0 :             break;
     239             : 
     240             :             case( SID_GRFFILTER_SOLARIZE ):
     241             :             {
     242           0 :                 SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
     243           0 :                 if(pFact)
     244             :                 {
     245           0 :                     boost::scoped_ptr<AbstractGraphicFilterDialog> aDlg(pFact->CreateGraphicFilterSolarize(pWindow, rGraphic, 128, false));
     246             :                     DBG_ASSERT(aDlg, "Dialog creation failed!");
     247           0 :                     if( aDlg->Execute() == RET_OK )
     248           0 :                         aGraphic = aDlg->GetFilteredGraphic( rGraphic, 1.0, 1.0 );
     249             :                 }
     250             :             }
     251           0 :             break;
     252             : 
     253             :             case SID_GRFFILTER :
     254             :             {
     255             :                 // do nothing; no error
     256           0 :                 nRet = SVX_GRAPHICFILTER_ERRCODE_NONE;
     257           0 :                 break;
     258             :             }
     259             : 
     260             :             default:
     261             :             {
     262             :                 OSL_FAIL( "SvxGraphicFilter: selected filter slot not yet implemented" );
     263           0 :                 nRet = SVX_GRAPHICFILTER_UNSUPPORTED_SLOT;
     264             :             }
     265           0 :             break;
     266             :         }
     267             : 
     268           0 :         if( aGraphic.GetType() != GRAPHIC_NONE )
     269             :         {
     270           0 :             rFilterObject.SetGraphic( aGraphic );
     271           0 :             nRet = SVX_GRAPHICFILTER_ERRCODE_NONE;
     272           0 :         }
     273             :     }
     274             : 
     275           0 :     return nRet;
     276             : }
     277             : 
     278             : 
     279             : 
     280           0 : void SvxGraphicFilter::DisableGraphicFilterSlots( SfxItemSet& rSet )
     281             : {
     282           0 :     if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER ) )
     283           0 :         rSet.DisableItem( SID_GRFFILTER );
     284             : 
     285           0 :     if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_INVERT ) )
     286           0 :         rSet.DisableItem( SID_GRFFILTER_INVERT );
     287             : 
     288           0 :     if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_SMOOTH ) )
     289           0 :         rSet.DisableItem( SID_GRFFILTER_SMOOTH );
     290             : 
     291           0 :     if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_SHARPEN ) )
     292           0 :         rSet.DisableItem( SID_GRFFILTER_SHARPEN );
     293             : 
     294           0 :     if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_REMOVENOISE ) )
     295           0 :         rSet.DisableItem( SID_GRFFILTER_REMOVENOISE );
     296             : 
     297           0 :     if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_SOBEL ) )
     298           0 :         rSet.DisableItem( SID_GRFFILTER_SOBEL );
     299             : 
     300           0 :     if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_MOSAIC ) )
     301           0 :         rSet.DisableItem( SID_GRFFILTER_MOSAIC );
     302             : 
     303           0 :     if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_EMBOSS ) )
     304           0 :         rSet.DisableItem( SID_GRFFILTER_EMBOSS );
     305             : 
     306           0 :     if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_POSTER ) )
     307           0 :         rSet.DisableItem( SID_GRFFILTER_POSTER );
     308             : 
     309           0 :     if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_POPART ) )
     310           0 :         rSet.DisableItem( SID_GRFFILTER_POPART );
     311             : 
     312           0 :     if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_SEPIA ) )
     313           0 :         rSet.DisableItem( SID_GRFFILTER_SEPIA );
     314             : 
     315           0 :     if( SfxItemState::DEFAULT <= rSet.GetItemState( SID_GRFFILTER_SOLARIZE ) )
     316           0 :         rSet.DisableItem( SID_GRFFILTER_SOLARIZE );
     317         390 : };
     318             : 
     319             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11