LCOV - code coverage report
Current view: top level - cui/source/dialogs - cuigrfflt.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 230 0.0 %
Date: 2014-04-11 Functions: 0 29 0.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 <tools/shl.hxx>
      21             : #include <vcl/builder.hxx>
      22             : #include <vcl/msgbox.hxx>
      23             : #include <sfx2/viewfrm.hxx>
      24             : #include <sfx2/viewsh.hxx>
      25             : #include <sfx2/objsh.hxx>
      26             : #include <sfx2/request.hxx>
      27             : #include <dialmgr.hxx>
      28             : #include "cuigrfflt.hxx"
      29             : #include <cuires.hrc>
      30             : #include <svx/dialogs.hrc>
      31             : 
      32           0 : GraphicPreviewWindow::GraphicPreviewWindow(Window* pParent,
      33             :     const WinBits nStyle)
      34             :     : Control(pParent, nStyle)
      35             :     , mpOrigGraphic(NULL)
      36             :     , mfScaleX(0.0)
      37           0 :     , mfScaleY(0.0)
      38             : {
      39           0 : }
      40             : 
      41           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeGraphicPreviewWindow(Window *pParent, VclBuilder::stringmap &rMap)
      42             : {
      43           0 :     WinBits nWinBits = WB_TABSTOP;
      44             : 
      45           0 :     OString sBorder = VclBuilder::extractCustomProperty(rMap);
      46           0 :     if (!sBorder.isEmpty())
      47           0 :        nWinBits |= WB_BORDER;
      48             : 
      49           0 :     return new GraphicPreviewWindow(pParent, nWinBits);
      50             : }
      51             : 
      52           0 : Size GraphicPreviewWindow::GetOptimalSize() const
      53             : {
      54           0 :     return LogicToPixel(Size(81, 73), MAP_APPFONT);
      55             : }
      56             : 
      57             : 
      58             : 
      59           0 : void GraphicPreviewWindow::Paint( const Rectangle& rRect )
      60             : {
      61           0 :     Control::Paint( rRect );
      62             : 
      63           0 :     const Size  aOutputSize( GetOutputSizePixel() );
      64             : 
      65           0 :     if( maPreview.IsAnimated() )
      66             :     {
      67           0 :         const Size  aGraphicSize( LogicToPixel( maPreview.GetPrefSize(), maPreview.GetPrefMapMode() ) );
      68           0 :         const Point aGraphicPosition( ( aOutputSize.Width()  - aGraphicSize.Width()  ) >> 1,
      69           0 :                                       ( aOutputSize.Height() - aGraphicSize.Height() ) >> 1 );
      70           0 :         maPreview.StartAnimation( this, aGraphicPosition, aGraphicSize );
      71             :     }
      72             :     else
      73             :     {
      74           0 :         const Size  aGraphicSize( maPreview.GetSizePixel() );
      75           0 :         const Point aGraphicPosition( ( aOutputSize.Width()  - aGraphicSize.Width()  ) >> 1,
      76           0 :                                       ( aOutputSize.Height() - aGraphicSize.Height() ) >> 1 );
      77           0 :         maPreview.Draw( this, aGraphicPosition, aGraphicSize );
      78             :     }
      79           0 : }
      80             : 
      81             : 
      82             : 
      83           0 : void GraphicPreviewWindow::SetPreview( const Graphic& rGraphic )
      84             : {
      85           0 :     maPreview = rGraphic;
      86           0 :     Invalidate();
      87           0 : }
      88             : 
      89           0 : void GraphicPreviewWindow::ScaleImageToFit()
      90             : {
      91           0 :     if (!mpOrigGraphic)
      92           0 :         return;
      93             : 
      94           0 :     maScaledOrig = *mpOrigGraphic;
      95             : 
      96           0 :     const Size  aPreviewSize( GetOutputSizePixel() );
      97           0 :     Size aSizePixel(LogicToPixel(mpOrigGraphic->GetPrefSize(),
      98           0 :         mpOrigGraphic->GetPrefMapMode()));
      99           0 :     Size aGrfSize(aSizePixel);
     100             : 
     101           0 :     if( mpOrigGraphic->GetType() == GRAPHIC_BITMAP &&
     102           0 :         aPreviewSize.Width() && aPreviewSize.Height() &&
     103           0 :         aGrfSize.Width() && aGrfSize.Height() )
     104             :     {
     105           0 :         const double fGrfWH = (double) aGrfSize.Width() / aGrfSize.Height();
     106           0 :         const double fPreWH = (double) aPreviewSize.Width() / aPreviewSize.Height();
     107             : 
     108           0 :         if( fGrfWH < fPreWH )
     109             :         {
     110           0 :             aGrfSize.Width()  = (long) ( aPreviewSize.Height() * fGrfWH );
     111           0 :             aGrfSize.Height() = aPreviewSize.Height();
     112             :         }
     113             :         else
     114             :         {
     115           0 :             aGrfSize.Width()  = aPreviewSize.Width();
     116           0 :             aGrfSize.Height() = (long) ( aPreviewSize.Width() / fGrfWH );
     117             :         }
     118             : 
     119           0 :         mfScaleX = (double) aGrfSize.Width() / aSizePixel.Width();
     120           0 :         mfScaleY = (double) aGrfSize.Height() / aSizePixel.Height();
     121             : 
     122           0 :         if( !mpOrigGraphic->IsAnimated() )
     123             :         {
     124           0 :             BitmapEx aBmpEx( mpOrigGraphic->GetBitmapEx() );
     125             : 
     126           0 :             if( aBmpEx.Scale( aGrfSize, BMP_SCALE_DEFAULT ) )
     127           0 :                 maScaledOrig = aBmpEx;
     128             :         }
     129             :     }
     130             : 
     131           0 :     maModifyHdl.Call(this);
     132             : }
     133             : 
     134           0 : void GraphicPreviewWindow::Resize()
     135             : {
     136           0 :     Control::Resize();
     137           0 :     ScaleImageToFit();
     138           0 : }
     139             : 
     140           0 : GraphicFilterDialog::GraphicFilterDialog(Window* pParent,
     141             :     const OString& rID, const OUString& rUIXMLDescription,
     142             :     const Graphic& rGraphic)
     143             :     : ModalDialog(pParent, rID, rUIXMLDescription)
     144             :     , maModifyHdl(LINK( this, GraphicFilterDialog, ImplModifyHdl))
     145             :     , maSizePixel(LogicToPixel(rGraphic.GetPrefSize(),
     146           0 :         rGraphic.GetPrefMapMode()))
     147             : {
     148           0 :     bIsBitmap = rGraphic.GetType() == GRAPHIC_BITMAP;
     149             : 
     150           0 :     maTimer.SetTimeoutHdl( LINK( this, GraphicFilterDialog, ImplPreviewTimeoutHdl ) );
     151           0 :     maTimer.SetTimeout( 5 );
     152             : 
     153           0 :     get(mpPreview, "preview");
     154           0 :     mpPreview->init(&rGraphic, maModifyHdl);
     155           0 : }
     156             : 
     157             : 
     158             : 
     159           0 : IMPL_LINK_NOARG(GraphicFilterDialog, ImplPreviewTimeoutHdl)
     160             : {
     161           0 :     maTimer.Stop();
     162           0 :     mpPreview->SetPreview(GetFilteredGraphic(mpPreview->GetScaledOriginal(),
     163           0 :         mpPreview->GetScaleX(), mpPreview->GetScaleY()));
     164             : 
     165           0 :     return 0;
     166             : }
     167             : 
     168             : 
     169             : 
     170           0 : IMPL_LINK_NOARG(GraphicFilterDialog, ImplModifyHdl)
     171             : {
     172           0 :     if (bIsBitmap)
     173             :     {
     174           0 :         maTimer.Stop();
     175           0 :         maTimer.Start();
     176             :     }
     177             : 
     178           0 :     return 0;
     179             : }
     180             : 
     181             : 
     182             : // - FilterMosaic -
     183             : 
     184             : 
     185           0 : GraphicFilterMosaic::GraphicFilterMosaic( Window* pParent, const Graphic& rGraphic,
     186             :                                           sal_uInt16 nTileWidth, sal_uInt16 nTileHeight, sal_Bool bEnhanceEdges )
     187             :     : GraphicFilterDialog(pParent, "MosaicDialog",
     188           0 :         "cui/ui/mosaicdialog.ui", rGraphic)
     189             : {
     190           0 :     get(mpMtrWidth, "width");
     191           0 :     get(mpMtrHeight, "height");
     192           0 :     get(mpCbxEdges, "edges");
     193             : 
     194           0 :     mpMtrWidth->SetValue( nTileWidth );
     195           0 :     mpMtrWidth->SetLast( GetGraphicSizePixel().Width() );
     196           0 :     mpMtrWidth->SetModifyHdl( GetModifyHdl() );
     197             : 
     198           0 :     mpMtrHeight->SetValue( nTileHeight );
     199           0 :     mpMtrHeight->SetLast( GetGraphicSizePixel().Height() );
     200           0 :     mpMtrHeight->SetModifyHdl( GetModifyHdl() );
     201             : 
     202           0 :     mpCbxEdges->Check( bEnhanceEdges );
     203           0 :     mpCbxEdges->SetToggleHdl( GetModifyHdl() );
     204             : 
     205           0 :     mpMtrWidth->GrabFocus();
     206           0 : }
     207             : 
     208             : 
     209             : 
     210           0 : Graphic GraphicFilterMosaic::GetFilteredGraphic( const Graphic& rGraphic,
     211             :                                                  double fScaleX, double fScaleY )
     212             : {
     213           0 :     Graphic         aRet;
     214           0 :     const Size      aSize( std::max( FRound( GetTileWidth() * fScaleX ), 1L ),
     215           0 :                            std::max( FRound( GetTileHeight() * fScaleY ), 1L ) );
     216           0 :     BmpFilterParam  aParam( aSize );
     217             : 
     218           0 :     if( rGraphic.IsAnimated() )
     219             :     {
     220           0 :         Animation aAnim( rGraphic.GetAnimation() );
     221             : 
     222           0 :         if( aAnim.Filter( BMP_FILTER_MOSAIC, &aParam ) )
     223             :         {
     224           0 :             if( IsEnhanceEdges() )
     225           0 :                 aAnim.Filter( BMP_FILTER_SHARPEN );
     226             : 
     227           0 :             aRet = aAnim;
     228           0 :         }
     229             :     }
     230             :     else
     231             :     {
     232           0 :         BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
     233             : 
     234           0 :         if( aBmpEx.Filter( BMP_FILTER_MOSAIC, &aParam ) )
     235             :         {
     236           0 :             if( IsEnhanceEdges() )
     237           0 :                 aBmpEx.Filter( BMP_FILTER_SHARPEN );
     238             : 
     239           0 :             aRet = aBmpEx;
     240           0 :         }
     241             :     }
     242             : 
     243           0 :     return aRet;
     244             : }
     245             : 
     246             : 
     247             : // - GraphicFilterSmooth -
     248             : 
     249             : 
     250           0 : GraphicFilterSmooth::GraphicFilterSmooth( Window* pParent, const Graphic& rGraphic, double nRadius)
     251             :     : GraphicFilterDialog(pParent, "SmoothDialog",
     252           0 :         "cui/ui/smoothdialog.ui", rGraphic)
     253             : {
     254           0 :     get(mpMtrRadius, "radius");
     255             : 
     256           0 :     mpMtrRadius->SetValue( nRadius* 10  );
     257           0 :     mpMtrRadius->SetModifyHdl( GetModifyHdl() );
     258           0 :     mpMtrRadius->GrabFocus();
     259           0 : }
     260             : 
     261             : 
     262             : 
     263           0 : Graphic GraphicFilterSmooth::GetFilteredGraphic( const Graphic& rGraphic, double /*fScaleX*/, double /*fScaleY*/ )
     264             : {
     265           0 :     Graphic         aRet;
     266           0 :     BmpFilterParam  aParam( GetRadius() );
     267             : 
     268           0 :     if( rGraphic.IsAnimated() )
     269             :     {
     270           0 :         Animation aAnim( rGraphic.GetAnimation() );
     271             : 
     272           0 :         if( aAnim.Filter( BMP_FILTER_SMOOTH, &aParam ) )
     273             :         {
     274           0 :             aRet = aAnim;
     275           0 :         }
     276             :     }
     277             :     else
     278             :     {
     279           0 :         BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
     280             : 
     281           0 :         if( aBmpEx.Filter( BMP_FILTER_SMOOTH, &aParam ) )
     282             :         {
     283           0 :             aRet = aBmpEx;
     284           0 :         }
     285             :     }
     286             : 
     287           0 :     return aRet;
     288             : }
     289             : 
     290             : 
     291             : // - GraphicFilterSolarize -
     292             : 
     293             : 
     294           0 : GraphicFilterSolarize::GraphicFilterSolarize( Window* pParent, const Graphic& rGraphic,
     295             :                                               sal_uInt8 cGreyThreshold, sal_Bool bInvert )
     296             :     : GraphicFilterDialog(pParent, "SolarizeDialog",
     297           0 :         "cui/ui/solarizedialog.ui", rGraphic)
     298             : {
     299           0 :     get(mpMtrThreshold, "value");
     300           0 :     get(mpCbxInvert, "invert");
     301             : 
     302           0 :     mpMtrThreshold->SetValue( FRound( cGreyThreshold / 2.55 ) );
     303           0 :     mpMtrThreshold->SetModifyHdl( GetModifyHdl() );
     304             : 
     305           0 :     mpCbxInvert->Check( bInvert );
     306           0 :     mpCbxInvert->SetToggleHdl( GetModifyHdl() );
     307           0 : }
     308             : 
     309             : 
     310             : 
     311           0 : Graphic GraphicFilterSolarize::GetFilteredGraphic( const Graphic& rGraphic,
     312             :                                                    double /*fScaleX*/, double /*fScaleY*/ )
     313             : {
     314           0 :     Graphic         aRet;
     315           0 :     BmpFilterParam  aParam( GetGreyThreshold() );
     316             : 
     317           0 :     if( rGraphic.IsAnimated() )
     318             :     {
     319           0 :         Animation aAnim( rGraphic.GetAnimation() );
     320             : 
     321           0 :         if( aAnim.Filter( BMP_FILTER_SOLARIZE, &aParam ) )
     322             :         {
     323           0 :             if( IsInvert() )
     324           0 :                 aAnim.Invert();
     325             : 
     326           0 :             aRet = aAnim;
     327           0 :         }
     328             :     }
     329             :     else
     330             :     {
     331           0 :         BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
     332             : 
     333           0 :         if( aBmpEx.Filter( BMP_FILTER_SOLARIZE, &aParam ) )
     334             :         {
     335           0 :             if( IsInvert() )
     336           0 :                 aBmpEx.Invert();
     337             : 
     338           0 :             aRet = aBmpEx;
     339           0 :         }
     340             :     }
     341             : 
     342           0 :     return aRet;
     343             : }
     344             : 
     345             : 
     346             : // - GraphicFilterSepia -
     347             : 
     348             : 
     349           0 : GraphicFilterSepia::GraphicFilterSepia( Window* pParent, const Graphic& rGraphic,
     350             :                                         sal_uInt16 nSepiaPercent )
     351             :     : GraphicFilterDialog(pParent, "AgingDialog",
     352           0 :         "cui/ui/agingdialog.ui", rGraphic)
     353             : {
     354           0 :     get(mpMtrSepia, "value");
     355             : 
     356           0 :     mpMtrSepia->SetValue( nSepiaPercent );
     357           0 :     mpMtrSepia->SetModifyHdl( GetModifyHdl() );
     358           0 : }
     359             : 
     360             : 
     361             : 
     362           0 : Graphic GraphicFilterSepia::GetFilteredGraphic( const Graphic& rGraphic,
     363             :                                                 double /*fScaleX*/, double /*fScaleY*/ )
     364             : {
     365           0 :     Graphic         aRet;
     366           0 :     BmpFilterParam  aParam( GetSepiaPercent() );
     367             : 
     368           0 :     if( rGraphic.IsAnimated() )
     369             :     {
     370           0 :         Animation aAnim( rGraphic.GetAnimation() );
     371             : 
     372           0 :         if( aAnim.Filter( BMP_FILTER_SEPIA, &aParam ) )
     373           0 :             aRet = aAnim;
     374             :     }
     375             :     else
     376             :     {
     377           0 :         BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
     378             : 
     379           0 :         if( aBmpEx.Filter( BMP_FILTER_SEPIA, &aParam ) )
     380           0 :             aRet = aBmpEx;
     381             :     }
     382             : 
     383           0 :     return aRet;
     384             : }
     385             : 
     386             : 
     387             : // - GraphicFilterPoster -
     388             : 
     389             : 
     390           0 : GraphicFilterPoster::GraphicFilterPoster(Window* pParent, const Graphic& rGraphic,
     391             :                                           sal_uInt16 nPosterCount)
     392             :     : GraphicFilterDialog(pParent, "PosterDialog",
     393           0 :         "cui/ui/posterdialog.ui", rGraphic)
     394             : {
     395           0 :     get(mpNumPoster, "value");
     396             : 
     397           0 :     mpNumPoster->SetFirst( 2 );
     398           0 :     mpNumPoster->SetLast( rGraphic.GetBitmapEx().GetBitCount() );
     399           0 :     mpNumPoster->SetValue( nPosterCount );
     400           0 :     mpNumPoster->SetModifyHdl( GetModifyHdl() );
     401           0 : }
     402             : 
     403             : 
     404             : 
     405           0 : Graphic GraphicFilterPoster::GetFilteredGraphic( const Graphic& rGraphic,
     406             :                                                  double /*fScaleX*/, double /*fScaleY*/ )
     407             : {
     408           0 :     Graphic         aRet;
     409           0 :     const sal_uInt16    nPosterCount = GetPosterColorCount();
     410             : 
     411           0 :     if( rGraphic.IsAnimated() )
     412             :     {
     413           0 :         Animation aAnim( rGraphic.GetAnimation() );
     414             : 
     415           0 :         if( aAnim.ReduceColors( nPosterCount, BMP_REDUCE_POPULAR ) )
     416           0 :             aRet = aAnim;
     417             :     }
     418             :     else
     419             :     {
     420           0 :         BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
     421             : 
     422           0 :         if( aBmpEx.ReduceColors( nPosterCount, BMP_REDUCE_POPULAR ) )
     423           0 :             aRet = aBmpEx;
     424             :     }
     425             : 
     426           0 :     return aRet;
     427             : }
     428             : 
     429             : 
     430             : // - GraphicFilterEmboss -
     431             : 
     432             : 
     433           0 : void EmbossControl::MouseButtonDown( const MouseEvent& rEvt )
     434             : {
     435           0 :     const RECT_POINT eOldRP = GetActualRP();
     436             : 
     437           0 :     SvxRectCtl::MouseButtonDown( rEvt );
     438             : 
     439           0 :     if( GetActualRP() != eOldRP )
     440           0 :         maModifyHdl.Call( this );
     441           0 : }
     442             : 
     443           0 : Size EmbossControl::GetOptimalSize() const
     444             : {
     445           0 :     return LogicToPixel(Size(77, 60), MAP_APPFONT);
     446             : }
     447             : 
     448           0 : extern "C" SAL_DLLPUBLIC_EXPORT Window* SAL_CALL makeEmbossControl(Window *pParent, VclBuilder::stringmap &)
     449             : {
     450           0 :     return new EmbossControl(pParent);
     451             : }
     452             : 
     453             : 
     454             : 
     455           0 : GraphicFilterEmboss::GraphicFilterEmboss(Window* pParent,
     456             :     const Graphic& rGraphic, RECT_POINT eLightSource)
     457             :     : GraphicFilterDialog (pParent, "EmbossDialog",
     458           0 :         "cui/ui/embossdialog.ui", rGraphic)
     459             : {
     460           0 :     get(mpCtlLight, "lightsource");
     461           0 :     mpCtlLight->SetActualRP(eLightSource);
     462           0 :     mpCtlLight->SetModifyHdl( GetModifyHdl() );
     463           0 :     mpCtlLight->GrabFocus();
     464           0 : }
     465             : 
     466             : 
     467             : 
     468           0 : Graphic GraphicFilterEmboss::GetFilteredGraphic( const Graphic& rGraphic,
     469             :                                                  double /*fScaleX*/, double /*fScaleY*/ )
     470             : {
     471           0 :     Graphic aRet;
     472             :     sal_uInt16  nAzim, nElev;
     473             : 
     474           0 :     switch( mpCtlLight->GetActualRP() )
     475             :     {
     476             :         default:       OSL_FAIL("svx::GraphicFilterEmboss::GetFilteredGraphic(), unknown Reference Point!" );
     477             :                        /* Fall through */
     478           0 :         case( RP_LT ): nAzim = 4500,    nElev = 4500; break;
     479           0 :         case( RP_MT ): nAzim = 9000,    nElev = 4500; break;
     480           0 :         case( RP_RT ): nAzim = 13500,   nElev = 4500; break;
     481           0 :         case( RP_LM ): nAzim = 0,       nElev = 4500; break;
     482           0 :         case( RP_MM ): nAzim = 0,       nElev = 9000; break;
     483           0 :         case( RP_RM ): nAzim = 18000,   nElev = 4500; break;
     484           0 :         case( RP_LB ): nAzim = 31500,   nElev = 4500; break;
     485           0 :         case( RP_MB ): nAzim = 27000,   nElev = 4500; break;
     486           0 :         case( RP_RB ): nAzim = 22500,   nElev = 4500; break;
     487             :     }
     488             : 
     489           0 :     BmpFilterParam aParam( nAzim, nElev );
     490             : 
     491           0 :     if( rGraphic.IsAnimated() )
     492             :     {
     493           0 :         Animation aAnim( rGraphic.GetAnimation() );
     494             : 
     495           0 :         if( aAnim.Filter( BMP_FILTER_EMBOSS_GREY, &aParam ) )
     496           0 :             aRet = aAnim;
     497             :     }
     498             :     else
     499             :     {
     500           0 :         BitmapEx aBmpEx( rGraphic.GetBitmapEx() );
     501             : 
     502           0 :         if( aBmpEx.Filter( BMP_FILTER_EMBOSS_GREY, &aParam ) )
     503           0 :             aRet = aBmpEx;
     504             :     }
     505             : 
     506           0 :     return aRet;
     507           0 : }
     508             : 
     509             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10