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

Generated by: LCOV version 1.10