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

Generated by: LCOV version 1.10