LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/cui/source/tabpages - grfpage.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 478 0.0 %
Date: 2013-07-09 Functions: 0 32 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 <svl/eitem.hxx>
      22             : #include <sfx2/app.hxx>
      23             : #include <sfx2/module.hxx>
      24             : #include <sfx2/sfxsids.hrc>
      25             : #include <dialmgr.hxx>
      26             : #include <svx/dlgutil.hxx>
      27             : #include <editeng/sizeitem.hxx>
      28             : #include <editeng/brushitem.hxx>
      29             : #include <grfpage.hxx>
      30             : #include <svx/grfcrop.hxx>
      31             : #include <grfpage.hrc>
      32             : #include <rtl/ustring.hxx>
      33             : #include <cuires.hrc>
      34             : #include <svx/dialogs.hrc> // for RID_SVXPAGE_GRFCROP
      35             : 
      36             : #define CM_1_TO_TWIP        567
      37             : #define TWIP_TO_INCH        1440
      38             : 
      39             : 
      40           0 : static inline long lcl_GetValue( MetricField& rMetric, FieldUnit eUnit )
      41             : {
      42           0 :     return static_cast<long>(rMetric.Denormalize( rMetric.GetValue( eUnit )));
      43             : }
      44             : 
      45             : /*--------------------------------------------------------------------
      46             :     description: crop graphic
      47             :  --------------------------------------------------------------------*/
      48             : 
      49           0 : SvxGrfCropPage::SvxGrfCropPage ( Window *pParent, const SfxItemSet &rSet )
      50           0 :     : SfxTabPage( pParent,  CUI_RES( RID_SVXPAGE_GRFCROP ), rSet ),
      51           0 :     aCropFL(        this, CUI_RES( FL_CROP    )),
      52           0 :     aZoomConstRB(   this, CUI_RES( RB_ZOOMCONST)),
      53           0 :     aSizeConstRB(   this, CUI_RES( RB_SIZECONST)),
      54           0 :     aLeftFT(        this, CUI_RES( FT_LEFT    )),
      55           0 :     aLeftMF(        this, CUI_RES( MF_LEFT    )),
      56           0 :     aRightFT(       this, CUI_RES( FT_RIGHT   )),
      57           0 :     aRightMF(       this, CUI_RES( MF_RIGHT   )),
      58           0 :     aTopFT(         this, CUI_RES( FT_TOP     )),
      59           0 :     aTopMF(         this, CUI_RES( MF_TOP     )),
      60           0 :     aBottomFT(      this, CUI_RES( FT_BOTTOM  )),
      61           0 :     aBottomMF(      this, CUI_RES( MF_BOTTOM  )),
      62           0 :     aZoomFL(        this, CUI_RES( FL_ZOOM    )),
      63           0 :     aWidthZoomFT(   this, CUI_RES( FT_WIDTHZOOM )),
      64           0 :     aWidthZoomMF(   this, CUI_RES( MF_WIDTHZOOM )),
      65           0 :     aHeightZoomFT(  this, CUI_RES( FT_HEIGHTZOOM)),
      66           0 :     aHeightZoomMF(  this, CUI_RES( MF_HEIGHTZOOM)),
      67           0 :     aSizeFL(        this, CUI_RES( FL_SIZE    )),
      68           0 :     aWidthFT(       this, CUI_RES( FT_WIDTH   )),
      69           0 :     aWidthMF(       this, CUI_RES( MF_WIDTH   )),
      70           0 :     aHeightFT(      this, CUI_RES( FT_HEIGHT  )),
      71           0 :     aHeightMF(      this, CUI_RES( MF_HEIGHT  )),
      72           0 :     aOrigSizeFT(    this, CUI_RES(FT_ORIG_SIZE)),
      73           0 :     aOrigSizePB(    this, CUI_RES( PB_ORGSIZE )),
      74           0 :     aExampleWN(     this, CUI_RES( WN_BSP     )),
      75             :     pLastCropField(0),
      76             :     bInitialized(sal_False),
      77           0 :     bSetOrigSize(sal_False)
      78             : {
      79           0 :     FreeResource();
      80             : 
      81           0 :     SetExchangeSupport();
      82             : 
      83             :     // set the correct metric
      84           0 :     const FieldUnit eMetric = GetModuleFieldUnit( rSet );
      85             : 
      86           0 :     SetFieldUnit( aWidthMF, eMetric );
      87           0 :     SetFieldUnit( aHeightMF, eMetric );
      88           0 :     SetFieldUnit( aLeftMF, eMetric );
      89           0 :     SetFieldUnit( aRightMF, eMetric );
      90           0 :     SetFieldUnit( aTopMF , eMetric );
      91           0 :     SetFieldUnit( aBottomMF, eMetric );
      92             : 
      93           0 :     Link aLk = LINK(this, SvxGrfCropPage, SizeHdl);
      94           0 :     aWidthMF.SetModifyHdl( aLk );
      95           0 :     aHeightMF.SetModifyHdl( aLk );
      96             : 
      97           0 :     aLk = LINK(this, SvxGrfCropPage, ZoomHdl);
      98           0 :     aWidthZoomMF.SetModifyHdl( aLk );
      99           0 :     aHeightZoomMF.SetModifyHdl( aLk );
     100             : 
     101           0 :     aLk = LINK(this, SvxGrfCropPage, CropHdl);
     102           0 :     aLeftMF.SetDownHdl( aLk );
     103           0 :     aRightMF.SetDownHdl( aLk );
     104           0 :     aTopMF.SetDownHdl( aLk );
     105           0 :     aBottomMF.SetDownHdl( aLk );
     106           0 :     aLeftMF.SetUpHdl( aLk );
     107           0 :     aRightMF.SetUpHdl( aLk );
     108           0 :     aTopMF.SetUpHdl( aLk );
     109           0 :     aBottomMF.SetUpHdl( aLk );
     110             : 
     111           0 :     aLk = LINK(this, SvxGrfCropPage, CropModifyHdl);
     112           0 :     aLeftMF.SetModifyHdl( aLk );
     113           0 :     aRightMF.SetModifyHdl( aLk );
     114           0 :     aTopMF.SetModifyHdl( aLk );
     115           0 :     aBottomMF.SetModifyHdl( aLk );
     116             : 
     117           0 :     aLk = LINK(this, SvxGrfCropPage, CropLoseFocusHdl);
     118           0 :     aLeftMF.SetLoseFocusHdl( aLk );
     119           0 :     aRightMF.SetLoseFocusHdl( aLk );
     120           0 :     aTopMF.SetLoseFocusHdl( aLk );
     121           0 :     aBottomMF.SetLoseFocusHdl( aLk );
     122             : 
     123           0 :     aLk = LINK(this, SvxGrfCropPage, OrigSizeHdl);
     124           0 :     aOrigSizePB.SetClickHdl( aLk );
     125             : 
     126           0 :     aTimer.SetTimeoutHdl(LINK(this, SvxGrfCropPage, Timeout));
     127           0 :     aTimer.SetTimeout( 1500 );
     128             : 
     129           0 :     aOrigSizePB.SetAccessibleRelationLabeledBy( &aOrigSizeFT );
     130           0 : }
     131             : 
     132           0 : SvxGrfCropPage::~SvxGrfCropPage()
     133             : {
     134           0 :     aTimer.Stop();
     135           0 : }
     136             : 
     137           0 : SfxTabPage* SvxGrfCropPage::Create(Window *pParent, const SfxItemSet &rSet)
     138             : {
     139           0 :     return new SvxGrfCropPage( pParent, rSet );
     140             : }
     141             : 
     142           0 : void SvxGrfCropPage::Reset( const SfxItemSet &rSet )
     143             : {
     144             :     const SfxPoolItem* pItem;
     145           0 :     const SfxItemPool& rPool = *rSet.GetPool();
     146             : 
     147           0 :     if(SFX_ITEM_SET == rSet.GetItemState( rPool.GetWhich(
     148           0 :                                     SID_ATTR_GRAF_KEEP_ZOOM ), sal_True, &pItem ))
     149             :     {
     150           0 :         if( ((const SfxBoolItem*)pItem)->GetValue() )
     151           0 :             aZoomConstRB.Check();
     152             :         else
     153           0 :             aSizeConstRB.Check();
     154           0 :         aZoomConstRB.SaveValue();
     155             :     }
     156             : 
     157           0 :     sal_uInt16 nW = rPool.GetWhich( SID_ATTR_GRAF_CROP );
     158           0 :     if( SFX_ITEM_SET == rSet.GetItemState( nW, sal_True, &pItem))
     159             :     {
     160           0 :         FieldUnit eUnit = MapToFieldUnit( rSet.GetPool()->GetMetric( nW ));
     161             : 
     162           0 :         SvxGrfCrop* pCrop =  (SvxGrfCrop*)pItem;
     163             : 
     164           0 :         aExampleWN.SetLeft(     pCrop->GetLeft());
     165           0 :         aExampleWN.SetRight(    pCrop->GetRight());
     166           0 :         aExampleWN.SetTop(      pCrop->GetTop());
     167           0 :         aExampleWN.SetBottom(   pCrop->GetBottom());
     168             : 
     169           0 :         aLeftMF.SetValue( aLeftMF.Normalize( pCrop->GetLeft()), eUnit );
     170           0 :         aRightMF.SetValue( aRightMF.Normalize( pCrop->GetRight()), eUnit );
     171           0 :         aTopMF.SetValue( aTopMF.Normalize( pCrop->GetTop()), eUnit );
     172           0 :         aBottomMF.SetValue( aBottomMF.Normalize( pCrop->GetBottom()), eUnit );
     173             :     }
     174             :     else
     175             :     {
     176           0 :         aLeftMF.SetValue( 0 );
     177           0 :         aRightMF.SetValue( 0 );
     178           0 :         aTopMF.SetValue( 0 );
     179           0 :         aBottomMF.SetValue( 0 );
     180             :     }
     181             : 
     182           0 :     nW = rPool.GetWhich( SID_ATTR_PAGE_SIZE );
     183           0 :     if ( SFX_ITEM_SET == rSet.GetItemState( nW, sal_False, &pItem ) )
     184             :     {
     185             :         // orientation and size from the PageItem
     186           0 :         FieldUnit eUnit = MapToFieldUnit( rSet.GetPool()->GetMetric( nW ));
     187             : 
     188           0 :         aPageSize = ((const SvxSizeItem*)pItem)->GetSize();
     189             : 
     190           0 :         sal_Int64 nTmp = aHeightMF.Normalize(aPageSize.Height());
     191           0 :         aHeightMF.SetMax( nTmp, eUnit );
     192           0 :         nTmp = aWidthMF.Normalize(aPageSize.Width());
     193           0 :         aWidthMF.SetMax( nTmp, eUnit );
     194           0 :         nTmp = aWidthMF.Normalize( 23 );
     195           0 :         aHeightMF.SetMin( nTmp, eUnit );
     196           0 :         aWidthMF.SetMin( nTmp, eUnit );
     197             :     }
     198             :     else
     199             :     {
     200             :         aPageSize = OutputDevice::LogicToLogic(
     201             :                         Size( CM_1_TO_TWIP,  CM_1_TO_TWIP ),
     202             :                         MapMode( MAP_TWIP ),
     203           0 :                         MapMode( (MapUnit)rSet.GetPool()->GetMetric( nW ) ) );
     204             :     }
     205             : 
     206           0 :     sal_Bool bFound = sal_False;
     207           0 :     if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_GRAF_GRAPHIC, sal_False, &pItem ) )
     208             :     {
     209           0 :         const Graphic* pGrf = ((SvxBrushItem*)pItem)->GetGraphic();
     210           0 :         if( pGrf ) {
     211           0 :             aOrigSize = GetGrfOrigSize( *pGrf );
     212           0 :             if (pGrf->GetType() == GRAPHIC_BITMAP && aOrigSize.Width() && aOrigSize.Height()) {
     213           0 :                 Bitmap aBitmap = pGrf->GetBitmap();
     214           0 :                 aOrigPixelSize = aBitmap.GetSizePixel();
     215             :             }
     216             :         }
     217             : 
     218           0 :         if( aOrigSize.Width() && aOrigSize.Height() )
     219             :         {
     220           0 :             CalcMinMaxBorder();
     221           0 :             aExampleWN.SetGraphic( *pGrf );
     222           0 :             aExampleWN.SetFrameSize( aOrigSize );
     223             : 
     224           0 :             bFound = sal_True;
     225           0 :             if( ((SvxBrushItem*)pItem)->GetGraphicLink() )
     226           0 :                 aGraphicName = *((SvxBrushItem*)pItem)->GetGraphicLink();
     227             :         }
     228             :     }
     229             : 
     230           0 :     GraphicHasChanged( bFound );
     231           0 :     bReset = sal_True;
     232           0 :     ActivatePage( rSet );
     233           0 :     bReset = sal_False;
     234           0 : }
     235             : 
     236           0 : sal_Bool SvxGrfCropPage::FillItemSet(SfxItemSet &rSet)
     237             : {
     238           0 :     const SfxItemPool& rPool = *rSet.GetPool();
     239           0 :     sal_Bool bModified = sal_False;
     240           0 :     if( aWidthMF.GetSavedValue() != aWidthMF.GetText() ||
     241           0 :         aHeightMF.GetSavedValue() != aHeightMF.GetText() )
     242             :     {
     243           0 :         sal_uInt16 nW = rPool.GetWhich( SID_ATTR_GRAF_FRMSIZE );
     244           0 :         FieldUnit eUnit = MapToFieldUnit( rSet.GetPool()->GetMetric( nW ));
     245             : 
     246           0 :         SvxSizeItem aSz( nW );
     247             : 
     248             :         // size could already have been set from another page
     249             :         // #44204#
     250           0 :         const SfxItemSet* pExSet = GetTabDialog() ? GetTabDialog()->GetExampleSet() : NULL;
     251           0 :         const SfxPoolItem* pItem = 0;
     252           0 :         if( pExSet && SFX_ITEM_SET ==
     253           0 :                 pExSet->GetItemState( nW, sal_False, &pItem ) )
     254           0 :             aSz = *(const SvxSizeItem*)pItem;
     255             :         else
     256           0 :             aSz = (const SvxSizeItem&)GetItemSet().Get( nW );
     257             : 
     258           0 :         Size aTmpSz( aSz.GetSize() );
     259           0 :         if( aWidthMF.GetText() != aWidthMF.GetSavedValue() )
     260           0 :             aTmpSz.Width() = lcl_GetValue( aWidthMF, eUnit );
     261           0 :         if( aHeightMF.GetText() != aHeightMF.GetSavedValue() )
     262           0 :             aTmpSz.Height() = lcl_GetValue( aHeightMF, eUnit );
     263           0 :         aSz.SetSize( aTmpSz );
     264           0 :         aWidthMF.SaveValue();
     265           0 :         aHeightMF.SaveValue();
     266             : 
     267           0 :         bModified |= 0 != rSet.Put( aSz );
     268             : 
     269           0 :         if( bSetOrigSize )
     270             :         {
     271             :             bModified |= 0 != rSet.Put( SvxSizeItem( rPool.GetWhich(
     272           0 :                         SID_ATTR_GRAF_FRMSIZE_PERCENT ), Size( 0, 0 )) );
     273           0 :         }
     274             :     }
     275           0 :     if( aLeftMF.IsModified() || aRightMF.IsModified() ||
     276           0 :         aTopMF.IsModified()  || aBottomMF.IsModified() )
     277             :     {
     278           0 :         sal_uInt16 nW = rPool.GetWhich( SID_ATTR_GRAF_CROP );
     279           0 :         FieldUnit eUnit = MapToFieldUnit( rSet.GetPool()->GetMetric( nW ));
     280           0 :         SvxGrfCrop* pNew = (SvxGrfCrop*)rSet.Get( nW ).Clone();
     281             : 
     282           0 :         pNew->SetLeft( lcl_GetValue( aLeftMF, eUnit ) );
     283           0 :         pNew->SetRight( lcl_GetValue( aRightMF, eUnit ) );
     284           0 :         pNew->SetTop( lcl_GetValue( aTopMF, eUnit ) );
     285           0 :         pNew->SetBottom( lcl_GetValue( aBottomMF, eUnit ) );
     286           0 :         bModified |= 0 != rSet.Put( *pNew );
     287           0 :         delete pNew;
     288             :     }
     289             : 
     290           0 :     if( aZoomConstRB.GetSavedValue() != aZoomConstRB.IsChecked() )
     291             :     {
     292             :         bModified |= 0 != rSet.Put( SfxBoolItem( rPool.GetWhich(
     293           0 :                     SID_ATTR_GRAF_KEEP_ZOOM), aZoomConstRB.IsChecked() ) );
     294             :     }
     295             : 
     296           0 :     bInitialized = sal_False;
     297             : 
     298           0 :     return bModified;
     299             : }
     300             : 
     301           0 : void SvxGrfCropPage::ActivatePage(const SfxItemSet& rSet)
     302             : {
     303             : #ifdef DBG_UTIL
     304             :     SfxItemPool* pPool = GetItemSet().GetPool();
     305             :     DBG_ASSERT( pPool, "Wo ist der Pool" );
     306             : #endif
     307             : 
     308           0 :     bSetOrigSize = sal_False;
     309             : 
     310             :     // Size
     311           0 :     Size aSize;
     312             :     const SfxPoolItem* pItem;
     313           0 :     if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_GRAF_FRMSIZE, sal_False, &pItem ) )
     314           0 :         aSize = ((const SvxSizeItem*)pItem)->GetSize();
     315             : 
     316           0 :     nOldWidth = aSize.Width();
     317           0 :     nOldHeight = aSize.Height();
     318             : 
     319           0 :     sal_Int64 nWidth = aWidthMF.Normalize(nOldWidth);
     320           0 :     sal_Int64 nHeight = aHeightMF.Normalize(nOldHeight);
     321             : 
     322           0 :     if (nWidth != aWidthMF.GetValue(FUNIT_TWIP))
     323             :     {
     324           0 :         if(!bReset)
     325             :         {
     326             :             // value was changed by wrap-tabpage and has to
     327             :             // be set with modify-flag
     328           0 :             aWidthMF.SetUserValue(nWidth, FUNIT_TWIP);
     329             :         }
     330             :         else
     331           0 :             aWidthMF.SetValue(nWidth, FUNIT_TWIP);
     332             :     }
     333           0 :     aWidthMF.SaveValue();
     334             : 
     335           0 :     if (nHeight != aHeightMF.GetValue(FUNIT_TWIP))
     336             :     {
     337           0 :         if (!bReset)
     338             :         {
     339             :             // value was changed by wrap-tabpage and has to
     340             :             // be set with modify-flag
     341           0 :             aHeightMF.SetUserValue(nHeight, FUNIT_TWIP);
     342             :         }
     343             :         else
     344           0 :             aHeightMF.SetValue(nHeight, FUNIT_TWIP);
     345             :     }
     346           0 :     aHeightMF.SaveValue();
     347           0 :     bInitialized = sal_True;
     348             : 
     349           0 :     if( SFX_ITEM_SET == rSet.GetItemState( SID_ATTR_GRAF_GRAPHIC, sal_False, &pItem ) )
     350             :     {
     351           0 :         const SvxBrushItem& rBrush = *(SvxBrushItem*)pItem;
     352           0 :         if( rBrush.GetGraphicLink() &&
     353           0 :             aGraphicName != *rBrush.GetGraphicLink() )
     354           0 :             aGraphicName = *rBrush.GetGraphicLink();
     355             : 
     356           0 :         const Graphic* pGrf = rBrush.GetGraphic();
     357           0 :         if( pGrf )
     358             :         {
     359           0 :             aExampleWN.SetGraphic( *pGrf );
     360           0 :             aOrigSize = GetGrfOrigSize( *pGrf );
     361           0 :             if (pGrf->GetType() == GRAPHIC_BITMAP && aOrigSize.Width() > 1 && aOrigSize.Height() > 1) {
     362           0 :                 Bitmap aBitmap = pGrf->GetBitmap();
     363           0 :                 aOrigPixelSize = aBitmap.GetSizePixel();
     364             :             }
     365           0 :             aExampleWN.SetFrameSize(aOrigSize);
     366           0 :             GraphicHasChanged( aOrigSize.Width() && aOrigSize.Height() );
     367           0 :             CalcMinMaxBorder();
     368             :         }
     369             :         else
     370           0 :             GraphicHasChanged( sal_False );
     371             :     }
     372             : 
     373           0 :     CalcZoom();
     374           0 : }
     375             : 
     376           0 : int SvxGrfCropPage::DeactivatePage(SfxItemSet *_pSet)
     377             : {
     378           0 :     if ( _pSet )
     379           0 :         FillItemSet( *_pSet );
     380           0 :     return sal_True;
     381             : }
     382             : 
     383             : /*--------------------------------------------------------------------
     384             :     description: scale changed, adjust size
     385             :  --------------------------------------------------------------------*/
     386             : 
     387           0 : IMPL_LINK( SvxGrfCropPage, ZoomHdl, MetricField *, pField )
     388             : {
     389           0 :     SfxItemPool* pPool = GetItemSet().GetPool();
     390             :     DBG_ASSERT( pPool, "Wo ist der Pool" );
     391             :     FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
     392           0 :                                                     SID_ATTR_GRAF_CROP ) ) );
     393             : 
     394           0 :     if( pField == &aWidthZoomMF )
     395             :     {
     396           0 :         long nLRBorders = lcl_GetValue(aLeftMF, eUnit)
     397           0 :                          +lcl_GetValue(aRightMF, eUnit);
     398             :         aWidthMF.SetValue( aWidthMF.Normalize(
     399           0 :             ((aOrigSize.Width() - nLRBorders) * pField->GetValue())/100L),
     400           0 :             eUnit);
     401             :     }
     402             :     else
     403             :     {
     404           0 :         long nULBorders = lcl_GetValue(aTopMF, eUnit)
     405           0 :                          +lcl_GetValue(aBottomMF, eUnit);
     406             :         aHeightMF.SetValue( aHeightMF.Normalize(
     407           0 :             ((aOrigSize.Height() - nULBorders ) * pField->GetValue())/100L) ,
     408           0 :             eUnit );
     409             :     }
     410             : 
     411           0 :     return 0;
     412             : }
     413             : 
     414             : /*--------------------------------------------------------------------
     415             :     description: change size, adjust scale
     416             :  --------------------------------------------------------------------*/
     417             : 
     418           0 : IMPL_LINK( SvxGrfCropPage, SizeHdl, MetricField *, pField )
     419             : {
     420           0 :     SfxItemPool* pPool = GetItemSet().GetPool();
     421             :     DBG_ASSERT( pPool, "Wo ist der Pool" );
     422             :     FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
     423           0 :                                                     SID_ATTR_GRAF_CROP ) ) );
     424             : 
     425             :     Size aSize( lcl_GetValue(aWidthMF, eUnit),
     426           0 :                 lcl_GetValue(aHeightMF, eUnit) );
     427             : 
     428           0 :     if(pField == &aWidthMF)
     429             :     {
     430           0 :         long nWidth = aOrigSize.Width() -
     431           0 :                 ( lcl_GetValue(aLeftMF, eUnit) +
     432           0 :                   lcl_GetValue(aRightMF, eUnit) );
     433           0 :         if(!nWidth)
     434           0 :             nWidth++;
     435           0 :         sal_uInt16 nZoom = (sal_uInt16)( aSize.Width() * 100L / nWidth);
     436           0 :         aWidthZoomMF.SetValue(nZoom);
     437             :     }
     438             :     else
     439             :     {
     440           0 :         long nHeight = aOrigSize.Height() -
     441           0 :                 ( lcl_GetValue(aTopMF, eUnit) +
     442           0 :                   lcl_GetValue(aBottomMF, eUnit));
     443           0 :         if(!nHeight)
     444           0 :             nHeight++;
     445           0 :         sal_uInt16 nZoom = (sal_uInt16)( aSize.Height() * 100L/ nHeight);
     446           0 :         aHeightZoomMF.SetValue(nZoom);
     447             :     }
     448             : 
     449           0 :     return 0;
     450             : }
     451             : 
     452             : /*--------------------------------------------------------------------
     453             :     description: evaluate border
     454             :  --------------------------------------------------------------------*/
     455             : 
     456           0 : IMPL_LINK( SvxGrfCropPage, CropHdl, const MetricField *, pField )
     457             : {
     458           0 :     SfxItemPool* pPool = GetItemSet().GetPool();
     459             :     DBG_ASSERT( pPool, "Wo ist der Pool" );
     460             :     FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
     461           0 :                                                     SID_ATTR_GRAF_CROP ) ) );
     462             : 
     463           0 :     sal_Bool bZoom = aZoomConstRB.IsChecked();
     464           0 :     if( pField == &aLeftMF || pField == &aRightMF )
     465             :     {
     466           0 :         long nLeft = lcl_GetValue( aLeftMF, eUnit );
     467           0 :         long nRight = lcl_GetValue( aRightMF, eUnit );
     468           0 :         long nWidthZoom = static_cast<long>(aWidthZoomMF.GetValue());
     469           0 :         if(bZoom && ( ( ( aOrigSize.Width() - (nLeft + nRight )) * nWidthZoom )
     470           0 :                             / 100 >= aPageSize.Width() ) )
     471             :         {
     472           0 :             if(pField == &aLeftMF)
     473             :             {
     474           0 :                 nLeft = aOrigSize.Width() -
     475           0 :                             ( aPageSize.Width() * 100 / nWidthZoom + nRight );
     476           0 :                 aLeftMF.SetValue( aLeftMF.Normalize( nLeft ), eUnit );
     477             :             }
     478             :             else
     479             :             {
     480           0 :                 nRight = aOrigSize.Width() -
     481           0 :                             ( aPageSize.Width() * 100 / nWidthZoom + nLeft );
     482           0 :                 aRightMF.SetValue( aRightMF.Normalize( nRight ), eUnit );
     483             :             }
     484             :         }
     485           0 :         aExampleWN.SetLeft(nLeft);
     486           0 :         aExampleWN.SetRight(nRight);
     487           0 :         if(bZoom)
     488             :         {
     489             :             // scale stays, recompute width
     490           0 :             ZoomHdl(&aWidthZoomMF);
     491           0 :         }
     492             :     }
     493             :     else
     494             :     {
     495           0 :         long nTop = lcl_GetValue( aTopMF, eUnit );
     496           0 :         long nBottom = lcl_GetValue( aBottomMF, eUnit );
     497           0 :         long nHeightZoom = static_cast<long>(aHeightZoomMF.GetValue());
     498           0 :         if(bZoom && ( ( ( aOrigSize.Height() - (nTop + nBottom )) * nHeightZoom)
     499           0 :                                             / 100 >= aPageSize.Height()))
     500             :         {
     501           0 :             if(pField == &aTopMF)
     502             :             {
     503           0 :                 nTop = aOrigSize.Height() -
     504           0 :                             ( aPageSize.Height() * 100 / nHeightZoom + nBottom);
     505           0 :                 aTopMF.SetValue( aWidthMF.Normalize( nTop ), eUnit );
     506             :             }
     507             :             else
     508             :             {
     509           0 :                 nBottom = aOrigSize.Height() -
     510           0 :                             ( aPageSize.Height() * 100 / nHeightZoom + nTop);
     511           0 :                 aBottomMF.SetValue( aWidthMF.Normalize( nBottom ), eUnit );
     512             :             }
     513             :         }
     514           0 :         aExampleWN.SetTop( nTop );
     515           0 :         aExampleWN.SetBottom( nBottom );
     516           0 :         if(bZoom)
     517             :         {
     518             :             // scale stays, recompute height
     519           0 :             ZoomHdl(&aHeightZoomMF);
     520             :         }
     521             :     }
     522           0 :     aExampleWN.Invalidate();
     523             :     // size and border changed -> recompute scale
     524           0 :     if(!bZoom)
     525           0 :         CalcZoom();
     526           0 :     CalcMinMaxBorder();
     527           0 :     return 0;
     528             : }
     529             : /*--------------------------------------------------------------------
     530             :     description: set original size
     531             :  --------------------------------------------------------------------*/
     532             : 
     533           0 : IMPL_LINK_NOARG(SvxGrfCropPage, OrigSizeHdl)
     534             : {
     535           0 :     SfxItemPool* pPool = GetItemSet().GetPool();
     536             :     DBG_ASSERT( pPool, "Wo ist der Pool" );
     537             :     FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
     538           0 :                                                     SID_ATTR_GRAF_CROP ) ) );
     539             : 
     540           0 :     long nWidth = aOrigSize.Width() -
     541           0 :         lcl_GetValue( aLeftMF, eUnit ) -
     542           0 :         lcl_GetValue( aRightMF, eUnit );
     543           0 :     aWidthMF.SetValue( aWidthMF.Normalize( nWidth ), eUnit );
     544           0 :     long nHeight = aOrigSize.Height() -
     545           0 :         lcl_GetValue( aTopMF, eUnit ) -
     546           0 :         lcl_GetValue( aBottomMF, eUnit );
     547           0 :     aHeightMF.SetValue( aHeightMF.Normalize( nHeight ), eUnit );
     548           0 :     aWidthZoomMF.SetValue(100);
     549           0 :     aHeightZoomMF.SetValue(100);
     550           0 :     bSetOrigSize = sal_True;
     551           0 :     return 0;
     552             : }
     553             : /*--------------------------------------------------------------------
     554             :     description: compute scale
     555             :  --------------------------------------------------------------------*/
     556             : 
     557           0 : void SvxGrfCropPage::CalcZoom()
     558             : {
     559           0 :     SfxItemPool* pPool = GetItemSet().GetPool();
     560             :     DBG_ASSERT( pPool, "Wo ist der Pool" );
     561             :     FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
     562           0 :                                                     SID_ATTR_GRAF_CROP ) ) );
     563             : 
     564           0 :     long nWidth = lcl_GetValue( aWidthMF, eUnit );
     565           0 :     long nHeight = lcl_GetValue( aHeightMF, eUnit );
     566           0 :     long nLRBorders = lcl_GetValue( aLeftMF, eUnit ) +
     567           0 :                       lcl_GetValue( aRightMF, eUnit );
     568           0 :     long nULBorders = lcl_GetValue( aTopMF, eUnit ) +
     569           0 :                       lcl_GetValue( aBottomMF, eUnit );
     570           0 :     sal_uInt16 nZoom = 0;
     571             :     long nDen;
     572           0 :     if( (nDen = aOrigSize.Width() - nLRBorders) > 0)
     573           0 :         nZoom = (sal_uInt16)((( nWidth  * 1000L / nDen )+5)/10);
     574           0 :     aWidthZoomMF.SetValue(nZoom);
     575           0 :     if( (nDen = aOrigSize.Height() - nULBorders) > 0)
     576           0 :         nZoom = (sal_uInt16)((( nHeight * 1000L / nDen )+5)/10);
     577             :     else
     578           0 :         nZoom = 0;
     579           0 :     aHeightZoomMF.SetValue(nZoom);
     580           0 : }
     581             : 
     582             : /*--------------------------------------------------------------------
     583             :     description: set minimum/maximum values for the margins
     584             :  --------------------------------------------------------------------*/
     585             : 
     586           0 : void SvxGrfCropPage::CalcMinMaxBorder()
     587             : {
     588           0 :     SfxItemPool* pPool = GetItemSet().GetPool();
     589             :     DBG_ASSERT( pPool, "Wo ist der Pool" );
     590             :     FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
     591           0 :                                                     SID_ATTR_GRAF_CROP ) ) );
     592           0 :     long nR = lcl_GetValue(aRightMF, eUnit );
     593           0 :     long nMinWidth = (aOrigSize.Width() * 10) /11;
     594           0 :     long nMin = nMinWidth - (nR >= 0 ? nR : 0);
     595           0 :     aLeftMF.SetMax( aLeftMF.Normalize(nMin), eUnit );
     596             : 
     597           0 :     long nL = lcl_GetValue(aLeftMF, eUnit );
     598           0 :     nMin = nMinWidth - (nL >= 0 ? nL : 0);
     599           0 :     aRightMF.SetMax( aRightMF.Normalize(nMin), eUnit );
     600             : 
     601           0 :     long nUp  = lcl_GetValue( aTopMF, eUnit );
     602           0 :     long nMinHeight = (aOrigSize.Height() * 10) /11;
     603           0 :     nMin = nMinHeight - (nUp >= 0 ? nUp : 0);
     604           0 :     aBottomMF.SetMax( aBottomMF.Normalize(nMin), eUnit );
     605             : 
     606           0 :     long nLow = lcl_GetValue(aBottomMF, eUnit );
     607           0 :     nMin = nMinHeight - (nLow >= 0 ? nLow : 0);
     608           0 :     aTopMF.SetMax( aTopMF.Normalize(nMin), eUnit );
     609           0 : }
     610             : /*--------------------------------------------------------------------
     611             :     description:   set spinsize to 1/20 of the original size,
     612             :                    fill FixedText with the original size
     613             :  --------------------------------------------------------------------*/
     614             : 
     615           0 : void SvxGrfCropPage::GraphicHasChanged( sal_Bool bFound )
     616             : {
     617           0 :     if( bFound )
     618             :     {
     619           0 :         SfxItemPool* pPool = GetItemSet().GetPool();
     620             :         DBG_ASSERT( pPool, "Wo ist der Pool" );
     621             :         FieldUnit eUnit = MapToFieldUnit( pPool->GetMetric( pPool->GetWhich(
     622           0 :                                                     SID_ATTR_GRAF_CROP ) ));
     623             : 
     624           0 :         sal_Int64 nSpin = aLeftMF.Normalize(aOrigSize.Width()) / 20;
     625           0 :         nSpin = MetricField::ConvertValue( nSpin, aOrigSize.Width(), 0,
     626           0 :                                                eUnit, aLeftMF.GetUnit());
     627             : 
     628             :         // if the margin is too big, it is set to 1/3 on both pages
     629           0 :         long nR = lcl_GetValue( aRightMF, eUnit );
     630           0 :         long nL = lcl_GetValue( aLeftMF, eUnit );
     631           0 :         if((nL + nR) < - aOrigSize.Width())
     632             :         {
     633           0 :             long nVal = aOrigSize.Width() / -3;
     634           0 :             aRightMF.SetValue( aRightMF.Normalize( nVal ), eUnit );
     635           0 :             aLeftMF.SetValue( aLeftMF.Normalize( nVal ), eUnit );
     636           0 :             aExampleWN.SetLeft(nVal);
     637           0 :             aExampleWN.SetRight(nVal);
     638             :         }
     639           0 :         long nUp  = lcl_GetValue(aTopMF, eUnit );
     640           0 :         long nLow = lcl_GetValue(aBottomMF, eUnit );
     641           0 :         if((nUp + nLow) < - aOrigSize.Height())
     642             :         {
     643           0 :             long nVal = aOrigSize.Height() / -3;
     644           0 :             aTopMF.SetValue( aTopMF.Normalize( nVal ), eUnit );
     645           0 :             aBottomMF.SetValue( aBottomMF.Normalize( nVal ), eUnit );
     646           0 :             aExampleWN.SetTop(nVal);
     647           0 :             aExampleWN.SetBottom(nVal);
     648             :         }
     649             : 
     650           0 :         aLeftMF.SetSpinSize(nSpin);
     651           0 :         aRightMF.SetSpinSize(nSpin);
     652           0 :         nSpin = aTopMF.Normalize(aOrigSize.Height()) / 20;
     653           0 :         nSpin = MetricField::ConvertValue( nSpin, aOrigSize.Width(), 0,
     654           0 :                                                eUnit, aLeftMF.GetUnit() );
     655           0 :         aTopMF.SetSpinSize(nSpin);
     656           0 :         aBottomMF.SetSpinSize(nSpin);
     657             : 
     658             :         // display original size
     659           0 :         const FieldUnit eMetric = GetModuleFieldUnit( GetItemSet() );
     660             : 
     661           0 :         MetricField aFld(this, WB_HIDE);
     662           0 :         SetFieldUnit( aFld, eMetric );
     663           0 :         aFld.SetDecimalDigits( aWidthMF.GetDecimalDigits() );
     664           0 :         aFld.SetMax( LONG_MAX - 1 );
     665             : 
     666           0 :         aFld.SetValue( aFld.Normalize( aOrigSize.Width() ), eUnit );
     667           0 :         OUString sTemp = aFld.GetText();
     668           0 :         aFld.SetValue( aFld.Normalize( aOrigSize.Height() ), eUnit );
     669             :         // multiplication sign (U+00D7)
     670           0 :         sTemp += OUString( sal_Unicode (0x00D7) );
     671           0 :         sTemp += aFld.GetText();
     672             : 
     673           0 :         if ( aOrigPixelSize.Width() && aOrigPixelSize.Height() ) {
     674           0 :              sal_Int32 ax = sal_Int32(floor((float)aOrigPixelSize.Width() /
     675           0 :                         ((float)aOrigSize.Width()/TWIP_TO_INCH)+0.5));
     676           0 :              sal_Int32 ay = sal_Int32(floor((float)aOrigPixelSize.Height() /
     677           0 :                         ((float)aOrigSize.Height()/TWIP_TO_INCH)+0.5));
     678           0 :              sTemp += " ";
     679           0 :              sTemp += CUI_RESSTR( STR_PPI );
     680           0 :              OUString sPPI = OUString::valueOf(ax);
     681           0 :              if (abs(ax - ay) > 1) {
     682           0 :                 sPPI += OUString( sal_Unicode (0x00D7) );
     683           0 :                 sPPI += OUString::valueOf(ay);
     684             :              }
     685           0 :              sTemp = sTemp.replaceAll("%1", sPPI);
     686             :         }
     687           0 :         aOrigSizeFT.SetText( sTemp );
     688             :     }
     689           0 :     aLeftFT         .Enable(bFound);
     690           0 :     aLeftMF         .Enable(bFound);
     691           0 :     aRightFT        .Enable(bFound);
     692           0 :     aRightMF        .Enable(bFound);
     693           0 :     aTopFT          .Enable(bFound);
     694           0 :     aTopMF          .Enable(bFound);
     695           0 :     aBottomFT       .Enable(bFound);
     696           0 :     aBottomMF       .Enable(bFound);
     697           0 :     aSizeConstRB    .Enable(bFound);
     698           0 :     aZoomConstRB    .Enable(bFound);
     699           0 :     aWidthFT        .Enable(bFound);
     700           0 :     aWidthMF        .Enable(bFound);
     701           0 :     aHeightFT       .Enable(bFound);
     702           0 :     aHeightMF       .Enable(bFound);
     703           0 :     aWidthZoomFT    .Enable(bFound);
     704           0 :     aWidthZoomMF    .Enable(bFound);
     705           0 :     aHeightZoomFT   .Enable(bFound);
     706           0 :     aHeightZoomMF   .Enable(bFound);
     707           0 :     aExampleWN      .Enable(bFound);
     708           0 :     aOrigSizePB     .Enable(bFound);
     709           0 :     aOrigSizeFT     .Enable(bFound);
     710           0 : }
     711             : 
     712           0 : IMPL_LINK_NOARG(SvxGrfCropPage, Timeout)
     713             : {
     714             :     DBG_ASSERT(pLastCropField,"Timeout ohne Feld?");
     715           0 :     CropHdl(pLastCropField);
     716           0 :     pLastCropField = 0;
     717           0 :     return 0;
     718             : }
     719             : 
     720             : 
     721           0 : IMPL_LINK( SvxGrfCropPage, CropLoseFocusHdl, MetricField*, pField )
     722             : {
     723           0 :     aTimer.Stop();
     724           0 :     CropHdl(pField);
     725           0 :     pLastCropField = 0;
     726           0 :     return 0;
     727             : }
     728             : 
     729             : 
     730           0 : IMPL_LINK( SvxGrfCropPage, CropModifyHdl, MetricField *, pField )
     731             : {
     732           0 :     aTimer.Start();
     733           0 :     pLastCropField = pField;
     734           0 :     return 0;
     735             : }
     736             : 
     737           0 : Size SvxGrfCropPage::GetGrfOrigSize( const Graphic& rGrf ) const
     738             : {
     739           0 :     const MapMode aMapTwip( MAP_TWIP );
     740           0 :     Size aSize( rGrf.GetPrefSize() );
     741           0 :     if( MAP_PIXEL == rGrf.GetPrefMapMode().GetMapUnit() )
     742           0 :         aSize = PixelToLogic( aSize, aMapTwip );
     743             :     else
     744             :         aSize = OutputDevice::LogicToLogic( aSize,
     745           0 :                                         rGrf.GetPrefMapMode(), aMapTwip );
     746           0 :     return aSize;
     747             : }
     748             : 
     749             : /*****************************************************************/
     750             : 
     751           0 : SvxGrfCropPage::SvxCropExample::SvxCropExample( Window* pPar,
     752             :                                                 const ResId& rResId )
     753             :     : Window( pPar, rResId ),
     754             :     aFrameSize( OutputDevice::LogicToLogic(
     755             :                             Size( CM_1_TO_TWIP / 2, CM_1_TO_TWIP / 2 ),
     756           0 :                             MapMode( MAP_TWIP ), GetMapMode() )),
     757           0 :     aTopLeft(0,0), aBottomRight(0,0)
     758             : {
     759           0 :     SetBorderStyle( WINDOW_BORDER_MONO );
     760           0 : }
     761             : 
     762           0 : void SvxGrfCropPage::SvxCropExample::Paint( const Rectangle& )
     763             : {
     764           0 :     Size aWinSize( PixelToLogic(GetOutputSizePixel() ));
     765           0 :     SetLineColor();
     766           0 :     SetFillColor( GetSettings().GetStyleSettings().GetWindowColor() );
     767           0 :     SetRasterOp( ROP_OVERPAINT );
     768           0 :     DrawRect( Rectangle( Point(), aWinSize ) );
     769             : 
     770           0 :     SetLineColor( Color( COL_WHITE ) );
     771           0 :     Rectangle aRect(Point((aWinSize.Width() - aFrameSize.Width())/2,
     772           0 :                           (aWinSize.Height() - aFrameSize.Height())/2),
     773           0 :                           aFrameSize );
     774           0 :     aGrf.Draw( this,  aRect.TopLeft(), aRect.GetSize() );
     775             : 
     776           0 :     Size aSz( 2, 0 );
     777           0 :     aSz = PixelToLogic( aSz );
     778           0 :     SetFillColor( Color( COL_TRANSPARENT ) );
     779           0 :     SetRasterOp( ROP_INVERT );
     780           0 :     aRect.Left()    += aTopLeft.Y();
     781           0 :     aRect.Top()     += aTopLeft.X();
     782           0 :     aRect.Right()   -= aBottomRight.Y();
     783           0 :     aRect.Bottom()  -= aBottomRight.X();
     784           0 :     DrawRect( aRect );
     785           0 : }
     786             : 
     787           0 : void SvxGrfCropPage::SvxCropExample::SetFrameSize( const Size& rSz )
     788             : {
     789           0 :     aFrameSize = rSz;
     790           0 :     if(!aFrameSize.Width())
     791           0 :         aFrameSize.Width() = 1;
     792           0 :     if(!aFrameSize.Height())
     793           0 :         aFrameSize.Height() = 1;
     794           0 :     Size aWinSize( GetOutputSizePixel() );
     795           0 :     Fraction aXScale( aWinSize.Width() * 4, aFrameSize.Width() * 5 );
     796           0 :     Fraction aYScale( aWinSize.Height() * 4, aFrameSize.Height() * 5 );
     797             : 
     798           0 :     if( aYScale < aXScale )
     799           0 :         aXScale = aYScale;
     800             : 
     801           0 :     MapMode aMapMode( GetMapMode() );
     802             : 
     803           0 :     aMapMode.SetScaleX( aXScale );
     804           0 :     aMapMode.SetScaleY( aXScale );
     805             : 
     806           0 :     SetMapMode( aMapMode );
     807           0 :     Invalidate();
     808           0 : }
     809             : 
     810             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10